@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.
Files changed (151) hide show
  1. package/dist/auth/CLAUDE.md +47 -36
  2. package/dist/auth/account_action_specs.d.ts +614 -150
  3. package/dist/auth/account_action_specs.d.ts.map +1 -1
  4. package/dist/auth/account_action_specs.js +56 -52
  5. package/dist/auth/account_route_schema.d.ts +401 -94
  6. package/dist/auth/account_route_schema.d.ts.map +1 -1
  7. package/dist/auth/account_route_schema.js +54 -39
  8. package/dist/auth/account_routes.js +1 -1
  9. package/dist/auth/account_schema.d.ts +531 -118
  10. package/dist/auth/account_schema.d.ts.map +1 -1
  11. package/dist/auth/account_schema.js +76 -58
  12. package/dist/auth/admin_action_specs.d.ts +1753 -240
  13. package/dist/auth/admin_action_specs.d.ts.map +1 -1
  14. package/dist/auth/admin_action_specs.js +28 -26
  15. package/dist/auth/admin_actions.d.ts +4 -4
  16. package/dist/auth/admin_actions.d.ts.map +1 -1
  17. package/dist/auth/admin_actions.js +3 -3
  18. package/dist/auth/all_cell_actions.d.ts +3 -3
  19. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  20. package/dist/auth/all_cell_actions.js +1 -1
  21. package/dist/auth/api_token.d.ts +4 -4
  22. package/dist/auth/api_token.d.ts.map +1 -1
  23. package/dist/auth/api_token.js +3 -3
  24. package/dist/auth/audit_emitter.d.ts +8 -3
  25. package/dist/auth/audit_emitter.d.ts.map +1 -1
  26. package/dist/auth/audit_emitter.js +32 -9
  27. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  28. package/dist/auth/audit_log_queries.js +4 -3
  29. package/dist/auth/audit_log_schema.d.ts +798 -291
  30. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  31. package/dist/auth/audit_log_schema.js +192 -201
  32. package/dist/auth/bootstrap_route_schema.d.ts +173 -50
  33. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  34. package/dist/auth/bootstrap_route_schema.js +35 -16
  35. package/dist/auth/cell_grant_action_specs.d.ts +1 -1
  36. package/dist/auth/cell_grant_action_specs.js +1 -1
  37. package/dist/auth/cell_grant_actions.d.ts +4 -4
  38. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  39. package/dist/auth/cell_grant_actions.js +1 -1
  40. package/dist/auth/credential_type_schema.d.ts +16 -29
  41. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  42. package/dist/auth/credential_type_schema.js +14 -18
  43. package/dist/auth/grant_path_schema.d.ts +15 -29
  44. package/dist/auth/grant_path_schema.d.ts.map +1 -1
  45. package/dist/auth/grant_path_schema.js +13 -17
  46. package/dist/auth/invite_schema.d.ts +98 -26
  47. package/dist/auth/invite_schema.d.ts.map +1 -1
  48. package/dist/auth/invite_schema.js +21 -14
  49. package/dist/auth/migrations.d.ts.map +1 -1
  50. package/dist/auth/migrations.js +28 -1
  51. package/dist/auth/name_schema.d.ts +7 -6
  52. package/dist/auth/name_schema.d.ts.map +1 -1
  53. package/dist/auth/name_schema.js +8 -9
  54. package/dist/auth/password.d.ts +15 -7
  55. package/dist/auth/password.d.ts.map +1 -1
  56. package/dist/auth/password.js +16 -9
  57. package/dist/auth/role_grant_offer_action_specs.d.ts +72 -72
  58. package/dist/auth/role_grant_offer_action_specs.js +2 -2
  59. package/dist/auth/role_grant_offer_actions.d.ts +4 -4
  60. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  61. package/dist/auth/role_grant_offer_actions.js +3 -3
  62. package/dist/auth/role_grant_offer_notifications.d.ts +60 -60
  63. package/dist/auth/role_grant_offer_notifications.js +2 -2
  64. package/dist/auth/role_grant_offer_schema.d.ts +8 -8
  65. package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
  66. package/dist/auth/role_grant_offer_schema.js +10 -10
  67. package/dist/auth/role_schema.d.ts +47 -55
  68. package/dist/auth/role_schema.d.ts.map +1 -1
  69. package/dist/auth/role_schema.js +29 -35
  70. package/dist/auth/scope_kind_schema.d.ts +22 -26
  71. package/dist/auth/scope_kind_schema.d.ts.map +1 -1
  72. package/dist/auth/scope_kind_schema.js +19 -19
  73. package/dist/auth/self_service_role_action_specs.js +1 -1
  74. package/dist/auth/self_service_role_actions.d.ts +6 -6
  75. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  76. package/dist/auth/self_service_role_actions.js +7 -6
  77. package/dist/auth/signup_route_schema.d.ts +71 -21
  78. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  79. package/dist/auth/signup_route_schema.js +18 -16
  80. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  81. package/dist/auth/standard_rpc_actions.js +1 -1
  82. package/dist/auth/token_lifetime.d.ts +33 -9
  83. package/dist/auth/token_lifetime.d.ts.map +1 -1
  84. package/dist/auth/token_lifetime.js +8 -7
  85. package/dist/auth/token_scope.d.ts +99 -25
  86. package/dist/auth/token_scope.d.ts.map +1 -1
  87. package/dist/auth/token_scope.js +57 -35
  88. package/dist/dev/setup.d.ts +14 -7
  89. package/dist/dev/setup.d.ts.map +1 -1
  90. package/dist/dev/setup.js +11 -6
  91. package/dist/primitive_schemas.d.ts +2 -22
  92. package/dist/primitive_schemas.d.ts.map +1 -1
  93. package/dist/primitive_schemas.js +2 -24
  94. package/dist/primitive_schemas_fuz.d.ts +56 -2
  95. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  96. package/dist/primitive_schemas_fuz.js +54 -4
  97. package/dist/testing/CLAUDE.md +29 -8
  98. package/dist/testing/admin_integration.d.ts +3 -3
  99. package/dist/testing/admin_integration.d.ts.map +1 -1
  100. package/dist/testing/admin_integration.js +1 -1
  101. package/dist/testing/app_server.d.ts +3 -1
  102. package/dist/testing/app_server.d.ts.map +1 -1
  103. package/dist/testing/app_server.js +6 -2
  104. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  105. package/dist/testing/audit_drift_guard.js +12 -13
  106. package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
  107. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  108. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  109. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  110. package/dist/testing/cross_backend/identity_parity.js +43 -8
  111. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
  112. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  113. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  114. package/dist/testing/cross_backend/session_cap.js +4 -3
  115. package/dist/testing/cross_backend/setup.d.ts +1 -1
  116. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  117. package/dist/testing/cross_backend/setup.js +45 -42
  118. package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
  119. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  120. package/dist/testing/cross_backend/standard.d.ts +4 -4
  121. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  122. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  123. package/dist/testing/cross_backend/token_lifetime.js +34 -1
  124. package/dist/testing/db_entities.d.ts +3 -1
  125. package/dist/testing/db_entities.d.ts.map +1 -1
  126. package/dist/testing/db_entities.js +4 -2
  127. package/dist/testing/integration.d.ts.map +1 -1
  128. package/dist/testing/integration.js +4 -3
  129. package/dist/testing/token_scope_fixtures.d.ts +24 -0
  130. package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
  131. package/dist/testing/token_scope_fixtures.js +49 -0
  132. package/dist/testing/transports/bootstrap.d.ts +1 -1
  133. package/dist/testing/transports/bootstrap.d.ts.map +1 -1
  134. package/dist/testing/transports/bootstrap.js +13 -12
  135. package/dist/ui/BootstrapForm.svelte +4 -2
  136. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  137. package/dist/ui/SignupForm.svelte +4 -2
  138. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  139. package/dist/zod.d.ts +2 -1
  140. package/dist/zod.d.ts.map +1 -1
  141. package/dist/zod.js +6 -2
  142. package/package.json +1 -1
  143. package/dist/auth/audit_log_schema_fuz.d.ts +0 -39
  144. package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
  145. package/dist/auth/audit_log_schema_fuz.js +0 -37
  146. package/dist/auth/role_schema_fuz.d.ts +0 -30
  147. package/dist/auth/role_schema_fuz.d.ts.map +0 -1
  148. package/dist/auth/role_schema_fuz.js +0 -30
  149. package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
  150. package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
  151. package/dist/auth/scope_kind_schema_fuz.js +0 -31
