mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
✨ Add Activation Trigger (#1570)
* ✨ n8n start trigger node * first declaration of WorkflowActivationMode * implement first WorkflowActivationMode: 'init', 'create', 'update', 'activate' * fix Server missing id * add activation infos to triggers * remove WorkflowActivationMode from webhook execution function * add some missing activation and add manual activation * clean up and fix some code * fix UnhandledPromiseRejectionWarning: Error: Overwrite NodeExecuteFunctions.getExecuteTriggerFunctions.emit function! * fix spaces * use a better name for the node * fix ident in package.json * Contributions to lublak's PR #1287 * Fixed linting issues and change the way parameters are displayed * ⚡ Fix name and minor improvements Co-authored-by: lublak <lublak.de@gmail.com> Co-authored-by: lublak <44057030+lublak@users.noreply.github.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
73
packages/nodes-base/nodes/ActivationTrigger.node.ts
Normal file
73
packages/nodes-base/nodes/ActivationTrigger.node.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user