n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -1,6 +1,4 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
export const contactOperations: INodeProperties[] = [
{
@@ -10,16 +8,15 @@ export const contactOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'contact',
],
resource: ['contact'],
},
},
options: [
{
name: 'Create or Update',
value: 'upsert',
description: 'Create a new contact, or update the current one if it already exists (upsert)',
description:
'Create a new contact, or update the current one if it already exists (upsert)',
action: 'Create or update a contact',
},
{
@@ -55,12 +52,8 @@ export const contactFields: INodeProperties[] = [
type: 'boolean',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'getAll',
],
resource: ['contact'],
operation: ['getAll'],
},
},
default: false,
@@ -72,15 +65,9 @@ export const contactFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'getAll',
],
returnAll: [
false,
],
resource: ['contact'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
@@ -98,12 +85,8 @@ export const contactFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'getAll',
],
resource: ['contact'],
operation: ['getAll'],
},
},
options: [
@@ -112,7 +95,8 @@ export const contactFields: INodeProperties[] = [
name: 'query',
type: 'string',
default: '',
description: 'The query field accepts valid <a href="https://sendgrid.com/docs/for-developers/sending-email/segmentation-query-language/">SGQL</a> for searching for a contact',
description:
'The query field accepts valid <a href="https://sendgrid.com/docs/for-developers/sending-email/segmentation-query-language/">SGQL</a> for searching for a contact',
},
],
},
@@ -128,12 +112,8 @@ export const contactFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'upsert',
],
resource: [
'contact',
],
operation: ['upsert'],
resource: ['contact'],
},
},
default: '',
@@ -147,12 +127,8 @@ export const contactFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'upsert',
],
resource: ['contact'],
operation: ['upsert'],
},
},
options: [
@@ -248,7 +224,8 @@ export const contactFields: INodeProperties[] = [
loadOptionsMethod: 'getListIds',
},
default: [],
description: 'ID of the field to set. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'ID of the field to set. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
],
},
@@ -277,7 +254,8 @@ export const contactFields: INodeProperties[] = [
loadOptionsMethod: 'getCustomFields',
},
default: '',
description: 'ID of the field. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'ID of the field. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Field Value',
@@ -303,15 +281,9 @@ export const contactFields: INodeProperties[] = [
default: '',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'delete',
],
deleteAll: [
false,
],
resource: ['contact'],
operation: ['delete'],
deleteAll: [false],
},
},
description: 'ID of the contact. Multiple can be added separated by comma.',
@@ -322,12 +294,8 @@ export const contactFields: INodeProperties[] = [
type: 'boolean',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'delete',
],
resource: ['contact'],
operation: ['delete'],
},
},
default: false,
@@ -354,12 +322,8 @@ export const contactFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'contact',
],
operation: ['get'],
resource: ['contact'],
},
},
default: 'id',
@@ -372,15 +336,9 @@ export const contactFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'contact',
],
by: [
'id',
],
operation: ['get'],
resource: ['contact'],
by: ['id'],
},
},
default: '',
@@ -394,15 +352,9 @@ export const contactFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'contact',
],
by: [
'email',
],
operation: ['get'],
resource: ['contact'],
by: ['email'],
},
},
default: '',

View File

@@ -1,6 +1,4 @@
import {
OptionsWithUri,
} from 'request';
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
@@ -9,11 +7,18 @@ import {
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject, NodeApiError,
} from 'n8n-workflow';
import { IDataObject, NodeApiError } from 'n8n-workflow';
export async function sendGridApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function sendGridApiRequest(
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
endpoint: string,
method: string,
// tslint:disable-next-line:no-any
body: any = {},
qs: IDataObject = {},
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const host = 'api.sendgrid.com/v3';
const options: OptionsWithUri = {
@@ -39,8 +44,16 @@ export async function sendGridApiRequest(this: IHookFunctions | IExecuteFunction
}
}
export async function sendGridApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, endpoint: string, method: string, propertyName: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function sendGridApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
endpoint: string,
method: string,
propertyName: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
@@ -54,9 +67,7 @@ export async function sendGridApiRequestAllItems(this: IExecuteFunctions | ILoad
if (query.limit && returnData.length >= query.limit) {
return returnData;
}
} while (
responseData._metadata.next !== undefined
);
} while (responseData._metadata.next !== undefined);
return returnData;
}

View File

