mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
63b6c9f128
* ✏️ Alphabetize rules * 🔖 Update version * ⚡ Update lintfix command * ⚡ Run baseline lintfix * 📦 Update package-lock.json * 👕 Apply `node-param-description-untrimmed` (#3200) * Removing unneeded backticks (#3249) * 👕 Apply node-param-description-wrong-for-return-all (#3253) * 👕 Apply node-param-description-missing-limit (#3252) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-description-excess-final-period (#3250) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-description-unencoded-angle-brackets (#3256) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-description-url-missing-protocol (#3258) * 👕 Apply `node-param-description-miscased-id` (#3254) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-description-wrong-for-limit (#3257) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-description-wrong-for-ignore-ssl-issues (#3261) * 👕 Apply rule * ⚡ Restore lintfix script * ⚡ Restore lintfix script Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 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',
|
|
eventTriggerDescription: '',
|
|
activationMessage: 'Your workflow will now trigger executions on the event you have defined.',
|
|
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:
|
|
<ul>
|
|
<li><b>Active Workflow Updated</b>: Triggers when this workflow is updated</li>
|
|
<li><b>Workflow Activated</b>: Triggers when this workflow is activated</li>
|
|
</ul>`,
|
|
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,
|
|
};
|
|
}
|
|
}
|