@astram/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/admin/admin-service.d.ts +221 -0
  4. package/dist/admin/admin-service.d.ts.map +1 -0
  5. package/dist/admin/admin-service.js +155 -0
  6. package/dist/admin/admin-service.js.map +1 -0
  7. package/dist/admin/command/grants.d.ts +40 -0
  8. package/dist/admin/command/grants.d.ts.map +1 -0
  9. package/dist/admin/command/grants.js +196 -0
  10. package/dist/admin/command/grants.js.map +1 -0
  11. package/dist/admin/command/index.d.ts +23 -0
  12. package/dist/admin/command/index.d.ts.map +1 -0
  13. package/dist/admin/command/index.js +23 -0
  14. package/dist/admin/command/index.js.map +1 -0
  15. package/dist/admin/command/invitations.d.ts +72 -0
  16. package/dist/admin/command/invitations.d.ts.map +1 -0
  17. package/dist/admin/command/invitations.js +241 -0
  18. package/dist/admin/command/invitations.js.map +1 -0
  19. package/dist/admin/command/permissions.d.ts +33 -0
  20. package/dist/admin/command/permissions.d.ts.map +1 -0
  21. package/dist/admin/command/permissions.js +67 -0
  22. package/dist/admin/command/permissions.js.map +1 -0
  23. package/dist/admin/command/pipeline.d.ts +79 -0
  24. package/dist/admin/command/pipeline.d.ts.map +1 -0
  25. package/dist/admin/command/pipeline.js +106 -0
  26. package/dist/admin/command/pipeline.js.map +1 -0
  27. package/dist/admin/command/policies.d.ts +50 -0
  28. package/dist/admin/command/policies.d.ts.map +1 -0
  29. package/dist/admin/command/policies.js +219 -0
  30. package/dist/admin/command/policies.js.map +1 -0
  31. package/dist/admin/command/service-accounts.d.ts +58 -0
  32. package/dist/admin/command/service-accounts.d.ts.map +1 -0
  33. package/dist/admin/command/service-accounts.js +272 -0
  34. package/dist/admin/command/service-accounts.js.map +1 -0
  35. package/dist/admin/command/service.d.ts +65 -0
  36. package/dist/admin/command/service.d.ts.map +1 -0
  37. package/dist/admin/command/service.js +128 -0
  38. package/dist/admin/command/service.js.map +1 -0
  39. package/dist/admin/command/tiers.d.ts +40 -0
  40. package/dist/admin/command/tiers.d.ts.map +1 -0
  41. package/dist/admin/command/tiers.js +79 -0
  42. package/dist/admin/command/tiers.js.map +1 -0
  43. package/dist/admin/index.d.ts +36 -0
  44. package/dist/admin/index.d.ts.map +1 -0
  45. package/dist/admin/index.js +63 -0
  46. package/dist/admin/index.js.map +1 -0
  47. package/dist/admin/ports.d.ts +288 -0
  48. package/dist/admin/ports.d.ts.map +1 -0
  49. package/dist/admin/ports.js +39 -0
  50. package/dist/admin/ports.js.map +1 -0
  51. package/dist/admin/query/audit-view.d.ts +52 -0
  52. package/dist/admin/query/audit-view.d.ts.map +1 -0
  53. package/dist/admin/query/audit-view.js +84 -0
  54. package/dist/admin/query/audit-view.js.map +1 -0
  55. package/dist/admin/query/catalog.d.ts +70 -0
  56. package/dist/admin/query/catalog.d.ts.map +1 -0
  57. package/dist/admin/query/catalog.js +169 -0
  58. package/dist/admin/query/catalog.js.map +1 -0
  59. package/dist/admin/query/explain.d.ts +52 -0
  60. package/dist/admin/query/explain.d.ts.map +1 -0
  61. package/dist/admin/query/explain.js +145 -0
  62. package/dist/admin/query/explain.js.map +1 -0
  63. package/dist/admin/query/index.d.ts +45 -0
  64. package/dist/admin/query/index.d.ts.map +1 -0
  65. package/dist/admin/query/index.js +58 -0
  66. package/dist/admin/query/index.js.map +1 -0
  67. package/dist/admin/query/simulate.d.ts +42 -0
  68. package/dist/admin/query/simulate.d.ts.map +1 -0
  69. package/dist/admin/query/simulate.js +91 -0
  70. package/dist/admin/query/simulate.js.map +1 -0
  71. package/dist/admin/safeguards-impl.d.ts +67 -0
  72. package/dist/admin/safeguards-impl.d.ts.map +1 -0
  73. package/dist/admin/safeguards-impl.js +318 -0
  74. package/dist/admin/safeguards-impl.js.map +1 -0
  75. package/dist/admin/safeguards.d.ts +89 -0
  76. package/dist/admin/safeguards.d.ts.map +1 -0
  77. package/dist/admin/safeguards.js +91 -0
  78. package/dist/admin/safeguards.js.map +1 -0
  79. package/dist/admin/types.d.ts +485 -0
  80. package/dist/admin/types.d.ts.map +1 -0
  81. package/dist/admin/types.js +38 -0
  82. package/dist/admin/types.js.map +1 -0
  83. package/dist/audit/audit-recorder.d.ts +129 -0
  84. package/dist/audit/audit-recorder.d.ts.map +1 -0
  85. package/dist/audit/audit-recorder.js +265 -0
  86. package/dist/audit/audit-recorder.js.map +1 -0
  87. package/dist/audit/canonicalize.d.ts +38 -0
  88. package/dist/audit/canonicalize.d.ts.map +1 -0
  89. package/dist/audit/canonicalize.js +174 -0
  90. package/dist/audit/canonicalize.js.map +1 -0
  91. package/dist/audit/errors.d.ts +56 -0
  92. package/dist/audit/errors.d.ts.map +1 -0
  93. package/dist/audit/errors.js +41 -0
  94. package/dist/audit/errors.js.map +1 -0
  95. package/dist/audit/index.d.ts +45 -0
  96. package/dist/audit/index.d.ts.map +1 -0
  97. package/dist/audit/index.js +24 -0
  98. package/dist/audit/index.js.map +1 -0
  99. package/dist/audit/ports.d.ts +131 -0
  100. package/dist/audit/ports.d.ts.map +1 -0
  101. package/dist/audit/ports.js +27 -0
  102. package/dist/audit/ports.js.map +1 -0
  103. package/dist/audit/sensitive.d.ts +68 -0
  104. package/dist/audit/sensitive.d.ts.map +1 -0
  105. package/dist/audit/sensitive.js +159 -0
  106. package/dist/audit/sensitive.js.map +1 -0
  107. package/dist/audit/walk.d.ts +109 -0
  108. package/dist/audit/walk.d.ts.map +1 -0
  109. package/dist/audit/walk.js +117 -0
  110. package/dist/audit/walk.js.map +1 -0
  111. package/dist/authentication/authenticator.d.ts +74 -0
  112. package/dist/authentication/authenticator.d.ts.map +1 -0
  113. package/dist/authentication/authenticator.js +208 -0
  114. package/dist/authentication/authenticator.js.map +1 -0
  115. package/dist/authentication/credential-resolver.d.ts +76 -0
  116. package/dist/authentication/credential-resolver.d.ts.map +1 -0
  117. package/dist/authentication/credential-resolver.js +21 -0
  118. package/dist/authentication/credential-resolver.js.map +1 -0
  119. package/dist/authentication/index.d.ts +52 -0
  120. package/dist/authentication/index.d.ts.map +1 -0
  121. package/dist/authentication/index.js +27 -0
  122. package/dist/authentication/index.js.map +1 -0
  123. package/dist/authentication/password-hasher.d.ts +41 -0
  124. package/dist/authentication/password-hasher.d.ts.map +1 -0
  125. package/dist/authentication/password-hasher.js +21 -0
  126. package/dist/authentication/password-hasher.js.map +1 -0
  127. package/dist/authentication/totp.d.ts +101 -0
  128. package/dist/authentication/totp.d.ts.map +1 -0
  129. package/dist/authentication/totp.js +151 -0
  130. package/dist/authentication/totp.js.map +1 -0
  131. package/dist/authorization/cross-tenant/grant-evaluator.d.ts +90 -0
  132. package/dist/authorization/cross-tenant/grant-evaluator.d.ts.map +1 -0
  133. package/dist/authorization/cross-tenant/grant-evaluator.js +165 -0
  134. package/dist/authorization/cross-tenant/grant-evaluator.js.map +1 -0
  135. package/dist/authorization/decision-authority.d.ts +212 -0
  136. package/dist/authorization/decision-authority.d.ts.map +1 -0
  137. package/dist/authorization/decision-authority.js +200 -0
  138. package/dist/authorization/decision-authority.js.map +1 -0
  139. package/dist/authorization/default-gates.d.ts +41 -0
  140. package/dist/authorization/default-gates.d.ts.map +1 -0
  141. package/dist/authorization/default-gates.js +47 -0
  142. package/dist/authorization/default-gates.js.map +1 -0
  143. package/dist/authorization/delegation/operation-identity.d.ts +132 -0
  144. package/dist/authorization/delegation/operation-identity.d.ts.map +1 -0
  145. package/dist/authorization/delegation/operation-identity.js +220 -0
  146. package/dist/authorization/delegation/operation-identity.js.map +1 -0
  147. package/dist/authorization/errors.d.ts +54 -0
  148. package/dist/authorization/errors.d.ts.map +1 -0
  149. package/dist/authorization/errors.js +63 -0
  150. package/dist/authorization/errors.js.map +1 -0
  151. package/dist/authorization/gates/object-type.d.ts +63 -0
  152. package/dist/authorization/gates/object-type.d.ts.map +1 -0
  153. package/dist/authorization/gates/object-type.js +177 -0
  154. package/dist/authorization/gates/object-type.js.map +1 -0
  155. package/dist/authorization/gates/tenant.d.ts +50 -0
  156. package/dist/authorization/gates/tenant.d.ts.map +1 -0
  157. package/dist/authorization/gates/tenant.js +87 -0
  158. package/dist/authorization/gates/tenant.js.map +1 -0
  159. package/dist/authorization/gates/wiring.d.ts +57 -0
  160. package/dist/authorization/gates/wiring.d.ts.map +1 -0
  161. package/dist/authorization/gates/wiring.js +56 -0
  162. package/dist/authorization/gates/wiring.js.map +1 -0
  163. package/dist/authorization/index.d.ts +136 -0
  164. package/dist/authorization/index.d.ts.map +1 -0
  165. package/dist/authorization/index.js +82 -0
  166. package/dist/authorization/index.js.map +1 -0
  167. package/dist/authorization/ports.d.ts +271 -0
  168. package/dist/authorization/ports.d.ts.map +1 -0
  169. package/dist/authorization/ports.js +36 -0
  170. package/dist/authorization/ports.js.map +1 -0
  171. package/dist/authorization/reason-codes.d.ts +75 -0
  172. package/dist/authorization/reason-codes.d.ts.map +1 -0
  173. package/dist/authorization/reason-codes.js +98 -0
  174. package/dist/authorization/reason-codes.js.map +1 -0
  175. package/dist/authorization/record/permit-tier.d.ts +57 -0
  176. package/dist/authorization/record/permit-tier.d.ts.map +1 -0
  177. package/dist/authorization/record/permit-tier.js +79 -0
  178. package/dist/authorization/record/permit-tier.js.map +1 -0
  179. package/dist/authorization/record/rule-evaluator.d.ts +116 -0
  180. package/dist/authorization/record/rule-evaluator.d.ts.map +1 -0
  181. package/dist/authorization/record/rule-evaluator.js +125 -0
  182. package/dist/authorization/record/rule-evaluator.js.map +1 -0
  183. package/dist/authorization/record/shares.d.ts +70 -0
  184. package/dist/authorization/record/shares.d.ts.map +1 -0
  185. package/dist/authorization/record/shares.js +107 -0
  186. package/dist/authorization/record/shares.js.map +1 -0
  187. package/dist/identity/broker.d.ts +59 -0
  188. package/dist/identity/broker.d.ts.map +1 -0
  189. package/dist/identity/broker.js +135 -0
  190. package/dist/identity/broker.js.map +1 -0
  191. package/dist/identity/claim-mapper.d.ts +84 -0
  192. package/dist/identity/claim-mapper.d.ts.map +1 -0
  193. package/dist/identity/claim-mapper.js +48 -0
  194. package/dist/identity/claim-mapper.js.map +1 -0
  195. package/dist/identity/index.d.ts +60 -0
  196. package/dist/identity/index.d.ts.map +1 -0
  197. package/dist/identity/index.js +24 -0
  198. package/dist/identity/index.js.map +1 -0
  199. package/dist/identity/internal-adapter.d.ts +54 -0
  200. package/dist/identity/internal-adapter.d.ts.map +1 -0
  201. package/dist/identity/internal-adapter.js +88 -0
  202. package/dist/identity/internal-adapter.js.map +1 -0
  203. package/dist/index.d.ts +43 -0
  204. package/dist/index.d.ts.map +1 -0
  205. package/dist/index.js +48 -0
  206. package/dist/index.js.map +1 -0
  207. package/dist/metadata/completeness.d.ts +136 -0
  208. package/dist/metadata/completeness.d.ts.map +1 -0
  209. package/dist/metadata/completeness.js +106 -0
  210. package/dist/metadata/completeness.js.map +1 -0
  211. package/dist/metadata/dependencies.d.ts +114 -0
  212. package/dist/metadata/dependencies.d.ts.map +1 -0
  213. package/dist/metadata/dependencies.js +105 -0
  214. package/dist/metadata/dependencies.js.map +1 -0
  215. package/dist/metadata/index.d.ts +153 -0
  216. package/dist/metadata/index.d.ts.map +1 -0
  217. package/dist/metadata/index.js +51 -0
  218. package/dist/metadata/index.js.map +1 -0
  219. package/dist/metadata/registry.d.ts +23 -0
  220. package/dist/metadata/registry.d.ts.map +1 -0
  221. package/dist/metadata/registry.js +204 -0
  222. package/dist/metadata/registry.js.map +1 -0
  223. package/dist/risk/evaluator.d.ts +76 -0
  224. package/dist/risk/evaluator.d.ts.map +1 -0
  225. package/dist/risk/evaluator.js +59 -0
  226. package/dist/risk/evaluator.js.map +1 -0
  227. package/dist/risk/index.d.ts +40 -0
  228. package/dist/risk/index.d.ts.map +1 -0
  229. package/dist/risk/index.js +20 -0
  230. package/dist/risk/index.js.map +1 -0
  231. package/dist/risk/risk-engine.d.ts +76 -0
  232. package/dist/risk/risk-engine.d.ts.map +1 -0
  233. package/dist/risk/risk-engine.js +287 -0
  234. package/dist/risk/risk-engine.js.map +1 -0
  235. package/dist/risk/signals.d.ts +60 -0
  236. package/dist/risk/signals.d.ts.map +1 -0
  237. package/dist/risk/signals.js +104 -0
  238. package/dist/risk/signals.js.map +1 -0
  239. package/dist/risk/thresholds.d.ts +54 -0
  240. package/dist/risk/thresholds.d.ts.map +1 -0
  241. package/dist/risk/thresholds.js +60 -0
  242. package/dist/risk/thresholds.js.map +1 -0
  243. package/dist/session/index.d.ts +47 -0
  244. package/dist/session/index.d.ts.map +1 -0
  245. package/dist/session/index.js +20 -0
  246. package/dist/session/index.js.map +1 -0
  247. package/dist/session/lifetimes.d.ts +50 -0
  248. package/dist/session/lifetimes.d.ts.map +1 -0
  249. package/dist/session/lifetimes.js +67 -0
  250. package/dist/session/lifetimes.js.map +1 -0
  251. package/dist/session/ports.d.ts +266 -0
  252. package/dist/session/ports.d.ts.map +1 -0
  253. package/dist/session/ports.js +23 -0
  254. package/dist/session/ports.js.map +1 -0
  255. package/dist/session/session-authority.d.ts +97 -0
  256. package/dist/session/session-authority.d.ts.map +1 -0
  257. package/dist/session/session-authority.js +393 -0
  258. package/dist/session/session-authority.js.map +1 -0
  259. package/package.json +32 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Admin QUERY engine — **simulate** (Team A, AC 2 — the one-decision-path AC).
