n8n/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts
Iván Ovejero b03e358a12
refactor: Integrate consistent-type-imports in nodes-base (no-changelog) (#5267)
* 👕 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
2023-01-27 12:22:44 +01:00

38 lines
871 B
TypeScript

import type { OptionsWithUri } from 'request';
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
export async function rocketchatApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
resource: string,
method: string,
operation: string,
body: any = {},
headers?: object,
): Promise<any> {
const credentials = await this.getCredentials('rocketchatApi');
const options: OptionsWithUri = {
headers,
method,
body,
uri: `${credentials.domain}/api/v1${resource}.${operation}`,
json: true,
};
if (Object.keys(options.body).length === 0) {
delete options.body;
}
return this.helpers.requestWithAuthentication.call(this, 'rocketchatApi', options);
}
export function validateJSON(json: string | undefined): any {
let result;
try {
result = JSON.parse(json!);
} catch (exception) {
result = [];
}
return result;
}