EsLint changes

This commit is contained in:
Rupenieks 2020-05-06 10:27:01 +02:00
parent 08220195a2
commit 7c4a588b70
8 changed files with 1180 additions and 1131 deletions

50
.eslintrc.json Normal file
View file

@ -0,0 +1,50 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:vue/essential",
"tslint-eslint-rules"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"parser": "@typescript-eslint/parser",
"sourceType": "module"
},
"plugins": [
"vue",
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"sort-imports": ["error", {
"ignoreCase": false,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
}],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]
}
}

View file

@ -16,5 +16,9 @@
"lerna": "^3.13.1", "lerna": "^3.13.1",
"run-script-os": "^1.0.7" "run-script-os": "^1.0.7"
}, },
"postcss": {} "postcss": {},
"dependencies": {
"@typescript-eslint/parser": "^2.31.0",
"tslint-eslint-rules": "^5.4.0"
}
} }

View file

@ -1,36 +1,36 @@
import { IExecuteFunctions } from 'n8n-core'; import { IExecuteFunctions } from 'n8n-core';
import { import {
IDataObject,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription
IDataObject
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
contactOperations, contactFields,
contactFields contactOperations
} from './ContactDescription'; } from './ContactDescription';
import { import {
companyOperations, companyFields,
companyFields companyOperations
} from './CompanyDescription'; } from './CompanyDescription';
import { import {
dealOperations, dealFields,
dealFields dealOperations
} from './DealDescription'; } from './DealDescription';
import { agileCrmApiRequest, validateJSON, agileCrmApiRequestUpdate} from './GenericFunctions'; import { IContact, IContactUpdate } from './ContactInterface';
import { IContact, IProperty, IContactUpdate } from './ContactInterface'; import { agileCrmApiRequest, agileCrmApiRequestUpdate, validateJSON} from './GenericFunctions';
import { IDeal } from './DealInterface'; import { IDeal } from './DealInterface';
export class AgileCrm implements INodeType { export class AgileCrm implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'AgileCRM', displayName: 'AgileCRM',
name: 'agileCrm', name: 'agileCrm',
icon: 'file:agilecrm.png', icon: 'file:agilecrm.png',
group: ['transform'], group: ['transform'],
version: 1, version: 1,
description: 'Consume AgileCRM API', description: 'Consume AgileCRM API',
@ -39,8 +39,8 @@ export class AgileCrm implements INodeType {
color: '#772244', color: '#772244',
}, },
inputs: ['main'], inputs: ['main'],
outputs: ['main'], outputs: ['main'],
credentials: [ credentials: [
{ {
name: 'agileCrmApi', name: 'agileCrmApi',
required: true, required: true,
@ -52,21 +52,21 @@ export class AgileCrm implements INodeType {
{ {
displayName: 'Resource', displayName: 'Resource',
name: 'resource', name: 'resource',
type: 'options', type: 'options',
options: [ options: [
{ {
name: 'Company', name: 'Company',
value: 'company' value: 'company'
},
{
name: 'Contact',
value: 'contact'
}, },
{ {
name: 'Deal', name: 'Contact',
value: 'deal' value: 'contact'
}, },
], {
name: 'Deal',
value: 'deal'
},
],
default: 'contact', default: 'contact',
description: 'Resource to consume.', description: 'Resource to consume.',
}, },
@ -92,14 +92,13 @@ export class AgileCrm implements INodeType {
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
const length = items.length as unknown as number; const length = items.length as unknown as number;
let responseData; let responseData;
const qs: IDataObject = {};
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if(resource === 'contact' || resource === 'company'){ if(resource === 'contact' || resource === 'company'){
let idGetter = resource === 'contact' ? 'contactId' : 'companyId'; const idGetter = resource === 'contact' ? 'contactId' : 'companyId';
if(operation === 'get'){ if(operation === 'get'){
const contactId = this.getNodeParameter(idGetter, i) as string; const contactId = this.getNodeParameter(idGetter, i) as string;
@ -122,7 +121,7 @@ export class AgileCrm implements INodeType {
if(resource === 'contact'){ if(resource === 'contact'){
if (returnAll) { if (returnAll) {
const endpoint = `api/contacts`; const endpoint = 'api/contacts';
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {}); responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
} else { } else {
const limit = this.getNodeParameter('limit', i) as number; const limit = this.getNodeParameter('limit', i) as number;
@ -131,7 +130,7 @@ export class AgileCrm implements INodeType {
} }
} else { } else {
if (returnAll) { if (returnAll) {
const endpoint = `api/contacts/companies/list`; const endpoint = 'api/contacts/companies/list';
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, {}); responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, {});
} else { } else {
const limit = this.getNodeParameter('limit', i) as number; const limit = this.getNodeParameter('limit', i) as number;
@ -145,7 +144,7 @@ export class AgileCrm implements INodeType {
if(operation === 'create'){ if(operation === 'create'){
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
const body: IContact = {}; const body: IContact = {};
let properties : IDataObject[] = []; const properties : IDataObject[] = [];
if (jsonParameters) { if (jsonParameters) {
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string; const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
@ -218,7 +217,7 @@ export class AgileCrm implements INodeType {
name: 'email', name: 'email',
value: property.email as string value: property.email as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.addressOptions){ if(additionalFields.addressOptions){
//@ts-ignore //@ts-ignore
@ -229,7 +228,7 @@ export class AgileCrm implements INodeType {
name: 'address', name: 'address',
value: property.address as string value: property.address as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.phoneOptions){ if(additionalFields.phoneOptions){
@ -241,7 +240,7 @@ export class AgileCrm implements INodeType {
name: 'phone', name: 'phone',
value: property.number as string value: property.number as string
} as IDataObject); } as IDataObject);
}) });
} }
} else if (resource === 'company') { } else if (resource === 'company') {
if(additionalFields.email){ if(additionalFields.email){
@ -279,7 +278,7 @@ export class AgileCrm implements INodeType {
name: 'webiste', name: 'webiste',
value: property.url as string value: property.url as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.customProperties){ if(additionalFields.customProperties){
@ -291,7 +290,7 @@ export class AgileCrm implements INodeType {
name: property.name, name: property.name,
value: property.value as string value: property.value as string
} as IDataObject); } as IDataObject);
}) });
} }
body.properties = properties; body.properties = properties;
@ -302,10 +301,10 @@ export class AgileCrm implements INodeType {
if(operation === 'update') { if(operation === 'update') {
const contactId = this.getNodeParameter(idGetter, i) as string; const contactId = this.getNodeParameter(idGetter, i) as string;
let contactUpdatePayload : IContactUpdate = {id: contactId}; const contactUpdatePayload : IContactUpdate = {id: contactId};
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
const body: IContact = {}; const body: IContact = {};
let properties : IDataObject[] = []; const properties : IDataObject[] = [];
if (jsonParameters) { if (jsonParameters) {
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string; const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
@ -372,7 +371,7 @@ export class AgileCrm implements INodeType {
name: 'email', name: 'email',
value: property.email as string value: property.email as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.addressOptions){ if(additionalFields.addressOptions){
//@ts-ignore //@ts-ignore
@ -383,7 +382,7 @@ export class AgileCrm implements INodeType {
name: 'address', name: 'address',
value: property.address as string value: property.address as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.phoneOptions){ if(additionalFields.phoneOptions){
@ -395,7 +394,7 @@ export class AgileCrm implements INodeType {
name: 'phone', name: 'phone',
value: property.number as string value: property.number as string
} as IDataObject); } as IDataObject);
}) });
} }
} else if (resource === 'company') { } else if (resource === 'company') {
if(additionalFields.email){ if(additionalFields.email){
@ -433,7 +432,7 @@ export class AgileCrm implements INodeType {
name: 'webiste', name: 'webiste',
value: property.url as string value: property.url as string
} as IDataObject); } as IDataObject);
}) });
} }
if(additionalFields.customProperties){ if(additionalFields.customProperties){
//@ts-ignore //@ts-ignore
@ -444,7 +443,7 @@ export class AgileCrm implements INodeType {
name: property.name, name: property.name,
value: property.value as string value: property.value as string
} as IDataObject); } as IDataObject);
}) });
} }
body.properties = properties; body.properties = properties;
} }
@ -476,7 +475,7 @@ export class AgileCrm implements INodeType {
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll) { if (returnAll) {
const endpoint = `api/opportunity`; const endpoint = 'api/opportunity';
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {}); responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
} else { } else {
const limit = this.getNodeParameter('limit', i) as number; const limit = this.getNodeParameter('limit', i) as number;
@ -524,7 +523,7 @@ export class AgileCrm implements INodeType {
} }
let endpoint = 'api/opportunity' const endpoint = 'api/opportunity';
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body); responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body);
} }
@ -574,7 +573,7 @@ export class AgileCrm implements INodeType {
} }
let endpoint = 'api/opportunity/partial-update' const endpoint = 'api/opportunity/partial-update';
responseData = await agileCrmApiRequest.call(this, 'PUT', endpoint, body); responseData = await agileCrmApiRequest.call(this, 'PUT', endpoint, body);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const contactOperations = [ export const contactOperations = [
{ {
@ -110,484 +110,484 @@ export const contactFields = [
} }
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:create */ /* contact:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'JSON Parameters', displayName: 'JSON Parameters',
name: 'jsonParameters', name: 'jsonParameters',
type: 'boolean', type: 'boolean',
default: false, default: false,
description: '', description: '',
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'contact', 'contact',
], ],
operation: [ operation: [
'create', 'create',
], ],
},
}, },
}, },
}, {
{ displayName: ' Additional Fields',
displayName: ' Additional Fields', name: 'additionalFieldsJson',
name: 'additionalFieldsJson', type: 'json',
type: 'json', typeOptions: {
typeOptions: { alwaysOpenEditWindow: true,
alwaysOpenEditWindow: true,
},
default: '',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'create',
],
jsonParameters: [
true,
],
}, },
default: '',
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'create',
],
jsonParameters: [
true,
],
},
},
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-contacts---companies-api" target="_blank">here</a>.`,
}, },
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-contacts---companies-api" target="_blank">here</a>.`,
},
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
type: 'collection', type: 'collection',
placeholder: 'Add Field', placeholder: 'Add Field',
default: {}, default: {},
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'contact', 'contact',
], ],
operation: [ operation: [
'create', 'create',
], ],
jsonParameters: [ jsonParameters: [
false, false,
], ],
},
}, },
options: [
{
displayName: 'Star Value',
name: 'starValue',
type: 'options',
default: '',
required: false,
description: 'Rating of contact (Max value 5). This is not applicable for companies.',
options: [
{
name: '0',
value: 0
},
{
name: '1',
value: 1
},
{
name: '2',
value: 2
},
{
name: '3',
value: 3
},
{
name: '4',
value: 4
},
{
name: '5',
value: 5
},
]
},
{
displayName: 'Lead Score',
name: 'leadScore',
type: 'number',
default: '',
description: 'Score of contact. This is not applicable for companies.',
required: false,
typeOptions: {
minValue: 0
}
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add Tag',
},
default: [],
placeholder: 'Tag',
description: 'Unique identifiers added to contact, for easy management of contacts. This is not applicable for companies.',
},
{
displayName: 'First Name',
name: 'firstName',
type: 'string',
required: false,
default: "",
placeholder: 'First Name',
description: 'Contact first name.',
},
{
displayName: 'Last Name',
name: 'lastName',
type: 'string',
required: false,
default: "",
placeholder: 'Last Name',
description: 'Contact last name.',
},
{
displayName: 'Company',
name: 'company',
type: 'string',
required: false,
default: "",
placeholder: 'Company',
description: 'Company Name.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
required: false,
default: "",
placeholder: 'Title',
description: 'Professional title.',
},
{
displayName: 'Email',
name: 'emailOptions',
type: 'fixedCollection',
required: false,
description: 'Contact email.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Email Properties',
name: 'emailProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of Email',
options: [
{
name: 'Work',
value: 'work'
},
{
name: 'Personal',
value: 'personal'
}
]
},
{
displayName: 'Email',
name: 'email',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Email',
}
]
},
]
},
{
displayName: 'Address',
name: 'addressOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts address.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Address Properties',
name: 'addressProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of address.',
options: [
{
name: 'Home',
value: 'home'
},
{
name: 'Postal',
value: 'postal'
}
,
{
name: 'Office',
value: 'office'
}
]
},
{
displayName: 'Address',
name: 'address',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Full address.',
}
]
},
]
},
{
displayName: 'Website',
name: 'websiteOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts websites.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Website properties.',
name: 'websiteProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of website.',
options: [
{
name: 'URL',
value: 'url',
},
{
name: 'SKYPE',
value: 'skype',
},
{
name: 'TWITTER',
value: 'twitter',
},
{
name: 'LINKEDIN',
value: 'linkedin',
},
{
name: 'FACEBOOK',
value: 'facebook',
},
{
name: 'XING',
value: 'xing',
},
{
name: 'FEED',
value: 'feed',
},
{
name: 'GOOGLE_PLUS',
value: 'googlePlus',
},
{
name: 'FLICKR',
value: 'flickr',
},
{
name: 'GITHUB',
value: 'github',
},
{
name: 'YOUTUBE',
value: 'youtube',
},
]
},
{
displayName: 'URL',
name: 'url',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Website URL',
}
]
},
]
},
{
displayName: 'Phone',
name: 'phoneOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts phone.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Phone properties',
name: 'phoneProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of phone number.',
options: [
{
name: 'Home',
value: 'home'
},
{
name: 'Work',
value: 'work'
}
,
{
name: 'Mobile',
value: 'mobile'
},
{
name: 'Main',
value: 'main'
},
{
name: 'Home Fax',
value: 'homeFax'
},
{
name: 'Work Fax',
value: 'workFax'
},
{
name: 'Other',
value: 'other'
},
]
},
{
displayName: 'Number',
name: 'number',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Phone number.',
}
]
},
]
},
{
displayName: 'Custom Properties',
name: 'customProperties',
type: 'fixedCollection',
required: false,
description: 'Custom Properties',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Property',
name: 'customProperty',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Property name.'
},
{
displayName: 'Sub Type',
name: 'subtype',
type: 'string',
required: false,
default: "",
placeholder: '',
description: 'Property sub type.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
required: false,
default: "",
placeholder: '',
description: 'Property value.',
}
]
},
]
},
],
}, },
options: [ /* -------------------------------------------------------------------------- */
{ /* contact:delete */
displayName: 'Star Value', /* -------------------------------------------------------------------------- */
name: 'starValue', {
type: 'options', displayName: 'Contact ID',
default: '', name: 'contactId',
required: false, type: 'string',
description: 'Rating of contact (Max value 5). This is not applicable for companies.', required: true,
options: [ displayOptions: {
{ show: {
name: '0', resource: [
value: 0 'contact',
}, ],
{ operation: [
name: '1', 'delete',
value: 1 ],
},
{
name: '2',
value: 2
},
{
name: '3',
value: 3
},
{
name: '4',
value: 4
},
{
name: '5',
value: 5
},
]
},
{
displayName: 'Lead Score',
name: 'leadScore',
type: 'number',
default: '',
description: 'Score of contact. This is not applicable for companies.',
required: false,
typeOptions: {
minValue: 0
}
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
typeOptions: {
multipleValues: true,
multipleValueButtonText: 'Add Tag',
}, },
default: [],
placeholder: 'Tag',
description: 'Unique identifiers added to contact, for easy management of contacts. This is not applicable for companies.',
},
{
displayName: 'First Name',
name: 'firstName',
type: 'string',
required: false,
default: "",
placeholder: 'First Name',
description: 'Contact first name.',
},
{
displayName: 'Last Name',
name: 'lastName',
type: 'string',
required: false,
default: "",
placeholder: 'Last Name',
description: 'Contact last name.',
},
{
displayName: 'Company',
name: 'company',
type: 'string',
required: false,
default: "",
placeholder: 'Company',
description: 'Company Name.',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
required: false,
default: "",
placeholder: 'Title',
description: 'Professional title.',
},
{
displayName: 'Email',
name: 'emailOptions',
type: 'fixedCollection',
required: false,
description: 'Contact email.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Email Properties',
name: 'emailProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of Email',
options: [
{
name: 'Work',
value: 'work'
},
{
name: 'Personal',
value: 'personal'
}
]
},
{
displayName: 'Email',
name: 'email',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Email',
}
]
},
]
},
{
displayName: 'Address',
name: 'addressOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts address.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Address Properties',
name: 'addressProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of address.',
options: [
{
name: 'Home',
value: 'home'
},
{
name: 'Postal',
value: 'postal'
}
,
{
name: 'Office',
value: 'office'
}
]
},
{
displayName: 'Address',
name: 'address',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Full address.',
}
]
},
]
},
{
displayName: 'Website',
name: 'websiteOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts websites.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Website properties.',
name: 'websiteProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of website.',
options: [
{
name: 'URL',
value: 'url',
},
{
name: 'SKYPE',
value: 'skype',
},
{
name: 'TWITTER',
value: 'twitter',
},
{
name: 'LINKEDIN',
value: 'linkedin',
},
{
name: 'FACEBOOK',
value: 'facebook',
},
{
name: 'XING',
value: 'xing',
},
{
name: 'FEED',
value: 'feed',
},
{
name: 'GOOGLE_PLUS',
value: 'googlePlus',
},
{
name: 'FLICKR',
value: 'flickr',
},
{
name: 'GITHUB',
value: 'github',
},
{
name: 'YOUTUBE',
value: 'youtube',
},
]
},
{
displayName: 'URL',
name: 'url',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Website URL',
}
]
},
]
},
{
displayName: 'Phone',
name: 'phoneOptions',
type: 'fixedCollection',
required: false,
description: 'Contacts phone.',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Phone properties',
name: 'phoneProperties',
values: [
{
displayName: 'Type',
name: 'subtype',
type: 'options',
required: true,
default: "",
placeholder: '',
description: 'Type of phone number.',
options: [
{
name: 'Home',
value: 'home'
},
{
name: 'Work',
value: 'work'
}
,
{
name: 'Mobile',
value: 'mobile'
},
{
name: 'Main',
value: 'main'
},
{
name: 'Home Fax',
value: 'homeFax'
},
{
name: 'Work Fax',
value: 'workFax'
},
{
name: 'Other',
value: 'other'
},
]
},
{
displayName: 'Number',
name: 'number',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Phone number.',
}
]
},
]
},
{
displayName: 'Custom Properties',
name: 'customProperties',
type: 'fixedCollection',
required: false,
description: 'Custom Properties',
typeOptions: {
multipleValues: true,
},
options: [
{
displayName: 'Property',
name: 'customProperty',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: "",
placeholder: '',
description: 'Property name.'
},
{
displayName: 'Sub Type',
name: 'subtype',
type: 'string',
required: false,
default: "",
placeholder: '',
description: 'Property sub type.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
required: false,
default: "",
placeholder: '',
description: 'Property value.',
}
]
},
]
},
],
},
/* -------------------------------------------------------------------------- */
/* contact:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Contact ID',
name: 'contactId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'contact',
],
operation: [
'delete',
],
}, },
default: '',
description: 'Unique identifier for a particular contact',
}, },
default: '',
description: 'Unique identifier for a particular contact',
},
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:update */ /* contact:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View file

@ -10,7 +10,7 @@ import {
} }
export interface IContact { export interface IContact {
type?: string, type?: string;
star_value?: string; star_value?: string;
lead_score?: string; lead_score?: string;
tags?: string[]; tags?: string[];
@ -18,8 +18,8 @@ import {
} }
export interface IContactUpdate { export interface IContactUpdate {
id: string, id: string;
properties?: IDataObject[], properties?: IDataObject[];
star_value?: string; star_value?: string;
lead_score?: string; lead_score?: string;
tags?: string[]; tags?: string[];

View file

@ -1,19 +1,15 @@
import { export interface IDealCustomProperty {
IDataObject,
} from 'n8n-workflow';
export interface IDealCustomProperty {
name: string; name: string;
value: string; value: string;
} }
export interface IDeal { export interface IDeal {
id?: number, id?: number;
expected_value?: number, expected_value?: number;
probability?: number, probability?: number;
name?: string, name?: string;
close_date?: number, close_date?: number;
milestone?: string, milestone?: string;
contactIds?: string[], contactIds?: string[];
customData?: IDealCustomProperty[] customData?: IDealCustomProperty[];
} }

View file

@ -1,5 +1,5 @@
import { import {
OptionsWithUri, OptionsWithUri
} from 'request'; } from 'request';
import { import {
@ -12,7 +12,7 @@ import {
import { import {
IDataObject, IDataObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { IContactUpdate } from './ContactInterface'; import { IContactUpdate, IProperty } from './ContactInterface';
export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> {
@ -51,7 +51,7 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
} }
export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> {
const baseUri = 'https://n8nio.agilecrm.com/dev/'; const baseUri = 'https://n8nio.agilecrm.com/dev/';
const credentials = this.getCredentials('agileCrmApi'); const credentials = this.getCredentials('agileCrmApi');
const options: OptionsWithUri = { const options: OptionsWithUri = {
@ -68,9 +68,9 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
json: true json: true
}; };
let successfulUpdates = []; const successfulUpdates = [];
let lastSuccesfulUpdateReturn : any; let lastSuccesfulUpdateReturn : any;
let payload : IContactUpdate = body; const payload : IContactUpdate = body;
try { try {
// Due to API, we must update each property separately // Due to API, we must update each property separately
@ -82,7 +82,7 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
// Iterate trough properties and show them as individial updates instead of only vague "properties" // Iterate trough properties and show them as individial updates instead of only vague "properties"
payload.properties?.map((property : any) => { payload.properties?.map((property : any) => {
successfulUpdates.push(`${property.name} `); successfulUpdates.push(`${property.name} `);
}) });
delete options.body.properties; delete options.body.properties;
} }
@ -102,7 +102,7 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
payload.tags?.map((tag : string) => { payload.tags?.map((tag : string) => {
successfulUpdates.push(`(Tag) ${tag} `); successfulUpdates.push(`(Tag) ${tag} `);
}) });
delete options.body.tags; delete options.body.tags;
} }