@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.d.cts
CHANGED
|
@@ -199,8 +199,12 @@ declare class DashboardService {
|
|
|
199
199
|
}) | null>;
|
|
200
200
|
/**
|
|
201
201
|
* Deliver a `ctx.webhook()` callback: turn an inbound POST (token + body) into the signal the
|
|
202
|
-
*
|
|
203
|
-
*
|
|
202
|
+
* run is (or will be) parked on. A callback that arrives BEFORE the run reaches `wait()` (the url
|
|
203
|
+
* was handed out and the run is still busy or sleeping) is buffered, and `wait()` consumes it, so
|
|
204
|
+
* the result is the run's current status. Returns `null` — mapped to 404 by the controller — for a
|
|
205
|
+
* token that is not a webhook token, whose run doesn't exist or is terminal, or whose wait already
|
|
206
|
+
* resolved (a duplicate): nothing is buffered for those, so a public endpoint can't leave junk
|
|
207
|
+
* rows behind or signal non-webhook tokens. Control-plane-only.
|
|
204
208
|
*/
|
|
205
209
|
deliverWebhook(token: string, body: unknown): Promise<RunResult | null>;
|
|
206
210
|
/** Side-effect-free read of a value a run published via `ctx.setEvent` (a live query). Control-plane-only. */
|
package/dist/server/index.d.ts
CHANGED
|
@@ -199,8 +199,12 @@ declare class DashboardService {
|
|
|
199
199
|
}) | null>;
|
|
200
200
|
/**
|
|
201
201
|
* Deliver a `ctx.webhook()` callback: turn an inbound POST (token + body) into the signal the
|
|
202
|
-
*
|
|
203
|
-
*
|
|
202
|
+
* run is (or will be) parked on. A callback that arrives BEFORE the run reaches `wait()` (the url
|
|
203
|
+
* was handed out and the run is still busy or sleeping) is buffered, and `wait()` consumes it, so
|
|
204
|
+
* the result is the run's current status. Returns `null` — mapped to 404 by the controller — for a
|
|
205
|
+
* token that is not a webhook token, whose run doesn't exist or is terminal, or whose wait already
|
|
206
|
+
* resolved (a duplicate): nothing is buffered for those, so a public endpoint can't leave junk
|
|
207
|
+
* rows behind or signal non-webhook tokens. Control-plane-only.
|
|
204
208
|
*/
|
|
205
209
|
deliverWebhook(token: string, body: unknown): Promise<RunResult | null>;
|
|
206
210
|
/** Side-effect-free read of a value a run published via `ctx.setEvent` (a live query). Control-plane-only. */
|
package/dist/server/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/server/dashboard.service.ts
|
|
5
|
-
import { RunGateway, STATE_STORE_CANONICAL, WorkflowEngine, collectMetrics } from "@dudousxd/nestjs-durable-core";
|
|
5
|
+
import { RunGateway, STATE_STORE_CANONICAL, TERMINAL_RUN_STATUSES, WorkflowEngine, collectMetrics, parseWebhookToken } from "@dudousxd/nestjs-durable-core";
|
|
6
6
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
7
7
|
import { Observable } from "rxjs";
|
|
8
8
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -211,11 +211,30 @@ var DashboardService = class {
|
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
213
|
* Deliver a `ctx.webhook()` callback: turn an inbound POST (token + body) into the signal the
|
|
214
|
-
*
|
|
215
|
-
*
|
|
214
|
+
* run is (or will be) parked on. A callback that arrives BEFORE the run reaches `wait()` (the url
|
|
215
|
+
* was handed out and the run is still busy or sleeping) is buffered, and `wait()` consumes it, so
|
|
216
|
+
* the result is the run's current status. Returns `null` — mapped to 404 by the controller — for a
|
|
217
|
+
* token that is not a webhook token, whose run doesn't exist or is terminal, or whose wait already
|
|
218
|
+
* resolved (a duplicate): nothing is buffered for those, so a public endpoint can't leave junk
|
|
219
|
+
* rows behind or signal non-webhook tokens. Control-plane-only.
|
|
216
220
|
*/
|
|
217
221
|
async deliverWebhook(token, body) {
|
|
218
|
-
|
|
222
|
+
const { store, engine } = this.controlPlane();
|
|
223
|
+
const parsed = parseWebhookToken(token);
|
|
224
|
+
if (!parsed) return null;
|
|
225
|
+
const run = await store.getRun(parsed.runId);
|
|
226
|
+
if (!run || TERMINAL_RUN_STATUSES.includes(run.status)) return null;
|
|
227
|
+
const resolved = await store.getCheckpoint(parsed.runId, parsed.seq);
|
|
228
|
+
if (resolved?.status === "completed") return null;
|
|
229
|
+
const delivered = await engine.signal(token, body);
|
|
230
|
+
if (delivered) return delivered;
|
|
231
|
+
const now = await store.getCheckpoint(parsed.runId, parsed.seq);
|
|
232
|
+
if (now?.status === "completed" && await store.takeBufferedSignal(token)) return null;
|
|
233
|
+
const fresh = await store.getRun(parsed.runId);
|
|
234
|
+
return {
|
|
235
|
+
runId: run.id,
|
|
236
|
+
status: fresh?.status ?? run.status
|
|
237
|
+
};
|
|
219
238
|
}
|
|
220
239
|
/** Side-effect-free read of a value a run published via `ctx.setEvent` (a live query). Control-plane-only. */
|
|
221
240
|
async getEvent(runId, key) {
|
|
@@ -1277,7 +1296,7 @@ var DurableApiController = class {
|
|
|
1277
1296
|
*/
|
|
1278
1297
|
async webhook(token, body) {
|
|
1279
1298
|
const result = await this.dashboard.deliverWebhook(token, body);
|
|
1280
|
-
if (!result) throw new NotFoundException(`no run is waiting
|
|
1299
|
+
if (!result) throw new NotFoundException(`no live run is waiting for webhook ${token}`);
|
|
1281
1300
|
return result;
|
|
1282
1301
|
}
|
|
1283
1302
|
/** Live query: the latest value a run published for `key` via `ctx.setEvent` (no side effect). */
|