feat(TheHive Node): Overhaul (#6457)

This commit is contained in:
Michael Kret
2023-09-04 18:15:52 +03:00
committed by GitHub
parent f286bd33c1
commit 73e782e2cf
85 changed files with 8291 additions and 4 deletions

View File

@@ -0,0 +1,86 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { alertRLC, caseRLC } from '../../descriptions';
const properties: INodeProperties[] = [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Add to',
name: 'addTo',
type: 'options',
options: [
{
name: 'Alert',
value: 'alert',
},
{
name: 'Case',
value: 'case',
},
],
default: 'alert',
},
{
...caseRLC,
name: 'id',
displayOptions: {
show: {
addTo: ['case'],
},
},
},
{
...alertRLC,
name: 'id',
displayOptions: {
show: {
addTo: ['alert'],
},
},
},
{
displayName: 'Message',
name: 'message',
type: 'string',
default: '',
required: true,
typeOptions: {
rows: 2,
},
},
];
const displayOptions = {
show: {
resource: ['comment'],
operation: ['add'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const addTo = this.getNodeParameter('addTo', i) as string;
const id = this.getNodeParameter('id', i, '', { extractValue: true });
const message = this.getNodeParameter('message', i) as string;
const body: IDataObject = {
message,
};
responseData = await theHiveApiRequest.call(this, 'POST', `/v1/${addTo}/${id}/comment`, body);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}

View File

@@ -0,0 +1,27 @@
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { commentRLC } from '../../descriptions';
const properties: INodeProperties[] = [commentRLC];
const displayOptions = {
show: {
resource: ['comment'],
operation: ['deleteComment'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
const commentId = this.getNodeParameter('commentId', i, '', { extractValue: true }) as string;
await theHiveApiRequest.call(this, 'DELETE', `/v1/comment/${commentId}`);
const executionData = this.helpers.constructExecutionMetaData(wrapData({ success: true }), {
itemData: { item: i },
});
return executionData;
}

View File

@@ -0,0 +1,50 @@
import type { INodeProperties } from 'n8n-workflow';
import * as add from './add.operation';
import * as deleteComment from './deleteComment.operation';
import * as search from './search.operation';
import * as update from './update.operation';
export { add, deleteComment, search, update };
export const description: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
required: true,
default: 'add',
options: [
{
name: 'Create',
value: 'add',
action: 'Create a comment in a case or alert',
},
{
name: 'Delete',
value: 'deleteComment',
action: 'Delete a comment',
},
{
name: 'Search',
value: 'search',
action: 'Search comments',
},
{
name: 'Update',
value: 'update',
action: 'Update a comment',
},
],
displayOptions: {
show: {
resource: ['comment'],
},
},
},
...add.description,
...deleteComment.description,
...search.description,
...update.description,
];

View File

@@ -0,0 +1,118 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import {
alertRLC,
caseRLC,
genericFiltersCollection,
returnAllAndLimit,
searchOptions,
sortCollection,
} from '../../descriptions';
import { theHiveApiQuery } from '../../transport';
import type { QueryScope } from '../../helpers/interfaces';
const properties: INodeProperties[] = [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Search in',
name: 'searchIn',
type: 'options',
default: 'all',
description:
'Whether to search for comments in all alerts and cases or in a specific case or alert',
options: [
{
name: 'Alerts and Cases',
value: 'all',
},
{
name: 'Alert',
value: 'alert',
},
{
name: 'Case',
value: 'case',
},
],
},
{
...caseRLC,
displayOptions: {
show: {
searchIn: ['case'],
},
},
},
{
...alertRLC,
displayOptions: {
show: {
searchIn: ['alert'],
},
},
},
...returnAllAndLimit,
genericFiltersCollection,
sortCollection,
searchOptions,
];
const displayOptions = {
show: {
resource: ['comment'],
operation: ['search'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const searchIn = this.getNodeParameter('searchIn', i) as string;
const filtersValues = this.getNodeParameter('filters.values', i, []) as IDataObject[];
const sortFields = this.getNodeParameter('sort.fields', i, []) as IDataObject[];
const returnAll = this.getNodeParameter('returnAll', i);
const { returnCount, extraData } = this.getNodeParameter('options', i);
let limit;
let scope: QueryScope;
if (searchIn === 'all') {
scope = { query: 'listComment' };
} else if (searchIn === 'alert') {
const alertId = this.getNodeParameter('alertId', i, '', { extractValue: true }) as string;
scope = { query: 'getAlert', id: alertId, restrictTo: 'comments' };
} else if (searchIn === 'case') {
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
scope = { query: 'getCase', id: caseId, restrictTo: 'comments' };
} else {
throw new NodeOperationError(this.getNode(), `Invalid 'Search In ...' value: ${searchIn}`);
}
if (!returnAll) {
limit = this.getNodeParameter('limit', i);
}
responseData = await theHiveApiQuery.call(
this,
scope,
filtersValues,
sortFields,
limit,
returnCount as boolean,
extraData as string[],
);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}

View File

@@ -0,0 +1,51 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { commentRLC } from '../../descriptions';
const properties: INodeProperties[] = [
commentRLC,
{
displayName: 'Message',
name: 'message',
type: 'string',
default: '',
required: true,
typeOptions: {
rows: 2,
},
},
];
const displayOptions = {
show: {
resource: ['comment'],
operation: ['update'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const commentId = this.getNodeParameter('commentId', i, '', { extractValue: true }) as string;
const message = this.getNodeParameter('message', i) as string;
const body: IDataObject = {
message,
};
responseData = await theHiveApiRequest.call(this, 'PATCH', `/v1/comment/${commentId}`, body);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}