first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.elasticSecurity",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Development"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/elasticsecurity/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.elasticsecurity/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
caseCommentFields,
|
||||
caseCommentOperations,
|
||||
caseFields,
|
||||
caseOperations,
|
||||
caseTagFields,
|
||||
caseTagOperations,
|
||||
connectorFields,
|
||||
connectorOperations,
|
||||
} from './descriptions';
|
||||
import {
|
||||
elasticSecurityApiRequest,
|
||||
getConnector,
|
||||
getVersion,
|
||||
handleListing,
|
||||
throwOnEmptyUpdate,
|
||||
} from './GenericFunctions';
|
||||
import type { Connector, ConnectorCreatePayload, ConnectorType } from './types';
|
||||
|
||||
export class ElasticSecurity implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Elastic Security',
|
||||
name: 'elasticSecurity',
|
||||
icon: 'file:elasticSecurity.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the Elastic Security API',
|
||||
schemaPath: 'Elastic/ElasticSecurity',
|
||||
defaults: {
|
||||
name: 'Elastic Security',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'elasticSecurityApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
noDataExpression: true,
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Case',
|
||||
value: 'case',
|
||||
},
|
||||
{
|
||||
name: 'Case Comment',
|
||||
value: 'caseComment',
|
||||
},
|
||||
{
|
||||
name: 'Case Tag',
|
||||
value: 'caseTag',
|
||||
},
|
||||
{
|
||||
name: 'Connector',
|
||||
value: 'connector',
|
||||
},
|
||||
],
|
||||
default: 'case',
|
||||
},
|
||||
...caseOperations,
|
||||
...caseFields,
|
||||
...caseCommentOperations,
|
||||
...caseCommentFields,
|
||||
...caseTagOperations,
|
||||
...caseTagFields,
|
||||
...connectorOperations,
|
||||
...connectorFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const tags = (await elasticSecurityApiRequest.call(this, 'GET', '/cases/tags')) as string[];
|
||||
return tags.map((tag) => ({ name: tag, value: tag }));
|
||||
},
|
||||
|
||||
async getConnectors(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = '/cases/configure/connectors/_find';
|
||||
const connectors = (await elasticSecurityApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
endpoint,
|
||||
)) as Connector[];
|
||||
return connectors.map(({ name, id }) => ({ name, value: id }));
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
let responseData;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'case') {
|
||||
// **********************************************************************
|
||||
// case
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------------
|
||||
// case: create
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-create.html
|
||||
|
||||
const body = {
|
||||
title: this.getNodeParameter('title', i),
|
||||
connector: {},
|
||||
owner: 'securitySolution',
|
||||
description: '',
|
||||
tags: [], // set via `caseTag: add` but must be present
|
||||
settings: {
|
||||
syncAlerts: this.getNodeParameter('additionalFields.syncAlerts', i, false),
|
||||
},
|
||||
} as IDataObject;
|
||||
|
||||
const connectorId = this.getNodeParameter('connectorId', i) as ConnectorType;
|
||||
|
||||
const {
|
||||
id: fetchedId,
|
||||
name: fetchedName,
|
||||
type: fetchedType,
|
||||
} = await getConnector.call(this, connectorId);
|
||||
|
||||
const selectedConnectorType = this.getNodeParameter(
|
||||
'connectorType',
|
||||
i,
|
||||
) as ConnectorType;
|
||||
|
||||
if (fetchedType !== selectedConnectorType) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Connector Type does not match the type of the connector in Connector Name',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const connector = {
|
||||
id: fetchedId,
|
||||
name: fetchedName,
|
||||
type: fetchedType,
|
||||
fields: {},
|
||||
};
|
||||
|
||||
if (selectedConnectorType === '.jira') {
|
||||
connector.fields = {
|
||||
issueType: this.getNodeParameter('issueType', i),
|
||||
priority: this.getNodeParameter('priority', i),
|
||||
parent: null, // required but unimplemented
|
||||
};
|
||||
} else if (selectedConnectorType === '.servicenow') {
|
||||
connector.fields = {
|
||||
urgency: this.getNodeParameter('urgency', i),
|
||||
severity: this.getNodeParameter('severity', i),
|
||||
impact: this.getNodeParameter('impact', i),
|
||||
category: this.getNodeParameter('category', i),
|
||||
subcategory: null, // required but unimplemented
|
||||
};
|
||||
} else if (selectedConnectorType === '.resilient') {
|
||||
const rawIssueTypes = this.getNodeParameter('issueTypes', i) as string;
|
||||
connector.fields = {
|
||||
issueTypes: rawIssueTypes.split(',').map(Number),
|
||||
severityCode: this.getNodeParameter('severityCode', i) as number,
|
||||
incidentTypes: null, // required but undocumented
|
||||
};
|
||||
}
|
||||
|
||||
body.connector = connector;
|
||||
|
||||
const {
|
||||
syncAlerts, // ignored because already set
|
||||
...rest
|
||||
} = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (Object.keys(rest).length) {
|
||||
Object.assign(body, rest);
|
||||
}
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'POST', '/cases', body);
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------------
|
||||
// case: delete
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-delete-case.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
await elasticSecurityApiRequest.call(this, 'DELETE', `/cases?ids=["${caseId}"]`);
|
||||
responseData = { success: true };
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------------
|
||||
// case: get
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-get-case.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'GET', `/cases/${caseId}`);
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------------
|
||||
// case: getAll
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-find-cases.html
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const { tags, status } = this.getNodeParameter('filters', i) as IDataObject & {
|
||||
tags: string[];
|
||||
status: string;
|
||||
};
|
||||
const sortOptions = this.getNodeParameter('sortOptions', i) as IDataObject;
|
||||
|
||||
qs.sortField = sortOptions.sortField ?? 'createdAt';
|
||||
qs.sortOrder = sortOptions.sortOrder ?? 'asc';
|
||||
|
||||
if (status) {
|
||||
qs.status = status;
|
||||
}
|
||||
|
||||
if (tags?.length) {
|
||||
qs.tags = tags.join(',');
|
||||
}
|
||||
|
||||
responseData = await handleListing.call(this, 'GET', '/cases/_find', {}, qs);
|
||||
} else if (operation === 'getStatus') {
|
||||
// ----------------------------------------
|
||||
// case: getStatus
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-get-status.html
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'GET', '/cases/status');
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------------
|
||||
// case: update
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-update.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
|
||||
const body = {} as IDataObject;
|
||||
const updateFields = this.getNodeParameter('updateFields', i);
|
||||
|
||||
if (!Object.keys(updateFields).length) {
|
||||
throwOnEmptyUpdate.call(this, resource);
|
||||
}
|
||||
|
||||
const { syncAlerts, ...rest } = updateFields;
|
||||
|
||||
Object.assign(body, {
|
||||
cases: [
|
||||
{
|
||||
id: caseId,
|
||||
version: await getVersion.call(this, `/cases/${caseId}`),
|
||||
...(syncAlerts && { settings: { syncAlerts } }),
|
||||
...rest,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', '/cases', body);
|
||||
}
|
||||
} else if (resource === 'caseTag') {
|
||||
// **********************************************************************
|
||||
// caseTag
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'add') {
|
||||
// ----------------------------------------
|
||||
// caseTag: add
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-create.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
|
||||
const { title, connector, owner, description, settings, tags } =
|
||||
await elasticSecurityApiRequest.call(this, 'GET', `/cases/${caseId}`);
|
||||
|
||||
const tagToAdd = this.getNodeParameter('tag', i);
|
||||
|
||||
if (tags.includes(tagToAdd)) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Cannot add tag "${tagToAdd}" to case ID ${caseId} because this case already has this tag.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const body = {};
|
||||
|
||||
Object.assign(body, {
|
||||
cases: [
|
||||
{
|
||||
id: caseId,
|
||||
title,
|
||||
connector,
|
||||
owner,
|
||||
description,
|
||||
settings,
|
||||
version: await getVersion.call(this, `/cases/${caseId}`),
|
||||
tags: [...tags, tagToAdd],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', '/cases', body);
|
||||
} else if (operation === 'remove') {
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-update.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
const tagToRemove = this.getNodeParameter('tag', i) as string;
|
||||
|
||||
const { title, connector, owner, description, settings, tags } =
|
||||
(await elasticSecurityApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/cases/${caseId}`,
|
||||
)) as IDataObject & { tags: string[] };
|
||||
|
||||
if (!tags.includes(tagToRemove)) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Cannot remove tag "${tagToRemove}" from case ID ${caseId} because this case does not have this tag.`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const body = {};
|
||||
|
||||
Object.assign(body, {
|
||||
cases: [
|
||||
{
|
||||
id: caseId,
|
||||
title,
|
||||
connector,
|
||||
owner,
|
||||
description,
|
||||
settings,
|
||||
version: await getVersion.call(this, `/cases/${caseId}`),
|
||||
tags: tags.filter((tag) => tag !== tagToRemove),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', '/cases', body);
|
||||
}
|
||||
} else if (resource === 'caseComment') {
|
||||
// **********************************************************************
|
||||
// caseComment
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'add') {
|
||||
// ----------------------------------------
|
||||
// caseComment: add
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-add-comment.html
|
||||
|
||||
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
const body = {
|
||||
comment: this.getNodeParameter('comment', i),
|
||||
type: 'user',
|
||||
owner: additionalFields.owner || 'securitySolution',
|
||||
} as IDataObject;
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
const endpoint = `/cases/${caseId}/comments`;
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'POST', endpoint, body);
|
||||
|
||||
if (simple) {
|
||||
const { comments } = responseData;
|
||||
responseData = comments[comments.length - 1];
|
||||
}
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------------
|
||||
// caseComment: get
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-get-comment.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
const commentId = this.getNodeParameter('commentId', i);
|
||||
|
||||
const endpoint = `/cases/${caseId}/comments/${commentId}`;
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'GET', endpoint);
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------------
|
||||
// caseComment: getAll
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-get-all-case-comments.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
|
||||
const endpoint = `/cases/${caseId}/comments`;
|
||||
responseData = await handleListing.call(this, 'GET', endpoint);
|
||||
} else if (operation === 'remove') {
|
||||
// ----------------------------------------
|
||||
// caseComment: remove
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-delete-comment.html
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
const commentId = this.getNodeParameter('commentId', i);
|
||||
|
||||
const endpoint = `/cases/${caseId}/comments/${commentId}`;
|
||||
await elasticSecurityApiRequest.call(this, 'DELETE', endpoint);
|
||||
responseData = { success: true };
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------------
|
||||
// caseComment: update
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/cases-api-update-comment.html
|
||||
|
||||
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
const commentId = this.getNodeParameter('commentId', i);
|
||||
|
||||
const body = {
|
||||
comment: this.getNodeParameter('comment', i),
|
||||
id: commentId,
|
||||
type: 'user',
|
||||
owner: 'securitySolution',
|
||||
version: await getVersion.call(this, `/cases/${caseId}/comments/${commentId}`),
|
||||
} as IDataObject;
|
||||
|
||||
const patchEndpoint = `/cases/${caseId}/comments`;
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', patchEndpoint, body);
|
||||
|
||||
if (simple) {
|
||||
const { comments } = responseData;
|
||||
responseData = comments[comments.length - 1];
|
||||
}
|
||||
}
|
||||
} else if (resource === 'connector') {
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------------
|
||||
// connector: create
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/security/current/register-connector.html
|
||||
|
||||
const connectorType = this.getNodeParameter('connectorType', i) as ConnectorType;
|
||||
|
||||
const body: ConnectorCreatePayload = {
|
||||
connector_type_id: connectorType,
|
||||
name: this.getNodeParameter('name', i) as string,
|
||||
};
|
||||
|
||||
if (connectorType === '.jira') {
|
||||
body.config = {
|
||||
apiUrl: this.getNodeParameter('apiUrl', i) as string,
|
||||
projectKey: this.getNodeParameter('projectKey', i) as string,
|
||||
};
|
||||
body.secrets = {
|
||||
email: this.getNodeParameter('email', i) as string,
|
||||
apiToken: this.getNodeParameter('apiToken', i) as string,
|
||||
};
|
||||
} else if (connectorType === '.resilient') {
|
||||
body.config = {
|
||||
apiUrl: this.getNodeParameter('apiUrl', i) as string,
|
||||
orgId: this.getNodeParameter('orgId', i) as string,
|
||||
};
|
||||
body.secrets = {
|
||||
apiKeyId: this.getNodeParameter('apiKeyId', i) as string,
|
||||
apiKeySecret: this.getNodeParameter('apiKeySecret', i) as string,
|
||||
};
|
||||
} else if (connectorType === '.servicenow') {
|
||||
body.config = {
|
||||
apiUrl: this.getNodeParameter('apiUrl', i) as string,
|
||||
};
|
||||
body.secrets = {
|
||||
username: this.getNodeParameter('username', i) as string,
|
||||
password: this.getNodeParameter('password', i) as string,
|
||||
};
|
||||
}
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/actions/connector',
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: error.message }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionErrorData);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
JsonObject,
|
||||
IRequestOptions,
|
||||
IHttpRequestMethods,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { Connector, ElasticSecurityApiCredentials } from './types';
|
||||
|
||||
export function tolerateTrailingSlash(baseUrl: string) {
|
||||
return baseUrl.endsWith('/') ? baseUrl.substr(0, baseUrl.length - 1) : baseUrl;
|
||||
}
|
||||
|
||||
export async function elasticSecurityApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
const { baseUrl: rawBaseUrl } =
|
||||
await this.getCredentials<ElasticSecurityApiCredentials>('elasticSecurityApi');
|
||||
|
||||
const baseUrl = tolerateTrailingSlash(rawBaseUrl);
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: `${baseUrl}/api${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (!Object.keys(qs).length) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'elasticSecurityApi', options);
|
||||
} catch (error) {
|
||||
if (error?.error?.error === 'Not Acceptable' && error?.error?.message) {
|
||||
error.error.error = `${error.error.error}: ${error.error.message}`;
|
||||
}
|
||||
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function elasticSecurityApiRequestAllItems(
|
||||
this: IExecuteFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
let _page = 1;
|
||||
const returnData: IDataObject[] = [];
|
||||
let responseData: any;
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as 'case' | 'caseComment';
|
||||
|
||||
do {
|
||||
responseData = await elasticSecurityApiRequest.call(this, method, endpoint, body, qs);
|
||||
_page++;
|
||||
|
||||
const items = resource === 'case' ? responseData.cases : responseData;
|
||||
|
||||
returnData.push(...(items as IDataObject[]));
|
||||
} while (returnData.length < responseData.total);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function handleListing(
|
||||
this: IExecuteFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
|
||||
if (returnAll) {
|
||||
return await elasticSecurityApiRequestAllItems.call(this, method, endpoint, body, qs);
|
||||
}
|
||||
|
||||
const responseData = await elasticSecurityApiRequestAllItems.call(
|
||||
this,
|
||||
method,
|
||||
endpoint,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
const limit = this.getNodeParameter('limit', 0);
|
||||
|
||||
return responseData.slice(0, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a connector name and type from a connector ID.
|
||||
*
|
||||
* https://www.elastic.co/guide/en/kibana/master/get-connector-api.html
|
||||
*/
|
||||
export async function getConnector(this: IExecuteFunctions, connectorId: string) {
|
||||
const endpoint = `/actions/connector/${connectorId}`;
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
connector_type_id: type,
|
||||
} = (await elasticSecurityApiRequest.call(this, 'GET', endpoint)) as Connector;
|
||||
|
||||
return { id, name, type };
|
||||
}
|
||||
|
||||
export function throwOnEmptyUpdate(this: IExecuteFunctions, resource: string) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Please enter at least one field to update for the ${resource}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getVersion(this: IExecuteFunctions, endpoint: string) {
|
||||
const { version } = (await elasticSecurityApiRequest.call(this, 'GET', endpoint)) as {
|
||||
version?: string;
|
||||
};
|
||||
|
||||
if (!version) {
|
||||
throw new NodeOperationError(this.getNode(), 'Cannot retrieve version for resource');
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"assignees": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uid": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"category": {
|
||||
"type": "null"
|
||||
},
|
||||
"connector": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "null"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"created_by": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"profile_uid": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"external_service": {
|
||||
"type": "null"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"owner": {
|
||||
"type": "string"
|
||||
},
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"syncAlerts": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"severity": {
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"type": "string"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"totalAlerts": {
|
||||
"type": "integer"
|
||||
},
|
||||
"totalComment": {
|
||||
"type": "integer"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const caseCommentOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
noDataExpression: true,
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Add',
|
||||
value: 'add',
|
||||
description: 'Add a comment to a case',
|
||||
action: 'Add a comment to a case',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a case comment',
|
||||
action: 'Get a case comment',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Retrieve many case comments',
|
||||
action: 'Get many case comments',
|
||||
},
|
||||
{
|
||||
name: 'Remove',
|
||||
value: 'remove',
|
||||
description: 'Remove a comment from a case',
|
||||
action: 'Remove a comment from a case',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a comment in a case',
|
||||
action: 'Update a comment from a case',
|
||||
},
|
||||
],
|
||||
default: 'add',
|
||||
},
|
||||
];
|
||||
|
||||
export const caseCommentFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// caseComment: add
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
description: 'ID of the case containing the comment to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Comment',
|
||||
name: 'comment',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify',
|
||||
name: 'simple',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description: 'Whether to return a simplified version of the response instead of the raw data',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Owner',
|
||||
name: 'owner',
|
||||
type: 'string',
|
||||
description:
|
||||
'Valid application owner registered within the Cases Role Based Access Control system',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: get
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
description: 'ID of the case containing the comment to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Comment ID',
|
||||
name: 'commentId',
|
||||
description: 'ID of the case comment to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: getAll
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: remove
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
description: 'ID of the case containing the comment to remove',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['remove'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Comment ID',
|
||||
name: 'commentId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['remove'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: update
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
description: 'ID of the case containing the comment to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Comment ID',
|
||||
name: 'commentId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Comment',
|
||||
name: 'comment',
|
||||
description: 'Text to replace current comment message',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify',
|
||||
name: 'simple',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseComment'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
default: true,
|
||||
description: 'Whether to return a simplified version of the response instead of the raw data',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,568 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const caseOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
noDataExpression: true,
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a case',
|
||||
action: 'Create a case',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a case',
|
||||
action: 'Delete a case',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a case',
|
||||
action: 'Get a case',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Retrieve many cases',
|
||||
action: 'Get many cases',
|
||||
},
|
||||
{
|
||||
name: 'Get Status',
|
||||
value: 'getStatus',
|
||||
description: 'Retrieve a summary of all case activity',
|
||||
action: 'Get the status of a case',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a case',
|
||||
action: 'Update a case',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const caseFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// case: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Connector Name or ID',
|
||||
name: 'connectorId',
|
||||
description:
|
||||
'Connectors allow you to send Elastic Security cases into other systems (only ServiceNow, Jira, or IBM Resilient). Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getConnectors',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Connector Type',
|
||||
name: 'connectorType',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '.jira',
|
||||
options: [
|
||||
{
|
||||
name: 'IBM Resilient',
|
||||
value: '.resilient',
|
||||
},
|
||||
{
|
||||
name: 'Jira',
|
||||
value: '.jira',
|
||||
},
|
||||
{
|
||||
name: 'ServiceNow ITSM',
|
||||
value: '.servicenow',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Issue Type',
|
||||
name: 'issueType',
|
||||
description: 'Type of the Jira issue to create for this case',
|
||||
type: 'string',
|
||||
placeholder: 'Task',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.jira'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Priority',
|
||||
name: 'priority',
|
||||
description: 'Priority of the Jira issue to create for this case',
|
||||
type: 'string',
|
||||
placeholder: 'High',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.jira'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Urgency',
|
||||
name: 'urgency',
|
||||
description: 'Urgency of the ServiceNow ITSM issue to create for this case',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: 1,
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: 'Medium',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Severity',
|
||||
name: 'severity',
|
||||
description: 'Severity of the ServiceNow ITSM issue to create for this case',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: 1,
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: 'Medium',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Impact',
|
||||
name: 'impact',
|
||||
description: 'Impact of the ServiceNow ITSM issue to create for this case',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: 1,
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: 'Medium',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Category',
|
||||
name: 'category',
|
||||
type: 'string',
|
||||
description: 'Category of the ServiceNow ITSM issue to create for this case',
|
||||
required: true,
|
||||
default: '',
|
||||
placeholder: 'Helpdesk',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Issue Types',
|
||||
name: 'issueTypes',
|
||||
description:
|
||||
'Comma-separated list of numerical types of the IBM Resilient issue to create for this case',
|
||||
type: 'string',
|
||||
placeholder: '123,456',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.resilient'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Severity Code',
|
||||
name: 'severityCode',
|
||||
description: 'Severity code of the IBM Resilient issue to create for this case',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
},
|
||||
required: true,
|
||||
default: 1,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.resilient'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Owner',
|
||||
name: 'owner',
|
||||
type: 'string',
|
||||
description:
|
||||
'Valid application owner registered within the Cases Role Based Access Control system',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Sync Alerts',
|
||||
name: 'syncAlerts',
|
||||
description: 'Whether to synchronize with alerts',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// case: delete
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// case: get
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// case: getAll
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Filters',
|
||||
name: 'filters',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add Filter',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'In Progress',
|
||||
value: 'in-progress',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
],
|
||||
default: 'open',
|
||||
},
|
||||
{
|
||||
displayName: 'Tag Names or IDs',
|
||||
name: 'tags',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTags',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Sort',
|
||||
name: 'sortOptions',
|
||||
type: 'fixedCollection',
|
||||
placeholder: 'Add Sort Options',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Sort Options',
|
||||
name: 'sortOptionsProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Sort Key',
|
||||
name: 'sortField',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Created At',
|
||||
value: 'createdAt',
|
||||
},
|
||||
{
|
||||
name: 'Updated At',
|
||||
value: 'updatedAt',
|
||||
},
|
||||
],
|
||||
default: 'createdAt',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Order',
|
||||
name: 'sortOrder',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Ascending',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'Descending',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
default: 'asc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// case: update
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['case'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
default: 'open',
|
||||
options: [
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'In Progress',
|
||||
value: 'in-progress',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Sync Alerts',
|
||||
name: 'syncAlerts',
|
||||
description: 'Whether to synchronize with alerts',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Version',
|
||||
name: 'version',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,102 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const caseTagOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseTag'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Add',
|
||||
value: 'add',
|
||||
description: 'Add a tag to a case',
|
||||
action: 'Add a tag to a case',
|
||||
},
|
||||
{
|
||||
name: 'Remove',
|
||||
value: 'remove',
|
||||
description: 'Remove a tag from a case',
|
||||
action: 'Remove a tag from a case',
|
||||
},
|
||||
],
|
||||
default: 'add',
|
||||
},
|
||||
];
|
||||
|
||||
export const caseTagFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// caseTag: add
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseTag'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Tag Name or ID',
|
||||
name: 'tag',
|
||||
type: 'options',
|
||||
description:
|
||||
'Tag to attach to the case. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
required: true,
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTags',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseTag'],
|
||||
operation: ['add'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// caseTag: remove
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Case ID',
|
||||
name: 'caseId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseTag'],
|
||||
operation: ['remove'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Tag Name or ID',
|
||||
name: 'tag',
|
||||
type: 'options',
|
||||
description:
|
||||
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
|
||||
required: true,
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTags',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['caseTag'],
|
||||
operation: ['remove'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const connectorOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
noDataExpression: true,
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a connector',
|
||||
action: 'Create a connector',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const connectorFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// connector: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Connector Name',
|
||||
name: 'name',
|
||||
description:
|
||||
'Connectors allow you to send Elastic Security cases into other systems (only ServiceNow, Jira, or IBM Resilient)',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Connector Type',
|
||||
name: 'connectorType',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '.jira',
|
||||
options: [
|
||||
{
|
||||
name: 'IBM Resilient',
|
||||
value: '.resilient',
|
||||
},
|
||||
{
|
||||
name: 'Jira',
|
||||
value: '.jira',
|
||||
},
|
||||
{
|
||||
name: 'ServiceNow ITSM',
|
||||
value: '.servicenow',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'API URL',
|
||||
name: 'apiUrl',
|
||||
type: 'string',
|
||||
description: 'URL of the third-party instance',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
description: 'Jira-registered email',
|
||||
type: 'string',
|
||||
placeholder: 'name@email.com',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.jira'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'API Token',
|
||||
name: 'apiToken',
|
||||
description: 'Jira API token',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.jira'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Project Key',
|
||||
name: 'projectKey',
|
||||
description: 'Jira Project Key',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.jira'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Username',
|
||||
name: 'username',
|
||||
description: 'ServiceNow ITSM username',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
name: 'password',
|
||||
description: 'ServiceNow ITSM password',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.servicenow'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'API Key ID',
|
||||
name: 'apiKeyId',
|
||||
description: 'IBM Resilient API key ID',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.resilient'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'API Key Secret',
|
||||
name: 'apiKeySecret',
|
||||
description: 'IBM Resilient API key secret',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.resilient'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'orgId',
|
||||
description: 'IBM Resilient organization ID',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['connector'],
|
||||
operation: ['create'],
|
||||
connectorType: ['.resilient'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './CaseDescription';
|
||||
export * from './CaseCommentDescription';
|
||||
export * from './CaseTagDescription';
|
||||
export * from './ConnectorDescription';
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="2 0 32 32"><g fill="none" fill-rule="evenodd"><path d="M0 0h32v32H0z"/><path fill="#FA744E" d="M9 7.008V0h20v16.744c0 3.913-6.378 6.477-9.015 7.256V7.008z"/><path fill="#1DBAB0" d="M3 20.073V10h14v22Q3 25.97 3 20.073"/><path fill="#343741" d="M9 10h8v14c-2.983-1.14-8-3.756-8-7.043z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 367 B |
@@ -0,0 +1,57 @@
|
||||
export type ElasticSecurityApiCredentials = {
|
||||
username?: string;
|
||||
password?: string;
|
||||
apiKey?: string;
|
||||
baseUrl: string;
|
||||
};
|
||||
|
||||
export type ConnectorType = '.jira' | '.servicenow' | '.resilient';
|
||||
|
||||
export type Connector = {
|
||||
id: string;
|
||||
name: string;
|
||||
connector_type_id: ConnectorType;
|
||||
};
|
||||
|
||||
export type ConnectorCreatePayload =
|
||||
| ServiceNowConnectorCreatePayload
|
||||
| JiraConnectorCreatePayload
|
||||
| IbmResilientConnectorCreatePayload;
|
||||
|
||||
type ServiceNowConnectorCreatePayload = {
|
||||
connector_type_id: '.servicenow';
|
||||
name: string;
|
||||
secrets?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
config?: {
|
||||
apiUrl: string;
|
||||
};
|
||||
};
|
||||
|
||||
type JiraConnectorCreatePayload = {
|
||||
connector_type_id: '.jira';
|
||||
name: string;
|
||||
secrets?: {
|
||||
email: string;
|
||||
apiToken: string;
|
||||
};
|
||||
config?: {
|
||||
apiUrl: string;
|
||||
projectKey: string;
|
||||
};
|
||||
};
|
||||
|
||||
type IbmResilientConnectorCreatePayload = {
|
||||
connector_type_id: '.resilient';
|
||||
name: string;
|
||||
secrets?: {
|
||||
apiKeyId: string;
|
||||
apiKeySecret: string;
|
||||
};
|
||||
config?: {
|
||||
apiUrl: string;
|
||||
orgId: string;
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.elasticsearch",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Development", "Data & Storage"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/elasticsearch/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.elasticsearch/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
import omit from 'lodash/omit';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, jsonParse, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import { documentFields, documentOperations, indexFields, indexOperations } from './descriptions';
|
||||
import {
|
||||
elasticsearchApiRequest,
|
||||
elasticsearchApiRequestAllItems,
|
||||
elasticsearchBulkApiRequest,
|
||||
} from './GenericFunctions';
|
||||
import type { DocumentGetAllOptions, FieldsUiValues } from './types';
|
||||
|
||||
export class Elasticsearch implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Elasticsearch',
|
||||
name: 'elasticsearch',
|
||||
icon: 'file:elasticsearch.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the Elasticsearch API',
|
||||
schemaPath: 'Elastic/Elasticsearch',
|
||||
defaults: {
|
||||
name: 'Elasticsearch',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'elasticsearchApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Document',
|
||||
value: 'document',
|
||||
},
|
||||
{
|
||||
name: 'Index',
|
||||
value: 'index',
|
||||
},
|
||||
],
|
||||
default: 'document',
|
||||
},
|
||||
...documentOperations,
|
||||
...documentFields,
|
||||
...indexOperations,
|
||||
...indexFields,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as 'document' | 'index';
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
let responseData;
|
||||
|
||||
let bulkBody: IDataObject = {};
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const bulkOperation = this.getNodeParameter('options.bulkOperation', i, false);
|
||||
if (resource === 'document') {
|
||||
// **********************************************************************
|
||||
// document
|
||||
// **********************************************************************
|
||||
if (operation === 'delete') {
|
||||
// ----------------------------------------
|
||||
// document: delete
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
const documentId = this.getNodeParameter('documentId', i);
|
||||
|
||||
if (bulkOperation) {
|
||||
bulkBody[i] = JSON.stringify({
|
||||
delete: {
|
||||
_index: indexId,
|
||||
_id: documentId,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const endpoint = `/${indexId}/_doc/${documentId}`;
|
||||
responseData = await elasticsearchApiRequest.call(this, 'DELETE', endpoint);
|
||||
}
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------------
|
||||
// document: get
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
const documentId = this.getNodeParameter('documentId', i);
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
|
||||
if (Object.keys(options).length) {
|
||||
Object.assign(qs, options);
|
||||
qs._source = true;
|
||||
}
|
||||
|
||||
const endpoint = `/${indexId}/_doc/${documentId}`;
|
||||
responseData = await elasticsearchApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
|
||||
const simple = this.getNodeParameter('simple', i) as IDataObject;
|
||||
|
||||
if (simple) {
|
||||
responseData = {
|
||||
_id: responseData._id,
|
||||
...responseData._source,
|
||||
};
|
||||
}
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------------
|
||||
// document: getAll
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
|
||||
const body = {} as IDataObject;
|
||||
const qs = {} as IDataObject;
|
||||
const options = this.getNodeParameter('options', i) as DocumentGetAllOptions;
|
||||
// const paginate = this.getNodeParameter('paginate', i) as boolean;
|
||||
|
||||
if (Object.keys(options).length) {
|
||||
const { query, ...rest } = options;
|
||||
if (query) {
|
||||
Object.assign(
|
||||
body,
|
||||
jsonParse(query, { errorMessage: "Invalid JSON in 'Query' option" }),
|
||||
);
|
||||
}
|
||||
Object.assign(qs, rest);
|
||||
qs._source = true;
|
||||
}
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
|
||||
if (returnAll) {
|
||||
//Defines the number of hits to return. Defaults to 10. By default, you cannot page through more than 10,000 hits
|
||||
qs.size = 10000;
|
||||
if (qs.sort) {
|
||||
responseData = await elasticsearchApiRequestAllItems.call(
|
||||
this,
|
||||
indexId as string,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
responseData = await elasticsearchApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${indexId}/_search`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.hits.hits;
|
||||
}
|
||||
} else {
|
||||
qs.size = this.getNodeParameter('limit', 0);
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${indexId}/_search`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.hits.hits;
|
||||
}
|
||||
|
||||
const simple = this.getNodeParameter('simple', 0) as IDataObject;
|
||||
|
||||
if (simple) {
|
||||
responseData = responseData.map((item: IDataObject) => {
|
||||
return {
|
||||
_id: item._id,
|
||||
...(item._source as IDataObject),
|
||||
};
|
||||
});
|
||||
}
|
||||
} else if (operation === 'create') {
|
||||
// ----------------------------------------
|
||||
// document: create
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
|
||||
|
||||
const body: IDataObject = {};
|
||||
|
||||
const dataToSend = this.getNodeParameter('dataToSend', 0) as
|
||||
| 'defineBelow'
|
||||
| 'autoMapInputData';
|
||||
|
||||
if (dataToSend === 'defineBelow') {
|
||||
const fields = this.getNodeParameter('fieldsUi.fieldValues', i, []) as FieldsUiValues;
|
||||
fields.forEach(({ fieldId, fieldValue }) => (body[fieldId] = fieldValue));
|
||||
} else {
|
||||
const inputData = items[i].json;
|
||||
const rawInputsToIgnore = this.getNodeParameter('inputsToIgnore', i) as string;
|
||||
const inputsToIgnore = rawInputsToIgnore.split(',').map((c) => c.trim());
|
||||
|
||||
for (const key of Object.keys(inputData)) {
|
||||
if (inputsToIgnore.includes(key)) continue;
|
||||
body[key] = inputData[key];
|
||||
}
|
||||
}
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (Object.keys(additionalFields).length) {
|
||||
Object.assign(qs, omit(additionalFields, ['documentId']));
|
||||
}
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
const { documentId } = additionalFields;
|
||||
|
||||
if (bulkOperation) {
|
||||
bulkBody[i] = JSON.stringify({
|
||||
index: {
|
||||
_index: indexId,
|
||||
_id: documentId,
|
||||
},
|
||||
});
|
||||
bulkBody[i] += `\n${JSON.stringify(body)}`;
|
||||
} else {
|
||||
if (documentId) {
|
||||
const endpoint = `/${indexId}/_doc/${documentId}`;
|
||||
responseData = await elasticsearchApiRequest.call(this, 'PUT', endpoint, body);
|
||||
} else {
|
||||
const endpoint = `/${indexId}/_doc`;
|
||||
responseData = await elasticsearchApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
}
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------------
|
||||
// document: update
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
|
||||
|
||||
const body = { doc: {} } as { doc: { [key: string]: string } };
|
||||
|
||||
const dataToSend = this.getNodeParameter('dataToSend', 0) as
|
||||
| 'defineBelow'
|
||||
| 'autoMapInputData';
|
||||
|
||||
if (dataToSend === 'defineBelow') {
|
||||
const fields = this.getNodeParameter('fieldsUi.fieldValues', i, []) as FieldsUiValues;
|
||||
fields.forEach(({ fieldId, fieldValue }) => (body.doc[fieldId] = fieldValue));
|
||||
} else {
|
||||
const inputData = items[i].json;
|
||||
const rawInputsToIgnore = this.getNodeParameter('inputsToIgnore', i) as string;
|
||||
const inputsToIgnore = rawInputsToIgnore.split(',').map((c) => c.trim());
|
||||
|
||||
for (const key of Object.keys(inputData)) {
|
||||
if (inputsToIgnore.includes(key)) continue;
|
||||
body.doc[key] = inputData[key] as string;
|
||||
}
|
||||
}
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
const documentId = this.getNodeParameter('documentId', i);
|
||||
|
||||
const endpoint = `/${indexId}/_update/${documentId}`;
|
||||
if (bulkOperation) {
|
||||
bulkBody[i] = JSON.stringify({
|
||||
update: {
|
||||
_index: indexId,
|
||||
_id: documentId,
|
||||
},
|
||||
});
|
||||
bulkBody[i] += `\n${JSON.stringify(body)}`;
|
||||
} else {
|
||||
responseData = await elasticsearchApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
}
|
||||
} else if (resource === 'index') {
|
||||
// **********************************************************************
|
||||
// index
|
||||
// **********************************************************************
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------------
|
||||
// index: create
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
|
||||
const body = {} as IDataObject;
|
||||
const qs = {} as IDataObject;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (Object.keys(additionalFields).length) {
|
||||
const { aliases, mappings, settings, ...rest } = additionalFields;
|
||||
Object.assign(body, aliases, mappings, settings);
|
||||
Object.assign(qs, rest);
|
||||
}
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'PUT', `/${indexId}`);
|
||||
responseData = { id: indexId, ...responseData };
|
||||
delete responseData.index;
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------------
|
||||
// index: delete
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i);
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'DELETE', `/${indexId}`);
|
||||
responseData = { success: true };
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------------
|
||||
// index: get
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html
|
||||
|
||||
const indexId = this.getNodeParameter('indexId', i) as string;
|
||||
|
||||
const qs = {} as IDataObject;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (Object.keys(additionalFields).length) {
|
||||
Object.assign(qs, additionalFields);
|
||||
}
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'GET', `/${indexId}`, {}, qs);
|
||||
responseData = { id: indexId, ...responseData[indexId] };
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------------
|
||||
// index: getAll
|
||||
// ----------------------------------------
|
||||
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'GET', '/_aliases');
|
||||
responseData = Object.keys(responseData as IDataObject).map((index) => ({
|
||||
indexId: index,
|
||||
}));
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (!returnAll) {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.slice(0, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bulkOperation) {
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
if (Object.keys(bulkBody).length >= 50) {
|
||||
responseData = (await elasticsearchBulkApiRequest.call(this, bulkBody)) as IDataObject[];
|
||||
for (let j = 0; j < responseData.length; j++) {
|
||||
const itemData = responseData[j];
|
||||
if (itemData.error) {
|
||||
const errorData = itemData.error as IDataObject;
|
||||
const message = errorData.type as string;
|
||||
const description = errorData.reason as string;
|
||||
const itemIndex = parseInt(Object.keys(bulkBody)[j]);
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push(
|
||||
...this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: message, message: itemData.error }),
|
||||
{ itemData: { item: itemIndex } },
|
||||
),
|
||||
);
|
||||
continue;
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message,
|
||||
description,
|
||||
itemIndex,
|
||||
} as JsonObject);
|
||||
}
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(itemData),
|
||||
{ itemData: { item: parseInt(Object.keys(bulkBody)[j]) } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
bulkBody = {};
|
||||
}
|
||||
}
|
||||
if (Object.keys(bulkBody).length) {
|
||||
responseData = (await elasticsearchBulkApiRequest.call(this, bulkBody)) as IDataObject[];
|
||||
for (let j = 0; j < responseData.length; j++) {
|
||||
const itemData = responseData[j];
|
||||
if (itemData.error) {
|
||||
const errorData = itemData.error as IDataObject;
|
||||
const message = errorData.type as string;
|
||||
const description = errorData.reason as string;
|
||||
const itemIndex = parseInt(Object.keys(bulkBody)[j]);
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push(
|
||||
...this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: message, message: itemData.error }),
|
||||
{ itemData: { item: itemIndex } },
|
||||
),
|
||||
);
|
||||
continue;
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message,
|
||||
description,
|
||||
itemIndex,
|
||||
} as JsonObject);
|
||||
}
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(itemData),
|
||||
{ itemData: { item: parseInt(Object.keys(bulkBody)[j]) } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
IHttpRequestOptions,
|
||||
IHttpRequestMethods,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import type { ElasticsearchApiCredentials } from './types';
|
||||
|
||||
export async function elasticsearchBulkApiRequest(this: IExecuteFunctions, body: IDataObject) {
|
||||
const { baseUrl, ignoreSSLIssues } =
|
||||
await this.getCredentials<ElasticsearchApiCredentials>('elasticsearchApi');
|
||||
|
||||
const bulkBody = Object.values(body).flat().join('\n') + '\n';
|
||||
|
||||
const options: IHttpRequestOptions = {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-ndjson' },
|
||||
body: bulkBody,
|
||||
url: `${baseUrl.replace(/\/$/, '')}/_bulk`,
|
||||
skipSslCertificateValidation: ignoreSSLIssues,
|
||||
returnFullResponse: true,
|
||||
ignoreHttpStatusErrors: true,
|
||||
};
|
||||
|
||||
const response = await this.helpers.httpRequestWithAuthentication.call(
|
||||
this,
|
||||
'elasticsearchApi',
|
||||
options,
|
||||
);
|
||||
|
||||
if (response.statusCode > 299) {
|
||||
if (this.continueOnFail()) {
|
||||
return Object.values(body).map((_) => ({ error: response.body.error }));
|
||||
} else {
|
||||
throw new NodeApiError(this.getNode(), { error: response.body.error } as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
return response.body.items.map((item: IDataObject) => {
|
||||
return {
|
||||
...(item.index as IDataObject),
|
||||
...(item.update as IDataObject),
|
||||
...(item.create as IDataObject),
|
||||
...(item.delete as IDataObject),
|
||||
...(item.error as IDataObject),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function elasticsearchApiRequest(
|
||||
this: IExecuteFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
const { baseUrl, ignoreSSLIssues } =
|
||||
await this.getCredentials<ElasticsearchApiCredentials>('elasticsearchApi');
|
||||
|
||||
const options: IHttpRequestOptions = {
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
url: `${baseUrl.replace(/\/$/, '')}${endpoint}`,
|
||||
json: true,
|
||||
skipSslCertificateValidation: ignoreSSLIssues,
|
||||
};
|
||||
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (!Object.keys(qs).length) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.httpRequestWithAuthentication.call(this, 'elasticsearchApi', options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function elasticsearchApiRequestAllItems(
|
||||
this: IExecuteFunctions,
|
||||
indexId: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
): Promise<any> {
|
||||
//https://www.elastic.co/guide/en/elasticsearch/reference/7.16/paginate-search-results.html#search-after
|
||||
try {
|
||||
//create a point in time (PIT) to preserve the current index state over your searches
|
||||
let pit = (
|
||||
await elasticsearchApiRequest.call(this, 'POST', `/${indexId}/_pit`, {}, { keep_alive: '1m' })
|
||||
)?.id as string;
|
||||
|
||||
let returnData: IDataObject[] = [];
|
||||
let responseData;
|
||||
let searchAfter: string[] = [];
|
||||
|
||||
const requestBody: IDataObject = {
|
||||
...body,
|
||||
size: 10000,
|
||||
pit: {
|
||||
id: pit,
|
||||
keep_alive: '1m',
|
||||
},
|
||||
track_total_hits: false, //Disable the tracking of total hits to speed up pagination
|
||||
};
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'POST', '/_search', requestBody, qs);
|
||||
if (responseData?.hits?.hits) {
|
||||
returnData = returnData.concat(responseData.hits.hits as IDataObject[]);
|
||||
const lastHitIndex = responseData.hits.hits.length - 1;
|
||||
//Sort values for the last returned hit with the tiebreaker value
|
||||
searchAfter = responseData.hits.hits[lastHitIndex].sort;
|
||||
//Update id for the point in time
|
||||
pit = responseData.pit_id;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
while (true) {
|
||||
requestBody.search_after = searchAfter;
|
||||
requestBody.pit = { id: pit, keep_alive: '1m' };
|
||||
|
||||
responseData = await elasticsearchApiRequest.call(this, 'POST', '/_search', requestBody, qs);
|
||||
|
||||
if (responseData?.hits?.hits?.length) {
|
||||
returnData = returnData.concat(responseData.hits.hits as IDataObject[]);
|
||||
const lastHitIndex = responseData.hits.hits.length - 1;
|
||||
searchAfter = responseData.hits.hits[lastHitIndex].sort;
|
||||
pit = responseData.pit_id;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await elasticsearchApiRequest.call(this, 'DELETE', '/_pit', { id: pit });
|
||||
|
||||
return returnData;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"_index": {
|
||||
"type": "string"
|
||||
},
|
||||
"_primary_term": {
|
||||
"type": "integer"
|
||||
},
|
||||
"_seq_no": {
|
||||
"type": "integer"
|
||||
},
|
||||
"_shards": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"failed": {
|
||||
"type": "integer"
|
||||
},
|
||||
"successful": {
|
||||
"type": "integer"
|
||||
},
|
||||
"total": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"_version": {
|
||||
"type": "integer"
|
||||
},
|
||||
"result": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 3
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"mappings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"author": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"keyword": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ignore_above": {
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"keyword": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ignore_above": {
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"page_count": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"release_date": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"index": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"creation_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"number_of_replicas": {
|
||||
"type": "string"
|
||||
},
|
||||
"number_of_shards": {
|
||||
"type": "string"
|
||||
},
|
||||
"provided_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"routing": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"allocation": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"include": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_tier_preference": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,868 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as placeholders from './placeholders';
|
||||
|
||||
export const documentOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a document',
|
||||
action: 'Create a document',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a document',
|
||||
action: 'Delete a document',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a document',
|
||||
action: 'Get a document',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many documents',
|
||||
action: 'Get many documents',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a document',
|
||||
action: 'Update a document',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const documentFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// document: delete
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index containing the document to delete',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Document ID',
|
||||
name: 'documentId',
|
||||
description: 'ID of the document to delete',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Bulk Delete',
|
||||
name: 'bulkOperation',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to use the bulk operation to delete the document/s',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// document: get
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index containing the document to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Document ID',
|
||||
name: 'documentId',
|
||||
description: 'ID of the document to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify',
|
||||
name: 'simple',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether to return a simplified version of the response instead of the raw data',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Source Excludes',
|
||||
name: '_source_excludes',
|
||||
description: 'Comma-separated list of source fields to exclude from the response',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Source Includes',
|
||||
name: '_source_includes',
|
||||
description: 'Comma-separated list of source fields to include in the response',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Stored Fields',
|
||||
name: 'stored_fields',
|
||||
description:
|
||||
'Whether to retrieve the document fields stored in the index rather than the document <code>_source</code>. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// document: getAll
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index containing the documents to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName:
|
||||
'By default, you cannot page through more than 10,000 hits. To page through more hits, add "Sort" from options.',
|
||||
name: 'paginateNotice',
|
||||
type: 'notice',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Simplify',
|
||||
name: 'simple',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether to return a simplified version of the response instead of the raw data',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Allow No Indices',
|
||||
name: 'allow_no_indices',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'If false, return an error if any of the following targets only missing/closed indices: wildcard expression, index alias, or <code>_all</code> value. Defaults to true.',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Allow Partial Search Results',
|
||||
name: 'allow_partial_search_results',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'<p>If true, return partial results if there are shard request timeouts or shard failures.</p><p>If false, returns an error with no partial results. Defaults to true.</p>.',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Batched Reduce Size',
|
||||
name: 'batched_reduce_size',
|
||||
description:
|
||||
'Number of shard results that should be reduced at once on the coordinating node. Defaults to 512.',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 2,
|
||||
},
|
||||
default: 512,
|
||||
},
|
||||
{
|
||||
displayName: 'CCS Minimize Roundtrips',
|
||||
name: 'ccs_minimize_roundtrips',
|
||||
description:
|
||||
'Whether network round-trips between the coordinating node and the remote clusters are minimized when executing cross-cluster search (CCS) requests. Defaults to true.',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Doc Value Fields',
|
||||
name: 'docvalue_fields',
|
||||
description:
|
||||
'Comma-separated list of fields to return as the docvalue representation of a field for each hit',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Expand Wildcards',
|
||||
name: 'expand_wildcards',
|
||||
description:
|
||||
'Type of index that wildcard expressions can match. Defaults to <code>open</code>',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'All',
|
||||
value: 'all',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
{
|
||||
name: 'Hidden',
|
||||
value: 'hidden',
|
||||
},
|
||||
{
|
||||
name: 'None',
|
||||
value: 'none',
|
||||
},
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
],
|
||||
default: 'open',
|
||||
},
|
||||
{
|
||||
displayName: 'Explain',
|
||||
name: 'explain',
|
||||
description:
|
||||
'Whether to return detailed information about score computation as part of a hit. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Ignore Throttled',
|
||||
name: 'ignore_throttled',
|
||||
description:
|
||||
'Whether concrete, expanded or aliased indices are ignored when frozen. Defaults to true.',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Ignore Unavailable',
|
||||
name: 'ignore_unavailable',
|
||||
description:
|
||||
'Whether missing or closed indices are not included in the response. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Max Concurrent Shard Requests',
|
||||
name: 'max_concurrent_shard_requests',
|
||||
description:
|
||||
'Define the number of shard requests per node this search executes concurrently. Defaults to 5.',
|
||||
type: 'number',
|
||||
default: 5,
|
||||
},
|
||||
{
|
||||
displayName: 'Pre-Filter Shard Size',
|
||||
name: 'pre_filter_shard_size',
|
||||
description:
|
||||
'Define a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting. Only used if the number of shards the search request expands to exceeds the threshold.',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 1,
|
||||
},
|
||||
{
|
||||
displayName: 'Query',
|
||||
name: 'query',
|
||||
description:
|
||||
'Query in the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html">Elasticsearch Query DSL</a>',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
placeholder: placeholders.query,
|
||||
},
|
||||
{
|
||||
displayName: 'Request Cache',
|
||||
name: 'request_cache',
|
||||
description:
|
||||
'Whether the caching of search results is enabled for requests where size is 0. See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html">Elasticsearch shard request cache settings</a>.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Routing',
|
||||
name: 'routing',
|
||||
description: 'Target this primary shard',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Search Type',
|
||||
name: 'search_type',
|
||||
description:
|
||||
'How distributed term frequencies are calculated for relevance scoring. Defaults to Query then Fetch.',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'DFS Query Then Fetch',
|
||||
value: 'dfs_query_then_fetch',
|
||||
},
|
||||
{
|
||||
name: 'Query Then Fetch',
|
||||
value: 'query_then_fetch',
|
||||
},
|
||||
],
|
||||
default: 'query_then_fetch',
|
||||
},
|
||||
{
|
||||
displayName: 'Sequence Number and Primary Term',
|
||||
name: 'seq_no_primary_term',
|
||||
description:
|
||||
'Whether to return the sequence number and primary term of the last modification of each hit. See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html">Optimistic concurrency control</a>.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Sort',
|
||||
name: 'sort',
|
||||
description: 'Comma-separated list of <code>field:direction</code> pairs',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Source Excludes',
|
||||
name: '_source_excludes',
|
||||
description: 'Comma-separated list of source fields to exclude from the response',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Source Includes',
|
||||
name: '_source_includes',
|
||||
description: 'Comma-separated list of source fields to include in the response',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Stats',
|
||||
name: 'stats',
|
||||
description: 'Tag of the request for logging and statistical purposes',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Stored Fields',
|
||||
name: 'stored_fields',
|
||||
description:
|
||||
'Whether to retrieve the document fields stored in the index rather than the document <code>_source</code>. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Terminate After',
|
||||
name: 'terminate_after',
|
||||
description: 'Max number of documents to collect for each shard',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Timeout',
|
||||
name: 'timeout',
|
||||
description:
|
||||
'Period to wait for active shards. Defaults to <code>1m</code> (one minute). See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units">Elasticsearch time units reference</a>',
|
||||
type: 'string',
|
||||
default: '1m',
|
||||
},
|
||||
{
|
||||
displayName: 'Track Scores',
|
||||
name: 'track_scores',
|
||||
description:
|
||||
'Whether to calculate and return document scores, even if the scores are not used for sorting. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Track Total Hits',
|
||||
name: 'track_total_hits',
|
||||
description: 'Number of hits matching the query to count accurately. Defaults to 10000.',
|
||||
type: 'number',
|
||||
default: 10000,
|
||||
},
|
||||
{
|
||||
displayName: 'Version',
|
||||
name: 'version',
|
||||
description: 'Whether to return document version as part of a hit. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// document: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index to add the document to',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Data to Send',
|
||||
name: 'dataToSend',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Define Below for Each Column',
|
||||
value: 'defineBelow',
|
||||
description: 'Set the value for each destination column',
|
||||
},
|
||||
{
|
||||
name: 'Auto-Map Input Data to Columns',
|
||||
value: 'autoMapInputData',
|
||||
description: 'Use when node input properties match destination column names',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: 'defineBelow',
|
||||
description: 'Whether to insert the input data this node receives in the new row',
|
||||
},
|
||||
{
|
||||
displayName: 'Inputs to Ignore',
|
||||
name: 'inputsToIgnore',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
dataToSend: ['autoMapInputData'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'List of input properties to avoid sending, separated by commas. Leave empty to send all properties.',
|
||||
placeholder: 'Enter properties...',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields to Send',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValueButtonText: 'Add Field to Send',
|
||||
multipleValues: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
dataToSend: ['defineBelow'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name',
|
||||
name: 'fieldId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Document ID',
|
||||
name: 'documentId',
|
||||
description: 'ID of the document to create and add to the index',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Routing',
|
||||
name: 'routing',
|
||||
description: 'Target this primary shard',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Timeout',
|
||||
name: 'timeout',
|
||||
description:
|
||||
'Period to wait for active shards. Defaults to <code>1m</code> (one minute). See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units">Elasticsearch time units reference</a>',
|
||||
type: 'string',
|
||||
default: '1m',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Bulk Create',
|
||||
name: 'bulkOperation',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to use the bulk operation to create the document/s',
|
||||
},
|
||||
{
|
||||
displayName: 'Pipeline ID',
|
||||
name: 'pipeline',
|
||||
description: 'ID of the pipeline to use to preprocess incoming documents',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Refresh',
|
||||
name: 'refresh',
|
||||
description:
|
||||
'If true, Elasticsearch refreshes the affected shards to make this operation visible to search,if wait_for then wait for a refresh to make this operation visible to search,if false do nothing with refreshes',
|
||||
type: 'options',
|
||||
default: 'false',
|
||||
options: [
|
||||
{
|
||||
name: 'True',
|
||||
value: 'true',
|
||||
description: 'Refreshes the affected shards to make this operation visible to search',
|
||||
},
|
||||
{
|
||||
name: 'Wait For',
|
||||
value: 'wait_for',
|
||||
description: 'Wait for a refresh to make this operation visible',
|
||||
},
|
||||
{
|
||||
name: 'False',
|
||||
value: 'false',
|
||||
description: 'Do nothing with refreshes',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// document: update
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the document to update',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Document ID',
|
||||
name: 'documentId',
|
||||
description: 'ID of the document to update',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Data to Send',
|
||||
name: 'dataToSend',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Define Below for Each Column',
|
||||
value: 'defineBelow',
|
||||
description: 'Set the value for each destination column',
|
||||
},
|
||||
{
|
||||
name: 'Auto-Map Input Data to Columns',
|
||||
value: 'autoMapInputData',
|
||||
description: 'Use when node input properties match destination column names',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
default: 'defineBelow',
|
||||
description: 'Whether to insert the input data this node receives in the new row',
|
||||
},
|
||||
{
|
||||
displayName: 'Inputs to Ignore',
|
||||
name: 'inputsToIgnore',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
dataToSend: ['autoMapInputData'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'List of input properties to avoid sending, separated by commas. Leave empty to send all properties.',
|
||||
placeholder: 'Enter properties...',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields to Send',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValueButtonText: 'Add Field to Send',
|
||||
multipleValues: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
dataToSend: ['defineBelow'],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name',
|
||||
name: 'fieldId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Bulk Update',
|
||||
name: 'bulkOperation',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to use the bulk operation to update the document/s',
|
||||
},
|
||||
{
|
||||
displayName: 'Refresh',
|
||||
name: 'refresh',
|
||||
description:
|
||||
'If true, Elasticsearch refreshes the affected shards to make this operation visible to search,if wait_for then wait for a refresh to make this operation visible to search,if false do nothing with refreshes',
|
||||
type: 'options',
|
||||
default: 'false',
|
||||
options: [
|
||||
{
|
||||
name: 'True',
|
||||
value: 'true',
|
||||
description: 'Refreshes the affected shards to make this operation visible to search',
|
||||
},
|
||||
{
|
||||
name: 'Wait For',
|
||||
value: 'wait_for',
|
||||
description: 'Wait for a refresh to make this operation visible',
|
||||
},
|
||||
{
|
||||
name: 'False',
|
||||
value: 'false',
|
||||
description: 'Do nothing with refreshes',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,304 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as placeholders from './placeholders';
|
||||
|
||||
export const indexOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create an index',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete an index',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get an index',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many indices',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const indexFields: INodeProperties[] = [
|
||||
// ----------------------------------------
|
||||
// index: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index to create',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Aliases',
|
||||
name: 'aliases',
|
||||
description:
|
||||
'Index aliases which include the index, as an <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html">alias object</a>',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
placeholder: placeholders.aliases,
|
||||
},
|
||||
{
|
||||
displayName: 'Include Type Name',
|
||||
name: 'include_type_name',
|
||||
description:
|
||||
'Whether a mapping type is expected in the body of mappings. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Mappings',
|
||||
name: 'mappings',
|
||||
description:
|
||||
'Mapping for fields in the index, as <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html">mapping object</a>',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
placeholder: placeholders.mappings,
|
||||
},
|
||||
{
|
||||
displayName: 'Master Timeout',
|
||||
name: 'master_timeout',
|
||||
description:
|
||||
'Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to <code>1m</code>. See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units">Elasticsearch time units reference</a>',
|
||||
type: 'string',
|
||||
default: '1m',
|
||||
},
|
||||
{
|
||||
displayName: 'Settings',
|
||||
name: 'settings',
|
||||
description:
|
||||
'Configuration options for the index, as an <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-modules-settings">index settings object</a>',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
placeholder: placeholders.indexSettings,
|
||||
},
|
||||
{
|
||||
displayName: 'Timeout',
|
||||
name: 'timeout',
|
||||
description:
|
||||
'Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Defaults to <code>30s</code>. See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units">Elasticsearch time units reference</a>',
|
||||
type: 'string',
|
||||
default: '30s',
|
||||
},
|
||||
{
|
||||
displayName: 'Wait for Active Shards',
|
||||
name: 'wait_for_active_shards',
|
||||
description:
|
||||
'The number of shard copies that must be active before proceeding with the operation. Set to <code>all</code> or any positive integer up to the total number of shards in the index. Default: 1, the primary shard',
|
||||
type: 'string',
|
||||
default: '1',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// index: delete
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index to delete',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// index: get
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Index ID',
|
||||
name: 'indexId',
|
||||
description: 'ID of the index to retrieve',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Allow No Indices',
|
||||
name: 'allow_no_indices',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'If false, return an error if any of the following targets only missing/closed indices: wildcard expression, index alias, or <code>_all</code> value. Defaults to true.',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Expand Wildcards',
|
||||
name: 'expand_wildcards',
|
||||
description:
|
||||
'Type of index that wildcard expressions can match. Defaults to <code>open</code>',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'All',
|
||||
value: 'all',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
{
|
||||
name: 'Hidden',
|
||||
value: 'hidden',
|
||||
},
|
||||
{
|
||||
name: 'None',
|
||||
value: 'none',
|
||||
},
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
],
|
||||
default: 'all',
|
||||
},
|
||||
{
|
||||
displayName: 'Flat Settings',
|
||||
name: 'flat_settings',
|
||||
description: 'Whether to return settings in flat format. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Ignore Unavailable',
|
||||
name: 'ignore_unavailable',
|
||||
description:
|
||||
'Whether to request that target a missing index return an error. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Include Defaults',
|
||||
name: 'include_defaults',
|
||||
description: 'Whether to return all default settings in the response. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Local',
|
||||
name: 'local',
|
||||
description: 'Whether to retrieve information from the local node only. Defaults to false.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Master Timeout',
|
||||
name: 'master_timeout',
|
||||
description:
|
||||
'Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to <code>1m</code>. See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units">Elasticsearch time units reference</a>',
|
||||
type: 'string',
|
||||
default: '1m',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// index: getAll
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['index'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './DocumentDescription';
|
||||
export * from './IndexDescription';
|
||||
@@ -0,0 +1,43 @@
|
||||
export const indexSettings = `{
|
||||
"settings": {
|
||||
"index": {
|
||||
"number_of_shards": 3,
|
||||
"number_of_replicas": 2
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
export const mappings = `{
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"field1": { "type": "text" }
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
export const aliases = `{
|
||||
"aliases": {
|
||||
"alias_1": {},
|
||||
"alias_2": {
|
||||
"filter": {
|
||||
"term": { "user.id": "kimchy" }
|
||||
},
|
||||
"routing": "shard-1"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
export const query = `{
|
||||
"query": {
|
||||
"term": {
|
||||
"user.id": "john"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
export const document = `{
|
||||
"timestamp": "2099-05-06T16:21:15.000Z",
|
||||
"event": {
|
||||
"original": "192.0.2.42 - - [06/May/2099:16:21:15 +0000] \"GET /images/bg.jpg HTTP/1.0\" 200 24736"
|
||||
}
|
||||
}`;
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="6 5 54 54"><g fill="none" fill-rule="evenodd"><path d="M0 0h64v64H0z"/><path fill="#FEC514" d="m55.725 14.708.003-.007C50.775 8.775 43.328 5 35 5c-10.6 0-19.767 6.11-24.186 15h35.192c2.525 0 4.983-.87 6.915-2.497a22.5 22.5 0 0 0 2.804-2.796"/><path fill="#343741" d="M8 32c0 2.422.324 4.767.922 7H42a7 7 0 1 0 0-14H8.922A27 27 0 0 0 8 32"/><path fill="#00BFB3" d="m55.725 49.293.003.005C50.775 55.226 43.328 59 35 59c-10.6 0-19.767-6.111-24.186-15h35.192c2.525 0 4.983.87 6.915 2.496a22.5 22.5 0 0 1 2.804 2.796"/></g></svg>
|
||||
|
After Width: | Height: | Size: 596 B |
@@ -0,0 +1,112 @@
|
||||
import { type IExecuteFunctions, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import { elasticsearchApiRequest } from '../GenericFunctions';
|
||||
|
||||
describe('Elasticsearch -> elasticsearchApiRequest', () => {
|
||||
let mockExecuteFunctions: IExecuteFunctions;
|
||||
|
||||
const mockHttpRequestWithAuthentication = jest.fn();
|
||||
|
||||
const setupMockFunctions = () => {
|
||||
mockExecuteFunctions = {
|
||||
getCredentials: jest.fn().mockResolvedValue({
|
||||
baseUrl: 'https://example.com',
|
||||
ignoreSSLIssues: false,
|
||||
}),
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: mockHttpRequestWithAuthentication,
|
||||
},
|
||||
getNode: jest.fn().mockReturnValue({}),
|
||||
} as unknown as IExecuteFunctions;
|
||||
jest.clearAllMocks();
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
setupMockFunctions();
|
||||
mockHttpRequestWithAuthentication.mockClear();
|
||||
});
|
||||
|
||||
const response = { success: true };
|
||||
|
||||
it('should make a successful GET API request', async () => {
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(response);
|
||||
|
||||
const result = await elasticsearchApiRequest.call(
|
||||
mockExecuteFunctions,
|
||||
'GET',
|
||||
'/test-endpoint',
|
||||
);
|
||||
|
||||
expect(result).toEqual(response);
|
||||
expect(mockExecuteFunctions.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'elasticsearchApi',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
url: 'https://example.com/test-endpoint',
|
||||
json: true,
|
||||
skipSslCertificateValidation: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should make a successful POST API request', async () => {
|
||||
const body = { key: 'value' };
|
||||
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(response);
|
||||
|
||||
const result = await elasticsearchApiRequest.call(
|
||||
mockExecuteFunctions,
|
||||
'POST',
|
||||
'/test-endpoint',
|
||||
body,
|
||||
);
|
||||
|
||||
expect(result).toEqual(response);
|
||||
expect(mockExecuteFunctions.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'elasticsearchApi',
|
||||
expect.objectContaining({
|
||||
body,
|
||||
method: 'POST',
|
||||
url: 'https://example.com/test-endpoint',
|
||||
json: true,
|
||||
skipSslCertificateValidation: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle API request errors', async () => {
|
||||
const errorResponse = { message: 'Error occurred' };
|
||||
mockHttpRequestWithAuthentication.mockRejectedValue(errorResponse);
|
||||
|
||||
await expect(
|
||||
elasticsearchApiRequest.call(mockExecuteFunctions, 'GET', '/test-endpoint'),
|
||||
).rejects.toThrow(NodeApiError);
|
||||
|
||||
expect(mockExecuteFunctions.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'elasticsearchApi',
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
url: 'https://example.com/test-endpoint',
|
||||
json: true,
|
||||
skipSslCertificateValidation: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore trailing slashes in the base URL', async () => {
|
||||
mockHttpRequestWithAuthentication.mockResolvedValue(response);
|
||||
|
||||
mockExecuteFunctions.getCredentials = jest.fn().mockResolvedValue({
|
||||
baseUrl: 'https://elastic.domain.com/',
|
||||
ignoreSSLIssues: false,
|
||||
});
|
||||
await elasticsearchApiRequest.call(mockExecuteFunctions, 'GET', '/test-endpoint');
|
||||
|
||||
expect(mockExecuteFunctions.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'elasticsearchApi',
|
||||
expect.objectContaining({
|
||||
url: 'https://elastic.domain.com/test-endpoint',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
export type ElasticsearchApiCredentials = {
|
||||
username: string;
|
||||
password: string;
|
||||
baseUrl: string;
|
||||
ignoreSSLIssues: boolean;
|
||||
};
|
||||
|
||||
export type DocumentGetAllOptions = Partial<{
|
||||
allow_no_indices: boolean;
|
||||
allow_partial_search_results: boolean;
|
||||
batched_reduce_size: number;
|
||||
ccs_minimize_roundtrips: boolean;
|
||||
docvalue_fields: string;
|
||||
expand_wildcards: 'All' | 'Closed' | 'Hidden' | 'None' | 'Open';
|
||||
explain: boolean;
|
||||
ignore_throttled: boolean;
|
||||
ignore_unavailable: boolean;
|
||||
max_concurrent_shard_requests: number;
|
||||
pre_filter_shard_size: number;
|
||||
query: string;
|
||||
request_cache: boolean;
|
||||
routing: string;
|
||||
search_type: 'query_then_fetch' | 'dfs_query_then_fetch';
|
||||
seq_no_primary_term: boolean;
|
||||
sort: string;
|
||||
_source: boolean;
|
||||
_source_excludes: string;
|
||||
_source_includes: string;
|
||||
stats: string;
|
||||
stored_fields: boolean;
|
||||
terminate_after: boolean;
|
||||
timeout: number;
|
||||
track_scores: boolean;
|
||||
track_total_hits: string;
|
||||
version: boolean;
|
||||
}>;
|
||||
|
||||
export type FieldsUiValues = Array<{
|
||||
fieldId: string;
|
||||
fieldValue: string;
|
||||
}>;
|
||||
Reference in New Issue
Block a user