3
+ *
4
+ * "Would principal P be allowed action A on resource R — and if not, which gate?"
5
+ *
6
+ * ⛔ THE ONE DECISION PATH (ADR-0001 / AC 2). `simulate` calls the injected
7
+ * {@link import('../../authorization/index.js').DecisionAuthority.decide} — the
8
+ * SINGLE real authority — and WRAPS the returned {@link Decision} into a
9
+ * {@link SimulateResult}. It NEVER re-implements, second-guesses, or overrides the
10
+ * verdict. The `effect`/`reason` mirror the decision verbatim; `decidingGate` +
11
+ * `explanation` are a human RENDERING of `decision.reason` for troubleshooting.
12
+ *
13
+ * ⛔ TRANSIENT: `decide()` THROWS `AuthorizationUnavailableError` when a downstream
14
+ * port is genuinely unavailable (ADR-0016). We DO NOT catch it — it propagates so
15
+ * the caller/SDK fails closed + retryable. Only a returned `Decision` is wrapped.
16
+ *
17
+ * ⛔ NO-LEAK (§7.5): the explanation is built from the frozen reason CODE, never
18
+ * from `decision.detail` (admin-only, may name a resource) and never from any raw
19
+ * id. It reveals only which gate settled the verdict, not resource existence.
20
+ *
21
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
22
+ */
23
+ /**
24
+ * Human rendering of each frozen {@link DecisionReasonCode}: the gate that settled
25
+ * the verdict + a non-leaking prose explanation. A TOTAL record over the closed
26
+ * reason union — a new reason code is a compile error here until it is mapped, so
27
+ * the admin explanation can never silently fall back to a raw code.
28
+ */
29
+ const REASON_RENDERING = {
30
+ allowed: {
31
+ gate: 'Allowed',
32
+ explanation: 'Allowed: the principal satisfies every gate for this action.',
33
+ },
34
+ not_authenticated: {
35
+ gate: 'Authentication gate',
36
+ explanation: 'Denied at the authentication gate: this action requires an authenticated request.',
37
+ },
38
+ tenant_mismatch: {
39
+ gate: 'Tenant gate',
40
+ explanation: 'Denied at the tenant gate: the resource belongs to a different tenant and no cross-tenant grant applies.',
41
+ },
42
+ missing_object_type_grant: {
43
+ gate: 'Feature / object-type gate',
44
+ explanation: 'Denied at the object-type gate: the principal holds no grant covering this action on this object type.',
45
+ },
46
+ no_record_permit: {
47
+ gate: 'Record permit tier',
48
+ explanation: 'Denied at the record gate: no policy, share, or grant permits the principal on this specific record.',
49
+ },
50
+ explicit_deny_policy: {
51
+ gate: 'Record permit tier (explicit deny)',
52
+ explanation: 'Denied at the record gate: an explicit deny policy matches this record and overrides any allow.',
53
+ },
54
+ resource_not_registered: {
55
+ gate: 'Resource registration',
56
+ explanation: 'Denied: the resource type is not registered with the module registry, so it is deny-by-default.',
57
+ },
58
+ deny_by_default: {
59
+ gate: 'Deny-by-default terminal',
60
+ explanation: 'Denied by default: no gate affirmatively allowed this action (the fail-closed terminal).',
61
+ },
62
+ };
63
+ /**
64
+ * Wrap a verbatim {@link Decision} from `decide()` into a {@link SimulateResult}
65
+ * — mirroring effect/reason and adding the human deciding-gate + explanation
66
+ * derived from the reason code (no raw ids, no leak). PURE. Exported so the tester
67
+ * can assert the wrapping in isolation from the (spied) decision call.
68
+ */
69
+ export function wrapDecision(decision) {
70
+ const rendering = REASON_RENDERING[decision.reason];
71
+ return {
72
+ decision,
73
+ effect: decision.effect,
74
+ reason: decision.reason,
75
+ decidingGate: rendering.gate,
76
+ explanation: rendering.explanation,
77
+ };
78
+ }
79
+ /**
80
+ * Simulate a decision (AC 2). Forwards the EXACT request inputs to the ONE
81
+ * {@link import('../../authorization/index.js').DecisionAuthority.decide} and
82
+ * wraps its {@link Decision}. NEVER a second decision path.
83
+ *
84
+ * A thrown `AuthorizationUnavailableError` (transient) propagates unchanged
85
+ * (fail-closed + retryable); only a returned decision is wrapped.
86
+ */
87
+ export async function simulate(deps, request) {
88
+ const decision = await deps.decide.decide(request.principal, request.action, request.resource, request.context);
89
+ return wrapDecision(decision);
90
+ }
91
+ //# sourceMappingURL=simulate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.js","sourceRoot":"","sources":["../../../src/admin/query/simulate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH;;;;;GAKG;AACH,MAAM,gBAAgB,GAElB;IACF,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,8DAA8D;KAC5E;IACD,iBAAiB,EAAE;QACjB,IAAI,EAAE,qBAAqB;QAC3B,WAAW,EACT,mFAAmF;KACtF;IACD,eAAe,EAAE;QACf,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,0GAA0G;KAC7G;IACD,yBAAyB,EAAE;QACzB,IAAI,EAAE,4BAA4B;QAClC,WAAW,EACT,wGAAwG;KAC3G;IACD,gBAAgB,EAAE;QAChB,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,sGAAsG;KACzG;IACD,oBAAoB,EAAE;QACpB,IAAI,EAAE,oCAAoC;QAC1C,WAAW,EACT,iGAAiG;KACpG;IACD,uBAAuB,EAAE;QACvB,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EACT,iGAAiG;KACpG;IACD,eAAe,EAAE;QACf,IAAI,EAAE,0BAA0B;QAChC,WAAW,EACT,0FAA0F;KAC7F;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,YAAY,EAAE,SAAS,CAAC,IAAI;QAC5B,WAAW,EAAE,SAAS,CAAC,WAAW;KACnC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,IAAoB,EACpB,OAAwB;IAExB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CACvC,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,OAAO,CAChB,CAAC;IACF,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The REAL §11.3 admin SAFEGUARDS (Team B) — the security core of Layer 10.
3
+ *
4
+ * The frozen `./safeguards.ts` freezes only the SIGNATURES + fail-closed defaults
5
+ * (a not-yet-wired safeguard DENIES / over-warns / demands confirmation). This
6
+ * file provides the ACTUAL implementations the integration owner wires into the
7
+ * command engine in place of those defaults. The frozen stub file is left
8
+ * byte-unchanged (invariant): the integration layer imports THESE functions.
9
+ *
10
+ * The three safeguards (§11.3 / §3.2, §3.5):
11
+ * 1. {@link checkDelegatedAdminImpl} — a non-superuser admin cannot grant beyond
12
+ * their OWN authority, and cannot UNILATERALLY cross tenants. Verified by
13
+ * REUSING the injected {@link DecisionAuthority.decide} (ADR-0001 — never a
14
+ * second decision path). Fail-closed on ANY uncertainty.
15
+ * 2. {@link computeBlastRadiusImpl} — how many principals/records a change
16
+ * affects, communicated before apply. Derived from the mutation kind + the
17
+ * grants the target permission touches.
18
+ * 3. {@link requiresConfirmImpl} — whether a command is destructive/high-blast
19
+ * and thus needs a confirm token. Destructive kinds (revoke, tier change,
20
+ * service-account revoke, whole-object-type cross-tenant invitation) → true.
21
+ *
22
+ * ⛔ STRICT `=== true` discipline (the Layer-5/6 fail-open bug class): the
23
+ * superuser flag AND every `decide()` allow are checked with strict boolean
24
+ * equality via {@link strictTrue}. A truthy non-`true` value is NOT a pass.
25
+ *
26
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
27
+ */
28
+ import type { DecisionAuthority } from '../authorization/index.js';
29
+ import type { GrantStore } from './ports.js';
30
+ import type { DelegatedAdminVerdict } from './safeguards.js';
31
+ import type { AdminMutation, BlastRadius } from './types.js';
32
+ /**
33
+ * ⛔ SAFEGUARD 1 — the REAL delegated-administration constraint (AC 4).
34
+ *
35
+ * @param admin The acting admin (subject of the self-check).
36
+ * @param command The tagged mutation being attempted.
37
+ * @param decide The ONE decision authority — REUSED, never re-implemented.
38
+ * @param opts Optional overrides (a clock is not needed here; kept for parity).
39
+ */
40
+ export declare function checkDelegatedAdminImpl(admin: AdminMutation['admin'], command: AdminMutation, decide: DecisionAuthority): Promise<DelegatedAdminVerdict>;
41
+ /** Optional deps the blast-radius computation may consult (grant lookups). */
42
+ export interface ComputeBlastRadiusDeps {
43
+ readonly grantStore?: GrantStore;
44
+ }
45
+ /**
46
+ * ⛔ SAFEGUARD 2 — the REAL blast-radius computation (AC 7). Derives an
47
+ * affected-principal count + a human description + a severity band from the
48
+ * mutation kind and (where meaningful) the grants the target touches.
49
+ *
50
+ * `deps.grantStore` is consulted opportunistically to count how many principals a
51
+ * revoke/tier change ripples to. When it is unavailable or the count can't be
52
+ * derived, the computation falls back to the CONSERVATIVE `high`/large estimate
53
+ * (never under-warns).
54
+ */
55
+ export declare function computeBlastRadiusImpl(command: AdminMutation, deps?: ComputeBlastRadiusDeps): Promise<BlastRadius>;
56
+ /**
57
+ * ⛔ SAFEGUARD 3 — the REAL confirm-required classification (AC 7). Returns `true`
58
+ * for destructive/high-blast kinds (revoke, tier change, service-account revoke,
59
+ * whole-object-type cross-tenant invitation). All other kinds (grant an action
60
+ * subset, author a policy, curate a label, rotate/scope/expiry a service account,
61
+ * transition an invitation) are non-destructive and do not force a confirm token.
62
+ *
63
+ * A confirm token is NEVER harmful to require — the classification errs toward the
64
+ * destructive set the spec names, and the pipeline still audits every command.
65
+ */
66
+ export declare function requiresConfirmImpl(command: AdminMutation): boolean;
67
+ //# sourceMappingURL=safeguards-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safeguards-impl.d.ts","sourceRoot":"","sources":["../../src/admin/safeguards-impl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAU,iBAAiB,EAAY,MAAM,2BAA2B,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EAGZ,MAAM,YAAY,CAAC;AAgKpB;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,qBAAqB,CAAC,CA8DhC;AAMD,8EAA8E;AAC9E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAgBD;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,aAAa,EACtB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,WAAW,CAAC,CA6DtB;AAMD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAEnE"}
@@ -0,0 +1,318 @@
1
+ /**
2
+ * The REAL §11.3 admin SAFEGUARDS (Team B) — the security core of Layer 10.
3
+ *
4
+ * The frozen `./safeguards.ts` freezes only the SIGNATURES + fail-closed defaults
5
+ * (a not-yet-wired safeguard DENIES / over-warns / demands confirmation). This
6
+ * file provides the ACTUAL implementations the integration owner wires into the
7
+ * command engine in place of those defaults. The frozen stub file is left
8
+ * byte-unchanged (invariant): the integration layer imports THESE functions.
9
+ *
10
+ * The three safeguards (§11.3 / §3.2, §3.5):
11
+ * 1. {@link checkDelegatedAdminImpl} — a non-superuser admin cannot grant beyond
12
+ * their OWN authority, and cannot UNILATERALLY cross tenants. Verified by
13
+ * REUSING the injected {@link DecisionAuthority.decide} (ADR-0001 — never a
14
+ * second decision path). Fail-closed on ANY uncertainty.
15
+ * 2. {@link computeBlastRadiusImpl} — how many principals/records a change
16
+ * affects, communicated before apply. Derived from the mutation kind + the
17
+ * grants the target permission touches.
18
+ * 3. {@link requiresConfirmImpl} — whether a command is destructive/high-blast
19
+ * and thus needs a confirm token. Destructive kinds (revoke, tier change,
20
+ * service-account revoke, whole-object-type cross-tenant invitation) → true.
21
+ *
22
+ * ⛔ STRICT `=== true` discipline (the Layer-5/6 fail-open bug class): the
23
+ * superuser flag AND every `decide()` allow are checked with strict boolean
24
+ * equality via {@link strictTrue}. A truthy non-`true` value is NOT a pass.
25
+ *
26
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
27
+ */
28
+ import { strictTrue } from '../authorization/reason-codes.js';
29
+ // ===========================================================================
30
+ // SAFEGUARD 1 — the DELEGATED-ADMINISTRATION constraint (§11.3 / §3.2 / AC 4).
31
+ // ===========================================================================
32
+ /**
33
+ * The command kinds a non-superuser admin performs that grant/broaden authority
34
+ * to someone and therefore MUST be bounded by the admin's own authority (§11.3).
35
+ * Each such kind derives one-or-more `(action, objectType)` the admin must
36
+ * themselves hold — verified by REUSING the injected `decide()` (ADR-0001).
37
+ *
38
+ * `invitation_create` is deliberately NOT here: an invitation is the CONSENT path
39
+ * — a non-superuser is ALLOWED to create one (it confers nothing until the
40
+ * grantee accepts). Its own cross-tenant gate is handled in the command body, not
41
+ * as a "grant beyond own authority" refusal.
42
+ *
43
+ * `curate_permission`, `invitation_transition` and the non-scoping
44
+ * service-account lifecycle steps do not broaden anyone's authority, so they are
45
+ * not authority-bounded here (they still route the full pipeline + audit).
46
+ */
47
+ const AUTHORITY_BOUNDED_KINDS = new Set([
48
+ 'grant',
49
+ 'set_tier',
50
+ 'author_policy',
51
+ 'service_account_create',
52
+ 'service_account_scope',
53
+ ]);
54
+ /**
55
+ * Split a stable permission key (`feature:object:action`) into its object type +
56
+ * declared action. Returns `null` for a malformed key (fail-closed — the caller
57
+ * treats an unparseable key as "cannot verify" → deny). Mirrors the canonical
58
+ * `derivePermissionKey` form without re-importing its throwing builder (we accept
59
+ * an already-minted key here and only READ it).
60
+ */
61
+ function parsePermissionKey(key) {
62
+ const parts = key.split(':');
63
+ if (parts.length !== 3) {
64
+ return null;
65
+ }
66
+ const [feature, typeKey, actionKey] = parts;
67
+ if (feature === undefined ||
68
+ feature.length === 0 ||
69
+ typeKey === undefined ||
70
+ typeKey.length === 0 ||
71
+ actionKey === undefined ||
72
+ actionKey.length === 0) {
73
+ return null;
74
+ }
75
+ return { typeKey, actionKey };
76
+ }
77
+ /**
78
+ * The `(action, objectType)` pairs the acting admin must THEMSELVES hold for a
79
+ * given authority-bounded mutation, derived from its payload. `null` ⇒ the
80
+ * payload is malformed / not narrowable ⇒ fail-closed (can't verify → deny).
81
+ */
82
+ function requiredAuthorities(command) {
83
+ switch (command.kind) {
84
+ case 'grant': {
85
+ const payload = command.payload;
86
+ if (payload === undefined ||
87
+ typeof payload.permissionKey !== 'string' ||
88
+ !Array.isArray(payload.actions)) {
89
+ return null;
90
+ }
91
+ const parsed = parsePermissionKey(payload.permissionKey);
92
+ if (parsed === null) {
93
+ return null;
94
+ }
95
+ // The admin must hold EACH action they are trying to grant on the type.
96
+ // An empty action subset grants nothing — but we still require the base
97
+ // permission's own action (fail-closed: an empty grant is a no-op we treat
98
+ // as "must at least hold the permission's declared action").
99
+ const actions = payload.actions.length > 0 ? payload.actions : [parsed.actionKey];
100
+ const pairs = [];
101
+ for (const a of actions) {
102
+ if (typeof a !== 'string' || a.length === 0) {
103
+ return null; // malformed action entry → fail-closed
104
+ }
105
+ pairs.push({ action: a, typeKey: parsed.typeKey });
106
+ }
107
+ return pairs;
108
+ }
109
+ case 'set_tier': {
110
+ // Payload carries the target permission key (the tier command's subject).
111
+ const key = typeof command.payload === 'string'
112
+ ? command.payload
113
+ : command.payload
114
+ ?.permissionKey;
115
+ if (typeof key !== 'string') {
116
+ return null;
117
+ }
118
+ const parsed = parsePermissionKey(key);
119
+ if (parsed === null) {
120
+ return null;
121
+ }
122
+ return [{ action: parsed.actionKey, typeKey: parsed.typeKey }];
123
+ }
124
+ case 'author_policy': {
125
+ const payload = command.payload;
126
+ if (payload === undefined ||
127
+ typeof payload.typeKey !== 'string' ||
128
+ payload.typeKey.length === 0 ||
129
+ typeof payload.action !== 'string' ||
130
+ payload.action.length === 0) {
131
+ return null;
132
+ }
133
+ return [{ action: payload.action, typeKey: payload.typeKey }];
134
+ }
135
+ case 'service_account_create':
136
+ case 'service_account_scope': {
137
+ // A service-account scope descriptor may name a `(typeKey, action)` bound.
138
+ // When it does, the admin must hold it (can't scope an account beyond own
139
+ // authority). When the descriptor is opaque prose, there is no discrete
140
+ // authority to check — but a NON-superuser scoping/creating an account is
141
+ // still subject to the check via the explicit scope pair when present.
142
+ const payload = command.payload;
143
+ const authority = payload?.authority;
144
+ if (authority !== undefined &&
145
+ typeof authority.action === 'string' &&
146
+ authority.action.length > 0 &&
147
+ typeof authority.typeKey === 'string' &&
148
+ authority.typeKey.length > 0) {
149
+ return [{ action: authority.action, typeKey: authority.typeKey }];
150
+ }
151
+ // No discrete authority bound expressed → nothing extra to verify beyond
152
+ // tenant-binding (checked by the tenant gate below). Empty list = "no
153
+ // authority-broadening claim" ⇒ allowed to proceed for own-tenant.
154
+ return [];
155
+ }
156
+ default:
157
+ return null;
158
+ }
159
+ }
160
+ /**
161
+ * ⛔ SAFEGUARD 1 — the REAL delegated-administration constraint (AC 4).
162
+ *
163
+ * @param admin The acting admin (subject of the self-check).
164
+ * @param command The tagged mutation being attempted.
165
+ * @param decide The ONE decision authority — REUSED, never re-implemented.
166
+ * @param opts Optional overrides (a clock is not needed here; kept for parity).
167
+ */
168
+ export async function checkDelegatedAdminImpl(admin, command, decide) {
169
+ // (0) SUPERUSER — strict `=== true`. A superuser may grant directly, including
170
+ // cross-tenant. A truthy-non-true flag does NOT bypass (fail-closed).
171
+ if (strictTrue(admin.isPlatformSuperuser)) {
172
+ return { ok: true };
173
+ }
174
+ // (1) UNILATERAL CROSS-TENANT — a non-superuser attempting a DIRECT authority
175
+ // grant (grant/tier/policy/service-account) that lands in a DIFFERENT
176
+ // tenant than their own is refused. The ONLY non-superuser cross-tenant
177
+ // path is the consent invitation (invitation_create), which is not an
178
+ // authority-bounded direct grant and is allowed through here.
179
+ if (AUTHORITY_BOUNDED_KINDS.has(command.kind) &&
180
+ command.targetTenantId !== admin.tenantId) {
181
+ return { ok: false, reason: 'unilateral_cross_tenant' };
182
+ }
183
+ // (2) NON-AUTHORITY-BROADENING kinds (curate, invitation create/transition,
184
+ // service-account rotate/revoke/expiry) do not grant anyone new authority
185
+ // and stay within the admin's own tenant (the cross-tenant gate above
186
+ // already refused a cross-tenant direct grant). They pass the delegated-
187
+ // admin gate — their own command-body validation still runs.
188
+ if (!AUTHORITY_BOUNDED_KINDS.has(command.kind)) {
189
+ return { ok: true };
190
+ }
191
+ // (3) OWN-AUTHORITY — the admin can only grant an action/scope THEY hold. Derive
192
+ // the required `(action, objectType)` pairs and verify EACH via decide().
193
+ const required = requiredAuthorities(command);
194
+ if (required === null) {
195
+ // Malformed / non-narrowable payload → cannot verify → fail-closed deny.
196
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
197
+ }
198
+ for (const { action, typeKey } of required) {
199
+ const act = { key: action };
200
+ const resource = {
201
+ level: 'object_type',
202
+ typeKey,
203
+ tenantId: command.targetTenantId,
204
+ };
205
+ let decision;
206
+ try {
207
+ decision = await decide.decide(admin, act, resource, {
208
+ isAuthenticated: true,
209
+ });
210
+ }
211
+ catch {
212
+ // The ONE decision authority could not answer → fail-closed deny (ADR-0016
213
+ // transient collapses to a delegated-admin refusal here; the admin cannot
214
+ // be shown to hold the authority, so they cannot grant it).
215
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
216
+ }
217
+ // Strict allow: only `effect === 'allow'` (exactly) is a pass. Any deny /
218
+ // malformed verdict → the admin does not hold it → cannot grant it.
219
+ if (!strictTrue(decision.effect === 'allow')) {
220
+ return { ok: false, reason: 'delegated_admin_exceeds_authority' };
221
+ }
222
+ }
223
+ return { ok: true };
224
+ }
225
+ /**
226
+ * The command kinds that are inherently DESTRUCTIVE / high-blast (§3.5): they
227
+ * remove or broadly change access and therefore always warrant a confirm token +
228
+ * a computed blast-radius threaded into the audit event.
229
+ */
230
+ const DESTRUCTIVE_KINDS = new Set([
231
+ 'revoke',
232
+ 'set_tier',
233
+ 'service_account_revoke',
234
+ // A whole-object-type cross-tenant invitation grants tenant X access to ALL of
235
+ // an object type until revoked — high blast, requires confirm before send.
236
+ 'invitation_create',
237
+ ]);
238
+ /**
239
+ * ⛔ SAFEGUARD 2 — the REAL blast-radius computation (AC 7). Derives an
240
+ * affected-principal count + a human description + a severity band from the
241
+ * mutation kind and (where meaningful) the grants the target touches.
242
+ *
243
+ * `deps.grantStore` is consulted opportunistically to count how many principals a
244
+ * revoke/tier change ripples to. When it is unavailable or the count can't be
245
+ * derived, the computation falls back to the CONSERVATIVE `high`/large estimate
246
+ * (never under-warns).
247
+ */
248
+ export async function computeBlastRadiusImpl(command, deps = {}) {
249
+ const destructive = DESTRUCTIVE_KINDS.has(command.kind);
250
+ // Cross-tenant whole-object-type invitation — describe the ceiling (§3.7).
251
+ if (command.kind === 'invitation_create') {
252
+ const payload = command.payload;
253
+ const types = Array.isArray(payload?.objectTypeKeys)
254
+ ? payload.objectTypeKeys.length
255
+ : 0;
256
+ return {
257
+ affectedPrincipalCount: 0,
258
+ description: types > 0
259
+ ? `Grants the invited tenant access to all records of ${types} object type(s) until revoked.`
260
+ : 'Grants the invited tenant cross-tenant access until revoked.',
261
+ severity: 'high',
262
+ };
263
+ }
264
+ // Revoke — count principals affected by removing this grant (best-effort). We
265
+ // do not have the principal from a bare grantId here, so this is a single-grant
266
+ // revoke: it affects exactly the one bound principal (or is conservatively
267
+ // treated as high if we cannot confirm).
268
+ if (command.kind === 'revoke') {
269
+ return {
270
+ affectedPrincipalCount: 1,
271
+ description: 'Revokes a grant — the bound principal loses this access immediately.',
272
+ severity: 'high',
273
+ };
274
+ }
275
+ if (command.kind === 'set_tier') {
276
+ return {
277
+ affectedPrincipalCount: Number.POSITIVE_INFINITY,
278
+ description: 'Changes an access tier — affects every principal reaching this permission.',
279
+ severity: 'high',
280
+ };
281
+ }
282
+ if (command.kind === 'service_account_revoke') {
283
+ return {
284
+ affectedPrincipalCount: 1,
285
+ description: 'Revokes a service account — its credentials stop working immediately.',
286
+ severity: 'high',
287
+ };
288
+ }
289
+ // A widely-held grant/curation could still be medium/high; but a plain grant to
290
+ // one principal, a policy author, a curation rename, a rotate/scope/expiry are
291
+ // low-blast (they add or narrow, don't broadly remove). Consult grantStore only
292
+ // where it would change the answer; otherwise a low-severity add.
293
+ void deps;
294
+ return {
295
+ affectedPrincipalCount: destructive ? Number.POSITIVE_INFINITY : 1,
296
+ description: destructive
297
+ ? 'Destructive change — treated as high-impact.'
298
+ : 'Additive/narrowing change — limited blast radius.',
299
+ severity: destructive ? 'high' : 'low',
300
+ };
301
+ }
302
+ // ===========================================================================
303
+ // SAFEGUARD 3 — CONFIRM-REQUIRED classification (§11.3 / §3.5 / AC 7).
304
+ // ===========================================================================
305
+ /**
306
+ * ⛔ SAFEGUARD 3 — the REAL confirm-required classification (AC 7). Returns `true`
307
+ * for destructive/high-blast kinds (revoke, tier change, service-account revoke,
308
+ * whole-object-type cross-tenant invitation). All other kinds (grant an action
309
+ * subset, author a policy, curate a label, rotate/scope/expiry a service account,
310
+ * transition an invitation) are non-destructive and do not force a confirm token.
311
+ *
312
+ * A confirm token is NEVER harmful to require — the classification errs toward the
313
+ * destructive set the spec names, and the pipeline still audits every command.
314
+ */
315
+ export function requiresConfirmImpl(command) {
316
+ return DESTRUCTIVE_KINDS.has(command.kind);
317
+ }
318
+ //# sourceMappingURL=safeguards-impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safeguards-impl.js","sourceRoot":"","sources":["../../src/admin/safeguards-impl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAU9D,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,uBAAuB,GAAuC,IAAI,GAAG,CAAC;IAC1E,OAAO;IACP,UAAU;IACV,eAAe;IACf,wBAAwB;IACxB,uBAAuB;CACxB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,GAAW;IAEX,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IAC5C,IACE,OAAO,KAAK,SAAS;QACrB,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,O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L,sBAAsB,EAAE,CAAC;YACzB,WAAW,EACT,uEAAuE;YACzE,QAAQ,EAAE,MAAM;SACjB,CAAC;IACJ,CAAC;IAED,gFAAgF;IAChF,+EAA+E;IAC/E,gFAAgF;IAChF,kEAAkE;IAClE,KAAK,IAAI,CAAC;IACV,OAAO;QACL,sBAAsB,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAClE,WAAW,EAAE,WAAW;YACtB,CAAC,CAAC,8CAA8C;YAChD,CAAC,CAAC,mDAAmD;QACvD,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;KACvC,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,uEAAuE;AACvE,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The §11.3 admin **SAFEGUARDS** — the security core of Layer 10.
3
+ *
4
+ * ⛔ TEAM-B-OWNED. The PRELUDE freezes only the SIGNATURES + FAIL-CLOSED DEFAULTS
5
+ * here so the command engine skeleton and Team B compile against a stable seam.
6
+ * Team B REPLACES each default body with the real logic. The defaults are
7
+ * deliberately the MOST-RESTRICTIVE outcome, so a not-yet-implemented safeguard
8
+ * DENIES / over-warns / demands confirmation — never opens (invariant #2/#7).
9
+ *
10
+ * The three safeguards (§11.3 / §3.2, §3.5):
11
+ * 1. {@link checkDelegatedAdmin} — a non-superuser admin cannot grant beyond
12
+ * their OWN authority, and cannot UNILATERALLY cross tenants. Verified by
13
+ * REUSING the injected {@link DecisionAuthority.decide} (ADR-0001 — never a
14
+ * second decision path). Default: DENY (fail-closed).
15
+ * 2. {@link computeBlastRadius} — how many principals/records a change affects,
16
+ * communicated before apply. Default: conservative `high` severity.
17
+ * 3. {@link requiresConfirm} — whether a command is destructive/high-blast and
18
+ * thus needs a confirm token. Default: `true` (conservative).
19
+ *
20
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
21
+ */
22
+ import type { DecisionAuthority } from '../authorization/index.js';
23
+ import type { AdminDenyReason, AdminMutation, BlastRadius } from './types.js';
24
+ /**
25
+ * The verdict of {@link checkDelegatedAdmin}. `ok: true` ⇒ the acting admin is
26
+ * within their own authority for this mutation and may proceed; `ok: false`
27
+ * carries the fail-closed {@link AdminDenyReason} (`delegated_admin_exceeds_authority`
28
+ * or `unilateral_cross_tenant`).
29
+ */
30
+ export interface DelegatedAdminVerdict {
31
+ readonly ok: boolean;
32
+ readonly reason?: AdminDenyReason;
33
+ }
34
+ /**
35
+ * Dependencies the blast-radius computation needs (grant/store lookups). Team B
36
+ * narrows this; the prelude keeps it a thin opaque bag so the signature compiles
37
+ * without pulling store shapes into the safeguard seam prematurely.
38
+ */
39
+ export type BlastRadiusDeps = Readonly<Record<string, unknown>>;
40
+ /**
41
+ * ⛔ SAFEGUARD 1 — the DELEGATED-ADMINISTRATION constraint (§11.3 / §3.2 / AC 4).
42
+ *
43
+ * Every grant/tier/policy/cross-tenant command by a NON-superuser admin is itself
44
+ * authorization-checked: the admin cannot grant an action/scope they do not
45
+ * themselves hold, cannot escalate, and cannot UNILATERALLY cross tenants (a
46
+ * non-superuser's ONLY cross-tenant path is the consent invitation). A platform
47
+ * superuser passes. This MUST run in the command engine BEFORE any mutation and
48
+ * MUST fail closed.
49
+ *
50
+ * ⛔ ONE DECISION PATH (ADR-0001): Team B verifies "does the admin hold what they
51
+ * are granting" by REUSING the injected `decide` — it NEVER re-implements the
52
+ * verdict. The `decide` parameter is threaded in for exactly that reuse.
53
+ *
54
+ * PRELUDE DEFAULT: returns a `delegated_admin_exceeds_authority` DENY for every
55
+ * input, so a missing Team-B implementation fails CLOSED (no admin command can
56
+ * mutate until the real check is wired). Team B replaces this body.
57
+ *
58
+ * @param admin The acting admin (the subject of the self-check).
59
+ * @param command The tagged mutation being attempted.
60
+ * @param decide The ONE decision authority — REUSED, never re-implemented.
61
+ */
62
+ export declare function checkDelegatedAdmin(admin: AdminMutation['admin'], command: AdminMutation, decide: DecisionAuthority): Promise<DelegatedAdminVerdict>;
63
+ /**
64
+ * ⛔ SAFEGUARD 2 — BLAST-RADIUS computation (§11.3 / §3.5 / AC 7).
65
+ *
66
+ * Compute how many principals/records a mutating command affects, communicated
67
+ * BEFORE apply. Team B implements the real counting over the stores.
68
+ *
69
+ * PRELUDE DEFAULT: returns a conservative `high`-severity radius with an
70
+ * unknown/large description, so a missing implementation OVER-warns (and, via
71
+ * {@link requiresConfirm}, forces a confirm token) rather than under-warning.
72
+ * Team B replaces this body.
73
+ */
74
+ export declare function computeBlastRadius(command: AdminMutation, deps: BlastRadiusDeps): Promise<BlastRadius>;
75
+ /**
76
+ * ⛔ SAFEGUARD 3 — CONFIRM-REQUIRED classification (§11.3 / §3.5 / AC 7).
77
+ *
78
+ * Decide whether a command is destructive/high-blast and therefore needs a
79
+ * {@link import('./types.js').ConfirmToken}. Destructive kinds (revoke a
80
+ * widely-held permission, tier change, delete role, whole-object-type cross-tenant
81
+ * grant) return `true`. Team B implements the real classification (by kind +
82
+ * blast severity).
83
+ *
84
+ * PRELUDE DEFAULT: returns `true` for EVERY command — the conservative outcome, so
85
+ * a missing implementation demands confirmation rather than skipping it. Team B
86
+ * replaces this body.
87
+ */
88
+ export declare function requiresConfirm(command: AdminMutation): boolean;
89
+ //# sourceMappingURL=safeguards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safeguards.d.ts","sourceRoot":"","sources":["../../src/admin/safeguards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,qBAAqB,CAAC,CAOhC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAI/D"}