From 3904f7d568523fd888219d4694b83cbcdf61872f Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 24 Apr 2021 17:49:52 +0200 Subject: [PATCH] :zap: Basic code cleanup on Intercom Node --- .../nodes/Intercom/CompanyDescription.ts | 27 ++- .../nodes/Intercom/Intercom.node.ts | 18 +- .../nodes/Intercom/LeadDescription.ts | 117 +++++++------ .../nodes/Intercom/UserDescription.ts | 157 +++++++++--------- 4 files changed, 153 insertions(+), 166 deletions(-) diff --git a/packages/nodes-base/nodes/Intercom/CompanyDescription.ts b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts index d547588fc..77b6bb6c3 100644 --- a/packages/nodes-base/nodes/Intercom/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts @@ -46,9 +46,9 @@ export const companyOperations = [ export const companyFields = [ -/* -------------------------------------------------------------------------- */ -/* company:users */ -/* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ + /* company:users */ + /* -------------------------------------------------------------------------- */ { displayName: 'List By', name: 'listBy', @@ -138,10 +138,9 @@ export const companyFields = [ description: 'How many results to return.', }, -/* -------------------------------------------------------------------------- */ -/* company:getAll */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* company:getAll */ + /* -------------------------------------------------------------------------- */ { displayName: 'Return All', name: 'returnAll', @@ -217,10 +216,9 @@ export const companyFields = [ ], }, -/* -------------------------------------------------------------------------- */ -/* company:get */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* company:get */ + /* -------------------------------------------------------------------------- */ { displayName: 'Select By', name: 'selectBy', @@ -274,10 +272,9 @@ export const companyFields = [ description: 'View by value', }, -/* -------------------------------------------------------------------------- */ -/* company:create/update */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* company:create/update */ + /* -------------------------------------------------------------------------- */ { displayName: 'Company Id', name: 'companyId', diff --git a/packages/nodes-base/nodes/Intercom/Intercom.node.ts b/packages/nodes-base/nodes/Intercom/Intercom.node.ts index fd13f91e9..d1f677dbc 100644 --- a/packages/nodes-base/nodes/Intercom/Intercom.node.ts +++ b/packages/nodes-base/nodes/Intercom/Intercom.node.ts @@ -24,7 +24,7 @@ import { IAvatar, ILead, ILeadCompany, - } from './LeadInterface'; +} from './LeadInterface'; import { userFields, userOpeations, @@ -179,7 +179,7 @@ export class Intercom implements INodeType { if (additionalFields.companies) { const companies: ILeadCompany[] = []; // @ts-ignore - additionalFields.companies.forEach( o => { + additionalFields.companies.forEach(o => { const company: ILeadCompany = {}; company.company_id = o; companies.push(company); @@ -270,9 +270,9 @@ export class Intercom implements INodeType { qs.user_id = value; responseData = await intercomApiRequest.call(this, '/contacts', 'DELETE', {}, qs); } - } catch (error) { - throw new NodeApiError(this.getNode(), error); - } + } catch (error) { + throw new NodeApiError(this.getNode(), error); + } } } //https://developers.intercom.com/intercom-api-reference/reference#users @@ -337,7 +337,7 @@ export class Intercom implements INodeType { if (additionalFields.companies) { const companies: IUserCompany[] = []; // @ts-ignore - additionalFields.companies.forEach( o => { + additionalFields.companies.forEach(o => { const company: IUserCompany = {}; company.company_id = o; companies.push(company); @@ -421,9 +421,9 @@ export class Intercom implements INodeType { const id = this.getNodeParameter('id', i) as string; try { responseData = await intercomApiRequest.call(this, `/users/${id}`, 'DELETE'); - } catch (error) { - throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`); - } + } catch (error) { + throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`); + } } } //https://developers.intercom.com/intercom-api-reference/reference#companies diff --git a/packages/nodes-base/nodes/Intercom/LeadDescription.ts b/packages/nodes-base/nodes/Intercom/LeadDescription.ts index 6ed0b459e..de41a9cf7 100644 --- a/packages/nodes-base/nodes/Intercom/LeadDescription.ts +++ b/packages/nodes-base/nodes/Intercom/LeadDescription.ts @@ -18,6 +18,11 @@ export const leadOpeations = [ value: 'create', description: 'Create a new lead', }, + { + name: 'Delete', + value: 'delete', + description: 'Delete a lead', + }, { name: 'Get', value: 'get', @@ -33,11 +38,6 @@ export const leadOpeations = [ value: 'update', description: 'Update new lead', }, - { - name: 'Delete', - value: 'delete', - description: 'Delete a lead', - }, ], default: 'create', description: 'The operation to perform.', @@ -46,10 +46,9 @@ export const leadOpeations = [ export const leadFields = [ -/* -------------------------------------------------------------------------- */ -/* lead:delete */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* lead:delete */ + /* -------------------------------------------------------------------------- */ { displayName: 'Delete By', name: 'deleteBy', @@ -97,10 +96,9 @@ export const leadFields = [ description: 'Delete by value', }, -/* -------------------------------------------------------------------------- */ -/* lead:get */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* lead:get */ + /* -------------------------------------------------------------------------- */ { displayName: 'Select By', name: 'selectBy', @@ -159,10 +157,9 @@ export const leadFields = [ description: 'View by value', }, -/* -------------------------------------------------------------------------- */ -/* lead:getAll */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* lead:getAll */ + /* -------------------------------------------------------------------------- */ { displayName: 'Return All', name: 'returnAll', @@ -238,10 +235,9 @@ export const leadFields = [ ], }, -/* -------------------------------------------------------------------------- */ -/* lead:update */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* lead:update */ + /* -------------------------------------------------------------------------- */ { displayName: 'Update By', name: 'updateBy', @@ -290,10 +286,9 @@ export const leadFields = [ description: 'Value of the property to identify the lead to update', }, -/* -------------------------------------------------------------------------- */ -/* lead:create */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* lead:create */ + /* -------------------------------------------------------------------------- */ { displayName: 'Email', name: 'email', @@ -355,6 +350,33 @@ export const leadFields = [ default: '', description: 'An avatar image URL. note: the image url needs to be https.', }, + { + displayName: 'Companies', + name: 'companies', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getCompanies', + }, + default: [], + description: 'Identifies the companies this user belongs to.', + }, + { + displayName: 'Email', + name: 'email', + type: 'string', + default: '', + displayOptions: { + show: { + '/resource': [ + 'lead', + ], + '/operation': [ + 'update', + ], + }, + }, + description: 'The email of the user.', + }, { displayName: 'Name', name: 'name', @@ -384,38 +406,18 @@ export const leadFields = [ description: 'A boolean value, which if true, instructs Intercom to update the
users last_request_at value to the current API service time in
UTC. default value if not sent is false.', }, { - displayName: 'Companies', - name: 'companies', - type: 'multiOptions', - typeOptions: { - loadOptionsMethod: 'getCompanies', - }, - default: [], - description: 'Identifies the companies this user belongs to.', - }, - { - displayName: 'Email', - name: 'email', + displayName: 'UTM Campaign', + name: 'utmCampaign', type: 'string', default: '', - displayOptions: { - show: { - '/resource': [ - 'lead', - ], - '/operation': [ - 'update', - ], - }, - }, - description: 'The email of the user.', + description: 'Identifies a specific product promotion or strategic campaign', }, { - displayName: 'UTM Source', - name: 'utmSource', + displayName: 'UTM Content', + name: 'utmContent', type: 'string', default: '', - description: 'An avatar image URL. note: the image url needs to be https.', + description: 'Identifies what specifically was clicked to bring the user to the site', }, { displayName: 'UTM Medium', @@ -425,11 +427,11 @@ export const leadFields = [ description: 'Identifies what type of link was used', }, { - displayName: 'UTM Campaign', - name: 'utmCampaign', + displayName: 'UTM Source', + name: 'utmSource', type: 'string', default: '', - description: 'Identifies a specific product promotion or strategic campaign', + description: 'An avatar image URL. note: the image url needs to be https.', }, { displayName: 'UTM Term', @@ -438,13 +440,6 @@ export const leadFields = [ default: '', description: 'Identifies search terms', }, - { - displayName: 'UTM Content', - name: 'utmContent', - type: 'string', - default: '', - description: 'Identifies what specifically was clicked to bring the user to the site', - }, ], }, { diff --git a/packages/nodes-base/nodes/Intercom/UserDescription.ts b/packages/nodes-base/nodes/Intercom/UserDescription.ts index a9439ff26..f446205e2 100644 --- a/packages/nodes-base/nodes/Intercom/UserDescription.ts +++ b/packages/nodes-base/nodes/Intercom/UserDescription.ts @@ -18,6 +18,11 @@ export const userOpeations = [ value: 'create', description: 'Create a new user', }, + { + name: 'Delete', + value: 'delete', + description: 'Delete a user', + }, { name: 'Get', value: 'get', @@ -33,11 +38,6 @@ export const userOpeations = [ value: 'update', description: 'Update a user', }, - { - name: 'Delete', - value: 'delete', - description: 'Delete a user', - }, ], default: 'create', description: 'The operation to perform.', @@ -46,10 +46,9 @@ export const userOpeations = [ export const userFields = [ -/* -------------------------------------------------------------------------- */ -/* user:delete */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* user:delete */ + /* -------------------------------------------------------------------------- */ { displayName: 'ID', name: 'id', @@ -69,10 +68,9 @@ export const userFields = [ description: 'The Intercom defined id representing the Lead', }, -/* -------------------------------------------------------------------------- */ -/* user:getAll */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* user:getAll */ + /* -------------------------------------------------------------------------- */ { displayName: 'Return All', name: 'returnAll', @@ -145,13 +143,6 @@ export const userFields = [ default: '', description: 'The email address of the user', }, - { - displayName: 'Tag ID', - name: 'tag_id', - type: 'string', - default: '', - description: 'Tag representing the user', - }, { displayName: 'Segment ID', name: 'segment_id', @@ -159,14 +150,20 @@ export const userFields = [ default: '', description: 'Segment representing the user', }, + { + displayName: 'Tag ID', + name: 'tag_id', + type: 'string', + default: '', + description: 'Tag representing the user', + }, ], }, -/* -------------------------------------------------------------------------- */ -/* user:get */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* user:get */ + /* -------------------------------------------------------------------------- */ { displayName: 'Select By', name: 'selectBy', @@ -217,10 +214,9 @@ export const userFields = [ description: 'View by value', }, -/* -------------------------------------------------------------------------- */ -/* user:update */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* user:update */ + /* -------------------------------------------------------------------------- */ { displayName: 'Update By', name: 'updateBy', @@ -275,10 +271,9 @@ export const userFields = [ description: 'Value of the property to identify the user to update', }, -/* -------------------------------------------------------------------------- */ -/* user:create */ -/* -------------------------------------------------------------------------- */ - + /* -------------------------------------------------------------------------- */ + /* user:create */ + /* -------------------------------------------------------------------------- */ { displayName: 'Identifier Type', name: 'identifierType', @@ -362,6 +357,23 @@ export const userFields = [ }, }, options: [ + { + displayName: 'Avatar', + name: 'avatar', + type: 'string', + default: '', + description: 'An avatar image URL. note: the image url needs to be https.', + }, + { + displayName: 'Companies', + name: 'companies', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getCompanies', + }, + default: [], + description: 'Identifies the companies this user belongs to.', + }, { displayName: 'Email', name: 'email', @@ -384,6 +396,29 @@ export const userFields = [ default: '', description: 'Email of the user', }, + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + placeholder: '', + description: 'Name of the user', + }, + { + displayName: 'Phone', + name: 'phone', + type: 'string', + default: '', + description: 'The phone number of the user', + }, + { + displayName: 'Session Count', + name: 'sessionCount', + type: 'number', + default: false, + options: [], + description: `How many sessions the user has recorded`, + }, { displayName: 'User ID', name: 'userId', @@ -407,21 +442,6 @@ export const userFields = [ default: '', description: 'Email of the user', }, - { - displayName: 'Phone', - name: 'phone', - type: 'string', - default: '', - description: 'The phone number of the user', - }, - { - displayName: 'Name', - name: 'name', - type: 'string', - default: '', - placeholder: '', - description: 'Name of the user', - }, { displayName: 'Unsubscribed From Emails', name: 'unsubscribedFromEmails', @@ -439,36 +459,18 @@ export const userFields = [ description: 'A boolean value, which if true, instructs Intercom to update the users
last_request_at value to the current API service time in UTC.', }, { - displayName: 'Session Count', - name: 'sessionCount', - type: 'number', - default: false, - options: [], - description: `How many sessions the user has recorded`, - }, - { - displayName: 'Companies', - name: 'companies', - type: 'multiOptions', - typeOptions: { - loadOptionsMethod: 'getCompanies', - }, - default: [], - description: 'Identifies the companies this user belongs to.', - }, - { - displayName: 'Avatar', - name: 'avatar', + displayName: 'UTM Campaign', + name: 'utmCampaign', type: 'string', default: '', - description: 'An avatar image URL. note: the image url needs to be https.', + description: 'Identifies a specific product promotion or strategic campaign', }, { - displayName: 'UTM Source', - name: 'utmSource', + displayName: 'UTM Content', + name: 'utmContent', type: 'string', default: '', - description: 'An avatar image URL. note: the image url needs to be https.', + description: 'Identifies what specifically was clicked to bring the user to the site', }, { displayName: 'UTM Medium', @@ -478,11 +480,11 @@ export const userFields = [ description: 'Identifies what type of link was used', }, { - displayName: 'UTM Campaign', - name: 'utmCampaign', + displayName: 'UTM Source', + name: 'utmSource', type: 'string', default: '', - description: 'Identifies a specific product promotion or strategic campaign', + description: 'An avatar image URL. note: the image url needs to be https.', }, { displayName: 'UTM Term', @@ -491,13 +493,6 @@ export const userFields = [ default: '', description: 'Identifies search terms', }, - { - displayName: 'UTM Content', - name: 'utmContent', - type: 'string', - default: '', - description: 'Identifies what specifically was clicked to bring the user to the site', - }, ], }, {