From cb6a1924d2fd221bcc6ffd4e20775573dabd3c88 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 29 Jan 2020 21:49:04 -0800 Subject: [PATCH] :zap: Minor improvements to Clearbit-Node --- .../nodes/Clearbit/Clearbit.node.ts | 12 ++--- .../nodes/Clearbit/CompanyDescription.ts | 23 +++------ .../nodes/Clearbit/GenericFunctions.ts | 17 +++++-- .../nodes/Clearbit/PersonDescription.ts | 51 ++++++++----------- packages/nodes-base/package.json | 4 +- 5 files changed, 49 insertions(+), 58 deletions(-) diff --git a/packages/nodes-base/nodes/Clearbit/Clearbit.node.ts b/packages/nodes-base/nodes/Clearbit/Clearbit.node.ts index e589f17621..4ed7bbc7d5 100644 --- a/packages/nodes-base/nodes/Clearbit/Clearbit.node.ts +++ b/packages/nodes-base/nodes/Clearbit/Clearbit.node.ts @@ -16,7 +16,7 @@ import { } from './CompanyDescription'; import { personOperations, - personFields, + personFields, } from './PersonDescription'; export class Clearbit implements INodeType { @@ -82,9 +82,6 @@ export class Clearbit implements INodeType { const email = this.getNodeParameter('email', i) as string; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; qs.email = email; - if (additionalFields.webhookUrl) { - qs.webhook_url = additionalFields.webhookUrl as string; - } if (additionalFields.givenName) { qs.given_name = additionalFields.givenName as string; } @@ -103,8 +100,8 @@ export class Clearbit implements INodeType { if (additionalFields.companyDomain) { qs.company_domain = additionalFields.companyDomain as string; } - if (additionalFields.linkedin) { - qs.linkedin = additionalFields.linkedin as string; + if (additionalFields.linkedIn) { + qs.linkedin = additionalFields.linkedIn as string; } if (additionalFields.twitter) { qs.twitter = additionalFields.twitter as string; @@ -120,9 +117,6 @@ export class Clearbit implements INodeType { const domain = this.getNodeParameter('domain', i) as string; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; qs.domain = domain; - if (additionalFields.webhookUrl) { - qs.webhook_url = additionalFields.webhookUrl as string; - } if (additionalFields.companyName) { qs.company_name = additionalFields.companyName as string; } diff --git a/packages/nodes-base/nodes/Clearbit/CompanyDescription.ts b/packages/nodes-base/nodes/Clearbit/CompanyDescription.ts index abd998051c..d9e629974b 100644 --- a/packages/nodes-base/nodes/Clearbit/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Clearbit/CompanyDescription.ts @@ -21,7 +21,7 @@ export const companyOperations = [ { name: 'Autocomplete', value: 'autocomplete', - description: 'lets you auto-complete company names and retreive logo and domain', + description: 'Lets you auto-complete company names and retreive logo and domain', }, ], default: 'enrich', @@ -69,13 +69,6 @@ export const companyFields = [ }, }, options: [ - { - displayName: 'Webhook URL', - name: 'webhookUrl', - type: 'string', - default: '', - description: 'A webhook URL that results will be sent to.', - }, { displayName: 'Company Name', name: 'companyName', @@ -83,6 +76,13 @@ export const companyFields = [ default: '', description: 'The name of the company.', }, + { + displayName: 'Facebook', + name: 'facebook', + type: 'string', + default: '', + description: 'The Facebook URL for the company.', + }, { displayName: 'Linkedin', name: 'linkedin', @@ -97,13 +97,6 @@ export const companyFields = [ default: '', description: 'The Twitter handle for the company.', }, - { - displayName: 'Facebook', - name: 'facebook', - type: 'string', - default: '', - description: 'The Facebook URL for the company.', - }, ], }, /* -------------------------------------------------------------------------- */ diff --git a/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts b/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts index bfe38e8991..f516c0dd88 100644 --- a/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts @@ -17,7 +17,7 @@ export async function clearbitApiRequest(this: IHookFunctions | IExecuteFunction method, qs, body, - uri: uri ||`https://${api}.clearbit.com${resource}`, + uri: uri ||`https://${api}-stream.clearbit.com${resource}`, json: true }; options = Object.assign({}, options, option); @@ -26,7 +26,18 @@ export async function clearbitApiRequest(this: IHookFunctions | IExecuteFunction } try { return await this.helpers.request!(options); - } catch (err) { - throw new Error(err); + } catch (error) { + if (error.statusCode === 401) { + // Return a clear error + throw new Error('The Clearbit credentials are not valid!'); + } + + if (error.response.body && error.response.body.error && error.response.body.error.message) { + // Try to return the error prettier + throw new Error(`Clearbit Error [${error.statusCode}]: ${error.response.body.error.message}`); + } + + // If that data does not exist for some reason return the actual error + throw new Error('Clearbit Error: ' + error.message); } } diff --git a/packages/nodes-base/nodes/Clearbit/PersonDescription.ts b/packages/nodes-base/nodes/Clearbit/PersonDescription.ts index a91fa0744e..72e7de4fe7 100644 --- a/packages/nodes-base/nodes/Clearbit/PersonDescription.ts +++ b/packages/nodes-base/nodes/Clearbit/PersonDescription.ts @@ -65,18 +65,25 @@ export const personFields = [ }, options: [ { - displayName: 'Webhook URL', - name: 'webhookUrl', + displayName: 'Company', + name: 'company', type: 'string', default: '', - description: 'A webhook URL that results will be sent to.', + description: 'The name of the person’s employer.', }, { - displayName: 'Given Name', - name: 'givenName', + displayName: 'Company Domain', + name: 'companyDomain', type: 'string', default: '', - description: 'First name of person.', + description: 'The domain for the person’s employer.', + }, + { + displayName: 'Facebook', + name: 'facebook', + type: 'string', + default: '', + description: 'The Facebook URL for the person.', }, { displayName: 'Family Name', @@ -85,6 +92,13 @@ export const personFields = [ default: '', description: 'Last name of person. If you have this, passing this is strongly recommended to improve match rates.', }, + { + displayName: 'Given Name', + name: 'givenName', + type: 'string', + default: '', + description: 'First name of person.', + }, { displayName: 'IP Address', name: 'ipAddress', @@ -100,22 +114,8 @@ export const personFields = [ description: 'The city or country where the person resides.', }, { - displayName: 'Company', - name: 'company', - type: 'string', - default: '', - description: 'The name of the person’s employer.', - }, - { - displayName: 'Company Domain', - name: 'companyDomain', - type: 'string', - default: '', - description: 'The domain for the person’s employer.', - }, - { - displayName: 'Linkedin', - name: 'linkedin', + displayName: 'LinkedIn', + name: 'linkedIn', type: 'string', default: '', description: 'The LinkedIn URL for the person.', @@ -127,13 +127,6 @@ export const personFields = [ default: '', description: 'The Twitter handle for the person.', }, - { - displayName: 'Facebook', - name: 'facebook', - type: 'string', - default: '', - description: 'The Facebook URL for the person.', - }, ], }, ] as INodeProperties[]; diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 5d52182543..9c1beb2006 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -35,10 +35,10 @@ "dist/credentials/BitbucketApi.credentials.js", "dist/credentials/BitlyApi.credentials.js", "dist/credentials/ChargebeeApi.credentials.js", + "dist/credentials/ClearbitApi.credentials.js", "dist/credentials/ClickUpApi.credentials.js", "dist/credentials/CodaApi.credentials.js", "dist/credentials/CopperApi.credentials.js", - "dist/credentials/ClearbitApi.credentials.js", "dist/credentials/DisqusApi.credentials.js", "dist/credentials/DropboxApi.credentials.js", "dist/credentials/EventbriteApi.credentials.js", @@ -109,11 +109,11 @@ "dist/nodes/Bitly/Bitly.node.js", "dist/nodes/Chargebee/Chargebee.node.js", "dist/nodes/Chargebee/ChargebeeTrigger.node.js", + "dist/nodes/Clearbit/Clearbit.node.js", "dist/nodes/ClickUp/ClickUp.node.js", "dist/nodes/ClickUp/ClickUpTrigger.node.js", "dist/nodes/Coda/Coda.node.js", "dist/nodes/Copper/CopperTrigger.node.js", - "dist/nodes/Clearbit/Clearbit.node.js", "dist/nodes/Cron.node.js", "dist/nodes/Discord/Discord.node.js", "dist/nodes/Disqus/Disqus.node.js",