@proofoftech/flowsafe 0.8.0 → 0.10.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 +44 -0
- package/README.md +8 -6
- package/dist/agent-host/approval-resumer.d.ts +7 -2
- package/dist/agent-host/approval-resumer.d.ts.map +1 -1
- package/dist/agent-host/approval-resumer.js +20 -10
- package/dist/agent-host/approval-resumer.js.map +1 -1
- package/dist/agent-host/catalog.d.ts.map +1 -1
- package/dist/agent-host/catalog.js +97 -1
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +3 -3
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js +1 -1
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +20 -1
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +87 -35
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/trusted-context.d.ts +0 -1
- package/dist/agent-host/trusted-context.d.ts.map +1 -1
- package/dist/agent-host/trusted-context.js +9 -11
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +38 -2
- package/dist/agent-host/types.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.d.ts +11 -3
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.js +10 -20
- package/dist/agent-runner/agent-run-state.js.map +1 -1
- package/dist/agent-runner/approval-shapes.d.ts +16 -4
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -1
- package/dist/agent-runner/approval-shapes.js +16 -6
- package/dist/agent-runner/approval-shapes.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +10 -9
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +12 -10
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/contract.d.ts +1 -1
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/contract.js +1 -1
- 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 +57 -20
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +5 -9
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +98 -55
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +5 -3
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +9 -2
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/principal.d.ts +214 -0
- package/dist/approval-api/principal.d.ts.map +1 -0
- package/dist/approval-api/principal.js +391 -0
- package/dist/approval-api/principal.js.map +1 -0
- package/dist/approval-api/router.d.ts +6 -4
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +7 -3
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +43 -2
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +185 -16
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +1 -1
- package/dist/approval-api/store.js +1 -1
- package/dist/approval-api/tenant-context.d.ts +7 -0
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +14 -3
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/types.d.ts +54 -3
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/do-runner/breakwater-keys.d.ts +4 -6
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +4 -6
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +3 -2
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/index.d.ts +1 -1
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +1 -1
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/mastra-registry.d.ts +7 -0
- package/dist/do-runner/mastra-registry.d.ts.map +1 -0
- package/dist/do-runner/mastra-registry.js +21 -0
- package/dist/do-runner/mastra-registry.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +10 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +57 -5
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +12 -1
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +30 -21
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/thread-header.d.ts +17 -4
- package/dist/do-runner/thread-header.d.ts.map +1 -1
- package/dist/do-runner/thread-header.js +17 -4
- package/dist/do-runner/thread-header.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +12 -7
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +79 -25
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +2 -2
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +10 -5
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +1 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +1 -1
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +1 -6
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +29 -5
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +1 -1
- package/dist/signal-providers/delivery.d.ts.map +1 -1
- package/dist/signal-providers/delivery.js +9 -3
- package/dist/signal-providers/delivery.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +9 -3
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +10 -10
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +3 -3
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// requestContext the resumed leg executes under is minted server-side by
|
|
7
7
|
// approvalGrantProvider on EVERY start/resume.
|
|
8
8
|
//
|
|
9
|
-
// Grants are SUSPENSION-SCOPED: a step-keyed approval unlocks
|
|
10
|
-
// only for the leg that resumes THAT step, and only when the decision binds
|
|
9
|
+
// Grants are STRUCTURED and SUSPENSION-SCOPED: a step-keyed approval unlocks
|
|
10
|
+
// its connectors only for the leg that resumes THAT step, and only when the decision binds
|
|
11
11
|
// to the step's CURRENT suspension. The preferred binding is clock-free and
|
|
12
12
|
// exact on the (suspendedAt, resumeCount) fingerprint: the creating bridge
|
|
13
13
|
// captures both into the record (CreateApprovalInput), and minting requires
|
|
@@ -36,10 +36,8 @@
|
|
|
36
36
|
// distinguishes them. A reset ledger only yields leg.resumeCount=undefined
|
|
37
37
|
// against a re-suspension record's defined count → deny (fail-closed re-deny),
|
|
38
38
|
// then a fresh decision mints.
|
|
39
|
-
// Records created
|
|
40
|
-
//
|
|
41
|
-
// core-clock suspendedAt — correct only where the two clocks are one
|
|
42
|
-
// (single-Worker/Cloudflare deployments; see the threat model, boundary 6).
|
|
39
|
+
// Records created without observing the suspension are legacy capability
|
|
40
|
+
// records and mint nothing.
|
|
43
41
|
//
|
|
44
42
|
// Run-scoped standing grants are EXPLICIT: a step-less record mints on every
|
|
45
43
|
// leg only when it also carries runScoped === true. A step-less record without
|
|
@@ -50,25 +48,23 @@
|
|
|
50
48
|
// is settable over HTTP (router.ts, TCB_ONLY_CREATE_FIELDS);
|
|
51
49
|
// suspend-observation bridges always set stepPath and never runScoped.
|
|
52
50
|
//
|
|
53
|
-
// The provider always returns the grant key — an empty list when
|
|
54
|
-
// applies — because Mastra merges provided context over the persisted
|
|
51
|
+
// The provider always returns the structured grant key — an empty list when
|
|
52
|
+
// nothing applies — because Mastra merges provided context over the persisted
|
|
55
53
|
// snapshot: overwriting each leg retires the previous leg's grants instead
|
|
56
54
|
// of letting them leak forward. A resume that bypasses decide() (or targets
|
|
57
55
|
// a suspension nothing was decided for) therefore finds no grant — fail
|
|
58
56
|
// closed.
|
|
59
57
|
import { tenantOfRunId } from '../do-runner/path-safe-id.js';
|
|
60
|
-
import {
|
|
58
|
+
import { BREAKWATER_CONNECTOR_GRANTS_KEY } from './contract.js';
|
|
61
59
|
import { listAllApprovedForRun, stepKeyOf, } from './store.js';
|
|
62
60
|
// Whether a step-keyed approval is bound to the resumed step's CURRENT
|
|
63
|
-
// suspension
|
|
64
|
-
// decidedAt-after fallback) — the predicate that decides whether a decision
|
|
65
|
-
// mints.
|
|
61
|
+
// suspension. Legacy records without a captured suspendedAt fail closed.
|
|
66
62
|
function boundToCurrentSuspension(record, suspendedAt, resumeCount) {
|
|
67
63
|
// Unknown suspension time (snapshot without step timestamps, or an
|
|
68
64
|
// unresolvable resume target) — fail closed for step-keyed grants.
|
|
69
65
|
if (suspendedAt === undefined)
|
|
70
66
|
return false;
|
|
71
|
-
//
|
|
67
|
+
// Clock-free binding on the (suspendedAt, resumeCount)
|
|
72
68
|
// fingerprint. suspendedAt comes from the core clock; resumeCount is the
|
|
73
69
|
// runtime's monotonic per-(run,step) resume ordinal (undefined on a first
|
|
74
70
|
// suspension, 1,2,… on re-suspensions), captured by the bridge at create
|
|
@@ -78,36 +74,19 @@ function boundToCurrentSuspension(record, suspendedAt, resumeCount) {
|
|
|
78
74
|
// approval (resumeCount undefined) can never mint into a re-suspension leg
|
|
79
75
|
// (resumeCount defined) even when their suspendedAt collide within one ms,
|
|
80
76
|
// and successive re-suspensions carry strictly increasing counts that never
|
|
81
|
-
// collide. A
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
// Legacy fallback for records created without observing the suspension
|
|
89
|
-
// (pre-capture bridges): service-clock decidedAt strictly after the core-
|
|
90
|
-
// clock suspendedAt — correct on same-clock (single-Worker/Cloudflare)
|
|
91
|
-
// topologies only; see security-threat-model.md boundary 6.
|
|
92
|
-
//
|
|
93
|
-
// TRANSITIONAL and self-draining — it fires only while pre-capture rows
|
|
94
|
-
// remain undecided, and no client can force it (`suspendedAt` is in
|
|
95
|
-
// TCB_ONLY_CREATE_FIELDS). INVARIANT for writers: every NEW step-keyed
|
|
96
|
-
// record MUST capture `suspendedAt` (host-kit's bridge does); creating one
|
|
97
|
-
// without it would re-open the clock-dependence this exact-match binding
|
|
98
|
-
// exists to close.
|
|
99
|
-
return (record.decidedAt !== undefined && Date.parse(record.decidedAt) > suspendedAt);
|
|
77
|
+
// collide. A first-suspension record has no resumeCount and only matches a
|
|
78
|
+
// first-suspension leg (`undefined === undefined`); it fails closed on every
|
|
79
|
+
// re-suspension leg, which always carries a positive count.
|
|
80
|
+
return (record.suspendedAt !== undefined &&
|
|
81
|
+
record.suspendedAt === suspendedAt &&
|
|
82
|
+
record.resumeCount === resumeCount);
|
|
100
83
|
}
|
|
101
84
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* legacy decidedAt-after fallback for records created without the capture),
|
|
106
|
-
* plus step-less records that explicitly opted in with `runScoped: true`.
|
|
107
|
-
* Start legs and unresolvable resume targets mint run-scoped records only. A
|
|
108
|
-
* step-less record without `runScoped` is inert on every leg — fail closed.
|
|
85
|
+
* Structured grants across approved records that apply to this leg. Every
|
|
86
|
+
* capability-bearing record must carry an explicit persisted grantScope;
|
|
87
|
+
* legacy or malformed records make the whole derivation empty.
|
|
109
88
|
*/
|
|
110
|
-
export async function
|
|
89
|
+
export async function connectorGrantsForLeg(store, workflowId, runId, leg) {
|
|
111
90
|
// Retrieve ALL approved records for the run via the shared complete-reader —
|
|
112
91
|
// its docstring carries the load-bearing workflowId/runId-predicate and
|
|
113
92
|
// fail-closed paging rationale grants.test.ts pins with a spy store. Grant
|
|
@@ -120,21 +99,85 @@ export async function approvedConnectorsForLeg(store, workflowId, runId, leg) {
|
|
|
120
99
|
: undefined;
|
|
121
100
|
const suspendedAt = leg.kind === 'resume' ? leg.suspendedAt : undefined;
|
|
122
101
|
const resumeCount = leg.kind === 'resume' ? leg.resumeCount : undefined;
|
|
123
|
-
const
|
|
102
|
+
const grants = [];
|
|
124
103
|
for (const record of approved) {
|
|
125
104
|
const recordKey = stepKeyOf(record.stepPath);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
105
|
+
if (record.connectors.length === 0)
|
|
106
|
+
continue;
|
|
107
|
+
if (record.workflowId !== workflowId ||
|
|
108
|
+
record.runId !== runId ||
|
|
109
|
+
!record.connectors.every((connector) => typeof connector === 'string' && connector.length > 0)) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
if (record.grantScope === 'run') {
|
|
113
|
+
if (record.runScoped !== true ||
|
|
114
|
+
recordKey !== '' ||
|
|
115
|
+
record.suspendedAt !== undefined ||
|
|
116
|
+
record.resumeCount !== undefined ||
|
|
117
|
+
record.toolCallId !== undefined) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
for (const connectorId of record.connectors) {
|
|
121
|
+
grants.push({
|
|
122
|
+
scope: 'run',
|
|
123
|
+
connectorId,
|
|
124
|
+
workflowId,
|
|
125
|
+
runId,
|
|
126
|
+
isolationScope: record.tenantId,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if ((record.grantScope !== 'suspension' &&
|
|
132
|
+
record.grantScope !== 'tool-call') ||
|
|
133
|
+
record.runScoped === true ||
|
|
134
|
+
recordKey === '') {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
if (record.stepPath === undefined ||
|
|
138
|
+
record.suspendedAt === undefined ||
|
|
139
|
+
(record.grantScope === 'tool-call'
|
|
140
|
+
? record.connectors.length !== 1 ||
|
|
141
|
+
typeof record.toolCallId !== 'string' ||
|
|
142
|
+
record.toolCallId.length === 0
|
|
143
|
+
: record.toolCallId !== undefined)) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
if (targetKey === undefined ||
|
|
147
|
+
recordKey !== targetKey ||
|
|
148
|
+
!boundToCurrentSuspension(record, suspendedAt, resumeCount)) {
|
|
132
149
|
continue;
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
}
|
|
151
|
+
const suspension = {
|
|
152
|
+
stepPath: [...record.stepPath],
|
|
153
|
+
suspendedAt: record.suspendedAt,
|
|
154
|
+
...(record.resumeCount === undefined
|
|
155
|
+
? {}
|
|
156
|
+
: { resumeCount: record.resumeCount }),
|
|
157
|
+
};
|
|
158
|
+
for (const connectorId of record.connectors) {
|
|
159
|
+
grants.push(record.grantScope === 'tool-call'
|
|
160
|
+
? {
|
|
161
|
+
scope: 'tool-call',
|
|
162
|
+
connectorId,
|
|
163
|
+
workflowId,
|
|
164
|
+
runId,
|
|
165
|
+
isolationScope: record.tenantId,
|
|
166
|
+
suspension,
|
|
167
|
+
toolCallId: record.toolCallId,
|
|
168
|
+
}
|
|
169
|
+
: {
|
|
170
|
+
scope: 'suspension',
|
|
171
|
+
connectorId,
|
|
172
|
+
workflowId,
|
|
173
|
+
runId,
|
|
174
|
+
isolationScope: record.tenantId,
|
|
175
|
+
suspension,
|
|
176
|
+
});
|
|
135
177
|
}
|
|
136
178
|
}
|
|
137
|
-
|
|
179
|
+
const unique = new Map(grants.map((grant) => [JSON.stringify(grant), grant]));
|
|
180
|
+
return [...unique.values()];
|
|
138
181
|
}
|
|
139
182
|
/**
|
|
140
183
|
* RequestContextProvider wiring the approval store into the DO runner:
|
|
@@ -148,10 +191,10 @@ export async function approvedConnectorsForLeg(store, workflowId, runId, leg) {
|
|
|
148
191
|
*/
|
|
149
192
|
export function approvalGrantProvider(store) {
|
|
150
193
|
return async (workflowId, runId, leg) => {
|
|
151
|
-
const
|
|
194
|
+
const grants = await connectorGrantsForLeg(store, workflowId, runId, leg);
|
|
152
195
|
// Always return the key (even empty) — see the header: overwrite, don't
|
|
153
196
|
// inherit, so stale grants from earlier legs cannot survive the merge.
|
|
154
|
-
return { [
|
|
197
|
+
return { [BREAKWATER_CONNECTOR_GRANTS_KEY]: grants };
|
|
155
198
|
};
|
|
156
199
|
}
|
|
157
200
|
/**
|
|
@@ -166,10 +209,10 @@ export function approvalGrantProviderFromFactory(factory) {
|
|
|
166
209
|
return async (workflowId, runId, leg) => {
|
|
167
210
|
const tenantId = tenantOfRunId(runId);
|
|
168
211
|
if (tenantId === undefined) {
|
|
169
|
-
return { [
|
|
212
|
+
return { [BREAKWATER_CONNECTOR_GRANTS_KEY]: [] };
|
|
170
213
|
}
|
|
171
|
-
const
|
|
172
|
-
return { [
|
|
214
|
+
const grants = await connectorGrantsForLeg(factory.forTenant(tenantId), workflowId, runId, leg);
|
|
215
|
+
return { [BREAKWATER_CONNECTOR_GRANTS_KEY]: grants };
|
|
173
216
|
};
|
|
174
217
|
}
|
|
175
218
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.js","sourceRoot":"","sources":["../../src/approval-api/grants.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kEAAkE;AAClE,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,yEAAyE;AACzE,+CAA+C;AAC/C,EAAE;AACF,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"gr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,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACtE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAsB,EACtB,UAKI,EAAE;IAEN,MAAM,eAAe,GAAG,OAAO,CAAC,UAAU,IAAI,iBAAiB,CAAC;IAChE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE;QAC9C,IAAI,EAAE,MAAM,CAAC,QAAQ;QACrB,UAAU,EAAE,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC;KAC9C,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type { ApprovalActor, ApprovalAuditEvent, ApprovalAuditSink, ApprovalNotificationEvent, ApprovalNotificationSink, ApprovalRole, ApprovalStreamEvent, ApprovalStreamSink, } from './contract.js';
|
|
2
|
-
export { APPROVAL_ROLES, BREAKWATER_ACTOR_KEY,
|
|
2
|
+
export { APPROVAL_ROLES, BREAKWATER_ACTOR_KEY, BREAKWATER_CONNECTOR_EXECUTION_KEY, BREAKWATER_CONNECTOR_GRANTS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, DECIDER_ROLES, RUN_START_ROLES, } from './contract.js';
|
|
3
3
|
export type { ApprovalDatabase, ApprovalPreparedStatement, } from './d1-store.js';
|
|
4
|
-
export { approvalGrantProvider, approvalGrantProviderFromFactory,
|
|
4
|
+
export { approvalGrantProvider, approvalGrantProviderFromFactory, connectorGrantsForLeg, defaultResumeData, resumeViaRuntime, } from './grants.js';
|
|
5
|
+
export type { AutomatedExecutionPrincipal, AutomatedPrincipalKind, ExecutionPrincipal, ExecutionPrincipalKind, TrustedAutomationPrincipal, } from './principal.js';
|
|
6
|
+
export { AUTOMATED_PRINCIPAL_KINDS, AUTOMATED_PROJECTED_ROLE, assertExecutionPrincipal, breakwaterActorFor, decodeExecutionPrincipal, EXECUTION_PRINCIPAL_KINDS, encodeExecutionPrincipal, humanPrincipal, isExecutionPrincipal, principalActor, principalAuditFields, samePrincipal, trustAutomationPrincipal, } from './principal.js';
|
|
5
7
|
export type { PurgeExpiredApprovalsOptions } from './retention.js';
|
|
6
8
|
export { purgeExpiredApprovals } from './retention.js';
|
|
7
9
|
export type { ApprovalRouter, ApprovalRouterOptions } from './router.js';
|
|
@@ -16,6 +18,6 @@ export type { CreateTenantResolverOptions, TenantContext, TenantResolver, } from
|
|
|
16
18
|
export { createTenantResolver, TenantResolutionError, } from './tenant-context.js';
|
|
17
19
|
export type { ApprovalStoreFactory } from './tenant-store.js';
|
|
18
20
|
export { D1ApprovalStoreFactory, InMemoryApprovalStoreFactory, } from './tenant-store.js';
|
|
19
|
-
export type { ApprovalCursor, ApprovalDecision, ApprovalListFilter, ApprovalListOrder, ApprovalMetrics, ApprovalPriority, ApprovalRecord, ApprovalResumeTarget, ApprovalStatus, BatchDecideItem, BatchDecideResult, CreateApprovalInput, DecideResult, ResumeOutcome, } from './types.js';
|
|
21
|
+
export type { ApprovalCursor, ApprovalDecision, ApprovalGrantScope, ApprovalListFilter, ApprovalListOrder, ApprovalMetrics, ApprovalPriority, ApprovalRecord, ApprovalResumeTarget, ApprovalStatus, BatchDecideItem, BatchDecideResult, ConnectorApprovalGrant, ConnectorApprovalGrantBase, ConnectorApprovalSuspension, CreateApprovalInput, DecideResult, ResumeOutcome, } from './types.js';
|
|
20
22
|
export { APPROVAL_LIST_ORDERS, APPROVAL_PRIORITIES, APPROVAL_STATUSES, approvalCursor, approvalListOrder, byReviewerOrder, MAX_APPROVAL_BATCH_DECIDE, MAX_APPROVAL_LIST_LIMIT, OPEN_STATUSES, parseApprovalCursor, TERMINAL_APPROVAL_STATUSES, } from './types.js';
|
|
21
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/approval-api/index.ts"],"names":[],"mappings":"AASA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,EAC7B,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAIvB,YAAY,EACV,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/approval-api/index.ts"],"names":[],"mappings":"AASA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kCAAkC,EAClC,+BAA+B,EAC/B,6BAA6B,EAC7B,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAIvB,YAAY,EACV,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,aAAa,EAMb,wBAAw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B,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,YAAY,CAAC"}
|
|
@@ -6,8 +6,15 @@
|
|
|
6
6
|
// start/resume (grants.ts). Plugs into the DO runner via
|
|
7
7
|
// requestContextForRun + resumeViaRuntime; persistence is D1 (or the
|
|
8
8
|
// in-memory store for tests/dev).
|
|
9
|
-
export { APPROVAL_ROLES, BREAKWATER_ACTOR_KEY,
|
|
10
|
-
export { approvalGrantProvider, approvalGrantProviderFromFactory,
|
|
9
|
+
export { APPROVAL_ROLES, BREAKWATER_ACTOR_KEY, BREAKWATER_CONNECTOR_EXECUTION_KEY, BREAKWATER_CONNECTOR_GRANTS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, DECIDER_ROLES, RUN_START_ROLES, } from './contract.js';
|
|
10
|
+
export { approvalGrantProvider, approvalGrantProviderFromFactory, connectorGrantsForLeg, defaultResumeData, resumeViaRuntime, } from './grants.js';
|
|
11
|
+
export { AUTOMATED_PRINCIPAL_KINDS, AUTOMATED_PROJECTED_ROLE, assertExecutionPrincipal, breakwaterActorFor, decodeExecutionPrincipal, EXECUTION_PRINCIPAL_KINDS, encodeExecutionPrincipal, humanPrincipal, isExecutionPrincipal, principalActor, principalAuditFields, samePrincipal,
|
|
12
|
+
// TRUSTED_AUTOMATION is deliberately NOT re-exported: `trustAutomationPrincipal`
|
|
13
|
+
// is the sanctioned constructor and covers every legitimate case, so naming the
|
|
14
|
+
// raw symbol here would only widen the public surface with plumbing. This is
|
|
15
|
+
// API hygiene, not a capability boundary — the brand stays recoverable by
|
|
16
|
+
// reflection from any vouched principal, and the threat model says so.
|
|
17
|
+
trustAutomationPrincipal, } from './principal.js';
|
|
11
18
|
export { purgeExpiredApprovals } from './retention.js';
|
|
12
19
|
export { CLIENT_CREATE_FIELDS, createApprovalRouter, TCB_ONLY_CREATE_FIELDS, } from './router.js';
|
|
13
20
|
export { ApprovalAuthzError, ApprovalConflictError, ApprovalService, InvalidApprovalInputError, selfDecisionExempts, sweepSLA, UnknownApprovalError, } from './service.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/approval-api/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,qEAAqE;AACrE,yDAAyD;AACzD,qEAAqE;AACrE,kCAAkC;AAYlC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,EAC7B,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAQvB,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/approval-api/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,qEAAqE;AACrE,yDAAyD;AACzD,qEAAqE;AACrE,kCAAkC;AAYlC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kCAAkC,EAClC,+BAA+B,EAC/B,6BAA6B,EAC7B,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAQvB,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAQrB,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,aAAa;AACb,iFAAiF;AACjF,gFAAgF;AAChF,6EAA6E;AAC7E,0EAA0E;AAC1E,uEAAuE;AACvE,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMjD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAqB3B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { type ApprovalActor, type ApprovalRole } from './contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Mirrors breakwater's `PrincipalKind` by value, for the same reason
|
|
4
|
+
* contract.ts mirrors the request-context keys: flowsafe does not import
|
|
5
|
+
* breakwater at runtime. The cross-package contract test pins the equality.
|
|
6
|
+
*/
|
|
7
|
+
export type ExecutionPrincipalKind = 'human' | 'service' | 'agent' | 'system';
|
|
8
|
+
export declare const EXECUTION_PRINCIPAL_KINDS: readonly ExecutionPrincipalKind[];
|
|
9
|
+
/** Automated kinds — everything that is not a logged-in person. */
|
|
10
|
+
export declare const AUTOMATED_PRINCIPAL_KINDS: readonly ExecutionPrincipalKind[];
|
|
11
|
+
export type AutomatedPrincipalKind = Exclude<ExecutionPrincipalKind, 'human'>;
|
|
12
|
+
/**
|
|
13
|
+
* `purpose` is REQUIRED on every automated kind, not optional as the roadmap
|
|
14
|
+
* sketch had it. The failure being fixed is that fabricated operators "lose
|
|
15
|
+
* provenance"; an optional field would let each new automated path skip the one
|
|
16
|
+
* thing that restores it. A human needs no purpose — the person is the reason.
|
|
17
|
+
*
|
|
18
|
+
* Fields are `readonly` because a principal is an authorization snapshot, not a
|
|
19
|
+
* mutable record: every consumer re-reads `kind` to decide what the holder may
|
|
20
|
+
* do, so a principal that can change between two reads has no meaning. The
|
|
21
|
+
* modifier is the compile-time half; `trustAutomationPrincipal` freezes the
|
|
22
|
+
* runtime half. `readonly` is not checked in assignability, so producers may
|
|
23
|
+
* still build one from an ordinary object literal.
|
|
24
|
+
*/
|
|
25
|
+
export type ExecutionPrincipal = {
|
|
26
|
+
readonly kind: 'human';
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly tenantId: string;
|
|
29
|
+
readonly role: ApprovalRole;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: 'service';
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly tenantId: string;
|
|
34
|
+
readonly purpose: string;
|
|
35
|
+
/** Only an agent delegates; `never` makes a wrong shape a type error. */
|
|
36
|
+
readonly delegatedBy?: never;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'agent';
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly tenantId: string;
|
|
41
|
+
readonly purpose: string;
|
|
42
|
+
/** The principal that delegated this run, for agent-to-agent work. */
|
|
43
|
+
readonly delegatedBy?: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'system';
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly tenantId: string;
|
|
48
|
+
readonly purpose: string;
|
|
49
|
+
readonly delegatedBy?: never;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The trusted-automation brand, following the TENANT_BOUND idiom for the same
|
|
53
|
+
* reason: TypeScript is structural, so a parameter typed plain
|
|
54
|
+
* `ExecutionPrincipal` is satisfied by any object literal. Without this, the
|
|
55
|
+
* service's automated entries authorize on the CALLER'S OWN ASSERTION that it
|
|
56
|
+
* is a robot — which would give automation strictly more create authority than
|
|
57
|
+
* a human `viewer`.
|
|
58
|
+
*
|
|
59
|
+
* The symbol is exported because declaration emit cannot reference a
|
|
60
|
+
* module-private name from an exported type. It is deliberately absent from the
|
|
61
|
+
* package barrel, but that is API-surface hygiene, NOT a capability boundary:
|
|
62
|
+
* the brand is recoverable by reflection from any vouched principal
|
|
63
|
+
* (`Object.getOwnPropertySymbols(maintenancePrincipal('x'))`), so in-process
|
|
64
|
+
* code that means to forge one still can. That residual is the same one
|
|
65
|
+
* TENANT_BOUND accepts, and it is deliberate — a TCB bypass on par with an `as`
|
|
66
|
+
* cast. What the brand eliminates is accidental satisfaction and the rushed fix
|
|
67
|
+
* that hands a request-derived principal to a trusted entry.
|
|
68
|
+
*/
|
|
69
|
+
export declare const TRUSTED_AUTOMATION: unique symbol;
|
|
70
|
+
/**
|
|
71
|
+
* Any non-human principal — the shape a duty needs when it wants provenance but
|
|
72
|
+
* derives no authority from the principal (the cron SLA sweep is the case).
|
|
73
|
+
* Separate from `TrustedAutomationPrincipal` so the brand is demanded only
|
|
74
|
+
* where it is actually read, which is `ApprovalService`'s two trusted entries.
|
|
75
|
+
*/
|
|
76
|
+
export type AutomatedExecutionPrincipal = Extract<ExecutionPrincipal, {
|
|
77
|
+
kind: AutomatedPrincipalKind;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* An automated principal that trusted platform code vouched for. The only kind
|
|
81
|
+
* accepted by `ApprovalService.createAsPrincipal` and
|
|
82
|
+
* `supersedeStaleAsPrincipal`.
|
|
83
|
+
*/
|
|
84
|
+
export type TrustedAutomationPrincipal = AutomatedExecutionPrincipal & {
|
|
85
|
+
readonly [TRUSTED_AUTOMATION]: true;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Vouch for an automated principal. Calling this IS the trust assertion, which
|
|
89
|
+
* is why it is a named function rather than a cast: it should be greppable, and
|
|
90
|
+
* it should never appear on a path that took the principal from a request.
|
|
91
|
+
*
|
|
92
|
+
* Throws on a human or a malformed principal — those must use the
|
|
93
|
+
* role-authorized entries.
|
|
94
|
+
*
|
|
95
|
+
* Returns a CANONICAL CLONE, branded and frozen. Validating the caller's object
|
|
96
|
+
* and handing the same reference back made the vouch time-of-check/time-of-use:
|
|
97
|
+
* the caller kept a mutable alias, so a validated `system` principal could be
|
|
98
|
+
* rewritten into `{kind:'human', role:'admin'}` after the check and before the
|
|
99
|
+
* service read it — and `#authorizeAutomated` re-reads `kind`. The clone comes
|
|
100
|
+
* from `canonicalPrincipal`, so it holds the exact values that were validated
|
|
101
|
+
* and no extra property rides into the trusted computing base; the brand lets
|
|
102
|
+
* consumers prove the value came from here, and the freeze keeps both true for
|
|
103
|
+
* the object's whole life.
|
|
104
|
+
*/
|
|
105
|
+
export declare function trustAutomationPrincipal(principal: ExecutionPrincipal): TrustedAutomationPrincipal;
|
|
106
|
+
/**
|
|
107
|
+
* Does this value carry the brand AND still hold a valid automated shape?
|
|
108
|
+
*
|
|
109
|
+
* The parameter type alone proves nothing at runtime — TypeScript is erased,
|
|
110
|
+
* and the ways in that remain (an `as` cast, a value rebuilt from storage or a
|
|
111
|
+
* structured clone across a boundary) all produce something the type accepts.
|
|
112
|
+
* This is the check that makes the brand load-bearing rather than decorative,
|
|
113
|
+
* so the trusted service entries call it instead of trusting their signature.
|
|
114
|
+
*
|
|
115
|
+
* Deliberately NOT on the package barrel: it is the enforcement half of an
|
|
116
|
+
* internal invariant, and exporting it would put a runtime shape check into the
|
|
117
|
+
* public API that consumers would have to keep working across minor versions.
|
|
118
|
+
*/
|
|
119
|
+
export declare function isTrustedAutomationPrincipal(value: unknown): value is TrustedAutomationPrincipal;
|
|
120
|
+
/**
|
|
121
|
+
* Validate and return a canonical principal that is not a person.
|
|
122
|
+
*
|
|
123
|
+
* The returned snapshot contains the exact values that passed validation, so
|
|
124
|
+
* callers never need to re-read a mutable or adversarial input. Kept off the
|
|
125
|
+
* package barrel: this is an internal enforcement helper, not public API.
|
|
126
|
+
*/
|
|
127
|
+
export declare function canonicalAutomatedPrincipal(value: unknown): AutomatedExecutionPrincipal | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Structural validation only. The TENANT binding is checked separately by
|
|
130
|
+
* `assertExecutionPrincipal`, because "is this shaped like a principal" and "is
|
|
131
|
+
* this principal allowed here" are different questions and conflating them
|
|
132
|
+
* produces call sites that answer neither.
|
|
133
|
+
*
|
|
134
|
+
* This answers only "was a valid principal readable from this value". It does
|
|
135
|
+
* NOT promise a later plain read returns what was validated — nothing can, for
|
|
136
|
+
* an object built to lie. Anything that goes on to USE the fields must take
|
|
137
|
+
* them from `canonicalPrincipal`'s snapshot (as `trustAutomationPrincipal` and
|
|
138
|
+
* `assertExecutionPrincipal` do) rather than from the argument.
|
|
139
|
+
*/
|
|
140
|
+
export declare function isExecutionPrincipal(value: unknown): value is ExecutionPrincipal;
|
|
141
|
+
/**
|
|
142
|
+
* Validate a principal AND bind it to the tenant that is about to act on it.
|
|
143
|
+
*
|
|
144
|
+
* `tenantId` on a decoded principal crosses an authentication boundary exactly
|
|
145
|
+
* as `ApprovalActor.tenantId` does — the type says `string`, and the type system
|
|
146
|
+
* has no authority over a value read back out of D1 or a DO's storage.
|
|
147
|
+
*
|
|
148
|
+
* Returns the canonical snapshot, not the argument: the tenant that was
|
|
149
|
+
* compared and the tenant the caller goes on to use are then the same string.
|
|
150
|
+
*/
|
|
151
|
+
export declare function assertExecutionPrincipal(value: unknown, expectedTenantId: string, label: string): ExecutionPrincipal;
|
|
152
|
+
/**
|
|
153
|
+
* Structural equality across every kind-specific field.
|
|
154
|
+
*
|
|
155
|
+
* Cast-free: the union narrows on `kind`, so a future variant with a new
|
|
156
|
+
* discriminating field becomes a compile error here rather than silently
|
|
157
|
+
* comparing equal. Three rebinding guards depend on that.
|
|
158
|
+
*/
|
|
159
|
+
export declare function samePrincipal(left: ExecutionPrincipal, right: ExecutionPrincipal): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* The role an automated principal projects into breakwater's `Actor`.
|
|
162
|
+
*
|
|
163
|
+
* `Actor.role` is required, so an automated principal must carry SOME label.
|
|
164
|
+
* breakwater's gate does not consult the role allowlist for a non-human kind,
|
|
165
|
+
* making this value inert there — it is the least-privileged role precisely so
|
|
166
|
+
* that any consumer which reads `actor.role` WITHOUT understanding `kind` gets
|
|
167
|
+
* the minimum rather than the `operator` these paths used to fabricate.
|
|
168
|
+
*
|
|
169
|
+
* `viewer` also holds no decider role, so an automated principal projected onto
|
|
170
|
+
* `ApprovalService` can never satisfy DECIDER_ROLES and approve anything.
|
|
171
|
+
*/
|
|
172
|
+
export declare const AUTOMATED_PROJECTED_ROLE: ApprovalRole;
|
|
173
|
+
/**
|
|
174
|
+
* Project a principal onto the approval-service identity.
|
|
175
|
+
*
|
|
176
|
+
* Automated principals keep their own id — attribution stays truthful — while
|
|
177
|
+
* borrowing the least-privileged role so that the approval service's own role
|
|
178
|
+
* gates (CAN_CREATE, DECIDER_ROLES) treat them as read-only.
|
|
179
|
+
*/
|
|
180
|
+
export declare function principalActor(principal: ExecutionPrincipal): ApprovalActor;
|
|
181
|
+
/**
|
|
182
|
+
* The principal as breakwater's `Actor`. The ONE place the projection rule is
|
|
183
|
+
* written; `principalActor` and the trusted request context both go through it
|
|
184
|
+
* so the breakwater-facing and approval-facing identities cannot disagree.
|
|
185
|
+
*/
|
|
186
|
+
export declare function breakwaterActorFor(principal: ExecutionPrincipal): {
|
|
187
|
+
id: string;
|
|
188
|
+
role: ApprovalRole;
|
|
189
|
+
kind: ExecutionPrincipalKind;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Serialize a principal for the trusted thread header. Every field is already
|
|
193
|
+
* bounded and header-control-free (`boundedText`), so plain JSON is safe and
|
|
194
|
+
* stays readable in a trace.
|
|
195
|
+
*/
|
|
196
|
+
export declare function encodeExecutionPrincipal(principal: ExecutionPrincipal): string;
|
|
197
|
+
/**
|
|
198
|
+
* Rebuild a principal from the trusted header, binding it to the tenant the DO
|
|
199
|
+
* already authenticated. Fields are picked EXPLICITLY rather than spread, so an
|
|
200
|
+
* attacker-supplied extra property cannot ride into DO storage or D1.
|
|
201
|
+
*
|
|
202
|
+
* Returns undefined on anything malformed; the caller fails closed.
|
|
203
|
+
*/
|
|
204
|
+
export declare function decodeExecutionPrincipal(header: string, tenantId: string): ExecutionPrincipal | undefined;
|
|
205
|
+
/** An authenticated human at the HTTP boundary, as an execution principal. */
|
|
206
|
+
export declare function humanPrincipal(actor: ApprovalActor): ExecutionPrincipal;
|
|
207
|
+
/** Correlation fields carried into every audit event for this principal. */
|
|
208
|
+
export declare function principalAuditFields(principal: ExecutionPrincipal): {
|
|
209
|
+
principalKind: ExecutionPrincipalKind;
|
|
210
|
+
principalId: string;
|
|
211
|
+
purpose?: string;
|
|
212
|
+
delegatedBy?: string;
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=principal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.d.ts","sourceRoot":"","sources":["../../src/approval-api/principal.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9E,eAAO,MAAM,yBAAyB,EAAE,SAAS,sBAAsB,EAKtE,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,yBAAyB,EAAE,SAAS,sBAAsB,EAItE,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAM9E;;;;;;;;;;;;GAYG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