@proofoftech/flowsafe 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +77 -47
- package/deployment-identity-protocol.d.mts +52 -0
- package/deployment-identity-protocol.mjs +231 -0
- package/dist/agent-host/approval-resumer.d.ts +3 -3
- package/dist/agent-host/approval-resumer.d.ts.map +1 -1
- package/dist/agent-host/approval-resumer.js +6 -7
- package/dist/agent-host/approval-resumer.js.map +1 -1
- package/dist/agent-host/catalog.d.ts +1 -1
- package/dist/agent-host/catalog.d.ts.map +1 -1
- package/dist/agent-host/catalog.js +26 -2
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +4 -3
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js +1 -0
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/router.d.ts +2 -2
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +22 -54
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +53 -9
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +624 -109
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +28 -7
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +97 -39
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-host/trusted-context.d.ts.map +1 -1
- package/dist/agent-host/trusted-context.js +9 -2
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +48 -0
- package/dist/agent-host/types.d.ts.map +1 -1
- package/dist/agent-host/types.js +1 -1
- package/dist/agent-host/types.js.map +1 -1
- package/dist/agent-runner/agent-run-state.d.ts +9 -8
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.js +78 -40
- package/dist/agent-runner/agent-run-state.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +120 -43
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +67 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -0
- package/dist/approval-api/actor-context.js +120 -0
- package/dist/approval-api/actor-context.js.map +1 -0
- package/dist/approval-api/contract.d.ts +13 -24
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/contract.js +1 -1
- package/dist/approval-api/contract.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts +7 -15
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +83 -159
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +3 -17
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +19 -39
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +9 -9
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +6 -6
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/principal.d.ts +29 -30
- package/dist/approval-api/principal.d.ts.map +1 -1
- package/dist/approval-api/principal.js +73 -54
- package/dist/approval-api/principal.js.map +1 -1
- package/dist/approval-api/resource-ownership.d.ts +64 -0
- package/dist/approval-api/resource-ownership.d.ts.map +1 -0
- package/dist/approval-api/resource-ownership.js +329 -0
- package/dist/approval-api/resource-ownership.js.map +1 -0
- package/dist/approval-api/retention.d.ts +6 -11
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js +7 -12
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/router.d.ts +9 -8
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +50 -18
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +26 -36
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +104 -166
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store-factory.d.ts +19 -0
- package/dist/approval-api/store-factory.d.ts.map +1 -0
- package/dist/approval-api/store-factory.js +49 -0
- package/dist/approval-api/store-factory.js.map +1 -0
- package/dist/approval-api/store.d.ts +22 -36
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +48 -66
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/types.d.ts +28 -22
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +51 -3
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/client.js +3 -3
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +4 -4
- package/dist/approval-ui/stream.d.ts.map +1 -1
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/tips.d.ts +1 -1
- package/dist/approval-ui/tips.js +1 -1
- package/dist/approval-ui/tips.js.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
- package/dist/approval-ui/use-approval-dashboard.js +1 -1
- package/dist/artifacts/index.d.ts +2 -3
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +9 -8
- package/dist/artifacts/index.js.map +1 -1
- package/dist/audit-export/audit-proxy.d.ts +71 -0
- package/dist/audit-export/audit-proxy.d.ts.map +1 -0
- package/dist/audit-export/audit-proxy.js +142 -0
- package/dist/audit-export/audit-proxy.js.map +1 -0
- package/dist/audit-export/index.d.ts +4 -7
- package/dist/audit-export/index.d.ts.map +1 -1
- package/dist/audit-export/index.js +1 -4
- package/dist/audit-export/index.js.map +1 -1
- package/dist/audit-export/queue-types.d.ts +5 -0
- package/dist/audit-export/queue-types.d.ts.map +1 -0
- package/dist/audit-export/queue-types.js +3 -0
- package/dist/audit-export/queue-types.js.map +1 -0
- package/dist/background-tasks/d1-storage.d.ts +9 -19
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +22 -52
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/background-tasks/host.d.ts +4 -6
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +14 -17
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/background-tasks/index.d.ts +1 -1
- package/dist/background-tasks/index.d.ts.map +1 -1
- package/dist/background-tasks/index.js +3 -3
- package/dist/background-tasks/index.js.map +1 -1
- package/dist/background-tasks/routes.d.ts +8 -4
- package/dist/background-tasks/routes.d.ts.map +1 -1
- package/dist/background-tasks/routes.js +33 -31
- package/dist/background-tasks/routes.js.map +1 -1
- package/dist/deployment-identity-protocol.d.ts +3 -0
- package/dist/deployment-identity-protocol.d.ts.map +1 -0
- package/dist/deployment-identity-protocol.js +3 -0
- package/dist/deployment-identity-protocol.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +16 -5
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +16 -5
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/cf-types.d.ts +18 -12
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +44 -182
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +102 -353
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/deployment-identity.d.ts +121 -0
- package/dist/do-runner/deployment-identity.d.ts.map +1 -0
- package/dist/do-runner/deployment-identity.js +272 -0
- package/dist/do-runner/deployment-identity.js.map +1 -0
- package/dist/do-runner/do-error-response.d.ts +1 -1
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +7 -1
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +23 -16
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +303 -70
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts +1 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +6 -8
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-principal-header.d.ts +16 -0
- package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
- package/dist/do-runner/execution-principal-header.js +20 -0
- package/dist/do-runner/execution-principal-header.js.map +1 -0
- package/dist/do-runner/hub-do.d.ts +17 -25
- package/dist/do-runner/hub-do.d.ts.map +1 -1
- package/dist/do-runner/hub-do.js +63 -59
- package/dist/do-runner/hub-do.js.map +1 -1
- package/dist/do-runner/index.d.ts +12 -10
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +10 -9
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +0 -7
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +1 -2
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +8 -25
- package/dist/do-runner/memory-id.d.ts.map +1 -1
- package/dist/do-runner/memory-id.js +25 -52
- package/dist/do-runner/memory-id.js.map +1 -1
- package/dist/do-runner/path-safe-id.d.ts +2 -48
- package/dist/do-runner/path-safe-id.d.ts.map +1 -1
- package/dist/do-runner/path-safe-id.js +3 -93
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/pubsub.d.ts +1 -1
- package/dist/do-runner/pubsub.js +1 -1
- package/dist/do-runner/runtime.d.ts +47 -34
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +281 -143
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/schedule-source.d.ts +81 -0
- package/dist/do-runner/schedule-source.d.ts.map +1 -0
- package/dist/do-runner/schedule-source.js +64 -0
- package/dist/do-runner/schedule-source.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +18 -32
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +52 -74
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/goals/objective-routes.d.ts +7 -4
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +58 -43
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +18 -21
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -37
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +3 -4
- package/dist/host-kit/bearer-auth.d.ts.map +1 -1
- package/dist/host-kit/bearer-auth.js +7 -11
- package/dist/host-kit/bearer-auth.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +14 -5
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +47 -15
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +1 -1
- package/dist/host-kit/env-vars.js +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +149 -73
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +619 -141
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +62 -54
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +90 -61
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +6 -7
- package/dist/host-kit/hub-topology.d.ts.map +1 -1
- package/dist/host-kit/hub-topology.js +16 -12
- package/dist/host-kit/hub-topology.js.map +1 -1
- package/dist/host-kit/index.d.ts +13 -11
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +9 -12
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/maintenance-capability.d.ts +58 -0
- package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
- package/dist/host-kit/maintenance-capability.js +268 -0
- package/dist/host-kit/maintenance-capability.js.map +1 -0
- package/dist/host-kit/memory-boundary.d.ts +4 -19
- package/dist/host-kit/memory-boundary.d.ts.map +1 -1
- package/dist/host-kit/memory-boundary.js +12 -27
- package/dist/host-kit/memory-boundary.js.map +1 -1
- package/dist/host-kit/resource-access.d.ts +4 -0
- package/dist/host-kit/resource-access.d.ts.map +1 -0
- package/dist/host-kit/resource-access.js +12 -0
- package/dist/host-kit/resource-access.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +25 -15
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +61 -46
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/state-egress.d.ts +51 -0
- package/dist/host-kit/state-egress.d.ts.map +1 -0
- package/dist/host-kit/state-egress.js +120 -0
- package/dist/host-kit/state-egress.js.map +1 -0
- package/dist/host-kit/stream-router.d.ts +9 -4
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-router.js +45 -38
- package/dist/host-kit/stream-router.js.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +10 -10
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +60 -90
- package/dist/host-kit/stream-ticket.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +17 -11
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +33 -59
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/host-kit/verifier.d.ts +6 -6
- package/dist/host-kit/verifier.d.ts.map +1 -1
- package/dist/host-kit/verifier.js +51 -119
- package/dist/host-kit/verifier.js.map +1 -1
- package/dist/http-body.d.ts +20 -0
- package/dist/http-body.d.ts.map +1 -0
- package/dist/http-body.js +67 -0
- package/dist/http-body.js.map +1 -0
- package/dist/schedules/index.d.ts +3 -2
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +5 -4
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/router.d.ts +16 -10
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +153 -91
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +88 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +411 -50
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/target-policy.d.ts +29 -0
- package/dist/schedules/target-policy.d.ts.map +1 -0
- package/dist/schedules/target-policy.js +70 -0
- package/dist/schedules/target-policy.js.map +1 -0
- package/dist/schedules/tick.d.ts +125 -21
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +637 -160
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +0 -19
- package/dist/signal-providers/delivery.d.ts.map +1 -1
- package/dist/signal-providers/delivery.js +5 -54
- package/dist/signal-providers/delivery.js.map +1 -1
- package/dist/signal-providers/github-provider.d.ts.map +1 -1
- package/dist/signal-providers/github-provider.js +9 -16
- package/dist/signal-providers/github-provider.js.map +1 -1
- package/dist/signal-providers/host-do.d.ts +3 -45
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +86 -106
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/host-topology.d.ts +5 -14
- package/dist/signal-providers/host-topology.d.ts.map +1 -1
- package/dist/signal-providers/host-topology.js +11 -25
- package/dist/signal-providers/host-topology.js.map +1 -1
- package/dist/signal-providers/index.d.ts +3 -3
- package/dist/signal-providers/index.d.ts.map +1 -1
- package/dist/signal-providers/index.js +3 -3
- package/dist/signal-providers/index.js.map +1 -1
- package/dist/signal-providers/provider.d.ts +4 -5
- package/dist/signal-providers/provider.d.ts.map +1 -1
- package/dist/signal-providers/provider.js +5 -6
- package/dist/signal-providers/provider.js.map +1 -1
- package/dist/signal-providers/subscription-d1.d.ts +10 -57
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
- package/dist/signal-providers/subscription-d1.js +208 -155
- package/dist/signal-providers/subscription-d1.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +28 -14
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +117 -88
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/client.js +8 -8
- package/dist/signals/client.js.map +1 -1
- package/dist/signals/d1-shared.js +1 -1
- package/dist/signals/d1-shared.js.map +1 -1
- package/dist/signals/index.d.ts +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +12 -6
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +37 -21
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +5 -8
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +8 -13
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +10 -10
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -51
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +74 -15
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +484 -41
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/dist/signals/thread-state-d1.d.ts.map +1 -1
- package/dist/signals/thread-state-d1.js +2 -3
- package/dist/signals/thread-state-d1.js.map +1 -1
- package/package.json +30 -7
- package/scripts/seed-deployment-identity.mjs +252 -0
- package/dist/approval-api/tenant-brand.d.ts +0 -35
- package/dist/approval-api/tenant-brand.d.ts.map +0 -1
- package/dist/approval-api/tenant-brand.js +0 -19
- package/dist/approval-api/tenant-brand.js.map +0 -1
- package/dist/approval-api/tenant-context.d.ts +0 -84
- package/dist/approval-api/tenant-context.d.ts.map +0 -1
- package/dist/approval-api/tenant-context.js +0 -112
- package/dist/approval-api/tenant-context.js.map +0 -1
- package/dist/approval-api/tenant-store.d.ts +0 -36
- package/dist/approval-api/tenant-store.d.ts.map +0 -1
- package/dist/approval-api/tenant-store.js +0 -129
- package/dist/approval-api/tenant-store.js.map +0 -1
- package/dist/do-runner/resume-ledger.d.ts +0 -48
- package/dist/do-runner/resume-ledger.d.ts.map +0 -1
- package/dist/do-runner/resume-ledger.js +0 -60
- package/dist/do-runner/resume-ledger.js.map +0 -1
- package/dist/do-runner/thread-header.d.ts +0 -31
- package/dist/do-runner/thread-header.d.ts.map +0 -1
- package/dist/do-runner/thread-header.js +0 -39
- package/dist/do-runner/thread-header.js.map +0 -1
- package/dist/host-kit/subdomain-check.d.ts +0 -23
- package/dist/host-kit/subdomain-check.d.ts.map +0 -1
- package/dist/host-kit/subdomain-check.js +0 -61
- package/dist/host-kit/subdomain-check.js.map +0 -1
- package/dist/host-kit/tenant-registry.d.ts +0 -51
- package/dist/host-kit/tenant-registry.d.ts.map +0 -1
- package/dist/host-kit/tenant-registry.js +0 -88
- package/dist/host-kit/tenant-registry.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// The agent-memory host boundary
|
|
3
|
-
//
|
|
4
|
-
// ownership 404, factored out because memory ids reach the boundary through
|
|
2
|
+
// The agent-memory host boundary — the memory analogue of createRunRouter's
|
|
3
|
+
// "runId is server-assigned" 400, factored out because memory ids reach the boundary through
|
|
5
4
|
// MANY routes (Track A's agent runs, Track C's signals, Track D's threaded
|
|
6
5
|
// schedule fires) where a runId reaches exactly one.
|
|
7
6
|
//
|
|
@@ -12,12 +11,12 @@
|
|
|
12
11
|
// every new route. One named, tested guard that every memory-touching route
|
|
13
12
|
// calls is the only version of this that survives contact with the fifth route.
|
|
14
13
|
//
|
|
15
|
-
// It lives in host-kit, not do-runner/memory-id.ts (which owns the mints
|
|
16
|
-
//
|
|
14
|
+
// It lives in host-kit, not do-runner/memory-id.ts (which owns the mints),
|
|
15
|
+
// because the guard's contract IS its HTTP
|
|
17
16
|
// status — RunRouteError carries the 400/404 the doctrine names, so a route
|
|
18
17
|
// gets the posture by calling it rather than by remembering to map an error —
|
|
19
|
-
// and
|
|
20
|
-
|
|
18
|
+
// and do-runner stays independent of HTTP routing.
|
|
19
|
+
import { isPathSafeId } from '../do-runner/index.js';
|
|
21
20
|
import { RunRouteError } from './run-route-error.js';
|
|
22
21
|
/**
|
|
23
22
|
* The memory-id fields no client body may name — the TCB_ONLY_CREATE_FIELDS
|
|
@@ -75,33 +74,19 @@ export function assertNoClientMemoryIds(body) {
|
|
|
75
74
|
}
|
|
76
75
|
for (const field of TCB_ONLY_MEMORY_FIELDS) {
|
|
77
76
|
if (field in value) {
|
|
78
|
-
throw new RunRouteError(400, `${field} is server-assigned (agent-memory ids are minted
|
|
77
|
+
throw new RunRouteError(400, `${field} is server-assigned (agent-memory ids are minted by the host)`);
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
worklist.push(...Object.values(value));
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* every read path into an existence oracle over ids a caller can guess (a
|
|
89
|
-
* resourceId is business identity — an email, a user id — so guessing is the
|
|
90
|
-
* expected case, not a stretch).
|
|
91
|
-
*
|
|
92
|
-
* This is the ONLY thing between a foreign threadId and its history — nothing
|
|
93
|
-
* downstream re-checks. Mastra's recall filters by `resourceId` only when the
|
|
94
|
-
* caller passes one (`if (resourceId) query += ' AND resourceId = ?'`), and core
|
|
95
|
-
* ships recall sites that pass a threadId alone, so a foreign thread recalls in
|
|
96
|
-
* FULL past this point (pinned in do-runner/memory-recall-tenancy.test.ts). Call
|
|
97
|
-
* it on EVERY memory read path; there is no second line.
|
|
98
|
-
*
|
|
99
|
-
* `tenant.ownsMemoryId` is exact because the tenant-ID pattern
|
|
100
|
-
* excludes '_' from tenant ids, so 'acme' can never own 'acmecorp_...'
|
|
101
|
-
* (do-runner/path-safe-id.ts).
|
|
84
|
+
* Validate a host-minted memory id before using it as a URL, D1, or Durable
|
|
85
|
+
* Object key. Malformed values map to 404 so the route exposes no separate
|
|
86
|
+
* validation oracle.
|
|
102
87
|
*/
|
|
103
|
-
export function
|
|
104
|
-
if (
|
|
88
|
+
export function requireMemoryId(id, label = 'threadId') {
|
|
89
|
+
if (!isPathSafeId(id)) {
|
|
105
90
|
throw new RunRouteError(404, `${label} not found`);
|
|
106
91
|
}
|
|
107
92
|
return id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-boundary.js","sourceRoot":"","sources":["../../src/host-kit/memory-boundary.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"memory-boundary.js","sourceRoot":"","sources":["../../src/host-kit/memory-boundary.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,4EAA4E;AAC5E,6FAA6F;AAC7F,2EAA2E;AAC3E,qDAAqD;AACrD,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,gFAAgF;AAChF,EAAE;AACF,2EAA2E;AAC3E,2CAA2C;AAC3C,4EAA4E;AAC5E,8EAA8E;AAC9E,mDAAmD;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,UAAU,EAAE,YAAY,CAAU,CAAC;AAI1E;;;;;;;;;;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|
|
2
|
+
/** Validate an opaque id and enforce deployment-local ownership as one 404. */
|
|
3
|
+
export declare function requireResourceAccess(context: ActorContext, kind: ResourceKind, resourceId: string, access: ResourceAccess, label?: "run" | "thread" | "resource" | "schedule"): Promise<string>;
|
|
4
|
+
//# sourceMappingURL=resource-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-access.d.ts","sourceRoot":"","sources":["../../src/host-kit/resource-access.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,+EAA+E;AAC/E,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,YAAY,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,EACtB,KAAK,6CAAO,GACX,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { isPathSafeId } from '../do-runner/index.js';
|
|
3
|
+
import { RunRouteError } from './run-route-error.js';
|
|
4
|
+
/** Validate an opaque id and enforce deployment-local ownership as one 404. */
|
|
5
|
+
export async function requireResourceAccess(context, kind, resourceId, access, label = kind) {
|
|
6
|
+
if (!isPathSafeId(resourceId) ||
|
|
7
|
+
!(await context.canAccessResource(kind, resourceId, access))) {
|
|
8
|
+
throw new RunRouteError(404, `${label} not found`);
|
|
9
|
+
}
|
|
10
|
+
return resourceId;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=resource-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-access.js","sourceRoot":"","sources":["../../src/host-kit/resource-access.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAOtC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,IAAkB,EAClB,UAAkB,EAClB,MAAsB,EACtB,KAAK,GAAG,IAAI;IAEZ,IACE,CAAC,YAAY,CAAC,UAAU,CAAC;QACzB,CAAC,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,EAC5D,CAAC;QACD,MAAM,IAAI,aAAa,CAAC,GAAG,EAAE,GAAG,KAAK,YAAY,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ActorContext, type ActorResolver, type ExecutionPrincipal, type ExecutionPrincipalKind } from '../approval-api/index.js';
|
|
2
2
|
import { type RunSummary } from '../do-runner/index.js';
|
|
3
3
|
import type { WorkflowMeta } from './workflow-meta.js';
|
|
4
4
|
export interface RunRouterOptions {
|
|
@@ -14,23 +14,24 @@ export interface RunRouterOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
workflows: ReadonlyArray<WorkflowMeta>;
|
|
16
16
|
/**
|
|
17
|
-
* Authenticates the request and
|
|
18
|
-
*
|
|
19
|
-
* from the resolved TenantContext. undefined yields 401.
|
|
17
|
+
* Authenticates the request and resolves the actor-scoped approval service
|
|
18
|
+
* and server-owned id minters. undefined yields 401.
|
|
20
19
|
*/
|
|
21
|
-
resolve:
|
|
20
|
+
resolve: ActorResolver;
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* tenant as the run it gates. Must differ from human actor ids or the
|
|
27
|
-
* separation-of-duties check can never fire. Default: 'flowsafe-system'.
|
|
22
|
+
* System-principal id used to authorize bridge bookkeeping. Approval
|
|
23
|
+
* requester provenance comes from the run summary, so this id need not be
|
|
24
|
+
* globally disjoint from human ids. Default: 'flowsafe-system'.
|
|
28
25
|
*/
|
|
29
|
-
|
|
26
|
+
systemPrincipalId?: string;
|
|
30
27
|
/** Host topology: in-process runtime, or a DO stub fetch. */
|
|
31
|
-
start: (
|
|
28
|
+
start: (input: RunStartInput) => Promise<RunSummary>;
|
|
32
29
|
status: (workflowId: string, runId: string) => Promise<RunSummary | undefined>;
|
|
33
|
-
resume: (workflowId: string, runId: string, body: unknown) => Promise<RunSummary>;
|
|
30
|
+
resume: (workflowId: string, runId: string, body: unknown, requestedBy: string, requestedByKind: ExecutionPrincipalKind) => Promise<RunSummary>;
|
|
31
|
+
/** Host policy that must pass immediately before a validated run start. */
|
|
32
|
+
beforeStart?: (context: ActorContext, workflowId: string, inputData: unknown) => Promise<void>;
|
|
33
|
+
/** Host policy that must pass immediately before a validated raw resume. */
|
|
34
|
+
beforeResume?: (context: ActorContext, workflowId: string, runId: string, body: unknown) => Promise<void>;
|
|
34
35
|
/**
|
|
35
36
|
* Self-healing hook invoked after a status() read reports the run
|
|
36
37
|
* suspended, so every status poll of a stuck run doubles as a check for a
|
|
@@ -49,10 +50,19 @@ export interface RunRouterOptions {
|
|
|
49
50
|
* logged here, never surfaced to the caller: a broken reconcile must not
|
|
50
51
|
* turn a working status read into a 500; the next poll simply retries.
|
|
51
52
|
* Absent => today's behavior (no reconciliation). Hosts wire
|
|
52
|
-
* reconcileApprovalsOnStatus(
|
|
53
|
+
* reconcileApprovalsOnStatus(systemPrincipalId) here, optionally wrapped for
|
|
53
54
|
* waitUntil-detachment.
|
|
54
55
|
*/
|
|
55
|
-
reconcileApprovals?: (
|
|
56
|
+
reconcileApprovals?: (context: ActorContext, workflowId: string, summary: RunSummary) => Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export interface RunStartInput {
|
|
59
|
+
workflowId: string;
|
|
60
|
+
runId: string;
|
|
61
|
+
inputData: unknown;
|
|
62
|
+
/** Full trusted identity stamped onto the target Durable Object request. */
|
|
63
|
+
principal: ExecutionPrincipal;
|
|
64
|
+
/** Present only for a target-verifiable schedule fire. */
|
|
65
|
+
scheduleId?: string;
|
|
56
66
|
}
|
|
57
67
|
export type RunRouter = (request: Request) => Promise<Response | null>;
|
|
58
68
|
export declare function createRunRouter(options: RunRouterOptions): RunRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,aAAa,EAElB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAE5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACvC;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACrD,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,sBAAsB,KACpC,OAAO,CAAC,UAAU,CAAC,CAAC;IACzB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,CACZ,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,CACb,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,KACV,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,kBAAkB,CAAC,EAAE,CACnB,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,UAAU,KAChB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,SAAS,EAAE,kBAAkB,CAAC;IAC9B,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAsEvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAmMpE"}
|
|
@@ -5,16 +5,12 @@
|
|
|
5
5
|
// `authenticate`, and `null` for paths outside its ownership so a host Worker
|
|
6
6
|
// can compose it after the approval router. (Its two paths are fixed rather
|
|
7
7
|
// than configurable: unlike the approval surface, a host mounts exactly one run
|
|
8
|
-
// surface.) What it owns that the hosts used to triplicate is the
|
|
9
|
-
// order:
|
|
8
|
+
// surface.) What it owns that the hosts used to triplicate is the route-specific
|
|
9
|
+
// AUTHORIZATION order:
|
|
10
10
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// applied to EVERY mutating
|
|
15
|
-
// route — start via the body's
|
|
16
|
-
// workflowId, resume and any
|
|
17
|
-
// future POST via the path's)
|
|
11
|
+
// start: authenticate -> coarse role -> workflow role -> host policy
|
|
12
|
+
// resume: authenticate -> catalog -> ownership -> coarse role -> workflow
|
|
13
|
+
// role -> host policy
|
|
18
14
|
//
|
|
19
15
|
// and the suspension bridge: a start that suspends queues its approval
|
|
20
16
|
// attributed to the STARTING actor, so that actor cannot later decide their own
|
|
@@ -24,9 +20,11 @@
|
|
|
24
20
|
// can flip a workflow boolean, but capability comes only from the server-derived
|
|
25
21
|
// grant the runtime mints per leg (approval-api/grants.ts), so a side-effecting
|
|
26
22
|
// step re-checks and fails closed. Approve through the queue, not this route.
|
|
27
|
-
import {
|
|
23
|
+
import { ActorResolutionError, RUN_START_ROLES, } from '../approval-api/index.js';
|
|
28
24
|
import { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, UnknownRunError, UnknownWorkflowError, } from '../do-runner/index.js';
|
|
25
|
+
import { readBoundedBody } from '../http-body.js';
|
|
29
26
|
import { queueApprovalForSuspension } from './approval-bridge.js';
|
|
27
|
+
import { requireResourceAccess } from './resource-access.js';
|
|
30
28
|
import { RunRouteError } from './run-route-error.js';
|
|
31
29
|
// no-store is defense in depth: this is an authenticated API served from the
|
|
32
30
|
// same origin as (and under) the SPA's `assets` block, and a run projection
|
|
@@ -44,9 +42,9 @@ function errorResponse(error) {
|
|
|
44
42
|
if (error instanceof RunRouteError) {
|
|
45
43
|
return json({ error: error.message }, error.status);
|
|
46
44
|
}
|
|
47
|
-
if (error instanceof
|
|
48
|
-
// Authenticated but
|
|
49
|
-
//
|
|
45
|
+
if (error instanceof ActorResolutionError) {
|
|
46
|
+
// Authenticated but malformed claims are a verifier bug, surfaced as
|
|
47
|
+
// forbidden rather than a retryable 500.
|
|
50
48
|
return json({ error: 'forbidden' }, 403);
|
|
51
49
|
}
|
|
52
50
|
if (error instanceof UnknownWorkflowError ||
|
|
@@ -62,9 +60,16 @@ function errorResponse(error) {
|
|
|
62
60
|
}
|
|
63
61
|
return json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
64
62
|
}
|
|
63
|
+
const MAX_RUN_BODY_BYTES = 1_048_576;
|
|
65
64
|
async function readJson(request) {
|
|
65
|
+
const raw = await readBoundedBody(request, MAX_RUN_BODY_BYTES, 'run body exceeds limit');
|
|
66
|
+
if (!raw.ok && raw.reason === 'payload-too-large') {
|
|
67
|
+
throw new RunRouteError(413, 'payload too large');
|
|
68
|
+
}
|
|
69
|
+
if (!raw.ok)
|
|
70
|
+
return null;
|
|
66
71
|
try {
|
|
67
|
-
return
|
|
72
|
+
return raw.text === '' ? null : JSON.parse(raw.text);
|
|
68
73
|
}
|
|
69
74
|
catch {
|
|
70
75
|
return null;
|
|
@@ -72,7 +77,7 @@ async function readJson(request) {
|
|
|
72
77
|
}
|
|
73
78
|
export function createRunRouter(options) {
|
|
74
79
|
const { workflows, resolve } = options;
|
|
75
|
-
const
|
|
80
|
+
const systemPrincipalId = options.systemPrincipalId ?? 'flowsafe-system';
|
|
76
81
|
const metaById = new Map(workflows.map((meta) => [meta.id, meta]));
|
|
77
82
|
function metaFor(workflowId) {
|
|
78
83
|
return metaById.get(workflowId);
|
|
@@ -83,18 +88,10 @@ export function createRunRouter(options) {
|
|
|
83
88
|
if (url.pathname !== '/workflows' && segments[0] !== 'runs')
|
|
84
89
|
return null;
|
|
85
90
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// below), never concatenates into a runId or an ownership prefix.
|
|
89
|
-
const tenant = await resolve(request);
|
|
90
|
-
if (!tenant)
|
|
91
|
+
const context = await resolve(request);
|
|
92
|
+
if (!context)
|
|
91
93
|
return json({ error: 'authentication required' }, 401);
|
|
92
|
-
const actor =
|
|
93
|
-
// Coarse gate: reviewers and viewers may inspect runs, never advance
|
|
94
|
-
// them. Applied before any route so a new POST route cannot forget it.
|
|
95
|
-
if (request.method === 'POST' && !RUN_START_ROLES.includes(actor.role)) {
|
|
96
|
-
return json({ error: 'forbidden' }, 403);
|
|
97
|
-
}
|
|
94
|
+
const actor = context.actor;
|
|
98
95
|
if (request.method === 'GET' && url.pathname === '/workflows') {
|
|
99
96
|
// The catalog echoes the AUTHENTICATED identity so the SPA renders
|
|
100
97
|
// role gates from the server's view of the actor — a client that
|
|
@@ -105,7 +102,6 @@ export function createRunRouter(options) {
|
|
|
105
102
|
actor: {
|
|
106
103
|
id: actor.id,
|
|
107
104
|
role: actor.role,
|
|
108
|
-
tenantId: actor.tenantId,
|
|
109
105
|
// Display hint: whether THIS caller may decide its own request.
|
|
110
106
|
// The resolver built it — the DECIDER_ROLES guard plus the
|
|
111
107
|
// deployment's SoD policy, fed the SAME allowSelfDecision the
|
|
@@ -113,7 +109,7 @@ export function createRunRouter(options) {
|
|
|
113
109
|
// decide() verdict. The SPA uses it to suppress a now-false "you
|
|
114
110
|
// will be refused" hint. Enforced server-side regardless
|
|
115
111
|
// (ApprovalService.decide).
|
|
116
|
-
canSelfDecide:
|
|
112
|
+
canSelfDecide: context.canSelfDecide(actor.role),
|
|
117
113
|
},
|
|
118
114
|
});
|
|
119
115
|
}
|
|
@@ -121,12 +117,15 @@ export function createRunRouter(options) {
|
|
|
121
117
|
return json({ error: 'not found' }, 404);
|
|
122
118
|
const [, workflowId, runId, action] = segments;
|
|
123
119
|
if (request.method === 'POST' && segments.length === 1) {
|
|
120
|
+
if (!RUN_START_ROLES.includes(actor.role)) {
|
|
121
|
+
return json({ error: 'forbidden' }, 403);
|
|
122
|
+
}
|
|
124
123
|
const body = (await readJson(request));
|
|
125
124
|
if (!body || typeof body.workflowId !== 'string') {
|
|
126
125
|
return json({ error: 'workflowId is required' }, 400);
|
|
127
126
|
}
|
|
128
|
-
//
|
|
129
|
-
//
|
|
127
|
+
// A client may never choose the runId. 400 (not silent override) so a
|
|
128
|
+
// caller pinning ids finds out.
|
|
130
129
|
if (body.runId !== undefined) {
|
|
131
130
|
return json({ error: 'runId is server-assigned' }, 400);
|
|
132
131
|
}
|
|
@@ -142,12 +141,28 @@ export function createRunRouter(options) {
|
|
|
142
141
|
error: `role '${actor.role}' may not start '${body.workflowId}'`,
|
|
143
142
|
}, 403);
|
|
144
143
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const summary = await options.start(
|
|
144
|
+
await options.beforeStart?.(context, body.workflowId, body.inputData);
|
|
145
|
+
const ownedRunId = context.newRunId();
|
|
146
|
+
const summary = await options.start({
|
|
147
|
+
workflowId: body.workflowId,
|
|
148
|
+
runId: ownedRunId,
|
|
149
|
+
inputData: body.inputData,
|
|
150
|
+
principal: context.principal,
|
|
151
|
+
});
|
|
148
152
|
if (summary.status !== 'suspended')
|
|
149
153
|
return json(summary);
|
|
150
|
-
|
|
154
|
+
let approvals = [];
|
|
155
|
+
try {
|
|
156
|
+
approvals = await queueApprovalForSuspension(context.service(), body.workflowId, summary, actor.id, systemPrincipalId);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(JSON.stringify({
|
|
160
|
+
type: 'approval-filing-error',
|
|
161
|
+
workflowId: body.workflowId,
|
|
162
|
+
runId: summary.runId,
|
|
163
|
+
error: error instanceof Error ? error.message : String(error),
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
151
166
|
// `approval` remains the single-gate response contract (what the SPA
|
|
152
167
|
// links); `approvals` carries every record a parallel multi-step
|
|
153
168
|
// suspension filed, so no gate is invisible to the caller.
|
|
@@ -159,22 +174,20 @@ export function createRunRouter(options) {
|
|
|
159
174
|
if (workflowId && runId && !metaFor(workflowId)) {
|
|
160
175
|
return json({ error: `unknown workflow '${workflowId}'` }, 404);
|
|
161
176
|
}
|
|
162
|
-
// Ownership
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return json({ error: 'run not found' }, 404);
|
|
177
|
+
// Ownership is resolved before role gates or runner access. A missing id
|
|
178
|
+
// and a resource owned by another principal are the same 404.
|
|
179
|
+
if (workflowId && runId && segments.length >= 3) {
|
|
180
|
+
await requireResourceAccess(context, 'run', runId, request.method === 'GET' ? 'read' : 'write', 'run');
|
|
181
|
+
}
|
|
182
|
+
if (request.method === 'POST' && !RUN_START_ROLES.includes(actor.role)) {
|
|
183
|
+
return json({ error: 'forbidden' }, 403);
|
|
170
184
|
}
|
|
171
185
|
// Per-workflow RBAC, mirrored from the start route: a module that
|
|
172
186
|
// narrows who may START a workflow also narrows who may ADVANCE it —
|
|
173
187
|
// resume drives the same state machine. Hoisted above dispatch so a
|
|
174
188
|
// future mutating route cannot forget it; GETs stay coarse
|
|
175
189
|
// (reviewer/viewer inspect runs they may not drive). Placed after the
|
|
176
|
-
//
|
|
177
|
-
// from its own /workflows catalog.
|
|
190
|
+
// catalog 404 above so an unknown workflow does not become a role oracle.
|
|
178
191
|
if (request.method !== 'GET' && workflowId) {
|
|
179
192
|
const allowedRoles = metaFor(workflowId)?.allowedRoles;
|
|
180
193
|
if (allowedRoles && !allowedRoles.includes(actor.role)) {
|
|
@@ -190,7 +203,7 @@ export function createRunRouter(options) {
|
|
|
190
203
|
return json({ error: 'run not found' }, 404);
|
|
191
204
|
if (summary.status === 'suspended' && options.reconcileApprovals) {
|
|
192
205
|
try {
|
|
193
|
-
await options.reconcileApprovals(
|
|
206
|
+
await options.reconcileApprovals(context, workflowId, summary);
|
|
194
207
|
}
|
|
195
208
|
catch (error) {
|
|
196
209
|
console.error(JSON.stringify({
|
|
@@ -208,7 +221,9 @@ export function createRunRouter(options) {
|
|
|
208
221
|
action === 'resume' &&
|
|
209
222
|
workflowId &&
|
|
210
223
|
runId) {
|
|
211
|
-
|
|
224
|
+
const body = (await readJson(request)) ?? {};
|
|
225
|
+
await options.beforeResume?.(context, workflowId, runId, body);
|
|
226
|
+
return json(await options.resume(workflowId, runId, body, context.principal.id, 'human'));
|
|
212
227
|
}
|
|
213
228
|
return json({ error: 'not found' }, 404);
|
|
214
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-router.js","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,gFAAgF;AAChF,
|
|
1
|
+
{"version":3,"file":"run-router.js","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,gFAAgF;AAChF,iFAAiF;AACjF,uBAAuB;AACvB,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,iCAAiC;AACjC,EAAE;AACF,uEAAuE;AACvE,gFAAgF;AAChF,8BAA8B;AAC9B,EAAE;AACF,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAE9E,OAAO,EAEL,oBAAoB,EAKpB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAkGrD,6EAA6E;AAC7E,4EAA4E;AAC5E,gDAAgD;AAChD,SAAS,IAAI,CAAC,OAAgB,EAAE,MAAM,GAAG,GAAG;IAC1C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC3C,MAAM;QACN,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,UAAU;SAC5B;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,Y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C;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;4BACb,IAAI,EAAE,iBAAiB;4BACvB,UAAU;4BACV,KAAK;4BACL,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAC9D,CAAC,CACH,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,IACE,OAAO,CAAC,MAAM,KAAK,MAAM;gBACzB,QAAQ,CAAC,MAAM,KAAK,CAAC;gBACrB,MAAM,KAAK,QAAQ;gBACnB,UAAU;gBACV,KAAK,EACL,CAAC;gBACD,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;gBAC7C,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC/D,OAAO,IAAI,CACT,MAAM,OAAO,CAAC,MAAM,CAClB,UAAU,EACV,KAAK,EACL,IAAI,EACJ,OAAO,CAAC,SAAS,CAAC,EAAE,EACpB,OAAO,CACR,CACF,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const STATE_EGRESS_CREDENTIAL_HEADER: "x-anchorage-state-credential";
|
|
2
|
+
export declare const STATE_EGRESS_TENANT_HEADER: "x-anchorage-state-tenant";
|
|
3
|
+
export declare const STATE_EGRESS_ENVIRONMENT_HEADER: "x-anchorage-state-environment";
|
|
4
|
+
export declare const STATE_EGRESS_RESOURCE_GROUP_HEADER: "x-anchorage-state-resource-group";
|
|
5
|
+
export declare const STATE_EGRESS_SCRIPT_HEADER: "x-anchorage-state-script";
|
|
6
|
+
export declare const STATE_EGRESS_ROUTE_HOSTNAME_HEADER: "x-anchorage-state-route-hostname";
|
|
7
|
+
export declare const STATE_EGRESS_POLICY_ID_HEADER: "x-anchorage-state-policy-id";
|
|
8
|
+
export declare const STATE_EGRESS_HEADERS: {
|
|
9
|
+
readonly credential: "x-anchorage-state-credential";
|
|
10
|
+
readonly tenantTag: "x-anchorage-state-tenant";
|
|
11
|
+
readonly environment: "x-anchorage-state-environment";
|
|
12
|
+
readonly resourceGroupId: "x-anchorage-state-resource-group";
|
|
13
|
+
readonly stateScriptName: "x-anchorage-state-script";
|
|
14
|
+
readonly routeHostname: "x-anchorage-state-route-hostname";
|
|
15
|
+
readonly policyId: "x-anchorage-state-policy-id";
|
|
16
|
+
};
|
|
17
|
+
export declare const STATE_EGRESS_RESERVED_HEADERS: ("x-anchorage-state-credential" | "x-anchorage-state-tenant" | "x-anchorage-state-environment" | "x-anchorage-state-resource-group" | "x-anchorage-state-script" | "x-anchorage-state-route-hostname" | "x-anchorage-state-policy-id")[];
|
|
18
|
+
export interface StateEgressBinding {
|
|
19
|
+
fetch(request: Request): Promise<Response>;
|
|
20
|
+
}
|
|
21
|
+
export interface StateEgressContext {
|
|
22
|
+
readonly credential: string;
|
|
23
|
+
readonly tenantTag: string;
|
|
24
|
+
readonly environment: string;
|
|
25
|
+
readonly resourceGroupId: string;
|
|
26
|
+
readonly stateScriptName: string;
|
|
27
|
+
readonly routeHostname: string;
|
|
28
|
+
readonly policyId: string;
|
|
29
|
+
}
|
|
30
|
+
/** Exact trusted-state bindings consumed by createStateEgressFetch. */
|
|
31
|
+
export interface StateEgressEnv {
|
|
32
|
+
readonly OUTBOUND_PROXY: StateEgressBinding;
|
|
33
|
+
readonly OUTBOUND_PROXY_CREDENTIAL: string;
|
|
34
|
+
readonly OUTBOUND_TENANT_ID: string;
|
|
35
|
+
readonly OUTBOUND_ENVIRONMENT: string;
|
|
36
|
+
readonly OUTBOUND_RESOURCE_GROUP_ID: string;
|
|
37
|
+
readonly OUTBOUND_STATE_SCRIPT_NAME: string;
|
|
38
|
+
readonly OUTBOUND_ROUTE_HOSTNAME: string;
|
|
39
|
+
readonly OUTBOUND_POLICY_ID: string;
|
|
40
|
+
readonly DEPLOYMENT_IDENTITY_SECRET: string;
|
|
41
|
+
}
|
|
42
|
+
/** Compare a presented state credential with the canonical stored digest. */
|
|
43
|
+
export declare function stateEgressCredentialMatches(actual: string, expectedSha256: string): Promise<boolean>;
|
|
44
|
+
/** Validate the complete trusted-state egress binding group. */
|
|
45
|
+
export declare function validateStateEgressEnv(env: StateEgressEnv): Promise<StateEgressContext>;
|
|
46
|
+
/**
|
|
47
|
+
* Adapt trusted-state fetches to the shared StateEgress entrypoint. The
|
|
48
|
+
* platform entrypoint, not this adapter, resolves and enforces the allowlist.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createStateEgressFetch(env: StateEgressEnv): typeof fetch;
|
|
51
|
+
//# sourceMappingURL=state-egress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-egress.d.ts","sourceRoot":"","sources":["../../src/host-kit/state-egress.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,8BAA8B,EACzC,8BAAuC,CAAC;AAC1C,eAAO,MAAM,0BAA0B,EAAG,0BAAmC,CAAC;AAC9E,eAAO,MAAM,+BAA+B,EAC1C,+BAAwC,CAAC;AAC3C,eAAO,MAAM,kCAAkC,EAC7C,kCAA2C,CAAC;AAC9C,eAAO,MAAM,0BAA0B,EAAG,0BAAmC,CAAC;AAC9E,eAAO,MAAM,kCAAkC,EAC7C,kCAA2C,CAAC;AAC9C,eAAO,MAAM,6BAA6B,EACxC,6BAAsC,CAAC;AAEzC,eAAO,MAAM,oBAA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sB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,KAAK,CAqBxE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { DEPLOYMENT_TAG_PATTERN, isDeploymentEnvironment, } from '../deployment-identity-protocol.js';
|
|
3
|
+
import { credentialsMatch } from '../do-runner/deployment-identity.js';
|
|
4
|
+
export const STATE_EGRESS_CREDENTIAL_HEADER = 'x-anchorage-state-credential';
|
|
5
|
+
export const STATE_EGRESS_TENANT_HEADER = 'x-anchorage-state-tenant';
|
|
6
|
+
export const STATE_EGRESS_ENVIRONMENT_HEADER = 'x-anchorage-state-environment';
|
|
7
|
+
export const STATE_EGRESS_RESOURCE_GROUP_HEADER = 'x-anchorage-state-resource-group';
|
|
8
|
+
export const STATE_EGRESS_SCRIPT_HEADER = 'x-anchorage-state-script';
|
|
9
|
+
export const STATE_EGRESS_ROUTE_HOSTNAME_HEADER = 'x-anchorage-state-route-hostname';
|
|
10
|
+
export const STATE_EGRESS_POLICY_ID_HEADER = 'x-anchorage-state-policy-id';
|
|
11
|
+
export const STATE_EGRESS_HEADERS = {
|
|
12
|
+
credential: STATE_EGRESS_CREDENTIAL_HEADER,
|
|
13
|
+
tenantTag: STATE_EGRESS_TENANT_HEADER,
|
|
14
|
+
environment: STATE_EGRESS_ENVIRONMENT_HEADER,
|
|
15
|
+
resourceGroupId: STATE_EGRESS_RESOURCE_GROUP_HEADER,
|
|
16
|
+
stateScriptName: STATE_EGRESS_SCRIPT_HEADER,
|
|
17
|
+
routeHostname: STATE_EGRESS_ROUTE_HOSTNAME_HEADER,
|
|
18
|
+
policyId: STATE_EGRESS_POLICY_ID_HEADER,
|
|
19
|
+
};
|
|
20
|
+
export const STATE_EGRESS_RESERVED_HEADERS = Object.values(STATE_EGRESS_HEADERS);
|
|
21
|
+
const CREDENTIAL_PATTERN = /^[\x21-\x7e]{32,256}$/;
|
|
22
|
+
const RESOURCE_GROUP_PATTERN = /^[a-f0-9]{20}$/;
|
|
23
|
+
const SCRIPT_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
24
|
+
const POLICY_ID_PATTERN = /^[a-z0-9][a-z0-9:_-]{0,127}$/;
|
|
25
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
26
|
+
/** Compare a presented state credential with the canonical stored digest. */
|
|
27
|
+
export async function stateEgressCredentialMatches(actual, expectedSha256) {
|
|
28
|
+
if (!CREDENTIAL_PATTERN.test(actual) ||
|
|
29
|
+
!SHA256_PATTERN.test(expectedSha256)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(actual));
|
|
33
|
+
const actualSha256 = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
34
|
+
return credentialsMatch(actualSha256, expectedSha256);
|
|
35
|
+
}
|
|
36
|
+
function canonicalRouteHostname(value) {
|
|
37
|
+
if (value !== value.toLowerCase())
|
|
38
|
+
return undefined;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = new URL(`https://${value}`);
|
|
41
|
+
return parsed.hostname === value && !parsed.port && parsed.pathname === '/'
|
|
42
|
+
? value
|
|
43
|
+
: undefined;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function stateEgressContext(env) {
|
|
50
|
+
if (!env.OUTBOUND_PROXY || typeof env.OUTBOUND_PROXY.fetch !== 'function') {
|
|
51
|
+
throw new Error('trusted state has no outbound proxy service binding');
|
|
52
|
+
}
|
|
53
|
+
if (!CREDENTIAL_PATTERN.test(env.OUTBOUND_PROXY_CREDENTIAL)) {
|
|
54
|
+
throw new Error('trusted state outbound credential must contain 32-256 visible ASCII characters');
|
|
55
|
+
}
|
|
56
|
+
if (!CREDENTIAL_PATTERN.test(env.DEPLOYMENT_IDENTITY_SECRET)) {
|
|
57
|
+
throw new Error('trusted state deployment identity is invalid');
|
|
58
|
+
}
|
|
59
|
+
if (!DEPLOYMENT_TAG_PATTERN.test(env.OUTBOUND_TENANT_ID)) {
|
|
60
|
+
throw new Error('trusted state outbound tenant is invalid');
|
|
61
|
+
}
|
|
62
|
+
if (!isDeploymentEnvironment(env.OUTBOUND_ENVIRONMENT)) {
|
|
63
|
+
throw new Error('trusted state outbound environment is invalid');
|
|
64
|
+
}
|
|
65
|
+
if (!RESOURCE_GROUP_PATTERN.test(env.OUTBOUND_RESOURCE_GROUP_ID)) {
|
|
66
|
+
throw new Error('trusted state outbound resource group is invalid');
|
|
67
|
+
}
|
|
68
|
+
if (!SCRIPT_NAME_PATTERN.test(env.OUTBOUND_STATE_SCRIPT_NAME)) {
|
|
69
|
+
throw new Error('trusted state outbound script is invalid');
|
|
70
|
+
}
|
|
71
|
+
const routeHostname = canonicalRouteHostname(env.OUTBOUND_ROUTE_HOSTNAME);
|
|
72
|
+
if (!routeHostname) {
|
|
73
|
+
throw new Error('trusted state outbound route hostname is invalid');
|
|
74
|
+
}
|
|
75
|
+
if (!POLICY_ID_PATTERN.test(env.OUTBOUND_POLICY_ID)) {
|
|
76
|
+
throw new Error('trusted state outbound policy is invalid');
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
credential: env.OUTBOUND_PROXY_CREDENTIAL,
|
|
80
|
+
tenantTag: env.OUTBOUND_TENANT_ID,
|
|
81
|
+
environment: env.OUTBOUND_ENVIRONMENT,
|
|
82
|
+
resourceGroupId: env.OUTBOUND_RESOURCE_GROUP_ID,
|
|
83
|
+
stateScriptName: env.OUTBOUND_STATE_SCRIPT_NAME,
|
|
84
|
+
routeHostname,
|
|
85
|
+
policyId: env.OUTBOUND_POLICY_ID,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Validate the complete trusted-state egress binding group. */
|
|
89
|
+
export async function validateStateEgressEnv(env) {
|
|
90
|
+
const context = stateEgressContext(env);
|
|
91
|
+
if (await credentialsMatch(context.credential, env.DEPLOYMENT_IDENTITY_SECRET)) {
|
|
92
|
+
throw new Error('trusted state outbound credential must differ from deployment identity');
|
|
93
|
+
}
|
|
94
|
+
return context;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adapt trusted-state fetches to the shared StateEgress entrypoint. The
|
|
98
|
+
* platform entrypoint, not this adapter, resolves and enforces the allowlist.
|
|
99
|
+
*/
|
|
100
|
+
export function createStateEgressFetch(env) {
|
|
101
|
+
const context = stateEgressContext(env);
|
|
102
|
+
const service = env.OUTBOUND_PROXY;
|
|
103
|
+
const deploymentIdentitySecret = env.DEPLOYMENT_IDENTITY_SECRET;
|
|
104
|
+
return async (input, init) => {
|
|
105
|
+
if (await credentialsMatch(context.credential, deploymentIdentitySecret)) {
|
|
106
|
+
throw new Error('trusted state outbound credential must differ from deployment identity');
|
|
107
|
+
}
|
|
108
|
+
const request = new Request(input, init);
|
|
109
|
+
const headers = new Headers(request.headers);
|
|
110
|
+
headers.set(STATE_EGRESS_CREDENTIAL_HEADER, context.credential);
|
|
111
|
+
headers.set(STATE_EGRESS_TENANT_HEADER, context.tenantTag);
|
|
112
|
+
headers.set(STATE_EGRESS_ENVIRONMENT_HEADER, context.environment);
|
|
113
|
+
headers.set(STATE_EGRESS_RESOURCE_GROUP_HEADER, context.resourceGroupId);
|
|
114
|
+
headers.set(STATE_EGRESS_SCRIPT_HEADER, context.stateScriptName);
|
|
115
|
+
headers.set(STATE_EGRESS_ROUTE_HOSTNAME_HEADER, context.routeHostname);
|
|
116
|
+
headers.set(STATE_EGRESS_POLICY_ID_HEADER, context.policyId);
|
|
117
|
+
return service.fetch(new Request(request, { headers }));
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=state-egress.js.map
|