@moostjs/event-wf 0.6.53 → 0.7.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/index.cjs +95 -17
- package/dist/index.d.ts +37 -4
- package/dist/index.mjs +79 -19
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,45 @@ function getWfMate() {
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region packages/event-wf/src/run-scope.ts
|
|
107
|
+
/** Marks a `WooksWf` whose runs release their moost DI scope (see {@link releaseRunScopes}). */ const RUN_SCOPES_RELEASED = Symbol.for("moost-wf.run-scopes-released");
|
|
108
|
+
/** Marks the cleanup that releases a run's scope, so a resumed run does not wrap it twice. */ const RUN_SCOPE_CLEANUP = Symbol.for("moost-wf.run-scope-cleanup");
|
|
109
|
+
/** Run options whose `cleanup` also releases the run's moost DI scope (when the run ends). */ function withRunScopeCleanup(opts) {
|
|
110
|
+
const own = opts?.cleanup;
|
|
111
|
+
if (own?.[RUN_SCOPE_CLEANUP]) return opts;
|
|
112
|
+
const cleanup = () => {
|
|
113
|
+
try {
|
|
114
|
+
own?.();
|
|
115
|
+
} finally {
|
|
116
|
+
(0, moost.getMoostInfact)().unregisterScope((0, moost.useScopeId)());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
cleanup[RUN_SCOPE_CLEANUP] = true;
|
|
120
|
+
return {
|
|
121
|
+
...opts,
|
|
122
|
+
cleanup
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Makes every run of `wfApp` release its moost DI scope when it ends — whoever starts it:
|
|
127
|
+
* `MoostWf.start()`, `getWfApp().start()`, an outlet trigger or `mintWfToken()`. Step handlers
|
|
128
|
+
* keep the run's scope (`FOR_EVENT` instances) alive across steps, so the run end releases it.
|
|
129
|
+
* Replaces the instance's `start`/`resume`: anything that captured them before (e.g. a
|
|
130
|
+
* `createOutletHandler(wooksWf)` made before `new MoostWf(wooksWf)`) bypasses the release.
|
|
131
|
+
*/ function releaseRunScopes(wfApp) {
|
|
132
|
+
const app = wfApp;
|
|
133
|
+
if (app[RUN_SCOPES_RELEASED]) return;
|
|
134
|
+
app[RUN_SCOPES_RELEASED] = true;
|
|
135
|
+
const { start, resume } = app;
|
|
136
|
+
app.start = function(schemaId, context, opts) {
|
|
137
|
+
return start.call(this, schemaId, context, withRunScopeCleanup(opts));
|
|
138
|
+
};
|
|
139
|
+
app.resume = function(state, opts) {
|
|
140
|
+
return resume.call(this, state, withRunScopeCleanup(opts));
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
105
144
|
//#endregion
|
|
106
145
|
//#region packages/event-wf/src/event-wf.ts
|
|
107
146
|
function _define_property(obj, key, value) {
|
|
@@ -160,17 +199,47 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
160
199
|
*
|
|
161
200
|
* Reads `wfid` (workflow ID) and `wfs` (state token) from the HTTP request,
|
|
162
201
|
* starts or resumes the workflow, and dispatches pauses to registered outlets.
|
|
202
|
+
* `allow`/`block` are judged on the registered flow id the request resolves to
|
|
203
|
+
* (see {@link MoostWf.resolveSchemaId}).
|
|
163
204
|
*
|
|
164
205
|
* Must be called from within an HTTP event context (e.g. a `@Post` handler)
|
|
165
206
|
* so that wooks HTTP composables are available.
|
|
166
207
|
*
|
|
167
208
|
* @param config - Outlet trigger configuration (allowed workflows, state strategy, outlets, etc.)
|
|
168
|
-
* @returns The outlet result (form payload + token)
|
|
209
|
+
* @returns The outlet result (form payload + token) or the finished response. Refusals
|
|
210
|
+
* (missing/invalid/expired token, forbidden or unknown flow) are thrown as `HttpError`s
|
|
211
|
+
* with a `code` (`WF_MISSING`, `WF_INVALID_TOKEN`, `WF_EXPIRED`, `WF_FORBIDDEN`, …).
|
|
169
212
|
*/ handleOutlet(config) {
|
|
170
|
-
return (0, _wooksjs_event_wf.handleWfOutletRequest)(config,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
213
|
+
return (0, _wooksjs_event_wf.handleWfOutletRequest)(config, this);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Resolves a workflow id, spelled as a caller would pass it to `start()` (`'auth/login'`,
|
|
217
|
+
* `'/auth/login'`, `'user/42'`), to the id of the registered flow `start()` would run
|
|
218
|
+
* (`'/auth/login'`, `'/user/:id'`) — also what a paused run stores as `state.schemaId`.
|
|
219
|
+
* Returns `undefined` when no flow matches.
|
|
220
|
+
*
|
|
221
|
+
* @param id - Workflow id as a caller spells it.
|
|
222
|
+
* @param opts - `eventContext`: the parent event `start()` would get (e.g. the HTTP request).
|
|
223
|
+
*/ resolveSchemaId(id, opts) {
|
|
224
|
+
return this.wfApp.resolveSchemaId(id, opts);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Starts a workflow without a request and persists its first pause the way the outlet
|
|
228
|
+
* trigger does, returning a token the trigger resumes (`<strategy>.<handle>`) — for
|
|
229
|
+
* server-initiated flows: invites, approval links, scheduled reminders. No outlet is called:
|
|
230
|
+
* deliver the token yourself. `allow`/`block` are not checked here; they apply on resume.
|
|
231
|
+
* The run's DI scope is released when it pauses or ends.
|
|
232
|
+
*
|
|
233
|
+
* @param options - `wfid`, `context`, `input`, the trigger's `state` config, `ttl` (ms),
|
|
234
|
+
* `meta`, and an optional parent `eventContext`.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const { token } = await wf.mint({ wfid: 'invite', context: { email }, state, ttl: 7 * 86_400_000 })
|
|
239
|
+
* if (token) await sendInvite(email, `https://app.example/invite?wfs=${token}`)
|
|
240
|
+
* ```
|
|
241
|
+
*/ mint(options) {
|
|
242
|
+
return (0, _wooksjs_event_wf.mintWfToken)(this, options);
|
|
174
243
|
}
|
|
175
244
|
/**
|
|
176
245
|
* Starts a new workflow execution.
|
|
@@ -183,12 +252,7 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
183
252
|
* `input` value (legacy positional form) is no longer supported — wrap it
|
|
184
253
|
* in `{ input }`.
|
|
185
254
|
*/ start(schemaId, initialContext, opts) {
|
|
186
|
-
return this.wfApp.start(schemaId, initialContext,
|
|
187
|
-
...opts,
|
|
188
|
-
cleanup: () => {
|
|
189
|
-
(0, moost.getMoostInfact)().unregisterScope((0, moost.useScopeId)());
|
|
190
|
-
}
|
|
191
|
-
});
|
|
255
|
+
return this.wfApp.start(schemaId, initialContext, opts);
|
|
192
256
|
}
|
|
193
257
|
/**
|
|
194
258
|
* Resumes a previously paused workflow from a saved state.
|
|
@@ -198,12 +262,7 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
198
262
|
* for parent-chain composable access, and `strategy.name` for the strategy
|
|
199
263
|
* that loaded this state. Legacy positional `input` is no longer supported.
|
|
200
264
|
*/ resume(state, opts) {
|
|
201
|
-
return this.wfApp.resume(state,
|
|
202
|
-
...opts,
|
|
203
|
-
cleanup: () => {
|
|
204
|
-
(0, moost.getMoostInfact)().unregisterScope((0, moost.useScopeId)());
|
|
205
|
-
}
|
|
206
|
-
});
|
|
265
|
+
return this.wfApp.resume(state, opts);
|
|
207
266
|
}
|
|
208
267
|
bindHandler(opts) {
|
|
209
268
|
let fn;
|
|
@@ -274,6 +333,7 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
274
333
|
if (opts && opts instanceof _wooksjs_event_wf.WooksWf) this.wfApp = opts;
|
|
275
334
|
else if (opts) this.wfApp = (0, _wooksjs_event_wf.createWfApp)(opts);
|
|
276
335
|
else this.wfApp = (0, _wooksjs_event_wf.createWfApp)();
|
|
336
|
+
releaseRunScopes(this.wfApp);
|
|
277
337
|
}
|
|
278
338
|
};
|
|
279
339
|
/** Names this adapter for DI independently of class identity (see `MOOST_ADAPTER_BRAND`). */ _define_property(MoostWf, moost.MOOST_ADAPTER_BRAND, "@moostjs/event-wf/MoostWf");
|
|
@@ -300,6 +360,12 @@ Object.defineProperty(exports, 'StepRetriableError', {
|
|
|
300
360
|
}
|
|
301
361
|
});
|
|
302
362
|
exports.StepTTL = StepTTL;
|
|
363
|
+
Object.defineProperty(exports, 'WF_TRIGGER_ERRORS', {
|
|
364
|
+
enumerable: true,
|
|
365
|
+
get: function () {
|
|
366
|
+
return _wooksjs_event_wf.WF_TRIGGER_ERRORS;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
303
369
|
Object.defineProperty(exports, 'WfStateStoreMemory', {
|
|
304
370
|
enumerable: true,
|
|
305
371
|
get: function () {
|
|
@@ -333,6 +399,18 @@ Object.defineProperty(exports, 'handleWfOutletRequest', {
|
|
|
333
399
|
return _wooksjs_event_wf.handleWfOutletRequest;
|
|
334
400
|
}
|
|
335
401
|
});
|
|
402
|
+
Object.defineProperty(exports, 'mintWfToken', {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function () {
|
|
405
|
+
return _wooksjs_event_wf.mintWfToken;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
Object.defineProperty(exports, 'normalizeWfId', {
|
|
409
|
+
enumerable: true,
|
|
410
|
+
get: function () {
|
|
411
|
+
return _wooksjs_event_wf.normalizeWfId;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
336
414
|
Object.defineProperty(exports, 'outlet', {
|
|
337
415
|
enumerable: true,
|
|
338
416
|
get: function () {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TWorkflowSchema, TWorkflowSpy, TFlowOutput } from '@prostojs/wf';
|
|
2
2
|
export { StepRetriableError, TFlowOutput, TWorkflowSchema } from '@prostojs/wf';
|
|
3
|
-
import { WooksWf, TWooksWfOptions, WfOutletTriggerConfig, TWfRunOptions } from '@wooksjs/event-wf';
|
|
4
|
-
export { WfFinishedResponse, WfOutletTokenConfig, WfOutletTriggerConfig, WfOutletTriggerDeps, WfPauseRequest, createEmailOutlet, createHttpOutlet, createOutletHandler, handleWfOutletRequest, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfStrategy, wfKind } from '@wooksjs/event-wf';
|
|
5
|
-
import { TMoostAdapter, MOOST_ADAPTER_BRAND, Moost, TMoostAdapterOptions } from 'moost';
|
|
3
|
+
import { WooksWf, TWooksWfOptions, WfOutletTriggerConfig, WfMintTokenOptions, WfMintTokenResult, TWfRunOptions } from '@wooksjs/event-wf';
|
|
4
|
+
export { WF_TRIGGER_ERRORS, WfFinishedResponse, WfMintTokenOptions, WfMintTokenResult, WfOutletTokenConfig, WfOutletTriggerConfig, WfOutletTriggerDeps, WfPauseRequest, WfStartRunner, WfTriggerErrorBody, WfTriggerErrorCode, createEmailOutlet, createHttpOutlet, createOutletHandler, handleWfOutletRequest, mintWfToken, normalizeWfId, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfStrategy, wfKind } from '@wooksjs/event-wf';
|
|
5
|
+
import { TMoostAdapter, MOOST_ADAPTER_BRAND, Moost, EventContext, TMoostAdapterOptions } from 'moost';
|
|
6
6
|
export { EncapsulatedStateStrategy, HandleStateStrategy, WfOutlet, WfOutletRequest, WfOutletResult, WfState, WfStateStore, WfStateStoreMemory, WfStateStrategy, outlet, outletEmail, outletHttp } from '@prostojs/wf/outlets';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -117,14 +117,47 @@ declare class MoostWf<T = any, IR = any> implements TMoostAdapter<TWfHandlerMeta
|
|
|
117
117
|
*
|
|
118
118
|
* Reads `wfid` (workflow ID) and `wfs` (state token) from the HTTP request,
|
|
119
119
|
* starts or resumes the workflow, and dispatches pauses to registered outlets.
|
|
120
|
+
* `allow`/`block` are judged on the registered flow id the request resolves to
|
|
121
|
+
* (see {@link MoostWf.resolveSchemaId}).
|
|
120
122
|
*
|
|
121
123
|
* Must be called from within an HTTP event context (e.g. a `@Post` handler)
|
|
122
124
|
* so that wooks HTTP composables are available.
|
|
123
125
|
*
|
|
124
126
|
* @param config - Outlet trigger configuration (allowed workflows, state strategy, outlets, etc.)
|
|
125
|
-
* @returns The outlet result (form payload + token)
|
|
127
|
+
* @returns The outlet result (form payload + token) or the finished response. Refusals
|
|
128
|
+
* (missing/invalid/expired token, forbidden or unknown flow) are thrown as `HttpError`s
|
|
129
|
+
* with a `code` (`WF_MISSING`, `WF_INVALID_TOKEN`, `WF_EXPIRED`, `WF_FORBIDDEN`, …).
|
|
126
130
|
*/
|
|
127
131
|
handleOutlet(config: WfOutletTriggerConfig): Promise<unknown>;
|
|
132
|
+
/**
|
|
133
|
+
* Resolves a workflow id, spelled as a caller would pass it to `start()` (`'auth/login'`,
|
|
134
|
+
* `'/auth/login'`, `'user/42'`), to the id of the registered flow `start()` would run
|
|
135
|
+
* (`'/auth/login'`, `'/user/:id'`) — also what a paused run stores as `state.schemaId`.
|
|
136
|
+
* Returns `undefined` when no flow matches.
|
|
137
|
+
*
|
|
138
|
+
* @param id - Workflow id as a caller spells it.
|
|
139
|
+
* @param opts - `eventContext`: the parent event `start()` would get (e.g. the HTTP request).
|
|
140
|
+
*/
|
|
141
|
+
resolveSchemaId(id: string, opts?: {
|
|
142
|
+
eventContext?: EventContext;
|
|
143
|
+
}): Promise<string | undefined>;
|
|
144
|
+
/**
|
|
145
|
+
* Starts a workflow without a request and persists its first pause the way the outlet
|
|
146
|
+
* trigger does, returning a token the trigger resumes (`<strategy>.<handle>`) — for
|
|
147
|
+
* server-initiated flows: invites, approval links, scheduled reminders. No outlet is called:
|
|
148
|
+
* deliver the token yourself. `allow`/`block` are not checked here; they apply on resume.
|
|
149
|
+
* The run's DI scope is released when it pauses or ends.
|
|
150
|
+
*
|
|
151
|
+
* @param options - `wfid`, `context`, `input`, the trigger's `state` config, `ttl` (ms),
|
|
152
|
+
* `meta`, and an optional parent `eventContext`.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const { token } = await wf.mint({ wfid: 'invite', context: { email }, state, ttl: 7 * 86_400_000 })
|
|
157
|
+
* if (token) await sendInvite(email, `https://app.example/invite?wfs=${token}`)
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
mint(options: WfMintTokenOptions): Promise<WfMintTokenResult>;
|
|
128
161
|
/**
|
|
129
162
|
* Starts a new workflow execution.
|
|
130
163
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WooksWf, createEmailOutlet, createHttpOutlet, createOutletHandler, createWfApp, handleWfOutletRequest, handleWfOutletRequest as handleWfOutletRequest$1, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfState as useWfState$1, useWfStrategy, wfKind } from "@wooksjs/event-wf";
|
|
1
|
+
import { WF_TRIGGER_ERRORS, WooksWf, createEmailOutlet, createHttpOutlet, createOutletHandler, createWfApp, handleWfOutletRequest, handleWfOutletRequest as handleWfOutletRequest$1, mintWfToken, mintWfToken as mintWfToken$1, normalizeWfId, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfState as useWfState$1, useWfStrategy, wfKind } from "@wooksjs/event-wf";
|
|
2
2
|
import { MOOST_ADAPTER_BRAND, Resolve, defineMoostEventHandler, getMoostInfact, getMoostMate, setControllerContext, useScopeId } from "moost";
|
|
3
3
|
import { StepRetriableError } from "@prostojs/wf";
|
|
4
4
|
import { EncapsulatedStateStrategy, HandleStateStrategy, WfStateStoreMemory, outlet, outletEmail, outletHttp } from "@prostojs/wf/outlets";
|
|
@@ -101,6 +101,45 @@ function getWfMate() {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region packages/event-wf/src/run-scope.ts
|
|
106
|
+
/** Marks a `WooksWf` whose runs release their moost DI scope (see {@link releaseRunScopes}). */ const RUN_SCOPES_RELEASED = Symbol.for("moost-wf.run-scopes-released");
|
|
107
|
+
/** Marks the cleanup that releases a run's scope, so a resumed run does not wrap it twice. */ const RUN_SCOPE_CLEANUP = Symbol.for("moost-wf.run-scope-cleanup");
|
|
108
|
+
/** Run options whose `cleanup` also releases the run's moost DI scope (when the run ends). */ function withRunScopeCleanup(opts) {
|
|
109
|
+
const own = opts?.cleanup;
|
|
110
|
+
if (own?.[RUN_SCOPE_CLEANUP]) return opts;
|
|
111
|
+
const cleanup = () => {
|
|
112
|
+
try {
|
|
113
|
+
own?.();
|
|
114
|
+
} finally {
|
|
115
|
+
getMoostInfact().unregisterScope(useScopeId());
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
cleanup[RUN_SCOPE_CLEANUP] = true;
|
|
119
|
+
return {
|
|
120
|
+
...opts,
|
|
121
|
+
cleanup
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Makes every run of `wfApp` release its moost DI scope when it ends — whoever starts it:
|
|
126
|
+
* `MoostWf.start()`, `getWfApp().start()`, an outlet trigger or `mintWfToken()`. Step handlers
|
|
127
|
+
* keep the run's scope (`FOR_EVENT` instances) alive across steps, so the run end releases it.
|
|
128
|
+
* Replaces the instance's `start`/`resume`: anything that captured them before (e.g. a
|
|
129
|
+
* `createOutletHandler(wooksWf)` made before `new MoostWf(wooksWf)`) bypasses the release.
|
|
130
|
+
*/ function releaseRunScopes(wfApp) {
|
|
131
|
+
const app = wfApp;
|
|
132
|
+
if (app[RUN_SCOPES_RELEASED]) return;
|
|
133
|
+
app[RUN_SCOPES_RELEASED] = true;
|
|
134
|
+
const { start, resume } = app;
|
|
135
|
+
app.start = function(schemaId, context, opts) {
|
|
136
|
+
return start.call(this, schemaId, context, withRunScopeCleanup(opts));
|
|
137
|
+
};
|
|
138
|
+
app.resume = function(state, opts) {
|
|
139
|
+
return resume.call(this, state, withRunScopeCleanup(opts));
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
104
143
|
//#endregion
|
|
105
144
|
//#region packages/event-wf/src/event-wf.ts
|
|
106
145
|
function _define_property(obj, key, value) {
|
|
@@ -159,17 +198,47 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
159
198
|
*
|
|
160
199
|
* Reads `wfid` (workflow ID) and `wfs` (state token) from the HTTP request,
|
|
161
200
|
* starts or resumes the workflow, and dispatches pauses to registered outlets.
|
|
201
|
+
* `allow`/`block` are judged on the registered flow id the request resolves to
|
|
202
|
+
* (see {@link MoostWf.resolveSchemaId}).
|
|
162
203
|
*
|
|
163
204
|
* Must be called from within an HTTP event context (e.g. a `@Post` handler)
|
|
164
205
|
* so that wooks HTTP composables are available.
|
|
165
206
|
*
|
|
166
207
|
* @param config - Outlet trigger configuration (allowed workflows, state strategy, outlets, etc.)
|
|
167
|
-
* @returns The outlet result (form payload + token)
|
|
208
|
+
* @returns The outlet result (form payload + token) or the finished response. Refusals
|
|
209
|
+
* (missing/invalid/expired token, forbidden or unknown flow) are thrown as `HttpError`s
|
|
210
|
+
* with a `code` (`WF_MISSING`, `WF_INVALID_TOKEN`, `WF_EXPIRED`, `WF_FORBIDDEN`, …).
|
|
168
211
|
*/ handleOutlet(config) {
|
|
169
|
-
return handleWfOutletRequest$1(config,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
212
|
+
return handleWfOutletRequest$1(config, this);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Resolves a workflow id, spelled as a caller would pass it to `start()` (`'auth/login'`,
|
|
216
|
+
* `'/auth/login'`, `'user/42'`), to the id of the registered flow `start()` would run
|
|
217
|
+
* (`'/auth/login'`, `'/user/:id'`) — also what a paused run stores as `state.schemaId`.
|
|
218
|
+
* Returns `undefined` when no flow matches.
|
|
219
|
+
*
|
|
220
|
+
* @param id - Workflow id as a caller spells it.
|
|
221
|
+
* @param opts - `eventContext`: the parent event `start()` would get (e.g. the HTTP request).
|
|
222
|
+
*/ resolveSchemaId(id, opts) {
|
|
223
|
+
return this.wfApp.resolveSchemaId(id, opts);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Starts a workflow without a request and persists its first pause the way the outlet
|
|
227
|
+
* trigger does, returning a token the trigger resumes (`<strategy>.<handle>`) — for
|
|
228
|
+
* server-initiated flows: invites, approval links, scheduled reminders. No outlet is called:
|
|
229
|
+
* deliver the token yourself. `allow`/`block` are not checked here; they apply on resume.
|
|
230
|
+
* The run's DI scope is released when it pauses or ends.
|
|
231
|
+
*
|
|
232
|
+
* @param options - `wfid`, `context`, `input`, the trigger's `state` config, `ttl` (ms),
|
|
233
|
+
* `meta`, and an optional parent `eventContext`.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const { token } = await wf.mint({ wfid: 'invite', context: { email }, state, ttl: 7 * 86_400_000 })
|
|
238
|
+
* if (token) await sendInvite(email, `https://app.example/invite?wfs=${token}`)
|
|
239
|
+
* ```
|
|
240
|
+
*/ mint(options) {
|
|
241
|
+
return mintWfToken$1(this, options);
|
|
173
242
|
}
|
|
174
243
|
/**
|
|
175
244
|
* Starts a new workflow execution.
|
|
@@ -182,12 +251,7 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
182
251
|
* `input` value (legacy positional form) is no longer supported — wrap it
|
|
183
252
|
* in `{ input }`.
|
|
184
253
|
*/ start(schemaId, initialContext, opts) {
|
|
185
|
-
return this.wfApp.start(schemaId, initialContext,
|
|
186
|
-
...opts,
|
|
187
|
-
cleanup: () => {
|
|
188
|
-
getMoostInfact().unregisterScope(useScopeId());
|
|
189
|
-
}
|
|
190
|
-
});
|
|
254
|
+
return this.wfApp.start(schemaId, initialContext, opts);
|
|
191
255
|
}
|
|
192
256
|
/**
|
|
193
257
|
* Resumes a previously paused workflow from a saved state.
|
|
@@ -197,12 +261,7 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
197
261
|
* for parent-chain composable access, and `strategy.name` for the strategy
|
|
198
262
|
* that loaded this state. Legacy positional `input` is no longer supported.
|
|
199
263
|
*/ resume(state, opts) {
|
|
200
|
-
return this.wfApp.resume(state,
|
|
201
|
-
...opts,
|
|
202
|
-
cleanup: () => {
|
|
203
|
-
getMoostInfact().unregisterScope(useScopeId());
|
|
204
|
-
}
|
|
205
|
-
});
|
|
264
|
+
return this.wfApp.resume(state, opts);
|
|
206
265
|
}
|
|
207
266
|
bindHandler(opts) {
|
|
208
267
|
let fn;
|
|
@@ -273,9 +332,10 @@ const LOGGER_TITLE = "moost-wf";
|
|
|
273
332
|
if (opts && opts instanceof WooksWf) this.wfApp = opts;
|
|
274
333
|
else if (opts) this.wfApp = createWfApp(opts);
|
|
275
334
|
else this.wfApp = createWfApp();
|
|
335
|
+
releaseRunScopes(this.wfApp);
|
|
276
336
|
}
|
|
277
337
|
};
|
|
278
338
|
/** Names this adapter for DI independently of class identity (see `MOOST_ADAPTER_BRAND`). */ _define_property(MoostWf, MOOST_ADAPTER_BRAND, "@moostjs/event-wf/MoostWf");
|
|
279
339
|
|
|
280
340
|
//#endregion
|
|
281
|
-
export { EncapsulatedStateStrategy, HandleStateStrategy, MoostWf, Step, StepRetriableError, StepTTL, WfStateStoreMemory, Workflow, WorkflowParam, WorkflowSchema, createEmailOutlet, createHttpOutlet, createOutletHandler, handleWfOutletRequest, outlet, outletEmail, outletHttp, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfStrategy, wfKind };
|
|
341
|
+
export { EncapsulatedStateStrategy, HandleStateStrategy, MoostWf, Step, StepRetriableError, StepTTL, WF_TRIGGER_ERRORS, WfStateStoreMemory, Workflow, WorkflowParam, WorkflowSchema, createEmailOutlet, createHttpOutlet, createOutletHandler, handleWfOutletRequest, mintWfToken, normalizeWfId, outlet, outletEmail, outletHttp, swapStrategy, useWfFinished, useWfOutlet, useWfState, useWfStrategy, wfKind };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-wf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "@moostjs/event-wf",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"composables",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@prostojs/wf": "^0.
|
|
42
|
-
"@wooksjs/event-wf": "^0.
|
|
41
|
+
"@prostojs/wf": "^0.3.0",
|
|
42
|
+
"@wooksjs/event-wf": "^0.8.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"vitest": "
|
|
45
|
+
"vitest": "4.1.12"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@prostojs/infact": "^0.6.1",
|
|
49
49
|
"@prostojs/mate": "^0.5.1",
|
|
50
|
-
"@wooksjs/event-core": "^0.
|
|
51
|
-
"wooks": "^0.
|
|
52
|
-
"moost": "^0.
|
|
50
|
+
"@wooksjs/event-core": "^0.8.0",
|
|
51
|
+
"wooks": "^0.8.0",
|
|
52
|
+
"moost": "^0.7.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"pub": "pnpm publish --access public",
|