@astram/core 0.1.0 → 1.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.
Files changed (142) hide show
  1. package/dist/admin/admin-service.d.ts +1 -1
  2. package/dist/admin/command/grants.js +3 -3
  3. package/dist/admin/command/grants.js.map +1 -1
  4. package/dist/admin/command/invitations.d.ts +2 -2
  5. package/dist/admin/command/invitations.js +8 -8
  6. package/dist/admin/command/invitations.js.map +1 -1
  7. package/dist/admin/command/service-accounts.d.ts +1 -1
  8. package/dist/admin/command/service-accounts.js +1 -1
  9. package/dist/admin/query/simulate.d.ts.map +1 -1
  10. package/dist/admin/query/simulate.js +4 -0
  11. package/dist/admin/query/simulate.js.map +1 -1
  12. package/dist/admin/safeguards-impl.d.ts +2 -2
  13. package/dist/admin/safeguards-impl.js +9 -9
  14. package/dist/admin/safeguards-impl.js.map +1 -1
  15. package/dist/admin/safeguards.d.ts +4 -4
  16. package/dist/admin/safeguards.js +4 -4
  17. package/dist/admin/types.d.ts +1 -1
  18. package/dist/admin/types.d.ts.map +1 -1
  19. package/dist/authentication/authenticator.d.ts +2 -2
  20. package/dist/authentication/authenticator.js +2 -2
  21. package/dist/authentication/authenticator.js.map +1 -1
  22. package/dist/authentication/credential-resolver.d.ts +1 -1
  23. package/dist/authorization/cross-tenant/grant-evaluator.d.ts +2 -2
  24. package/dist/authorization/cross-tenant/grant-evaluator.js +2 -2
  25. package/dist/authorization/decision-authority.d.ts +2 -2
  26. package/dist/authorization/decision-authority.d.ts.map +1 -1
  27. package/dist/authorization/decision-authority.js +11 -3
  28. package/dist/authorization/decision-authority.js.map +1 -1
  29. package/dist/authorization/errors.d.ts +37 -0
  30. package/dist/authorization/errors.d.ts.map +1 -1
  31. package/dist/authorization/errors.js +43 -0
  32. package/dist/authorization/errors.js.map +1 -1
  33. package/dist/authorization/gates/object-type.d.ts +2 -2
  34. package/dist/authorization/gates/object-type.d.ts.map +1 -1
  35. package/dist/authorization/gates/object-type.js +20 -7
  36. package/dist/authorization/gates/object-type.js.map +1 -1
  37. package/dist/authorization/gates/tenant.d.ts +3 -3
  38. package/dist/authorization/gates/tenant.js +7 -7
  39. package/dist/authorization/gates/tenant.js.map +1 -1
  40. package/dist/authorization/index.d.ts +33 -4
  41. package/dist/authorization/index.d.ts.map +1 -1
  42. package/dist/authorization/index.js +39 -4
  43. package/dist/authorization/index.js.map +1 -1
  44. package/dist/authorization/ports.d.ts +3 -3
  45. package/dist/authorization/reason-codes.d.ts +7 -1
  46. package/dist/authorization/reason-codes.d.ts.map +1 -1
  47. package/dist/authorization/reason-codes.js +9 -1
  48. package/dist/authorization/reason-codes.js.map +1 -1
  49. package/dist/authorization/record/owner-baseline.d.ts +43 -0
  50. package/dist/authorization/record/owner-baseline.d.ts.map +1 -0
  51. package/dist/authorization/record/owner-baseline.js +72 -0
  52. package/dist/authorization/record/owner-baseline.js.map +1 -0
  53. package/dist/authorization/record/permit-tier.d.ts.map +1 -1
  54. package/dist/authorization/record/permit-tier.js +16 -5
  55. package/dist/authorization/record/permit-tier.js.map +1 -1
  56. package/dist/identity/broker.d.ts +8 -8
  57. package/dist/identity/broker.d.ts.map +1 -1
  58. package/dist/identity/broker.js +8 -8
  59. package/dist/identity/broker.js.map +1 -1
  60. package/dist/identity/claim-mapper.d.ts +8 -8
  61. package/dist/identity/claim-mapper.d.ts.map +1 -1
  62. package/dist/identity/claim-mapper.js +4 -4
  63. package/dist/identity/index.d.ts +2 -2
  64. package/dist/identity/index.d.ts.map +1 -1
  65. package/dist/identity/internal-adapter.d.ts +12 -12
  66. package/dist/identity/internal-adapter.d.ts.map +1 -1
  67. package/dist/identity/internal-adapter.js +9 -9
  68. package/dist/identity/internal-adapter.js.map +1 -1
  69. package/dist/metadata/index.d.ts +43 -0
  70. package/dist/metadata/index.d.ts.map +1 -1
  71. package/dist/metadata/index.js +6 -0
  72. package/dist/metadata/index.js.map +1 -1
  73. package/dist/metadata/registry.d.ts.map +1 -1
  74. package/dist/metadata/registry.js +2 -1
  75. package/dist/metadata/registry.js.map +1 -1
  76. package/dist-cjs/admin/admin-service.js +159 -0
  77. package/dist-cjs/admin/command/grants.js +200 -0
  78. package/dist-cjs/admin/command/index.js +38 -0
  79. package/dist-cjs/admin/command/invitations.js +246 -0
  80. package/dist-cjs/admin/command/permissions.js +69 -0
  81. package/dist-cjs/admin/command/pipeline.js +110 -0
  82. package/dist-cjs/admin/command/policies.js +223 -0
  83. package/dist-cjs/admin/command/service-accounts.js +278 -0
  84. package/dist-cjs/admin/command/service.js +130 -0
  85. package/dist-cjs/admin/command/tiers.js +81 -0
  86. package/dist-cjs/admin/index.js +78 -0
  87. package/dist-cjs/admin/ports.js +41 -0
  88. package/dist-cjs/admin/query/audit-view.js +88 -0
  89. package/dist-cjs/admin/query/catalog.js +174 -0
  90. package/dist-cjs/admin/query/explain.js +149 -0
  91. package/dist-cjs/admin/query/index.js +74 -0
  92. package/dist-cjs/admin/query/simulate.js +98 -0
  93. package/dist-cjs/admin/safeguards-impl.js +322 -0
  94. package/dist-cjs/admin/safeguards.js +95 -0
  95. package/dist-cjs/admin/types.js +40 -0
  96. package/dist-cjs/audit/audit-recorder.js +269 -0
  97. package/dist-cjs/audit/canonicalize.js +176 -0
  98. package/dist-cjs/audit/errors.js +44 -0
  99. package/dist-cjs/audit/index.js +39 -0
  100. package/dist-cjs/audit/ports.js +27 -0
  101. package/dist-cjs/audit/sensitive.js +162 -0
  102. package/dist-cjs/audit/walk.js +123 -0
  103. package/dist-cjs/authentication/authenticator.js +210 -0
  104. package/dist-cjs/authentication/credential-resolver.js +21 -0
  105. package/dist-cjs/authentication/index.js +42 -0
  106. package/dist-cjs/authentication/password-hasher.js +21 -0
  107. package/dist-cjs/authentication/totp.js +155 -0
  108. package/dist-cjs/authorization/cross-tenant/grant-evaluator.js +167 -0
  109. package/dist-cjs/authorization/decision-authority.js +213 -0
  110. package/dist-cjs/authorization/default-gates.js +53 -0
  111. package/dist-cjs/authorization/delegation/operation-identity.js +226 -0
  112. package/dist-cjs/authorization/errors.js +110 -0
  113. package/dist-cjs/authorization/gates/object-type.js +192 -0
  114. package/dist-cjs/authorization/gates/tenant.js +89 -0
  115. package/dist-cjs/authorization/gates/wiring.js +59 -0
  116. package/dist-cjs/authorization/index.js +134 -0
  117. package/dist-cjs/authorization/ports.js +36 -0
  118. package/dist-cjs/authorization/reason-codes.js +117 -0
  119. package/dist-cjs/authorization/record/owner-baseline.js +74 -0
  120. package/dist-cjs/authorization/record/permit-tier.js +92 -0
  121. package/dist-cjs/authorization/record/rule-evaluator.js +128 -0
  122. package/dist-cjs/authorization/record/shares.js +110 -0
  123. package/dist-cjs/identity/broker.js +139 -0
  124. package/dist-cjs/identity/claim-mapper.js +51 -0
  125. package/dist-cjs/identity/index.js +39 -0
  126. package/dist-cjs/identity/internal-adapter.js +91 -0
  127. package/dist-cjs/index.js +63 -0
  128. package/dist-cjs/metadata/completeness.js +108 -0
  129. package/dist-cjs/metadata/dependencies.js +110 -0
  130. package/dist-cjs/metadata/index.js +76 -0
  131. package/dist-cjs/metadata/registry.js +207 -0
  132. package/dist-cjs/package.json +3 -0
  133. package/dist-cjs/risk/evaluator.js +63 -0
  134. package/dist-cjs/risk/index.js +35 -0
  135. package/dist-cjs/risk/risk-engine.js +290 -0
  136. package/dist-cjs/risk/signals.js +106 -0
  137. package/dist-cjs/risk/thresholds.js +63 -0
  138. package/dist-cjs/session/index.js +35 -0
  139. package/dist-cjs/session/lifetimes.js +70 -0
  140. package/dist-cjs/session/ports.js +23 -0
  141. package/dist-cjs/session/session-authority.js +398 -0
  142. package/package.json +13 -10
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ /**
3
+ * The REAL §11.3 admin SAFEGUARDS (Team B) — the security core of Layer 10.
4
+ *
5
+ * The frozen `./safeguards.ts` freezes only the SIGNATURES + fail-closed defaults
6
+ * (a not-yet-wired safeguard DENIES / over-warns / demands confirmation). This
7
+ * file provides the ACTUAL implementations the integration owner wires into the
8
+ * command engine in place of those defaults. The frozen stub file is left
9
+ * byte-unchanged (invariant): the integration layer imports THESE functions.
10
+ *
11
+ * The three safeguards (§11.3 / §3.2, §3.5):
12
+ * 1. {@link checkDelegatedAdminImpl} — a non-root admin cannot grant beyond
13
+ * their OWN authority, and cannot UNILATERALLY cross tenants. Verified by
14
+ * REUSING the injected {@link DecisionAuthority.decide} (ADR-0001 — never a
15
+ * second decision path). Fail-closed on ANY uncertainty.
16
+ * 2. {@link computeBlastRadiusImpl} — how many principals/records a change
17
+ * affects, communicated before apply. Derived from the mutation kind + the
18
+ * grants the target permission touches.
19
+ * 3. {@link requiresConfirmImpl} — whether a command is destructive/high-blast
20
+ * and thus needs a confirm token. Destructive kinds (revoke, tier change,
21
+ * service-account revoke, whole-object-type cross-tenant invitation) → true.
22
+ *
23
+ * ⛔ STRICT `=== true` discipline (the Layer-5/6 fail-open bug class): the
24
+ * root flag AND every `decide()` allow are checked with strict boolean
25
+ * equality via {@link strictTrue}. A truthy non-`true` value is NOT a pass.
26
+ *
27
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.checkDelegatedAdminImpl = checkDelegatedAdminImpl;
31
+ exports.computeBlastRadiusImpl = computeBlastRadiusImpl;
32
+ exports.requiresConfirmImpl = requiresConfirmImpl;
33
+ const reason_codes_js_1 = require("../authorization/reason-codes.js");
34
+ // ===========================================================================
35
+ // SAFEGUARD 1 — the DELEGATED-ADMINISTRATION constraint (§11.3 / §3.2 / AC 4).
36
+ // ===========================================================================
37
+ /**
38
+ * The command kinds a non-root admin performs that grant/broaden authority
39
+ * to someone and therefore MUST be bounded by the admin's own authority (§11.3).
40
+ * Each such kind derives one-or-more `(action, objectType)` the admin must
41
+ * themselves hold — verified by REUSING the injected `decide()` (ADR-0001).
42
+ *
43
+ * `invitation_create` is deliberately NOT here: an invitation is the CONSENT path
44
+ * — a non-root is ALLOWED to create one (it confers nothing until the
45
+ * grantee accepts). Its own cross-tenant gate is handled in the command body, not
46
+ * as a "grant beyond own authority" refusal.
47
+ *
48
+ * `curate_permission`, `invitation_transition` and the non-scoping
49
+ * service-account lifecycle steps do not broaden anyone's authority, so they are
50
+ * not authority-bounded here (they still route the full pipeline + audit).
51
+ */
52
+ const AUTHORITY_BOUNDED_KINDS = new Set([
53
+ 'grant',
54
+ 'set_tier',
55
+ 'author_policy',
56
+ 'service_account_create',
57
+ 'service_account_scope',
58
+ ]);
59
+ /**
60
+ * Split a stable permission key (`feature:object:action`) into its object type +
61
+ * declared action. Returns `null` for a malformed key (fail-closed — the caller
62
+ * treats an unparseable key as "cannot verify" → deny). Mirrors the canonical
63
+ * `derivePermissionKey` form without re-importing its throwing builder (we accept
64
+ * an already-minted key here and only READ it).
65
+ */
66
+ function parsePermissionKey(key) {
67
+ const parts = key.split(':');
68
+ if (parts.length !== 3) {
69
+ return null;
70
+ }
71
+ const [feature, typeKey, actionKey] = parts;
72
+ if (feature === undefined ||
73
+ feature.length === 0 ||
74
+ typeKey === undefined ||
75
+ typeKey.length === 0 ||
76
+ actionKey === undefined ||
77
+ actionKey.length === 0) {
78
+ return null;
79
+ }
80
+ return { typeKey, actionKey };
81
+ }
82
+ /**
83
+ * The `(action, objectType)` pairs the acting admin must THEMSELVES hold for a
84
+ * given authority-bounded mutation, derived from its payload. `null` ⇒ the
85
+ * payload is malformed / not narrowable ⇒ fail-closed (can't verify → deny).
86
+ */
87
+ function requiredAuthorities(command) {
88
+ switch (command.kind) {
89
+ case 'grant': {
90
+ const payload = command.payload;
91
+ if (payload === undefined ||
92
+ typeof payload.permissionKey !== 'string' ||
93
+ !Array.isArray(payload.actions)) {
94
+ return null;
95
+ }
96
+ const parsed = parsePermissionKey(payload.permissionKey);
97
+ if (parsed === null) {
98
+ return null;
99
+ }
100
+ // The admin must hold EACH action they are trying to grant on the type.
101
+ // An empty action subset grants nothing — but we still require the base
102
+ // permission's own action (fail-closed: an empty grant is a no-op we treat
103
+ // as "must at least hold the permission's declared action").
104
+ const actions = payload.actions.length > 0 ? payload.actions : [parsed.actionKey];
105
+ const pairs = [];
106
+ for (const a of actions) {
107
+ if (typeof a !== 'string' || a.length === 0) {
108
+ return null; // malformed action entry → fail-closed
109
+ }
110
+ pairs.push({ action: a, typeKey: parsed.typeKey });
111
+ }
112
+ return pairs;
113
+ }
114
+ case 'set_tier': {
115
+ // Payload carries the target permission key (the tier command's subject).
116
+ const key = typeof command.payload === 'string'
117
+ ? command.payload
118
+ : command.payload
119
+ ?.permissionKey;
120
+ if (typeof key !== 'string') {
121
+ return null;
122
+ }
123
+ const parsed = parsePermissionKey(key);
124
+ if (parsed === null) {
125
+ return null;
126
+ }
127
+ return [{ action: parsed.actionKey, typeKey: parsed.typeKey }];
128
+ }
129
+ case 'author_policy': {
130
+ const payload = command.payload;
131
+ if (payload === undefined ||
132
+ typeof payload.typeKey !== 'string' ||
133
+ payload.typeKey.length === 0 ||
134
+ typeof payload.action !== 'string' ||
135
+ payload.action.length === 0) {
136
+ return null;
137
+ }
138
+ return [{ action: payload.action, typeKey: payload.typeKey }];
139
+ }
140
+ case 'service_account_create':
141
+ case 'service_account_scope': {
142
+ // A service-account scope descriptor may name a `(typeKey, action)` bound.
143
+ // When it does, the admin must hold it (can't scope an account beyond own
144
+ // authority). When the descriptor is opaque prose, there is no discrete
145
+ // authority to check — but a NON-root scoping/creating an account is
146
+ // still subject to the check via the explicit scope pair when present.
147
+ const payload = command.payload;
148
+ const authority = payload?.authority;
149
+ if (authority !== undefined &&
150
+ typeof authority.action === 'string' &&
151
+ authority.action.length > 0 &&
152
+ typeof authority.typeKey === 'string' &&
153
+ authority.typeKey.length > 0) {
154
+ return [{ action: authority.action, typeKey: authority.typeKey }];
155
+ }
156
+ // No discrete authority bound expressed → nothing extra to verify beyond
157
+ // tenant-binding (checked by the tenant gate below). Empty list = "no
158
+ // authority-broadening claim" ⇒ allowed to proceed for own-tenant.
159
+ return [];
160
+ }
161
+ default:
162
+ return null;
163
+ }
164
+ }
165
+ /**
166
+ * ⛔ SAFEGUARD 1 — the REAL delegated-administration constraint (AC 4).
167
+ *
168
+ * @param admin The acting admin (subject of the self-check).
169
+ * @param command The tagged mutation being attempted.
170
+ * @param decide The ONE decision authority — REUSED, never re-implemented.
171
+ * @param opts Optional overrides (a clock is not needed here; kept for parity).
172
+ */
173
+ async function checkDelegatedAdminImpl(admin, command, decide) {
174
+ // (0) ROOT — strict `=== true`. A root may grant directly, including
175
+ // cross-tenant. A truthy-non-true flag does NOT bypass (fail-closed).
176
+ if ((0, reason_codes_js_1.strictTrue)(admin.isRoot)) {
177
+ return { ok: true };
178
+ }
179
+ // (1) UNILATERAL CROSS-TENANT — a non-root attempting a DIRECT authority
180
+ // grant (grant/tier/policy/service-account) that lands in a DIFFERENT
181
+ // tenant than their own is refused. The ONLY non-root cross-tenant
182
+ // path is the consent invitation (invitation_create), which is not an
183
+ // authority-bounded direct grant and is allowed through here.
184
+ if (AUTHORITY_BOUNDED_KINDS.has(command.kind) &&
185
+ command.targetTenantId !== admin.tenantId) {
186
+ return { ok: false, reason: 'unilateral_cross_tenant' };
187
+ }
188
+ // (2) NON-AUTHORITY-BROADENING kinds (curate, invitation create/transition,
189
+ // service-account rotate/revoke/expiry) do not grant anyone new authority
190
+ // and stay within the admin's own tenant (the cross-tenant gate above
191
+ // already refused a cross-tenant direct grant). They pass the delegated-
192
+ // admin gate — their own command-body validation still runs.
193
+ if (!AUTHORITY_BOUNDED_KINDS.has(command.kind)) {
194
+ return { ok: true };
195
+ }
196
+ // (3) OWN-AUTHORITY — the admin can only grant an action/scope THEY hold. Derive
197
+ // the required `(action, objectType)` pairs and verify EACH via decide().
198
+ const required = requiredAuthorities(command);
199
+ if (required === null) {
200
+ // Malformed / non-narrowable payload → cannot verify → fail-closed deny.
201
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
202
+ }
203
+ for (const { action, typeKey } of required) {
204
+ const act = { key: action };
205
+ const resource = {
206
+ level: 'object_type',
207
+ typeKey,
208
+ tenantId: command.targetTenantId,
209
+ };
210
+ let decision;
211
+ try {
212
+ decision = await decide.decide(admin, act, resource, {
213
+ isAuthenticated: true,
214
+ });
215
+ }
216
+ catch {
217
+ // The ONE decision authority could not answer → fail-closed deny (ADR-0016
218
+ // transient collapses to a delegated-admin refusal here; the admin cannot
219
+ // be shown to hold the authority, so they cannot grant it).
220
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
221
+ }
222
+ // Strict allow: only `effect === 'allow'` (exactly) is a pass. Any deny /
223
+ // malformed verdict → the admin does not hold it → cannot grant it.
224
+ if (!(0, reason_codes_js_1.strictTrue)(decision.effect === 'allow')) {
225
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
226
+ }
227
+ }
228
+ return { ok: true };
229
+ }
230
+ /**
231
+ * The command kinds that are inherently DESTRUCTIVE / high-blast (§3.5): they
232
+ * remove or broadly change access and therefore always warrant a confirm token +
233
+ * a computed blast-radius threaded into the audit event.
234
+ */
235
+ const DESTRUCTIVE_KINDS = new Set([
236
+ 'revoke',
237
+ 'set_tier',
238
+ 'service_account_revoke',
239
+ // A whole-object-type cross-tenant invitation grants tenant X access to ALL of
240
+ // an object type until revoked — high blast, requires confirm before send.
241
+ 'invitation_create',
242
+ ]);
243
+ /**
244
+ * ⛔ SAFEGUARD 2 — the REAL blast-radius computation (AC 7). Derives an
245
+ * affected-principal count + a human description + a severity band from the
246
+ * mutation kind and (where meaningful) the grants the target touches.
247
+ *
248
+ * `deps.grantStore` is consulted opportunistically to count how many principals a
249
+ * revoke/tier change ripples to. When it is unavailable or the count can't be
250
+ * derived, the computation falls back to the CONSERVATIVE `high`/large estimate
251
+ * (never under-warns).
252
+ */
253
+ async function computeBlastRadiusImpl(command, deps = {}) {
254
+ const destructive = DESTRUCTIVE_KINDS.has(command.kind);
255
+ // Cross-tenant whole-object-type invitation — describe the ceiling (§3.7).
256
+ if (command.kind === 'invitation_create') {
257
+ const payload = command.payload;
258
+ const types = Array.isArray(payload?.objectTypeKeys)
259
+ ? payload.objectTypeKeys.length
260
+ : 0;
261
+ return {
262
+ affectedPrincipalCount: 0,
263
+ description: types > 0
264
+ ? `Grants the invited tenant access to all records of ${types} object type(s) until revoked.`
265
+ : 'Grants the invited tenant cross-tenant access until revoked.',
266
+ severity: 'high',
267
+ };
268
+ }
269
+ // Revoke — count principals affected by removing this grant (best-effort). We
270
+ // do not have the principal from a bare grantId here, so this is a single-grant
271
+ // revoke: it affects exactly the one bound principal (or is conservatively
272
+ // treated as high if we cannot confirm).
273
+ if (command.kind === 'revoke') {
274
+ return {
275
+ affectedPrincipalCount: 1,
276
+ description: 'Revokes a grant — the bound principal loses this access immediately.',
277
+ severity: 'high',
278
+ };
279
+ }
280
+ if (command.kind === 'set_tier') {
281
+ return {
282
+ affectedPrincipalCount: Number.POSITIVE_INFINITY,
283
+ description: 'Changes an access tier — affects every principal reaching this permission.',
284
+ severity: 'high',
285
+ };
286
+ }
287
+ if (command.kind === 'service_account_revoke') {
288
+ return {
289
+ affectedPrincipalCount: 1,
290
+ description: 'Revokes a service account — its credentials stop working immediately.',
291
+ severity: 'high',
292
+ };
293
+ }
294
+ // A widely-held grant/curation could still be medium/high; but a plain grant to
295
+ // one principal, a policy author, a curation rename, a rotate/scope/expiry are
296
+ // low-blast (they add or narrow, don't broadly remove). Consult grantStore only
297
+ // where it would change the answer; otherwise a low-severity add.
298
+ void deps;
299
+ return {
300
+ affectedPrincipalCount: destructive ? Number.POSITIVE_INFINITY : 1,
301
+ description: destructive
302
+ ? 'Destructive change — treated as high-impact.'
303
+ : 'Additive/narrowing change — limited blast radius.',
304
+ severity: destructive ? 'high' : 'low',
305
+ };
306
+ }
307
+ // ===========================================================================
308
+ // SAFEGUARD 3 — CONFIRM-REQUIRED classification (§11.3 / §3.5 / AC 7).
309
+ // ===========================================================================
310
+ /**
311
+ * ⛔ SAFEGUARD 3 — the REAL confirm-required classification (AC 7). Returns `true`
312
+ * for destructive/high-blast kinds (revoke, tier change, service-account revoke,
313
+ * whole-object-type cross-tenant invitation). All other kinds (grant an action
314
+ * subset, author a policy, curate a label, rotate/scope/expiry a service account,
315
+ * transition an invitation) are non-destructive and do not force a confirm token.
316
+ *
317
+ * A confirm token is NEVER harmful to require — the classification errs toward the
318
+ * destructive set the spec names, and the pipeline still audits every command.
319
+ */
320
+ function requiresConfirmImpl(command) {
321
+ return DESTRUCTIVE_KINDS.has(command.kind);
322
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /**
3
+ * The §11.3 admin **SAFEGUARDS** — the security core of Layer 10.
4
+ *
5
+ * ⛔ TEAM-B-OWNED. The PRELUDE freezes only the SIGNATURES + FAIL-CLOSED DEFAULTS
6
+ * here so the command engine skeleton and Team B compile against a stable seam.
7
+ * Team B REPLACES each default body with the real logic. The defaults are
8
+ * deliberately the MOST-RESTRICTIVE outcome, so a not-yet-implemented safeguard
9
+ * DENIES / over-warns / demands confirmation — never opens (invariant #2/#7).
10
+ *
11
+ * The three safeguards (§11.3 / §3.2, §3.5):
12
+ * 1. {@link checkDelegatedAdmin} — a non-root admin cannot grant beyond
13
+ * their OWN authority, and cannot UNILATERALLY cross tenants. Verified by
14
+ * REUSING the injected {@link DecisionAuthority.decide} (ADR-0001 — never a
15
+ * second decision path). Default: DENY (fail-closed).
16
+ * 2. {@link computeBlastRadius} — how many principals/records a change affects,
17
+ * communicated before apply. Default: conservative `high` severity.
18
+ * 3. {@link requiresConfirm} — whether a command is destructive/high-blast and
19
+ * thus needs a confirm token. Default: `true` (conservative).
20
+ *
21
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.checkDelegatedAdmin = checkDelegatedAdmin;
25
+ exports.computeBlastRadius = computeBlastRadius;
26
+ exports.requiresConfirm = requiresConfirm;
27
+ /**
28
+ * ⛔ SAFEGUARD 1 — the DELEGATED-ADMINISTRATION constraint (§11.3 / §3.2 / AC 4).
29
+ *
30
+ * Every grant/tier/policy/cross-tenant command by a NON-root admin is itself
31
+ * authorization-checked: the admin cannot grant an action/scope they do not
32
+ * themselves hold, cannot escalate, and cannot UNILATERALLY cross tenants (a
33
+ * non-root's ONLY cross-tenant path is the consent invitation). A root
34
+ * passes. This MUST run in the command engine BEFORE any mutation and
35
+ * MUST fail closed.
36
+ *
37
+ * ⛔ ONE DECISION PATH (ADR-0001): Team B verifies "does the admin hold what they
38
+ * are granting" by REUSING the injected `decide` — it NEVER re-implements the
39
+ * verdict. The `decide` parameter is threaded in for exactly that reuse.
40
+ *
41
+ * PRELUDE DEFAULT: returns a `delegated_admin_exceeds_authority` DENY for every
42
+ * input, so a missing Team-B implementation fails CLOSED (no admin command can
43
+ * mutate until the real check is wired). Team B replaces this body.
44
+ *
45
+ * @param admin The acting admin (the subject of the self-check).
46
+ * @param command The tagged mutation being attempted.
47
+ * @param decide The ONE decision authority — REUSED, never re-implemented.
48
+ */
49
+ async function checkDelegatedAdmin(admin, command, decide) {
50
+ // Params named for the real signature but unused in the fail-closed stub.
51
+ void admin;
52
+ void command;
53
+ void decide;
54
+ // FAIL CLOSED: until Team B implements the real §11.3 constraint, deny.
55
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
56
+ }
57
+ /**
58
+ * ⛔ SAFEGUARD 2 — BLAST-RADIUS computation (§11.3 / §3.5 / AC 7).
59
+ *
60
+ * Compute how many principals/records a mutating command affects, communicated
61
+ * BEFORE apply. Team B implements the real counting over the stores.
62
+ *
63
+ * PRELUDE DEFAULT: returns a conservative `high`-severity radius with an
64
+ * unknown/large description, so a missing implementation OVER-warns (and, via
65
+ * {@link requiresConfirm}, forces a confirm token) rather than under-warning.
66
+ * Team B replaces this body.
67
+ */
68
+ async function computeBlastRadius(command, deps) {
69
+ void command;
70
+ void deps;
71
+ // CONSERVATIVE DEFAULT: assume high impact until Team B computes the real one.
72
+ return {
73
+ affectedPrincipalCount: Number.POSITIVE_INFINITY,
74
+ description: 'Blast radius not yet computed — treated as high-impact (fail-closed default).',
75
+ severity: 'high',
76
+ };
77
+ }
78
+ /**
79
+ * ⛔ SAFEGUARD 3 — CONFIRM-REQUIRED classification (§11.3 / §3.5 / AC 7).
80
+ *
81
+ * Decide whether a command is destructive/high-blast and therefore needs a
82
+ * {@link import('./types.js').ConfirmToken}. Destructive kinds (revoke a
83
+ * widely-held permission, tier change, delete role, whole-object-type cross-tenant
84
+ * grant) return `true`. Team B implements the real classification (by kind +
85
+ * blast severity).
86
+ *
87
+ * PRELUDE DEFAULT: returns `true` for EVERY command — the conservative outcome, so
88
+ * a missing implementation demands confirmation rather than skipping it. Team B
89
+ * replaces this body.
90
+ */
91
+ function requiresConfirm(command) {
92
+ void command;
93
+ // CONSERVATIVE DEFAULT: require confirmation until Team B classifies precisely.
94
+ return true;
95
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Admin Console — the shared **query + command types** (Layer 10).
4
+ *
5
+ * These are the types the admin QUERY engine (Team A), the admin COMMAND engine
6
+ * (Team B), the SDK admin surface, and the React console (Team C) all speak. The
7
+ * prelude freezes them; the teams fill the engine bodies against them.
8
+ *
9
+ * ⛔ TWO INVARIANTS ARE BAKED INTO THESE SHAPES (ADR-0012 / §13.4, §3):
10
+ * 1. **No raw identifiers in any query OUTPUT.** Every user-facing field carries
11
+ * a resolved human **label**, never a route/path/uuid. Opaque ids appear only
12
+ * in command INPUTS and non-user-facing correlation fields (documented as
13
+ * such). The {@link import('./ports.js').LabelResolver} port is the
14
+ * id→label chokepoint; output types below carry the label, not the id.
15
+ * 2. **Guided builder only — no raw expressions.** A policy is authored as a
16
+ * structured {@link GuidedPolicy} (field → operator → value); there is NO
17
+ * raw-string / raw-expression field ANYWHERE in these types by design, so a
18
+ * raw condition literally cannot be represented (ADR-0012 / §3.4).
19
+ *
20
+ * The **one decision path** is preserved by shape too: {@link SimulateResult}
21
+ * WRAPS the real {@link Decision} produced by the injected
22
+ * {@link DecisionAuthority.decide} — the admin layer never re-derives a verdict
23
+ * (ADR-0001 / §3.1).
24
+ *
25
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.INVITATION_TRANSITIONS = void 0;
29
+ /**
30
+ * The allowed invitation state transitions (§10bis) — the single source of truth
31
+ * the command engine's transition validator checks against, so the state machine
32
+ * can't drift. A transition NOT listed here is rejected `invalid_transition`.
33
+ */
34
+ exports.INVITATION_TRANSITIONS = {
35
+ pending: ['accepted', 'denied', 'expired', 'revoked'],
36
+ accepted: ['revoked', 'expired'],
37
+ denied: [],
38
+ expired: [],
39
+ revoked: [],
40
+ };