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,28 +1,28 @@
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';
@ -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);
} }
} }

View file

@ -1,6 +1,6 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const companyOperations = [ export const companyOperations = [
{ {
@ -70,9 +70,9 @@ export const companyFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* company:get all */ /* company:get all */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
@ -110,11 +110,11 @@ export const companyFields = [
} }
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* company:create */ /* company:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'JSON Parameters', displayName: 'JSON Parameters',
name: 'jsonParameters', name: 'jsonParameters',
type: 'boolean', type: 'boolean',
@ -130,8 +130,8 @@ export const companyFields = [
], ],
}, },
}, },
}, },
{ {
displayName: ' Additional Fields', displayName: ' Additional Fields',
name: 'additionalFieldsJson', name: 'additionalFieldsJson',
type: 'json', type: 'json',
@ -153,10 +153,10 @@ export const companyFields = [
}, },
}, },
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.`, description: 'Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.',
}, },
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
type: 'collection', type: 'collection',
@ -238,7 +238,7 @@ export const companyFields = [
name: 'name', name: 'name',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: 'Company name', placeholder: 'Company name',
description: 'Company name.', description: 'Company name.',
}, },
@ -279,7 +279,7 @@ export const companyFields = [
name: 'subtype', name: 'subtype',
type: 'options', type: 'options',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Type of website.', description: 'Type of website.',
options: [ options: [
@ -334,7 +334,7 @@ export const companyFields = [
name: 'url', name: 'url',
type: 'string', type: 'string',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Website URL', description: 'Website URL',
} }
@ -371,7 +371,7 @@ export const companyFields = [
name: 'name', name: 'name',
type: 'string', type: 'string',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property name.' description: 'Property name.'
}, },
@ -380,7 +380,7 @@ export const companyFields = [
name: 'subtype', name: 'subtype',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property sub type.', description: 'Property sub type.',
}, },
@ -389,7 +389,7 @@ export const companyFields = [
name: 'value', name: 'value',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property value.', description: 'Property value.',
} }
@ -399,11 +399,11 @@ export const companyFields = [
] ]
}, },
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* company:delete */ /* company:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'company ID', displayName: 'company ID',
name: 'companyId', name: 'companyId',
type: 'string', type: 'string',
@ -420,11 +420,11 @@ export const companyFields = [
}, },
default: '', default: '',
description: 'Unique identifier for a particular company', description: 'Unique identifier for a particular company',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* company:update */ /* company:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'company ID', displayName: 'company ID',
name: 'companyId', name: 'companyId',
type: 'string', type: 'string',
@ -441,8 +441,8 @@ export const companyFields = [
}, },
default: '', default: '',
description: 'Unique identifier for a particular company', description: 'Unique identifier for a particular company',
}, },
{ {
displayName: 'JSON Parameters', displayName: 'JSON Parameters',
name: 'jsonParameters', name: 'jsonParameters',
type: 'boolean', type: 'boolean',
@ -458,8 +458,8 @@ export const companyFields = [
], ],
}, },
}, },
}, },
{ {
displayName: ' Additional Fields', displayName: ' Additional Fields',
name: 'additionalFieldsJson', name: 'additionalFieldsJson',
type: 'json', type: 'json',
@ -481,10 +481,10 @@ export const companyFields = [
}, },
}, },
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.`, description: 'Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-companys---companies-api" target="_blank">here</a>.',
}, },
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
type: 'collection', type: 'collection',
@ -566,7 +566,7 @@ export const companyFields = [
name: 'name', name: 'name',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: 'Company name', placeholder: 'Company name',
description: 'Company name.', description: 'Company name.',
}, },
@ -607,7 +607,7 @@ export const companyFields = [
name: 'subtype', name: 'subtype',
type: 'options', type: 'options',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Type of website.', description: 'Type of website.',
options: [ options: [
@ -662,7 +662,7 @@ export const companyFields = [
name: 'url', name: 'url',
type: 'string', type: 'string',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Website URL', description: 'Website URL',
} }
@ -699,7 +699,7 @@ export const companyFields = [
name: 'name', name: 'name',
type: 'string', type: 'string',
required: true, required: true,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property name.' description: 'Property name.'
}, },
@ -708,7 +708,7 @@ export const companyFields = [
name: 'subtype', name: 'subtype',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property sub type.', description: 'Property sub type.',
}, },
@ -717,7 +717,7 @@ export const companyFields = [
name: 'value', name: 'value',
type: 'string', type: 'string',
required: false, required: false,
default: "", default: '',
placeholder: '', placeholder: '',
description: 'Property value.', description: 'Property value.',
} }
@ -727,6 +727,6 @@ export const companyFields = [
] ]
}, },
], ],
}, },
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -1,6 +1,6 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const contactOperations = [ export const contactOperations = [
{ {
@ -110,11 +110,11 @@ export const contactFields = [
} }
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:create */ /* contact:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'JSON Parameters', displayName: 'JSON Parameters',
name: 'jsonParameters', name: 'jsonParameters',
type: 'boolean', type: 'boolean',
@ -130,8 +130,8 @@ export const contactFields = [
], ],
}, },
}, },
}, },
{ {
displayName: ' Additional Fields', displayName: ' Additional Fields',
name: 'additionalFieldsJson', name: 'additionalFieldsJson',
type: 'json', type: 'json',
@ -154,9 +154,9 @@ export const contactFields = [
}, },
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',
@ -566,11 +566,11 @@ export const contactFields = [
] ]
}, },
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:delete */ /* contact:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Contact ID', displayName: 'Contact ID',
name: 'contactId', name: 'contactId',
type: 'string', type: 'string',
@ -587,7 +587,7 @@ export const contactFields = [
}, },
default: '', default: '',
description: 'Unique identifier for a particular contact', 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;
} }