From 756d27e902ef4ad611878f823244675d87db673b Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 24 Jan 2020 17:01:11 -0800 Subject: [PATCH] :twisted_rightwards_arrows: Small improvements on Hunter-Node --- .../nodes/Hunter/GenericFunctions.ts | 2 +- .../nodes-base/nodes/Hunter/Hunter.node.ts | 65 +++++++++++++++---- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/packages/nodes-base/nodes/Hunter/GenericFunctions.ts b/packages/nodes-base/nodes/Hunter/GenericFunctions.ts index 02fafdd482..e566db93e8 100644 --- a/packages/nodes-base/nodes/Hunter/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hunter/GenericFunctions.ts @@ -45,7 +45,7 @@ export async function hunterApiRequestAllItems(this: IHookFunctions | IExecuteFu do { responseData = await hunterApiRequest.call(this, method, resource, body, query); - returnData.push.apply(returnData, responseData[propertyName]); + returnData.push(responseData[propertyName]); query.offset += query.limit; } while ( responseData.meta !== undefined && diff --git a/packages/nodes-base/nodes/Hunter/Hunter.node.ts b/packages/nodes-base/nodes/Hunter/Hunter.node.ts index b4df2e1595..c27da7a1d4 100644 --- a/packages/nodes-base/nodes/Hunter/Hunter.node.ts +++ b/packages/nodes-base/nodes/Hunter/Hunter.node.ts @@ -67,15 +67,26 @@ export class Hunter implements INodeType { operation: [ 'domainSearch', ], - returnAll: [ - false, - ], }, }, default: '', required: true, description: 'Domain name from which you want to find the email addresses. For example, "stripe.com".', }, + { + displayName: 'Only Emails', + name: 'onlyEmails', + type: 'boolean', + displayOptions: { + show: { + operation: [ + 'domainSearch', + ], + }, + }, + default: true, + description: 'Return only the the found emails.', + }, { displayName: 'Return All', name: 'returnAll', @@ -108,7 +119,7 @@ export class Hunter implements INodeType { minValue: 1, maxValue: 100, }, - default: 50, + default: 100, description: 'How many results to return.', }, { @@ -219,7 +230,7 @@ export class Hunter implements INodeType { displayOptions: { show: { operation: [ - 'emailFinder' + 'emailFinder', ], }, }, @@ -233,13 +244,13 @@ export class Hunter implements INodeType { displayOptions: { show: { operation: [ - 'emailFinder' + 'emailFinder', ], }, }, default: '', required: true, - description: `The person's first name. It doesn't need to be in lowercase..`, + description: `The person's first name. It doesn't need to be in lowercase.`, }, { displayName: 'Last Name', @@ -248,13 +259,13 @@ export class Hunter implements INodeType { displayOptions: { show: { operation: [ - 'emailFinder' + 'emailFinder', ], }, }, default: '', required: true, - description: `The person's last name. It doesn't need to be in lowercase..`, + description: `The person's last name. It doesn't need to be in lowercase.`, }, { displayName: 'Email', @@ -263,13 +274,13 @@ export class Hunter implements INodeType { displayOptions: { show: { operation: [ - 'emailVerifier' + 'emailVerifier', ], }, }, default: '', required: true, - description: 'The email address you want to verify', + description: 'The email address you want to verify.', }, ], }; @@ -287,6 +298,8 @@ export class Hunter implements INodeType { const returnAll = this.getNodeParameter('returnAll', i) as boolean; const filters = this.getNodeParameter('filters', i) as IDataObject; const domain = this.getNodeParameter('domain', i) as string; + const onlyEmails = this.getNodeParameter('onlyEmails', i, false) as boolean; + qs.domain = domain; if (filters.type){ qs.type = filters.type; @@ -299,12 +312,42 @@ export class Hunter implements INodeType { } if (returnAll) { responseData = await hunterApiRequestAllItems.call(this, 'data', 'GET', '/domain-search', {}, qs); + + // Make sure that the company information is there only once and + // the emails are combined underneath it. + if (onlyEmails === false) { + let tempReturnData: IDataObject = {}; + + for (let i = 0; i < responseData.length; i++) { + if (i === 0) { + tempReturnData = responseData[i]; + continue; + } + ((tempReturnData as IDataObject).emails as IDataObject[]).push.apply(tempReturnData.emails, responseData[i].emails); + } + + responseData = tempReturnData; + } } else { const limit = this.getNodeParameter('limit', i) as number; qs.limit = limit; responseData = await hunterApiRequest.call(this, 'GET', '/domain-search', {}, qs); responseData = responseData.data; } + + if (onlyEmails === true) { + let tempReturnData: IDataObject[] = []; + + if (Array.isArray(responseData)) { + for (const data of responseData) { + tempReturnData.push.apply(tempReturnData, data.emails); + } + } else { + tempReturnData = responseData.emails; + } + + responseData = tempReturnData; + } } //https://hunter.io/api-documentation/v2#email-finder if (operation === 'emailFinder') {