@numen-crypto/contract 0.1.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/README.md +54 -0
- package/dist/index.cjs +740 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2448 -0
- package/dist/index.d.ts +2448 -0
- package/dist/index.js +683 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @numen-crypto/contract
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Published to npm under the `numen-crypto` org:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @numen-crypto/contract zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`zod` is a peer dependency (the host app provides the single instance).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { LoginCommand, ERROR_CODE, REST_API } from '@numen-crypto/contract';
|
|
19
|
+
|
|
20
|
+
// validate a request body
|
|
21
|
+
const body = LoginCommand.RequestSchema.parse(input);
|
|
22
|
+
|
|
23
|
+
// typed response
|
|
24
|
+
const res: LoginCommand.Response = { user };
|
|
25
|
+
|
|
26
|
+
// route + method metadata
|
|
27
|
+
LoginCommand.endpointDetails; // { method: 'POST', path: '/auth/login', summary: '...' }
|
|
28
|
+
REST_API.AUTH.LOGIN; // '/auth/login'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Layout
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
constants/error-codes.ts # ErrorCode enum, shared by API error responses
|
|
36
|
+
models/ # shared zod models (money, pagination, user, session)
|
|
37
|
+
commands/ # one namespace per endpoint: RequestSchema / ResponseSchema / endpointDetails
|
|
38
|
+
auth/
|
|
39
|
+
api/routes.ts # flat REST route registry
|
|
40
|
+
index.ts # public barrel
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Conventions
|
|
44
|
+
|
|
45
|
+
- One namespace per command: `RequestSchema`, `ResponseSchema`, `Request`, `Response`, `endpointDetails`.
|
|
46
|
+
- Money is always a string (`MoneyStringSchema`), never a number.
|
|
47
|
+
- `zod` is a peer dependency — the host app provides the single instance.
|
|
48
|
+
|
|
49
|
+
## Build
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install
|
|
53
|
+
npm run build # tsup -> dist (esm + cjs + d.ts)
|
|
54
|
+
```
|