From 81d8a9f332c152cbe5f80e8adda83b6a9b529b1e Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Sat, 24 Apr 2021 23:14:06 +0200 Subject: [PATCH] :boom: Deprecate Activation Trigger and add two new replacement nodes (#1680) * 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 * :zap: Minor improvements Co-authored-by: dali Co-authored-by: Jan Oberhauser --- packages/cli/BREAKING-CHANGES.md | 16 ++++ .../nodes/ActivationTrigger.node.ts | 73 ----------------- packages/nodes-base/nodes/N8nTrigger.node.ts | 71 ++++++++++++++++ .../nodes-base/nodes/WorkflowTrigger.node.ts | 81 +++++++++++++++++++ packages/nodes-base/nodes/n8nTrigger.svg | 24 ++++++ packages/nodes-base/package.json | 3 +- 6 files changed, 194 insertions(+), 74 deletions(-) delete mode 100644 packages/nodes-base/nodes/ActivationTrigger.node.ts create mode 100644 packages/nodes-base/nodes/N8nTrigger.node.ts create mode 100644 packages/nodes-base/nodes/WorkflowTrigger.node.ts create mode 100644 packages/nodes-base/nodes/n8nTrigger.svg diff --git a/packages/cli/BREAKING-CHANGES.md b/packages/cli/BREAKING-CHANGES.md index 5435714e8e..55be53d7c7 100644 --- a/packages/cli/BREAKING-CHANGES.md +++ b/packages/cli/BREAKING-CHANGES.md @@ -5,6 +5,21 @@ This list shows all the versions which include breaking changes and how to upgra ## 0.117.0 ### What changed? +Removed the "Activation Trigger" node. This node was replaced by two other nodes. + +The "Activation Trigger" node was added on version 0.113.0 but was not fully compliant to UX, so we decided to refactor and change it ASAP so it affects the least possible users. + +The new nodes are "n8n Trigger" and "Workflow Trigger". Behavior-wise, the nodes do the same, we just split the functionality to make it more intuitive to users. + +### When is action necessary? + +If you use the "Activation Trigger" in any of your workflows, please replace it by the new nodes. + +### How to upgrade: + +Remove the previous node and add the new ones according to your workflows. + +---------------------------- Changed the behavior for nodes that use Postgres Wire Protocol: Postgres, QuestDB, CrateDB and TimescaleDB. @@ -22,6 +37,7 @@ By default, all `insert` operations will have `Return fields: *` as the default, Previously, the node would return all information it received, without taking into account what actually happened in the database. + ## 0.113.0 ### What changed? diff --git a/packages/nodes-base/nodes/ActivationTrigger.node.ts b/packages/nodes-base/nodes/ActivationTrigger.node.ts deleted file mode 100644 index 83c656ade1..0000000000 --- a/packages/nodes-base/nodes/ActivationTrigger.node.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { ITriggerFunctions } from 'n8n-core'; -import { - INodeType, - INodeTypeDescription, - ITriggerResponse, -} from 'n8n-workflow'; - -export class ActivationTrigger implements INodeType { - description: INodeTypeDescription = { - displayName: 'Activation Trigger', - name: 'activationTrigger', - icon: 'fa:play-circle', - group: ['trigger'], - version: 1, - description: 'Executes whenever the workflow becomes active.', - defaults: { - name: 'Activation Trigger', - color: '#00e000', - }, - inputs: [], - outputs: ['main'], - properties: [ - { - displayName: 'Events', - name: 'events', - type: 'multiOptions', - required: true, - default: [], - description: 'Specifies under which conditions an execution should happen:
' + - '- Activation: Workflow gets activated
' + - '- Update: Workflow gets saved while active
' + - '- Start: n8n starts or restarts', - options: [ - { - name: 'Activation', - value: 'activate', - description: 'Run when workflow gets activated', - }, - { - name: 'Start', - value: 'init', - description: 'Run when n8n starts or restarts', - }, - { - name: 'Update', - value: 'update', - description: 'Run when workflow gets saved while it is active', - }, - ], - }, - ], - }; - - - async trigger(this: ITriggerFunctions): Promise { - const events = this.getNodeParameter('events', []) as string[]; - - const activationMode = this.getActivationMode(); - - if (events.includes(activationMode)) { - this.emit([this.helpers.returnJsonArray([{ activation: activationMode }])]); - } - - const self = this; - async function manualTriggerFunction() { - self.emit([self.helpers.returnJsonArray([{ activation: 'manual' }])]); - } - - return { - manualTriggerFunction, - }; - } -} diff --git a/packages/nodes-base/nodes/N8nTrigger.node.ts b/packages/nodes-base/nodes/N8nTrigger.node.ts new file mode 100644 index 0000000000..245f65601e --- /dev/null +++ b/packages/nodes-base/nodes/N8nTrigger.node.ts @@ -0,0 +1,71 @@ +import { ITriggerFunctions } from 'n8n-core'; +import { + 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 from your n8n instance', + defaults: { + name: 'n8n 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:
' + + '- Instance started: 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 { + 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 self = this; + async function manualTriggerFunction() { + self.emit([self.helpers.returnJsonArray([{ event: 'Manual execution', timestamp: (new Date()).toISOString(), workflow_id: self.getWorkflow().id }])]); + } + + return { + manualTriggerFunction, + }; + } +} diff --git a/packages/nodes-base/nodes/WorkflowTrigger.node.ts b/packages/nodes-base/nodes/WorkflowTrigger.node.ts new file mode 100644 index 0000000000..dfd7f2190b --- /dev/null +++ b/packages/nodes-base/nodes/WorkflowTrigger.node.ts @@ -0,0 +1,81 @@ +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:
' + + '- Active Workflow Updated: Triggers when this workflow is updated
' + + '- Workflow Activated: 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 { + 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, + }; + } +} diff --git a/packages/nodes-base/nodes/n8nTrigger.svg b/packages/nodes-base/nodes/n8nTrigger.svg new file mode 100644 index 0000000000..5cc4cbc1f3 --- /dev/null +++ b/packages/nodes-base/nodes/n8nTrigger.svg @@ -0,0 +1,24 @@ + + + + + + diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index c2dcda32b5..54bb70c5f4 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -271,7 +271,6 @@ "dist/credentials/ZulipApi.credentials.js" ], "nodes": [ - "dist/nodes/ActivationTrigger.node.js", "dist/nodes/ActiveCampaign/ActiveCampaign.node.js", "dist/nodes/ActiveCampaign/ActiveCampaignTrigger.node.js", "dist/nodes/AgileCrm/AgileCrm.node.js", @@ -442,6 +441,7 @@ "dist/nodes/MoveBinaryData.node.js", "dist/nodes/Msg91/Msg91.node.js", "dist/nodes/MySql/MySql.node.js", + "dist/nodes/N8nTrigger.node.js", "dist/nodes/Nasa/Nasa.node.js", "dist/nodes/NextCloud/NextCloud.node.js", "dist/nodes/NoOp.node.js", @@ -539,6 +539,7 @@ "dist/nodes/Webhook.node.js", "dist/nodes/Wekan/Wekan.node.js", "dist/nodes/Wordpress/Wordpress.node.js", + "dist/nodes/WorkflowTrigger.node.js", "dist/nodes/WooCommerce/WooCommerce.node.js", "dist/nodes/WooCommerce/WooCommerceTrigger.node.js", "dist/nodes/WriteBinaryFile.node.js",