mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getCustomerOptionalFields,
|
||||
getSearchFilters,
|
||||
} from './GenericFunctions';
|
||||
import { getCustomerOptionalFields, getSearchFilters } from './GenericFunctions';
|
||||
|
||||
export const customerOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -15,9 +10,7 @@ export const customerOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
resource: ['customer'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -57,7 +50,6 @@ export const customerOperations: INodeProperties[] = [
|
||||
];
|
||||
|
||||
export const customerFields: INodeProperties[] = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* customer:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -70,12 +62,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Email address of the user to create',
|
||||
@@ -88,12 +76,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'First name of the user to create',
|
||||
@@ -106,12 +90,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Last name of the user to create',
|
||||
@@ -124,17 +104,11 @@ export const customerFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
...getCustomerOptionalFields(),
|
||||
],
|
||||
options: [...getCustomerOptionalFields()],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -147,12 +121,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the customer to update',
|
||||
@@ -165,12 +135,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -181,12 +147,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -197,12 +159,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -210,15 +168,12 @@ export const customerFields: 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: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -234,17 +189,11 @@ export const customerFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
...getCustomerOptionalFields(),
|
||||
],
|
||||
options: [...getCustomerOptionalFields()],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -258,13 +207,8 @@ export const customerFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
'get',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -278,12 +222,8 @@ export const customerFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -295,15 +235,9 @@ export const customerFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'customer',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['customer'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -313,9 +247,5 @@ export const customerFields: INodeProperties[] = [
|
||||
default: 5,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
...getSearchFilters(
|
||||
'customer',
|
||||
'getSystemAttributes',
|
||||
'getSystemAttributes',
|
||||
),
|
||||
...getSearchFilters('customer', 'getSystemAttributes', 'getSystemAttributes'),
|
||||
];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const invoiceOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -10,9 +8,7 @@ export const invoiceOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'invoice',
|
||||
],
|
||||
resource: ['invoice'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -28,7 +24,6 @@ export const invoiceOperations: INodeProperties[] = [
|
||||
];
|
||||
|
||||
export const invoiceFields: INodeProperties[] = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* invoice:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -40,12 +35,8 @@ export const invoiceFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'invoice',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['invoice'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
@@ -31,25 +26,13 @@ import {
|
||||
validateJSON,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
customerFields,
|
||||
customerOperations,
|
||||
} from './CustomerDescription';
|
||||
import { customerFields, customerOperations } from './CustomerDescription';
|
||||
|
||||
import {
|
||||
orderFields,
|
||||
orderOperations,
|
||||
} from './OrderDescription';
|
||||
import { orderFields, orderOperations } from './OrderDescription';
|
||||
|
||||
import {
|
||||
productFields,
|
||||
productOperations,
|
||||
} from './ProductDescription';
|
||||
import { productFields, productOperations } from './ProductDescription';
|
||||
|
||||
import {
|
||||
invoiceFields,
|
||||
invoiceOperations,
|
||||
} from './InvoiceDescription';
|
||||
import { invoiceFields, invoiceOperations } from './InvoiceDescription';
|
||||
|
||||
import {
|
||||
CustomAttribute,
|
||||
@@ -60,9 +43,7 @@ import {
|
||||
Search,
|
||||
} from './Types';
|
||||
|
||||
import {
|
||||
capitalCase,
|
||||
} from 'change-case';
|
||||
import { capitalCase } from 'change-case';
|
||||
|
||||
export class Magento2 implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -125,7 +106,11 @@ export class Magento2 implements INodeType {
|
||||
loadOptions: {
|
||||
async getCountries(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/directorycountries
|
||||
const countries = await magentoApiRequest.call(this, 'GET', '/rest/default/V1/directory/countries');
|
||||
const countries = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/rest/default/V1/directory/countries',
|
||||
);
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const country of countries) {
|
||||
returnData.push({
|
||||
@@ -138,7 +123,11 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/customerGroupsdefault#operation/customerGroupManagementV1GetDefaultGroupGet
|
||||
const group = await magentoApiRequest.call(this, 'GET', '/rest/default/V1/customerGroups/default');
|
||||
const group = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/rest/default/V1/customerGroups/default',
|
||||
);
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
returnData.push({
|
||||
name: group.code,
|
||||
@@ -149,7 +138,11 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getStores(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/storestoreConfigs
|
||||
const stores = await magentoApiRequest.call(this, 'GET', '/rest/default/V1/store/storeConfigs');
|
||||
const stores = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/rest/default/V1/store/storeConfigs',
|
||||
);
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const store of stores) {
|
||||
returnData.push({
|
||||
@@ -162,7 +155,11 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getWebsites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/storewebsites
|
||||
const websites = await magentoApiRequest.call(this, 'GET', '/rest/default/V1/store/websites');
|
||||
const websites = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/rest/default/V1/store/websites',
|
||||
);
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const website of websites) {
|
||||
returnData.push({
|
||||
@@ -176,7 +173,11 @@ export class Magento2 implements INodeType {
|
||||
async getCustomAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/attributeMetadatacustomer#operation/customerCustomerMetadataV1GetAllAttributesMetadataGet
|
||||
const resource = this.getCurrentNodeParameter('resource') as string;
|
||||
const attributes = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/attributeMetadata/${resource}`) as CustomerAttributeMetadata[];
|
||||
const attributes = (await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/attributeMetadata/${resource}`,
|
||||
)) as CustomerAttributeMetadata[];
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const attribute of attributes) {
|
||||
if (attribute.system === false && attribute.frontend_label !== '') {
|
||||
@@ -192,7 +193,11 @@ export class Magento2 implements INodeType {
|
||||
async getSystemAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/attributeMetadatacustomer#operation/customerCustomerMetadataV1GetAllAttributesMetadataGet
|
||||
const resource = this.getCurrentNodeParameter('resource') as string;
|
||||
const attributes = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/attributeMetadata/${resource}`) as CustomerAttributeMetadata[];
|
||||
const attributes = (await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/attributeMetadata/${resource}`,
|
||||
)) as CustomerAttributeMetadata[];
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const attribute of attributes) {
|
||||
if (attribute.system === true && attribute.frontend_label !== null) {
|
||||
@@ -207,7 +212,11 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getProductTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/productslinkstypes
|
||||
const types = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/products/types`) as IDataObject[];
|
||||
const types = (await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/products/types`,
|
||||
)) as IDataObject[];
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const type of types) {
|
||||
returnData.push({
|
||||
@@ -220,21 +229,27 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getCategories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/categories#operation/catalogCategoryManagementV1GetTreeGet
|
||||
const { items: categories } = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/categories/list`, {}, {
|
||||
search_criteria: {
|
||||
filter_groups: [
|
||||
{
|
||||
filters: [
|
||||
{
|
||||
field: 'is_active',
|
||||
condition_type: 'eq',
|
||||
value: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
const { items: categories } = (await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/categories/list`,
|
||||
{},
|
||||
{
|
||||
search_criteria: {
|
||||
filter_groups: [
|
||||
{
|
||||
filters: [
|
||||
{
|
||||
field: 'is_active',
|
||||
condition_type: 'eq',
|
||||
value: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}) as { items: IDataObject[] };
|
||||
)) as { items: IDataObject[] };
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const category of categories) {
|
||||
returnData.push({
|
||||
@@ -247,9 +262,15 @@ export class Magento2 implements INodeType {
|
||||
},
|
||||
async getAttributeSets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/productsattribute-setssetslist#operation/catalogAttributeSetRepositoryV1GetListGet
|
||||
const { items: attributeSets } = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/products/attribute-sets/sets/list`, {}, {
|
||||
search_criteria: 0,
|
||||
}) as { items: IDataObject[] };
|
||||
const { items: attributeSets } = (await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/products/attribute-sets/sets/list`,
|
||||
{},
|
||||
{
|
||||
search_criteria: 0,
|
||||
},
|
||||
)) as { items: IDataObject[] };
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const attributeSet of attributeSets) {
|
||||
returnData.push({
|
||||
@@ -260,7 +281,9 @@ export class Magento2 implements INodeType {
|
||||
returnData.sort(sort);
|
||||
return returnData;
|
||||
},
|
||||
async getFilterableCustomerAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
async getFilterableCustomerAttributes(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
return getProductAttributes.call(this, (attribute) => attribute.is_filterable === true);
|
||||
},
|
||||
async getProductAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
@@ -269,14 +292,20 @@ export class Magento2 implements INodeType {
|
||||
// async getProductAttributesFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
// return getProductAttributes.call(this, undefined, { name: '*', value: '*', description: 'All properties' });
|
||||
// },
|
||||
async getFilterableProductAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
async getFilterableProductAttributes(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
return getProductAttributes.call(this, (attribute) => attribute.is_searchable === '1');
|
||||
},
|
||||
async getSortableProductAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
async getSortableProductAttributes(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
return getProductAttributes.call(this, (attribute) => attribute.used_for_sort_by === true);
|
||||
},
|
||||
async getOrderAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
return getOrderFields().map(field => ({ name: capitalCase(field), value: field })).sort(sort);
|
||||
return getOrderFields()
|
||||
.map((field) => ({ name: capitalCase(field), value: field }))
|
||||
.sort(sort);
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -299,21 +328,21 @@ export class Magento2 implements INodeType {
|
||||
const firstname = this.getNodeParameter('firstname', i) as string;
|
||||
const lastname = this.getNodeParameter('lastname', i) as string;
|
||||
|
||||
const {
|
||||
addresses,
|
||||
customAttributes,
|
||||
password,
|
||||
...rest
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
const { addresses, customAttributes, password, ...rest } = this.getNodeParameter(
|
||||
'additionalFields',
|
||||
i,
|
||||
) as {
|
||||
addresses: {
|
||||
address: [{
|
||||
street: string,
|
||||
}]
|
||||
address: [
|
||||
{
|
||||
street: string;
|
||||
},
|
||||
];
|
||||
};
|
||||
customAttributes: {
|
||||
customAttribute: CustomAttribute[],
|
||||
},
|
||||
password: string,
|
||||
customAttribute: CustomAttribute[];
|
||||
};
|
||||
password: string;
|
||||
};
|
||||
|
||||
const body: NewCustomer = {
|
||||
@@ -328,7 +357,12 @@ export class Magento2 implements INodeType {
|
||||
|
||||
body.customer!.custom_attributes = customAttributes?.customAttribute || {};
|
||||
|
||||
body.customer!.extension_attributes = ['amazon_id', 'is_subscribed', 'vertex_customer_code', 'vertex_customer_country']
|
||||
body.customer!.extension_attributes = [
|
||||
'amazon_id',
|
||||
'is_subscribed',
|
||||
'vertex_customer_code',
|
||||
'vertex_customer_country',
|
||||
]
|
||||
// tslint:disable-next-line: no-any
|
||||
.reduce((obj, value: string): any => {
|
||||
if ((rest as IDataObject).hasOwnProperty(value)) {
|
||||
@@ -353,7 +387,11 @@ export class Magento2 implements INodeType {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1SavePut
|
||||
const customerId = this.getNodeParameter('customerId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'DELETE', `/rest/default/V1/customers/${customerId}`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/rest/default/V1/customers/${customerId}`,
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
@@ -362,13 +400,19 @@ export class Magento2 implements INodeType {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1GetByIdGet
|
||||
const customerId = this.getNodeParameter('customerId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/customers/${customerId}`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/customers/${customerId}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/customerssearch
|
||||
const filterType = this.getNodeParameter('filterType', i) as string;
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as { sort: [{ direction: string, field: string }] };
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as {
|
||||
sort: [{ direction: string; field: string }];
|
||||
};
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
let qs: Search = {};
|
||||
|
||||
@@ -381,7 +425,9 @@ export class Magento2 implements INodeType {
|
||||
if (validateJSON(filterJson) !== undefined) {
|
||||
qs = JSON.parse(filterJson);
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), { message: 'Filter (JSON) must be a valid json' });
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'Filter (JSON) must be a valid json',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qs = {
|
||||
@@ -397,12 +443,24 @@ export class Magento2 implements INodeType {
|
||||
|
||||
if (returnAll === true) {
|
||||
qs.search_criteria!.page_size = 100;
|
||||
responseData = await magentoApiRequestAllItems.call(this, 'items', 'GET', `/rest/default/V1/customers/search`, {}, qs as unknown as IDataObject);
|
||||
|
||||
responseData = await magentoApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/rest/default/V1/customers/search`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0) as number;
|
||||
qs.search_criteria!.page_size = limit;
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/customers/search`, {}, qs as unknown as IDataObject);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/customers/search`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
}
|
||||
@@ -414,21 +472,21 @@ export class Magento2 implements INodeType {
|
||||
const lastName = this.getNodeParameter('lastName', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
|
||||
const {
|
||||
addresses,
|
||||
customAttributes,
|
||||
password,
|
||||
...rest
|
||||
} = this.getNodeParameter('updateFields', i) as {
|
||||
const { addresses, customAttributes, password, ...rest } = this.getNodeParameter(
|
||||
'updateFields',
|
||||
i,
|
||||
) as {
|
||||
addresses: {
|
||||
address: [{
|
||||
street: string,
|
||||
}]
|
||||
address: [
|
||||
{
|
||||
street: string;
|
||||
},
|
||||
];
|
||||
};
|
||||
customAttributes: {
|
||||
customAttribute: CustomAttribute[],
|
||||
},
|
||||
password: string,
|
||||
customAttribute: CustomAttribute[];
|
||||
};
|
||||
password: string;
|
||||
};
|
||||
|
||||
const body: NewCustomer = {
|
||||
@@ -445,7 +503,12 @@ export class Magento2 implements INodeType {
|
||||
|
||||
body.customer!.custom_attributes = customAttributes?.customAttribute || {};
|
||||
|
||||
body.customer!.extension_attributes = ['amazon_id', 'is_subscribed', 'vertex_customer_code', 'vertex_customer_country']
|
||||
body.customer!.extension_attributes = [
|
||||
'amazon_id',
|
||||
'is_subscribed',
|
||||
'vertex_customer_code',
|
||||
'vertex_customer_country',
|
||||
]
|
||||
// tslint:disable-next-line: no-any
|
||||
.reduce((obj, value: string): any => {
|
||||
if ((rest as IDataObject).hasOwnProperty(value)) {
|
||||
@@ -463,7 +526,12 @@ export class Magento2 implements INodeType {
|
||||
|
||||
Object.assign(body.customer, rest);
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'PUT', `/rest/V1/customers/${customerId}`, body);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/rest/V1/customers/${customerId}`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,19 +540,26 @@ export class Magento2 implements INodeType {
|
||||
///https://magento.redoc.ly/2.3.7-admin/tag/orderorderIdinvoice
|
||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'POST', `/rest/default/V1/order/${orderId}/invoice`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/rest/default/V1/order/${orderId}/invoice`,
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'order') {
|
||||
|
||||
if (operation === 'cancel') {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/ordersidcancel
|
||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'POST', `/rest/default/V1/orders/${orderId}/cancel`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/rest/default/V1/orders/${orderId}/cancel`,
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
@@ -493,14 +568,22 @@ export class Magento2 implements INodeType {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/ordersid#operation/salesOrderRepositoryV1GetGet
|
||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/orders/${orderId}`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/orders/${orderId}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (operation === 'ship') {
|
||||
///https://magento.redoc.ly/2.3.7-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost
|
||||
const orderId = this.getNodeParameter('orderId', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'POST', `/rest/default/V1/order/${orderId}/ship`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/rest/default/V1/order/${orderId}/ship`,
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
@@ -508,7 +591,9 @@ export class Magento2 implements INodeType {
|
||||
if (operation === 'getAll') {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/orders#operation/salesOrderRepositoryV1GetListGet
|
||||
const filterType = this.getNodeParameter('filterType', i) as string;
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as { sort: [{ direction: string, field: string }] };
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as {
|
||||
sort: [{ direction: string; field: string }];
|
||||
};
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
let qs: Search = {};
|
||||
|
||||
@@ -521,7 +606,9 @@ export class Magento2 implements INodeType {
|
||||
if (validateJSON(filterJson) !== undefined) {
|
||||
qs = JSON.parse(filterJson);
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), { message: 'Filter (JSON) must be a valid json' });
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'Filter (JSON) must be a valid json',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qs = {
|
||||
@@ -536,12 +623,24 @@ export class Magento2 implements INodeType {
|
||||
|
||||
if (returnAll === true) {
|
||||
qs.search_criteria!.page_size = 100;
|
||||
responseData = await magentoApiRequestAllItems.call(this, 'items', 'GET', `/rest/default/V1/orders`, {}, qs as unknown as IDataObject);
|
||||
|
||||
responseData = await magentoApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/rest/default/V1/orders`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0) as number;
|
||||
qs.search_criteria!.page_size = limit;
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/orders`, {}, qs as unknown as IDataObject);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/orders`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
}
|
||||
@@ -555,15 +654,14 @@ export class Magento2 implements INodeType {
|
||||
const attributeSetId = this.getNodeParameter('attributeSetId', i) as string;
|
||||
const price = this.getNodeParameter('price', i) as number;
|
||||
|
||||
const {
|
||||
customAttributes,
|
||||
category,
|
||||
...rest
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
const { customAttributes, category, ...rest } = this.getNodeParameter(
|
||||
'additionalFields',
|
||||
i,
|
||||
) as {
|
||||
customAttributes: {
|
||||
customAttribute: CustomAttribute[],
|
||||
},
|
||||
category: string,
|
||||
customAttribute: CustomAttribute[];
|
||||
};
|
||||
category: string;
|
||||
};
|
||||
|
||||
const body: NewProduct = {
|
||||
@@ -579,14 +677,23 @@ export class Magento2 implements INodeType {
|
||||
|
||||
Object.assign(body.product, rest);
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'POST', '/rest/default/V1/products', body);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/rest/default/V1/products',
|
||||
body,
|
||||
);
|
||||
}
|
||||
|
||||
if (operation === 'delete') {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1DeleteByIdDelete
|
||||
const sku = this.getNodeParameter('sku', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'DELETE', `/rest/default/V1/products/${sku}`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/rest/default/V1/products/${sku}`,
|
||||
);
|
||||
|
||||
responseData = { success: true };
|
||||
}
|
||||
@@ -595,13 +702,19 @@ export class Magento2 implements INodeType {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1GetGet
|
||||
const sku = this.getNodeParameter('sku', i) as string;
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/products/${sku}`);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/products/${sku}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/customerssearch
|
||||
const filterType = this.getNodeParameter('filterType', i) as string;
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as { sort: [{ direction: string, field: string }] };
|
||||
const sort = this.getNodeParameter('options.sort', i, {}) as {
|
||||
sort: [{ direction: string; field: string }];
|
||||
};
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
let qs: Search = {};
|
||||
|
||||
@@ -614,7 +727,9 @@ export class Magento2 implements INodeType {
|
||||
if (validateJSON(filterJson) !== undefined) {
|
||||
qs = JSON.parse(filterJson);
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), { message: 'Filter (JSON) must be a valid json' });
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'Filter (JSON) must be a valid json',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
qs = {
|
||||
@@ -629,12 +744,24 @@ export class Magento2 implements INodeType {
|
||||
|
||||
if (returnAll === true) {
|
||||
qs.search_criteria!.page_size = 100;
|
||||
responseData = await magentoApiRequestAllItems.call(this, 'items', 'GET', `/rest/default/V1/products`, {}, qs as unknown as IDataObject);
|
||||
|
||||
responseData = await magentoApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/rest/default/V1/products`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0) as number;
|
||||
qs.search_criteria!.page_size = limit;
|
||||
responseData = await magentoApiRequest.call(this, 'GET', `/rest/default/V1/products`, {}, qs as unknown as IDataObject);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/rest/default/V1/products`,
|
||||
{},
|
||||
qs as unknown as IDataObject,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
}
|
||||
@@ -643,17 +770,16 @@ export class Magento2 implements INodeType {
|
||||
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1SavePut
|
||||
const sku = this.getNodeParameter('sku', i) as string;
|
||||
|
||||
const {
|
||||
customAttributes,
|
||||
...rest
|
||||
} = this.getNodeParameter('updateFields', i) as {
|
||||
const { customAttributes, ...rest } = this.getNodeParameter('updateFields', i) as {
|
||||
customAttributes: {
|
||||
customAttribute: CustomAttribute[],
|
||||
},
|
||||
customAttribute: CustomAttribute[];
|
||||
};
|
||||
};
|
||||
|
||||
if (!Object.keys(rest).length) {
|
||||
throw new NodeApiError(this.getNode(), { message: 'At least one parameter has to be updated' });
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'At least one parameter has to be updated',
|
||||
});
|
||||
}
|
||||
|
||||
const body: NewProduct = {
|
||||
@@ -666,14 +792,18 @@ export class Magento2 implements INodeType {
|
||||
|
||||
Object.assign(body.product, rest);
|
||||
|
||||
responseData = await magentoApiRequest.call(this, 'PUT', `/rest/default/V1/products/${sku}`, body);
|
||||
responseData = await magentoApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/rest/default/V1/products/${sku}`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Array.isArray(responseData)
|
||||
? returnData.push(...responseData)
|
||||
: returnData.push(responseData);
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getSearchFilters,
|
||||
} from './GenericFunctions';
|
||||
import { getSearchFilters } from './GenericFunctions';
|
||||
|
||||
export const orderOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -14,9 +10,7 @@ export const orderOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'order',
|
||||
],
|
||||
resource: ['order'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -50,7 +44,6 @@ export const orderOperations: INodeProperties[] = [
|
||||
];
|
||||
|
||||
export const orderFields: INodeProperties[] = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* order:cancel */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -62,14 +55,8 @@ export const orderFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'order',
|
||||
],
|
||||
operation: [
|
||||
'cancel',
|
||||
'get',
|
||||
'ship',
|
||||
],
|
||||
resource: ['order'],
|
||||
operation: ['cancel', 'get', 'ship'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -83,12 +70,8 @@ export const orderFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'order',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['order'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -100,15 +83,9 @@ export const orderFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'order',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['order'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -118,10 +95,5 @@ export const orderFields: INodeProperties[] = [
|
||||
default: 5,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
...getSearchFilters(
|
||||
'order',
|
||||
'getOrderAttributes',
|
||||
'getOrderAttributes',
|
||||
),
|
||||
|
||||
...getSearchFilters('order', 'getOrderAttributes', 'getOrderAttributes'),
|
||||
];
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getProductOptionalFields,
|
||||
getSearchFilters,
|
||||
} from './GenericFunctions';
|
||||
import { getProductOptionalFields, getSearchFilters } from './GenericFunctions';
|
||||
|
||||
export const productOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -15,9 +10,7 @@ export const productOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
resource: ['product'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -57,7 +50,6 @@ export const productOperations: INodeProperties[] = [
|
||||
];
|
||||
|
||||
export const productFields: INodeProperties[] = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* product:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -69,13 +61,8 @@ export const productFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
'update',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Stock-keeping unit of the product',
|
||||
@@ -87,12 +74,8 @@ export const productFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -101,15 +84,12 @@ export const productFields: INodeProperties[] = [
|
||||
displayName: 'Attribute Set Name or ID',
|
||||
name: 'attributeSetId',
|
||||
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: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -123,12 +103,8 @@ export const productFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: 0,
|
||||
@@ -141,17 +117,11 @@ export const productFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
...getProductOptionalFields(),
|
||||
],
|
||||
options: [...getProductOptionalFields()],
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
@@ -161,17 +131,11 @@ export const productFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
...getProductOptionalFields(),
|
||||
],
|
||||
options: [...getProductOptionalFields()],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -185,13 +149,8 @@ export const productFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
'get',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description: 'Stock-keeping unit of the product',
|
||||
@@ -206,12 +165,8 @@ export const productFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -223,15 +178,9 @@ export const productFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'product',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['product'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -245,6 +194,6 @@ export const productFields: INodeProperties[] = [
|
||||
'product',
|
||||
//'getProductAttributesFields',
|
||||
'getFilterableProductAttributes',
|
||||
'getSortableProductAttributes'),
|
||||
|
||||
'getSortableProductAttributes',
|
||||
),
|
||||
];
|
||||
|
||||
20
packages/nodes-base/nodes/Magento/Types.d.ts
vendored
20
packages/nodes-base/nodes/Magento/Types.d.ts
vendored
@@ -1,4 +1,3 @@
|
||||
|
||||
export interface NewCustomer {
|
||||
customer?: Customer;
|
||||
password?: string;
|
||||
@@ -121,8 +120,7 @@ export interface CustomerAttributeMetadataOption {
|
||||
options?: OptionOption[];
|
||||
}
|
||||
|
||||
export interface OptionOption {
|
||||
}
|
||||
export interface OptionOption {}
|
||||
|
||||
export interface ValidationRule {
|
||||
name?: string;
|
||||
@@ -174,19 +172,21 @@ export interface Product {
|
||||
updated_at?: string;
|
||||
weight?: number;
|
||||
extension_attributes?: {
|
||||
category_links?: [{
|
||||
category_id?: string,
|
||||
}]
|
||||
}
|
||||
category_links?: [
|
||||
{
|
||||
category_id?: string;
|
||||
},
|
||||
];
|
||||
};
|
||||
custom_attributes?: CustomAttribute[];
|
||||
}
|
||||
|
||||
export interface ProductAttribute {
|
||||
is_filterable_in_search: boolean,
|
||||
is_filterable_in_search: boolean;
|
||||
default_frontend_label: string;
|
||||
attribute_id: string;
|
||||
is_filterable: boolean;
|
||||
used_for_sort_by: boolean;
|
||||
is_searchable: string,
|
||||
attribute_code: string,
|
||||
is_searchable: string;
|
||||
attribute_code: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user