@proofoftech/flowsafe 0.3.0 → 0.6.0
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/CHANGELOG.md +336 -0
- package/dist/agent-runner/approval-shapes.d.ts +36 -0
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
- package/dist/agent-runner/approval-shapes.js +101 -0
- package/dist/agent-runner/approval-shapes.js.map +1 -0
- package/dist/agent-runner/durable-agent-runner.d.ts +154 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +291 -0
- package/dist/agent-runner/durable-agent-runner.js.map +1 -0
- package/dist/agent-runner/index.d.ts +3 -0
- package/dist/agent-runner/index.d.ts.map +1 -0
- package/dist/agent-runner/index.js +10 -0
- package/dist/agent-runner/index.js.map +1 -0
- package/dist/approval-api/contract.d.ts +29 -0
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +112 -18
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +8 -32
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +2 -2
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/router.d.ts +1 -1
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +1 -0
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +24 -3
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +116 -1
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +29 -6
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +62 -2
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +17 -1
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/tenant-store.js +8 -2
- package/dist/approval-api/tenant-store.js.map +1 -1
- package/dist/approval-api/types.d.ts +19 -0
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +16 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +9 -1
- package/dist/approval-ui/App.d.ts.map +1 -1
- package/dist/approval-ui/App.js +10 -5
- package/dist/approval-ui/App.js.map +1 -1
- package/dist/approval-ui/DetailView.d.ts +4 -1
- package/dist/approval-ui/DetailView.d.ts.map +1 -1
- package/dist/approval-ui/DetailView.js +2 -2
- package/dist/approval-ui/DetailView.js.map +1 -1
- package/dist/approval-ui/QueueView.d.ts +7 -1
- package/dist/approval-ui/QueueView.d.ts.map +1 -1
- package/dist/approval-ui/QueueView.js +8 -3
- package/dist/approval-ui/QueueView.js.map +1 -1
- package/dist/approval-ui/client.d.ts +19 -0
- package/dist/approval-ui/client.d.ts.map +1 -1
- package/dist/approval-ui/client.js +29 -1
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/components.d.ts +20 -0
- package/dist/approval-ui/components.d.ts.map +1 -1
- package/dist/approval-ui/components.js +2 -0
- package/dist/approval-ui/components.js.map +1 -1
- package/dist/approval-ui/index.d.ts +4 -2
- package/dist/approval-ui/index.d.ts.map +1 -1
- package/dist/approval-ui/index.js +3 -0
- package/dist/approval-ui/index.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +142 -0
- package/dist/approval-ui/stream.d.ts.map +1 -0
- package/dist/approval-ui/stream.js +136 -0
- package/dist/approval-ui/stream.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +74 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +307 -7
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +10 -0
- package/dist/approval-ui/use-web-socket-transport.d.ts.map +1 -0
- package/dist/approval-ui/use-web-socket-transport.js +46 -0
- package/dist/approval-ui/use-web-socket-transport.js.map +1 -0
- package/dist/background-tasks/d1-storage.d.ts +66 -0
- package/dist/background-tasks/d1-storage.d.ts.map +1 -0
- package/dist/background-tasks/d1-storage.js +196 -0
- package/dist/background-tasks/d1-storage.js.map +1 -0
- package/dist/background-tasks/host.d.ts +82 -0
- package/dist/background-tasks/host.d.ts.map +1 -0
- package/dist/background-tasks/host.js +275 -0
- package/dist/background-tasks/host.js.map +1 -0
- package/dist/background-tasks/index.d.ts +7 -0
- package/dist/background-tasks/index.d.ts.map +1 -0
- package/dist/background-tasks/index.js +10 -0
- package/dist/background-tasks/index.js.map +1 -0
- package/dist/background-tasks/routes.d.ts +15 -0
- package/dist/background-tasks/routes.d.ts.map +1 -0
- package/dist/background-tasks/routes.js +144 -0
- package/dist/background-tasks/routes.js.map +1 -0
- package/dist/do-runner/cf-types.d.ts +70 -2
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js +30 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +343 -2
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +566 -13
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +29 -0
- package/dist/do-runner/do-error-response.d.ts.map +1 -0
- package/dist/do-runner/do-error-response.js +73 -0
- package/dist/do-runner/do-error-response.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +5 -2
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +87 -20
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +55 -0
- package/dist/do-runner/hub-do.d.ts.map +1 -0
- package/dist/do-runner/hub-do.js +197 -0
- package/dist/do-runner/hub-do.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -4
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +9 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +20 -0
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +12 -1
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/path-safe-id.js +1 -1
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/pubsub.d.ts +18 -0
- package/dist/do-runner/pubsub.d.ts.map +1 -0
- package/dist/do-runner/pubsub.js +42 -0
- package/dist/do-runner/pubsub.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +24 -0
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +29 -2
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +74 -0
- package/dist/do-runner/thread-do.d.ts.map +1 -0
- package/dist/do-runner/thread-do.js +156 -0
- package/dist/do-runner/thread-do.js.map +1 -0
- package/dist/do-runner/thread-header.d.ts +16 -0
- package/dist/do-runner/thread-header.d.ts.map +1 -0
- package/dist/do-runner/thread-header.js +24 -0
- package/dist/do-runner/thread-header.js.map +1 -0
- package/dist/goals/index.d.ts +2 -0
- package/dist/goals/index.d.ts.map +1 -0
- package/dist/goals/index.js +7 -0
- package/dist/goals/index.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +87 -0
- package/dist/goals/objective-routes.d.ts.map +1 -0
- package/dist/goals/objective-routes.js +375 -0
- package/dist/goals/objective-routes.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +24 -4
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +32 -10
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +20 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +30 -0
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +134 -5
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +283 -47
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +20 -1
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +15 -0
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +35 -0
- package/dist/host-kit/hub-topology.d.ts.map +1 -0
- package/dist/host-kit/hub-topology.js +32 -0
- package/dist/host-kit/hub-topology.js.map +1 -0
- package/dist/host-kit/index.d.ts +8 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +10 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/memory-boundary.d.ts +64 -0
- package/dist/host-kit/memory-boundary.d.ts.map +1 -0
- package/dist/host-kit/memory-boundary.js +109 -0
- package/dist/host-kit/memory-boundary.js.map +1 -0
- package/dist/host-kit/route-path.d.ts +17 -0
- package/dist/host-kit/route-path.d.ts.map +1 -0
- package/dist/host-kit/route-path.js +35 -0
- package/dist/host-kit/route-path.js.map +1 -0
- package/dist/host-kit/stream-router.d.ts +22 -0
- package/dist/host-kit/stream-router.d.ts.map +1 -0
- package/dist/host-kit/stream-router.js +191 -0
- package/dist/host-kit/stream-router.js.map +1 -0
- package/dist/host-kit/stream-ticket.d.ts +55 -0
- package/dist/host-kit/stream-ticket.d.ts.map +1 -0
- package/dist/host-kit/stream-ticket.js +156 -0
- package/dist/host-kit/stream-ticket.js.map +1 -0
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/tenant-registry.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +44 -0
- package/dist/host-kit/thread-topology.d.ts.map +1 -0
- package/dist/host-kit/thread-topology.js +76 -0
- package/dist/host-kit/thread-topology.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal-error-response.d.ts +3 -0
- package/dist/internal-error-response.d.ts.map +1 -0
- package/dist/internal-error-response.js +20 -0
- package/dist/internal-error-response.js.map +1 -0
- package/dist/numeric-config.d.ts +4 -0
- package/dist/numeric-config.d.ts.map +1 -0
- package/dist/numeric-config.js +23 -0
- package/dist/numeric-config.js.map +1 -0
- package/dist/schedules/index.d.ts +5 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +13 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/schedules/router.d.ts +66 -0
- package/dist/schedules/router.d.ts.map +1 -0
- package/dist/schedules/router.js +827 -0
- package/dist/schedules/router.js.map +1 -0
- package/dist/schedules/schedules-d1.d.ts +30 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -0
- package/dist/schedules/schedules-d1.js +374 -0
- package/dist/schedules/schedules-d1.js.map +1 -0
- package/dist/schedules/storage.d.ts +11 -0
- package/dist/schedules/storage.d.ts.map +1 -0
- package/dist/schedules/storage.js +34 -0
- package/dist/schedules/storage.js.map +1 -0
- package/dist/schedules/tick.d.ts +131 -0
- package/dist/schedules/tick.d.ts.map +1 -0
- package/dist/schedules/tick.js +598 -0
- package/dist/schedules/tick.js.map +1 -0
- package/dist/signal-providers/delivery.d.ts +24 -0
- package/dist/signal-providers/delivery.d.ts.map +1 -0
- package/dist/signal-providers/delivery.js +62 -0
- package/dist/signal-providers/delivery.js.map +1 -0
- package/dist/signal-providers/github-provider.d.ts +33 -0
- package/dist/signal-providers/github-provider.d.ts.map +1 -0
- package/dist/signal-providers/github-provider.js +116 -0
- package/dist/signal-providers/github-provider.js.map +1 -0
- package/dist/signal-providers/host-do.d.ts +79 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +216 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/index.d.ts +7 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +19 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +92 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +87 -0
- package/dist/signal-providers/provider.js.map +1 -0
- package/dist/signal-providers/subscription-d1.d.ts +88 -0
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
- package/dist/signal-providers/subscription-d1.js +259 -0
- package/dist/signal-providers/subscription-d1.js.map +1 -0
- package/dist/signal-providers/webhook-route.d.ts +88 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +391 -0
- package/dist/signal-providers/webhook-route.js.map +1 -0
- package/dist/signals/client.d.ts +72 -0
- package/dist/signals/client.d.ts.map +1 -0
- package/dist/signals/client.js +87 -0
- package/dist/signals/client.js.map +1 -0
- package/dist/signals/d1-shared.d.ts +43 -0
- package/dist/signals/d1-shared.d.ts.map +1 -0
- package/dist/signals/d1-shared.js +46 -0
- package/dist/signals/d1-shared.js.map +1 -0
- package/dist/signals/index.d.ts +9 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +15 -0
- package/dist/signals/index.js.map +1 -0
- package/dist/signals/notification-dispatch.d.ts +52 -0
- package/dist/signals/notification-dispatch.d.ts.map +1 -0
- package/dist/signals/notification-dispatch.js +198 -0
- package/dist/signals/notification-dispatch.js.map +1 -0
- package/dist/signals/notifications-d1.d.ts +28 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +704 -0
- package/dist/signals/notifications-d1.js.map +1 -0
- package/dist/signals/router.d.ts +73 -0
- package/dist/signals/router.d.ts.map +1 -0
- package/dist/signals/router.js +240 -0
- package/dist/signals/router.js.map +1 -0
- package/dist/signals/storage.d.ts +11 -0
- package/dist/signals/storage.d.ts.map +1 -0
- package/dist/signals/storage.js +27 -0
- package/dist/signals/storage.js.map +1 -0
- package/dist/signals/thread-do-routes.d.ts +82 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -0
- package/dist/signals/thread-do-routes.js +660 -0
- package/dist/signals/thread-do-routes.js.map +1 -0
- package/dist/signals/thread-state-d1.d.ts +22 -0
- package/dist/signals/thread-state-d1.d.ts.map +1 -0
- package/dist/signals/thread-state-d1.js +83 -0
- package/dist/signals/thread-state-d1.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The stream surface every streaming host mounts (DL-010, DL-015, DL-009),
|
|
3
|
+
// mirroring createRunRouter's shape: plain fetch routing that returns `null` for
|
|
4
|
+
// paths outside its ownership so the composer can compose it, and `Response` for
|
|
5
|
+
// everything under `/api/stream/`. Because every route is namespaced under
|
|
6
|
+
// `/api/stream/`, the hosts' existing `/api/*` run_worker_first entry already
|
|
7
|
+
// routes them — no assets-block edit (DL-015).
|
|
8
|
+
//
|
|
9
|
+
// The Worker is the SOLE ticket-verification authority. The ticket route
|
|
10
|
+
// authenticates through the shared TenantResolver and mints a short-lived HMAC
|
|
11
|
+
// ticket; the two WebSocket-upgrade routes verify that ticket HERE and forward
|
|
12
|
+
// the raw upgrade to the addressed Durable Object, which re-binds the connection
|
|
13
|
+
// by its own idFromName identity (INV-1 for a run, id.name===tenantId for the
|
|
14
|
+
// hub). No grant ever crosses this surface — the ticket is ADDRESSING only.
|
|
15
|
+
//
|
|
16
|
+
// Ownership mirrors the run router: a run ticket for a run the tenant does not
|
|
17
|
+
// own gets 404 (not 403), so the route is never an existence oracle for another
|
|
18
|
+
// tenant's runIds.
|
|
19
|
+
import { TenantResolutionError, } from '../approval-api/index.js';
|
|
20
|
+
import { tenantOfRunId } from '../do-runner/path-safe-id.js';
|
|
21
|
+
import { createHubTopology } from './hub-topology.js';
|
|
22
|
+
import { mintStreamTicket, verifyStreamTicket } from './stream-ticket.js';
|
|
23
|
+
// A ticket is a short-lived credential; no-store keeps it out of shared caches.
|
|
24
|
+
function json(payload, status = 200) {
|
|
25
|
+
return new Response(JSON.stringify(payload), {
|
|
26
|
+
status,
|
|
27
|
+
headers: {
|
|
28
|
+
'content-type': 'application/json',
|
|
29
|
+
'cache-control': 'no-store',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function readJson(request) {
|
|
34
|
+
try {
|
|
35
|
+
return await request.json();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isWebSocketUpgrade(request) {
|
|
42
|
+
return request.headers.get('upgrade')?.toLowerCase() === 'websocket';
|
|
43
|
+
}
|
|
44
|
+
const TICKET_TTL_SECONDS = 60;
|
|
45
|
+
export function createStreamRouter(options) {
|
|
46
|
+
const { resolve, ticketSecret, hub, runner } = options;
|
|
47
|
+
const base = options.wsBaseUrl ?? '';
|
|
48
|
+
async function mintRoute(request) {
|
|
49
|
+
const tenant = await resolve(request);
|
|
50
|
+
if (!tenant)
|
|
51
|
+
return json({ error: 'authentication required' }, 401);
|
|
52
|
+
const body = (await readJson(request));
|
|
53
|
+
const channel = body?.channel;
|
|
54
|
+
if (channel !== 'hub' && channel !== 'run') {
|
|
55
|
+
return json({ error: "channel must be 'hub' or 'run'" }, 400);
|
|
56
|
+
}
|
|
57
|
+
let runId;
|
|
58
|
+
let url;
|
|
59
|
+
if (channel === 'run') {
|
|
60
|
+
if (typeof body?.runId !== 'string') {
|
|
61
|
+
return json({ error: 'runId is required for a run ticket' }, 400);
|
|
62
|
+
}
|
|
63
|
+
runId = body.runId;
|
|
64
|
+
// Ownership, not authorization: a run the tenant does not own is 404, not
|
|
65
|
+
// 403, so the ticket route is not an existence oracle (mirrors run-router).
|
|
66
|
+
if (!tenant.ownsRun(runId)) {
|
|
67
|
+
return json({ error: 'run not found' }, 404);
|
|
68
|
+
}
|
|
69
|
+
// The run WS path needs the workflowId (the DO is keyed `${wf}:${runId}`);
|
|
70
|
+
// the client, which drives the run, knows it. When supplied the returned
|
|
71
|
+
// url is complete; otherwise it carries the runId for the client to
|
|
72
|
+
// qualify. The ticket claims never carry the workflowId — the WS route
|
|
73
|
+
// takes it from the path and binds by claims.runId + tenantOfRunId.
|
|
74
|
+
const workflowId = typeof body.workflowId === 'string' ? body.workflowId : undefined;
|
|
75
|
+
url =
|
|
76
|
+
workflowId !== undefined
|
|
77
|
+
? `${base}/api/stream/run/${workflowId}/${runId}`
|
|
78
|
+
: `${base}/api/stream/run/${runId}`;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
url = `${base}/api/stream/hub`;
|
|
82
|
+
}
|
|
83
|
+
const ticket = await mintStreamTicket({
|
|
84
|
+
secret: ticketSecret,
|
|
85
|
+
tenantId: tenant.tenantId,
|
|
86
|
+
channel,
|
|
87
|
+
runId,
|
|
88
|
+
actor: tenant.actor,
|
|
89
|
+
ttlSeconds: TICKET_TTL_SECONDS,
|
|
90
|
+
});
|
|
91
|
+
return json({
|
|
92
|
+
url,
|
|
93
|
+
ticket,
|
|
94
|
+
expiresAt: Date.now() + TICKET_TTL_SECONDS * 1000,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function hubUpgrade(request, url) {
|
|
98
|
+
if (!isWebSocketUpgrade(request)) {
|
|
99
|
+
return json({ error: 'websocket upgrade required' }, 426);
|
|
100
|
+
}
|
|
101
|
+
const ticket = url.searchParams.get('ticket');
|
|
102
|
+
if (!ticket)
|
|
103
|
+
return json({ error: 'stream ticket required' }, 401);
|
|
104
|
+
const claims = await verifyStreamTicket({
|
|
105
|
+
secret: ticketSecret,
|
|
106
|
+
token: ticket,
|
|
107
|
+
});
|
|
108
|
+
// Fail closed: an expired/forged/cross-channel ticket never subscribes.
|
|
109
|
+
if (!claims)
|
|
110
|
+
return json({ error: 'invalid stream ticket' }, 403);
|
|
111
|
+
if (claims.channel !== 'hub') {
|
|
112
|
+
return json({ error: 'invalid stream ticket' }, 403);
|
|
113
|
+
}
|
|
114
|
+
// Rewrite to /subscribe, dropping the ticket and passing the verified
|
|
115
|
+
// actorId/role as query params (the hub reads presence from the query — it
|
|
116
|
+
// performs no verification of its own, trusting the Worker's routing).
|
|
117
|
+
const forwardUrl = new URL(url);
|
|
118
|
+
forwardUrl.pathname = '/subscribe';
|
|
119
|
+
forwardUrl.search = '';
|
|
120
|
+
forwardUrl.searchParams.set('actorId', claims.actorId);
|
|
121
|
+
forwardUrl.searchParams.set('role', claims.role);
|
|
122
|
+
const forwardRequest = new Request(forwardUrl.toString(), request);
|
|
123
|
+
return createHubTopology(hub).forwardSubscribe(claims.tenantId, forwardRequest);
|
|
124
|
+
}
|
|
125
|
+
async function runUpgrade(request, url, workflowId, runId) {
|
|
126
|
+
if (!isWebSocketUpgrade(request)) {
|
|
127
|
+
return json({ error: 'websocket upgrade required' }, 426);
|
|
128
|
+
}
|
|
129
|
+
const ticket = url.searchParams.get('ticket');
|
|
130
|
+
if (!ticket)
|
|
131
|
+
return json({ error: 'stream ticket required' }, 401);
|
|
132
|
+
const claims = await verifyStreamTicket({
|
|
133
|
+
secret: ticketSecret,
|
|
134
|
+
token: ticket,
|
|
135
|
+
});
|
|
136
|
+
// The ticket must be a run ticket for THIS run, and its tenant must be the
|
|
137
|
+
// one the runId carries (INV-1) — belt over the ownership already baked into
|
|
138
|
+
// the runId prefix. Any mismatch fails closed.
|
|
139
|
+
if (!claims)
|
|
140
|
+
return json({ error: 'invalid stream ticket' }, 403);
|
|
141
|
+
if (claims.channel !== 'run' ||
|
|
142
|
+
claims.runId !== runId ||
|
|
143
|
+
claims.tenantId !== tenantOfRunId(runId)) {
|
|
144
|
+
return json({ error: 'invalid stream ticket' }, 403);
|
|
145
|
+
}
|
|
146
|
+
const forwardUrl = new URL(url);
|
|
147
|
+
forwardUrl.pathname = `/runs/${workflowId}/${runId}/stream`;
|
|
148
|
+
forwardUrl.search = '';
|
|
149
|
+
const forwardRequest = new Request(forwardUrl.toString(), request);
|
|
150
|
+
// The runner DO is keyed `${wf}:${runId}` (the same instance that runs the
|
|
151
|
+
// workflow). See UpgradeForwardStub for why the stub is coerced here.
|
|
152
|
+
const stub = runner.get(runner.idFromName(`${workflowId}:${runId}`));
|
|
153
|
+
return stub.fetch(forwardRequest);
|
|
154
|
+
}
|
|
155
|
+
return async (request) => {
|
|
156
|
+
const url = new URL(request.url);
|
|
157
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
158
|
+
// Own only /api/stream/*; everything else falls through to the next router.
|
|
159
|
+
if (segments[0] !== 'api' || segments[1] !== 'stream')
|
|
160
|
+
return null;
|
|
161
|
+
try {
|
|
162
|
+
if (request.method === 'POST' &&
|
|
163
|
+
segments.length === 3 &&
|
|
164
|
+
segments[2] === 'ticket') {
|
|
165
|
+
return await mintRoute(request);
|
|
166
|
+
}
|
|
167
|
+
if (request.method === 'GET' &&
|
|
168
|
+
segments.length === 3 &&
|
|
169
|
+
segments[2] === 'hub') {
|
|
170
|
+
return await hubUpgrade(request, url);
|
|
171
|
+
}
|
|
172
|
+
if (request.method === 'GET' &&
|
|
173
|
+
segments.length === 5 &&
|
|
174
|
+
segments[2] === 'run' &&
|
|
175
|
+
segments[3] &&
|
|
176
|
+
segments[4]) {
|
|
177
|
+
return await runUpgrade(request, url, segments[3], segments[4]);
|
|
178
|
+
}
|
|
179
|
+
return json({ error: 'not found' }, 404);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// A malformed tenant claim is a verifier bug -> 403 (mirrors run-router);
|
|
183
|
+
// anything else is an unexpected 500.
|
|
184
|
+
if (error instanceof TenantResolutionError) {
|
|
185
|
+
return json({ error: 'forbidden' }, 403);
|
|
186
|
+
}
|
|
187
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=stream-router.js.map
|
|
@@ -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EACjE,GAAG,CACJ,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ApprovalActor, type ApprovalRole } from '../approval-api/index.js';
|
|
2
|
+
/** The two live channels (DL-009): the per-tenant hub, or a per-run WebSocket. */
|
|
3
|
+
export type StreamChannel = 'hub' | 'run';
|
|
4
|
+
/**
|
|
5
|
+
* The addressing a stream ticket carries. `runId` is present IFF `channel` is
|
|
6
|
+
* `'run'`. `exp` is epoch SECONDS (matching the JWT `exp` convention). No
|
|
7
|
+
* capability is ever encoded here — the ticket addresses a channel, nothing
|
|
8
|
+
* more.
|
|
9
|
+
*/
|
|
10
|
+
export interface StreamTicketClaims {
|
|
11
|
+
tenantId: string;
|
|
12
|
+
channel: StreamChannel;
|
|
13
|
+
runId?: string;
|
|
14
|
+
actorId: string;
|
|
15
|
+
role: ApprovalRole;
|
|
16
|
+
/** Epoch SECONDS. */
|
|
17
|
+
exp: number;
|
|
18
|
+
}
|
|
19
|
+
export interface MintStreamTicketOptions {
|
|
20
|
+
/** The dedicated stream-ticket signing secret (STREAM_TICKET_SECRET). */
|
|
21
|
+
secret: string;
|
|
22
|
+
/** The AUTHENTICATED tenant the ticket is bound to (INV-3-valid upstream). */
|
|
23
|
+
tenantId: string;
|
|
24
|
+
channel: StreamChannel;
|
|
25
|
+
/** REQUIRED for the `'run'` channel; omitted for `'hub'`. */
|
|
26
|
+
runId?: string;
|
|
27
|
+
/** The authenticated actor — only `id` and `role` are carried. */
|
|
28
|
+
actor: ApprovalActor;
|
|
29
|
+
/** Ticket lifetime in seconds (exp = now + ttl). Default 60. */
|
|
30
|
+
ttlSeconds?: number;
|
|
31
|
+
/** Epoch-ms clock, injectable for tests. Default Date.now. */
|
|
32
|
+
now?: () => number;
|
|
33
|
+
}
|
|
34
|
+
export interface VerifyStreamTicketOptions {
|
|
35
|
+
secret: string;
|
|
36
|
+
token: string;
|
|
37
|
+
/** Epoch-ms clock, injectable for tests. Default Date.now. */
|
|
38
|
+
now?: () => number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Mint a compact `base64url(claims).signature` ticket. For the `'run'` channel
|
|
42
|
+
* a runId is REQUIRED — a run ticket with no run to address is a programmer
|
|
43
|
+
* error (throws a generic Error; a client never reaches this mint directly).
|
|
44
|
+
*/
|
|
45
|
+
export declare function mintStreamTicket(options: MintStreamTicketOptions): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Verify a stream ticket, returning its claims or `undefined` (fail closed).
|
|
48
|
+
* The signature is recomputed over the presented payload segment and compared
|
|
49
|
+
* CONSTANT-TIME; then every claim is validated: `exp` unexpired, `tenantId`
|
|
50
|
+
* INV-3-valid and not reserved, `channel` known, `runId` present IFF the run
|
|
51
|
+
* channel (and when present PATH_SAFE and tenant-owned), `actorId` non-empty,
|
|
52
|
+
* and `role` a recognized APPROVAL_ROLE. Any failure returns `undefined`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function verifyStreamTicket(options: VerifyStreamTicketOptions): Promise<StreamTicketClaims | undefined>;
|
|
55
|
+
//# sourceMappingURL=stream-ticket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-ticket.d.ts","sourceRoot":"","sources":["../../src/host-kit/stream-ticket.ts"],"names":[],"mappings":"AAwBA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AASlC,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,YAAY,CAAC;IACnB,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,aAAa,CAAC;IACvB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,KAAK,EAAE,aAAa,CAAC;IACrB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAKD;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAoEzC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Short-lived HMAC "stream ticket" auth for the WebSocket handshake (DL-010).
|
|
3
|
+
//
|
|
4
|
+
// A browser cannot set an Authorization header on `new WebSocket()`, so the
|
|
5
|
+
// bearer identity cannot ride the upgrade and a long-lived token in the URL
|
|
6
|
+
// would leak through proxy/referrer logs. Instead a client mints a ~60s ticket
|
|
7
|
+
// over the AUTHENTICATED REST surface (stream-router.ts) and presents it in the
|
|
8
|
+
// WS URL query. The ticket is signed with the SAME HS256 primitives as the
|
|
9
|
+
// session verifier (verifier.ts hmacSign/base64UrlEncode) but under a DEDICATED
|
|
10
|
+
// STREAM_TICKET_SECRET (DL-019), so a ticket and a session JWT can never be
|
|
11
|
+
// confused under one signing key. A leaked ticket URL is limited to a brief
|
|
12
|
+
// replay on exactly ONE tenant's own channel.
|
|
13
|
+
//
|
|
14
|
+
// The ticket carries ONLY ADDRESSING — tenant, channel, runId, actor, exp —
|
|
15
|
+
// never a grant. Connector capability comes solely from the server-derived
|
|
16
|
+
// requestContext grant the runtime mints per leg (approval-api/grants.ts); no
|
|
17
|
+
// capability ever travels on the WebSocket. The Worker is the SOLE verification
|
|
18
|
+
// authority: it verifies the ticket once and routes by ticket.tenantId/runId to
|
|
19
|
+
// idFromName, so the hub/runner DOs re-bind the connection to one tenant/run by
|
|
20
|
+
// their own identity (INV-1 / id.name===tenantId) and hold no secret.
|
|
21
|
+
//
|
|
22
|
+
// Fail-closed: an expired, forged, cross-tenant, cross-channel, or otherwise
|
|
23
|
+
// malformed ticket verifies to `undefined`, never to a default identity.
|
|
24
|
+
import { APPROVAL_ROLES, } from '../approval-api/index.js';
|
|
25
|
+
import { PATH_SAFE_ID_PATTERN, RESERVED_TENANT_IDS, TENANT_ID_PATTERN, tenantOwnsSaltedId, } from '../do-runner/path-safe-id.js';
|
|
26
|
+
import { base64UrlEncode, hmacSign } from './verifier.js';
|
|
27
|
+
const encoder = new TextEncoder();
|
|
28
|
+
const decoder = new TextDecoder();
|
|
29
|
+
/**
|
|
30
|
+
* Mint a compact `base64url(claims).signature` ticket. For the `'run'` channel
|
|
31
|
+
* a runId is REQUIRED — a run ticket with no run to address is a programmer
|
|
32
|
+
* error (throws a generic Error; a client never reaches this mint directly).
|
|
33
|
+
*/
|
|
34
|
+
export async function mintStreamTicket(options) {
|
|
35
|
+
const { secret, tenantId, channel, runId, actor } = options;
|
|
36
|
+
if (channel === 'run' && runId === undefined) {
|
|
37
|
+
throw new Error("mintStreamTicket: a 'run' channel ticket requires a runId");
|
|
38
|
+
}
|
|
39
|
+
const nowSeconds = Math.floor((options.now ?? Date.now)() / 1000);
|
|
40
|
+
const claims = {
|
|
41
|
+
tenantId,
|
|
42
|
+
channel,
|
|
43
|
+
// Omit runId entirely off the run channel so the "present IFF run" verify
|
|
44
|
+
// check is exact (an undefined field serializes away under JSON.stringify).
|
|
45
|
+
...(runId !== undefined ? { runId } : {}),
|
|
46
|
+
actorId: actor.id,
|
|
47
|
+
role: actor.role,
|
|
48
|
+
exp: nowSeconds + (options.ttlSeconds ?? 60),
|
|
49
|
+
};
|
|
50
|
+
const payload = base64UrlEncode(encoder.encode(JSON.stringify(claims)));
|
|
51
|
+
const signature = await hmacSign(secret, payload);
|
|
52
|
+
return `${payload}.${signature}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Verify a stream ticket, returning its claims or `undefined` (fail closed).
|
|
56
|
+
* The signature is recomputed over the presented payload segment and compared
|
|
57
|
+
* CONSTANT-TIME; then every claim is validated: `exp` unexpired, `tenantId`
|
|
58
|
+
* INV-3-valid and not reserved, `channel` known, `runId` present IFF the run
|
|
59
|
+
* channel (and when present PATH_SAFE and tenant-owned), `actorId` non-empty,
|
|
60
|
+
* and `role` a recognized APPROVAL_ROLE. Any failure returns `undefined`.
|
|
61
|
+
*/
|
|
62
|
+
export async function verifyStreamTicket(options) {
|
|
63
|
+
const { secret, token } = options;
|
|
64
|
+
const parts = token.split('.');
|
|
65
|
+
if (parts.length !== 2)
|
|
66
|
+
return undefined;
|
|
67
|
+
const [payload, signature] = parts;
|
|
68
|
+
// Recompute the HMAC over the presented payload segment and compare in
|
|
69
|
+
// constant time. hmacSign is the one signer both mint and verify share, so a
|
|
70
|
+
// tampered payload OR signature yields a different recomputed sig and fails.
|
|
71
|
+
const expected = await hmacSign(secret, payload);
|
|
72
|
+
if (!constantTimeEqual(signature, expected))
|
|
73
|
+
return undefined;
|
|
74
|
+
const claims = base64UrlDecodeJson(payload);
|
|
75
|
+
// `typeof null === 'object'`, so a JSON `null` payload would slip past a bare
|
|
76
|
+
// object check and throw on the first `claims.exp` read — breaking this
|
|
77
|
+
// function's "malformed → undefined, never throws" contract (F5). Guard it.
|
|
78
|
+
if (claims === undefined || claims === null || typeof claims !== 'object') {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const nowSeconds = (options.now ?? Date.now)() / 1000;
|
|
82
|
+
if (typeof claims.exp !== 'number' || nowSeconds >= claims.exp) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (typeof claims.tenantId !== 'string' ||
|
|
86
|
+
!TENANT_ID_PATTERN.test(claims.tenantId) ||
|
|
87
|
+
RESERVED_TENANT_IDS.includes(claims.tenantId)) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (claims.channel !== 'hub' && claims.channel !== 'run')
|
|
91
|
+
return undefined;
|
|
92
|
+
// runId present IFF the run channel; when present it must be PATH_SAFE and
|
|
93
|
+
// owned by the ticket's tenant (so a run ticket can never address another
|
|
94
|
+
// tenant's run even if the signature were somehow honoured).
|
|
95
|
+
const hasRunId = claims.runId !== undefined;
|
|
96
|
+
if ((claims.channel === 'run') !== hasRunId)
|
|
97
|
+
return undefined;
|
|
98
|
+
if (claims.channel === 'run') {
|
|
99
|
+
if (typeof claims.runId !== 'string' ||
|
|
100
|
+
!PATH_SAFE_ID_PATTERN.test(claims.runId) ||
|
|
101
|
+
!tenantOwnsSaltedId(claims.tenantId, claims.runId)) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (typeof claims.actorId !== 'string' || claims.actorId.length === 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if (typeof claims.role !== 'string' ||
|
|
109
|
+
!APPROVAL_ROLES.includes(claims.role)) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
tenantId: claims.tenantId,
|
|
114
|
+
channel: claims.channel,
|
|
115
|
+
...(claims.channel === 'run' ? { runId: claims.runId } : {}),
|
|
116
|
+
actorId: claims.actorId,
|
|
117
|
+
role: claims.role,
|
|
118
|
+
exp: claims.exp,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Constant-time string equality for the recomputed base64url signatures. The
|
|
123
|
+
* length branch leaks nothing: an HMAC-SHA256 base64url signature is a fixed 43
|
|
124
|
+
* chars, so the length is not secret; only the content comparison must be
|
|
125
|
+
* timing-safe, and it is (a full XOR-accumulate over every char).
|
|
126
|
+
*/
|
|
127
|
+
function constantTimeEqual(a, b) {
|
|
128
|
+
if (a.length !== b.length)
|
|
129
|
+
return false;
|
|
130
|
+
let mismatch = 0;
|
|
131
|
+
for (let index = 0; index < a.length; index += 1) {
|
|
132
|
+
mismatch |= a.charCodeAt(index) ^ b.charCodeAt(index);
|
|
133
|
+
}
|
|
134
|
+
return mismatch === 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Compact base64url -> JSON decoder for the claims segment (verifier.ts keeps
|
|
138
|
+
* its own copy module-private; this is the "add a compact one" the ticket needs
|
|
139
|
+
* to read claims). Any malformed input returns `undefined` rather than throwing.
|
|
140
|
+
*/
|
|
141
|
+
function base64UrlDecodeJson(segment) {
|
|
142
|
+
const normalized = segment.replace(/-/g, '+').replace(/_/g, '/');
|
|
143
|
+
const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4);
|
|
144
|
+
try {
|
|
145
|
+
const binary = atob(padded);
|
|
146
|
+
const bytes = new Uint8Array(binary.length);
|
|
147
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
148
|
+
bytes[index] = binary.charCodeAt(index);
|
|
149
|
+
}
|
|
150
|
+
return JSON.parse(decoder.decode(bytes));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=stream-ticket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-ticket.js","sourceRoot":"","sources":["../../src/host-kit/stream-ticket.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,8EAA8E;AAC9E,EAAE;A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AC;QAC5B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YACtD,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -65,7 +65,7 @@ function isUniqueViolation(error) {
|
|
|
65
65
|
*/
|
|
66
66
|
export async function provisionTenant(db, options) {
|
|
67
67
|
const { tenantId, kind } = options;
|
|
68
|
-
if (!TENANT_ID_PATTERN.test(tenantId)) {
|
|
68
|
+
if (typeof tenantId !== 'string' || !TENANT_ID_PATTERN.test(tenantId)) {
|
|
69
69
|
throw new Error(`tenantId '${tenantId}' violates INV-3 (^[a-z0-9]{3,32}$) — not provisioned`);
|
|
70
70
|
}
|
|
71
71
|
if (RESERVED_FOR_ALLOCATION.includes(tenantId)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenant-registry.js","sourceRoot":"","sources":["../../src/host-kit/tenant-registry.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,sEAAsE;AACtE,wEAAwE;AACxE,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,yEAAyE;AACzE,2EAA2E;AAE3E,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAYtC,MAAM,oBAAoB,GAAG;;;;EAI3B,CAAC;AAEH;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAE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OAAO,KAAK,EAAE,CAAC;QACf,IAAI,iBAAiB,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TenantContext } from '../approval-api/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The subset of a DurableObjectStub the thread topology uses. The raw-`Request`
|
|
4
|
+
* overload is what lets a WebSocket UPGRADE forward through the stub unchanged;
|
|
5
|
+
* the string/init overload carries ordinary JSON routes.
|
|
6
|
+
*/
|
|
7
|
+
export interface ThreadStubLike {
|
|
8
|
+
fetch(request: Request): Promise<Response>;
|
|
9
|
+
fetch(url: string, init?: {
|
|
10
|
+
method?: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
body?: string;
|
|
13
|
+
}): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
/** The subset of a DurableObjectNamespace the thread topology uses. */
|
|
16
|
+
export interface ThreadNamespaceLike<Id = unknown> {
|
|
17
|
+
idFromName(name: string): Id;
|
|
18
|
+
get(id: Id): ThreadStubLike;
|
|
19
|
+
}
|
|
20
|
+
/** What `send` carries beyond the sanctioned header — a route's own payload. */
|
|
21
|
+
export interface ThreadRequestInit {
|
|
22
|
+
method?: string;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
body?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ThreadTopology {
|
|
27
|
+
/**
|
|
28
|
+
* Send an authenticated request to a thread DO. `path` is the DO-side route
|
|
29
|
+
* (e.g. `/messages`). Throws RunRouteError(404) when the tenant does not own
|
|
30
|
+
* `threadId` — before the DO is addressed, so a foreign thread is never even
|
|
31
|
+
* woken, and the caller surfaces the 404 its router already maps.
|
|
32
|
+
*/
|
|
33
|
+
send(tenant: TenantContext, threadId: string, path: string, init?: ThreadRequestInit): Promise<Response>;
|
|
34
|
+
/**
|
|
35
|
+
* Forward a client Request (e.g. a verified WebSocket upgrade) to a thread DO,
|
|
36
|
+
* with the tenant header OVERWRITTEN from the authenticated context. Same
|
|
37
|
+
* ownership 404 as `send`. Use this instead of `stub.fetch(request)`: a
|
|
38
|
+
* verbatim forward carries the client's own headers, including a forged
|
|
39
|
+
* `x-flowsafe-tenant`.
|
|
40
|
+
*/
|
|
41
|
+
forward(tenant: TenantContext, threadId: string, request: Request): Promise<Response>;
|
|
42
|
+
}
|
|
43
|
+
export declare function createThreadTopology<Id>(namespace: ThreadNamespaceLike<Id>): ThreadTopology;
|
|
44
|
+
//# sourceMappingURL=thread-topology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread-topology.d.ts","sourceRoot":"","sources":["../../src/host-kit/thread-topology.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3C,KAAK,CACH,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GACA,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB;AAED,uEAAuE;AACvE,MAAM,WAAW,mBAAmB,CAAC,EAAE,GAAG,OAAO;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC;IAC7B,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAAC;CAC7B;AAED,gFAAgF;AAChF,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,IAAI,CACF,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB;;;;;;OAMG;IACH,OAAO,CACL,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EACrC,SAAS,EAAE,mBAAmB,CAAC,EAAE,CAAC,GACjC,cAAc,CAmDhB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The per-thread DO topology seam — and the MINTER for the tenant header
|
|
3
|
+
// ThreadDurableObject verifies (DL-002). Mint and verify ship together, the same
|
|
4
|
+
// posture stream-ticket.ts takes, because a verifier whose input the caller can
|
|
5
|
+
// write is not a check.
|
|
6
|
+
//
|
|
7
|
+
// THE TRAP THIS EXISTS TO CLOSE. The house idiom for forwarding into a DO is
|
|
8
|
+
// hub-topology.ts's `forwardSubscribe: (tenantId, request) => stub(tenantId)
|
|
9
|
+
// .fetch(request)` — the CLIENT's Request, headers and all. That is safe for the
|
|
10
|
+
// hub, which trusts the forwarded request for nothing (it re-asserts
|
|
11
|
+
// event.record.tenantId against its own id.name from server-side data). A thread
|
|
12
|
+
// route copying that shape would hand the client the very header the thread DO
|
|
13
|
+
// authenticates on: `x-flowsafe-tenant: <victim>` and the assertion passes. So
|
|
14
|
+
// this module, not the caller, decides the header's value — on EVERY path,
|
|
15
|
+
// including forwarded upgrades, where it OVERWRITES rather than defaults.
|
|
16
|
+
//
|
|
17
|
+
// Reach a thread DO through here. A route that addresses the namespace itself
|
|
18
|
+
// re-opens the hole, so the namespace-shaped seam is deliberately not re-exported
|
|
19
|
+
// for ad-hoc use: `send`/`forward` are the sanctioned surface, and both refuse a
|
|
20
|
+
// threadId the caller's tenant does not own BEFORE the DO is ever addressed.
|
|
21
|
+
//
|
|
22
|
+
// Structural namespace/stub types (method syntax, so a real
|
|
23
|
+
// DurableObjectNamespace satisfies them under TS method-parameter bivariance),
|
|
24
|
+
// keeping host-kit free of @cloudflare/workers-types — same convention as
|
|
25
|
+
// RunnerNamespaceLike / HubNamespaceLike.
|
|
26
|
+
import { THREAD_ACTOR_HEADER, THREAD_TENANT_HEADER, } from '../do-runner/index.js';
|
|
27
|
+
import { requireOwnedMemoryId } from './memory-boundary.js';
|
|
28
|
+
export function createThreadTopology(namespace) {
|
|
29
|
+
// One DO per thread: id.name IS the tenant-minted threadId, so the instance
|
|
30
|
+
// carries its tenant exactly like a runId carries its own (DL-002).
|
|
31
|
+
const stub = (threadId) => namespace.get(namespace.idFromName(threadId));
|
|
32
|
+
// Ownership FIRST, then address. Both barriers are load-bearing and neither
|
|
33
|
+
// subsumes the other: this 404 is what stops tenant B reaching tenant A's
|
|
34
|
+
// thread at all, and the header the DO re-asserts is what stops a routing bug
|
|
35
|
+
// here from being the only thing between them.
|
|
36
|
+
const owned = (tenant, threadId) => requireOwnedMemoryId(tenant, threadId, 'threadId');
|
|
37
|
+
// Both surfaces are `async` so the ownership refusal REJECTS rather than
|
|
38
|
+
// throwing synchronously out of a Promise-typed call: a caller writing
|
|
39
|
+
// `topology.send(...).catch(handle)` would never see a sync throw, and the
|
|
40
|
+
// 404 would escape past the very handler meant to map it.
|
|
41
|
+
return {
|
|
42
|
+
send: async (tenant, threadId, path, init = {}) => {
|
|
43
|
+
// Merge through Headers so the stamp wins by case-INSENSITIVE name. A
|
|
44
|
+
// plain-object spread keeps a caller's `X-Flowsafe-Tenant` as a SECOND
|
|
45
|
+
// property; Headers' fill algorithm then appends both into `globex, acme`,
|
|
46
|
+
// which the DO reads as claimed !== tenantId — a 403 that looks like an
|
|
47
|
+
// identity attack (fail-closed, but the wrong error and a false
|
|
48
|
+
// "spelling cannot win" story). `set` is the primitive `forward` already
|
|
49
|
+
// relies on; it overwrites at every spelling. The value is the RESOLVED
|
|
50
|
+
// tenant context (authenticate -> INV-3 -> bind), never a header or body.
|
|
51
|
+
const merged = new Headers(init.headers);
|
|
52
|
+
merged.set(THREAD_TENANT_HEADER, tenant.tenantId);
|
|
53
|
+
merged.set(THREAD_ACTOR_HEADER, tenant.actor.id);
|
|
54
|
+
const headers = {};
|
|
55
|
+
merged.forEach((value, key) => {
|
|
56
|
+
headers[key] = value;
|
|
57
|
+
});
|
|
58
|
+
return stub(owned(tenant, threadId)).fetch(`http://thread${path}`, {
|
|
59
|
+
...init,
|
|
60
|
+
headers,
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
forward: async (tenant, threadId, request) => {
|
|
64
|
+
const addressed = owned(tenant, threadId);
|
|
65
|
+
// A cloned Request has MUTABLE headers where an inbound one does not, so
|
|
66
|
+
// this is what lets the overwrite happen at all — and `set` (not `append`)
|
|
67
|
+
// is what makes a forged client value vanish rather than ride along as a
|
|
68
|
+
// second value the DO might read.
|
|
69
|
+
const forwarded = new Request(request);
|
|
70
|
+
forwarded.headers.set(THREAD_TENANT_HEADER, tenant.tenantId);
|
|
71
|
+
forwarded.headers.set(THREAD_ACTOR_HEADER, tenant.actor.id);
|
|
72
|
+
return stub(addressed).fetch(forwarded);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=thread-topology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread-topology.js","sourceRoot":"","sources":["../../src/host-kit/thread-topology.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,iFAAiF;AACjF,gFAAgF;AAChF,wBAAwB;AACxB,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,iFAAiF;AACjF,qEA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AK,CAAC,EAAE,CAAC,CAAC;YACjD,MAAM,OAAO,GAA2B,EAAE,CAAC;YAC3C,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAC5B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,IAAI,EAAE,EAAE;gBACjE,GAAG,IAAI;gBACP,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;YAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC1C,yEAAyE;YACzE,2EAA2E;YAC3E,yEAAyE;YACzE,kCAAkC;YAClC,MAAM,SAAS,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;YACvC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7D,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5D,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type { ApprovalActor, ApprovalAuditEvent, ApprovalAuditSink, ApprovalCursor, ApprovalDatabase, ApprovalDecision, ApprovalListFilter, ApprovalListOrder, ApprovalMetrics, ApprovalNotificationEvent, ApprovalNotificationSink, ApprovalPatch, ApprovalPreparedStatement, ApprovalPriority, ApprovalRecord, ApprovalRole, ApprovalRouter, ApprovalRouterOptions, ApprovalServiceOptions, ApprovalStatus, ApprovalStore, ApprovalStoreFactory, BatchDecideItem, BatchDecideResult, CreateApprovalInput, CreateResult, CreateTenantResolverOptions, DecideResult, PurgeExpiredApprovalsOptions, ResumeOutcome, SelfDecisionPolicy, SweepSLAOptions, SystemApprovalStore, TenantBoundApprovalStore, TenantContext, TenantResolver, } from './approval-api/index.js';
|
|
1
|
+
export type { ApprovalActor, ApprovalAuditEvent, ApprovalAuditSink, ApprovalCursor, ApprovalDatabase, ApprovalDecision, ApprovalListFilter, ApprovalListOrder, ApprovalMetrics, ApprovalNotificationEvent, ApprovalNotificationSink, ApprovalPatch, ApprovalPreparedStatement, ApprovalPriority, ApprovalRecord, ApprovalResumeTarget, ApprovalRole, ApprovalRouter, ApprovalRouterOptions, ApprovalServiceOptions, ApprovalStatus, ApprovalStore, ApprovalStoreFactory, ApprovalStreamEvent, ApprovalStreamSink, BatchDecideItem, BatchDecideResult, CreateApprovalInput, CreateResult, CreateTenantResolverOptions, DecideResult, PurgeExpiredApprovalsOptions, ResumeOutcome, SelfDecisionPolicy, SweepSLAOptions, SystemApprovalStore, TenantBoundApprovalStore, TenantContext, TenantResolver, } from './approval-api/index.js';
|
|
2
2
|
export { APPROVAL_LIST_ORDERS, APPROVAL_PRIORITIES, APPROVAL_ROLES, APPROVAL_STATUSES, ApprovalAuthzError, ApprovalConflictError, ApprovalService, approvalCursor, approvalGrantProvider, approvalGrantProviderFromFactory, approvalListOrder, approvedConnectorsForLeg, BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, byReviewerOrder, CLIENT_CREATE_FIELDS, createApprovalRouter, createTenantResolver, D1ApprovalStoreFactory, DECIDER_ROLES, defaultResumeData, InMemoryApprovalStore, InMemoryApprovalStoreFactory, InvalidApprovalInputError, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, parseApprovalCursor, purgeExpiredApprovals, RUN_START_ROLES, resumeViaRuntime, selfDecisionExempts, stepKeyOf, sweepSLA, TCB_ONLY_CREATE_FIELDS, TENANT_BOUND, TERMINAL_APPROVAL_STATUSES, TenantResolutionError, UnknownApprovalError, } from './approval-api/index.js';
|
|
3
3
|
export type { ArtifactBody, ArtifactBucket, ArtifactBucketListResult, ArtifactBucketObject, ArtifactBucketObjectBody, ArtifactContent, ArtifactRecord, ArtifactRef, ListArtifactsScope, PutArtifactOptions, R2ArtifactStoreOptions, } from './artifacts/index.js';
|
|
4
4
|
export { InMemoryArtifactBucket, InvalidArtifactRefError, R2ArtifactStore, } from './artifacts/index.js';
|
|
5
5
|
export type { AuditExportFetch, AuditExportOptions, AuditMessageBatch, AuditQueue, AuditQueueMessage, } from './audit-export/index.js';
|
|
6
6
|
export { createAuditQueueConsumer, createAuditQueueHandler, queueAuditSink, } from './audit-export/index.js';
|
|
7
|
-
export type { D1DatabaseBinding, D1StorageOptions, DORunnerEnv, DurableObjectRunnerState, InitOptions, InitResult, InitSource, PurgeExpiredRunsOptions, PurgeTenantOptions, PurgeTenantResult, RequestContextProvider, ResumeLedger, ResumeLedgerStorage, ResumeRunOptions, RunLeg, RunnerRuntimeOptions, RunSummary, SnapshotDatabase, SnapshotStatement, StartRunOptions, TenantArtifactPurger, } from './do-runner/index.js';
|
|
8
|
-
export { createD1Storage, DurableObjectRunner, DurableStorageResumeLedger, d1Changes, ensureSnapshotRunIdIndex, InMemoryResumeLedger, InvalidRunRequestError, init, mintResourceId, mintThreadId, PATH_SAFE_ID_PATTERN, purgeExpiredWorkflowRuns, purgeTenant, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, TENANT_ID_PATTERN, tenantOfMemoryId, tenantOfRunId, tenantOwnsMemoryId, UnknownRunError, UnknownWorkflowError, } from './do-runner/index.js';
|
|
7
|
+
export type { D1DatabaseBinding, D1StorageOptions, DORunnerEnv, DurableObjectRunnerState, HostPubSub, InitOptions, InitResult, InitSource, PurgeExpiredBackgroundTasksOptions, PurgeExpiredBackgroundTasksResult, PurgeExpiredRunsOptions, PurgeExpiredThreadsOptions, PurgeExpiredThreadsResult, PurgeTenantOptions, PurgeTenantResult, RequestContextProvider, ResumeLedger, ResumeLedgerStorage, ResumeRunOptions, RunLeg, RunnerRuntimeOptions, RunSummary, SnapshotDatabase, SnapshotStatement, StartRunOptions, TenantArtifactPurger, TenantRangePurgeCounter, TenantRangePurgeTable, ThreadScope, } from './do-runner/index.js';
|
|
8
|
+
export { BACKGROUND_TASK_TTL_PURGE_TABLES, createD1Storage, createHostPubSub, DoStatusError, DurableObjectRunner, DurableStorageResumeLedger, d1Changes, doErrorResponse, ensureSnapshotRunIdIndex, InMemoryResumeLedger, InvalidRunRequestError, init, mintResourceId, mintThreadId, PATH_SAFE_ID_PATTERN, purgeExpiredBackgroundTasks, purgeExpiredThreads, purgeExpiredWorkflowRuns, purgeTenant, RUN_TTL_PURGE_TABLES, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, TENANT_ID_PATTERN, TENANT_RANGE_PURGE_TABLES, THREAD_ACTOR_HEADER, THREAD_TENANT_HEADER, THREAD_TTL_PURGE_TABLES, ThreadDurableObject, ThreadIdentityError, tenantOfMemoryId, tenantOfRunId, tenantOwnsMemoryId, UnknownRunError, UnknownWorkflowError, } from './do-runner/index.js';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,E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,GACf,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,wBAAwB,EACxB,WAAW,EACX,UAAU,EACV,UAAU,EACV,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,EACN,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,2BAA2B,EAC3B,YAAY,EACZ,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,gCAAgC,EAChC,iBAAiB,EACjB,wBAAwB,EACxB,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,EAC7B,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,aAA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EACnB,0BAA0B,EAC1B,SAAS,EACT,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GACrB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
export { APPROVAL_LIST_ORDERS, APPROVAL_PRIORITIES, APPROVAL_ROLES, APPROVAL_STATUSES, ApprovalAuthzError, ApprovalConflictError, ApprovalService, approvalCursor, approvalGrantProvider, approvalGrantProviderFromFactory, approvalListOrder, approvedConnectorsForLeg, BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, byReviewerOrder, CLIENT_CREATE_FIELDS, createApprovalRouter, createTenantResolver, D1ApprovalStoreFactory, DECIDER_ROLES, defaultResumeData, InMemoryApprovalStore, InMemoryApprovalStoreFactory, InvalidApprovalInputError, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, parseApprovalCursor, purgeExpiredApprovals, RUN_START_ROLES, resumeViaRuntime, selfDecisionExempts, stepKeyOf, sweepSLA, TCB_ONLY_CREATE_FIELDS, TENANT_BOUND, TERMINAL_APPROVAL_STATUSES, TenantResolutionError, UnknownApprovalError, } from './approval-api/index.js';
|
|
23
23
|
export { InMemoryArtifactBucket, InvalidArtifactRefError, R2ArtifactStore, } from './artifacts/index.js';
|
|
24
24
|
export { createAuditQueueConsumer, createAuditQueueHandler, queueAuditSink, } from './audit-export/index.js';
|
|
25
|
-
export { createD1Storage, DurableObjectRunner, DurableStorageResumeLedger, d1Changes, ensureSnapshotRunIdIndex, InMemoryResumeLedger, InvalidRunRequestError, init, mintResourceId, mintThreadId, PATH_SAFE_ID_PATTERN, purgeExpiredWorkflowRuns, purgeTenant, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, TENANT_ID_PATTERN, tenantOfMemoryId, tenantOfRunId, tenantOwnsMemoryId, UnknownRunError, UnknownWorkflowError, } from './do-runner/index.js';
|
|
25
|
+
export { BACKGROUND_TASK_TTL_PURGE_TABLES, createD1Storage, createHostPubSub, DoStatusError, DurableObjectRunner, DurableStorageResumeLedger, d1Changes, doErrorResponse, ensureSnapshotRunIdIndex, InMemoryResumeLedger, InvalidRunRequestError, init, mintResourceId, mintThreadId, PATH_SAFE_ID_PATTERN, purgeExpiredBackgroundTasks, purgeExpiredThreads, purgeExpiredWorkflowRuns, purgeTenant, RUN_TTL_PURGE_TABLES, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, TENANT_ID_PATTERN, TENANT_RANGE_PURGE_TABLES, THREAD_ACTOR_HEADER, THREAD_TENANT_HEADER, THREAD_TTL_PURGE_TABLES, ThreadDurableObject, ThreadIdentityError, tenantOfMemoryId, tenantOfRunId, tenantOwnsMemoryId, UnknownRunError, UnknownWorkflowError, } from './do-runner/index.js';
|
|
26
26
|
//# sourceMappingURL=index.js.map
|