@proofoftech/flowsafe 0.10.0 → 0.12.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 +50 -0
- package/README.md +77 -47
- package/deployment-identity-protocol.d.mts +52 -0
- package/deployment-identity-protocol.mjs +231 -0
- package/dist/agent-host/approval-resumer.d.ts +3 -3
- package/dist/agent-host/approval-resumer.d.ts.map +1 -1
- package/dist/agent-host/approval-resumer.js +6 -7
- package/dist/agent-host/approval-resumer.js.map +1 -1
- package/dist/agent-host/catalog.d.ts +1 -1
- package/dist/agent-host/catalog.d.ts.map +1 -1
- package/dist/agent-host/catalog.js +26 -2
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +4 -3
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js +1 -0
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/router.d.ts +2 -2
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +22 -54
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +53 -9
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +624 -109
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +28 -7
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +97 -39
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-host/trusted-context.d.ts.map +1 -1
- package/dist/agent-host/trusted-context.js +9 -2
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +48 -0
- package/dist/agent-host/types.d.ts.map +1 -1
- package/dist/agent-host/types.js +1 -1
- package/dist/agent-host/types.js.map +1 -1
- package/dist/agent-runner/agent-run-state.d.ts +9 -8
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.js +78 -40
- package/dist/agent-runner/agent-run-state.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +120 -43
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +67 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -0
- package/dist/approval-api/actor-context.js +120 -0
- package/dist/approval-api/actor-context.js.map +1 -0
- package/dist/approval-api/contract.d.ts +13 -24
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/contract.js +1 -1
- package/dist/approval-api/contract.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts +7 -15
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +83 -159
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +3 -17
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +19 -39
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +9 -9
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +6 -6
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/principal.d.ts +29 -30
- package/dist/approval-api/principal.d.ts.map +1 -1
- package/dist/approval-api/principal.js +73 -54
- package/dist/approval-api/principal.js.map +1 -1
- package/dist/approval-api/resource-ownership.d.ts +64 -0
- package/dist/approval-api/resource-ownership.d.ts.map +1 -0
- package/dist/approval-api/resource-ownership.js +329 -0
- package/dist/approval-api/resource-ownership.js.map +1 -0
- package/dist/approval-api/retention.d.ts +6 -11
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js +7 -12
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/router.d.ts +9 -8
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +50 -18
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +26 -36
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +104 -166
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store-factory.d.ts +19 -0
- package/dist/approval-api/store-factory.d.ts.map +1 -0
- package/dist/approval-api/store-factory.js +49 -0
- package/dist/approval-api/store-factory.js.map +1 -0
- package/dist/approval-api/store.d.ts +22 -36
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +48 -66
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/types.d.ts +28 -22
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +51 -3
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/client.js +3 -3
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +4 -4
- package/dist/approval-ui/stream.d.ts.map +1 -1
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/tips.d.ts +1 -1
- package/dist/approval-ui/tips.js +1 -1
- package/dist/approval-ui/tips.js.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
- package/dist/approval-ui/use-approval-dashboard.js +1 -1
- package/dist/artifacts/index.d.ts +2 -3
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +9 -8
- package/dist/artifacts/index.js.map +1 -1
- package/dist/audit-export/audit-proxy.d.ts +71 -0
- package/dist/audit-export/audit-proxy.d.ts.map +1 -0
- package/dist/audit-export/audit-proxy.js +142 -0
- package/dist/audit-export/audit-proxy.js.map +1 -0
- package/dist/audit-export/index.d.ts +4 -7
- package/dist/audit-export/index.d.ts.map +1 -1
- package/dist/audit-export/index.js +1 -4
- package/dist/audit-export/index.js.map +1 -1
- package/dist/audit-export/queue-types.d.ts +5 -0
- package/dist/audit-export/queue-types.d.ts.map +1 -0
- package/dist/audit-export/queue-types.js +3 -0
- package/dist/audit-export/queue-types.js.map +1 -0
- package/dist/background-tasks/d1-storage.d.ts +9 -19
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +22 -52
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/background-tasks/host.d.ts +4 -6
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +14 -17
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/background-tasks/index.d.ts +1 -1
- package/dist/background-tasks/index.d.ts.map +1 -1
- package/dist/background-tasks/index.js +3 -3
- package/dist/background-tasks/index.js.map +1 -1
- package/dist/background-tasks/routes.d.ts +8 -4
- package/dist/background-tasks/routes.d.ts.map +1 -1
- package/dist/background-tasks/routes.js +33 -31
- package/dist/background-tasks/routes.js.map +1 -1
- package/dist/deployment-identity-protocol.d.ts +3 -0
- package/dist/deployment-identity-protocol.d.ts.map +1 -0
- package/dist/deployment-identity-protocol.js +3 -0
- package/dist/deployment-identity-protocol.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +16 -5
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +16 -5
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/cf-types.d.ts +18 -12
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +44 -182
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +102 -353
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/deployment-identity.d.ts +121 -0
- package/dist/do-runner/deployment-identity.d.ts.map +1 -0
- package/dist/do-runner/deployment-identity.js +272 -0
- package/dist/do-runner/deployment-identity.js.map +1 -0
- package/dist/do-runner/do-error-response.d.ts +1 -1
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +7 -1
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +23 -16
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +303 -70
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts +1 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +6 -8
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-principal-header.d.ts +16 -0
- package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
- package/dist/do-runner/execution-principal-header.js +20 -0
- package/dist/do-runner/execution-principal-header.js.map +1 -0
- package/dist/do-runner/hub-do.d.ts +17 -25
- package/dist/do-runner/hub-do.d.ts.map +1 -1
- package/dist/do-runner/hub-do.js +63 -59
- package/dist/do-runner/hub-do.js.map +1 -1
- package/dist/do-runner/index.d.ts +12 -10
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +10 -9
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +0 -7
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +1 -2
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +8 -25
- package/dist/do-runner/memory-id.d.ts.map +1 -1
- package/dist/do-runner/memory-id.js +25 -52
- package/dist/do-runner/memory-id.js.map +1 -1
- package/dist/do-runner/path-safe-id.d.ts +2 -48
- package/dist/do-runner/path-safe-id.d.ts.map +1 -1
- package/dist/do-runner/path-safe-id.js +3 -93
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/pubsub.d.ts +1 -1
- package/dist/do-runner/pubsub.js +1 -1
- package/dist/do-runner/runtime.d.ts +47 -34
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +281 -143
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/schedule-source.d.ts +81 -0
- package/dist/do-runner/schedule-source.d.ts.map +1 -0
- package/dist/do-runner/schedule-source.js +64 -0
- package/dist/do-runner/schedule-source.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +18 -32
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +52 -74
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/goals/objective-routes.d.ts +7 -4
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +58 -43
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +18 -21
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -37
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +3 -4
- package/dist/host-kit/bearer-auth.d.ts.map +1 -1
- package/dist/host-kit/bearer-auth.js +7 -11
- package/dist/host-kit/bearer-auth.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +14 -5
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +47 -15
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +1 -1
- package/dist/host-kit/env-vars.js +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +149 -73
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +619 -141
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +62 -54
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +90 -61
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +6 -7
- package/dist/host-kit/hub-topology.d.ts.map +1 -1
- package/dist/host-kit/hub-topology.js +16 -12
- package/dist/host-kit/hub-topology.js.map +1 -1
- package/dist/host-kit/index.d.ts +13 -11
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +9 -12
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/maintenance-capability.d.ts +58 -0
- package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
- package/dist/host-kit/maintenance-capability.js +268 -0
- package/dist/host-kit/maintenance-capability.js.map +1 -0
- package/dist/host-kit/memory-boundary.d.ts +4 -19
- package/dist/host-kit/memory-boundary.d.ts.map +1 -1
- package/dist/host-kit/memory-boundary.js +12 -27
- package/dist/host-kit/memory-boundary.js.map +1 -1
- package/dist/host-kit/resource-access.d.ts +4 -0
- package/dist/host-kit/resource-access.d.ts.map +1 -0
- package/dist/host-kit/resource-access.js +12 -0
- package/dist/host-kit/resource-access.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +25 -15
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +61 -46
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/state-egress.d.ts +51 -0
- package/dist/host-kit/state-egress.d.ts.map +1 -0
- package/dist/host-kit/state-egress.js +120 -0
- package/dist/host-kit/state-egress.js.map +1 -0
- package/dist/host-kit/stream-router.d.ts +9 -4
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-router.js +45 -38
- package/dist/host-kit/stream-router.js.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +10 -10
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +60 -90
- package/dist/host-kit/stream-ticket.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +17 -11
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +33 -59
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/host-kit/verifier.d.ts +6 -6
- package/dist/host-kit/verifier.d.ts.map +1 -1
- package/dist/host-kit/verifier.js +51 -119
- package/dist/host-kit/verifier.js.map +1 -1
- package/dist/http-body.d.ts +20 -0
- package/dist/http-body.d.ts.map +1 -0
- package/dist/http-body.js +67 -0
- package/dist/http-body.js.map +1 -0
- package/dist/schedules/index.d.ts +3 -2
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +5 -4
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/router.d.ts +16 -10
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +153 -91
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +88 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +411 -50
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/target-policy.d.ts +29 -0
- package/dist/schedules/target-policy.d.ts.map +1 -0
- package/dist/schedules/target-policy.js +70 -0
- package/dist/schedules/target-policy.js.map +1 -0
- package/dist/schedules/tick.d.ts +125 -21
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +637 -160
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +0 -19
- package/dist/signal-providers/delivery.d.ts.map +1 -1
- package/dist/signal-providers/delivery.js +5 -54
- package/dist/signal-providers/delivery.js.map +1 -1
- package/dist/signal-providers/github-provider.d.ts.map +1 -1
- package/dist/signal-providers/github-provider.js +9 -16
- package/dist/signal-providers/github-provider.js.map +1 -1
- package/dist/signal-providers/host-do.d.ts +3 -45
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +86 -106
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/host-topology.d.ts +5 -14
- package/dist/signal-providers/host-topology.d.ts.map +1 -1
- package/dist/signal-providers/host-topology.js +11 -25
- package/dist/signal-providers/host-topology.js.map +1 -1
- package/dist/signal-providers/index.d.ts +3 -3
- package/dist/signal-providers/index.d.ts.map +1 -1
- package/dist/signal-providers/index.js +3 -3
- package/dist/signal-providers/index.js.map +1 -1
- package/dist/signal-providers/provider.d.ts +4 -5
- package/dist/signal-providers/provider.d.ts.map +1 -1
- package/dist/signal-providers/provider.js +5 -6
- package/dist/signal-providers/provider.js.map +1 -1
- package/dist/signal-providers/subscription-d1.d.ts +10 -57
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
- package/dist/signal-providers/subscription-d1.js +208 -155
- package/dist/signal-providers/subscription-d1.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +28 -14
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +117 -88
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/client.js +8 -8
- package/dist/signals/client.js.map +1 -1
- package/dist/signals/d1-shared.js +1 -1
- package/dist/signals/d1-shared.js.map +1 -1
- package/dist/signals/index.d.ts +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +12 -6
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +37 -21
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +5 -8
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +8 -13
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +10 -10
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -51
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +74 -15
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +484 -41
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/dist/signals/thread-state-d1.d.ts.map +1 -1
- package/dist/signals/thread-state-d1.js +2 -3
- package/dist/signals/thread-state-d1.js.map +1 -1
- package/package.json +30 -7
- package/scripts/seed-deployment-identity.mjs +252 -0
- package/dist/approval-api/tenant-brand.d.ts +0 -35
- package/dist/approval-api/tenant-brand.d.ts.map +0 -1
- package/dist/approval-api/tenant-brand.js +0 -19
- package/dist/approval-api/tenant-brand.js.map +0 -1
- package/dist/approval-api/tenant-context.d.ts +0 -84
- package/dist/approval-api/tenant-context.d.ts.map +0 -1
- package/dist/approval-api/tenant-context.js +0 -112
- package/dist/approval-api/tenant-context.js.map +0 -1
- package/dist/approval-api/tenant-store.d.ts +0 -36
- package/dist/approval-api/tenant-store.d.ts.map +0 -1
- package/dist/approval-api/tenant-store.js +0 -129
- package/dist/approval-api/tenant-store.js.map +0 -1
- package/dist/do-runner/resume-ledger.d.ts +0 -48
- package/dist/do-runner/resume-ledger.d.ts.map +0 -1
- package/dist/do-runner/resume-ledger.js +0 -60
- package/dist/do-runner/resume-ledger.js.map +0 -1
- package/dist/do-runner/thread-header.d.ts +0 -31
- package/dist/do-runner/thread-header.d.ts.map +0 -1
- package/dist/do-runner/thread-header.js +0 -39
- package/dist/do-runner/thread-header.js.map +0 -1
- package/dist/host-kit/subdomain-check.d.ts +0 -23
- package/dist/host-kit/subdomain-check.d.ts.map +0 -1
- package/dist/host-kit/subdomain-check.js +0 -61
- package/dist/host-kit/subdomain-check.js.map +0 -1
- package/dist/host-kit/tenant-registry.d.ts +0 -51
- package/dist/host-kit/tenant-registry.d.ts.map +0 -1
- package/dist/host-kit/tenant-registry.js +0 -88
- package/dist/host-kit/tenant-registry.js.map +0 -1
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Deployment-local resource ownership. Physical deployment isolation removes
|
|
3
|
+
// cross-organization predicates; this registry retains the independent
|
|
4
|
+
// user-to-user boundary for opaque run/thread/schedule ids and validated
|
|
5
|
+
// host-owned resource keys.
|
|
6
|
+
import { isPathSafeId } from '../do-runner/path-safe-id.js';
|
|
7
|
+
import { assertExecutionPrincipal, isExecutionPrincipalId, isExecutionPrincipalKind, } from './principal.js';
|
|
8
|
+
export const RESOURCE_KINDS = [
|
|
9
|
+
'run',
|
|
10
|
+
'thread',
|
|
11
|
+
'resource',
|
|
12
|
+
'schedule',
|
|
13
|
+
];
|
|
14
|
+
export class ResourceOwnershipError extends Error {
|
|
15
|
+
constructor(kind, resourceId) {
|
|
16
|
+
super(`${kind} '${resourceId}' is unavailable or owned by another principal`);
|
|
17
|
+
this.name = 'ResourceOwnershipError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function canonicalResourceKind(kind) {
|
|
21
|
+
if (typeof kind !== 'string' ||
|
|
22
|
+
!RESOURCE_KINDS.includes(kind)) {
|
|
23
|
+
throw new Error('resource kind is invalid');
|
|
24
|
+
}
|
|
25
|
+
return kind;
|
|
26
|
+
}
|
|
27
|
+
function canonicalResourceId(resourceId) {
|
|
28
|
+
if (!isPathSafeId(resourceId)) {
|
|
29
|
+
throw new Error('resource id must be path-safe');
|
|
30
|
+
}
|
|
31
|
+
return resourceId;
|
|
32
|
+
}
|
|
33
|
+
function ownDataField(value, key) {
|
|
34
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
35
|
+
return descriptor !== undefined && 'value' in descriptor
|
|
36
|
+
? descriptor.value
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
export function canonicalResourceOwner(owner) {
|
|
40
|
+
if (owner === null || typeof owner !== 'object') {
|
|
41
|
+
throw new Error('resource owner must be a valid execution principal');
|
|
42
|
+
}
|
|
43
|
+
const kind = ownDataField(owner, 'kind');
|
|
44
|
+
const id = ownDataField(owner, 'id');
|
|
45
|
+
if (!isExecutionPrincipalKind(kind) || !isExecutionPrincipalId(id)) {
|
|
46
|
+
throw new Error('resource owner must be a valid execution principal');
|
|
47
|
+
}
|
|
48
|
+
return Object.freeze({ kind, id });
|
|
49
|
+
}
|
|
50
|
+
function canonicalClaims(claims) {
|
|
51
|
+
if (!Array.isArray(claims))
|
|
52
|
+
throw new Error('resource claims must be an array');
|
|
53
|
+
const unique = new Set();
|
|
54
|
+
return Array.from(claims, (claim) => {
|
|
55
|
+
if (claim === null || typeof claim !== 'object') {
|
|
56
|
+
throw new Error('resource claim is invalid');
|
|
57
|
+
}
|
|
58
|
+
const kind = canonicalResourceKind(ownDataField(claim, 'kind'));
|
|
59
|
+
const resourceId = canonicalResourceId(ownDataField(claim, 'resourceId'));
|
|
60
|
+
const key = `${kind}:${resourceId}`;
|
|
61
|
+
if (unique.has(key))
|
|
62
|
+
throw new Error(`duplicate resource claim '${key}'`);
|
|
63
|
+
unique.add(key);
|
|
64
|
+
return Object.freeze({ kind, resourceId });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function sameOwner(left, right) {
|
|
68
|
+
return left.kind === right.kind && left.id === right.id;
|
|
69
|
+
}
|
|
70
|
+
export const RESOURCE_OWNERSHIP_TABLE = 'flowsafe_resource_owners';
|
|
71
|
+
const SCHEMA = `CREATE TABLE IF NOT EXISTS ${RESOURCE_OWNERSHIP_TABLE} (
|
|
72
|
+
resource_kind TEXT NOT NULL CHECK (resource_kind IN ('run', 'thread', 'resource', 'schedule')),
|
|
73
|
+
resource_id TEXT NOT NULL,
|
|
74
|
+
owner_kind TEXT NOT NULL CHECK (owner_kind IN ('human', 'service', 'agent', 'system')),
|
|
75
|
+
owner_id TEXT NOT NULL,
|
|
76
|
+
reservation_token TEXT,
|
|
77
|
+
PRIMARY KEY (resource_kind, resource_id)
|
|
78
|
+
)`;
|
|
79
|
+
export async function createResourceOwnershipSchema(db) {
|
|
80
|
+
await db.prepare(SCHEMA).run();
|
|
81
|
+
}
|
|
82
|
+
function ownerFromRow(row) {
|
|
83
|
+
if (row === null)
|
|
84
|
+
return undefined;
|
|
85
|
+
try {
|
|
86
|
+
return canonicalResourceOwner({
|
|
87
|
+
kind: row.owner_kind,
|
|
88
|
+
id: row.owner_id,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export class D1ResourceOwnershipStore {
|
|
96
|
+
#db;
|
|
97
|
+
#ready;
|
|
98
|
+
constructor(db, options = {}) {
|
|
99
|
+
this.#db = db;
|
|
100
|
+
if (options.ready) {
|
|
101
|
+
this.#ready = options.ready;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
let ready;
|
|
105
|
+
this.#ready = () => {
|
|
106
|
+
ready ??= createResourceOwnershipSchema(db).catch((error) => {
|
|
107
|
+
ready = undefined;
|
|
108
|
+
throw error;
|
|
109
|
+
});
|
|
110
|
+
return ready;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async claim(kind, resourceId, owner) {
|
|
115
|
+
const safeKind = canonicalResourceKind(kind);
|
|
116
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
117
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
118
|
+
await this.#ready();
|
|
119
|
+
await this.#db
|
|
120
|
+
.prepare(`INSERT OR IGNORE INTO ${RESOURCE_OWNERSHIP_TABLE}
|
|
121
|
+
(resource_kind, resource_id, owner_kind, owner_id)
|
|
122
|
+
VALUES (?, ?, ?, ?)`)
|
|
123
|
+
.bind(safeKind, safeResourceId, safeOwner.kind, safeOwner.id)
|
|
124
|
+
.run();
|
|
125
|
+
const stored = await this.owner(safeKind, safeResourceId);
|
|
126
|
+
return stored !== undefined && sameOwner(stored, safeOwner);
|
|
127
|
+
}
|
|
128
|
+
async reserveAll(claims, owner, token) {
|
|
129
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
130
|
+
const safeToken = canonicalResourceId(token);
|
|
131
|
+
const safeClaims = canonicalClaims(claims);
|
|
132
|
+
if (safeClaims.length === 0)
|
|
133
|
+
return true;
|
|
134
|
+
await this.#ready();
|
|
135
|
+
const requested = safeClaims.map(() => '(?, ?)').join(', ');
|
|
136
|
+
await this.#db
|
|
137
|
+
.prepare(`WITH requested(resource_kind, resource_id) AS (VALUES ${requested})
|
|
138
|
+
INSERT OR IGNORE INTO ${RESOURCE_OWNERSHIP_TABLE}
|
|
139
|
+
(resource_kind, resource_id, owner_kind, owner_id, reservation_token)
|
|
140
|
+
SELECT resource_kind, resource_id, ?, ?, ? FROM requested
|
|
141
|
+
WHERE NOT EXISTS (
|
|
142
|
+
SELECT 1 FROM requested AS candidate
|
|
143
|
+
JOIN ${RESOURCE_OWNERSHIP_TABLE} AS existing
|
|
144
|
+
ON existing.resource_kind = candidate.resource_kind
|
|
145
|
+
AND existing.resource_id = candidate.resource_id
|
|
146
|
+
WHERE existing.owner_kind <> ? OR existing.owner_id <> ?
|
|
147
|
+
OR (existing.reservation_token IS NOT NULL
|
|
148
|
+
AND existing.reservation_token <> ?)
|
|
149
|
+
)`)
|
|
150
|
+
.bind(...safeClaims.flatMap((claim) => [claim.kind, claim.resourceId]), safeOwner.kind, safeOwner.id, safeToken, safeOwner.kind, safeOwner.id, safeToken)
|
|
151
|
+
.run();
|
|
152
|
+
for (const claim of safeClaims) {
|
|
153
|
+
const row = await this.#db
|
|
154
|
+
.prepare(`SELECT owner_kind, owner_id, reservation_token
|
|
155
|
+
FROM ${RESOURCE_OWNERSHIP_TABLE}
|
|
156
|
+
WHERE resource_kind = ? AND resource_id = ?`)
|
|
157
|
+
.bind(claim.kind, claim.resourceId)
|
|
158
|
+
.first();
|
|
159
|
+
const stored = ownerFromRow(row);
|
|
160
|
+
if (!stored ||
|
|
161
|
+
!sameOwner(stored, safeOwner) ||
|
|
162
|
+
(row?.reservation_token != null && row.reservation_token !== safeToken)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
async settleReservation(token, release) {
|
|
169
|
+
const safeToken = canonicalResourceId(token);
|
|
170
|
+
const safeRelease = canonicalClaims(release);
|
|
171
|
+
await this.#ready();
|
|
172
|
+
const batch = this.#db.batch?.bind(this.#db);
|
|
173
|
+
if (!batch) {
|
|
174
|
+
throw new Error('settleReservation requires database.batch() for atomic recovery');
|
|
175
|
+
}
|
|
176
|
+
const statements = [];
|
|
177
|
+
for (const claim of safeRelease) {
|
|
178
|
+
statements.push(this.#db
|
|
179
|
+
.prepare(`DELETE FROM ${RESOURCE_OWNERSHIP_TABLE}
|
|
180
|
+
WHERE resource_kind = ? AND resource_id = ?
|
|
181
|
+
AND reservation_token = ?`)
|
|
182
|
+
.bind(claim.kind, claim.resourceId, safeToken));
|
|
183
|
+
}
|
|
184
|
+
statements.push(this.#db
|
|
185
|
+
.prepare(`UPDATE ${RESOURCE_OWNERSHIP_TABLE}
|
|
186
|
+
SET reservation_token = NULL
|
|
187
|
+
WHERE reservation_token = ?`)
|
|
188
|
+
.bind(safeToken));
|
|
189
|
+
await batch(statements);
|
|
190
|
+
}
|
|
191
|
+
async owner(kind, resourceId) {
|
|
192
|
+
const safeKind = canonicalResourceKind(kind);
|
|
193
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
194
|
+
await this.#ready();
|
|
195
|
+
const row = await this.#db
|
|
196
|
+
.prepare(`SELECT owner_kind, owner_id FROM ${RESOURCE_OWNERSHIP_TABLE}
|
|
197
|
+
WHERE resource_kind = ? AND resource_id = ?
|
|
198
|
+
AND reservation_token IS NULL`)
|
|
199
|
+
.bind(safeKind, safeResourceId)
|
|
200
|
+
.first();
|
|
201
|
+
return ownerFromRow(row);
|
|
202
|
+
}
|
|
203
|
+
async release(kind, resourceId, owner) {
|
|
204
|
+
const safeKind = canonicalResourceKind(kind);
|
|
205
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
206
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
207
|
+
await this.#ready();
|
|
208
|
+
const result = (await this.#db
|
|
209
|
+
.prepare(`DELETE FROM ${RESOURCE_OWNERSHIP_TABLE}
|
|
210
|
+
WHERE resource_kind = ? AND resource_id = ?
|
|
211
|
+
AND owner_kind = ? AND owner_id = ?
|
|
212
|
+
AND reservation_token IS NULL`)
|
|
213
|
+
.bind(safeKind, safeResourceId, safeOwner.kind, safeOwner.id)
|
|
214
|
+
.run());
|
|
215
|
+
return Number(result.meta?.changes ?? 0) > 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export class InMemoryResourceOwnershipStore {
|
|
219
|
+
#owners = new Map();
|
|
220
|
+
#reservations = new Map();
|
|
221
|
+
async claim(kind, resourceId, owner) {
|
|
222
|
+
const safeKind = canonicalResourceKind(kind);
|
|
223
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
224
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
225
|
+
const key = `${safeKind}:${safeResourceId}`;
|
|
226
|
+
const stored = this.#owners.get(key);
|
|
227
|
+
if (stored) {
|
|
228
|
+
return !this.#reservations.has(key) && sameOwner(stored, safeOwner);
|
|
229
|
+
}
|
|
230
|
+
this.#owners.set(key, safeOwner);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
async reserveAll(claims, owner, token) {
|
|
234
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
235
|
+
const safeToken = canonicalResourceId(token);
|
|
236
|
+
const safeClaims = canonicalClaims(claims);
|
|
237
|
+
for (const claim of safeClaims) {
|
|
238
|
+
const key = `${claim.kind}:${claim.resourceId}`;
|
|
239
|
+
const stored = this.#owners.get(key);
|
|
240
|
+
if (stored && !sameOwner(stored, safeOwner))
|
|
241
|
+
return false;
|
|
242
|
+
const reservedBy = this.#reservations.get(key);
|
|
243
|
+
if (reservedBy !== undefined && reservedBy !== safeToken)
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
for (const claim of safeClaims) {
|
|
247
|
+
const key = `${claim.kind}:${claim.resourceId}`;
|
|
248
|
+
if (!this.#owners.has(key)) {
|
|
249
|
+
this.#owners.set(key, safeOwner);
|
|
250
|
+
this.#reservations.set(key, safeToken);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
async settleReservation(token, release) {
|
|
256
|
+
const safeToken = canonicalResourceId(token);
|
|
257
|
+
const safeRelease = canonicalClaims(release);
|
|
258
|
+
const released = new Set(safeRelease.map((claim) => `${claim.kind}:${claim.resourceId}`));
|
|
259
|
+
for (const [key, reservedBy] of this.#reservations) {
|
|
260
|
+
if (reservedBy !== safeToken)
|
|
261
|
+
continue;
|
|
262
|
+
if (released.has(key))
|
|
263
|
+
this.#owners.delete(key);
|
|
264
|
+
this.#reservations.delete(key);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async owner(kind, resourceId) {
|
|
268
|
+
const safeKind = canonicalResourceKind(kind);
|
|
269
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
270
|
+
const key = `${safeKind}:${safeResourceId}`;
|
|
271
|
+
if (this.#reservations.has(key))
|
|
272
|
+
return undefined;
|
|
273
|
+
const stored = this.#owners.get(key);
|
|
274
|
+
return stored;
|
|
275
|
+
}
|
|
276
|
+
async release(kind, resourceId, owner) {
|
|
277
|
+
const safeKind = canonicalResourceKind(kind);
|
|
278
|
+
const safeResourceId = canonicalResourceId(resourceId);
|
|
279
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
280
|
+
const key = `${safeKind}:${safeResourceId}`;
|
|
281
|
+
if (this.#reservations.has(key))
|
|
282
|
+
return false;
|
|
283
|
+
const stored = this.#owners.get(key);
|
|
284
|
+
if (!stored || !sameOwner(stored, safeOwner))
|
|
285
|
+
return false;
|
|
286
|
+
return this.#owners.delete(key);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export async function requireResourceOwner(resources, kind, resourceId) {
|
|
290
|
+
const owner = await resources.owner(kind, resourceId);
|
|
291
|
+
if (!owner)
|
|
292
|
+
throw new Error(`${kind} '${resourceId}' has no registered owner`);
|
|
293
|
+
return owner;
|
|
294
|
+
}
|
|
295
|
+
export async function requireCommonResourceOwner(resources, claims) {
|
|
296
|
+
const safeClaims = canonicalClaims(claims);
|
|
297
|
+
if (safeClaims.length === 0) {
|
|
298
|
+
throw new Error('at least one registered resource is required');
|
|
299
|
+
}
|
|
300
|
+
const first = safeClaims[0];
|
|
301
|
+
const owner = await requireResourceOwner(resources, first.kind, first.resourceId);
|
|
302
|
+
for (const claim of safeClaims.slice(1)) {
|
|
303
|
+
const candidate = await requireResourceOwner(resources, claim.kind, claim.resourceId);
|
|
304
|
+
if (!sameOwner(owner, candidate)) {
|
|
305
|
+
throw new Error('registered resources do not share one owner');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return owner;
|
|
309
|
+
}
|
|
310
|
+
export function principalOwner(principal) {
|
|
311
|
+
const safePrincipal = assertExecutionPrincipal(principal, 'resource owner principal');
|
|
312
|
+
return Object.freeze({ kind: safePrincipal.kind, id: safePrincipal.id });
|
|
313
|
+
}
|
|
314
|
+
export function principalMayAccess(principal, owner, access) {
|
|
315
|
+
const safePrincipal = assertExecutionPrincipal(principal, 'resource access principal');
|
|
316
|
+
const safeOwner = canonicalResourceOwner(owner);
|
|
317
|
+
if (access !== 'read' && access !== 'write') {
|
|
318
|
+
throw new Error('resource access mode is invalid');
|
|
319
|
+
}
|
|
320
|
+
if (sameOwner(safePrincipal, safeOwner))
|
|
321
|
+
return true;
|
|
322
|
+
if (safePrincipal.kind !== 'human')
|
|
323
|
+
return false;
|
|
324
|
+
if (safePrincipal.role === 'admin')
|
|
325
|
+
return true;
|
|
326
|
+
return (access === 'read' &&
|
|
327
|
+
(safePrincipal.role === 'reviewer' || safePrincipal.role === 'viewer'));
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=resource-ownership.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-ownership.js","sourceRoot":"","sources":["../../src/approval-api/resource-ownership.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,uEAAuE;AACvE,yEAAyE;AACzE,4BAA4B;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAK5D,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM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MAAM,UAAU,cAAc,CAAC,SAA6B;IAC1D,MAAM,aAAa,GAAG,wBAAwB,CAC5C,SAAS,EACT,0BAA0B,CAC3B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,SAA6B,EAC7B,KAAoB,EACpB,MAAsB;IAEtB,MAAM,aAAa,GAAG,wBAAwB,CAC5C,SAAS,EACT,2BAA2B,CAC5B,CAAC;IACF,MAAM,SAAS,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,SAAS,CAAC,aAAa,EAAE,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,aAAa,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACjD,IAAI,aAAa,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,CACL,MAAM,KAAK,MAAM;QACjB,CAAC,aAAa,CAAC,IAAI,KAAK,UAAU,IAAI,aAAa,CAAC,IAAI,KAAK,QAAQ,CAAC,CACvE,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApprovalStore } from './store.js';
|
|
2
2
|
export interface PurgeExpiredApprovalsOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Decided (approved/rejected) records whose terminal timestamp — decidedAt,
|
|
@@ -6,8 +6,7 @@ export interface PurgeExpiredApprovalsOptions {
|
|
|
6
6
|
* than this are eligible. Open requests (pending/claimed/escalated) are
|
|
7
7
|
* NEVER purged at any age: an approval still awaiting a decision is not
|
|
8
8
|
* garbage (mirrors purgeExpiredWorkflowRuns' "live runs are never
|
|
9
|
-
* purged").
|
|
10
|
-
* by purgeTenant() at offboarding.
|
|
9
|
+
* purged").
|
|
11
10
|
*/
|
|
12
11
|
ttlMs: number;
|
|
13
12
|
/** Injectable clock (tests, deterministic TTL math). Default: Date.now. */
|
|
@@ -20,13 +19,9 @@ export interface PurgeExpiredApprovalsOptions {
|
|
|
20
19
|
limit?: number;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
* Deletes decided approval records past their retention TTL
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* would be the same IDOR-shaped hole sweepSLA's doc comment describes for an
|
|
27
|
-
* HTTP-reachable sweep. The distinct SystemApprovalStore parameter type
|
|
28
|
-
* makes "cross-tenant deletes happen only inside the TCB" a compile-time
|
|
29
|
-
* property, not a convention. Returns the number of deleted records.
|
|
22
|
+
* Deletes decided approval records past their retention TTL. Trusted
|
|
23
|
+
* maintenance code — deliberately not a service method or HTTP route. Returns
|
|
24
|
+
* the number of deleted records.
|
|
30
25
|
*/
|
|
31
|
-
export declare function purgeExpiredApprovals(store:
|
|
26
|
+
export declare function purgeExpiredApprovals(store: ApprovalStore, options: PurgeExpiredApprovalsOptions): Promise<number>;
|
|
32
27
|
//# sourceMappingURL=retention.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../src/approval-api/retention.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../src/approval-api/retention.ts"],"names":[],"mappings":"AAoDA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
//
|
|
2
|
+
// Alarm-owned approval-queue retention purge (2026-07-11 audit, D3) — the
|
|
3
3
|
// approvals analog of do-runner's purgeExpiredWorkflowRuns
|
|
4
4
|
// (do-runner/d1-storage.ts), structured like sweepSLA (service.ts): a free
|
|
5
|
-
// function over the
|
|
6
|
-
// request scope by type, never a service method, never an HTTP route.
|
|
5
|
+
// function over the deployment store, never a service method or HTTP route.
|
|
7
6
|
//
|
|
8
7
|
// TERMINAL-TIMESTAMP CHOICE: a decided (approved/rejected) record's terminal
|
|
9
8
|
// instant is decidedAt — service.ts's decide() always stamps decidedAt and
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
// CURRENT suspension fingerprint, requiring a NEW decision — deliberately:
|
|
36
35
|
// an approval that aged past retention should not silently re-arm the grant
|
|
37
36
|
// it already spent. One separation-of-duties relaxation applies only in this
|
|
38
|
-
// recovery path: the re-filed record's requestedBy is the system
|
|
37
|
+
// recovery path: the re-filed record's requestedBy is the system principal
|
|
39
38
|
// rather than a human, so the reviewer who decided the purged record MAY
|
|
40
39
|
// legally decide its replacement — there is no human "who advanced the run
|
|
41
40
|
// to this suspension" left to attribute it to. Operators should still set
|
|
@@ -51,13 +50,9 @@
|
|
|
51
50
|
// superseded record is excluded from grant derivation by its STATUS alone,
|
|
52
51
|
// the same guarantee this purge relies on for a decided-then-purged record.
|
|
53
52
|
/**
|
|
54
|
-
* Deletes decided approval records past their retention TTL
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* would be the same IDOR-shaped hole sweepSLA's doc comment describes for an
|
|
58
|
-
* HTTP-reachable sweep. The distinct SystemApprovalStore parameter type
|
|
59
|
-
* makes "cross-tenant deletes happen only inside the TCB" a compile-time
|
|
60
|
-
* property, not a convention. Returns the number of deleted records.
|
|
53
|
+
* Deletes decided approval records past their retention TTL. Trusted
|
|
54
|
+
* maintenance code — deliberately not a service method or HTTP route. Returns
|
|
55
|
+
* the number of deleted records.
|
|
61
56
|
*/
|
|
62
57
|
export async function purgeExpiredApprovals(store, options) {
|
|
63
58
|
// Validated here so BOTH backends inherit it: a negative ttlMs turns the
|
|
@@ -65,7 +60,7 @@ export async function purgeExpiredApprovals(store, options) {
|
|
|
65
60
|
// old ones, and a negative limit diverges by backend — the in-memory
|
|
66
61
|
// purge's `purged >= limit` guard never fires (no-op), while D1's `LIMIT
|
|
67
62
|
// -1` is unbounded (SQLite treats a negative LIMIT as "no limit"), turning
|
|
68
|
-
// a batch cap into
|
|
63
|
+
// a batch cap into an unbounded DELETE. limit: 0 (no-op) and
|
|
69
64
|
// ttlMs: 0 (purge decided approvals now) stay valid — both are real
|
|
70
65
|
// operator intents (see numberVar's allowZero convention).
|
|
71
66
|
if (!Number.isFinite(options.ttlMs) || options.ttlMs < 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/approval-api/retention.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/approval-api/retention.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,2DAA2D;AAC3D,2EAA2E;AAC3E,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,6BAA6B;AAC7B,EAAE;AACF,oEAAoE;AACpE,8DAA8D;AAC9D,6EAA6E;AAC7E,yEAAyE;AACzE,sEAAsE;AACtE,8EAA8E;AAC9E,qD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CAAC,WAAW,EAAE,CAAC;IAChE,OAAO,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ActorResolver } from './actor-context.js';
|
|
2
2
|
/**
|
|
3
3
|
* Fields on CreateApprovalInput that select CAPABILITY or ATTRIBUTION, and so
|
|
4
4
|
* belong to the trusted computing base alone (security-threat-model.md, trust
|
|
@@ -15,8 +15,10 @@ import { type TenantResolver } from './tenant-context.js';
|
|
|
15
15
|
* future trusted merge must never inherit client-selected identity.
|
|
16
16
|
* - `requestedBy` is the field decide()'s separation-of-duties check compares
|
|
17
17
|
* against; spoofing it lets one principal approve their own request.
|
|
18
|
+
* - `requestedByKind` distinguishes a human requester from automation with
|
|
19
|
+
* the same id and is therefore equally trust-sensitive.
|
|
18
20
|
*/
|
|
19
|
-
export declare const TCB_ONLY_CREATE_FIELDS: readonly ["connectors", "grantScope", "toolCallId", "stepPath", "suspendedAt", "resumedAt", "resumeCount", "runScoped", "requestedBy", "resumeTarget"];
|
|
21
|
+
export declare const TCB_ONLY_CREATE_FIELDS: readonly ["connectors", "grantScope", "toolCallId", "stepPath", "suspendedAt", "resumedAt", "resumeCount", "runScoped", "requestedBy", "requestedByKind", "resumeTarget"];
|
|
20
22
|
/**
|
|
21
23
|
* The complement: what a request body MAY set. The create route copies ONLY
|
|
22
24
|
* these fields off the body — an allowlist, so a field added to
|
|
@@ -30,12 +32,10 @@ export declare const TCB_ONLY_CREATE_FIELDS: readonly ["connectors", "grantScope
|
|
|
30
32
|
export declare const CLIENT_CREATE_FIELDS: readonly ["workflowId", "runId", "title", "summary", "payload", "priority", "slaSeconds"];
|
|
31
33
|
export interface ApprovalRouterOptions {
|
|
32
34
|
/**
|
|
33
|
-
* Authenticates the request
|
|
34
|
-
*
|
|
35
|
-
* wraps is constructed AFTER authentication, bound to the actor's tenant —
|
|
36
|
-
* there is no pre-auth service to leak through. undefined yields 401.
|
|
35
|
+
* Authenticates the request before exposing the service. undefined yields
|
|
36
|
+
* 401.
|
|
37
37
|
*/
|
|
38
|
-
resolve:
|
|
38
|
+
resolve: ActorResolver;
|
|
39
39
|
/** Route prefix. Default: '/api/approvals'. */
|
|
40
40
|
basePath?: string;
|
|
41
41
|
/**
|
|
@@ -44,7 +44,8 @@ export interface ApprovalRouterOptions {
|
|
|
44
44
|
* approval bridge), so the HTTP route is an inert "file a request"
|
|
45
45
|
* affordance at best. When enabled it force-sets `requestedBy` to the
|
|
46
46
|
* authenticated actor and 400s on any TCB_ONLY_CREATE_FIELDS member, so it
|
|
47
|
-
* can never author capability.
|
|
47
|
+
* can never author capability. The actor must also have write access to the
|
|
48
|
+
* named run; missing and foreign runs both yield 404.
|
|
48
49
|
*/
|
|
49
50
|
allowCreate?: boolean;
|
|
50
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAqB9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sBAAsB,2KAYzB,CAAC;AAEX;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,2FAW9B,CAAC;AAEJ,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAwJ5E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAoIhB"}
|
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
//
|
|
11
11
|
// The create route is OFF by default (allowCreate) and, when mounted, cannot
|
|
12
12
|
// author capability: it rejects every TCB_ONLY_CREATE_FIELDS member and
|
|
13
|
-
// force-attributes the request to the authenticated actor.
|
|
14
|
-
//
|
|
15
|
-
// from
|
|
13
|
+
// force-attributes the request to the authenticated actor. It also requires
|
|
14
|
+
// write access to the named run before touching the approval store. Approval
|
|
15
|
+
// records that carry grants are minted in-process from an observed suspension,
|
|
16
|
+
// never from a request body.
|
|
17
|
+
import { isPathSafeId } from '../do-runner/path-safe-id.js';
|
|
18
|
+
import { readBoundedBody } from '../http-body.js';
|
|
19
|
+
import { ActorResolutionError } from './actor-context.js';
|
|
16
20
|
import { ApprovalAuthzError, ApprovalConflictError, InvalidApprovalInputError, UnknownApprovalError, } from './service.js';
|
|
17
|
-
import { TenantResolutionError, } from './tenant-context.js';
|
|
18
21
|
import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVAL_LIST_LIMIT, parseApprovalCursor, parseApprovalTimeBound, } from './types.js';
|
|
19
22
|
/**
|
|
20
23
|
* Fields on CreateApprovalInput that select CAPABILITY or ATTRIBUTION, and so
|
|
@@ -32,6 +35,8 @@ import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVA
|
|
|
32
35
|
* future trusted merge must never inherit client-selected identity.
|
|
33
36
|
* - `requestedBy` is the field decide()'s separation-of-duties check compares
|
|
34
37
|
* against; spoofing it lets one principal approve their own request.
|
|
38
|
+
* - `requestedByKind` distinguishes a human requester from automation with
|
|
39
|
+
* the same id and is therefore equally trust-sensitive.
|
|
35
40
|
*/
|
|
36
41
|
export const TCB_ONLY_CREATE_FIELDS = [
|
|
37
42
|
'connectors',
|
|
@@ -43,6 +48,7 @@ export const TCB_ONLY_CREATE_FIELDS = [
|
|
|
43
48
|
'resumeCount',
|
|
44
49
|
'runScoped',
|
|
45
50
|
'requestedBy',
|
|
51
|
+
'requestedByKind',
|
|
46
52
|
'resumeTarget',
|
|
47
53
|
];
|
|
48
54
|
/**
|
|
@@ -64,6 +70,8 @@ export const CLIENT_CREATE_FIELDS = [
|
|
|
64
70
|
'priority',
|
|
65
71
|
'slaSeconds',
|
|
66
72
|
];
|
|
73
|
+
class ApprovalPayloadTooLargeError extends Error {
|
|
74
|
+
}
|
|
67
75
|
function json(payload, status = 200) {
|
|
68
76
|
return new Response(JSON.stringify(payload), {
|
|
69
77
|
status,
|
|
@@ -71,13 +79,15 @@ function json(payload, status = 200) {
|
|
|
71
79
|
});
|
|
72
80
|
}
|
|
73
81
|
function errorResponse(error) {
|
|
82
|
+
if (error instanceof ApprovalPayloadTooLargeError) {
|
|
83
|
+
return json({ error: error.message }, 413);
|
|
84
|
+
}
|
|
74
85
|
if (error instanceof InvalidApprovalInputError) {
|
|
75
86
|
return json({ error: error.message }, 400);
|
|
76
87
|
}
|
|
77
|
-
if (error instanceof
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
// reads as "try again". Forbidden, with the reason in the body.
|
|
88
|
+
if (error instanceof ActorResolutionError) {
|
|
89
|
+
// Invalid authenticated claims are a verifier bug, not a client 4xx it
|
|
90
|
+
// can fix. Fail closed without echoing claim details.
|
|
81
91
|
return json({ error: 'forbidden' }, 403);
|
|
82
92
|
}
|
|
83
93
|
if (error instanceof ApprovalAuthzError) {
|
|
@@ -93,9 +103,16 @@ function errorResponse(error) {
|
|
|
93
103
|
return json({ error: message }, 500);
|
|
94
104
|
}
|
|
95
105
|
async function readJsonObject(request) {
|
|
106
|
+
const raw = await readBoundedBody(request, 1_048_576, 'approval body exceeds limit');
|
|
107
|
+
if (!raw.ok && raw.reason === 'payload-too-large') {
|
|
108
|
+
throw new ApprovalPayloadTooLargeError('payload too large');
|
|
109
|
+
}
|
|
110
|
+
if (!raw.ok) {
|
|
111
|
+
throw new InvalidApprovalInputError('request body must be JSON');
|
|
112
|
+
}
|
|
96
113
|
let body;
|
|
97
114
|
try {
|
|
98
|
-
body =
|
|
115
|
+
body = JSON.parse(raw.text);
|
|
99
116
|
}
|
|
100
117
|
catch {
|
|
101
118
|
throw new InvalidApprovalInputError('request body must be JSON');
|
|
@@ -199,11 +216,11 @@ export function createApprovalRouter(options) {
|
|
|
199
216
|
.split('/')
|
|
200
217
|
.filter(Boolean);
|
|
201
218
|
try {
|
|
202
|
-
const
|
|
203
|
-
if (!
|
|
219
|
+
const context = await resolve(request);
|
|
220
|
+
if (!context)
|
|
204
221
|
return json({ error: 'authentication required' }, 401);
|
|
205
|
-
const actor =
|
|
206
|
-
const service =
|
|
222
|
+
const actor = context.actor;
|
|
223
|
+
const service = context.service();
|
|
207
224
|
if (request.method === 'GET') {
|
|
208
225
|
if (segments.length === 0) {
|
|
209
226
|
return json(await service.list(parseListFilter(url), actor));
|
|
@@ -230,18 +247,33 @@ export function createApprovalRouter(options) {
|
|
|
230
247
|
// in-process bridge (which legitimately attributes the human who
|
|
231
248
|
// advanced the run), so the tightening lives here at the HTTP
|
|
232
249
|
// boundary alone.
|
|
233
|
-
const input = {
|
|
250
|
+
const input = {
|
|
251
|
+
requestedBy: actor.id,
|
|
252
|
+
requestedByKind: 'human',
|
|
253
|
+
};
|
|
234
254
|
for (const field of CLIENT_CREATE_FIELDS) {
|
|
235
255
|
if (field in body)
|
|
236
256
|
input[field] = body[field];
|
|
237
257
|
}
|
|
258
|
+
const runId = input.runId;
|
|
259
|
+
if (typeof runId !== 'string' || runId.length === 0) {
|
|
260
|
+
throw new InvalidApprovalInputError('runId is required');
|
|
261
|
+
}
|
|
262
|
+
if (!isPathSafeId(runId)) {
|
|
263
|
+
throw new InvalidApprovalInputError(`runId '${runId}' is not path-safe — approvals bind to server-minted runs (INV-1)`);
|
|
264
|
+
}
|
|
265
|
+
// The optional public filing route may only attach a request to a
|
|
266
|
+
// run the authenticated principal may advance. Resolve ownership
|
|
267
|
+
// before touching the approval store: an unregistered id and a
|
|
268
|
+
// foreign id are the same 404, so this cannot become a run oracle.
|
|
269
|
+
if (!(await context.canAccessResource('run', runId, 'write'))) {
|
|
270
|
+
return json({ error: 'run not found' }, 404);
|
|
271
|
+
}
|
|
238
272
|
const { record, created } = await service.create(input, actor);
|
|
239
273
|
return json(record, created ? 201 : 200);
|
|
240
274
|
}
|
|
241
|
-
// NOTE: there is deliberately
|
|
242
|
-
//
|
|
243
|
-
// sweepSLA() function over a SystemApprovalStore, unreachable from
|
|
244
|
-
// request scope by type.
|
|
275
|
+
// NOTE: there is deliberately no /sla/sweep route. Maintenance calls
|
|
276
|
+
// sweepSLA() from trusted host code.
|
|
245
277
|
//
|
|
246
278
|
// Batch decide matches BEFORE the generic [id, action] arms — those
|
|
247
279
|
// would otherwise resolve this path as decide('batch') and 404.
|