mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-11 07:04:06 -08:00
0ecbb4a19d
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
IHookFunctions,
|
|
IHttpRequestMethods,
|
|
IHttpRequestOptions,
|
|
INodePropertyOptions,
|
|
IWebhookFunctions,
|
|
NodeApiError,
|
|
} from 'n8n-workflow';
|
|
|
|
export async function calApiRequest(
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
method: IHttpRequestMethods,
|
|
resource: string,
|
|
// tslint:disable-next-line:no-any
|
|
body: any = {},
|
|
query: IDataObject = {},
|
|
option: IDataObject = {},
|
|
// tslint:disable-next-line:no-any
|
|
): Promise<any> {
|
|
const credentials = await this.getCredentials('calApi');
|
|
|
|
let options: IHttpRequestOptions = {
|
|
baseURL: credentials.host as string,
|
|
method,
|
|
body,
|
|
qs: query,
|
|
url: resource,
|
|
};
|
|
|
|
if (!Object.keys(query).length) {
|
|
delete options.qs;
|
|
}
|
|
options = Object.assign({}, options, option);
|
|
try {
|
|
return await this.helpers.httpRequestWithAuthentication.call(this, 'calApi', options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|
|
|
|
export function sortOptionParameters(
|
|
optionParameters: INodePropertyOptions[],
|
|
): INodePropertyOptions[] {
|
|
optionParameters.sort((a, b) => {
|
|
const aName = a.name.toLowerCase();
|
|
const bName = b.name.toLowerCase();
|
|
if (aName < bName) {
|
|
return -1;
|
|
}
|
|
if (aName > bName) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
return optionParameters;
|
|
}
|