@proofoftech/flowsafe 0.19.0 → 0.21.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 +106 -0
- package/README.md +68 -6
- package/deployment-identity-protocol.d.mts +70 -1
- package/deployment-identity-protocol.mjs +423 -5
- package/dist/agent-host/index.d.ts +1 -1
- 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.map +1 -1
- package/dist/agent-host/router.js +17 -4
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +14 -1
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +865 -308
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +43 -1
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +301 -28
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +107 -8
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +427 -55
- 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.map +1 -1
- package/dist/approval-api/actor-context.d.ts +4 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -1
- package/dist/approval-api/actor-context.js +53 -5
- package/dist/approval-api/actor-context.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +6 -3
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/principal-identity.d.ts +32 -0
- package/dist/approval-api/principal-identity.d.ts.map +1 -0
- package/dist/approval-api/principal-identity.js +69 -0
- package/dist/approval-api/principal-identity.js.map +1 -0
- package/dist/approval-api/principal.d.ts +10 -13
- package/dist/approval-api/principal.d.ts.map +1 -1
- package/dist/approval-api/principal.js +10 -46
- package/dist/approval-api/principal.js.map +1 -1
- package/dist/approval-api/retention.d.ts +1 -2
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +9 -1
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +29 -14
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +83 -25
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/types.d.ts +12 -0
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +12 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/audit-export/index.d.ts +2 -2
- package/dist/audit-export/index.js +2 -2
- package/dist/background-tasks/d1-storage.d.ts +4 -3
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +7 -13
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/background-tasks/host.d.ts +127 -14
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +579 -50
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/background-tasks/index.d.ts +2 -2
- package/dist/background-tasks/index.d.ts.map +1 -1
- package/dist/background-tasks/index.js +11 -6
- package/dist/background-tasks/index.js.map +1 -1
- package/dist/background-tasks/routes.d.ts +19 -2
- package/dist/background-tasks/routes.d.ts.map +1 -1
- package/dist/background-tasks/routes.js +4 -4
- package/dist/background-tasks/routes.js.map +1 -1
- package/dist/deployment-identity-protocol.d.ts +2 -2
- package/dist/deployment-identity-protocol.d.ts.map +1 -1
- package/dist/deployment-identity-protocol.js +1 -1
- package/dist/deployment-identity-protocol.js.map +1 -1
- package/dist/do-runner/cause-chain.d.ts +53 -0
- package/dist/do-runner/cause-chain.d.ts.map +1 -0
- package/dist/do-runner/cause-chain.js +96 -0
- package/dist/do-runner/cause-chain.js.map +1 -0
- package/dist/do-runner/constants.d.ts +3 -0
- package/dist/do-runner/constants.d.ts.map +1 -0
- package/dist/do-runner/constants.js +3 -0
- package/dist/do-runner/constants.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +47 -69
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +972 -196
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/deployment-identity.d.ts +29 -5
- package/dist/do-runner/deployment-identity.d.ts.map +1 -1
- package/dist/do-runner/deployment-identity.js +23 -6
- package/dist/do-runner/deployment-identity.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +4 -23
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +19 -24
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/do-status-error.d.ts +37 -0
- package/dist/do-runner/do-status-error.d.ts.map +1 -0
- package/dist/do-runner/do-status-error.js +42 -0
- package/dist/do-runner/do-status-error.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +2 -1
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +617 -144
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-admission.d.ts +114 -0
- package/dist/do-runner/execution-admission.d.ts.map +1 -0
- package/dist/do-runner/execution-admission.js +206 -0
- package/dist/do-runner/execution-admission.js.map +1 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +1 -0
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-fence.d.ts +379 -0
- package/dist/do-runner/execution-fence.d.ts.map +1 -0
- package/dist/do-runner/execution-fence.js +1098 -0
- package/dist/do-runner/execution-fence.js.map +1 -0
- package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
- package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflow-capability.js +3 -0
- package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.js +894 -0
- package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
- package/dist/do-runner/index.d.ts +20 -8
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +21 -4
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +82 -1
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +58 -3
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
- package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
- package/dist/do-runner/initial-admission-refusal.js +41 -0
- package/dist/do-runner/initial-admission-refusal.js.map +1 -0
- package/dist/do-runner/inventory.d.ts +295 -0
- package/dist/do-runner/inventory.d.ts.map +1 -0
- package/dist/do-runner/inventory.js +800 -0
- package/dist/do-runner/inventory.js.map +1 -0
- package/dist/do-runner/notification-predicate.d.ts +8 -0
- package/dist/do-runner/notification-predicate.d.ts.map +1 -0
- package/dist/do-runner/notification-predicate.js +136 -0
- package/dist/do-runner/notification-predicate.js.map +1 -0
- package/dist/do-runner/run-lifecycle.d.ts +20 -1
- package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
- package/dist/do-runner/run-lifecycle.js +67 -13
- package/dist/do-runner/run-lifecycle.js.map +1 -1
- package/dist/do-runner/run-provenance.d.ts +38 -0
- package/dist/do-runner/run-provenance.d.ts.map +1 -0
- package/dist/do-runner/run-provenance.js +152 -0
- package/dist/do-runner/run-provenance.js.map +1 -0
- package/dist/do-runner/run-storage-tables.d.ts +2 -0
- package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
- package/dist/do-runner/run-storage-tables.js +4 -0
- package/dist/do-runner/run-storage-tables.js.map +1 -0
- package/dist/do-runner/run-terminal-state.d.ts +29 -0
- package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
- package/dist/do-runner/run-terminal-state.js +105 -0
- package/dist/do-runner/run-terminal-state.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +191 -46
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +994 -378
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/start-idempotency.d.ts +285 -0
- package/dist/do-runner/start-idempotency.d.ts.map +1 -0
- package/dist/do-runner/start-idempotency.js +994 -0
- package/dist/do-runner/start-idempotency.js.map +1 -0
- package/dist/do-runner/start-reservation-contract.d.ts +103 -0
- package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
- package/dist/do-runner/start-reservation-contract.js +338 -0
- package/dist/do-runner/start-reservation-contract.js.map +1 -0
- package/dist/do-runner/suspension-deadline.d.ts +4 -11
- package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
- package/dist/do-runner/suspension-deadline.js +8 -12
- package/dist/do-runner/suspension-deadline.js.map +1 -1
- package/dist/do-runner/table-prefix.d.ts.map +1 -1
- package/dist/do-runner/table-prefix.js +2 -1
- package/dist/do-runner/table-prefix.js.map +1 -1
- package/dist/do-runner/testing.d.ts +3 -0
- package/dist/do-runner/testing.d.ts.map +1 -0
- package/dist/do-runner/testing.js +3 -0
- package/dist/do-runner/testing.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +2 -1
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +14 -10
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
- package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
- package/dist/do-runner/workflow-snapshot-row.js +97 -0
- package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +15 -5
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +64 -64
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +10 -7
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/do-response.d.ts +16 -0
- package/dist/host-kit/do-response.d.ts.map +1 -1
- package/dist/host-kit/do-response.js +181 -0
- package/dist/host-kit/do-response.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +3 -0
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +36 -8
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +5 -6
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +49 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +409 -111
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +24 -14
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +29 -40
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +9 -3
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +5 -1
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-route-error.d.ts +8 -4
- package/dist/host-kit/run-route-error.d.ts.map +1 -1
- package/dist/host-kit/run-route-error.js +14 -11
- package/dist/host-kit/run-route-error.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +63 -2
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +167 -45
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-router.js +18 -9
- package/dist/host-kit/stream-router.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +7 -3
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/internal-error-response.d.ts.map +1 -1
- package/dist/internal-error-response.js +16 -6
- package/dist/internal-error-response.js.map +1 -1
- package/dist/schedules/index.d.ts +1 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +1 -7
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/mutation-contract.d.ts +38 -0
- package/dist/schedules/mutation-contract.d.ts.map +1 -0
- package/dist/schedules/mutation-contract.js +21 -0
- package/dist/schedules/mutation-contract.js.map +1 -0
- package/dist/schedules/router.d.ts +15 -8
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +170 -59
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +11 -5
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +570 -143
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/storage.d.ts +0 -7
- package/dist/schedules/storage.d.ts.map +1 -1
- package/dist/schedules/storage.js +0 -27
- package/dist/schedules/storage.js.map +1 -1
- package/dist/schedules/tick.d.ts +13 -0
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +66 -40
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/host-do.d.ts +12 -1
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +28 -3
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +15 -1
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +126 -113
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/d1-shared.d.ts +11 -8
- package/dist/signals/d1-shared.d.ts.map +1 -1
- package/dist/signals/d1-shared.js +1 -6
- 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 +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +109 -5
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +430 -46
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +14 -1
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +229 -18
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +6 -4
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -84
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +2 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +330 -83
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +6 -3
- package/patches/@mastra__core@1.53.0.patch +54 -0
- package/scripts/seed-deployment-identity.mjs +34 -9
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
function errorText(error) {
|
|
3
|
-
|
|
3
|
+
try {
|
|
4
|
+
return String(error instanceof Error ? error.message : error);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return 'unreadable error';
|
|
8
|
+
}
|
|
4
9
|
}
|
|
5
10
|
/** Package-internal catch-all for public HTTP routes. */
|
|
6
11
|
export function internalErrorResponse(route, error, status = 500) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
try {
|
|
13
|
+
console.error(JSON.stringify({
|
|
14
|
+
type: 'route-internal-error',
|
|
15
|
+
route,
|
|
16
|
+
error: errorText(error),
|
|
17
|
+
}), error);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Diagnostic failure cannot prevent the HTTP response.
|
|
21
|
+
}
|
|
12
22
|
return new Response(JSON.stringify({ error: 'internal error' }), {
|
|
13
23
|
status,
|
|
14
24
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-error-response.js","sourceRoot":"","sources":["../src/internal-error-response.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"internal-error-response.js","sourceRoot":"","sources":["../src/internal-error-response.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,kBAAkB,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,KAAc,EACd,SAAoB,GAAG;IAEvB,IAAI,CAAC;QACH,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,sBAAsB;YAC5B,KAAK;YACL,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC;SACxB,CAAC,EACF,KAAK,CACN,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,uDAAuD;IACzD,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,EAAE;QAC/D,MAAM;QACN,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,UAAU;SAC5B;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { FENCED_SCHEDULE_STORAGE, type FencedScheduleMutationCapability, ScheduleMutationConflictError, ScheduleMutationOutcomeUnknownError, type ScheduleResumeMutation, } from './mutation-contract.js';
|
|
1
2
|
export { createScheduleRouter, type ScheduleFacadeStore, type ScheduleOperation, type ScheduleRouteAuditEvent, type ScheduleRouteAuditSink, type ScheduleRouter, type ScheduleRouterOptions, } from './router.js';
|
|
2
3
|
export { D1SchedulesStorage, parseScheduleAgentDispatchReceipt, type Schedule, type ScheduleAgentDispatchAction, type ScheduleAgentDispatchReceipt, type ScheduleAgentDispatchState, type ScheduleDatabase, type ScheduleFireClaim, type ScheduleStatement, type ScheduleTrigger, } from './schedules-d1.js';
|
|
3
4
|
export { createScheduleStorageDomains } from './storage.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,KAAK,gCAAgC,EACrC,6BAA6B,EAC7B,mCAAmC,EACnC,KAAK,sBAAsB,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,iCAAiC,EACjC,KAAK,QAAQ,EACb,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,KAAK,kBAAkB,EACvB,0BAA0B,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,wBAAwB,EACxB,8BAA8B,EAC9B,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,EAC9B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,4BAA4B,EAC5B,KAAK,sBAAsB,GAC5B,MAAM,WAAW,CAAC"}
|
package/dist/schedules/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
// facade. Subpath-only (`@proofoftech/flowsafe/schedules`), like agent-runner /
|
|
4
|
-
// background-tasks / signals / goals: host-side wiring a consumer opts into, not
|
|
5
|
-
// in the root barrel.
|
|
6
|
-
// The facade router (CI-M-006-003).
|
|
2
|
+
export { FENCED_SCHEDULE_STORAGE, ScheduleMutationConflictError, ScheduleMutationOutcomeUnknownError, } from './mutation-contract.js';
|
|
7
3
|
export { createScheduleRouter, } from './router.js';
|
|
8
|
-
// The D1 schedules storage domain (CI-M-006-001).
|
|
9
4
|
export { D1SchedulesStorage, parseScheduleAgentDispatchReceipt, } from './schedules-d1.js';
|
|
10
5
|
export { createScheduleStorageDomains } from './storage.js';
|
|
11
6
|
export { createScheduleTargetPolicy, scheduleCreatorRole, scheduleWithCreatorRole, } from './target-policy.js';
|
|
12
|
-
// The CAS tick (CI-M-006-002).
|
|
13
7
|
export { buildScheduledLegContext, canPersistScheduledAgentSignal, createScheduleStartSource, createScheduleTick, isReservedScheduleContextKey, RESERVED_SCHEDULE_CONTEXT_KEYS, stripReservedScheduleContext, } from './tick.js';
|
|
14
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EACL,uBAAuB,EAEvB,6BAA6B,EAC7B,mCAAmC,GAEpC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,oBAAoB,GAOrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,iCAAiC,GASlC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAEL,0BAA0B,EAK1B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,wBAAwB,EACxB,8BAA8B,EAC9B,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,EAoB9B,4BAA4B,GAE7B,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Schedule, ScheduleUpdate } from '@mastra/core/storage';
|
|
2
|
+
import type { ResourceOwner } from '../approval-api/resource-ownership.js';
|
|
3
|
+
import { DoStatusError } from '../do-runner/do-status-error.js';
|
|
4
|
+
import type { MutationEpochContext } from '../do-runner/execution-admission.js';
|
|
5
|
+
import type { SignalDatabase } from '../signals/d1-shared.js';
|
|
6
|
+
import type { AuthorizedSchedule } from './target-policy.js';
|
|
7
|
+
export declare const FENCED_SCHEDULE_STORAGE: unique symbol;
|
|
8
|
+
export interface ScheduleResumeMutation {
|
|
9
|
+
readonly expectedCron: Schedule['cron'];
|
|
10
|
+
readonly expectedTimezone: Schedule['timezone'];
|
|
11
|
+
readonly nextFireAt: Schedule['nextFireAt'];
|
|
12
|
+
}
|
|
13
|
+
/** Epoch activation can race a waiting request, so this contract applies before activation. */
|
|
14
|
+
export interface FencedScheduleMutationCapability {
|
|
15
|
+
readonly database: SignalDatabase & Required<Pick<SignalDatabase, 'batch'>>;
|
|
16
|
+
createOwnedSchedule(schedule: AuthorizedSchedule, owner: ResourceOwner, maxSchedules: number, context: MutationEpochContext): Promise<Schedule | null>;
|
|
17
|
+
updateSchedule(id: string, patch: ScheduleUpdate, context: MutationEpochContext): Promise<Schedule>;
|
|
18
|
+
pauseSchedule(id: string, context: MutationEpochContext): Promise<Schedule>;
|
|
19
|
+
resumeSchedule(id: string, mutation: ScheduleResumeMutation, context: MutationEpochContext): Promise<Schedule>;
|
|
20
|
+
deleteOwnedSchedule(id: string, context: MutationEpochContext): Promise<'deleted' | 'pending'>;
|
|
21
|
+
observeScheduleMutation(id: string, operation: 'pause' | 'resume', context: MutationEpochContext): Promise<Schedule | null>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ScheduleMutationConflictError extends DoStatusError {
|
|
24
|
+
readonly status = 409;
|
|
25
|
+
readonly reason: {
|
|
26
|
+
readonly code: 'SCHEDULE_MUTATION_CONFLICT';
|
|
27
|
+
readonly classification: 'fence-changed' | 'schedule-changed';
|
|
28
|
+
};
|
|
29
|
+
constructor(classification: 'fence-changed' | 'schedule-changed');
|
|
30
|
+
}
|
|
31
|
+
export declare class ScheduleMutationOutcomeUnknownError extends DoStatusError {
|
|
32
|
+
readonly status = 503;
|
|
33
|
+
readonly reason: {
|
|
34
|
+
readonly code: "SCHEDULE_MUTATION_OUTCOME_UNKNOWN";
|
|
35
|
+
};
|
|
36
|
+
constructor(options?: ErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=mutation-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-contract.d.ts","sourceRoot":"","sources":["../../src/schedules/mutation-contract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,uBAAuB,EAAE,OAAO,MAE5C,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CAC7C;AAED,+FAA+F;AAC/F,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5E,mBAAmB,CACjB,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,cAAc,CACZ,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5E,cAAc,CACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB,mBAAmB,CACjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClC,uBAAuB,CACrB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,OAAO,GAAG,QAAQ,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CAC7B;AAED,qBAAa,6BAA8B,SAAQ,aAAa;IAC9D,QAAQ,CAAC,MAAM,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,IAAI,EAAE,4BAA4B,CAAC;QAC5C,QAAQ,CAAC,cAAc,EAAE,eAAe,GAAG,kBAAkB,CAAC;KAC/D,CAAC;gBAEU,cAAc,EAAE,eAAe,GAAG,kBAAkB;CAKjE;AAED,qBAAa,mCAAoC,SAAQ,aAAa;IACpE,QAAQ,CAAC,MAAM,OAAO;IACtB,QAAQ,CAAC,MAAM;;MAA0D;gBAE7D,OAAO,CAAC,EAAE,YAAY;CAInC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { DoStatusError } from '../do-runner/do-status-error.js';
|
|
3
|
+
export const FENCED_SCHEDULE_STORAGE = Symbol('flowsafe.fencedScheduleStorage');
|
|
4
|
+
export class ScheduleMutationConflictError extends DoStatusError {
|
|
5
|
+
status = 409;
|
|
6
|
+
reason;
|
|
7
|
+
constructor(classification) {
|
|
8
|
+
super('schedule mutation conflicted with a concurrent change');
|
|
9
|
+
this.name = 'ScheduleMutationConflictError';
|
|
10
|
+
this.reason = { code: 'SCHEDULE_MUTATION_CONFLICT', classification };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ScheduleMutationOutcomeUnknownError extends DoStatusError {
|
|
14
|
+
status = 503;
|
|
15
|
+
reason = { code: 'SCHEDULE_MUTATION_OUTCOME_UNKNOWN' };
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super('schedule mutation outcome is unknown', options);
|
|
18
|
+
this.name = 'ScheduleMutationOutcomeUnknownError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mutation-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-contract.js","sourceRoot":"","sources":["../../src/schedules/mutation-contract.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAItC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAKhE,MAAM,CAAC,MAAM,uBAAuB,GAAkB,MAAM,CAC1D,gCAAgC,CACjC,CAAC;AAuCF,MAAM,OAAO,6BAA8B,SAAQ,aAAa;IACrD,MAAM,GAAG,GAAG,CAAC;IACb,MAAM,CAGb;IAEF,YAAY,cAAoD;QAC9D,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,4BAA4B,EAAE,cAAc,EAAE,CAAC;IACvE,CAAC;CACF;AAED,MAAM,OAAO,mCAAoC,SAAQ,aAAa;IAC3D,MAAM,GAAG,GAAG,CAAC;IACb,MAAM,GAAG,EAAE,IAAI,EAAE,mCAAmC,EAAW,CAAC;IAEzE,YAAY,OAAsB;QAChC,KAAK,CAAC,sCAAsC,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,qCAAqC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { Schedule, ScheduleFilter, ScheduleTrigger, ScheduleTriggerListOptions, ScheduleUpdate } from '@mastra/core/storage';
|
|
2
2
|
import { type ActorResolver, type ApprovalRole, type ResourceOwner } from '../approval-api/index.js';
|
|
3
|
+
import { type MutationEpochContext } from '../do-runner/execution-admission.js';
|
|
4
|
+
import { type ExecutionFenceWiring } from '../do-runner/index.js';
|
|
3
5
|
import { type BoundThreadTargetValidator } from '../host-kit/index.js';
|
|
6
|
+
import { FENCED_SCHEDULE_STORAGE, type FencedScheduleMutationCapability } from './mutation-contract.js';
|
|
4
7
|
import { type AuthorizedSchedule, type ScheduleTargetPolicy } from './target-policy.js';
|
|
5
8
|
/** The storage subset the facade reads/writes (a subset of D1SchedulesStorage). */
|
|
6
9
|
export interface ScheduleFacadeStore {
|
|
7
|
-
|
|
10
|
+
readonly [FENCED_SCHEDULE_STORAGE]?: FencedScheduleMutationCapability;
|
|
11
|
+
createOwnedSchedule(schedule: AuthorizedSchedule, owner: ResourceOwner, maxSchedules: number, context?: MutationEpochContext): Promise<Schedule | null>;
|
|
8
12
|
getSchedule(id: string): Promise<Schedule | null>;
|
|
9
13
|
listSchedules(filter?: ScheduleFilter): Promise<Schedule[]>;
|
|
10
|
-
updateSchedule(id: string, patch: ScheduleUpdate): Promise<Schedule>;
|
|
11
|
-
deleteOwnedSchedule(id: string): Promise<'deleted' | 'pending'>;
|
|
14
|
+
updateSchedule(id: string, patch: ScheduleUpdate, context?: MutationEpochContext): Promise<Schedule>;
|
|
15
|
+
deleteOwnedSchedule(id: string, context?: MutationEpochContext): Promise<'deleted' | 'pending'>;
|
|
12
16
|
listTriggers(scheduleId: string, opts?: ScheduleTriggerListOptions): Promise<ScheduleTrigger[]>;
|
|
13
17
|
}
|
|
14
18
|
/** The operations, one per route. */
|
|
@@ -37,11 +41,7 @@ export interface ScheduleRouterOptions {
|
|
|
37
41
|
targetPolicy: ScheduleTargetPolicy;
|
|
38
42
|
/** Prove fixed-thread agent targets are durable bound memory. */
|
|
39
43
|
validateThreadTarget: BoundThreadTargetValidator;
|
|
40
|
-
/**
|
|
41
|
-
* Who may create/update/delete/pause/resume. Default RUN_START_ROLES
|
|
42
|
-
* (operator/admin) — reviewers/viewers cannot author schedules. Reads (get/
|
|
43
|
-
* list/triggers) are not role-gated beyond ownership.
|
|
44
|
-
*/
|
|
44
|
+
/** Roles allowed to mutate schedules. Defaults to RUN_START_ROLES. */
|
|
45
45
|
roles?: readonly ApprovalRole[];
|
|
46
46
|
/** Every mutation (and denied read) is audited through this. Absent ⇒ no audit. */
|
|
47
47
|
audit?: ScheduleRouteAuditSink;
|
|
@@ -64,6 +64,13 @@ export interface ScheduleRouterOptions {
|
|
|
64
64
|
* zero denies every non-empty body. Default 16384 (16 KiB).
|
|
65
65
|
*/
|
|
66
66
|
maxContentBytes?: number;
|
|
67
|
+
/**
|
|
68
|
+
* The early state gate. A configured fence requires the store's same-binding
|
|
69
|
+
* mutation capability before epoch activation can race a waiting request.
|
|
70
|
+
* `'none'` supports method-only custom facades; an advertised capability still
|
|
71
|
+
* applies its storage-level mutation guards.
|
|
72
|
+
*/
|
|
73
|
+
executionFence: ExecutionFenceWiring;
|
|
67
74
|
/** Route prefix. Default '/api/schedules'. */
|
|
68
75
|
basePath?: string;
|
|
69
76
|
}
|
|
@@ -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":"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"}
|
package/dist/schedules/router.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// avoided (a slugify-drift + existence-oracle vector).
|
|
2
|
+
// createScheduleRouter, the authenticated facade over the deployment schedules
|
|
3
|
+
// domain. Ids are SERVER-MINTED `${prefix}${uuid}` (agent_/schedule_): a client
|
|
4
|
+
// cannot name the id, so it cannot collide with or probe for another schedule.
|
|
5
|
+
// The host-owned run-id posture applies to schedule ids; core's slugified
|
|
6
|
+
// client-id path is avoided because it exposes slug drift and existence probes.
|
|
8
7
|
//
|
|
9
|
-
// The write path is an ingestion trust boundary
|
|
10
|
-
//
|
|
8
|
+
// The write path is an ingestion trust boundary with the same gate order that
|
|
9
|
+
// createSignalRouter and createObjectiveRouter enforce:
|
|
11
10
|
//
|
|
12
|
-
// 1. resolve
|
|
13
|
-
// 2. existing-schedule ownership
|
|
14
|
-
// 3.
|
|
15
|
-
// 4.
|
|
16
|
-
// 5.
|
|
17
|
-
// 6.
|
|
11
|
+
// 1. resolve and validate the actor -> 401 / 403
|
|
12
|
+
// 2. verify existing-schedule ownership -> 404
|
|
13
|
+
// 3. require RUN_START_ROLES for mutations -> 403
|
|
14
|
+
// 4. cap the raw body, then parse JSON -> 413 / 400
|
|
15
|
+
// 5. validate fields, count cap, and rate cap -> 400
|
|
16
|
+
// 6. reject reserved request-context keys -> 400
|
|
18
17
|
// 7. audit (schedule.route) + persist
|
|
19
18
|
//
|
|
20
|
-
//
|
|
19
|
+
// STORED-CONTEXT BARRIER: a stored WorkflowSchedule.requestContext
|
|
21
20
|
// / agent ScheduleStreamOptions.requestContext replays into a future run, so it is
|
|
22
21
|
// a stored-capability channel — the same class as the approval create-route leak.
|
|
23
22
|
// Create/update REJECT any requestContext naming a reserved key (the whole
|
|
@@ -37,12 +36,17 @@
|
|
|
37
36
|
// starts no runs.
|
|
38
37
|
import { AGENT_SCHEDULE_PREFIX, ScheduleInputSchema, toScheduleView, WORKFLOW_SCHEDULE_PREFIX, } from '@mastra/core/schedules';
|
|
39
38
|
import { computeNextFireAt, validateCron } from '@mastra/core/workflows';
|
|
39
|
+
import { captureActorContext } from '../approval-api/actor-context.js';
|
|
40
40
|
import { ActorResolutionError, RUN_START_ROLES, } from '../approval-api/index.js';
|
|
41
|
+
import { InvalidMutationEpochError, MutationEpochMismatchError, } from '../do-runner/execution-admission.js';
|
|
42
|
+
import { admitsWorkAuthoring, executionFencedResponse, isExecutionFenceRefusal, readExecutionFence, } from '../do-runner/index.js';
|
|
43
|
+
import { hostErrorText } from '../host-kit/host-approval-service.js';
|
|
41
44
|
import { RunRouteError, requireMemoryId, requireResourceAccess, } from '../host-kit/index.js';
|
|
42
45
|
import { safeDecodeSegment } from '../host-kit/route-path.js';
|
|
43
46
|
import { readBoundedBody } from '../http-body.js';
|
|
44
47
|
import { internalErrorResponse } from '../internal-error-response.js';
|
|
45
48
|
import { nonnegativeSafeInteger, positiveSafeInteger, } from '../numeric-config.js';
|
|
49
|
+
import { FENCED_SCHEDULE_STORAGE, ScheduleMutationConflictError, ScheduleMutationOutcomeUnknownError, } from './mutation-contract.js';
|
|
46
50
|
import { scheduleCreatorRole, scheduleWithCreatorRole, } from './target-policy.js';
|
|
47
51
|
import { isReservedScheduleContextKey } from './tick.js';
|
|
48
52
|
function json(payload, status = 200) {
|
|
@@ -150,7 +154,7 @@ function checkFireRate(cron, timezone, minFireIntervalMs, now) {
|
|
|
150
154
|
const second = nextFireOrReject(cron, timezone, first.value);
|
|
151
155
|
if (!second.ok)
|
|
152
156
|
return second.error;
|
|
153
|
-
// NOTE
|
|
157
|
+
// NOTE: this samples only the NEXT two fires at request
|
|
154
158
|
// time. A non-uniform cron (e.g. a dense minute cluster + a long gap) can pass
|
|
155
159
|
// when sampled during the gap yet still fire the dense cluster later; the
|
|
156
160
|
// deployment COUNT cap and the tick's run-cap seam are the real aggregate
|
|
@@ -431,8 +435,54 @@ function buildCreateRow(body, now, minFireIntervalMs) {
|
|
|
431
435
|
},
|
|
432
436
|
};
|
|
433
437
|
}
|
|
438
|
+
const FENCE_GATED_SCHEDULE_OPERATIONS = new Set([
|
|
439
|
+
'create',
|
|
440
|
+
'update',
|
|
441
|
+
'resume',
|
|
442
|
+
]);
|
|
443
|
+
function captureScheduleMutations(store, executionFence) {
|
|
444
|
+
const capability = store[FENCED_SCHEDULE_STORAGE];
|
|
445
|
+
if (capability === undefined) {
|
|
446
|
+
if (executionFence !== 'none') {
|
|
447
|
+
throw new Error('fenced schedule storage capability is unavailable');
|
|
448
|
+
}
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
if (capability === null ||
|
|
452
|
+
typeof capability !== 'object' ||
|
|
453
|
+
Array.isArray(capability)) {
|
|
454
|
+
throw new Error('schedule mutation capability is malformed');
|
|
455
|
+
}
|
|
456
|
+
const { database, createOwnedSchedule, updateSchedule, pauseSchedule, resumeSchedule, deleteOwnedSchedule, observeScheduleMutation, } = capability;
|
|
457
|
+
if (!database ||
|
|
458
|
+
typeof database !== 'object' ||
|
|
459
|
+
Array.isArray(database) ||
|
|
460
|
+
typeof database.prepare !== 'function' ||
|
|
461
|
+
typeof database.batch !== 'function' ||
|
|
462
|
+
typeof createOwnedSchedule !== 'function' ||
|
|
463
|
+
typeof updateSchedule !== 'function' ||
|
|
464
|
+
typeof pauseSchedule !== 'function' ||
|
|
465
|
+
typeof resumeSchedule !== 'function' ||
|
|
466
|
+
typeof deleteOwnedSchedule !== 'function' ||
|
|
467
|
+
typeof observeScheduleMutation !== 'function') {
|
|
468
|
+
throw new Error('schedule mutation capability is malformed');
|
|
469
|
+
}
|
|
470
|
+
if (executionFence !== 'none' && !executionFence.usesDatabase(database)) {
|
|
471
|
+
throw new Error('schedule storage binding disagrees with execution fence');
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
database,
|
|
475
|
+
createOwnedSchedule: createOwnedSchedule.bind(capability),
|
|
476
|
+
updateSchedule: updateSchedule.bind(capability),
|
|
477
|
+
pauseSchedule: pauseSchedule.bind(capability),
|
|
478
|
+
resumeSchedule: resumeSchedule.bind(capability),
|
|
479
|
+
deleteOwnedSchedule: deleteOwnedSchedule.bind(capability),
|
|
480
|
+
observeScheduleMutation: observeScheduleMutation.bind(capability),
|
|
481
|
+
};
|
|
482
|
+
}
|
|
434
483
|
export function createScheduleRouter(options) {
|
|
435
|
-
const { resolve, store, targetPolicy } = options;
|
|
484
|
+
const { executionFence, resolve, store, targetPolicy, audit: auditSink, } = options;
|
|
485
|
+
const mutations = captureScheduleMutations(store, executionFence);
|
|
436
486
|
const roles = options.roles ?? RUN_START_ROLES;
|
|
437
487
|
const maxSchedules = nonnegativeSafeInteger(options.maxSchedules ?? 100, 'maxSchedules');
|
|
438
488
|
const minFireIntervalMs = positiveSafeInteger(options.minFireIntervalMs ?? 60_000, 'minFireIntervalMs');
|
|
@@ -471,49 +521,70 @@ export function createScheduleRouter(options) {
|
|
|
471
521
|
// no-ops while it is — so a pre-auth failure never writes the log (an
|
|
472
522
|
// unauthenticated flood cannot spam the audit sink).
|
|
473
523
|
let context;
|
|
524
|
+
const reportError = (type, error) => {
|
|
525
|
+
try {
|
|
526
|
+
console.error(JSON.stringify({
|
|
527
|
+
type,
|
|
528
|
+
operation,
|
|
529
|
+
...(id !== undefined ? { scheduleId: id } : {}),
|
|
530
|
+
reason: hostErrorText(error, true),
|
|
531
|
+
}), error);
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
// Diagnostics cannot change the request's selected outcome.
|
|
535
|
+
}
|
|
536
|
+
};
|
|
474
537
|
const audit = async (outcome, reason) => {
|
|
475
|
-
if (!
|
|
538
|
+
if (!auditSink || !context)
|
|
476
539
|
return;
|
|
477
540
|
// A benign read is not audited; only its denial is.
|
|
478
541
|
if (!isMutation && outcome === 'accepted')
|
|
479
542
|
return;
|
|
480
|
-
await options.audit({
|
|
481
|
-
type: 'schedule.route',
|
|
482
|
-
...(context.deploymentTag !== undefined
|
|
483
|
-
? { deploymentTag: context.deploymentTag }
|
|
484
|
-
: {}),
|
|
485
|
-
actorId: context.actor.id,
|
|
486
|
-
operation,
|
|
487
|
-
...(id !== undefined ? { scheduleId: id } : {}),
|
|
488
|
-
outcome,
|
|
489
|
-
...(reason !== undefined ? { reason } : {}),
|
|
490
|
-
timestamp: new Date().toISOString(),
|
|
491
|
-
});
|
|
492
|
-
};
|
|
493
|
-
const auditCommittedMutation = async () => {
|
|
494
543
|
try {
|
|
495
|
-
await
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
544
|
+
await auditSink.call(options, {
|
|
545
|
+
type: 'schedule.route',
|
|
546
|
+
...(context.deploymentTag !== undefined
|
|
547
|
+
? { deploymentTag: context.deploymentTag }
|
|
548
|
+
: {}),
|
|
549
|
+
actorId: context.actor.id,
|
|
500
550
|
operation,
|
|
501
551
|
...(id !== undefined ? { scheduleId: id } : {}),
|
|
502
|
-
|
|
503
|
-
|
|
552
|
+
outcome,
|
|
553
|
+
...(reason !== undefined ? { reason } : {}),
|
|
554
|
+
timestamp: new Date().toISOString(),
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
reportError('schedule.route-audit-error', error);
|
|
504
559
|
}
|
|
505
560
|
};
|
|
506
561
|
try {
|
|
507
562
|
// 1. Resolve.
|
|
508
|
-
|
|
509
|
-
if (!
|
|
563
|
+
const resolved = await resolve(request);
|
|
564
|
+
if (!resolved)
|
|
510
565
|
return json({ error: 'authentication required' }, 401);
|
|
566
|
+
context = captureActorContext(resolved);
|
|
567
|
+
const mutation = Object.freeze({
|
|
568
|
+
mutationEpoch: context.mutationEpoch,
|
|
569
|
+
});
|
|
511
570
|
// CREATE has no resource to resolve yet, so its coarse role gate comes
|
|
512
571
|
// immediately after authentication.
|
|
513
572
|
if (operation === 'create' && !roles.includes(context.actor.role)) {
|
|
514
573
|
await audit('rejected', 'forbidden-role');
|
|
515
574
|
return json({ error: 'forbidden' }, 403);
|
|
516
575
|
}
|
|
576
|
+
// The execution fence, after authentication so a refusal is auditable
|
|
577
|
+
// and tells an anonymous caller nothing about the deployment's state.
|
|
578
|
+
// Only the operations that ARM future fires are gated: pause and delete
|
|
579
|
+
// remove work, which is the direction a drain is going, and reads stay
|
|
580
|
+
// open in every state.
|
|
581
|
+
if (FENCE_GATED_SCHEDULE_OPERATIONS.has(operation)) {
|
|
582
|
+
const reading = await readExecutionFence(executionFence);
|
|
583
|
+
if (!admitsWorkAuthoring(reading)) {
|
|
584
|
+
await audit('rejected', 'execution-fenced');
|
|
585
|
+
return executionFencedResponse(reading.state, `schedule ${operation}`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
517
588
|
// LIST returns only schedules this principal may read. Reviewer/admin
|
|
518
589
|
// policy is applied by canAccessResource; owners always retain access.
|
|
519
590
|
if (operation === 'list') {
|
|
@@ -550,12 +621,14 @@ export function createScheduleRouter(options) {
|
|
|
550
621
|
}
|
|
551
622
|
await requireTargetOwner(context, built.value.target, context.resourceOwner, options.validateThreadTarget);
|
|
552
623
|
const row = scheduleWithCreatorRole(built.value, context.actor.role);
|
|
553
|
-
const created =
|
|
624
|
+
const created = mutations
|
|
625
|
+
? await mutations.createOwnedSchedule(row, context.resourceOwner, maxSchedules, mutation)
|
|
626
|
+
: await store.createOwnedSchedule(row, context.resourceOwner, maxSchedules);
|
|
554
627
|
if (!created) {
|
|
555
628
|
await audit('rejected', 'schedule-count-cap');
|
|
556
629
|
return json({ error: `deployment schedule cap of ${maxSchedules} reached` }, 400);
|
|
557
630
|
}
|
|
558
|
-
await
|
|
631
|
+
await audit('accepted');
|
|
559
632
|
return json({ schedule: toView(created) }, 201);
|
|
560
633
|
}
|
|
561
634
|
// Everything below addresses ONE schedule by id — 404 (no oracle) on a
|
|
@@ -578,13 +651,21 @@ export function createScheduleRouter(options) {
|
|
|
578
651
|
return json({ triggers });
|
|
579
652
|
}
|
|
580
653
|
if (operation === 'delete') {
|
|
581
|
-
const outcome =
|
|
582
|
-
|
|
654
|
+
const outcome = mutations
|
|
655
|
+
? await mutations.deleteOwnedSchedule(scheduleId, mutation)
|
|
656
|
+
: await store.deleteOwnedSchedule(scheduleId);
|
|
657
|
+
await audit('accepted');
|
|
583
658
|
return outcome === 'pending'
|
|
584
659
|
? json({ ok: true, pending: true }, 202)
|
|
585
660
|
: json({ ok: true });
|
|
586
661
|
}
|
|
587
|
-
|
|
662
|
+
let existing = await store.getSchedule(scheduleId);
|
|
663
|
+
if (existing &&
|
|
664
|
+
mutations &&
|
|
665
|
+
((operation === 'pause' && existing.status === 'paused') ||
|
|
666
|
+
(operation === 'resume' && existing.status === 'active'))) {
|
|
667
|
+
existing = await mutations.observeScheduleMutation(scheduleId, operation, mutation);
|
|
668
|
+
}
|
|
588
669
|
if (!existing) {
|
|
589
670
|
await audit('rejected', 'not-found');
|
|
590
671
|
return json({ error: 'not found' }, 404);
|
|
@@ -594,18 +675,18 @@ export function createScheduleRouter(options) {
|
|
|
594
675
|
}
|
|
595
676
|
if (operation === 'pause') {
|
|
596
677
|
if (existing.status === 'paused') {
|
|
597
|
-
await
|
|
678
|
+
await audit('accepted');
|
|
598
679
|
return json({ schedule: toView(existing) });
|
|
599
680
|
}
|
|
600
|
-
const updated =
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
await
|
|
681
|
+
const updated = mutations
|
|
682
|
+
? await mutations.pauseSchedule(scheduleId, mutation)
|
|
683
|
+
: await store.updateSchedule(scheduleId, { status: 'paused' });
|
|
684
|
+
await audit('accepted');
|
|
604
685
|
return json({ schedule: toView(updated) });
|
|
605
686
|
}
|
|
606
687
|
if (operation === 'resume') {
|
|
607
688
|
if (existing.status === 'active') {
|
|
608
|
-
await
|
|
689
|
+
await audit('accepted');
|
|
609
690
|
return json({ schedule: toView(existing) });
|
|
610
691
|
}
|
|
611
692
|
// Re-activating recomputes nextFireAt from now (core's resume semantics).
|
|
@@ -618,11 +699,17 @@ export function createScheduleRouter(options) {
|
|
|
618
699
|
return json({ error: nextFire.error.message }, nextFire.error.status);
|
|
619
700
|
}
|
|
620
701
|
const nextFireAt = nextFire.value;
|
|
621
|
-
const updated =
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
702
|
+
const updated = mutations
|
|
703
|
+
? await mutations.resumeSchedule(scheduleId, {
|
|
704
|
+
expectedCron: existing.cron,
|
|
705
|
+
expectedTimezone: existing.timezone,
|
|
706
|
+
nextFireAt,
|
|
707
|
+
}, mutation)
|
|
708
|
+
: await store.updateSchedule(scheduleId, {
|
|
709
|
+
status: 'active',
|
|
710
|
+
nextFireAt,
|
|
711
|
+
});
|
|
712
|
+
await audit('accepted');
|
|
626
713
|
return json({ schedule: toView(updated) });
|
|
627
714
|
}
|
|
628
715
|
// UPDATE (PATCH).
|
|
@@ -650,11 +737,35 @@ export function createScheduleRouter(options) {
|
|
|
650
737
|
}
|
|
651
738
|
await requireTargetOwner(context, patch.value.target, scheduleOwner, options.validateThreadTarget);
|
|
652
739
|
}
|
|
653
|
-
const updated =
|
|
654
|
-
|
|
740
|
+
const updated = mutations
|
|
741
|
+
? await mutations.updateSchedule(scheduleId, patch.value, mutation)
|
|
742
|
+
: await store.updateSchedule(scheduleId, patch.value);
|
|
743
|
+
await audit('accepted');
|
|
655
744
|
return json({ schedule: toView(updated) });
|
|
656
745
|
}
|
|
657
746
|
catch (error) {
|
|
747
|
+
// A fence that could not be READ is not evidence the deployment is open,
|
|
748
|
+
// so it degrades closed with its own retryable 503 rather than the
|
|
749
|
+
// generic 500 below — an operator must be able to tell a deployment
|
|
750
|
+
// that is being migrated from one that is broken.
|
|
751
|
+
if (isExecutionFenceRefusal(error)) {
|
|
752
|
+
await audit('rejected', error.reason.code === 'EXECUTION_FENCED'
|
|
753
|
+
? 'execution-fenced'
|
|
754
|
+
: 'execution-fence-unreadable');
|
|
755
|
+
return json({ error: error.message, reason: error.reason }, error.status);
|
|
756
|
+
}
|
|
757
|
+
if (error instanceof InvalidMutationEpochError ||
|
|
758
|
+
error instanceof MutationEpochMismatchError ||
|
|
759
|
+
error instanceof ScheduleMutationConflictError ||
|
|
760
|
+
error instanceof ScheduleMutationOutcomeUnknownError) {
|
|
761
|
+
if (error instanceof ScheduleMutationOutcomeUnknownError) {
|
|
762
|
+
reportError('schedule.route-mutation-error', error);
|
|
763
|
+
}
|
|
764
|
+
await audit('rejected', 'classification' in error.reason
|
|
765
|
+
? `${error.reason.code}:${error.reason.classification}`
|
|
766
|
+
: error.reason.code);
|
|
767
|
+
return json({ error: error.message, reason: error.reason }, error.status);
|
|
768
|
+
}
|
|
658
769
|
if (error instanceof RunRouteError) {
|
|
659
770
|
await audit('rejected', error.status === 404
|
|
660
771
|
? 'resource-not-found'
|