n8n-nodes-base
Version:
Base nodes of n8n
79 lines • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TheHiveTrigger = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const EventsDescription_1 = require("./descriptions/EventsDescription");
class TheHiveTrigger {
description = {
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: [n8n_workflow_1.NodeConnectionTypes.Main],
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
properties: [
{
displayName: 'You must set up the webhook in TheHive — instructions <a href="https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.thehivetrigger/#configure-a-webhook-in-thehive" target="_blank">here</a>',
name: 'notice',
type: 'notice',
default: '',
},
...EventsDescription_1.eventsDescription,
],
};
webhookMethods = {
default: {
async checkExists() {
return true;
},
async create() {
return true;
},
async delete() {
return true;
},
},
};
async webhook() {
// Get the request body
const bodyData = this.getBodyData();
const events = this.getNodeParameter('events', []);
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.replace('Creation', 'Create');
const event = `${bodyData.objectType.toLowerCase()}_${operation.toLowerCase()}`;
if (events.indexOf('*') === -1 && events.indexOf(event) === -1) {
return {};
}
// The data to return and so start the workflow with
const returnData = [];
returnData.push({
event,
body: this.getBodyData(),
headers: this.getHeaderData(),
query: this.getQueryData(),
});
return {
workflowData: [this.helpers.returnJsonArray(returnData)],
};
}
}
exports.TheHiveTrigger = TheHiveTrigger;
//# sourceMappingURL=TheHiveTrigger.node.js.map