@@ -28,17 +28,21 @@
28
28
  *
29
29
  * @module
30
30
  */
31
- import { z } from 'zod';
31
+ import { array, boolean, literal, object, optional, parse, string, variant } from '@fuzdev/fuz_schema/schema.ts';
32
+ import { to_bytes } from '@fuzdev/fuz_util/bytes.ts';
32
33
  import { is_valid_name } from './name_schema.js';
33
34
  /** Current `TokenScope` document version. Must match the Rust `TOKEN_SCOPE_VERSION`. */
34
35
  export const TOKEN_SCOPE_VERSION = 1;
35
36
  /**
36
- * Serialized-document cap. Matches the Rust `MAX_TOKEN_SCOPE_BYTES` and
37
+ * Serialized-document cap, in UTF-8 bytes of the document's compact JSON (no
38
+ * whitespace, what `JSON.stringify` writes) — never the text a driver or
39
+ * Postgres prints it as, which for `jsonb` adds a space after every `:` and
40
+ * `,`. Matches the Rust `MAX_TOKEN_SCOPE_BYTES`, which measures the same, and
37
41
  * fuz_forge's `MAX_POLICY_BYTES`.
38
42
  */
39
43
  export const MAX_TOKEN_SCOPE_BYTES = 4 * 1024;
40
44
  /**
41
- * The stored `api_token.scope` document.
45
+ * The stored `api_token.scope` document, a `@fuzdev/fuz_schema` schema.
42
46
  *
43
47
  * `grandfathered` is a fact about the *row* — the `api_token_scope` migration
44
48
  * wrote it; no minter chose it — that only the token list cares about. The
@@ -50,31 +54,31 @@ export const MAX_TOKEN_SCOPE_BYTES = 4 * 1024;
50
54
  * The discriminated union also refuses the contradiction
51
55
  * `{kind: 'full', methods: [...]}`.
52
56
  */
