n8n/packages/nodes-base/nodes/Cal/GenericFunctions.ts
Iván Ovejero cfd32d2642
refactor: Phase out TSLint in nodes-base (no-changelog) (#4798)
* 🔥 Remove TSLint scripts

* 🔥 Remove TSLint config

* 🔥 Remove TSLint exceptions

* 👕 Adjust lint config

* ✏️ Add story numbers
2022-12-02 15:25:21 +01:00

60 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,
body: any = {},
query: IDataObject = {},
option: IDataObject = {},
): 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;
}