n8n/packages/nodes-base/nodes/Elastic/Elasticsearch/GenericFunctions.ts
Michael Kret 0ecbb4a19d
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
2022-08-01 22:47:55 +02:00

43 lines
987 B
TypeScript

import { OptionsWithUri } from 'request';
import { IExecuteFunctions } from 'n8n-core';
import { IDataObject, JsonObject, NodeApiError } from 'n8n-workflow';
import { ElasticsearchApiCredentials } from './types';
export async function elasticsearchApiRequest(
this: IExecuteFunctions,
method: 'GET' | 'PUT' | 'POST' | 'DELETE',
endpoint: string,
body: IDataObject = {},
qs: IDataObject = {},
) {
const { baseUrl, ignoreSSLIssues } = (await this.getCredentials(
'elasticsearchApi',
)) as ElasticsearchApiCredentials;
const options: OptionsWithUri = {
method,
body,
qs,
uri: `${baseUrl}${endpoint}`,
json: true,
rejectUnauthorized: !ignoreSSLIssues,
};
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) {
delete options.qs;
}
try {
return await this.helpers.requestWithAuthentication.call(this, 'elasticsearchApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}