@lushly-dev/afd-server 2.4.0 → 3.0.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/README.md +239 -56
- package/dist/admission.d.ts +137 -0
- package/dist/admission.d.ts.map +1 -0
- package/dist/admission.js +144 -0
- package/dist/admission.js.map +1 -0
- package/dist/app-call-registry.d.ts +31 -0
- package/dist/app-call-registry.d.ts.map +1 -0
- package/dist/app-call-registry.js +64 -0
- package/dist/app-call-registry.js.map +1 -0
- package/dist/approval-admission.d.ts +139 -0
- package/dist/approval-admission.d.ts.map +1 -0
- package/dist/approval-admission.js +252 -0
- package/dist/approval-admission.js.map +1 -0
- package/dist/approval-crypto.d.ts +37 -17
- package/dist/approval-crypto.d.ts.map +1 -1
- package/dist/approval-crypto.js +84 -75
- package/dist/approval-crypto.js.map +1 -1
- package/dist/approval-process-state.d.ts +21 -0
- package/dist/approval-process-state.d.ts.map +1 -0
- package/dist/approval-process-state.js +29 -0
- package/dist/approval-process-state.js.map +1 -0
- package/dist/approval-relay.d.ts +192 -9
- package/dist/approval-relay.d.ts.map +1 -1
- package/dist/approval-relay.js +45 -9
- package/dist/approval-relay.js.map +1 -1
- package/dist/approval-up-front.d.ts +40 -0
- package/dist/approval-up-front.d.ts.map +1 -0
- package/dist/approval-up-front.js +409 -0
- package/dist/approval-up-front.js.map +1 -0
- package/dist/approval.d.ts +65 -12
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +311 -47
- package/dist/approval.js.map +1 -1
- package/dist/approver.d.ts +84 -0
- package/dist/approver.d.ts.map +1 -0
- package/dist/approver.js +107 -0
- package/dist/approver.js.map +1 -0
- package/dist/auth-middleware-check.d.ts +23 -0
- package/dist/auth-middleware-check.d.ts.map +1 -0
- package/dist/auth-middleware-check.js +48 -0
- package/dist/auth-middleware-check.js.map +1 -0
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +27 -3
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-docs.d.ts.map +1 -1
- package/dist/bootstrap/afd-docs.js +4 -0
- package/dist/bootstrap/afd-docs.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +4 -1
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +19 -4
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +3 -1
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/command-allow.d.ts +4 -4
- package/dist/command-allow.d.ts.map +1 -1
- package/dist/command-allow.js +10 -15
- package/dist/command-allow.js.map +1 -1
- package/dist/command-routing.d.ts +56 -8
- package/dist/command-routing.d.ts.map +1 -1
- package/dist/command-routing.js +82 -16
- package/dist/command-routing.js.map +1 -1
- package/dist/command-timeout.d.ts +17 -0
- package/dist/command-timeout.d.ts.map +1 -0
- package/dist/command-timeout.js +99 -0
- package/dist/command-timeout.js.map +1 -0
- package/dist/confirmation-gate.d.ts +7 -7
- package/dist/confirmation-gate.d.ts.map +1 -1
- package/dist/confirmation-gate.js +26 -12
- package/dist/confirmation-gate.js.map +1 -1
- package/dist/confirmations.d.ts +28 -3
- package/dist/confirmations.d.ts.map +1 -1
- package/dist/confirmations.js +6 -7
- package/dist/confirmations.js.map +1 -1
- package/dist/context-fields.d.ts +16 -1
- package/dist/context-fields.d.ts.map +1 -1
- package/dist/context-fields.js +30 -13
- package/dist/context-fields.js.map +1 -1
- package/dist/context-scope.d.ts +3 -3
- package/dist/context-scope.d.ts.map +1 -1
- package/dist/context-scope.js +7 -8
- package/dist/context-scope.js.map +1 -1
- package/dist/define-core.d.ts +63 -1
- package/dist/define-core.d.ts.map +1 -1
- package/dist/define-core.js +27 -4
- package/dist/define-core.js.map +1 -1
- package/dist/define.d.ts +4 -3
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +1 -1
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +54 -8
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +64 -8
- package/dist/direct-registry.js.map +1 -1
- package/dist/direct-tool-surface.d.ts +1 -1
- package/dist/direct-tool-surface.d.ts.map +1 -1
- package/dist/direct-tool-surface.js +28 -6
- package/dist/direct-tool-surface.js.map +1 -1
- package/dist/direct.d.ts +6 -2
- package/dist/direct.d.ts.map +1 -1
- package/dist/direct.js +4 -1
- package/dist/direct.js.map +1 -1
- package/dist/elicitation-state.d.ts +5 -1
- package/dist/elicitation-state.d.ts.map +1 -1
- package/dist/elicitation-state.js +4 -1
- package/dist/elicitation-state.js.map +1 -1
- package/dist/execution.d.ts +52 -6
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +183 -19
- package/dist/execution.js.map +1 -1
- package/dist/host-state.d.ts +81 -0
- package/dist/host-state.d.ts.map +1 -0
- package/dist/host-state.js +62 -0
- package/dist/host-state.js.map +1 -0
- package/dist/http-handler.d.ts +48 -11
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +207 -58
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts +14 -1
- package/dist/http-security.d.ts.map +1 -1
- package/dist/http-security.js +79 -17
- package/dist/http-security.js.map +1 -1
- package/dist/http-sessions.d.ts +45 -5
- package/dist/http-sessions.d.ts.map +1 -1
- package/dist/http-sessions.js +52 -10
- package/dist/http-sessions.js.map +1 -1
- package/dist/http-sse.d.ts +9 -0
- package/dist/http-sse.d.ts.map +1 -1
- package/dist/http-sse.js +12 -3
- package/dist/http-sse.js.map +1 -1
- package/dist/human-relay.d.ts +195 -0
- package/dist/human-relay.d.ts.map +1 -0
- package/dist/human-relay.js +670 -0
- package/dist/human-relay.js.map +1 -0
- package/dist/idempotency-step.d.ts +231 -0
- package/dist/idempotency-step.d.ts.map +1 -0
- package/dist/idempotency-step.js +389 -0
- package/dist/idempotency-step.js.map +1 -0
- package/dist/idempotency-store.d.ts +107 -0
- package/dist/idempotency-store.d.ts.map +1 -0
- package/dist/idempotency-store.js +100 -0
- package/dist/idempotency-store.js.map +1 -0
- package/dist/index.d.ts +18 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -4
- package/dist/index.js.map +1 -1
- package/dist/instance-state.d.ts +53 -0
- package/dist/instance-state.d.ts.map +1 -0
- package/dist/instance-state.js +94 -0
- package/dist/instance-state.js.map +1 -0
- package/dist/journal-off-tape.d.ts +52 -0
- package/dist/journal-off-tape.d.ts.map +1 -0
- package/dist/journal-off-tape.js +150 -0
- package/dist/journal-off-tape.js.map +1 -0
- package/dist/journal-replay.d.ts.map +1 -1
- package/dist/journal-replay.js +48 -3
- package/dist/journal-replay.js.map +1 -1
- package/dist/journal-view.d.ts +50 -0
- package/dist/journal-view.d.ts.map +1 -0
- package/dist/journal-view.js +214 -0
- package/dist/journal-view.js.map +1 -0
- package/dist/journal.d.ts +34 -6
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +183 -47
- package/dist/journal.js.map +1 -1
- package/dist/json-rpc.d.ts +3 -2
- package/dist/json-rpc.d.ts.map +1 -1
- package/dist/json-rpc.js +5 -3
- package/dist/json-rpc.js.map +1 -1
- package/dist/lazy-tools.d.ts +27 -2
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +22 -4
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-auth-bearer.d.ts +2 -0
- package/dist/mcp-auth-bearer.d.ts.map +1 -1
- package/dist/mcp-auth-bearer.js +1 -1
- package/dist/mcp-auth-bearer.js.map +1 -1
- package/dist/mcp-auth-dispatch.d.ts +38 -0
- package/dist/mcp-auth-dispatch.d.ts.map +1 -0
- package/dist/mcp-auth-dispatch.js +113 -0
- package/dist/mcp-auth-dispatch.js.map +1 -0
- package/dist/mcp-auth-jwt.d.ts +3 -2
- package/dist/mcp-auth-jwt.d.ts.map +1 -1
- package/dist/mcp-auth-jwt.js.map +1 -1
- package/dist/mcp-auth-resource.d.ts +6 -2
- package/dist/mcp-auth-resource.d.ts.map +1 -1
- package/dist/mcp-auth-resource.js +6 -5
- package/dist/mcp-auth-resource.js.map +1 -1
- package/dist/mcp-auth-scopes.d.ts +84 -0
- package/dist/mcp-auth-scopes.d.ts.map +1 -0
- package/dist/mcp-auth-scopes.js +125 -0
- package/dist/mcp-auth-scopes.js.map +1 -0
- package/dist/mcp-auth-view.d.ts +50 -0
- package/dist/mcp-auth-view.d.ts.map +1 -0
- package/dist/mcp-auth-view.js +179 -0
- package/dist/mcp-auth-view.js.map +1 -0
- package/dist/mcp-auth.d.ts +94 -3
- package/dist/mcp-auth.d.ts.map +1 -1
- package/dist/mcp-auth.js +241 -23
- package/dist/mcp-auth.js.map +1 -1
- package/dist/mcp-modern.d.ts +80 -6
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +378 -91
- package/dist/mcp-modern.js.map +1 -1
- package/dist/meta-argument.d.ts +9 -8
- package/dist/meta-argument.d.ts.map +1 -1
- package/dist/meta-argument.js +28 -10
- package/dist/meta-argument.js.map +1 -1
- package/dist/meta-tools.js +2 -2
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts +16 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +57 -10
- package/dist/middleware.js.map +1 -1
- package/dist/output-budget.d.ts +77 -0
- package/dist/output-budget.d.ts.map +1 -0
- package/dist/output-budget.js +202 -0
- package/dist/output-budget.js.map +1 -0
- package/dist/principal-binding.js +1 -1
- package/dist/principal-binding.js.map +1 -1
- package/dist/relay-evidence.d.ts +74 -0
- package/dist/relay-evidence.d.ts.map +1 -0
- package/dist/relay-evidence.js +143 -0
- package/dist/relay-evidence.js.map +1 -0
- package/dist/resources.d.ts +35 -10
- package/dist/resources.d.ts.map +1 -1
- package/dist/resources.js +59 -18
- package/dist/resources.js.map +1 -1
- package/dist/schema.d.ts +4 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -3
- package/dist/schema.js.map +1 -1
- package/dist/scope-view.d.ts +65 -0
- package/dist/scope-view.d.ts.map +1 -0
- package/dist/scope-view.js +45 -0
- package/dist/scope-view.js.map +1 -0
- package/dist/server-types.d.ts +182 -27
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +26 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +403 -61
- package/dist/server.js.map +1 -1
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +99 -3
- package/dist/skills.js.map +1 -1
- package/dist/task-dispatch.d.ts +35 -0
- package/dist/task-dispatch.d.ts.map +1 -0
- package/dist/task-dispatch.js +25 -0
- package/dist/task-dispatch.js.map +1 -0
- package/dist/tasks-runtime.d.ts +115 -0
- package/dist/tasks-runtime.d.ts.map +1 -0
- package/dist/tasks-runtime.js +760 -0
- package/dist/tasks-runtime.js.map +1 -0
- package/dist/tasks.d.ts +237 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +321 -0
- package/dist/tasks.js.map +1 -0
- package/dist/tool-router.d.ts +68 -3
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +293 -70
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +32 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +162 -55
- package/dist/tools.js.map +1 -1
- package/dist/up-front-steps.d.ts +35 -0
- package/dist/up-front-steps.d.ts.map +1 -0
- package/dist/up-front-steps.js +159 -0
- package/dist/up-front-steps.js.map +1 -0
- package/dist/validation.d.ts +38 -3
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +118 -23
- package/dist/validation.js.map +1 -1
- package/dist/verified-credentials.d.ts +13 -5
- package/dist/verified-credentials.d.ts.map +1 -1
- package/dist/verified-credentials.js +43 -10
- package/dist/verified-credentials.js.map +1 -1
- package/package.json +15 -11
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Which calls an approval step admitted (internal; not exported by the package).
|
|
3
|
+
*
|
|
4
|
+
* The execution engine records each call's declared approval policy on the call's own context
|
|
5
|
+
* object before any middleware runs. The approval middleware decides from that record (the
|
|
6
|
+
* command's own policy) and, when it lets the call through, records what it decided on: the
|
|
7
|
+
* command name, the canonical JSON of the input it decided on, and whether the policy its
|
|
8
|
+
* `commands` option lists for the command gates it. The engine dispatches a call whose own or
|
|
9
|
+
* listed policy is not `'not-required'` only when every such admission matches the command and
|
|
10
|
+
* validated input it is about to run, and it takes them as it dispatches, so one admission runs
|
|
11
|
+
* one handler. An input with no canonical form, which only a policy that let the call through
|
|
12
|
+
* admits (the middleware refuses to hold one), is compared by identity, so a change inside it is
|
|
13
|
+
* not seen.
|
|
14
|
+
*
|
|
15
|
+
* Every call gets a fresh context object (`withContextDefaults` copies), so a batch item, a
|
|
16
|
+
* pipeline step or a command run from inside another command's handler has its own record and
|
|
17
|
+
* never inherits an outer call's admission.
|
|
18
|
+
*
|
|
19
|
+
* The records live in one WeakMap on `globalThis`, under a registered symbol, so that two
|
|
20
|
+
* installed copies of this package (an engine from one, the middleware from the other) share it.
|
|
21
|
+
* The first copy installs it as a non-writable, non-configurable property; a later copy uses it
|
|
22
|
+
* only when it is that: a plain `WeakMap` installed that way. Anything else there is ignored and
|
|
23
|
+
* this copy keeps its records to itself, so an admission from elsewhere is not honoured. This is
|
|
24
|
+
* not a boundary against code running in the same process or page.
|
|
25
|
+
*/
|
|
26
|
+
const KEY = Symbol.for('dev.afd/approval-admission');
|
|
27
|
+
// Captured once, so later changes to WeakMap.prototype do not reach these records.
|
|
28
|
+
const weakGet = WeakMap.prototype.get;
|
|
29
|
+
const weakSet = WeakMap.prototype.set;
|
|
30
|
+
const setAdd = Set.prototype.add;
|
|
31
|
+
const setHas = Set.prototype.has;
|
|
32
|
+
const weakSetAdd = WeakSet.prototype.add;
|
|
33
|
+
const weakSetHas = WeakSet.prototype.has;
|
|
34
|
+
/**
|
|
35
|
+
* The shared map on `holder` (`globalThis`) when another copy installed it as this module does,
|
|
36
|
+
* else a fresh one, installed on `holder` when the key is free. Exported for its tests.
|
|
37
|
+
*/
|
|
38
|
+
export function installAdmissionRecords(holder = globalThis) {
|
|
39
|
+
const existing = Object.getOwnPropertyDescriptor(holder, KEY);
|
|
40
|
+
if (existing === undefined) {
|
|
41
|
+
const map = new WeakMap();
|
|
42
|
+
try {
|
|
43
|
+
Object.defineProperty(holder, KEY, {
|
|
44
|
+
value: map,
|
|
45
|
+
writable: false,
|
|
46
|
+
configurable: false,
|
|
47
|
+
enumerable: false,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// A frozen or non-extensible global: keep the records private.
|
|
52
|
+
}
|
|
53
|
+
return map;
|
|
54
|
+
}
|
|
55
|
+
const value = existing.value;
|
|
56
|
+
if ('value' in existing &&
|
|
57
|
+
existing.writable === false &&
|
|
58
|
+
existing.configurable === false &&
|
|
59
|
+
value instanceof WeakMap &&
|
|
60
|
+
Object.getPrototypeOf(value) === WeakMap.prototype &&
|
|
61
|
+
Reflect.ownKeys(value).length === 0) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
return new WeakMap();
|
|
65
|
+
}
|
|
66
|
+
const RECORDS = installAdmissionRecords();
|
|
67
|
+
function record(context) {
|
|
68
|
+
return weakGet.call(RECORDS, context);
|
|
69
|
+
}
|
|
70
|
+
/** Record, before any middleware runs, the command this call's `context` runs, not yet admitted. */
|
|
71
|
+
export function beginAdmission(context, command) {
|
|
72
|
+
weakSet.call(RECORDS, context, {
|
|
73
|
+
command: {
|
|
74
|
+
name: command.name,
|
|
75
|
+
approval: command.approval,
|
|
76
|
+
confirmPrompt: command.confirmPrompt,
|
|
77
|
+
...(command.secret === true && { secret: true }),
|
|
78
|
+
// Always a boolean in this copy's records, so a record from an older copy of the
|
|
79
|
+
// package, which never sets it, reads as unknown.
|
|
80
|
+
mutation: command.mutation === true,
|
|
81
|
+
...((command.idempotency === 'natural' || command.idempotency === 'keyed') && {
|
|
82
|
+
idempotency: command.idempotency,
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
admitted: [],
|
|
86
|
+
steps: new Set(),
|
|
87
|
+
token: Object.freeze({}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Record that an approval step admitted the call of `context`. A no-op outside the engine. */
|
|
91
|
+
export function admitApproval(context, admit) {
|
|
92
|
+
const found = record(context);
|
|
93
|
+
if (!found)
|
|
94
|
+
return;
|
|
95
|
+
if (admit.listedGate)
|
|
96
|
+
found.listedGate = true;
|
|
97
|
+
setAdd.call(found.steps, admit.step);
|
|
98
|
+
found.admitted.push({
|
|
99
|
+
step: admit.step,
|
|
100
|
+
name: admit.commandName,
|
|
101
|
+
canonical: admit.canonical,
|
|
102
|
+
input: admit.input,
|
|
103
|
+
canonicalize: admit.canonicalize,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Record that the policy an approval step's `commands` option lists for the command the call of
|
|
108
|
+
* `context` runs gates it, whatever name the step was called with, so a call renamed on its way
|
|
109
|
+
* to the step is still checked at dispatch. A no-op outside the engine.
|
|
110
|
+
*/
|
|
111
|
+
export function markListedGate(context) {
|
|
112
|
+
const found = record(context);
|
|
113
|
+
if (found)
|
|
114
|
+
found.listedGate = true;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Whether the engine must take and check an admission before it dispatches the call of
|
|
118
|
+
* `context`: its command's own policy gates it, or an approval step recorded that its listed
|
|
119
|
+
* policy does.
|
|
120
|
+
*/
|
|
121
|
+
export function needsAdmission(context) {
|
|
122
|
+
const found = record(context);
|
|
123
|
+
return found !== undefined && (gates(found.command.approval) || found.listedGate === true);
|
|
124
|
+
}
|
|
125
|
+
/** Whether a declared policy needs an approval step: anything but unset or `'not-required'`. */
|
|
126
|
+
export function gates(policy) {
|
|
127
|
+
return policy !== undefined && policy !== 'not-required';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Take the admissions of the call of `context`: `admitted` when every approval step that ever
|
|
131
|
+
* admitted it admitted it again since the last dispatch, each on `commandName` and `input`: the
|
|
132
|
+
* same name, and the same canonical input (the same value, by `Object.is`, when the input has no
|
|
133
|
+
* canonical form; a change inside such a value is not seen), `missing` with none, `mismatch`
|
|
134
|
+
* otherwise. Taken whatever the answer, so a second dispatch needs a second admission from each.
|
|
135
|
+
*/
|
|
136
|
+
export function takeAdmission(context, commandName, input) {
|
|
137
|
+
const found = record(context);
|
|
138
|
+
if (!found)
|
|
139
|
+
return 'missing';
|
|
140
|
+
const admitted = found.admitted;
|
|
141
|
+
if (admitted.length === 0)
|
|
142
|
+
return found.taken ? 'mismatch' : 'missing';
|
|
143
|
+
found.admitted = [];
|
|
144
|
+
found.taken = true;
|
|
145
|
+
const fresh = new Set();
|
|
146
|
+
for (const step of admitted)
|
|
147
|
+
setAdd.call(fresh, step.step);
|
|
148
|
+
for (const step of found.steps)
|
|
149
|
+
if (!setHas.call(fresh, step))
|
|
150
|
+
return 'mismatch';
|
|
151
|
+
const same = admitted.every((step) => {
|
|
152
|
+
if (step.name !== commandName)
|
|
153
|
+
return false;
|
|
154
|
+
const canonical = step.canonicalize(input);
|
|
155
|
+
return step.canonical === undefined
|
|
156
|
+
? Object.is(step.input, input) && canonical === undefined
|
|
157
|
+
: canonical === step.canonical;
|
|
158
|
+
});
|
|
159
|
+
return same ? 'admitted' : 'mismatch';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The declared policy of the command the call of `context` runs. `found` is false when the call
|
|
163
|
+
* did not come through the engine (the middleware was called directly).
|
|
164
|
+
*/
|
|
165
|
+
export function livePolicy(context) {
|
|
166
|
+
const found = record(context);
|
|
167
|
+
return found
|
|
168
|
+
? { found: true, policy: found.command.approval }
|
|
169
|
+
: { found: false, policy: undefined };
|
|
170
|
+
}
|
|
171
|
+
/** The command the call of `context` runs, as recorded by the engine; undefined outside it. */
|
|
172
|
+
export function liveCommand(context) {
|
|
173
|
+
return record(context)?.command;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Mark `inner` as the engine's when `outer` is: `composeMiddleware` builds continuations of its own
|
|
177
|
+
* for the parts it composes, and a part the engine reached through it is still the engine's.
|
|
178
|
+
*/
|
|
179
|
+
export function inheritEngineNext(context, outer, inner) {
|
|
180
|
+
const found = record(context);
|
|
181
|
+
if (found?.chain && weakSetHas.call(found.chain, outer))
|
|
182
|
+
weakSetAdd.call(found.chain, inner);
|
|
183
|
+
}
|
|
184
|
+
/** Mark `next` as a continuation the engine built for the call of `context`. */
|
|
185
|
+
export function markEngineNext(context, next) {
|
|
186
|
+
const found = record(context);
|
|
187
|
+
if (!found)
|
|
188
|
+
return;
|
|
189
|
+
if (!found.chain)
|
|
190
|
+
found.chain = new WeakSet();
|
|
191
|
+
weakSetAdd.call(found.chain, next);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* What the engine records of the call of `context`, for the journal: for a middleware the engine
|
|
195
|
+
* invoked (its `next` is one the engine built), and `undefined` for any other recorder: outside
|
|
196
|
+
* the engine, or one a handler runs itself on the same context, at any time. Its `secret` is
|
|
197
|
+
* whether the command declares `secret`, and its `token` is the call's identity, by which the
|
|
198
|
+
* journal tells a recorder of the same call from one of a call it runs inside.
|
|
199
|
+
*/
|
|
200
|
+
export function liveDispatch(context, next) {
|
|
201
|
+
const found = record(context);
|
|
202
|
+
if (!found?.chain || !weakSetHas.call(found.chain, next))
|
|
203
|
+
return undefined;
|
|
204
|
+
return { token: found.token, secret: found.command.secret === true };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Whether the command the engine runs for `context` declares `mutation`, for the retry
|
|
208
|
+
* middleware: `true` or `false` for a middleware the engine invoked, and `undefined` for any other
|
|
209
|
+
* caller, as {@link liveDispatch} decides.
|
|
210
|
+
*/
|
|
211
|
+
export function liveMutation(context, next) {
|
|
212
|
+
const found = record(context);
|
|
213
|
+
if (!found?.chain || !weakSetHas.call(found.chain, next))
|
|
214
|
+
return undefined;
|
|
215
|
+
const mutation = found.command.mutation;
|
|
216
|
+
return typeof mutation === 'boolean' ? mutation : undefined;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The command's declaration and the call's key, for the retry middleware (`spec/idempotency.md`,
|
|
220
|
+
* R1): for a middleware the engine invoked, and `undefined` for any other caller, as
|
|
221
|
+
* {@link liveDispatch} decides.
|
|
222
|
+
*/
|
|
223
|
+
export function liveRepeatDeclaration(context, next) {
|
|
224
|
+
const found = record(context);
|
|
225
|
+
if (!found?.chain || !weakSetHas.call(found.chain, next))
|
|
226
|
+
return undefined;
|
|
227
|
+
const mutation = found.command.mutation;
|
|
228
|
+
if (typeof mutation !== 'boolean')
|
|
229
|
+
return undefined;
|
|
230
|
+
return {
|
|
231
|
+
mutation,
|
|
232
|
+
...(found.command.idempotency && { idempotency: found.command.idempotency }),
|
|
233
|
+
carriesKey: found.key?.carriesKey === true,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** Record whether the call of `context` carries a key the retry middleware may count. */
|
|
237
|
+
export function recordCallKey(context, carriesKey) {
|
|
238
|
+
const found = record(context);
|
|
239
|
+
if (found)
|
|
240
|
+
found.key = { carriesKey };
|
|
241
|
+
}
|
|
242
|
+
/** Record that the idempotency step reserved the key of the call of `context` (R3). */
|
|
243
|
+
export function markIdempotencyStepActed(context) {
|
|
244
|
+
const found = record(context);
|
|
245
|
+
if (found)
|
|
246
|
+
found.key = { carriesKey: found.key?.carriesKey === true, stepActed: true };
|
|
247
|
+
}
|
|
248
|
+
/** Whether the idempotency step reserved the key of the call of `context` (R3). */
|
|
249
|
+
export function idempotencyStepActed(context) {
|
|
250
|
+
return record(context)?.key?.stepActed === true;
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=approval-admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-admission.js","sourceRoot":"","sources":["../src/approval-admission.ts"],"names":[],"mappings":"AAAA;;;;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wBAAwB,CAAC,OAAuB;IAC/D,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,KAAK;QAAE,KAAK,CAAC,GAAG,GAAG,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACxF,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAAC,OAAuB;IAC3D,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC;AACjD,CAAC"}
|
|
@@ -6,33 +6,53 @@
|
|
|
6
6
|
* the approval middleware loads no Node.js built-in. Tokens are byte for byte what the
|
|
7
7
|
* `node:crypto` implementation issued: `spec/vectors/approval-tokens.json` checks it.
|
|
8
8
|
*/
|
|
9
|
-
import type { Actor } from '@lushly-dev/afd-core';
|
|
10
|
-
|
|
11
|
-
export
|
|
9
|
+
import type { Actor, CommandError } from '@lushly-dev/afd-core';
|
|
10
|
+
import { canonicalJson } from '@lushly-dev/afd-core/internal/canonical-json';
|
|
11
|
+
export { canonicalJson };
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* members are dropped, and `undefined` in an array is `null`).
|
|
16
|
-
*
|
|
17
|
-
* It fails closed rather than collide: only plain objects, arrays, strings, finite numbers,
|
|
18
|
-
* booleans, `null` and values with `toJSON` are accepted. A `bigint`, a non-finite number, a
|
|
19
|
-
* cycle, or an object of any other kind (`Map`, `Set`, `RegExp`, typed arrays, class
|
|
20
|
-
* instances) throws, so a call whose validated input holds one cannot be approved.
|
|
21
|
-
*
|
|
22
|
-
* @throws TypeError for a value it cannot encode without ambiguity
|
|
13
|
+
* The answer to a call that needs approval on an input with no canonical form: no token can bind
|
|
14
|
+
* it, so the person is not asked.
|
|
23
15
|
*/
|
|
24
|
-
export declare function
|
|
16
|
+
export declare function inputNotCanonical(commandName: string): CommandError;
|
|
17
|
+
/**
|
|
18
|
+
* The answer when a call's input changed while the approval step was deciding on it (inside a
|
|
19
|
+
* policy function or a store it awaited), so what a person would be shown is not what a token
|
|
20
|
+
* would bind.
|
|
21
|
+
*/
|
|
22
|
+
export declare function inputChanged(commandName: string): CommandError;
|
|
23
|
+
/** The canonical JSON of `value`, or undefined for a value canonical JSON refuses. */
|
|
24
|
+
export declare function canonicalOrUndefined(value: unknown): string | undefined;
|
|
25
|
+
export declare const MIN_SECRET_BYTES = 32;
|
|
26
|
+
/** An HMAC key: a string (UTF-8) or raw bytes, at least 32 bytes long. */
|
|
27
|
+
export type ApprovalSecret = string | Uint8Array;
|
|
25
28
|
/** The actor fields a token is bound to. `label` is display text, so it is left out. */
|
|
26
29
|
export declare function actorJson(actor: Actor | undefined): string;
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* An HMAC-SHA256 key, imported on first use and reused for every token it signs or checks. The
|
|
32
|
+
* import waits for first use so that an app that never asks for approval starts where WebCrypto
|
|
33
|
+
* is missing, such as a browser page served over plain HTTP from a network address (#1699).
|
|
34
|
+
*/
|
|
28
35
|
export interface ApprovalKey {
|
|
29
36
|
readonly key: Promise<CryptoKey>;
|
|
30
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* WebCrypto is missing: Node.js before 22, or a browser page on an insecure origin, where
|
|
40
|
+
* `crypto.subtle` is not exposed. The approval middleware answers a call it meets this way with
|
|
41
|
+
* `APPROVAL_UNAVAILABLE` (`details.reason: "no-webcrypto"`).
|
|
42
|
+
*/
|
|
43
|
+
export declare class WebCryptoUnavailableError extends TypeError {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
31
46
|
export declare function toKeys(secret: ApprovalSecret | readonly ApprovalSecret[] | undefined): ApprovalKey[];
|
|
32
47
|
/** HMAC-SHA256 of the UTF-8 bytes of `data`. */
|
|
33
48
|
export declare function hmac(key: ApprovalKey, data: string): Promise<Uint8Array>;
|
|
34
|
-
/**
|
|
35
|
-
export declare function
|
|
49
|
+
/** Unpadded base64url SHA-256 of the UTF-8 bytes of `data` (WebCrypto, Node and browser). */
|
|
50
|
+
export declare function sha256Base64url(data: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* A keyed digest; `purpose` keeps an input digest from ever matching an actor digest, and an
|
|
53
|
+
* approver's principal digest from matching either.
|
|
54
|
+
*/
|
|
55
|
+
export declare function digest(key: ApprovalKey, purpose: 'input' | 'actor' | 'principal', value: string): Promise<Uint8Array>;
|
|
36
56
|
/** Constant-time equality. Lengths are not secret (every digest here is 32 bytes). */
|
|
37
57
|
export declare function safeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
38
58
|
/** Constant-time equality of two strings' UTF-8 bytes. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-crypto.d.ts","sourceRoot":"","sources":["../src/approval-crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"approval-crypto.d.ts","sourceRoot":"","sources":["../src/approval-crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CASnE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAU9D;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMvE;AAED,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAInC,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,U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C,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiBpE;AAED,2EAA2E;AAC3E,wBAAgB,sBAAsB;IAGpC,OAAO,QAAQ,MAAM,aAAa,MAAM,OAAO,MAAM,GAAG,OAAO;EAShE"}
|
package/dist/approval-crypto.js
CHANGED
|
@@ -6,81 +6,65 @@
|
|
|
6
6
|
* the approval middleware loads no Node.js built-in. Tokens are byte for byte what the
|
|
7
7
|
* `node:crypto` implementation issued: `spec/vectors/approval-tokens.json` checks it.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const decoder = new TextDecoder();
|
|
9
|
+
import { canonicalJson } from '@lushly-dev/afd-core/internal/canonical-json';
|
|
10
|
+
export { canonicalJson };
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* members are dropped, and `undefined` in an array is `null`).
|
|
16
|
-
*
|
|
17
|
-
* It fails closed rather than collide: only plain objects, arrays, strings, finite numbers,
|
|
18
|
-
* booleans, `null` and values with `toJSON` are accepted. A `bigint`, a non-finite number, a
|
|
19
|
-
* cycle, or an object of any other kind (`Map`, `Set`, `RegExp`, typed arrays, class
|
|
20
|
-
* instances) throws, so a call whose validated input holds one cannot be approved.
|
|
21
|
-
*
|
|
22
|
-
* @throws TypeError for a value it cannot encode without ambiguity
|
|
12
|
+
* The answer to a call that needs approval on an input with no canonical form: no token can bind
|
|
13
|
+
* it, so the person is not asked.
|
|
23
14
|
*/
|
|
24
|
-
export function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
if (Array.isArray(object)) {
|
|
57
|
-
return `[${object.map((item) => encode(item) ?? 'null').join(',')}]`;
|
|
58
|
-
}
|
|
59
|
-
const prototype = Object.getPrototypeOf(object);
|
|
60
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
61
|
-
const kind = object.constructor?.name ?? 'object';
|
|
62
|
-
throw new TypeError(`Cannot bind an approval to a ${kind}: use plain JSON input`);
|
|
63
|
-
}
|
|
64
|
-
const members = [];
|
|
65
|
-
for (const key of Object.keys(object).sort()) {
|
|
66
|
-
const member = encode(object[key]);
|
|
67
|
-
if (member !== undefined)
|
|
68
|
-
members.push(`${JSON.stringify(key)}:${member}`);
|
|
69
|
-
}
|
|
70
|
-
return `{${members.join(',')}}`;
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
ancestors.delete(object);
|
|
74
|
-
}
|
|
15
|
+
export function inputNotCanonical(commandName) {
|
|
16
|
+
return {
|
|
17
|
+
code: 'APPROVAL_UNAVAILABLE',
|
|
18
|
+
message: `${commandName} needs a person's approval, and this input cannot be bound to one`,
|
|
19
|
+
suggestion: "Do not retry with this input: it has no exact canonical form, so an approval cannot be bound to it. Send the input in a form canonical JSON accepts (for example, an integer a JavaScript number cannot hold exactly, such as 2^53 + 1, as a string). If the command's schema itself produces such a value (a Set, Map, bigint or class instance), tell the user: the operator must change the schema.",
|
|
20
|
+
retryable: false,
|
|
21
|
+
details: { reason: 'input-not-canonical' },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The answer when a call's input changed while the approval step was deciding on it (inside a
|
|
26
|
+
* policy function or a store it awaited), so what a person would be shown is not what a token
|
|
27
|
+
* would bind.
|
|
28
|
+
*/
|
|
29
|
+
export function inputChanged(commandName) {
|
|
30
|
+
return {
|
|
31
|
+
code: 'APPROVAL_UNAVAILABLE',
|
|
32
|
+
message: `${commandName}'s input changed while its approval was being decided`,
|
|
33
|
+
suggestion: 'Do not retry: this call is not the one the approval step decided on. The operator fixes the policy function or middleware that changes the input.',
|
|
34
|
+
retryable: false,
|
|
35
|
+
recovery: { kind: 'external' },
|
|
36
|
+
details: { reason: 'admission-mismatch' },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The canonical JSON of `value`, or undefined for a value canonical JSON refuses. */
|
|
40
|
+
export function canonicalOrUndefined(value) {
|
|
41
|
+
try {
|
|
42
|
+
return canonicalJson(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
75
46
|
}
|
|
76
|
-
return encode(value) ?? 'null';
|
|
77
47
|
}
|
|
48
|
+
export const MIN_SECRET_BYTES = 32;
|
|
49
|
+
const encoder = new TextEncoder();
|
|
50
|
+
const decoder = new TextDecoder();
|
|
78
51
|
/** The actor fields a token is bound to. `label` is display text, so it is left out. */
|
|
79
52
|
export function actorJson(actor) {
|
|
80
53
|
if (!actor)
|
|
81
54
|
return 'null';
|
|
82
55
|
return canonicalJson({ kind: actor.kind, id: actor.id, onBehalfOf: actor.onBehalfOf });
|
|
83
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* WebCrypto is missing: Node.js before 22, or a browser page on an insecure origin, where
|
|
59
|
+
* `crypto.subtle` is not exposed. The approval middleware answers a call it meets this way with
|
|
60
|
+
* `APPROVAL_UNAVAILABLE` (`details.reason: "no-webcrypto"`).
|
|
61
|
+
*/
|
|
62
|
+
export class WebCryptoUnavailableError extends TypeError {
|
|
63
|
+
constructor() {
|
|
64
|
+
super('The approval middleware needs WebCrypto (globalThis.crypto.subtle): Node.js 22 or later, or a browser on a secure origin (HTTPS or localhost)');
|
|
65
|
+
this.name = 'WebCryptoUnavailableError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
84
68
|
export function toKeys(secret) {
|
|
85
69
|
const secrets = Array.isArray(secret) ? secret : [secret];
|
|
86
70
|
if (secrets.length === 0)
|
|
@@ -89,15 +73,33 @@ export function toKeys(secret) {
|
|
|
89
73
|
if (typeof candidate !== 'string' && !(candidate instanceof Uint8Array)) {
|
|
90
74
|
throw new TypeError('Approval secret is required: pass a string or Uint8Array');
|
|
91
75
|
}
|
|
92
|
-
// A copy, so a caller that reuses its buffer cannot change the key
|
|
93
|
-
|
|
76
|
+
// A copy, so a caller that reuses its buffer cannot change the key, which is imported only
|
|
77
|
+
// on first use. `new Uint8Array` copies a Node.js `Buffer` too, whose `slice` shares memory.
|
|
78
|
+
const bytes = typeof candidate === 'string' ? encoder.encode(candidate) : new Uint8Array(candidate);
|
|
94
79
|
if (bytes.length < MIN_SECRET_BYTES) {
|
|
95
80
|
throw new TypeError(`Approval secret must be at least ${MIN_SECRET_BYTES} bytes`);
|
|
96
81
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
let key;
|
|
83
|
+
return {
|
|
84
|
+
get key() {
|
|
85
|
+
if (!key) {
|
|
86
|
+
try {
|
|
87
|
+
const imported = cryptoApi().subtle.importKey('raw', bytes, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
88
|
+
// A failed import is not kept, so a later call tries again.
|
|
89
|
+
imported.catch(() => {
|
|
90
|
+
if (key === imported)
|
|
91
|
+
key = undefined;
|
|
92
|
+
});
|
|
93
|
+
key = imported;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Not kept: a page that gains WebCrypto later is not held to the first answer.
|
|
97
|
+
return Promise.reject(error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return key;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
/** HMAC-SHA256 of the UTF-8 bytes of `data`. */
|
|
@@ -105,7 +107,15 @@ export async function hmac(key, data) {
|
|
|
105
107
|
const mac = await cryptoApi().subtle.sign('HMAC', await key.key, encoder.encode(data));
|
|
106
108
|
return new Uint8Array(mac);
|
|
107
109
|
}
|
|
108
|
-
/**
|
|
110
|
+
/** Unpadded base64url SHA-256 of the UTF-8 bytes of `data` (WebCrypto, Node and browser). */
|
|
111
|
+
export async function sha256Base64url(data) {
|
|
112
|
+
const hash = await cryptoApi().subtle.digest('SHA-256', encoder.encode(data));
|
|
113
|
+
return base64url(new Uint8Array(hash));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A keyed digest; `purpose` keeps an input digest from ever matching an actor digest, and an
|
|
117
|
+
* approver's principal digest from matching either.
|
|
118
|
+
*/
|
|
109
119
|
export function digest(key, purpose, value) {
|
|
110
120
|
return hmac(key, `${purpose}\0${value}`);
|
|
111
121
|
}
|
|
@@ -196,9 +206,8 @@ export function createMemoryNonceStore() {
|
|
|
196
206
|
}
|
|
197
207
|
function cryptoApi() {
|
|
198
208
|
const api = globalThis.crypto;
|
|
199
|
-
if (!api?.subtle)
|
|
200
|
-
throw new
|
|
201
|
-
}
|
|
209
|
+
if (!api?.subtle)
|
|
210
|
+
throw new WebCryptoUnavailableError();
|
|
202
211
|
return api;
|
|
203
212
|
}
|
|
204
213
|
//# sourceMappingURL=approval-crypto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-crypto.js","sourceRoot":"","sources":["../src/approval-crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"approval-crypto.js","sourceRoot":"","sources":["../src/approval-crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACpD,OAAO;QACN,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,GAAG,WAAW,mEAAmE;QAC1F,UAAU,EACT,wYAAwY;QACzY,SAAS,EAAE,KAAK;QAChB,OAAO,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AM;QAAE,MAAM,IAAI,yBAAyB,EAAE,CAAC;IACxD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview What an approval middleware keeps or needs per process, marked on the middleware
|
|
3
|
+
* itself under a registered symbol, so a server built from one installed copy of this package
|
|
4
|
+
* reads it from a middleware made by another copy, and `composeMiddleware` carries its parts'.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether an approval middleware asks over MCP (so the server's `confirmationKey` signs its
|
|
8
|
+
* state), and whether its single-use nonces are kept only in this instance's memory.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApprovalProcessState {
|
|
11
|
+
relay: boolean;
|
|
12
|
+
perProcessNonces: boolean;
|
|
13
|
+
perProcessRelayNonces?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Mark `middleware` with what it keeps per process: non-writable, non-enumerable, permanent. */
|
|
16
|
+
export declare function markApprovalProcessState(middleware: object, state: ApprovalProcessState): void;
|
|
17
|
+
/** The per-process state marked on `middleware` (its own property), if any. */
|
|
18
|
+
export declare function approvalProcessState(middleware: unknown): ApprovalProcessState | undefined;
|
|
19
|
+
/** Mark `composed` with what any of `parts` keeps per process; nothing when none is marked. */
|
|
20
|
+
export declare function carryApprovalProcessState(composed: object, parts: readonly unknown[]): void;
|
|
21
|
+
//# sourceMappingURL=approval-process-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-process-state.d.ts","sourceRoot":"","sources":["../src/approval-process-state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC;AAID,iGAAiG;AACjG,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAE9F;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAI1F;AAED,+FAA+F;AAC/F,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,CAU3F"}
|