@proofoftech/flowsafe 0.4.0 → 0.7.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 +327 -0
- package/README.md +295 -251
- 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 +158 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +295 -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 +2 -2
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +87 -19
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.js +1 -1
- package/dist/approval-api/index.d.ts +1 -1
- 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 +2 -2
- 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 +10 -11
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +22 -9
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +27 -22
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +25 -9
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts +6 -6
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +15 -0
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/types.d.ts +13 -4
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +2 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +2 -2
- package/dist/approval-ui/FilterBar.d.ts +3 -3
- package/dist/approval-ui/FilterBar.js +3 -3
- package/dist/approval-ui/client.d.ts +1 -1
- package/dist/approval-ui/components.d.ts +1 -1
- package/dist/approval-ui/stream.d.ts +3 -3
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +6 -9
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
- package/dist/approval-ui/use-web-socket-transport.js +1 -1
- 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/breakwater-keys.d.ts +1 -1
- package/dist/do-runner/breakwater-keys.js +1 -1
- package/dist/do-runner/cf-types.d.ts +1 -1
- package/dist/do-runner/d1-storage.d.ts +347 -5
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +571 -17
- 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 +3 -3
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +7 -21
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +2 -2
- package/dist/do-runner/index.d.ts +9 -3
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +8 -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/memory-id.d.ts +3 -3
- package/dist/do-runner/memory-id.js +3 -3
- package/dist/do-runner/path-safe-id.d.ts +6 -6
- package/dist/do-runner/path-safe-id.js +6 -6
- 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 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +28 -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 +28 -8
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -15
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +1 -1
- package/dist/host-kit/bearer-auth.js +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 +113 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +253 -63
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +13 -13
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/index.d.ts +3 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +7 -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/run-router.d.ts +10 -11
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +3 -3
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +1 -1
- package/dist/host-kit/tenant-registry.d.ts +1 -1
- package/dist/host-kit/tenant-registry.js +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/host-kit/verifier.d.ts +1 -1
- package/dist/host-kit/verifier.js +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- 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 +132 -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 +81 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +229 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/host-topology.d.ts +27 -0
- package/dist/signal-providers/host-topology.d.ts.map +1 -0
- package/dist/signal-providers/host-topology.js +36 -0
- package/dist/signal-providers/host-topology.js.map +1 -0
- package/dist/signal-providers/index.d.ts +8 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +21 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +93 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +89 -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 +96 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +444 -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 +27 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +703 -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,109 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The agent-memory host boundary (docs/agent-memory-tenancy.md item 5) — the
|
|
3
|
+
// memory analogue of createRunRouter's "runId is server-assigned" 400 and its
|
|
4
|
+
// ownership 404, factored out because memory ids reach the boundary through
|
|
5
|
+
// MANY routes (Track A's agent runs, Track C's signals, Track D's threaded
|
|
6
|
+
// schedule fires) where a runId reaches exactly one.
|
|
7
|
+
//
|
|
8
|
+
// Why a shared seam rather than the check inline in each router: threadId and
|
|
9
|
+
// resourceId are Mastra's CALLER-CHOSEN business identity (a user id, an email,
|
|
10
|
+
// a conversation slug), so the natural route body carries them and the natural
|
|
11
|
+
// handler trusts them — that is the leak, and it reads like ordinary code on
|
|
12
|
+
// every new route. One named, tested guard that every memory-touching route
|
|
13
|
+
// calls is the only version of this that survives contact with the fifth route.
|
|
14
|
+
//
|
|
15
|
+
// It lives in host-kit, not do-runner/memory-id.ts (which owns the mints and the
|
|
16
|
+
// pure ownership predicate), for two reasons: the guard's contract IS its HTTP
|
|
17
|
+
// status — RunRouteError carries the 400/404 the doctrine names, so a route
|
|
18
|
+
// gets the posture by calling it rather than by remembering to map an error —
|
|
19
|
+
// and TenantContext lives in approval-api, which already imports do-runner
|
|
20
|
+
// (a do-runner guard taking a TenantContext would invert that layering).
|
|
21
|
+
import { RunRouteError } from './run-route-error.js';
|
|
22
|
+
/**
|
|
23
|
+
* The memory-id fields no client body may name — the TCB_ONLY_CREATE_FIELDS
|
|
24
|
+
* doctrine applied to memory: a client that picks its own threadId/resourceId
|
|
25
|
+
* picks whose memory it reads, so these are minted server-side or not at all.
|
|
26
|
+
*/
|
|
27
|
+
export const TCB_ONLY_MEMORY_FIELDS = ['threadId', 'resourceId'];
|
|
28
|
+
/**
|
|
29
|
+
* Refuse a request body that names a memory id ANYWHERE in it. 400 rather than
|
|
30
|
+
* a silent override, for the same reason the run router 400s a client runId: a
|
|
31
|
+
* caller pinning ids must find out, not watch its value get quietly replaced and
|
|
32
|
+
* conclude the field works.
|
|
33
|
+
*
|
|
34
|
+
* NESTED, not just top-level, because the shape the first real consumer sends is
|
|
35
|
+
* nested: an agent run starts through `POST /runs` as
|
|
36
|
+
* `{workflowId, inputData: {...}}`, so the natural body for a threaded run is
|
|
37
|
+
* `{inputData: {threadId, prompt}}` — a top-level-only check would pass exactly
|
|
38
|
+
* the request this guard exists to refuse. A legitimate payload never carries a
|
|
39
|
+
* memory id (that is the whole doctrine: they are minted server-side and travel
|
|
40
|
+
* through requestContext, never a body), so refusing the name at any depth costs
|
|
41
|
+
* nothing real and closes the shape the leak actually arrives in.
|
|
42
|
+
*
|
|
43
|
+
* `undefined` is refused along with a value — a body carrying the KEY is a
|
|
44
|
+
* caller that believes it may choose, and the day someone writes
|
|
45
|
+
* `threadId: maybeUndefined` the tolerant reading is a leak waiting on one
|
|
46
|
+
* truthiness bug. Non-object bodies name no field and pass; body SHAPE is each
|
|
47
|
+
* route's own schema business.
|
|
48
|
+
*
|
|
49
|
+
* The walk is ITERATIVE and UNBOUNDED in depth. A depth cap would be a bypass
|
|
50
|
+
* with a number on it — nest one level past it and the id sails through the
|
|
51
|
+
* check — and depth is the attacker's choice, not the route's. Recursion is what
|
|
52
|
+
* a hostile 10k-deep body would actually break (the stack), so the fix is to not
|
|
53
|
+
* recurse: an explicit worklist costs heap proportional to a body JSON.parse has
|
|
54
|
+
* already materialized. A `seen` set keeps a cyclic in-process object (never a
|
|
55
|
+
* parsed body, which cannot cycle) from looping forever.
|
|
56
|
+
*
|
|
57
|
+
* Covers what a JSON body can express. A `Map`'s entries and a non-enumerable
|
|
58
|
+
* property are invisible to it — neither survives JSON.parse, so no HTTP caller
|
|
59
|
+
* can reach them; a route handing this a hand-built in-process object is outside
|
|
60
|
+
* the contract.
|
|
61
|
+
*/
|
|
62
|
+
export function assertNoClientMemoryIds(body) {
|
|
63
|
+
const worklist = [body];
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
while (worklist.length > 0) {
|
|
66
|
+
const value = worklist.pop();
|
|
67
|
+
if (typeof value !== 'object' || value === null)
|
|
68
|
+
continue;
|
|
69
|
+
if (seen.has(value))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(value);
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
worklist.push(...value);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const field of TCB_ONLY_MEMORY_FIELDS) {
|
|
77
|
+
if (field in value) {
|
|
78
|
+
throw new RunRouteError(400, `${field} is server-assigned (agent-memory ids are minted from the authenticated tenant — see docs/agent-memory-tenancy.md)`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
worklist.push(...Object.values(value));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Assert the authenticated tenant owns a memory id, returning it for use.
|
|
86
|
+
* 404 — never 403 — on a foreign id: the run router's rule, for the same
|
|
87
|
+
* reason. A 403 would confirm that another tenant's threadId EXISTS, turning
|
|
88
|
+
* every read path into an existence oracle over ids a caller can guess (a
|
|
89
|
+
* resourceId is business identity — an email, a user id — so guessing is the
|
|
90
|
+
* expected case, not a stretch).
|
|
91
|
+
*
|
|
92
|
+
* This is the ONLY thing between a foreign threadId and its history — nothing
|
|
93
|
+
* downstream re-checks. Mastra's recall filters by `resourceId` only when the
|
|
94
|
+
* caller passes one (`if (resourceId) query += ' AND resourceId = ?'`), and core
|
|
95
|
+
* ships recall sites that pass a threadId alone, so a foreign thread recalls in
|
|
96
|
+
* FULL past this point (pinned in do-runner/memory-recall-tenancy.test.ts). Call
|
|
97
|
+
* it on EVERY memory read path; there is no second line.
|
|
98
|
+
*
|
|
99
|
+
* `tenant.ownsMemoryId` is exact because the tenant-ID pattern
|
|
100
|
+
* excludes '_' from tenant ids, so 'acme' can never own 'acmecorp_...'
|
|
101
|
+
* (do-runner/path-safe-id.ts).
|
|
102
|
+
*/
|
|
103
|
+
export function requireOwnedMemoryId(tenant, id, label = 'threadId') {
|
|
104
|
+
if (typeof id !== 'string' || !tenant.ownsMemoryId(id)) {
|
|
105
|
+
throw new RunRouteError(404, `${label} not found`);
|
|
106
|
+
}
|
|
107
|
+
return id;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=memory-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-boundary.js","sourceRoot":"","sources":["../../src/host-kit/memory-boundary.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,2EAA2E;AAC3E,qDAAqD;AACrD,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AA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MAAM,UAAU,oBAAoB,CAClC,MAAqB,EACrB,EAAU,EACV,QAA4B,UAAU;IAEtC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,aAAa,CAAC,GAAG,EAAE,GAAG,KAAK,YAAY,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode a URL path segment, returning `undefined` on malformed percent-encoding
|
|
3
|
+
* (a lone `%`) instead of THROWING the way bare `decodeURIComponent` does.
|
|
4
|
+
*
|
|
5
|
+
* `new URL(...).pathname` passes an invalid `%` through unnormalized, so an
|
|
6
|
+
* unguarded `decodeURIComponent` inside a router would be a PRE-AUTH fault: the
|
|
7
|
+
* `URIError` escapes the router before authentication. This is the PRIMARY,
|
|
8
|
+
* source-level defense — callers treat `undefined` as "not a real route target"
|
|
9
|
+
* and return route-absent (`null`), byte-identical to a non-matching path, so a
|
|
10
|
+
* malformed id is indistinguishable from a path that was never ours (strictly
|
|
11
|
+
* better than surfacing a generic 500). `createFlowsafeWorker`'s fetch handler
|
|
12
|
+
* additionally wraps the router calls in a try/catch as defense-in-depth, so any
|
|
13
|
+
* future unguarded decode is still contained as a generic 500 rather than
|
|
14
|
+
* rejecting out of `fetch()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function safeDecodeSegment(segment: string | undefined): string | undefined;
|
|
17
|
+
//# sourceMappingURL=route-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-path.d.ts","sourceRoot":"","sources":["../../src/host-kit/route-path.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,MAAM,GAAG,SAAS,CAOpB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A routing primitive shared by every P6 ingestion router: decode a URL path
|
|
3
|
+
// segment without letting malformed percent-encoding crash the handler.
|
|
4
|
+
//
|
|
5
|
+
// A zero-dependency leaf, imported directly by the routers that need it
|
|
6
|
+
// (signals / goals / schedules / signal-providers / background-tasks) rather
|
|
7
|
+
// than re-exported from the host-kit barrel — it is internal plumbing, not a
|
|
8
|
+
// public host-kit API, and staying a leaf keeps it cycle-free (the same reason
|
|
9
|
+
// RunRouteError is a leaf).
|
|
10
|
+
/**
|
|
11
|
+
* Decode a URL path segment, returning `undefined` on malformed percent-encoding
|
|
12
|
+
* (a lone `%`) instead of THROWING the way bare `decodeURIComponent` does.
|
|
13
|
+
*
|
|
14
|
+
* `new URL(...).pathname` passes an invalid `%` through unnormalized, so an
|
|
15
|
+
* unguarded `decodeURIComponent` inside a router would be a PRE-AUTH fault: the
|
|
16
|
+
* `URIError` escapes the router before authentication. This is the PRIMARY,
|
|
17
|
+
* source-level defense — callers treat `undefined` as "not a real route target"
|
|
18
|
+
* and return route-absent (`null`), byte-identical to a non-matching path, so a
|
|
19
|
+
* malformed id is indistinguishable from a path that was never ours (strictly
|
|
20
|
+
* better than surfacing a generic 500). `createFlowsafeWorker`'s fetch handler
|
|
21
|
+
* additionally wraps the router calls in a try/catch as defense-in-depth, so any
|
|
22
|
+
* future unguarded decode is still contained as a generic 500 rather than
|
|
23
|
+
* rejecting out of `fetch()`.
|
|
24
|
+
*/
|
|
25
|
+
export function safeDecodeSegment(segment) {
|
|
26
|
+
if (segment === undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
try {
|
|
29
|
+
return decodeURIComponent(segment);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=route-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-path.js","sourceRoot":"","sources":["../../src/host-kit/route-path.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,4BAA4B;AAE5B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA2B;IAE3B,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -14,7 +14,7 @@ export interface RunRouterOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
workflows: ReadonlyArray<WorkflowMeta>;
|
|
16
16
|
/**
|
|
17
|
-
* Authenticates the request and binds the tenant scope
|
|
17
|
+
* Authenticates the request and binds the tenant scope: the
|
|
18
18
|
* approval service, the runId mint, and the ownership predicate all come
|
|
19
19
|
* from the resolved TenantContext. undefined yields 401.
|
|
20
20
|
*/
|
|
@@ -32,18 +32,17 @@ export interface RunRouterOptions {
|
|
|
32
32
|
status: (workflowId: string, runId: string) => Promise<RunSummary | undefined>;
|
|
33
33
|
resume: (workflowId: string, runId: string, body: unknown) => Promise<RunSummary>;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* re-queue failure previously left it there with no recovery path — see
|
|
35
|
+
* Self-healing hook invoked after a status() read reports the run
|
|
36
|
+
* suspended, so every status poll of a stuck run doubles as a check for a
|
|
37
|
+
* gate whose approval never made it into the queue (see
|
|
39
38
|
* reconcileApprovalsForSummary in approval-bridge.ts). Awaited rather than
|
|
40
|
-
* fire-and-forget by
|
|
39
|
+
* fire-and-forget by default: this host-agnostic layer has no ctx.waitUntil
|
|
41
40
|
* of its own to keep a detached promise alive past the response, so a
|
|
42
|
-
* plain awaited call is what it can offer on its own.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* plain awaited call is what it can offer on its own. Reconciliation pages
|
|
42
|
+
* the run's full approval history and may supersede stale open records
|
|
43
|
+
* before filing a fresh one, so the two ctx-capable hosts
|
|
44
|
+
* (deploy/worker.ts and the showcase worker) hand this hook a wrapper that
|
|
45
|
+
* detaches the real work
|
|
47
46
|
* via ctx.waitUntil and resolves immediately — this option's contract (an
|
|
48
47
|
* awaited function of this exact shape) is unchanged either way, only
|
|
49
48
|
* what a given host's function actually blocks on. A throw is caught and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AA2BA,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACvC;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,KAAK,EAAE,CACL,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAA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A2LpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-router.js","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,SAAS;AACT,EAAE;AACF,kDAAkD;AAClD,oFAAoF;AACpF,kFAAkF;AAClF,+EAA+E;AAC/E,kFAAkF;AAClF,gFAAgF;AAChF,iFAAiF;AACjF,EAAE;AACF,uEAAuE;AACvE,gFAAgF;AAChF,8BAA8B;AAC9B,EAAE;AACF,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAE9E,OAAO,EAEL,eAAe,EAEf,qBAAqB,GAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"run-router.js","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,SAAS;AACT,EAAE;AACF,kDAAkD;AAClD,oFAAoF;AACpF,kFAAkF;AAClF,+EAA+E;AAC/E,kFAAkF;AAClF,gFAAgF;AAChF,iFAAiF;AACjF,EAAE;AACF,uEAAuE;AACvE,gFAAgF;AAChF,8BAA8B;AAC9B,EAAE;AACF,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAE9E,OAAO,EAEL,eAAe,EAEf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,CAAC,MAAM,KAAK,CAAC;gBACrB,MAAM,KAAK,QAAQ;gBACnB,UAAU;gBACV,KAAK,EACL,CAAC;gBACD,OAAO,IAAI,CACT,MAAM,OAAO,CAAC,MAAM,CAClB,UAAU,EACV,KAAK,EACL,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAChC,CACF,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { type TenantResolver } from '../approval-api/index.js';
|
|
|
2
2
|
import type { RunnerNamespaceLike } from './do-run-topology.js';
|
|
3
3
|
import { type HubNamespaceLike } from './hub-topology.js';
|
|
4
4
|
export interface StreamRouterOptions {
|
|
5
|
-
/** The shared
|
|
5
|
+
/** The shared authenticate, validate, and tenant-bind resolver used by the ticket route. */
|
|
6
6
|
resolve: TenantResolver;
|
|
7
7
|
/** The dedicated stream-ticket signing secret (STREAM_TICKET_SECRET). */
|
|
8
8
|
ticketSecret: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/stream-router.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG7E,MAAM,WAAW,mBAAmB;IAClC,
|
|
1
|
+
{"version":3,"file":"stream-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/stream-router.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG7E,MAAM,WAAW,mBAAmB;IAClC,4FAA4F;IAC5F,OAAO,EAAE,cAAc,CAAC;IACxB,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,GAAG,EAAE,gBAAgB,CAAC;IACtB,kFAAkF;IAClF,MAAM,EAAE,mBAAmB,CAAC;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAyC1E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA2K7E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApprovalActor, type ApprovalRole } from '../approval-api/index.js';
|
|
2
|
-
/** The two live channels
|
|
2
|
+
/** The two live channels: the per-tenant hub or a per-run WebSocket. */
|
|
3
3
|
export type StreamChannel = 'hub' | 'run';
|
|
4
4
|
/**
|
|
5
5
|
* The addressing a stream ticket carries. `runId` is present IFF `channel` is
|
|
@@ -19,7 +19,7 @@ export interface StreamTicketClaims {
|
|
|
19
19
|
export interface MintStreamTicketOptions {
|
|
20
20
|
/** The dedicated stream-ticket signing secret (STREAM_TICKET_SECRET). */
|
|
21
21
|
secret: string;
|
|
22
|
-
/** The
|
|
22
|
+
/** The authenticated, previously validated tenant to which the ticket is bound. */
|
|
23
23
|
tenantId: string;
|
|
24
24
|
channel: StreamChannel;
|
|
25
25
|
/** REQUIRED for the `'run'` channel; omitted for `'hub'`. */
|
|
@@ -47,7 +47,7 @@ export declare function mintStreamTicket(options: MintStreamTicketOptions): Prom
|
|
|
47
47
|
* Verify a stream ticket, returning its claims or `undefined` (fail closed).
|
|
48
48
|
* The signature is recomputed over the presented payload segment and compared
|
|
49
49
|
* CONSTANT-TIME; then every claim is validated: `exp` unexpired, `tenantId`
|
|
50
|
-
*
|
|
50
|
+
* pattern-valid and not reserved, `channel` known, `runId` present if and only if the run
|
|
51
51
|
* channel (and when present PATH_SAFE and tenant-owned), `actorId` non-empty,
|
|
52
52
|
* and `role` a recognized APPROVAL_ROLE. Any failure returns `undefined`.
|
|
53
53
|
*/
|
|
@@ -1 +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,
|
|
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,wEAAwE;AACxE,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,mFAAmF;IACnF,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"}
|
|
@@ -55,7 +55,7 @@ export async function mintStreamTicket(options) {
|
|
|
55
55
|
* Verify a stream ticket, returning its claims or `undefined` (fail closed).
|
|
56
56
|
* The signature is recomputed over the presented payload segment and compared
|
|
57
57
|
* CONSTANT-TIME; then every claim is validated: `exp` unexpired, `tenantId`
|
|
58
|
-
*
|
|
58
|
+
* pattern-valid and not reserved, `channel` known, `runId` present if and only if the run
|
|
59
59
|
* channel (and when present PATH_SAFE and tenant-owned), `actorId` non-empty,
|
|
60
60
|
* and `role` a recognized APPROVAL_ROLE. Any failure returns `undefined`.
|
|
61
61
|
*/
|
|
@@ -41,7 +41,7 @@ export interface ProvisionTenantOptions {
|
|
|
41
41
|
now?: () => number;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Allocate a tenantId, or throw.
|
|
44
|
+
* Allocate a tenantId, or throw. The tenant-ID pattern is validated here too — a tenant that
|
|
45
45
|
* cannot be range-purged or prefix-matched must never exist in the first
|
|
46
46
|
* place. Insert-or-fail: a collision throws TenantCollisionError instead of
|
|
47
47
|
* silently adopting the existing row, because "provisioned twice" means two
|
|
@@ -57,7 +57,7 @@ function isUniqueViolation(error) {
|
|
|
57
57
|
/UNIQUE constraint failed|PRIMARY KEY constraint/i.test(error.message));
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Allocate a tenantId, or throw.
|
|
60
|
+
* Allocate a tenantId, or throw. The tenant-ID pattern is validated here too — a tenant that
|
|
61
61
|
* cannot be range-purged or prefix-matched must never exist in the first
|
|
62
62
|
* place. Insert-or-fail: a collision throws TenantCollisionError instead of
|
|
63
63
|
* silently adopting the existing row, because "provisioned twice" means two
|
|
@@ -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;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AAC,oBAAoB,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAClD,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,KAAK,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"}
|
|
@@ -5,7 +5,7 @@ export interface TokenVerifier {
|
|
|
5
5
|
/**
|
|
6
6
|
* Validate an untyped candidate into an ApprovalActor — the ONE place a
|
|
7
7
|
* decoded token/map entry becomes an identity. No `as`-casting at the JSON
|
|
8
|
-
* boundary: id non-empty, role recognized, tenantId
|
|
8
|
+
* boundary: id non-empty, role recognized, tenantId pattern-valid and not a
|
|
9
9
|
* reserved identity.
|
|
10
10
|
*/
|
|
11
11
|
export declare function toApprovalActor(candidate: unknown): ApprovalActor | undefined;
|
|
@@ -20,7 +20,7 @@ import { RESERVED_TENANT_IDS, TENANT_ID_PATTERN, } from '../do-runner/path-safe-
|
|
|
20
20
|
/**
|
|
21
21
|
* Validate an untyped candidate into an ApprovalActor — the ONE place a
|
|
22
22
|
* decoded token/map entry becomes an identity. No `as`-casting at the JSON
|
|
23
|
-
* boundary: id non-empty, role recognized, tenantId
|
|
23
|
+
* boundary: id non-empty, role recognized, tenantId pattern-valid and not a
|
|
24
24
|
* reserved identity.
|
|
25
25
|
*/
|
|
26
26
|
export function toApprovalActor(candidate) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export type { AuditExportFetch, AuditExportOptions, AuditMessageBatch, AuditQueue, AuditQueueMessage, } from './audit-export/index.js';
|
|
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';
|
|
1
|
+
export * from './approval-api/index.js';
|
|
2
|
+
export * from './artifacts/index.js';
|
|
3
|
+
export * from './audit-export/index.js';
|
|
4
|
+
export * from './do-runner/index.js';
|
|
9
5
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
// artifacts, and audit-export subpath barrels COMPLETELY — anything those
|
|
20
20
|
// subpaths export is also importable from the package root. approval-ui and
|
|
21
21
|
// host-kit are subpath-only by design (React peer / host glue).
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
22
|
+
export * from './approval-api/index.js';
|
|
23
|
+
export * from './artifacts/index.js';
|
|
24
|
+
export * from './audit-export/index.js';
|
|
25
|
+
export * from './do-runner/index.js';
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,4EAA4E;AAC5E,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,gDAAgD;AAChD,kEAAkE;AAClE,6EAA6E;AAC7E,4BAA4B;AAC5B,mFAAmF;AACnF,yEAAyE;AACzE,gCAAgC;AAChC,2EAA2E;AAC3E,iFAAiF;AACjF,+EAA+E;AAC/E,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAC5E,gEAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,4EAA4E;AAC5E,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,gDAAgD;AAChD,kEAAkE;AAClE,6EAA6E;AAC7E,4BAA4B;AAC5B,mFAAmF;AACnF,yEAAyE;AACzE,gCAAgC;AAChC,2EAA2E;AAC3E,iFAAiF;AACjF,+EAA+E;AAC/E,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAC5E,gEAAgE;AAEhE,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-error-response.d.ts","sourceRoot":"","sources":["../src/internal-error-response.ts"],"names":[],"mappings":"AAMA,yDAAyD;AACzD,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,GAAG,GAAG,GAAS,GACtB,QAAQ,CAeV"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
function errorText(error) {
|
|
3
|
+
return error instanceof Error ? error.message : String(error);
|
|
4
|
+
}
|
|
5
|
+
/** Package-internal catch-all for public HTTP routes. */
|
|
6
|
+
export function internalErrorResponse(route, error, status = 500) {
|
|
7
|
+
console.error(JSON.stringify({
|
|
8
|
+
type: 'route-internal-error',
|
|
9
|
+
route,
|
|
10
|
+
error: errorText(error),
|
|
11
|
+
}));
|
|
12
|
+
return new Response(JSON.stringify({ error: 'internal error' }), {
|
|
13
|
+
status,
|
|
14
|
+
headers: {
|
|
15
|
+
'content-type': 'application/json',
|
|
16
|
+
'cache-control': 'no-store',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=internal-error-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-error-response.js","sourceRoot":"","sources":["../src/internal-error-response.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,KAAc,EACd,SAAoB,GAAG;IAEvB,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,sBAAsB;QAC5B,KAAK;QACL,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC;KACxB,CAAC,CACH,CAAC;IACF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,EAAE;QAC/D,MAAM;QACN,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,UAAU;SAC5B;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function nonnegativeSafeInteger(value: number, name: string): number;
|
|
2
|
+
export declare function positiveSafeInteger(value: number, name: string): number;
|
|
3
|
+
export declare function finiteNonnegativeNumber(value: number, name: string): number;
|
|
4
|
+
//# sourceMappingURL=numeric-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-config.d.ts","sourceRoot":"","sources":["../src/numeric-config.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKvE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3E"}
|