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

@@ -9,17 +9,30 @@ import {
IWebhookFunctions,
} from 'n8n-core';
import {
IDataObject, NodeApiError, NodeOperationError,
} from 'n8n-workflow';
export async function payPalApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
export async function payPalApiRequest(
this:
| IHookFunctions
| IExecuteFunctions
| IExecuteSingleFunctions
| ILoadOptionsFunctions
| IWebhookFunctions,
endpoint: string,
method: string,
// tslint:disable-next-line:no-any
body: any = {},
query?: IDataObject,
uri?: string,
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = await this.getCredentials('payPalApi');
const env = getEnvironment(credentials.env as string);
const tokenInfo = await getAccessToken.call(this);
const headerWithAuthentication = Object.assign({ },
{ Authorization: `Bearer ${tokenInfo.access_token}`, 'Content-Type': 'application/json' });
const tokenInfo = await getAccessToken.call(this);
const headerWithAuthentication = Object.assign(
{},
{ Authorization: `Bearer ${tokenInfo.access_token}`, 'Content-Type': 'application/json' },
);
const options = {
headers: headerWithAuthentication,
method,
@@ -38,26 +51,38 @@ export async function payPalApiRequest(this: IHookFunctions | IExecuteFunctions
function getEnvironment(env: string): string {
// @ts-ignore
return {
'sanbox': 'https://api-m.sandbox.paypal.com',
'live': 'https://api-m.paypal.com',
sanbox: 'https://api-m.sandbox.paypal.com',
live: 'https://api-m.paypal.com',
}[env];
}
async function getAccessToken(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions): Promise<any> { // tslint:disable-line:no-any
async function getAccessToken(
this:
| IHookFunctions
| IExecuteFunctions
| IExecuteSingleFunctions
| ILoadOptionsFunctions
| IWebhookFunctions,
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = await this.getCredentials('payPalApi');
const env = getEnvironment(credentials!.env as string);
const data = Buffer.from(`${credentials!.clientId}:${credentials!.secret}`).toString(BINARY_ENCODING);
const headerWithAuthentication = Object.assign({},
{ Authorization: `Basic ${data}`, 'Content-Type': 'application/x-www-form-urlencoded' });
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method: 'POST',
form: {
grant_type: 'client_credentials',
},
uri: `${env}/v1/oauth2/token`,
json: true,
};
const data = Buffer.from(`${credentials!.clientId}:${credentials!.secret}`).toString(
BINARY_ENCODING,
);
const headerWithAuthentication = Object.assign(
{},
{ Authorization: `Basic ${data}`, 'Content-Type': 'application/x-www-form-urlencoded' },
);
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method: 'POST',
form: {
grant_type: 'client_credentials',
},
uri: `${env}/v1/oauth2/token`,
json: true,
};
try {
return await this.helpers.request!(options);
} catch (error) {
@@ -69,8 +94,17 @@ async function getAccessToken(this: IHookFunctions | IExecuteFunctions | IExecut
* Make an API request to paginated paypal endpoint
* and return all results
*/
export async function payPalApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
export async function payPalApiRequestAllItems(
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
propertyName: string,
endpoint: string,
method: string,
// tslint:disable-next-line:no-any
body: any = {},
query?: IDataObject,
uri?: string,
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
@@ -81,9 +115,7 @@ export async function payPalApiRequestAllItems(this: IHookFunctions | IExecuteFu
responseData = await payPalApiRequest.call(this, endpoint, method, body, query, uri);
uri = getNext(responseData.links);
returnData.push.apply(returnData, responseData[propertyName]);
} while (
getNext(responseData.links) !== undefined
);
} while (getNext(responseData.links) !== undefined);
return returnData;
}
@@ -97,7 +129,8 @@ function getNext(links: IDataObject[]): string | undefined {
return undefined;
}
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!);
@@ -108,7 +141,10 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
}
export function upperFist(s: string): string {
return s.split('.').map(e => {
return e.toLowerCase().charAt(0).toUpperCase() + e.toLowerCase().slice(1);
}).join(' ');
return s
.split('.')
.map((e) => {
return e.toLowerCase().charAt(0).toUpperCase() + e.toLowerCase().slice(1);
})
.join(' ');
}