53
- export const TokenScope = z.discriminatedUnion('kind', [
54
- z.strictObject({
55
- version: z.literal(TOKEN_SCOPE_VERSION),
56
- kind: z.literal('full'),
57
- grandfathered: z.boolean().optional()
57
+ export const TokenScope = variant('kind', [
58
+ object({
59
+ version: literal(TOKEN_SCOPE_VERSION),
60
+ kind: literal('full'),
61
+ grandfathered: optional(boolean)
58
62
  }),
59
- z.strictObject({
60
- version: z.literal(TOKEN_SCOPE_VERSION),
61
- kind: z.literal('methods'),
62
- methods: z.array(z.string()),
63
- grandfathered: z.boolean().optional()
63
+ object({
64
+ version: literal(TOKEN_SCOPE_VERSION),
65
+ kind: literal('methods'),
66
+ methods: array(string),
67
+ grandfathered: optional(boolean)
64
68
  })
65
69
  ]);
66
70
  /**
67
71
  * The `scope` input accepted by `account_token_create` — the stored shape minus
68
- * the row-owned fields.
72
+ * the row-owned fields, a `@fuzdev/fuz_schema` schema.
69
73
  *
70
74
  * A minter cannot set `version` or `grandfathered`: the first is stamped by
71
75
  * `token_scope_full` / `token_scope_methods`, and the second is the migration's
72
76
  * mark for tokens that predate scoping. Letting a caller forge `grandfathered`
73
77
  * would turn a tracked debt into a laundered one.
74
78
  */
75
- export const TokenScopeInput = z.discriminatedUnion('kind', [
76
- z.strictObject({ kind: z.literal('full') }),
77
- z.strictObject({ kind: z.literal('methods'), methods: z.array(z.string()) })
79
+ export const TokenScopeInput = variant('kind', [
80
+ object({ kind: literal('full') }),
81
+ object({ kind: literal('methods'), methods: array(string) })
78
82
  ]);
79
83
  /** A deliberately-minted full-authority scope. */
80
84
  export const token_scope_full = () => ({
@@ -219,8 +223,33 @@ export const token_scope_label = (scope) => {
219
223
  return scope.grandfathered ? 'full (grandfathered)' : 'full';
220
224
  return `${scope.methods.length} methods`;
221
225
  };
226
+ /** The UTF-8 byte length of `json`, the unit `MAX_TOKEN_SCOPE_BYTES` counts. */
227
+ const token_scope_json_bytes = (json) => to_bytes(json).length;
222
228
  /**
223
- * Parse a stored document, enforcing the size cap and the schema.
229
+ * Read a document's parsed JSON value, enforcing the size cap on its compact
230
+ * serialization and the schema; `null` when it is unreadable.
231
+ */
232
+ const token_scope_from_value = (value) => {
233
+ // `JSON.stringify(undefined)` returns `undefined`, not a string — so a row
234
+ // missing the column entirely must be caught here rather than measured.
235
+ // Absent is *unreadable*, which is fail-closed: the caller refuses the
236
+ // credential.
237
+ const json = JSON.stringify(value);
238
+ if (json === undefined || token_scope_json_bytes(json) > MAX_TOKEN_SCOPE_BYTES)
239
+ return null;
240
+ const parsed = parse(TokenScope, value);
241
+ return parsed.ok ? parsed.value : null;
242
+ };
243
+ /**
244
+ * Parse a stored document, enforcing the size cap and the schema. The cap is
245
+ * measured on the document's compact serialization, not on `raw`, so the
246
+ * spaced text Postgres prints a `jsonb` as reads as the document it is.
247
+ *
248
+ * A `raw` past twice the cap is refused before it is parsed. Postgres prints a
249
+ * `jsonb` as its compact form plus one space after each `:` and `,` outside
250
+ * strings, each of which is a byte of that form beside its braces, so the
251
+ * printed text of a document either spine can write is under twice the cap and
252
+ * never refused here.
224
253
  *
225
254
  * **Fail-closed**: returns `null` on an unreadable document, and every caller on
226
255
  * the enforcement path treats `null` as "refuse the credential" rather than
@@ -230,7 +259,8 @@ export const token_scope_label = (scope) => {
230
259
  * authority exactly when something is already wrong.
231
260
  */
232
261
  export const parse_token_scope = (raw) => {
233
- if (raw.length > MAX_TOKEN_SCOPE_BYTES)
262
+ // code units, which never exceed UTF-8 bytes, so this refuses no text the byte cap reads
263
+ if (raw.length > 2 * MAX_TOKEN_SCOPE_BYTES)
234
264
  return null;
235
265
  let value;
236
266
  try {
@@ -239,19 +269,19 @@ export const parse_token_scope = (raw) => {
239
269
  catch {
240
270
  return null;
241
271
  }
242
- const parsed = TokenScope.safeParse(value);
243
- return parsed.success ? parsed.data : null;
272
+ return token_scope_from_value(value);
244
273
  };
245
274
  /**
246
- * Serialize for storage, enforcing the size cap.
275
+ * Serialize for storage, enforcing the size cap in UTF-8 bytes.
247
276
  *
248
277
  * Throws on an over-cap document — the mint path maps that to a 400, matching
249
278
  * the Rust side's `TokenScopeError::TooLarge`.
250
279
  */
251
280
  export const serialize_token_scope = (scope) => {
252
281
  const json = JSON.stringify(scope);
253
- if (json.length > MAX_TOKEN_SCOPE_BYTES) {
254
- throw new Error(`token scope document is ${json.length} bytes, exceeding the ${MAX_TOKEN_SCOPE_BYTES} byte cap`);
282
+ const bytes = token_scope_json_bytes(json);
283
+ if (bytes > MAX_TOKEN_SCOPE_BYTES) {
284
+ throw new Error(`token scope document is ${bytes} bytes, exceeding the ${MAX_TOKEN_SCOPE_BYTES} byte cap`);
255
285
  }
256
286
  return json;
257
287
  };
@@ -261,16 +291,8 @@ export const serialize_token_scope = (scope) => {
261
291
  *
262
292
  * The DB driver may hand `scope` back already-parsed (JSONB → object) or as
263
293
  * text depending on backend, so both are normalized here rather than at each
264
- * call site. Lives here rather than beside the queries so the pure scope module
294
+ * call site, and either is held to the cap by its compact serialization, as
295
+ * the Rust spine holds the spaced `scope::text` it reads. Lives here rather than beside the queries so the pure scope module
265
296
  * owns every parse — and so mocking the query module doesn't drag this along.
266
297
  */
267
- export const parse_stored_token_scope = (value) => {
268
- if (typeof value === 'string')
269
- return parse_token_scope(value);
270
- // `JSON.stringify(undefined)` returns `undefined`, not a string — so a row
271
- // missing the column entirely must be caught here rather than reaching
272
- // `parse_token_scope` and throwing on `.length`. Absent is *unreadable*,
273
- // which is fail-closed: the caller refuses the credential.
274
- const json = JSON.stringify(value);
275
- return json === undefined ? null : parse_token_scope(json);
276
- };
298
+ export const parse_stored_token_scope = (value) => typeof value === 'string' ? parse_token_scope(value) : token_scope_from_value(value);
@@ -179,9 +179,12 @@ export declare const create_database: (deps: CommandDeps, db_name: string, optio
179
179
  export declare const reset_database: (deps: CommandDeps & FsReadDeps & FsRemoveDeps, database_url: string, options?: ResetDatabaseOptions) => Promise<ResetDbResult>;
180
180
  /** Input to `seed_dev_account`. */
181
181
  export interface SeedDevAccountInput {
182
- /** Account username. Policy is bypassed — any non-empty string is accepted. */
182
+ /**
183
+ * Account username, stored lowercased, as the `account_username_lowercase`
184
+ * CHECK requires. Its length and grammar (`Username`) are not checked.
185
+ */
183
186
  username: string;
184
- /** Account password. Policy is bypassed — any non-empty string is accepted. */
187
+ /** Account password, hashed as given — the password policy is bypassed. */
185
188
  password: string;
186
189
  /** Roles to grant via role_grant (idempotent). */
187
190
  roles?: ReadonlyArray<string>;
@@ -199,11 +202,15 @@ export interface SeedDevAccountDeps extends QueryDeps {
199
202
  hash_password: (password: string) => Promise<string>;
200
203
  }
201
204
  /**
202
- * Seed a development test account, bypassing username/password policy.
203
- *
204
- * Idempotent by username — if an account with the given username already
205
- * exists, reuses it and only reconciles the requested role grants. Never
206
- * updates an existing password (rerun would silently rotate it).
205
+ * Seed a development test account, bypassing the username and password
206
+ * policy: the username is stored lowercased, for the account and its actor's
207
+ * `name`, its length and grammar unchecked, and the password is hashed as
208
+ * given.
209
+ *
210
+ * Idempotent by username, compared case-insensitively — if an account with
211
+ * the given username already exists, reuses it and only reconciles the
212
+ * requested role grants. Never updates an existing password (rerun would
213
+ * silently rotate it).
207
214
  *
208
215
  * Intended for `scripts/dev_setup.ts` — do not call in production.
209
216
  *
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/dev/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,UAAU,EACV,YAAY,EACZ,WAAW,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAWrD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1B,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,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CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,2CAA2C;AAC3C,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACpD,oEAAoE;IACpE,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,GAC5B,MAAM,kBAAkB,EACxB,OAAO,mBAAmB,EAC1B,UAAU;IAAE,GAAG,CAAC,EAAE,WAAW,CAAA;CAAE,KAC7B,OAAO,CAAC,oBAAoB,CAyC9B,CAAC"}
package/dist/dev/setup.js CHANGED
@@ -283,11 +283,15 @@ export const reset_database = async (deps, database_url, options) => {
283
283
  return { reset: true, skipped: false, db_type: 'postgres' };
284
284
  };
285
285
  /**
286
- * Seed a development test account, bypassing username/password policy.
286
+ * Seed a development test account, bypassing the username and password
287
+ * policy: the username is stored lowercased, for the account and its actor's
288
+ * `name`, its length and grammar unchecked, and the password is hashed as
289
+ * given.
287
290
  *
288
- * Idempotent by username — if an account with the given username already
289
- * exists, reuses it and only reconciles the requested role grants. Never
290
- * updates an existing password (rerun would silently rotate it).
291
+ * Idempotent by username, compared case-insensitively — if an account with
292
+ * the given username already exists, reuses it and only reconciles the
293
+ * requested role grants. Never updates an existing password (rerun would
294
+ * silently rotate it).
291
295
  *
292
296
  * Intended for `scripts/dev_setup.ts` — do not call in production.
293
297
  *
@@ -297,7 +301,8 @@ export const reset_database = async (deps, database_url, options) => {
297
301
  export const seed_dev_account = async (deps, input, options) => {
298
302
  const log = options?.log ?? default_setup_logger;
299
303
  const query_deps = { db: deps.db };
300
- const existing = await query_account_by_username(query_deps, input.username);
304
+ const username = input.username.toLowerCase();
305
+ const existing = await query_account_by_username(query_deps, username);
301
306
  if (existing) {
302
307
  const actors = await query_actors_by_account(query_deps, existing.id);
303
308
  if (actors.length === 0) {
@@ -319,7 +324,7 @@ export const seed_dev_account = async (deps, input, options) => {
319
324
  }
320
325
  const password_hash = await deps.hash_password(input.password);
321
326
  const { account, actor } = await query_create_account_with_actor(query_deps, {
322
- username: input.username,
327
+ username,
323
328
  password_hash
324
329
  });
325
330
  for (const role of input.roles ?? []) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Reusable validator-schema primitives — `bounded_string`, `Username`,
3
- * `UsernameProvided`, `Email`, the branded `Uuid` and `Datetime` with their
4
- * factories, and the hash schemas `Blake3Hash` and `FactHashSchema`. Lives at
3
+ * `Email`, the branded `Uuid` and `Datetime` with their factories, and the
4
+ * hash schema `FactHashSchema`. Lives at
5
5
  * the top level (not inside `auth/` or `http/`) because these shapes don't
6
6
  * depend on or imply any domain — accounts hold a username and email, but
7
7
  * invites, password resets, cells, and other surfaces all reach for the same
@@ -79,23 +79,6 @@ export declare const USERNAME_PROVIDED_LENGTH_MAX = 255;
79
79
  */
80
80
  export declare const Username: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
81
81
  export type Username = z.infer<typeof Username>;
82
- /**
83
- * Username submitted for login or lookup — minimal validation for forward-compatibility if format rules change.
84
- *
85
- * Canonicalized via `.trim().toLowerCase()` at parse time so login's
86
- * per-account rate-limit key and DB lookup see a uniform value
87
- * regardless of casing or surrounding whitespace. Mirrors the storage
88
- * canonicalization on `Username` so submission and storage agree.
89
- *
90
- * The trailing `.refine` rejects a whitespace-only identifier: `.min(1)`
91
- * runs on the raw string (so `" "` passes it), and without the post-trim
92
- * check the value would canonicalize to `""` and fall through to a
93
- * lookup-miss 401 instead of a 400 — an empty identifier is malformed
94
- * input, not a wrong credential. Keeps the Rust spine's
95
- * `account_login` (which rejects empty-after-trim) in parity.
96
- */
97
- export declare const UsernameProvided: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
98
- export type UsernameProvided = z.infer<typeof UsernameProvided>;
99
82
  /**
100
83
  * Maximum email length in **bytes** — RFC 5321 §4.5.3.1.3 path-length limit
101
84
  * (the limit is octets). `Email` bounds the UTF-8 byte length, matching the
@@ -206,9 +189,6 @@ export declare const get_datetime_now: () => Datetime;
206
189
  /** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
207
190
  export declare const DatetimeNow: z.ZodDefault<z.core.$ZodBranded<z.ZodISODateTime, "Datetime", "out">>;
208
191
  export type DatetimeNow = z.infer<typeof DatetimeNow>;
209
- /** Zod schema for a BLAKE3 hex hash — 64 lowercase hex characters (256-bit output). */
210
- export declare const Blake3Hash: z.ZodString;
211
- export type Blake3Hash = z.infer<typeof Blake3Hash>;
212
192
  /**
213
193
  * Wire-form schema for a `blake3:`-prefixed fact hash, whose output is
214
194
  * `FactHash` from `@fuzdev/fuz_util/hash_schemas.ts` — the type
@@ -1 +1 @@
1
- {"version":3,"file":"primitive_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAIlF,gEAAgE;AAChE,MAAM,WAAW,oBAAoB;IACpC,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,oBAAoB,KAAG,CAAC,CAAC,SA+ChE,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,6GAA6G;AAC7G,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,cAAc,Q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AAqC,CAAC;AAC3D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,QAAO,QAAgD,CAAC;AAErF,sFAAsF;AACtF,eAAO,MAAM,WAAW,uEAAqC,CAAC;AAC9D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAEA,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Reusable validator-schema primitives — `bounded_string`, `Username`,
3
- * `UsernameProvided`, `Email`, the branded `Uuid` and `Datetime` with their
4
- * factories, and the hash schemas `Blake3Hash` and `FactHashSchema`. Lives at
3
+ * `Email`, the branded `Uuid` and `Datetime` with their factories, and the
4
+ * hash schema `FactHashSchema`. Lives at
5
5
  * the top level (not inside `auth/` or `http/`) because these shapes don't
6
6
  * depend on or imply any domain — accounts hold a username and email, but
7
7
  * invites, password resets, cells, and other surfaces all reach for the same
@@ -117,24 +117,6 @@ export const USERNAME_PROVIDED_LENGTH_MAX = 255;
117
117
  export const Username = bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX })
118
118
  .regex(USERNAME_REGEX)
119
119
  .transform((s) => s.toLowerCase());
120
- /**
121
- * Username submitted for login or lookup — minimal validation for forward-compatibility if format rules change.
122
- *
123
- * Canonicalized via `.trim().toLowerCase()` at parse time so login's
124
- * per-account rate-limit key and DB lookup see a uniform value
125
- * regardless of casing or surrounding whitespace. Mirrors the storage
126
- * canonicalization on `Username` so submission and storage agree.
127
- *
128
- * The trailing `.refine` rejects a whitespace-only identifier: `.min(1)`
129
- * runs on the raw string (so `" "` passes it), and without the post-trim
130
- * check the value would canonicalize to `""` and fall through to a
131
- * lookup-miss 401 instead of a 400 — an empty identifier is malformed
132
- * input, not a wrong credential. Keeps the Rust spine's
133
- * `account_login` (which rejects empty-after-trim) in parity.
134
- */
135
- export const UsernameProvided = bounded_string({ min: 1, max: USERNAME_PROVIDED_LENGTH_MAX })
136
- .transform((s) => s.trim().toLowerCase())
137
- .refine((s) => s.length > 0, { message: 'Username must not be empty after trimming whitespace' });
138
120
  /**
139
121
  * Maximum email length in **bytes** — RFC 5321 §4.5.3.1.3 path-length limit
140
122
  * (the limit is octets). `Email` bounds the UTF-8 byte length, matching the
@@ -257,10 +239,6 @@ export const Datetime = z.iso.datetime().brand('Datetime');
257
239
  export const get_datetime_now = () => new Date().toISOString();
258
240
  /** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
259
241
  export const DatetimeNow = Datetime.default(get_datetime_now);
260
- /** Zod schema for a BLAKE3 hex hash — 64 lowercase hex characters (256-bit output). */
261
- export const Blake3Hash = z
262
- .string()
263
- .regex(/^[0-9a-f]{64}$/, 'Expected a 64-character lowercase hex blake3 hash');
264
242
  /**
265
243
  * Wire-form schema for a `blake3:`-prefixed fact hash, whose output is
266
244
  * `FactHash` from `@fuzdev/fuz_util/hash_schemas.ts` — the type
@@ -2,7 +2,10 @@
2
2
  * `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Username`,
3
3
  * `Email`, `Uuid`, `UuidWithDefault` (`primitive_schemas.ts`), and
4
4
  * `ActingActor` (`http/auth_shape.ts`), under the same names, for schemas
5
- * written in fuz_schema.
5
+ * written in fuz_schema; `UsernameCanonical`, the username an output carries;
6
+ * `UsernameProvided`, the username login and lookup take; `Timestamp`, a
7
+ * timestamp on the wire; and `Blake3Hash`, a BLAKE3 hex hash. The last four
8
+ * have no Zod twin.
6
9
  *
7
10
  * The output type is shared: the Zod `Uuid` outputs fuz_schema's
8
11
  * `Branded<string, 'Uuid'>` too, so a value parsed by either twin goes where
@@ -12,7 +15,7 @@
12
15
  * says, the max UUID included, and the Rust spine's: every input gets the same
13
16
  * verdict and output from both, and their JSON Schema is the same.
14
17
  *
15
- * The exports are `@nodocs` while the Zod schemas of the same names stay, as
18
+ * The twins are `@nodocs` while the Zod schemas of the same names stay, as
16
19
  * the docs build refuses two exports of one name.
17
20
  *
18
21
  * @module
@@ -43,6 +46,39 @@ export declare const bounded_string: (options: BoundedStringOptions) => PipeSche
43
46
  export declare const Username: PipeSchema<string, PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>>;
44
47
  /** @nodocs */
45
48
  export type Username = Infer<typeof Username>;
49
+ /**
50
+ * A username's canonical grammar, `USERNAME_REGEX` in lowercase: a lowercase
51
+ * letter, then lowercase letters, digits, `_` or `-`, ending in a lowercase
52
+ * letter or digit. What `Username` outputs, and what an `account` row holds
53
+ * (its `account_username_lowercase` CHECK).
54
+ */
55
+ export declare const USERNAME_CANONICAL_REGEX: RegExp;
56
+ /**
57
+ * A username as an account row holds it, the `username` of an output: the
58
+ * bounds of `Username` and `USERNAME_CANONICAL_REGEX`, no transform. A
59
+ * username in any other case fails, where the Zod `Username` lowercased it.
60
+ */
61
+ export declare const UsernameCanonical: PipeSchema<string, PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>>;
62
+ export type UsernameCanonical = Infer<typeof UsernameCanonical>;
63
+ /**
64
+ * Username submitted for login or lookup — minimal validation, for
65
+ * forward-compatibility if the creation grammar changes: at least one and at
66
+ * most `USERNAME_PROVIDED_LENGTH_MAX` UTF-16 code units, measured before
67
+ * trimming, holding a character that isn't whitespace.
68
+ *
69
+ * Canonicalized to `.trim().toLowerCase()` at parse time, so login's
70
+ * per-account rate-limit key and its lookup see one value whatever the casing
71
+ * or surrounding whitespace, as `Username` canonicalizes what is stored.
72
+ *
73
+ * A whitespace-only identifier is refused, not canonicalized to `""` and left
74
+ * to fall through to a lookup-miss 401: an empty identifier is malformed
75
+ * input, not a wrong credential, and the Rust spine's `account_login` refuses
76
+ * it too. JS `\s` is exactly the set `trim` removes (ECMA-262's WhiteSpace and
77
+ * LineTerminator), so the `regex` ahead of the transform refuses what would
78
+ * trim to nothing.
79
+ */
80
+ export declare const UsernameProvided: PipeSchema<string, PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>>;
81
+ export type UsernameProvided = Infer<typeof UsernameProvided>;
46
82
  /**
47
83
  * Email validation, the twin of the Zod `Email`: `EMAIL_REGEX` and at most
48
84
  * `EMAIL_LENGTH_MAX` UTF-8 bytes, no transform. The `max_length` ahead of the
@@ -89,6 +125,24 @@ export declare const UuidWithDefault: import("@fuzdev/fuz_schema/schema.ts").Sch
89
125
  }>>;
90
126
  /** @nodocs */
91
127
  export type UuidWithDefault = Infer<typeof UuidWithDefault>;
128
+ /**
129
+ * A timestamp on the wire: a date and time of RFC 3339 in UTC, fuz_schema's
130
+ * `iso_datetime`, which both spines' `YYYY-MM-DDTHH:MM:SSZ`
131
+ * (`iso8601_timestamp_column`) and a `toISOString()` stamp satisfy. Not
132
+ * branded, unlike the Zod `Datetime`.
133
+ */
134
+ export declare const Timestamp: PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>;
135
+ export type Timestamp = Infer<typeof Timestamp>;
136
+ /** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
137
+ export declare const BLAKE3_HASH_REGEX: RegExp;
138
+ /** The message of a string off `BLAKE3_HASH_REGEX`. */
139
+ export declare const BLAKE3_HASH_MESSAGE = "Expected a 64-character lowercase hex blake3 hash";
140
+ /**
141
+ * A BLAKE3 hex hash: `BLAKE3_HASH_REGEX`, whose issue carries
142
+ * `BLAKE3_HASH_MESSAGE`. A value that is no string gets fuz_schema's message.
143
+ */
144
+ export declare const Blake3Hash: PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").Schema<string, string, "string", undefined>>;
145
+ export type Blake3Hash = Infer<typeof Blake3Hash>;
92
146
  /** The `description` both `ActingActor` twins carry. */
93
147
  export declare const ACTING_ACTOR_DESCRIPTION = "Actor on the authenticated account that this request acts as. Omit on single-actor accounts; required on multi-actor.";
94
148
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"primitive_schemas_fuz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/primitive_schemas_fuz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EASN,MAAM,EAIN,KAAK,KAAK,EACV,KAAK,UAAU,EACf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EASN,KAAK,oBAAoB,EACzB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAC1B,SAAS,oBAAoB,KAC3B,UAAU,CAAC,MAAM,EAAE,OAAO,MAAM,CAKlC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,4HAIpB,CAAC;AACF,cAAc;AACd,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,wGAKjB,CAAC;AACF,cAAc;AACd,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;AAExC;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;;;;CAAmD,CAAC;AACrE,cAAc;AACd,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;GAAqC,CAAC;AAClE,cAAc;AACd,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE5D,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,0HACmF,CAAC;AAEzH;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;;;;;GAAkE,CAAC;AAC3F,cAAc;AACd,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OA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,cAAc;AACd,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,SAAS,wGAA6B,CAAC;AACpD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAEhD,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,QAAmB,CAAC;AAElD,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,UAAU,wGAAuE,CAAC;AAC/F,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,0HACmF,CAAC;AAEzH;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;;;;;GAAkE,CAAC;AAC3F,cAAc;AACd,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -2,7 +2,10 @@
2
2
  * `@fuzdev/fuz_schema` twins of the Zod `bounded_string`, `Username`,
3
3
  * `Email`, `Uuid`, `UuidWithDefault` (`primitive_schemas.ts`), and
4
4
  * `ActingActor` (`http/auth_shape.ts`), under the same names, for schemas
5
- * written in fuz_schema.
5
+ * written in fuz_schema; `UsernameCanonical`, the username an output carries;
6
+ * `UsernameProvided`, the username login and lookup take; `Timestamp`, a
7
+ * timestamp on the wire; and `Blake3Hash`, a BLAKE3 hex hash. The last four
8
+ * have no Zod twin.
6
9
  *
7
10
  * The output type is shared: the Zod `Uuid` outputs fuz_schema's
8
11
  * `Branded<string, 'Uuid'>` too, so a value parsed by either twin goes where
@@ -12,14 +15,14 @@
12
15
  * says, the max UUID included, and the Rust spine's: every input gets the same
13
16
  * verdict and output from both, and their JSON Schema is the same.
14
17
  *
15
- * The exports are `@nodocs` while the Zod schemas of the same names stay, as
18
+ * The twins are `@nodocs` while the Zod schemas of the same names stay, as
16
19
  * the docs build refuses two exports of one name.
17
20
  *
18
21
  * @module
19
22
  */
20
23
  import { meta } from '@fuzdev/fuz_schema/meta.ts';
21
- import { brand, check, max_length, message, min_length, optional, pipe, regex, string, to_lower_case, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
22
- import { create_uuid, EMAIL_LENGTH_MAX, EMAIL_LENGTH_MESSAGE, EMAIL_REGEX, is_email_within_length_max, USERNAME_LENGTH_MAX, USERNAME_LENGTH_MIN, USERNAME_REGEX } from './primitive_schemas.js';
24
+ import { brand, check, iso_datetime, max_length, message, min_length, optional, pipe, regex, string, to_lower_case, transform, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
25
+ import { create_uuid, EMAIL_LENGTH_MAX, EMAIL_LENGTH_MESSAGE, EMAIL_REGEX, is_email_within_length_max, USERNAME_LENGTH_MAX, USERNAME_LENGTH_MIN, USERNAME_PROVIDED_LENGTH_MAX, USERNAME_REGEX } from './primitive_schemas.js';
23
26
  /**
24
27
  * A string schema whose length is bounded in UTF-16 code units, the twin of
25
28
  * the Zod `bounded_string`: fuz_schema's `min_length` / `max_length` read
@@ -46,6 +49,37 @@ export const bounded_string = (options) => {
46
49
  * @nodocs
47
50
  */
48
51
  export const Username = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_REGEX), to_lower_case);
52
+ /**
53
+ * A username's canonical grammar, `USERNAME_REGEX` in lowercase: a lowercase
54
+ * letter, then lowercase letters, digits, `_` or `-`, ending in a lowercase
55
+ * letter or digit. What `Username` outputs, and what an `account` row holds
56
+ * (its `account_username_lowercase` CHECK).
57
+ */
58
+ export const USERNAME_CANONICAL_REGEX = /^[a-z][0-9a-z_-]*[0-9a-z]$/;
59
+ /**
60
+ * A username as an account row holds it, the `username` of an output: the
61
+ * bounds of `Username` and `USERNAME_CANONICAL_REGEX`, no transform. A
62
+ * username in any other case fails, where the Zod `Username` lowercased it.
63
+ */
64
+ export const UsernameCanonical = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_CANONICAL_REGEX));
65
+ /**
66
+ * Username submitted for login or lookup — minimal validation, for
67
+ * forward-compatibility if the creation grammar changes: at least one and at
68
+ * most `USERNAME_PROVIDED_LENGTH_MAX` UTF-16 code units, measured before
69
+ * trimming, holding a character that isn't whitespace.
70
+ *
71
+ * Canonicalized to `.trim().toLowerCase()` at parse time, so login's
72
+ * per-account rate-limit key and its lookup see one value whatever the casing
73
+ * or surrounding whitespace, as `Username` canonicalizes what is stored.
74
+ *
75
+ * A whitespace-only identifier is refused, not canonicalized to `""` and left
76
+ * to fall through to a lookup-miss 401: an empty identifier is malformed
77
+ * input, not a wrong credential, and the Rust spine's `account_login` refuses
78
+ * it too. JS `\s` is exactly the set `trim` removes (ECMA-262's WhiteSpace and
79
+ * LineTerminator), so the `regex` ahead of the transform refuses what would
80
+ * trim to nothing.
81
+ */
82
+ export const UsernameProvided = pipe(bounded_string({ min: 1, max: USERNAME_PROVIDED_LENGTH_MAX }), message(regex(/\S/), 'Username must not be empty after trimming whitespace'), transform((s) => s.trim().toLowerCase()));
49
83
  /**
50
84
  * Email validation, the twin of the Zod `Email`: `EMAIL_REGEX` and at most
51
85
  * `EMAIL_LENGTH_MAX` UTF-8 bytes, no transform. The `max_length` ahead of the
@@ -76,6 +110,22 @@ export const Uuid = brand(pipe(string, uuid, to_lower_case), 'Uuid');
76
110
  * @nodocs
77
111
  */
78
112
  export const UuidWithDefault = with_default_fn(Uuid, create_uuid);
113
+ /**
114
+ * A timestamp on the wire: a date and time of RFC 3339 in UTC, fuz_schema's
115
+ * `iso_datetime`, which both spines' `YYYY-MM-DDTHH:MM:SSZ`
116
+ * (`iso8601_timestamp_column`) and a `toISOString()` stamp satisfy. Not
117
+ * branded, unlike the Zod `Datetime`.
118
+ */
119
+ export const Timestamp = pipe(string, iso_datetime);
120
+ /** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
121
+ export const BLAKE3_HASH_REGEX = /^[0-9a-f]{64}$/;
122
+ /** The message of a string off `BLAKE3_HASH_REGEX`. */
123
+ export const BLAKE3_HASH_MESSAGE = 'Expected a 64-character lowercase hex blake3 hash';
124
+ /**
125
+ * A BLAKE3 hex hash: `BLAKE3_HASH_REGEX`, whose issue carries
126
+ * `BLAKE3_HASH_MESSAGE`. A value that is no string gets fuz_schema's message.
127
+ */
128
+ export const Blake3Hash = pipe(string, message(regex(BLAKE3_HASH_REGEX), BLAKE3_HASH_MESSAGE));
79
129
  /** The `description` both `ActingActor` twins carry. */
80
130
  export const ACTING_ACTOR_DESCRIPTION = 'Actor on the authenticated account that this request acts as. Omit on single-actor accounts; required on multi-actor.';
81
131
  /**