mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
b03e358a12
* 👕 Enable `consistent-type-imports` for nodes-base
* 👕 Apply to nodes-base
* ⏪ Undo unrelated changes
* 🚚 Move to `.eslintrc.js` in nodes-base
* ⏪ Revert "Enable `consistent-type-imports` for nodes-base"
This reverts commit 529ad72b05
.
* 👕 Fix severity
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import type { OptionsWithUri } from 'request';
|
|
|
|
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
|
|
|
import type { IDataObject, IHookFunctions, IWebhookFunctions } from 'n8n-workflow';
|
|
import { NodeApiError } from 'n8n-workflow';
|
|
|
|
export async function zulipApiRequest(
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
method: string,
|
|
resource: string,
|
|
|
|
body: any = {},
|
|
query: IDataObject = {},
|
|
uri?: string,
|
|
option: IDataObject = {},
|
|
): Promise<any> {
|
|
const credentials = await this.getCredentials('zulipApi');
|
|
|
|
const endpoint = `${credentials.url}/api/v1`;
|
|
|
|
let options: OptionsWithUri = {
|
|
auth: {
|
|
user: credentials.email as string,
|
|
password: credentials.apiKey as string,
|
|
},
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
method,
|
|
form: body,
|
|
qs: query,
|
|
uri: uri || `${endpoint}${resource}`,
|
|
json: true,
|
|
};
|
|
if (!Object.keys(body).length) {
|
|
delete options.form;
|
|
}
|
|
if (!Object.keys(query).length) {
|
|
delete options.qs;
|
|
}
|
|
options = Object.assign({}, options, option);
|
|
try {
|
|
return await this.helpers.request(options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|
|
|
|
export function validateJSON(json: string | undefined): any {
|
|
let result;
|
|
try {
|
|
result = JSON.parse(json!);
|
|
} catch (exception) {
|
|
result = undefined;
|
|
}
|
|
return result;
|
|
}
|