mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-27 21:49:41 -08:00
61e26804ba
* ⚡ enabled array-type * ⚡ await-thenable on * ⚡ ban-types on * ⚡ default-param-last on * ⚡ dot-notation on * ⚡ member-delimiter-style on * ⚡ no-duplicate-imports on * ⚡ no-empty-interface on * ⚡ no-floating-promises on * ⚡ no-for-in-array on * ⚡ no-invalid-void-type on * ⚡ no-loop-func on * ⚡ no-shadow on * ⚡ ban-ts-comment re enabled * ⚡ @typescript-eslint/lines-between-class-members on * address my own comment * @typescript-eslint/return-await on * @typescript-eslint/promise-function-async on * @typescript-eslint/no-unnecessary-boolean-literal-compare on * @typescript-eslint/no-unnecessary-type-assertion on * prefer-const on * @typescript-eslint/prefer-optional-chain on Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import { IWebhookFunctions } from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
IHookFunctions,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
IWebhookResponseData,
|
|
} from 'n8n-workflow';
|
|
import { eventsDescription } from './descriptions/EventsDescription';
|
|
|
|
export class TheHiveTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'TheHive Trigger',
|
|
name: 'theHiveTrigger',
|
|
icon: 'file:thehive.svg',
|
|
group: ['trigger'],
|
|
version: [1, 2],
|
|
description: 'Starts the workflow when TheHive events occur',
|
|
defaults: {
|
|
name: 'TheHive Trigger',
|
|
},
|
|
inputs: [],
|
|
outputs: ['main'],
|
|
webhooks: [
|
|
{
|
|
name: 'default',
|
|
httpMethod: 'POST',
|
|
reponseMode: 'onReceived',
|
|
path: 'webhook',
|
|
},
|
|
],
|
|
properties: [...eventsDescription],
|
|
};
|
|
|
|
// @ts-ignore (because of request)
|
|
webhookMethods = {
|
|
default: {
|
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
|
return true;
|
|
},
|
|
async create(this: IHookFunctions): Promise<boolean> {
|
|
return true;
|
|
},
|
|
async delete(this: IHookFunctions): Promise<boolean> {
|
|
return true;
|
|
},
|
|
},
|
|
};
|
|
|
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
|
// Get the request body
|
|
const bodyData = this.getBodyData();
|
|
const events = this.getNodeParameter('events', []) as string[];
|
|
if (!bodyData.operation || !bodyData.objectType) {
|
|
// Don't start the workflow if mandatory fields are not specified
|
|
return {};
|
|
}
|
|
|
|
// Don't start the workflow if the event is not fired
|
|
// Replace Creation with Create for TheHive 3 support
|
|
const operation = (bodyData.operation as string).replace('Creation', 'Create');
|
|
const event = `${(bodyData.objectType as string).toLowerCase()}_${operation.toLowerCase()}`;
|
|
|
|
if (events.indexOf('*') === -1 && events.indexOf(event) === -1) {
|
|
return {};
|
|
}
|
|
|
|
// The data to return and so start the workflow with
|
|
const returnData: IDataObject[] = [];
|
|
returnData.push({
|
|
event,
|
|
body: this.getBodyData(),
|
|
headers: this.getHeaderData(),
|
|
query: this.getQueryData(),
|
|
});
|
|
|
|
return {
|
|
workflowData: [this.helpers.returnJsonArray(returnData)],
|
|
};
|
|
}
|
|
}
|