@proofoftech/flowsafe 0.1.0 → 0.3.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 +60 -0
- package/README.md +22 -8
- package/dist/approval-api/contract.d.ts +52 -1
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/contract.js +12 -5
- package/dist/approval-api/contract.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +25 -4
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +28 -3
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +6 -6
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +4 -3
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js +1 -0
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +33 -1
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +56 -5
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +213 -45
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +5 -2
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +24 -2
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-brand.d.ts.map +1 -1
- package/dist/approval-api/tenant-brand.js +1 -0
- package/dist/approval-api/tenant-brand.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts +35 -2
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +22 -3
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/tenant-store.js +1 -0
- package/dist/approval-api/tenant-store.js.map +1 -1
- package/dist/approval-api/types.d.ts +56 -2
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +23 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +7 -1
- package/dist/approval-ui/App.d.ts.map +1 -1
- package/dist/approval-ui/App.js +19 -1
- package/dist/approval-ui/App.js.map +1 -1
- package/dist/approval-ui/DetailView.d.ts.map +1 -1
- package/dist/approval-ui/DetailView.js +1 -0
- package/dist/approval-ui/DetailView.js.map +1 -1
- package/dist/approval-ui/FilterBar.d.ts +43 -0
- package/dist/approval-ui/FilterBar.d.ts.map +1 -0
- package/dist/approval-ui/FilterBar.js +109 -0
- package/dist/approval-ui/FilterBar.js.map +1 -0
- package/dist/approval-ui/MetricsView.d.ts.map +1 -1
- package/dist/approval-ui/MetricsView.js.map +1 -1
- package/dist/approval-ui/QueueView.d.ts +8 -1
- package/dist/approval-ui/QueueView.d.ts.map +1 -1
- package/dist/approval-ui/QueueView.js +18 -1
- package/dist/approval-ui/QueueView.js.map +1 -1
- package/dist/approval-ui/client.d.ts +8 -1
- package/dist/approval-ui/client.d.ts.map +1 -1
- package/dist/approval-ui/client.js +19 -0
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/components.d.ts +36 -2
- package/dist/approval-ui/components.d.ts.map +1 -1
- package/dist/approval-ui/components.js +10 -0
- package/dist/approval-ui/components.js.map +1 -1
- package/dist/approval-ui/index.d.ts +5 -3
- package/dist/approval-ui/index.d.ts.map +1 -1
- package/dist/approval-ui/index.js +8 -2
- package/dist/approval-ui/index.js.map +1 -1
- package/dist/approval-ui/mount.d.ts.map +1 -1
- package/dist/approval-ui/mount.js +1 -0
- package/dist/approval-ui/mount.js.map +1 -1
- package/dist/approval-ui/tips.d.ts.map +1 -1
- package/dist/approval-ui/tips.js +1 -0
- package/dist/approval-ui/tips.js.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts +61 -3
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +85 -4
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/view-model.d.ts.map +1 -1
- package/dist/approval-ui/view-model.js +1 -0
- package/dist/approval-ui/view-model.js.map +1 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +1 -0
- package/dist/artifacts/index.js.map +1 -1
- package/dist/audit-export/index.d.ts.map +1 -1
- package/dist/audit-export/index.js +1 -0
- package/dist/audit-export/index.js.map +1 -1
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +1 -0
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js +1 -0
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +13 -4
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +40 -6
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +1 -0
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/index.d.ts +1 -0
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +4 -0
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +1 -0
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +28 -0
- package/dist/do-runner/memory-id.d.ts.map +1 -0
- package/dist/do-runner/memory-id.js +61 -0
- package/dist/do-runner/memory-id.js.map +1 -0
- package/dist/do-runner/path-safe-id.d.ts +31 -0
- package/dist/do-runner/path-safe-id.d.ts.map +1 -1
- package/dist/do-runner/path-safe-id.js +44 -0
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/resume-ledger.d.ts.map +1 -1
- package/dist/do-runner/resume-ledger.js +1 -0
- package/dist/do-runner/resume-ledger.js.map +1 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +1 -0
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +7 -1
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts.map +1 -1
- package/dist/host-kit/bearer-auth.js +1 -0
- package/dist/host-kit/bearer-auth.js.map +1 -1
- package/dist/host-kit/do-response.d.ts.map +1 -1
- package/dist/host-kit/do-response.js +1 -0
- package/dist/host-kit/do-response.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +1 -0
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +15 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +37 -0
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +106 -0
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -0
- package/dist/host-kit/flowsafe-worker.js +212 -0
- package/dist/host-kit/flowsafe-worker.js.map +1 -0
- package/dist/host-kit/host-approval-service.d.ts +22 -1
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +4 -0
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +3 -0
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +2 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/module.d.ts.map +1 -1
- package/dist/host-kit/module.js +1 -0
- package/dist/host-kit/module.js.map +1 -1
- package/dist/host-kit/registration.d.ts +1 -2
- package/dist/host-kit/registration.d.ts.map +1 -1
- package/dist/host-kit/registration.js +1 -0
- package/dist/host-kit/registration.js.map +1 -1
- package/dist/host-kit/run-route-error.d.ts.map +1 -1
- package/dist/host-kit/run-route-error.js +1 -0
- package/dist/host-kit/run-route-error.js.map +1 -1
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +14 -1
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/subdomain-check.d.ts.map +1 -1
- package/dist/host-kit/subdomain-check.js +1 -0
- package/dist/host-kit/subdomain-check.js.map +1 -1
- package/dist/host-kit/tenant-registry.d.ts.map +1 -1
- package/dist/host-kit/tenant-registry.js +1 -0
- package/dist/host-kit/tenant-registry.js.map +1 -1
- package/dist/host-kit/verifier.d.ts.map +1 -1
- package/dist/host-kit/verifier.js +1 -0
- package/dist/host-kit/verifier.js.map +1 -1
- package/dist/host-kit/workflow-meta.d.ts.map +1 -1
- package/dist/host-kit/workflow-meta.js +1 -0
- package/dist/host-kit/workflow-meta.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
2
|
// HTTP surface for the approval queue (flowsafe-architecture.md endpoint
|
|
2
3
|
// table). Plain fetch routing like the DO runner — no HTTP framework.
|
|
3
4
|
//
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
// from a request body.
|
|
15
16
|
import { ApprovalAuthzError, ApprovalConflictError, InvalidApprovalInputError, UnknownApprovalError, } from './service.js';
|
|
16
17
|
import { TenantResolutionError, } from './tenant-context.js';
|
|
17
|
-
import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVAL_LIST_LIMIT, parseApprovalCursor, } from './types.js';
|
|
18
|
+
import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVAL_LIST_LIMIT, parseApprovalCursor, parseApprovalTimeBound, } from './types.js';
|
|
18
19
|
/**
|
|
19
20
|
* Fields on CreateApprovalInput that select CAPABILITY or ATTRIBUTION, and so
|
|
20
21
|
* belong to the trusted computing base alone (security-threat-model.md, trust
|
|
@@ -120,6 +121,23 @@ function parseListFilter(url) {
|
|
|
120
121
|
const claimedBy = url.searchParams.get('claimedBy');
|
|
121
122
|
if (claimedBy !== null)
|
|
122
123
|
filter.claimedBy = claimedBy;
|
|
124
|
+
const requestedBy = url.searchParams.get('requestedBy');
|
|
125
|
+
if (requestedBy !== null)
|
|
126
|
+
filter.requestedBy = requestedBy;
|
|
127
|
+
// Eager 400 on unparseable time bounds (the cursor convention):
|
|
128
|
+
// parseApprovalTimeBound is the exact gate both stores re-apply.
|
|
129
|
+
for (const field of ['createdBefore', 'createdAfter']) {
|
|
130
|
+
const value = url.searchParams.get(field);
|
|
131
|
+
if (value === null)
|
|
132
|
+
continue;
|
|
133
|
+
try {
|
|
134
|
+
parseApprovalTimeBound(value, field);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
throw new InvalidApprovalInputError(error instanceof Error ? error.message : String(error));
|
|
138
|
+
}
|
|
139
|
+
filter[field] = value;
|
|
140
|
+
}
|
|
123
141
|
const limit = url.searchParams.get('limit');
|
|
124
142
|
if (limit !== null) {
|
|
125
143
|
const parsed = Number(limit);
|
|
@@ -219,6 +237,20 @@ export function createApprovalRouter(options) {
|
|
|
219
237
|
// unfiltered cross-tenant read+write; it lives in the cron-owned
|
|
220
238
|
// sweepSLA() function over a SystemApprovalStore, unreachable from
|
|
221
239
|
// request scope by type.
|
|
240
|
+
//
|
|
241
|
+
// Batch decide matches BEFORE the generic [id, action] arms — those
|
|
242
|
+
// would otherwise resolve this path as decide('batch') and 404.
|
|
243
|
+
// Record ids are server-minted UUIDs, so 'batch' can never collide
|
|
244
|
+
// with a real id. Always mounted: it is decide fan-out, not create.
|
|
245
|
+
if (segments.length === 2 &&
|
|
246
|
+
segments[0] === 'batch' &&
|
|
247
|
+
segments[1] === 'decide') {
|
|
248
|
+
const body = await readJsonObject(request);
|
|
249
|
+
return json(await service.decideBatch(body.ids, {
|
|
250
|
+
decision: body.decision,
|
|
251
|
+
comment: body.comment,
|
|
252
|
+
}, actor));
|
|
253
|
+
}
|
|
222
254
|
const [id, action] = segments;
|
|
223
255
|
if (segments.length === 2 && id && action === 'claim') {
|
|
224
256
|
return json(await service.claim(id, actor));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,uBAAuB;AAEvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,GAEtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAKjB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,uBAAuB;AAEvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,GAEtB,MA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
import type { ApprovalActor, ApprovalAuditSink, ApprovalNotificationSink, ApprovalRole } from './contract.js';
|
|
2
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';
|
|
3
|
+
import { type ApprovalDecision, type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalStatus, type BatchDecideResult, type CreateApprovalInput, type DecideResult } from './types.js';
|
|
4
4
|
/** Requester failed role authorization — HTTP 403. */
|
|
5
5
|
export declare class ApprovalAuthzError extends Error {
|
|
6
6
|
constructor(message: string);
|
|
@@ -18,6 +18,21 @@ export declare class ApprovalConflictError extends Error {
|
|
|
18
18
|
export declare class InvalidApprovalInputError extends Error {
|
|
19
19
|
constructor(message: string);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Separation-of-duties exemption. `false`/absent = SoD on (the requester can
|
|
23
|
+
* never decide their own request); `true` = every decider may self-decide;
|
|
24
|
+
* `{ roles }` = only actors whose role is listed (single-operator deployments
|
|
25
|
+
* set e.g. `{ roles: ['admin'] }`).
|
|
26
|
+
*/
|
|
27
|
+
export type SelfDecisionPolicy = boolean | {
|
|
28
|
+
roles: readonly ApprovalRole[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Whether an actor of `role` may decide their OWN request under `policy`. Total
|
|
32
|
+
* and pure — the run-router's catalog echo and the service's decide() gate
|
|
33
|
+
* share this ONE definition so the SPA hint and the server verdict can't drift.
|
|
34
|
+
*/
|
|
35
|
+
export declare function selfDecisionExempts(policy: SelfDecisionPolicy | undefined, role: ApprovalRole): boolean;
|
|
21
36
|
export interface ApprovalServiceOptions {
|
|
22
37
|
/**
|
|
23
38
|
* MUST be tenant-bound (INV-2): the service asserts every acting
|
|
@@ -32,6 +47,15 @@ export interface ApprovalServiceOptions {
|
|
|
32
47
|
* AuditLogger's own sink policy).
|
|
33
48
|
*/
|
|
34
49
|
audit?: ApprovalAuditSink;
|
|
50
|
+
/**
|
|
51
|
+
* Notification transport seam — fired once per record actually CREATED
|
|
52
|
+
* (`created: true`; the idempotent re-observation of an already-open step
|
|
53
|
+
* never re-notifies). Fire-and-forget: a throwing or rejecting sink is
|
|
54
|
+
* contained and recorded to the audit sink as `approval.notify`/'error',
|
|
55
|
+
* never failing the create. See ApprovalNotificationSink (contract.ts) for
|
|
56
|
+
* the ctx.waitUntil convention on Workers hosts.
|
|
57
|
+
*/
|
|
58
|
+
notify?: ApprovalNotificationSink;
|
|
35
59
|
/** Applied when CreateApprovalInput.slaSeconds is absent. */
|
|
36
60
|
defaultSlaSeconds?: number;
|
|
37
61
|
/**
|
|
@@ -42,10 +66,12 @@ export interface ApprovalServiceOptions {
|
|
|
42
66
|
resumeRun?: (record: ApprovalRecord, decision: ApprovalDecision) => Promise<unknown>;
|
|
43
67
|
/**
|
|
44
68
|
* Permit the requester to decide their own request. Off by default —
|
|
45
|
-
* separation of duties is the safe enterprise default
|
|
46
|
-
* single-operator
|
|
69
|
+
* separation of duties is the safe enterprise default. `true` exempts every
|
|
70
|
+
* decider; `{ roles }` exempts only those roles (a single-operator
|
|
71
|
+
* deployment sets e.g. `{ roles: ['admin'] }`). A permitted self-decision is
|
|
72
|
+
* audited with `detail.selfDecision: true`.
|
|
47
73
|
*/
|
|
48
|
-
allowSelfDecision?:
|
|
74
|
+
allowSelfDecision?: SelfDecisionPolicy;
|
|
49
75
|
/** Injectable clock (tests, deterministic SLA math). */
|
|
50
76
|
now?: () => Date;
|
|
51
77
|
}
|
|
@@ -63,6 +89,23 @@ export declare class ApprovalService {
|
|
|
63
89
|
decision: ApprovalDecision;
|
|
64
90
|
comment?: string;
|
|
65
91
|
}, actor: ApprovalActor): Promise<DecideResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Triage fan-out: apply ONE decision to up to MAX_APPROVAL_BATCH_DECIDE
|
|
94
|
+
* records, each through the EXISTING decide() — per-record CAS, SoD,
|
|
95
|
+
* audit, and resume semantics untouched; the one-decision-per-suspension
|
|
96
|
+
* model is not widened. Partial success is the contract: each record's
|
|
97
|
+
* outcome (or typed failure) is reported in the envelope, never as a
|
|
98
|
+
* thrown error. Only record-INDEPENDENT failures reject the whole batch:
|
|
99
|
+
* the caller's role, malformed ids, the cap, and a malformed decision.
|
|
100
|
+
*
|
|
101
|
+
* Sequential, not Promise.all — preserves audit ordering and avoids
|
|
102
|
+
* hammering the store's CAS with concurrent writes (D1/DO contention);
|
|
103
|
+
* a batch is a reviewer clicking once, not a throughput path.
|
|
104
|
+
*/
|
|
105
|
+
decideBatch(ids: readonly string[], input: {
|
|
106
|
+
decision: ApprovalDecision;
|
|
107
|
+
comment?: string;
|
|
108
|
+
}, actor: ApprovalActor): Promise<BatchDecideResult>;
|
|
66
109
|
/**
|
|
67
110
|
* D4 follow-up (2026-07-11 audit): CAS-transitions a STALE OPEN record
|
|
68
111
|
* (pending/claimed/escalated, bound to a suspension its step has since
|
|
@@ -117,6 +160,14 @@ export interface SweepSLAOptions {
|
|
|
117
160
|
audit?: ApprovalAuditSink;
|
|
118
161
|
/** Fired for each record escalated. */
|
|
119
162
|
onEscalation?: (record: ApprovalRecord) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Notification transport seam — fired once per escalated record, alongside
|
|
165
|
+
* (not instead of) onEscalation: onEscalation is the hosts' structured-log
|
|
166
|
+
* hook, notify is the reviewer-facing transport. Same containment as
|
|
167
|
+
* ApprovalServiceOptions.notify: failures audit as `approval.notify`/'error'
|
|
168
|
+
* and never abort the sweep.
|
|
169
|
+
*/
|
|
170
|
+
notify?: ApprovalNotificationSink;
|
|
120
171
|
/** Injectable clock (tests, deterministic SLA math). */
|
|
121
172
|
now?: () => Date;
|
|
122
173
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/approval-api/service.ts"],"names":[],"mappings":"
|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,CAAC;IA+C7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAuB3B,QAAQ,CACZ,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EACrB,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,cAAc,CAAC;IA6BpB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;CAiR9D;AA0CD,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,WAAW,EAAE,aAAa,CAAC;IAC3B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,uCAAuC;IACvC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,EAAE,CAAC,CAqG3B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
2
|
// ApprovalService — the queue's business rules: role authorization, CAS
|
|
2
3
|
// transitions, SLA escalation, audit emission, and the post-decision resume.
|
|
3
4
|
//
|
|
@@ -6,8 +7,9 @@
|
|
|
6
7
|
// of approval grants. decide() persists the decision; the grant provider
|
|
7
8
|
// (grants.ts) derives requestContext grants from approved records at
|
|
8
9
|
// start/resume. Nothing here ever reads capability data from client input.
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { tenantOwnsSaltedId } from '../do-runner/path-safe-id.js';
|
|
11
|
+
import { APPROVAL_ROLES, DECIDER_ROLES } from './contract.js';
|
|
12
|
+
import { APPROVAL_PRIORITIES, approvalCursor, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, } from './types.js';
|
|
11
13
|
/** Requester failed role authorization — HTTP 403. */
|
|
12
14
|
export class ApprovalAuthzError extends Error {
|
|
13
15
|
constructor(message) {
|
|
@@ -38,10 +40,24 @@ export class InvalidApprovalInputError extends Error {
|
|
|
38
40
|
this.name = 'InvalidApprovalInputError';
|
|
39
41
|
}
|
|
40
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Whether an actor of `role` may decide their OWN request under `policy`. Total
|
|
45
|
+
* and pure — the run-router's catalog echo and the service's decide() gate
|
|
46
|
+
* share this ONE definition so the SPA hint and the server verdict can't drift.
|
|
47
|
+
*/
|
|
48
|
+
export function selfDecisionExempts(policy, role) {
|
|
49
|
+
if (policy === true)
|
|
50
|
+
return true;
|
|
51
|
+
if (!policy)
|
|
52
|
+
return false;
|
|
53
|
+
return policy.roles.includes(role);
|
|
54
|
+
}
|
|
41
55
|
// Role policy from security-threat-model.md: reviewers decide, operators run
|
|
42
56
|
// the system, admins do both; every authenticated role may read. (The SLA
|
|
43
57
|
// sweep has no role: it is cron-owned TCB code — see sweepSLA below.)
|
|
44
|
-
|
|
58
|
+
// CAN_REVIEW IS the exported DECIDER_ROLES — one source, so the run-router's
|
|
59
|
+
// canSelfDecide echo and this gate can never disagree on who may decide.
|
|
60
|
+
const CAN_REVIEW = DECIDER_ROLES;
|
|
45
61
|
const CAN_CREATE = ['operator', 'builder', 'admin'];
|
|
46
62
|
function isNonEmptyString(value) {
|
|
47
63
|
return typeof value === 'string' && value.length > 0;
|
|
@@ -49,6 +65,7 @@ function isNonEmptyString(value) {
|
|
|
49
65
|
export class ApprovalService {
|
|
50
66
|
#store;
|
|
51
67
|
#audit;
|
|
68
|
+
#notify;
|
|
52
69
|
#defaultSlaSeconds;
|
|
53
70
|
#resumeRun;
|
|
54
71
|
#allowSelfDecision;
|
|
@@ -56,9 +73,10 @@ export class ApprovalService {
|
|
|
56
73
|
constructor(options) {
|
|
57
74
|
this.#store = options.store;
|
|
58
75
|
this.#audit = options.audit;
|
|
76
|
+
this.#notify = options.notify;
|
|
59
77
|
this.#defaultSlaSeconds = options.defaultSlaSeconds;
|
|
60
78
|
this.#resumeRun = options.resumeRun;
|
|
61
|
-
this.#allowSelfDecision = options.allowSelfDecision
|
|
79
|
+
this.#allowSelfDecision = options.allowSelfDecision;
|
|
62
80
|
this.#now = options.now ?? (() => new Date());
|
|
63
81
|
}
|
|
64
82
|
async create(input, actor) {
|
|
@@ -113,6 +131,12 @@ export class ApprovalService {
|
|
|
113
131
|
created: result.created,
|
|
114
132
|
},
|
|
115
133
|
});
|
|
134
|
+
// Only an actual insert notifies — the idempotent re-observation path
|
|
135
|
+
// (created: false) returns the EXISTING open record, which already
|
|
136
|
+
// notified when it entered the queue.
|
|
137
|
+
if (result.created) {
|
|
138
|
+
fireNotification(this.#notify, { type: 'created', record: result.record }, (reason) => this.#record(actor, 'approval.notify', `approval:${result.record.id}`, 'error', { reason, detail: { tenantId: result.record.tenantId } }));
|
|
139
|
+
}
|
|
116
140
|
return result;
|
|
117
141
|
}
|
|
118
142
|
async get(id, actor) {
|
|
@@ -145,13 +169,11 @@ export class ApprovalService {
|
|
|
145
169
|
}
|
|
146
170
|
async decide(id, input, actor) {
|
|
147
171
|
this.#authorize(actor, CAN_REVIEW, 'approval.decide', `approval:${id}`);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
if (!this.#allowSelfDecision) {
|
|
172
|
+
this.#assertDecisionInput(input);
|
|
173
|
+
// Role-scoped SoD: an exempt decider (allowSelfDecision: true, or a role
|
|
174
|
+
// named in { roles }) skips the pre-read entirely; everyone else keeps
|
|
175
|
+
// today's read-then-CAS self-request denial.
|
|
176
|
+
if (!selfDecisionExempts(this.#allowSelfDecision, actor.role)) {
|
|
155
177
|
const existing = await this.#store.get(id);
|
|
156
178
|
if (!existing)
|
|
157
179
|
throw new UnknownApprovalError(id);
|
|
@@ -181,16 +203,79 @@ export class ApprovalService {
|
|
|
181
203
|
from: OPEN_STATUSES,
|
|
182
204
|
patch,
|
|
183
205
|
});
|
|
206
|
+
// Annotate a PERMITTED self-decision from the post-transition record (no
|
|
207
|
+
// extra read): an exercised SoD exemption must leave an audit trail. Fires
|
|
208
|
+
// for both a global `true` and a role-scoped exemption.
|
|
209
|
+
const selfDecision = updated.requestedBy === actor.id;
|
|
184
210
|
this.#record(actor, 'approval.decide', `approval:${id}`, 'allowed', {
|
|
185
211
|
detail: {
|
|
186
212
|
decision: input.decision,
|
|
213
|
+
// Queue dwell time (created -> decided), in seconds. Feeds the
|
|
214
|
+
// generic durationSeconds histogram convention breakwater's
|
|
215
|
+
// metricsAuditSink observes — any emitter may adopt the field.
|
|
216
|
+
durationSeconds: (Date.parse(now) - Date.parse(updated.createdAt)) / 1000,
|
|
187
217
|
tenantId: updated.tenantId,
|
|
188
218
|
workflowId: updated.workflowId,
|
|
189
219
|
runId: updated.runId,
|
|
220
|
+
...(selfDecision ? { selfDecision: true } : {}),
|
|
190
221
|
},
|
|
191
222
|
});
|
|
192
223
|
return { record: updated, resume: await this.#resume(updated, actor) };
|
|
193
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Triage fan-out: apply ONE decision to up to MAX_APPROVAL_BATCH_DECIDE
|
|
227
|
+
* records, each through the EXISTING decide() — per-record CAS, SoD,
|
|
228
|
+
* audit, and resume semantics untouched; the one-decision-per-suspension
|
|
229
|
+
* model is not widened. Partial success is the contract: each record's
|
|
230
|
+
* outcome (or typed failure) is reported in the envelope, never as a
|
|
231
|
+
* thrown error. Only record-INDEPENDENT failures reject the whole batch:
|
|
232
|
+
* the caller's role, malformed ids, the cap, and a malformed decision.
|
|
233
|
+
*
|
|
234
|
+
* Sequential, not Promise.all — preserves audit ordering and avoids
|
|
235
|
+
* hammering the store's CAS with concurrent writes (D1/DO contention);
|
|
236
|
+
* a batch is a reviewer clicking once, not a throughput path.
|
|
237
|
+
*/
|
|
238
|
+
async decideBatch(ids, input, actor) {
|
|
239
|
+
this.#authorize(actor, CAN_REVIEW, 'approval.decide', 'approval');
|
|
240
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
241
|
+
throw new InvalidApprovalInputError('ids must be a non-empty array of approval ids');
|
|
242
|
+
}
|
|
243
|
+
if (!ids.every((id) => isNonEmptyString(id))) {
|
|
244
|
+
throw new InvalidApprovalInputError('every id must be a non-empty string');
|
|
245
|
+
}
|
|
246
|
+
// Order-preserving dedupe: deciding an id twice in one batch would
|
|
247
|
+
// guarantee a spurious per-record conflict for the duplicate.
|
|
248
|
+
const unique = [...new Set(ids)];
|
|
249
|
+
if (unique.length > MAX_APPROVAL_BATCH_DECIDE) {
|
|
250
|
+
throw new InvalidApprovalInputError(`a batch may decide at most ${MAX_APPROVAL_BATCH_DECIDE} approvals (got ${unique.length} unique ids)`);
|
|
251
|
+
}
|
|
252
|
+
// Same validation decide() applies — hoisted so a malformed decision is
|
|
253
|
+
// one 400, not N identical per-record failures.
|
|
254
|
+
this.#assertDecisionInput(input);
|
|
255
|
+
const results = [];
|
|
256
|
+
for (const id of unique) {
|
|
257
|
+
try {
|
|
258
|
+
const { record, resume } = await this.decide(id, input, actor);
|
|
259
|
+
results.push({ id, ok: true, record, resume });
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
results.push({
|
|
263
|
+
id,
|
|
264
|
+
ok: false,
|
|
265
|
+
error: errorMessage(error),
|
|
266
|
+
code: batchDecideErrorCode(error),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const decided = results.filter((item) => item.ok).length;
|
|
271
|
+
const failed = results.length - decided;
|
|
272
|
+
// Summary only — each decide() above already left its own per-record
|
|
273
|
+
// trail (allowed/denied), so this is the batch's one-line correlation.
|
|
274
|
+
this.#record(actor, 'approval.decide.batch', 'approval', 'allowed', {
|
|
275
|
+
detail: { requested: unique.length, decided, failed },
|
|
276
|
+
});
|
|
277
|
+
return { results, decided, failed };
|
|
278
|
+
}
|
|
194
279
|
/**
|
|
195
280
|
* D4 follow-up (2026-07-11 audit): CAS-transitions a STALE OPEN record
|
|
196
281
|
* (pending/claimed/escalated, bound to a suspension its step has since
|
|
@@ -364,7 +449,7 @@ export class ApprovalService {
|
|
|
364
449
|
if (!this.#audit)
|
|
365
450
|
return;
|
|
366
451
|
try {
|
|
367
|
-
this.#audit({
|
|
452
|
+
const outcome = this.#audit({
|
|
368
453
|
actor,
|
|
369
454
|
action,
|
|
370
455
|
resource,
|
|
@@ -372,12 +457,30 @@ export class ApprovalService {
|
|
|
372
457
|
reason: extra.reason,
|
|
373
458
|
detail: extra.detail,
|
|
374
459
|
});
|
|
460
|
+
// The sink may return a promise (a composed breakwater sink with an
|
|
461
|
+
// async member); a rejection must be contained here too or it becomes
|
|
462
|
+
// an unhandled rejection after the action already returned.
|
|
463
|
+
if (outcome instanceof Promise) {
|
|
464
|
+
outcome.catch(() => {
|
|
465
|
+
// Availability over export reliability — same policy as below.
|
|
466
|
+
});
|
|
467
|
+
}
|
|
375
468
|
}
|
|
376
469
|
catch {
|
|
377
470
|
// Availability over export reliability (AuditLogger's own policy): a
|
|
378
471
|
// crashing sink must not fail the approval action it records.
|
|
379
472
|
}
|
|
380
473
|
}
|
|
474
|
+
// Shared by decide() and decideBatch() — one home for the decision-shape
|
|
475
|
+
// rules, so the two surfaces can never drift on wording or strictness.
|
|
476
|
+
#assertDecisionInput(input) {
|
|
477
|
+
if (input.decision !== 'approve' && input.decision !== 'reject') {
|
|
478
|
+
throw new InvalidApprovalInputError("decision must be 'approve' or 'reject'");
|
|
479
|
+
}
|
|
480
|
+
if (input.comment !== undefined && typeof input.comment !== 'string') {
|
|
481
|
+
throw new InvalidApprovalInputError('comment must be a string');
|
|
482
|
+
}
|
|
483
|
+
}
|
|
381
484
|
#validateCreate(input) {
|
|
382
485
|
if (!isNonEmptyString(input.workflowId)) {
|
|
383
486
|
throw new InvalidApprovalInputError('workflowId is required');
|
|
@@ -389,7 +492,7 @@ export class ApprovalService {
|
|
|
389
492
|
// by parsing run_id), so a foreign-prefixed record would not leak — but it
|
|
390
493
|
// would be an orphan row no tenant's queue ever shows. Turn it into a
|
|
391
494
|
// loud error at the only write path.
|
|
392
|
-
if (!
|
|
495
|
+
if (!tenantOwnsSaltedId(this.#store.tenantId, input.runId)) {
|
|
393
496
|
throw new InvalidApprovalInputError(`runId '${input.runId}' does not carry this tenant's prefix '${this.#store.tenantId}_' — approvals bind to tenant-salted runs (INV-1)`);
|
|
394
497
|
}
|
|
395
498
|
if (!isNonEmptyString(input.title)) {
|
|
@@ -464,6 +567,40 @@ export class ApprovalService {
|
|
|
464
567
|
function errorMessage(error) {
|
|
465
568
|
return error instanceof Error ? error.message : String(error);
|
|
466
569
|
}
|
|
570
|
+
// Maps a per-record decide() failure to BatchDecideItem.code — the same
|
|
571
|
+
// classification errorResponse (router.ts) applies to thrown errors, kept as
|
|
572
|
+
// data because a batch envelope has one HTTP status for N outcomes.
|
|
573
|
+
function batchDecideErrorCode(error) {
|
|
574
|
+
if (error instanceof UnknownApprovalError)
|
|
575
|
+
return 'not-found';
|
|
576
|
+
if (error instanceof ApprovalConflictError)
|
|
577
|
+
return 'conflict';
|
|
578
|
+
if (error instanceof ApprovalAuthzError)
|
|
579
|
+
return 'forbidden';
|
|
580
|
+
if (error instanceof InvalidApprovalInputError)
|
|
581
|
+
return 'invalid';
|
|
582
|
+
return 'error';
|
|
583
|
+
}
|
|
584
|
+
// Containment for the notification seam (shared by create() and sweepSLA):
|
|
585
|
+
// the sink is fire-and-forget — a sync throw is caught here, an async
|
|
586
|
+
// rejection is caught on the returned promise — and either failure is
|
|
587
|
+
// reported through the AUDIT sink (as `approval.notify`/'error') so the
|
|
588
|
+
// evidence survives without the approval action ever failing. Deliberately
|
|
589
|
+
// not awaited: hosts that must keep a transport alive past the response wrap
|
|
590
|
+
// it in ctx.waitUntil themselves (see ApprovalNotificationSink).
|
|
591
|
+
function fireNotification(notify, event, reportError) {
|
|
592
|
+
if (!notify)
|
|
593
|
+
return;
|
|
594
|
+
try {
|
|
595
|
+
const outcome = notify(event);
|
|
596
|
+
if (outcome) {
|
|
597
|
+
outcome.catch((error) => reportError(`notification sink rejected: ${errorMessage(error)}`));
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
reportError(`notification sink threw: ${errorMessage(error)}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
467
604
|
/**
|
|
468
605
|
* Escalate every open request past its SLA deadline, ACROSS TENANTS.
|
|
469
606
|
* Idempotent: already escalated records are not re-escalated (their status
|
|
@@ -480,7 +617,7 @@ export async function sweepSLA(store, options) {
|
|
|
480
617
|
if (!options.audit)
|
|
481
618
|
return;
|
|
482
619
|
try {
|
|
483
|
-
options.audit({
|
|
620
|
+
const outcome = options.audit({
|
|
484
621
|
actor: options.systemActor,
|
|
485
622
|
action,
|
|
486
623
|
resource,
|
|
@@ -488,6 +625,13 @@ export async function sweepSLA(store, options) {
|
|
|
488
625
|
reason: extra.reason,
|
|
489
626
|
detail: extra.detail,
|
|
490
627
|
});
|
|
628
|
+
// Same promise containment as ApprovalService's #record: a composed
|
|
629
|
+
// sink's rejection must never surface as an unhandled rejection.
|
|
630
|
+
if (outcome instanceof Promise) {
|
|
631
|
+
outcome.catch(() => {
|
|
632
|
+
// Availability over export reliability — see below.
|
|
633
|
+
});
|
|
634
|
+
}
|
|
491
635
|
}
|
|
492
636
|
catch {
|
|
493
637
|
// Availability over export reliability — a crashing sink must not
|
|
@@ -496,41 +640,65 @@ export async function sweepSLA(store, options) {
|
|
|
496
640
|
};
|
|
497
641
|
const at = now();
|
|
498
642
|
const nowIso = at.toISOString();
|
|
499
|
-
const open = await store.list({ status: ['pending', 'claimed'] });
|
|
500
643
|
const escalated = [];
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
// emits unattributable audit events.
|
|
515
|
-
detail: {
|
|
516
|
-
tenantId: updated.tenantId,
|
|
517
|
-
workflowId: updated.workflowId,
|
|
518
|
-
runId: updated.runId,
|
|
519
|
-
},
|
|
644
|
+
// D3: page the cross-tenant open set with an explicit cursor instead of one
|
|
645
|
+
// unbounded SELECT (the system view is deliberately un-defaulted, so a bare
|
|
646
|
+
// list() here would be the whole table). Keyset paging is on (createdAt, id);
|
|
647
|
+
// escalating a record only drops it from the pending/claimed filter and never
|
|
648
|
+
// changes its cursor position, so every currently-open record is visited
|
|
649
|
+
// exactly once — no skips, no repeats — and every breach as of `at` still
|
|
650
|
+
// escalates regardless of where it sits in FIFO order.
|
|
651
|
+
let after;
|
|
652
|
+
for (;;) {
|
|
653
|
+
const page = await store.list({
|
|
654
|
+
status: ['pending', 'claimed'],
|
|
655
|
+
limit: MAX_APPROVAL_LIST_LIMIT,
|
|
656
|
+
after,
|
|
520
657
|
});
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
658
|
+
for (const candidate of page) {
|
|
659
|
+
if (candidate.slaDeadlineAt === undefined ||
|
|
660
|
+
Date.parse(candidate.slaDeadlineAt) > at.getTime()) {
|
|
661
|
+
continue;
|
|
524
662
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
663
|
+
const updated = await store.transition(candidate.id, ['pending', 'claimed'], { status: 'escalated', escalatedAt: nowIso, updatedAt: nowIso });
|
|
664
|
+
// null = lost a race (decided or escalated concurrently) — skip quietly.
|
|
665
|
+
if (!updated)
|
|
666
|
+
continue;
|
|
667
|
+
escalated.push(updated);
|
|
668
|
+
record('approval.escalate', `approval:${updated.id}`, 'allowed', {
|
|
669
|
+
reason: `SLA deadline ${updated.slaDeadlineAt} breached`,
|
|
670
|
+
// tenantId attributes the escalation: a cross-tenant sweep without it
|
|
671
|
+
// emits unattributable audit events.
|
|
672
|
+
detail: {
|
|
673
|
+
tenantId: updated.tenantId,
|
|
674
|
+
workflowId: updated.workflowId,
|
|
675
|
+
runId: updated.runId,
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
if (options.onEscalation) {
|
|
679
|
+
try {
|
|
680
|
+
options.onEscalation(updated);
|
|
681
|
+
}
|
|
682
|
+
catch (error) {
|
|
683
|
+
// The hook is notification-only; a crashing notifier must not
|
|
684
|
+
// abort the sweep. The audit trail keeps the evidence.
|
|
685
|
+
record('approval.escalate', `approval:${updated.id}`, 'error', {
|
|
686
|
+
reason: `onEscalation threw: ${errorMessage(error)}`,
|
|
687
|
+
detail: { tenantId: updated.tenantId },
|
|
688
|
+
});
|
|
689
|
+
}
|
|
532
690
|
}
|
|
533
|
-
|
|
691
|
+
fireNotification(options.notify, { type: 'escalated', record: updated }, (reason) => record('approval.notify', `approval:${updated.id}`, 'error', {
|
|
692
|
+
reason,
|
|
693
|
+
detail: { tenantId: updated.tenantId },
|
|
694
|
+
}));
|
|
695
|
+
}
|
|
696
|
+
// Full page ⇒ there may be more; cursor past the last row (FIFO order, so
|
|
697
|
+
// `after` is valid) and continue. Short page ⇒ done.
|
|
698
|
+
const last = page.at(-1);
|
|
699
|
+
if (page.length < MAX_APPROVAL_LIST_LIMIT || !last)
|
|
700
|
+
break;
|
|
701
|
+
after = approvalCursor(last);
|
|
534
702
|
}
|
|
535
703
|
return escalated;
|
|
536
704
|
}
|