@numen-crypto/contract
v0.2.2
Published
Numen API contracts: zod schemas, types, route registry and error codes shared between backend and frontend
Readme
@numen-crypto/contract
Shared API contracts for the Numen platform: zod schemas, inferred TypeScript types, REST route registry and error codes. Consumed by the backend (NestJS) and the frontend (Next.js) so request/response shapes stay in sync from a single source.
Install
Published to npm under the numen-crypto org:
npm install @numen-crypto/contract zodzod is a peer dependency (the host app provides the single instance).
Usage
import { LoginCommand, ERROR_CODE, REST_API } from '@numen-crypto/contract';
// validate a request body
const body = LoginCommand.RequestSchema.parse(input);
// typed response
const res: LoginCommand.Response = { user };
// route + method metadata
LoginCommand.endpointDetails; // { method: 'POST', path: '/auth/login', summary: '...' }
REST_API.AUTH.LOGIN; // '/auth/login'Layout
src/
constants/error-codes.ts # ErrorCode enum, shared by API error responses
models/ # shared zod models (money, pagination, user, session)
commands/ # one namespace per endpoint: RequestSchema / ResponseSchema / endpointDetails
auth/
api/routes.ts # flat REST route registry
index.ts # public barrelConventions
- One namespace per command:
RequestSchema,ResponseSchema,Request,Response,endpointDetails. - Money is always a string (
MoneyStringSchema), never a number. zodis a peer dependency — the host app provides the single instance.
Build
npm install
npm run build # tsup -> dist (esm + cjs + d.ts)