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",
"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 {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IDataObject
INodeTypeDescription
} from 'n8n-workflow';
import {
contactOperations,
contactFields
contactFields,
contactOperations
} from './ContactDescription';
import {
companyOperations,
companyFields
companyFields,
companyOperations
} from './CompanyDescription';
import {
dealOperations,
dealFields
dealFields,
dealOperations
} from './DealDescription';
import { agileCrmApiRequest, validateJSON, agileCrmApiRequestUpdate} from './GenericFunctions';
import { IContact, IProperty, IContactUpdate } from './ContactInterface';
import { IContact, IContactUpdate } from './ContactInterface';
import { agileCrmApiRequest, agileCrmApiRequestUpdate, validateJSON} from './GenericFunctions';
import { IDeal } from './DealInterface';
@ -92,14 +92,13 @@ export class AgileCrm implements INodeType {
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let responseData;
const qs: IDataObject = {};
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 === 'contact' || resource === 'company'){
let idGetter = resource === 'contact' ? 'contactId' : 'companyId';
const idGetter = resource === 'contact' ? 'contactId' : 'companyId';
if(operation === 'get'){
const contactId = this.getNodeParameter(idGetter, i) as string;
@ -122,7 +121,7 @@ export class AgileCrm implements INodeType {
if(resource === 'contact'){
if (returnAll) {
const endpoint = `api/contacts`;
const endpoint = 'api/contacts';
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
} else {
const limit = this.getNodeParameter('limit', i) as number;
@ -131,7 +130,7 @@ export class AgileCrm implements INodeType {
}
} else {
if (returnAll) {
const endpoint = `api/contacts/companies/list`;
const endpoint = 'api/contacts/companies/list';
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, {});
} else {
const limit = this.getNodeParameter('limit', i) as number;
@ -145,7 +144,7 @@ export class AgileCrm implements INodeType {
if(operation === 'create'){
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
const body: IContact = {};
let properties : IDataObject[] = [];
const properties : IDataObject[] = [];
if (jsonParameters) {
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
@ -218,7 +217,7 @@ export class AgileCrm implements INodeType {
name: 'email',
value: property.email as string
} as IDataObject);
})
});
}
if(additionalFields.addressOptions){
//@ts-ignore
@ -229,7 +228,7 @@ export class AgileCrm implements INodeType {
name: 'address',
value: property.address as string
} as IDataObject);
})
});
}
if(additionalFields.phoneOptions){
@ -241,7 +240,7 @@ export class AgileCrm implements INodeType {
name: 'phone',
value: property.number as string
} as IDataObject);
})
});
}
} else if (resource === 'company') {
if(additionalFields.email){
@ -279,7 +278,7 @@ export class AgileCrm implements INodeType {
name: 'webiste',
value: property.url as string
} as IDataObject);
})
});
}
if(additionalFields.customProperties){
@ -291,7 +290,7 @@ export class AgileCrm implements INodeType {
name: property.name,
value: property.value as string
} as IDataObject);
})
});
}
body.properties = properties;
@ -302,10 +301,10 @@ export class AgileCrm implements INodeType {
if(operation === 'update') {
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 body: IContact = {};
let properties : IDataObject[] = [];
const properties : IDataObject[] = [];
if (jsonParameters) {
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
@ -372,7 +371,7 @@ export class AgileCrm implements INodeType {
name: 'email',
value: property.email as string
} as IDataObject);
})
});
}
if(additionalFields.addressOptions){
//@ts-ignore
@ -383,7 +382,7 @@ export class AgileCrm implements INodeType {
name: 'address',
value: property.address as string
} as IDataObject);
})
});
}
if(additionalFields.phoneOptions){
@ -395,7 +394,7 @@ export class AgileCrm implements INodeType {
name: 'phone',
value: property.number as string
} as IDataObject);
})
});
}
} else if (resource === 'company') {
if(additionalFields.email){
@ -433,7 +432,7 @@ export class AgileCrm implements INodeType {
name: 'webiste',
value: property.url as string
} as IDataObject);
})
});
}
if(additionalFields.customProperties){
//@ts-ignore
@ -444,7 +443,7 @@ export class AgileCrm implements INodeType {
name: property.name,
value: property.value as string
} as IDataObject);
})
});
}
body.properties = properties;
}
@ -476,7 +475,7 @@ export class AgileCrm implements INodeType {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll) {
const endpoint = `api/opportunity`;
const endpoint = 'api/opportunity';
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
} else {
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);
}
@ -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);
}
}

View file

