@wooksjs/event-wf 0.7.10 → 0.7.11

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 CHANGED
@@ -172,10 +172,10 @@ async function handleWfOutletRequest(config, deps) {
172
172
  const strategy = resolveStrategy(wfid ?? "");
173
173
  ctx.set(stateStrategyKey, strategy);
174
174
  const state = await strategy.consume(token);
175
- if (!state) return {
176
- error: "Invalid or expired workflow state",
177
- status: 400
178
- };
175
+ if (!state) {
176
+ response.setStatus(410);
177
+ return { error: "Invalid or expired workflow state" };
178
+ }
179
179
  if (state.schemaId !== (wfid ?? "")) {
180
180
  const realStrategy = resolveStrategy(state.schemaId);
181
181
  ctx.set(stateStrategyKey, realStrategy);
@@ -185,14 +185,14 @@ async function handleWfOutletRequest(config, deps) {
185
185
  eventContext: ctx
186
186
  });
187
187
  } else if (wfid) {
188
- if (config.allow?.length && !config.allow.includes(wfid)) return {
189
- error: `Workflow '${wfid}' is not allowed`,
190
- status: 403
191
- };
192
- if (config.block?.includes(wfid)) return {
193
- error: `Workflow '${wfid}' is blocked`,
194
- status: 403
195
- };
188
+ if (config.allow?.length && !config.allow.includes(wfid)) {
189
+ response.setStatus(403);
190
+ return { error: `Workflow '${wfid}' is not allowed` };
191
+ }
192
+ if (config.block?.includes(wfid)) {
193
+ response.setStatus(403);
194
+ return { error: `Workflow '${wfid}' is blocked` };
195
+ }
196
196
  const strategy = resolveStrategy(wfid);
197
197
  ctx.set(stateStrategyKey, strategy);
198
198
  const initialContext = config.initialContext ? config.initialContext(body, wfid) : {};
@@ -200,10 +200,10 @@ async function handleWfOutletRequest(config, deps) {
200
200
  input,
201
201
  eventContext: ctx
202
202
  });
203
- } else return {
204
- error: "Missing wfs (state token) or wfid (workflow ID)",
205
- status: 400
206
- };
203
+ } else {
204
+ response.setStatus(400);
205
+ return { error: "Missing wfs (state token) or wfid (workflow ID)" };
206
+ }
207
207
  if (output.finished) {
208
208
  if (config.onFinished) return config.onFinished({
209
209
  context: output.state.context,
@@ -212,19 +212,23 @@ async function handleWfOutletRequest(config, deps) {
212
212
  const finished = ctx.get(wfFinishedKey);
213
213
  if (finished?.cookies) for (const [name, cookie] of Object.entries(finished.cookies)) response.setCookie(name, cookie.value, cookie.options);
214
214
  if (finished?.type === "redirect") {
215
+ response.setStatus(finished.status ?? 302);
215
216
  response.setHeader("location", finished.value);
216
- return { status: finished.status ?? 302 };
217
+ return "";
218
+ }
219
+ if (finished) {
220
+ if (finished.status) response.setStatus(finished.status);
221
+ return finished.value;
217
222
  }
218
- if (finished) return finished.value;
219
223
  return { finished: true };
220
224
  }
221
225
  if (output.inputRequired) {
222
226
  const outletReq = output.inputRequired;
223
227
  const outletHandler = registry.get(outletReq.outlet);
224
- if (!outletHandler) return {
225
- error: `Unknown outlet: '${outletReq.outlet}'`,
226
- status: 500
227
- };
228
+ if (!outletHandler) {
229
+ response.setStatus(500);
230
+ return { error: `Unknown outlet: '${outletReq.outlet}'` };
231
+ }
228
232
  const strategy = ctx.get(stateStrategyKey);
229
233
  const stateWithMeta = {
230
234
  ...output.state,
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) return {
153
- error: "Invalid or expired workflow state",
154
- status: 400
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)) return {
166
- error: `Workflow '${wfid}' is not allowed`,
167
- status: 403
168
- };
169
- if (config.block?.includes(wfid)) return {
170
- error: `Workflow '${wfid}' is blocked`,
171
- status: 403
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 return {
181
- error: "Missing wfs (state token) or wfid (workflow ID)",
182
- status: 400
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 { status: finished.status ?? 302 };
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) return {
202
- error: `Unknown outlet: '${outletReq.outlet}'`,
203
- status: 500
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-wf",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
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-http": "^0.7.10",
46
- "@wooksjs/event-core": "^0.7.10",
47
- "wooks": "^0.7.10",
48
- "@wooksjs/http-body": "^0.7.10"
45
+ "@wooksjs/event-core": "^0.7.11",
46
+ "@wooksjs/event-http": "^0.7.11",
47
+ "@wooksjs/http-body": "^0.7.11",
48
+ "wooks": "^0.7.11"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@prostojs/logger": "^0.4.3",
52
- "@wooksjs/event-core": "^0.7.10",
53
- "@wooksjs/event-http": "^0.7.10",
54
- "@wooksjs/http-body": "^0.7.10",
55
- "wooks": "^0.7.10"
52
+ "@wooksjs/event-core": "^0.7.11",
53
+ "@wooksjs/event-http": "^0.7.11",
54
+ "@wooksjs/http-body": "^0.7.11",
55
+ "wooks": "^0.7.11"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "@wooksjs/event-http": {