@fuzdev/fuz_app 0.162.0 → 0.164.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 (280) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/action_event_data.d.ts +1 -1
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +4 -0
  5. package/dist/actions/action_spec.d.ts +3 -3
  6. package/dist/actions/action_spec.d.ts.map +1 -1
  7. package/dist/auth/CLAUDE.md +39 -36
  8. package/dist/auth/account_action_specs.d.ts +441 -115
  9. package/dist/auth/account_action_specs.d.ts.map +1 -1
  10. package/dist/auth/account_action_specs.js +47 -46
  11. package/dist/auth/account_route_schema.d.ts +98 -62
  12. package/dist/auth/account_route_schema.d.ts.map +1 -1
  13. package/dist/auth/account_route_schema.js +45 -45
  14. package/dist/auth/account_routes.js +1 -1
  15. package/dist/auth/account_schema.d.ts +54 -27
  16. package/dist/auth/account_schema.d.ts.map +1 -1
  17. package/dist/auth/account_schema.js +16 -18
  18. package/dist/auth/admin_action_specs.d.ts +76 -76
  19. package/dist/auth/admin_action_specs.js +2 -4
  20. package/dist/auth/admin_actions.d.ts +4 -4
  21. package/dist/auth/admin_actions.d.ts.map +1 -1
  22. package/dist/auth/admin_actions.js +3 -3
  23. package/dist/auth/all_cell_actions.d.ts +3 -3
  24. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  25. package/dist/auth/all_cell_actions.js +1 -1
  26. package/dist/auth/api_token.d.ts +4 -4
  27. package/dist/auth/api_token.d.ts.map +1 -1
  28. package/dist/auth/api_token.js +3 -3
  29. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  30. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  31. package/dist/auth/audit_log_route_schema.js +4 -5
  32. package/dist/auth/audit_log_schema.d.ts +46 -66
  33. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  34. package/dist/auth/audit_log_schema.js +34 -30
  35. package/dist/auth/bootstrap_route_schema.d.ts +146 -52
  36. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  37. package/dist/auth/bootstrap_route_schema.js +33 -19
  38. package/dist/auth/cell_grant_action_specs.d.ts +1 -1
  39. package/dist/auth/cell_grant_action_specs.js +1 -1
  40. package/dist/auth/cell_grant_actions.d.ts +4 -4
  41. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  42. package/dist/auth/cell_grant_actions.js +1 -1
  43. package/dist/auth/credential_type_schema.d.ts +16 -29
  44. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  45. package/dist/auth/credential_type_schema.js +14 -18
  46. package/dist/auth/daemon_token.d.ts +4 -4
  47. package/dist/auth/daemon_token.d.ts.map +1 -1
  48. package/dist/auth/daemon_token.js +3 -3
  49. package/dist/auth/daemon_token_middleware.d.ts +1 -1
  50. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  51. package/dist/auth/daemon_token_middleware.js +5 -5
  52. package/dist/auth/grant_path_schema.d.ts +15 -29
  53. package/dist/auth/grant_path_schema.d.ts.map +1 -1
  54. package/dist/auth/grant_path_schema.js +13 -17
  55. package/dist/auth/middleware.js +4 -4
  56. package/dist/auth/migrations.js +1 -1
  57. package/dist/auth/name_schema.d.ts +7 -6
  58. package/dist/auth/name_schema.d.ts.map +1 -1
  59. package/dist/auth/name_schema.js +8 -9
  60. package/dist/auth/password.d.ts +15 -7
  61. package/dist/auth/password.d.ts.map +1 -1
  62. package/dist/auth/password.js +16 -9
  63. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  64. package/dist/auth/role_grant_offer_action_specs.js +2 -2
  65. package/dist/auth/role_grant_offer_actions.d.ts +4 -4
  66. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  67. package/dist/auth/role_grant_offer_actions.js +3 -3
  68. package/dist/auth/role_grant_offer_notifications.js +2 -2
  69. package/dist/auth/role_grant_offer_schema.d.ts +2 -2
  70. package/dist/auth/role_grant_offer_schema.js +2 -2
  71. package/dist/auth/role_schema.d.ts +47 -55
  72. package/dist/auth/role_schema.d.ts.map +1 -1
  73. package/dist/auth/role_schema.js +29 -35
  74. package/dist/auth/scope_kind_schema.d.ts +22 -26
  75. package/dist/auth/scope_kind_schema.d.ts.map +1 -1
  76. package/dist/auth/scope_kind_schema.js +19 -19
  77. package/dist/auth/self_service_role_action_specs.js +1 -1
  78. package/dist/auth/self_service_role_actions.d.ts +6 -6
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +7 -6
  81. package/dist/auth/signup_route_schema.d.ts +71 -21
  82. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  83. package/dist/auth/signup_route_schema.js +17 -19
  84. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  85. package/dist/auth/standard_rpc_actions.js +1 -1
  86. package/dist/auth/token_lifetime.d.ts +33 -9
  87. package/dist/auth/token_lifetime.d.ts.map +1 -1
  88. package/dist/auth/token_lifetime.js +8 -7
  89. package/dist/auth/token_scope.d.ts +99 -25
  90. package/dist/auth/token_scope.d.ts.map +1 -1
  91. package/dist/auth/token_scope.js +57 -35
  92. package/dist/db/CLAUDE.md +2 -1
  93. package/dist/db/file_fact_url.d.ts +11 -6
  94. package/dist/db/file_fact_url.d.ts.map +1 -1
  95. package/dist/db/file_fact_url.js +5 -5
  96. package/dist/db/schema_ready.d.ts +0 -5
  97. package/dist/db/schema_ready.d.ts.map +1 -1
  98. package/dist/db/schema_ready.js +0 -5
  99. package/dist/http/CLAUDE.md +104 -71
  100. package/dist/http/auth_shape.d.ts +48 -29
  101. package/dist/http/auth_shape.d.ts.map +1 -1
  102. package/dist/http/auth_shape.js +12 -85
  103. package/dist/http/body_limit.d.ts +12 -0
  104. package/dist/http/body_limit.d.ts.map +1 -1
  105. package/dist/http/body_limit.js +15 -0
  106. package/dist/http/body_limit_schema.d.ts +20 -0
  107. package/dist/http/body_limit_schema.d.ts.map +1 -0
  108. package/dist/http/body_limit_schema.js +20 -0
  109. package/dist/http/common_routes.d.ts +1 -1
  110. package/dist/http/common_routes.d.ts.map +1 -1
  111. package/dist/http/common_routes.js +11 -14
  112. package/dist/http/db_routes.d.ts.map +1 -1
  113. package/dist/http/db_routes.js +59 -69
  114. package/dist/http/dev_route_error_check.d.ts +70 -0
  115. package/dist/http/dev_route_error_check.d.ts.map +1 -0
  116. package/dist/http/dev_route_error_check.js +119 -0
  117. package/dist/http/error_schemas.d.ts +365 -189
  118. package/dist/http/error_schemas.d.ts.map +1 -1
  119. package/dist/http/error_schemas.js +256 -149
  120. package/dist/http/health_schema.d.ts +10 -6
  121. package/dist/http/health_schema.d.ts.map +1 -1
  122. package/dist/http/health_schema.js +3 -3
  123. package/dist/http/middleware_spec.d.ts +8 -3
  124. package/dist/http/middleware_spec.d.ts.map +1 -1
  125. package/dist/http/origin.d.ts +12 -43
  126. package/dist/http/origin.d.ts.map +1 -1
  127. package/dist/http/origin.js +10 -6
  128. package/dist/http/route_error_check.d.ts +158 -0
  129. package/dist/http/route_error_check.d.ts.map +1 -0
  130. package/dist/http/route_error_check.js +247 -0
  131. package/dist/http/route_errors.d.ts +80 -0
  132. package/dist/http/route_errors.d.ts.map +1 -0
  133. package/dist/http/route_errors.js +83 -0
  134. package/dist/http/route_spec.d.ts +33 -17
  135. package/dist/http/route_spec.d.ts.map +1 -1
  136. package/dist/http/route_spec.js +48 -62
  137. package/dist/http/schema_helpers.d.ts +0 -33
  138. package/dist/http/schema_helpers.d.ts.map +1 -1
  139. package/dist/http/schema_helpers.js +0 -45
  140. package/dist/http/surface.d.ts +19 -12
  141. package/dist/http/surface.d.ts.map +1 -1
  142. package/dist/http/surface.js +25 -38
  143. package/dist/http/surface_query.d.ts +11 -2
  144. package/dist/http/surface_query.d.ts.map +1 -1
  145. package/dist/http/surface_query.js +7 -1
  146. package/dist/primitive_schemas.d.ts +2 -19
  147. package/dist/primitive_schemas.d.ts.map +1 -1
  148. package/dist/primitive_schemas.js +2 -20
  149. package/dist/primitive_schemas_fuz.d.ts +39 -5
  150. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  151. package/dist/primitive_schemas_fuz.js +36 -7
  152. package/dist/rate_limiter.d.ts +13 -0
  153. package/dist/rate_limiter.d.ts.map +1 -1
  154. package/dist/rate_limiter.js +20 -2
  155. package/dist/schema_issues.d.ts +29 -11
  156. package/dist/schema_issues.d.ts.map +1 -1
  157. package/dist/schema_issues.js +11 -10
  158. package/dist/schema_meta.d.ts +8 -1
  159. package/dist/schema_meta.d.ts.map +1 -1
  160. package/dist/schema_meta.js +2 -1
  161. package/dist/server/app_server.d.ts +3 -1
  162. package/dist/server/app_server.d.ts.map +1 -1
  163. package/dist/server/app_server.js +24 -10
  164. package/dist/server/serve_fact_route.d.ts.map +1 -1
  165. package/dist/server/serve_fact_route.js +8 -31
  166. package/dist/server/surface_route.d.ts.map +1 -1
  167. package/dist/server/surface_route.js +5 -6
  168. package/dist/server/x_accel.d.ts +12 -7
  169. package/dist/server/x_accel.d.ts.map +1 -1
  170. package/dist/server/x_accel.js +7 -9
  171. package/dist/testing/CLAUDE.md +55 -44
  172. package/dist/testing/admin_integration.d.ts +3 -3
  173. package/dist/testing/admin_integration.d.ts.map +1 -1
  174. package/dist/testing/admin_integration.js +2 -2
  175. package/dist/testing/adversarial_404.d.ts +4 -18
  176. package/dist/testing/adversarial_404.d.ts.map +1 -1
  177. package/dist/testing/adversarial_404.js +19 -51
  178. package/dist/testing/adversarial_headers.d.ts +3 -4
  179. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  180. package/dist/testing/adversarial_headers.js +8 -6
  181. package/dist/testing/adversarial_input.d.ts.map +1 -1
  182. package/dist/testing/adversarial_input.js +18 -17
  183. package/dist/testing/assertions.d.ts +33 -11
  184. package/dist/testing/assertions.d.ts.map +1 -1
  185. package/dist/testing/assertions.js +52 -12
  186. package/dist/testing/attack_surface.d.ts +5 -35
  187. package/dist/testing/attack_surface.d.ts.map +1 -1
  188. package/dist/testing/attack_surface.js +29 -91
  189. package/dist/testing/auth_apps.d.ts.map +1 -1
  190. package/dist/testing/auth_apps.js +2 -1
  191. package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
  192. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  193. package/dist/testing/cross_backend/action_manifest.js +11 -11
  194. package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
  195. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  196. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/cell_crud.js +2 -1
  198. package/dist/testing/cross_backend/conformance_table.js +1 -1
  199. package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
  200. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  201. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  202. package/dist/testing/cross_backend/fact_serving.js +3 -3
  203. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  204. package/dist/testing/cross_backend/identity_parity.js +39 -6
  205. package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
  206. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  207. package/dist/testing/cross_backend/origin_conformance.js +21 -21
  208. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
  209. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  210. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
  211. package/dist/testing/cross_backend/setup.d.ts +14 -1
  212. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  213. package/dist/testing/cross_backend/setup.js +68 -48
  214. package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
  215. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  216. package/dist/testing/cross_backend/standard.d.ts +4 -4
  217. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  218. package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
  219. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  220. package/dist/testing/cross_backend/testing_origin_check.js +16 -13
  221. package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
  222. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  224. package/dist/testing/cross_backend/token_lifetime.js +34 -1
  225. package/dist/testing/data_exposure.d.ts.map +1 -1
  226. package/dist/testing/data_exposure.js +5 -4
  227. package/dist/testing/error_coverage.d.ts +24 -34
  228. package/dist/testing/error_coverage.d.ts.map +1 -1
  229. package/dist/testing/error_coverage.js +46 -89
  230. package/dist/testing/integration.d.ts.map +1 -1
  231. package/dist/testing/integration.js +6 -14
  232. package/dist/testing/integration_helpers.d.ts +37 -9
  233. package/dist/testing/integration_helpers.d.ts.map +1 -1
  234. package/dist/testing/integration_helpers.js +86 -40
  235. package/dist/testing/middleware.d.ts +3 -5
  236. package/dist/testing/middleware.d.ts.map +1 -1
  237. package/dist/testing/middleware.js +5 -4
  238. package/dist/testing/rate_limiting.d.ts +1 -1
  239. package/dist/testing/rate_limiting.d.ts.map +1 -1
  240. package/dist/testing/rate_limiting.js +5 -4
  241. package/dist/testing/round_trip.d.ts.map +1 -1
  242. package/dist/testing/round_trip.js +5 -3
  243. package/dist/testing/schema_generators.d.ts +10 -3
  244. package/dist/testing/schema_generators.d.ts.map +1 -1
  245. package/dist/testing/schema_generators.js +23 -11
  246. package/dist/testing/stubs.d.ts +10 -1
  247. package/dist/testing/stubs.d.ts.map +1 -1
  248. package/dist/testing/stubs.js +15 -5
  249. package/dist/testing/surface_invariants.d.ts +36 -115
  250. package/dist/testing/surface_invariants.d.ts.map +1 -1
  251. package/dist/testing/surface_invariants.js +106 -269
  252. package/dist/testing/token_scope_fixtures.d.ts +24 -0
  253. package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
  254. package/dist/testing/token_scope_fixtures.js +49 -0
  255. package/dist/testing/transports/bootstrap.d.ts +1 -1
  256. package/dist/testing/transports/bootstrap.d.ts.map +1 -1
  257. package/dist/testing/transports/bootstrap.js +13 -12
  258. package/dist/ui/BootstrapForm.svelte +4 -2
  259. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  260. package/dist/ui/CLAUDE.md +4 -2
  261. package/dist/ui/SignupForm.svelte +4 -2
  262. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  263. package/dist/ui/auth_state.svelte.d.ts.map +1 -1
  264. package/dist/ui/auth_state.svelte.js +2 -8
  265. package/dist/ui/backend_probe.svelte.js +3 -3
  266. package/dist/ui/table_state.svelte.d.ts.map +1 -1
  267. package/dist/ui/table_state.svelte.js +1 -8
  268. package/dist/ui/ui_fetch.d.ts +12 -2
  269. package/dist/ui/ui_fetch.d.ts.map +1 -1
  270. package/dist/ui/ui_fetch.js +22 -4
  271. package/package.json +1 -1
  272. package/dist/auth/audit_log_schema_fuz.d.ts +0 -53
  273. package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
  274. package/dist/auth/audit_log_schema_fuz.js +0 -50
  275. package/dist/auth/role_schema_fuz.d.ts +0 -30
  276. package/dist/auth/role_schema_fuz.d.ts.map +0 -1
  277. package/dist/auth/role_schema_fuz.js +0 -30
  278. package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
  279. package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
  280. package/dist/auth/scope_kind_schema_fuz.js +0 -31
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Role system — builtin roles, role specs, and extensible role schema factory.
2
+ * Role system — builtin roles, role specs, and extensible role registry factory.
3
3
  *
