@fuzdev/fuz_app 0.161.0 → 0.163.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.
- package/dist/auth/CLAUDE.md +47 -36
- package/dist/auth/account_action_specs.d.ts +614 -150
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +56 -52
- package/dist/auth/account_route_schema.d.ts +401 -94
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +54 -39
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +531 -118
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +76 -58
- package/dist/auth/admin_action_specs.d.ts +1753 -240
- package/dist/auth/admin_action_specs.d.ts.map +1 -1
- package/dist/auth/admin_action_specs.js +28 -26
- package/dist/auth/admin_actions.d.ts +4 -4
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +3 -3
- package/dist/auth/all_cell_actions.d.ts +3 -3
- package/dist/auth/all_cell_actions.d.ts.map +1 -1
- package/dist/auth/all_cell_actions.js +1 -1
- package/dist/auth/api_token.d.ts +4 -4
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +3 -3
- package/dist/auth/audit_emitter.d.ts +8 -3
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +32 -9
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +4 -3
- package/dist/auth/audit_log_schema.d.ts +798 -291
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +192 -201
- package/dist/auth/bootstrap_route_schema.d.ts +173 -50
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +35 -16
- package/dist/auth/cell_grant_action_specs.d.ts +1 -1
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_actions.d.ts +4 -4
- package/dist/auth/cell_grant_actions.d.ts.map +1 -1
- package/dist/auth/cell_grant_actions.js +1 -1
- package/dist/auth/credential_type_schema.d.ts +16 -29
- package/dist/auth/credential_type_schema.d.ts.map +1 -1
- package/dist/auth/credential_type_schema.js +14 -18
- package/dist/auth/grant_path_schema.d.ts +15 -29
- package/dist/auth/grant_path_schema.d.ts.map +1 -1
- package/dist/auth/grant_path_schema.js +13 -17
- package/dist/auth/invite_schema.d.ts +98 -26
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +21 -14
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +28 -1
- package/dist/auth/name_schema.d.ts +7 -6
- package/dist/auth/name_schema.d.ts.map +1 -1
- package/dist/auth/name_schema.js +8 -9
- package/dist/auth/password.d.ts +15 -7
- package/dist/auth/password.d.ts.map +1 -1
- package/dist/auth/password.js +16 -9
- package/dist/auth/role_grant_offer_action_specs.d.ts +72 -72
- package/dist/auth/role_grant_offer_action_specs.js +2 -2
- package/dist/auth/role_grant_offer_actions.d.ts +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +3 -3
- package/dist/auth/role_grant_offer_notifications.d.ts +60 -60
- package/dist/auth/role_grant_offer_notifications.js +2 -2
- package/dist/auth/role_grant_offer_schema.d.ts +8 -8
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +10 -10
- package/dist/auth/role_schema.d.ts +47 -55
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +29 -35
- package/dist/auth/scope_kind_schema.d.ts +22 -26
- package/dist/auth/scope_kind_schema.d.ts.map +1 -1
- package/dist/auth/scope_kind_schema.js +19 -19
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +6 -6
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +7 -6
- package/dist/auth/signup_route_schema.d.ts +71 -21
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +18 -16
- package/dist/auth/standard_rpc_actions.d.ts +1 -1
- package/dist/auth/standard_rpc_actions.js +1 -1
- package/dist/auth/token_lifetime.d.ts +33 -9
- package/dist/auth/token_lifetime.d.ts.map +1 -1
- package/dist/auth/token_lifetime.js +8 -7
- package/dist/auth/token_scope.d.ts +99 -25
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +57 -35
- package/dist/dev/setup.d.ts +14 -7
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +11 -6
- package/dist/primitive_schemas.d.ts +2 -22
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +2 -24
- package/dist/primitive_schemas_fuz.d.ts +56 -2
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +54 -4
- package/dist/testing/CLAUDE.md +29 -8
- package/dist/testing/admin_integration.d.ts +3 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +1 -1
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +6 -2
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +12 -13
- package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +2 -2
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +43 -8
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +4 -3
- package/dist/testing/cross_backend/setup.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +45 -42
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.d.ts +4 -4
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +34 -1
- package/dist/testing/db_entities.d.ts +3 -1
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +4 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +4 -3
- package/dist/testing/token_scope_fixtures.d.ts +24 -0
- package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
- package/dist/testing/token_scope_fixtures.js +49 -0
- package/dist/testing/transports/bootstrap.d.ts +1 -1
- package/dist/testing/transports/bootstrap.d.ts.map +1 -1
- package/dist/testing/transports/bootstrap.js +13 -12
- package/dist/ui/BootstrapForm.svelte +4 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte +4 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/zod.d.ts +2 -1
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +6 -2
- package/package.json +1 -1
- package/dist/auth/audit_log_schema_fuz.d.ts +0 -39
- package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
- package/dist/auth/audit_log_schema_fuz.js +0 -37
- package/dist/auth/role_schema_fuz.d.ts +0 -30
- package/dist/auth/role_schema_fuz.d.ts.map +0 -1
- package/dist/auth/role_schema_fuz.js +0 -30
- package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
- package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
- 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
|
|
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 `
|
|
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
|
-
* (`
|
|
11
|
-
* `
|
|
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 {
|
|
24
|
-
import { type
|
|
25
|
-
import { type
|
|
26
|
-
import type {
|
|
27
|
-
/** The message of a role name longer than `NAME_LENGTH_MAX
|
|
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
|
|
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.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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:
|
|
41
|
-
export type 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
|
-
/**
|
|
49
|
-
export
|
|
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 `
|
|
73
|
-
* `applicable_scope_kinds` against `
|
|
74
|
-
* `grant_paths` against `
|
|
75
|
-
* results to `
|
|
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
|
-
* `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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
|
|
128
|
+
* no effect on already-built role registries (the factory copies entries
|
|
133
129
|
* into a fresh `Map`).
|
|
134
130
|
*/
|
|
135
|
-
export declare const
|
|
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
|
|
138
|
-
/** Pass `
|
|
139
|
-
credential_types?:
|
|
140
|
-
/** Pass `
|
|
141
|
-
scope_kinds?:
|
|
142
|
-
/** Pass `
|
|
143
|
-
grant_paths?:
|
|
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 `
|
|
146
|
-
export interface
|
|
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
|
|
154
|
-
*
|
|
147
|
+
* Create the role spec map that extends the builtins with app-defined
|
|
148
|
+
* roles.
|
|
155
149
|
*
|
|
156
|
-
* Call once at server init. The
|
|
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
|
-
* `
|
|
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 `{
|
|
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 =
|
|
192
|
-
* const scope_kinds =
|
|
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 =
|
|
187
|
+
* const grant_paths = create_grant_path_registry();
|
|
196
188
|
*
|
|
197
|
-
* const {
|
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"role_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,gEAAgE;AAChE,eAAO,MAAM,wBAAwB,QAAqC,CAAC;AAE3E,mDAAmD;AACnD,eAAO,MAAM,yBAAyB,QAAsC,CAAC;AAE7E;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,0MAA6B,CAAC;AACnD,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAI9C,sFAAsF;AACtF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,iEAAiE;AACjE,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC,+CAA+C;AAC/C,eAAO,MAAM,aAAa,8BAAqC,CAAC;AAEhE,gDAAgD;AAChD,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,IAAI,IAAI,WACX,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,QAAQ;IACxB,qHAAqH;IACrH,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;OAQG;IACH,yBAAyB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAClD;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC/C;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAuB3D,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"}
|
package/dist/auth/role_schema.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Role system — builtin roles, role specs, and extensible role
|
|
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 `
|
|
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
|
-
* (`
|
|
11
|
-
* `
|
|
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 {
|
|
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
|
|
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
|
|
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.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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 `
|
|
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
|
|
65
|
+
* no effect on already-built role registries (the factory copies entries
|
|
68
66
|
* into a fresh `Map`).
|
|
69
67
|
*/
|
|
70
|
-
export const
|
|
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
|
|
103
|
-
*
|
|
100
|
+
* Create the role spec map that extends the builtins with app-defined
|
|
101
|
+
* roles.
|
|
104
102
|
*
|
|
105
|
-
* Call once at server init. The
|
|
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
|
-
* `
|
|
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 `{
|
|
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 =
|
|
141
|
-
* const scope_kinds =
|
|
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 =
|
|
140
|
+
* const grant_paths = create_grant_path_registry();
|
|
145
141
|
*
|
|
146
|
-
* const {
|
|
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
|
|
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
|
|
166
|
-
if (!parsed.
|
|
167
|
-
throw new Error(`Invalid role name "${spec.name}": ${parsed.
|
|
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 (
|
|
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(
|
|
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
|
-
|
|
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
|
-
* `
|
|
19
|
-
* `
|
|
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 {
|
|
35
|
-
/** The message of a scope-kind name longer than `NAME_LENGTH_MAX
|
|
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
|
|
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
|
-
*
|
|
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.
|
|
47
|
-
*
|
|
48
|
-
* `
|
|
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:
|
|
51
|
-
export type 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 `
|
|
61
|
-
export interface
|
|
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
|
|
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 `
|
|
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 `{
|
|
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 {
|
|
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
|
|
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,
|
|
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
|
-
* `
|
|
19
|
-
* `
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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.
|
|
48
|
-
*
|
|
49
|
-
* `
|
|
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
|
|
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 `
|
|
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 `{
|
|
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 {
|
|
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
|
|
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
|
|
86
|
-
if (!parsed.
|
|
87
|
-
throw new Error(`Invalid scope-kind name "${name}": ${parsed.
|
|
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 {
|
|
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 './
|
|
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. */
|