mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
@@ -17,26 +15,30 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
ICouponLine,
|
||||
IFeeLine,
|
||||
ILineItem,
|
||||
IShoppingLine,
|
||||
} from './OrderInterface';
|
||||
import { ICouponLine, IFeeLine, ILineItem, IShoppingLine } from './OrderInterface';
|
||||
|
||||
import {
|
||||
createHash,
|
||||
} from 'crypto';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
import {
|
||||
snakeCase,
|
||||
} from 'change-case';
|
||||
import { snakeCase } from 'change-case';
|
||||
|
||||
import {
|
||||
omit
|
||||
} from 'lodash';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function woocommerceApiRequest(
|
||||
this:
|
||||
| IHookFunctions
|
||||
| IExecuteFunctions
|
||||
| IExecuteSingleFunctions
|
||||
| ILoadOptionsFunctions
|
||||
| IWebhookFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('wooCommerceApi');
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
@@ -52,21 +54,30 @@ export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunct
|
||||
}
|
||||
options = Object.assign({}, options, option);
|
||||
try {
|
||||
return await this.helpers.requestWithAuthentication.call(this,'wooCommerceApi', options);
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'wooCommerceApi', options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function woocommerceApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function woocommerceApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
let uri: string | undefined;
|
||||
query.per_page = 100;
|
||||
do {
|
||||
responseData = await woocommerceApiRequest.call(this, method, endpoint, body, query, uri, { resolveWithFullResponse: true });
|
||||
responseData = await woocommerceApiRequest.call(this, method, endpoint, body, query, uri, {
|
||||
resolveWithFullResponse: true,
|
||||
});
|
||||
const links = responseData.headers.link.split(',');
|
||||
const nextLink = links.find((link: string) => link.indexOf('rel="next"') !== -1);
|
||||
if (nextLink) {
|
||||
@@ -93,12 +104,9 @@ export function getAutomaticSecret(credentials: ICredentialDataDecryptedObject)
|
||||
return createHash('md5').update(data).digest('hex');
|
||||
}
|
||||
|
||||
export function setMetadata(data:
|
||||
IShoppingLine[] |
|
||||
IShoppingLine[] |
|
||||
IFeeLine[] |
|
||||
ILineItem[] |
|
||||
ICouponLine[]) {
|
||||
export function setMetadata(
|
||||
data: IShoppingLine[] | IShoppingLine[] | IFeeLine[] | ILineItem[] | ICouponLine[],
|
||||
) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
//@ts-ignore\
|
||||
if (data[i].metadataUi && data[i].metadataUi.metadataValues) {
|
||||
@@ -113,13 +121,9 @@ export function setMetadata(data:
|
||||
}
|
||||
}
|
||||
|
||||
export function toSnakeCase(data:
|
||||
IShoppingLine[] |
|
||||
IShoppingLine[] |
|
||||
IFeeLine[] |
|
||||
ILineItem[] |
|
||||
ICouponLine[] |
|
||||
IDataObject) {
|
||||
export function toSnakeCase(
|
||||
data: IShoppingLine[] | IShoppingLine[] | IFeeLine[] | ILineItem[] | ICouponLine[] | IDataObject,
|
||||
) {
|
||||
if (!Array.isArray(data)) {
|
||||
data = [data];
|
||||
}
|
||||
@@ -142,13 +146,12 @@ export function toSnakeCase(data:
|
||||
}
|
||||
|
||||
export function setFields(fieldsToSet: IDataObject, body: IDataObject) {
|
||||
for(const fields in fieldsToSet) {
|
||||
for (const fields in fieldsToSet) {
|
||||
if (fields === 'tags') {
|
||||
body['tags'] = (fieldsToSet[fields] as string[]).map(tag => ({id: parseInt(tag, 10)}));
|
||||
body['tags'] = (fieldsToSet[fields] as string[]).map((tag) => ({ id: parseInt(tag, 10) }));
|
||||
} else {
|
||||
body[snakeCase(fields.toString())] = fieldsToSet[fields];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,5 +167,5 @@ export function adjustMetadata(fields: IDataObject & Metadata) {
|
||||
type Metadata = {
|
||||
meta_data?: {
|
||||
meta_data_fields: Array<{ key: string; value: string }>;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user