@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,245 @@
|
|
|
1
|
+
// HTTP surface for the approval queue (flowsafe-architecture.md endpoint
|
|
2
|
+
// table). Plain fetch routing like the DO runner — no HTTP framework.
|
|
3
|
+
//
|
|
4
|
+
// The router returns null for paths outside its base so a host Worker can
|
|
5
|
+
// compose it ahead of its other routes. Authentication is injected: the
|
|
6
|
+
// authenticate option maps a Request to the acting principal and is part of
|
|
7
|
+
// the trusted computing base (it asserts identity; the service enforces
|
|
8
|
+
// roles). No actor -> 401 before any service call.
|
|
9
|
+
//
|
|
10
|
+
// The create route is OFF by default (allowCreate) and, when mounted, cannot
|
|
11
|
+
// author capability: it rejects every TCB_ONLY_CREATE_FIELDS member and
|
|
12
|
+
// force-attributes the request to the authenticated actor. Approval records
|
|
13
|
+
// that carry grants are minted in-process from an observed suspension, never
|
|
14
|
+
// from a request body.
|
|
15
|
+
import { ApprovalAuthzError, ApprovalConflictError, InvalidApprovalInputError, UnknownApprovalError, } from './service.js';
|
|
16
|
+
import { TenantResolutionError, } from './tenant-context.js';
|
|
17
|
+
import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVAL_LIST_LIMIT, parseApprovalCursor, } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Fields on CreateApprovalInput that select CAPABILITY or ATTRIBUTION, and so
|
|
20
|
+
* belong to the trusted computing base alone (security-threat-model.md, trust
|
|
21
|
+
* boundary 6). A request body that names any of them is rejected outright:
|
|
22
|
+
*
|
|
23
|
+
* - `connectors` IS the minted grant — an approved record's connectors become
|
|
24
|
+
* the requestContext grant the write gate checks.
|
|
25
|
+
* - `runScoped` turns a step-less record into a standing grant on every leg.
|
|
26
|
+
* - `stepPath`, `suspendedAt`, `resumedAt`, `resumeCount` select WHICH leg a
|
|
27
|
+
* grant mints on. A step-keyed body with no `suspendedAt` would fall into
|
|
28
|
+
* grants.ts's legacy decidedAt-after fallback and mint, so rejecting
|
|
29
|
+
* `connectors` alone is insufficient — reject the whole set.
|
|
30
|
+
* - `requestedBy` is the field decide()'s separation-of-duties check compares
|
|
31
|
+
* against; spoofing it lets one principal approve their own request.
|
|
32
|
+
*/
|
|
33
|
+
export const TCB_ONLY_CREATE_FIELDS = [
|
|
34
|
+
'connectors',
|
|
35
|
+
'stepPath',
|
|
36
|
+
'suspendedAt',
|
|
37
|
+
'resumedAt',
|
|
38
|
+
'resumeCount',
|
|
39
|
+
'runScoped',
|
|
40
|
+
'requestedBy',
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* The complement: what a request body MAY set. The create route copies ONLY
|
|
44
|
+
* these fields off the body — an allowlist, so a field added to
|
|
45
|
+
* CreateApprovalInput later is INERT over HTTP until it is deliberately
|
|
46
|
+
* classified here (fail closed by construction; a body spread would instead
|
|
47
|
+
* hand every future field to service.create unless someone remembered to
|
|
48
|
+
* extend the denylist above). TCB_ONLY_CREATE_FIELDS stays as the
|
|
49
|
+
* 400-with-a-reason layer; router.test.ts pins at the type level that the two
|
|
50
|
+
* lists exactly cover CreateApprovalInput.
|
|
51
|
+
*/
|
|
52
|
+
export const CLIENT_CREATE_FIELDS = [
|
|
53
|
+
'workflowId',
|
|
54
|
+
'runId',
|
|
55
|
+
'title',
|
|
56
|
+
'summary',
|
|
57
|
+
'payload',
|
|
58
|
+
'priority',
|
|
59
|
+
'slaSeconds',
|
|
60
|
+
];
|
|
61
|
+
function json(payload, status = 200) {
|
|
62
|
+
return new Response(JSON.stringify(payload), {
|
|
63
|
+
status,
|
|
64
|
+
headers: { 'content-type': 'application/json' },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function errorResponse(error) {
|
|
68
|
+
if (error instanceof InvalidApprovalInputError) {
|
|
69
|
+
return json({ error: error.message }, 400);
|
|
70
|
+
}
|
|
71
|
+
if (error instanceof TenantResolutionError) {
|
|
72
|
+
// An authenticated actor with a malformed tenant claim is a verifier
|
|
73
|
+
// bug, not a client 4xx it can fix — but it must not become a 500 that
|
|
74
|
+
// reads as "try again". Forbidden, with the reason in the body.
|
|
75
|
+
return json({ error: 'forbidden' }, 403);
|
|
76
|
+
}
|
|
77
|
+
if (error instanceof ApprovalAuthzError) {
|
|
78
|
+
return json({ error: error.message }, 403);
|
|
79
|
+
}
|
|
80
|
+
if (error instanceof UnknownApprovalError) {
|
|
81
|
+
return json({ error: error.message }, 404);
|
|
82
|
+
}
|
|
83
|
+
if (error instanceof ApprovalConflictError) {
|
|
84
|
+
return json({ error: error.message, currentStatus: error.currentStatus }, 409);
|
|
85
|
+
}
|
|
86
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
87
|
+
return json({ error: message }, 500);
|
|
88
|
+
}
|
|
89
|
+
async function readJsonObject(request) {
|
|
90
|
+
let body;
|
|
91
|
+
try {
|
|
92
|
+
body = await request.json();
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new InvalidApprovalInputError('request body must be JSON');
|
|
96
|
+
}
|
|
97
|
+
if (body === null || typeof body !== 'object' || Array.isArray(body)) {
|
|
98
|
+
throw new InvalidApprovalInputError('request body must be a JSON object');
|
|
99
|
+
}
|
|
100
|
+
return body;
|
|
101
|
+
}
|
|
102
|
+
function parseListFilter(url) {
|
|
103
|
+
const filter = {};
|
|
104
|
+
const status = url.searchParams.get('status');
|
|
105
|
+
if (status !== null) {
|
|
106
|
+
const statuses = status.split(',').map((value) => value.trim());
|
|
107
|
+
for (const value of statuses) {
|
|
108
|
+
if (!APPROVAL_STATUSES.includes(value)) {
|
|
109
|
+
throw new InvalidApprovalInputError(`unknown status '${value}' (expected one of [${APPROVAL_STATUSES.join(', ')}])`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
filter.status = statuses;
|
|
113
|
+
}
|
|
114
|
+
const workflowId = url.searchParams.get('workflowId');
|
|
115
|
+
if (workflowId !== null)
|
|
116
|
+
filter.workflowId = workflowId;
|
|
117
|
+
const runId = url.searchParams.get('runId');
|
|
118
|
+
if (runId !== null)
|
|
119
|
+
filter.runId = runId;
|
|
120
|
+
const claimedBy = url.searchParams.get('claimedBy');
|
|
121
|
+
if (claimedBy !== null)
|
|
122
|
+
filter.claimedBy = claimedBy;
|
|
123
|
+
const limit = url.searchParams.get('limit');
|
|
124
|
+
if (limit !== null) {
|
|
125
|
+
const parsed = Number(limit);
|
|
126
|
+
if (!Number.isInteger(parsed) ||
|
|
127
|
+
parsed < 1 ||
|
|
128
|
+
parsed > MAX_APPROVAL_LIST_LIMIT) {
|
|
129
|
+
throw new InvalidApprovalInputError(`limit must be an integer between 1 and ${MAX_APPROVAL_LIST_LIMIT} (got '${limit}')`);
|
|
130
|
+
}
|
|
131
|
+
filter.limit = parsed;
|
|
132
|
+
}
|
|
133
|
+
const after = url.searchParams.get('after');
|
|
134
|
+
if (after !== null) {
|
|
135
|
+
// Validate eagerly so a malformed cursor is a 400 here, not a 500 (or a
|
|
136
|
+
// silently-empty page) once it reaches the store — parseApprovalCursor
|
|
137
|
+
// is the one shared decoder (types.ts), so this is the exact check
|
|
138
|
+
// store.ts/d1-store.ts will apply again when they actually page with it.
|
|
139
|
+
try {
|
|
140
|
+
parseApprovalCursor(after);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
throw new InvalidApprovalInputError(`after is not a valid approval cursor (got '${after}')`);
|
|
144
|
+
}
|
|
145
|
+
filter.after = after;
|
|
146
|
+
}
|
|
147
|
+
const orderBy = url.searchParams.get('orderBy');
|
|
148
|
+
if (orderBy !== null) {
|
|
149
|
+
if (!APPROVAL_LIST_ORDERS.includes(orderBy)) {
|
|
150
|
+
throw new InvalidApprovalInputError(`unknown orderBy '${orderBy}' (expected one of [${APPROVAL_LIST_ORDERS.join(', ')}])`);
|
|
151
|
+
}
|
|
152
|
+
filter.orderBy = orderBy;
|
|
153
|
+
}
|
|
154
|
+
// Same eager-validation rationale as the cursor above: the reviewer/after
|
|
155
|
+
// incoherence must 400 here, not surface as a store throw mapped to 500 —
|
|
156
|
+
// approvalListOrder is the one shared rule the stores re-apply.
|
|
157
|
+
try {
|
|
158
|
+
approvalListOrder(filter);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
throw new InvalidApprovalInputError(error instanceof Error ? error.message : String(error));
|
|
162
|
+
}
|
|
163
|
+
return filter;
|
|
164
|
+
}
|
|
165
|
+
export function createApprovalRouter(options) {
|
|
166
|
+
const { resolve } = options;
|
|
167
|
+
const basePath = options.basePath ?? '/api/approvals';
|
|
168
|
+
const allowCreate = options.allowCreate ?? false;
|
|
169
|
+
return async (request) => {
|
|
170
|
+
const url = new URL(request.url);
|
|
171
|
+
if (url.pathname !== basePath && !url.pathname.startsWith(`${basePath}/`)) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const segments = url.pathname
|
|
175
|
+
.slice(basePath.length)
|
|
176
|
+
.split('/')
|
|
177
|
+
.filter(Boolean);
|
|
178
|
+
try {
|
|
179
|
+
const tenant = await resolve(request);
|
|
180
|
+
if (!tenant)
|
|
181
|
+
return json({ error: 'authentication required' }, 401);
|
|
182
|
+
const actor = tenant.actor;
|
|
183
|
+
const service = tenant.service();
|
|
184
|
+
if (request.method === 'GET') {
|
|
185
|
+
if (segments.length === 0) {
|
|
186
|
+
return json(await service.list(parseListFilter(url), actor));
|
|
187
|
+
}
|
|
188
|
+
if (segments.length === 1 && segments[0] === 'metrics') {
|
|
189
|
+
return json(await service.metrics(actor));
|
|
190
|
+
}
|
|
191
|
+
if (segments.length === 1 && segments[0]) {
|
|
192
|
+
return json(await service.get(segments[0], actor));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (request.method === 'POST') {
|
|
196
|
+
if (segments.length === 0) {
|
|
197
|
+
if (!allowCreate)
|
|
198
|
+
return json({ error: 'not found' }, 404);
|
|
199
|
+
const body = await readJsonObject(request);
|
|
200
|
+
for (const field of TCB_ONLY_CREATE_FIELDS) {
|
|
201
|
+
if (field in body) {
|
|
202
|
+
throw new InvalidApprovalInputError(`${field} may not be set over HTTP`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Attribution is the authenticated identity, never the body:
|
|
206
|
+
// service.create still honours input.requestedBy for the
|
|
207
|
+
// in-process bridge (which legitimately attributes the human who
|
|
208
|
+
// advanced the run), so the tightening lives here at the HTTP
|
|
209
|
+
// boundary alone.
|
|
210
|
+
const input = { requestedBy: actor.id };
|
|
211
|
+
for (const field of CLIENT_CREATE_FIELDS) {
|
|
212
|
+
if (field in body)
|
|
213
|
+
input[field] = body[field];
|
|
214
|
+
}
|
|
215
|
+
const { record, created } = await service.create(input, actor);
|
|
216
|
+
return json(record, created ? 201 : 200);
|
|
217
|
+
}
|
|
218
|
+
// NOTE: there is deliberately NO /sla/sweep route. The sweep is an
|
|
219
|
+
// unfiltered cross-tenant read+write; it lives in the cron-owned
|
|
220
|
+
// sweepSLA() function over a SystemApprovalStore, unreachable from
|
|
221
|
+
// request scope by type.
|
|
222
|
+
const [id, action] = segments;
|
|
223
|
+
if (segments.length === 2 && id && action === 'claim') {
|
|
224
|
+
return json(await service.claim(id, actor));
|
|
225
|
+
}
|
|
226
|
+
if (segments.length === 2 && id && action === 'decide') {
|
|
227
|
+
const body = await readJsonObject(request);
|
|
228
|
+
return json(await service.decide(id, {
|
|
229
|
+
decision: body.decision,
|
|
230
|
+
comment: body.comment,
|
|
231
|
+
}, actor));
|
|
232
|
+
}
|
|
233
|
+
if (segments.length === 2 && id && action === 'delegate') {
|
|
234
|
+
const body = await readJsonObject(request);
|
|
235
|
+
return json(await service.delegate(id, { to: body.to }, actor));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return json({ error: 'not found' }, 404);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
return errorResponse(error);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src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EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAY,EAAE,EAAE,KAAK,CAAC,CAC7D,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { ApprovalActor, ApprovalAuditSink } from './contract.js';
|
|
2
|
+
import type { SystemApprovalStore, TenantBoundApprovalStore } from './tenant-brand.js';
|
|
3
|
+
import { type ApprovalDecision, type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalStatus, type CreateApprovalInput, type DecideResult } from './types.js';
|
|
4
|
+
/** Requester failed role authorization — HTTP 403. */
|
|
5
|
+
export declare class ApprovalAuthzError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/** No approval with that id — HTTP 404. */
|
|
9
|
+
export declare class UnknownApprovalError extends Error {
|
|
10
|
+
constructor(id: string);
|
|
11
|
+
}
|
|
12
|
+
/** CAS guard failed: the request moved to a state the action no longer applies to — HTTP 409. */
|
|
13
|
+
export declare class ApprovalConflictError extends Error {
|
|
14
|
+
readonly currentStatus: ApprovalStatus;
|
|
15
|
+
constructor(id: string, action: string, currentStatus: ApprovalStatus);
|
|
16
|
+
}
|
|
17
|
+
/** A request the caller can fix — HTTP 400. */
|
|
18
|
+
export declare class InvalidApprovalInputError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
export interface ApprovalServiceOptions {
|
|
22
|
+
/**
|
|
23
|
+
* MUST be tenant-bound (INV-2): the service asserts every acting
|
|
24
|
+
* principal's tenant against this binding, and the store's predicates are
|
|
25
|
+
* what scope reads/writes. Obtain via a store factory's forTenant().
|
|
26
|
+
*/
|
|
27
|
+
store: TenantBoundApprovalStore;
|
|
28
|
+
/**
|
|
29
|
+
* Structural match for breakwater AuditLogger.record — wire
|
|
30
|
+
* `(event) => auditLogger.record(event)`. Must not throw; failures are
|
|
31
|
+
* contained anyway (availability over export reliability, matching
|
|
32
|
+
* AuditLogger's own sink policy).
|
|
33
|
+
*/
|
|
34
|
+
audit?: ApprovalAuditSink;
|
|
35
|
+
/** Applied when CreateApprovalInput.slaSeconds is absent. */
|
|
36
|
+
defaultSlaSeconds?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Resumes the run after a decision (approve AND reject — the workflow
|
|
39
|
+
* learns the outcome via resumeData). Same-Worker deployments use
|
|
40
|
+
* resumeViaRuntime(runtime); cross-Worker ones fetch the run's DO.
|
|
41
|
+
*/
|
|
42
|
+
resumeRun?: (record: ApprovalRecord, decision: ApprovalDecision) => Promise<unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Permit the requester to decide their own request. Off by default —
|
|
45
|
+
* separation of duties is the safe enterprise default; enable only for
|
|
46
|
+
* single-operator deployments.
|
|
47
|
+
*/
|
|
48
|
+
allowSelfDecision?: boolean;
|
|
49
|
+
/** Injectable clock (tests, deterministic SLA math). */
|
|
50
|
+
now?: () => Date;
|
|
51
|
+
}
|
|
52
|
+
export declare class ApprovalService {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(options: ApprovalServiceOptions);
|
|
55
|
+
create(input: CreateApprovalInput, actor: ApprovalActor): Promise<{
|
|
56
|
+
record: ApprovalRecord;
|
|
57
|
+
created: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
get(id: string, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
60
|
+
list(filter: ApprovalListFilter, actor: ApprovalActor): Promise<ApprovalRecord[]>;
|
|
61
|
+
claim(id: string, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
62
|
+
decide(id: string, input: {
|
|
63
|
+
decision: ApprovalDecision;
|
|
64
|
+
comment?: string;
|
|
65
|
+
}, actor: ApprovalActor): Promise<DecideResult>;
|
|
66
|
+
/**
|
|
67
|
+
* D4 follow-up (2026-07-11 audit): CAS-transitions a STALE OPEN record
|
|
68
|
+
* (pending/claimed/escalated, bound to a suspension its step has since
|
|
69
|
+
* moved past) straight to 'rejected'. host-kit's reconcileApprovalsForSummary
|
|
70
|
+
* calls this before filing a fresh record for a step whose only open
|
|
71
|
+
* record no longer matches the run's CURRENT (suspendedAt, resumeCount)
|
|
72
|
+
* fingerprint — the loop where a stale-but-open record otherwise never
|
|
73
|
+
* heals (every poll re-lists, finds the same open record via the
|
|
74
|
+
* open-step uniqueness index, and re-files nothing).
|
|
75
|
+
*
|
|
76
|
+
* Deliberately bypasses decide(): a rejection decision resumes the run
|
|
77
|
+
* with declined semantics via #resume(), and a stale record must die
|
|
78
|
+
* WITHOUT touching a run that is already suspended at a DIFFERENT
|
|
79
|
+
* (current) fingerprint — this method never calls #resume(). 'rejected'
|
|
80
|
+
* (not 'approved') is the deliberate terminal choice: approvedConnectorsForLeg
|
|
81
|
+
* (grants.ts) reads ONLY status: 'approved' records when deriving a leg's
|
|
82
|
+
* grants, so a superseded record is excluded by its STATUS alone, not
|
|
83
|
+
* merely by its stale fingerprint — it can never mint even if a future
|
|
84
|
+
* change loosened the fingerprint check.
|
|
85
|
+
*
|
|
86
|
+
* Never routed by router.ts (an ApprovalService method the HTTP surface
|
|
87
|
+
* never wires up) — reachable only from host-kit's
|
|
88
|
+
* reconcileApprovalsForSummary, itself only invoked from createRunRouter's
|
|
89
|
+
* optional reconcileApprovals hook on a status() read, never from a
|
|
90
|
+
* request body. Authorized like create() (CAN_CREATE, not CAN_REVIEW):
|
|
91
|
+
* the only actor that ever calls this is the same system actor create()
|
|
92
|
+
* already accepts for reconcile-filed records — superseding is the
|
|
93
|
+
* symmetric "un-file" half of that same self-healing operation, not a
|
|
94
|
+
* reviewer decision.
|
|
95
|
+
*
|
|
96
|
+
* Returns null — mirroring the store's own CAS contract, rather than
|
|
97
|
+
* throwing — when the record is unknown or already left the OPEN set (a
|
|
98
|
+
* real decision won the race): the caller backs off instead of treating a
|
|
99
|
+
* lost race as an error, the same "null = lost a race, skip quietly"
|
|
100
|
+
* contract sweepSLA uses for its own store-level CAS.
|
|
101
|
+
*/
|
|
102
|
+
supersedeStale(id: string, actor: ApprovalActor, reason: string): Promise<ApprovalRecord | null>;
|
|
103
|
+
delegate(id: string, input: {
|
|
104
|
+
to: string;
|
|
105
|
+
}, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
106
|
+
metrics(actor: ApprovalActor): Promise<ApprovalMetrics>;
|
|
107
|
+
}
|
|
108
|
+
/** Options for the cron-owned SLA sweep. */
|
|
109
|
+
export interface SweepSLAOptions {
|
|
110
|
+
/**
|
|
111
|
+
* Attribution identity for audit events (e.g. the worker's system actor).
|
|
112
|
+
* Attribution only — the sweep runs inside the trusted computing base
|
|
113
|
+
* (cron), so there is no role check: the TYPE of the store argument is the
|
|
114
|
+
* authorization (a SystemApprovalStore is unobtainable from request scope).
|
|
115
|
+
*/
|
|
116
|
+
systemActor: ApprovalActor;
|
|
117
|
+
audit?: ApprovalAuditSink;
|
|
118
|
+
/** Fired for each record escalated. */
|
|
119
|
+
onEscalation?: (record: ApprovalRecord) => void;
|
|
120
|
+
/** Injectable clock (tests, deterministic SLA math). */
|
|
121
|
+
now?: () => Date;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Escalate every open request past its SLA deadline, ACROSS TENANTS.
|
|
125
|
+
* Idempotent: already escalated records are not re-escalated (their status
|
|
126
|
+
* left the guard set). Cron-owned TCB code — deliberately NOT a service
|
|
127
|
+
* method and NOT reachable over HTTP: an unfiltered cross-tenant read+write
|
|
128
|
+
* behind a role check was an IDOR-shaped hole (any CAN_SWEEP actor could
|
|
129
|
+
* escalate every tenant's queue). The distinct SystemApprovalStore parameter
|
|
130
|
+
* type makes "cross-tenant reads happen only inside the TCB" a compile-time
|
|
131
|
+
* property, not a convention.
|
|
132
|
+
*/
|
|
133
|
+
export declare function sweepSLA(store: SystemApprovalStore, options: SweepSLAOptions): Promise<ApprovalRecord[]>;
|
|
134
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/approval-api/service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAElB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAGlB,MAAM,YAAY,CAAC;AAEpB,sDAAsD;AACtD,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,2CAA2C;AAC3C,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,EAAE,EAAE,MAAM;CAIvB;AAED,iGAAiG;AACjG,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAC;gBAE3B,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc;CAKtE;AAED,+CAA+C;AAC/C,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,KAAK,EAAE,wBAAwB,CAAC;IAChC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,6DAA6D;IAC7D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CACV,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,gBAAgB,KACvB,OAA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