@proofoftech/flowsafe 0.11.0 → 0.13.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 +54 -0
- package/README.md +91 -44
- 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.js +2 -2
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +2 -2
- package/dist/agent-host/index.d.ts.map +1 -1
- 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 +42 -8
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +533 -106
- 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 +3 -1
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +2 -0
- package/dist/agent-host/types.d.ts.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 +12 -23
- package/dist/approval-api/contract.d.ts.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 +8 -8
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +5 -5
- 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 +7 -5
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +7 -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 +51 -189
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +111 -362
- 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 +4 -7
- 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/table-prefix.d.ts +3 -0
- package/dist/do-runner/table-prefix.d.ts.map +1 -0
- package/dist/do-runner/table-prefix.js +17 -0
- package/dist/do-runner/table-prefix.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 +159 -80
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +629 -142
- 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 +29 -6
- 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
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
// of approval grants. decide() persists the decision; the grant provider
|
|
8
8
|
// (grants.ts) derives requestContext grants from approved records at
|
|
9
9
|
// start/resume. Nothing here ever reads capability data from client input.
|
|
10
|
-
import {
|
|
10
|
+
import { isPathSafeId } from '../do-runner/path-safe-id.js';
|
|
11
11
|
import { APPROVAL_ROLES, DECIDER_ROLES } from './contract.js';
|
|
12
|
-
import { canonicalAutomatedPrincipal,
|
|
13
|
-
import { listAllApprovedForRun } from './store.js';
|
|
14
|
-
import { APPROVAL_PRIORITIES, approvalCursor, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, } from './types.js';
|
|
12
|
+
import { canonicalApprovalActor, canonicalAutomatedPrincipal, EXECUTION_PRINCIPAL_KINDS, isExecutionPrincipalId, isExecutionPrincipalKind, isTrustedAutomationPrincipal, principalActor, principalAuditFields, } from './principal.js';
|
|
13
|
+
import { listAllApprovedForRun, } from './store.js';
|
|
14
|
+
import { APPROVAL_PRIORITIES, approvalCursor, canonicalApprovalResumeTarget, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, } from './types.js';
|
|
15
15
|
/** Requester failed role authorization — HTTP 403. */
|
|
16
16
|
export class ApprovalAuthzError extends Error {
|
|
17
17
|
constructor(message) {
|
|
@@ -56,7 +56,7 @@ export function selfDecisionExempts(policy, role) {
|
|
|
56
56
|
}
|
|
57
57
|
// Role policy from security-threat-model.md: reviewers decide, operators run
|
|
58
58
|
// the system, admins do both; every authenticated role may read. (The SLA
|
|
59
|
-
// sweep has no role: it is
|
|
59
|
+
// sweep has no role: it is maintenance-owned TCB code; see sweepSLA below.)
|
|
60
60
|
// CAN_REVIEW IS the exported DECIDER_ROLES — one source, so the run-router's
|
|
61
61
|
// canSelfDecide echo and this gate can never disagree on who may decide.
|
|
62
62
|
const CAN_REVIEW = DECIDER_ROLES;
|
|
@@ -73,14 +73,6 @@ export class ApprovalService {
|
|
|
73
73
|
#resumeRun;
|
|
74
74
|
#allowSelfDecision;
|
|
75
75
|
#now;
|
|
76
|
-
/**
|
|
77
|
-
* The tenant this service is bound to. Exposed so the host-kit bridges can
|
|
78
|
-
* mint their own bookkeeping principal against it instead of making every
|
|
79
|
-
* host construct one and vouch for it.
|
|
80
|
-
*/
|
|
81
|
-
get tenantId() {
|
|
82
|
-
return this.#store.tenantId;
|
|
83
|
-
}
|
|
84
76
|
constructor(options) {
|
|
85
77
|
this.#store = options.store;
|
|
86
78
|
this.#audit = options.audit;
|
|
@@ -92,8 +84,12 @@ export class ApprovalService {
|
|
|
92
84
|
this.#now = options.now ?? (() => new Date());
|
|
93
85
|
}
|
|
94
86
|
async create(input, actor, resumeTarget) {
|
|
95
|
-
this.#authorize(actor, CAN_CREATE, 'approval.create', 'approval');
|
|
96
|
-
|
|
87
|
+
const authorized = this.#authorize(actor, CAN_CREATE, 'approval.create', 'approval');
|
|
88
|
+
if (input.requestedByKind !== undefined &&
|
|
89
|
+
input.requestedByKind !== 'human') {
|
|
90
|
+
throw new InvalidApprovalInputError("human approval creation may only use requestedByKind 'human'");
|
|
91
|
+
}
|
|
92
|
+
return this.#createAuthorized(input, authorized, 'human', resumeTarget);
|
|
97
93
|
}
|
|
98
94
|
/**
|
|
99
95
|
* File an approval on behalf of an AUTOMATED principal — the trusted entry
|
|
@@ -104,7 +100,7 @@ export class ApprovalService {
|
|
|
104
100
|
* They cannot simply project onto a role instead: automated principals
|
|
105
101
|
* project to the least-privileged role precisely so they can never decide,
|
|
106
102
|
* and `viewer` is not in CAN_CREATE. So the role gate is replaced here — not
|
|
107
|
-
* widened — by a kind
|
|
103
|
+
* widened — by a trusted-kind check.
|
|
108
104
|
*
|
|
109
105
|
* There is deliberately NO principal-taking claim/decide/delegate. Filing a
|
|
110
106
|
* request is trusted platform work; deciding one is a human judgement, and an
|
|
@@ -113,9 +109,9 @@ export class ApprovalService {
|
|
|
113
109
|
*/
|
|
114
110
|
async createAsPrincipal(input, principal, resumeTarget) {
|
|
115
111
|
this.#authorizeAutomated(principal, 'approval.create', 'approval');
|
|
116
|
-
return this.#createAuthorized(input, principalActor(principal), resumeTarget, principalAuditFields(principal));
|
|
112
|
+
return this.#createAuthorized(input, principalActor(principal), principal.kind, resumeTarget, principalAuditFields(principal));
|
|
117
113
|
}
|
|
118
|
-
async #createAuthorized(input, actor, resumeTarget, provenance) {
|
|
114
|
+
async #createAuthorized(input, actor, defaultRequestedByKind, resumeTarget, provenance) {
|
|
119
115
|
this.#validateCreate(input);
|
|
120
116
|
const now = this.#now();
|
|
121
117
|
const slaSeconds = input.slaSeconds ?? this.#defaultSlaSeconds;
|
|
@@ -135,9 +131,6 @@ export class ApprovalService {
|
|
|
135
131
|
}
|
|
136
132
|
const record = {
|
|
137
133
|
id: crypto.randomUUID(),
|
|
138
|
-
// The bound store re-stamps this from its own field either way; setting
|
|
139
|
-
// it here keeps the literal honest for the type and the audit trail.
|
|
140
|
-
tenantId: this.#store.tenantId,
|
|
141
134
|
workflowId: input.workflowId,
|
|
142
135
|
runId: input.runId,
|
|
143
136
|
title: input.title,
|
|
@@ -169,20 +162,18 @@ export class ApprovalService {
|
|
|
169
162
|
if (input.payload !== undefined)
|
|
170
163
|
record.payload = input.payload;
|
|
171
164
|
if (resumeTarget !== undefined) {
|
|
172
|
-
this.#
|
|
173
|
-
record.resumeTarget = structuredClone(resumeTarget);
|
|
165
|
+
record.resumeTarget = this.#canonicalResumeTarget(resumeTarget);
|
|
174
166
|
}
|
|
175
|
-
// Attribution powers the self-approval check
|
|
176
|
-
//
|
|
177
|
-
// caller already holds a CAN_CREATE role either way.
|
|
167
|
+
// Attribution powers the self-approval check. Trusted bridges may file on
|
|
168
|
+
// behalf of the run requester; direct human creation defaults to its actor.
|
|
178
169
|
record.requestedBy = input.requestedBy ?? actor.id;
|
|
170
|
+
record.requestedByKind = input.requestedByKind ?? defaultRequestedByKind;
|
|
179
171
|
if (slaSeconds !== undefined) {
|
|
180
172
|
record.slaDeadlineAt = new Date(now.getTime() + slaSeconds * 1000).toISOString();
|
|
181
173
|
}
|
|
182
174
|
const result = await this.#store.create(record);
|
|
183
175
|
this.#record(actor, 'approval.create', `approval:${result.record.id}`, 'allowed', {
|
|
184
176
|
detail: {
|
|
185
|
-
tenantId: result.record.tenantId,
|
|
186
177
|
workflowId: result.record.workflowId,
|
|
187
178
|
runId: result.record.runId,
|
|
188
179
|
grantScope: result.record.grantScope,
|
|
@@ -200,11 +191,11 @@ export class ApprovalService {
|
|
|
200
191
|
// incident unreconstructable: the failures are the rows an operator reads.
|
|
201
192
|
fireNotification(this.#notify, { type: 'created', record: result.record }, (reason) => this.#record(actor, 'approval.notify', `approval:${result.record.id}`, 'error', {
|
|
202
193
|
reason,
|
|
203
|
-
detail: {
|
|
194
|
+
detail: { ...provenance },
|
|
204
195
|
}));
|
|
205
196
|
fireStreamEvent(this.#stream, { type: 'created', record: result.record }, (reason) => this.#record(actor, 'approval.stream', `approval:${result.record.id}`, 'error', {
|
|
206
197
|
reason,
|
|
207
|
-
detail: {
|
|
198
|
+
detail: { ...provenance },
|
|
208
199
|
}));
|
|
209
200
|
}
|
|
210
201
|
return result;
|
|
@@ -221,43 +212,42 @@ export class ApprovalService {
|
|
|
221
212
|
return this.#store.list(filter);
|
|
222
213
|
}
|
|
223
214
|
async claim(id, actor) {
|
|
224
|
-
this.#authorize(actor, CAN_REVIEW, 'approval.claim', `approval:${id}`);
|
|
215
|
+
const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.claim', `approval:${id}`);
|
|
225
216
|
const now = this.#now().toISOString();
|
|
226
217
|
// 'claimed' is deliberately not claimable — reassignment is delegate()'s
|
|
227
218
|
// job, so a claim can never silently steal another reviewer's item.
|
|
228
|
-
const updated = await this.#transitionOrExplain(id, 'claim',
|
|
219
|
+
const updated = await this.#transitionOrExplain(id, 'claim', authorized, {
|
|
229
220
|
from: ['pending', 'escalated'],
|
|
230
221
|
patch: {
|
|
231
222
|
status: 'claimed',
|
|
232
|
-
claimedBy:
|
|
223
|
+
claimedBy: authorized.id,
|
|
233
224
|
claimedAt: now,
|
|
234
225
|
updatedAt: now,
|
|
235
226
|
},
|
|
236
227
|
});
|
|
237
|
-
this.#record(
|
|
238
|
-
fireStreamEvent(this.#stream, { type: 'claimed', record: updated }, (reason) => this.#record(
|
|
228
|
+
this.#record(authorized, 'approval.claim', `approval:${id}`, 'allowed');
|
|
229
|
+
fireStreamEvent(this.#stream, { type: 'claimed', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
|
|
239
230
|
reason,
|
|
240
|
-
detail: { tenantId: updated.tenantId },
|
|
241
231
|
}));
|
|
242
232
|
return updated;
|
|
243
233
|
}
|
|
244
234
|
async decide(id, input, actor) {
|
|
245
|
-
this.#authorize(actor, CAN_REVIEW, 'approval.decide', `approval:${id}`);
|
|
235
|
+
const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.decide', `approval:${id}`);
|
|
246
236
|
this.#assertDecisionInput(input);
|
|
247
237
|
// Role-scoped SoD: an exempt decider (allowSelfDecision: true, or a role
|
|
248
238
|
// named in { roles }) skips the pre-read entirely; everyone else keeps
|
|
249
239
|
// today's read-then-CAS self-request denial.
|
|
250
|
-
if (!selfDecisionExempts(this.#allowSelfDecision,
|
|
240
|
+
if (!selfDecisionExempts(this.#allowSelfDecision, authorized.role)) {
|
|
251
241
|
const existing = await this.#store.get(id);
|
|
252
242
|
if (!existing)
|
|
253
243
|
throw new UnknownApprovalError(id);
|
|
254
|
-
// requestedBy
|
|
255
|
-
// TOCTOU hazard
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.#record(
|
|
244
|
+
// requestedBy and requestedByKind are immutable after create, so this
|
|
245
|
+
// read-then-CAS has no TOCTOU hazard. Missing kind denotes a legacy row
|
|
246
|
+
// and is treated as human: ambiguity must preserve the SoD bar, not let
|
|
247
|
+
// an old row become self-decidable after this field is introduced.
|
|
248
|
+
if (existing.requestedBy === authorized.id &&
|
|
249
|
+
(existing.requestedByKind ?? 'human') === 'human') {
|
|
250
|
+
this.#record(authorized, 'approval.decide', `approval:${id}`, 'denied', {
|
|
261
251
|
reason: 'self-approval: decider is the requester',
|
|
262
252
|
});
|
|
263
253
|
throw new ApprovalAuthzError('the requester cannot decide their own approval (separation of duties; set allowSelfDecision to permit)');
|
|
@@ -265,7 +255,7 @@ export class ApprovalService {
|
|
|
265
255
|
// Cross-gate causal SoD: a reviewer who APPROVED an earlier gate of THIS
|
|
266
256
|
// run advanced it to the gate now before them, so they must not also
|
|
267
257
|
// decide this one. requestedBy attribution cannot carry this on its own —
|
|
268
|
-
// reconcileApprovalsForSummary files the next gate as the SYSTEM
|
|
258
|
+
// reconcileApprovalsForSummary files the next gate as the SYSTEM principal,
|
|
269
259
|
// which the requestedBy check above never blocks — so the bar is derived
|
|
270
260
|
// from the run's own APPROVED history instead.
|
|
271
261
|
//
|
|
@@ -299,7 +289,7 @@ export class ApprovalService {
|
|
|
299
289
|
const barred = priorApproved.some((prior) => {
|
|
300
290
|
if (prior.id === existing.id)
|
|
301
291
|
return false;
|
|
302
|
-
if (prior.decidedBy !==
|
|
292
|
+
if (prior.decidedBy !== authorized.id)
|
|
303
293
|
return false;
|
|
304
294
|
if (typeof prior.decidedAt !== 'string')
|
|
305
295
|
return false;
|
|
@@ -307,7 +297,7 @@ export class ApprovalService {
|
|
|
307
297
|
return (Number.isNaN(priorAt) || Number.isNaN(gateAt) || priorAt <= gateAt);
|
|
308
298
|
});
|
|
309
299
|
if (barred) {
|
|
310
|
-
this.#record(
|
|
300
|
+
this.#record(authorized, 'approval.decide', `approval:${id}`, 'denied', {
|
|
311
301
|
reason: 'cross-gate separation of duties: this actor approved an earlier gate of the run',
|
|
312
302
|
});
|
|
313
303
|
throw new ApprovalAuthzError('the reviewer who advanced this run at an earlier gate cannot also decide this gate (separation of duties; set allowSelfDecision to permit)');
|
|
@@ -316,29 +306,29 @@ export class ApprovalService {
|
|
|
316
306
|
const now = this.#now().toISOString();
|
|
317
307
|
const patch = {
|
|
318
308
|
status: input.decision === 'approve' ? 'approved' : 'rejected',
|
|
319
|
-
decidedBy:
|
|
309
|
+
decidedBy: authorized.id,
|
|
320
310
|
decision: input.decision,
|
|
321
311
|
decidedAt: now,
|
|
322
312
|
updatedAt: now,
|
|
323
313
|
};
|
|
324
314
|
if (input.comment !== undefined)
|
|
325
315
|
patch.comment = input.comment;
|
|
326
|
-
const updated = await this.#transitionOrExplain(id, 'decide',
|
|
316
|
+
const updated = await this.#transitionOrExplain(id, 'decide', authorized, {
|
|
327
317
|
from: OPEN_STATUSES,
|
|
328
318
|
patch,
|
|
329
319
|
});
|
|
330
320
|
// Annotate a PERMITTED self-decision from the post-transition record (no
|
|
331
321
|
// extra read): an exercised SoD exemption must leave an audit trail. Fires
|
|
332
322
|
// for both a global `true` and a role-scoped exemption.
|
|
333
|
-
const selfDecision = updated.requestedBy ===
|
|
334
|
-
|
|
323
|
+
const selfDecision = updated.requestedBy === authorized.id &&
|
|
324
|
+
(updated.requestedByKind ?? 'human') === 'human';
|
|
325
|
+
this.#record(authorized, 'approval.decide', `approval:${id}`, 'allowed', {
|
|
335
326
|
detail: {
|
|
336
327
|
decision: input.decision,
|
|
337
328
|
// Queue dwell time (created -> decided), in seconds. Feeds the
|
|
338
329
|
// generic durationSeconds histogram convention breakwater's
|
|
339
330
|
// metricsAuditSink observes — any emitter may adopt the field.
|
|
340
331
|
durationSeconds: (Date.parse(now) - Date.parse(updated.createdAt)) / 1000,
|
|
341
|
-
tenantId: updated.tenantId,
|
|
342
332
|
workflowId: updated.workflowId,
|
|
343
333
|
runId: updated.runId,
|
|
344
334
|
grantScope: updated.grantScope,
|
|
@@ -361,11 +351,13 @@ export class ApprovalService {
|
|
|
361
351
|
// Fire the live-stream event AFTER the transition + audit and BEFORE
|
|
362
352
|
// #resume: the queue fan-out reflects the durable decision immediately,
|
|
363
353
|
// independent of whether the subsequent run resume succeeds.
|
|
364
|
-
fireStreamEvent(this.#stream, { type: 'decided', record: updated }, (reason) => this.#record(
|
|
354
|
+
fireStreamEvent(this.#stream, { type: 'decided', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
|
|
365
355
|
reason,
|
|
366
|
-
detail: { tenantId: updated.tenantId },
|
|
367
356
|
}));
|
|
368
|
-
return {
|
|
357
|
+
return {
|
|
358
|
+
record: updated,
|
|
359
|
+
resume: await this.#resume(updated, authorized),
|
|
360
|
+
};
|
|
369
361
|
}
|
|
370
362
|
/**
|
|
371
363
|
* Triage fan-out: apply ONE decision to up to MAX_APPROVAL_BATCH_DECIDE
|
|
@@ -381,7 +373,7 @@ export class ApprovalService {
|
|
|
381
373
|
* a batch is a reviewer clicking once, not a throughput path.
|
|
382
374
|
*/
|
|
383
375
|
async decideBatch(ids, input, actor) {
|
|
384
|
-
this.#authorize(actor, CAN_REVIEW, 'approval.decide', 'approval');
|
|
376
|
+
const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.decide', 'approval');
|
|
385
377
|
if (!Array.isArray(ids) || ids.length === 0) {
|
|
386
378
|
throw new InvalidApprovalInputError('ids must be a non-empty array of approval ids');
|
|
387
379
|
}
|
|
@@ -400,7 +392,7 @@ export class ApprovalService {
|
|
|
400
392
|
const results = [];
|
|
401
393
|
for (const id of unique) {
|
|
402
394
|
try {
|
|
403
|
-
const { record, resume } = await this.decide(id, input,
|
|
395
|
+
const { record, resume } = await this.decide(id, input, authorized);
|
|
404
396
|
results.push({ id, ok: true, record, resume });
|
|
405
397
|
}
|
|
406
398
|
catch (error) {
|
|
@@ -416,7 +408,7 @@ export class ApprovalService {
|
|
|
416
408
|
const failed = results.length - decided;
|
|
417
409
|
// Summary only — each decide() above already left its own per-record
|
|
418
410
|
// trail (allowed/denied), so this is the batch's one-line correlation.
|
|
419
|
-
this.#record(
|
|
411
|
+
this.#record(authorized, 'approval.decide.batch', 'approval', 'allowed', {
|
|
420
412
|
detail: { requested: unique.length, decided, failed },
|
|
421
413
|
});
|
|
422
414
|
return { results, decided, failed };
|
|
@@ -445,7 +437,7 @@ export class ApprovalService {
|
|
|
445
437
|
* reconcileApprovalsForSummary, itself only invoked from createRunRouter's
|
|
446
438
|
* optional reconcileApprovals hook on a status() read, never from a
|
|
447
439
|
* request body. Authorized like create() (CAN_CREATE, not CAN_REVIEW):
|
|
448
|
-
* the only
|
|
440
|
+
* the only principal that ever calls this is the same system principal create()
|
|
449
441
|
* already accepts for reconcile-filed records — superseding is the
|
|
450
442
|
* symmetric "un-file" half of that same self-healing operation, not a
|
|
451
443
|
* reviewer decision.
|
|
@@ -457,8 +449,8 @@ export class ApprovalService {
|
|
|
457
449
|
* contract sweepSLA uses for its own store-level CAS.
|
|
458
450
|
*/
|
|
459
451
|
async supersedeStale(id, actor, reason) {
|
|
460
|
-
this.#authorize(actor, CAN_CREATE, 'approval.supersede', `approval:${id}`);
|
|
461
|
-
return this.#supersedeAuthorized(id,
|
|
452
|
+
const authorized = this.#authorize(actor, CAN_CREATE, 'approval.supersede', `approval:${id}`);
|
|
453
|
+
return this.#supersedeAuthorized(id, authorized, reason);
|
|
462
454
|
}
|
|
463
455
|
/**
|
|
464
456
|
* Supersede on behalf of an AUTOMATED principal — the reconcile bridge's
|
|
@@ -488,7 +480,6 @@ export class ApprovalService {
|
|
|
488
480
|
this.#record(actor, 'approval.supersede', `approval:${id}`, 'allowed', {
|
|
489
481
|
reason,
|
|
490
482
|
detail: {
|
|
491
|
-
tenantId: updated.tenantId,
|
|
492
483
|
workflowId: updated.workflowId,
|
|
493
484
|
runId: updated.runId,
|
|
494
485
|
...provenance,
|
|
@@ -498,12 +489,12 @@ export class ApprovalService {
|
|
|
498
489
|
// is renamed so it does not shadow it.
|
|
499
490
|
fireStreamEvent(this.#stream, { type: 'superseded', record: updated }, (streamError) => this.#record(actor, 'approval.stream', `approval:${id}`, 'error', {
|
|
500
491
|
reason: streamError,
|
|
501
|
-
detail: {
|
|
492
|
+
detail: { ...provenance },
|
|
502
493
|
}));
|
|
503
494
|
return updated;
|
|
504
495
|
}
|
|
505
496
|
async delegate(id, input, actor) {
|
|
506
|
-
this.#authorize(actor, CAN_REVIEW, 'approval.delegate', `approval:${id}`);
|
|
497
|
+
const authorized = this.#authorize(actor, CAN_REVIEW, 'approval.delegate', `approval:${id}`);
|
|
507
498
|
if (!isNonEmptyString(input.to)) {
|
|
508
499
|
throw new InvalidApprovalInputError("delegate requires a non-empty 'to' reviewer id");
|
|
509
500
|
}
|
|
@@ -513,7 +504,7 @@ export class ApprovalService {
|
|
|
513
504
|
// assignee is the last write. Delegation is reassignment — unlike decide
|
|
514
505
|
// (mutual exclusion) or claim (no-steal), there is no side effect to
|
|
515
506
|
// protect, only a pointer to move.
|
|
516
|
-
const updated = await this.#transitionOrExplain(id, 'delegate',
|
|
507
|
+
const updated = await this.#transitionOrExplain(id, 'delegate', authorized, {
|
|
517
508
|
from: OPEN_STATUSES,
|
|
518
509
|
patch: {
|
|
519
510
|
status: 'claimed',
|
|
@@ -523,12 +514,11 @@ export class ApprovalService {
|
|
|
523
514
|
updatedAt: now,
|
|
524
515
|
},
|
|
525
516
|
});
|
|
526
|
-
this.#record(
|
|
517
|
+
this.#record(authorized, 'approval.delegate', `approval:${id}`, 'allowed', {
|
|
527
518
|
detail: { to: input.to },
|
|
528
519
|
});
|
|
529
|
-
fireStreamEvent(this.#stream, { type: 'delegated', record: updated }, (reason) => this.#record(
|
|
520
|
+
fireStreamEvent(this.#stream, { type: 'delegated', record: updated }, (reason) => this.#record(authorized, 'approval.stream', `approval:${id}`, 'error', {
|
|
530
521
|
reason,
|
|
531
|
-
detail: { tenantId: updated.tenantId },
|
|
532
522
|
}));
|
|
533
523
|
return updated;
|
|
534
524
|
}
|
|
@@ -557,7 +547,15 @@ export class ApprovalService {
|
|
|
557
547
|
throw new ApprovalConflictError(id, action, current.status);
|
|
558
548
|
}
|
|
559
549
|
async #resume(record, actor) {
|
|
560
|
-
|
|
550
|
+
// A plain queue record is a decision log, not proof that a suspended run
|
|
551
|
+
// exists. Only trusted in-process creation can author one of these three
|
|
552
|
+
// resumability anchors; the optional HTTP create route rejects all three.
|
|
553
|
+
// Without an anchor, calling resumeRun would turn an attacker-selected
|
|
554
|
+
// runId on an inert record into a target invocation after review.
|
|
555
|
+
const resumable = record.stepPath !== undefined ||
|
|
556
|
+
record.runScoped === true ||
|
|
557
|
+
record.resumeTarget !== undefined;
|
|
558
|
+
if (!this.#resumeRun || !resumable)
|
|
561
559
|
return { attempted: false };
|
|
562
560
|
// record.decision is set by decide()'s patch before this runs.
|
|
563
561
|
const decision = record.decision;
|
|
@@ -565,7 +563,6 @@ export class ApprovalService {
|
|
|
565
563
|
const summary = await this.#resumeRun(record, decision);
|
|
566
564
|
this.#record(actor, 'approval.resume', `approval:${record.id}`, 'allowed', {
|
|
567
565
|
detail: {
|
|
568
|
-
tenantId: record.tenantId,
|
|
569
566
|
workflowId: record.workflowId,
|
|
570
567
|
runId: record.runId,
|
|
571
568
|
},
|
|
@@ -579,7 +576,6 @@ export class ApprovalService {
|
|
|
579
576
|
this.#record(actor, 'approval.resume', `approval:${record.id}`, 'error', {
|
|
580
577
|
reason: message,
|
|
581
578
|
detail: {
|
|
582
|
-
tenantId: record.tenantId,
|
|
583
579
|
workflowId: record.workflowId,
|
|
584
580
|
runId: record.runId,
|
|
585
581
|
},
|
|
@@ -588,34 +584,19 @@ export class ApprovalService {
|
|
|
588
584
|
}
|
|
589
585
|
}
|
|
590
586
|
#authorize(actor, roles, action, resource) {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
// INV-2 belt at the service layer: the acting principal's tenant must
|
|
595
|
-
// BE the store's binding. The resolver constructs the service from the
|
|
596
|
-
// actor's own tenant so this can only fire on a wiring bug — which is
|
|
597
|
-
// exactly when it must fail closed rather than act cross-tenant.
|
|
598
|
-
isNonEmptyString(actor.tenantId) &&
|
|
599
|
-
actor.tenantId === this.#store.tenantId) {
|
|
600
|
-
return;
|
|
587
|
+
const canonical = canonicalApprovalActor(actor);
|
|
588
|
+
if (canonical && roles.includes(canonical.role)) {
|
|
589
|
+
return canonical;
|
|
601
590
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
APPROVAL_ROLES.includes(actor.role) &&
|
|
605
|
-
roles.includes(actor.role);
|
|
606
|
-
this.#record(actor ?? null, action, resource, 'denied', {
|
|
607
|
-
reason: !actor
|
|
591
|
+
this.#record(canonical ?? null, action, resource, 'denied', {
|
|
592
|
+
reason: !canonical
|
|
608
593
|
? 'no actor'
|
|
609
|
-
:
|
|
610
|
-
? `role '${actor.role}' is not in [${roles.join(', ')}]`
|
|
611
|
-
: `actor tenant '${actor.tenantId}' does not match the store binding '${this.#store.tenantId}'`,
|
|
594
|
+
: `role '${canonical.role}' is not in [${roles.join(', ')}]`,
|
|
612
595
|
});
|
|
613
|
-
throw new ApprovalAuthzError(
|
|
614
|
-
? `${action}: actor tenant does not match this service's tenant binding`
|
|
615
|
-
: `${action} requires one of roles [${roles.join(', ')}]`);
|
|
596
|
+
throw new ApprovalAuthzError(`${action} requires one of roles [${roles.join(', ')}]`);
|
|
616
597
|
}
|
|
617
598
|
/**
|
|
618
|
-
* Authorize an automated caller on kind
|
|
599
|
+
* Authorize an automated caller on kind and brand.
|
|
619
600
|
*
|
|
620
601
|
* The parameter type is NOT the enforcement. `trustAutomationPrincipal` is
|
|
621
602
|
* the only minter, but TypeScript is erased at runtime, so a cast or a value
|
|
@@ -623,10 +604,6 @@ export class ApprovalService {
|
|
|
623
604
|
* caller left it. Re-reading the brand and the shape is what turns "only the
|
|
624
605
|
* minter produces this" from a convention into a check — and it is what stops
|
|
625
606
|
* a principal validated as `system` from being read back as a human `admin`.
|
|
626
|
-
*
|
|
627
|
-
* The tenant is checked for the same reason `#authorize` checks it: the
|
|
628
|
-
* resolver builds the service from the principal's own tenant, so a mismatch
|
|
629
|
-
* can only be a wiring bug — exactly when it must fail closed.
|
|
630
607
|
*/
|
|
631
608
|
#authorizeAutomated(principal, action, resource) {
|
|
632
609
|
if (!isTrustedAutomationPrincipal(principal)) {
|
|
@@ -638,15 +615,6 @@ export class ApprovalService {
|
|
|
638
615
|
});
|
|
639
616
|
throw new ApprovalAuthzError(`${action}: principal is not a vouched automated principal`);
|
|
640
617
|
}
|
|
641
|
-
if (principal.tenantId === this.#store.tenantId)
|
|
642
|
-
return;
|
|
643
|
-
this.#record(principalActor(principal), action, resource, 'denied', {
|
|
644
|
-
reason: `principal tenant '${principal.tenantId}' does not match the store binding '${this.#store.tenantId}'`,
|
|
645
|
-
// A denial is an automated event too: without these the only automated
|
|
646
|
-
// audit rows carrying provenance would be the ones that succeeded.
|
|
647
|
-
detail: principalAuditFields(principal),
|
|
648
|
-
});
|
|
649
|
-
throw new ApprovalAuthzError(`${action}: principal tenant does not match this service's tenant binding`);
|
|
650
618
|
}
|
|
651
619
|
// Callers pass the final resource string ('approval' for collection-level
|
|
652
620
|
// actions, 'approval:<id>' for record-level) — no format inference here.
|
|
@@ -693,12 +661,12 @@ export class ApprovalService {
|
|
|
693
661
|
if (!isNonEmptyString(input.runId)) {
|
|
694
662
|
throw new InvalidApprovalInputError('runId is required');
|
|
695
663
|
}
|
|
696
|
-
// Cheap INV-1 belt
|
|
697
|
-
//
|
|
698
|
-
//
|
|
699
|
-
//
|
|
700
|
-
if (!
|
|
701
|
-
throw new InvalidApprovalInputError(`runId '${input.runId}'
|
|
664
|
+
// Cheap INV-1 belt at the only write path: an approval binds to a
|
|
665
|
+
// server-minted run, and every context a runId keys (D1 row, DO name,
|
|
666
|
+
// URL path) requires the path-safe charset. A record filed under a
|
|
667
|
+
// malformed runId would be an orphan no resume can ever reach.
|
|
668
|
+
if (!isPathSafeId(input.runId)) {
|
|
669
|
+
throw new InvalidApprovalInputError(`runId '${input.runId}' is not path-safe — approvals bind to server-minted runs (INV-1)`);
|
|
702
670
|
}
|
|
703
671
|
if (!isNonEmptyString(input.title)) {
|
|
704
672
|
throw new InvalidApprovalInputError('title is required');
|
|
@@ -722,8 +690,16 @@ export class ApprovalService {
|
|
|
722
690
|
// explicit one must be a usable identity — an empty string would silently
|
|
723
691
|
// match no actor and, worse, read as "attributed" to any later reader.
|
|
724
692
|
if (input.requestedBy !== undefined &&
|
|
725
|
-
!
|
|
726
|
-
throw new InvalidApprovalInputError('requestedBy must be a
|
|
693
|
+
!isExecutionPrincipalId(input.requestedBy)) {
|
|
694
|
+
throw new InvalidApprovalInputError('requestedBy must be a valid execution principal id');
|
|
695
|
+
}
|
|
696
|
+
if (input.requestedByKind !== undefined &&
|
|
697
|
+
!isExecutionPrincipalKind(input.requestedByKind)) {
|
|
698
|
+
throw new InvalidApprovalInputError(`requestedByKind must be one of [${EXECUTION_PRINCIPAL_KINDS.join(', ')}]`);
|
|
699
|
+
}
|
|
700
|
+
if ((input.requestedBy === undefined) !==
|
|
701
|
+
(input.requestedByKind === undefined)) {
|
|
702
|
+
throw new InvalidApprovalInputError('requestedBy and requestedByKind must be provided together');
|
|
727
703
|
}
|
|
728
704
|
// runScoped is a capability switch (mints on every leg); only a real
|
|
729
705
|
// boolean opts in, never a truthy string from a lax caller.
|
|
@@ -797,35 +773,12 @@ export class ApprovalService {
|
|
|
797
773
|
}
|
|
798
774
|
}
|
|
799
775
|
}
|
|
800
|
-
#
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
const ownsPathSafeId = (value) => typeof value === 'string' &&
|
|
805
|
-
PATH_SAFE_ID_PATTERN.test(value) &&
|
|
806
|
-
tenantOwnsSaltedId(this.#store.tenantId, value);
|
|
807
|
-
if (target.kind === 'thread') {
|
|
808
|
-
if (!ownsPathSafeId(target.threadId) ||
|
|
809
|
-
(target.resourceId !== undefined && !ownsPathSafeId(target.resourceId))) {
|
|
810
|
-
throw new InvalidApprovalInputError('resumeTarget must name path-safe thread/resource ids owned by the bound tenant');
|
|
811
|
-
}
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
if (target.kind === 'agent-thread') {
|
|
815
|
-
if (typeof target.agentId !== 'string' ||
|
|
816
|
-
!PATH_SAFE_ID_PATTERN.test(target.agentId) ||
|
|
817
|
-
!ownsPathSafeId(target.threadId) ||
|
|
818
|
-
!ownsPathSafeId(target.resourceId) ||
|
|
819
|
-
// Fails closed on the pre-principal `{id, role, tenantId}` form: an
|
|
820
|
-
// ApprovalActor is not an ExecutionPrincipal, and coercing one would
|
|
821
|
-
// resurrect a fabricated operator as a human.
|
|
822
|
-
!isExecutionPrincipal(target.principal) ||
|
|
823
|
-
target.principal.tenantId !== this.#store.tenantId) {
|
|
824
|
-
throw new InvalidApprovalInputError('agent resumeTarget must name path-safe ids and a valid execution principal owned by the bound tenant');
|
|
825
|
-
}
|
|
826
|
-
return;
|
|
776
|
+
#canonicalResumeTarget(target) {
|
|
777
|
+
const canonical = canonicalApprovalResumeTarget(target);
|
|
778
|
+
if (!canonical) {
|
|
779
|
+
throw new InvalidApprovalInputError('resumeTarget must be a trusted thread or agent-thread target with path-safe ids and a valid execution principal');
|
|
827
780
|
}
|
|
828
|
-
|
|
781
|
+
return canonical;
|
|
829
782
|
}
|
|
830
783
|
}
|
|
831
784
|
function errorMessage(error) {
|
|
@@ -873,7 +826,7 @@ function fireNotification(notify, event, reportError) {
|
|
|
873
826
|
// the AUDIT sink (as `approval.stream`/'error') so the mutation that fired it
|
|
874
827
|
// never fails. Deliberately not awaited: a host that must keep a hub publish
|
|
875
828
|
// alive past the response wraps it in ctx.waitUntil itself (see
|
|
876
|
-
// ApprovalStreamSink); the
|
|
829
|
+
// ApprovalStreamSink); the maintenance sweep collects it into pendingSends instead.
|
|
877
830
|
function fireStreamEvent(stream, event, reportError) {
|
|
878
831
|
if (!stream)
|
|
879
832
|
return;
|
|
@@ -888,22 +841,14 @@ function fireStreamEvent(stream, event, reportError) {
|
|
|
888
841
|
}
|
|
889
842
|
}
|
|
890
843
|
/**
|
|
891
|
-
* Escalate every open request past its SLA deadline
|
|
844
|
+
* Escalate every open request past its SLA deadline in this deployment.
|
|
892
845
|
* Idempotent: already escalated records are not re-escalated (their status
|
|
893
|
-
* left the guard set).
|
|
894
|
-
* method and
|
|
895
|
-
* behind a role check was an IDOR-shaped hole (any CAN_SWEEP actor could
|
|
896
|
-
* escalate every tenant's queue). The distinct SystemApprovalStore parameter
|
|
897
|
-
* type makes "cross-tenant reads happen only inside the TCB" a compile-time
|
|
898
|
-
* property, not a convention.
|
|
846
|
+
* left the guard set). Trusted-maintenance code — deliberately not a service
|
|
847
|
+
* method and not reachable over HTTP.
|
|
899
848
|
*/
|
|
900
849
|
export async function sweepSLA(store, options) {
|
|
901
|
-
// The principal is attribution, not authorization
|
|
902
|
-
//
|
|
903
|
-
// this is the erased-type half, because this is the one exported cross-tenant
|
|
904
|
-
// function that CARRIES an attribution principal (purgeExpiredApprovals takes
|
|
905
|
-
// none, so it has no attribution to corrupt), and a bad principal here makes
|
|
906
|
-
// every escalation it emits, for every tenant, unattributable.
|
|
850
|
+
// The principal is attribution, not authorization. The parameter type
|
|
851
|
+
// excludes a human, and the runtime check closes the erased-type boundary.
|
|
907
852
|
const systemPrincipal = canonicalAutomatedPrincipal(options.systemPrincipal);
|
|
908
853
|
if (systemPrincipal === undefined) {
|
|
909
854
|
throw new Error('sweepSLA: systemPrincipal must be a valid automated execution principal');
|
|
@@ -942,9 +887,8 @@ export async function sweepSLA(store, options) {
|
|
|
942
887
|
const at = now();
|
|
943
888
|
const nowIso = at.toISOString();
|
|
944
889
|
const escalated = [];
|
|
945
|
-
// D3: page the
|
|
946
|
-
//
|
|
947
|
-
// list() here would be the whole table). Keyset paging is on (createdAt, id);
|
|
890
|
+
// D3: page the deployment's open set with an explicit cursor. Keyset paging
|
|
891
|
+
// is on (createdAt, id);
|
|
948
892
|
// escalating a record only drops it from the pending/claimed filter and never
|
|
949
893
|
// changes its cursor position, so every currently-open record is visited
|
|
950
894
|
// exactly once — no skips, no repeats — and every breach as of `at` still
|
|
@@ -968,10 +912,7 @@ export async function sweepSLA(store, options) {
|
|
|
968
912
|
escalated.push(updated);
|
|
969
913
|
record('approval.escalate', `approval:${updated.id}`, 'allowed', {
|
|
970
914
|
reason: `SLA deadline ${updated.slaDeadlineAt} breached`,
|
|
971
|
-
// tenantId attributes the escalation: a cross-tenant sweep without it
|
|
972
|
-
// emits unattributable audit events.
|
|
973
915
|
detail: {
|
|
974
|
-
tenantId: updated.tenantId,
|
|
975
916
|
workflowId: updated.workflowId,
|
|
976
917
|
runId: updated.runId,
|
|
977
918
|
},
|
|
@@ -985,17 +926,14 @@ export async function sweepSLA(store, options) {
|
|
|
985
926
|
// abort the sweep. The audit trail keeps the evidence.
|
|
986
927
|
record('approval.escalate', `approval:${updated.id}`, 'error', {
|
|
987
928
|
reason: `onEscalation threw: ${errorMessage(error)}`,
|
|
988
|
-
detail: { tenantId: updated.tenantId },
|
|
989
929
|
});
|
|
990
930
|
}
|
|
991
931
|
}
|
|
992
932
|
fireNotification(options.notify, { type: 'escalated', record: updated }, (reason) => record('approval.notify', `approval:${updated.id}`, 'error', {
|
|
993
933
|
reason,
|
|
994
|
-
detail: { tenantId: updated.tenantId },
|
|
995
934
|
}));
|
|
996
935
|
fireStreamEvent(options.stream, { type: 'escalated', record: updated }, (reason) => record('approval.stream', `approval:${updated.id}`, 'error', {
|
|
997
936
|
reason,
|
|
998
|
-
detail: { tenantId: updated.tenantId },
|
|
999
937
|
}));
|
|
1000
938
|
}
|
|
1001
939
|
// Full page ⇒ there may be more; cursor past the last row (FIFO order, so
|