nvent 0.4.5 → 0.5.0
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 +1 -1
- package/dist/module.mjs +433 -175
- package/dist/runtime/adapters/base/index.d.ts +6 -0
- package/dist/runtime/adapters/base/index.js +1 -0
- package/dist/runtime/adapters/base/store-validator.d.ts +48 -0
- package/dist/runtime/adapters/base/store-validator.js +147 -0
- package/dist/runtime/adapters/builtin/file-queue.d.ts +15 -1
- package/dist/runtime/adapters/builtin/file-queue.js +70 -6
- package/dist/runtime/adapters/builtin/file-store.d.ts +4 -18
- package/dist/runtime/adapters/builtin/file-store.js +90 -109
- package/dist/runtime/adapters/builtin/memory-queue.js +4 -0
- package/dist/runtime/adapters/builtin/memory-store.d.ts +42 -31
- package/dist/runtime/adapters/builtin/memory-store.js +253 -183
- package/dist/runtime/adapters/factory.d.ts +2 -2
- package/dist/runtime/adapters/factory.js +54 -20
- package/dist/runtime/adapters/interfaces/store.d.ts +177 -113
- package/dist/runtime/config/index.d.ts +2 -2
- package/dist/runtime/config/index.js +14 -6
- package/dist/runtime/config/types.d.ts +32 -2
- package/dist/runtime/events/eventBus.d.ts +1 -1
- package/dist/runtime/events/types.d.ts +31 -2
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +8 -0
- package/dist/runtime/events/utils/scheduleTrigger.js +69 -0
- package/dist/runtime/events/utils/stallDetector.d.ts +44 -3
- package/dist/runtime/events/utils/stallDetector.js +288 -89
- package/dist/runtime/events/utils/triggerRuntime.d.ts +58 -0
- package/dist/runtime/events/utils/triggerRuntime.js +212 -0
- package/dist/runtime/events/wiring/flowWiring.d.ts +11 -5
- package/dist/runtime/events/wiring/flowWiring.js +620 -92
- package/dist/runtime/events/wiring/registry.d.ts +2 -2
- package/dist/runtime/events/wiring/registry.js +8 -6
- package/dist/runtime/events/wiring/streamWiring.d.ts +15 -11
- package/dist/runtime/events/wiring/streamWiring.js +88 -11
- package/dist/runtime/events/wiring/triggerWiring.d.ts +21 -0
- package/dist/runtime/events/wiring/triggerWiring.js +412 -0
- package/dist/runtime/{server → nitro}/plugins/00.adapters.js +8 -4
- package/dist/runtime/{server → nitro}/plugins/02.workers.js +21 -3
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +12 -0
- package/dist/runtime/nitro/plugins/03.triggers.js +55 -0
- package/dist/runtime/nitro/routes/webhook.await.d.ts +23 -0
- package/dist/runtime/nitro/routes/webhook.await.js +90 -0
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +69 -0
- package/dist/runtime/nitro/routes/webhook.trigger.js +64 -0
- package/dist/runtime/{utils → nitro/utils}/adapters.d.ts +6 -6
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +120 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +28 -0
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +55 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +16 -0
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +78 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +67 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +15 -0
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +120 -0
- package/dist/runtime/{utils → nitro/utils}/defineFunction.d.ts +2 -2
- package/dist/runtime/{utils → nitro/utils}/defineFunction.js +3 -3
- package/dist/runtime/{utils → nitro/utils}/defineFunctionConfig.d.ts +156 -0
- package/dist/runtime/{utils → nitro/utils}/defineFunctionConfig.js +1 -0
- package/dist/runtime/nitro/utils/defineHooks.d.ts +41 -0
- package/dist/runtime/nitro/utils/defineHooks.js +6 -0
- package/dist/runtime/{utils → nitro/utils}/registerAdapter.d.ts +3 -3
- package/dist/runtime/{utils → nitro/utils}/registerAdapter.js +1 -1
- package/dist/runtime/nitro/utils/useAwait.d.ts +71 -0
- package/dist/runtime/nitro/utils/useAwait.js +139 -0
- package/dist/runtime/{utils → nitro/utils}/useEventManager.d.ts +2 -2
- package/dist/runtime/{utils → nitro/utils}/useEventManager.js +1 -1
- package/dist/runtime/nitro/utils/useFlow.d.ts +68 -0
- package/dist/runtime/nitro/utils/useFlow.js +226 -0
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +34 -0
- package/dist/runtime/nitro/utils/useHookRegistry.js +25 -0
- package/dist/runtime/nitro/utils/useRunContext.d.ts +6 -0
- package/dist/runtime/nitro/utils/useRunContext.js +102 -0
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +83 -0
- package/dist/runtime/nitro/utils/useStreamTopics.js +94 -0
- package/dist/runtime/nitro/utils/useTrigger.d.ts +150 -0
- package/dist/runtime/nitro/utils/useTrigger.js +320 -0
- package/dist/runtime/scheduler/index.d.ts +33 -0
- package/dist/runtime/scheduler/index.js +38 -0
- package/dist/runtime/scheduler/scheduler.d.ts +113 -0
- package/dist/runtime/scheduler/scheduler.js +623 -0
- package/dist/runtime/scheduler/types.d.ts +116 -0
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/worker/node/runner.d.ts +12 -2
- package/dist/runtime/worker/node/runner.js +141 -37
- package/package.json +6 -6
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.d.ts +0 -10
- package/dist/runtime/server/api/_flows/[name]/clear-history.delete.js +0 -55
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/runs/[runId]/cancel.post.js +0 -21
- package/dist/runtime/server/api/_flows/[name]/runs.get.d.ts +0 -17
- package/dist/runtime/server/api/_flows/[name]/runs.get.js +0 -64
- package/dist/runtime/server/api/_flows/[name]/schedule.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedule.post.js +0 -66
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules/[id].delete.js +0 -47
- package/dist/runtime/server/api/_flows/[name]/schedules.get.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/schedules.get.js +0 -50
- package/dist/runtime/server/api/_flows/[name]/start.post.d.ts +0 -2
- package/dist/runtime/server/api/_flows/[name]/start.post.js +0 -9
- package/dist/runtime/server/api/_flows/index.get.d.ts +0 -6
- package/dist/runtime/server/api/_flows/index.get.js +0 -5
- package/dist/runtime/server/api/_flows/ws.d.ts +0 -60
- package/dist/runtime/server/api/_flows/ws.js +0 -209
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/[id].get.js +0 -14
- package/dist/runtime/server/api/_queues/[name]/job/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/[name]/job/index.get.js +0 -27
- package/dist/runtime/server/api/_queues/index.get.d.ts +0 -2
- package/dist/runtime/server/api/_queues/index.get.js +0 -106
- package/dist/runtime/server/api/_queues/ws.d.ts +0 -48
- package/dist/runtime/server/api/_queues/ws.js +0 -215
- package/dist/runtime/utils/useFlowEngine.d.ts +0 -19
- package/dist/runtime/utils/useFlowEngine.js +0 -108
- package/dist/runtime/utils/useStreamTopics.d.ts +0 -72
- package/dist/runtime/utils/useStreamTopics.js +0 -47
- /package/dist/runtime/{server → nitro}/plugins/00.adapters.d.ts +0 -0
- /package/dist/runtime/{server → nitro}/plugins/01.ws-lifecycle.d.ts +0 -0
- /package/dist/runtime/{server → nitro}/plugins/01.ws-lifecycle.js +0 -0
- /package/dist/runtime/{server → nitro}/plugins/02.workers.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/adapters.js +0 -0
- /package/dist/runtime/{utils → nitro/utils}/useNventLogger.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/useNventLogger.js +0 -0
- /package/dist/runtime/{utils → nitro/utils}/wsPeerManager.d.ts +0 -0
- /package/dist/runtime/{utils → nitro/utils}/wsPeerManager.js +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useNventLogger, useScheduler } from "#imports";
|
|
2
|
+
import { getEventBus } from "../../../events/eventBus.js";
|
|
3
|
+
import { CronJob } from "cron";
|
|
4
|
+
export async function registerScheduleAwait(runId, stepName, flowName, config, position = "after") {
|
|
5
|
+
const logger = useNventLogger("await-schedule");
|
|
6
|
+
const eventBus = getEventBus();
|
|
7
|
+
const scheduler = useScheduler();
|
|
8
|
+
if (!config.cron) {
|
|
9
|
+
throw new Error("Schedule await requires cron expression configuration");
|
|
10
|
+
}
|
|
11
|
+
logger.info(`Registering schedule await: ${config.cron}`, { runId, stepName });
|
|
12
|
+
const cronJob = new CronJob(config.cron, () => {
|
|
13
|
+
}, null, false, config.timezone || "UTC");
|
|
14
|
+
const nextDate = cronJob.nextDate();
|
|
15
|
+
const nextOccurrence = nextDate ? nextDate.toMillis() : Date.now() + 6e4;
|
|
16
|
+
const timeUntilNext = nextOccurrence - Date.now();
|
|
17
|
+
const jobId = `await-schedule-${runId}-${stepName}-${position}`;
|
|
18
|
+
await scheduler.schedule({
|
|
19
|
+
id: jobId,
|
|
20
|
+
name: `Schedule Await: ${flowName} - ${stepName}`,
|
|
21
|
+
type: "one-time",
|
|
22
|
+
executeAt: nextOccurrence,
|
|
23
|
+
handler: async () => {
|
|
24
|
+
await resolveScheduleAwait(runId, stepName, flowName, position, { scheduledAt: nextOccurrence });
|
|
25
|
+
},
|
|
26
|
+
metadata: {
|
|
27
|
+
component: "await-pattern",
|
|
28
|
+
awaitType: "schedule",
|
|
29
|
+
runId,
|
|
30
|
+
stepName,
|
|
31
|
+
flowName,
|
|
32
|
+
position,
|
|
33
|
+
cron: config.cron,
|
|
34
|
+
timezone: config.timezone
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
eventBus.publish({
|
|
38
|
+
type: "await.registered",
|
|
39
|
+
flowName,
|
|
40
|
+
runId,
|
|
41
|
+
stepName,
|
|
42
|
+
awaitType: "schedule",
|
|
43
|
+
position,
|
|
44
|
+
config,
|
|
45
|
+
data: {
|
|
46
|
+
cron: config.cron,
|
|
47
|
+
nextOccurrence,
|
|
48
|
+
timeUntilNext,
|
|
49
|
+
registeredAt: Date.now()
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
logger.debug(`Schedule await registered: ${config.cron} (next: ${new Date(nextOccurrence).toISOString()})`, {
|
|
53
|
+
runId,
|
|
54
|
+
stepName
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
cron: config.cron,
|
|
58
|
+
nextOccurrence,
|
|
59
|
+
timeUntilNext
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function resolveScheduleAwait(runId, stepName, flowName, position, scheduleData) {
|
|
63
|
+
const logger = useNventLogger("await-schedule");
|
|
64
|
+
const eventBus = getEventBus();
|
|
65
|
+
logger.info(`Resolving schedule await`, { runId, stepName });
|
|
66
|
+
eventBus.publish({
|
|
67
|
+
type: "await.resolved",
|
|
68
|
+
flowName,
|
|
69
|
+
runId,
|
|
70
|
+
stepName,
|
|
71
|
+
position,
|
|
72
|
+
triggerData: scheduleData,
|
|
73
|
+
data: {
|
|
74
|
+
resolvedAt: Date.now()
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
logger.debug(`Schedule await resolved`, { runId, stepName });
|
|
78
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwaitConfig } from '../../../../registry/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Await Pattern: Time
|
|
4
|
+
*
|
|
5
|
+
* Simple delay/timeout - waits for a specific duration
|
|
6
|
+
* Useful for cooldown periods, rate limiting, delayed notifications
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerTimeAwait(runId: string, stepName: string, flowName: string, config: AwaitConfig, position?: 'before' | 'after'): Promise<{
|
|
9
|
+
delay: number;
|
|
10
|
+
resolveAt: number;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve time await when delay completes
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveTimeAwait(runId: string, stepName: string, flowName: string, position: 'before' | 'after', timeData: any): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useNventLogger, useScheduler } from "#imports";
|
|
2
|
+
import { getEventBus } from "../../../events/eventBus.js";
|
|
3
|
+
export async function registerTimeAwait(runId, stepName, flowName, config, position = "after") {
|
|
4
|
+
const logger = useNventLogger("await-time");
|
|
5
|
+
const eventBus = getEventBus();
|
|
6
|
+
const scheduler = useScheduler();
|
|
7
|
+
if (!config.delay) {
|
|
8
|
+
throw new Error("Time await requires delay configuration (in milliseconds)");
|
|
9
|
+
}
|
|
10
|
+
logger.info(`Registering time await: ${config.delay}ms`, { runId, stepName });
|
|
11
|
+
const resolveAt = Date.now() + config.delay;
|
|
12
|
+
const jobId = `await-time-${runId}-${stepName}-${position}`;
|
|
13
|
+
await scheduler.schedule({
|
|
14
|
+
id: jobId,
|
|
15
|
+
name: `Time Await: ${flowName} - ${stepName}`,
|
|
16
|
+
type: "one-time",
|
|
17
|
+
executeAt: resolveAt,
|
|
18
|
+
handler: async () => {
|
|
19
|
+
await resolveTimeAwait(runId, stepName, flowName, position, { delayCompleted: true });
|
|
20
|
+
},
|
|
21
|
+
metadata: {
|
|
22
|
+
component: "await-pattern",
|
|
23
|
+
awaitType: "time",
|
|
24
|
+
runId,
|
|
25
|
+
stepName,
|
|
26
|
+
flowName,
|
|
27
|
+
position,
|
|
28
|
+
delay: config.delay
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
eventBus.publish({
|
|
32
|
+
type: "await.registered",
|
|
33
|
+
flowName,
|
|
34
|
+
runId,
|
|
35
|
+
stepName,
|
|
36
|
+
awaitType: "time",
|
|
37
|
+
position,
|
|
38
|
+
config,
|
|
39
|
+
data: {
|
|
40
|
+
delay: config.delay,
|
|
41
|
+
resolveAt,
|
|
42
|
+
registeredAt: Date.now()
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
logger.debug(`Time await registered: ${config.delay}ms`, { runId, stepName });
|
|
46
|
+
return {
|
|
47
|
+
delay: config.delay,
|
|
48
|
+
resolveAt
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export async function resolveTimeAwait(runId, stepName, flowName, position, timeData) {
|
|
52
|
+
const logger = useNventLogger("await-time");
|
|
53
|
+
const eventBus = getEventBus();
|
|
54
|
+
logger.info(`Resolving time await`, { runId, stepName });
|
|
55
|
+
eventBus.publish({
|
|
56
|
+
type: "await.resolved",
|
|
57
|
+
flowName,
|
|
58
|
+
runId,
|
|
59
|
+
stepName,
|
|
60
|
+
position,
|
|
61
|
+
triggerData: timeData,
|
|
62
|
+
data: {
|
|
63
|
+
resolvedAt: Date.now()
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
logger.debug(`Time await resolved`, { runId, stepName });
|
|
67
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwaitConfig } from '../../../../registry/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Await Pattern: Webhook
|
|
4
|
+
*
|
|
5
|
+
* Creates a dynamic webhook endpoint that resolves when called
|
|
6
|
+
* Useful for human approval flows, external integrations
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerWebhookAwait(runId: string, stepName: string, flowName: string, config: AwaitConfig, position?: 'before' | 'after'): Promise<{
|
|
9
|
+
webhookUrl: string;
|
|
10
|
+
timeout: number | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve webhook await when webhook is called
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveWebhookAwait(runId: string, stepName: string, flowName: string, position: 'before' | 'after', webhookData: any): Promise<void>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useNventLogger, useRuntimeConfig, useScheduler } from "#imports";
|
|
2
|
+
import { getEventBus } from "../../../events/eventBus.js";
|
|
3
|
+
export async function registerWebhookAwait(runId, stepName, flowName, config, position = "after") {
|
|
4
|
+
const logger = useNventLogger("await-webhook");
|
|
5
|
+
const eventBus = getEventBus();
|
|
6
|
+
const runtimeConfig = useRuntimeConfig();
|
|
7
|
+
const path = `/${flowName}/${runId}/${stepName}`;
|
|
8
|
+
let baseUrl = runtimeConfig.nvent?.webhooks?.baseUrl;
|
|
9
|
+
if (!baseUrl) {
|
|
10
|
+
const nitroApp = runtimeConfig.nitro?.app;
|
|
11
|
+
if (nitroApp?.baseURL) {
|
|
12
|
+
baseUrl = `${nitroApp.baseURL}`;
|
|
13
|
+
}
|
|
14
|
+
if (!baseUrl) {
|
|
15
|
+
baseUrl = process.env.NITRO_URL || process.env.URL || (process.env.NODE_ENV === "development" ? "http://localhost:3000" : void 0);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!baseUrl) {
|
|
19
|
+
logger.warn("No baseUrl configured for webhooks. Set NUXT_PUBLIC_SITE_URL or nvent.webhooks.baseUrl");
|
|
20
|
+
baseUrl = "http://localhost:3000";
|
|
21
|
+
}
|
|
22
|
+
const webhookPath = `/api/_webhook/await${path}`;
|
|
23
|
+
const fullWebhookUrl = `${baseUrl.replace(/\/$/, "")}${webhookPath}`;
|
|
24
|
+
logger.info(`Registering webhook await: ${fullWebhookUrl}`, { runId, stepName });
|
|
25
|
+
eventBus.publish({
|
|
26
|
+
type: "await.registered",
|
|
27
|
+
flowName,
|
|
28
|
+
runId,
|
|
29
|
+
stepName,
|
|
30
|
+
awaitType: "webhook",
|
|
31
|
+
position,
|
|
32
|
+
config,
|
|
33
|
+
data: {
|
|
34
|
+
path,
|
|
35
|
+
method: config.method || "POST",
|
|
36
|
+
timeout: config.timeout,
|
|
37
|
+
registeredAt: Date.now(),
|
|
38
|
+
webhookUrl: fullWebhookUrl
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (config.timeout && config.timeout > 0) {
|
|
42
|
+
const scheduler = useScheduler();
|
|
43
|
+
const timeoutAt = Date.now() + config.timeout;
|
|
44
|
+
const jobId = `await-webhook-timeout-${runId}-${stepName}-${position}`;
|
|
45
|
+
await scheduler.schedule({
|
|
46
|
+
id: jobId,
|
|
47
|
+
name: `Webhook Timeout: ${flowName} - ${stepName}`,
|
|
48
|
+
type: "one-time",
|
|
49
|
+
executeAt: timeoutAt,
|
|
50
|
+
handler: async () => {
|
|
51
|
+
logger.warn("Webhook await timeout", {
|
|
52
|
+
runId,
|
|
53
|
+
stepName,
|
|
54
|
+
flowName,
|
|
55
|
+
timeout: config.timeout,
|
|
56
|
+
timeoutAction: config.timeoutAction || "fail"
|
|
57
|
+
});
|
|
58
|
+
eventBus.publish({
|
|
59
|
+
type: "await.timeout",
|
|
60
|
+
flowName,
|
|
61
|
+
runId,
|
|
62
|
+
stepName,
|
|
63
|
+
position,
|
|
64
|
+
awaitType: "webhook",
|
|
65
|
+
timeoutAction: config.timeoutAction || "fail",
|
|
66
|
+
data: {
|
|
67
|
+
timeout: config.timeout,
|
|
68
|
+
registeredAt: Date.now() - (config.timeout || 0),
|
|
69
|
+
timedOutAt: Date.now()
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
metadata: {
|
|
74
|
+
component: "await-pattern",
|
|
75
|
+
awaitType: "webhook",
|
|
76
|
+
runId,
|
|
77
|
+
stepName,
|
|
78
|
+
flowName,
|
|
79
|
+
position,
|
|
80
|
+
timeout: config.timeout
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
logger.debug(`Webhook timeout scheduled`, {
|
|
84
|
+
runId,
|
|
85
|
+
stepName,
|
|
86
|
+
timeout: config.timeout,
|
|
87
|
+
timeoutAction: config.timeoutAction
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
logger.debug(`Webhook await registered: ${fullWebhookUrl}`, { runId, stepName });
|
|
91
|
+
return {
|
|
92
|
+
webhookUrl: fullWebhookUrl,
|
|
93
|
+
timeout: config.timeout
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export async function resolveWebhookAwait(runId, stepName, flowName, position, webhookData) {
|
|
97
|
+
const logger = useNventLogger("await-webhook");
|
|
98
|
+
const eventBus = getEventBus();
|
|
99
|
+
const scheduler = useScheduler();
|
|
100
|
+
logger.info(`Resolving webhook await`, { runId, stepName });
|
|
101
|
+
const jobId = `await-webhook-timeout-${runId}-${stepName}-${position}`;
|
|
102
|
+
try {
|
|
103
|
+
await scheduler.unschedule(jobId);
|
|
104
|
+
logger.debug("Unscheduled webhook timeout job", { runId, stepName, jobId });
|
|
105
|
+
} catch {
|
|
106
|
+
logger.debug("Could not unschedule timeout job (may not exist)", { runId, stepName, jobId });
|
|
107
|
+
}
|
|
108
|
+
eventBus.publish({
|
|
109
|
+
type: "await.resolved",
|
|
110
|
+
flowName,
|
|
111
|
+
runId,
|
|
112
|
+
stepName,
|
|
113
|
+
position,
|
|
114
|
+
triggerData: webhookData,
|
|
115
|
+
data: {
|
|
116
|
+
resolvedAt: Date.now()
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
logger.debug(`Webhook await resolved`, { runId, stepName });
|
|
120
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useFlow, useQueueAdapter } from '#imports';
|
|
2
2
|
import type { RunContext, NodeHandler } from '../worker/node/runner.js';
|
|
3
3
|
export type ExtendedRunContext = RunContext & {
|
|
4
4
|
provider: ReturnType<typeof useQueueAdapter>;
|
|
5
|
-
flow: ReturnType<typeof
|
|
5
|
+
flow: ReturnType<typeof useFlow>;
|
|
6
6
|
registry: any;
|
|
7
7
|
};
|
|
8
8
|
export type DefineFunction = (handler: (input: any, ctx: ExtendedRunContext) => Promise<any>) => NodeHandler;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $useFunctionRegistry, useFlow, useQueueAdapter } from "#imports";
|
|
2
2
|
export const defineFunction = (handler) => {
|
|
3
3
|
const wrapped = async (input, ctx) => {
|
|
4
4
|
const provider = useQueueAdapter();
|
|
5
|
-
const flow = ctx.flow ||
|
|
6
|
-
const registry = $
|
|
5
|
+
const flow = ctx.flow || useFlow();
|
|
6
|
+
const registry = $useFunctionRegistry();
|
|
7
7
|
const extended = {
|
|
8
8
|
...ctx,
|
|
9
9
|
provider,
|
|
@@ -1,4 +1,72 @@
|
|
|
1
1
|
export type FlowRole = 'entry' | 'step';
|
|
2
|
+
/**
|
|
3
|
+
* Trigger definition for inline trigger registration
|
|
4
|
+
* Can be defined in function config alongside subscription
|
|
5
|
+
*/
|
|
6
|
+
export interface TriggerDefinition {
|
|
7
|
+
/**
|
|
8
|
+
* Unique trigger name (e.g., 'manual.approve-order')
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Trigger type
|
|
13
|
+
*/
|
|
14
|
+
type: 'event' | 'webhook' | 'schedule' | 'manual';
|
|
15
|
+
/**
|
|
16
|
+
* Trigger scope: 'flow' for entry triggers, 'await' for await patterns
|
|
17
|
+
*/
|
|
18
|
+
scope?: 'flow' | 'await';
|
|
19
|
+
/**
|
|
20
|
+
* Human-readable display name
|
|
21
|
+
*/
|
|
22
|
+
displayName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Description of what this trigger does
|
|
25
|
+
*/
|
|
26
|
+
description?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Expected flows that should subscribe to this trigger (for validation)
|
|
29
|
+
*/
|
|
30
|
+
expectedSubscribers?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Webhook-specific configuration
|
|
33
|
+
*/
|
|
34
|
+
webhook?: {
|
|
35
|
+
/**
|
|
36
|
+
* URL path for webhook (e.g., '/api/webhooks/stripe')
|
|
37
|
+
*/
|
|
38
|
+
path: string;
|
|
39
|
+
/**
|
|
40
|
+
* HTTP method
|
|
41
|
+
*/
|
|
42
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
43
|
+
/**
|
|
44
|
+
* Authentication configuration
|
|
45
|
+
*/
|
|
46
|
+
auth?: any;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Schedule-specific configuration
|
|
50
|
+
*/
|
|
51
|
+
schedule?: {
|
|
52
|
+
/**
|
|
53
|
+
* Cron expression (e.g., '0 9 * * *' for 9 AM daily)
|
|
54
|
+
*/
|
|
55
|
+
cron: string;
|
|
56
|
+
/**
|
|
57
|
+
* Timezone for cron expression
|
|
58
|
+
*/
|
|
59
|
+
timezone?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether schedule is enabled
|
|
62
|
+
*/
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Additional configuration options
|
|
67
|
+
*/
|
|
68
|
+
config?: Record<string, any>;
|
|
69
|
+
}
|
|
2
70
|
export interface FlowConfig {
|
|
3
71
|
/**
|
|
4
72
|
* One or more flow names this step belongs to.
|
|
@@ -22,6 +90,88 @@ export interface FlowConfig {
|
|
|
22
90
|
* The compiler normalizes this to `string[]` under `subscribes`.
|
|
23
91
|
*/
|
|
24
92
|
subscribes?: string | string[];
|
|
93
|
+
/**
|
|
94
|
+
* Entry trigger configuration (v0.5)
|
|
95
|
+
* Define and/or subscribe to triggers to start flow runs
|
|
96
|
+
*/
|
|
97
|
+
triggers?: {
|
|
98
|
+
/**
|
|
99
|
+
* Define a new trigger inline (optional)
|
|
100
|
+
* If provided, this trigger will be registered at build time
|
|
101
|
+
*/
|
|
102
|
+
define?: TriggerDefinition;
|
|
103
|
+
/**
|
|
104
|
+
* Array of trigger names to subscribe to
|
|
105
|
+
* Can include the defined trigger or external triggers
|
|
106
|
+
*/
|
|
107
|
+
subscribe: string[];
|
|
108
|
+
/**
|
|
109
|
+
* Trigger mode: 'auto' (immediate) or 'manual' (requires approval)
|
|
110
|
+
*/
|
|
111
|
+
mode?: 'auto' | 'manual';
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Await pattern: Wait BEFORE step execution (v0.5)
|
|
115
|
+
* Step won't execute until trigger fires
|
|
116
|
+
*/
|
|
117
|
+
awaitBefore?: AwaitConfig;
|
|
118
|
+
/**
|
|
119
|
+
* Await pattern: Wait AFTER step execution (v0.5)
|
|
120
|
+
* Next steps won't trigger until trigger fires
|
|
121
|
+
*/
|
|
122
|
+
awaitAfter?: AwaitConfig;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Await configuration (run-scoped triggers)
|
|
126
|
+
* Declared in config, no functions allowed (AST-parsed)
|
|
127
|
+
*/
|
|
128
|
+
export interface AwaitConfig {
|
|
129
|
+
/**
|
|
130
|
+
* Trigger type
|
|
131
|
+
*/
|
|
132
|
+
type: 'webhook' | 'event' | 'schedule' | 'time';
|
|
133
|
+
/**
|
|
134
|
+
* URL path for webhook (supports template variables: {runId}, {stepId})
|
|
135
|
+
*/
|
|
136
|
+
path?: string;
|
|
137
|
+
/**
|
|
138
|
+
* HTTP method for webhook
|
|
139
|
+
*/
|
|
140
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
141
|
+
/**
|
|
142
|
+
* Event name to wait for
|
|
143
|
+
*/
|
|
144
|
+
event?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Key to match between event and step data
|
|
147
|
+
* e.g., 'orderId' matches event.orderId === step.orderId
|
|
148
|
+
* Supports nested paths: 'order.id' matches event.order.id === step.order.id
|
|
149
|
+
*/
|
|
150
|
+
filterKey?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Cron expression (e.g., '0 9 * * *' for 9 AM daily)
|
|
153
|
+
*/
|
|
154
|
+
cron?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Hours to add after step completion before calculating next cron occurrence
|
|
157
|
+
*/
|
|
158
|
+
nextAfterHours?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Timezone for cron expression
|
|
161
|
+
*/
|
|
162
|
+
timezone?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Delay in milliseconds
|
|
165
|
+
*/
|
|
166
|
+
delay?: number;
|
|
167
|
+
/**
|
|
168
|
+
* Maximum wait time in milliseconds
|
|
169
|
+
*/
|
|
170
|
+
timeout?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Action to take on timeout
|
|
173
|
+
*/
|
|
174
|
+
timeoutAction?: 'fail' | 'continue' | 'retry';
|
|
25
175
|
}
|
|
26
176
|
export interface QueueJobDefaults {
|
|
27
177
|
/**
|
|
@@ -151,4 +301,10 @@ export interface QueueWorkerConfig {
|
|
|
151
301
|
}
|
|
152
302
|
export type DefineFunctionConfig = <T extends QueueWorkerConfig>(cfg: T) => T;
|
|
153
303
|
export declare const defineFunctionConfig: DefineFunctionConfig;
|
|
304
|
+
/**
|
|
305
|
+
* Helper for defining trigger configurations inline
|
|
306
|
+
* This is just a type helper, actual value is the same as defineFunctionConfig
|
|
307
|
+
*/
|
|
308
|
+
export type DefineTriggerConfig = <T extends TriggerDefinition>(cfg: T) => T;
|
|
309
|
+
export declare const defineTriggerConfig: DefineTriggerConfig;
|
|
154
310
|
export default defineFunctionConfig;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe hook definitions for await patterns
|
|
3
|
+
* v0.5 - Await Integration
|
|
4
|
+
*/
|
|
5
|
+
import type { RunContext } from '../worker/node/runner.js';
|
|
6
|
+
export interface AwaitRegisterContext extends Pick<RunContext, 'flowId' | 'flowName' | 'stepName' | 'logger' | 'state'> {
|
|
7
|
+
awaitType: 'webhook' | 'event' | 'schedule' | 'time';
|
|
8
|
+
awaitConfig: any;
|
|
9
|
+
}
|
|
10
|
+
export interface AwaitResolveContext extends Pick<RunContext, 'flowId' | 'flowName' | 'stepName' | 'logger' | 'state'> {
|
|
11
|
+
awaitType: 'webhook' | 'event' | 'schedule' | 'time';
|
|
12
|
+
resolvedData: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Define onAwaitRegister hook with proper types
|
|
16
|
+
* Called when an await pattern is registered (before handler execution or after completion)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* export const onAwaitRegister = defineAwaitRegisterHook(async (webhookUrl, stepData, ctx) => {
|
|
20
|
+
* // Send notification email with webhook URL
|
|
21
|
+
* await sendEmail({
|
|
22
|
+
* to: stepData.reviewerEmail,
|
|
23
|
+
* subject: 'Approval Required',
|
|
24
|
+
* approveUrl: webhookUrl
|
|
25
|
+
* })
|
|
26
|
+
* })
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineAwaitRegisterHook(hook: (webhookUrl: string, stepData: any, ctx: AwaitRegisterContext) => Promise<void>): (webhookUrl: string, stepData: any, ctx: AwaitRegisterContext) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Define onAwaitResolve hook with proper types
|
|
31
|
+
* Called when an await pattern is resolved (external trigger fired)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* export const onAwaitResolve = defineAwaitResolveHook(async (resolvedData, stepData, ctx) => {
|
|
35
|
+
* ctx.logger.log('info', 'Approval received', { approved: resolvedData.approved })
|
|
36
|
+
*
|
|
37
|
+
* // Update external system
|
|
38
|
+
* await updateTicketStatus(stepData.ticketId, resolvedData.approved ? 'approved' : 'rejected')
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
export declare function defineAwaitResolveHook(hook: (resolvedData: any, stepData: any, ctx: AwaitResolveContext) => Promise<void>): (resolvedData: any, stepData: any, ctx: AwaitResolveContext) => Promise<void>;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Used by external adapter modules to register their adapters with nvent
|
|
5
5
|
*/
|
|
6
|
-
import type { QueueAdapter } from '
|
|
7
|
-
import type { StreamAdapter } from '
|
|
8
|
-
import type { StoreAdapter } from '
|
|
6
|
+
import type { QueueAdapter } from '../../adapters/interfaces/queue.js';
|
|
7
|
+
import type { StreamAdapter } from '../../adapters/interfaces/stream.js';
|
|
8
|
+
import type { StoreAdapter } from '../../adapters/interfaces/store.js';
|
|
9
9
|
/**
|
|
10
10
|
* Register a queue adapter
|
|
11
11
|
*
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AwaitConfig } from '../../../registry/types.js';
|
|
2
|
+
import { registerAwaitPattern, resolveAwaitPattern, registerWebhookAwait, resolveWebhookAwait, registerEventAwait, resolveEventAwait, registerScheduleAwait, resolveScheduleAwait, registerTimeAwait, resolveTimeAwait } from './awaitPatterns/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Await pattern composable
|
|
5
|
+
* Provides unified API for managing await patterns in flows
|
|
6
|
+
* Separate from useTrigger which handles entry triggers (manual, webhook, schedule, event)
|
|
7
|
+
*/
|
|
8
|
+
export declare function useAwait(): {
|
|
9
|
+
/**
|
|
10
|
+
* Register an await pattern based on config type
|
|
11
|
+
* Automatically routes to appropriate implementation
|
|
12
|
+
*/
|
|
13
|
+
register: typeof registerAwaitPattern;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve an await pattern by type
|
|
16
|
+
*/
|
|
17
|
+
resolve: typeof resolveAwaitPattern;
|
|
18
|
+
/**
|
|
19
|
+
* Direct access to specific await pattern implementations
|
|
20
|
+
*/
|
|
21
|
+
webhook: {
|
|
22
|
+
register: typeof registerWebhookAwait;
|
|
23
|
+
resolve: typeof resolveWebhookAwait;
|
|
24
|
+
};
|
|
25
|
+
event: {
|
|
26
|
+
register: typeof registerEventAwait;
|
|
27
|
+
resolve: typeof resolveEventAwait;
|
|
28
|
+
};
|
|
29
|
+
schedule: {
|
|
30
|
+
register: typeof registerScheduleAwait;
|
|
31
|
+
resolve: typeof resolveScheduleAwait;
|
|
32
|
+
};
|
|
33
|
+
time: {
|
|
34
|
+
register: typeof registerTimeAwait;
|
|
35
|
+
resolve: typeof resolveTimeAwait;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Query methods for await state
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Get await state for a specific flow run and step
|
|
42
|
+
*/
|
|
43
|
+
getAwaitState(flowName: string, runId: string, stepName?: string): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a step is currently awaiting
|
|
46
|
+
*/
|
|
47
|
+
isAwaiting(flowName: string, runId: string, stepName: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Get all active awaits across all flows
|
|
50
|
+
*/
|
|
51
|
+
getAllActiveAwaits(flowName?: string): Promise<{
|
|
52
|
+
flowName: string;
|
|
53
|
+
runId: string;
|
|
54
|
+
stepName: string;
|
|
55
|
+
awaitType: string;
|
|
56
|
+
position: "before" | "after";
|
|
57
|
+
registeredAt: string;
|
|
58
|
+
}[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Get await history for a specific flow run from stream
|
|
61
|
+
*/
|
|
62
|
+
getAwaitHistory(runId: string, opts?: {
|
|
63
|
+
limit?: number;
|
|
64
|
+
stepName?: string;
|
|
65
|
+
}): Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Cancel/timeout an active await
|
|
68
|
+
*/
|
|
69
|
+
timeoutAwait(flowName: string, runId: string, stepName: string, reason?: string): Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
export type { AwaitConfig };
|