@proofoftech/flowsafe 0.11.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 +36 -0
- package/README.md +65 -43
- 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 +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 +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/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 +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
|
@@ -22,21 +22,10 @@ export declare const RUN_START_ROLES: readonly ApprovalRole[];
|
|
|
22
22
|
* never affirms a role that could not decide anyway).
|
|
23
23
|
*/
|
|
24
24
|
export declare const DECIDER_ROLES: readonly ApprovalRole[];
|
|
25
|
-
/**
|
|
26
|
-
* The acting principal — breakwater's Actor shape plus the platform's tenant
|
|
27
|
-
* dimension. breakwater stays tenant-agnostic (it is a standalone library);
|
|
28
|
-
* flowsafe is the multi-tenant host, so ITS actor carries the tenant. The
|
|
29
|
-
* e2e mirror tripwire pins "breakwater's Actor fields + tenantId".
|
|
30
|
-
*
|
|
31
|
-
* `tenantId` crosses an authentication boundary (bearer map or JWT claims):
|
|
32
|
-
* every verifier must validate it against TENANT_ID_PATTERN in
|
|
33
|
-
* do-runner/path-safe-id.ts before constructing an ApprovalActor — the type
|
|
34
|
-
* says `string`, but the type system has no authority over a decoded token.
|
|
35
|
-
*/
|
|
25
|
+
/** The authenticated human actor, mirrored from breakwater's Actor shape. */
|
|
36
26
|
export interface ApprovalActor {
|
|
37
|
-
id: string;
|
|
38
|
-
role: ApprovalRole;
|
|
39
|
-
tenantId: string;
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly role: ApprovalRole;
|
|
40
29
|
}
|
|
41
30
|
/**
|
|
42
31
|
* Audit event the approval service emits — structurally assignable to
|
|
@@ -68,7 +57,7 @@ export type ApprovalAuditSink = (event: ApprovalAuditEvent) => unknown;
|
|
|
68
57
|
* A queue moment worth pushing at reviewers: a NEW request entered the queue
|
|
69
58
|
* ('created' — fired only when a record is actually inserted, never on the
|
|
70
59
|
* idempotent re-observation of an already-open step), or an open request
|
|
71
|
-
* breached its SLA ('escalated', fired per record by the
|
|
60
|
+
* breached its SLA ('escalated', fired per record by the maintenance sweep).
|
|
72
61
|
* Decisions are deliberately not notification events — the decider is looking
|
|
73
62
|
* at the dashboard when they happen.
|
|
74
63
|
*/
|
|
@@ -94,9 +83,9 @@ export interface ApprovalNotificationEvent {
|
|
|
94
83
|
*/
|
|
95
84
|
export type ApprovalNotificationSink = (event: ApprovalNotificationEvent) => void | Promise<void>;
|
|
96
85
|
/**
|
|
97
|
-
* A live-stream moment worth fanning out to every open dashboard
|
|
98
|
-
*
|
|
99
|
-
* escalated. Distinct from ApprovalNotificationEvent (deliberately only
|
|
86
|
+
* A live-stream moment worth fanning out to every open dashboard in the
|
|
87
|
+
* deployment: a request was created, claimed, decided, delegated, superseded,
|
|
88
|
+
* or escalated. Distinct from ApprovalNotificationEvent (deliberately only
|
|
100
89
|
* 'created' | 'escalated', the reviewer-facing transport): a live queue also
|
|
101
90
|
* needs claimed/decided/delegated/superseded so a dashboard can upsert-by-id
|
|
102
91
|
* without a refetch. `record` is the POST-transition record.
|
|
@@ -106,8 +95,8 @@ export interface ApprovalStreamEvent {
|
|
|
106
95
|
record: ApprovalRecord;
|
|
107
96
|
}
|
|
108
97
|
/**
|
|
109
|
-
* The live fan-out seam (
|
|
110
|
-
*
|
|
98
|
+
* The live fan-out seam (the deployment hub Durable Object relays each event
|
|
99
|
+
* to open dashboard sockets — flowsafe ships NO transport).
|
|
111
100
|
* Fire-and-forget with the same availability-over-delivery policy as
|
|
112
101
|
* ApprovalNotificationSink: a sink that throws or rejects never fails the
|
|
113
102
|
* approval mutation that fired it — the failure is recorded to the AUDIT sink
|
|
@@ -117,9 +106,9 @@ export interface ApprovalStreamEvent {
|
|
|
117
106
|
*
|
|
118
107
|
* TRUST: unlike ApprovalNotificationSink — which addresses lower-trust channels
|
|
119
108
|
* (email, chat) and so a transport must project or redact the record — this is
|
|
120
|
-
* a SAME-TRUST
|
|
121
|
-
* reviewer
|
|
122
|
-
* is an ADDRESSING feed, never a capability — no grant ever travels on it.
|
|
109
|
+
* a SAME-TRUST in-deployment feed: every subscriber is already an
|
|
110
|
+
* authenticated reviewer, so it carries the FULL ApprovalRecord unredacted.
|
|
111
|
+
* It is an ADDRESSING feed, never a capability — no grant ever travels on it.
|
|
123
112
|
*/
|
|
124
113
|
export type ApprovalStreamSink = (event: ApprovalStreamEvent) => void | Promise<void>;
|
|
125
114
|
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/approval-api/contract.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,+BAA+B,EAC/B,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,sEAAsE;AACtE,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAMjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAIlD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EAA0B,CAAC;AAE5E
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/approval-api/contract.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,+BAA+B,EAC/B,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,sEAAsE;AACtE,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAMjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAIlD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EAA0B,CAAC;AAE5E,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;IAC9B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,wBAAwB,GAAG,CACrC,KAAK,EAAE,yBAAyB,KAC7B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EACA,SAAS,GACT,SAAS,GACT,SAAS,GACT,WAAW,GACX,YAAY,GACZ,WAAW,CAAC;IAChB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,EAAE,mBAAmB,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type ApprovalPatch, type ApprovalStore, type CreateResult } from './store.js';
|
|
2
|
-
import { type SystemApprovalStore, TENANT_BOUND } from './tenant-brand.js';
|
|
3
2
|
import { type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalStatus } from './types.js';
|
|
4
3
|
/**
|
|
5
4
|
* The subset of D1Database this store uses, held structurally so tests can
|
|
@@ -17,11 +16,9 @@ export interface ApprovalPreparedStatement {
|
|
|
17
16
|
}>;
|
|
18
17
|
}
|
|
19
18
|
export interface D1ApprovalStoreOptions {
|
|
20
|
-
tenantId: string;
|
|
21
19
|
/**
|
|
22
|
-
* Shared schema gate: the factory memoizes
|
|
23
|
-
*
|
|
24
|
-
* than once per request. Default: this instance memoizes its own.
|
|
20
|
+
* Shared schema gate: the factory memoizes one schema-init promise per
|
|
21
|
+
* isolate. Default: this instance memoizes its own.
|
|
25
22
|
*/
|
|
26
23
|
ready?: () => Promise<void>;
|
|
27
24
|
}
|
|
@@ -29,24 +26,19 @@ export interface D1ApprovalStoreOptions {
|
|
|
29
26
|
* One-shot schema creation + fail-closed shape check. Exported for the
|
|
30
27
|
* factory (which owns the cross-instance memo) and the schema tests.
|
|
31
28
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* A database created before the tenant column must be recreated (nothing is
|
|
36
|
-
* deployed; local `.wrangler/` state is deleted, not migrated).
|
|
29
|
+
* Refuses the legacy pooled table. Dropping tenant_id in place would require a
|
|
30
|
+
* table rebuild and could preserve stale tenant-keyed indexes; pre-1.0
|
|
31
|
+
* deployments must recreate the database during this breaking migration.
|
|
37
32
|
*/
|
|
38
33
|
export declare function createApprovalSchema(db: ApprovalDatabase): Promise<void>;
|
|
39
34
|
export declare class D1ApprovalStore implements ApprovalStore {
|
|
40
35
|
#private;
|
|
41
|
-
|
|
42
|
-
readonly [TENANT_BOUND]: true;
|
|
43
|
-
constructor(db: ApprovalDatabase, options: D1ApprovalStoreOptions);
|
|
36
|
+
constructor(db: ApprovalDatabase, options?: D1ApprovalStoreOptions);
|
|
44
37
|
create(record: ApprovalRecord): Promise<CreateResult>;
|
|
45
38
|
get(id: string): Promise<ApprovalRecord | null>;
|
|
46
39
|
list(filter?: ApprovalListFilter): Promise<ApprovalRecord[]>;
|
|
47
40
|
metrics(nowMs: number): Promise<ApprovalMetrics>;
|
|
48
41
|
transition(id: string, from: readonly ApprovalStatus[], patch: ApprovalPatch): Promise<ApprovalRecord | null>;
|
|
42
|
+
purgeExpired(cutoffIso: string, limit: number): Promise<number>;
|
|
49
43
|
}
|
|
50
|
-
/** The cron-only cross-tenant view over the same table — see tenant-brand.ts. */
|
|
51
|
-
export declare function d1SystemApprovalStore(db: ApprovalDatabase, ready: () => Promise<void>): SystemApprovalStore;
|
|
52
44
|
//# sourceMappingURL=d1-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EASpB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAAC;CACnD;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,yBAAyB,CAAC;IACtD,KAAK,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/C;AAqYD,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,gBAAgB,GACnB,OAAO,CAAC,IAAI,CAAC,CAoDf;AAED,qBAAa,eAAgB,YAAW,aAAa;;gBAKvC,EAAE,EAAE,gBAAgB,EAAE,OAAO,GAAE,sBAA2B;IAKhE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAmGrD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAS/C,IAAI,CAAC,MAAM,GAAE,kBAAuB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAgBhE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAShD,UAAU,CACd,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,SAAS,cAAc,EAAE,EAC/B,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAwE3B,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBtE"}
|
|
@@ -5,37 +5,22 @@
|
|
|
5
5
|
// rows and it gets null). Open-request uniqueness is a partial unique index,
|
|
6
6
|
// so duplicate creates collapse to the existing open record even across
|
|
7
7
|
// concurrent Workers.
|
|
8
|
-
//
|
|
9
|
-
// TENANT BINDING (INV-2): the store is bound to ONE tenant at construction
|
|
10
|
-
// and every SELECT/UPDATE carries `tenant_id = ?` sourced from that field —
|
|
11
|
-
// never from a request parameter. `tenantId` is deliberately NOT a member of
|
|
12
|
-
// ApprovalListFilter: an omissible tenant filter is the canonical fail-open
|
|
13
|
-
// (an empty filter would scan every tenant). Construct through
|
|
14
|
-
// D1ApprovalStoreFactory (tenant-store.ts) — this class is not exported from
|
|
15
|
-
// the package barrel.
|
|
16
8
|
import { d1Changes } from '../do-runner/d1-storage.js';
|
|
17
|
-
import {
|
|
18
|
-
import { isExecutionPrincipal } from './principal.js';
|
|
9
|
+
import { isExecutionPrincipalId, isExecutionPrincipalKind, } from './principal.js';
|
|
19
10
|
import { stepKeyOf, } from './store.js';
|
|
20
|
-
import {
|
|
21
|
-
import { approvalListOrder, clampApprovalLimit, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, parseApprovalCursor, parseApprovalTimeBound, TERMINAL_APPROVAL_STATUSES, } from './types.js';
|
|
11
|
+
import { approvalListOrder, canonicalApprovalResumeTarget, clampApprovalLimit, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, parseApprovalCursor, parseApprovalTimeBound, TERMINAL_APPROVAL_STATUSES, } from './types.js';
|
|
22
12
|
const TABLE = 'flowsafe_approvals';
|
|
23
13
|
// The partial index preserves open-step uniqueness. Captured suspensions add a
|
|
24
14
|
// second, all-status fingerprint index after the legacy nullable columns are
|
|
25
15
|
// present: terminal records must block a stale reconciler filing the SAME
|
|
26
16
|
// suspension, while a later re-suspension changes suspended_at/resume_count.
|
|
27
17
|
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
// it, leaving open-uniqueness enforced WITHOUT the tenant dimension (tenant
|
|
32
|
-
// B's create would collapse into tenant A's open record). The migration must
|
|
33
|
-
// DROP the old index and create the new one under a NEW NAME, and the
|
|
34
|
-
// schema-upgrade test creates the OLD index first to prove the drop happens.
|
|
18
|
+
// Index names change with the single-deployment schema. CREATE INDEX IF NOT
|
|
19
|
+
// EXISTS matches on name only, so retaining the pooled names would silently
|
|
20
|
+
// preserve tenant-keyed definitions on a reused database.
|
|
35
21
|
const SCHEMA_STATEMENTS = [
|
|
36
22
|
`CREATE TABLE IF NOT EXISTS ${TABLE} (
|
|
37
23
|
id TEXT PRIMARY KEY,
|
|
38
|
-
tenant_id TEXT NOT NULL,
|
|
39
24
|
workflow_id TEXT NOT NULL,
|
|
40
25
|
run_id TEXT NOT NULL,
|
|
41
26
|
step_key TEXT NOT NULL DEFAULT '',
|
|
@@ -54,6 +39,7 @@ const SCHEMA_STATEMENTS = [
|
|
|
54
39
|
priority TEXT NOT NULL,
|
|
55
40
|
status TEXT NOT NULL,
|
|
56
41
|
requested_by TEXT,
|
|
42
|
+
requested_by_kind TEXT,
|
|
57
43
|
claimed_by TEXT,
|
|
58
44
|
decided_by TEXT,
|
|
59
45
|
decision TEXT,
|
|
@@ -67,13 +53,15 @@ const SCHEMA_STATEMENTS = [
|
|
|
67
53
|
sla_deadline_at TEXT
|
|
68
54
|
)`,
|
|
69
55
|
`DROP INDEX IF EXISTS ${TABLE}_open_step`,
|
|
70
|
-
`
|
|
71
|
-
|
|
56
|
+
`DROP INDEX IF EXISTS ${TABLE}_open_step_v2`,
|
|
57
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${TABLE}_open_step_v3
|
|
58
|
+
ON ${TABLE} (workflow_id, run_id, step_key)
|
|
72
59
|
WHERE status IN ('pending', 'claimed', 'escalated')`,
|
|
73
60
|
`CREATE INDEX IF NOT EXISTS ${TABLE}_status ON ${TABLE} (status)`,
|
|
74
61
|
`DROP INDEX IF EXISTS ${TABLE}_run`,
|
|
75
|
-
`
|
|
76
|
-
|
|
62
|
+
`DROP INDEX IF EXISTS ${TABLE}_run_v2`,
|
|
63
|
+
`CREATE INDEX IF NOT EXISTS ${TABLE}_run_v3
|
|
64
|
+
ON ${TABLE} (workflow_id, run_id)`,
|
|
77
65
|
];
|
|
78
66
|
// First suspensions have a NULL resume_count; SQLite UNIQUE indexes otherwise
|
|
79
67
|
// treat every NULL as distinct, so normalize it to text outside the number
|
|
@@ -82,9 +70,9 @@ const SCHEMA_STATEMENTS = [
|
|
|
82
70
|
// runs after the additive ALTER loop. If a legacy database already contains
|
|
83
71
|
// duplicate fingerprints, index creation fails closed instead of choosing one
|
|
84
72
|
// audit record silently.
|
|
85
|
-
const FINGERPRINT_INDEX = `CREATE UNIQUE INDEX IF NOT EXISTS ${TABLE}
|
|
73
|
+
const FINGERPRINT_INDEX = `CREATE UNIQUE INDEX IF NOT EXISTS ${TABLE}_fingerprint_v2
|
|
86
74
|
ON ${TABLE} (
|
|
87
|
-
|
|
75
|
+
workflow_id, run_id, step_key, suspended_at,
|
|
88
76
|
COALESCE(resume_count, 'none')
|
|
89
77
|
)
|
|
90
78
|
WHERE step_path IS NOT NULL AND suspended_at IS NOT NULL`;
|
|
@@ -101,11 +89,7 @@ const PATCH_COLUMNS = {
|
|
|
101
89
|
escalatedAt: 'escalated_at',
|
|
102
90
|
};
|
|
103
91
|
/**
|
|
104
|
-
* The optional WHERE clauses of list()
|
|
105
|
-
* store and the cron-only system view. The bound store SEEDS the arrays with
|
|
106
|
-
* its unconditional `tenant_id = ?`; the system view seeds them empty. Two
|
|
107
|
-
* hand-written copies would drift, and only one of them is on the request
|
|
108
|
-
* path (the other is the sweep) — so a fix would silently miss it.
|
|
92
|
+
* The optional WHERE clauses of list().
|
|
109
93
|
*/
|
|
110
94
|
function appendListFilters(filter, where, values) {
|
|
111
95
|
if (filter.status !== undefined) {
|
|
@@ -194,8 +178,7 @@ const METRICS_QUERY = `SELECT
|
|
|
194
178
|
WHEN status IN ('approved','rejected') AND decided_at IS NOT NULL
|
|
195
179
|
THEN (julianday(decided_at) - julianday(created_at)) * 86400.0
|
|
196
180
|
END) AS avg_resolution_seconds
|
|
197
|
-
FROM ${TABLE}
|
|
198
|
-
WHERE tenant_id = ?`;
|
|
181
|
+
FROM ${TABLE}`;
|
|
199
182
|
function rowToApprovalMetrics(row) {
|
|
200
183
|
if (!row) {
|
|
201
184
|
return {
|
|
@@ -218,7 +201,7 @@ function rowToApprovalMetrics(row) {
|
|
|
218
201
|
avgResolutionSeconds: row.avg_resolution_seconds,
|
|
219
202
|
};
|
|
220
203
|
}
|
|
221
|
-
/** The `SET col = ?` fragments + bound values of a CAS patch
|
|
204
|
+
/** The `SET col = ?` fragments + bound values of a CAS patch. */
|
|
222
205
|
function buildPatchSets(patch) {
|
|
223
206
|
const sets = [];
|
|
224
207
|
const values = [];
|
|
@@ -245,7 +228,6 @@ function rowToRecord(row) {
|
|
|
245
228
|
}
|
|
246
229
|
const record = {
|
|
247
230
|
id: row.id,
|
|
248
|
-
tenantId: row.tenant_id,
|
|
249
231
|
workflowId: row.workflow_id,
|
|
250
232
|
runId: row.run_id,
|
|
251
233
|
title: row.title,
|
|
@@ -290,38 +272,36 @@ function rowToRecord(row) {
|
|
|
290
272
|
catch {
|
|
291
273
|
throw new Error(`approval '${row.id}' has invalid resume_target JSON`);
|
|
292
274
|
}
|
|
293
|
-
const ownsPathSafeId = (value) => typeof value === 'string' &&
|
|
294
|
-
PATH_SAFE_ID_PATTERN.test(value) &&
|
|
295
|
-
tenantOwnsSaltedId(row.tenant_id, value);
|
|
296
|
-
const object = typeof target === 'object' && target !== null
|
|
297
|
-
? target
|
|
298
|
-
: undefined;
|
|
299
|
-
const validThreadTarget = object?.kind === 'thread' &&
|
|
300
|
-
ownsPathSafeId(object.threadId) &&
|
|
301
|
-
(object.resourceId === undefined || ownsPathSafeId(object.resourceId));
|
|
302
275
|
// Rows written before execution principals stored an ApprovalActor here.
|
|
303
|
-
//
|
|
276
|
+
// Canonical target parsing rejects that shape, which is the intended migration:
|
|
304
277
|
// a run started by the schedule tick stored `role: 'operator'`, so reading
|
|
305
278
|
// it back as a human principal would hand a scheduled job the authority of
|
|
306
279
|
// a human operator. Such a row fails closed and its run cannot resume.
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
ownsPathSafeId(object.threadId) &&
|
|
311
|
-
ownsPathSafeId(object.resourceId) &&
|
|
312
|
-
isExecutionPrincipal(object.principal) &&
|
|
313
|
-
object.principal.tenantId === row.tenant_id;
|
|
314
|
-
if (!validThreadTarget && !validAgentTarget) {
|
|
315
|
-
throw new Error(`approval '${row.id}' has an invalid or foreign resume_target`);
|
|
280
|
+
const canonical = canonicalApprovalResumeTarget(target);
|
|
281
|
+
if (!canonical) {
|
|
282
|
+
throw new Error(`approval '${row.id}' has an invalid resume_target`);
|
|
316
283
|
}
|
|
317
|
-
record.resumeTarget =
|
|
284
|
+
record.resumeTarget = canonical;
|
|
318
285
|
}
|
|
319
286
|
if (row.summary !== null)
|
|
320
287
|
record.summary = row.summary;
|
|
321
288
|
if (row.payload !== null)
|
|
322
289
|
record.payload = JSON.parse(row.payload);
|
|
323
|
-
if (row.requested_by !== null)
|
|
290
|
+
if (row.requested_by !== null && row.requested_by !== undefined) {
|
|
291
|
+
if (!isExecutionPrincipalId(row.requested_by)) {
|
|
292
|
+
throw new Error(`approval '${row.id}' has invalid requested_by`);
|
|
293
|
+
}
|
|
324
294
|
record.requestedBy = row.requested_by;
|
|
295
|
+
}
|
|
296
|
+
if (row.requested_by_kind !== null && row.requested_by_kind !== undefined) {
|
|
297
|
+
if (row.requested_by === null || row.requested_by === undefined) {
|
|
298
|
+
throw new Error(`approval '${row.id}' has requested_by_kind without requested_by`);
|
|
299
|
+
}
|
|
300
|
+
if (!isExecutionPrincipalKind(row.requested_by_kind)) {
|
|
301
|
+
throw new Error(`approval '${row.id}' has invalid requested_by_kind`);
|
|
302
|
+
}
|
|
303
|
+
record.requestedByKind = row.requested_by_kind;
|
|
304
|
+
}
|
|
325
305
|
if (row.claimed_by !== null)
|
|
326
306
|
record.claimedBy = row.claimed_by;
|
|
327
307
|
if (row.decided_by !== null)
|
|
@@ -349,27 +329,22 @@ function isUniqueViolation(error) {
|
|
|
349
329
|
* One-shot schema creation + fail-closed shape check. Exported for the
|
|
350
330
|
* factory (which owns the cross-instance memo) and the schema tests.
|
|
351
331
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* A database created before the tenant column must be recreated (nothing is
|
|
356
|
-
* deployed; local `.wrangler/` state is deleted, not migrated).
|
|
332
|
+
* Refuses the legacy pooled table. Dropping tenant_id in place would require a
|
|
333
|
+
* table rebuild and could preserve stale tenant-keyed indexes; pre-1.0
|
|
334
|
+
* deployments must recreate the database during this breaking migration.
|
|
357
335
|
*/
|
|
358
336
|
export async function createApprovalSchema(db) {
|
|
359
337
|
const existing = await db
|
|
360
338
|
.prepare(`PRAGMA table_info(${TABLE})`)
|
|
361
339
|
.all();
|
|
362
340
|
const columns = new Set(existing.results.map((column) => column.name));
|
|
363
|
-
if (columns.
|
|
364
|
-
throw new Error(`${TABLE}
|
|
341
|
+
if (columns.has('tenant_id')) {
|
|
342
|
+
throw new Error(`${TABLE} uses the retired pooled-tenant schema — recreate the database before serving this single-deployment release`);
|
|
365
343
|
}
|
|
366
344
|
for (const statement of SCHEMA_STATEMENTS) {
|
|
367
345
|
await db.prepare(statement).run();
|
|
368
346
|
}
|
|
369
|
-
//
|
|
370
|
-
// databases backfill those nullable INTEGER columns in place (see the
|
|
371
|
-
// upgrade-window notes in the git history); tenant_id can never join this
|
|
372
|
-
// loop — it is TEXT NOT NULL and semantically non-backfillable.
|
|
347
|
+
// Older single-deployment schemas backfill nullable fields in place.
|
|
373
348
|
for (const column of [
|
|
374
349
|
'suspended_at',
|
|
375
350
|
'resumed_at',
|
|
@@ -386,7 +361,7 @@ export async function createApprovalSchema(db) {
|
|
|
386
361
|
throw error;
|
|
387
362
|
}
|
|
388
363
|
}
|
|
389
|
-
for (const column of ['grant_scope', 'tool_call_id']) {
|
|
364
|
+
for (const column of ['grant_scope', 'tool_call_id', 'requested_by_kind']) {
|
|
390
365
|
try {
|
|
391
366
|
await db.prepare(`ALTER TABLE ${TABLE} ADD COLUMN ${column} TEXT`).run();
|
|
392
367
|
}
|
|
@@ -395,6 +370,7 @@ export async function createApprovalSchema(db) {
|
|
|
395
370
|
throw error;
|
|
396
371
|
}
|
|
397
372
|
}
|
|
373
|
+
await db.prepare(`DROP INDEX IF EXISTS ${TABLE}_fingerprint_v1`).run();
|
|
398
374
|
try {
|
|
399
375
|
await db
|
|
400
376
|
.prepare(`ALTER TABLE ${TABLE} ADD COLUMN resume_target TEXT`)
|
|
@@ -414,43 +390,34 @@ export async function createApprovalSchema(db) {
|
|
|
414
390
|
}
|
|
415
391
|
}
|
|
416
392
|
export class D1ApprovalStore {
|
|
417
|
-
tenantId;
|
|
418
|
-
[TENANT_BOUND] = true;
|
|
419
393
|
#db;
|
|
420
394
|
#sharedReady;
|
|
421
395
|
#schemaReady;
|
|
422
|
-
constructor(db, options) {
|
|
423
|
-
if (typeof options.tenantId !== 'string' ||
|
|
424
|
-
!TENANT_ID_PATTERN.test(options.tenantId)) {
|
|
425
|
-
throw new Error(`D1ApprovalStore: tenantId '${options.tenantId}' violates INV-3 (^[a-z0-9]{3,32}$)`);
|
|
426
|
-
}
|
|
396
|
+
constructor(db, options = {}) {
|
|
427
397
|
this.#db = db;
|
|
428
|
-
this.tenantId = options.tenantId;
|
|
429
398
|
this.#sharedReady = options.ready;
|
|
430
399
|
}
|
|
431
400
|
async create(record) {
|
|
432
401
|
await this.#ready();
|
|
433
|
-
//
|
|
434
|
-
//
|
|
435
|
-
//
|
|
436
|
-
|
|
437
|
-
// behind a thrown create.
|
|
438
|
-
const snapshot = structuredClone({ ...record, tenantId: this.tenantId });
|
|
402
|
+
// Clone BEFORE the INSERT: a non-cloneable payload must fail the call
|
|
403
|
+
// without persisting anything (the in-memory store fails at the same
|
|
404
|
+
// point), never orphan a row behind a thrown create.
|
|
405
|
+
const snapshot = structuredClone(record);
|
|
439
406
|
const stepKey = stepKeyOf(snapshot.stepPath);
|
|
440
407
|
const insert = () => this.#db
|
|
441
408
|
.prepare(`INSERT INTO ${TABLE} (
|
|
442
|
-
id,
|
|
409
|
+
id, workflow_id, run_id, step_key, step_path,
|
|
443
410
|
suspended_at, resumed_at, resume_count, run_scoped, title, summary,
|
|
444
411
|
resume_target, payload, connectors, grant_scope, tool_call_id,
|
|
445
|
-
priority, status, requested_by, claimed_by,
|
|
412
|
+
priority, status, requested_by, requested_by_kind, claimed_by,
|
|
446
413
|
decided_by, decision, comment, delegated_to, created_at, updated_at,
|
|
447
414
|
claimed_at, decided_at, escalated_at, sla_deadline_at
|
|
448
415
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
449
|
-
.bind(snapshot.id,
|
|
416
|
+
.bind(snapshot.id, snapshot.workflowId, snapshot.runId, stepKey, snapshot.stepPath ? JSON.stringify(snapshot.stepPath) : null, snapshot.suspendedAt ?? null, snapshot.resumedAt ?? null, snapshot.resumeCount ?? null, snapshot.runScoped === undefined ? null : snapshot.runScoped ? 1 : 0, snapshot.title, snapshot.summary ?? null, snapshot.resumeTarget === undefined
|
|
450
417
|
? null
|
|
451
418
|
: JSON.stringify(snapshot.resumeTarget), snapshot.payload === undefined
|
|
452
419
|
? null
|
|
453
|
-
: JSON.stringify(snapshot.payload), JSON.stringify(snapshot.connectors), snapshot.grantScope ?? null, snapshot.toolCallId ?? null, snapshot.priority, snapshot.status, snapshot.requestedBy ?? null, snapshot.claimedBy ?? null, snapshot.decidedBy ?? null, snapshot.decision ?? null, snapshot.comment ?? null, snapshot.delegatedTo ?? null, snapshot.createdAt, snapshot.updatedAt, snapshot.claimedAt ?? null, snapshot.decidedAt ?? null, snapshot.escalatedAt ?? null, snapshot.slaDeadlineAt ?? null)
|
|
420
|
+
: JSON.stringify(snapshot.payload), JSON.stringify(snapshot.connectors), snapshot.grantScope ?? null, snapshot.toolCallId ?? null, snapshot.priority, snapshot.status, snapshot.requestedBy ?? null, snapshot.requestedByKind ?? null, snapshot.claimedBy ?? null, snapshot.decidedBy ?? null, snapshot.decision ?? null, snapshot.comment ?? null, snapshot.delegatedTo ?? null, snapshot.createdAt, snapshot.updatedAt, snapshot.claimedAt ?? null, snapshot.decidedAt ?? null, snapshot.escalatedAt ?? null, snapshot.slaDeadlineAt ?? null)
|
|
454
421
|
.run();
|
|
455
422
|
// A UNIQUE collision can now be either the all-status exact fingerprint or
|
|
456
423
|
// the open-step index. Resolve the exact fingerprint FIRST: a decision may
|
|
@@ -493,26 +460,23 @@ export class D1ApprovalStore {
|
|
|
493
460
|
}
|
|
494
461
|
async get(id) {
|
|
495
462
|
await this.#ready();
|
|
496
|
-
// Wrong tenant == unknown id: no oracle for other tenants' record ids.
|
|
497
463
|
const row = await this.#db
|
|
498
|
-
.prepare(`SELECT * FROM ${TABLE} WHERE id =
|
|
499
|
-
.bind(id
|
|
464
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE id = ?`)
|
|
465
|
+
.bind(id)
|
|
500
466
|
.first();
|
|
501
467
|
return row ? rowToRecord(row) : null;
|
|
502
468
|
}
|
|
503
469
|
async list(filter = {}) {
|
|
504
470
|
await this.#ready();
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const where = ['tenant_id = ?'];
|
|
508
|
-
const values = [this.tenantId];
|
|
471
|
+
const where = [];
|
|
472
|
+
const values = [];
|
|
509
473
|
appendListFilters(filter, where, values);
|
|
510
|
-
|
|
511
|
-
//
|
|
512
|
-
//
|
|
474
|
+
const clause = where.length > 0 ? ` WHERE ${where.join(' AND ')}` : '';
|
|
475
|
+
// D3: default a bare list() to the max, so a repeated poll can never fall
|
|
476
|
+
// back to an unbounded SELECT.
|
|
513
477
|
const limit = clampApprovalLimit(filter.limit) ?? MAX_APPROVAL_LIST_LIMIT;
|
|
514
478
|
const { results } = await this.#db
|
|
515
|
-
.prepare(`SELECT * FROM ${TABLE}
|
|
479
|
+
.prepare(`SELECT * FROM ${TABLE}${clause} ${listOrderBy(filter)} LIMIT ?`)
|
|
516
480
|
.bind(...values, limit)
|
|
517
481
|
.all();
|
|
518
482
|
return results.map(rowToRecord);
|
|
@@ -521,7 +485,7 @@ export class D1ApprovalStore {
|
|
|
521
485
|
await this.#ready();
|
|
522
486
|
const row = await this.#db
|
|
523
487
|
.prepare(METRICS_QUERY)
|
|
524
|
-
.bind(new Date(nowMs).toISOString()
|
|
488
|
+
.bind(new Date(nowMs).toISOString())
|
|
525
489
|
.first();
|
|
526
490
|
return rowToApprovalMetrics(row);
|
|
527
491
|
}
|
|
@@ -530,23 +494,21 @@ export class D1ApprovalStore {
|
|
|
530
494
|
return null;
|
|
531
495
|
await this.#ready();
|
|
532
496
|
const { sets, values } = buildPatchSets(patch);
|
|
533
|
-
// A wrong tenant matches zero rows and reuses the existing loser-of-CAS
|
|
534
|
-
// null path (404/409 upstream) — no new error branch, no oracle.
|
|
535
497
|
const row = await this.#db
|
|
536
498
|
.prepare(`UPDATE ${TABLE} SET ${sets.join(', ')}
|
|
537
|
-
WHERE id = ? AND
|
|
499
|
+
WHERE id = ? AND status IN (${from.map(() => '?').join(', ')})
|
|
538
500
|
RETURNING *`)
|
|
539
|
-
.bind(...values, id,
|
|
501
|
+
.bind(...values, id, ...from)
|
|
540
502
|
.first();
|
|
541
503
|
return row ? rowToRecord(row) : null;
|
|
542
504
|
}
|
|
543
505
|
async #openFor(workflowId, runId, stepKey) {
|
|
544
506
|
const row = await this.#db
|
|
545
507
|
.prepare(`SELECT * FROM ${TABLE}
|
|
546
|
-
WHERE
|
|
508
|
+
WHERE workflow_id = ? AND run_id = ? AND step_key = ?
|
|
547
509
|
AND status IN (${OPEN_STATUSES.map(() => '?').join(', ')})
|
|
548
510
|
LIMIT 1`)
|
|
549
|
-
.bind(
|
|
511
|
+
.bind(workflowId, runId, stepKey, ...OPEN_STATUSES)
|
|
550
512
|
.first();
|
|
551
513
|
return row ? rowToRecord(row) : null;
|
|
552
514
|
}
|
|
@@ -556,10 +518,10 @@ export class D1ApprovalStore {
|
|
|
556
518
|
}
|
|
557
519
|
const row = await this.#db
|
|
558
520
|
.prepare(`SELECT * FROM ${TABLE}
|
|
559
|
-
WHERE
|
|
521
|
+
WHERE workflow_id = ? AND run_id = ? AND step_key = ?
|
|
560
522
|
AND step_path IS NOT NULL AND suspended_at = ? AND resume_count IS ?
|
|
561
523
|
LIMIT 1`)
|
|
562
|
-
.bind(
|
|
524
|
+
.bind(record.workflowId, record.runId, stepKey, record.suspendedAt, record.resumeCount ?? null)
|
|
563
525
|
.first();
|
|
564
526
|
return row ? rowToRecord(row) : null;
|
|
565
527
|
}
|
|
@@ -576,61 +538,23 @@ export class D1ApprovalStore {
|
|
|
576
538
|
});
|
|
577
539
|
return this.#schemaReady;
|
|
578
540
|
}
|
|
541
|
+
async purgeExpired(cutoffIso, limit) {
|
|
542
|
+
await this.#ready();
|
|
543
|
+
const placeholders = TERMINAL_APPROVAL_STATUSES.map(() => '?').join(', ');
|
|
544
|
+
const result = await this.#db
|
|
545
|
+
.prepare(`DELETE FROM ${TABLE}
|
|
546
|
+
WHERE id IN (
|
|
547
|
+
SELECT id FROM ${TABLE}
|
|
548
|
+
WHERE status IN (${placeholders})
|
|
549
|
+
AND COALESCE(decided_at, updated_at) < ?
|
|
550
|
+
LIMIT ?
|
|
551
|
+
)`)
|
|
552
|
+
.bind(...TERMINAL_APPROVAL_STATUSES, cutoffIso, limit)
|
|
553
|
+
.run();
|
|
554
|
+
return d1Changes(result);
|
|
555
|
+
}
|
|
579
556
|
}
|
|
580
557
|
function isDuplicateColumn(error) {
|
|
581
558
|
return error instanceof Error && /duplicate column/i.test(error.message);
|
|
582
559
|
}
|
|
583
|
-
/** The cron-only cross-tenant view over the same table — see tenant-brand.ts. */
|
|
584
|
-
export function d1SystemApprovalStore(db, ready) {
|
|
585
|
-
return {
|
|
586
|
-
// The bound store's queries minus the tenant predicate — same builders,
|
|
587
|
-
// so a filter/CAS fix cannot reach the request path and miss the sweep.
|
|
588
|
-
async list(filter = {}) {
|
|
589
|
-
await ready();
|
|
590
|
-
const where = [];
|
|
591
|
-
const values = [];
|
|
592
|
-
appendListFilters(filter, where, values);
|
|
593
|
-
const clause = where.length > 0 ? ` WHERE ${where.join(' AND ')}` : '';
|
|
594
|
-
const limit = clampApprovalLimit(filter.limit);
|
|
595
|
-
const { results } = await db
|
|
596
|
-
.prepare(`SELECT * FROM ${TABLE}${clause} ${listOrderBy(filter)}${limit !== undefined ? ' LIMIT ?' : ''}`)
|
|
597
|
-
.bind(...values, ...(limit !== undefined ? [limit] : []))
|
|
598
|
-
.all();
|
|
599
|
-
return results.map(rowToRecord);
|
|
600
|
-
},
|
|
601
|
-
async transition(id, from, patch) {
|
|
602
|
-
if (from.length === 0)
|
|
603
|
-
return null;
|
|
604
|
-
await ready();
|
|
605
|
-
const { sets, values } = buildPatchSets(patch);
|
|
606
|
-
const row = await db
|
|
607
|
-
.prepare(`UPDATE ${TABLE} SET ${sets.join(', ')}
|
|
608
|
-
WHERE id = ? AND status IN (${from.map(() => '?').join(', ')})
|
|
609
|
-
RETURNING *`)
|
|
610
|
-
.bind(...values, id, ...from)
|
|
611
|
-
.first();
|
|
612
|
-
return row ? rowToRecord(row) : null;
|
|
613
|
-
},
|
|
614
|
-
// Retention purge (D3/PART 4) — mirrors do-runner's
|
|
615
|
-
// purgeExpiredWorkflowRuns row-only batching: one LIMIT-batched DELETE
|
|
616
|
-
// per firing, no ORDER BY (the shrinking eligible set across firings is
|
|
617
|
-
// the cursor, not which N rows one firing picks). COALESCE(decided_at,
|
|
618
|
-
// updated_at) is the terminal-timestamp choice — see retention.ts.
|
|
619
|
-
async purgeExpired(cutoffIso, limit) {
|
|
620
|
-
await ready();
|
|
621
|
-
const placeholders = TERMINAL_APPROVAL_STATUSES.map(() => '?').join(', ');
|
|
622
|
-
const result = await db
|
|
623
|
-
.prepare(`DELETE FROM ${TABLE}
|
|
624
|
-
WHERE id IN (
|
|
625
|
-
SELECT id FROM ${TABLE}
|
|
626
|
-
WHERE status IN (${placeholders})
|
|
627
|
-
AND COALESCE(decided_at, updated_at) < ?
|
|
628
|
-
LIMIT ?
|
|
629
|
-
)`)
|
|
630
|
-
.bind(...TERMINAL_APPROVAL_STATUSES, cutoffIso, limit)
|
|
631
|
-
.run();
|
|
632
|
-
return d1Changes(result);
|
|
633
|
-
},
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
560
|
//# sourceMappingURL=d1-store.js.map
|