n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -1,6 +1,4 @@
import {
OptionsWithUri,
} from 'request';
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
@@ -9,22 +7,22 @@ import {
IWebhookFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeProperties,
INodePropertyOptions,
NodeApiError,
} from 'n8n-workflow';
import { IDataObject, INodeProperties, INodePropertyOptions, NodeApiError } from 'n8n-workflow';
import {
Address,
Filter,
FilterGroup,
ProductAttribute,
Search,
} from './Types';
import { Address, Filter, FilterGroup, ProductAttribute, Search } from './Types';
export async function magentoApiRequest(this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function magentoApiRequest(
this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
qs: IDataObject = {},
uri?: string,
headers: IDataObject = {},
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = await this.getCredentials('magento2Api');
let options: OptionsWithUri = {
@@ -47,8 +45,16 @@ export async function magentoApiRequest(this: IWebhookFunctions | IHookFunctions
}
}
export async function magentoApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, propertyName: string, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function magentoApiRequestAllItems(
this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions,
propertyName: string,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
@@ -56,10 +62,8 @@ export async function magentoApiRequestAllItems(this: IHookFunctions | ILoadOpti
do {
responseData = await magentoApiRequest.call(this, method, resource, body, query);
returnData.push.apply(returnData, responseData[propertyName]);
query['current_page'] = (query.current_page) ? (query.current_page as number)++ : 1;
} while (
returnData.length < responseData.total_count
);
query['current_page'] = query.current_page ? (query.current_page as number)++ : 1;
} while (returnData.length < responseData.total_count);
return returnData;
}
@@ -110,7 +114,8 @@ export function getAddressesUi(): INodeProperties {
displayName: 'Country Name or ID',
name: 'country_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getCountries',
},
@@ -189,7 +194,7 @@ export function getAddressesUi(): INodeProperties {
}
// tslint:disable-next-line: no-any
export function adjustAddresses(addresses: [{ street: string, [key: string]: string }]): Address[] {
export function adjustAddresses(addresses: [{ street: string; [key: string]: string }]): Address[] {
const _addresses: Address[] = [];
for (let i = 0; i < addresses.length; i++) {
if (addresses[i]?.region === '') {
@@ -203,7 +208,11 @@ export function adjustAddresses(addresses: [{ street: string, [key: string]: str
return _addresses;
}
export function getSearchFilters(resource: string, filterableAttributeFunction: string, sortableAttributeFunction: string): INodeProperties[] {
export function getSearchFilters(
resource: string,
filterableAttributeFunction: string,
sortableAttributeFunction: string,
): INodeProperties[] {
return [
{
displayName: 'Filter',
@@ -225,12 +234,8 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
],
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
resource: [resource],
operation: ['getAll'],
},
},
default: 'none',
@@ -251,15 +256,9 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
],
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
filterType: [
'manual',
],
resource: [resource],
operation: ['getAll'],
filterType: ['manual'],
},
},
default: 'anyFilter',
@@ -273,15 +272,9 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
},
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
filterType: [
'manual',
],
resource: [resource],
operation: ['getAll'],
filterType: ['manual'],
},
},
default: {},
@@ -290,27 +283,20 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
{
displayName: 'Conditions',
name: 'conditions',
values: [
...getConditions(filterableAttributeFunction),
],
values: [...getConditions(filterableAttributeFunction)],
},
],
},
{
displayName: 'See <a href="https://devdocs.magento.com/guides/v2.4/rest/performing-searches.html" target="_blank">Magento guide</a> to creating filters',
displayName:
'See <a href="https://devdocs.magento.com/guides/v2.4/rest/performing-searches.html" target="_blank">Magento guide</a> to creating filters',
name: 'jsonNotice',
type: 'notice',
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
filterType: [
'json',
],
resource: [resource],
operation: ['getAll'],
filterType: ['json'],
},
},
default: '',
@@ -324,15 +310,9 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
},
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
filterType: [
'json',
],
resource: [resource],
operation: ['getAll'],
filterType: ['json'],
},
},
default: '',
@@ -345,12 +325,8 @@ export function getSearchFilters(resource: string, filterableAttributeFunction:
default: {},
displayOptions: {
show: {
resource: [
resource,
],
operation: [
'getAll',
],
resource: [resource],
operation: ['getAll'],
},
},
options: [
@@ -494,10 +470,7 @@ function getConditions(attributeFunction: string): INodeProperties[] {
type: 'string',
displayOptions: {
hide: {
condition_type: [
'null',
'notnull',
],
condition_type: ['null', 'notnull'],
},
},
default: '',
@@ -505,8 +478,11 @@ function getConditions(attributeFunction: string): INodeProperties[] {
];
}
export function getFilterQuery(data: { conditions?: Filter[], matchType: string, sort: [{ direction: string, field: string }] }): Search {
export function getFilterQuery(data: {
conditions?: Filter[];
matchType: string;
sort: [{ direction: string; field: string }];
}): Search {
if (!data.hasOwnProperty('conditions') || data.conditions?.length === 0) {
throw new Error('At least one filter has to be set');
}
@@ -539,7 +515,8 @@ export function getFilterQuery(data: { conditions?: Filter[], matchType: string,
};
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
// tslint:disable-next-line:no-any
export function validateJSON(json: string | undefined): any {
let result;
try {
result = JSON.parse(json!);
@@ -582,7 +559,8 @@ export function getCustomerOptionalFields(): INodeProperties[] {
displayName: 'Attribute Code Name or ID',
name: 'attribute_code',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getCustomAttributes',
},
@@ -640,7 +618,8 @@ export function getCustomerOptionalFields(): INodeProperties[] {
displayName: 'Group Name or ID',
name: 'group_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getGroups',
},
@@ -674,7 +653,8 @@ export function getCustomerOptionalFields(): INodeProperties[] {
displayName: 'Store Name or ID',
name: 'store_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getStores',
},
@@ -702,12 +682,11 @@ export function getCustomerOptionalFields(): INodeProperties[] {
displayName: 'Website Name or ID',
name: 'website_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
displayOptions: {
show: {
'/operation': [
'create',
],
'/operation': ['create'],
},
},
typeOptions: {
@@ -724,12 +703,11 @@ export function getProductOptionalFields(): INodeProperties[] {
displayName: 'Attribute Set Name or ID',
name: 'attribute_set_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
displayOptions: {
show: {
'/operation': [
'update',
],
'/operation': ['update'],
},
},
typeOptions: {
@@ -743,9 +721,7 @@ export function getProductOptionalFields(): INodeProperties[] {
type: 'string',
displayOptions: {
show: {
'/operation': [
'update',
],
'/operation': ['update'],
},
},
default: '',
@@ -798,9 +774,7 @@ export function getProductOptionalFields(): INodeProperties[] {
type: 'number',
displayOptions: {
show: {
'/operation': [
'update',
],
'/operation': ['update'],
},
},
default: 0,
@@ -825,7 +799,8 @@ export function getProductOptionalFields(): INodeProperties[] {
displayName: 'Type Name or ID',
name: 'type_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getProductTypes',
},
@@ -1000,21 +975,38 @@ export function getOrderFields() {
];
}
export const sort = (a: { name: string }, b: { name: string }) => {
if (a.name < b.name) { return -1; }
if (a.name > b.name) { return 1; }
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
};
// tslint:disable-next-line: no-any
export async function getProductAttributes(this: ILoadOptionsFunctions, filter?: (attribute: ProductAttribute) => any, extraValue?: { name: string, value: string }): Promise<INodePropertyOptions[]> {
export async function getProductAttributes(
this: ILoadOptionsFunctions,
// tslint:disable-next-line:no-any
filter?: (attribute: ProductAttribute) => any,
extraValue?: { name: string; value: string },
): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/productsattribute-setssetslist#operation/catalogAttributeSetRepositoryV1GetListGet
let attributes: ProductAttribute[] = await magentoApiRequestAllItems.call(this, 'items', 'GET', `/rest/default/V1/products/attributes`, {}, {
search_criteria: 0,
});
let attributes: ProductAttribute[] = await magentoApiRequestAllItems.call(
this,
'items',
'GET',
`/rest/default/V1/products/attributes`,
{},
{
search_criteria: 0,
},
);
attributes = attributes.filter((attribute) =>
attribute.default_frontend_label !== undefined && attribute.default_frontend_label !== '');
attributes = attributes.filter(
(attribute) =>
attribute.default_frontend_label !== undefined && attribute.default_frontend_label !== '',
);
if (filter) {
attributes = attributes.filter(filter);