n8n/packages/nodes-base/nodes/Elastic/Elasticsearch/GenericFunctions.ts
Jonathan Bennetts 8999403228
feat(Elasticsearch Node): Add 'Source Excludes' and 'Source Includes' options on 'Document: getAll' operation (#3660)
* Added 'Source Excludes' and 'Source Includes' options on  'document: getAll' operation

* Updated credentials to use new system

Co-authored-by: mp <miguel@mconf.com>
Co-authored-by: miguel-mconf <107938570+miguel-mconf@users.noreply.github.com>
Co-authored-by: Jan Oberhauser <janober@users.noreply.github.com>
2022-07-10 13:11:12 +03:00

54 lines
995 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);
}
}