4
4
  * Defines the authorization policy vocabulary: which roles exist, their
5
5
  * required credential types, the scope kinds each role applies to, and
6
6
  * the grant paths through which each role can be granted. Each role
7
- * gets a structured `RoleSpec`; the factory `create_role_schema` merges
7
+ * gets a structured `RoleSpec`; the factory `create_role_registry` merges
8
8
  * builtins with consumer-declared specs and validates every cross-axis
9
9
  * field against the corresponding open registries
10
- * (`create_credential_type_schema`, `create_scope_kind_schema`,
11
- * `create_grant_path_schema`) at construction time so misconfigurations
10
+ * (`create_credential_type_registry`, `create_scope_kind_registry`,
11
+ * `create_grant_path_registry`) at construction time so misconfigurations
12
12
  * fire at server startup, not at first call.
13
13
  *
14
14
  * `RoleSpec` carries the four cross-axis fields that the dispatcher
@@ -20,37 +20,33 @@
20
20
  *
21
21
  * @module
22
22
  */
23
- import { z } from 'zod';
24
- import { type CredentialTypeSchemaResult } from './credential_type_schema.js';
25
- import { type GrantPathSchemaResult } from './grant_path_schema.js';
26
- import type { ScopeKindSchemaResult } from './scope_kind_schema.js';
27
- /** The message of a role name longer than `NAME_LENGTH_MAX`, in both `RoleName`s. */
23
+ import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
24
+ import { type CredentialTypeRegistry } from './credential_type_schema.js';
25
+ import { type GrantPathRegistry } from './grant_path_schema.js';
26
+ import type { ScopeKindRegistry } from './scope_kind_schema.js';
27
+ /** The message of a role name longer than `NAME_LENGTH_MAX`. */
28
28
  export declare const ROLE_NAME_LENGTH_MESSAGE: string;
