mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user