From d57ae97669b6bfa62f434a23f92e5109ca1997b3 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sat, 24 Apr 2021 13:34:59 -0400 Subject: [PATCH] :sparkles: Add Mailcheck Node (#1690) * Add Mailcheck integration * compress logo * Add mailcheck node info * :zap: Improvements Co-authored-by: bugagashenkj Co-authored-by: Nosov Konstantin --- .../credentials/MailcheckApi.credentials.ts | 18 +++ .../nodes/Mailcheck/GenericFunctions.ts | 47 ++++++++ .../nodes/Mailcheck/Mailcheck.node.json | 15 +++ .../nodes/Mailcheck/Mailcheck.node.ts | 112 ++++++++++++++++++ .../nodes-base/nodes/Mailcheck/mailcheck.svg | 1 + packages/nodes-base/package.json | 2 + 6 files changed, 195 insertions(+) create mode 100644 packages/nodes-base/credentials/MailcheckApi.credentials.ts create mode 100644 packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts create mode 100644 packages/nodes-base/nodes/Mailcheck/Mailcheck.node.json create mode 100644 packages/nodes-base/nodes/Mailcheck/Mailcheck.node.ts create mode 100644 packages/nodes-base/nodes/Mailcheck/mailcheck.svg diff --git a/packages/nodes-base/credentials/MailcheckApi.credentials.ts b/packages/nodes-base/credentials/MailcheckApi.credentials.ts new file mode 100644 index 0000000000..c84d857495 --- /dev/null +++ b/packages/nodes-base/credentials/MailcheckApi.credentials.ts @@ -0,0 +1,18 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + +export class MailcheckApi implements ICredentialType { + name = 'mailcheckApi'; + displayName = 'Mailcheck API'; + documentationUrl = 'mailcheck'; + properties = [ + { + displayName: 'API Key', + name: 'apiKey', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts b/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts new file mode 100644 index 0000000000..ba9ef974e1 --- /dev/null +++ b/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts @@ -0,0 +1,47 @@ +import { + OptionsWithUri, +} from 'request'; + +import { + IExecuteFunctions, + IHookFunctions, + ILoadOptionsFunctions, + IWebhookFunctions, +} from 'n8n-core'; + +import { + IDataObject +} from 'n8n-workflow'; + +export async function mailCheckApiRequest(this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any + const credentials = this.getCredentials('mailcheckApi') as IDataObject; + + let options: OptionsWithUri = { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${credentials.apiKey}`, + }, + method, + body, + qs, + uri: uri || `https://api.mailcheck.co/v1${resource}`, + json: true, + }; + try { + options = Object.assign({}, options, option); + if (Object.keys(headers).length !== 0) { + options.headers = Object.assign({}, options.headers, headers); + } + if (Object.keys(body).length === 0) { + delete options.body; + } + //@ts-ignore + return await this.helpers.request.call(this, options); + } catch (error) { + if (error.response && error.response.body && error.response.body.message) { + // Try to return the error prettier + throw new Error(`Mailcheck error response [${error.statusCode}]: ${error.response.body.message}`); + } + throw error; + } +} \ No newline at end of file diff --git a/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.json b/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.json new file mode 100644 index 0000000000..b205ef1b28 --- /dev/null +++ b/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.json @@ -0,0 +1,15 @@ +{ + "node": "n8n-nodes-base.mailcheck", + "nodeVersion": "1.0", + "codexVersion": "1.0", + "categories": [ + "Utility" + ], + "resources": { + "credentialDocumentation": [ + { + "url": "https://docs.n8n.io/credentials/mailcheck" + } + ] + } +} \ No newline at end of file diff --git a/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.ts b/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.ts new file mode 100644 index 0000000000..fc0e1ef6e5 --- /dev/null +++ b/packages/nodes-base/nodes/Mailcheck/Mailcheck.node.ts @@ -0,0 +1,112 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; + +import { + IDataObject, + INodeExecutionData, + INodeType, + INodeTypeDescription, +} from 'n8n-workflow'; + +import { + mailCheckApiRequest, +} from './GenericFunctions'; + +export class Mailcheck implements INodeType { + description: INodeTypeDescription = { + displayName: 'Mailcheck', + name: 'mailcheck', + icon: 'file:mailcheck.svg', + group: ['transform'], + version: 1, + subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', + description: 'Consume Mailcheck API', + defaults: { + name: 'Mailcheck', + color: '#4f44d7', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'mailcheckApi', + required: true, + }, + ], + properties: [ + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Email', + value: 'email', + }, + ], + default: 'email', + }, + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'email', + ], + }, + }, + options: [ + { + name: 'Check', + value: 'check', + }, + ], + default: 'check', + }, + { + displayName: 'Email', + name: 'email', + type: 'string', + displayOptions: { + show: { + resource: [ + 'email', + ], + operation: [ + 'check', + ], + }, + }, + default: '', + description: 'Email address to check.', + }, + ], + }; + + async execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + const returnData: IDataObject[] = []; + const length = items.length as unknown as number; + let responseData; + + const resource = this.getNodeParameter('resource', 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; + for (let i = 0; i < length; i++) { + if (resource === 'email') { + if (operation === 'check') { + const email = this.getNodeParameter('email', i) as string; + responseData = await mailCheckApiRequest.call(this, 'POST', '/singleEmail:check', { email }); + } + } + if (Array.isArray(responseData)) { + returnData.push.apply(returnData, responseData as IDataObject[]); + } else { + returnData.push(responseData as IDataObject); + } + } + return [this.helpers.returnJsonArray(returnData)]; + } +} \ No newline at end of file diff --git a/packages/nodes-base/nodes/Mailcheck/mailcheck.svg b/packages/nodes-base/nodes/Mailcheck/mailcheck.svg new file mode 100644 index 0000000000..9e9829db7e --- /dev/null +++ b/packages/nodes-base/nodes/Mailcheck/mailcheck.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 2483866586..c2dcda32b5 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -138,6 +138,7 @@ "dist/credentials/LingvaNexApi.credentials.js", "dist/credentials/LinkedInOAuth2Api.credentials.js", "dist/credentials/MailerLiteApi.credentials.js", + "dist/credentials/MailcheckApi.credentials.js", "dist/credentials/MailchimpApi.credentials.js", "dist/credentials/MailchimpOAuth2Api.credentials.js", "dist/credentials/MailgunApi.credentials.js", @@ -413,6 +414,7 @@ "dist/nodes/LinkedIn/LinkedIn.node.js", "dist/nodes/MailerLite/MailerLite.node.js", "dist/nodes/MailerLite/MailerLiteTrigger.node.js", + "dist/nodes/Mailcheck/Mailcheck.node.js", "dist/nodes/Mailchimp/Mailchimp.node.js", "dist/nodes/Mailchimp/MailchimpTrigger.node.js", "dist/nodes/Mailgun/Mailgun.node.js",