29
- /** The message of a role name off `NAME_REGEX`, in both `RoleName`s. */
29
+ /** The message of a role name off `NAME_REGEX`. */
30
30
  export declare const ROLE_NAME_PATTERN_MESSAGE: string;
31
31
  /**
32
32
  * Valid role name: the shared name grammar (`auth/name_schema.ts`), lowercase
33
33
  * letters and underscores, no leading, trailing or consecutive underscores, at
34
34
  * most `NAME_LENGTH_MAX` characters. A role string is caller-chosen text until
35
35
  * it passes the grammar, and the grant verbs record the role they refuse in a
36
- * failure audit row, so the grammar bounds its length too. Both `RoleName`s
37
- * hold it, the Zod one here and the `@fuzdev/fuz_schema` twin in
38
- * `auth/role_schema_fuz.ts`.
36
+ * failure audit row, so the grammar bounds its length too. A string it
37
+ * refuses gets `ROLE_NAME_LENGTH_MESSAGE` or `ROLE_NAME_PATTERN_MESSAGE`; a
38
+ * value that is no string, fuz_schema's message.
39
39
  */
40
- export declare const RoleName: z.ZodString;
41
- export type RoleName = z.infer<typeof RoleName>;
40
+ export declare const RoleName: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>>;
41
+ export type RoleName = Infer<typeof RoleName>;
42
42
  /** System-level role. Requires daemon token (filesystem proof). Controls the keep. */
43
43
  export declare const ROLE_KEEPER = "keeper";
44
44
  /** App-level administrative role. Granted via the admin path. */
45
45
  export declare const ROLE_ADMIN = "admin";
46
46
  /** The builtin role names as a const tuple. */
47
47
  export declare const BUILTIN_ROLES: readonly ["keeper", "admin"];
