2023-01-27 03:22:44 -08:00
|
|
|
import type { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import type {
|
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { hunterApiRequest, hunterApiRequestAllItems } from './GenericFunctions';
|
2020-01-24 13:16:54 -08:00
|
|
|
|
|
|
|
export class Hunter implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Hunter',
|
|
|
|
name: 'hunter',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-01-24 13:16:54 -08:00
|
|
|
icon: 'file:hunter.png',
|
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"]}}',
|
|
|
|
description: 'Consume Hunter API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Hunter',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'hunterApi',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-01-24 13:16:54 -08:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-01-24 13:16:54 -08:00
|
|
|
options: [
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
name: 'Domain Search',
|
2020-01-24 13:16:54 -08:00
|
|
|
value: 'domainSearch',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Get every email address found on the internet using a given domain name, with sources',
|
|
|
|
action:
|
|
|
|
'Get every email address found on the internet using a given domain name, with sources',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
name: 'Email Finder',
|
2020-01-24 13:16:54 -08:00
|
|
|
value: 'emailFinder',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Generate or retrieve the most likely email address from a domain name, a first name and a last name',
|
|
|
|
action:
|
|
|
|
'Generate or retrieve the most likely email address from a domain name, a first name and a last name',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Email Verifier',
|
|
|
|
value: 'emailVerifier',
|
2020-07-24 03:56:41 -07:00
|
|
|
description: 'Verify the deliverability of an email address',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Verify the deliverability of an email address',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'domainSearch',
|
2022-06-03 10:23:49 -07:00
|
|
|
description: 'Operation to consume',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Domain',
|
|
|
|
name: 'domain',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['domainSearch'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Domain name from which you want to find the email addresses. For example, "stripe.com".',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
2020-01-24 17:01:11 -08:00
|
|
|
{
|
|
|
|
displayName: 'Only Emails',
|
|
|
|
name: 'onlyEmails',
|
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['domainSearch'],
|
2020-01-24 17:01:11 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: true,
|
2022-06-20 07:54:01 -07:00
|
|
|
description: 'Whether to return only the the found emails',
|
2020-01-24 17:01:11 -08:00
|
|
|
},
|
2020-01-24 13:16:54 -08:00
|
|
|
{
|
|
|
|
displayName: 'Return All',
|
|
|
|
name: 'returnAll',
|
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['domainSearch'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: false,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Whether to return all results or only up to a given limit',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Limit',
|
|
|
|
name: 'limit',
|
|
|
|
type: 'number',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['domainSearch'],
|
|
|
|
returnAll: [false],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
typeOptions: {
|
|
|
|
minValue: 1,
|
|
|
|
maxValue: 100,
|
|
|
|
},
|
2020-01-24 17:01:11 -08:00
|
|
|
default: 100,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Max number of results to return',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Filters',
|
|
|
|
name: 'filters',
|
|
|
|
type: 'collection',
|
|
|
|
placeholder: 'Add Filter',
|
|
|
|
default: {},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['domainSearch'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Type',
|
|
|
|
name: 'type',
|
|
|
|
type: 'options',
|
|
|
|
default: '',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Personal',
|
|
|
|
value: 'personal',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Generic',
|
|
|
|
value: 'generic',
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Seniority',
|
|
|
|
name: 'seniority',
|
|
|
|
type: 'multiOptions',
|
|
|
|
default: [],
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Junior',
|
|
|
|
value: 'junior',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Senior',
|
|
|
|
value: 'senior',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Executive',
|
|
|
|
value: 'executive',
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Department',
|
|
|
|
name: 'department',
|
|
|
|
type: 'multiOptions',
|
|
|
|
default: [],
|
|
|
|
options: [
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Communication',
|
|
|
|
value: 'communication',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Executive',
|
|
|
|
value: 'executive',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Finance',
|
|
|
|
value: 'finance',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'HR',
|
|
|
|
value: 'hr',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'IT',
|
|
|
|
value: 'it',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Legal',
|
|
|
|
value: 'legal',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Management',
|
|
|
|
value: 'management',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Marketing',
|
|
|
|
value: 'marketing',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Sales',
|
|
|
|
value: 'sales',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Support',
|
|
|
|
value: 'support',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Domain',
|
|
|
|
name: 'domain',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['emailFinder'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
required: true,
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Domain name from which you want to find the email addresses. For example, "stripe.com".',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'First Name',
|
|
|
|
name: 'firstname',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['emailFinder'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-08-17 08:50:24 -07:00
|
|
|
description: "The person's first name. It doesn't need to be in lowercase.",
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Last Name',
|
|
|
|
name: 'lastname',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['emailFinder'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-08-17 08:50:24 -07:00
|
|
|
description: "The person's last name. It doesn't need to be in lowercase.",
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Email',
|
|
|
|
name: 'email',
|
|
|
|
type: 'string',
|
2022-06-20 07:54:01 -07:00
|
|
|
placeholder: 'name@email.com',
|
2020-01-24 13:16:54 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['emailVerifier'],
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The email address you want to verify',
|
2020-01-24 13:16:54 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-01-24 13:16:54 -08:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://hunter.io/api-documentation/v2#domain-search
|
|
|
|
if (operation === 'domainSearch') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const domain = this.getNodeParameter('domain', i) as string;
|
|
|
|
const onlyEmails = this.getNodeParameter('onlyEmails', i, false) as boolean;
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.domain = domain;
|
2022-08-17 08:50:24 -07:00
|
|
|
if (filters.type) {
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.type = filters.type;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
if (filters.seniority) {
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.seniority = (filters.seniority as string[]).join(',');
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
if (filters.department) {
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.department = (filters.department as string[]).join(',');
|
|
|
|
}
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await hunterApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
'/domain-search',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Make sure that the company information is there only once and
|
|
|
|
// the emails are combined underneath it.
|
2022-12-02 12:54:28 -08:00
|
|
|
if (!onlyEmails) {
|
2021-07-19 23:58:54 -07:00
|
|
|
let tempReturnData: IDataObject = {};
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
for (let index = 0; index < responseData.length; index++) {
|
|
|
|
if (index === 0) {
|
|
|
|
tempReturnData = responseData[index];
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
(tempReturnData.emails as IDataObject[]).push.apply(
|
2022-08-17 08:50:24 -07:00
|
|
|
tempReturnData.emails,
|
2022-12-02 12:54:28 -08:00
|
|
|
responseData[index].emails,
|
2022-08-17 08:50:24 -07:00
|
|
|
);
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = tempReturnData;
|
|
|
|
}
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.limit = limit;
|
|
|
|
responseData = await hunterApiRequest.call(this, 'GET', '/domain-search', {}, qs);
|
|
|
|
responseData = responseData.data;
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
if (onlyEmails) {
|
2021-07-19 23:58:54 -07:00
|
|
|
let tempReturnData: IDataObject[] = [];
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (Array.isArray(responseData)) {
|
|
|
|
for (const data of responseData) {
|
|
|
|
tempReturnData.push.apply(tempReturnData, data.emails);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tempReturnData = responseData.emails;
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = tempReturnData;
|
|
|
|
}
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://hunter.io/api-documentation/v2#email-finder
|
|
|
|
if (operation === 'emailFinder') {
|
|
|
|
const domain = this.getNodeParameter('domain', i) as string;
|
|
|
|
const firstname = this.getNodeParameter('firstname', i) as string;
|
|
|
|
const lastname = this.getNodeParameter('lastname', i) as string;
|
|
|
|
qs.first_name = firstname;
|
|
|
|
qs.last_name = lastname;
|
|
|
|
qs.domain = domain;
|
|
|
|
responseData = await hunterApiRequest.call(this, 'GET', '/email-finder', {}, qs);
|
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
//https://hunter.io/api-documentation/v2#email-verifier
|
|
|
|
if (operation === 'emailVerifier') {
|
|
|
|
const email = this.getNodeParameter('email', i) as string;
|
|
|
|
qs.email = email;
|
|
|
|
responseData = await hunterApiRequest.call(this, 'GET', '/email-verifier', {}, qs);
|
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-01-24 13:16:54 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
return this.prepareOutputData(returnData);
|
2020-01-24 13:16:54 -08:00
|
|
|
}
|
|
|
|
}
|