UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

64 lines 3.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SseTrigger = void 0; const eventsource_1 = __importDefault(require("eventsource")); const n8n_workflow_1 = require("n8n-workflow"); class SseTrigger { description = { displayName: 'SSE Trigger', name: 'sseTrigger', icon: 'fa:cloud-download-alt', iconColor: 'dark-blue', group: ['trigger'], version: 1, description: 'Triggers the workflow when Server-Sent Events occur', eventTriggerDescription: '', activationMessage: 'You can now make calls to your SSE URL to trigger executions.', defaults: { name: 'SSE Trigger', color: '#225577', }, triggerPanel: { header: '', executionsHelp: { inactive: "<b>While building your workflow</b>, click the 'execute step' button, then trigger an SSE event. This will trigger an execution, which will show up in this editor.<br /> <br /><b>Once you're happy with your workflow</b>, publish it. Then every time a change is detected, the workflow will execute. These executions will show up in the <a data-key='executions'>executions list</a>, but not in the editor.", active: "<b>While building your workflow</b>, click the 'execute step' button, then trigger an SSE event. This will trigger an execution, which will show up in this editor.<br /> <br /><b>Your workflow will also execute automatically</b>, since it's activated. Every time a change is detected, this node will trigger an execution. These executions will show up in the <a data-key='executions'>executions list</a>, but not in the editor.", }, activationHint: 'Once you’ve finished building your workflow, publish it to have it also listen continuously (you just won’t see those executions here).', }, inputs: [], outputs: [n8n_workflow_1.NodeConnectionTypes.Main], properties: [ { displayName: 'URL', name: 'url', type: 'string', default: '', placeholder: 'http://example.com', description: 'The URL to receive the SSE from', required: true, }, ], }; async trigger() { const url = this.getNodeParameter('url'); const eventSource = new eventsource_1.default(url); eventSource.onmessage = (event) => { const eventData = (0, n8n_workflow_1.jsonParse)(event.data, { errorMessage: 'Invalid JSON for event data', }); this.emit([this.helpers.returnJsonArray([eventData])]); }; async function closeFunction() { eventSource.close(); } return { closeFunction, }; } } exports.SseTrigger = SseTrigger; //# sourceMappingURL=SseTrigger.node.js.map