48
- /** Zod schema for builtin roles only. */
49
- export declare const BuiltinRole: z.ZodEnum<{
50
- admin: "admin";
51
- keeper: "keeper";
52
- }>;
53
- export type BuiltinRole = z.infer<typeof BuiltinRole>;
48
+ /** A builtin role name, `keeper` or `admin`. */
49
+ export type BuiltinRole = (typeof BUILTIN_ROLES)[number];
54
50
  /**
55
51
  * Whether `name` is a builtin role (`keeper` / `admin`).
56
52
  *
@@ -69,10 +65,10 @@ export declare const is_builtin_role: (name: string) => name is BuiltinRole;
69
65
  * Each role declares the credential types its holders are meant to use, the
70
66
  * scope kinds it applies to, and the grant paths through which it can
71
67
  * be granted. Every cross-axis field is an open-registry string array —
72
- * `required_credential_types` against `create_credential_type_schema`,
73
- * `applicable_scope_kinds` against `create_scope_kind_schema`,
74
- * `grant_paths` against `create_grant_path_schema`. Pass the registry
75
- * results to `create_role_schema` and every entry is checked at
68
+ * `required_credential_types` against `create_credential_type_registry`,
69
+ * `applicable_scope_kinds` against `create_scope_kind_registry`,
70
+ * `grant_paths` against `create_grant_path_registry`. Pass the registry
71
+ * results to `create_role_registry` and every entry is checked at
76
72
  * construction time.
77
73
  *
78
74
  * Empty arrays carry meaning:
@@ -87,7 +83,7 @@ export declare const is_builtin_role: (name: string) => name is BuiltinRole;
87
83
  * flows. Only useful for diagnostic snapshotting.
88
84
  *
89
85
  * Builtins (`keeper`, `admin`) ship preconfigured in
90
- * `builtin_role_specs_by_name`.
86
+ * `builtin_role_specs`.
91
87
  */
