UNPKG

n8n-nodes-emailverify

Version:

n8n node to verify emails using EmailVerify.io

141 lines (140 loc) 5.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmailVerify = void 0; const GenericFunctions_1 = require("./GenericFunctions"); class EmailVerify { description = { displayName: 'EmailVerify.io', name: 'emailVerify', icon: 'file:emailverify.svg', group: ['output'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Consume EmailVerify.io API', defaults: { name: 'EmailVerify.io', }, usableAsTool: true, inputs: [{ type: "main" /* NodeConnectionType.Main */ }], outputs: [{ type: "main" /* NodeConnectionType.Main */ }], credentials: [ { name: 'emailVerifyApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Verify Email', value: 'verifyEmail', description: 'Verify the validity of an email address', action: 'Verify the validity of an email address', }, { name: 'Find Email', value: 'findEmail', description: 'Find an email address using a name and domain', action: 'Find an email address using a name and domain', }, { name: 'Check Account Balance', value: 'checkBalance', description: 'Check your account balance and remaining credits', action: 'Check your account balance and remaining credits', }, ], default: 'verifyEmail', }, { displayName: 'Email', name: 'email', type: 'string', placeholder: 'name@email.com', displayOptions: { show: { operation: ['verifyEmail'], }, }, default: '', required: true, description: 'The email address you want to verify', }, { displayName: 'Name', name: 'name', type: 'string', placeholder: 'John', displayOptions: { show: { operation: ['findEmail'], }, }, default: '', required: true, description: 'The name of the person you want to find the email for', }, { displayName: 'Domain', name: 'domain', type: 'string', placeholder: 'example.com', displayOptions: { show: { operation: ['findEmail'], }, }, default: '', required: true, description: 'The domain of the company or website', }, ], }; async execute() { const items = this.getInputData(); const returnData = []; const length = items.length; let responseData; for (let i = 0; i < length; i++) { try { const operation = this.getNodeParameter('operation', i); if (operation === 'verifyEmail') { const email = this.getNodeParameter('email', i); const qs = { email, }; responseData = await GenericFunctions_1.emailVerifyIoApiRequest.call(this, 'GET', '/validate', {}, qs); } if (operation === 'findEmail') { const name = this.getNodeParameter('name', i); const domain = this.getNodeParameter('domain', i); const qs = { name, domain, }; responseData = await GenericFunctions_1.emailVerifyIoApiRequest.call(this, 'GET', '/finder', {}, qs); } if (operation === 'checkBalance') { responseData = await GenericFunctions_1.emailVerifyIoApiRequest.call(this, 'GET', '/check-account-balance/', {}); } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }); returnData.push(...executionErrorData); continue; } throw error; } } return [returnData]; } } exports.EmailVerify = EmailVerify;