@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,262 @@
|
|
|
1
|
+
// Host-agnostic approval bridge: the glue that turns a workflow suspension into
|
|
2
|
+
// an approval request and re-queues the next gate on a multi-gate run. Promoted
|
|
3
|
+
// out of gtm-app/worker.ts so every host (the showcase Worker, the dev backend)
|
|
4
|
+
// shares one implementation instead of re-deriving the (suspendedAt, resumeCount)
|
|
5
|
+
// capture and the SoD-across-gates re-queue.
|
|
6
|
+
import { approvalCursor, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, stepKeyOf, } from '../approval-api/index.js';
|
|
7
|
+
/** Steps declare the grants they need in their suspend payload. */
|
|
8
|
+
export function requestedConnectors(stepPayload) {
|
|
9
|
+
if (stepPayload === null || typeof stepPayload !== 'object')
|
|
10
|
+
return [];
|
|
11
|
+
const connectors = stepPayload.connectors;
|
|
12
|
+
return Array.isArray(connectors) &&
|
|
13
|
+
connectors.every((c) => typeof c === 'string')
|
|
14
|
+
? connectors
|
|
15
|
+
: [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A suspension IS an approval request: queue one record per suspended step
|
|
19
|
+
* path (idempotently — the store's partial unique open-step index collapses
|
|
20
|
+
* duplicates, so re-queuing an already-queued gate is a no-op). EVERY path
|
|
21
|
+
* files: `.parallel()` branches can suspend together
|
|
22
|
+
* (`summary.suspended = [['a'], ['b']]`), and a gate that never reaches the
|
|
23
|
+
* queue can never be decided — its connector then denies on every resume
|
|
24
|
+
* (fail closed) with nothing telling a reviewer why the run is stuck.
|
|
25
|
+
* Capturing each step's (suspendedAt, resumeCount) pair binds its approval to
|
|
26
|
+
* THAT suspension exactly (clock-free grant minting), and each suspend
|
|
27
|
+
* payload's `connectors` declares what a decision should mint.
|
|
28
|
+
*
|
|
29
|
+
* `requestedBy` is the HUMAN who advanced the run to this suspension — the actor
|
|
30
|
+
* who started it, or the reviewer whose decision caused a re-suspension at the
|
|
31
|
+
* next gate. It must NOT be the system actor: the library's self-decision
|
|
32
|
+
* separation-of-duties check compares `requestedBy` to the deciding actor, so
|
|
33
|
+
* attributing every request to the system actor would make that check unfireable.
|
|
34
|
+
* `systemActor` is only the record's creator (needs a create-capable role).
|
|
35
|
+
*/
|
|
36
|
+
export async function queueApprovalForSuspension(service, workflowId, summary, requestedBy, systemActor) {
|
|
37
|
+
const suspended = summary.suspended ?? [];
|
|
38
|
+
const records = [];
|
|
39
|
+
const failures = [];
|
|
40
|
+
for (const stepPath of suspended) {
|
|
41
|
+
const stepKey = stepPath.join('.');
|
|
42
|
+
const stepPayload = summary.suspendPayload !== null &&
|
|
43
|
+
typeof summary.suspendPayload === 'object'
|
|
44
|
+
? summary.suspendPayload[stepKey]
|
|
45
|
+
: undefined;
|
|
46
|
+
const connectors = requestedConnectors(stepPayload);
|
|
47
|
+
try {
|
|
48
|
+
const { record } = await service.create({
|
|
49
|
+
workflowId,
|
|
50
|
+
runId: summary.runId,
|
|
51
|
+
stepPath,
|
|
52
|
+
suspendedAt: summary.suspendedAt?.[stepKey],
|
|
53
|
+
resumedAt: summary.resumedAt?.[stepKey],
|
|
54
|
+
resumeCount: summary.resumeCount?.[stepKey],
|
|
55
|
+
title: `Approve '${workflowId}' run`,
|
|
56
|
+
payload: summary.suspendPayload,
|
|
57
|
+
connectors: connectors.length > 0 ? connectors : undefined,
|
|
58
|
+
requestedBy,
|
|
59
|
+
}, systemActor);
|
|
60
|
+
records.push(record);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// Isolate per path (the purge loops' convention): the run is ALREADY
|
|
64
|
+
// suspended by the time this files, and a client retry of POST /runs
|
|
65
|
+
// mints a fresh runId rather than re-filing this one — so a transient
|
|
66
|
+
// store failure on one gate must not abandon its siblings' filings.
|
|
67
|
+
// File every path that can file, then re-throw aggregated so the
|
|
68
|
+
// caller still surfaces the failure. Filed records persist (create is
|
|
69
|
+
// idempotent under the open-step unique index), and the next
|
|
70
|
+
// decision's re-queue re-files any gate still missing.
|
|
71
|
+
failures.push({
|
|
72
|
+
stepKey,
|
|
73
|
+
message: error instanceof Error ? error.message : String(error),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (failures.length > 0) {
|
|
78
|
+
throw new Error(`queueApprovalForSuspension: ${failures.length} of ${suspended.length} gate filing(s) failed, the rest were queued (${failures
|
|
79
|
+
.map((failure) => `${failure.stepKey}: ${failure.message}`)
|
|
80
|
+
.join('; ')})`);
|
|
81
|
+
}
|
|
82
|
+
return records;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Wrap a base resume fn so a run that re-suspends at a LATER gate auto-queues
|
|
86
|
+
* its next approval(s) — the multi-gate flow (product-launch's two gates); every
|
|
87
|
+
* suspended path re-queues, not just the first. The base
|
|
88
|
+
* resume (resumeViaRuntime or a DO-stub fetch) deliberately omits re-queue; this
|
|
89
|
+
* adds it without coupling to the host's resume topology.
|
|
90
|
+
*
|
|
91
|
+
* The reviewer whose decision advanced the run becomes the next gate's
|
|
92
|
+
* `requestedBy`, so they cannot also decide it (SoD across gates). Guard
|
|
93
|
+
* fail-CLOSED: refuse to re-queue without a requester rather than fall back to
|
|
94
|
+
* the system id.
|
|
95
|
+
*
|
|
96
|
+
* `getService` is a thunk because the service references this closure at its own
|
|
97
|
+
* construction (`service = new ApprovalService({ resumeRun: resumeRunWithRequeue(base, () => service, sys) })`);
|
|
98
|
+
* the closure only runs on a later decision, so the reference is resolved by then.
|
|
99
|
+
*
|
|
100
|
+
* `audit` is optional and should be the SAME sink the service itself uses
|
|
101
|
+
* (buildHostApprovalService wires it that way): the base resume above has
|
|
102
|
+
* already durably advanced the run by the time the re-queue below can fail,
|
|
103
|
+
* so a throw here (D4, 2026-07-11 audit) leaves a gate suspended with no
|
|
104
|
+
* approval record and no other signal that happened. reconcileApprovalsForSummary
|
|
105
|
+
* is the recovery; this event is what tells an operator it was needed.
|
|
106
|
+
*/
|
|
107
|
+
export function resumeRunWithRequeue(base, getService, systemActor, audit) {
|
|
108
|
+
return async (record, decision) => {
|
|
109
|
+
const summary = await base(record, decision);
|
|
110
|
+
if (summary.status === 'suspended') {
|
|
111
|
+
if (!record.decidedBy) {
|
|
112
|
+
throw new Error('resumeRunWithRequeue: decidedBy unset — refusing to re-queue an approval without a requester');
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
await queueApprovalForSuspension(getService(), record.workflowId, summary, record.decidedBy, systemActor);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// Best-effort: a crashing sink must not mask the resume failure it is
|
|
119
|
+
// reporting (same "availability over export reliability" posture as
|
|
120
|
+
// ApprovalService's own #record).
|
|
121
|
+
try {
|
|
122
|
+
audit?.({
|
|
123
|
+
actor: systemActor,
|
|
124
|
+
action: 'approval.requeue',
|
|
125
|
+
resource: `approval:${record.id}`,
|
|
126
|
+
decision: 'error',
|
|
127
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
128
|
+
detail: {
|
|
129
|
+
tenantId: record.tenantId,
|
|
130
|
+
workflowId: record.workflowId,
|
|
131
|
+
runId: record.runId,
|
|
132
|
+
suspended: summary.suspended,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// ignore — see comment above
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return summary;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Pages service.list() to completion via the D3 cursor instead of one
|
|
147
|
+
* unbounded call (`filter.limit` unset otherwise means "no limit" —
|
|
148
|
+
* types.ts's clampApprovalLimit). reconcileApprovalsForSummary needs a
|
|
149
|
+
* suspended run's FULL approval history — every status, every past
|
|
150
|
+
* suspension — to tell a stale fingerprint from a current one; a truncated
|
|
151
|
+
* read could hide a stale open record (so it never gets superseded) or a
|
|
152
|
+
* decided-current one (so a fresh record double-files over it).
|
|
153
|
+
*/
|
|
154
|
+
async function listAllApprovals(service, filter, actor) {
|
|
155
|
+
const all = [];
|
|
156
|
+
let after;
|
|
157
|
+
for (;;) {
|
|
158
|
+
const page = await service.list({ ...filter, limit: MAX_APPROVAL_LIST_LIMIT, after }, actor);
|
|
159
|
+
all.push(...page);
|
|
160
|
+
const last = page.at(-1);
|
|
161
|
+
if (page.length < MAX_APPROVAL_LIST_LIMIT || !last)
|
|
162
|
+
break;
|
|
163
|
+
after = approvalCursor(last);
|
|
164
|
+
}
|
|
165
|
+
return all;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* D4 recovery primitive: given a run's suspended RunSummary, heals every
|
|
169
|
+
* CURRENTLY suspended step whose exact (suspendedAt, resumeCount)
|
|
170
|
+
* fingerprint has no approval record of ANY status, then files it fresh.
|
|
171
|
+
* Safe to call on every status() read of a suspended run, rather than only
|
|
172
|
+
* after a confirmed bridge failure, because per step:
|
|
173
|
+
*
|
|
174
|
+
* - any record (any status) already bound to the CURRENT fingerprint means
|
|
175
|
+
* nothing to do — a matching pending/claimed/escalated record makes
|
|
176
|
+
* queueApprovalForSuspension's own idempotent create() a no-op anyway
|
|
177
|
+
* (this skips the round-trip), and a matching DECIDED record means the
|
|
178
|
+
* decision landed but its resume has not (yet, or ever, on the wedge path
|
|
179
|
+
* this exists for) re-queued the next gate — re-filing would double-file
|
|
180
|
+
* a gate correctly waiting on its own resume, the decide -> resume
|
|
181
|
+
* in-flight window;
|
|
182
|
+
* - otherwise, every STALE OPEN record for that step (pending/claimed/
|
|
183
|
+
* escalated, bound to a suspension the step has since moved past —
|
|
184
|
+
* produced e.g. by the raw grant-free resume route re-suspending the step
|
|
185
|
+
* while an earlier request still sits open) is SUPERSEDED first
|
|
186
|
+
* (ApprovalService.supersedeStale: a CAS transition straight to
|
|
187
|
+
* 'rejected', system-attributed, audited as approval.supersede, never
|
|
188
|
+
* through decide() — so it never touches the run) before the fresh file,
|
|
189
|
+
* closing the loop where a stale-but-open record otherwise never heals
|
|
190
|
+
* (every poll re-lists, finds the same open record via the open-step
|
|
191
|
+
* uniqueness index, and re-files nothing). A stale DECIDED record needs
|
|
192
|
+
* no supersede — it is already terminal and excluded from grant
|
|
193
|
+
* derivation by its own (non-'approved', or fingerprint-mismatched)
|
|
194
|
+
* status.
|
|
195
|
+
* - if a supersede loses its CAS (a real decision won the race between the
|
|
196
|
+
* list() above and the supersede), this step is left alone for this
|
|
197
|
+
* round entirely — no fresh file — rather than clobbering or
|
|
198
|
+
* double-filing over a decision that just landed; the next status() read
|
|
199
|
+
* re-evaluates against a fresh summary and a fresh list().
|
|
200
|
+
*
|
|
201
|
+
* Delegates the actual filing to queueApprovalForSuspension against a copy of
|
|
202
|
+
* `summary` narrowed to only the healed paths, so a step with a live or
|
|
203
|
+
* in-flight record is never touched. `requestedBy` on a reconciled record is
|
|
204
|
+
* the SYSTEM actor, not a human: on the re-queue-failure trigger a reviewer
|
|
205
|
+
* DID cause the suspension, but reconcile has only the RunSummary to work
|
|
206
|
+
* from and no reliable way to recover who — so it attributes to the system
|
|
207
|
+
* actor rather than guess (see the SoD note in retention.ts and the
|
|
208
|
+
* operations runbook). That is a deliberate, narrow SoD relaxation on this
|
|
209
|
+
* recovery path only: the gate-A decider MAY legally decide the reconciled
|
|
210
|
+
* gate B, same as the retention-purge recovery path.
|
|
211
|
+
*/
|
|
212
|
+
export async function reconcileApprovalsForSummary(service, workflowId, summary, systemActor) {
|
|
213
|
+
const suspended = summary.suspended ?? [];
|
|
214
|
+
if (suspended.length === 0)
|
|
215
|
+
return [];
|
|
216
|
+
const existing = await listAllApprovals(service, { workflowId, runId: summary.runId }, systemActor);
|
|
217
|
+
const toFile = [];
|
|
218
|
+
for (const stepPath of suspended) {
|
|
219
|
+
const stepKey = stepKeyOf(stepPath);
|
|
220
|
+
const suspendedAt = summary.suspendedAt?.[stepKey];
|
|
221
|
+
const resumeCount = summary.resumeCount?.[stepKey];
|
|
222
|
+
const stepRecords = existing.filter((record) => stepKeyOf(record.stepPath) === stepKey);
|
|
223
|
+
const boundToCurrent = stepRecords.some((record) => record.suspendedAt === suspendedAt &&
|
|
224
|
+
record.resumeCount === resumeCount);
|
|
225
|
+
if (boundToCurrent)
|
|
226
|
+
continue;
|
|
227
|
+
let lostRace = false;
|
|
228
|
+
for (const record of stepRecords) {
|
|
229
|
+
if (!OPEN_STATUSES.includes(record.status))
|
|
230
|
+
continue;
|
|
231
|
+
const superseded = await service.supersedeStale(record.id, systemActor, 'superseded: stale suspension fingerprint');
|
|
232
|
+
// null = a real decision won the CAS between the list() above and this
|
|
233
|
+
// supersede — back off THIS step for THIS round rather than clobber or
|
|
234
|
+
// double-file; the next status() read re-evaluates fresh.
|
|
235
|
+
if (!superseded)
|
|
236
|
+
lostRace = true;
|
|
237
|
+
}
|
|
238
|
+
if (lostRace)
|
|
239
|
+
continue;
|
|
240
|
+
toFile.push(stepPath);
|
|
241
|
+
}
|
|
242
|
+
if (toFile.length === 0)
|
|
243
|
+
return [];
|
|
244
|
+
return queueApprovalForSuspension(service, workflowId, { ...summary, suspended: toFile }, systemActor.id, systemActor);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Adapts reconcileApprovalsForSummary to RunRouterOptions.reconcileApprovals's
|
|
248
|
+
* per-request shape: `tenant.service()`/`tenant.tenantId` only exist once a
|
|
249
|
+
* request resolves, so only the systemActorId (a per-deployment constant) can
|
|
250
|
+
* be bound ahead of time — everything else is read from the tenant the router
|
|
251
|
+
* hands in on each call.
|
|
252
|
+
*/
|
|
253
|
+
export function reconcileApprovalsOnStatus(systemActorId) {
|
|
254
|
+
return async (tenant, workflowId, summary) => {
|
|
255
|
+
await reconcileApprovalsForSummary(tenant.service(), workflowId, summary, {
|
|
256
|
+
id: systemActorId,
|
|
257
|
+
role: 'operator',
|
|
258
|
+
tenantId: tenant.tenantId,
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=approval-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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ACd,WAAW,CACZ,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,aAAqB;IAMrB,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QAC3C,MAAM,4BAA4B,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE;YACxE,EAAE,EAAE,aAAa;YACjB,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ApprovalActor } from '../approval-api/index.js';
|
|
2
|
+
import { type TokenVerifier } from './verifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parse the `APPROVAL_ACTOR_TOKENS` secret:
|
|
5
|
+
* `{"<token>": {"id","role","tenantId"}}`. Every entry passes the real
|
|
6
|
+
* validator (toApprovalActor) — unknown roles, empty ids, and missing,
|
|
7
|
+
* non-INV-3, or reserved-identity ('system') tenantIds are dropped rather
|
|
8
|
+
* than trusted; there is no `as`-cast at this JSON boundary.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseActorTokens(raw: string | undefined): Map<string, ApprovalActor>;
|
|
11
|
+
/**
|
|
12
|
+
* Build the `authenticate` seam over a TokenVerifier. Callers with a parsed
|
|
13
|
+
* token map wrap it: `bearerActorAuthenticator(staticTokenVerifier(map))`.
|
|
14
|
+
* Parsing the map stays outside so the JSON is parsed once and shared across
|
|
15
|
+
* both routers (a Worker `fetch` authenticates twice — approval router, then
|
|
16
|
+
* run router; the secret arrives on `env`, so once per request is the floor).
|
|
17
|
+
*/
|
|
18
|
+
export declare function bearerActorAuthenticator(verifier: TokenVerifier): (request: Request) => Promise<ApprovalActor | undefined>;
|
|
19
|
+
//# sourceMappingURL=bearer-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer-auth.d.ts","sourceRoot":"","sources":["../../src/host-kit/bearer-auth.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,eAAe,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAiC5B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,aAAa,GACtB,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAO1D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// The bearer auth seam every host shares: extract the bearer token, hand it
|
|
2
|
+
// to a TokenVerifier (static map or HS256 JWT — verifier.ts), get back an
|
|
3
|
+
// ApprovalActor or undefined.
|
|
4
|
+
//
|
|
5
|
+
// This is trusted-computing-base code: it ASSERTS identity (the service
|
|
6
|
+
// enforces roles from it; the tenant predicates key on actor.tenantId), so a
|
|
7
|
+
// malformed map must fail closed — an unparseable or absent secret yields an
|
|
8
|
+
// empty map and every authenticated route 401s, and an entry without an
|
|
9
|
+
// INV-3-valid tenantId is dropped (its token 401s) rather than admitted
|
|
10
|
+
// tenant-less.
|
|
11
|
+
import { toApprovalActor } from './verifier.js';
|
|
12
|
+
/**
|
|
13
|
+
* Parse the `APPROVAL_ACTOR_TOKENS` secret:
|
|
14
|
+
* `{"<token>": {"id","role","tenantId"}}`. Every entry passes the real
|
|
15
|
+
* validator (toApprovalActor) — unknown roles, empty ids, and missing,
|
|
16
|
+
* non-INV-3, or reserved-identity ('system') tenantIds are dropped rather
|
|
17
|
+
* than trusted; there is no `as`-cast at this JSON boundary.
|
|
18
|
+
*/
|
|
19
|
+
export function parseActorTokens(raw) {
|
|
20
|
+
const actors = new Map();
|
|
21
|
+
if (!raw)
|
|
22
|
+
return actors;
|
|
23
|
+
let parsed;
|
|
24
|
+
try {
|
|
25
|
+
parsed = JSON.parse(raw);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
console.error(JSON.stringify({
|
|
29
|
+
type: 'config-error',
|
|
30
|
+
var: 'APPROVAL_ACTOR_TOKENS',
|
|
31
|
+
reason: 'not valid JSON — all authenticated routes will 401',
|
|
32
|
+
}));
|
|
33
|
+
return actors;
|
|
34
|
+
}
|
|
35
|
+
if (parsed === null || typeof parsed !== 'object')
|
|
36
|
+
return actors;
|
|
37
|
+
for (const [token, candidate] of Object.entries(parsed)) {
|
|
38
|
+
const actor = toApprovalActor(candidate);
|
|
39
|
+
if (actor) {
|
|
40
|
+
actors.set(token, actor);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error(JSON.stringify({
|
|
44
|
+
type: 'config-error',
|
|
45
|
+
var: 'APPROVAL_ACTOR_TOKENS',
|
|
46
|
+
reason: "entry dropped: needs non-empty id, a known role, and an INV-3 tenantId (^[a-z0-9]{3,32}$, not the reserved identity 'system') — its token will 401",
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return actors;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build the `authenticate` seam over a TokenVerifier. Callers with a parsed
|
|
54
|
+
* token map wrap it: `bearerActorAuthenticator(staticTokenVerifier(map))`.
|
|
55
|
+
* Parsing the map stays outside so the JSON is parsed once and shared across
|
|
56
|
+
* both routers (a Worker `fetch` authenticates twice — approval router, then
|
|
57
|
+
* run router; the secret arrives on `env`, so once per request is the floor).
|
|
58
|
+
*/
|
|
59
|
+
export function bearerActorAuthenticator(verifier) {
|
|
60
|
+
return async (request) => {
|
|
61
|
+
const token = request.headers
|
|
62
|
+
.get('authorization')
|
|
63
|
+
?.match(/^Bearer\s+(.+)$/i)?.[1];
|
|
64
|
+
return token ? verifier.verify(token) : undefined;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=bearer-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer-auth.js","sourceRoot":"","sources":["../../src/host-kit/bearer-auth.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,8BAA8B;AAC9B,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,eAAe;AAGf,OAAO,EAAsB,eAAe,EAAE,MAAM,eAAe,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAuB;IAEvB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAChD,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IACxB,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,cAAc;YACpB,GAAG,EAAE,uBAAuB;YAC5B,MAAM,EAAE,oDAAoD;SAC7D,CAAC,CACH,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IACjE,KAAK,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,cAAc;gBACpB,GAAG,EAAE,uBAAuB;gBAC5B,MAAM,EACJ,oJAAoJ;aACvJ,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAuB;IAEvB,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO;aAC1B,GAAG,CAAC,eAAe,CAAC;YACrB,EAAE,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RunSummary } from '../do-runner/index.js';
|
|
2
|
+
/** The subset of a DO fetch Response this reader touches. */
|
|
3
|
+
export interface DoResponseLike {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
status: number;
|
|
6
|
+
json(): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse a DO response as a RunSummary, translating a non-ok answer into a
|
|
10
|
+
* RunRouteError carrying the DO's own status and message.
|
|
11
|
+
*/
|
|
12
|
+
export declare function doSummary(response: DoResponseLike): Promise<RunSummary>;
|
|
13
|
+
//# sourceMappingURL=do-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-response.d.ts","sourceRoot":"","sources":["../../src/host-kit/do-response.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAY7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Reading a Durable Object's answer back as a RunSummary.
|
|
2
|
+
//
|
|
3
|
+
// Hosts that reach their runs through a DO stub (the showcase, the deploy
|
|
4
|
+
// template) all need this: the DO already mapped the runtime's typed errors to
|
|
5
|
+
// 404/409/400, so a non-ok answer must carry that status through the run
|
|
6
|
+
// router's error mapping rather than collapse into a generic 500.
|
|
7
|
+
import { RunRouteError } from './run-route-error.js';
|
|
8
|
+
/**
|
|
9
|
+
* Parse a DO response as a RunSummary, translating a non-ok answer into a
|
|
10
|
+
* RunRouteError carrying the DO's own status and message.
|
|
11
|
+
*/
|
|
12
|
+
export async function doSummary(response) {
|
|
13
|
+
const payload = await response.json();
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
const message = payload !== null &&
|
|
16
|
+
typeof payload === 'object' &&
|
|
17
|
+
typeof payload.error === 'string'
|
|
18
|
+
? payload.error
|
|
19
|
+
: `run request failed with status ${response.status}`;
|
|
20
|
+
throw new RunRouteError(response.status, message);
|
|
21
|
+
}
|
|
22
|
+
return payload;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=do-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-response.js","sourceRoot":"","sources":["../../src/host-kit/do-response.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,yEAAyE;AACzE,kEAAkE;AAGlE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AASrD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAwB;IACtD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACtC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,OAAO,GACX,OAAO,KAAK,IAAI;YAChB,OAAO,OAAO,KAAK,QAAQ;YAC3B,OAAQ,OAA+B,CAAC,KAAK,KAAK,QAAQ;YACxD,CAAC,CAAE,OAA6B,CAAC,KAAK;YACtC,CAAC,CAAC,kCAAkC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC1D,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,OAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ApprovalDecision, ApprovalRecord } from '../approval-api/index.js';
|
|
2
|
+
import type { RunSummary } from '../do-runner/index.js';
|
|
3
|
+
import { type DoResponseLike } from './do-response.js';
|
|
4
|
+
/** The subset of a DurableObjectStub the topology uses. */
|
|
5
|
+
export interface RunnerStubLike {
|
|
6
|
+
fetch(url: string, init?: {
|
|
7
|
+
method?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
body?: string;
|
|
10
|
+
}): Promise<DoResponseLike>;
|
|
11
|
+
}
|
|
12
|
+
/** The subset of a DurableObjectNamespace the topology uses. */
|
|
13
|
+
export interface RunnerNamespaceLike<Id = unknown> {
|
|
14
|
+
idFromName(name: string): Id;
|
|
15
|
+
get(id: Id): RunnerStubLike;
|
|
16
|
+
}
|
|
17
|
+
export interface DoRunTopology {
|
|
18
|
+
/** createRunRouter's `start` thunk. */
|
|
19
|
+
start(workflowId: string, runId: string, inputData: unknown): Promise<RunSummary>;
|
|
20
|
+
/** createRunRouter's `status` thunk (a DO 404 reads as undefined). */
|
|
21
|
+
status(workflowId: string, runId: string): Promise<RunSummary | undefined>;
|
|
22
|
+
/** createRunRouter's `resume` thunk. */
|
|
23
|
+
resume(workflowId: string, runId: string, body: unknown): Promise<RunSummary>;
|
|
24
|
+
/**
|
|
25
|
+
* ApprovalServiceOptions.resumeRun base: resume a DECIDED approval's run
|
|
26
|
+
* through its DO stub with the standard resumeData contract. Hand this to
|
|
27
|
+
* buildHostApprovalService, which wraps it in the SoD-guarded re-queue.
|
|
28
|
+
*/
|
|
29
|
+
resumeRecord(record: ApprovalRecord, decision: ApprovalDecision): Promise<RunSummary>;
|
|
30
|
+
}
|
|
31
|
+
export declare function createDoRunTopology<Id>(namespace: RunnerNamespaceLike<Id>): DoRunTopology;
|
|
32
|
+
//# sourceMappingURL=do-run-topology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-run-topology.d.ts","sourceRoot":"","sources":["../../src/host-kit/do-run-topology.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,kBAAkB,CAAC;AAElE,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,KAAK,CACH,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GACA,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB,CAAC,EAAE,GAAG,OAAO;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC;IAC7B,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,KAAK,CACH,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,sEAAsE;IACtE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC3E,wCAAwC;IACxC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9E;;;;OAIG;IACH,YAAY,CACV,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;CACxB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EACpC,SAAS,EAAE,mBAAmB,CAAC,EAAE,CAAC,GACjC,aAAa,CA+Cf"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The DO-stub run topology every DO-routing host repeated verbatim: one
|
|
2
|
+
// Durable Object instance per (workflowId, runId), addressed by idFromName,
|
|
3
|
+
// with start/status/resume travelling as HTTP through the stub and read back
|
|
4
|
+
// via doSummary. Hosts pass their `env.RUNNER` binding directly — the
|
|
5
|
+
// namespace/stub types are structural subsets so this module (like the rest
|
|
6
|
+
// of host-kit) never imports @cloudflare/workers-types.
|
|
7
|
+
import { defaultResumeData } from '../approval-api/index.js';
|
|
8
|
+
import { doSummary } from './do-response.js';
|
|
9
|
+
export function createDoRunTopology(namespace) {
|
|
10
|
+
// One DO per (workflowId, runId): the name join is unambiguous because
|
|
11
|
+
// PATH_SAFE_ID_PATTERN excludes ':' from both ids.
|
|
12
|
+
const stub = (workflowId, runId) => namespace.get(namespace.idFromName(`${workflowId}:${runId}`));
|
|
13
|
+
const resume = async (workflowId, runId, body) => doSummary(await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}/resume`, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: { 'content-type': 'application/json' },
|
|
16
|
+
body: JSON.stringify(body),
|
|
17
|
+
}));
|
|
18
|
+
return {
|
|
19
|
+
start: async (workflowId, runId, inputData) => doSummary(await stub(workflowId, runId).fetch('http://do/runs', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: { 'content-type': 'application/json' },
|
|
22
|
+
body: JSON.stringify({ workflowId, runId, inputData }),
|
|
23
|
+
})),
|
|
24
|
+
// The DO answers 404 for a run it has never seen; the router turns the
|
|
25
|
+
// undefined into its own 404 rather than leaking the DO's body.
|
|
26
|
+
status: async (workflowId, runId) => {
|
|
27
|
+
const response = await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}`);
|
|
28
|
+
if (response.status === 404)
|
|
29
|
+
return undefined;
|
|
30
|
+
return doSummary(response);
|
|
31
|
+
},
|
|
32
|
+
resume,
|
|
33
|
+
resumeRecord: (record, decision) => resume(record.workflowId, record.runId, {
|
|
34
|
+
step: record.stepPath,
|
|
35
|
+
resumeData: defaultResumeData(record, decision),
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=do-run-topology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-run-topology.js","sourceRoot":"","sources":["../../src/host-kit/do-run-topology.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,wDAAwD;AAMxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAuB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA0ClE,MAAM,UAAU,mBAAmB,CACjC,SAAkC;IAElC,uEAAuE;IACvE,mDAAmD;IACnD,MAAM,IAAI,GAAG,CAAC,UAAkB,EAAE,KAAa,EAAkB,EAAE,CACjE,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC;IAEhE,MAAM,MAAM,GAAG,KAAK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AAQ,CAAC;SAChD,CAAC;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface NumberVarOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Permit 0. Cap-style vars opt in: `DEMO_DAILY_RUN_CAP=0` ("freeze the
|
|
4
|
+
* demo") and `RUN_RETENTION_DAYS=0` ("purge terminal runs immediately")
|
|
5
|
+
* are real operator intents — exactly the values an incident reaches for —
|
|
6
|
+
* and rejecting them silently reverts to the fallback while the
|
|
7
|
+
* config-error line reads as a caught typo. Duration/TTL vars keep the
|
|
8
|
+
* default rejection: a 0-second JWT or 0-hour sandbox is never meant.
|
|
9
|
+
*/
|
|
10
|
+
allowZero?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function numberVar(raw: string | undefined, fallback: number, name: string, options?: NumberVarOptions): number;
|
|
13
|
+
/**
|
|
14
|
+
* Boolean env var. Absent or empty => false (the flag is simply not set).
|
|
15
|
+
* The usual spellings parse case-insensitively (true/1/yes/on,
|
|
16
|
+
* false/0/no/off); any OTHER value logs a config-error and returns
|
|
17
|
+
* `onInvalid` — the caller states its fail-closed reading, because polarity
|
|
18
|
+
* decides it: for a kill switch (DEMO_DISABLED) the safe reading of
|
|
19
|
+
* `DEMO_DISABLED=disable-now-please` is `true` (demo dies), never "carry on
|
|
20
|
+
* as if unset" — an emergency control that only recognizes one literal
|
|
21
|
+
* silently no-ops in the incident it exists for.
|
|
22
|
+
*/
|
|
23
|
+
export declare function boolVar(raw: string | undefined, name: string, options: {
|
|
24
|
+
onInvalid: boolean;
|
|
25
|
+
}): boolean;
|
|
26
|
+
//# sourceMappingURL=env-vars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-vars.d.ts","sourceRoot":"","sources":["../../src/host-kit/env-vars.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAaR;AAKD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,GAC9B,OAAO,CAcT"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Env-var parsing shared by the Worker hosts (previously copied verbatim
|
|
2
|
+
// into each). Fallback-not-fail is the numeric contract: maintenance and
|
|
3
|
+
// auth must keep running on a typo'd var, and the config-error log line is
|
|
4
|
+
// the operator's tripwire. The boolean contract is the opposite where it
|
|
5
|
+
// matters: a kill switch fed garbage must KILL, not silently carry on — the
|
|
6
|
+
// caller names its fail-closed value.
|
|
7
|
+
export function numberVar(raw, fallback, name, options = {}) {
|
|
8
|
+
if (raw === undefined || raw === '')
|
|
9
|
+
return fallback;
|
|
10
|
+
const value = Number(raw);
|
|
11
|
+
const belowFloor = options.allowZero ? value < 0 : value <= 0;
|
|
12
|
+
if (!Number.isFinite(value) || belowFloor) {
|
|
13
|
+
// Fall back rather than fail: maintenance must keep running on a typo'd
|
|
14
|
+
// var, and the log line is the operator's tripwire.
|
|
15
|
+
console.error(JSON.stringify({ type: 'config-error', var: name, raw, fallback }));
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
const TRUTHY = new Set(['true', '1', 'yes', 'on']);
|
|
21
|
+
const FALSY = new Set(['false', '0', 'no', 'off']);
|
|
22
|
+
/**
|
|
23
|
+
* Boolean env var. Absent or empty => false (the flag is simply not set).
|
|
24
|
+
* The usual spellings parse case-insensitively (true/1/yes/on,
|
|
25
|
+
* false/0/no/off); any OTHER value logs a config-error and returns
|
|
26
|
+
* `onInvalid` — the caller states its fail-closed reading, because polarity
|
|
27
|
+
* decides it: for a kill switch (DEMO_DISABLED) the safe reading of
|
|
28
|
+
* `DEMO_DISABLED=disable-now-please` is `true` (demo dies), never "carry on
|
|
29
|
+
* as if unset" — an emergency control that only recognizes one literal
|
|
30
|
+
* silently no-ops in the incident it exists for.
|
|
31
|
+
*/
|
|
32
|
+
export function boolVar(raw, name, options) {
|
|
33
|
+
if (raw === undefined || raw === '')
|
|
34
|
+
return false;
|
|
35
|
+
const value = raw.trim().toLowerCase();
|
|
36
|
+
if (TRUTHY.has(value))
|
|
37
|
+
return true;
|
|
38
|
+
if (FALSY.has(value))
|
|
39
|
+
return false;
|
|
40
|
+
console.error(JSON.stringify({
|
|
41
|
+
type: 'config-error',
|
|
42
|
+
var: name,
|
|
43
|
+
raw,
|
|
44
|
+
effective: options.onInvalid,
|
|
45
|
+
}));
|
|
46
|
+
return options.onInvalid;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=env-vars.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-vars.js","sourceRoot":"","sources":["../../src/host-kit/env-vars.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,sCAAsC;AActC,MAAM,UAAU,SAAS,CACvB,GAAuB,EACvB,QAAgB,EAChB,IAAY,EACZ,UAA4B,EAAE;IAE9B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IACrD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAC9D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,U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