@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,136 @@
1
+ /**
2
+ * The **boot-completeness-check contract** (ADR-0002 fail-closed enforcement,
3
+ * ADR-0010 auto-discovered operations).
4
+ *
5
+ * At build/boot, every non-public operation the application exposes MUST resolve
6
+ * to a permission in the registry; any that doesn't is a HARD FAILURE and denied
7
+ * until wired (ADR-0002/0010). This module defines the TYPES + the pure function
8
+ * SIGNATURE that performs that reconciliation. It is **framework-agnostic**
9
+ * (ADR-0003): the operation inventory is **CALLER-FED** (confirmed decision #2) —
10
+ * `@astram/core` does NOT reflect NestJS routes; `@astram/guard` discovers the
11
+ * live operations and hands them in as an {@link OperationInventory}.
12
+ *
13
+ * The TYPES are the frozen contract; {@link checkCompleteness} is the PURE
14
+ * reconciliation implemented over them (Team C). No I/O, no framework imports —
15
+ * the inventory is handed in.
16
+ */
17
+ import type { PermissionKey } from '../authorization/index.js';
18
+ import type { ModuleRegistry } from './index.js';
19
+ /**
20
+ * One live, discovered operation the application exposes — the caller-fed unit
21
+ * of the inventory (built by `@astram/guard` from route reflection, NOT by
22
+ * core). Deliberately minimal: identity, whether it opted out via Public, and
23
+ * the permission it claims to bind to (if any).
24
+ */
25
+ export interface DiscoveredOperation {
26
+ /**
27
+ * Stable, unique operation id (the co-located handler identity from ADR-0010 —
28
+ * e.g. `controllerClass#method`). Machine identity only; never shown to admins.
29
+ */
30
+ readonly operationId: string;
31
+ /**
32
+ * `true` iff the operation is an explicit, code-reviewed Public opt-out
33
+ * (ADR-0004). Public operations are exempt from the "must resolve to a
34
+ * permission" rule; everything else must classify or it is denied.
35
+ */
36
+ readonly isPublic: boolean;
37
+ /**
38
+ * The stable permission identity this operation declares it binds to (ADR-0010),
39
+ * if it declared one. Absent on a non-public operation ⇒ a STRANDED op (no
40
+ * association) — a hard failure.
41
+ */
42
+ readonly permissionKey?: PermissionKey;
43
+ }
44
+ /**
45
+ * The complete caller-fed set of discovered operations to reconcile against the
46
+ * registry (confirmed decision #2). Produced by the framework-integration layer
47
+ * (`@astram/guard`), consumed by {@link checkCompleteness}.
48
+ */
49
+ export interface OperationInventory {
50
+ readonly operations: readonly DiscoveredOperation[];
51
+ }
52
+ /**
53
+ * A non-public operation that resolves to NO permission classification — it
54
+ * declared no permission key, OR its key resolves to no registered action.
55
+ * Deny-by-default until wired (ADR-0002/0010). Reported for the build/boot
56
+ * hard-failure.
57
+ */
58
+ export interface UnclassifiedOperation {
59
+ readonly operationId: string;
60
+ /** The key it declared, if any (absent ⇒ it declared none — stranded). */
61
+ readonly declaredPermissionKey?: PermissionKey;
62
+ }
63
+ /**
64
+ * A permission that exists in the registry (a grant can bind to it) but that NO
65
+ * live operation derives — an orphaned capability. Reported for review
66
+ * (ADR-0010): typically a removed/renamed operation whose grant lingers.
67
+ */
68
+ export interface OrphanedPermission {
69
+ readonly permissionKey: PermissionKey;
70
+ /** The module that still declares the action deriving it, for triage. */
71
+ readonly moduleKey: string;
72
+ }
73
+ /**
74
+ * A non-public operation that carries NO association at all (declared no
75
+ * permission key) — a subset-of-intent distinct from a key that fails to
76
+ * resolve. Called out separately so the report can say "this handler forgot to
77
+ * declare its permission" vs "this handler's permission isn't registered".
78
+ */
79
+ export interface StrandedOperation {
80
+ readonly operationId: string;
81
+ }
82
+ /**
83
+ * The outcome of the boot-completeness reconciliation. `passed` is `true` ONLY
84
+ * when there are zero unclassified and zero stranded operations (orphaned
85
+ * permissions are reported for review but, per ADR-0010, are a soft warning —
86
+ * a lingering grant does not open a hole, so they do not by themselves fail the
87
+ * boot; Team C confirms this policy when implementing).
88
+ */
89
+ export interface CompletenessResult {
90
+ /** `true` ⇒ safe to boot; `false` ⇒ hard failure, deny until wired. */
91
+ readonly passed: boolean;
92
+ /** Non-public ops with no resolvable permission classification. */
93
+ readonly unclassifiedOperations: readonly UnclassifiedOperation[];
94
+ /** Registered permissions with no live operation (review, not a hole). */
95
+ readonly orphanedPermissions: readonly OrphanedPermission[];
96
+ /** Non-public ops that declared no association at all. */
97
+ readonly strandedOperations: readonly StrandedOperation[];
98
+ }
99
+ /**
100
+ * Reconcile the caller-fed live operation inventory against the registry's
101
+ * declared permissions (ADR-0002/0010). PURE (no I/O) — the inventory is passed
102
+ * in; core never reflects routes itself (ADR-0003, confirmed decision #2).
103
+ *
104
+ * Reports: (a) non-public operations with no resolved permission/classification,
105
+ * (b) orphaned permissions (registered but no live op), (c) stranded ops (op with
106
+ * no association). `passed` gates boot per ADR-0002.
107
+ *
108
+ * Reconciliation rules (per the frozen contract, DONE §5):
109
+ *
110
+ * - **Public op** (`isPublic: true`) — exempt from the resolve requirement
111
+ * (ADR-0004). Skipped entirely; contributes to no failure list. A public op's
112
+ * `permissionKey`, if present, still counts as "claimed" so it does NOT strand a
113
+ * matching registered action as orphaned.
114
+ * - **Non-public op with NO `permissionKey`** — a STRANDED operation (declared no
115
+ * association at all). It is ALSO reported as unclassified (it resolves to no
116
+ * classification), with `declaredPermissionKey` absent to signal "declared none".
117
+ * - **Non-public op with a `permissionKey` that `resolveByPermissionKey` misses**
118
+ * — an UNCLASSIFIED operation (its key is registered nowhere), with the declared
119
+ * key echoed for triage. It is NOT stranded (it did declare an association).
120
+ * - **Orphaned permission** — a `registry.listActions()` entry whose `permissionKey`
121
+ * is claimed by NO live operation in the inventory (public or non-public).
122
+ * Reported for review (ADR-0010): a lingering grant opens no hole, so — per the
123
+ * {@link CompletenessResult} contract — orphaned permissions do NOT by themselves
124
+ * fail the boot.
125
+ *
126
+ * **Fail-closed semantics (ADR-0002):**
127
+ * `passed === (unclassifiedOperations.length === 0 && strandedOperations.length === 0)`.
128
+ * Any non-public op that resolves to nothing ⇒ `passed: false` ⇒ the caller
129
+ * (`@astram/guard`) hard-fails boot and denies until wired. Orphaned permissions
130
+ * are excluded from this gate (soft warning only).
131
+ *
132
+ * **Deterministic:** every returned list is sorted by a stable key (operationId /
133
+ * permissionKey) so identical inputs always yield byte-identical output.
134
+ */
135
+ export declare function checkCompleteness(inventory: OperationInventory, registry: ModuleRegistry): CompletenessResult;
136
+ //# sourceMappingURL=completeness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../src/metadata/completeness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;CACxC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACrD;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,qBAAqB,CAAC,EAAE,aAAa,CAAC;CAChD;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,sBAAsB,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAClE,0EAA0E;IAC1E,QAAQ,CAAC,mBAAmB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC5D,0DAA0D;IAC1D,QAAQ,CAAC,kBAAkB,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,kBAAkB,EAC7B,QAAQ,EAAE,cAAc,GACvB,kBAAkB,CA+DpB"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The **boot-completeness-check contract** (ADR-0002 fail-closed enforcement,
3
+ * ADR-0010 auto-discovered operations).
4
+ *
5
+ * At build/boot, every non-public operation the application exposes MUST resolve
6
+ * to a permission in the registry; any that doesn't is a HARD FAILURE and denied
7
+ * until wired (ADR-0002/0010). This module defines the TYPES + the pure function
8
+ * SIGNATURE that performs that reconciliation. It is **framework-agnostic**
9
+ * (ADR-0003): the operation inventory is **CALLER-FED** (confirmed decision #2) —
10
+ * `@astram/core` does NOT reflect NestJS routes; `@astram/guard` discovers the
11
+ * live operations and hands them in as an {@link OperationInventory}.
12
+ *
13
+ * The TYPES are the frozen contract; {@link checkCompleteness} is the PURE
14
+ * reconciliation implemented over them (Team C). No I/O, no framework imports —
15
+ * the inventory is handed in.
16
+ */
17
+ /**
18
+ * Reconcile the caller-fed live operation inventory against the registry's
19
+ * declared permissions (ADR-0002/0010). PURE (no I/O) — the inventory is passed
20
+ * in; core never reflects routes itself (ADR-0003, confirmed decision #2).
21
+ *
22
+ * Reports: (a) non-public operations with no resolved permission/classification,
23
+ * (b) orphaned permissions (registered but no live op), (c) stranded ops (op with
24
+ * no association). `passed` gates boot per ADR-0002.
25
+ *
26
+ * Reconciliation rules (per the frozen contract, DONE §5):
27
+ *
28
+ * - **Public op** (`isPublic: true`) — exempt from the resolve requirement
29
+ * (ADR-0004). Skipped entirely; contributes to no failure list. A public op's
30
+ * `permissionKey`, if present, still counts as "claimed" so it does NOT strand a
31
+ * matching registered action as orphaned.
32
+ * - **Non-public op with NO `permissionKey`** — a STRANDED operation (declared no
33
+ * association at all). It is ALSO reported as unclassified (it resolves to no
34
+ * classification), with `declaredPermissionKey` absent to signal "declared none".
35
+ * - **Non-public op with a `permissionKey` that `resolveByPermissionKey` misses**
36
+ * — an UNCLASSIFIED operation (its key is registered nowhere), with the declared
37
+ * key echoed for triage. It is NOT stranded (it did declare an association).
38
+ * - **Orphaned permission** — a `registry.listActions()` entry whose `permissionKey`
39
+ * is claimed by NO live operation in the inventory (public or non-public).
40
+ * Reported for review (ADR-0010): a lingering grant opens no hole, so — per the
41
+ * {@link CompletenessResult} contract — orphaned permissions do NOT by themselves
42
+ * fail the boot.
43
+ *
44
+ * **Fail-closed semantics (ADR-0002):**
45
+ * `passed === (unclassifiedOperations.length === 0 && strandedOperations.length === 0)`.
46
+ * Any non-public op that resolves to nothing ⇒ `passed: false` ⇒ the caller
47
+ * (`@astram/guard`) hard-fails boot and denies until wired. Orphaned permissions
48
+ * are excluded from this gate (soft warning only).
49
+ *
50
+ * **Deterministic:** every returned list is sorted by a stable key (operationId /
51
+ * permissionKey) so identical inputs always yield byte-identical output.
52
+ */
53
+ export function checkCompleteness(inventory, registry) {
54
+ const unclassifiedOperations = [];
55
+ const strandedOperations = [];
56
+ // The set of permission keys that some live operation claims to bind to —
57
+ // used to detect orphaned permissions (registered but claimed by no live op).
58
+ // A public op that declares a key still "claims" it, so it is included here.
59
+ const claimedPermissionKeys = new Set();
60
+ for (const op of inventory.operations) {
61
+ if (op.permissionKey !== undefined) {
62
+ claimedPermissionKeys.add(op.permissionKey);
63
+ }
64
+ // Public operations are an explicit, code-reviewed opt-out (ADR-0004) and are
65
+ // exempt from the "must resolve to a permission" rule.
66
+ if (op.isPublic) {
67
+ continue;
68
+ }
69
+ if (op.permissionKey === undefined) {
70
+ // Declared no association at all ⇒ stranded AND unclassified.
71
+ strandedOperations.push({ operationId: op.operationId });
72
+ unclassifiedOperations.push({ operationId: op.operationId });
73
+ continue;
74
+ }
75
+ // Declared a key — it must resolve to a registered action, else unclassified.
76
+ if (registry.resolveByPermissionKey(op.permissionKey) === undefined) {
77
+ unclassifiedOperations.push({
78
+ operationId: op.operationId,
79
+ declaredPermissionKey: op.permissionKey,
80
+ });
81
+ }
82
+ }
83
+ // Orphaned permissions: every registered action whose permission key no live
84
+ // operation claims. Reported for review (ADR-0010) — NOT a boot failure.
85
+ const orphanedPermissions = [];
86
+ for (const registered of registry.listActions()) {
87
+ if (!claimedPermissionKeys.has(registered.permissionKey)) {
88
+ orphanedPermissions.push({
89
+ permissionKey: registered.permissionKey,
90
+ moduleKey: registered.moduleKey,
91
+ });
92
+ }
93
+ }
94
+ // Deterministic ordering — stable, total sort keys.
95
+ unclassifiedOperations.sort((a, b) => (a.operationId < b.operationId ? -1 : a.operationId > b.operationId ? 1 : 0));
96
+ strandedOperations.sort((a, b) => (a.operationId < b.operationId ? -1 : a.operationId > b.operationId ? 1 : 0));
97
+ orphanedPermissions.sort((a, b) => a.permissionKey < b.permissionKey ? -1 : a.permissionKey > b.permissionKey ? 1 : 0);
98
+ const passed = unclassifiedOperations.length === 0 && strandedOperations.length === 0;
99
+ return {
100
+ passed,
101
+ unclassifiedOperations,
102
+ orphanedPermissions,
103
+ strandedOperations,
104
+ };
105
+ }
106
+ //# sourceMappingURL=completeness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completeness.js","sourceRoot":"","sources":["../../src/metadata/completeness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA2FH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAA6B,EAC7B,QAAwB;IAExB,MAAM,sBAAsB,GAA4B,EAAE,CAAC;IAC3D,MAAM,kBAAkB,GAAwB,EAAE,CAAC;IAEnD,0EAA0E;IAC1E,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhD,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACtC,IAAI,EAAE,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACnC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QAC9C,CAAC;QAED,8EAA8E;QAC9E,uDAAuD;QACvD,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;YAChB,SAAS;QACX,CAAC;QAED,IAAI,EAAE,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACnC,8DAA8D;YAC9D,kBAAkB,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YACzD,sBAAsB,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAC7D,SAAS;QACX,CAAC;QAED,8EAA8E;QAC9E,IAAI,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE,CAAC;YACpE,sBAAsB,CAAC,IAAI,CAAC;gBAC1B,WAAW,EAAE,EAAE,CAAC,WAAW;gBAC3B,qBAAqB,EAAE,EAAE,CAAC,aAAa;aACxC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,6EAA6E;IAC7E,yEAAyE;IACzE,MAAM,mBAAmB,GAAyB,EAAE,CAAC;IACrD,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;QAChD,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YACzD,mBAAmB,CAAC,IAAI,CAAC;gBACvB,aAAa,EAAE,UAAU,CAAC,aAAa;gBACvC,SAAS,EAAE,UAAU,CAAC,SAAS;aAChC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,oDAAoD;IACpD,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpH,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChH,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACnF,CAAC;IAEF,MAAM,MAAM,GAAG,sBAAsB,CAAC,MAAM,KAAK,CAAC,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,CAAC;IAEtF,OAAO;QACL,MAAM;QACN,sBAAsB;QACtB,mBAAmB;QACnB,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * **Supporting read-only dependency auto-derivation** (ADR-0012 §"Supporting
3
+ * read-only lookups", ADR-0010 stable identity, ADR-0004 tiers).
4
+ *
5
+ * ADR-0012's decision: *"Supporting read-only lookups (e.g. the department/role
6
+ * lists a create-user form needs) are auto-derived from object reference fields
7
+ * and granted read-only with the owning permission; a sensitive lookup can be
8
+ * marked 'requires its own permission.'"*
9
+ *
10
+ * This module turns that decision into PURE functions over metadata. Given an
11
+ * object type's reference fields ({@link FieldDescriptor.referencesTypeKey}), it
12
+ * derives the READ-ONLY lookups those fields imply — the referenced object types
13
+ * each need a read-only list so a form can populate its dropdowns. A reference
14
+ * whose {@link SupportingDependency.neverAutoGrant} is `true` (a sensitive
15
+ * lookup, ADR-0012 escape hatch) is EXCLUDED — it requires its own explicit
16
+ * permission and is never auto-granted.
17
+ *
18
+ * PURE (ADR-0003, framework-agnostic): no I/O, no registry mutation, no imports
19
+ * of engine/registry code. To validate that a referenced type actually exists,
20
+ * the caller injects a resolver (dependency injection) rather than this module
21
+ * reaching into the registry — keeping it decoupled from Team A and trivially
22
+ * testable.
23
+ *
24
+ * SCOPE: derivation only. This computes WHICH read-only lookups a permission
25
+ * implies from the declared reference fields. It makes NO access decision — that
26
+ * is the Authorization step's `DecisionAuthority.decide`, not here.
27
+ */
28
+ import type { FieldDescriptor, ObjectTypeDescriptor, SupportingDependency } from './index.js';
29
+ /**
30
+ * The single read-only capability an auto-derived supporting lookup confers.
31
+ * Auto-derived lookups are ALWAYS read-only (ADR-0012) — they let a form list
32
+ * options; they never confer create/edit/delete on the referenced type. Modelled
33
+ * as a one-member union (not a bare string) so the read-only guarantee is
34
+ * expressed in the type and cannot silently widen to a mutating capability.
35
+ */
36
+ export type SupportingCapability = 'read';
37
+ /**
38
+ * The read-only capability auto-derived lookups confer. Single-source constant so
39
+ * every derived dependency is stamped read-only from one place (ADR-0012).
40
+ */
41
+ export declare const SUPPORTING_READ_CAPABILITY: SupportingCapability;
42
+ /**
43
+ * A supporting read-only lookup auto-derived from a reference field (ADR-0012).
44
+ * The owning permission implies read-only access to `typeKey` so a form can
45
+ * populate the dropdown that reference field renders as.
46
+ */
47
+ export interface DerivedSupportingDependency {
48
+ /** The referenced object type that gets a read-only lookup. */
49
+ readonly typeKey: string;
50
+ /**
51
+ * Always {@link SUPPORTING_READ_CAPABILITY} (`'read'`) — auto-derivation NEVER
52
+ * confers create/edit/delete on the dependency (ADR-0012).
53
+ */
54
+ readonly capability: SupportingCapability;
55
+ }
56
+ /** Options for {@link deriveSupportingDependencies}. */
57
+ export interface DeriveSupportingDependenciesOptions {
58
+ /**
59
+ * The action's declared {@link SupportingDependency} list (from
60
+ * `ActionDescriptor.supportingDependencies`). Any entry whose `neverAutoGrant`
61
+ * is `true` marks that `typeKey` as SENSITIVE — it is excluded from
62
+ * auto-derivation and requires its own explicit permission (ADR-0012 escape
63
+ * hatch). Entries with `neverAutoGrant: false` are permitted to auto-derive
64
+ * (this is the default behaviour anyway; the list only ever RESTRICTS).
65
+ */
66
+ readonly declaredDependencies?: readonly SupportingDependency[];
67
+ /**
68
+ * Optional resolver to confirm a referenced type is actually registered
69
+ * (dependency injection — this module never imports the registry, ADR-0003).
70
+ * When provided, a `referencesTypeKey` that resolves to `undefined` is skipped
71
+ * (no lookup is derived for a type the platform doesn't know). When omitted,
72
+ * every non-sensitive reference derives a lookup (validation is the caller's
73
+ * concern).
74
+ */
75
+ readonly resolveObjectType?: (typeKey: string) => ObjectTypeDescriptor | undefined;
76
+ }
77
+ /**
78
+ * The set of `typeKey`s marked sensitive (`neverAutoGrant: true`) among the
79
+ * action's declared dependencies. PURE helper — exported for reuse/testing.
80
+ */
81
+ export declare function collectNeverAutoGrantTypeKeys(declaredDependencies?: readonly SupportingDependency[]): ReadonlySet<string>;
82
+ /**
83
+ * Extract the referenced type keys from an object type's reference fields, in
84
+ * declaration order and de-duplicated. A field is a reference iff its
85
+ * {@link FieldDescriptor.referencesTypeKey} is a non-empty string. PURE helper —
86
+ * exported for reuse/testing.
87
+ */
88
+ export declare function collectReferencedTypeKeys(fields: readonly FieldDescriptor[]): readonly string[];
89
+ /**
90
+ * Auto-derive the READ-ONLY supporting lookups an object type's reference fields
91
+ * imply (ADR-0012). For every field with a `referencesTypeKey`, the referenced
92
+ * type gets a read-only lookup so a form over `objectType` can populate that
93
+ * field's dropdown — UNLESS the referenced type is marked `neverAutoGrant` in the
94
+ * action's declared dependencies (sensitive → its own explicit permission).
95
+ *
96
+ * PURE: takes descriptors (and an optional injected resolver), returns derived
97
+ * dependencies. No I/O, no registry mutation, no access decision.
98
+ *
99
+ * Rules enforced (ADR-0012):
100
+ * 1. Derived lookups are ALWAYS read-only — `capability` is always `'read'`;
101
+ * never create/edit/delete on the dependency.
102
+ * 2. A `neverAutoGrant` dependency is EXCLUDED (requires its own permission).
103
+ * 3. No reference fields ⇒ empty list.
104
+ * 4. Duplicate references collapse to a single lookup (declaration order).
105
+ * 5. A `resolveObjectType` that returns `undefined` for a reference ⇒ that
106
+ * reference is skipped (unknown type gets no auto-grant).
107
+ *
108
+ * @param objectType the object type whose reference fields drive the derivation.
109
+ * @param options declared dependencies (for the `neverAutoGrant` escape hatch)
110
+ * and an optional resolver to validate referenced types exist.
111
+ * @returns the de-duplicated, declaration-ordered read-only supporting lookups.
112
+ */
113
+ export declare function deriveSupportingDependencies(objectType: ObjectTypeDescriptor, options?: DeriveSupportingDependenciesOptions): readonly DerivedSupportingDependency[];
114
+ //# sourceMappingURL=dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/metadata/dependencies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,oBAA6B,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,oBAAoB,CAAC;CAC3C;AAED,wDAAwD;AACxD,MAAM,WAAW,mCAAmC;IAClD;;;;;;;OAOG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAChE;;;;;;;OAOG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAC3B,OAAO,EAAE,MAAM,KACZ,oBAAoB,GAAG,SAAS,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,oBAAoB,CAAC,EAAE,SAAS,oBAAoB,EAAE,GACrD,WAAW,CAAC,MAAM,CAAC,CAQrB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,eAAe,EAAE,GACjC,SAAS,MAAM,EAAE,CAWnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,oBAAoB,EAChC,OAAO,GAAE,mCAAwC,GAChD,SAAS,2BAA2B,EAAE,CAiBxC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * **Supporting read-only dependency auto-derivation** (ADR-0012 §"Supporting
3
+ * read-only lookups", ADR-0010 stable identity, ADR-0004 tiers).
4
+ *
5
+ * ADR-0012's decision: *"Supporting read-only lookups (e.g. the department/role
6
+ * lists a create-user form needs) are auto-derived from object reference fields
7
+ * and granted read-only with the owning permission; a sensitive lookup can be
8
+ * marked 'requires its own permission.'"*
9
+ *
10
+ * This module turns that decision into PURE functions over metadata. Given an
11
+ * object type's reference fields ({@link FieldDescriptor.referencesTypeKey}), it
12
+ * derives the READ-ONLY lookups those fields imply — the referenced object types
13
+ * each need a read-only list so a form can populate its dropdowns. A reference
14
+ * whose {@link SupportingDependency.neverAutoGrant} is `true` (a sensitive
15
+ * lookup, ADR-0012 escape hatch) is EXCLUDED — it requires its own explicit
16
+ * permission and is never auto-granted.
17
+ *
18
+ * PURE (ADR-0003, framework-agnostic): no I/O, no registry mutation, no imports
19
+ * of engine/registry code. To validate that a referenced type actually exists,
20
+ * the caller injects a resolver (dependency injection) rather than this module
21
+ * reaching into the registry — keeping it decoupled from Team A and trivially
22
+ * testable.
23
+ *
24
+ * SCOPE: derivation only. This computes WHICH read-only lookups a permission
25
+ * implies from the declared reference fields. It makes NO access decision — that
26
+ * is the Authorization step's `DecisionAuthority.decide`, not here.
27
+ */
28
+ /**
29
+ * The read-only capability auto-derived lookups confer. Single-source constant so
30
+ * every derived dependency is stamped read-only from one place (ADR-0012).
31
+ */
32
+ export const SUPPORTING_READ_CAPABILITY = 'read';
33
+ /**
34
+ * The set of `typeKey`s marked sensitive (`neverAutoGrant: true`) among the
35
+ * action's declared dependencies. PURE helper — exported for reuse/testing.
36
+ */
37
+ export function collectNeverAutoGrantTypeKeys(declaredDependencies) {
38
+ const sensitive = new Set();
39
+ for (const dep of declaredDependencies ?? []) {
40
+ if (dep.neverAutoGrant) {
41
+ sensitive.add(dep.typeKey);
42
+ }
43
+ }
44
+ return sensitive;
45
+ }
46
+ /**
47
+ * Extract the referenced type keys from an object type's reference fields, in
48
+ * declaration order and de-duplicated. A field is a reference iff its
49
+ * {@link FieldDescriptor.referencesTypeKey} is a non-empty string. PURE helper —
50
+ * exported for reuse/testing.
51
+ */
52
+ export function collectReferencedTypeKeys(fields) {
53
+ const seen = new Set();
54
+ const ordered = [];
55
+ for (const field of fields) {
56
+ const ref = field.referencesTypeKey;
57
+ if (typeof ref === 'string' && ref.length > 0 && !seen.has(ref)) {
58
+ seen.add(ref);
59
+ ordered.push(ref);
60
+ }
61
+ }
62
+ return ordered;
63
+ }
64
+ /**
65
+ * Auto-derive the READ-ONLY supporting lookups an object type's reference fields
66
+ * imply (ADR-0012). For every field with a `referencesTypeKey`, the referenced
67
+ * type gets a read-only lookup so a form over `objectType` can populate that
68
+ * field's dropdown — UNLESS the referenced type is marked `neverAutoGrant` in the
69
+ * action's declared dependencies (sensitive → its own explicit permission).
70
+ *
71
+ * PURE: takes descriptors (and an optional injected resolver), returns derived
72
+ * dependencies. No I/O, no registry mutation, no access decision.
73
+ *
74
+ * Rules enforced (ADR-0012):
75
+ * 1. Derived lookups are ALWAYS read-only — `capability` is always `'read'`;
76
+ * never create/edit/delete on the dependency.
77
+ * 2. A `neverAutoGrant` dependency is EXCLUDED (requires its own permission).
78
+ * 3. No reference fields ⇒ empty list.
79
+ * 4. Duplicate references collapse to a single lookup (declaration order).
80
+ * 5. A `resolveObjectType` that returns `undefined` for a reference ⇒ that
81
+ * reference is skipped (unknown type gets no auto-grant).
82
+ *
83
+ * @param objectType the object type whose reference fields drive the derivation.
84
+ * @param options declared dependencies (for the `neverAutoGrant` escape hatch)
85
+ * and an optional resolver to validate referenced types exist.
86
+ * @returns the de-duplicated, declaration-ordered read-only supporting lookups.
87
+ */
88
+ export function deriveSupportingDependencies(objectType, options = {}) {
89
+ const sensitive = collectNeverAutoGrantTypeKeys(options.declaredDependencies);
90
+ const resolve = options.resolveObjectType;
91
+ const derived = [];
92
+ for (const typeKey of collectReferencedTypeKeys(objectType.fields)) {
93
+ // Escape hatch (ADR-0012): a sensitive lookup is never auto-granted.
94
+ if (sensitive.has(typeKey)) {
95
+ continue;
96
+ }
97
+ // Optional validation: skip references to types the platform doesn't know.
98
+ if (resolve && resolve(typeKey) === undefined) {
99
+ continue;
100
+ }
101
+ derived.push({ typeKey, capability: SUPPORTING_READ_CAPABILITY });
102
+ }
103
+ return derived;
104
+ }
105
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/metadata/dependencies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAiBH;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,MAAM,CAAC;AAyCvE;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,oBAAsD;IAEtD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,oBAAoB,IAAI,EAAE,EAAE,CAAC;QAC7C,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;YACvB,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAkC;IAElC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,KAAK,CAAC,iBAAiB,CAAC;QACpC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAChE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAAgC,EAChC,UAA+C,EAAE;IAEjD,MAAM,SAAS,GAAG,6BAA6B,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC9E,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAE1C,MAAM,OAAO,GAAkC,EAAE,CAAC;IAClD,KAAK,MAAM,OAAO,IAAI,yBAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,qEAAqE;QACrE,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QACD,2EAA2E;QAC3E,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9C,SAAS;QACX,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * The **module-registers-metadata contract**.
3
+ *
4
+ * Per ADR-0003 + 010_Architecture "Module model": a business module plugs into
5
+ * the Core by **declaring metadata** (its object types + fields, the actions it
6
+ * exposes, each operation's access tier / required permission, supporting
7
+ * read-only dependencies, and policies) — it NEVER implements access checks
8
+ * itself. The Core discovers this metadata and gates everything centrally.
9
+ *
10
+ * A module that adds an operation without a classification is denied by default
11
+ * and flagged at build/boot — never silently open (§5.4). Dynamic (admin-defined)
12
+ * object types register via the SAME contract at runtime (§5.5, ADR-0014).
13
+ *
14
+ * TYPES + REGISTRY INTERFACE STUB ONLY — no discovery/enforcement logic here.
15
+ * ADR-0003: framework-agnostic.
16
+ */
17
+ import { type AccessTier, type PermissionKey } from '../authorization/index.js';
18
+ export * from './completeness.js';
19
+ export * from './registry.js';
20
+ export * from './dependencies.js';
21
+ /** A field on a declared object type (metadata only — no storage concern). */
22
+ export interface FieldDescriptor {
23
+ /** Stable field key (business-meaningful, not a column name). */
24
+ readonly key: string;
25
+ readonly label: string;
26
+ /**
27
+ * If this field references another object type, its stable type key — used to
28
+ * auto-derive supporting read-only dependencies (§5.3).
29
+ */
30
+ readonly referencesTypeKey?: string;
31
+ }
32
+ /** An object type a module declares to the Core (§5, "Module model"). */
33
+ export interface ObjectTypeDescriptor {
34
+ /** Stable object-type key (never a table/route name) (§5.2). */
35
+ readonly typeKey: string;
36
+ readonly label: string;
37
+ readonly fields: readonly FieldDescriptor[];
38
+ }
39
+ /**
40
+ * A supporting read-only dependency (§5.3): a subordinate lookup auto-permitted
41
+ * (read-only) whenever the owning action is granted.
42
+ */
43
+ export interface SupportingDependency {
44
+ /** The object-type key that is auto-granted read-only as a dependency. */
45
+ readonly typeKey: string;
46
+ /**
47
+ * Sensitive dependencies MUST NOT be auto-granted (§5.3 escape hatch): when
48
+ * `true`, this reference requires its own explicit permission.
49
+ */
50
+ readonly neverAutoGrant: boolean;
51
+ }
52
+ /**
53
+ * An action a module exposes, bound to a stable permission identity (§5.2) and
54
+ * classified by its access tier (§6). Absence of a classification ⇒ Gated/Deny
55
+ * by default (§5.4, §7.2) — enforced by the Core, not the module.
56
+ */
57
+ export interface ActionDescriptor {
58
+ /** Stable action key (e.g. `create`, `read`, ...). */
59
+ readonly actionKey: string;
60
+ /** Object type this action operates on. */
61
+ readonly typeKey: string;
62
+ /**
63
+ * Baseline reachability (§6). Omit to default to `gated` — the Core treats an
64
+ * unclassified action as Gated (never silently open).
65
+ */
66
+ readonly tier?: AccessTier;
67
+ /** Read-only lookups this action requires to function (§5.3). */
68
+ readonly supportingDependencies?: readonly SupportingDependency[];
69
+ }
70
+ /**
71
+ * The complete metadata a module registers with the Core. This is the ONLY thing
72
+ * a module contributes to the security model — declarations, never checks.
73
+ */
74
+ export interface ModuleMetadata {
75
+ /** Stable module key (business-meaningful). */
76
+ readonly moduleKey: string;
77
+ readonly objectTypes: readonly ObjectTypeDescriptor[];
78
+ readonly actions: readonly ActionDescriptor[];
79
+ }
80
+ /**
81
+ * Resolve an action's baseline access tier (§6, ADR-0004): the action's own
82
+ * `tier`, or `gated` when omitted — the fail-closed default. PURE. This is the
83
+ * single canonical tier-resolution rule; every consumer (registry lookups,
84
+ * completeness check, the future evaluator) MUST route through it rather than
85
+ * re-implementing the `?? 'gated'` default, so the default can never drift.
86
+ */
87
+ export declare function resolveTier(action: ActionDescriptor): AccessTier;
88
+ /**
89
+ * Derive an action's stable permission identity (ADR-0010) within its owning
90
+ * module: `moduleKey:typeKey:actionKey`. PURE — wraps {@link derivePermissionKey}
91
+ * with the action's own `typeKey`. Grants bind to this result.
92
+ *
93
+ * NOTE: `public`-tier actions are reachable without a grant; the permission key
94
+ * still derives (for catalog/audit listing per ADR-0012) but a Public action
95
+ * needs no bound grant to be allowed. The consumer decides whether to require a
96
+ * grant based on {@link resolveTier}.
97
+ */
98
+ export declare function resolveActionPermissionKey(moduleKey: string, action: ActionDescriptor): PermissionKey;
99
+ /**
100
+ * A registered action resolved to its owning module plus its derived stable
101
+ * identity + tier — the shape registry lookups return so callers never re-derive
102
+ * the permission key or re-apply the tier default. Produced by the registry
103
+ * (Team A) from a {@link ModuleMetadata} + {@link ActionDescriptor} via
104
+ * {@link resolveActionPermissionKey} / {@link resolveTier}.
105
+ */
106
+ export interface RegisteredAction {
107
+ /** Owning module's stable key. */
108
+ readonly moduleKey: string;
109
+ /** The declared action. */
110
+ readonly action: ActionDescriptor;
111
+ /** Stable permission identity (ADR-0010) — `moduleKey:typeKey:actionKey`. */
112
+ readonly permissionKey: PermissionKey;
113
+ /** Resolved baseline tier (never undefined — `gated` when unclassified). */
114
+ readonly tier: AccessTier;
115
+ }
116
+ /**
117
+ * Module Registry seam — the Core's intake for module metadata, both at
118
+ * build/startup (static modules) and at runtime (dynamic object types, §5.5),
119
+ * PLUS the resolved lookups the boot-completeness check (ADR-0002/0010) and the
120
+ * decision path consume.
121
+ *
122
+ * CONTRACT ONLY. Team A implements the body (discovery intake, indexing,
123
+ * fail-closed flagging of unclassified operations). Implementations MUST derive
124
+ * `permissionKey`/`tier` via {@link resolveActionPermissionKey}/{@link resolveTier}
125
+ * — never re-implement those rules.
126
+ */
127
+ export interface ModuleRegistry {
128
+ /** Register a static module's declared metadata (build/startup path). */
129
+ register(metadata: ModuleMetadata): void;
130
+ /**
131
+ * Register a runtime-created object type (dynamic-DDL path, §5.5 / ADR-0014).
132
+ * Classified Gated by default; registration is part of the creation's success
133
+ * condition — an unregistered dynamic resource resolves to Deny.
134
+ */
135
+ registerDynamicObjectType(objectType: ObjectTypeDescriptor): void;
136
+ /** Enumerate all registered metadata (discovery/completeness pass, §5.4). */
137
+ list(): readonly ModuleMetadata[];
138
+ /**
139
+ * Resolve a stable object-type key to its registered descriptor, or
140
+ * `undefined` if no such type is registered (⇒ the decision path treats it as
141
+ * `resource_not_registered` → Deny). Spans static + dynamic types.
142
+ */
143
+ resolveObjectType(typeKey: string): ObjectTypeDescriptor | undefined;
144
+ /**
145
+ * Resolve a stable {@link PermissionKey} to the registered action that owns it
146
+ * (with its tier + module), or `undefined` if no live action derives it (an
147
+ * ORPHANED permission — a grant referencing it has no operation to gate).
148
+ */
149
+ resolveByPermissionKey(permissionKey: PermissionKey): RegisteredAction | undefined;
150
+ /** Enumerate every registered action, resolved (completeness cross-check). */
151
+ listActions(): readonly RegisteredAction[];
152
+ }
153
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EACnB,MAAM,2BAA2B,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAKlC,cAAc,eAAe,CAAC;AAK9B,cAAc,mBAAmB,CAAC;AAElC,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,yEAAyE;AACzE,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,sBAAsB,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CACnE;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACtD,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CAEhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,gBAAgB,GACvB,aAAa,CAEf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAEzC;;;;OAIG;IACH,yBAAyB,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAElE,6EAA6E;IAC7E,IAAI,IAAI,SAAS,cAAc,EAAE,CAAC;IAElC;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAAC;IAErE;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,aAAa,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEnF,8EAA8E;IAC9E,WAAW,IAAI,SAAS,gBAAgB,EAAE,CAAC;CAC5C"}