2020-01-24 13:16:54 -08:00
|
|
|
import {
|
|
|
|
IExecuteFunctions,
|
|
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeTypeDescription,
|
2020-01-24 13:16:54 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
|
|
hunterApiRequest,
|
|
|
|
hunterApiRequestAllItems,
|
|
|
|
} from './GenericFunctions';
|
|
|
|
|
|
|
|
export class Hunter implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Hunter',
|
|
|
|
name: 'hunter',
|
|
|
|
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',
|
2020-07-24 03:56:41 -07:00
|
|
|
description: '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',
|
2020-07-24 03:56:41 -07:00
|
|
|
description: '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',
|
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: {
|
|
|
|
operation: [
|
|
|
|
'domainSearch',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
description: 'Domain name from which you want to find the email addresses. For example, "stripe.com".',
|
|
|
|
},
|
2020-01-24 17:01:11 -08:00
|
|
|
{
|
|
|
|
displayName: 'Only Emails',
|
|
|
|
name: 'onlyEmails',
|
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'domainSearch',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: true,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: '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: {
|
|
|
|
operation: [
|
|
|
|
'domainSearch',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
operation: [
|
|
|
|
'domainSearch',
|
|
|
|
],
|
|
|
|
returnAll: [
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
operation: [
|
|
|
|
'domainSearch',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
name: 'Executive',
|
|
|
|
value: 'executive',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'IT',
|
|
|
|
value: 'it',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Finance',
|
|
|
|
value: 'finance',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Management',
|
|
|
|
value: 'management',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Sales',
|
|
|
|
value: 'sales',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Legal',
|
|
|
|
value: 'legal',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Support',
|
|
|
|
value: 'support',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'HR',
|
|
|
|
value: 'hr',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Marketing',
|
|
|
|
value: 'marketing',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Communication',
|
|
|
|
value: 'communication',
|
|
|
|
},
|
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: {
|
|
|
|
operation: [
|
2020-01-24 17:01:11 -08:00
|
|
|
'emailFinder',
|
2020-01-24 13:16:54 -08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
required: true,
|
|
|
|
description: 'Domain name from which you want to find the email addresses. For example, "stripe.com".',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'First Name',
|
|
|
|
name: 'firstname',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
2020-01-24 17:01:11 -08:00
|
|
|
'emailFinder',
|
2020-01-24 13:16:54 -08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-05-06 14:01:25 -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: {
|
|
|
|
operation: [
|
2020-01-24 17:01:11 -08:00
|
|
|
'emailFinder',
|
2020-01-24 13:16:54 -08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
required: true,
|
2022-05-06 14:01:25 -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',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
2020-01-24 17:01:11 -08:00
|
|
|
'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();
|
|
|
|
const returnData: IDataObject[] = [];
|
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 {
|
|
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
|
|
//https://hunter.io/api-documentation/v2#domain-search
|
|
|
|
if (operation === 'domainSearch') {
|
|
|
|
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;
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.domain = domain;
|
|
|
|
if (filters.type){
|
|
|
|
qs.type = filters.type;
|
|
|
|
}
|
|
|
|
if (filters.seniority){
|
|
|
|
qs.seniority = (filters.seniority as string[]).join(',');
|
|
|
|
}
|
|
|
|
if (filters.department){
|
|
|
|
qs.department = (filters.department as string[]).join(',');
|
|
|
|
}
|
|
|
|
if (returnAll) {
|
|
|
|
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.
|
|
|
|
if (onlyEmails === false) {
|
|
|
|
let tempReturnData: IDataObject = {};
|
2020-01-24 17:01:11 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
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);
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
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;
|
2020-01-24 17:01:11 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (onlyEmails === true) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (Array.isArray(responseData)) {
|
|
|
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
|
|
|
} else {
|
|
|
|
returnData.push(responseData as IDataObject);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
returnData.push({ error: error.message });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-01-24 13:16:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|