Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
102 lines
2.8 KiB
TypeScript
102 lines
2.8 KiB
TypeScript
import type {
|
|
ITriggerFunctions,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
ITriggerResponse,
|
|
} from 'n8n-workflow';
|
|
import { NodeConnectionTypes } from 'n8n-workflow';
|
|
|
|
type eventType = 'Instance started' | 'Workflow published' | 'Workflow updated' | undefined;
|
|
|
|
export class N8nTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'n8n Trigger',
|
|
name: 'n8nTrigger',
|
|
icon: 'file:n8nTrigger.svg',
|
|
group: ['trigger'],
|
|
version: 1,
|
|
description: 'Handle events and perform actions on your n8n instance',
|
|
eventTriggerDescription: '',
|
|
mockManualExecution: true,
|
|
defaults: {
|
|
name: 'n8n Trigger',
|
|
},
|
|
inputs: [],
|
|
outputs: [NodeConnectionTypes.Main],
|
|
properties: [
|
|
{
|
|
displayName: 'Events',
|
|
name: 'events',
|
|
type: 'multiOptions',
|
|
required: true,
|
|
default: [],
|
|
description: `Specifies under which conditions an execution should happen:
|
|
<ul>
|
|
<li><b>Published Workflow Updated</b>: Triggers when workflow version is published from a published state (workflow was already published)</li>
|
|
<li><b>Instance Started</b>: Triggers when this n8n instance is started or re-started</li>
|
|
<li><b>Workflow Published</b>: Triggers when workflow version is published from an unpublished state (workflow was unpublished)</li>
|
|
</ul>`,
|
|
options: [
|
|
{
|
|
name: 'Published Workflow Updated',
|
|
value: 'update',
|
|
description:
|
|
'Triggers when workflow version is published from a published state (workflow was already published)',
|
|
},
|
|
{
|
|
name: 'Instance Started',
|
|
value: 'init',
|
|
description: 'Triggers when this n8n instance is started or re-started',
|
|
},
|
|
{
|
|
name: 'Workflow Published',
|
|
value: 'activate',
|
|
description:
|
|
'Triggers when workflow version is published from an unpublished state (workflow was not published)',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
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 === 'activate') {
|
|
event = 'Workflow published';
|
|
}
|
|
if (activationMode === 'update') {
|
|
event = 'Workflow updated';
|
|
}
|
|
if (activationMode === 'init') {
|
|
event = 'Instance started';
|
|
}
|
|
this.emit([
|
|
this.helpers.returnJsonArray([
|
|
{ event, timestamp: new Date().toISOString(), workflow_id: this.getWorkflow().id },
|
|
]),
|
|
]);
|
|
}
|
|
|
|
const manualTriggerFunction = async () => {
|
|
this.emit([
|
|
this.helpers.returnJsonArray([
|
|
{
|
|
event: 'Manual execution',
|
|
timestamp: new Date().toISOString(),
|
|
workflow_id: this.getWorkflow().id,
|
|
},
|
|
]),
|
|
]);
|
|
};
|
|
|
|
return {
|
|
manualTriggerFunction,
|
|
};
|
|
}
|
|
}
|