nvent 0.5.15 → 1.0.0-alpha.2
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 +181 -8
- package/dist/module.json +1 -1
- package/dist/module.mjs +1257 -1196
- package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
- package/dist/runtime/app/composables/useFunctionCall.js +25 -0
- package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
- package/dist/runtime/app/composables/useNventStream.js +58 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
- package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
- package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
- package/dist/runtime/nitro/utils/console.d.ts +32 -0
- package/dist/runtime/nitro/utils/console.js +95 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
- package/dist/runtime/nitro/utils/defineFunction.js +224 -4
- package/dist/runtime/nitro/utils/engine.d.ts +25 -0
- package/dist/runtime/nitro/utils/engine.js +130 -0
- package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
- package/dist/runtime/nitro/utils/nventDir.js +20 -0
- package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
- package/dist/runtime/nitro/utils/useIii.js +14 -0
- package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
- package/dist/runtime/nitro/utils/workers/node.js +57 -0
- package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
- package/dist/runtime/nitro/utils/workers/python.js +220 -0
- package/dist/runtime/python/nvent.py +208 -0
- package/dist/runtime/python/worker_runtime.py +659 -0
- package/dist/runtime/virtual.d.ts +17 -0
- package/dist/types.d.mts +5 -1
- package/package.json +11 -14
- package/dist/runtime/adapters/base/index.d.ts +0 -6
- package/dist/runtime/adapters/base/index.js +0 -1
- package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
- package/dist/runtime/adapters/base/store-validator.js +0 -147
- package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
- package/dist/runtime/adapters/builtin/file-queue.js +0 -499
- package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
- package/dist/runtime/adapters/builtin/file-store.js +0 -206
- package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
- package/dist/runtime/adapters/builtin/file-stream.js +0 -56
- package/dist/runtime/adapters/builtin/index.d.ts +0 -10
- package/dist/runtime/adapters/builtin/index.js +0 -5
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
- package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
- package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
- package/dist/runtime/adapters/builtin/memory-store.js +0 -357
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
- package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
- package/dist/runtime/adapters/factory.d.ts +0 -31
- package/dist/runtime/adapters/factory.js +0 -135
- package/dist/runtime/adapters/index.d.ts +0 -8
- package/dist/runtime/adapters/index.js +0 -3
- package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
- package/dist/runtime/adapters/interfaces/index.js +0 -3
- package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
- package/dist/runtime/adapters/interfaces/queue.js +0 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
- package/dist/runtime/adapters/interfaces/store.js +0 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
- package/dist/runtime/adapters/interfaces/stream.js +0 -0
- package/dist/runtime/adapters/registry.d.ts +0 -85
- package/dist/runtime/adapters/registry.js +0 -161
- package/dist/runtime/config/index.d.ts +0 -23
- package/dist/runtime/config/index.js +0 -200
- package/dist/runtime/config/types.d.ts +0 -439
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/eventBus.d.ts +0 -20
- package/dist/runtime/events/eventBus.js +0 -35
- package/dist/runtime/events/types.d.ts +0 -144
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
- package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
- package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
- package/dist/runtime/events/utils/stallDetector.js +0 -318
- package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
- package/dist/runtime/events/utils/triggerRuntime.js +0 -212
- package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
- package/dist/runtime/events/wiring/flowWiring.js +0 -1258
- package/dist/runtime/events/wiring/registry.d.ts +0 -19
- package/dist/runtime/events/wiring/registry.js +0 -43
- package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
- package/dist/runtime/events/wiring/stateWiring.js +0 -92
- package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
- package/dist/runtime/events/wiring/streamWiring.js +0 -156
- package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
- package/dist/runtime/events/wiring/triggerWiring.js +0 -422
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
- package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
- package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
- package/dist/runtime/nitro/plugins/02.workers.js +0 -92
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
- package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
- package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
- package/dist/runtime/nitro/routes/webhook.await.js +0 -112
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
- package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
- package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
- package/dist/runtime/nitro/utils/adapters.js +0 -51
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
- package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
- package/dist/runtime/nitro/utils/defineHooks.js +0 -9
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
- package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
- package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
- package/dist/runtime/nitro/utils/useAwait.js +0 -169
- package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
- package/dist/runtime/nitro/utils/useEventManager.js +0 -26
- package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
- package/dist/runtime/nitro/utils/useFlow.js +0 -310
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
- package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
- package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
- package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
- package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
- package/dist/runtime/nitro/utils/useRunContext.js +0 -102
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
- package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
- package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
- package/dist/runtime/nitro/utils/useTrigger.js +0 -311
- package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
- package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
- package/dist/runtime/scheduler/index.d.ts +0 -33
- package/dist/runtime/scheduler/index.js +0 -42
- package/dist/runtime/scheduler/scheduler.d.ts +0 -132
- package/dist/runtime/scheduler/scheduler.js +0 -799
- package/dist/runtime/scheduler/types.d.ts +0 -122
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/worker/node/runner.d.ts +0 -95
- package/dist/runtime/worker/node/runner.js +0 -272
- package/dist/runtime/worker/python/get_config.py +0 -64
- package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
- package/dist/runtime/worker/system/awaitHandlers.js +0 -230
- package/dist/runtime/worker/system/index.d.ts +0 -24
- package/dist/runtime/worker/system/index.js +0 -39
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useNventLogger } from "#imports";
|
|
2
|
-
import { registerWebhookAwait, resolveWebhookAwait } from "./webhook.js";
|
|
3
|
-
import { registerEventAwait, resolveEventAwait } from "./event.js";
|
|
4
|
-
import { registerScheduleAwait, resolveScheduleAwait } from "./schedule.js";
|
|
5
|
-
import { registerTimeAwait, resolveTimeAwait } from "./time.js";
|
|
6
|
-
export async function registerAwaitPattern(runId, stepName, flowName, config, position = "after") {
|
|
7
|
-
const logger = useNventLogger("await-patterns");
|
|
8
|
-
logger.info(`Registering await pattern: ${config.type}`, {
|
|
9
|
-
runId,
|
|
10
|
-
stepName,
|
|
11
|
-
type: config.type
|
|
12
|
-
});
|
|
13
|
-
switch (config.type) {
|
|
14
|
-
case "webhook":
|
|
15
|
-
return await registerWebhookAwait(runId, stepName, flowName, config, position);
|
|
16
|
-
case "event":
|
|
17
|
-
return await registerEventAwait(runId, stepName, flowName, config, position);
|
|
18
|
-
case "schedule":
|
|
19
|
-
return await registerScheduleAwait(runId, stepName, flowName, config, position);
|
|
20
|
-
case "time":
|
|
21
|
-
return await registerTimeAwait(runId, stepName, flowName, config, position);
|
|
22
|
-
default:
|
|
23
|
-
throw new Error(`Unknown await pattern type: ${config.type}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export async function resolveAwaitPattern(type, runId, stepName, flowName, position, data) {
|
|
27
|
-
const logger = useNventLogger("await-patterns");
|
|
28
|
-
logger.info(`Resolving await pattern: ${type}`, {
|
|
29
|
-
runId,
|
|
30
|
-
stepName,
|
|
31
|
-
type
|
|
32
|
-
});
|
|
33
|
-
switch (type) {
|
|
34
|
-
case "webhook":
|
|
35
|
-
return await resolveWebhookAwait(runId, stepName, data);
|
|
36
|
-
case "event":
|
|
37
|
-
return await resolveEventAwait(runId, stepName, data);
|
|
38
|
-
case "schedule":
|
|
39
|
-
return await resolveScheduleAwait(runId, stepName, data);
|
|
40
|
-
case "time":
|
|
41
|
-
return await resolveTimeAwait(runId, stepName, flowName, position, data);
|
|
42
|
-
default:
|
|
43
|
-
throw new Error(`Unknown await pattern type: ${type}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
registerWebhookAwait,
|
|
48
|
-
resolveWebhookAwait,
|
|
49
|
-
registerEventAwait,
|
|
50
|
-
resolveEventAwait,
|
|
51
|
-
registerScheduleAwait,
|
|
52
|
-
resolveScheduleAwait,
|
|
53
|
-
registerTimeAwait,
|
|
54
|
-
resolveTimeAwait
|
|
55
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { AwaitConfig } from '../../../../registry/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Await Pattern: Schedule
|
|
4
|
-
*
|
|
5
|
-
* Waits until next cron schedule occurrence
|
|
6
|
-
* Useful for batch processing, daily reports, scheduled operations
|
|
7
|
-
*/
|
|
8
|
-
export declare function registerScheduleAwait(runId: string, stepName: string, flowName: string, config: AwaitConfig, position?: 'before' | 'after'): Promise<{
|
|
9
|
-
cron: string;
|
|
10
|
-
nextOccurrence: number;
|
|
11
|
-
timeUntilNext: number;
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* Resolve schedule await when cron time is reached
|
|
15
|
-
*/
|
|
16
|
-
export declare function resolveScheduleAwait(runId: string, stepName: string, flowName: string, position: 'before' | 'after', scheduleData: any): Promise<void>;
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
position,
|
|
47
|
-
// Store position in data for database persistence
|
|
48
|
-
cron: config.cron,
|
|
49
|
-
nextOccurrence,
|
|
50
|
-
timeUntilNext,
|
|
51
|
-
registeredAt: Date.now()
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
logger.debug(`Schedule await registered: ${config.cron} (next: ${new Date(nextOccurrence).toISOString()})`, {
|
|
55
|
-
runId,
|
|
56
|
-
stepName
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
cron: config.cron,
|
|
60
|
-
nextOccurrence,
|
|
61
|
-
timeUntilNext
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export async function resolveScheduleAwait(runId, stepName, flowName, position, scheduleData) {
|
|
65
|
-
const logger = useNventLogger("await-schedule");
|
|
66
|
-
const eventBus = getEventBus();
|
|
67
|
-
logger.info(`Resolving schedule await`, { runId, stepName });
|
|
68
|
-
const scheduledAt = scheduleData?.scheduledAt || Date.now();
|
|
69
|
-
eventBus.publish({
|
|
70
|
-
type: "await.resolved",
|
|
71
|
-
flowName,
|
|
72
|
-
runId,
|
|
73
|
-
stepName,
|
|
74
|
-
position,
|
|
75
|
-
triggerData: { scheduledAt },
|
|
76
|
-
data: {
|
|
77
|
-
position,
|
|
78
|
-
// Store position in data for database persistence
|
|
79
|
-
resolvedAt: Date.now()
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
logger.debug(`Schedule await resolved`, { runId, stepName });
|
|
83
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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>;
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
position,
|
|
41
|
-
// Store position in data for database persistence
|
|
42
|
-
delay: config.delay,
|
|
43
|
-
resolveAt,
|
|
44
|
-
registeredAt: Date.now()
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
logger.debug(`Time await registered: ${config.delay}ms`, { runId, stepName });
|
|
48
|
-
return {
|
|
49
|
-
delay: config.delay,
|
|
50
|
-
resolveAt
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export async function resolveTimeAwait(runId, stepName, flowName, position, _timeData) {
|
|
54
|
-
const logger = useNventLogger("await-time");
|
|
55
|
-
const eventBus = getEventBus();
|
|
56
|
-
logger.info(`Resolving time await`, { runId, stepName });
|
|
57
|
-
eventBus.publish({
|
|
58
|
-
type: "await.resolved",
|
|
59
|
-
flowName,
|
|
60
|
-
runId,
|
|
61
|
-
stepName,
|
|
62
|
-
position,
|
|
63
|
-
triggerData: {},
|
|
64
|
-
data: {
|
|
65
|
-
position,
|
|
66
|
-
// Store position in data for database persistence
|
|
67
|
-
resolvedAt: Date.now()
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
logger.debug(`Time await resolved`, { runId, stepName });
|
|
71
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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>;
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
const { useAwaitDefaults } = await import("../useAwait.js");
|
|
26
|
-
const { webhookTimeout: defaultTimeout, timeoutAction: defaultTimeoutAction } = useAwaitDefaults();
|
|
27
|
-
const timeoutMs = config.timeout && config.timeout > 0 ? config.timeout : defaultTimeout;
|
|
28
|
-
eventBus.publish({
|
|
29
|
-
type: "await.registered",
|
|
30
|
-
flowName,
|
|
31
|
-
runId,
|
|
32
|
-
stepName,
|
|
33
|
-
awaitType: "webhook",
|
|
34
|
-
position,
|
|
35
|
-
config,
|
|
36
|
-
data: {
|
|
37
|
-
position,
|
|
38
|
-
// Store position in data for database persistence
|
|
39
|
-
path,
|
|
40
|
-
method: config.method || "POST",
|
|
41
|
-
timeout: timeoutMs,
|
|
42
|
-
// Store resolved timeout (with default)
|
|
43
|
-
registeredAt: Date.now(),
|
|
44
|
-
webhookUrl: fullWebhookUrl,
|
|
45
|
-
timeoutAction: config.timeoutAction || defaultTimeoutAction
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
const scheduler = useScheduler();
|
|
49
|
-
const timeoutAt = Date.now() + timeoutMs;
|
|
50
|
-
const jobId = `await-webhook-timeout-${runId}-${stepName}-${position}`;
|
|
51
|
-
await scheduler.schedule({
|
|
52
|
-
id: jobId,
|
|
53
|
-
name: `Webhook Timeout: ${flowName} - ${stepName}`,
|
|
54
|
-
type: "one-time",
|
|
55
|
-
executeAt: timeoutAt,
|
|
56
|
-
handler: async () => {
|
|
57
|
-
logger.warn("Webhook await timeout", {
|
|
58
|
-
runId,
|
|
59
|
-
stepName,
|
|
60
|
-
flowName,
|
|
61
|
-
timeout: timeoutMs,
|
|
62
|
-
timeoutAction: config.timeoutAction || "fail"
|
|
63
|
-
});
|
|
64
|
-
eventBus.publish({
|
|
65
|
-
type: "await.timeout",
|
|
66
|
-
flowName,
|
|
67
|
-
runId,
|
|
68
|
-
stepName,
|
|
69
|
-
position,
|
|
70
|
-
awaitType: "webhook",
|
|
71
|
-
timeoutAction: config.timeoutAction || "fail",
|
|
72
|
-
data: {
|
|
73
|
-
timeout: timeoutMs,
|
|
74
|
-
registeredAt: Date.now() - timeoutMs,
|
|
75
|
-
timedOutAt: Date.now()
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
metadata: {
|
|
80
|
-
component: "await-pattern",
|
|
81
|
-
awaitType: "webhook",
|
|
82
|
-
runId,
|
|
83
|
-
stepName,
|
|
84
|
-
flowName,
|
|
85
|
-
position,
|
|
86
|
-
timeout: timeoutMs
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
logger.debug(`Webhook timeout scheduled`, {
|
|
90
|
-
runId,
|
|
91
|
-
stepName,
|
|
92
|
-
timeout: timeoutMs,
|
|
93
|
-
timeoutAction: config.timeoutAction,
|
|
94
|
-
isDefault: !config.timeout || config.timeout <= 0
|
|
95
|
-
});
|
|
96
|
-
logger.debug(`Webhook await registered: ${fullWebhookUrl}`, { runId, stepName });
|
|
97
|
-
return {
|
|
98
|
-
webhookUrl: fullWebhookUrl,
|
|
99
|
-
timeout: config.timeout
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
export async function resolveWebhookAwait(runId, stepName, flowName, position, webhookData) {
|
|
103
|
-
const logger = useNventLogger("await-webhook");
|
|
104
|
-
const eventBus = getEventBus();
|
|
105
|
-
const scheduler = useScheduler();
|
|
106
|
-
logger.info(`Resolving webhook await`, { runId, stepName });
|
|
107
|
-
const jobId = `await-webhook-timeout-${runId}-${stepName}-${position}`;
|
|
108
|
-
try {
|
|
109
|
-
await scheduler.unschedule(jobId);
|
|
110
|
-
logger.debug("Unscheduled webhook timeout job", { runId, stepName, jobId });
|
|
111
|
-
} catch {
|
|
112
|
-
logger.debug("Could not unschedule timeout job (may not exist)", { runId, stepName, jobId });
|
|
113
|
-
}
|
|
114
|
-
eventBus.publish({
|
|
115
|
-
type: "await.resolved",
|
|
116
|
-
flowName,
|
|
117
|
-
runId,
|
|
118
|
-
stepName,
|
|
119
|
-
position,
|
|
120
|
-
triggerData: webhookData,
|
|
121
|
-
data: {
|
|
122
|
-
position,
|
|
123
|
-
// Store position in data for database persistence
|
|
124
|
-
resolvedAt: Date.now()
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
logger.debug(`Webhook await resolved`, { runId, stepName });
|
|
128
|
-
}
|