💥 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

*  Minor improvements

Co-authored-by: dali <servfrdali@yahoo.fr>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Omar Ajoue
2021-04-24 23:14:06 +02:00
committed by GitHub
parent 41669c0e0f
commit 81d8a9f332
6 changed files with 194 additions and 74 deletions

View File

@@ -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:<br />' +
'- <b>Activation</b>: Workflow gets activated<br />' +
'- <b>Update</b>: Workflow gets saved while active<br>' +
'- <b>Start</b>: 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<ITriggerResponse> {
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,
};
}
}

View File

@@ -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:<br />' +
'- <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 self = this;
async function manualTriggerFunction() {
self.emit([self.helpers.returnJsonArray([{ event: 'Manual execution', timestamp: (new Date()).toISOString(), workflow_id: self.getWorkflow().id }])]);
}
return {
manualTriggerFunction,
};
}
}

View File

@@ -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:<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,
};
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="5 5 55 55" style="enable-background:new 0 0 40 40;" xml:space="preserve">
<style type="text/css">
.st0{display:none;fill:#FF6D5A;}
.st1{fill:#FF6D5A;}
</style>
<path class="st0" d="M50.41,30.55v-1c0-0.55-0.45-1-1-1h-17.5v-2.5h4.5c1.1,0,2-0.9,2-2v-8c0-1.1-0.9-2-2-2h-12c-1.1,0-2,0.9-2,2v8
c0,1.1,0.9,2,2,2h4.5v2.5h-17.5c-0.55,0-1,0.45-1,1v1c0,0.55,0.45,1,1,1h6.5v2.5h-3.5c-1.1,0-2,0.9-2,2v8c0,1.1,0.9,2,2,2h10
c1.1,0,2-0.9,2-2v-8c0-1.1-0.9-2-2-2h-3.5v-2.5h19v2.5h-3.5c-1.1,0-2,0.9-2,2v8c0,1.1,0.9,2,2,2h10c1.1,0,2-0.9,2-2v-8
c0-1.1-0.9-2-2-2h-3.5v-2.5h6.5C49.96,31.55,50.41,31.1,50.41,30.55z M26.41,22.05v-4h8v4H26.41z M22.41,42.05h-6v-4h6V42.05z
M44.41,42.05h-6v-4h6V42.05z"/>
<path class="st1" d="M50.28,17.26c-2.39,0-4.4,1.64-4.97,3.86h-7.15c-2.8,0-5.08,2.28-5.08,5.08c0,1.4-1.14,2.54-2.54,2.54h-1.02
c-0.57-2.22-2.58-3.86-4.97-3.86c-2.39,0-4.4,1.64-4.97,3.86h-4.08c-0.57-2.22-2.58-3.86-4.97-3.86c-2.83,0-5.13,2.3-5.13,5.13
s2.3,5.13,5.13,5.13c2.39,0,4.4-1.64,4.97-3.86h4.08c0.57,2.22,2.58,3.86,4.97,3.86c2.37,0,4.37-1.62,4.95-3.81h1.03
c1.4,0,2.54,1.14,2.54,2.54c0,2.8,2.28,5.09,5.08,5.09h1.66c0.57,2.22,2.58,3.86,4.97,3.86c2.83,0,5.13-2.3,5.13-5.13
c0-2.83-2.3-5.13-5.13-5.13c-2.39,0-4.4,1.64-4.97,3.86h-1.66c-1.4,0-2.54-1.14-2.54-2.54c0-1.53-0.68-2.9-1.76-3.84
c1.07-0.93,1.76-2.31,1.76-3.84c0-1.4,1.14-2.54,2.54-2.54h7.15c0.57,2.22,2.58,3.86,4.97,3.86c2.83,0,5.13-2.3,5.13-5.13
S53.11,17.26,50.28,17.26z M10.54,32.61c-1.43,0-2.59-1.16-2.59-2.59c0-1.43,1.16-2.59,2.59-2.59s2.59,1.16,2.59,2.59
C13.13,31.45,11.97,32.61,10.54,32.61z M24.56,32.61c-1.43,0-2.59-1.16-2.59-2.59c0-1.43,1.16-2.59,2.59-2.59
c1.43,0,2.59,1.16,2.59,2.59C27.15,31.45,25.98,32.61,24.56,32.61z M44.8,35.11c1.43,0,2.59,1.16,2.59,2.59
c0,1.43-1.16,2.59-2.59,2.59c-1.43,0-2.59-1.16-2.59-2.59C42.21,36.27,43.37,35.11,44.8,35.11z M50.28,24.98
c-1.43,0-2.59-1.16-2.59-2.59c0-1.43,1.16-2.59,2.59-2.59c1.43,0,2.59,1.16,2.59,2.59C52.87,23.82,51.71,24.98,50.28,24.98z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -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",