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,102 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { caseRLC } from '../../descriptions';
const properties: INodeProperties[] = [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Create in',
name: 'location',
type: 'options',
options: [
{
name: 'Case',
value: 'case',
},
{
name: 'Knowledge Base',
value: 'knowledgeBase',
},
],
default: 'case',
},
{
...caseRLC,
displayOptions: {
show: {
location: ['case'],
},
},
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Category',
name: 'category',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
required: true,
typeOptions: {
rows: 2,
},
},
];
const displayOptions = {
show: {
resource: ['page'],
operation: ['create'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const location = this.getNodeParameter('location', i) as string;
const title = this.getNodeParameter('title', i) as string;
const category = this.getNodeParameter('category', i) as string;
const content = this.getNodeParameter('content', i) as string;
let endpoint;
if (location === 'case') {
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
endpoint = `/v1/case/${caseId}/page`;
} else {
endpoint = '/v1/page';
}
const body: IDataObject = {
title,
category,
content,
};
responseData = await theHiveApiRequest.call(this, 'POST', endpoint, body);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}

View File

@@ -0,0 +1,63 @@
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { caseRLC, pageRLC } from '../../descriptions';
const properties: INodeProperties[] = [
{
displayName: 'Delete From ...',
name: 'location',
type: 'options',
options: [
{
name: 'Case',
value: 'case',
},
{
name: 'Knowledge Base',
value: 'knowledgeBase',
},
],
default: 'knowledgeBase',
},
{
...caseRLC,
displayOptions: {
show: {
location: ['case'],
},
},
},
pageRLC,
];
const displayOptions = {
show: {
resource: ['page'],
operation: ['deletePage'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
const location = this.getNodeParameter('location', i) as string;
const pageId = this.getNodeParameter('pageId', i, '', { extractValue: true }) as string;
let endpoint;
if (location === 'case') {
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
endpoint = `/v1/case/${caseId}/page/${pageId}`;
} else {
endpoint = `/v1/page/${pageId}`;
}
await theHiveApiRequest.call(this, 'DELETE', endpoint);
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 create from './create.operation';
import * as deletePage from './deletePage.operation';
import * as search from './search.operation';
import * as update from './update.operation';
export { create, deletePage, search, update };
export const description: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
noDataExpression: true,
type: 'options',
required: true,
default: 'create',
options: [
{
name: 'Create',
value: 'create',
action: 'Create a page',
},
{
name: 'Delete',
value: 'deletePage',
action: 'Delete a page',
},
{
name: 'Search',
value: 'search',
action: 'Search pages',
},
{
name: 'Update',
value: 'update',
action: 'Update a page',
},
],
displayOptions: {
show: {
resource: ['page'],
},
},
},
...create.description,
...deletePage.description,
...search.description,
...update.description,
];

View File

@@ -0,0 +1,96 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import {
caseRLC,
genericFiltersCollection,
returnAllAndLimit,
sortCollection,
searchOptions,
} from '../../descriptions';
import { theHiveApiQuery } from '../../transport';
import type { QueryScope } from '../../helpers/interfaces';
const properties: INodeProperties[] = [
{
displayName: 'Search in Knowledge Base',
name: 'searchInKnowledgeBase',
type: 'boolean',
default: true,
description: 'Whether to search in knowledge base or only in the selected case',
},
{
...caseRLC,
displayOptions: {
show: {
searchInKnowledgeBase: [false],
},
},
},
...returnAllAndLimit,
genericFiltersCollection,
sortCollection,
{
...searchOptions,
displayOptions: {
show: {
returnAll: [true],
},
},
},
];
const displayOptions = {
show: {
resource: ['page'],
operation: ['search'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const searchInKnowledgeBase = this.getNodeParameter('searchInKnowledgeBase', i) as boolean;
const filtersValues = this.getNodeParameter('filters.values', i, []) as IDataObject[];
const sortFields = this.getNodeParameter('sort.fields', i, []) as IDataObject[];
const returnAll = this.getNodeParameter('returnAll', i);
let returnCount = false;
if (!returnAll) {
returnCount = this.getNodeParameter('options.returnCount', i, false) as boolean;
}
let limit;
let scope: QueryScope;
if (searchInKnowledgeBase) {
scope = { query: 'listOrganisationPage' };
} else {
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
scope = { query: 'getCase', id: caseId, restrictTo: 'pages' };
}
if (!returnAll) {
limit = this.getNodeParameter('limit', i);
}
responseData = await theHiveApiQuery.call(
this,
scope,
filtersValues,
sortFields,
limit,
returnCount,
);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}

View File

@@ -0,0 +1,118 @@
import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { theHiveApiRequest } from '../../transport';
import { caseRLC, pageRLC } from '../../descriptions';
const properties: INodeProperties[] = [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Update in',
name: 'location',
type: 'options',
options: [
{
name: 'Case',
value: 'case',
},
{
name: 'Knowledge Base',
value: 'knowledgeBase',
},
],
default: 'case',
},
{
...caseRLC,
displayOptions: {
show: {
location: ['case'],
},
},
},
pageRLC,
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
typeOptions: {
rows: 2,
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Category',
name: 'category',
type: 'string',
default: '',
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
},
{
displayName: 'Order',
name: 'order',
type: 'number',
default: 0,
typeOptions: {
minValue: 0,
},
},
],
},
];
const displayOptions = {
show: {
resource: ['page'],
operation: ['update'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
let responseData: IDataObject | IDataObject[] = [];
const location = this.getNodeParameter('location', i) as string;
const pageId = this.getNodeParameter('pageId', i, '', { extractValue: true }) as string;
const content = this.getNodeParameter('content', i, '') as string;
const options = this.getNodeParameter('options', i, {});
let endpoint;
if (location === 'case') {
const caseId = this.getNodeParameter('caseId', i, '', { extractValue: true }) as string;
endpoint = `/v1/case/${caseId}/page/${pageId}`;
} else {
endpoint = `/v1/page/${pageId}`;
}
const body: IDataObject = options;
if (content) {
body.content = content;
}
responseData = await theHiveApiRequest.call(this, 'PATCH', endpoint, body);
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
itemData: { item: i },
});
return executionData;
}