@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,126 @@
|
|
|
1
|
+
import { TENANT_BOUND } from './tenant-brand.js';
|
|
2
|
+
import { type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalStatus } from './types.js';
|
|
3
|
+
/** Uniqueness scope for open requests: one per (workflowId, runId, stepKey). */
|
|
4
|
+
export declare function stepKeyOf(stepPath: string[] | undefined): string;
|
|
5
|
+
export interface CreateResult {
|
|
6
|
+
record: ApprovalRecord;
|
|
7
|
+
/** false when an open request for the same (workflowId, runId, stepKey) already existed and was returned instead. */
|
|
8
|
+
created: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fields transition() may change. updatedAt is mandatory — every transition
|
|
12
|
+
* is a write and must say when.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApprovalPatch {
|
|
15
|
+
status?: ApprovalStatus;
|
|
16
|
+
claimedBy?: string;
|
|
17
|
+
decidedBy?: string;
|
|
18
|
+
decision?: ApprovalRecord['decision'];
|
|
19
|
+
comment?: string;
|
|
20
|
+
delegatedTo?: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
claimedAt?: string;
|
|
23
|
+
decidedAt?: string;
|
|
24
|
+
escalatedAt?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ApprovalStore {
|
|
27
|
+
/**
|
|
28
|
+
* Insert — unless an OPEN request (pending | claimed | escalated) already
|
|
29
|
+
* exists for the same (workflowId, runId, stepKey); then that record is
|
|
30
|
+
* returned with created: false (idempotent create, so the runner glue can
|
|
31
|
+
* fire on every suspend observation without duplicating queue entries).
|
|
32
|
+
* Decided requests never block a new one: a later re-suspension of the
|
|
33
|
+
* same step opens a fresh approval.
|
|
34
|
+
*/
|
|
35
|
+
create(record: ApprovalRecord): Promise<CreateResult>;
|
|
36
|
+
get(id: string): Promise<ApprovalRecord | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Ordered per filter.orderBy: oldest-first (createdAt, then id — FIFO
|
|
39
|
+
* queue order) by default, or the reviewer queue order (priority → SLA →
|
|
40
|
+
* FIFO, byReviewerOrder) under 'reviewer' — applied BEFORE filter.limit,
|
|
41
|
+
* so a bounded page is the top of the reviewer queue. Bounded by
|
|
42
|
+
* filter.limit/filter.after (D3: an unfiltered list() repeated on every
|
|
43
|
+
* dashboard poll is a full-table scan).
|
|
44
|
+
*/
|
|
45
|
+
list(filter?: ApprovalListFilter): Promise<ApprovalRecord[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Compare-and-swap: apply patch iff the current status is in `from`.
|
|
48
|
+
* Returns the updated record, or null when the guard fails (the status
|
|
49
|
+
* moved concurrently, or the id is unknown — callers disambiguate via
|
|
50
|
+
* get()).
|
|
51
|
+
*/
|
|
52
|
+
transition(id: string, from: readonly ApprovalStatus[], patch: ApprovalPatch): Promise<ApprovalRecord | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Aggregate queue metrics for this store's tenant — field semantics on
|
|
55
|
+
* ApprovalMetrics (types.ts), computed here instead of by the caller
|
|
56
|
+
* loading every record into JS (D3: metrics() used to do exactly that).
|
|
57
|
+
* `nowMs` is the SLA-breach reference instant (the service's injected
|
|
58
|
+
* clock), keeping the computation deterministic under tests.
|
|
59
|
+
*/
|
|
60
|
+
metrics(nowMs: number): Promise<ApprovalMetrics>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The filter predicate, shared by the tenant-bound store and the cron-only
|
|
64
|
+
* system view (tenant-store.ts). Internal to approval-api — deliberately not
|
|
65
|
+
* on the package barrel; the two views must never drift.
|
|
66
|
+
*/
|
|
67
|
+
export declare function matchesFilter(record: ApprovalRecord, filter: ApprovalListFilter): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* FIFO queue order (createdAt, then id) — shared by both store views.
|
|
70
|
+
* Bytewise via the shared compareStrings (NOT localeCompare): D1 orders with
|
|
71
|
+
* BINARY collation and the cursor row-value comparison in appendListFilters
|
|
72
|
+
* compares bytewise too, so a locale-collated in-memory sort would disagree
|
|
73
|
+
* with D1 on an id tie-break (mixed-case ids) and with its own cursor
|
|
74
|
+
* filter.
|
|
75
|
+
*/
|
|
76
|
+
export declare function byQueueOrder(a: ApprovalRecord, b: ApprovalRecord): number;
|
|
77
|
+
/**
|
|
78
|
+
* The comparator for a filter's effective orderBy — shared by both in-memory
|
|
79
|
+
* list() implementations, same no-drift rationale as matchesFilter. Also the
|
|
80
|
+
* chokepoint where the reviewer/after incoherence throws (approvalListOrder);
|
|
81
|
+
* D1's list() resolves through the same function when building its ORDER BY.
|
|
82
|
+
*/
|
|
83
|
+
export declare function approvalListComparator(filter: ApprovalListFilter): (a: ApprovalRecord, b: ApprovalRecord) => number;
|
|
84
|
+
/**
|
|
85
|
+
* Cursor + limit paging over an already status/workflow/run/claimedBy-
|
|
86
|
+
* filtered, orderBy-sorted record array — shared by both in-memory
|
|
87
|
+
* list() implementations (the tenant-bound store below and the system view
|
|
88
|
+
* in tenant-store.ts) so they can never drift, same rationale as
|
|
89
|
+
* matchesFilter/byQueueOrder. `after` only ever reaches this under the
|
|
90
|
+
* default FIFO order (approvalListOrder rejects it under 'reviewer' before
|
|
91
|
+
* any sort happens). D1's list() applies the equivalent conditions in SQL
|
|
92
|
+
* (appendListFilters' cursor clause + a LIMIT, d1-store.ts) instead of
|
|
93
|
+
* calling this.
|
|
94
|
+
*/
|
|
95
|
+
export declare function paginateApprovalList(records: readonly ApprovalRecord[], filter: Pick<ApprovalListFilter, 'after' | 'limit'>): ApprovalRecord[];
|
|
96
|
+
/**
|
|
97
|
+
* The in-memory metrics reduction — ALSO the reference "old JS computation"
|
|
98
|
+
* the D1 aggregate SQL (d1-store.ts's METRICS_QUERY) must match; see
|
|
99
|
+
* store.test.ts's cross-backend parity case. Field semantics: ApprovalMetrics
|
|
100
|
+
* (types.ts).
|
|
101
|
+
*/
|
|
102
|
+
export declare function computeApprovalMetrics(records: readonly ApprovalRecord[], nowMs: number): ApprovalMetrics;
|
|
103
|
+
/**
|
|
104
|
+
* In-memory reference implementation, BOUND to one tenant at construction
|
|
105
|
+
* (INV-2). Mirrors D1ApprovalStore semantics — both run the same contract
|
|
106
|
+
* test suite, including the cross-tenant cases over ONE shared backend (pass
|
|
107
|
+
* the same `records` Map to two instances; the InMemoryApprovalStoreFactory
|
|
108
|
+
* does exactly that). CAS atomicity holds because the check-and-mutate
|
|
109
|
+
* section is synchronous (no awaits inside).
|
|
110
|
+
*
|
|
111
|
+
* Every read/write carries the tenant predicate sourced from the constructor
|
|
112
|
+
* field — never from a parameter — and create() STAMPS the tenant, so no
|
|
113
|
+
* caller (and no spoofed input) can write another tenant's row.
|
|
114
|
+
*/
|
|
115
|
+
export declare class InMemoryApprovalStore implements ApprovalStore {
|
|
116
|
+
#private;
|
|
117
|
+
readonly tenantId: string;
|
|
118
|
+
readonly [TENANT_BOUND]: true;
|
|
119
|
+
constructor(tenantId: string, records?: Map<string, ApprovalRecord>);
|
|
120
|
+
create(record: ApprovalRecord): Promise<CreateResult>;
|
|
121
|
+
get(id: string): Promise<ApprovalRecord | null>;
|
|
122
|
+
list(filter?: ApprovalListFilter): Promise<ApprovalRecord[]>;
|
|
123
|
+
metrics(nowMs: number): Promise<ApprovalMetrics>;
|
|
124
|
+
transition(id: string, from: readonly ApprovalStatus[], patch: ApprovalPatch): Promise<ApprovalRecord | null>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/approval-api/store.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EAOpB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAEhE;AA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.
|
|
2
|
+
//
|
|
3
|
+
// Every state change goes through transition(), a compare-and-swap guarded by
|
|
4
|
+
// the record's CURRENT status: racing writers (two reviewers deciding, a
|
|
5
|
+
// sweep racing a claim) resolve to exactly one winner; losers get null and
|
|
6
|
+
// surface as HTTP 409. There is deliberately no unconditional update.
|
|
7
|
+
import { TENANT_ID_PATTERN } from '../do-runner/path-safe-id.js';
|
|
8
|
+
import { TENANT_BOUND } from './tenant-brand.js';
|
|
9
|
+
import { approvalListOrder, byReviewerOrder, clampApprovalLimit, compareStrings, OPEN_STATUSES, parseApprovalCursor, } from './types.js';
|
|
10
|
+
/** Uniqueness scope for open requests: one per (workflowId, runId, stepKey). */
|
|
11
|
+
export function stepKeyOf(stepPath) {
|
|
12
|
+
return stepPath?.join('.') ?? '';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The filter predicate, shared by the tenant-bound store and the cron-only
|
|
16
|
+
* system view (tenant-store.ts). Internal to approval-api — deliberately not
|
|
17
|
+
* on the package barrel; the two views must never drift.
|
|
18
|
+
*/
|
|
19
|
+
export function matchesFilter(record, filter) {
|
|
20
|
+
if (filter.status !== undefined) {
|
|
21
|
+
const statuses = Array.isArray(filter.status)
|
|
22
|
+
? filter.status
|
|
23
|
+
: [filter.status];
|
|
24
|
+
if (!statuses.includes(record.status))
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (filter.workflowId !== undefined &&
|
|
28
|
+
record.workflowId !== filter.workflowId)
|
|
29
|
+
return false;
|
|
30
|
+
if (filter.runId !== undefined && record.runId !== filter.runId)
|
|
31
|
+
return false;
|
|
32
|
+
if (filter.claimedBy !== undefined && record.claimedBy !== filter.claimedBy)
|
|
33
|
+
return false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* FIFO queue order (createdAt, then id) — shared by both store views.
|
|
38
|
+
* Bytewise via the shared compareStrings (NOT localeCompare): D1 orders with
|
|
39
|
+
* BINARY collation and the cursor row-value comparison in appendListFilters
|
|
40
|
+
* compares bytewise too, so a locale-collated in-memory sort would disagree
|
|
41
|
+
* with D1 on an id tie-break (mixed-case ids) and with its own cursor
|
|
42
|
+
* filter.
|
|
43
|
+
*/
|
|
44
|
+
export function byQueueOrder(a, b) {
|
|
45
|
+
return compareStrings(a.createdAt, b.createdAt) || compareStrings(a.id, b.id);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The comparator for a filter's effective orderBy — shared by both in-memory
|
|
49
|
+
* list() implementations, same no-drift rationale as matchesFilter. Also the
|
|
50
|
+
* chokepoint where the reviewer/after incoherence throws (approvalListOrder);
|
|
51
|
+
* D1's list() resolves through the same function when building its ORDER BY.
|
|
52
|
+
*/
|
|
53
|
+
export function approvalListComparator(filter) {
|
|
54
|
+
return approvalListOrder(filter) === 'reviewer'
|
|
55
|
+
? byReviewerOrder
|
|
56
|
+
: byQueueOrder;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Cursor + limit paging over an already status/workflow/run/claimedBy-
|
|
60
|
+
* filtered, orderBy-sorted record array — shared by both in-memory
|
|
61
|
+
* list() implementations (the tenant-bound store below and the system view
|
|
62
|
+
* in tenant-store.ts) so they can never drift, same rationale as
|
|
63
|
+
* matchesFilter/byQueueOrder. `after` only ever reaches this under the
|
|
64
|
+
* default FIFO order (approvalListOrder rejects it under 'reviewer' before
|
|
65
|
+
* any sort happens). D1's list() applies the equivalent conditions in SQL
|
|
66
|
+
* (appendListFilters' cursor clause + a LIMIT, d1-store.ts) instead of
|
|
67
|
+
* calling this.
|
|
68
|
+
*/
|
|
69
|
+
export function paginateApprovalList(records, filter) {
|
|
70
|
+
let page = records;
|
|
71
|
+
if (filter.after !== undefined) {
|
|
72
|
+
const cursor = parseApprovalCursor(filter.after);
|
|
73
|
+
page = page.filter((record) => record.createdAt > cursor.createdAt ||
|
|
74
|
+
(record.createdAt === cursor.createdAt && record.id > cursor.id));
|
|
75
|
+
}
|
|
76
|
+
const limit = clampApprovalLimit(filter.limit);
|
|
77
|
+
return limit !== undefined ? page.slice(0, limit) : [...page];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The in-memory metrics reduction — ALSO the reference "old JS computation"
|
|
81
|
+
* the D1 aggregate SQL (d1-store.ts's METRICS_QUERY) must match; see
|
|
82
|
+
* store.test.ts's cross-backend parity case. Field semantics: ApprovalMetrics
|
|
83
|
+
* (types.ts).
|
|
84
|
+
*/
|
|
85
|
+
export function computeApprovalMetrics(records, nowMs) {
|
|
86
|
+
const open = records.filter((record) => OPEN_STATUSES.includes(record.status));
|
|
87
|
+
const decided = records.filter((record) => record.status === 'approved' || record.status === 'rejected');
|
|
88
|
+
const resolutionsSeconds = decided
|
|
89
|
+
.filter((record) => record.decidedAt !== undefined)
|
|
90
|
+
.map((record) => (Date.parse(record.decidedAt) -
|
|
91
|
+
Date.parse(record.createdAt)) /
|
|
92
|
+
1000);
|
|
93
|
+
return {
|
|
94
|
+
openCount: open.length,
|
|
95
|
+
slaBreachedCount: open.filter((record) => record.slaDeadlineAt !== undefined &&
|
|
96
|
+
Date.parse(record.slaDeadlineAt) <= nowMs).length,
|
|
97
|
+
escalationCount: records.filter((record) => record.escalatedAt !== undefined).length,
|
|
98
|
+
decidedCount: decided.length,
|
|
99
|
+
approvedCount: decided.filter((record) => record.status === 'approved')
|
|
100
|
+
.length,
|
|
101
|
+
rejectedCount: decided.filter((record) => record.status === 'rejected')
|
|
102
|
+
.length,
|
|
103
|
+
avgResolutionSeconds: resolutionsSeconds.length > 0
|
|
104
|
+
? resolutionsSeconds.reduce((sum, value) => sum + value, 0) /
|
|
105
|
+
resolutionsSeconds.length
|
|
106
|
+
: null,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// Records carry caller-provided payloads; clone on every boundary so callers
|
|
110
|
+
// can never mutate stored state (or observe another caller's mutations).
|
|
111
|
+
function clone(record) {
|
|
112
|
+
return structuredClone(record);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* In-memory reference implementation, BOUND to one tenant at construction
|
|
116
|
+
* (INV-2). Mirrors D1ApprovalStore semantics — both run the same contract
|
|
117
|
+
* test suite, including the cross-tenant cases over ONE shared backend (pass
|
|
118
|
+
* the same `records` Map to two instances; the InMemoryApprovalStoreFactory
|
|
119
|
+
* does exactly that). CAS atomicity holds because the check-and-mutate
|
|
120
|
+
* section is synchronous (no awaits inside).
|
|
121
|
+
*
|
|
122
|
+
* Every read/write carries the tenant predicate sourced from the constructor
|
|
123
|
+
* field — never from a parameter — and create() STAMPS the tenant, so no
|
|
124
|
+
* caller (and no spoofed input) can write another tenant's row.
|
|
125
|
+
*/
|
|
126
|
+
export class InMemoryApprovalStore {
|
|
127
|
+
tenantId;
|
|
128
|
+
[TENANT_BOUND] = true;
|
|
129
|
+
#records;
|
|
130
|
+
constructor(tenantId, records) {
|
|
131
|
+
if (!TENANT_ID_PATTERN.test(tenantId)) {
|
|
132
|
+
throw new Error(`InMemoryApprovalStore: tenantId '${tenantId}' violates INV-3 (^[a-z0-9]{3,32}$)`);
|
|
133
|
+
}
|
|
134
|
+
this.tenantId = tenantId;
|
|
135
|
+
this.#records = records ?? new Map();
|
|
136
|
+
}
|
|
137
|
+
#owns(record) {
|
|
138
|
+
return record !== undefined && record.tenantId === this.tenantId;
|
|
139
|
+
}
|
|
140
|
+
async create(record) {
|
|
141
|
+
// Stamp, never trust: the bound store is the tenant authority.
|
|
142
|
+
const stamped = { ...record, tenantId: this.tenantId };
|
|
143
|
+
const key = stepKeyOf(stamped.stepPath);
|
|
144
|
+
for (const existing of this.#records.values()) {
|
|
145
|
+
if (existing.tenantId === this.tenantId &&
|
|
146
|
+
existing.workflowId === stamped.workflowId &&
|
|
147
|
+
existing.runId === stamped.runId &&
|
|
148
|
+
stepKeyOf(existing.stepPath) === key &&
|
|
149
|
+
OPEN_STATUSES.includes(existing.status)) {
|
|
150
|
+
return { record: clone(existing), created: false };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (this.#records.has(stamped.id)) {
|
|
154
|
+
throw new Error(`approval id '${stamped.id}' already exists`);
|
|
155
|
+
}
|
|
156
|
+
this.#records.set(stamped.id, clone(stamped));
|
|
157
|
+
return { record: clone(stamped), created: true };
|
|
158
|
+
}
|
|
159
|
+
async get(id) {
|
|
160
|
+
const record = this.#records.get(id);
|
|
161
|
+
return this.#owns(record) ? clone(record) : null;
|
|
162
|
+
}
|
|
163
|
+
async list(filter = {}) {
|
|
164
|
+
const matched = [...this.#records.values()]
|
|
165
|
+
.filter((record) => record.tenantId === this.tenantId && matchesFilter(record, filter))
|
|
166
|
+
.sort(approvalListComparator(filter));
|
|
167
|
+
return paginateApprovalList(matched, filter).map(clone);
|
|
168
|
+
}
|
|
169
|
+
async metrics(nowMs) {
|
|
170
|
+
const owned = [...this.#records.values()].filter((record) => record.tenantId === this.tenantId);
|
|
171
|
+
return computeApprovalMetrics(owned, nowMs);
|
|
172
|
+
}
|
|
173
|
+
async transition(id, from, patch) {
|
|
174
|
+
const current = this.#records.get(id);
|
|
175
|
+
// A wrong-tenant id behaves exactly like an unknown id (null -> 404/409
|
|
176
|
+
// disambiguation upstream) — no oracle for other tenants' record ids.
|
|
177
|
+
if (!this.#owns(current) || !from.includes(current.status))
|
|
178
|
+
return null;
|
|
179
|
+
const updated = { ...current };
|
|
180
|
+
for (const [field, value] of Object.entries(patch)) {
|
|
181
|
+
if (value !== undefined) {
|
|
182
|
+
updated[field] = value;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this.#records.set(id, updated);
|
|
186
|
+
return clone(updated);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/approval-api/store.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,2EAA2E;AAC3E,sEAAsE;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AAC;IAC1D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC9C,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAC9C,CAAC;QACF,OAAO,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,UAAU,CACd,EAAU,EACV,IAA+B,EAC/B,KAAoB;QAEpB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,wEAAwE;QACxE,sEAAsE;QACtE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC;QACxE,MAAM,OAAO,GAAmB,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACvB,OAA8C,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;YACjE,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ApprovalPatch, ApprovalStore } from './store.js';
|
|
2
|
+
import type { ApprovalListFilter, ApprovalRecord } from './types.js';
|
|
3
|
+
export declare const TENANT_BOUND: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* An ApprovalStore constructed bound to exactly one tenant: every
|
|
6
|
+
* SELECT/UPDATE/DELETE it issues carries `tenant_id = <ctor field>`. The only
|
|
7
|
+
* store type request-scoped code (ApprovalService, approvalGrantProvider) may
|
|
8
|
+
* touch.
|
|
9
|
+
*/
|
|
10
|
+
export type TenantBoundApprovalStore = ApprovalStore & {
|
|
11
|
+
readonly tenantId: string;
|
|
12
|
+
readonly [TENANT_BOUND]: true;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The cron-only cross-tenant view (SLA sweep). Deliberately NOT an
|
|
16
|
+
* ApprovalStore (no create/get) and NOT brandable (`[TENANT_BOUND]?: never`),
|
|
17
|
+
* so it is unassignable wherever a TenantBoundApprovalStore is required —
|
|
18
|
+
* "system stores never reach a request handler" is a compile error, not a
|
|
19
|
+
* convention.
|
|
20
|
+
*/
|
|
21
|
+
export interface SystemApprovalStore {
|
|
22
|
+
readonly [TENANT_BOUND]?: never;
|
|
23
|
+
list(filter?: ApprovalListFilter): Promise<ApprovalRecord[]>;
|
|
24
|
+
transition(id: string, from: readonly ApprovalRecord['status'][], patch: ApprovalPatch): Promise<ApprovalRecord | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Deletes TERMINAL (approved/rejected) records whose terminal timestamp —
|
|
27
|
+
* decidedAt, or updatedAt when a decided record was persisted without one
|
|
28
|
+
* — is strictly before cutoffIso, bounded to at most `limit` deletions.
|
|
29
|
+
* The retention-purge primitive behind purgeExpiredApprovals
|
|
30
|
+
* (retention.ts) — cron-only by type, exactly like list/transition: a
|
|
31
|
+
* tenant-bound store never gains this method.
|
|
32
|
+
*/
|
|
33
|
+
purgeExpired(cutoffIso: string, limit: number): Promise<number>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=tenant-brand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-brand.d.ts","sourceRoot":"","sources":["../../src/approval-api/tenant-brand.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAErE,eAAO,MAAM,YAAY,EAAE,OAAO,MAAuC,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAAG,aAAa,GAAG;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;CAC/B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,UAAU,CACR,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,SAAS,cAAc,CAAC,QAAQ,CAAC,EAAE,EACzC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAClC;;;;;;;OAOG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The tenant-binding brand (INV-2). TypeScript is structural: a plain
|
|
2
|
+
// `readonly tenantId: string` discriminator is satisfied by any object
|
|
3
|
+
// literal, and a #private field is nominal PER CLASS — which breaks here
|
|
4
|
+
// because two concrete stores (D1ApprovalStore, InMemoryApprovalStore) must
|
|
5
|
+
// both satisfy the bound type. A shared `unique symbol` property is satisfied
|
|
6
|
+
// by both classes and by nothing that does not deliberately import this
|
|
7
|
+
// symbol and stamp it.
|
|
8
|
+
//
|
|
9
|
+
// The symbol is exported because declaration emit (.d.ts) cannot reference a
|
|
10
|
+
// module-private name from an exported type. The residual risk is explicit
|
|
11
|
+
// and grep-visible: forging a bound store requires
|
|
12
|
+
// `import { TENANT_BOUND }` + `[TENANT_BOUND]: true` — a deliberate TCB
|
|
13
|
+
// bypass on par with an `as TenantBoundApprovalStore` cast, which no brand
|
|
14
|
+
// can prevent. What the brand DOES eliminate: accidental structural
|
|
15
|
+
// satisfaction, and the rushed fix that passes an unbound or system store
|
|
16
|
+
// into a request handler.
|
|
17
|
+
export const TENANT_BOUND = Symbol('flowsafe.tenantBound');
|
|
18
|
+
//# sourceMappingURL=tenant-brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-brand.js","sourceRoot":"","sources":["../../src/approval-api/tenant-brand.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,uEAAuE;AACvE,yEAAyE;AACzE,4EAA4E;AAC5E,8EAA8E;AAC9E,wEAAwE;AACxE,uBAAuB;AACvB,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,mDAAmD;AACnD,wEAAwE;AACxE,2EAA2E;AAC3E,oEAAoE;AACpE,0EAA0E;AAC1E,0BAA0B;AAK1B,MAAM,CAAC,MAAM,YAAY,GAAkB,MAAM,CAAC,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ApprovalActor } from './contract.js';
|
|
2
|
+
import type { ApprovalService } from './service.js';
|
|
3
|
+
import type { TenantBoundApprovalStore } from './tenant-brand.js';
|
|
4
|
+
export interface TenantContext {
|
|
5
|
+
/** Already authenticated; tenantId === actor.tenantId, INV-3-validated. */
|
|
6
|
+
readonly actor: ApprovalActor;
|
|
7
|
+
readonly tenantId: string;
|
|
8
|
+
/** The approval service over a store bound to THIS tenant. */
|
|
9
|
+
service(): ApprovalService;
|
|
10
|
+
/** Mint a tenant-salted runId: `${tenantId}_${uuid}` (INV-1). */
|
|
11
|
+
newRunId(): string;
|
|
12
|
+
/** Exact ownership: `runId.startsWith(`${tenantId}_`)` — see INV-3. */
|
|
13
|
+
ownsRun(runId: string): boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* undefined => no identity => 401. Throws TenantResolutionError when an
|
|
17
|
+
* AUTHENTICATED actor carries a tenant that fails INV-3 or names a reserved
|
|
18
|
+
* identity ('system') — either is a verifier or claim-mapping bug, surfaced
|
|
19
|
+
* as 403 by the routers, never concatenated into a runId ("undefined" is
|
|
20
|
+
* itself an INV-3-valid string, so an unvalidated `String(undefined)` would
|
|
21
|
+
* silently authorize a tenant literally named 'undefined').
|
|
22
|
+
*/
|
|
23
|
+
export type TenantResolver = (request: Request) => Promise<TenantContext | undefined>;
|
|
24
|
+
export declare class TenantResolutionError extends Error {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
export interface CreateTenantResolverOptions {
|
|
28
|
+
/** The host's authenticate seam (bearerActorAuthenticator over a verifier). */
|
|
29
|
+
authenticate: (request: Request) => Promise<ApprovalActor | undefined> | ApprovalActor | undefined;
|
|
30
|
+
/** Store factory (D1 or in-memory) — binds per request, DDL memoized once. */
|
|
31
|
+
storeFactory: {
|
|
32
|
+
forTenant(tenantId: string): TenantBoundApprovalStore;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Host-specific service assembly (resumeRun topology, audit sink, SLA
|
|
36
|
+
* defaults) over the request's bound store. Called lazily, at most once per
|
|
37
|
+
* request.
|
|
38
|
+
*/
|
|
39
|
+
buildService: (store: TenantBoundApprovalStore, actor: ApprovalActor) => ApprovalService;
|
|
40
|
+
/** The uuid half of minted runIds. Default: crypto.randomUUID. */
|
|
41
|
+
newRunId?: () => string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createTenantResolver(options: CreateTenantResolverOptions): TenantResolver;
|
|
44
|
+
//# sourceMappingURL=tenant-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-context.d.ts","sourceRoot":"","sources":["../../src/approval-api/tenant-context.ts"],"names":[],"mappings":"AAaA,OAAO,KAA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bound to the authenticated tenant, but a
|
|
3
|
+
// host's fetch() historically built its ApprovalService from `env` before
|
|
4
|
+
// anyone was authenticated, so "bind at construction from actor.tenantId" had
|
|
5
|
+
// no valid call site — the exact ordering hole a rushed fix plugs with an
|
|
6
|
+
// unauthenticated header. TenantResolver inverts the order: routers resolve
|
|
7
|
+
// the request FIRST (authenticate -> validate INV-3 -> bind), and everything
|
|
8
|
+
// downstream reads tenant.service() / tenant.newRunId() / tenant.ownsRun().
|
|
9
|
+
import { RESERVED_TENANT_IDS, TENANT_ID_PATTERN, } from '../do-runner/path-safe-id.js';
|
|
10
|
+
export class TenantResolutionError extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'TenantResolutionError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function createTenantResolver(options) {
|
|
17
|
+
const mintUuid = options.newRunId ?? (() => crypto.randomUUID());
|
|
18
|
+
return async (request) => {
|
|
19
|
+
const actor = await options.authenticate(request);
|
|
20
|
+
if (!actor)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (!TENANT_ID_PATTERN.test(actor.tenantId)) {
|
|
23
|
+
throw new TenantResolutionError(`authenticated actor '${actor.id}' carries a non-INV-3 tenantId — fix the verifier; refusing to scope the request`);
|
|
24
|
+
}
|
|
25
|
+
// Belt over the verifier seam: the built-in toApprovalActor already drops
|
|
26
|
+
// reserved identities, but a custom TokenVerifier or a hand-built actor
|
|
27
|
+
// map handed to staticTokenVerifier never crosses it. This resolver is
|
|
28
|
+
// the one chokepoint every routed request passes before a store binds or
|
|
29
|
+
// a runId mints, so the TCB's own audit identity is re-refused here
|
|
30
|
+
// whatever the verifier admitted. ('system' is INV-3-valid — the pattern
|
|
31
|
+
// check above cannot catch it.)
|
|
32
|
+
if (RESERVED_TENANT_IDS.includes(actor.tenantId)) {
|
|
33
|
+
throw new TenantResolutionError(`authenticated actor '${actor.id}' carries the reserved tenantId '${actor.tenantId}' (the TCB's own audit identity) — fix the verifier; refusing to scope the request`);
|
|
34
|
+
}
|
|
35
|
+
const tenantId = actor.tenantId;
|
|
36
|
+
let service;
|
|
37
|
+
return {
|
|
38
|
+
actor,
|
|
39
|
+
tenantId,
|
|
40
|
+
service: () => {
|
|
41
|
+
service ??= options.buildService(options.storeFactory.forTenant(tenantId), actor);
|
|
42
|
+
return service;
|
|
43
|
+
},
|
|
44
|
+
newRunId: () => `${tenantId}_${mintUuid()}`,
|
|
45
|
+
ownsRun: (runId) => runId.startsWith(`${tenantId}_`),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=tenant-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-context.js","sourceRoot":"","sources":["../../src/approval-api/tenant-context.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,0EAA0E;AAC1E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAE5E,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AA6BtC,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAsBD,MAAM,UAAU,oBAAoB,CAClC,OAAoC;IAEpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjE,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,qBAAqB,CAC7B,wBAAwB,KAAK,CAAC,EAAE,kFAAkF,CACnH,CAAC;QACJ,CAAC;QACD,0EAA0E;QAC1E,wEAAwE;QACxE,uEAAuE;QACvE,yEAAyE;QACzE,oEAAoE;QACpE,yEAAyE;QACzE,gCAAgC;QAChC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,qBAAqB,CAC7B,wBAAwB,KAAK,CAAC,EAAE,oCAAoC,KAAK,CAAC,QAAQ,oFAAoF,CACvK,CAAC;QACJ,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,OAAoC,CAAC;QACzC,OAAO;YACL,KAAK;YACL,QAAQ;YACR,OAAO,EAAE,GAAG,EAAE;gBACZ,OAAO,KAAK,OAAO,CAAC,YAAY,CAC9B,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,EACxC,KAAK,CACN,CAAC;gBACF,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,EAAE;YAC3C,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC;SAC7D,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ApprovalDatabase } from './d1-store.js';
|
|
2
|
+
import type { SystemApprovalStore, TenantBoundApprovalStore } from './tenant-brand.js';
|
|
3
|
+
export interface ApprovalStoreFactory {
|
|
4
|
+
/** Bind a store to one tenant. Throws unless tenantId satisfies INV-3. */
|
|
5
|
+
forTenant(tenantId: string): TenantBoundApprovalStore;
|
|
6
|
+
/** The cron-only cross-tenant view (SLA sweep). Never request-scoped. */
|
|
7
|
+
system(): SystemApprovalStore;
|
|
8
|
+
}
|
|
9
|
+
export declare class D1ApprovalStoreFactory implements ApprovalStoreFactory {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(db: ApprovalDatabase);
|
|
12
|
+
forTenant(tenantId: string): TenantBoundApprovalStore;
|
|
13
|
+
system(): SystemApprovalStore;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* In-memory factory over ONE shared Map. Not decoration: two independent
|
|
17
|
+
* `new InMemoryApprovalStore(...)` instances hold separate Maps, so a
|
|
18
|
+
* cross-tenant get/transition test against them passes trivially without
|
|
19
|
+
* exercising the tenant predicate — the exact "InMemory hides what D1 does"
|
|
20
|
+
* divergence the shared contract suite exists to close. Tenant A and tenant B
|
|
21
|
+
* views minted here share the backend, like two bound D1 stores share the
|
|
22
|
+
* table.
|
|
23
|
+
*/
|
|
24
|
+
export declare class InMemoryApprovalStoreFactory implements ApprovalStoreFactory {
|
|
25
|
+
#private;
|
|
26
|
+
forTenant(tenantId: string): TenantBoundApprovalStore;
|
|
27
|
+
/**
|
|
28
|
+
* Delete every record stamped with this tenant, returning the count — the
|
|
29
|
+
* in-memory mirror of the D1 `purgeTenant` approvals delete (in-memory hosts
|
|
30
|
+
* have no D1 for that function to run against). Factory-level like
|
|
31
|
+
* `system()`: offboarding is not a request-scoped capability.
|
|
32
|
+
*/
|
|
33
|
+
purgeTenant(tenantId: string): number;
|
|
34
|
+
system(): SystemApprovalStore;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=tenant-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/tenant-store.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,gBAAgB,EAItB,MAAM,eAAe,CAAC;AAQvB,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,CAAC;IACtD,yEAAyE;IACzE,MAAM,IAAI,mBAAmB,CAAC;CAC/B;AAUD,qBAAa,sBAAuB,YAAW,oBAAoB;;gBAIrD,EAAE,EAAE,gBAAgB;IAiBhC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB;IAKrD,MAAM,IAAI,mBAAmB;CAG9B;AAED;;;;;;;;GAQG;AACH,qBAAa,4BAA6B,YAAW,oBAAoB;;IAGvE,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB;IAKrD;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAYrC,MAAM,IAAI,mBAAmB;CAoD9B"}
|