mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
:sparkles Done
This commit is contained in:
@@ -5,34 +5,30 @@ import {
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
BINARY_ENCODING
|
||||
} from 'n8n-core';
|
||||
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, operation: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const credentials = this.getCredentials('rocketchatApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const apiKey = `${credentials.apiKey}:X`;
|
||||
const headerWithAuthentication = Object.assign({}, headers,
|
||||
{ 'X-Auth-Token': credentials.authKey, 'X-User-Id': credentials.userId });
|
||||
|
||||
const headerWithAuthentication = Object.assign({}, headers, { Authorization: `${Buffer.from(apiKey).toString(BINARY_ENCODING)}` });
|
||||
|
||||
const endpoint = '';
|
||||
const endpoint = 'rocket.chat/api/v1';
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
body,
|
||||
uri: `https://${credentials.domain}.${endpoint}${resource}`,
|
||||
uri: `https://${credentials.subdomain}.${endpoint}${resource}.${operation}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
if (_.isEmpty(options.body)) {
|
||||
if (Object.keys(options.body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
@@ -49,3 +45,13 @@ export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFuncti
|
||||
throw error.response.body;
|
||||
}
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = [];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user