@dudousxd/nestjs-durable-dashboard 0.51.0 → 0.51.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/server/index.cjs
CHANGED
|
@@ -245,11 +245,30 @@ var DashboardService = class {
|
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
247
|
* Deliver a `ctx.webhook()` callback: turn an inbound POST (token + body) into the signal the
|
|
248
|
-
*
|
|
249
|
-
*
|
|
248
|
+
* run is (or will be) parked on. A callback that arrives BEFORE the run reaches `wait()` (the url
|
|
249
|
+
* was handed out and the run is still busy or sleeping) is buffered, and `wait()` consumes it, so
|
|
250
|
+
* the result is the run's current status. Returns `null` — mapped to 404 by the controller — for a
|
|
251
|
+
* token that is not a webhook token, whose run doesn't exist or is terminal, or whose wait already
|
|
252
|
+
* resolved (a duplicate): nothing is buffered for those, so a public endpoint can't leave junk
|
|
253
|
+
* rows behind or signal non-webhook tokens. Control-plane-only.
|
|
250
254
|
*/
|
|
251
255
|
async deliverWebhook(token, body) {
|
|
252
|
-
|
|
256
|
+
const { store, engine } = this.controlPlane();
|
|
257
|
+
const parsed = (0, import_nestjs_durable_core.parseWebhookToken)(token);
|
|
258
|
+
if (!parsed) return null;
|
|
259
|
+
const run = await store.getRun(parsed.runId);
|
|
260
|
+
if (!run || import_nestjs_durable_core.TERMINAL_RUN_STATUSES.includes(run.status)) return null;
|
|
261
|
+
const resolved = await store.getCheckpoint(parsed.runId, parsed.seq);
|
|
262
|
+
if (resolved?.status === "completed") return null;
|
|
263
|
+
const delivered = await engine.signal(token, body);
|
|
264
|
+
if (delivered) return delivered;
|
|
265
|
+
const now = await store.getCheckpoint(parsed.runId, parsed.seq);
|
|
266
|
+
if (now?.status === "completed" && await store.takeBufferedSignal(token)) return null;
|
|
267
|
+
const fresh = await store.getRun(parsed.runId);
|
|
268
|
+
return {
|
|
269
|
+
runId: run.id,
|
|
270
|
+
status: fresh?.status ?? run.status
|
|
271
|
+
};
|
|
253
272
|
}
|
|
254
273
|
/** Side-effect-free read of a value a run published via `ctx.setEvent` (a live query). Control-plane-only. */
|
|
255
274
|
async getEvent(runId, key) {
|
|
@@ -1311,7 +1330,7 @@ var DurableApiController = class {
|
|
|
1311
1330
|
*/
|
|
1312
1331
|
async webhook(token, body) {
|
|
1313
1332
|
const result = await this.dashboard.deliverWebhook(token, body);
|
|
1314
|
-
if (!result) throw new import_common5.NotFoundException(`no run is waiting
|
|
1333
|
+
if (!result) throw new import_common5.NotFoundException(`no live run is waiting for webhook ${token}`);
|
|
1315
1334
|
return result;
|
|
1316
1335
|
}
|
|
1317
1336
|
/** Live query: the latest value a run published for `key` via `ctx.setEvent` (no side effect). */
|