@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
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { Schedule, ScheduleFilter, ScheduleTrigger, ScheduleTriggerListOptions, ScheduleUpdate } from '@mastra/core/storage';
|
|
2
|
-
import { type ApprovalRole, type
|
|
2
|
+
import { type ActorResolver, type ApprovalRole, type ResourceOwner } from '../approval-api/index.js';
|
|
3
|
+
import { type BoundThreadTargetValidator } from '../host-kit/index.js';
|
|
4
|
+
import { type AuthorizedSchedule, type ScheduleTargetPolicy } from './target-policy.js';
|
|
3
5
|
/** The storage subset the facade reads/writes (a subset of D1SchedulesStorage). */
|
|
4
6
|
export interface ScheduleFacadeStore {
|
|
5
|
-
|
|
7
|
+
createOwnedSchedule(schedule: AuthorizedSchedule, owner: ResourceOwner, maxSchedules: number): Promise<Schedule | null>;
|
|
6
8
|
getSchedule(id: string): Promise<Schedule | null>;
|
|
7
9
|
listSchedules(filter?: ScheduleFilter): Promise<Schedule[]>;
|
|
8
10
|
updateSchedule(id: string, patch: ScheduleUpdate): Promise<Schedule>;
|
|
9
|
-
|
|
11
|
+
deleteOwnedSchedule(id: string): Promise<'deleted' | 'pending'>;
|
|
10
12
|
listTriggers(scheduleId: string, opts?: ScheduleTriggerListOptions): Promise<ScheduleTrigger[]>;
|
|
11
13
|
}
|
|
12
14
|
/** The operations, one per route. */
|
|
@@ -14,7 +16,7 @@ export type ScheduleOperation = 'create' | 'get' | 'list' | 'update' | 'delete'
|
|
|
14
16
|
/** The structured audit event a mutation (and a denied read) emits. */
|
|
15
17
|
export interface ScheduleRouteAuditEvent {
|
|
16
18
|
type: 'schedule.route';
|
|
17
|
-
|
|
19
|
+
deploymentTag?: string;
|
|
18
20
|
actorId: string;
|
|
19
21
|
operation: ScheduleOperation;
|
|
20
22
|
/** Present once an id is in play (all but create/list). */
|
|
@@ -27,10 +29,14 @@ export interface ScheduleRouteAuditEvent {
|
|
|
27
29
|
/** The audit seam — a host bridges this to its AuditLogger / SIEM sink. */
|
|
28
30
|
export type ScheduleRouteAuditSink = (event: ScheduleRouteAuditEvent) => void | Promise<void>;
|
|
29
31
|
export interface ScheduleRouterOptions {
|
|
30
|
-
/** Authenticate
|
|
31
|
-
resolve:
|
|
32
|
+
/** Authenticate and validate the actor; undefined means 401. */
|
|
33
|
+
resolve: ActorResolver;
|
|
32
34
|
/** The schedules domain the facade reads/writes. */
|
|
33
35
|
store: ScheduleFacadeStore;
|
|
36
|
+
/** Catalog-backed target authorization shared with the fire-time tick. */
|
|
37
|
+
targetPolicy: ScheduleTargetPolicy;
|
|
38
|
+
/** Prove fixed-thread agent targets are durable bound memory. */
|
|
39
|
+
validateThreadTarget: BoundThreadTargetValidator;
|
|
34
40
|
/**
|
|
35
41
|
* Who may create/update/delete/pause/resume. Default RUN_START_ROLES
|
|
36
42
|
* (operator/admin) — reviewers/viewers cannot author schedules. Reads (get/
|
|
@@ -40,16 +46,16 @@ export interface ScheduleRouterOptions {
|
|
|
40
46
|
/** Every mutation (and denied read) is audited through this. Absent ⇒ no audit. */
|
|
41
47
|
audit?: ScheduleRouteAuditSink;
|
|
42
48
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
49
|
+
* Deployment count cap. A create at or over it is REJECTED. Must be a
|
|
50
|
+
* nonnegative safe integer; zero denies
|
|
45
51
|
* every create. Default 100.
|
|
46
52
|
*/
|
|
47
|
-
|
|
53
|
+
maxSchedules?: number;
|
|
48
54
|
/**
|
|
49
55
|
* Per-schedule fire-rate cap: the minimum interval between two
|
|
50
56
|
* consecutive fires of a schedule's cron, in ms. A cron whose interval is
|
|
51
57
|
* shorter is REJECTED at create/update — bounding the aggregate fire rate a
|
|
52
|
-
*
|
|
58
|
+
* deployment can schedule (with the count cap). Must be a positive safe integer.
|
|
53
59
|
* Default 60000 (1 minute).
|
|
54
60
|
*/
|
|
55
61
|
minFireIntervalMs?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/schedules/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/schedules/router.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,0BAA0B,EAC1B,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,0BAA0B,EAIhC,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAG1B,MAAM,oBAAoB,CAAC;AAG5B,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IAClC,mBAAmB,CACjB,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAClD,aAAa,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5D,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrE,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAChE,YAAY,CACV,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CAC/B;AAED,qCAAqC;AACrC,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,KAAK,GACL,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,UAAU,CAAC;AAEf,uEAAuE;AACvE,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,gBAAgB,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,UAAU,GAAG,UAAU,CAAC;IACjC,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAAG,CACnC,KAAK,EAAE,uBAAuB,KAC3B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,OAAO,EAAE,aAAa,CAAC;IACvB,oDAAoD;IACpD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,0EAA0E;IAC1E,YAAY,EAAE,oBAAoB,CAAC;IACnC,iEAAiE;IACjE,oBAAoB,EAAE,0BAA0B,CAAC;IACjD;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,mFAAmF;IACnF,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAuf5E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAoUhB"}
|
package/dist/schedules/router.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Track D (M-006), CI-M-006-003 — createScheduleRouter, the
|
|
3
|
-
// the schedules domain.
|
|
4
|
-
// is stamped into metadata.tenantId at create (server-controlled, never a client
|
|
5
|
-
// value) and every read/list/mutation is tenant-scoped on it. Ids are
|
|
2
|
+
// Track D (M-006), CI-M-006-003 — createScheduleRouter, the authenticated facade
|
|
3
|
+
// over the deployment schedules domain. Ids are
|
|
6
4
|
// SERVER-MINTED `${prefix}${uuid}` (agent_/schedule_) — a client cannot name the
|
|
7
|
-
// id, so it cannot collide with (or probe for) another
|
|
5
|
+
// id, so it cannot collide with (or probe for) another schedule, the
|
|
8
6
|
// INV-1 posture applied to schedule ids; core's slugified client-id path is
|
|
9
7
|
// avoided (a slugify-drift + existence-oracle vector).
|
|
10
8
|
//
|
|
11
9
|
// The write path is an ingestion trust boundary (P6-lite, DL-006) — the same gate
|
|
12
10
|
// order createSignalRouter / createObjectiveRouter enforce:
|
|
13
11
|
//
|
|
14
|
-
// 1. resolve (authenticate
|
|
15
|
-
// 2.
|
|
16
|
-
// 3.
|
|
12
|
+
// 1. resolve (authenticate and validate actor) -> 401 / 403
|
|
13
|
+
// 2. existing-schedule ownership before role or storage -> 404
|
|
14
|
+
// 3. coarse role (RUN_START_ROLES) on MUTATIONS -> 403 (reads stay coarse)
|
|
17
15
|
// 4. size cap on the raw body, THEN JSON parse -> 413 / 400
|
|
18
|
-
// 5. field validation +
|
|
16
|
+
// 5. field validation + deployment COUNT cap + fire-RATE cap (DL-007)
|
|
19
17
|
// 6. P4 reserved requestContext-key rejection (DL-004) -> 400
|
|
20
18
|
// 7. audit (schedule.route) + persist
|
|
21
19
|
//
|
|
@@ -28,8 +26,8 @@
|
|
|
28
26
|
// ifIdle.streamOptions.requestContext).
|
|
29
27
|
//
|
|
30
28
|
// Every MUTATION is audited on ACCEPT and on EVERY post-auth denial (role 403,
|
|
31
|
-
//
|
|
32
|
-
// post-auth denial
|
|
29
|
+
// missing 404, cap/field/reserved-key 400). A GET/list is audited only on a
|
|
30
|
+
// post-auth denial; a benign successful read is not. A
|
|
33
31
|
// pre-auth failure (401 / resolver throw -> 403) is NOT audited: an
|
|
34
32
|
// unauthenticated flood must never be able to write the log.
|
|
35
33
|
//
|
|
@@ -39,11 +37,13 @@
|
|
|
39
37
|
// starts no runs.
|
|
40
38
|
import { AGENT_SCHEDULE_PREFIX, ScheduleInputSchema, toScheduleView, WORKFLOW_SCHEDULE_PREFIX, } from '@mastra/core/schedules';
|
|
41
39
|
import { computeNextFireAt, validateCron } from '@mastra/core/workflows';
|
|
42
|
-
import {
|
|
43
|
-
import { RunRouteError,
|
|
40
|
+
import { ActorResolutionError, RUN_START_ROLES, } from '../approval-api/index.js';
|
|
41
|
+
import { RunRouteError, requireMemoryId, requireResourceAccess, } from '../host-kit/index.js';
|
|
44
42
|
import { safeDecodeSegment } from '../host-kit/route-path.js';
|
|
43
|
+
import { readBoundedBody } from '../http-body.js';
|
|
45
44
|
import { internalErrorResponse } from '../internal-error-response.js';
|
|
46
45
|
import { nonnegativeSafeInteger, positiveSafeInteger, } from '../numeric-config.js';
|
|
46
|
+
import { scheduleCreatorRole, scheduleWithCreatorRole, } from './target-policy.js';
|
|
47
47
|
import { isReservedScheduleContextKey } from './tick.js';
|
|
48
48
|
function json(payload, status = 200) {
|
|
49
49
|
return new Response(JSON.stringify(payload), {
|
|
@@ -54,15 +54,36 @@ function json(payload, status = 200) {
|
|
|
54
54
|
},
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
+
function sameOwner(left, right) {
|
|
58
|
+
return left.kind === right.kind && left.id === right.id;
|
|
59
|
+
}
|
|
60
|
+
async function requireTargetOwner(context, target, owner, validateThreadTarget) {
|
|
61
|
+
if (target.type !== 'agent' ||
|
|
62
|
+
target.threadId === undefined ||
|
|
63
|
+
target.resourceId === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await requireResourceAccess(context, 'thread', target.threadId, 'write', 'thread');
|
|
67
|
+
await requireResourceAccess(context, 'resource', target.resourceId, 'write', 'resource');
|
|
68
|
+
const [threadOwner, resourceOwner] = await Promise.all([
|
|
69
|
+
context.resourceOwnerFor('thread', target.threadId),
|
|
70
|
+
context.resourceOwnerFor('resource', target.resourceId),
|
|
71
|
+
]);
|
|
72
|
+
if (!threadOwner ||
|
|
73
|
+
!resourceOwner ||
|
|
74
|
+
!sameOwner(threadOwner, owner) ||
|
|
75
|
+
!sameOwner(resourceOwner, owner)) {
|
|
76
|
+
throw new RunRouteError(404, 'target resource not found');
|
|
77
|
+
}
|
|
78
|
+
await validateThreadTarget(context, {
|
|
79
|
+
agentId: target.agentId,
|
|
80
|
+
threadId: target.threadId,
|
|
81
|
+
resourceId: target.resourceId,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
57
84
|
function reject(reason, message, status = 400) {
|
|
58
85
|
return { reason, message, status };
|
|
59
86
|
}
|
|
60
|
-
/** A schedule is owned by the tenant iff its metadata.tenantId matches. */
|
|
61
|
-
function ownsSchedule(schedule, tenantId) {
|
|
62
|
-
const owner = schedule.metadata
|
|
63
|
-
?.tenantId;
|
|
64
|
-
return owner === tenantId;
|
|
65
|
-
}
|
|
66
87
|
/**
|
|
67
88
|
* The stored-context barrier over both requestContext-carrying surfaces of a create/update
|
|
68
89
|
* body: the top-level `requestContext` (workflow + non-standard agent) and the
|
|
@@ -132,7 +153,7 @@ function checkFireRate(cron, timezone, minFireIntervalMs, now) {
|
|
|
132
153
|
// NOTE (DL-007 limitation): this samples only the NEXT two fires at request
|
|
133
154
|
// time. A non-uniform cron (e.g. a dense minute cluster + a long gap) can pass
|
|
134
155
|
// when sampled during the gap yet still fire the dense cluster later; the
|
|
135
|
-
//
|
|
156
|
+
// deployment COUNT cap and the tick's run-cap seam are the real aggregate
|
|
136
157
|
// backstops. A precise cycle-wide bound is deliberately not attempted here.
|
|
137
158
|
if (second.value - first.value < minFireIntervalMs) {
|
|
138
159
|
return reject('fire-rate-too-high', `cron fires more often than the ${minFireIntervalMs}ms floor`);
|
|
@@ -207,7 +228,7 @@ function metadataOrReject(value) {
|
|
|
207
228
|
}
|
|
208
229
|
return { ok: true, value: value };
|
|
209
230
|
}
|
|
210
|
-
function validateMemoryIds(body
|
|
231
|
+
function validateMemoryIds(body) {
|
|
211
232
|
const hasThread = body.threadId !== undefined;
|
|
212
233
|
const hasResource = body.resourceId !== undefined;
|
|
213
234
|
if (hasThread && !nonEmptyString(body.threadId)) {
|
|
@@ -226,8 +247,8 @@ function validateMemoryIds(body, tenant) {
|
|
|
226
247
|
if (!hasResource) {
|
|
227
248
|
return reject('resourceId-required', 'resourceId is required when threadId is set');
|
|
228
249
|
}
|
|
229
|
-
|
|
230
|
-
|
|
250
|
+
requireMemoryId(body.threadId, 'threadId');
|
|
251
|
+
requireMemoryId(body.resourceId, 'resourceId');
|
|
231
252
|
return undefined;
|
|
232
253
|
}
|
|
233
254
|
function normalizeAgentTarget(scheduleId, values) {
|
|
@@ -262,9 +283,8 @@ function normalizeAgentTarget(scheduleId, values) {
|
|
|
262
283
|
},
|
|
263
284
|
};
|
|
264
285
|
}
|
|
265
|
-
/** Build a fresh Schedule row from a create body
|
|
266
|
-
function buildCreateRow(body,
|
|
267
|
-
const tenantId = tenant.tenantId;
|
|
286
|
+
/** Build a fresh server-id'd Schedule row from a create body. */
|
|
287
|
+
function buildCreateRow(body, now, minFireIntervalMs) {
|
|
268
288
|
const hasWorkflow = 'workflowId' in body && body.workflowId !== undefined;
|
|
269
289
|
const hasAgent = 'agentId' in body && body.agentId !== undefined;
|
|
270
290
|
if (hasWorkflow === hasAgent) {
|
|
@@ -313,11 +333,6 @@ function buildCreateRow(body, tenant, now, minFireIntervalMs) {
|
|
|
313
333
|
return parsedMetadata;
|
|
314
334
|
clientMetadata = parsedMetadata.value;
|
|
315
335
|
}
|
|
316
|
-
// tenantId is stamped LAST so a client value can never override it (DL-013).
|
|
317
|
-
const metadata = {
|
|
318
|
-
...clientMetadata,
|
|
319
|
-
tenantId,
|
|
320
|
-
};
|
|
321
336
|
// checkFireRate above already proved the cron has a future occurrence, so this
|
|
322
337
|
// cannot throw; nextFireOrReject keeps it defensive without a bare computeNextFireAt.
|
|
323
338
|
const nextFire = nextFireOrReject(cron, timezone, now);
|
|
@@ -331,7 +346,7 @@ function buildCreateRow(body, tenant, now, minFireIntervalMs) {
|
|
|
331
346
|
nextFireAt,
|
|
332
347
|
createdAt: now,
|
|
333
348
|
updatedAt: now,
|
|
334
|
-
metadata,
|
|
349
|
+
...(body.metadata !== undefined ? { metadata: clientMetadata } : {}),
|
|
335
350
|
};
|
|
336
351
|
if (hasWorkflow) {
|
|
337
352
|
const unknown = firstUnknownField(body, WORKFLOW_CREATE_FIELDS);
|
|
@@ -396,7 +411,7 @@ function buildCreateRow(body, tenant, now, minFireIntervalMs) {
|
|
|
396
411
|
error: reject('name-invalid', 'name must be a string'),
|
|
397
412
|
};
|
|
398
413
|
}
|
|
399
|
-
const memory = validateMemoryIds(body
|
|
414
|
+
const memory = validateMemoryIds(body);
|
|
400
415
|
if (memory)
|
|
401
416
|
return { ok: false, error: memory };
|
|
402
417
|
const reserved = reservedContextRejection(body, 'agent');
|
|
@@ -417,9 +432,9 @@ function buildCreateRow(body, tenant, now, minFireIntervalMs) {
|
|
|
417
432
|
};
|
|
418
433
|
}
|
|
419
434
|
export function createScheduleRouter(options) {
|
|
420
|
-
const { resolve, store } = options;
|
|
435
|
+
const { resolve, store, targetPolicy } = options;
|
|
421
436
|
const roles = options.roles ?? RUN_START_ROLES;
|
|
422
|
-
const maxSchedules = nonnegativeSafeInteger(options.
|
|
437
|
+
const maxSchedules = nonnegativeSafeInteger(options.maxSchedules ?? 100, 'maxSchedules');
|
|
423
438
|
const minFireIntervalMs = positiveSafeInteger(options.minFireIntervalMs ?? 60_000, 'minFireIntervalMs');
|
|
424
439
|
const maxContentBytes = nonnegativeSafeInteger(options.maxContentBytes ?? 16_384, 'schedule maxContentBytes');
|
|
425
440
|
const base = options.basePath ?? '/api/schedules';
|
|
@@ -451,21 +466,23 @@ export function createScheduleRouter(options) {
|
|
|
451
466
|
return json({ error: 'method not allowed' }, 405);
|
|
452
467
|
}
|
|
453
468
|
const isMutation = operation !== 'get' && operation !== 'list' && operation !== 'triggers';
|
|
454
|
-
// `
|
|
455
|
-
//
|
|
469
|
+
// `context` is hoisted so the audit closure can read it. It stays undefined
|
|
470
|
+
// until resolve succeeds, and the closure
|
|
456
471
|
// no-ops while it is — so a pre-auth failure never writes the log (an
|
|
457
472
|
// unauthenticated flood cannot spam the audit sink).
|
|
458
|
-
let
|
|
473
|
+
let context;
|
|
459
474
|
const audit = async (outcome, reason) => {
|
|
460
|
-
if (!options.audit || !
|
|
475
|
+
if (!options.audit || !context)
|
|
461
476
|
return;
|
|
462
477
|
// A benign read is not audited; only its denial is.
|
|
463
478
|
if (!isMutation && outcome === 'accepted')
|
|
464
479
|
return;
|
|
465
480
|
await options.audit({
|
|
466
481
|
type: 'schedule.route',
|
|
467
|
-
|
|
468
|
-
|
|
482
|
+
...(context.deploymentTag !== undefined
|
|
483
|
+
? { deploymentTag: context.deploymentTag }
|
|
484
|
+
: {}),
|
|
485
|
+
actorId: context.actor.id,
|
|
469
486
|
operation,
|
|
470
487
|
...(id !== undefined ? { scheduleId: id } : {}),
|
|
471
488
|
outcome,
|
|
@@ -473,24 +490,44 @@ export function createScheduleRouter(options) {
|
|
|
473
490
|
timestamp: new Date().toISOString(),
|
|
474
491
|
});
|
|
475
492
|
};
|
|
493
|
+
const auditCommittedMutation = async () => {
|
|
494
|
+
try {
|
|
495
|
+
await audit('accepted');
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
console.error(JSON.stringify({
|
|
499
|
+
type: 'schedule.route-audit-error',
|
|
500
|
+
operation,
|
|
501
|
+
...(id !== undefined ? { scheduleId: id } : {}),
|
|
502
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
503
|
+
}));
|
|
504
|
+
}
|
|
505
|
+
};
|
|
476
506
|
try {
|
|
477
507
|
// 1. Resolve.
|
|
478
|
-
|
|
479
|
-
if (!
|
|
508
|
+
context = await resolve(request);
|
|
509
|
+
if (!context)
|
|
480
510
|
return json({ error: 'authentication required' }, 401);
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
// 2. Coarse role on mutations.
|
|
485
|
-
if (isMutation && !roles.includes(tenant.actor.role)) {
|
|
511
|
+
// CREATE has no resource to resolve yet, so its coarse role gate comes
|
|
512
|
+
// immediately after authentication.
|
|
513
|
+
if (operation === 'create' && !roles.includes(context.actor.role)) {
|
|
486
514
|
await audit('rejected', 'forbidden-role');
|
|
487
515
|
return json({ error: 'forbidden' }, 403);
|
|
488
516
|
}
|
|
489
|
-
// LIST
|
|
517
|
+
// LIST returns only schedules this principal may read. Reviewer/admin
|
|
518
|
+
// policy is applied by canAccessResource; owners always retain access.
|
|
490
519
|
if (operation === 'list') {
|
|
520
|
+
const accessContext = context;
|
|
491
521
|
const all = await store.listSchedules();
|
|
492
|
-
const
|
|
493
|
-
|
|
522
|
+
const accessible = await Promise.all(all.map(async (schedule) => ({
|
|
523
|
+
schedule,
|
|
524
|
+
allowed: await accessContext.canAccessResource('schedule', schedule.id, 'read'),
|
|
525
|
+
})));
|
|
526
|
+
return json({
|
|
527
|
+
schedules: accessible
|
|
528
|
+
.filter((entry) => entry.allowed)
|
|
529
|
+
.map((entry) => toView(entry.schedule)),
|
|
530
|
+
});
|
|
494
531
|
}
|
|
495
532
|
// CREATE — count cap, field/cron/fire-rate/reserved-key checks, persist.
|
|
496
533
|
if (operation === 'create') {
|
|
@@ -499,38 +536,40 @@ export function createScheduleRouter(options) {
|
|
|
499
536
|
await audit('rejected', parsed.status === 413 ? 'payload-too-large' : 'malformed-body');
|
|
500
537
|
return parsed;
|
|
501
538
|
}
|
|
502
|
-
|
|
503
|
-
// is check-then-act (no atomic increment through the domain seam), so N
|
|
504
|
-
// concurrent creates at count = cap-1 can each read the same count and
|
|
505
|
-
// all insert, overshooting by up to N — self-limited to the requester's
|
|
506
|
-
// own tenant. The tick's run-cap seam is the real cost backstop; a hard
|
|
507
|
-
// atomic cap would need a transaction D1 does not expose here.
|
|
508
|
-
const owned = (await store.listSchedules()).filter((s) => ownsSchedule(s, ownerTenant));
|
|
509
|
-
if (owned.length >= maxSchedules) {
|
|
510
|
-
await audit('rejected', 'schedule-count-cap');
|
|
511
|
-
return json({ error: `tenant schedule cap of ${maxSchedules} reached` }, 400);
|
|
512
|
-
}
|
|
513
|
-
const built = buildCreateRow(parsed, tenant, Date.now(), minFireIntervalMs);
|
|
539
|
+
const built = buildCreateRow(parsed, Date.now(), minFireIntervalMs);
|
|
514
540
|
if (!built.ok) {
|
|
515
541
|
await audit('rejected', built.error.reason);
|
|
516
542
|
return json({ error: built.error.message }, built.error.status);
|
|
517
543
|
}
|
|
518
|
-
const
|
|
519
|
-
|
|
544
|
+
const targetDecision = targetPolicy.authorize(built.value.target, context.actor.role);
|
|
545
|
+
if (!targetDecision.allowed) {
|
|
546
|
+
await audit('rejected', targetDecision.reason);
|
|
547
|
+
return json({
|
|
548
|
+
error: targetDecision.status === 404 ? 'not found' : 'forbidden',
|
|
549
|
+
}, targetDecision.status);
|
|
550
|
+
}
|
|
551
|
+
await requireTargetOwner(context, built.value.target, context.resourceOwner, options.validateThreadTarget);
|
|
552
|
+
const row = scheduleWithCreatorRole(built.value, context.actor.role);
|
|
553
|
+
const created = await store.createOwnedSchedule(row, context.resourceOwner, maxSchedules);
|
|
554
|
+
if (!created) {
|
|
555
|
+
await audit('rejected', 'schedule-count-cap');
|
|
556
|
+
return json({ error: `deployment schedule cap of ${maxSchedules} reached` }, 400);
|
|
557
|
+
}
|
|
558
|
+
await auditCommittedMutation();
|
|
520
559
|
return json({ schedule: toView(created) }, 201);
|
|
521
560
|
}
|
|
522
561
|
// Everything below addresses ONE schedule by id — 404 (no oracle) on a
|
|
523
|
-
// missing
|
|
562
|
+
// missing or foreign one, before role checks or storage access.
|
|
524
563
|
const scheduleId = id;
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
await audit('rejected', '
|
|
528
|
-
return json({ error: '
|
|
529
|
-
}
|
|
530
|
-
if (operation === 'get') {
|
|
531
|
-
return json({ schedule: toView(existing) });
|
|
564
|
+
await requireResourceAccess(context, 'schedule', scheduleId, isMutation ? 'write' : 'read', 'schedule');
|
|
565
|
+
if (isMutation && !roles.includes(context.actor.role)) {
|
|
566
|
+
await audit('rejected', 'forbidden-role');
|
|
567
|
+
return json({ error: 'forbidden' }, 403);
|
|
532
568
|
}
|
|
533
569
|
if (operation === 'triggers') {
|
|
570
|
+
// A delete-requested schedule remains owned while an indeterminate
|
|
571
|
+
// dispatch is reconciled. Its trigger history is the only public handle
|
|
572
|
+
// for that run, so keep it readable until settlement finalizes deletion.
|
|
534
573
|
// Default the limit so an omitted/garbage `?limit` never returns an
|
|
535
574
|
// UNBOUNDED history (trigger rows grow per fire; SCHEDULE_TRIGGER_
|
|
536
575
|
// RETENTION_DAYS is opt-in/unset by default).
|
|
@@ -539,24 +578,34 @@ export function createScheduleRouter(options) {
|
|
|
539
578
|
return json({ triggers });
|
|
540
579
|
}
|
|
541
580
|
if (operation === 'delete') {
|
|
542
|
-
await store.
|
|
543
|
-
await
|
|
544
|
-
return
|
|
581
|
+
const outcome = await store.deleteOwnedSchedule(scheduleId);
|
|
582
|
+
await auditCommittedMutation();
|
|
583
|
+
return outcome === 'pending'
|
|
584
|
+
? json({ ok: true, pending: true }, 202)
|
|
585
|
+
: json({ ok: true });
|
|
586
|
+
}
|
|
587
|
+
const existing = await store.getSchedule(scheduleId);
|
|
588
|
+
if (!existing) {
|
|
589
|
+
await audit('rejected', 'not-found');
|
|
590
|
+
return json({ error: 'not found' }, 404);
|
|
591
|
+
}
|
|
592
|
+
if (operation === 'get') {
|
|
593
|
+
return json({ schedule: toView(existing) });
|
|
545
594
|
}
|
|
546
595
|
if (operation === 'pause') {
|
|
547
596
|
if (existing.status === 'paused') {
|
|
548
|
-
await
|
|
597
|
+
await auditCommittedMutation();
|
|
549
598
|
return json({ schedule: toView(existing) });
|
|
550
599
|
}
|
|
551
600
|
const updated = await store.updateSchedule(scheduleId, {
|
|
552
601
|
status: 'paused',
|
|
553
602
|
});
|
|
554
|
-
await
|
|
603
|
+
await auditCommittedMutation();
|
|
555
604
|
return json({ schedule: toView(updated) });
|
|
556
605
|
}
|
|
557
606
|
if (operation === 'resume') {
|
|
558
607
|
if (existing.status === 'active') {
|
|
559
|
-
await
|
|
608
|
+
await auditCommittedMutation();
|
|
560
609
|
return json({ schedule: toView(existing) });
|
|
561
610
|
}
|
|
562
611
|
// Re-activating recomputes nextFireAt from now (core's resume semantics).
|
|
@@ -573,7 +622,7 @@ export function createScheduleRouter(options) {
|
|
|
573
622
|
status: 'active',
|
|
574
623
|
nextFireAt,
|
|
575
624
|
});
|
|
576
|
-
await
|
|
625
|
+
await auditCommittedMutation();
|
|
577
626
|
return json({ schedule: toView(updated) });
|
|
578
627
|
}
|
|
579
628
|
// UPDATE (PATCH).
|
|
@@ -587,18 +636,32 @@ export function createScheduleRouter(options) {
|
|
|
587
636
|
await audit('rejected', patch.error.reason);
|
|
588
637
|
return json({ error: patch.error.message }, patch.error.status);
|
|
589
638
|
}
|
|
639
|
+
if (patch.value.target !== undefined) {
|
|
640
|
+
const targetDecision = targetPolicy.authorize(patch.value.target, scheduleCreatorRole(existing));
|
|
641
|
+
if (!targetDecision.allowed) {
|
|
642
|
+
await audit('rejected', targetDecision.reason);
|
|
643
|
+
return json({
|
|
644
|
+
error: targetDecision.status === 404 ? 'not found' : 'forbidden',
|
|
645
|
+
}, targetDecision.status);
|
|
646
|
+
}
|
|
647
|
+
const scheduleOwner = await context.resourceOwnerFor('schedule', scheduleId);
|
|
648
|
+
if (!scheduleOwner) {
|
|
649
|
+
throw new RunRouteError(404, 'schedule not found');
|
|
650
|
+
}
|
|
651
|
+
await requireTargetOwner(context, patch.value.target, scheduleOwner, options.validateThreadTarget);
|
|
652
|
+
}
|
|
590
653
|
const updated = await store.updateSchedule(scheduleId, patch.value);
|
|
591
|
-
await
|
|
654
|
+
await auditCommittedMutation();
|
|
592
655
|
return json({ schedule: toView(updated) });
|
|
593
656
|
}
|
|
594
657
|
catch (error) {
|
|
595
658
|
if (error instanceof RunRouteError) {
|
|
596
659
|
await audit('rejected', error.status === 404
|
|
597
|
-
? '
|
|
660
|
+
? 'resource-not-found'
|
|
598
661
|
: `route-error-${error.status}`);
|
|
599
662
|
return json({ error: error.message }, error.status);
|
|
600
663
|
}
|
|
601
|
-
if (error instanceof
|
|
664
|
+
if (error instanceof ActorResolutionError) {
|
|
602
665
|
// Pre-auth: unauthenticated, so not audited.
|
|
603
666
|
return json({ error: 'forbidden' }, 403);
|
|
604
667
|
}
|
|
@@ -707,13 +770,10 @@ function buildUpdatePatch(existing, body, minFireIntervalMs, now) {
|
|
|
707
770
|
if (nextTarget.value !== undefined)
|
|
708
771
|
patch.target = nextTarget.value;
|
|
709
772
|
if (body.metadata !== undefined) {
|
|
710
|
-
// A client may not change tenantId — re-stamp the existing owner.
|
|
711
|
-
const owner = existing.metadata
|
|
712
|
-
?.tenantId;
|
|
713
773
|
const clientMeta = metadataOrReject(body.metadata);
|
|
714
774
|
if (!clientMeta.ok)
|
|
715
775
|
return clientMeta;
|
|
716
|
-
patch.metadata =
|
|
776
|
+
patch.metadata = clientMeta.value;
|
|
717
777
|
}
|
|
718
778
|
return { ok: true, value: patch };
|
|
719
779
|
}
|
|
@@ -806,13 +866,15 @@ function clampLimit(raw) {
|
|
|
806
866
|
}
|
|
807
867
|
/** Size-cap the raw body at the wire, THEN parse it to a JSON object. */
|
|
808
868
|
async function readBody(request, maxContentBytes) {
|
|
809
|
-
const raw = await request
|
|
810
|
-
|
|
811
|
-
if (bytes > maxContentBytes) {
|
|
869
|
+
const raw = await readBoundedBody(request, maxContentBytes, 'schedule body exceeds limit');
|
|
870
|
+
if (!raw.ok && raw.reason === 'payload-too-large') {
|
|
812
871
|
return json({ error: `payload exceeds ${maxContentBytes} bytes` }, 413);
|
|
813
872
|
}
|
|
873
|
+
if (!raw.ok) {
|
|
874
|
+
return json({ error: 'a JSON object body is required' }, 400);
|
|
875
|
+
}
|
|
814
876
|
try {
|
|
815
|
-
const parsed = raw === '' ? {} : JSON.parse(raw);
|
|
877
|
+
const parsed = raw.text === '' ? {} : JSON.parse(raw.text);
|
|
816
878
|
if (typeof parsed !== 'object' ||
|
|
817
879
|
parsed === null ||
|
|
818
880
|
Array.isArray(parsed)) {
|