@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,47 @@
1
+ /**
2
+ * PRELUDE DEFAULT GATES — trivial, fail-closed placeholders for the four seam gate
3
+ * functions (gates 3/5/6/7) so `createDecisionAuthority(...)` compiles and the
4
+ * prelude's own guarantees are testable NOW, BEFORE Teams A/B/C/D ship the real
5
+ * evaluators.
6
+ *
7
+ * ⛔ These are DELIBERATELY the most conservative possible bodies — deny-by-default
8
+ * everywhere (the tenant gate `continue`s ONLY so the pipeline can be exercised
9
+ * end-to-end; every other gate denies). They implement NO real authorization logic.
10
+ * The integration owner REPLACES each with the corresponding team's evaluator when
11
+ * wiring the real `DecisionAuthorityDeps.gates`.
12
+ *
13
+ * - `defaultTenantGate` → `continue` (same-tenant assumption for the skeleton
14
+ * ONLY; TEAM A/C replace it with the real tenant + cross-tenant-grant gate).
15
+ * - `defaultObjectTypeGate` → `deny(deny_by_default)` (TEAM A replaces).
16
+ * - `defaultRecordPermit` → `deny(deny_by_default)` (TEAM B/C replace).
17
+ * - `defaultDelegationOverlay` → `continue` (pass-through: baseline stands;
18
+ * TEAM D replaces with the real delegation overlay).
19
+ *
20
+ * A default-wired authority therefore DENIES every gated/authenticated request
21
+ * (fail-closed) except the pure short-circuits the pipeline owns (public tier,
22
+ * authenticated_global) — exactly what a not-yet-filled authority must do.
23
+ *
24
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
25
+ */
26
+ import { gateContinue, gateDeny, } from './decision-authority.js';
27
+ import { denyByDefault } from './reason-codes.js';
28
+ /** Prelude default: let evaluation PROCEED past the tenant gate (skeleton only). */
29
+ export const defaultTenantGate = async () => gateContinue();
30
+ /** Prelude default: DENY at the feature/object-type gate (fail-closed until TEAM A). */
31
+ export const defaultObjectTypeGate = async () => gateDeny(denyByDefault());
32
+ /** Prelude default: DENY at the record permit tier (fail-closed until TEAM B/C). */
33
+ export const defaultRecordPermit = async () => gateDeny(denyByDefault());
34
+ /** Prelude default: pass-through delegation overlay (baseline stands until TEAM D). */
35
+ export const defaultDelegationOverlay = async () => gateContinue();
36
+ /**
37
+ * The complete deny-by-default gate set — inject this as `DecisionAuthorityDeps.gates`
38
+ * to get a compiling, fail-closed authority the prelude tests exercise. Teams replace
39
+ * each member with the real evaluator at integration.
40
+ */
41
+ export const DEFAULT_DENY_BY_DEFAULT_GATES = Object.freeze({
42
+ tenantGate: defaultTenantGate,
43
+ objectTypeGate: defaultObjectTypeGate,
44
+ recordPermit: defaultRecordPermit,
45
+ delegationOverlay: defaultDelegationOverlay,
46
+ });
47
+ //# sourceMappingURL=default-gates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-gates.js","sourceRoot":"","sources":["../../src/authorization/default-gates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,YAAY,EACZ,QAAQ,GAMT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAiB,KAAK,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC;AAE1E,wFAAwF;AACxF,MAAM,CAAC,MAAM,qBAAqB,GAAqB,KAAK,IAAI,EAAE,CAChE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;AAE5B,oFAAoF;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAmB,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;AAEzF,uFAAuF;AACvF,MAAM,CAAC,MAAM,wBAAwB,GAAwB,KAAK,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC;AAExF;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAkB,MAAM,CAAC,MAAM,CAAC;IACxE,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,qBAAqB;IACrC,YAAY,EAAE,mBAAmB;IACjC,iBAAiB,EAAE,wBAAwB;CAC5C,CAAC,CAAC"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Gate 7 — DELEGATION overlay / **trusted operation identity** (§10 / ADR-0008).
3
+ *
4
+ * The case (§10, worked example): ONE server operation performs an internal
5
+ * side-effect on a resource the CALLER may not modify directly — e.g. "create
6
+ * user" also writes an onboarding record in a SEPARATE object type the caller has
7
+ * no standing grant on. The requirement is that the internal step runs under the
8
+ * OPERATION's OWN declared, scoped, least-privilege authority — NOT the caller's
9
+ * grants, and NOT a wildcard "skip all checks".
10
+ *
11
+ * This overlay is the LAST gate the pipeline runs (`decision-authority.ts` gate 7).
12
+ * It receives the BASELINE `Decision` that gates 0–6 computed under the CALLER's
13
+ * identity and decides the FINAL outcome:
14
+ *
15
+ * • **Pass-through (the common case, §10.6).** The request is NOT a delegated
16
+ * internal step (no delegation marker), OR the operation declares no authority
17
+ * for this step (`resolveDelegatedAuthority → undefined`). The overlay does NOT
18
+ * override — it returns `gateContinue()`, so the gates-0–6 `baseline` stands
19
+ * (whatever it was, allow or a specific deny). Delegation NEVER silently widens
20
+ * a non-delegated request.
21
+ *
22
+ * • **Delegated step (§10.2/§10.3).** The request IS a delegated internal step and
23
+ * the operation DECLARES a scoped authority for it. The caller's own baseline for
24
+ * this internal resource is TYPICALLY a permission deny (the caller lacks the
25
+ * grant — that is expected and correct). The overlay RE-EVALUATES the step under
26
+ * the OPERATION's declared authority:
27
+ * 1. `authority = OperationAuthorityPort.resolveDelegatedAuthority(op, step)`.
28
+ * `undefined` ⇒ NOT delegated ⇒ pass-through (baseline stands). Fail-closed.
29
+ * 2. **Scope ceiling (§10.3, AC-15).** The step's `resource.typeKey` MUST be a
30
+ * member of the authority's declared `objectTypeKeys` AND the `action.key`
31
+ * MUST be a member of the declared `allowedActions` — STRICT `=== true`
32
+ * membership, never a wildcard. Out of EITHER ⇒ the operation is trying to
33
+ * act beyond what it was delegated ⇒ `deny(missing_object_type_grant)`. This
34
+ * is AC-15 "the same operation cannot write to an object it was not
35
+ * delegated authority for".
36
+ * 3. **Tenant still applies (§10.4).** Delegation crosses PERMISSION, never
37
+ * TENANT. A `tenant_mismatch` baseline is NEVER overridden to allow — a
38
+ * delegated step may not open a tenant boundary a §10bis grant has not
39
+ * ALREADY opened for the request. The overlay only ever overrides a
40
+ * *permission* deny; a tenant deny is preserved verbatim.
41
+ * 4. In-scope + tenant OK ⇒ `allow()` (the step runs under the operation's own
42
+ * authority; the "on behalf of" audit trail is the adapter's concern — §10.5,
43
+ * not this pure gate's).
44
+ *
45
+ * ── SCOPE, NEVER SUPERUSER. A delegated step gets EXACTLY the operation's declared
46
+ * object-type(s) + action(s) — never more, never the caller's grants, never a
47
+ * wildcard. Every ambiguity fails CLOSED (out-of-scope ⇒ deny; a malformed
48
+ * authority ⇒ deny). This is the #1 over-grant risk in the whole engine, so the
49
+ * membership checks route through the load-bearing `strictTrue` guard.
50
+ *
51
+ * ── TRANSIENT-vs-DENY (ADR-0016). This overlay NEVER catches. `resolveDelegatedAuthority`
52
+ * is a pure declared-metadata lookup, but if a concrete adapter must reach a store
53
+ * and throws {@link AuthorizationUnavailableError} (or any other error), it
54
+ * PROPAGATES unchanged so `decide()` can re-throw it (503-retryable). We never
55
+ * swallow a throw into a pass-through/allow — that would fail OPEN.
56
+ *
57
+ * ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the port +
58
+ * context are injected via the pipeline's `GateContext`. Deterministic; no leak.
59
+ */
60
+ import type { DelegationOverlayFn, GateContext } from '../decision-authority.js';
61
+ import type { DelegatedAuthority } from '../ports.js';
62
+ /**
63
+ * The FROZEN `DecisionContext.attributes` bag key under which the enforcement
64
+ * adapter marks a decision as a DELEGATED internal step and names its operation +
65
+ * step. The prelude did NOT add a dedicated channel to `GateContext` (the frozen
66
+ * seam), so this overlay reads the marker from the open-ended `attributes` bag the
67
+ * seam already carries — no frozen type is changed.
68
+ *
69
+ * ⛔ ENFORCEMENT-ADAPTER CONTRACT (`@astram/guard`): to run an internal step under
70
+ * an operation's delegated authority, populate
71
+ * `context.attributes['shield.delegation'] = { operationKey, stepKey }` on the
72
+ * per-step decision. Absent (or malformed) ⇒ the request is treated as a NORMAL,
73
+ * non-delegated decision (pass-through) — evaluated entirely under the caller.
74
+ */
75
+ export declare const DELEGATION_MARKER_ATTRIBUTE: "shield.delegation";
76
+ /**
77
+ * The delegated-step marker the enforcement adapter writes into
78
+ * `context.attributes[{@link DELEGATION_MARKER_ATTRIBUTE}]`. Names the trusted
79
+ * operation and the specific step being performed — the key the
80
+ * {@link OperationAuthorityPort} resolves a declared authority against.
81
+ */
82
+ export interface DelegationMarker {
83
+ /** Stable key of the trusted operation (the operation's manifest identity). */
84
+ readonly operationKey: string;
85
+ /** Stable key of the specific internal step within the operation. */
86
+ readonly stepKey: string;
87
+ }
88
+ /**
89
+ * Read + VALIDATE the delegation marker off the frozen `DecisionContext.attributes`
90
+ * bag. Returns the marker ONLY when the attribute is a well-formed object carrying
91
+ * BOTH a non-empty `operationKey` and a non-empty `stepKey` (both strings); anything
92
+ * else — absent, wrong type, empty strings, a hostile shape — yields `undefined`
93
+ * (treated as "not a delegated step", i.e. pass-through). Fail-closed: a garbage
94
+ * marker never manufactures a delegation.
95
+ */
96
+ export declare function readDelegationMarker(ctx: GateContext): DelegationMarker | undefined;
97
+ /**
98
+ * §10.3 SCOPE CEILING — is the step's object type a member of the authority's
99
+ * DECLARED `objectTypeKeys`? STRICT membership (exact string equality; no wildcard,
100
+ * no prefix). A malformed `objectTypeKeys` (non-array / non-string members) is
101
+ * treated as covering NOTHING (fail-closed) — an operation with a garbage scope
102
+ * delegates over no object type.
103
+ */
104
+ export declare function isTypeInScope(authority: DelegatedAuthority, typeKey: string): boolean;
105
+ /**
106
+ * §10.3 ACTION CEILING — is the attempted action a member of the authority's
107
+ * DECLARED `allowedActions`? STRICT membership (exact string equality; no wildcard).
108
+ * A malformed `allowedActions` covers NO action (fail-closed) — a delegated step may
109
+ * perform ONLY the exact actions the operation named.
110
+ */
111
+ export declare function isActionInScope(authority: DelegatedAuthority, actionKey: string): boolean;
112
+ /** Options for {@link createDelegationOverlay}. Reserved for future injectables. */
113
+ export type CreateDelegationOverlayOptions = Record<string, never>;
114
+ /**
115
+ * Build the gate-7 {@link DelegationOverlayFn} the pipeline injects. PURE — reaches
116
+ * the {@link OperationAuthorityPort} through `ctx.deps.operationAuthority`; holds no
117
+ * state.
118
+ *
119
+ * Contract (see the module doc for the full rationale):
120
+ * - No delegation marker OR `resolveDelegatedAuthority → undefined` ⇒
121
+ * `gateContinue()` (pass-through; the gates-0–6 baseline stands).
122
+ * - A delegated step whose declared authority covers the step's object type AND
123
+ * action, AND whose baseline deny is a PERMISSION deny (never `tenant_mismatch`)
124
+ * ⇒ `gateAllow()` (re-evaluated under the operation's own authority).
125
+ * - A delegated step OUT of the declared object-type or action scope ⇒
126
+ * `gateDeny(missing_object_type_grant)` (AC-15 over-grant refusal).
127
+ * - A delegated step whose baseline is a tenant (or pre-authz) deny ⇒
128
+ * `gateContinue()` — the overlay refuses to override it (§10.4 preserved).
129
+ * - Any throw from the port PROPAGATES unchanged (ADR-0016; never swallowed).
130
+ */
131
+ export declare function createDelegationOverlay(_options?: CreateDelegationOverlayOptions): DelegationOverlayFn;
132
+ //# sourceMappingURL=operation-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-identity.d.ts","sourceRoot":"","sources":["../../../src/authorization/delegation/operation-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EAEZ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,2BAA2B,EAAG,mBAA4B,CAAC;AAExE;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,GACf,gBAAgB,GAAG,SAAS,CAe9B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,MAAM,GACd,OAAO,CAMT;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,kBAAkB,EAC7B,SAAS,EAAE,MAAM,GAChB,OAAO,CAMT;AAoCD,oFAAoF;AACpF,MAAM,MAAM,8BAA8B,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,8BAAmC,GAC5C,mBAAmB,CAyDrB"}
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Gate 7 — DELEGATION overlay / **trusted operation identity** (§10 / ADR-0008).
3
+ *
4
+ * The case (§10, worked example): ONE server operation performs an internal
5
+ * side-effect on a resource the CALLER may not modify directly — e.g. "create
6
+ * user" also writes an onboarding record in a SEPARATE object type the caller has
7
+ * no standing grant on. The requirement is that the internal step runs under the
8
+ * OPERATION's OWN declared, scoped, least-privilege authority — NOT the caller's
9
+ * grants, and NOT a wildcard "skip all checks".
10
+ *
11
+ * This overlay is the LAST gate the pipeline runs (`decision-authority.ts` gate 7).
12
+ * It receives the BASELINE `Decision` that gates 0–6 computed under the CALLER's
13
+ * identity and decides the FINAL outcome:
14
+ *
15
+ * • **Pass-through (the common case, §10.6).** The request is NOT a delegated
16
+ * internal step (no delegation marker), OR the operation declares no authority
17
+ * for this step (`resolveDelegatedAuthority → undefined`). The overlay does NOT
18
+ * override — it returns `gateContinue()`, so the gates-0–6 `baseline` stands
19
+ * (whatever it was, allow or a specific deny). Delegation NEVER silently widens
20
+ * a non-delegated request.
21
+ *
22
+ * • **Delegated step (§10.2/§10.3).** The request IS a delegated internal step and
23
+ * the operation DECLARES a scoped authority for it. The caller's own baseline for
24
+ * this internal resource is TYPICALLY a permission deny (the caller lacks the
25
+ * grant — that is expected and correct). The overlay RE-EVALUATES the step under
26
+ * the OPERATION's declared authority:
27
+ * 1. `authority = OperationAuthorityPort.resolveDelegatedAuthority(op, step)`.
28
+ * `undefined` ⇒ NOT delegated ⇒ pass-through (baseline stands). Fail-closed.
29
+ * 2. **Scope ceiling (§10.3, AC-15).** The step's `resource.typeKey` MUST be a
30
+ * member of the authority's declared `objectTypeKeys` AND the `action.key`
31
+ * MUST be a member of the declared `allowedActions` — STRICT `=== true`
32
+ * membership, never a wildcard. Out of EITHER ⇒ the operation is trying to
33
+ * act beyond what it was delegated ⇒ `deny(missing_object_type_grant)`. This
34
+ * is AC-15 "the same operation cannot write to an object it was not
35
+ * delegated authority for".
36
+ * 3. **Tenant still applies (§10.4).** Delegation crosses PERMISSION, never
37
+ * TENANT. A `tenant_mismatch` baseline is NEVER overridden to allow — a
38
+ * delegated step may not open a tenant boundary a §10bis grant has not
39
+ * ALREADY opened for the request. The overlay only ever overrides a
40
+ * *permission* deny; a tenant deny is preserved verbatim.
41
+ * 4. In-scope + tenant OK ⇒ `allow()` (the step runs under the operation's own
42
+ * authority; the "on behalf of" audit trail is the adapter's concern — §10.5,
43
+ * not this pure gate's).
44
+ *
45
+ * ── SCOPE, NEVER SUPERUSER. A delegated step gets EXACTLY the operation's declared
46
+ * object-type(s) + action(s) — never more, never the caller's grants, never a
47
+ * wildcard. Every ambiguity fails CLOSED (out-of-scope ⇒ deny; a malformed
48
+ * authority ⇒ deny). This is the #1 over-grant risk in the whole engine, so the
49
+ * membership checks route through the load-bearing `strictTrue` guard.
50
+ *
51
+ * ── TRANSIENT-vs-DENY (ADR-0016). This overlay NEVER catches. `resolveDelegatedAuthority`
52
+ * is a pure declared-metadata lookup, but if a concrete adapter must reach a store
53
+ * and throws {@link AuthorizationUnavailableError} (or any other error), it
54
+ * PROPAGATES unchanged so `decide()` can re-throw it (503-retryable). We never
55
+ * swallow a throw into a pass-through/allow — that would fail OPEN.
56
+ *
57
+ * ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the port +
58
+ * context are injected via the pipeline's `GateContext`. Deterministic; no leak.
59
+ */
60
+ import { gateAllow, gateContinue, gateDeny } from '../decision-authority.js';
61
+ import { denyMissingObjectTypeGrant, strictTrue } from '../reason-codes.js';
62
+ /**
63
+ * The FROZEN `DecisionContext.attributes` bag key under which the enforcement
64
+ * adapter marks a decision as a DELEGATED internal step and names its operation +
65
+ * step. The prelude did NOT add a dedicated channel to `GateContext` (the frozen
66
+ * seam), so this overlay reads the marker from the open-ended `attributes` bag the
67
+ * seam already carries — no frozen type is changed.
68
+ *
69
+ * ⛔ ENFORCEMENT-ADAPTER CONTRACT (`@astram/guard`): to run an internal step under
70
+ * an operation's delegated authority, populate
71
+ * `context.attributes['shield.delegation'] = { operationKey, stepKey }` on the
72
+ * per-step decision. Absent (or malformed) ⇒ the request is treated as a NORMAL,
73
+ * non-delegated decision (pass-through) — evaluated entirely under the caller.
74
+ */
75
+ export const DELEGATION_MARKER_ATTRIBUTE = 'shield.delegation';
76
+ /**
77
+ * Read + VALIDATE the delegation marker off the frozen `DecisionContext.attributes`
78
+ * bag. Returns the marker ONLY when the attribute is a well-formed object carrying
79
+ * BOTH a non-empty `operationKey` and a non-empty `stepKey` (both strings); anything
80
+ * else — absent, wrong type, empty strings, a hostile shape — yields `undefined`
81
+ * (treated as "not a delegated step", i.e. pass-through). Fail-closed: a garbage
82
+ * marker never manufactures a delegation.
83
+ */
84
+ export function readDelegationMarker(ctx) {
85
+ const raw = ctx.context.attributes?.[DELEGATION_MARKER_ATTRIBUTE];
86
+ if (typeof raw !== 'object' || raw === null) {
87
+ return undefined;
88
+ }
89
+ const { operationKey, stepKey } = raw;
90
+ if (typeof operationKey !== 'string' ||
91
+ operationKey.length === 0 ||
92
+ typeof stepKey !== 'string' ||
93
+ stepKey.length === 0) {
94
+ return undefined;
95
+ }
96
+ return { operationKey, stepKey };
97
+ }
98
+ /**
99
+ * §10.3 SCOPE CEILING — is the step's object type a member of the authority's
100
+ * DECLARED `objectTypeKeys`? STRICT membership (exact string equality; no wildcard,
101
+ * no prefix). A malformed `objectTypeKeys` (non-array / non-string members) is
102
+ * treated as covering NOTHING (fail-closed) — an operation with a garbage scope
103
+ * delegates over no object type.
104
+ */
105
+ export function isTypeInScope(authority, typeKey) {
106
+ const declared = authority.objectTypeKeys;
107
+ if (!Array.isArray(declared)) {
108
+ return false;
109
+ }
110
+ return strictTrue(declared.some((t) => t === typeKey));
111
+ }
112
+ /**
113
+ * §10.3 ACTION CEILING — is the attempted action a member of the authority's
114
+ * DECLARED `allowedActions`? STRICT membership (exact string equality; no wildcard).
115
+ * A malformed `allowedActions` covers NO action (fail-closed) — a delegated step may
116
+ * perform ONLY the exact actions the operation named.
117
+ */
118
+ export function isActionInScope(authority, actionKey) {
119
+ const declared = authority.allowedActions;
120
+ if (!Array.isArray(declared)) {
121
+ return false;
122
+ }
123
+ return strictTrue(declared.some((a) => a === actionKey));
124
+ }
125
+ /**
126
+ * A baseline deny that the delegation overlay is allowed to OVERRIDE is a
127
+ * *permission* deny only. §10.4: delegation crosses PERMISSION, never TENANT — so a
128
+ * `tenant_mismatch` baseline is NEVER overridable. `resource_not_registered` /
129
+ * `not_authenticated` are pre-gate-3 outcomes that never reach gate 7 in the real
130
+ * pipeline, but we guard them too (defense-in-depth): only a permission-tier deny
131
+ * (`missing_object_type_grant` / `no_record_permit` / `explicit_deny_policy` /
132
+ * `deny_by_default`) may be re-decided under the operation's authority.
133
+ *
134
+ * Note: `explicit_deny_policy` (a deny-wins record-rule deny) IS a permission-tier
135
+ * deny and MAY be overridden by a valid in-scope delegated authority — the operation
136
+ * acts under its OWN identity, for which the caller-scoped rule deny is irrelevant.
137
+ */
138
+ function isOverridablePermissionDeny(baseline) {
139
+ if (baseline.effect !== 'deny') {
140
+ return false;
141
+ }
142
+ switch (baseline.reason) {
143
+ case 'tenant_mismatch':
144
+ case 'resource_not_registered':
145
+ case 'not_authenticated':
146
+ // Never overridable by delegation (tenant boundary + pre-authz gates).
147
+ return false;
148
+ case 'missing_object_type_grant':
149
+ case 'no_record_permit':
150
+ case 'explicit_deny_policy':
151
+ case 'deny_by_default':
152
+ return true;
153
+ default:
154
+ // Unknown/hostile reason ⇒ fail-closed (do NOT override).
155
+ return false;
156
+ }
157
+ }
158
+ /**
159
+ * Build the gate-7 {@link DelegationOverlayFn} the pipeline injects. PURE — reaches
160
+ * the {@link OperationAuthorityPort} through `ctx.deps.operationAuthority`; holds no
161
+ * state.
162
+ *
163
+ * Contract (see the module doc for the full rationale):
164
+ * - No delegation marker OR `resolveDelegatedAuthority → undefined` ⇒
165
+ * `gateContinue()` (pass-through; the gates-0–6 baseline stands).
166
+ * - A delegated step whose declared authority covers the step's object type AND
167
+ * action, AND whose baseline deny is a PERMISSION deny (never `tenant_mismatch`)
168
+ * ⇒ `gateAllow()` (re-evaluated under the operation's own authority).
169
+ * - A delegated step OUT of the declared object-type or action scope ⇒
170
+ * `gateDeny(missing_object_type_grant)` (AC-15 over-grant refusal).
171
+ * - A delegated step whose baseline is a tenant (or pre-authz) deny ⇒
172
+ * `gateContinue()` — the overlay refuses to override it (§10.4 preserved).
173
+ * - Any throw from the port PROPAGATES unchanged (ADR-0016; never swallowed).
174
+ */
175
+ export function createDelegationOverlay(_options = {}) {
176
+ return async function delegationOverlay(ctx, baseline) {
177
+ // (1) Is THIS request a delegated internal step? Absent/garbage marker ⇒ the
178
+ // request is a normal, caller-scoped decision — the baseline stands verbatim.
179
+ const marker = readDelegationMarker(ctx);
180
+ if (marker === undefined) {
181
+ return gateContinue();
182
+ }
183
+ // (2) Does the OPERATION declare a scoped authority for this step? A throw here
184
+ // (transient-unavailable adapter) PROPAGATES so `decide()` re-throws it — we do
185
+ // NOT catch. `undefined` ⇒ no declared authority ⇒ NOT delegated ⇒ pass-through
186
+ // (fail-closed to the caller's baseline, never to an allow).
187
+ const authority = ctx.deps.operationAuthority.resolveDelegatedAuthority(marker.operationKey, marker.stepKey);
188
+ if (authority === undefined) {
189
+ return gateContinue();
190
+ }
191
+ // (3) §10.4 TENANT PRESERVATION (before any override). Delegation crosses
192
+ // PERMISSION, never TENANT. If the baseline denied for the tenant boundary (or a
193
+ // pre-authz gate), the overlay MUST NOT override it — the delegated authority
194
+ // cannot open a tenant boundary a §10bis grant has not already opened. Preserve
195
+ // the baseline exactly.
196
+ if (baseline.effect === 'deny' && !isOverridablePermissionDeny(baseline)) {
197
+ return gateContinue();
198
+ }
199
+ // (4) §10.3 / AC-15 SCOPE CEILING. The step may act ONLY on the DECLARED object
200
+ // type(s) + action(s) — never wider, never a wildcard, never the caller's grants.
201
+ // Out of EITHER ⇒ the operation is attempting to write beyond its delegated
202
+ // authority ⇒ DENY (the AC-15 "cannot write to an object it was not delegated
203
+ // authority for" bound). `missing_object_type_grant` is the truest reason: the
204
+ // operation identity lacks a grant covering this step's object type/action.
205
+ if (!isTypeInScope(authority, ctx.resource.typeKey) ||
206
+ !isActionInScope(authority, ctx.action.key)) {
207
+ return gateDeny(denyMissingObjectTypeGrant());
208
+ }
209
+ // (5) In-scope AND tenant OK. The step runs under the OPERATION's own declared,
210
+ // scoped, least-privilege authority — overriding the caller's permission-deny
211
+ // baseline. (The "on behalf of" audit — §10.5 — is the enforcement adapter's job,
212
+ // not this pure decision gate's.)
213
+ //
214
+ // Note: when the baseline was already an ALLOW (a pass-through step the operation
215
+ // ALSO declared authority for, and the caller happened to be authorized), an
216
+ // in-scope authority likewise yields allow — same terminal outcome, no widening.
217
+ return gateAllow();
218
+ };
219
+ }
220
+ //# sourceMappingURL=operation-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-identity.js","sourceRoot":"","sources":["../../../src/authorization/delegation/operation-identity.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Authorization engine ERRORS — the typed transient signal that resolves the
3
+ * ADR-0016 "transient-vs-deny" seam gap WITHOUT touching the frozen
4
+ * {@link DecisionReasonCode} enum (KICKOFF §"BINDING ARCHITECT DECISION").
5
+ *
6
+ * The frozen enum (8 members) has NO `authorization_unavailable` member, and per
7
+ * ADR-0016 the transient distinction lives in the ENFORCEMENT ADAPTER, not inside
8
+ * the pure `decide()` seam. So `decide()` never fabricates an out-of-enum reason:
9
+ *
10
+ * - it can RENDER a decision → returns a {@link Decision} (`allow`/`deny`);
11
+ * - a port is genuinely UNAVAILABLE (transient) → it THROWS this typed error;
12
+ * - any OTHER unexpected exception → fail-closed `deny` (`deny_by_default`).
13
+ *
14
+ * The enforcement adapter (`@astram/guard`) maps a thrown
15
+ * {@link AuthorizationUnavailableError} → **503 retryable**, while a returned
16
+ * `Decision{effect:'deny'}` → **403 terminal**. BOTH keep the request unserved
17
+ * (fail-closed); only the *signal* differs, exactly where the ADR places it.
18
+ *
19
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
20
+ */
21
+ /**
22
+ * A TYPED, transient-unavailable signal thrown by `decide()` ONLY when an injected
23
+ * port genuinely CANNOT answer (ADR-0016) — e.g. the hot-facts read yields
24
+ * `unavailable`, or a rule/share/grant port throws a transient/outage error.
25
+ *
26
+ * ⛔ This is NOT a normal Deny. A port returning "no rule / no share / no grant /
27
+ * facts-absent-but-store-up" is a normal **data-absence** → it contributes to a
28
+ * returned `deny` Decision (`no_record_permit` / `deny_by_default`), NEVER this
29
+ * error. Only a genuine `unavailable`/transient-throw becomes this signal — the
30
+ * same `found|absent|unavailable` discipline Session uses.
31
+ *
32
+ * Fail-closed either way: a thrown `AuthorizationUnavailableError` leaves the
33
+ * request UNSERVED (the adapter maps it to 503-retryable); it must never be
34
+ * silently converted into an Allow, nor swallowed into a `deny_by_default` (that
35
+ * would erase the retryable signal the ADR mandates). The `decide()` pipeline
36
+ * therefore RE-THROWS this type unchanged and only converts OTHER exceptions to a
37
+ * fail-closed deny.
38
+ */
39
+ export declare class AuthorizationUnavailableError extends Error {
40
+ /**
41
+ * The underlying transient cause (a port outage error, an `unavailable` marker,
42
+ * etc.), retained for admin troubleshooting/logging by the adapter. NEVER
43
+ * surfaced to end users and NEVER used to leak resource existence (§7.5).
44
+ */
45
+ readonly cause?: unknown;
46
+ /**
47
+ * Optional non-leaking admin-only detail (e.g. which port was unavailable).
48
+ * Same §7.5 discipline as {@link Decision.detail}: admin troubleshooting only,
49
+ * never returned to the caller, never reveals whether a resource exists.
50
+ */
51
+ readonly detail?: string;
52
+ constructor(detail?: string, cause?: unknown);
53
+ }
54
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/authorization/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;IACtD;;;;OAIG;IACH,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAQ7C"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Authorization engine ERRORS — the typed transient signal that resolves the
3
+ * ADR-0016 "transient-vs-deny" seam gap WITHOUT touching the frozen
4
+ * {@link DecisionReasonCode} enum (KICKOFF §"BINDING ARCHITECT DECISION").
5
+ *
6
+ * The frozen enum (8 members) has NO `authorization_unavailable` member, and per
7
+ * ADR-0016 the transient distinction lives in the ENFORCEMENT ADAPTER, not inside
8
+ * the pure `decide()` seam. So `decide()` never fabricates an out-of-enum reason:
9
+ *
10
+ * - it can RENDER a decision → returns a {@link Decision} (`allow`/`deny`);
11
+ * - a port is genuinely UNAVAILABLE (transient) → it THROWS this typed error;
12
+ * - any OTHER unexpected exception → fail-closed `deny` (`deny_by_default`).
13
+ *
14
+ * The enforcement adapter (`@astram/guard`) maps a thrown
15
+ * {@link AuthorizationUnavailableError} → **503 retryable**, while a returned
16
+ * `Decision{effect:'deny'}` → **403 terminal**. BOTH keep the request unserved
17
+ * (fail-closed); only the *signal* differs, exactly where the ADR places it.
18
+ *
19
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
20
+ */
21
+ /**
22
+ * A TYPED, transient-unavailable signal thrown by `decide()` ONLY when an injected
23
+ * port genuinely CANNOT answer (ADR-0016) — e.g. the hot-facts read yields
24
+ * `unavailable`, or a rule/share/grant port throws a transient/outage error.
25
+ *
26
+ * ⛔ This is NOT a normal Deny. A port returning "no rule / no share / no grant /
27
+ * facts-absent-but-store-up" is a normal **data-absence** → it contributes to a
28
+ * returned `deny` Decision (`no_record_permit` / `deny_by_default`), NEVER this
29
+ * error. Only a genuine `unavailable`/transient-throw becomes this signal — the
30
+ * same `found|absent|unavailable` discipline Session uses.
31
+ *
32
+ * Fail-closed either way: a thrown `AuthorizationUnavailableError` leaves the
33
+ * request UNSERVED (the adapter maps it to 503-retryable); it must never be
34
+ * silently converted into an Allow, nor swallowed into a `deny_by_default` (that
35
+ * would erase the retryable signal the ADR mandates). The `decide()` pipeline
36
+ * therefore RE-THROWS this type unchanged and only converts OTHER exceptions to a
37
+ * fail-closed deny.
38
+ */
39
+ export class AuthorizationUnavailableError extends Error {
40
+ /**
41
+ * The underlying transient cause (a port outage error, an `unavailable` marker,
42
+ * etc.), retained for admin troubleshooting/logging by the adapter. NEVER
43
+ * surfaced to end users and NEVER used to leak resource existence (§7.5).
44
+ */
45
+ cause;
46
+ /**
47
+ * Optional non-leaking admin-only detail (e.g. which port was unavailable).
48
+ * Same §7.5 discipline as {@link Decision.detail}: admin troubleshooting only,
49
+ * never returned to the caller, never reveals whether a resource exists.
50
+ */
51
+ detail;
52
+ constructor(detail, cause) {
53
+ super(detail ?? 'authorization_unavailable');
54
+ this.name = 'AuthorizationUnavailableError';
55
+ if (detail !== undefined)
56
+ this.detail = detail;
57
+ if (cause !== undefined)
58
+ this.cause = cause;
59
+ // Preserve the prototype chain when compiled down-level so `instanceof` works.
60
+ Object.setPrototypeOf(this, AuthorizationUnavailableError.prototype);
61
+ }
62
+ }
63
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/authorization/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IACtD;;;;OAIG;IACe,KAAK,CAAW;IAElC;;;;OAIG;IACM,MAAM,CAAU;IAEzB,YAAY,MAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,MAAM,IAAI,2BAA2B,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5C,+EAA+E;QAC/E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,6BAA6B,CAAC,SAAS,CAAC,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Gate 5 — the **FEATURE / OBJECT-TYPE permission gate** (TEAM A, Hard Gates) —
3
+ * §7.3.3 / ADR-0011.
4
+ *
5
+ * Runs ONLY for GATED resources (public + authenticated_global already
6
+ * short-circuited to Allow upstream; unauthenticated + cross-tenant-without-grant
7
+ * already denied). It answers the coarse question: *does this principal hold a
8
+ * feature/object-type grant for the action's stable permission key?* — the
9
+ * ADR-0011 hot path.
10
+ *
11
+ * ── Permission identity: the required grant key is the action's STABLE
12
+ * permission key (ADR-0010) — `moduleKey:typeKey:actionKey`. The pipeline
13
+ * resolved the {@link RegisteredAction} at gate 1 but does NOT stash it on the
14
+ * read-only {@link GateContext}, so this gate re-resolves it over the FROZEN
15
+ * registry surface (`listActions()` matched by `typeKey + actionKey`), exactly
16
+ * as the pipeline does, and reads its `permissionKey`. An action not registered
17
+ * for this type has no derivable grant → `deny(missing_object_type_grant)`.
18
+ *
19
+ * ── Coarse-grants source (ADR-0011, hot path, in order):
20
+ * 1. Read THIS request's session facts (`deps.sessionFacts`): compare the cached
21
+ * `permissionsVersion` against {@link PermissionFactsPort.currentPermissionsVersion}.
22
+ * - versions MATCH and `cachedFacts` present ⇒ use `cachedFacts` (NO reload) —
23
+ * a revoke takes effect within the version bound.
24
+ * - versions DIFFER (stale) OR `cachedFacts` null/unusable ⇒ RELOAD via
25
+ * {@link PermissionFactsPort.loadCoarseGrants}.
26
+ * 2. `cachedFacts` is the opaque ADR-0011 slot; this gate interprets it as
27
+ * {@link CoarseGrants} (`{ permissionsVersion, grantedPermissionKeys }`) — the
28
+ * exact shape `ports.ts` defines. (Assumption documented in DONE.md: the
29
+ * prelude left the slot typed `unknown`; we read it through a minimal typed
30
+ * view here and never mutate the frozen slot.)
31
+ *
32
+ * ── Cross-tenant case (§7.3.3): when the tenant DIFFERS (and the principal is not
33
+ * the platform superuser), gate 3 only let evaluation proceed BECAUSE a
34
+ * cross-tenant grant covers it — and that grant's scope + action-ceiling SERVES
35
+ * AS the object-type grant. Coarse facts are the WRONG-tenant facts, so this
36
+ * gate does NOT consult them; it RE-RESOLVES the grant via
37
+ * {@link CrossTenantGrantPort} (gate 3 is pure and stashed nothing) and, if the
38
+ * action is in-ceiling, `continue`s (record level → gate 6 runs) or `allow`s
39
+ * (feature/object-type level → terminates). A superuser crossing tenants is NOT
40
+ * grant-backed; it takes the normal coarse-grants path below.
41
+ *
42
+ * ── Decision:
43
+ * - grant held for this action (STRICT membership) →
44
+ * `record` level ⇒ `continue` (gate 6 record-permit runs next);
45
+ * feature/object_type level ⇒ `allow` (terminates here).
46
+ * - no applicable grant ⇒ `deny(missing_object_type_grant)`.
47
+ * - {@link PermissionFactsPort} / {@link CrossTenantGrantPort} throws
48
+ * {@link AuthorizationUnavailableError} (transient) ⇒ PROPAGATES (pipeline
49
+ * re-throws → 503). Any OTHER throw also propagates (pipeline fail-closes to
50
+ * `deny_by_default`). This gate NEVER swallows a throw into a `deny`.
51
+ *
52
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
53
+ */
54
+ import { type ObjectTypeGateFn } from '../decision-authority.js';
55
+ /**
56
+ * Build the feature/object-type gate (gate 5). No injected deps of its own — it
57
+ * reaches the registry, session facts, {@link PermissionFactsPort}, and
58
+ * {@link CrossTenantGrantPort} through {@link GateContext.deps}. Returns an
59
+ * {@link ObjectTypeGateFn} the integration owner injects as
60
+ * `DecisionAuthorityDeps.gates.objectTypeGate`.
61
+ */
62
+ export declare function createObjectTypeGate(): ObjectTypeGateFn;
63
+ //# sourceMappingURL=object-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-type.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AA0ClC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CA4DvD"}