From 224a51fa56d0d86f95c7c083fefdf85091e1109c Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 7 Feb 2020 14:56:48 -0800 Subject: [PATCH] :zap: Small improvements to AWS-SES-Node --- packages/nodes-base/nodes/Aws/AwsSes.node.ts | 248 +++++++----------- .../nodes-base/nodes/Aws/GenericFunctions.ts | 3 +- packages/nodes-base/nodes/Aws/ses.png | Bin 2528 -> 1022 bytes packages/nodes-base/package.json | 2 +- 4 files changed, 94 insertions(+), 159 deletions(-) diff --git a/packages/nodes-base/nodes/Aws/AwsSes.node.ts b/packages/nodes-base/nodes/Aws/AwsSes.node.ts index c22e6adc43..74870cc90f 100644 --- a/packages/nodes-base/nodes/Aws/AwsSes.node.ts +++ b/packages/nodes-base/nodes/Aws/AwsSes.node.ts @@ -1,4 +1,4 @@ -import { IExecuteFunctions, LoadNodeParameterOptions } from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { INodeTypeDescription, INodeExecutionData, @@ -10,7 +10,7 @@ import { awsApiRequestSOAP } from './GenericFunctions'; function setParameter(params: string[], base: string, values: string[]) { for (let i = 0; i < values.length; i++) { - params.push(`${base}.${i+1}=${values[i]}`) + params.push(`${base}.${i+1}=${values[i]}`); } } @@ -61,26 +61,7 @@ export class AwsSes implements INodeType { }, }, default: false, - description: 'Weather the body is html or not', - }, - { - displayName: 'Body', - name: 'body', - type: 'string', - typeOptions: { - alwaysOpenEditWindow: true, - }, - displayOptions: { - show: { - operation: [ - 'sendEmail', - ], - }, - }, - options: [], - default: '', - description: 'The message to be sent.', - required: true, + description: 'If body is HTML or simple text.', }, { displayName: 'Subject', @@ -97,8 +78,26 @@ export class AwsSes implements INodeType { required: true, }, { - displayName: 'Source', - name: 'source', + displayName: 'Body', + name: 'body', + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + default: '', + description: 'The message to be sent.', + required: true, + }, + { + displayName: 'From Email', + name: 'fromEmail', type: 'string', displayOptions: { show: { @@ -108,9 +107,29 @@ export class AwsSes implements INodeType { }, }, required: true, - description: 'The email address that is sending the email.', + description: 'Email address of the sender.', + placeholder: 'admin@example.com', default: '', }, + { + displayName: 'To Addresses', + name: 'toAddresses', + type: 'string', + description: 'Email addresses of the recipients.', + typeOptions: { + multipleValues: true, + multipleValueButtonText: 'Add To Email', + }, + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + placeholder: 'info@example.com', + default: [], + }, { displayName: 'Additional Fields', name: 'additionalFields', @@ -125,18 +144,52 @@ export class AwsSes implements INodeType { }, }, options: [ + { + displayName: 'Bcc Addresses', + name: 'bccAddresses', + type: 'string', + typeOptions: { + multipleValues: true, + multipleValueButtonText: 'Add Bcc Email', + }, + description: 'Bcc Recipients of the email.', + default: [], + }, + { + displayName: 'Cc Addresses', + name: 'ccAddresses', + type: 'string', + typeOptions: { + multipleValues: true, + multipleValueButtonText: 'Add Cc Email', + }, + description: 'Cc recipients of the email.', + default: [], + }, { displayName: 'Configuration Set Name', name: 'configurationSetName', type: 'string', - description: 'The name of the configuration set to use when you send an email using SendEmail.', + description: 'Name of the configuration set to use when you send an email using SendEmail.', default: '', }, + { + displayName: 'Reply To Addresses', + name: 'replyToAddresses', + type: 'string', + typeOptions: { + multipleValues: true, + multipleValueButtonText: 'Add Reply To Email', + }, + placeholder: 'Add Reply Address', + description: 'Reply-to email address(es) for the message.', + default: [], + }, { displayName: 'Return Path', name: 'returnPath', type: 'string', - description: 'The email address that bounces and complaints will be forwarded to when feedback forwarding is enabled', + description: 'Email address that bounces and complaints will be forwarded to when feedback forwarding is enabled', default: '', }, { @@ -153,113 +206,6 @@ export class AwsSes implements INodeType { description: 'This parameter is used only for sending authorization.', default: '', }, - { - displayName: 'Reply To Addresses', - name: 'replyToAddressesUI', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - placeholder: 'Add Reply Address', - description: 'The reply-to email address(es) for the message.', - default: {}, - options: [ - { - displayName: 'Reply Address', - name: 'replyToAddressesValues', - values: [ - { - displayName: 'Address', - name: 'address', - type: 'string', - default: '', - }, - ], - }, - ], - }, - { - displayName: 'Cc Addresses', - name: 'ccAddressesUi', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - placeholder: 'Add Cc Address', - description: 'The recipients to place on the CC: line of the message.', - default: {}, - options: [ - { - displayName: 'Cc Address', - name: 'ccAddressesValues', - values: [ - { - displayName: 'Address', - name: 'address', - type: 'string', - default: '', - }, - ], - }, - ], - }, - { - displayName: 'Bcc Addresses', - name: 'bccAddressesUi', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - placeholder: 'Add CC Address', - description: 'The recipients to place on the BCC: line of the message.', - default: {}, - options: [ - { - displayName: 'Bcc Address', - name: 'bccAddressesValues', - values: [ - { - displayName: 'Address', - name: 'address', - type: 'string', - default: '', - }, - ], - }, - ], - }, - ], - }, - { - displayName: 'To Addresses', - name: 'toAddressesUi', - type: 'fixedCollection', - description: 'The recipients to place on the To: line of the message.', - typeOptions: { - multipleValues: true, - }, - displayOptions: { - show: { - operation: [ - 'sendEmail', - ], - }, - }, - placeholder: 'Add Address', - default: {}, - options: [ - { - displayName: 'Address', - name: 'toAddressesValues', - values: [ - { - displayName: 'Address', - name: 'address', - type: 'string', - default: '', - }, - ], - }, ], }, ], @@ -268,30 +214,29 @@ export class AwsSes implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const returnData: IDataObject[] = []; - const length = items.length as unknown as number; let responseData; const operation = this.getNodeParameter('operation', 0) as string; - for (let i = 0; i < length; i++) { + for (let i = 0; i < items.length; i++) { if (operation === 'sendEmail') { - let toAddresses = (this.getNodeParameter('toAddressesUi', i) as IDataObject).toAddressesValues as string[]; + const toAddresses = this.getNodeParameter('toAddresses', i) as string[]; const message = this.getNodeParameter('body', i) as string; const subject = this.getNodeParameter('subject', i) as string; - const source = this.getNodeParameter('source', i) as string; + const fromEmail = this.getNodeParameter('fromEmail', i) as string; const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const params = [ `Message.Subject.Data=${subject}`, - `Source=${source}`, + `Source=${fromEmail}`, ]; if (isBodyHtml) { params.push(`Message.Body.Html.Data=${message}`); } else { params.push(`Message.Body.Text.Data=${message}`); } - if (toAddresses) { - //@ts-ignore - toAddresses = toAddresses.map(o => o.address); + if (toAddresses.length) { setParameter(params, 'Destination.ToAddresses.member', toAddresses); + } else { + throw new Error('At least one "To Address" has to be added!'); } if (additionalFields.configurationSetName) { params.push(`ConfigurationSetName=${additionalFields.configurationSetName}`); @@ -305,21 +250,11 @@ export class AwsSes implements INodeType { if (additionalFields.sourceArn) { params.push(`SourceArn=${additionalFields.sourceArn}`); } - if (additionalFields.replyToAddressesUI) { - let replyToAddresses = (additionalFields.replyToAddressesUI as IDataObject).replyToAddressesValues as string[]; - //@ts-ignore - replyToAddresses = replyToAddresses.map(o => o.address); - if (replyToAddresses) { - setParameter(params, 'ReplyToAddresses.member', replyToAddresses); - } + if (additionalFields.replyToAddresses) { + setParameter(params, 'ReplyToAddresses.member', additionalFields.replyToAddresses as string[]); } - if (additionalFields.bccAddressesUi) { - let bccAddresses = (additionalFields.bccAddressesUi as IDataObject).bccAddressesValues as string[]; - //@ts-ignore - bccAddresses = bccAddresses.map(o => o.address); - if (bccAddresses) { - setParameter(params, 'Destination.BccAddresses.member', bccAddresses); - } + if (additionalFields.bccAddresses) { + setParameter(params, 'Destination.BccAddresses.member', additionalFields.bccAddresses as string[]); } if (additionalFields.ccAddressesUi) { let ccAddresses = (additionalFields.ccAddressesUi as IDataObject).ccAddressesValues as string[]; @@ -329,6 +264,7 @@ export class AwsSes implements INodeType { setParameter(params, 'Destination.CcAddresses.member', ccAddresses); } } + try { responseData = await awsApiRequestSOAP.call(this, 'email', 'POST', '/?Action=SendEmail&' + params.join('&')); } catch(err) { diff --git a/packages/nodes-base/nodes/Aws/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/GenericFunctions.ts index b11d8fcae1..303a027078 100644 --- a/packages/nodes-base/nodes/Aws/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/GenericFunctions.ts @@ -31,9 +31,8 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I try { return await this.helpers.request!(options); } catch (error) { - //console.error(error); + const errorMessage = error.response.body.message || error.response.body.Message || error.message; - const errorMessage = error.response.body.message || error.response.body.Message; if (error.statusCode === 403) { if (errorMessage === 'The security token included in the request is invalid.') { throw new Error('The AWS credentials are not valid!'); diff --git a/packages/nodes-base/nodes/Aws/ses.png b/packages/nodes-base/nodes/Aws/ses.png index e07e379a6030a1e776e3a8dad38147b833491cb3..d4b396df8fbb36c2ef4ce843332d64b63e2f7ab7 100644 GIT binary patch delta 1011 zcmV>0+NnO6Z!L&wDTiq&*{nf{X(q>+JEVUx*{4C>uRMrpDd)y2gls0vuO!c) zKFyvzhiNK?XeZpNMA@f6+o(UNf-{I|DTZn(*{4C-r$ODUKY!k{IEiT~h-oR=r$F4P zLD{H5ifAc?X(;B!D~M(#kZvxBYAD&KK(&lFrhqbpY$@KWLV#x|u!%K-W+%#>I^L^7 zf@Ua(XDQvVI)ZH}p@1;Pn>yO6LZEywjAbI1TqE49L%Vq|np+^al{na^L9d85i&-F; zT^ZY`L)oW7h<|1)=%-4CWGRAkB-*Dzn}02-OC9XdBiW}xhiNH-WhmaOLfolB%A7se zr9$1RLWE~1gJvk(sX>KkDX@q&ifbyZh&AJ`M7oeTse?0`cP^1}EQM<-)T2MZlsdMJ zH>7_uj&3WIb1mk~mze+n09SNUPE!E>`}vFd{4V>86MqW)-HR6f`sKxOOb!D6`_r_G zdl>ri=HcGmvZ955cXDf1Q9&df4f^``@9pZ^*woF)$Huv|v8J7zl#_yfbZ=%^R8UV! zMm;qyEg~v37&!m{0su)wK~zY`?bg>*+dvQo@VkUK4zgn77;x<15JDi7KuGVs_t18A zvZ{^g?SKD&VI@2?ac3ky;_pc_n%{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1_&V3dO65jO_;60g{?_ifzqeDYP<=*|>P6T8E>?dKi^%bqEv#t}Gw z@?Nwv5cs9zaYalKAHjQQ+%!^{e4v`@xqcnH(tMaHJfAeyP34#$5V9i+iZrXVd$?$D zMil$@sjMtZX@+D9tcP8o@UtxjI2D?^nKS6Lpij>(d}w_a4mA~zc3fECrxZMkjKG`D zckY!Hh-xOk!d8VC?QJ&iX%m2iVc#>&kUhbr`p;;ttdshuqyK$f*O+IbnLvAtBmL@& R9rV#Z%J{N{ezmT1%%8t+hWh{j diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 2ffdb92e68..a1a31e472c 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -105,8 +105,8 @@ "dist/nodes/Asana/Asana.node.js", "dist/nodes/Asana/AsanaTrigger.node.js", "dist/nodes/Aws/AwsLambda.node.js", - "dist/nodes/Aws/AwsSns.node.js", "dist/nodes/Aws/AwsSes.node.js", + "dist/nodes/Aws/AwsSns.node.js", "dist/nodes/Bitbucket/BitbucketTrigger.node.js", "dist/nodes/Bitly/Bitly.node.js", "dist/nodes/Chargebee/Chargebee.node.js",