@wooksjs/event-wf 0.7.10 → 0.7.12
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/index.cjs +72 -99
- package/dist/index.mjs +33 -38
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key$2; i < n; i++) {
|
|
10
|
-
key$2 = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key$2) && key$2 !== except) __defProp(to, key$2, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key$2),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key$2)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
|
|
25
|
-
const __wooksjs_event_http = __toESM(require("@wooksjs/event-http"));
|
|
26
|
-
const __wooksjs_http_body = __toESM(require("@wooksjs/http-body"));
|
|
27
|
-
const node_crypto = __toESM(require("node:crypto"));
|
|
28
|
-
const __prostojs_wf = __toESM(require("@prostojs/wf"));
|
|
29
|
-
const wooks = __toESM(require("wooks"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _wooksjs_event_core = require("@wooksjs/event-core");
|
|
3
|
+
let _wooksjs_event_http = require("@wooksjs/event-http");
|
|
4
|
+
let _wooksjs_http_body = require("@wooksjs/http-body");
|
|
5
|
+
let node_crypto = require("node:crypto");
|
|
6
|
+
let _prostojs_wf = require("@prostojs/wf");
|
|
7
|
+
let wooks = require("wooks");
|
|
30
8
|
|
|
31
9
|
//#region packages/event-wf/src/wf-kind.ts
|
|
32
|
-
const wfKind = (0,
|
|
33
|
-
schemaId: (0,
|
|
34
|
-
stepId: (0,
|
|
35
|
-
inputContext: (0,
|
|
36
|
-
indexes: (0,
|
|
37
|
-
input: (0,
|
|
10
|
+
const wfKind = (0, _wooksjs_event_core.defineEventKind)("WF", {
|
|
11
|
+
schemaId: (0, _wooksjs_event_core.slot)(),
|
|
12
|
+
stepId: (0, _wooksjs_event_core.slot)(),
|
|
13
|
+
inputContext: (0, _wooksjs_event_core.slot)(),
|
|
14
|
+
indexes: (0, _wooksjs_event_core.slot)(),
|
|
15
|
+
input: (0, _wooksjs_event_core.slot)()
|
|
38
16
|
});
|
|
39
|
-
const resumeKey = (0,
|
|
17
|
+
const resumeKey = (0, _wooksjs_event_core.key)("wf.resume");
|
|
40
18
|
|
|
41
19
|
//#endregion
|
|
42
20
|
//#region packages/event-wf/src/composables/wf-state.ts
|
|
@@ -49,7 +27,7 @@ const resumeKey = (0, __wooksjs_event_core.key)("wf.resume");
|
|
|
49
27
|
* const stepInput = input<MyInput>()
|
|
50
28
|
* ```
|
|
51
29
|
*/
|
|
52
|
-
const useWfState = (0,
|
|
30
|
+
const useWfState = (0, _wooksjs_event_core.defineWook)((c) => ({
|
|
53
31
|
ctx: () => c.get(wfKind.keys.inputContext),
|
|
54
32
|
input: () => c.get(wfKind.keys.input),
|
|
55
33
|
schemaId: c.get(wfKind.keys.schemaId),
|
|
@@ -62,15 +40,15 @@ const useWfState = (0, __wooksjs_event_core.defineWook)((c) => ({
|
|
|
62
40
|
//#region packages/event-wf/src/event-wf.ts
|
|
63
41
|
/** Creates a WF event context for a fresh workflow execution and runs `fn` inside it. */
|
|
64
42
|
function createWfContext(options, seeds, fn) {
|
|
65
|
-
return (0,
|
|
66
|
-
(0,
|
|
43
|
+
return (0, _wooksjs_event_core.createEventContext)(options, wfKind, seeds, () => {
|
|
44
|
+
(0, _wooksjs_event_core.current)().set(resumeKey, false);
|
|
67
45
|
return fn();
|
|
68
46
|
});
|
|
69
47
|
}
|
|
70
48
|
/** Creates a WF event context for resuming a paused workflow and runs `fn` inside it. */
|
|
71
49
|
function resumeWfContext(options, seeds, fn) {
|
|
72
|
-
return (0,
|
|
73
|
-
(0,
|
|
50
|
+
return (0, _wooksjs_event_core.createEventContext)(options, wfKind, seeds, () => {
|
|
51
|
+
(0, _wooksjs_event_core.current)().set(resumeKey, true);
|
|
74
52
|
return fn();
|
|
75
53
|
});
|
|
76
54
|
}
|
|
@@ -78,11 +56,11 @@ function resumeWfContext(options, seeds, fn) {
|
|
|
78
56
|
//#endregion
|
|
79
57
|
//#region packages/event-wf/src/outlets/outlet-context.ts
|
|
80
58
|
/** Registered outlet handlers, keyed by name */
|
|
81
|
-
const outletsRegistryKey = (0,
|
|
59
|
+
const outletsRegistryKey = (0, _wooksjs_event_core.key)("wf.outlets.registry");
|
|
82
60
|
/** Active state strategy for current request */
|
|
83
|
-
const stateStrategyKey = (0,
|
|
61
|
+
const stateStrategyKey = (0, _wooksjs_event_core.key)("wf.outlets.stateStrategy");
|
|
84
62
|
/** Finished response set by workflow steps */
|
|
85
|
-
const wfFinishedKey = (0,
|
|
63
|
+
const wfFinishedKey = (0, _wooksjs_event_core.key)("wf.outlets.finished");
|
|
86
64
|
|
|
87
65
|
//#endregion
|
|
88
66
|
//#region packages/event-wf/src/outlets/use-wf-outlet.ts
|
|
@@ -93,7 +71,7 @@ const wfFinishedKey = (0, __wooksjs_event_core.key)("wf.outlets.finished");
|
|
|
93
71
|
* `outletEmail(to, template)`. This composable is for advanced cases
|
|
94
72
|
* where steps need to inspect or modify outlet state directly.
|
|
95
73
|
*/
|
|
96
|
-
const useWfOutlet = (0,
|
|
74
|
+
const useWfOutlet = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
97
75
|
getStateStrategy: () => ctx.get(stateStrategyKey),
|
|
98
76
|
getOutlets: () => ctx.get(outletsRegistryKey),
|
|
99
77
|
getOutlet: (name) => ctx.get(outletsRegistryKey)?.get(name) ?? null
|
|
@@ -113,7 +91,7 @@ const useWfOutlet = (0, __wooksjs_event_core.defineWook)((ctx) => ({
|
|
|
113
91
|
* useWfFinished().set({ type: 'data', value: { success: true } })
|
|
114
92
|
* ```
|
|
115
93
|
*/
|
|
116
|
-
const useWfFinished = (0,
|
|
94
|
+
const useWfFinished = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
117
95
|
set: (response) => ctx.set(wfFinishedKey, response),
|
|
118
96
|
get: () => ctx.has(wfFinishedKey) ? ctx.get(wfFinishedKey) : void 0
|
|
119
97
|
}));
|
|
@@ -147,14 +125,14 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
147
125
|
];
|
|
148
126
|
const tokenWrite = tok.write ?? "body";
|
|
149
127
|
const wfidName = config.wfidName ?? "wfid";
|
|
150
|
-
const ctx = (0,
|
|
128
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
151
129
|
const registry = new Map(config.outlets.map((o) => [o.name, o]));
|
|
152
130
|
ctx.set(outletsRegistryKey, registry);
|
|
153
131
|
ctx.set(wfFinishedKey, void 0);
|
|
154
|
-
const { parseBody } = (0,
|
|
155
|
-
const { params } = (0,
|
|
156
|
-
const { getCookie } = (0,
|
|
157
|
-
const response = (0,
|
|
132
|
+
const { parseBody } = (0, _wooksjs_http_body.useBody)();
|
|
133
|
+
const { params } = (0, _wooksjs_event_http.useUrlParams)();
|
|
134
|
+
const { getCookie } = (0, _wooksjs_event_http.useCookies)();
|
|
135
|
+
const response = (0, _wooksjs_event_http.useResponse)();
|
|
158
136
|
const body = await parseBody().catch(() => void 0);
|
|
159
137
|
const queryParams = params();
|
|
160
138
|
let token;
|
|
@@ -172,10 +150,10 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
172
150
|
const strategy = resolveStrategy(wfid ?? "");
|
|
173
151
|
ctx.set(stateStrategyKey, strategy);
|
|
174
152
|
const state = await strategy.consume(token);
|
|
175
|
-
if (!state)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
153
|
+
if (!state) {
|
|
154
|
+
response.setStatus(410);
|
|
155
|
+
return { error: "Invalid or expired workflow state" };
|
|
156
|
+
}
|
|
179
157
|
if (state.schemaId !== (wfid ?? "")) {
|
|
180
158
|
const realStrategy = resolveStrategy(state.schemaId);
|
|
181
159
|
ctx.set(stateStrategyKey, realStrategy);
|
|
@@ -185,14 +163,14 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
185
163
|
eventContext: ctx
|
|
186
164
|
});
|
|
187
165
|
} else if (wfid) {
|
|
188
|
-
if (config.allow?.length && !config.allow.includes(wfid))
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
if (config.block?.includes(wfid))
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
166
|
+
if (config.allow?.length && !config.allow.includes(wfid)) {
|
|
167
|
+
response.setStatus(403);
|
|
168
|
+
return { error: `Workflow '${wfid}' is not allowed` };
|
|
169
|
+
}
|
|
170
|
+
if (config.block?.includes(wfid)) {
|
|
171
|
+
response.setStatus(403);
|
|
172
|
+
return { error: `Workflow '${wfid}' is blocked` };
|
|
173
|
+
}
|
|
196
174
|
const strategy = resolveStrategy(wfid);
|
|
197
175
|
ctx.set(stateStrategyKey, strategy);
|
|
198
176
|
const initialContext = config.initialContext ? config.initialContext(body, wfid) : {};
|
|
@@ -200,10 +178,10 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
200
178
|
input,
|
|
201
179
|
eventContext: ctx
|
|
202
180
|
});
|
|
203
|
-
} else
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
181
|
+
} else {
|
|
182
|
+
response.setStatus(400);
|
|
183
|
+
return { error: "Missing wfs (state token) or wfid (workflow ID)" };
|
|
184
|
+
}
|
|
207
185
|
if (output.finished) {
|
|
208
186
|
if (config.onFinished) return config.onFinished({
|
|
209
187
|
context: output.state.context,
|
|
@@ -212,19 +190,23 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
212
190
|
const finished = ctx.get(wfFinishedKey);
|
|
213
191
|
if (finished?.cookies) for (const [name, cookie] of Object.entries(finished.cookies)) response.setCookie(name, cookie.value, cookie.options);
|
|
214
192
|
if (finished?.type === "redirect") {
|
|
193
|
+
response.setStatus(finished.status ?? 302);
|
|
215
194
|
response.setHeader("location", finished.value);
|
|
216
|
-
return
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
if (finished) {
|
|
198
|
+
if (finished.status) response.setStatus(finished.status);
|
|
199
|
+
return finished.value;
|
|
217
200
|
}
|
|
218
|
-
if (finished) return finished.value;
|
|
219
201
|
return { finished: true };
|
|
220
202
|
}
|
|
221
203
|
if (output.inputRequired) {
|
|
222
204
|
const outletReq = output.inputRequired;
|
|
223
205
|
const outletHandler = registry.get(outletReq.outlet);
|
|
224
|
-
if (!outletHandler)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
206
|
+
if (!outletHandler) {
|
|
207
|
+
response.setStatus(500);
|
|
208
|
+
return { error: `Unknown outlet: '${outletReq.outlet}'` };
|
|
209
|
+
}
|
|
228
210
|
const strategy = ctx.get(stateStrategyKey);
|
|
229
211
|
const stateWithMeta = {
|
|
230
212
|
...output.state,
|
|
@@ -270,11 +252,10 @@ function createHttpOutlet(opts) {
|
|
|
270
252
|
name: "http",
|
|
271
253
|
tokenDelivery: "caller",
|
|
272
254
|
async deliver(request, _token) {
|
|
273
|
-
|
|
255
|
+
return { response: opts?.transform ? opts.transform(request.payload, request.context) : typeof request.payload === "object" && request.payload !== null ? {
|
|
274
256
|
...request.payload,
|
|
275
257
|
...request.context
|
|
276
|
-
} : request.payload;
|
|
277
|
-
return { response: body };
|
|
258
|
+
} : request.payload };
|
|
278
259
|
}
|
|
279
260
|
};
|
|
280
261
|
}
|
|
@@ -544,23 +525,22 @@ var WfStateStoreMemory = class {
|
|
|
544
525
|
//#endregion
|
|
545
526
|
//#region packages/event-wf/src/workflow.ts
|
|
546
527
|
/** Workflow engine that resolves steps via Wooks router lookup. */
|
|
547
|
-
var WooksWorkflow = class extends
|
|
548
|
-
constructor(wooks
|
|
528
|
+
var WooksWorkflow = class extends _prostojs_wf.Workflow {
|
|
529
|
+
constructor(wooks) {
|
|
549
530
|
super([]);
|
|
550
|
-
this.wooks = wooks
|
|
531
|
+
this.wooks = wooks;
|
|
551
532
|
}
|
|
552
533
|
resolveStep(stepId) {
|
|
553
534
|
const stepIdNorm = `/${stepId}`.replace(/\/{2,}/gu, "/");
|
|
554
535
|
try {
|
|
555
|
-
const ctx = (0,
|
|
536
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
556
537
|
const found = this.wooks.lookup("WF_STEP", stepIdNorm);
|
|
557
538
|
if (found.handlers?.length) {
|
|
558
539
|
ctx.set(wfKind.keys.stepId, stepIdNorm);
|
|
559
540
|
return found.handlers[0]();
|
|
560
541
|
}
|
|
561
542
|
} catch {
|
|
562
|
-
const
|
|
563
|
-
const found = router.lookup("WF_STEP", stepIdNorm);
|
|
543
|
+
const found = this.wooks.getRouter().lookup("WF_STEP", stepIdNorm);
|
|
564
544
|
if (found?.route?.handlers.length) return found.route.handlers[0]();
|
|
565
545
|
}
|
|
566
546
|
throw new Error(`Step "${stepIdNorm}" not found.`);
|
|
@@ -576,9 +556,6 @@ const wfShortcuts = {
|
|
|
576
556
|
};
|
|
577
557
|
/** Wooks adapter for defining and executing workflow schemas with step-based routing. */
|
|
578
558
|
var WooksWf = class extends wooks.WooksAdapterBase {
|
|
579
|
-
logger;
|
|
580
|
-
wf;
|
|
581
|
-
eventContextOptions;
|
|
582
559
|
constructor(opts, wooks$1) {
|
|
583
560
|
super(wooks$1, opts?.logger, opts?.router);
|
|
584
561
|
this.opts = opts;
|
|
@@ -596,7 +573,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
596
573
|
}
|
|
597
574
|
/** Registers a workflow step with the given id and handler. */
|
|
598
575
|
step(id, opts) {
|
|
599
|
-
const step = (0,
|
|
576
|
+
const step = (0, _prostojs_wf.createStep)(id, opts);
|
|
600
577
|
return this.on("WF_STEP", id, () => step);
|
|
601
578
|
}
|
|
602
579
|
/** Registers a workflow flow schema with the given id. */
|
|
@@ -642,19 +619,16 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
642
619
|
async _start(schemaId, inputContext, indexes, opts, parentCtx) {
|
|
643
620
|
const { input, spy, cleanup } = opts ?? {};
|
|
644
621
|
const resume = !!indexes?.length;
|
|
645
|
-
|
|
646
|
-
const ctxOptions = parentCtx ? {
|
|
622
|
+
return (resume ? resumeWfContext : createWfContext)(parentCtx ? {
|
|
647
623
|
...this.eventContextOptions,
|
|
648
624
|
parent: parentCtx
|
|
649
|
-
} : this.eventContextOptions
|
|
650
|
-
const seeds = {
|
|
625
|
+
} : this.eventContextOptions, {
|
|
651
626
|
inputContext,
|
|
652
627
|
schemaId,
|
|
653
628
|
stepId: null,
|
|
654
629
|
indexes,
|
|
655
630
|
input
|
|
656
|
-
}
|
|
657
|
-
return factory(ctxOptions, seeds, async () => {
|
|
631
|
+
}, async () => {
|
|
658
632
|
const { handlers: foundHandlers } = this.wooks.lookup("WF_FLOW", `/${schemaId}`.replace(/^\/+/u, "/"));
|
|
659
633
|
const handlers = foundHandlers || this.opts?.onNotFound && [this.opts.onNotFound] || null;
|
|
660
634
|
if (handlers && handlers.length > 0) {
|
|
@@ -664,8 +638,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
664
638
|
if (spy) spy(...args);
|
|
665
639
|
if (firstStep && args[0] === "step") {
|
|
666
640
|
firstStep = false;
|
|
667
|
-
|
|
668
|
-
ctx.set(wfKind.keys.input, void 0);
|
|
641
|
+
(0, _wooksjs_event_core.current)().set(wfKind.keys.input, void 0);
|
|
669
642
|
}
|
|
670
643
|
};
|
|
671
644
|
try {
|
|
@@ -728,8 +701,8 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
728
701
|
* await app.start('my-flow', { data: 'hello' })
|
|
729
702
|
* ```
|
|
730
703
|
*/
|
|
731
|
-
function createWfApp(opts, wooks$
|
|
732
|
-
return new WooksWf(opts, wooks$
|
|
704
|
+
function createWfApp(opts, wooks$2) {
|
|
705
|
+
return new WooksWf(opts, wooks$2);
|
|
733
706
|
}
|
|
734
707
|
|
|
735
708
|
//#endregion
|
|
@@ -738,7 +711,7 @@ exports.HandleStateStrategy = HandleStateStrategy;
|
|
|
738
711
|
Object.defineProperty(exports, 'StepRetriableError', {
|
|
739
712
|
enumerable: true,
|
|
740
713
|
get: function () {
|
|
741
|
-
return
|
|
714
|
+
return _prostojs_wf.StepRetriableError;
|
|
742
715
|
}
|
|
743
716
|
});
|
|
744
717
|
exports.WfStateStoreMemory = WfStateStoreMemory;
|
|
@@ -757,13 +730,13 @@ exports.resumeWfContext = resumeWfContext;
|
|
|
757
730
|
Object.defineProperty(exports, 'useLogger', {
|
|
758
731
|
enumerable: true,
|
|
759
732
|
get: function () {
|
|
760
|
-
return
|
|
733
|
+
return _wooksjs_event_core.useLogger;
|
|
761
734
|
}
|
|
762
735
|
});
|
|
763
736
|
Object.defineProperty(exports, 'useRouteParams', {
|
|
764
737
|
enumerable: true,
|
|
765
738
|
get: function () {
|
|
766
|
-
return
|
|
739
|
+
return _wooksjs_event_core.useRouteParams;
|
|
767
740
|
}
|
|
768
741
|
});
|
|
769
742
|
exports.useWfFinished = useWfFinished;
|
package/dist/index.mjs
CHANGED
|
@@ -149,10 +149,10 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
149
149
|
const strategy = resolveStrategy(wfid ?? "");
|
|
150
150
|
ctx.set(stateStrategyKey, strategy);
|
|
151
151
|
const state = await strategy.consume(token);
|
|
152
|
-
if (!state)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
152
|
+
if (!state) {
|
|
153
|
+
response.setStatus(410);
|
|
154
|
+
return { error: "Invalid or expired workflow state" };
|
|
155
|
+
}
|
|
156
156
|
if (state.schemaId !== (wfid ?? "")) {
|
|
157
157
|
const realStrategy = resolveStrategy(state.schemaId);
|
|
158
158
|
ctx.set(stateStrategyKey, realStrategy);
|
|
@@ -162,14 +162,14 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
162
162
|
eventContext: ctx
|
|
163
163
|
});
|
|
164
164
|
} else if (wfid) {
|
|
165
|
-
if (config.allow?.length && !config.allow.includes(wfid))
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
if (config.block?.includes(wfid))
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
165
|
+
if (config.allow?.length && !config.allow.includes(wfid)) {
|
|
166
|
+
response.setStatus(403);
|
|
167
|
+
return { error: `Workflow '${wfid}' is not allowed` };
|
|
168
|
+
}
|
|
169
|
+
if (config.block?.includes(wfid)) {
|
|
170
|
+
response.setStatus(403);
|
|
171
|
+
return { error: `Workflow '${wfid}' is blocked` };
|
|
172
|
+
}
|
|
173
173
|
const strategy = resolveStrategy(wfid);
|
|
174
174
|
ctx.set(stateStrategyKey, strategy);
|
|
175
175
|
const initialContext = config.initialContext ? config.initialContext(body, wfid) : {};
|
|
@@ -177,10 +177,10 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
177
177
|
input,
|
|
178
178
|
eventContext: ctx
|
|
179
179
|
});
|
|
180
|
-
} else
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
180
|
+
} else {
|
|
181
|
+
response.setStatus(400);
|
|
182
|
+
return { error: "Missing wfs (state token) or wfid (workflow ID)" };
|
|
183
|
+
}
|
|
184
184
|
if (output.finished) {
|
|
185
185
|
if (config.onFinished) return config.onFinished({
|
|
186
186
|
context: output.state.context,
|
|
@@ -189,19 +189,23 @@ async function handleWfOutletRequest(config, deps) {
|
|
|
189
189
|
const finished = ctx.get(wfFinishedKey);
|
|
190
190
|
if (finished?.cookies) for (const [name, cookie] of Object.entries(finished.cookies)) response.setCookie(name, cookie.value, cookie.options);
|
|
191
191
|
if (finished?.type === "redirect") {
|
|
192
|
+
response.setStatus(finished.status ?? 302);
|
|
192
193
|
response.setHeader("location", finished.value);
|
|
193
|
-
return
|
|
194
|
+
return "";
|
|
195
|
+
}
|
|
196
|
+
if (finished) {
|
|
197
|
+
if (finished.status) response.setStatus(finished.status);
|
|
198
|
+
return finished.value;
|
|
194
199
|
}
|
|
195
|
-
if (finished) return finished.value;
|
|
196
200
|
return { finished: true };
|
|
197
201
|
}
|
|
198
202
|
if (output.inputRequired) {
|
|
199
203
|
const outletReq = output.inputRequired;
|
|
200
204
|
const outletHandler = registry.get(outletReq.outlet);
|
|
201
|
-
if (!outletHandler)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
+
if (!outletHandler) {
|
|
206
|
+
response.setStatus(500);
|
|
207
|
+
return { error: `Unknown outlet: '${outletReq.outlet}'` };
|
|
208
|
+
}
|
|
205
209
|
const strategy = ctx.get(stateStrategyKey);
|
|
206
210
|
const stateWithMeta = {
|
|
207
211
|
...output.state,
|
|
@@ -247,11 +251,10 @@ function createHttpOutlet(opts) {
|
|
|
247
251
|
name: "http",
|
|
248
252
|
tokenDelivery: "caller",
|
|
249
253
|
async deliver(request, _token) {
|
|
250
|
-
|
|
254
|
+
return { response: opts?.transform ? opts.transform(request.payload, request.context) : typeof request.payload === "object" && request.payload !== null ? {
|
|
251
255
|
...request.payload,
|
|
252
256
|
...request.context
|
|
253
|
-
} : request.payload;
|
|
254
|
-
return { response: body };
|
|
257
|
+
} : request.payload };
|
|
255
258
|
}
|
|
256
259
|
};
|
|
257
260
|
}
|
|
@@ -536,8 +539,7 @@ var WooksWorkflow = class extends Workflow {
|
|
|
536
539
|
return found.handlers[0]();
|
|
537
540
|
}
|
|
538
541
|
} catch {
|
|
539
|
-
const
|
|
540
|
-
const found = router.lookup("WF_STEP", stepIdNorm);
|
|
542
|
+
const found = this.wooks.getRouter().lookup("WF_STEP", stepIdNorm);
|
|
541
543
|
if (found?.route?.handlers.length) return found.route.handlers[0]();
|
|
542
544
|
}
|
|
543
545
|
throw new Error(`Step "${stepIdNorm}" not found.`);
|
|
@@ -553,9 +555,6 @@ const wfShortcuts = {
|
|
|
553
555
|
};
|
|
554
556
|
/** Wooks adapter for defining and executing workflow schemas with step-based routing. */
|
|
555
557
|
var WooksWf = class extends WooksAdapterBase {
|
|
556
|
-
logger;
|
|
557
|
-
wf;
|
|
558
|
-
eventContextOptions;
|
|
559
558
|
constructor(opts, wooks) {
|
|
560
559
|
super(wooks, opts?.logger, opts?.router);
|
|
561
560
|
this.opts = opts;
|
|
@@ -619,19 +618,16 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
619
618
|
async _start(schemaId, inputContext, indexes, opts, parentCtx) {
|
|
620
619
|
const { input, spy, cleanup } = opts ?? {};
|
|
621
620
|
const resume = !!indexes?.length;
|
|
622
|
-
|
|
623
|
-
const ctxOptions = parentCtx ? {
|
|
621
|
+
return (resume ? resumeWfContext : createWfContext)(parentCtx ? {
|
|
624
622
|
...this.eventContextOptions,
|
|
625
623
|
parent: parentCtx
|
|
626
|
-
} : this.eventContextOptions
|
|
627
|
-
const seeds = {
|
|
624
|
+
} : this.eventContextOptions, {
|
|
628
625
|
inputContext,
|
|
629
626
|
schemaId,
|
|
630
627
|
stepId: null,
|
|
631
628
|
indexes,
|
|
632
629
|
input
|
|
633
|
-
}
|
|
634
|
-
return factory(ctxOptions, seeds, async () => {
|
|
630
|
+
}, async () => {
|
|
635
631
|
const { handlers: foundHandlers } = this.wooks.lookup("WF_FLOW", `/${schemaId}`.replace(/^\/+/u, "/"));
|
|
636
632
|
const handlers = foundHandlers || this.opts?.onNotFound && [this.opts.onNotFound] || null;
|
|
637
633
|
if (handlers && handlers.length > 0) {
|
|
@@ -641,8 +637,7 @@ var WooksWf = class extends WooksAdapterBase {
|
|
|
641
637
|
if (spy) spy(...args);
|
|
642
638
|
if (firstStep && args[0] === "step") {
|
|
643
639
|
firstStep = false;
|
|
644
|
-
|
|
645
|
-
ctx.set(wfKind.keys.input, void 0);
|
|
640
|
+
current().set(wfKind.keys.input, void 0);
|
|
646
641
|
}
|
|
647
642
|
};
|
|
648
643
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-wf",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"description": "@wooksjs/event-wf",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^3.2.4",
|
|
45
|
-
"@wooksjs/event-
|
|
46
|
-
"@wooksjs/event-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
45
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
46
|
+
"@wooksjs/event-http": "^0.7.12",
|
|
47
|
+
"@wooksjs/http-body": "^0.7.12",
|
|
48
|
+
"wooks": "^0.7.12"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@prostojs/logger": "^0.4.3",
|
|
52
|
-
"@wooksjs/event-core": "^0.7.
|
|
53
|
-
"@wooksjs/
|
|
54
|
-
"
|
|
55
|
-
"
|
|
52
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
53
|
+
"@wooksjs/http-body": "^0.7.12",
|
|
54
|
+
"wooks": "^0.7.12",
|
|
55
|
+
"@wooksjs/event-http": "^0.7.12"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@wooksjs/event-http": {
|