@ -1,6 +1,6 @@
import {
INodeProperties,
} from 'n8n-workflow';
} from 'n8n-workflow';
export const companyOperations = [
{
@ -70,9 +70,9 @@ export const companyFields = [
},
/* -------------------------------------------------------------------------- */
/* company:get all */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* company:get all */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
@ -110,11 +110,11 @@ export const companyFields = [
}
},
/* -------------------------------------------------------------------------- */
/* company:create */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* company:create */
/* -------------------------------------------------------------------------- */
{
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
@ -130,8 +130,8 @@ export const companyFields = [
],
},
},
},
{
},
{
displayName: ' Additional Fields',
name: 'additionalFieldsJson',
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',
name: 'additionalFields',
type: 'collection',
@ -238,7 +238,7 @@ export const companyFields = [
name: 'name',
type: 'string',
required: false,
default: "",
default: '',
placeholder: 'Company name',
description: 'Company name.',
},
@ -279,7 +279,7 @@ export const companyFields = [
name: 'subtype',
type: 'options',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Type of website.',
options: [
@ -334,7 +334,7 @@ export const companyFields = [
name: 'url',
type: 'string',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Website URL',
}
@ -371,7 +371,7 @@ export const companyFields = [
name: 'name',
type: 'string',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Property name.'
},
@ -380,7 +380,7 @@ export const companyFields = [
name: 'subtype',
type: 'string',
required: false,
default: "",
default: '',
placeholder: '',
description: 'Property sub type.',
},
@ -389,7 +389,7 @@ export const companyFields = [
name: 'value',
type: 'string',
required: false,
default: "",
default: '',
placeholder: '',
description: 'Property value.',
}
@ -399,11 +399,11 @@ export const companyFields = [
]
},
],
},
/* -------------------------------------------------------------------------- */
/* company:delete */
/* -------------------------------------------------------------------------- */
{
},
/* -------------------------------------------------------------------------- */
/* company:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'company ID',
name: 'companyId',
type: 'string',
@ -420,11 +420,11 @@ export const companyFields = [
},
default: '',
description: 'Unique identifier for a particular company',
},
/* -------------------------------------------------------------------------- */
/* company:update */
/* -------------------------------------------------------------------------- */
{
},
/* -------------------------------------------------------------------------- */
/* company:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'company ID',
name: 'companyId',
type: 'string',
@ -441,8 +441,8 @@ export const companyFields = [
},
default: '',
description: 'Unique identifier for a particular company',
},
{
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
@ -458,8 +458,8 @@ export const companyFields = [
],
},
},
},
{
},
{
displayName: ' Additional Fields',
name: 'additionalFieldsJson',
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',
name: 'additionalFields',
type: 'collection',
@ -566,7 +566,7 @@ export const companyFields = [
name: 'name',
type: 'string',
required: false,
default: "",
default: '',
placeholder: 'Company name',
description: 'Company name.',
},
@ -607,7 +607,7 @@ export const companyFields = [
name: 'subtype',
type: 'options',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Type of website.',
options: [
@ -662,7 +662,7 @@ export const companyFields = [
name: 'url',
type: 'string',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Website URL',
}
@ -699,7 +699,7 @@ export const companyFields = [
name: 'name',
type: 'string',
required: true,
default: "",
default: '',
placeholder: '',
description: 'Property name.'
},
@ -708,7 +708,7 @@ export const companyFields = [
name: 'subtype',
type: 'string',
required: false,
default: "",
default: '',
placeholder: '',
description: 'Property sub type.',
},
@ -717,7 +717,7 @@ export const companyFields = [
name: 'value',
type: 'string',
required: false,
default: "",
default: '',
placeholder: '',
description: 'Property value.',
}
@ -727,6 +727,6 @@ export const companyFields = [
]
},
],
},
},
] as INodeProperties[];

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import {
OptionsWithUri,
OptionsWithUri
} from 'request';
import {
@ -12,7 +12,7 @@ import {
import {
IDataObject,
} 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> {
@ -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 credentials = this.getCredentials('agileCrmApi');
const options: OptionsWithUri = {
@ -68,9 +68,9 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
json: true
};
let successfulUpdates = [];
const successfulUpdates = [];
let lastSuccesfulUpdateReturn : any;
let payload : IContactUpdate = body;
const payload : IContactUpdate = body;
try {
// 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"
payload.properties?.map((property : any) => {
successfulUpdates.push(`${property.name} `);
})
});
delete options.body.properties;
}
@ -102,7 +102,7 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu
payload.tags?.map((tag : string) => {
successfulUpdates.push(`(Tag) ${tag} `);
})
});
delete options.body.tags;
}