@proofoftech/flowsafe 0.1.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 +21 -0
- package/LICENSE +202 -0
- package/README.md +273 -0
- package/dist/approval-api/contract.d.ts +45 -0
- package/dist/approval-api/contract.d.ts.map +1 -0
- package/dist/approval-api/contract.js +37 -0
- package/dist/approval-api/contract.js.map +1 -0
- package/dist/approval-api/d1-store.d.ts +52 -0
- package/dist/approval-api/d1-store.d.ts.map +1 -0
- package/dist/approval-api/d1-store.js +468 -0
- package/dist/approval-api/d1-store.js.map +1 -0
- package/dist/approval-api/grants.d.ts +52 -0
- package/dist/approval-api/grants.d.ts.map +1 -0
- package/dist/approval-api/grants.js +200 -0
- package/dist/approval-api/grants.js.map +1 -0
- package/dist/approval-api/index.d.ts +21 -0
- package/dist/approval-api/index.d.ts.map +1 -0
- package/dist/approval-api/index.js +18 -0
- package/dist/approval-api/index.js.map +1 -0
- package/dist/approval-api/retention.d.ts +32 -0
- package/dist/approval-api/retention.d.ts.map +1 -0
- package/dist/approval-api/retention.js +81 -0
- package/dist/approval-api/retention.js.map +1 -0
- package/dist/approval-api/router.d.ts +51 -0
- package/dist/approval-api/router.d.ts.map +1 -0
- package/dist/approval-api/router.js +245 -0
- package/dist/approval-api/router.js.map +1 -0
- package/dist/approval-api/service.d.ts +134 -0
- package/dist/approval-api/service.d.ts.map +1 -0
- package/dist/approval-api/service.js +537 -0
- package/dist/approval-api/service.js.map +1 -0
- package/dist/approval-api/store.d.ts +126 -0
- package/dist/approval-api/store.d.ts.map +1 -0
- package/dist/approval-api/store.js +189 -0
- package/dist/approval-api/store.js.map +1 -0
- package/dist/approval-api/tenant-brand.d.ts +35 -0
- package/dist/approval-api/tenant-brand.d.ts.map +1 -0
- package/dist/approval-api/tenant-brand.js +18 -0
- package/dist/approval-api/tenant-brand.js.map +1 -0
- package/dist/approval-api/tenant-context.d.ts +44 -0
- package/dist/approval-api/tenant-context.d.ts.map +1 -0
- package/dist/approval-api/tenant-context.js +49 -0
- package/dist/approval-api/tenant-context.js.map +1 -0
- package/dist/approval-api/tenant-store.d.ts +36 -0
- package/dist/approval-api/tenant-store.d.ts.map +1 -0
- package/dist/approval-api/tenant-store.js +122 -0
- package/dist/approval-api/tenant-store.js.map +1 -0
- package/dist/approval-api/types.d.ts +247 -0
- package/dist/approval-api/types.d.ts.map +1 -0
- package/dist/approval-api/types.js +157 -0
- package/dist/approval-api/types.js.map +1 -0
- package/dist/approval-ui/App.d.ts +11 -0
- package/dist/approval-ui/App.d.ts.map +1 -0
- package/dist/approval-ui/App.js +15 -0
- package/dist/approval-ui/App.js.map +1 -0
- package/dist/approval-ui/DetailView.d.ts +13 -0
- package/dist/approval-ui/DetailView.d.ts.map +1 -0
- package/dist/approval-ui/DetailView.js +20 -0
- package/dist/approval-ui/DetailView.js.map +1 -0
- package/dist/approval-ui/MetricsView.d.ts +7 -0
- package/dist/approval-ui/MetricsView.d.ts.map +1 -0
- package/dist/approval-ui/MetricsView.js +22 -0
- package/dist/approval-ui/MetricsView.js.map +1 -0
- package/dist/approval-ui/QueueView.d.ts +11 -0
- package/dist/approval-ui/QueueView.d.ts.map +1 -0
- package/dist/approval-ui/QueueView.js +59 -0
- package/dist/approval-ui/QueueView.js.map +1 -0
- package/dist/approval-ui/client.d.ts +34 -0
- package/dist/approval-ui/client.d.ts.map +1 -0
- package/dist/approval-ui/client.js +103 -0
- package/dist/approval-ui/client.js.map +1 -0
- package/dist/approval-ui/components.d.ts +125 -0
- package/dist/approval-ui/components.d.ts.map +1 -0
- package/dist/approval-ui/components.js +54 -0
- package/dist/approval-ui/components.js.map +1 -0
- package/dist/approval-ui/index.d.ts +21 -0
- package/dist/approval-ui/index.d.ts.map +1 -0
- package/dist/approval-ui/index.js +21 -0
- package/dist/approval-ui/index.js.map +1 -0
- package/dist/approval-ui/mount.d.ts +23 -0
- package/dist/approval-ui/mount.d.ts.map +1 -0
- package/dist/approval-ui/mount.js +17 -0
- package/dist/approval-ui/mount.js.map +1 -0
- package/dist/approval-ui/tips.d.ts +32 -0
- package/dist/approval-ui/tips.d.ts.map +1 -0
- package/dist/approval-ui/tips.js +32 -0
- package/dist/approval-ui/tips.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +70 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.js +148 -0
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -0
- package/dist/approval-ui/view-model.d.ts +24 -0
- package/dist/approval-ui/view-model.d.ts.map +1 -0
- package/dist/approval-ui/view-model.js +62 -0
- package/dist/approval-ui/view-model.js.map +1 -0
- package/dist/artifacts/index.d.ts +123 -0
- package/dist/artifacts/index.d.ts.map +1 -0
- package/dist/artifacts/index.js +223 -0
- package/dist/artifacts/index.js.map +1 -0
- package/dist/audit-export/index.d.ts +71 -0
- package/dist/audit-export/index.d.ts.map +1 -0
- package/dist/audit-export/index.js +124 -0
- package/dist/audit-export/index.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +23 -0
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -0
- package/dist/do-runner/breakwater-keys.js +38 -0
- package/dist/do-runner/breakwater-keys.js.map +1 -0
- package/dist/do-runner/cf-types.d.ts +26 -0
- package/dist/do-runner/cf-types.d.ts.map +1 -0
- package/dist/do-runner/cf-types.js +13 -0
- package/dist/do-runner/cf-types.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +128 -0
- package/dist/do-runner/d1-storage.d.ts.map +1 -0
- package/dist/do-runner/d1-storage.js +287 -0
- package/dist/do-runner/d1-storage.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +28 -0
- package/dist/do-runner/durable-object.d.ts.map +1 -0
- package/dist/do-runner/durable-object.js +164 -0
- package/dist/do-runner/durable-object.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -0
- package/dist/do-runner/index.d.ts.map +1 -0
- package/dist/do-runner/index.js +11 -0
- package/dist/do-runner/index.js.map +1 -0
- package/dist/do-runner/init.d.ts +38 -0
- package/dist/do-runner/init.d.ts.map +1 -0
- package/dist/do-runner/init.js +45 -0
- package/dist/do-runner/init.js.map +1 -0
- package/dist/do-runner/path-safe-id.d.ts +19 -0
- package/dist/do-runner/path-safe-id.d.ts.map +1 -0
- package/dist/do-runner/path-safe-id.js +70 -0
- package/dist/do-runner/path-safe-id.js.map +1 -0
- package/dist/do-runner/resume-ledger.d.ts +48 -0
- package/dist/do-runner/resume-ledger.d.ts.map +1 -0
- package/dist/do-runner/resume-ledger.js +59 -0
- package/dist/do-runner/resume-ledger.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +161 -0
- package/dist/do-runner/runtime.d.ts.map +1 -0
- package/dist/do-runner/runtime.js +509 -0
- package/dist/do-runner/runtime.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +109 -0
- package/dist/host-kit/approval-bridge.d.ts.map +1 -0
- package/dist/host-kit/approval-bridge.js +262 -0
- package/dist/host-kit/approval-bridge.js.map +1 -0
- package/dist/host-kit/bearer-auth.d.ts +19 -0
- package/dist/host-kit/bearer-auth.d.ts.map +1 -0
- package/dist/host-kit/bearer-auth.js +67 -0
- package/dist/host-kit/bearer-auth.js.map +1 -0
- package/dist/host-kit/do-response.d.ts +13 -0
- package/dist/host-kit/do-response.d.ts.map +1 -0
- package/dist/host-kit/do-response.js +24 -0
- package/dist/host-kit/do-response.js.map +1 -0
- package/dist/host-kit/do-run-topology.d.ts +32 -0
- package/dist/host-kit/do-run-topology.d.ts.map +1 -0
- package/dist/host-kit/do-run-topology.js +39 -0
- package/dist/host-kit/do-run-topology.js.map +1 -0
- package/dist/host-kit/env-vars.d.ts +26 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -0
- package/dist/host-kit/env-vars.js +48 -0
- package/dist/host-kit/env-vars.js.map +1 -0
- package/dist/host-kit/host-approval-service.d.ts +125 -0
- package/dist/host-kit/host-approval-service.d.ts.map +1 -0
- package/dist/host-kit/host-approval-service.js +187 -0
- package/dist/host-kit/host-approval-service.js.map +1 -0
- package/dist/host-kit/index.d.ts +18 -0
- package/dist/host-kit/index.d.ts.map +1 -0
- package/dist/host-kit/index.js +34 -0
- package/dist/host-kit/index.js.map +1 -0
- package/dist/host-kit/module.d.ts +34 -0
- package/dist/host-kit/module.d.ts.map +1 -0
- package/dist/host-kit/module.js +17 -0
- package/dist/host-kit/module.js.map +1 -0
- package/dist/host-kit/registration.d.ts +11 -0
- package/dist/host-kit/registration.d.ts.map +1 -0
- package/dist/host-kit/registration.js +21 -0
- package/dist/host-kit/registration.js.map +1 -0
- package/dist/host-kit/run-route-error.d.ts +11 -0
- package/dist/host-kit/run-route-error.d.ts.map +1 -0
- package/dist/host-kit/run-route-error.js +22 -0
- package/dist/host-kit/run-route-error.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +60 -0
- package/dist/host-kit/run-router.d.ts.map +1 -0
- package/dist/host-kit/run-router.js +212 -0
- package/dist/host-kit/run-router.js.map +1 -0
- package/dist/host-kit/subdomain-check.d.ts +23 -0
- package/dist/host-kit/subdomain-check.d.ts.map +1 -0
- package/dist/host-kit/subdomain-check.js +60 -0
- package/dist/host-kit/subdomain-check.js.map +1 -0
- package/dist/host-kit/tenant-registry.d.ts +51 -0
- package/dist/host-kit/tenant-registry.d.ts.map +1 -0
- package/dist/host-kit/tenant-registry.js +87 -0
- package/dist/host-kit/tenant-registry.js.map +1 -0
- package/dist/host-kit/verifier.d.ts +63 -0
- package/dist/host-kit/verifier.d.ts.map +1 -0
- package/dist/host-kit/verifier.js +191 -0
- package/dist/host-kit/verifier.js.map +1 -0
- package/dist/host-kit/workflow-meta.d.ts +25 -0
- package/dist/host-kit/workflow-meta.d.ts.map +1 -0
- package/dist/host-kit/workflow-meta.js +12 -0
- package/dist/host-kit/workflow-meta.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { ApprovalActor, ApprovalAuditEvent, ApprovalAuditSink, ApprovalDatabase, SystemApprovalStore, TenantBoundApprovalStore } from '../approval-api/index.js';
|
|
2
|
+
import { ApprovalService, D1ApprovalStoreFactory } from '../approval-api/index.js';
|
|
3
|
+
import { type AuditQueue } from '../audit-export/index.js';
|
|
4
|
+
import { type ResumeRunFn, reconcileApprovalsOnStatus } from './approval-bridge.js';
|
|
5
|
+
/**
|
|
6
|
+
* Attribution identity for cron maintenance — audit only. The sweep is TCB
|
|
7
|
+
* code over the system store, so 'system' here is the reserved audit
|
|
8
|
+
* identity (RESERVED_TENANT_IDS), which no verifier admits and no store
|
|
9
|
+
* binds to; per-record tenants ride in the audit detail.
|
|
10
|
+
*/
|
|
11
|
+
export declare function maintenanceActor(systemActorId: string): ApprovalActor;
|
|
12
|
+
export declare function approvalStoreFactoryFor(db: ApprovalDatabase): D1ApprovalStoreFactory;
|
|
13
|
+
export interface HostAuditSinkOptions {
|
|
14
|
+
/** Optional Cloudflare queue producer for SIEM export. */
|
|
15
|
+
queue?: AuditQueue<ApprovalAuditEvent>;
|
|
16
|
+
/**
|
|
17
|
+
* Keeps each queue send alive past the handler — ctx.waitUntil in fetch
|
|
18
|
+
* scope; a cron runner collects and awaits instead (it already executes
|
|
19
|
+
* under the handler's waitUntil).
|
|
20
|
+
*/
|
|
21
|
+
keepAlive?: (send: Promise<unknown>) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The audit sink every host wires: structured Workers Logs always, plus the
|
|
25
|
+
* SIEM queue when bound. Never throws and never blocks the approval path —
|
|
26
|
+
* a failed send is logged, not propagated.
|
|
27
|
+
*/
|
|
28
|
+
export declare function hostAuditSink(options?: HostAuditSinkOptions): ApprovalAuditSink;
|
|
29
|
+
export interface HostApprovalServiceOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Id for system-created records (the bridge's record creator). Must differ
|
|
32
|
+
* from human actor ids or the separation-of-duties check can never fire.
|
|
33
|
+
*/
|
|
34
|
+
systemActorId: string;
|
|
35
|
+
/** Applied when CreateApprovalInput.slaSeconds is absent. */
|
|
36
|
+
defaultSlaSeconds?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The host's resume topology — createDoRunTopology(...).resumeRecord for a
|
|
39
|
+
* DO host, resumeViaRuntime(runtime) for an in-process one. Wrapped in
|
|
40
|
+
* resumeRunWithRequeue here, so a run that re-suspends at a later gate
|
|
41
|
+
* auto-queues its next approval(s) with SoD intact (the deciding reviewer
|
|
42
|
+
* becomes the next gate's requester).
|
|
43
|
+
*/
|
|
44
|
+
resumeRun: ResumeRunFn;
|
|
45
|
+
/** Optional audit export queue (wrangler `queues` producer binding). */
|
|
46
|
+
queue?: AuditQueue<ApprovalAuditEvent>;
|
|
47
|
+
/** ctx.waitUntil — keeps audit queue sends alive past the response. */
|
|
48
|
+
waitUntil?: (send: Promise<unknown>) => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Worker-level approval service sharing the DO's D1 database. Decisions
|
|
52
|
+
* resume the run through the injected topology (grants come from the store
|
|
53
|
+
* via the DO-side provider, never from this request); if the resumed run
|
|
54
|
+
* suspends again at a later gate, the next approval is queued right here, so
|
|
55
|
+
* multi-gate workflows keep flowing through the queue.
|
|
56
|
+
*
|
|
57
|
+
* One audit sink instance backs both the service's own trail AND the
|
|
58
|
+
* bridge's re-queue-failure signal (D4): a re-queue that fails after a
|
|
59
|
+
* durable resume is reported through it rather than silently absorbed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildHostApprovalService(store: TenantBoundApprovalStore, options: HostApprovalServiceOptions): ApprovalService;
|
|
62
|
+
export interface SlaSweepMaintenanceOptions {
|
|
63
|
+
/** factory.system() — the cron-only cross-tenant view. */
|
|
64
|
+
store: SystemApprovalStore;
|
|
65
|
+
/** maintenanceActor(systemActorId). */
|
|
66
|
+
systemActor: ApprovalActor;
|
|
67
|
+
/** Optional audit export queue. */
|
|
68
|
+
queue?: AuditQueue<ApprovalAuditEvent>;
|
|
69
|
+
/** The firing cron expression — log correlation only. */
|
|
70
|
+
cron: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The cron-owned SLA sweep, verbatim-shared by the hosts: sweepSLA over the
|
|
74
|
+
* SYSTEM store (the only legitimate cross-tenant read+write, unreachable
|
|
75
|
+
* over HTTP), audit to logs + optional queue, a structured line per
|
|
76
|
+
* escalation, and containment — a sweep failure logs a maintenance-error and
|
|
77
|
+
* resolves rather than throwing, so a caller running other duties is never
|
|
78
|
+
* starved by this one (the two-cron split covers the uncatchable CPU-limit
|
|
79
|
+
* case). Queue sends are collected and awaited HERE: the whole runner
|
|
80
|
+
* already executes under the handler's ctx.waitUntil, where a nested
|
|
81
|
+
* waitUntil is unavailable.
|
|
82
|
+
*/
|
|
83
|
+
export declare function runSlaSweepMaintenance(options: SlaSweepMaintenanceOptions): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* waitUntil-detached wrapper over reconcileApprovalsOnStatus for
|
|
86
|
+
* ExecutionContext-capable hosts (D4, 2026-07-11 audit follow-up): the heal
|
|
87
|
+
* only matters to a LATER poll, never the response being built, so its D1
|
|
88
|
+
* reads AND writes (the supersede CAS + the fresh create) leave the
|
|
89
|
+
* status-response path. A rejection is logged as `reconcile-error`, never
|
|
90
|
+
* left unhandled inside waitUntil. Hosts without an ExecutionContext keep
|
|
91
|
+
* passing reconcileApprovalsOnStatus(...) directly (awaited in-path) — the
|
|
92
|
+
* host-agnostic default createRunRouter documents.
|
|
93
|
+
*/
|
|
94
|
+
export declare function reconcileApprovalsOnStatusDetached(systemActorId: string, waitUntil: (promise: Promise<unknown>) => void): ReturnType<typeof reconcileApprovalsOnStatus>;
|
|
95
|
+
/** Options for the cron-owned approval-retention purge. */
|
|
96
|
+
export interface ApprovalRetentionPurgeOptions {
|
|
97
|
+
/** factory.system() — the cron-only cross-tenant view. */
|
|
98
|
+
store: SystemApprovalStore;
|
|
99
|
+
/**
|
|
100
|
+
* Raw APPROVAL_RETENTION_DAYS env value; parsed via numberVar(…, 30,
|
|
101
|
+
* 'APPROVAL_RETENTION_DAYS', { allowZero: true }) and converted to ms —
|
|
102
|
+
* 0 purges decided approvals immediately, the same convention
|
|
103
|
+
* RUN_RETENTION_DAYS uses.
|
|
104
|
+
*/
|
|
105
|
+
retentionDays: string | undefined;
|
|
106
|
+
/** The firing cron expression — carried into the maintenance-error log line for correlation. */
|
|
107
|
+
cron: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The cron-owned approval-retention purge, previously hand-copied verbatim
|
|
111
|
+
* by the hosts (deploy/worker.ts and the showcase worker): purgeExpiredApprovals
|
|
112
|
+
* over the SYSTEM store (cross-tenant, cron-only — never a service method or
|
|
113
|
+
* HTTP route, see retention.ts), the APPROVAL_RETENTION_DAYS var parsing
|
|
114
|
+
* (allowZero: a 0-day retention purges decided approvals immediately, the
|
|
115
|
+
* same convention RUN_RETENTION_DAYS uses), and containment — a purge
|
|
116
|
+
* failure logs a maintenance-error and resolves `undefined` instead of
|
|
117
|
+
* throwing, so it never aborts a caller's other maintenance duties. Unlike
|
|
118
|
+
* runSlaSweepMaintenance, this does NOT log its own "maintenance" summary
|
|
119
|
+
* line: both hosts fold the returned count into ONE combined purge log
|
|
120
|
+
* alongside their other maintenance duties (the snapshot purge, and — for
|
|
121
|
+
* the showcase — the demo-tenant reaper), so logging it here too would
|
|
122
|
+
* double-log.
|
|
123
|
+
*/
|
|
124
|
+
export declare function runApprovalRetentionPurge(options: ApprovalRetentionPurgeOptions): Promise<number | undefined>;
|
|
125
|
+
//# sourceMappingURL=host-approval-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-approval-service.d.ts","sourceRoot":"","sources":["../../src/host-kit/host-approval-service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB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AAmB,CAAC;IAC3B,uCAAuC;IACvC,WAAW,EAAE,aAAa,CAAC;IAC3B,mCAAmC;IACnC,KAAK,CAAC,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACvC,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED;;;;;;;;;GASG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,GAC7C,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAiB/C;AAED,2DAA2D;AAC3D,MAAM,WAAW,6BAA6B;IAC5C,0DAA0D;IAC1D,KAAK,EAAE,mBAAmB,CAAC;IAC3B;;;;;OAKG;IACH,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,gGAAgG;IAChG,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAyB7B"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// The host-side ApprovalService assembly and cron SLA sweep that the
|
|
2
|
+
// showcase Worker and the deploy template previously carried as byte-copies:
|
|
3
|
+
// the structured-log + optional-Queues audit sink, the system actor derived
|
|
4
|
+
// from the store's own tenant binding, and the SoD-guarded multi-gate
|
|
5
|
+
// re-queue over the host's injected resume topology. The only genuine host
|
|
6
|
+
// difference — HOW a run resumes — stays injected as `resumeRun`
|
|
7
|
+
// (createDoRunTopology(...).resumeRecord for DO hosts, resumeViaRuntime for
|
|
8
|
+
// in-process ones). Also home to the isolate-scoped D1ApprovalStoreFactory
|
|
9
|
+
// memo, which every host needs for the same reason (the DDL promise must
|
|
10
|
+
// span the isolate, not one request).
|
|
11
|
+
import { ApprovalService, D1ApprovalStoreFactory, purgeExpiredApprovals, sweepSLA, } from '../approval-api/index.js';
|
|
12
|
+
import { queueAuditSink } from '../audit-export/index.js';
|
|
13
|
+
import { reconcileApprovalsOnStatus, resumeRunWithRequeue, } from './approval-bridge.js';
|
|
14
|
+
import { numberVar } from './env-vars.js';
|
|
15
|
+
/**
|
|
16
|
+
* Attribution identity for cron maintenance — audit only. The sweep is TCB
|
|
17
|
+
* code over the system store, so 'system' here is the reserved audit
|
|
18
|
+
* identity (RESERVED_TENANT_IDS), which no verifier admits and no store
|
|
19
|
+
* binds to; per-record tenants ride in the audit detail.
|
|
20
|
+
*/
|
|
21
|
+
export function maintenanceActor(systemActorId) {
|
|
22
|
+
return { id: systemActorId, role: 'operator', tenantId: 'system' };
|
|
23
|
+
}
|
|
24
|
+
// One factory per isolate, not per request: it owns the memoized schema-init
|
|
25
|
+
// promise, so rebuilding it inside fetch() would re-run the whole DDL pass
|
|
26
|
+
// (CREATE TABLE + DROP/CREATE indexes + PRAGMA + ALTERs) on every request.
|
|
27
|
+
// Keyed by the D1 binding, which is stable for an isolate's lifetime.
|
|
28
|
+
const approvalFactories = new WeakMap();
|
|
29
|
+
export function approvalStoreFactoryFor(db) {
|
|
30
|
+
let factory = approvalFactories.get(db);
|
|
31
|
+
if (!factory) {
|
|
32
|
+
factory = new D1ApprovalStoreFactory(db);
|
|
33
|
+
approvalFactories.set(db, factory);
|
|
34
|
+
}
|
|
35
|
+
return factory;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The audit sink every host wires: structured Workers Logs always, plus the
|
|
39
|
+
* SIEM queue when bound. Never throws and never blocks the approval path —
|
|
40
|
+
* a failed send is logged, not propagated.
|
|
41
|
+
*/
|
|
42
|
+
export function hostAuditSink(options = {}) {
|
|
43
|
+
const queueSink = options.queue ? queueAuditSink(options.queue) : undefined;
|
|
44
|
+
return (event) => {
|
|
45
|
+
console.log(JSON.stringify({ type: 'audit', ...event }));
|
|
46
|
+
if (queueSink) {
|
|
47
|
+
const send = queueSink(event).catch((error) => console.error(JSON.stringify({
|
|
48
|
+
type: 'audit-queue-error',
|
|
49
|
+
reason: String(error),
|
|
50
|
+
})));
|
|
51
|
+
options.keepAlive?.(send);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Worker-level approval service sharing the DO's D1 database. Decisions
|
|
57
|
+
* resume the run through the injected topology (grants come from the store
|
|
58
|
+
* via the DO-side provider, never from this request); if the resumed run
|
|
59
|
+
* suspends again at a later gate, the next approval is queued right here, so
|
|
60
|
+
* multi-gate workflows keep flowing through the queue.
|
|
61
|
+
*
|
|
62
|
+
* One audit sink instance backs both the service's own trail AND the
|
|
63
|
+
* bridge's re-queue-failure signal (D4): a re-queue that fails after a
|
|
64
|
+
* durable resume is reported through it rather than silently absorbed.
|
|
65
|
+
*/
|
|
66
|
+
export function buildHostApprovalService(store, options) {
|
|
67
|
+
const systemActor = {
|
|
68
|
+
id: options.systemActorId,
|
|
69
|
+
role: 'operator',
|
|
70
|
+
tenantId: store.tenantId,
|
|
71
|
+
};
|
|
72
|
+
const audit = hostAuditSink({
|
|
73
|
+
queue: options.queue,
|
|
74
|
+
keepAlive: options.waitUntil,
|
|
75
|
+
});
|
|
76
|
+
const service = new ApprovalService({
|
|
77
|
+
store,
|
|
78
|
+
defaultSlaSeconds: options.defaultSlaSeconds,
|
|
79
|
+
audit,
|
|
80
|
+
resumeRun: resumeRunWithRequeue(options.resumeRun, () => service, systemActor, audit),
|
|
81
|
+
});
|
|
82
|
+
return service;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The cron-owned SLA sweep, verbatim-shared by the hosts: sweepSLA over the
|
|
86
|
+
* SYSTEM store (the only legitimate cross-tenant read+write, unreachable
|
|
87
|
+
* over HTTP), audit to logs + optional queue, a structured line per
|
|
88
|
+
* escalation, and containment — a sweep failure logs a maintenance-error and
|
|
89
|
+
* resolves rather than throwing, so a caller running other duties is never
|
|
90
|
+
* starved by this one (the two-cron split covers the uncatchable CPU-limit
|
|
91
|
+
* case). Queue sends are collected and awaited HERE: the whole runner
|
|
92
|
+
* already executes under the handler's ctx.waitUntil, where a nested
|
|
93
|
+
* waitUntil is unavailable.
|
|
94
|
+
*/
|
|
95
|
+
export async function runSlaSweepMaintenance(options) {
|
|
96
|
+
let escalated;
|
|
97
|
+
const pendingSends = [];
|
|
98
|
+
try {
|
|
99
|
+
escalated = (await sweepSLA(options.store, {
|
|
100
|
+
systemActor: options.systemActor,
|
|
101
|
+
audit: hostAuditSink({
|
|
102
|
+
queue: options.queue,
|
|
103
|
+
keepAlive: (send) => pendingSends.push(send),
|
|
104
|
+
}),
|
|
105
|
+
onEscalation: (record) => console.log(JSON.stringify({
|
|
106
|
+
type: 'sla-escalation',
|
|
107
|
+
id: record.id,
|
|
108
|
+
tenantId: record.tenantId,
|
|
109
|
+
workflowId: record.workflowId,
|
|
110
|
+
runId: record.runId,
|
|
111
|
+
slaDeadlineAt: record.slaDeadlineAt,
|
|
112
|
+
})),
|
|
113
|
+
})).length;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(JSON.stringify({
|
|
117
|
+
type: 'maintenance-error',
|
|
118
|
+
surface: 'sla-sweep',
|
|
119
|
+
cron: options.cron,
|
|
120
|
+
error: String(error),
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
await Promise.all(pendingSends);
|
|
124
|
+
console.log(JSON.stringify({ type: 'maintenance', cron: options.cron, escalated }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* waitUntil-detached wrapper over reconcileApprovalsOnStatus for
|
|
128
|
+
* ExecutionContext-capable hosts (D4, 2026-07-11 audit follow-up): the heal
|
|
129
|
+
* only matters to a LATER poll, never the response being built, so its D1
|
|
130
|
+
* reads AND writes (the supersede CAS + the fresh create) leave the
|
|
131
|
+
* status-response path. A rejection is logged as `reconcile-error`, never
|
|
132
|
+
* left unhandled inside waitUntil. Hosts without an ExecutionContext keep
|
|
133
|
+
* passing reconcileApprovalsOnStatus(...) directly (awaited in-path) — the
|
|
134
|
+
* host-agnostic default createRunRouter documents.
|
|
135
|
+
*/
|
|
136
|
+
export function reconcileApprovalsOnStatusDetached(systemActorId, waitUntil) {
|
|
137
|
+
const reconcile = reconcileApprovalsOnStatus(systemActorId);
|
|
138
|
+
return (tenant, workflowId, summary) => {
|
|
139
|
+
waitUntil(reconcile(tenant, workflowId, summary).catch((error) => console.error(JSON.stringify({
|
|
140
|
+
type: 'reconcile-error',
|
|
141
|
+
workflowId,
|
|
142
|
+
runId: summary.runId,
|
|
143
|
+
error: error instanceof Error ? error.message : String(error),
|
|
144
|
+
}))));
|
|
145
|
+
return Promise.resolve();
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The cron-owned approval-retention purge, previously hand-copied verbatim
|
|
150
|
+
* by the hosts (deploy/worker.ts and the showcase worker): purgeExpiredApprovals
|
|
151
|
+
* over the SYSTEM store (cross-tenant, cron-only — never a service method or
|
|
152
|
+
* HTTP route, see retention.ts), the APPROVAL_RETENTION_DAYS var parsing
|
|
153
|
+
* (allowZero: a 0-day retention purges decided approvals immediately, the
|
|
154
|
+
* same convention RUN_RETENTION_DAYS uses), and containment — a purge
|
|
155
|
+
* failure logs a maintenance-error and resolves `undefined` instead of
|
|
156
|
+
* throwing, so it never aborts a caller's other maintenance duties. Unlike
|
|
157
|
+
* runSlaSweepMaintenance, this does NOT log its own "maintenance" summary
|
|
158
|
+
* line: both hosts fold the returned count into ONE combined purge log
|
|
159
|
+
* alongside their other maintenance duties (the snapshot purge, and — for
|
|
160
|
+
* the showcase — the demo-tenant reaper), so logging it here too would
|
|
161
|
+
* double-log.
|
|
162
|
+
*/
|
|
163
|
+
export async function runApprovalRetentionPurge(options) {
|
|
164
|
+
try {
|
|
165
|
+
return await purgeExpiredApprovals(options.store, {
|
|
166
|
+
// allowZero: APPROVAL_RETENTION_DAYS=0 means "purge decided approvals
|
|
167
|
+
// now" — same convention as RUN_RETENTION_DAYS.
|
|
168
|
+
ttlMs: numberVar(options.retentionDays, 30, 'APPROVAL_RETENTION_DAYS', {
|
|
169
|
+
allowZero: true,
|
|
170
|
+
}) *
|
|
171
|
+
24 *
|
|
172
|
+
60 *
|
|
173
|
+
60 *
|
|
174
|
+
1000,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error(JSON.stringify({
|
|
179
|
+
type: 'maintenance-error',
|
|
180
|
+
surface: 'approval-retention-purge',
|
|
181
|
+
cron: options.cron,
|
|
182
|
+
error: String(error),
|
|
183
|
+
}));
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=host-approval-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-approval-service.js","sourceRoot":"","sources":["../../src/host-kit/host-approval-service.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,2EAA2E;AAC3E,iEAAiE;AACjE,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,sCAAsC;AAUtC,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAmB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAEL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,aAAqB;IACpD,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AACrE,CAA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,yBAAyB,CAC7C,OAAsC;IAEtC,IAAI,CAAC;QACH,OAAO,MAAM,qBAAqB,CAAC,OAAO,CAAC,KAAK,EAAE;YAChD,sEAAsE;YACtE,gDAAgD;YAChD,KAAK,EACH,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,EAAE,yBAAyB,EAAE;gBAC9D,SAAS,EAAE,IAAI;aAChB,CAAC;gBACF,EAAE;gBACF,EAAE;gBACF,EAAE;gBACF,IAAI;SACP,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,0BAA0B;YACnC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;SACrB,CAAC,CACH,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { queueApprovalForSuspension, type ResumeRunFn, reconcileApprovalsForSummary, reconcileApprovalsOnStatus, resumeRunWithRequeue, } from './approval-bridge.js';
|
|
2
|
+
export { bearerActorAuthenticator, parseActorTokens } from './bearer-auth.js';
|
|
3
|
+
export { type DoResponseLike, doSummary } from './do-response.js';
|
|
4
|
+
export { createDoRunTopology, type DoRunTopology, type RunnerNamespaceLike, type RunnerStubLike, } from './do-run-topology.js';
|
|
5
|
+
export { boolVar, type NumberVarOptions, numberVar } from './env-vars.js';
|
|
6
|
+
export { type ApprovalRetentionPurgeOptions, approvalStoreFactoryFor, buildHostApprovalService, type HostApprovalServiceOptions, maintenanceActor, reconcileApprovalsOnStatusDetached, runApprovalRetentionPurge, runSlaSweepMaintenance, type SlaSweepMaintenanceOptions, } from './host-approval-service.js';
|
|
7
|
+
export { assertWorkflowsRegistered } from './registration.js';
|
|
8
|
+
export { RunRouteError } from './run-route-error.js';
|
|
9
|
+
export type { RunRouter, RunRouterOptions } from './run-router.js';
|
|
10
|
+
export { createRunRouter } from './run-router.js';
|
|
11
|
+
export type { SubdomainCrossCheckOptions } from './subdomain-check.js';
|
|
12
|
+
export { withSubdomainCrossCheck } from './subdomain-check.js';
|
|
13
|
+
export type { ProvisionTenantOptions, TenantRegistryDatabase, TenantRegistryStatement, } from './tenant-registry.js';
|
|
14
|
+
export { provisionTenant, RESERVED_FOR_ALLOCATION, RESERVED_TENANT_IDS, TenantCollisionError, } from './tenant-registry.js';
|
|
15
|
+
export type { HmacVerifierOptions, MintHmacTokenOptions, TokenVerifier, } from './verifier.js';
|
|
16
|
+
export { base64UrlEncode, hmacSign, hmacVerifier, mintHmacToken, staticTokenVerifier, toApprovalActor, } from './verifier.js';
|
|
17
|
+
export type { WorkflowMeta } from './workflow-meta.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host-kit/index.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,0BAA0B,EAC1B,KAAK,WAAW,EAChB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,KAAK,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK1E,OAAO,EACL,KAAK,6BAA6B,EAClC,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,gBAAgB,EAChB,kCAAkC,EAClC,yBAAyB,EACzB,sBAAsB,EACtB,KAAK,0BAA0B,GAChC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAIvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// host-kit — workflow-agnostic host glue shared by the showcase Worker, the
|
|
2
|
+
// reference deploy template, and the dev backend. It is intentionally NOT a
|
|
3
|
+
// generic host: the two resume topologies (DO-stub fetch vs in-process) stay in
|
|
4
|
+
// their hosts, injected as thunks. What lives here is everything a host must
|
|
5
|
+
// not re-derive — the auth seam, the run routes and their RBAC gate order, and
|
|
6
|
+
// the security-critical approval bridge (the (suspendedAt, resumeCount) capture
|
|
7
|
+
// and the separation-of-duties re-queue).
|
|
8
|
+
//
|
|
9
|
+
// This barrel is deliberately breakwater-free, so `@proofoftech/flowsafe/host-kit`
|
|
10
|
+
// typechecks for a consumer that mounts routes without authoring workflow
|
|
11
|
+
// modules. The module-authoring contract (WorkflowModule, WorkflowModuleContext)
|
|
12
|
+
// carries a breakwater AuditLogger, so it ships under its own subpath —
|
|
13
|
+
// `@proofoftech/flowsafe/host-kit/module` — which only authors (who already
|
|
14
|
+
// depend on breakwater for their connectors) need to reach for. See module.ts.
|
|
15
|
+
export { queueApprovalForSuspension, reconcileApprovalsForSummary, reconcileApprovalsOnStatus, resumeRunWithRequeue, } from './approval-bridge.js';
|
|
16
|
+
export { bearerActorAuthenticator, parseActorTokens } from './bearer-auth.js';
|
|
17
|
+
export { doSummary } from './do-response.js';
|
|
18
|
+
export { createDoRunTopology, } from './do-run-topology.js';
|
|
19
|
+
export { boolVar, numberVar } from './env-vars.js';
|
|
20
|
+
// hostAuditSink stays module-internal for the same reason as
|
|
21
|
+
// requestedConnectors below: it is the primitive beneath
|
|
22
|
+
// buildHostApprovalService / runSlaSweepMaintenance, and no host consumes it
|
|
23
|
+
// directly.
|
|
24
|
+
export { approvalStoreFactoryFor, buildHostApprovalService, maintenanceActor, reconcileApprovalsOnStatusDetached, runApprovalRetentionPurge, runSlaSweepMaintenance, } from './host-approval-service.js';
|
|
25
|
+
export { assertWorkflowsRegistered } from './registration.js';
|
|
26
|
+
export { RunRouteError } from './run-route-error.js';
|
|
27
|
+
export { createRunRouter } from './run-router.js';
|
|
28
|
+
// requestedConnectors and subdomainTenantOf stay module-internal on purpose:
|
|
29
|
+
// they are the primitives beneath queueApprovalForSuspension /
|
|
30
|
+
// withSubdomainCrossCheck, and no host consumes them directly.
|
|
31
|
+
export { withSubdomainCrossCheck } from './subdomain-check.js';
|
|
32
|
+
export { provisionTenant, RESERVED_FOR_ALLOCATION, RESERVED_TENANT_IDS, TenantCollisionError, } from './tenant-registry.js';
|
|
33
|
+
export { base64UrlEncode, hmacSign, hmacVerifier, mintHmacToken, staticTokenVerifier, toApprovalActor, } from './verifier.js';
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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GAChB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AuditLogger } from '@proofoftech/breakwater';
|
|
2
|
+
import type { InitResult } from '../do-runner/index.js';
|
|
3
|
+
import type { WorkflowMeta } from './workflow-meta.js';
|
|
4
|
+
export type { WorkflowMeta };
|
|
5
|
+
/**
|
|
6
|
+
* What a module's register() receives: the init()-derived builder factories
|
|
7
|
+
* (createWorkflow is the register-intercepting wrapper; createStep is raw
|
|
8
|
+
* Mastra) plus the shared, binding-gated infrastructure its connectors close
|
|
9
|
+
* over. `deps` is generic so the kit imposes no host-specific shape.
|
|
10
|
+
*/
|
|
11
|
+
export interface WorkflowModuleContext<Deps = unknown> {
|
|
12
|
+
createWorkflow: InitResult['createWorkflow'];
|
|
13
|
+
createStep: InitResult['createStep'];
|
|
14
|
+
/** Connector audit sink shared across every module on the runtime. */
|
|
15
|
+
audit: AuditLogger;
|
|
16
|
+
deps: Deps;
|
|
17
|
+
}
|
|
18
|
+
/** A workflow packaged for host-agnostic registration. */
|
|
19
|
+
export interface WorkflowModule<Deps = unknown> {
|
|
20
|
+
meta: WorkflowMeta;
|
|
21
|
+
/**
|
|
22
|
+
* Build the steps + connectors and .commit() the workflow onto the runtime.
|
|
23
|
+
*
|
|
24
|
+
* INVARIANT the type system cannot enforce: a gate step's suspend payload
|
|
25
|
+
* `connectors` MUST be a server-authored static literal (a module-level
|
|
26
|
+
* `const`, not a value derived from the run's inputData). The approval bridge
|
|
27
|
+
* copies it verbatim into the approval record, and an APPROVED record's
|
|
28
|
+
* connectors ARE the minted grant — so deriving the list from run input would
|
|
29
|
+
* let client input choose its own capability, re-opening the hole that
|
|
30
|
+
* TCB_ONLY_CREATE_FIELDS closes at the HTTP boundary.
|
|
31
|
+
*/
|
|
32
|
+
register(ctx: WorkflowModuleContext<Deps>): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/host-kit/module.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB,CAAC,IAAI,GAAG,OAAO;IACnD,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC7C,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,sEAAsE;IACtE,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,0DAA0D;AAC1D,MAAM,WAAW,cAAc,CAAC,IAAI,GAAG,OAAO;IAC5C,IAAI,EAAE,YAAY,CAAC;IACnB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAClD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The WorkflowModule contract: a self-contained workflow (its metadata + a
|
|
2
|
+
// register() that builds its steps/connectors and commits it onto a shared
|
|
3
|
+
// runtime). One RunnerRuntime hosts many modules — register-before-first-run is
|
|
4
|
+
// satisfied by a single builder that calls every module's register() before the
|
|
5
|
+
// first start. Generic over Deps so this kit stays workflow-agnostic: a host
|
|
6
|
+
// (the showcase) supplies its own shared-infrastructure bag.
|
|
7
|
+
//
|
|
8
|
+
// Ships under its OWN subpath — `@proofoftech/flowsafe/host-kit/module` — not
|
|
9
|
+
// through host-kit's barrel. `WorkflowModuleContext.audit` is breakwater's
|
|
10
|
+
// AuditLogger, a class with private fields (so it cannot be mirrored
|
|
11
|
+
// structurally), and breakwater is a devDependency of this package. Re-exporting
|
|
12
|
+
// this from `./host-kit` would force every consumer of `createRunRouter` to
|
|
13
|
+
// resolve a breakwater type they do not need. Module authors already depend on
|
|
14
|
+
// breakwater — their connectors do — so the split costs them one import and
|
|
15
|
+
// keeps the route-mounting surface dependency-free.
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/host-kit/module.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,6DAA6D;AAC7D,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,qEAAqE;AACrE,iFAAiF;AACjF,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,oDAAoD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RunnerRuntime } from '../do-runner/index.js';
|
|
2
|
+
import type { WorkflowMeta } from './workflow-meta.js';
|
|
3
|
+
/** Structural view of the runtime: only the registered-ids listing is needed. */
|
|
4
|
+
type WorkflowIdSource = Pick<RunnerRuntime, 'workflowIds'>;
|
|
5
|
+
/**
|
|
6
|
+
* Throw unless every advertised meta id was actually committed onto `runtime`.
|
|
7
|
+
* Call once, after registering all workflows and before serving traffic.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertWorkflowsRegistered(runtime: WorkflowIdSource, workflows: ReadonlyArray<WorkflowMeta>): void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/host-kit/registration.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,iFAAiF;AACjF,KAAK,gBAAgB,GAAG,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,GACrC,IAAI,CASN"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The catalog/runtime consistency check.
|
|
2
|
+
//
|
|
3
|
+
// createRunRouter looks a workflow up by WorkflowMeta.id, but start/resume route
|
|
4
|
+
// by the id the workflow was COMMITTED under (createWorkflow's id). Nothing in
|
|
5
|
+
// the type system ties the two together, so a typo in a meta surfaces as a
|
|
6
|
+
// mysterious 404 on a workflow the runtime is genuinely hosting. Every host
|
|
7
|
+
// asserts the two agree at registration time instead — a startup error, not a
|
|
8
|
+
// runtime mystery. Shared so no host can forget it or skew its wording.
|
|
9
|
+
/**
|
|
10
|
+
* Throw unless every advertised meta id was actually committed onto `runtime`.
|
|
11
|
+
* Call once, after registering all workflows and before serving traffic.
|
|
12
|
+
*/
|
|
13
|
+
export function assertWorkflowsRegistered(runtime, workflows) {
|
|
14
|
+
const registered = new Set(runtime.workflowIds());
|
|
15
|
+
for (const meta of workflows) {
|
|
16
|
+
if (!registered.has(meta.id)) {
|
|
17
|
+
throw new Error(`workflow '${meta.id}' is advertised but was never registered on the runtime`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/host-kit/registration.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,iFAAiF;AACjF,+EAA+E;AAC/E,2EAA2E;AAC3E,4EAA4E;AAC5E,8EAA8E;AAC9E,wEAAwE;AAQxE;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAyB,EACzB,SAAsC;IAEtC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,EAAE,yDAAyD,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A transport failure from a host's start/status/resume thunk, carrying the
|
|
3
|
+
* status to surface. Hosts that reach their runs through a Durable Object stub
|
|
4
|
+
* get this from `doSummary`: the DO already mapped the runtime's typed errors to
|
|
5
|
+
* 404/409/400, so that status must survive rather than collapse into a 500.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RunRouteError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
constructor(status: number, message: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=run-route-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-route-error.d.ts","sourceRoot":"","sources":["../../src/host-kit/run-route-error.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Shared vocabulary between the DO-response reader and the run router: an error
|
|
2
|
+
// that already knows the HTTP status it should surface as.
|
|
3
|
+
//
|
|
4
|
+
// Its own leaf because both sides need it and neither should depend on the
|
|
5
|
+
// other — `doSummary` (do-response.ts) throws it, `createRunRouter`
|
|
6
|
+
// (run-router.ts) catches it. Homing it in the router would make the primitive
|
|
7
|
+
// depend on the composite.
|
|
8
|
+
/**
|
|
9
|
+
* A transport failure from a host's start/status/resume thunk, carrying the
|
|
10
|
+
* status to surface. Hosts that reach their runs through a Durable Object stub
|
|
11
|
+
* get this from `doSummary`: the DO already mapped the runtime's typed errors to
|
|
12
|
+
* 404/409/400, so that status must survive rather than collapse into a 500.
|
|
13
|
+
*/
|
|
14
|
+
export class RunRouteError extends Error {
|
|
15
|
+
status;
|
|
16
|
+
constructor(status, message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'RunRouteError';
|
|
19
|
+
this.status = status;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=run-route-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-route-error.js","sourceRoot":"","sources":["../../src/host-kit/run-route-error.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,2DAA2D;AAC3D,EAAE;AACF,2EAA2E;AAC3E,oEAAoE;AACpE,+EAA+E;AAC/E,2BAA2B;AAE3B;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAS;IAExB,YAAY,MAAc,EAAE,OAAe;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type TenantContext, type TenantResolver } from '../approval-api/index.js';
|
|
2
|
+
import { type RunSummary } from '../do-runner/index.js';
|
|
3
|
+
import type { WorkflowMeta } from './workflow-meta.js';
|
|
4
|
+
export interface RunRouterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The catalog: GET /workflows lists these; POST /runs resolves against them
|
|
7
|
+
* and enforces each one's `allowedRoles`.
|
|
8
|
+
*
|
|
9
|
+
* Metadata, not WorkflowModules: the router registers nothing, so depending
|
|
10
|
+
* on the registration machinery would force every host to build a
|
|
11
|
+
* WorkflowModuleContext (and its AuditLogger) just to expose a route. Hosts
|
|
12
|
+
* pass `modules.map((m) => m.meta)`; that the ids match what was actually
|
|
13
|
+
* committed is asserted at registration (see buildShowcaseRuntime).
|
|
14
|
+
*/
|
|
15
|
+
workflows: ReadonlyArray<WorkflowMeta>;
|
|
16
|
+
/**
|
|
17
|
+
* Authenticates the request and binds the tenant scope (INV-2): the
|
|
18
|
+
* approval service, the runId mint, and the ownership predicate all come
|
|
19
|
+
* from the resolved TenantContext. undefined yields 401.
|
|
20
|
+
*/
|
|
21
|
+
resolve: TenantResolver;
|
|
22
|
+
/**
|
|
23
|
+
* Creator identity for bridge-queued approval records. Only the id is
|
|
24
|
+
* configurable — the role is 'operator' (create-capable) and the tenant is
|
|
25
|
+
* ALWAYS the request's resolved tenant, so the record lands in the same
|
|
26
|
+
* tenant as the run it gates. Must differ from human actor ids or the
|
|
27
|
+
* separation-of-duties check can never fire. Default: 'flowsafe-system'.
|
|
28
|
+
*/
|
|
29
|
+
systemActorId?: string;
|
|
30
|
+
/** Host topology: in-process runtime, or a DO stub fetch. */
|
|
31
|
+
start: (workflowId: string, runId: string, inputData: unknown) => Promise<RunSummary>;
|
|
32
|
+
status: (workflowId: string, runId: string) => Promise<RunSummary | undefined>;
|
|
33
|
+
resume: (workflowId: string, runId: string, body: unknown) => Promise<RunSummary>;
|
|
34
|
+
/**
|
|
35
|
+
* D4 self-healing hook (2026-07-11 audit): invoked after a status() read
|
|
36
|
+
* reports the run suspended, so every status poll of a stuck run doubles
|
|
37
|
+
* as a check for a gate whose approval never made it into the queue (a
|
|
38
|
+
* re-queue failure previously left it there with no recovery path — see
|
|
39
|
+
* reconcileApprovalsForSummary in approval-bridge.ts). Awaited rather than
|
|
40
|
+
* fire-and-forget by DEFAULT: this host-agnostic layer has no ctx.waitUntil
|
|
41
|
+
* of its own to keep a detached promise alive past the response, so a
|
|
42
|
+
* plain awaited call is what it can offer on its own. The work is no
|
|
43
|
+
* longer cheap (2026-07-11 audit follow-up): reconcile now pages the run's
|
|
44
|
+
* full approval history and may supersede stale open records before
|
|
45
|
+
* filing a fresh one, so the two ctx-capable hosts (deploy/worker.ts, the
|
|
46
|
+
* showcase worker) hand this hook a wrapper that detaches the real work
|
|
47
|
+
* via ctx.waitUntil and resolves immediately — this option's contract (an
|
|
48
|
+
* awaited function of this exact shape) is unchanged either way, only
|
|
49
|
+
* what a given host's function actually blocks on. A throw is caught and
|
|
50
|
+
* logged here, never surfaced to the caller: a broken reconcile must not
|
|
51
|
+
* turn a working status read into a 500; the next poll simply retries.
|
|
52
|
+
* Absent => today's behavior (no reconciliation). Hosts wire
|
|
53
|
+
* reconcileApprovalsOnStatus(systemActorId) here, optionally wrapped for
|
|
54
|
+
* waitUntil-detachment.
|
|
55
|
+
*/
|
|
56
|
+
reconcileApprovals?: (tenant: TenantContext, workflowId: string, summary: RunSummary) => Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export type RunRouter = (request: Request) => Promise<Response | null>;
|
|
59
|
+
export declare function createRunRouter(options: RunRouterOptions): RunRouter;
|
|
60
|
+
//# sourceMappingURL=run-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-router.d.ts","sourceRoot":"","sources":["../../src/host-kit/run-router.ts"],"names":[],"mappings":"AA0BA,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACvC;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,KAAK,EAAE,CACL,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACrC,MAAM,EAAE,CACN,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,KACV,OAAO,CAAC,UAAU,CAAC,CAAC;IACzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CAAC,EAAE,CACnB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,UAAU,KAChB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AA2DvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA+KpE"}
|