@42-lyon/42api-zod-schemas 1.0.0 → 1.0.2

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 (2) hide show
  1. package/README.md +33 -66
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -12,93 +12,60 @@ This package centralises Zod schemas for common 42 API resources so downstream p
12
12
 
13
13
 
14
14
  ```bash
15
- # Navigate to your project
16
- cd <my-awsome-project>
17
-
18
- # clone this repository:
19
- git clone git@github.com:42-Lyon/42API-zod-schemas.git
20
- # or add it as a submodule
21
- git submodule add git@github.com:42-Lyon/42API-zod-schemas.git
22
-
23
- # Install the module as a local package
24
- npm install ./42API-zod-schemas
15
+ npm install @42-lyon/42api-zod-schemas
16
+ # or
17
+ pnpm add @42-lyon/42api-zod-schemas
18
+ # or
19
+ yarn add @42-lyon/42api-zod-schemas
25
20
  ```
26
21
 
27
- This package is distributed as an ESM package and ships TypeScript types in `dist`.
28
-
29
- ## Quick usage
22
+ The package is ESM-only and ships bundled `.d.ts` definitions.
30
23
 
31
- Import a schema and parse/validate API responses. The package exports individual resource schemas from `src/resources`.
32
-
33
- Example (ESM / TypeScript):
24
+ ## Quick start
34
25
 
35
26
  ```ts
36
- import { intraUserSchema } from '42api-zod-schemas';
27
+ import { intraUserSchema, type IntraUser } from '@42-lyon/42api-zod-schemas';
37
28
 
38
- // Validate a response body
39
29
  const response = await fetch('https://api.intra.42.fr/v2/users/cameo');
40
- const data = await response.json();
30
+ const payload = await response.json();
41
31
 
42
- // Throws if validation fails
43
- const user = intraUserSchema.parse(data);
32
+ // Throws on invalid payload
33
+ const user: IntraUser = intraUserSchema.parse(payload);
44
34
 
45
- // Or use safe parsing
46
- const result = intraUserSchema.safeParse(data);
35
+ // Or keep control over the error path
36
+ const result = intraUserSchema.safeParse(payload);
47
37
  if (!result.success) {
48
- console.error('Invalid user response', result.error);
49
- } else {
50
- // Typed as the inferred type below
51
- const typedUser = result.data;
52
- }
53
-
54
- ```
55
-
56
- For each schema, a related type is also available
57
- ```ts
58
- import { intraUserSchema, type IntraUser } from '42api-zod-schemas';
59
-
60
- const user: IntraUser = {
61
- ...
38
+ console.error(result.error.format());
62
39
  }
63
-
64
40
  ```
65
41
 
66
- ## Exported schemas
67
-
68
- The package re-exports schemas from `src/resources`. As of this release it includes (but may not be limited to):
69
-
70
- - `achievement`
71
- - `bloc`
72
- - `campus`
73
- - `close`
74
- - `events`
75
- - `pool`
76
- - `project`
77
- - `quest`
78
- - `user`
79
-
80
- ## Build
42
+ ### Tree-shakeable imports
81
43
 
82
- This package is authored in TypeScript. Build with:
44
+ Schemas are exported individually so you can import only what you need:
83
45
 
84
- ```bash
85
- npm run build
46
+ ```ts
47
+ import { projectSchema } from '@42-lyon/42api-zod-schemas/project';
86
48
  ```
87
49
 
88
- That runs `tsc` and emits `dist` (see `package.json` `main`/`types` fields).
89
-
90
- ## Contributing
91
-
92
- Contributions welcome. Suggested workflow:
50
+ ## Available schemas
93
51
 
94
- 1. Fork the repo and create a feature branch.
95
- 2. Add or update schemas under `src/resources`.
96
- 3. Run `npm run build` to ensure types build correctly.
97
- 4. Open a PR describing your changes.
52
+ - achievements (`achievements` and `achievements_users`)
53
+ - bloc
54
+ - campus
55
+ - close
56
+ - events
57
+ - experiences
58
+ - pool
59
+ - project
60
+ - quest
61
+ - team
62
+ - transactions
63
+ - user
98
64
 
99
- When adding schemas, follow the existing pattern: export a Zod schema and an inferred TypeScript type.
65
+ Each schema is exported alongside its inferred type (e.g. `intraUserSchema` and `IntraUser`).
100
66
 
101
67
  ## Links
102
68
 
69
+ - npm: https://www.npmjs.com/package/@42-lyon/42api-zod-schemas
103
70
  - Repository: https://github.com/42-Lyon/42API-zod-schemas
104
71
  - Issues: https://github.com/42-Lyon/42API-zod-schemas/issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42-lyon/42api-zod-schemas",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Zod schemas and TypeScript types for validating and typing 42API response bodies",
5
5
  "homepage": "https://github.com/42-Lyon/42API-zod-schemas#readme",
6
6
  "bugs": {
@@ -39,4 +39,4 @@
39
39
  "dist",
40
40
  "README.md"
41
41
  ]
42
- }
42
+ }