92
88
  export interface RoleSpec {
93
89
  /** Unique role name. Must match `RoleName` — the name grammar and its length cap; collisions with builtins throw. */
@@ -97,7 +93,7 @@ export interface RoleSpec {
97
93
  /**
98
94
  * Credential types whose holders are meant to exercise this role.
99
95
  * Informative only: each entry is checked at construction time against
100
- * the `credential_types` registry passed to `create_role_schema`, but no
96
+ * the `credential_types` registry passed to `create_role_registry`, but no
101
97
  * middleware or dispatcher reads it per request — a route or action
102
98
  * gates credentials with its own `auth.credential_types` (the keeper
103
99
  * verbs declare `['daemon_token']` there). Empty array = any
@@ -107,14 +103,14 @@ export interface RoleSpec {
107
103
  /**
108
104
  * Scope kinds at which this role's role_grants may be granted. Each
109
105
  * entry is checked at construction time against the `scope_kinds`
110
- * registry passed to `create_role_schema`. Empty array = global only.
106
+ * registry passed to `create_role_registry`. Empty array = global only.
111
107
  * v1 keeps this informative-only (no INSERT-time enforcement).
112
108
  */
113
109
  applicable_scope_kinds?: ReadonlyArray<string>;
114
110
  /**
115
111
  * Grant paths through which this role can be granted. Each entry is
116
112
  * checked at construction time against the `grant_paths` registry
117
- * passed to `create_role_schema`. Drives downstream defaults:
113
+ * passed to `create_role_registry`. Drives downstream defaults:
118
114
  *
119
115
  * - `admin_actions.grantable_roles` ⊇ {role : `'admin'` ∈ grant_paths}
120
116
  * - `self_service_role_actions` default eligibility ⊇ {role : `'self_service'` ∈ grant_paths}
@@ -126,36 +122,32 @@ export interface RoleSpec {
126
122
  }
127
123
  /**
128
124
  * Builtin role specs, keyed by role name. Not overridable by consumers
129
- * — read once at startup by `create_role_schema` and the action
125
+ * — read once at startup by `create_role_registry` and the action
130
126
  * factories that fall back to builtins when no consumer `roles` is
131
127
  * supplied. `ReadonlyMap` encodes the contract; runtime mutation has
132
- * no effect on already-built role schemas (the factory copies entries
128
+ * no effect on already-built role registries (the factory copies entries
133
129
  * into a fresh `Map`).
134
130
  */
135
- export declare const builtin_role_specs_by_name: ReadonlyMap<string, RoleSpec>;
131
+ export declare const builtin_role_specs: ReadonlyMap<string, RoleSpec>;
136
132
  /** Optional registries to validate `RoleSpec` cross-axis fields against at construction time. */
137
- export interface CreateRoleSchemaOptions {
138
- /** Pass `create_credential_type_schema()` to validate `RoleSpec.required_credential_types` entries. */
139
- credential_types?: CredentialTypeSchemaResult;
140
- /** Pass `create_scope_kind_schema()` to validate `RoleSpec.applicable_scope_kinds` entries. */
141
- scope_kinds?: ScopeKindSchemaResult;
142
- /** Pass `create_grant_path_schema()` to validate `RoleSpec.grant_paths` entries. */
143
- grant_paths?: GrantPathSchemaResult;
133
+ export interface CreateRoleRegistryOptions {
134
+ /** Pass `create_credential_type_registry()` to validate `RoleSpec.required_credential_types` entries. */
135
+ credential_types?: CredentialTypeRegistry;
136
+ /** Pass `create_scope_kind_registry()` to validate `RoleSpec.applicable_scope_kinds` entries. */
137
+ scope_kinds?: ScopeKindRegistry;
138
+ /** Pass `create_grant_path_registry()` to validate `RoleSpec.grant_paths` entries. */
139
+ grant_paths?: GrantPathRegistry;
144
140
  }
145
- /** The result of `create_role_schema` — a Zod schema and spec map for all roles. */
146
- export interface RoleSchemaResult {
147
- /** Zod schema that validates role strings. Use at I/O boundaries (grant endpoint, role_grant queries). */
148
- Role: z.ZodType<string>;
141
+ /** The result of `create_role_registry` — the spec map for all roles. */
142
+ export interface RoleRegistry {
149
143
  /** Specs for every role (builtins + app-defined). Keyed by role name. */
150
144
  role_specs: ReadonlyMap<string, RoleSpec>;
151
145
  }
152
146
  /**
153
- * Create a role schema and spec map that extends the builtins with
154
- * app-defined roles.
147
+ * Create the role spec map that extends the builtins with app-defined
148
+ * roles.
155
149
  *
156
- * Call once at server init. The returned `Role` schema validates role
157
- * strings at I/O boundaries (grant endpoint, role_grant queries). The
158
- * `role_specs` map is read by the admin / self-service factories to derive
150
+ * Call once at server init. The `role_specs` map is read by the admin / self-service factories to derive
159
151
  * their default eligibility filters from `RoleSpec.grant_paths`, and by the
160
152
  * cell grant verbs to refuse an unregistered role principal.
161
153
  * `RoleSpec.required_credential_types` is validated here but enforced
@@ -177,24 +169,24 @@ export interface RoleSchemaResult {
177
169
  * `grant_paths` is registered in that map. (Builtins use only
178
170
  * `'admin'` and `'bootstrap'`, both of which are builtin grant
179
171
  * paths, so they pass the default registry from
180
- * `create_grant_path_schema()`.)
172
+ * `create_grant_path_registry()`.)
181
173
  *
182
174
  * @param consumer_roles - app-defined role specs
183
175
  * @param options - optional registries for cross-axis validation
184
- * @returns `{Role, role_specs}` — Zod schema and full spec map
176
+ * @returns `{role_specs}` — the full spec map
185
177
  *
186
178
  * @throws Error if any `consumer_roles` entry fails any of the construction-time guards above
187
179
  *
188
180
  * @example
189
181
  * ```ts
190
182
  * // visiones — opt into all four registries for full construction-time validation
191
- * const credential_types = create_credential_type_schema();
192
- * const scope_kinds = create_scope_kind_schema({
183
+ * const credential_types = create_credential_type_registry();
184
+ * const scope_kinds = create_scope_kind_registry({
193
185
  * classroom: {description: 'A classroom — teacher and student role_grants scope here.'},
194
186
  * });
195
- * const grant_paths = create_grant_path_schema();
187
+ * const grant_paths = create_grant_path_registry();
196
188
  *
197
- * const {Role, role_specs} = create_role_schema(
189
+ * const {role_specs} = create_role_registry(
198
190
  * [
199
191
  * {
200
192
  * name: 'teacher',
@@ -207,7 +199,7 @@ export interface RoleSchemaResult {
207
199
  * );
208
200
  * ```
209
201
  */
210
- export declare const create_role_schema: (consumer_roles: ReadonlyArray<RoleSpec>, options?: CreateRoleSchemaOptions) => RoleSchemaResult;
202
+ export declare const create_role_registry: (consumer_roles: ReadonlyArray<RoleSpec>, options?: CreateRoleRegistryOptions) => RoleRegistry;
211
203
  /**
212
204
  * Predicate over a `RoleSpec` map: does the named role include the given
213
205
  * grant path? Returns `false` for unknown roles. Used by
@@ -1 +1 @@
1
- {"version":3,"file":"role_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_schema.ts"],"names":[],"mappings":"AAAA;;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AuB3D,CAAC;AAEH,iGAAiG;AACjG,MAAM,WAAW,yBAAyB;IACzC,yGAAyG;IACzG,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAC1C,iGAAiG;IACjG,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,sFAAsF;IACtF,WAAW,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC5B,yEAAyE;IACzE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAC1C;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAO,MAAM,oBAAoB,GAChC,gBAAgB,aAAa,CAAC,QAAQ,CAAC,EACvC,UAAS,yBAA8B,KACrC,YAwCF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC/B,YAAY,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,EACzC,MAAM,MAAM,EACZ,YAAY,MAAM,KAChB,OAGF,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,0BAA0B,GACtC,YAAY,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,EACzC,YAAY,MAAM,KAChB,KAAK,CAAC,MAAM,CAMd,CAAC"}
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Role system — builtin roles, role specs, and extensible role schema factory.
2
+ * Role system — builtin roles, role specs, and extensible role registry factory.
3
3
  *
4
4
  * Defines the authorization policy vocabulary: which roles exist, their
5
5
  * required credential types, the scope kinds each role applies to, and
6
6
  * the grant paths through which each role can be granted. Each role
7
- * gets a structured `RoleSpec`; the factory `create_role_schema` merges
7
+ * gets a structured `RoleSpec`; the factory `create_role_registry` merges
8
8
  * builtins with consumer-declared specs and validates every cross-axis
9
9
  * field against the corresponding open registries
10
- * (`create_credential_type_schema`, `create_scope_kind_schema`,
11
- * `create_grant_path_schema`) at construction time so misconfigurations
10
+ * (`create_credential_type_registry`, `create_scope_kind_registry`,
11
+ * `create_grant_path_registry`) at construction time so misconfigurations
12
12
  * fire at server startup, not at first call.
13
13
  *
14
14
  * `RoleSpec` carries the four cross-axis fields that the dispatcher
@@ -20,22 +20,22 @@
20
20
  *
21
21
  * @module
22
22
  */
23
- import { z } from 'zod';
23
+ import { format_issue, parse } from '@fuzdev/fuz_schema/schema.ts';
24
24
  import { CREDENTIAL_TYPE_DAEMON_TOKEN } from './credential_type_schema.js';
25
25
  import { GRANT_PATH_ADMIN, GRANT_PATH_BOOTSTRAP } from './grant_path_schema.js';
26
26
  import { create_name_schema, format_name_length_message, format_name_pattern_message } from './name_schema.js';
27
- /** The message of a role name longer than `NAME_LENGTH_MAX`, in both `RoleName`s. */
27
+ /** The message of a role name longer than `NAME_LENGTH_MAX`. */
28
28
  export const ROLE_NAME_LENGTH_MESSAGE = format_name_length_message('Role');
29
- /** The message of a role name off `NAME_REGEX`, in both `RoleName`s. */
29
+ /** The message of a role name off `NAME_REGEX`. */
30
30
  export const ROLE_NAME_PATTERN_MESSAGE = format_name_pattern_message('Role');
31
31
  /**
32
32
  * Valid role name: the shared name grammar (`auth/name_schema.ts`), lowercase
33
33
  * letters and underscores, no leading, trailing or consecutive underscores, at
34
34
  * most `NAME_LENGTH_MAX` characters. A role string is caller-chosen text until
35
35
  * it passes the grammar, and the grant verbs record the role they refuse in a
36
- * failure audit row, so the grammar bounds its length too. Both `RoleName`s
37
- * hold it, the Zod one here and the `@fuzdev/fuz_schema` twin in
38
- * `auth/role_schema_fuz.ts`.
36
+ * failure audit row, so the grammar bounds its length too. A string it
37
+ * refuses gets `ROLE_NAME_LENGTH_MESSAGE` or `ROLE_NAME_PATTERN_MESSAGE`; a
38
+ * value that is no string, fuz_schema's message.
39
39
  */
40
40
  export const RoleName = create_name_schema('Role');
41
41
  // Builtin roles — provided by fuz_app, always available.
@@ -45,8 +45,6 @@ export const ROLE_KEEPER = 'keeper';
45
45
  export const ROLE_ADMIN = 'admin';
46
46
  /** The builtin role names as a const tuple. */
47
47
  export const BUILTIN_ROLES = [ROLE_KEEPER, ROLE_ADMIN];
48
- /** Zod schema for builtin roles only. */
49
- export const BuiltinRole = z.enum(BUILTIN_ROLES);
50
48
  /**
51
49
  * Whether `name` is a builtin role (`keeper` / `admin`).
52
50
  *
@@ -61,13 +59,13 @@ export const BuiltinRole = z.enum(BUILTIN_ROLES);
61
59
  export const is_builtin_role = (name) => name === ROLE_KEEPER || name === ROLE_ADMIN;
62
60
  /**
63
61
  * Builtin role specs, keyed by role name. Not overridable by consumers
64
- * — read once at startup by `create_role_schema` and the action
62
+ * — read once at startup by `create_role_registry` and the action
65
63
  * factories that fall back to builtins when no consumer `roles` is
66
64
  * supplied. `ReadonlyMap` encodes the contract; runtime mutation has
67
- * no effect on already-built role schemas (the factory copies entries
65
+ * no effect on already-built role registries (the factory copies entries
68
66
  * into a fresh `Map`).
69
67
  */
70
- export const builtin_role_specs_by_name = new Map([
68
+ export const builtin_role_specs = new Map([
71
69
  [
72
70
  ROLE_KEEPER,
73
71
  {
@@ -99,12 +97,10 @@ const validate_registry_membership = (role_name, field, values, registry) => {
99
97
  }
100
98
  };
101
99
  /**
102
- * Create a role schema and spec map that extends the builtins with
103
- * app-defined roles.
100
+ * Create the role spec map that extends the builtins with app-defined
101
+ * roles.
104
102
  *
105
- * Call once at server init. The returned `Role` schema validates role
106
- * strings at I/O boundaries (grant endpoint, role_grant queries). The
107
- * `role_specs` map is read by the admin / self-service factories to derive
103
+ * Call once at server init. The `role_specs` map is read by the admin / self-service factories to derive
108
104
  * their default eligibility filters from `RoleSpec.grant_paths`, and by the
109
105
  * cell grant verbs to refuse an unregistered role principal.
110
106
  * `RoleSpec.required_credential_types` is validated here but enforced
@@ -126,24 +122,24 @@ const validate_registry_membership = (role_name, field, values, registry) => {
126
122
  * `grant_paths` is registered in that map. (Builtins use only
127
123
  * `'admin'` and `'bootstrap'`, both of which are builtin grant
128
124
  * paths, so they pass the default registry from
129
- * `create_grant_path_schema()`.)
125
+ * `create_grant_path_registry()`.)
130
126
  *
131
127
  * @param consumer_roles - app-defined role specs
132
128
  * @param options - optional registries for cross-axis validation
133
- * @returns `{Role, role_specs}` — Zod schema and full spec map
129
+ * @returns `{role_specs}` — the full spec map
134
130
  *
135
131
  * @throws Error if any `consumer_roles` entry fails any of the construction-time guards above
136
132
  *
137
133
  * @example
138
134
  * ```ts
139
135
  * // visiones — opt into all four registries for full construction-time validation
140
- * const credential_types = create_credential_type_schema();
141
- * const scope_kinds = create_scope_kind_schema({
136
+ * const credential_types = create_credential_type_registry();
137
+ * const scope_kinds = create_scope_kind_registry({
142
138
  * classroom: {description: 'A classroom — teacher and student role_grants scope here.'},
143
139
  * });
144
- * const grant_paths = create_grant_path_schema();
140
+ * const grant_paths = create_grant_path_registry();
145
141
  *
146
- * const {Role, role_specs} = create_role_schema(
142
+ * const {role_specs} = create_role_registry(
147
143
  * [
148
144
  * {
149
145
  * name: 'teacher',
@@ -156,17 +152,17 @@ const validate_registry_membership = (role_name, field, values, registry) => {
156
152
  * );
157
153
  * ```
158
154
  */
159
- export const create_role_schema = (consumer_roles, options = {}) => {
155
+ export const create_role_registry = (consumer_roles, options = {}) => {
160
156
  const credential_types_registry = options.credential_types?.credential_types ?? null;
161
157
  const scope_kinds_registry = options.scope_kinds?.scope_kinds ?? null;
162
158
  const grant_paths_registry = options.grant_paths?.grant_paths ?? null;
163
159
  const seen = new Set();
164
160
  for (const spec of consumer_roles) {
165
- const parsed = RoleName.safeParse(spec.name);
166
- if (!parsed.success) {
167
- throw new Error(`Invalid role name "${spec.name}": ${parsed.error.issues[0].message}`);
161
+ const parsed = parse(RoleName, spec.name);
162
+ if (!parsed.ok) {
163
+ throw new Error(`Invalid role name "${spec.name}": ${format_issue(parsed.issues[0])}`);
168
164
  }
169
- if (builtin_role_specs_by_name.has(spec.name)) {
165
+ if (builtin_role_specs.has(spec.name)) {
170
166
  throw new Error(`App role "${spec.name}" collides with builtin role`);
171
167
  }
172
168
  if (seen.has(spec.name)) {
@@ -177,13 +173,11 @@ export const create_role_schema = (consumer_roles, options = {}) => {
177
173
  validate_registry_membership(spec.name, 'applicable_scope_kinds', spec.applicable_scope_kinds, scope_kinds_registry);
178
174
  validate_registry_membership(spec.name, 'grant_paths', spec.grant_paths, grant_paths_registry);
179
175
  }
180
- const role_specs = new Map(builtin_role_specs_by_name);
176
+ const role_specs = new Map(builtin_role_specs);
181
177
  for (const spec of consumer_roles) {
182
178
  role_specs.set(spec.name, spec);
183
179
  }
184
- const all_names = [...role_specs.keys()];
185
- const Role = z.enum(all_names);
186
- return { Role, role_specs };
180
+ return { role_specs };
187
181
  };
188
182
  /**
189
183
  * Predicate over a `RoleSpec` map: does the named role include the given
@@ -15,8 +15,8 @@
15
15
  * `(scope_kind=NULL, scope_id=NULL)`.
16
16
  *
17
17
  * Open registry, no builtins. Consumers declare their kinds via
18
- * `create_scope_kind_schema(consumer_kinds)` and pass the result to
19
- * `create_role_schema` so `RoleSpec.applicable_scope_kinds` can be
18
+ * `create_scope_kind_registry(consumer_kinds)` and pass the result to
19
+ * `create_role_registry` so `RoleSpec.applicable_scope_kinds` can be
20
20
  * validated at construction time. Mirrors the open-string registry
21
21
  * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialTypeName`.
22
22
  *
@@ -31,24 +31,25 @@
31
31
  *
32
32
  * @module
33
33
  */
34
- import { z } from 'zod';
35
- /** The message of a scope-kind name longer than `NAME_LENGTH_MAX`, in both `ScopeKindName`s. */
34
+ import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
35
+ /** The message of a scope-kind name longer than `NAME_LENGTH_MAX`. */
36
36
  export declare const SCOPE_KIND_NAME_LENGTH_MESSAGE: string;
37
- /** The message of a scope-kind name off `NAME_REGEX`, in both `ScopeKindName`s. */
37
+ /** The message of a scope-kind name off `NAME_REGEX`. */
38
38
  export declare const SCOPE_KIND_NAME_PATTERN_MESSAGE: string;
39
39
  /**
40
- * Zod schema for valid scope-kind name strings: a registered name, and the
40
+ * Valid scope-kind name strings: a registered name, and the
41
41
  * `scope_kind` the grant inputs take. The shared name grammar
42
42
  * (`auth/name_schema.ts`), at most `NAME_LENGTH_MAX` UTF-16 code units, which
43
43
  * bounds a registered name and the tag where it enters — the grant inputs
44
44
  * (`role_grant_offer_create`, `role_grant_assign`) copy it into the row and
45
45
  * its audit metadata — so no registry declares a kind the grant inputs would
46
- * refuse. Off the grammar is the index-side `'GLOBAL'` token. Twin of the Rust
47
- * spine's `is_valid_name`, and of the `@fuzdev/fuz_schema` `ScopeKindName` in
48
- * `auth/scope_kind_schema_fuz.ts`, built from the same constants.
46
+ * refuse. Off the grammar is the index-side `'GLOBAL'` token. A string it
47
+ * refuses gets `SCOPE_KIND_NAME_LENGTH_MESSAGE` or
48
+ * `SCOPE_KIND_NAME_PATTERN_MESSAGE`; a value that is no string, fuz_schema's
49
+ * message. Twin of the Rust spine's `is_valid_name`.
49
50
  */
50
- export declare const ScopeKindName: z.ZodString;
51
- export type ScopeKindName = z.infer<typeof ScopeKindName>;
51
+ export declare const ScopeKindName: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>>;
52
+ export type ScopeKindName = Infer<typeof ScopeKindName>;
52
53
  /**
53
54
  * Per-scope-kind metadata. `description` is admin-UI-facing copy
54
55
  * (mirrors `RoleSpec.description`). Open shape so v2 can extend without
@@ -57,30 +58,25 @@ export type ScopeKindName = z.infer<typeof ScopeKindName>;
57
58
  export interface ScopeKindMeta {
58
59
  description?: string;
59
60
  }
60
- /** The result of `create_scope_kind_schema` — a Zod schema and metadata map. */
61
- export interface ScopeKindSchemaResult {
62
- /**
63
- * Zod schema that validates scope-kind name strings against the
64
- * registered set. Use at I/O boundaries (admin UIs, codegen) and as
65
- * the construction-time check inside `create_role_schema` for every
66
- * `RoleSpec.applicable_scope_kinds` entry.
67
- */
68
- ScopeKind: z.ZodType<string>;
61
+ /** The result of `create_scope_kind_registry` — the metadata map. */
62
+ export interface ScopeKindRegistry {
69
63
  /**
70
64
  * Map of every registered scope-kind to its metadata. Keyed by name.
71
- * Read at startup by admin / codegen surfaces.
65
+ * Read at startup by admin / codegen surfaces, and by
66
+ * `create_role_registry` to check every `RoleSpec.applicable_scope_kinds`
67
+ * entry.
72
68
  */
73
69
  scope_kinds: ReadonlyMap<string, ScopeKindMeta>;
74
70
  }
75
71
  /**
76
- * Create a scope-kind schema from a consumer-declared registry.
72
+ * Create a scope-kind registry from the consumer-declared set.
77
73
  *
78
74
  * Open registry — no builtins. The `'GLOBAL'` token used inside the
79
75
  * partial unique indexes on `role_grant` and `role_grant_offer` is not a
80
76
  * registry entry (it's an index expression only), and no consumer can
81
77
  * declare it because the regex rejects uppercase.
82
78
  *
83
- * Call once at server init. Pass the result into `create_role_schema`'s
79
+ * Call once at server init. Pass the result into `create_role_registry`'s
84
80
  * optional `scope_kinds` parameter so each role's
85
81
  * `applicable_scope_kinds` entries are validated against this set at
86
82
  * construction time. v1 keeps `applicable_scope_kinds` informative-only
@@ -89,17 +85,17 @@ export interface ScopeKindSchemaResult {
89
85
  * consumer usage.
90
86
  *
91
87
  * @param consumer_kinds - the consumer-declared scope-kind set with optional metadata
92
- * @returns `{ScopeKind, scope_kinds}` — Zod schema and metadata map
88
+ * @returns `{scope_kinds}` — the metadata map
93
89
  *
94
90
  * @throws Error if any `consumer_kinds` key fails `ScopeKindName` (its grammar or its length cap) or appears more than once
95
91
  *
96
92
  * @example
97
93
  * ```ts
98
94
  * // visiones
99
- * const {ScopeKind, scope_kinds} = create_scope_kind_schema({
95
+ * const {scope_kinds} = create_scope_kind_registry({
100
96
  * classroom: {description: 'A classroom — teacher and student role_grants scope here.'},
101
97
  * });
102
98
  * ```
103
99
  */
104
- export declare const create_scope_kind_schema: (consumer_kinds: Record<string, ScopeKindMeta>) => ScopeKindSchemaResult;
100
+ export declare const create_scope_kind_registry: (consumer_kinds: Record<string, ScopeKindMeta>) => ScopeKindRegistry;
105
101
  //# sourceMappingURL=scope_kind_schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scope_kind_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/scope_kind_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,gGAAgG;AAChG,eAAO,MAAM,8BAA8B,QAA2C,CAAC;AAEvF,mFAAmF;AACnF,eAAO,MAAM,+BAA+B,QAA4C,CAAC;AAEzF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,aAAmC,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gFAAgF;AAChF,MAAM,WAAW,qBAAqB;IACrC;;;;;OAKG;IACH,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,wBAAwB,GACpC,gBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KAC3C,qBAwBF,CAAC"}
1
+ {"version":3,"file":"scope_kind_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/scope_kind_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAQ/E,sEAAsE;AACtE,eAAO,MAAM,8BAA8B,QAA2C,CAAC;AAEvF,yDAAyD;AACzD,eAAO,MAAM,+BAA+B,QAA4C,CAAC;AAEzF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,0MAAmC,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IACjC;;;;;OAKG;IACH,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,0BAA0B,GACtC,gBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KAC3C,iBAqBF,CAAC"}
@@ -15,8 +15,8 @@
15
15
  * `(scope_kind=NULL, scope_id=NULL)`.
16
16
  *
17
17
  * Open registry, no builtins. Consumers declare their kinds via
18
- * `create_scope_kind_schema(consumer_kinds)` and pass the result to
19
- * `create_role_schema` so `RoleSpec.applicable_scope_kinds` can be
18
+ * `create_scope_kind_registry(consumer_kinds)` and pass the result to
19
+ * `create_role_registry` so `RoleSpec.applicable_scope_kinds` can be
20
20
  * validated at construction time. Mirrors the open-string registry
21
21
  * pattern used for `RoleName`, `AuditEventTypeName`, and `CredentialTypeName`.
22
22
  *
@@ -31,33 +31,34 @@
31
31
  *
32
32
  * @module
33
33
  */
34
- import { z } from 'zod';
34
+ import { format_issue, parse } from '@fuzdev/fuz_schema/schema.ts';
35
35
  import { create_name_schema, format_name_length_message, format_name_pattern_message } from './name_schema.js';
36
- /** The message of a scope-kind name longer than `NAME_LENGTH_MAX`, in both `ScopeKindName`s. */
36
+ /** The message of a scope-kind name longer than `NAME_LENGTH_MAX`. */
37
37
  export const SCOPE_KIND_NAME_LENGTH_MESSAGE = format_name_length_message('Scope-kind');
38
- /** The message of a scope-kind name off `NAME_REGEX`, in both `ScopeKindName`s. */
38
+ /** The message of a scope-kind name off `NAME_REGEX`. */
39
39
  export const SCOPE_KIND_NAME_PATTERN_MESSAGE = format_name_pattern_message('Scope-kind');
40
40
  /**
41
- * Zod schema for valid scope-kind name strings: a registered name, and the
41
+ * Valid scope-kind name strings: a registered name, and the
42
42
  * `scope_kind` the grant inputs take. The shared name grammar
43
43
  * (`auth/name_schema.ts`), at most `NAME_LENGTH_MAX` UTF-16 code units, which
44
44
  * bounds a registered name and the tag where it enters — the grant inputs
45
45
  * (`role_grant_offer_create`, `role_grant_assign`) copy it into the row and
46
46
  * its audit metadata — so no registry declares a kind the grant inputs would
47
- * refuse. Off the grammar is the index-side `'GLOBAL'` token. Twin of the Rust
48
- * spine's `is_valid_name`, and of the `@fuzdev/fuz_schema` `ScopeKindName` in
49
- * `auth/scope_kind_schema_fuz.ts`, built from the same constants.
47
+ * refuse. Off the grammar is the index-side `'GLOBAL'` token. A string it
48
+ * refuses gets `SCOPE_KIND_NAME_LENGTH_MESSAGE` or
49
+ * `SCOPE_KIND_NAME_PATTERN_MESSAGE`; a value that is no string, fuz_schema's
50
+ * message. Twin of the Rust spine's `is_valid_name`.
50
51
  */
51
52
  export const ScopeKindName = create_name_schema('Scope-kind');
52
53
  /**
53
- * Create a scope-kind schema from a consumer-declared registry.
54
+ * Create a scope-kind registry from the consumer-declared set.
54
55
  *
55
56
  * Open registry — no builtins. The `'GLOBAL'` token used inside the
56
57
  * partial unique indexes on `role_grant` and `role_grant_offer` is not a
57
58
  * registry entry (it's an index expression only), and no consumer can
58
59
  * declare it because the regex rejects uppercase.
59
60
  *
60
- * Call once at server init. Pass the result into `create_role_schema`'s
61
+ * Call once at server init. Pass the result into `create_role_registry`'s
61
62
  * optional `scope_kinds` parameter so each role's
62
63
  * `applicable_scope_kinds` entries are validated against this set at
63
64
  * construction time. v1 keeps `applicable_scope_kinds` informative-only
@@ -66,35 +67,34 @@ export const ScopeKindName = create_name_schema('Scope-kind');
66
67
  * consumer usage.
67
68
  *
68
69
  * @param consumer_kinds - the consumer-declared scope-kind set with optional metadata
69
- * @returns `{ScopeKind, scope_kinds}` — Zod schema and metadata map
70
+ * @returns `{scope_kinds}` — the metadata map
70
71
  *
71
72
  * @throws Error if any `consumer_kinds` key fails `ScopeKindName` (its grammar or its length cap) or appears more than once
72
73
  *
73
74
  * @example
74
75
  * ```ts
75
76
  * // visiones
76
- * const {ScopeKind, scope_kinds} = create_scope_kind_schema({
77
+ * const {scope_kinds} = create_scope_kind_registry({
77
78
  * classroom: {description: 'A classroom — teacher and student role_grants scope here.'},
78
79
  * });
79
80
  * ```
80
81
  */
81
- export const create_scope_kind_schema = (consumer_kinds) => {
82
+ export const create_scope_kind_registry = (consumer_kinds) => {
82
83
  const names = Object.keys(consumer_kinds);
83
84
  const seen = new Set();
84
85
  for (const name of names) {
85
- const parsed = ScopeKindName.safeParse(name);
86
- if (!parsed.success) {
87
- throw new Error(`Invalid scope-kind name "${name}": ${parsed.error.issues[0].message}`);
86
+ const parsed = parse(ScopeKindName, name);
87
+ if (!parsed.ok) {
88
+ throw new Error(`Invalid scope-kind name "${name}": ${format_issue(parsed.issues[0])}`);
88
89
  }
89
90
  if (seen.has(name)) {
90
91
  throw new Error(`Duplicate scope-kind name "${name}"`);
91
92
  }
92
93
  seen.add(name);
93
94
  }
94
- const ScopeKind = names.length === 0 ? z.never() : z.enum(names);
95
95
  const scope_kinds = new Map();
96
96
  for (const name of names) {
97
97
  scope_kinds.set(name, consumer_kinds[name]);
98
98
  }
99
- return { ScopeKind, scope_kinds };
99
+ return { scope_kinds };
100
100
  };
@@ -10,7 +10,7 @@
10
10
  import { meta } from '@fuzdev/fuz_schema/meta.ts';
11
11
  import { boolean, literal, object } from '@fuzdev/fuz_schema/schema.ts';
12
12
  import { ActingActor } from '../primitive_schemas_fuz.js';
13
- import { RoleName } from './role_schema_fuz.js';
13
+ import { RoleName } from './role_schema.js';
14
14
  /** Error reason — caller asked to self-toggle a role outside the configured allowlist. */
15
15
  export const ERROR_ROLE_NOT_SELF_SERVICE_ELIGIBLE = 'role_not_self_service_eligible';
16
16
  /** Input for `self_service_role_set`, a `@fuzdev/fuz_schema` schema. */