diff --git a/packages/nodes-base/credentials/UpleadApi.credentials.ts b/packages/nodes-base/credentials/UpleadApi.credentials.ts new file mode 100644 index 0000000000..18c4ca9e38 --- /dev/null +++ b/packages/nodes-base/credentials/UpleadApi.credentials.ts @@ -0,0 +1,17 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + +export class UpleadApi implements ICredentialType { + name = 'upleadApi'; + displayName = 'Uplead API'; + properties = [ + { + displayName: 'API Key', + name: 'apiKey', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Uplead/CompanyDesciption.ts b/packages/nodes-base/nodes/Uplead/CompanyDesciption.ts new file mode 100644 index 0000000000..39ca13e01a --- /dev/null +++ b/packages/nodes-base/nodes/Uplead/CompanyDesciption.ts @@ -0,0 +1,65 @@ +import { INodeProperties } from 'n8n-workflow'; + +export const companyOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'company', + ], + }, + }, + options: [ + { + name: 'Enrich', + value: 'enrich', + }, + ], + default: 'enrich', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const companyFields = [ + +/* -------------------------------------------------------------------------- */ +/* company:enrich */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Company', + name: 'company', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'the name of the company (e.g – amazon)', + }, + { + displayName: 'Domain', + name: 'domain', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'the domain name (e.g – amazon.com)', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Uplead/GenericFunctions.ts b/packages/nodes-base/nodes/Uplead/GenericFunctions.ts new file mode 100644 index 0000000000..ff6d7b481a --- /dev/null +++ b/packages/nodes-base/nodes/Uplead/GenericFunctions.ts @@ -0,0 +1,32 @@ +import { OptionsWithUri } from 'request'; +import { + IExecuteFunctions, + IExecuteSingleFunctions, + IHookFunctions, + ILoadOptionsFunctions, +} from 'n8n-core'; +import { IDataObject } from 'n8n-workflow'; + +export async function upleadApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any + const credentials = this.getCredentials('upleadApi'); + if (credentials === undefined) { + throw new Error('No credentials got returned!'); + } + let options: OptionsWithUri = { + headers: { Authorization: credentials.apiKey }, + method, + qs, + body, + uri: uri ||`https://api.uplead.com/v2${resource}`, + json: true + }; + options = Object.assign({}, options, option); + if (Object.keys(options.body).length === 0) { + delete options.body; + } + try { + return await this.helpers.request!(options); + } catch (err) { + throw new Error(err); + } +} diff --git a/packages/nodes-base/nodes/Uplead/PersonDescription.ts b/packages/nodes-base/nodes/Uplead/PersonDescription.ts new file mode 100644 index 0000000000..8e65faa64a --- /dev/null +++ b/packages/nodes-base/nodes/Uplead/PersonDescription.ts @@ -0,0 +1,99 @@ +import { INodeProperties } from 'n8n-workflow'; + +export const personOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'person', + ], + }, + }, + options: [ + { + name: 'Enrich', + value: 'enrich', + }, + ], + default: 'enrich', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const personFields = [ + +/* -------------------------------------------------------------------------- */ +/* person:enrich */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Email', + name: 'email', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'person', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'Email address (e.g – mbenioff@salesforce.com)', + }, + { + displayName: 'Fist Name', + name: 'firstname', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'person', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'First name of the person (e.g – Marc)', + }, + { + displayName: 'Last Name', + name: 'lastname', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'person', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'Last name of the person (e.g – Benioff)', + }, + { + displayName: 'Domain', + name: 'domain', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'person', + ], + operation: [ + 'enrich', + ], + }, + }, + description: 'The domain name (e.g – salesforce.com)', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Uplead/Uplead.node.ts b/packages/nodes-base/nodes/Uplead/Uplead.node.ts new file mode 100644 index 0000000000..e47bdbe71c --- /dev/null +++ b/packages/nodes-base/nodes/Uplead/Uplead.node.ts @@ -0,0 +1,121 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; +import { + IDataObject, + INodeExecutionData, + INodeType, + INodeTypeDescription, +} from 'n8n-workflow'; +import { + upleadApiRequest, +} from './GenericFunctions'; +import { + companyFields, + companyOperations, +} from './CompanyDesciption'; +import { + personOperations, + personFields, +} from './PersonDescription'; + +export class Uplead implements INodeType { + description: INodeTypeDescription = { + displayName: 'Uplead', + name: 'uplead', + icon: 'file:uplead.png', + group: ['output'], + version: 1, + subtitle: '={{$parameter["operation"] + ":" + $parameter["resource"]}}', + description: 'Consume Uplead API', + defaults: { + name: 'Uplead', + color: '#5d6f7b', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'upleadApi', + required: true, + } + ], + properties: [ + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Company', + value: 'company', + description: 'Company API lets you lookup company data via a domain name or company name.', + }, + { + name: 'Person', + value: 'person', + description: `Person API lets you lookup a person based on an email address OR based on a domain name + first name + last name` + }, + ], + default: 'company', + description: 'Resource to consume.', + }, + ...companyOperations, + ...companyFields, + ...personOperations, + ...personFields, + ], + }; + + async execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + const returnData: IDataObject[] = []; + const length = items.length as unknown as number; + const qs: IDataObject = {}; + 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 === 'person') { + if (operation === 'enrich') { + const email = this.getNodeParameter('email', i) as string; + const firstname = this.getNodeParameter('firstname', i) as string; + const lastname = this.getNodeParameter('lastname', i) as string; + const domain = this.getNodeParameter('domain', i) as string; + if (email) { + qs.email = email; + } + if (firstname) { + qs.first_name = firstname; + } + if (lastname) { + qs.last_name = lastname; + } + if (domain) { + qs.domain = domain; + } + responseData = await upleadApiRequest.call(this, 'GET', '/person-search', {}, qs); + } + } + if (resource === 'company') { + if (operation === 'enrich') { + const domain = this.getNodeParameter('domain', i) as string; + const company = this.getNodeParameter('company', i) as string; + if (domain) { + qs.domain = domain; + } + if (company) { + qs.company = company; + } + responseData = await upleadApiRequest.call(this, 'GET', '/company-search', {}, qs); + } + } + if (Array.isArray(responseData.data)) { + returnData.push.apply(returnData, responseData.data as IDataObject[]); + } else { + returnData.push(responseData.data as IDataObject); + } + } + return [this.helpers.returnJsonArray(returnData)]; + } +} diff --git a/packages/nodes-base/nodes/Uplead/uplead.png b/packages/nodes-base/nodes/Uplead/uplead.png new file mode 100644 index 0000000000..8eb61801a7 Binary files /dev/null and b/packages/nodes-base/nodes/Uplead/uplead.png differ diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 2c40a4d076..d0ff3791e6 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -85,6 +85,7 @@ "dist/credentials/TwilioApi.credentials.js", "dist/credentials/TypeformApi.credentials.js", "dist/credentials/TogglApi.credentials.js", + "dist/credentials/UpleadApi.credentials.js", "dist/credentials/VeroApi.credentials.js", "dist/credentials/WebflowApi.credentials.js", "dist/credentials/WordpressApi.credentials.js", @@ -190,6 +191,7 @@ "dist/nodes/Trello/TrelloTrigger.node.js", "dist/nodes/Twilio/Twilio.node.js", "dist/nodes/Typeform/TypeformTrigger.node.js", + "dist/nodes/Uplead/Uplead.node.js", "dist/nodes/Vero/Vero.node.js", "dist/nodes/Webflow/WebflowTrigger.node.js", "dist/nodes/Webhook.node.js",