n8n/packages/nodes-base/nodes/N8nTrigger/N8nTrigger.node.ts
OlegIvaniv 9a1e7b52f7
feat(editor): Unify regular and trigger node creator panels (#5315)
* WIP: Merge TriggerHelperPanel with MainPanel

* WIP: Implement switching between views

* Remove logging

* WIP: Rework search

* Fix category toggling and search results display

* Fix node item description

* Sort actions based on the root view

* Adjust personalisation modal, make trigger canvas node round

* Linting fixes

* Fix filtering of API options

* Fix types and no result state

* Cleanup

* Linting fixes

* Adjust mode prop for node creator tracking

* Fix merging of core nodes and filtering of single placeholder actions

* Lint fixes

* Implement actions override, fix node creator view item spacing and increase click radius of trigger node icon

* Fix keyboard view navigation

* WIP: E2E Tests

* Address product review

* Minor fixes & cleanup

* Fix tests

* Some more test fixes

* Add specs to check actions and panels

* Update personalisation survey snapshot
2023-02-17 15:08:26 +01:00

75 lines
1.8 KiB
TypeScript

import type { ITriggerFunctions } from 'n8n-core';
import type { INodeType, INodeTypeDescription, ITriggerResponse } from 'n8n-workflow';
type eventType = 'Instance started' | undefined;
export class N8nTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'n8n Trigger',
name: 'n8nTrigger',
icon: 'file:n8nTrigger.svg',
group: ['trigger'],
version: 1,
description: 'Handle events and perform actions on your n8n instance',
eventTriggerDescription: '',
mockManualExecution: true,
defaults: {
name: 'n8n Trigger',
},
inputs: [],
outputs: ['main'],
properties: [
{
displayName: 'Events',
name: 'events',
type: 'multiOptions',
required: true,
default: [],
description:
'Specifies under which conditions an execution should happen: <b>Instance started</b>: Triggers when this n8n instance is started or re-started',
options: [
{
name: 'Instance Started',
value: 'init',
description: 'Triggers when this n8n instance is started or re-started',
},
],
},
],
};
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
const events = this.getNodeParameter('events', []) as string[];
const activationMode = this.getActivationMode();
if (events.includes(activationMode)) {
let event: eventType;
if (activationMode === 'init') {
event = 'Instance started';
}
this.emit([
this.helpers.returnJsonArray([
{ event, timestamp: new Date().toISOString(), workflow_id: this.getWorkflow().id },
]),
]);
}
const manualTriggerFunction = async () => {
this.emit([
this.helpers.returnJsonArray([
{
event: 'Manual execution',
timestamp: new Date().toISOString(),
workflow_id: this.getWorkflow().id,
},
]),
]);
};
return {
manualTriggerFunction,
};
}
}