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
38 lines
871 B
TypeScript
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;
|
|
}
|