mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add full continue-on-fail support to all nodes (#1996)
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
@@ -139,22 +139,30 @@ export class SendGrid implements INodeType {
|
||||
if (resource === 'contact') {
|
||||
if (operation === 'getAll') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
let endpoint = '/marketing/contacts';
|
||||
let method = 'GET';
|
||||
const body: IDataObject = {};
|
||||
if (filters.query && filters.query !== '') {
|
||||
endpoint = '/marketing/contacts/search';
|
||||
method = 'POST';
|
||||
Object.assign(body, { query: filters.query });
|
||||
try {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
let endpoint = '/marketing/contacts';
|
||||
let method = 'GET';
|
||||
const body: IDataObject = {};
|
||||
if (filters.query && filters.query !== '') {
|
||||
endpoint = '/marketing/contacts/search';
|
||||
method = 'POST';
|
||||
Object.assign(body, { query: filters.query });
|
||||
}
|
||||
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);
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
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);
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
@@ -163,272 +171,343 @@ export class SendGrid implements INodeType {
|
||||
let method;
|
||||
const body: IDataObject = {};
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (by === 'id') {
|
||||
method = 'GET';
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
endpoint = `/marketing/contacts/${contactId}`;
|
||||
} else {
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
endpoint = '/marketing/contacts/search';
|
||||
method = 'POST';
|
||||
Object.assign(body, { query: `email LIKE '${email}' ` });
|
||||
try {
|
||||
if (by === 'id') {
|
||||
method = 'GET';
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
endpoint = `/marketing/contacts/${contactId}`;
|
||||
} else {
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
endpoint = '/marketing/contacts/search';
|
||||
method = 'POST';
|
||||
Object.assign(body, { query: `email LIKE '${email}' ` });
|
||||
}
|
||||
responseData = await sendGridApiRequest.call(this, endpoint, method, body, qs);
|
||||
responseData = responseData.result || responseData;
|
||||
if (Array.isArray(responseData)) {
|
||||
responseData = responseData[0];
|
||||
}
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
responseData = await sendGridApiRequest.call(this, endpoint, method, body, qs);
|
||||
responseData = responseData.result || responseData;
|
||||
if (Array.isArray(responseData)) {
|
||||
responseData = responseData[0];
|
||||
}
|
||||
returnData.push(responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'upsert') {
|
||||
const contacts = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
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 addressLine1 = addressValues.address1 as string;
|
||||
const addressLine2 = addressValues.address2 as string;
|
||||
if (addressLine2) {
|
||||
Object.assign(contact, { address_line_2: addressLine2 });
|
||||
try {
|
||||
const contacts = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
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 addressLine1 = addressValues.address1 as string;
|
||||
const addressLine2 = addressValues.address2 as string;
|
||||
if (addressLine2) {
|
||||
Object.assign(contact, { address_line_2: addressLine2 });
|
||||
}
|
||||
Object.assign(contact, { address_line_1: addressLine1 });
|
||||
}
|
||||
Object.assign(contact, { address_line_1: addressLine1 });
|
||||
}
|
||||
if (additionalFields.city) {
|
||||
const city = additionalFields.city as string;
|
||||
Object.assign(contact, { city });
|
||||
}
|
||||
if (additionalFields.country) {
|
||||
const country = additionalFields.country as string;
|
||||
Object.assign(contact, { country });
|
||||
}
|
||||
if (additionalFields.firstName) {
|
||||
const firstName = additionalFields.firstName as string;
|
||||
Object.assign(contact, { first_name: firstName });
|
||||
}
|
||||
if (additionalFields.lastName) {
|
||||
const lastName = additionalFields.lastName as string;
|
||||
Object.assign(contact, { last_name: lastName });
|
||||
}
|
||||
if (additionalFields.postalCode) {
|
||||
const postalCode = additionalFields.postalCode as string;
|
||||
Object.assign(contact, { postal_code: postalCode });
|
||||
}
|
||||
if (additionalFields.stateProvinceRegion) {
|
||||
const stateProvinceRegion = additionalFields.stateProvinceRegion as string;
|
||||
Object.assign(contact, { state_province_region: stateProvinceRegion });
|
||||
}
|
||||
if (additionalFields.alternateEmails) {
|
||||
const alternateEmails = ((additionalFields.alternateEmails as string).split(',') as string[]).filter(email => !!email);
|
||||
if (alternateEmails.length !== 0) {
|
||||
Object.assign(contact, { alternate_emails: alternateEmails });
|
||||
if (additionalFields.city) {
|
||||
const city = additionalFields.city as string;
|
||||
Object.assign(contact, { city });
|
||||
}
|
||||
}
|
||||
if (additionalFields.listIdsUi) {
|
||||
const listIdValues = (additionalFields.listIdsUi as IDataObject).listIdValues as IDataObject;
|
||||
const listIds = listIdValues.listIds as IDataObject[];
|
||||
Object.assign(contact, { list_ids: listIds });
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
|
||||
if (customFields) {
|
||||
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(contact, { custom_fields: data });
|
||||
if (additionalFields.country) {
|
||||
const country = additionalFields.country as string;
|
||||
Object.assign(contact, { country });
|
||||
}
|
||||
if (additionalFields.firstName) {
|
||||
const firstName = additionalFields.firstName as string;
|
||||
Object.assign(contact, { first_name: firstName });
|
||||
}
|
||||
if (additionalFields.lastName) {
|
||||
const lastName = additionalFields.lastName as string;
|
||||
Object.assign(contact, { last_name: lastName });
|
||||
}
|
||||
if (additionalFields.postalCode) {
|
||||
const postalCode = additionalFields.postalCode as string;
|
||||
Object.assign(contact, { postal_code: postalCode });
|
||||
}
|
||||
if (additionalFields.stateProvinceRegion) {
|
||||
const stateProvinceRegion = additionalFields.stateProvinceRegion as string;
|
||||
Object.assign(contact, { state_province_region: stateProvinceRegion });
|
||||
}
|
||||
if (additionalFields.alternateEmails) {
|
||||
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 listIds = listIdValues.listIds as IDataObject[];
|
||||
Object.assign(contact, { list_ids: listIds });
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
|
||||
if (customFields) {
|
||||
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(contact, { custom_fields: data });
|
||||
}
|
||||
}
|
||||
contacts.push(contact);
|
||||
}
|
||||
contacts.push(contact);
|
||||
}
|
||||
responseData = await sendGridApiRequest.call(this, '/marketing/contacts', 'PUT', { contacts }, qs);
|
||||
responseData = await sendGridApiRequest.call(this, '/marketing/contacts', 'PUT', { contacts }, qs);
|
||||
|
||||
returnData.push(responseData);
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation === 'delete') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
const deleteAll = this.getNodeParameter('deleteAll', i) as boolean;
|
||||
if (deleteAll === true) {
|
||||
qs.delete_all_contacts = 'true';
|
||||
try {
|
||||
const deleteAll = this.getNodeParameter('deleteAll', i) as boolean;
|
||||
if (deleteAll === true) {
|
||||
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);
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
qs.ids = (this.getNodeParameter('ids', i) as string).replace(/\s/g, '');
|
||||
responseData = await sendGridApiRequest.call(this, `/marketing/contacts`, 'DELETE', {}, qs);
|
||||
returnData.push(responseData);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'list') {
|
||||
if (operation === 'getAll') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
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);
|
||||
try {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
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);
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
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);
|
||||
returnData.push(responseData);
|
||||
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);
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation === 'create') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
responseData = await sendGridApiRequest.call(this, '/marketing/lists', 'POST', { name }, qs);
|
||||
returnData.push(responseData);
|
||||
try {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
responseData = await sendGridApiRequest.call(this, '/marketing/lists', 'POST', { name }, qs);
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation === 'delete') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
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 = { success: true };
|
||||
returnData.push(responseData);
|
||||
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 = { success: true };
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation === 'update') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
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);
|
||||
returnData.push(responseData);
|
||||
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);
|
||||
returnData.push(responseData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'mail') {
|
||||
if (operation === 'send') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
const toEmail = this.getNodeParameter('toEmail', i) as string;
|
||||
|
||||
const toEmail = this.getNodeParameter('toEmail', i) as string;
|
||||
const parsedToEmail = toEmail.includes(',')
|
||||
? toEmail.split(',').map((i) => ({ email: i.trim() }))
|
||||
: [{ email: toEmail.trim() }];
|
||||
|
||||
const parsedToEmail = toEmail.includes(',')
|
||||
? toEmail.split(',').map((i) => ({ email: i.trim() }))
|
||||
: [{ email: toEmail.trim() }];
|
||||
|
||||
const {
|
||||
bccEmail,
|
||||
ccEmail,
|
||||
enableSandbox,
|
||||
sendAt,
|
||||
headers,
|
||||
attachments,
|
||||
categories,
|
||||
ipPoolName,
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
bccEmail: string;
|
||||
ccEmail: string;
|
||||
enableSandbox: boolean,
|
||||
sendAt: string;
|
||||
headers: { details: Array<{ key: string; value: string }> };
|
||||
attachments: string;
|
||||
categories: string;
|
||||
ipPoolName: string;
|
||||
};
|
||||
|
||||
const body: SendMailBody = {
|
||||
personalizations: [{
|
||||
to: parsedToEmail,
|
||||
}],
|
||||
from: {
|
||||
email: (this.getNodeParameter('fromEmail', i) as string).trim(),
|
||||
name: this.getNodeParameter('fromName', i) as string,
|
||||
},
|
||||
mail_settings: {
|
||||
sandbox_mode: {
|
||||
enable: enableSandbox || false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const dynamicTemplateEnabled = this.getNodeParameter('dynamicTemplate', i);
|
||||
|
||||
// dynamic template
|
||||
if (dynamicTemplateEnabled) {
|
||||
body.template_id = this.getNodeParameter('templateId', i) as string;
|
||||
|
||||
const { fields } = this.getNodeParameter('dynamicTemplateFields', i) as {
|
||||
fields: Array<{ [key: string]: string }>
|
||||
const {
|
||||
bccEmail,
|
||||
ccEmail,
|
||||
enableSandbox,
|
||||
sendAt,
|
||||
headers,
|
||||
attachments,
|
||||
categories,
|
||||
ipPoolName,
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
bccEmail: string;
|
||||
ccEmail: string;
|
||||
enableSandbox: boolean,
|
||||
sendAt: string;
|
||||
headers: { details: Array<{ key: string; value: string }> };
|
||||
attachments: string;
|
||||
categories: string;
|
||||
ipPoolName: string;
|
||||
};
|
||||
|
||||
if (fields) {
|
||||
body.personalizations[0].dynamic_template_data = {};
|
||||
fields.forEach(field => {
|
||||
body.personalizations[0].dynamic_template_data![field.key] = field.value;
|
||||
});
|
||||
}
|
||||
const body: SendMailBody = {
|
||||
personalizations: [{
|
||||
to: parsedToEmail,
|
||||
}],
|
||||
from: {
|
||||
email: (this.getNodeParameter('fromEmail', i) as string).trim(),
|
||||
name: this.getNodeParameter('fromName', i) as string,
|
||||
},
|
||||
mail_settings: {
|
||||
sandbox_mode: {
|
||||
enable: enableSandbox || false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 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,
|
||||
}];
|
||||
}
|
||||
const dynamicTemplateEnabled = this.getNodeParameter('dynamicTemplate', i);
|
||||
|
||||
if (attachments) {
|
||||
const attachmentsToSend = [];
|
||||
const binaryProperties = attachments.split(',').map((p) => p.trim());
|
||||
// dynamic template
|
||||
if (dynamicTemplateEnabled) {
|
||||
body.template_id = this.getNodeParameter('templateId', i) as string;
|
||||
|
||||
for (const property of binaryProperties) {
|
||||
if (!items[i].binary?.hasOwnProperty(property)) {
|
||||
throw new NodeOperationError(this.getNode(), `The binary property ${property} does not exist`);
|
||||
const { fields } = this.getNodeParameter('dynamicTemplateFields', i) as {
|
||||
fields: Array<{ [key: string]: string }>
|
||||
};
|
||||
|
||||
if (fields) {
|
||||
body.personalizations[0].dynamic_template_data = {};
|
||||
fields.forEach(field => {
|
||||
body.personalizations[0].dynamic_template_data![field.key] = field.value;
|
||||
});
|
||||
}
|
||||
|
||||
const binaryProperty = items[i].binary![property];
|
||||
|
||||
attachmentsToSend.push({
|
||||
content: binaryProperty.data,
|
||||
filename: binaryProperty.fileName || 'unknown',
|
||||
type: binaryProperty.mimeType,
|
||||
});
|
||||
// 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,
|
||||
}];
|
||||
}
|
||||
|
||||
if (attachmentsToSend.length) {
|
||||
body.attachments = attachmentsToSend;
|
||||
if (attachments) {
|
||||
const attachmentsToSend = [];
|
||||
const binaryProperties = attachments.split(',').map((p) => p.trim());
|
||||
|
||||
for (const property of binaryProperties) {
|
||||
if (!items[i].binary?.hasOwnProperty(property)) {
|
||||
throw new NodeOperationError(this.getNode(), `The binary property ${property} does not exist`);
|
||||
}
|
||||
|
||||
const binaryProperty = items[i].binary![property];
|
||||
|
||||
attachmentsToSend.push({
|
||||
content: binaryProperty.data,
|
||||
filename: binaryProperty.fileName || 'unknown',
|
||||
type: binaryProperty.mimeType,
|
||||
});
|
||||
}
|
||||
|
||||
if (attachmentsToSend.length) {
|
||||
body.attachments = attachmentsToSend;
|
||||
}
|
||||
}
|
||||
|
||||
if (bccEmail) {
|
||||
body.personalizations[0].bcc = bccEmail.split(',').map(i => ({ email: i.trim() }));
|
||||
}
|
||||
|
||||
if (ccEmail) {
|
||||
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']);
|
||||
body.headers = parsedHeaders;
|
||||
}
|
||||
|
||||
if (categories) {
|
||||
body.categories = categories.split(',') as string[];
|
||||
}
|
||||
|
||||
if (ipPoolName) {
|
||||
body.ip_pool_name = ipPoolName as string;
|
||||
}
|
||||
|
||||
if (sendAt) {
|
||||
body.personalizations[0].send_at = moment.tz(sendAt, timezone).unix();
|
||||
}
|
||||
|
||||
const data = await sendGridApiRequest.call(this, '/mail/send', 'POST', body, qs, { resolveWithFullResponse: true });
|
||||
|
||||
returnData.push({ messageId: data!.headers['x-message-id'] });
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (bccEmail) {
|
||||
body.personalizations[0].bcc = bccEmail.split(',').map(i => ({ email: i.trim() }));
|
||||
}
|
||||
|
||||
if (ccEmail) {
|
||||
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']);
|
||||
body.headers = parsedHeaders;
|
||||
}
|
||||
|
||||
if (categories) {
|
||||
body.categories = categories.split(',') as string[];
|
||||
}
|
||||
|
||||
if (ipPoolName) {
|
||||
body.ip_pool_name = ipPoolName as string;
|
||||
}
|
||||
|
||||
if (sendAt) {
|
||||
body.personalizations[0].send_at = moment.tz(sendAt, timezone).unix();
|
||||
}
|
||||
|
||||
const data = await sendGridApiRequest.call(this, '/mail/send', 'POST', body, qs, { resolveWithFullResponse: true });
|
||||
|
||||
returnData.push({ messageId: data!.headers['x-message-id'] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user