@nvent-addon/app 0.4.5 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +19 -1
- package/dist/module.mjs +20 -8
- package/dist/runtime/app/components/{nhealth/component-router.d.vue.ts → ComponentRouter.d.vue.ts} +1 -5
- package/dist/runtime/app/components/{nhealth/component-router.vue.d.ts → ComponentRouter.vue.d.ts} +1 -5
- package/dist/runtime/app/components/{nhealth/component-shell.d.vue.ts → ComponentShell.d.vue.ts} +4 -9
- package/dist/runtime/app/components/ComponentShell.vue +87 -0
- package/dist/runtime/app/components/{nhealth/component-shell.vue.d.ts → ComponentShell.vue.d.ts} +4 -9
- package/dist/runtime/app/components/ConfirmDialog.d.vue.ts +1 -6
- package/dist/runtime/app/components/ConfirmDialog.vue.d.ts +1 -6
- package/dist/runtime/app/components/ListItem.d.vue.ts +3 -6
- package/dist/runtime/app/components/ListItem.vue.d.ts +3 -6
- package/dist/runtime/app/components/LiveIndicator.d.vue.ts +7 -0
- package/dist/runtime/app/components/LiveIndicator.vue +30 -0
- package/dist/runtime/app/components/LiveIndicator.vue.d.ts +7 -0
- package/dist/runtime/app/components/{QueueConfigDetails.d.vue.ts → QueueConfiguration.d.vue.ts} +1 -10
- package/dist/runtime/app/components/QueueConfiguration.vue +387 -0
- package/dist/runtime/app/components/{QueueConfigDetails.vue.d.ts → QueueConfiguration.vue.d.ts} +1 -10
- package/dist/runtime/app/components/StatCard.d.vue.ts +9 -0
- package/dist/runtime/app/components/StatCard.vue +57 -0
- package/dist/runtime/app/components/StatCard.vue.d.ts +9 -0
- package/dist/runtime/app/components/TimelineList.vue +67 -0
- package/dist/runtime/app/components/flow/AwaitNode.d.vue.ts +18 -0
- package/dist/runtime/app/components/flow/AwaitNode.vue +91 -0
- package/dist/runtime/app/components/flow/AwaitNode.vue.d.ts +18 -0
- package/dist/runtime/app/components/{FlowDiagram.d.vue.ts → flow/Diagram.d.vue.ts} +12 -1
- package/dist/runtime/app/components/{FlowDiagram.vue → flow/Diagram.vue} +92 -11
- package/dist/runtime/app/components/{FlowDiagram.vue.d.ts → flow/Diagram.vue.d.ts} +12 -1
- package/dist/runtime/app/components/{FlowRunOverview.d.vue.ts → flow/RunOverview.d.vue.ts} +3 -0
- package/dist/runtime/app/components/{FlowRunOverview.vue → flow/RunOverview.vue} +94 -8
- package/dist/runtime/app/components/{FlowRunOverview.vue.d.ts → flow/RunOverview.vue.d.ts} +3 -0
- package/dist/runtime/app/components/{FlowRunStatusBadge.d.vue.ts → flow/RunStatusBadge.d.vue.ts} +2 -8
- package/dist/runtime/app/components/{FlowRunStatusBadge.vue → flow/RunStatusBadge.vue} +8 -1
- package/dist/runtime/app/components/{FlowRunStatusBadge.vue.d.ts → flow/RunStatusBadge.vue.d.ts} +2 -8
- package/dist/runtime/app/components/{FlowRunTimeline.vue → flow/RunTimeline.vue} +1 -1
- package/dist/runtime/app/components/{FlowStepSelector.d.vue.ts → flow/StepSelector.d.vue.ts} +1 -0
- package/dist/runtime/app/components/flow/StepSelector.vue +553 -0
- package/dist/runtime/app/components/{FlowStepSelector.vue.d.ts → flow/StepSelector.vue.d.ts} +1 -0
- package/dist/runtime/app/components/trigger/BasicInfoCard.d.vue.ts +33 -0
- package/dist/runtime/app/components/trigger/BasicInfoCard.vue +168 -0
- package/dist/runtime/app/components/trigger/BasicInfoCard.vue.d.ts +33 -0
- package/dist/runtime/app/components/{FlowSchedulesList.d.vue.ts → trigger/DangerZone.d.vue.ts} +4 -6
- package/dist/runtime/app/components/trigger/DangerZone.vue +46 -0
- package/dist/runtime/app/components/{FlowSchedulesList.vue.d.ts → trigger/DangerZone.vue.d.ts} +4 -6
- package/dist/runtime/app/components/trigger/EditHeader.d.vue.ts +15 -0
- package/dist/runtime/app/components/trigger/EditHeader.vue +55 -0
- package/dist/runtime/app/components/trigger/EditHeader.vue.d.ts +15 -0
- package/dist/runtime/app/components/trigger/EventConfig.d.vue.ts +24 -0
- package/dist/runtime/app/components/trigger/EventConfig.vue +68 -0
- package/dist/runtime/app/components/trigger/EventConfig.vue.d.ts +24 -0
- package/dist/runtime/app/components/trigger/FlowSubscriptions.d.vue.ts +14 -0
- package/dist/runtime/app/components/trigger/FlowSubscriptions.vue +128 -0
- package/dist/runtime/app/components/trigger/FlowSubscriptions.vue.d.ts +14 -0
- package/dist/runtime/app/components/trigger/ScheduleConfig.d.vue.ts +27 -0
- package/dist/runtime/app/components/trigger/ScheduleConfig.vue +375 -0
- package/dist/runtime/app/components/trigger/ScheduleConfig.vue.d.ts +27 -0
- package/dist/runtime/app/components/{FlowScheduleDialog.d.vue.ts → trigger/StatusConfig.d.vue.ts} +6 -6
- package/dist/runtime/app/components/trigger/StatusConfig.vue +78 -0
- package/dist/runtime/app/components/{FlowScheduleDialog.vue.d.ts → trigger/StatusConfig.vue.d.ts} +6 -6
- package/dist/runtime/app/components/trigger/WebhookConfig.d.vue.ts +30 -0
- package/dist/runtime/app/components/trigger/WebhookConfig.vue +97 -0
- package/dist/runtime/app/components/trigger/WebhookConfig.vue.d.ts +30 -0
- package/dist/runtime/app/composables/useAnalyzedFlows.d.ts +5 -0
- package/dist/runtime/app/composables/useAnalyzedFlows.js +15 -1
- package/dist/runtime/app/composables/useComponentRouter.d.ts +8 -0
- package/dist/runtime/app/composables/useComponentRouter.js +10 -2
- package/dist/runtime/app/composables/useFlowRunsInfinite.d.ts +1 -1
- package/dist/runtime/app/composables/useFlowState.js +65 -0
- package/dist/runtime/app/composables/useFlowWebSocket.d.ts +11 -2
- package/dist/runtime/app/composables/useFlowWebSocket.js +181 -65
- package/dist/runtime/app/composables/useQueueJobs.d.ts +12 -1
- package/dist/runtime/app/composables/useQueueJobs.js +13 -7
- package/dist/runtime/app/composables/useTrigger.d.ts +137 -0
- package/dist/runtime/app/composables/useTrigger.js +116 -0
- package/dist/runtime/app/composables/useTriggerWebSocket.d.ts +35 -0
- package/dist/runtime/app/composables/useTriggerWebSocket.js +333 -0
- package/dist/runtime/app/pages/dashboard.d.vue.ts +3 -0
- package/dist/runtime/app/pages/dashboard.vue +738 -0
- package/dist/runtime/app/pages/dashboard.vue.d.ts +3 -0
- package/dist/runtime/app/pages/flows/[name].d.vue.ts +3 -0
- package/dist/runtime/app/pages/flows/[name].vue +680 -0
- package/dist/runtime/app/pages/flows/[name].vue.d.ts +3 -0
- package/dist/runtime/app/pages/flows/index.vue +321 -620
- package/dist/runtime/app/pages/index.vue +39 -9
- package/dist/runtime/app/pages/queues/index.vue +202 -194
- package/dist/runtime/app/pages/queues/jobs.vue +534 -207
- package/dist/runtime/app/pages/settings/scheduler.d.vue.ts +3 -0
- package/dist/runtime/app/pages/settings/scheduler.vue +310 -0
- package/dist/runtime/app/pages/settings/scheduler.vue.d.ts +3 -0
- package/dist/runtime/app/pages/triggers/[name]/edit.d.vue.ts +3 -0
- package/dist/runtime/app/pages/triggers/[name]/edit.vue +429 -0
- package/dist/runtime/app/pages/triggers/[name]/edit.vue.d.ts +3 -0
- package/dist/runtime/app/pages/triggers/[name].d.vue.ts +3 -0
- package/dist/runtime/app/pages/triggers/[name].vue +898 -0
- package/dist/runtime/app/pages/triggers/[name].vue.d.ts +3 -0
- package/dist/runtime/app/pages/triggers/index.d.vue.ts +3 -0
- package/dist/runtime/app/pages/triggers/index.vue +528 -0
- package/dist/runtime/app/pages/triggers/index.vue.d.ts +3 -0
- package/dist/runtime/app/pages/triggers/new.d.vue.ts +3 -0
- package/dist/runtime/app/pages/triggers/new.vue +610 -0
- package/dist/runtime/app/pages/triggers/new.vue.d.ts +3 -0
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +10 -0
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +49 -0
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.d.ts +2 -0
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +21 -0
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +17 -0
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +64 -0
- package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +2 -0
- package/dist/runtime/server/api/_flows/[name]/start.post.js +9 -0
- package/dist/runtime/server/api/_flows/index.get.d.ts +7 -0
- package/dist/runtime/server/api/_flows/index.get.js +5 -0
- package/dist/runtime/server/api/_flows/recent-runs.get.d.ts +15 -0
- package/dist/runtime/server/api/_flows/recent-runs.get.js +67 -0
- package/dist/runtime/server/api/_flows/ws.d.ts +80 -0
- package/dist/runtime/server/api/_flows/ws.js +309 -0
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +2 -0
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +14 -0
- package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +2 -0
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +39 -0
- package/dist/runtime/server/api/_queues/index.get.d.ts +2 -0
- package/dist/runtime/server/api/_queues/index.get.js +106 -0
- package/dist/runtime/server/api/_queues/ws.d.ts +48 -0
- package/dist/runtime/server/api/_queues/ws.js +215 -0
- package/dist/runtime/server/api/_scheduler/jobs.get.d.ts +19 -0
- package/dist/runtime/server/api/_scheduler/jobs.get.js +36 -0
- package/dist/runtime/server/api/_triggers/[name]/events.get.d.ts +6 -0
- package/dist/runtime/server/api/_triggers/[name]/events.get.js +43 -0
- package/dist/runtime/server/api/_triggers/[name]/index.get.d.ts +6 -0
- package/dist/runtime/server/api/_triggers/[name]/index.get.js +76 -0
- package/dist/runtime/server/api/_triggers/[name].delete.d.ts +7 -0
- package/dist/runtime/server/api/_triggers/[name].delete.js +37 -0
- package/dist/runtime/server/api/_triggers/[name].patch.d.ts +7 -0
- package/dist/runtime/server/api/_triggers/[name].patch.js +117 -0
- package/dist/runtime/server/api/_triggers/index.get.d.ts +6 -0
- package/dist/runtime/server/api/_triggers/index.get.js +44 -0
- package/dist/runtime/server/api/_triggers/index.post.d.ts +7 -0
- package/dist/runtime/server/api/_triggers/index.post.js +124 -0
- package/dist/runtime/server/api/_triggers/stats.get.d.ts +6 -0
- package/dist/runtime/server/api/_triggers/stats.get.js +41 -0
- package/dist/runtime/server/api/_triggers/ws.d.ts +74 -0
- package/dist/runtime/server/api/_triggers/ws.js +315 -0
- package/dist/runtime/server/tsconfig.json +7 -0
- package/package.json +8 -8
- package/dist/runtime/app/components/FlowScheduleDialog.vue +0 -226
- package/dist/runtime/app/components/FlowSchedulesList.vue +0 -99
- package/dist/runtime/app/components/FlowStepSelector.vue +0 -238
- package/dist/runtime/app/components/QueueConfigDetails.vue +0 -412
- package/dist/runtime/app/components/nhealth/component-shell.vue +0 -89
- /package/dist/runtime/app/components/{nhealth/component-router.vue → ComponentRouter.vue} +0 -0
- /package/dist/runtime/app/components/{FlowNodeCard.d.vue.ts → flow/NodeCard.d.vue.ts} +0 -0
- /package/dist/runtime/app/components/{FlowNodeCard.vue → flow/NodeCard.vue} +0 -0
- /package/dist/runtime/app/components/{FlowNodeCard.vue.d.ts → flow/NodeCard.vue.d.ts} +0 -0
- /package/dist/runtime/app/components/{FlowRunTimeline.d.vue.ts → flow/RunTimeline.d.vue.ts} +0 -0
- /package/dist/runtime/app/components/{FlowRunTimeline.vue.d.ts → flow/RunTimeline.vue.d.ts} +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { defineEventHandler, getRouterParam, readBody, useTrigger } from "#imports";
|
|
2
|
+
export default defineEventHandler(async (event) => {
|
|
3
|
+
const logger = {
|
|
4
|
+
info: console.log,
|
|
5
|
+
error: console.error
|
|
6
|
+
};
|
|
7
|
+
const trigger = useTrigger();
|
|
8
|
+
const name = getRouterParam(event, "name");
|
|
9
|
+
if (!name) {
|
|
10
|
+
return {
|
|
11
|
+
error: "Missing trigger name",
|
|
12
|
+
statusCode: 400
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const body = await readBody(event);
|
|
17
|
+
logger.info("Updating trigger", {
|
|
18
|
+
name,
|
|
19
|
+
updates: Object.keys(body)
|
|
20
|
+
});
|
|
21
|
+
if (!trigger.hasTrigger(name)) {
|
|
22
|
+
return {
|
|
23
|
+
error: "Trigger not found",
|
|
24
|
+
statusCode: 404
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const existing = trigger.getTrigger(name);
|
|
28
|
+
if (!existing) {
|
|
29
|
+
return {
|
|
30
|
+
error: "Trigger not found",
|
|
31
|
+
statusCode: 404
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const updateOpts = {
|
|
35
|
+
name,
|
|
36
|
+
type: existing.type,
|
|
37
|
+
scope: existing.scope,
|
|
38
|
+
status: body.status !== void 0 ? body.status : existing.status,
|
|
39
|
+
displayName: body.displayName !== void 0 ? body.displayName : existing.displayName,
|
|
40
|
+
description: body.description !== void 0 ? body.description : existing.description,
|
|
41
|
+
source: existing.source
|
|
42
|
+
};
|
|
43
|
+
if (existing.type === "webhook" && body.config) {
|
|
44
|
+
updateOpts.webhook = {
|
|
45
|
+
path: body.config.path !== void 0 ? body.config.path : existing.webhook?.path,
|
|
46
|
+
method: body.config.method !== void 0 ? body.config.method : existing.webhook?.method,
|
|
47
|
+
auth: body.config.requireAuth ? {
|
|
48
|
+
header: body.config.authHeader || existing.webhook?.auth?.header || "X-API-Key"
|
|
49
|
+
} : void 0
|
|
50
|
+
};
|
|
51
|
+
} else if (existing.webhook) {
|
|
52
|
+
updateOpts.webhook = existing.webhook;
|
|
53
|
+
}
|
|
54
|
+
if (existing.type === "schedule" && body.config) {
|
|
55
|
+
updateOpts.schedule = {
|
|
56
|
+
cron: body.config.cron !== void 0 ? body.config.cron : existing.schedule?.cron,
|
|
57
|
+
timezone: body.config.timezone !== void 0 ? body.config.timezone : existing.schedule?.timezone
|
|
58
|
+
};
|
|
59
|
+
if (body.config.interval !== void 0 || existing.schedule?.interval !== void 0) {
|
|
60
|
+
updateOpts.schedule.interval = body.config.interval !== void 0 ? body.config.interval : existing.schedule?.interval;
|
|
61
|
+
}
|
|
62
|
+
} else if (existing.schedule) {
|
|
63
|
+
updateOpts.schedule = existing.schedule;
|
|
64
|
+
}
|
|
65
|
+
if (existing.type === "event" && body.config) {
|
|
66
|
+
updateOpts.config = {
|
|
67
|
+
event: body.config.event !== void 0 ? body.config.event : existing.config?.event,
|
|
68
|
+
filter: body.config.filter !== void 0 ? body.config.filter ? JSON.parse(body.config.filter) : void 0 : existing.config?.filter
|
|
69
|
+
};
|
|
70
|
+
} else if (existing.config) {
|
|
71
|
+
updateOpts.config = existing.config;
|
|
72
|
+
}
|
|
73
|
+
await trigger.registerTrigger(updateOpts);
|
|
74
|
+
if (body.subscriptions !== void 0) {
|
|
75
|
+
const currentSubs = trigger.getSubscribedFlows(name);
|
|
76
|
+
const newSubs = Array.from(new Set(body.subscriptions));
|
|
77
|
+
logger.info("Processing subscription changes", {
|
|
78
|
+
trigger: name,
|
|
79
|
+
currentSubs,
|
|
80
|
+
newSubs,
|
|
81
|
+
toRemove: currentSubs.filter((f) => !newSubs.includes(f)),
|
|
82
|
+
toAdd: newSubs.filter((f) => !currentSubs.includes(f))
|
|
83
|
+
});
|
|
84
|
+
for (const flowName of currentSubs) {
|
|
85
|
+
if (!newSubs.includes(flowName)) {
|
|
86
|
+
logger.info(`Removing subscription: ${flowName} from ${name}`);
|
|
87
|
+
await trigger.unsubscribeTrigger(name, flowName);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const flowName of newSubs) {
|
|
91
|
+
if (!currentSubs.includes(flowName)) {
|
|
92
|
+
logger.info(`Adding new subscription: ${flowName} to ${name}`);
|
|
93
|
+
await trigger.subscribeTrigger({
|
|
94
|
+
trigger: name,
|
|
95
|
+
flow: flowName,
|
|
96
|
+
mode: "auto"
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
logger.info(`Subscription already exists: ${flowName}, skipping`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
logger.info(`Successfully updated trigger '${name}'`);
|
|
104
|
+
const updated = trigger.getTrigger(name);
|
|
105
|
+
return {
|
|
106
|
+
success: true,
|
|
107
|
+
trigger: updated
|
|
108
|
+
};
|
|
109
|
+
} catch (err) {
|
|
110
|
+
logger.error("Failed to update trigger", { error: err });
|
|
111
|
+
return {
|
|
112
|
+
error: "Failed to update trigger",
|
|
113
|
+
message: err instanceof Error ? err.message : String(err),
|
|
114
|
+
statusCode: 500
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineEventHandler, useTrigger } from "#imports";
|
|
2
|
+
export default defineEventHandler(async () => {
|
|
3
|
+
const { getAllTriggers, getSubscribedFlows, getTriggerStats } = useTrigger();
|
|
4
|
+
const triggers = getAllTriggers({
|
|
5
|
+
sortBy: "registeredAt",
|
|
6
|
+
order: "desc"
|
|
7
|
+
});
|
|
8
|
+
const enhancedTriggers = await Promise.all(
|
|
9
|
+
triggers.map(async (trigger) => {
|
|
10
|
+
const subscribedFlows = getSubscribedFlows(trigger.name);
|
|
11
|
+
const stats = await getTriggerStats(trigger.name);
|
|
12
|
+
return {
|
|
13
|
+
name: trigger.name,
|
|
14
|
+
type: trigger.type,
|
|
15
|
+
scope: trigger.scope,
|
|
16
|
+
displayName: trigger.displayName,
|
|
17
|
+
description: trigger.description,
|
|
18
|
+
source: trigger.source,
|
|
19
|
+
status: trigger.status || "active",
|
|
20
|
+
registeredAt: trigger.registeredAt,
|
|
21
|
+
lastActivityAt: trigger.lastActivityAt,
|
|
22
|
+
webhook: trigger.webhook,
|
|
23
|
+
schedule: trigger.schedule,
|
|
24
|
+
config: trigger.config,
|
|
25
|
+
subscribedFlows,
|
|
26
|
+
subscriptionCount: subscribedFlows.length,
|
|
27
|
+
stats: {
|
|
28
|
+
totalFires: stats?.totalFires || 0,
|
|
29
|
+
last24h: 0,
|
|
30
|
+
// Not tracked yet in current implementation
|
|
31
|
+
successCount: 0,
|
|
32
|
+
// Not tracked yet
|
|
33
|
+
failureCount: 0,
|
|
34
|
+
// Not tracked yet
|
|
35
|
+
activeSubscribers: stats?.activeSubscribers || subscribedFlows.length,
|
|
36
|
+
successRate: 100,
|
|
37
|
+
// Default since failures not tracked yet
|
|
38
|
+
lastFiredAt: stats?.lastFiredAt
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
return enhancedTriggers;
|
|
44
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { defineEventHandler, readBody, useTrigger } from "#imports";
|
|
2
|
+
export default defineEventHandler(async (event) => {
|
|
3
|
+
const logger = {
|
|
4
|
+
info: console.log,
|
|
5
|
+
error: console.error
|
|
6
|
+
};
|
|
7
|
+
const trigger = useTrigger();
|
|
8
|
+
try {
|
|
9
|
+
const body = await readBody(event);
|
|
10
|
+
if (!body.name) {
|
|
11
|
+
return {
|
|
12
|
+
error: "Missing required field: name",
|
|
13
|
+
statusCode: 400
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (!body.type) {
|
|
17
|
+
return {
|
|
18
|
+
error: "Missing required field: type",
|
|
19
|
+
statusCode: 400
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!["event", "webhook", "schedule", "manual"].includes(body.type)) {
|
|
23
|
+
return {
|
|
24
|
+
error: "Invalid trigger type",
|
|
25
|
+
statusCode: 400
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (body.type === "event" && !body.config?.event) {
|
|
29
|
+
return {
|
|
30
|
+
error: "Event triggers require config.event",
|
|
31
|
+
statusCode: 400
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (body.type === "webhook" && !body.config?.path) {
|
|
35
|
+
return {
|
|
36
|
+
error: "Webhook triggers require config.path",
|
|
37
|
+
statusCode: 400
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (body.type === "schedule") {
|
|
41
|
+
if (!body.config?.cron && !body.config?.interval) {
|
|
42
|
+
return {
|
|
43
|
+
error: "Schedule triggers require config.cron or config.interval",
|
|
44
|
+
statusCode: 400
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
logger.info("Registering new trigger", {
|
|
49
|
+
name: body.name,
|
|
50
|
+
type: body.type,
|
|
51
|
+
subscriptions: body.subscriptions?.length || 0
|
|
52
|
+
});
|
|
53
|
+
if (trigger.hasTrigger(body.name)) {
|
|
54
|
+
return {
|
|
55
|
+
error: "Trigger already exists",
|
|
56
|
+
statusCode: 409
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const triggerOpts = {
|
|
60
|
+
name: body.name,
|
|
61
|
+
type: body.type,
|
|
62
|
+
scope: body.scope || "flow",
|
|
63
|
+
displayName: body.displayName || body.name,
|
|
64
|
+
description: body.description,
|
|
65
|
+
source: "ui"
|
|
66
|
+
};
|
|
67
|
+
if (body.type === "webhook") {
|
|
68
|
+
triggerOpts.webhook = {
|
|
69
|
+
path: body.config.path,
|
|
70
|
+
method: body.config.method || "POST",
|
|
71
|
+
auth: body.config.requireAuth ? {
|
|
72
|
+
header: body.config.authHeader || "X-API-Key"
|
|
73
|
+
} : void 0
|
|
74
|
+
};
|
|
75
|
+
} else if (body.type === "schedule") {
|
|
76
|
+
triggerOpts.schedule = {
|
|
77
|
+
cron: body.config.cron || void 0,
|
|
78
|
+
interval: body.config.interval || void 0,
|
|
79
|
+
timezone: body.config.timezone || "UTC"
|
|
80
|
+
};
|
|
81
|
+
if (body.config.runImmediately) {
|
|
82
|
+
triggerOpts.config = { runImmediately: true };
|
|
83
|
+
}
|
|
84
|
+
} else if (body.type === "event") {
|
|
85
|
+
triggerOpts.config = {
|
|
86
|
+
event: body.config.event,
|
|
87
|
+
filter: body.config.filter ? JSON.parse(body.config.filter) : void 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
await trigger.registerTrigger(triggerOpts);
|
|
91
|
+
if (body.subscriptions && body.subscriptions.length > 0) {
|
|
92
|
+
for (const flowName of body.subscriptions) {
|
|
93
|
+
await trigger.subscribeTrigger({
|
|
94
|
+
trigger: body.name,
|
|
95
|
+
flow: flowName,
|
|
96
|
+
mode: "auto"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
logger.info(
|
|
101
|
+
`Successfully registered trigger '${body.name}' with ${body.subscriptions?.length || 0} subscriptions`
|
|
102
|
+
);
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
trigger: {
|
|
106
|
+
name: body.name,
|
|
107
|
+
displayName: body.displayName || body.name,
|
|
108
|
+
type: body.type,
|
|
109
|
+
scope: body.scope || "flow",
|
|
110
|
+
config: body.config || {},
|
|
111
|
+
subscriptions: body.subscriptions || [],
|
|
112
|
+
status: "active",
|
|
113
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
} catch (err) {
|
|
117
|
+
logger.error("Failed to create trigger", { error: err });
|
|
118
|
+
return {
|
|
119
|
+
error: "Failed to create trigger",
|
|
120
|
+
message: err instanceof Error ? err.message : String(err),
|
|
121
|
+
statusCode: 500
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineEventHandler, useTrigger } from "#imports";
|
|
2
|
+
export default defineEventHandler(async () => {
|
|
3
|
+
const { getAllTriggers, getAllSubscriptions } = useTrigger();
|
|
4
|
+
const triggers = getAllTriggers();
|
|
5
|
+
const subscriptions = getAllSubscriptions();
|
|
6
|
+
const byType = triggers.reduce((acc, trigger) => {
|
|
7
|
+
acc[trigger.type] = (acc[trigger.type] || 0) + 1;
|
|
8
|
+
return acc;
|
|
9
|
+
}, {});
|
|
10
|
+
const byScope = triggers.reduce((acc, trigger) => {
|
|
11
|
+
acc[trigger.scope] = (acc[trigger.scope] || 0) + 1;
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
const byStatus = triggers.reduce((acc, trigger) => {
|
|
15
|
+
const status = trigger.status || "active";
|
|
16
|
+
acc[status] = (acc[status] || 0) + 1;
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
const { getTriggerStats } = useTrigger();
|
|
20
|
+
let totalFires = 0;
|
|
21
|
+
for (const trigger of triggers) {
|
|
22
|
+
const stats = await getTriggerStats(trigger.name);
|
|
23
|
+
totalFires += stats?.totalFires || 0;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
total: triggers.length,
|
|
27
|
+
active: byStatus.active || 0,
|
|
28
|
+
inactive: byStatus.inactive || 0,
|
|
29
|
+
retired: byStatus.retired || 0,
|
|
30
|
+
byType,
|
|
31
|
+
byScope,
|
|
32
|
+
byStatus,
|
|
33
|
+
totalSubscriptions: subscriptions.length,
|
|
34
|
+
totalFires,
|
|
35
|
+
// Count triggers with active subscriptions
|
|
36
|
+
withSubscribers: triggers.filter((t) => {
|
|
37
|
+
const triggerSubs = subscriptions.filter((s) => s.triggerName === t.name);
|
|
38
|
+
return triggerSubs.length > 0;
|
|
39
|
+
}).length
|
|
40
|
+
};
|
|
41
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket endpoint for trigger events
|
|
3
|
+
* Supports subscribing to specific triggers and receiving real-time updates
|
|
4
|
+
*
|
|
5
|
+
* Message format (client -> server):
|
|
6
|
+
* {
|
|
7
|
+
* "type": "subscribe",
|
|
8
|
+
* "triggerName": "user.created"
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* {
|
|
12
|
+
* "type": "unsubscribe",
|
|
13
|
+
* "triggerName": "user.created"
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* {
|
|
17
|
+
* "type": "ping"
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* {
|
|
21
|
+
* "type": "subscribe.stats"
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* {
|
|
25
|
+
* "type": "unsubscribe.stats"
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* Message format (server -> client):
|
|
29
|
+
* {
|
|
30
|
+
* "type": "event",
|
|
31
|
+
* "triggerName": "user.created",
|
|
32
|
+
* "event": { type: "...", data: {...}, timestamp: ... }
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* {
|
|
36
|
+
* "type": "history",
|
|
37
|
+
* "triggerName": "user.created",
|
|
38
|
+
* "events": [ ...historicalEvents ]
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* {
|
|
42
|
+
* "type": "subscribed",
|
|
43
|
+
* "triggerName": "user.created"
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* {
|
|
47
|
+
* "type": "unsubscribed",
|
|
48
|
+
* "triggerName": "user.created"
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* {
|
|
52
|
+
* "type": "trigger.stats.initial",
|
|
53
|
+
* "data": { id: "triggerName", metadata: {...} },
|
|
54
|
+
* "timestamp": 1234567890
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* {
|
|
58
|
+
* "type": "trigger.stats.update",
|
|
59
|
+
* "data": { id: "triggerName", metadata: {...} },
|
|
60
|
+
* "timestamp": 1234567890
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* {
|
|
64
|
+
* "type": "pong",
|
|
65
|
+
* "timestamp": 1234567890
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* {
|
|
69
|
+
* "type": "error",
|
|
70
|
+
* "message": "error description"
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
declare const _default: any;
|
|
74
|
+
export default _default;
|