mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
81d8a9f332
* Add Workflow & n8n Trigger nodes
* Update nodes descriptions & icons
* Remove Activation Trigger node
* Update nodes descriptions & Add timestamp and workflow_id
* Added breaking change notice and types to events
* ⚡ Minor improvements
Co-authored-by: dali <servfrdali@yahoo.fr>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { ITriggerFunctions } from 'n8n-core';
|
|
import {
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
ITriggerResponse,
|
|
} from 'n8n-workflow';
|
|
|
|
type eventType = 'Workflow activated' | 'Workflow updated' | undefined;
|
|
type activationType = 'activate' | 'update';
|
|
|
|
export class WorkflowTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Workflow Trigger',
|
|
name: 'workflowTrigger',
|
|
icon: 'fa:network-wired',
|
|
group: ['trigger'],
|
|
version: 1,
|
|
description: 'Triggers based on various lifecycle events, like when a workflow is activated',
|
|
defaults: {
|
|
name: 'Workflow Trigger',
|
|
color: '#ff6d5a',
|
|
},
|
|
inputs: [],
|
|
outputs: ['main'],
|
|
properties: [
|
|
{
|
|
displayName: 'Events',
|
|
name: 'events',
|
|
type: 'multiOptions',
|
|
required: true,
|
|
default: [],
|
|
description: 'Specifies under which conditions an execution should happen:<br />' +
|
|
'- <b>Active Workflow Updated</b>: Triggers when this workflow is updated<br />' +
|
|
'- <b>Workflow Activated</b>: Triggers when this workflow is activated',
|
|
options: [
|
|
{
|
|
name: 'Active Workflow Updated',
|
|
value: 'update',
|
|
description: 'Triggers when this workflow is updated',
|
|
},
|
|
{
|
|
name: 'Workflow Activated',
|
|
value: 'activate',
|
|
description: 'Triggers when this workflow is activated',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
|
|
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
|
const events = this.getNodeParameter('events', []) as activationType[];
|
|
|
|
const activationMode = this.getActivationMode() as activationType;
|
|
|
|
if (events.includes(activationMode)) {
|
|
let event: eventType;
|
|
if (activationMode === 'activate') {
|
|
event = 'Workflow activated';
|
|
}
|
|
if (activationMode === 'update') {
|
|
event = 'Workflow updated';
|
|
}
|
|
this.emit([
|
|
this.helpers.returnJsonArray([
|
|
{ event, timestamp: (new Date()).toISOString(), workflow_id: this.getWorkflow().id },
|
|
]),
|
|
]);
|
|
}
|
|
|
|
const self = this;
|
|
async function manualTriggerFunction() {
|
|
self.emit([self.helpers.returnJsonArray([{ event: 'Manual execution', timestamp: (new Date()).toISOString(), workflow_id: self.getWorkflow().id }])]);
|
|
}
|
|
|
|
return {
|
|
manualTriggerFunction,
|
|
};
|
|
}
|
|
}
|