@@ -1,6 +1,4 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
export const listOperations: INodeProperties[] = [
{
@@ -10,9 +8,7 @@ export const listOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'list',
],
resource: ['list'],
},
},
options: [
@@ -61,12 +57,8 @@ export const listFields: INodeProperties[] = [
type: 'boolean',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'getAll',
],
resource: ['list'],
operation: ['getAll'],
},
},
default: false,
@@ -78,15 +70,9 @@ export const listFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
resource: [
'list',
],
operation: [
'getAll',
],
returnAll: [
false,
],
resource: ['list'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
@@ -107,12 +93,8 @@ export const listFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'list',
],
operation: ['create'],
resource: ['list'],
},
},
default: '',
@@ -129,12 +111,8 @@ export const listFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'list',
],
operation: ['delete'],
resource: ['list'],
},
},
default: '',
@@ -147,12 +125,8 @@ export const listFields: INodeProperties[] = [
default: false,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'list',
],
operation: ['delete'],
resource: ['list'],
},
},
description: 'Whether to delete all contacts on the list',
@@ -168,12 +142,8 @@ export const listFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'list',
],
operation: ['get'],
resource: ['list'],
},
},
default: '',
@@ -186,12 +156,8 @@ export const listFields: INodeProperties[] = [
default: false,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'list',
],
operation: ['get'],
resource: ['list'],
},
},
description: 'Whether to return the contact sample',
@@ -206,12 +172,8 @@ export const listFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'list',
],
operation: ['update'],
resource: ['list'],
},
},
default: '',
@@ -224,12 +186,8 @@ export const listFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'list',
],
operation: ['update'],
resource: ['list'],
},
},
default: '',

View File

@@ -1,6 +1,4 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
export const mailOperations: INodeProperties[] = [
{
@@ -10,9 +8,7 @@ export const mailOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'mail',
],
resource: ['mail'],
},
},
options: [
@@ -40,12 +36,8 @@ export const mailFields: INodeProperties[] = [
description: 'Email address of the sender of the email',
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
resource: ['mail'],
operation: ['send'],
},
},
},
@@ -58,12 +50,8 @@ export const mailFields: INodeProperties[] = [
description: 'Name of the sender of the email',
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
resource: ['mail'],
operation: ['send'],
},
},
},
@@ -76,12 +64,8 @@ export const mailFields: INodeProperties[] = [
description: 'Comma-separated list of recipient email addresses',
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
resource: ['mail'],
operation: ['send'],
},
},
},
@@ -93,15 +77,9 @@ export const mailFields: INodeProperties[] = [
description: 'Subject of the email to send',
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
dynamicTemplate: [
false,
],
resource: ['mail'],
operation: ['send'],
dynamicTemplate: [false],
},
},
},
@@ -114,12 +92,8 @@ export const mailFields: INodeProperties[] = [
description: 'Whether this email will contain a dynamic template',
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
resource: ['mail'],
operation: ['send'],
},
},
},
@@ -141,15 +115,9 @@ export const mailFields: INodeProperties[] = [
],
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
dynamicTemplate: [
false,
],
resource: ['mail'],
operation: ['send'],
dynamicTemplate: [false],
},
},
},
@@ -165,15 +133,9 @@ export const mailFields: INodeProperties[] = [
},
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
dynamicTemplate: [
false,
],
resource: ['mail'],
operation: ['send'],
dynamicTemplate: [false],
},
},
},
@@ -181,22 +143,17 @@ export const mailFields: INodeProperties[] = [
displayName: 'Template Name or ID',
name: 'templateId',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: [],
typeOptions: {
loadOptionsMethod: 'getTemplateIds',
},
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
dynamicTemplate: [
true,
],
resource: ['mail'],
operation: ['send'],
dynamicTemplate: [true],
},
},
},
@@ -211,15 +168,9 @@ export const mailFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
dynamicTemplate: [
true,
],
resource: ['mail'],
operation: ['send'],
dynamicTemplate: [true],
},
},
options: [
@@ -253,12 +204,8 @@ export const mailFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'mail',
],
operation: [
'send',
],
resource: ['mail'],
operation: ['send'],
},
},
options: [
@@ -274,21 +221,24 @@ export const mailFields: INodeProperties[] = [
name: 'bccEmail',
type: 'string',
default: '',
description: 'Comma-separated list of emails of the recipients of a blind carbon copy of the email',
description:
'Comma-separated list of emails of the recipients of a blind carbon copy of the email',
},
{
displayName: 'Categories',
name: 'categories',
type: 'string',
default: '',
description: 'Comma-separated list of categories. Each category name may not exceed 255 characters.',
description:
'Comma-separated list of categories. Each category name may not exceed 255 characters.',
},
{
displayName: 'CC Email',
name: 'ccEmail',
type: 'string',
default: '',
description: 'Comma-separated list of emails of the recipients of a carbon copy of the email',
description:
'Comma-separated list of emails of the recipients of a carbon copy of the email',
},
{
displayName: 'Enable Sandbox',
@@ -341,7 +291,8 @@ export const mailFields: INodeProperties[] = [
name: 'sendAt',
type: 'dateTime',
default: '',
description: 'When to deliver the email. Scheduling more than 72 hours in advance is forbidden.',
description:
'When to deliver the email. Scheduling more than 72 hours in advance is forbidden.',
},
],
},
@@ -349,35 +300,35 @@ export const mailFields: INodeProperties[] = [
export type SendMailBody = {
personalizations: Array<{
to: EmailName[],
subject?: string,
cc?: EmailName[],
bcc?: EmailName[],
dynamic_template_data?: { [key: string]: string },
send_at?: number,
}>,
to: EmailName[];
subject?: string;
cc?: EmailName[];
bcc?: EmailName[];
dynamic_template_data?: { [key: string]: string };
send_at?: number;
}>;
ip_pool_name?: string;
from: EmailName,
template_id?: string,
from: EmailName;
template_id?: string;
content?: Array<{
type: string,
value: string,
}>,
categories?: string[],
headers?: { [key: string]: string },
type: string;
value: string;
}>;
categories?: string[];
headers?: { [key: string]: string };
attachments?: Array<{
content: string,
filename: string,
type: string,
}>,
content: string;
filename: string;
type: string;
}>;
mail_settings: {
sandbox_mode: {
enable: boolean,
},
},
enable: boolean;
};
};
};
type EmailName = {
email: string,
name?: string,
email: string;
name?: string;
};

