@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,36 @@
1
+ /**
2
+ * Engine seam: **Admin Console** (Layer 10) — the administration experience over
3
+ * the security Core.
4
+ *
5
+ * Manage the human-readable permission catalog, grants, guided record-access
6
+ * policies, access tiers, service accounts, and cross-tenant invitations, and
7
+ * review audit — all in human-readable terms (never routes/ids, ADR-0012). Plus
8
+ * effective-access explain/simulate. Every administrative capability is subject to
9
+ * the §11.3 safeguards (delegated-administration, blast-radius, confirm-and-audit).
10
+ *
11
+ * This is a NEW top-level Core module (sibling to authorization/audit); it touches
12
+ * NO frozen prior-layer seam. The PRELUDE freezes the ports, the shared query +
13
+ * command types, the safeguard SIGNATURES (fail-closed defaults), and the
14
+ * query/command service factories + the §11.3 command pipeline order; the three
15
+ * parallel teams fill the engine bodies:
16
+ * - Team A → the QUERY engine (catalog / explain / simulate / audit viewer).
17
+ * - Team B → the COMMAND engine + the `./safeguards.ts` bodies.
18
+ * - Team C → the React console over the SDK admin surface.
19
+ *
20
+ * ⛔ NON-NEGOTIABLES: ONE decision path (simulate + delegated-admin REUSE
21
+ * `decide()`, ADR-0001); fail-closed defaults everywhere; no raw ids out (the
22
+ * `LabelResolver` chokepoint, ADR-0012); guided builder only (no raw expressions);
23
+ * blast-radius + confirm + audit on destructive commands (§11.3); Public is
24
+ * code-only (the tier command refuses it).
25
+ *
26
+ * APPEND-ONLY re-exports (mirrors the identity/session/authorization/audit
27
+ * barrels). ADR-0003: framework-agnostic — zero-dep Core.
28
+ */
29
+ export * from './ports.js';
30
+ export * from './types.js';
31
+ export * from './safeguards.js';
32
+ export * from './admin-service.js';
33
+ export * from './query/index.js';
34
+ export * from './safeguards-impl.js';
35
+ export * from './command/index.js';
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,cAAc,YAAY,CAAC;AAI3B,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,oBAAoB,CAAC;AAmBnC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Engine seam: **Admin Console** (Layer 10) — the administration experience over
3
+ * the security Core.
4
+ *
5
+ * Manage the human-readable permission catalog, grants, guided record-access
6
+ * policies, access tiers, service accounts, and cross-tenant invitations, and
7
+ * review audit — all in human-readable terms (never routes/ids, ADR-0012). Plus
8
+ * effective-access explain/simulate. Every administrative capability is subject to
9
+ * the §11.3 safeguards (delegated-administration, blast-radius, confirm-and-audit).
10
+ *
11
+ * This is a NEW top-level Core module (sibling to authorization/audit); it touches
12
+ * NO frozen prior-layer seam. The PRELUDE freezes the ports, the shared query +
13
+ * command types, the safeguard SIGNATURES (fail-closed defaults), and the
14
+ * query/command service factories + the §11.3 command pipeline order; the three
15
+ * parallel teams fill the engine bodies:
16
+ * - Team A → the QUERY engine (catalog / explain / simulate / audit viewer).
17
+ * - Team B → the COMMAND engine + the `./safeguards.ts` bodies.
18
+ * - Team C → the React console over the SDK admin surface.
19
+ *
20
+ * ⛔ NON-NEGOTIABLES: ONE decision path (simulate + delegated-admin REUSE
21
+ * `decide()`, ADR-0001); fail-closed defaults everywhere; no raw ids out (the
22
+ * `LabelResolver` chokepoint, ADR-0012); guided builder only (no raw expressions);
23
+ * blast-radius + confirm + audit on destructive commands (§11.3); Public is
24
+ * code-only (the tier command refuses it).
25
+ *
26
+ * APPEND-ONLY re-exports (mirrors the identity/session/authorization/audit
27
+ * barrels). ADR-0003: framework-agnostic — zero-dep Core.
28
+ */
29
+ // The injected admin PORTs (curation / grant / policy / invitation / service-account
30
+ // stores + the audit reader + the id→label chokepoint) + their input shapes:
31
+ export * from './ports.js';
32
+ // The shared query + command TYPES (catalog view, explain, simulate, guided
33
+ // policy, blast-radius, confirm token, invitation state machine, service account,
34
+ // command result + deny reasons):
35
+ export * from './types.js';
36
+ // The §11.3 SAFEGUARD signatures + fail-closed defaults (Team B implements bodies):
37
+ export * from './safeguards.js';
38
+ // The query/command service factories + interfaces + the §11.3 command pipeline
39
+ // order (the seam Teams A/B fill method-by-method):
40
+ export * from './admin-service.js';
41
+ // ---------------------------------------------------------------------------
42
+ // INTEGRATION APPEND (Layer-10 integration owner) — surface the REAL engine
43
+ // bodies on the package barrel. Everything ABOVE this line is the frozen
44
+ // prelude seam (types + fail-closed factories) and is UNCHANGED. The frozen
45
+ // `createAdminQueryService` / `createAdminCommandService` remain the typed
46
+ // fail-closed DEFAULT; the SANCTIONED entry points a consumer wires are the
47
+ // REAL composers re-exported here:
48
+ // - Team A query engine → `composeAdminQueryService(deps)` (query/index.js)
49
+ // - Team B command engine → `createRealAdminCommandService(deps)` (command/index.js)
50
+ // - Team B real safeguards → `checkDelegatedAdminImpl` / `computeBlastRadiusImpl`
51
+ // / `requiresConfirmImpl` (safeguards-impl.js) — the REAL §11.3 safeguards
52
+ // that the real command pipeline (`runAdminCommand`) uses, NEVER the frozen
53
+ // deny-stub `runCommandPipeline`.
54
+ // ---------------------------------------------------------------------------
55
+ // Team A — the REAL query engine (catalog / explain / simulate / audit view) +
56
+ // `composeAdminQueryService`:
57
+ export * from './query/index.js';
58
+ // Team B — the REAL §11.3 safeguard implementations (replace the fail-closed stubs):
59
+ export * from './safeguards-impl.js';
60
+ // Team B — the command engine (real service factory + builders + validators + the
61
+ // real §11.3 pipeline runner `runAdminCommand`):
62
+ export * from './command/index.js';
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,qFAAqF;AACrF,6EAA6E;AAC7E,cAAc,YAAY,CAAC;AAC3B,4EAA4E;AAC5E,kFAAkF;AAClF,kCAAkC;AAClC,cAAc,YAAY,CAAC;AAC3B,oFAAoF;AACpF,cAAc,iBAAiB,CAAC;AAChC,gFAAgF;AAChF,oDAAoD;AACpD,cAAc,oBAAoB,CAAC;AAEnC,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,mCAAmC;AACnC,+EAA+E;AAC/E,uFAAuF;AACvF,oFAAoF;AACpF,+EAA+E;AAC/E,gFAAgF;AAChF,sCAAsC;AACtC,8EAA8E;AAE9E,+EAA+E;AAC/E,8BAA8B;AAC9B,cAAc,kBAAkB,CAAC;AACjC,qFAAqF;AACrF,cAAc,sBAAsB,CAAC;AACrC,kFAAkF;AAClF,iDAAiD;AACjD,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,288 @@
1
+ /**
2
+ * The Admin Console engine **PORTS** — the framework-agnostic contracts the admin
3
+ * query/command engines (`./admin-service.ts`) use to reach the curation overlay,
4
+ * grants, policies, cross-tenant invitations, service accounts, the audit read
5
+ * side, and id→label resolution, WITHOUT the engine ever knowing which DB / cache
6
+ * / directory backs them (Layer 10).
7
+ *
8
+ * ADR-0003 (zero-dep Core): every concrete adapter (MariaDB stores, an IdP-backed
9
+ * label directory, the audit read model) is a real runtime dependency and CANNOT
10
+ * live here. The Core defines only these interfaces; `@astram/guard` ships the
11
+ * concretes and INJECTS them into `createAdminQueryService(...)` /
12
+ * `createAdminCommandService(...)`. This keeps `@astram/core` at ZERO runtime
13
+ * dependencies (the load-bearing invariant) while the substrate stays swappable.
14
+ *
15
+ * ⛔ DATA-ABSENCE vs TRANSIENT-UNAVAILABLE (mirrors session/audit ports). A port
16
+ * returning `null` / `[]` means "the store answered: no such data" — a NORMAL
17
+ * miss the engine handles as an ordinary empty result. A port that genuinely
18
+ * CANNOT answer (DB down / timeout) MUST **throw** so the engine fails CLOSED
19
+ * (ADR-0016) — it must NEVER conflate "down" with "absent" (that would fail open
20
+ * or misreport an empty catalog). Each method below documents its absence value.
21
+ *
22
+ * ⛔ NO RAW IDENTIFIERS reach the UI. The {@link LabelResolver} port is the
23
+ * id→label chokepoint (ADR-0012 / §13.4). Stores traffic in opaque ids for
24
+ * correlation; the query engine resolves every user-facing id to a label via
25
+ * {@link LabelResolver} before it leaves the Core.
26
+ *
27
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
28
+ */
29
+ import type { AuditEvent } from '../audit/index.js';
30
+ import type { AccessTier, PermissionKey } from '../authorization/index.js';
31
+ import type { CatalogCuration, CrossTenantInvitation, Grant, InvitationState, Policy, GuidedPolicy, ServiceAccount } from './types.js';
32
+ /** A curated group descriptor — a human group label the admin defined. */
33
+ export interface CatalogGroup {
34
+ /** The human-readable group label. */
35
+ readonly label: string;
36
+ }
37
+ /**
38
+ * The **catalog curation store** PORT. Persists the admin's custom labels/groups
39
+ * for permissions (the overlay; the registry is the base). Concrete adapter ships
40
+ * in `@astram/guard`.
41
+ */
42
+ export interface CatalogStore {
43
+ /**
44
+ * Read the curation overlaid on `permissionKey`. Returns `null` when NO curation
45
+ * exists (a NORMAL miss — the caller falls back to the registry label). MUST
46
+ * throw if the store cannot answer (fail-closed).
47
+ */
48
+ getCuration(permissionKey: PermissionKey): Promise<CatalogCuration | null>;
49
+ /**
50
+ * Upsert the curation for a permission (custom label/group). Idempotent by the
51
+ * permission key (natural key). Throws on a transient failure.
52
+ */
53
+ setCuration(curation: CatalogCuration): Promise<void>;
54
+ /**
55
+ * List every curated group (for the console's group picker). Returns `[]` when
56
+ * none exist (NORMAL). MUST throw if it cannot answer.
57
+ */
58
+ listGroups(): Promise<readonly CatalogGroup[]>;
59
+ }
60
+ /**
61
+ * The **grant store** PORT. Persists grants (principal + permission + action
62
+ * subset + conditions + tenant). Concrete adapter ships in `@astram/guard`.
63
+ */
64
+ export interface GrantStore {
65
+ /**
66
+ * List the grants bound to `principalId` within `tenantId`. Returns `[]` when
67
+ * the principal has no grants (a NORMAL empty result — the explain view shows
68
+ * "no effective grants"). MUST throw if the store cannot answer (fail-closed).
69
+ */
70
+ listGrants(principalId: string, tenantId: string): Promise<readonly Grant[]>;
71
+ /**
72
+ * Upsert a grant. Idempotent by the grant's natural key (principal + permission
73
+ * + tenant); the engine has already passed the delegated-admin safeguard before
74
+ * this is called. Throws on a transient failure.
75
+ */
76
+ saveGrant(grant: Grant): Promise<void>;
77
+ /**
78
+ * Fetch a single grant by its opaque `grantId`. Returns `null` when NO such
79
+ * grant exists (a NORMAL miss — an unknown/already-removed handle; the command
80
+ * engine maps it to a fail-closed deny so a foreign/nonexistent grantId can
81
+ * NEVER be revoked cross-tenant). MUST throw if the store cannot answer
82
+ * (fail-closed, ADR-0016) — "down" is never conflated with "absent".
83
+ *
84
+ * ⛔ SECURITY-REQUIRED (RULING 2, round 2): revoke takes an opaque `grantId`
85
+ * with no tenant; resolving the grant's OWNING tenant here is what lets the
86
+ * revoke command gate `existing.tenantId !== admin's-authority-tenant` — the
87
+ * same tenant-isolation gate every `service_account_*` command already applies
88
+ * via `ServiceAccountStore.get`. This method is an ADDITIVE port extension: it
89
+ * does not alter any existing signature, so no existing consumer breaks.
90
+ */
91
+ getGrant(grantId: string): Promise<Grant | null>;
92
+ /**
93
+ * Revoke the grant identified by `grantId` (immediate effect). Idempotent — a
94
+ * second revoke of an already-revoked/absent grant is a no-op, NOT an error.
95
+ * Throws only on a transient failure.
96
+ */
97
+ revokeGrant(grantId: string): Promise<void>;
98
+ }
99
+ /**
100
+ * The **policy store** PORT. Persists guided record-access policies (structured
101
+ * field→operator→value forms — never raw expressions, validated upstream).
102
+ * Concrete adapter ships in `@astram/guard`.
103
+ */
104
+ export interface PolicyStore {
105
+ /**
106
+ * List the policies governing object type `typeKey` in `tenantId`. Returns `[]`
107
+ * when none exist (NORMAL). MUST throw if the store cannot answer (fail-closed).
108
+ */
109
+ listPolicies(typeKey: string, tenantId: string): Promise<readonly Policy[]>;
110
+ /**
111
+ * Upsert a guided policy for a tenant, returning the persisted {@link Policy}
112
+ * (with its assigned `policyId`). The engine has already VALIDATED the structure
113
+ * (AC 5) before this is called — the store persists a known-good form. Throws on
114
+ * a transient failure.
115
+ */
116
+ savePolicy(tenantId: string, policy: GuidedPolicy): Promise<Policy>;
117
+ /**
118
+ * Delete the policy identified by `policyId` (immediate effect). Idempotent — a
119
+ * second delete of an absent policy is a no-op, NOT an error. Throws only on a
120
+ * transient failure.
121
+ */
122
+ deletePolicy(policyId: string): Promise<void>;
123
+ }
124
+ /** Input to {@link CrossTenantInvitationStore.create} (all caller-supplied). */
125
+ export interface CreateInvitationInput {
126
+ readonly owningTenantId: string;
127
+ readonly granteeTenantEmail: string;
128
+ readonly objectTypeKeys: readonly string[];
129
+ readonly scope: string;
130
+ readonly actions: readonly string[];
131
+ readonly expiresAtMs: number;
132
+ }
133
+ /**
134
+ * The **cross-tenant invitation store** PORT (§10bis / AC 9). Persists the
135
+ * invitation + its lifecycle state; the ENGINE is the state machine (it validates
136
+ * transitions against {@link import('./types.js').INVITATION_TRANSITIONS} before
137
+ * calling {@link updateState}). Concrete adapter ships in `@astram/guard`.
138
+ *
139
+ * ⛔ An invitation confers NOTHING until `accepted` (§3.7); the store only records
140
+ * state — grant activation is the command engine's job on the `accepted` transition.
141
+ */
142
+ export interface CrossTenantInvitationStore {
143
+ /**
144
+ * Create an invitation in `pending` state, returning the persisted record (with
145
+ * its assigned `id`). Throws on a transient failure.
146
+ */
147
+ create(input: CreateInvitationInput): Promise<CrossTenantInvitation>;
148
+ /**
149
+ * Fetch an invitation by id. Returns `null` when NO such invitation exists (a
150
+ * NORMAL miss the engine maps to `not_found`). MUST throw if it cannot answer.
151
+ */
152
+ get(invitationId: string): Promise<CrossTenantInvitation | null>;
153
+ /**
154
+ * List the invitations addressed to `tenantId` (the grantee's INBOX). Returns
155
+ * `[]` when the inbox is empty (NORMAL). MUST throw if it cannot answer.
156
+ */
157
+ listInbox(tenantId: string): Promise<readonly CrossTenantInvitation[]>;
158
+ /**
159
+ * List the currently-`accepted` (active) invitations OWNED by `tenantId` — the
160
+ * owner-side active-grant management view. Returns `[]` when none (NORMAL).
161
+ * MUST throw if it cannot answer.
162
+ */
163
+ listActiveGrants(tenantId: string): Promise<readonly CrossTenantInvitation[]>;
164
+ /**
165
+ * Persist a state transition to `newState` (the engine has already validated it
166
+ * is a legal transition). Idempotent for an already-in-`newState` record.
167
+ * Throws only on a transient failure.
168
+ */
169
+ updateState(invitationId: string, newState: InvitationState): Promise<void>;
170
+ }
171
+ /** Input to {@link ServiceAccountStore.create} (least-privilege, tenant-bound). */
172
+ export interface CreateServiceAccountStoreInput {
173
+ readonly tenantId: string;
174
+ readonly label: string;
175
+ readonly scope: string;
176
+ readonly expiresAtMs?: number;
177
+ }
178
+ /**
179
+ * The **service-account store** PORT (AC 10). Persists the account + its scope +
180
+ * expiry + revocation, and the credential HASH (never a raw secret — the hash is
181
+ * produced by the Auth layer's hasher port before it reaches here). Concrete
182
+ * adapter ships in `@astram/guard`.
183
+ */
184
+ export interface ServiceAccountStore {
185
+ /**
186
+ * Create a service account (tenant-bound, least-privilege scope), returning the
187
+ * persisted record (with its assigned `id`). Throws on a transient failure.
188
+ */
189
+ create(input: CreateServiceAccountStoreInput): Promise<ServiceAccount>;
190
+ /**
191
+ * Fetch a service account by id. Returns `null` when NO such account exists (a
192
+ * NORMAL miss the engine maps to `not_found`). MUST throw if it cannot answer.
193
+ */
194
+ get(id: string): Promise<ServiceAccount | null>;
195
+ /**
196
+ * List the service accounts in `tenantId`. Returns `[]` when none (NORMAL).
197
+ * MUST throw if it cannot answer (fail-closed).
198
+ */
199
+ list(tenantId: string): Promise<readonly ServiceAccount[]>;
200
+ /** Update an account's scope (re-scope). Throws on a transient failure. */
201
+ updateScope(id: string, scope: string): Promise<void>;
202
+ /**
203
+ * ⛔ Persist the account's credential HASH (never a raw secret). The hash is
204
+ * produced by the Auth layer's Argon2id hasher port BEFORE it reaches here.
205
+ * Throws on a transient failure.
206
+ */
207
+ setCredentialHash(id: string, hash: string): Promise<void>;
208
+ /**
209
+ * Revoke the account (immediate effect, AC 10). Idempotent — revoking an
210
+ * already-revoked account is a no-op, NOT an error. Throws only on transient.
211
+ */
212
+ revoke(id: string): Promise<void>;
213
+ /**
214
+ * Set/clear the account's absolute expiry (UTC epoch ms, or `null` to clear).
215
+ * Throws on a transient failure.
216
+ */
217
+ setExpiry(id: string, expiresAtMs: number | null): Promise<void>;
218
+ }
219
+ /**
220
+ * Query parameters for {@link AuditReader.read} — a tenant-scoped, ordered,
221
+ * paginated audit read for the viewer. `before` is a cursor (an opaque ordering
222
+ * key from a prior page); `limit` bounds the page.
223
+ */
224
+ export interface AuditReadQuery {
225
+ /** Tenant whose audit trail to read (tenant isolation, invariant #4). */
226
+ readonly tenantId: string;
227
+ /** Optional filter by event type. */
228
+ readonly type?: AuditEvent['type'];
229
+ /** Optional filter by actor (opaque id — the viewer resolves it to a label). */
230
+ readonly actorId?: string;
231
+ /** Max events to return (page size). */
232
+ readonly limit?: number;
233
+ /** Opaque pagination cursor — return events ORDERED before this point. */
234
+ readonly before?: string;
235
+ }
236
+ /**
237
+ * The **audit reader** PORT — the ORDERED read side of the audit store, for the
238
+ * viewer (§13). READ ONLY; the WRITE side is the frozen L9 {@link AuditSink}.
239
+ * Concrete adapter ships in `@astram/guard`.
240
+ *
241
+ * ⛔ Returns events in a STABLE order (newest-first) so the viewer paginates
242
+ * deterministically. Returns `[]` when the query matches nothing (NORMAL). MUST
243
+ * throw if the store cannot answer (fail-closed). Actor ids in the returned events
244
+ * are resolved to labels by the query engine via {@link LabelResolver} — the
245
+ * viewer never renders a raw actor id (ADR-0012).
246
+ */
247
+ export interface AuditReader {
248
+ /** Read a page of audit events matching `query`, newest-first. */
249
+ read(query: AuditReadQuery): Promise<readonly AuditEvent[]>;
250
+ }
251
+ /**
252
+ * The kinds of entity the {@link LabelResolver} can resolve to a human label.
253
+ * A closed union so a new resolvable kind is an intentional addition, not an
254
+ * accidental raw-id leak.
255
+ */
256
+ export type LabelKind = 'principal' | 'role' | 'service_account' | 'object_type' | 'permission' | 'tenant';
257
+ /**
258
+ * The **label resolver** PORT — the id→human-label chokepoint (ADR-0012 / §13.4).
259
+ * EVERY user-facing id the query engine emits passes through here first. Concrete
260
+ * adapter (IdP directory / entity tables) ships in `@astram/guard`; a reference
261
+ * resolver proves it.
262
+ *
263
+ * ⛔ NON-NEGOTIABLE (ADR-0012 / §3.3): a DELETED / unknown entity MUST resolve to a
264
+ * sensible human FALLBACK — "Deleted role", "Deleted user", "(unknown)" — and
265
+ * NEVER the raw id. This is the guarantee that no raw identifier ever reaches the
266
+ * UI. `resolve` therefore ALWAYS returns a label string; it does NOT return
267
+ * `null`/the id for a miss — a miss is a fallback label, not an id.
268
+ *
269
+ * ⛔ It MUST throw (not return the id) if it genuinely cannot answer (directory
270
+ * down) so the engine fails CLOSED — a transient failure is NOT the same as a
271
+ * deleted entity (which is a fallback label). Distinguishing them is the point.
272
+ */
273
+ export interface LabelResolver {
274
+ /**
275
+ * Resolve `(kind, id)` to a human display label. A deleted/unknown entity →
276
+ * a fallback label (NEVER the id). `tenantId` scopes the lookup where the id is
277
+ * tenant-relative. Throws on a transient directory failure (fail-closed).
278
+ */
279
+ resolve(kind: LabelKind, id: string, tenantId?: string): Promise<string>;
280
+ }
281
+ /**
282
+ * The default access tier the tier-set command is permitted to assign. Exported
283
+ * for Team B's tier command + the safeguards: the console may set `gated` or
284
+ * `authenticated_global`, but MUST refuse `public` (Public is code-only, §3.6 /
285
+ * AC 8). This names the admin-settable subset so the refusal can't drift.
286
+ */
287
+ export declare const ADMIN_SETTABLE_TIERS: readonly AccessTier[];
288
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/admin/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,MAAM,EACN,YAAY,EACZ,cAAc,EACf,MAAM,YAAY,CAAC;AASpB,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAE3E;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;OAGG;IACH,UAAU,IAAI,OAAO,C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0 +1,39 @@
1
+ /**
2
+ * The Admin Console engine **PORTS** — the framework-agnostic contracts the admin
3
+ * query/command engines (`./admin-service.ts`) use to reach the curation overlay,
4
+ * grants, policies, cross-tenant invitations, service accounts, the audit read
5
+ * side, and id→label resolution, WITHOUT the engine ever knowing which DB / cache
6
+ * / directory backs them (Layer 10).
7
+ *
8
+ * ADR-0003 (zero-dep Core): every concrete adapter (MariaDB stores, an IdP-backed
9
+ * label directory, the audit read model) is a real runtime dependency and CANNOT
10
+ * live here. The Core defines only these interfaces; `@astram/guard` ships the
11
+ * concretes and INJECTS them into `createAdminQueryService(...)` /
12
+ * `createAdminCommandService(...)`. This keeps `@astram/core` at ZERO runtime
13
+ * dependencies (the load-bearing invariant) while the substrate stays swappable.
14
+ *
15
+ * ⛔ DATA-ABSENCE vs TRANSIENT-UNAVAILABLE (mirrors session/audit ports). A port
16
+ * returning `null` / `[]` means "the store answered: no such data" — a NORMAL
17
+ * miss the engine handles as an ordinary empty result. A port that genuinely
18
+ * CANNOT answer (DB down / timeout) MUST **throw** so the engine fails CLOSED
19
+ * (ADR-0016) — it must NEVER conflate "down" with "absent" (that would fail open
20
+ * or misreport an empty catalog). Each method below documents its absence value.
21
+ *
22
+ * ⛔ NO RAW IDENTIFIERS reach the UI. The {@link LabelResolver} port is the
23
+ * id→label chokepoint (ADR-0012 / §13.4). Stores traffic in opaque ids for
24
+ * correlation; the query engine resolves every user-facing id to a label via
25
+ * {@link LabelResolver} before it leaves the Core.
26
+ *
27
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
28
+ */
29
+ /**
30
+ * The default access tier the tier-set command is permitted to assign. Exported
31
+ * for Team B's tier command + the safeguards: the console may set `gated` or
32
+ * `authenticated_global`, but MUST refuse `public` (Public is code-only, §3.6 /
33
+ * AC 8). This names the admin-settable subset so the refusal can't drift.
34
+ */
35
+ export const ADMIN_SETTABLE_TIERS = [
36
+ 'gated',
37
+ 'authenticated_global',
38
+ ];
39
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/admin/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAsVH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IACzD,OAAO;IACP,sBAAsB;CACd,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Admin QUERY engine — the **audit viewer read-model** (Team A, AC 6, §13).
3
+ *
4
+ * Reads a page of audit events over {@link import('../ports.js').AuditReader}
5
+ * (newest-first, tenant-scoped, paginated) and maps each {@link AuditEvent} to an
6
+ * {@link AuditViewEvent} whose actor is resolved to a human LABEL.
7
+ *
8
+ * ⛔ NO RAW IDENTIFIERS (ADR-0012 / §13.4) — the crossing-to-UI invariant. The
9
+ * viewer renders `actorLabel`, NEVER `event.actorId`. `actorLabel` is resolved via
10
+ * the {@link import('../ports.js').LabelResolver} chokepoint; a DELETED actor
11
+ * resolves to the resolver's fallback ("Deleted user"/"(unknown)"), never the raw
12
+ * id. (The frozen {@link AuditViewEvent} embeds the raw `event` for completeness;
13
+ * the SDK projection — Team C — MUST send only `actorLabel` + non-id event fields
14
+ * to the browser, NOT `event.actorId`. Documented in the team DONE.md.)
15
+ *
16
+ * ⛔ DATA-ABSENCE vs TRANSIENT: `read` → `[]` means "nothing matched" (a NORMAL
17
+ * empty page → `nextCursor: null`). A reader that THROWS (unavailable) propagates
18
+ * — a fail-closed read (ADR-0016).
19
+ *
20
+ * ⛔ PAGINATION: the reader returns a STABLE newest-first order. `nextCursor` is
21
+ * the ordering key of the LAST event on a FULL page (there may be more); `null`
22
+ * when the page is short (last page) or no limit was set. The cursor is opaque
23
+ * ordering data (a timestamp key), not a user-facing id.
24
+ *
25
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
26
+ */
27
+ import type { AuditEvent } from '../../audit/index.js';
28
+ import type { AdminQueryDeps } from '../admin-service.js';
29
+ import type { LabelResolver } from '../ports.js';
30
+ import type { AuditReadResult, AuditViewEvent } from '../types.js';
31
+ /**
32
+ * Map one {@link AuditEvent} to an {@link AuditViewEvent} — resolving the actor to
33
+ * a human label via the chokepoint (deleted → fallback, never the id). The
34
+ * resolver may THROW (unavailable) → propagate, fail-closed.
35
+ */
36
+ export declare function toViewEvent(event: AuditEvent, labels: LabelResolver): Promise<AuditViewEvent>;
37
+ /**
38
+ * Derive the opaque next-page cursor. Newest-first events paginate by the LAST
39
+ * (oldest-on-page) event's ordering key. Returns `null` when the page is not full
40
+ * (no more data) or no `limit` was requested (single unbounded read). PURE.
41
+ */
42
+ export declare function deriveNextCursor(events: readonly AuditEvent[], limit: number | undefined): string | null;
43
+ /**
44
+ * The audit viewer read-model (§13 / AC 6): read a page of events for the query's
45
+ * tenant, resolve every actor to a label, echo the query (cursor continuity), and
46
+ * compute the next-page cursor.
47
+ *
48
+ * ⛔ Reads ONLY the fields the port's {@link AuditReadQuery} defines; the returned
49
+ * events carry a resolved `actorLabel` so no raw actor id crosses to the UI.
50
+ */
51
+ export declare function auditView(deps: AdminQueryDeps, query: AuditReadResult['query']): Promise<AuditReadResult>;
52
+ //# sourceMappingURL=audit-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-view.d.ts","sourceRoot":"","sources":["../../../src/admin/query/audit-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,cAAc,CAAC,CAMzB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAC9B,OAAO,CAAC,eAAe,CAAC,CAwB1B"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Admin QUERY engine — the **audit viewer read-model** (Team A, AC 6, §13).
3
+ *
4
+ * Reads a page of audit events over {@link import('../ports.js').AuditReader}
5
+ * (newest-first, tenant-scoped, paginated) and maps each {@link AuditEvent} to an
6
+ * {@link AuditViewEvent} whose actor is resolved to a human LABEL.
7
+ *
8
+ * ⛔ NO RAW IDENTIFIERS (ADR-0012 / §13.4) — the crossing-to-UI invariant. The
9
+ * viewer renders `actorLabel`, NEVER `event.actorId`. `actorLabel` is resolved via
10
+ * the {@link import('../ports.js').LabelResolver} chokepoint; a DELETED actor
11
+ * resolves to the resolver's fallback ("Deleted user"/"(unknown)"), never the raw
12
+ * id. (The frozen {@link AuditViewEvent} embeds the raw `event` for completeness;
13
+ * the SDK projection — Team C — MUST send only `actorLabel` + non-id event fields
14
+ * to the browser, NOT `event.actorId`. Documented in the team DONE.md.)
15
+ *
16
+ * ⛔ DATA-ABSENCE vs TRANSIENT: `read` → `[]` means "nothing matched" (a NORMAL
17
+ * empty page → `nextCursor: null`). A reader that THROWS (unavailable) propagates
18
+ * — a fail-closed read (ADR-0016).
19
+ *
20
+ * ⛔ PAGINATION: the reader returns a STABLE newest-first order. `nextCursor` is
21
+ * the ordering key of the LAST event on a FULL page (there may be more); `null`
22
+ * when the page is short (last page) or no limit was set. The cursor is opaque
23
+ * ordering data (a timestamp key), not a user-facing id.
24
+ *
25
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
26
+ */
27
+ /**
28
+ * Map one {@link AuditEvent} to an {@link AuditViewEvent} — resolving the actor to
29
+ * a human label via the chokepoint (deleted → fallback, never the id). The
30
+ * resolver may THROW (unavailable) → propagate, fail-closed.
31
+ */
32
+ export async function toViewEvent(event, labels) {
33
+ const actorLabel = await labels.resolve('principal', event.actorId, event.tenantId);
34
+ return {
35
+ event,
36
+ actorLabel: actorLabel.length > 0 ? actorLabel : '(unknown actor)',
37
+ };
38
+ }
39
+ /**
40
+ * Derive the opaque next-page cursor. Newest-first events paginate by the LAST
41
+ * (oldest-on-page) event's ordering key. Returns `null` when the page is not full
42
+ * (no more data) or no `limit` was requested (single unbounded read). PURE.
43
+ */
44
+ export function deriveNextCursor(events, limit) {
45
+ if (limit === undefined || events.length < limit || events.length === 0) {
46
+ return null;
47
+ }
48
+ const last = events[events.length - 1];
49
+ if (last === undefined) {
50
+ return null;
51
+ }
52
+ // The stable ordering key is the (UTC) occurrence time; opaque to the caller.
53
+ return String(last.occurredAtMs);
54
+ }
55
+ /**
56
+ * The audit viewer read-model (§13 / AC 6): read a page of events for the query's
57
+ * tenant, resolve every actor to a label, echo the query (cursor continuity), and
58
+ * compute the next-page cursor.
59
+ *
60
+ * ⛔ Reads ONLY the fields the port's {@link AuditReadQuery} defines; the returned
61
+ * events carry a resolved `actorLabel` so no raw actor id crosses to the UI.
62
+ */
63
+ export async function auditView(deps, query) {
64
+ const { auditReader, labels } = deps;
65
+ const readQuery = {
66
+ tenantId: query.tenantId,
67
+ ...(query.type !== undefined ? { type: query.type } : {}),
68
+ ...(query.actorId !== undefined ? { actorId: query.actorId } : {}),
69
+ ...(query.limit !== undefined ? { limit: query.limit } : {}),
70
+ ...(query.before !== undefined ? { before: query.before } : {}),
71
+ };
72
+ // [] = nothing matched (NORMAL empty page); a throw = unavailable → propagates.
73
+ const events = await auditReader.read(readQuery);
74
+ const viewEvents = [];
75
+ for (const event of events) {
76
+ viewEvents.push(await toViewEvent(event, labels));
77
+ }
78
+ return {
79
+ query,
80
+ events: viewEvents,
81
+ nextCursor: deriveNextCursor(events, query.limit),
82
+ };
83
+ }
84
+ //# sourceMappingURL=audit-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-view.js","sourceRoot":"","sources":["../../../src/admin/query/audit-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAOH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAiB,EACjB,MAAqB;IAErB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpF,OAAO;QACL,KAAK;QACL,UAAU,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB;KACnE,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAA6B,EAC7B,KAAyB;IAEzB,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,8EAA8E;IAC9E,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAoB,EACpB,KAA+B;IAE/B,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,SAAS,GAAmB;QAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ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