n8n/packages/nodes-base/nodes/SendInBlue/GenericFunctions.ts

390 lines
9.8 KiB
TypeScript
Raw Normal View History

feat(SendInBlue Node): Add SendInBlue Regular + Trigger Node (#3746) * add sendinblue svg icon * Add code and required files for new sendinblue node * Add node to package.json * Update credentials to display API Key instead of Access Token * Use new svg found in brandfetch * :zap: Improvements * :recycle: Moved descriptions for email to it's own file * :zap: Added support for contact get * :zap: moved email descriptions to it's own file * :zap: Add logic to conditionally remove/format sms,email * :zap: Improvements * :zap: Refactor Sender descriptions to it's own file * :zap: Fix urls * :zap: Improvements attempt * :zap: Refactor remove inline descriptions * :zap: Minor improvement * :art: Learn a nice way to send options as key-value * :zap: Improvements * :recycle: Fix Create Operation structure * :recycle: Refactor create functionality for attribute :recycle: Introduce override for createAttribute selectedCategory :recycle: Add delete functionality * :fire: Remove preSend from delete * :zap: Implement override for body types * :zap: Cleanup node file * :zap: Update response for contact update :zap: Update request url for contact delete * :zap: Add presend check for optional properties that are empty :zap: Add Model file and TransactionalEmail interface * :zap: formatting * :recycle: Remove requestOperations from Node Description level * :recycle: Cleanup routing for Get All :recycle: Make Identifier required * :zap: Formatting * :recycle: Add Options Collection * :recycle: Add Filters area * :recycle: Formatting * :recycle: Handle empty return * :recycle: Remove unused code * :recycle: Fix pagination :recycle: Fix empty return for delete * :zap: Add pagination * :zap: Fix Modified Since * :recycle: Reorder send operation ui * :zap: Remove no longer needed presend :zap: Add send html template operation * :recycle: Make Contact Attribute name and type required * :recycle: Rename Attribute to Contact Attribute * :recycle: Rename Identifier to Contact Identifier * :recycle: Remove SMS from root level because it can exist in Contact Attributes * :recycle: Fix Array type using 'Array<T>' :recycle: Fix double quotes should be single quotes * :tshirt: Lint Fix * :zap: Add email attachment functionality :zap: Add attachment data validation * :zap: Add dynamic loading of Email Template IDs * :recycle: Cleanup validation method * :zap: Introduce workaround and use binary data for attachments * feat: Migrated to npm release of riot-tmpl fork. * :tshirt: Lint fix rules * :shirt: Lint fix rules * fix: Updated imports to use @n8n_io/riot-tmpl * fix: Fixed Logger.ts types. * :zap: Fix mixmatch of filename and package.json credentials list * :zap: fix mixmatch in nodes list * feat(core): Give access to getBinaryDataBuffer in preSend method * :zap: clean up mixmatches in node naming * :recycle: Refactor code to use newly exposed getBinaryDataBuffer method * :zap: Improvements * :fire: Remove unnecessary lines * :shirt: Fix linting issues * :zap: Fix issues with up to date APIs and improve readability * :zap: update naming of files * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Add attribute name url encoding :recycle: Change limit's default to 50 * :zap: Fix default for templateId * :zap: Fix display name for attribute list * :recycle: Add clarity to attribute value display name * :recycle: Add tags and attachments for emails * :recycle: Add use of item's binary data fileName * :shirt: Fix action lint rule * :shirt: Remove deprecated lint rule * :arrow_up: Update eslint-plugin-n8n-nodes-base * :shirt: Fix lint rule for file name * :zap: Fix update attribute * :recycle: Add upsert capabilites * :fire: Remove create or update operation * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fixing existing linting issues * :rotating_light: Enable namespacing in tslint file * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :fire: Remove unused Model.ts file * :recycle: Update node to use SendInBlue namespace * :zap: Revert back to allowing upsert functionality * :recycle: Fix options to better describe events * Remove update flag for create operation * :recycle: Fix discrepancies for contact resource * remove no-namespace lint rule * :shirt: Fix linting issues * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :recycle: Fix options to better describe events * Add optionswithuri import that was lost * :zap: Fix details from janober's review * :zap: Fix order of displayName and name properties * :zap: Fix default value and improve loadOptions * :zap: Introduce support for comma separated attribute values * :zap: Introduce support for comma separated attribute values * :shirt: Fix linting issues * Update defaults and required props * :zap: Fix copy paste issue Upsert was not using correct endpoint * :zap: Fix upsert email field display name * :zap: Last update, upsert email description * :zap: Add PostReceived type limit Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2022-08-03 09:08:51 -07:00
import {
IExecuteSingleFunctions,
IHookFunctions,
IHttpRequestOptions,
IWebhookFunctions,
JsonObject,
jsonParse,
feat(SendInBlue Node): Add SendInBlue Regular + Trigger Node (#3746) * add sendinblue svg icon * Add code and required files for new sendinblue node * Add node to package.json * Update credentials to display API Key instead of Access Token * Use new svg found in brandfetch * :zap: Improvements * :recycle: Moved descriptions for email to it's own file * :zap: Added support for contact get * :zap: moved email descriptions to it's own file * :zap: Add logic to conditionally remove/format sms,email * :zap: Improvements * :zap: Refactor Sender descriptions to it's own file * :zap: Fix urls * :zap: Improvements attempt * :zap: Refactor remove inline descriptions * :zap: Minor improvement * :art: Learn a nice way to send options as key-value * :zap: Improvements * :recycle: Fix Create Operation structure * :recycle: Refactor create functionality for attribute :recycle: Introduce override for createAttribute selectedCategory :recycle: Add delete functionality * :fire: Remove preSend from delete * :zap: Implement override for body types * :zap: Cleanup node file * :zap: Update response for contact update :zap: Update request url for contact delete * :zap: Add presend check for optional properties that are empty :zap: Add Model file and TransactionalEmail interface * :zap: formatting * :recycle: Remove requestOperations from Node Description level * :recycle: Cleanup routing for Get All :recycle: Make Identifier required * :zap: Formatting * :recycle: Add Options Collection * :recycle: Add Filters area * :recycle: Formatting * :recycle: Handle empty return * :recycle: Remove unused code * :recycle: Fix pagination :recycle: Fix empty return for delete * :zap: Add pagination * :zap: Fix Modified Since * :recycle: Reorder send operation ui * :zap: Remove no longer needed presend :zap: Add send html template operation * :recycle: Make Contact Attribute name and type required * :recycle: Rename Attribute to Contact Attribute * :recycle: Rename Identifier to Contact Identifier * :recycle: Remove SMS from root level because it can exist in Contact Attributes * :recycle: Fix Array type using 'Array<T>' :recycle: Fix double quotes should be single quotes * :tshirt: Lint Fix * :zap: Add email attachment functionality :zap: Add attachment data validation * :zap: Add dynamic loading of Email Template IDs * :recycle: Cleanup validation method * :zap: Introduce workaround and use binary data for attachments * feat: Migrated to npm release of riot-tmpl fork. * :tshirt: Lint fix rules * :shirt: Lint fix rules * fix: Updated imports to use @n8n_io/riot-tmpl * fix: Fixed Logger.ts types. * :zap: Fix mixmatch of filename and package.json credentials list * :zap: fix mixmatch in nodes list * feat(core): Give access to getBinaryDataBuffer in preSend method * :zap: clean up mixmatches in node naming * :recycle: Refactor code to use newly exposed getBinaryDataBuffer method * :zap: Improvements * :fire: Remove unnecessary lines * :shirt: Fix linting issues * :zap: Fix issues with up to date APIs and improve readability * :zap: update naming of files * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Add attribute name url encoding :recycle: Change limit's default to 50 * :zap: Fix default for templateId * :zap: Fix display name for attribute list * :recycle: Add clarity to attribute value display name * :recycle: Add tags and attachments for emails * :recycle: Add use of item's binary data fileName * :shirt: Fix action lint rule * :shirt: Remove deprecated lint rule * :arrow_up: Update eslint-plugin-n8n-nodes-base * :shirt: Fix lint rule for file name * :zap: Fix update attribute * :recycle: Add upsert capabilites * :fire: Remove create or update operation * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fixing existing linting issues * :rotating_light: Enable namespacing in tslint file * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :fire: Remove unused Model.ts file * :recycle: Update node to use SendInBlue namespace * :zap: Revert back to allowing upsert functionality * :recycle: Fix options to better describe events * Remove update flag for create operation * :recycle: Fix discrepancies for contact resource * remove no-namespace lint rule * :shirt: Fix linting issues * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :recycle: Fix options to better describe events * Add optionswithuri import that was lost * :zap: Fix details from janober's review * :zap: Fix order of displayName and name properties * :zap: Fix default value and improve loadOptions * :zap: Introduce support for comma separated attribute values * :zap: Introduce support for comma separated attribute values * :shirt: Fix linting issues * Update defaults and required props * :zap: Fix copy paste issue Upsert was not using correct endpoint * :zap: Fix upsert email field display name * :zap: Last update, upsert email description * :zap: Add PostReceived type limit Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2022-08-03 09:08:51 -07:00
NodeOperationError,
} from 'n8n-workflow';
import { OptionsWithUri } from 'request';
import MailComposer from 'nodemailer/lib/mail-composer';
export namespace SendInBlueNode {
type ValidEmailFields = { to: string } | { sender: string } | { cc: string } | { bcc: string };
type Address = { address: string; name?: string };
type Email = { email: string; name?: string };
type ToEmail = { to: Email[] };
type SenderEmail = { sender: Email };
type CCEmail = { cc: Email[] };
type BBCEmail = { bbc: Email[] };
type ValidatedEmail = ToEmail | SenderEmail | CCEmail | BBCEmail;
enum OVERRIDE_MAP_VALUES {
'CATEGORY' = 'category',
'NORMAL' = 'boolean',
'TRANSACTIONAL' = 'id',
}
enum OVERRIDE_MAP_TYPE {
'CATEGORY' = 'category',
'NORMAL' = 'normal',
'TRANSACTIONAL' = 'transactional',
}
export const INTERCEPTORS = new Map<string, (body: JsonObject) => void>([
[
OVERRIDE_MAP_TYPE.CATEGORY,
(body: JsonObject) => {
body!.type = OVERRIDE_MAP_VALUES.CATEGORY;
},
],
[
OVERRIDE_MAP_TYPE.NORMAL,
(body: JsonObject) => {
body!.type = OVERRIDE_MAP_VALUES.NORMAL;
},
],
[
OVERRIDE_MAP_TYPE.TRANSACTIONAL,
(body: JsonObject) => {
body!.type = OVERRIDE_MAP_VALUES.TRANSACTIONAL;
},
],
]);
export namespace Validators {
export async function validateAndCompileAttachmentsData(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const dataPropertyList = this.getNodeParameter(
'additionalFields.emailAttachments.attachment',
) as JsonObject;
const { body } = requestOptions;
const { attachment = [] } = body as { attachment: Array<{ content: string; name: string }> };
try {
const { binaryPropertyName } = dataPropertyList;
const dataMappingList = (binaryPropertyName as string).split(',');
for (const attachmentDataName of dataMappingList) {
const binaryPropertyName = attachmentDataName;
const item = this.getInputData();
if (item.binary![binaryPropertyName as string] === undefined) {
throw new NodeOperationError(
this.getNode(),
`No binary data property “${binaryPropertyName}” exists on item!`,
);
}
const bufferFromIncomingData = (await this.helpers.getBinaryDataBuffer(
binaryPropertyName,
)) as Buffer;
const {
data: content,
mimeType,
fileName,
fileExtension,
} = await this.helpers.prepareBinaryData(bufferFromIncomingData);
const itemIndex = this.getItemIndex();
const name = getFileName(
itemIndex,
mimeType,
fileExtension,
fileName || item.binary!.data.fileName,
);
attachment.push({ content, name });
}
Object.assign(body!, { attachment });
return requestOptions;
} catch (err) {
throw new NodeOperationError(this.getNode(), `${err}`);
}
}
export async function validateAndCompileTags(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const { tag } = this.getNodeParameter('additionalFields.emailTags.tags') as JsonObject;
const tags = (tag as string)
.split(',')
.map((tag) => tag.trim())
.filter((tag) => {
return tag !== '';
});
const { body } = requestOptions;
Object.assign(body!, { tags });
return requestOptions;
}
export async function validateAndCompileCCEmails(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const ccData = this.getNodeParameter(
'additionalFields.receipientsCC.receipientCc',
) as JsonObject;
const { cc } = ccData;
const { body } = requestOptions;
const data = validateEmailStrings({ cc: cc as string });
Object.assign(body!, data);
return requestOptions;
}
export async function validateAndCompileBCCEmails(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const bccData = this.getNodeParameter(
'additionalFields.receipientsBCC.receipientBcc',
) as JsonObject;
const { bcc } = bccData;
const { body } = requestOptions;
const data = validateEmailStrings({ bcc: bcc as string });
Object.assign(body!, data);
return requestOptions;
}
export async function validateAndCompileReceipientEmails(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const to = this.getNodeParameter('receipients') as string;
const { body } = requestOptions;
const data = validateEmailStrings({ to });
Object.assign(body!, data);
return requestOptions;
}
export async function validateAndCompileSenderEmail(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const sender = this.getNodeParameter('sender') as string;
const { body } = requestOptions;
const data = validateEmailStrings({ sender });
Object.assign(body!, data);
return requestOptions;
}
export async function validateAndCompileTemplateParameters(
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const parameterData = this.getNodeParameter(
'additionalFields.templateParameters.parameterValues',
);
const { body } = requestOptions;
const { parmeters } = parameterData as JsonObject;
const params = (parmeters as string)
.split(',')
.filter((parameter) => {
return parameter.split('=').length === 2;
})
.map((parameter) => {
const [key, value] = parameter.split('=');
return {
[key]: value,
};
})
.reduce((obj, cObj) => {
Object.assign(obj, cObj);
return obj;
}, {});
Object.assign(body!, { params });
return requestOptions;
}
function validateEmailStrings(input: ValidEmailFields): ValidatedEmail {
const composer = new MailComposer({ ...input });
const addressFields = composer.compile().getAddresses();
const fieldFetcher = new Map<string, () => Email[] | Email>([
[
'bcc',
() => {
return (addressFields.bcc as unknown as Address[])?.map(formatToEmailName);
},
],
[
'cc',
() => {
return (addressFields.cc as unknown as Address[])?.map(formatToEmailName);
},
],
[
'from',
() => {
return (addressFields.from as unknown as Address[])?.map(formatToEmailName);
},
],
[
'reply-to',
() => {
return (addressFields['reply-to'] as unknown as Address[])?.map(formatToEmailName);
},
],
[
'sender',
() => {
return (addressFields.sender as unknown as Address[])?.map(formatToEmailName)[0];
},
],
[
'to',
() => {
return (addressFields.to as unknown as Address[])?.map(formatToEmailName);
},
],
]);
const result: { [key in keyof ValidatedEmail]: Email[] | Email } = {} as ValidatedEmail;
Object.keys(input).reduce((obj: { [key: string]: Email[] | Email }, key: string) => {
const getter = fieldFetcher.get(key);
const value = getter!();
obj[key] = value;
return obj;
}, result);
return result as ValidatedEmail;
}
}
function getFileName(
itemIndex: number,
mimeType: string,
fileExt: string,
fileName: string,
): string {
let ext = fileExt;
if (fileExt === undefined) {
ext = mimeType.split('/')[1];
}
let name = `${fileName}.${ext}`;
if (fileName === undefined) {
name = `file-${itemIndex}.${ext}`;
}
return name;
}
function formatToEmailName(data: Address): Email {
const { address: email, name } = data;
const result = { email };
if (name !== undefined && name !== '') {
Object.assign(result, { name });
}
return { ...result };
}
}
export namespace SendInBlueWebhookApi {
interface WebhookDetails {
url: string;
id: number;
description: string;
events: string[];
type: string;
createdAt: string;
modifiedAt: string;
}
interface WebhookId {
id: string;
}
interface Webhooks {
webhooks: WebhookDetails[];
}
const credentialsName = 'sendinblueApi';
const baseURL = 'https://api.sendinblue.com/v3';
export const supportedAuthMap = new Map<string, (ref: IWebhookFunctions) => Promise<string>>([
[
'apiKey',
async (ref: IWebhookFunctions): Promise<string> => {
const credentials = await ref.getCredentials(credentialsName);
return credentials.sharedSecret as string;
},
],
]);
export const fetchWebhooks = async (ref: IHookFunctions, type: string): Promise<Webhooks> => {
const endpoint = `${baseURL}/webhooks?type=${type}`;
const options: OptionsWithUri = {
method: 'GET',
headers: {
Accept: 'application/json',
},
uri: endpoint,
};
const webhooks = (await ref.helpers.requestWithAuthentication.call(
ref,
credentialsName,
options,
)) as string;
return jsonParse(webhooks) as Webhooks;
feat(SendInBlue Node): Add SendInBlue Regular + Trigger Node (#3746) * add sendinblue svg icon * Add code and required files for new sendinblue node * Add node to package.json * Update credentials to display API Key instead of Access Token * Use new svg found in brandfetch * :zap: Improvements * :recycle: Moved descriptions for email to it's own file * :zap: Added support for contact get * :zap: moved email descriptions to it's own file * :zap: Add logic to conditionally remove/format sms,email * :zap: Improvements * :zap: Refactor Sender descriptions to it's own file * :zap: Fix urls * :zap: Improvements attempt * :zap: Refactor remove inline descriptions * :zap: Minor improvement * :art: Learn a nice way to send options as key-value * :zap: Improvements * :recycle: Fix Create Operation structure * :recycle: Refactor create functionality for attribute :recycle: Introduce override for createAttribute selectedCategory :recycle: Add delete functionality * :fire: Remove preSend from delete * :zap: Implement override for body types * :zap: Cleanup node file * :zap: Update response for contact update :zap: Update request url for contact delete * :zap: Add presend check for optional properties that are empty :zap: Add Model file and TransactionalEmail interface * :zap: formatting * :recycle: Remove requestOperations from Node Description level * :recycle: Cleanup routing for Get All :recycle: Make Identifier required * :zap: Formatting * :recycle: Add Options Collection * :recycle: Add Filters area * :recycle: Formatting * :recycle: Handle empty return * :recycle: Remove unused code * :recycle: Fix pagination :recycle: Fix empty return for delete * :zap: Add pagination * :zap: Fix Modified Since * :recycle: Reorder send operation ui * :zap: Remove no longer needed presend :zap: Add send html template operation * :recycle: Make Contact Attribute name and type required * :recycle: Rename Attribute to Contact Attribute * :recycle: Rename Identifier to Contact Identifier * :recycle: Remove SMS from root level because it can exist in Contact Attributes * :recycle: Fix Array type using 'Array<T>' :recycle: Fix double quotes should be single quotes * :tshirt: Lint Fix * :zap: Add email attachment functionality :zap: Add attachment data validation * :zap: Add dynamic loading of Email Template IDs * :recycle: Cleanup validation method * :zap: Introduce workaround and use binary data for attachments * feat: Migrated to npm release of riot-tmpl fork. * :tshirt: Lint fix rules * :shirt: Lint fix rules * fix: Updated imports to use @n8n_io/riot-tmpl * fix: Fixed Logger.ts types. * :zap: Fix mixmatch of filename and package.json credentials list * :zap: fix mixmatch in nodes list * feat(core): Give access to getBinaryDataBuffer in preSend method * :zap: clean up mixmatches in node naming * :recycle: Refactor code to use newly exposed getBinaryDataBuffer method * :zap: Improvements * :fire: Remove unnecessary lines * :shirt: Fix linting issues * :zap: Fix issues with up to date APIs and improve readability * :zap: update naming of files * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Add attribute name url encoding :recycle: Change limit's default to 50 * :zap: Fix default for templateId * :zap: Fix display name for attribute list * :recycle: Add clarity to attribute value display name * :recycle: Add tags and attachments for emails * :recycle: Add use of item's binary data fileName * :shirt: Fix action lint rule * :shirt: Remove deprecated lint rule * :arrow_up: Update eslint-plugin-n8n-nodes-base * :shirt: Fix lint rule for file name * :zap: Fix update attribute * :recycle: Add upsert capabilites * :fire: Remove create or update operation * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fixing existing linting issues * :rotating_light: Enable namespacing in tslint file * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :fire: Remove unused Model.ts file * :recycle: Update node to use SendInBlue namespace * :zap: Revert back to allowing upsert functionality * :recycle: Fix options to better describe events * Remove update flag for create operation * :recycle: Fix discrepancies for contact resource * remove no-namespace lint rule * :shirt: Fix linting issues * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :recycle: Fix options to better describe events * Add optionswithuri import that was lost * :zap: Fix details from janober's review * :zap: Fix order of displayName and name properties * :zap: Fix default value and improve loadOptions * :zap: Introduce support for comma separated attribute values * :zap: Introduce support for comma separated attribute values * :shirt: Fix linting issues * Update defaults and required props * :zap: Fix copy paste issue Upsert was not using correct endpoint * :zap: Fix upsert email field display name * :zap: Last update, upsert email description * :zap: Add PostReceived type limit Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2022-08-03 09:08:51 -07:00
};
export const createWebHook = async (
ref: IHookFunctions,
type: string,
events: string[],
url: string,
): Promise<WebhookId> => {
const endpoint = `${baseURL}/webhooks`;
const options: OptionsWithUri = {
method: 'POST',
headers: {
Accept: 'application/json',
},
uri: endpoint,
body: {
events,
type,
url,
},
};
const webhookId = await ref.helpers.requestWithAuthentication.call(
ref,
credentialsName,
options,
);
return jsonParse(webhookId) as WebhookId;
feat(SendInBlue Node): Add SendInBlue Regular + Trigger Node (#3746) * add sendinblue svg icon * Add code and required files for new sendinblue node * Add node to package.json * Update credentials to display API Key instead of Access Token * Use new svg found in brandfetch * :zap: Improvements * :recycle: Moved descriptions for email to it's own file * :zap: Added support for contact get * :zap: moved email descriptions to it's own file * :zap: Add logic to conditionally remove/format sms,email * :zap: Improvements * :zap: Refactor Sender descriptions to it's own file * :zap: Fix urls * :zap: Improvements attempt * :zap: Refactor remove inline descriptions * :zap: Minor improvement * :art: Learn a nice way to send options as key-value * :zap: Improvements * :recycle: Fix Create Operation structure * :recycle: Refactor create functionality for attribute :recycle: Introduce override for createAttribute selectedCategory :recycle: Add delete functionality * :fire: Remove preSend from delete * :zap: Implement override for body types * :zap: Cleanup node file * :zap: Update response for contact update :zap: Update request url for contact delete * :zap: Add presend check for optional properties that are empty :zap: Add Model file and TransactionalEmail interface * :zap: formatting * :recycle: Remove requestOperations from Node Description level * :recycle: Cleanup routing for Get All :recycle: Make Identifier required * :zap: Formatting * :recycle: Add Options Collection * :recycle: Add Filters area * :recycle: Formatting * :recycle: Handle empty return * :recycle: Remove unused code * :recycle: Fix pagination :recycle: Fix empty return for delete * :zap: Add pagination * :zap: Fix Modified Since * :recycle: Reorder send operation ui * :zap: Remove no longer needed presend :zap: Add send html template operation * :recycle: Make Contact Attribute name and type required * :recycle: Rename Attribute to Contact Attribute * :recycle: Rename Identifier to Contact Identifier * :recycle: Remove SMS from root level because it can exist in Contact Attributes * :recycle: Fix Array type using 'Array<T>' :recycle: Fix double quotes should be single quotes * :tshirt: Lint Fix * :zap: Add email attachment functionality :zap: Add attachment data validation * :zap: Add dynamic loading of Email Template IDs * :recycle: Cleanup validation method * :zap: Introduce workaround and use binary data for attachments * feat: Migrated to npm release of riot-tmpl fork. * :tshirt: Lint fix rules * :shirt: Lint fix rules * fix: Updated imports to use @n8n_io/riot-tmpl * fix: Fixed Logger.ts types. * :zap: Fix mixmatch of filename and package.json credentials list * :zap: fix mixmatch in nodes list * feat(core): Give access to getBinaryDataBuffer in preSend method * :zap: clean up mixmatches in node naming * :recycle: Refactor code to use newly exposed getBinaryDataBuffer method * :zap: Improvements * :fire: Remove unnecessary lines * :shirt: Fix linting issues * :zap: Fix issues with up to date APIs and improve readability * :zap: update naming of files * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Move sendHtml boolean above subject :recycle: Update naming from Parameters to Fields * :recycle: Add attribute name url encoding :recycle: Change limit's default to 50 * :zap: Fix default for templateId * :zap: Fix display name for attribute list * :recycle: Add clarity to attribute value display name * :recycle: Add tags and attachments for emails * :recycle: Add use of item's binary data fileName * :shirt: Fix action lint rule * :shirt: Remove deprecated lint rule * :arrow_up: Update eslint-plugin-n8n-nodes-base * :shirt: Fix lint rule for file name * :zap: Fix update attribute * :recycle: Add upsert capabilites * :fire: Remove create or update operation * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fixing existing linting issues * :rotating_light: Enable namespacing in tslint file * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :fire: Remove unused Model.ts file * :recycle: Update node to use SendInBlue namespace * :zap: Revert back to allowing upsert functionality * :recycle: Fix options to better describe events * Remove update flag for create operation * :recycle: Fix discrepancies for contact resource * remove no-namespace lint rule * :shirt: Fix linting issues * :recycle: Add sendInBlueWebhookApi namespace * :recycle: Add Webhook API functionality * :zap: Add SendInBlue Trigger * :zap: Return correct webhookId data * :zap: Add placeholder for receiving data * :shirt: Fix linting issues * :zap: Rename exported WebhookApi * :recycle: Fix options to better describe events * Add optionswithuri import that was lost * :zap: Fix details from janober's review * :zap: Fix order of displayName and name properties * :zap: Fix default value and improve loadOptions * :zap: Introduce support for comma separated attribute values * :zap: Introduce support for comma separated attribute values * :shirt: Fix linting issues * Update defaults and required props * :zap: Fix copy paste issue Upsert was not using correct endpoint * :zap: Fix upsert email field display name * :zap: Last update, upsert email description * :zap: Add PostReceived type limit Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2022-08-03 09:08:51 -07:00
};
export const deleteWebhook = async (ref: IHookFunctions, webhookId: string) => {
const endpoint = `${baseURL}/webhooks/${webhookId}`;
const body = {};
const options: OptionsWithUri = {
method: 'DELETE',
headers: {
Accept: 'application/json',
},
uri: endpoint,
body,
};
return await ref.helpers.requestWithAuthentication.call(ref, credentialsName, options);
};
}