View File

@@ -7,29 +7,16 @@ import {
INodePropertyOptions,
INodeType,
INodeTypeDescription,
NodeOperationError
NodeOperationError,
} from 'n8n-workflow';
import {
listFields,
listOperations,
} from './ListDescription';
import { listFields, listOperations } from './ListDescription';
import {
contactFields,
contactOperations
} from './ContactDescription';
import { contactFields, contactOperations } from './ContactDescription';
import {
mailFields,
mailOperations,
SendMailBody,
} from './MailDescription';
import { mailFields, mailOperations, SendMailBody } from './MailDescription';
import {
sendGridApiRequest,
sendGridApiRequestAllItems,
} from './GenericFunctions';
import { sendGridApiRequest, sendGridApiRequestAllItems } from './GenericFunctions';
import moment from 'moment-timezone';
@@ -90,9 +77,15 @@ export class SendGrid implements INodeType {
methods = {
loadOptions: {
// Get custom fields to display to user so that they can select them easily
async getCustomFields(this: ILoadOptionsFunctions,): Promise<INodePropertyOptions[]> {
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const { custom_fields } = await sendGridApiRequest.call(this, '/marketing/field_definitions', 'GET', {}, {});
const { custom_fields } = await sendGridApiRequest.call(
this,
'/marketing/field_definitions',
'GET',
{},
{},
);
if (custom_fields !== undefined) {
for (const customField of custom_fields) {
returnData.push({
@@ -106,7 +99,14 @@ export class SendGrid implements INodeType {
// Get lists to display to user so that they can select them easily
async getListIds(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const lists = await sendGridApiRequestAllItems.call(this, `/marketing/lists`, 'GET', 'result', {}, {});
const lists = await sendGridApiRequestAllItems.call(
this,
`/marketing/lists`,
'GET',
'result',
{},
{},
);
for (const list of lists) {
returnData.push({
name: list.name,
@@ -116,8 +116,17 @@ export class SendGrid implements INodeType {
return returnData;
},
async getTemplateIds(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const responseData = await sendGridApiRequest.call(this, '/templates', 'GET', {}, { generations: 'dynamic' });
return responseData.templates.map(({ id, name }: { id: string, name: string }) => ({ name, value: id }));
const responseData = await sendGridApiRequest.call(
this,
'/templates',
'GET',
{},
{ generations: 'dynamic' },
);
return responseData.templates.map(({ id, name }: { id: string; name: string }) => ({
name,
value: id,
}));
},
},
};
@@ -146,7 +155,14 @@ export class SendGrid implements INodeType {
method = 'POST';
Object.assign(body, { query: filters.query });
}
responseData = await sendGridApiRequestAllItems.call(this, endpoint, method, 'result', body, qs);
responseData = await sendGridApiRequestAllItems.call(
this,
endpoint,
method,
'result',
body,
qs,
);
if (returnAll === false) {
const limit = this.getNodeParameter('limit', i) as number;
responseData = responseData.splice(0, limit);
@@ -199,15 +215,13 @@ export class SendGrid implements INodeType {
let lists;
for (let i = 0; i < length; i++) {
const email = this.getNodeParameter('email', i) as string;
const additionalFields = this.getNodeParameter(
'additionalFields',
i,
) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const contact: IDataObject = {
email,
};
if (additionalFields.addressUi) {
const addressValues = (additionalFields.addressUi as IDataObject).addressValues as IDataObject;
const addressValues = (additionalFields.addressUi as IDataObject)
.addressValues as IDataObject;
const addressLine1 = addressValues.address1 as string;
const addressLine2 = addressValues.address2 as string;
if (addressLine2) {
@@ -240,26 +254,39 @@ export class SendGrid implements INodeType {
Object.assign(contact, { state_province_region: stateProvinceRegion });
}
if (additionalFields.alternateEmails) {
const alternateEmails = ((additionalFields.alternateEmails as string).split(',') as string[]).filter(email => !!email);
const alternateEmails = (
(additionalFields.alternateEmails as string).split(',') as string[]
).filter((email) => !!email);
if (alternateEmails.length !== 0) {
Object.assign(contact, { alternate_emails: alternateEmails });
}
}
if (additionalFields.listIdsUi) {
const listIdValues = (additionalFields.listIdsUi as IDataObject).listIdValues as IDataObject;
const listIdValues = (additionalFields.listIdsUi as IDataObject)
.listIdValues as IDataObject;
const listIds = listIdValues.listIds as IDataObject[];
lists = listIds;
}
if (additionalFields.customFieldsUi) {
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
const customFields = (additionalFields.customFieldsUi as IDataObject)
.customFieldValues as IDataObject[];
if (customFields) {
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
const data = customFields.reduce(
(obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }),
{},
);
Object.assign(contact, { custom_fields: data });
}
}
contacts.push(contact);
}
responseData = await sendGridApiRequest.call(this, '/marketing/contacts', 'PUT', { list_ids: lists, contacts }, qs);
responseData = await sendGridApiRequest.call(
this,
'/marketing/contacts',
'PUT',
{ list_ids: lists, contacts },
qs,
);
returnData.push(responseData);
} catch (error) {
if (this.continueOnFail()) {
@@ -277,7 +304,13 @@ export class SendGrid implements INodeType {
qs.delete_all_contacts = 'true';
}
qs.ids = (this.getNodeParameter('ids', i) as string).replace(/\s/g, '');
responseData = await sendGridApiRequest.call(this, `/marketing/contacts`, 'DELETE', {}, qs);
responseData = await sendGridApiRequest.call(
this,
`/marketing/contacts`,
'DELETE',
{},
qs,
);
returnData.push(responseData);
} catch (error) {
if (this.continueOnFail()) {
@@ -294,7 +327,14 @@ export class SendGrid implements INodeType {
for (let i = 0; i < length; i++) {
try {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
responseData = await sendGridApiRequestAllItems.call(this, `/marketing/lists`, 'GET', 'result', {}, qs);
responseData = await sendGridApiRequestAllItems.call(
this,
`/marketing/lists`,
'GET',
'result',
{},
qs,
);
if (returnAll === false) {
const limit = this.getNodeParameter('limit', i) as number;
responseData = responseData.splice(0, limit);
@@ -314,7 +354,13 @@ export class SendGrid implements INodeType {
try {
const listId = this.getNodeParameter('listId', i) as string;
qs.contact_sample = this.getNodeParameter('contactSample', i) as boolean;
responseData = await sendGridApiRequest.call(this, `/marketing/lists/${listId}`, 'GET', {}, qs);
responseData = await sendGridApiRequest.call(
this,
`/marketing/lists/${listId}`,
'GET',
{},
qs,
);
returnData.push(responseData);
} catch (error) {
if (this.continueOnFail()) {
@@ -329,7 +375,13 @@ export class SendGrid implements INodeType {
for (let i = 0; i < length; i++) {
try {
const name = this.getNodeParameter('name', i) as string;
responseData = await sendGridApiRequest.call(this, '/marketing/lists', 'POST', { name }, qs);
responseData = await sendGridApiRequest.call(
this,
'/marketing/lists',
'POST',
{ name },
qs,
);
returnData.push(responseData);
} catch (error) {
if (this.continueOnFail()) {
@@ -345,7 +397,13 @@ export class SendGrid implements INodeType {
try {
const listId = this.getNodeParameter('listId', i) as string;
qs.delete_contacts = this.getNodeParameter('deleteContacts', i) as boolean;
responseData = await sendGridApiRequest.call(this, `/marketing/lists/${listId}`, 'DELETE', {}, qs);
responseData = await sendGridApiRequest.call(
this,
`/marketing/lists/${listId}`,
'DELETE',
{},
qs,
);
responseData = { success: true };
returnData.push(responseData);
} catch (error) {
@@ -362,7 +420,13 @@ export class SendGrid implements INodeType {
try {
const name = this.getNodeParameter('name', i) as string;
const listId = this.getNodeParameter('listId', i) as string;
responseData = await sendGridApiRequest.call(this, `/marketing/lists/${listId}`, 'PATCH', { name }, qs);
responseData = await sendGridApiRequest.call(
this,
`/marketing/lists/${listId}`,
'PATCH',
{ name },
qs,
);
returnData.push(responseData);
} catch (error) {
if (this.continueOnFail()) {
@@ -396,7 +460,7 @@ export class SendGrid implements INodeType {
} = this.getNodeParameter('additionalFields', i) as {
bccEmail: string;
ccEmail: string;
enableSandbox: boolean,
enableSandbox: boolean;
sendAt: string;
headers: { details: Array<{ key: string; value: string }> };
attachments: string;
@@ -405,9 +469,11 @@ export class SendGrid implements INodeType {
};
const body: SendMailBody = {
personalizations: [{
to: parsedToEmail,
}],
personalizations: [
{
to: parsedToEmail,
},
],
from: {
email: (this.getNodeParameter('fromEmail', i) as string).trim(),
name: this.getNodeParameter('fromName', i) as string,
@@ -426,12 +492,12 @@ export class SendGrid implements INodeType {
body.template_id = this.getNodeParameter('templateId', i) as string;
const { fields } = this.getNodeParameter('dynamicTemplateFields', i) as {
fields: Array<{ [key: string]: string }>
fields: Array<{ [key: string]: string }>;
};
if (fields) {
body.personalizations[0].dynamic_template_data = {};
fields.forEach(field => {
fields.forEach((field) => {
body.personalizations[0].dynamic_template_data![field.key] = field.value;
});
}
@@ -439,10 +505,12 @@ export class SendGrid implements INodeType {
// message body
} else {
body.personalizations[0].subject = this.getNodeParameter('subject', i) as string;
body.content = [{
type: this.getNodeParameter('contentType', i) as string,
value: this.getNodeParameter('contentValue', i) as string,
}];
body.content = [
{
type: this.getNodeParameter('contentType', i) as string,
value: this.getNodeParameter('contentValue', i) as string,
},
];
}
if (attachments) {
@@ -451,7 +519,11 @@ export class SendGrid implements INodeType {
for (const property of binaryProperties) {
if (!items[i].binary?.hasOwnProperty(property)) {
throw new NodeOperationError(this.getNode(), `The binary property ${property} does not exist`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The binary property ${property} does not exist`,
{ itemIndex: i },
);
}
const binaryProperty = items[i].binary![property];
@@ -471,16 +543,16 @@ export class SendGrid implements INodeType {
}
if (bccEmail) {
body.personalizations[0].bcc = bccEmail.split(',').map(i => ({ email: i.trim() }));
body.personalizations[0].bcc = bccEmail.split(',').map((i) => ({ email: i.trim() }));
}
if (ccEmail) {
body.personalizations[0].cc = ccEmail.split(',').map(i => ({ email: i.trim() }));
body.personalizations[0].cc = ccEmail.split(',').map((i) => ({ email: i.trim() }));
}
if (headers?.details.length) {
const parsedHeaders: { [key: string]: string } = {};
headers.details.forEach(obj => parsedHeaders[obj['key']] = obj['value']);
headers.details.forEach((obj) => (parsedHeaders[obj['key']] = obj['value']));
body.headers = parsedHeaders;
}
@@ -496,7 +568,9 @@ export class SendGrid implements INodeType {
body.personalizations[0].send_at = moment.tz(sendAt, timezone).unix();
}
const data = await sendGridApiRequest.call(this, '/mail/send', 'POST', body, qs, { resolveWithFullResponse: true });
const data = await sendGridApiRequest.call(this, '/mail/send', 'POST', body, qs, {
resolveWithFullResponse: true,
});
returnData.push({ messageId: data!.headers['x-message-id'] });
} catch (error) {