primitive_schemas.ts

Reusable validator-schema primitives — Username, UsernameProvided, Email. Lives at the top level (not inside auth/ or http/) because these shapes don't depend on or imply any domain — accounts hold a username and email, but invites, password resets, future cell-sharing, and other surfaces all reach for the same primitives without going through auth.

Split out from auth/account_schema.ts so the auth module shrinks to entity types + client-safe JSON shapes (its real responsibility) and non-auth consumers can import these primitives without dragging the auth domain along. Future cross-domain primitives (phone, url, slug) land here too.

Declarations
#

6 declarations

view source

Email
#

primitive_schemas.ts view source

ZodEmail

Email validation. Lives here rather than @fuzdev/fuz_util because every current consumer pairs it with Username (signup, invites, audit log) — keeping the two together avoids a cross-package import for the identity-primitive bundle. Promote to fuz_util if a non-identity consumer surfaces.

Username
#

primitive_schemas.ts view source

ZodPipe<ZodString, ZodTransform<string, string>>

Username for account creation — starts with letter, alphanumeric/dash/underscore middle, ends with alphanumeric. No @ or . allowed.

Canonicalized to lowercase at parse time. The regex rejects whitespace outright, so .trim() is unnecessary here. Storage is canonical across every creation site (bootstrap, signup, admin-create, invite acceptance) because the schema is the single source of truth — eliminates the per-caller trim().toLowerCase() ritual and keeps the LOWER(username) = LOWER($1) lookup contract simple.

USERNAME_LENGTH_MAX
#

USERNAME_LENGTH_MIN
#

USERNAME_PROVIDED_LENGTH_MAX
#

UsernameProvided
#

primitive_schemas.ts view source

ZodPipe<ZodString, ZodTransform<string, string>>

Username submitted for login or lookup — minimal validation for forward-compatibility if format rules change.

Canonicalized via .trim().toLowerCase() at parse time so login's per-account rate-limit key and DB lookup see a uniform value regardless of casing or surrounding whitespace. Mirrors the storage canonicalization on Username so submission and storage agree.

Imported by
#