mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
@@ -42,9 +40,7 @@ import {
|
||||
ElasticSecurityApiCredentials,
|
||||
} from './types';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
export class ElasticSecurity implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -107,13 +103,17 @@ export class ElasticSecurity implements INodeType {
|
||||
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 }));
|
||||
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[];
|
||||
const connectors = (await elasticSecurityApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
endpoint,
|
||||
)) as Connector[];
|
||||
return connectors.map(({ name, id }) => ({ name, value: id }));
|
||||
},
|
||||
},
|
||||
@@ -172,17 +172,13 @@ export class ElasticSecurity implements INodeType {
|
||||
let responseData;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
|
||||
try {
|
||||
|
||||
if (resource === 'case') {
|
||||
|
||||
// **********************************************************************
|
||||
// case
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------------
|
||||
// case: create
|
||||
// ----------------------------------------
|
||||
@@ -208,7 +204,10 @@ export class ElasticSecurity implements INodeType {
|
||||
type: fetchedType,
|
||||
} = await getConnector.call(this, connectorId);
|
||||
|
||||
const selectedConnectorType = this.getNodeParameter('connectorType', i) as ConnectorType;
|
||||
const selectedConnectorType = this.getNodeParameter(
|
||||
'connectorType',
|
||||
i,
|
||||
) as ConnectorType;
|
||||
|
||||
if (fetchedType !== selectedConnectorType) {
|
||||
throw new NodeOperationError(
|
||||
@@ -260,9 +259,7 @@ export class ElasticSecurity implements INodeType {
|
||||
}
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'POST', '/cases', body);
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
|
||||
// ----------------------------------------
|
||||
// case: delete
|
||||
// ----------------------------------------
|
||||
@@ -272,9 +269,7 @@ export class ElasticSecurity implements INodeType {
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
await elasticSecurityApiRequest.call(this, 'DELETE', `/cases?ids=["${caseId}"]`);
|
||||
responseData = { success: true };
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------------
|
||||
// case: get
|
||||
// ----------------------------------------
|
||||
@@ -283,9 +278,7 @@ export class ElasticSecurity implements INodeType {
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'GET', `/cases/${caseId}`);
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------------
|
||||
// case: getAll
|
||||
// ----------------------------------------
|
||||
@@ -293,10 +286,10 @@ export class ElasticSecurity implements INodeType {
|
||||
// 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 { 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';
|
||||
@@ -311,9 +304,7 @@ export class ElasticSecurity implements INodeType {
|
||||
}
|
||||
|
||||
responseData = await handleListing.call(this, 'GET', '/cases/_find', {}, qs);
|
||||
|
||||
} else if (operation === 'getStatus') {
|
||||
|
||||
// ----------------------------------------
|
||||
// case: getStatus
|
||||
// ----------------------------------------
|
||||
@@ -321,9 +312,7 @@ export class ElasticSecurity implements INodeType {
|
||||
// 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
|
||||
// ----------------------------------------
|
||||
@@ -353,17 +342,13 @@ export class ElasticSecurity implements INodeType {
|
||||
});
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', '/cases', body);
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'caseTag') {
|
||||
|
||||
// **********************************************************************
|
||||
// caseTag
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'add') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseTag: add
|
||||
// ----------------------------------------
|
||||
@@ -372,14 +357,8 @@ export class ElasticSecurity implements INodeType {
|
||||
|
||||
const caseId = this.getNodeParameter('caseId', i);
|
||||
|
||||
const {
|
||||
title,
|
||||
connector,
|
||||
owner,
|
||||
description,
|
||||
settings,
|
||||
tags,
|
||||
} = await elasticSecurityApiRequest.call(this, 'GET', `/cases/${caseId}`);
|
||||
const { title, connector, owner, description, settings, tags } =
|
||||
await elasticSecurityApiRequest.call(this, 'GET', `/cases/${caseId}`);
|
||||
|
||||
const tagToAdd = this.getNodeParameter('tag', i);
|
||||
|
||||
@@ -409,25 +388,25 @@ export class ElasticSecurity implements INodeType {
|
||||
});
|
||||
|
||||
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[] };
|
||||
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 });
|
||||
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 = {};
|
||||
@@ -448,17 +427,13 @@ export class ElasticSecurity implements INodeType {
|
||||
});
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'PATCH', '/cases', body);
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'caseComment') {
|
||||
|
||||
// **********************************************************************
|
||||
// caseComment
|
||||
// **********************************************************************
|
||||
|
||||
if (operation === 'add') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: add
|
||||
// ----------------------------------------
|
||||
@@ -483,9 +458,7 @@ export class ElasticSecurity implements INodeType {
|
||||
const { comments } = responseData;
|
||||
responseData = comments[comments.length - 1];
|
||||
}
|
||||
|
||||
} else if (operation === 'get') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: get
|
||||
// ----------------------------------------
|
||||
@@ -497,9 +470,7 @@ export class ElasticSecurity implements INodeType {
|
||||
|
||||
const endpoint = `/cases/${caseId}/comments/${commentId}`;
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'GET', endpoint);
|
||||
|
||||
} else if (operation === 'getAll') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: getAll
|
||||
// ----------------------------------------
|
||||
@@ -510,9 +481,7 @@ export class ElasticSecurity implements INodeType {
|
||||
|
||||
const endpoint = `/cases/${caseId}/comments`;
|
||||
responseData = await handleListing.call(this, 'GET', endpoint);
|
||||
|
||||
} else if (operation === 'remove') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: remove
|
||||
// ----------------------------------------
|
||||
@@ -525,9 +494,7 @@ export class ElasticSecurity implements INodeType {
|
||||
const endpoint = `/cases/${caseId}/comments/${commentId}`;
|
||||
await elasticSecurityApiRequest.call(this, 'DELETE', endpoint);
|
||||
responseData = { success: true };
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
||||
// ----------------------------------------
|
||||
// caseComment: update
|
||||
// ----------------------------------------
|
||||
@@ -553,13 +520,9 @@ export class ElasticSecurity implements INodeType {
|
||||
const { comments } = responseData;
|
||||
responseData = comments[comments.length - 1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if (resource === 'connector') {
|
||||
|
||||
if (operation === 'create') {
|
||||
|
||||
// ----------------------------------------
|
||||
// connector: create
|
||||
// ----------------------------------------
|
||||
@@ -601,16 +564,18 @@ export class ElasticSecurity implements INodeType {
|
||||
};
|
||||
}
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(this, 'POST', '/actions/connector', body);
|
||||
|
||||
responseData = await elasticSecurityApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/actions/connector',
|
||||
body,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Array.isArray(responseData)
|
||||
? returnData.push(...responseData)
|
||||
: returnData.push(responseData);
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
@@ -618,7 +583,6 @@ export class ElasticSecurity implements INodeType {
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
|
||||
Reference in New Issue
Block a user