@tahanabavi/typefetch 1.5.6 → 1.6.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 +103 -1
- package/dist/cli/index.js +5242 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.mts +218 -1
- package/dist/index.d.ts +218 -1
- package/dist/index.js +729 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +721 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**TypeFetch** is a strongly typed HTTP client for TypeScript projects, built around **Zod** contracts.
|
|
4
4
|
|
|
5
|
-
Define your API once with Zod schemas, then TypeFetch generates a fully typed client with request validation, response validation, middleware support, retries, mock data, response wrappers, token handling,
|
|
5
|
+
Define your API once with Zod schemas, then TypeFetch generates a fully typed client with request validation, response validation, middleware support, retries, mock data, response wrappers, token handling, structured request support, contract-driven API testing, CLI workflows, and report generation.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
const user = await api.user.getUser({
|
|
@@ -29,6 +29,68 @@ const user = await api.user.getUser({
|
|
|
29
29
|
* Normalized error handling with `RichError`
|
|
30
30
|
* Field-level encryption middleware
|
|
31
31
|
* Backward-compatible flat request schemas
|
|
32
|
+
* Contract-driven API test runner
|
|
33
|
+
* Automatic test input generation from Zod schemas
|
|
34
|
+
* Schema, mock, live, and full API test modes
|
|
35
|
+
* Markdown, HTML, and JSON test reports
|
|
36
|
+
* CLI commands for project setup, endpoint listing, API testing, and release documentation
|
|
37
|
+
* Versioned release documentation under `docs/releases`
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## What's New in v1.6.0
|
|
42
|
+
|
|
43
|
+
TypeFetch now includes a contract-driven testing layer and CLI tooling.
|
|
44
|
+
|
|
45
|
+
### Testing runner
|
|
46
|
+
|
|
47
|
+
The testing runner can discover endpoints from your contracts, generate valid request inputs, run schema/mock/live checks, validate responses, and export reports.
|
|
48
|
+
|
|
49
|
+
Supported modes:
|
|
50
|
+
|
|
51
|
+
* `schema` — validates generated or custom request input without network calls
|
|
52
|
+
* `mock` — validates endpoint `mockData` against the response schema
|
|
53
|
+
* `live` — executes real requests through `ApiClient`
|
|
54
|
+
* `full` — runs schema, mock, and live phases where applicable
|
|
55
|
+
|
|
56
|
+
### CLI
|
|
57
|
+
|
|
58
|
+
The CLI provides a simple workflow for setting up and running contract tests.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
typefetch init
|
|
62
|
+
typefetch test --mode full --format markdown,json,html --output ./typefetch-report/report
|
|
63
|
+
typefetch list
|
|
64
|
+
typefetch release-doc --version v1.6.0 --title "CLI & Testing Feature"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Endpoint test metadata
|
|
68
|
+
|
|
69
|
+
Endpoints can now include optional `test` metadata for custom inputs, tags, expected errors, destructive endpoint safety, and context-based flows.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
getUserById: {
|
|
73
|
+
method: "GET",
|
|
74
|
+
path: "/users/:id",
|
|
75
|
+
request: z.object({
|
|
76
|
+
path: z.object({
|
|
77
|
+
id: z.string(),
|
|
78
|
+
}),
|
|
79
|
+
}),
|
|
80
|
+
response: z.object({
|
|
81
|
+
id: z.string(),
|
|
82
|
+
name: z.string(),
|
|
83
|
+
}),
|
|
84
|
+
test: {
|
|
85
|
+
tags: ["user", "smoke"],
|
|
86
|
+
input: {
|
|
87
|
+
path: {
|
|
88
|
+
id: "user-1",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
```
|
|
32
94
|
|
|
33
95
|
---
|
|
34
96
|
|
|
@@ -1101,6 +1163,15 @@ src/
|
|
|
1101
1163
|
cache.ts
|
|
1102
1164
|
auth.ts
|
|
1103
1165
|
encryption.ts
|
|
1166
|
+
|
|
1167
|
+
typefetch.test.config.ts
|
|
1168
|
+
typefetch.env.example
|
|
1169
|
+
typefetch-report/
|
|
1170
|
+
test-fixtures/
|
|
1171
|
+
|
|
1172
|
+
docs/
|
|
1173
|
+
releases/
|
|
1174
|
+
v1.6.0-cli-testing.md
|
|
1104
1175
|
```
|
|
1105
1176
|
|
|
1106
1177
|
Example:
|
|
@@ -1151,6 +1222,21 @@ const user = await api.user.getUser({
|
|
|
1151
1222
|
expect(user.name).toBe("Taha");
|
|
1152
1223
|
```
|
|
1153
1224
|
|
|
1225
|
+
Contract-driven API testing can also be run through the TypeFetch CLI.
|
|
1226
|
+
|
|
1227
|
+
```bash
|
|
1228
|
+
typefetch init
|
|
1229
|
+
typefetch test --mode schema
|
|
1230
|
+
typefetch test --mode mock
|
|
1231
|
+
typefetch test --mode live --base-url http://localhost:3000
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
Generated reports can be exported as Markdown, HTML, or JSON:
|
|
1235
|
+
|
|
1236
|
+
```bash
|
|
1237
|
+
typefetch test --mode full --format markdown,json,html --output ./typefetch-report/report
|
|
1238
|
+
```
|
|
1239
|
+
|
|
1154
1240
|
Recommended test coverage:
|
|
1155
1241
|
|
|
1156
1242
|
* Request validation
|
|
@@ -1171,6 +1257,20 @@ Recommended test coverage:
|
|
|
1171
1257
|
|
|
1172
1258
|
---
|
|
1173
1259
|
|
|
1260
|
+
## Versioned Release Documentation
|
|
1261
|
+
|
|
1262
|
+
Starting with v1.6.0, detailed documentation for larger updates is stored separately under `docs/releases`.
|
|
1263
|
+
|
|
1264
|
+
The main README stays focused on quick usage and core concepts, while release files contain deeper implementation notes, migration details, CLI examples, test strategy, and full feature explanations.
|
|
1265
|
+
|
|
1266
|
+
Recommended structure:
|
|
1267
|
+
|
|
1268
|
+
```txt
|
|
1269
|
+
docs/
|
|
1270
|
+
releases/
|
|
1271
|
+
v1.6.0.md
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1174
1274
|
## Notes
|
|
1175
1275
|
|
|
1176
1276
|
* Always call `client.init()` before using `client.modules`.
|
|
@@ -1182,6 +1282,8 @@ Recommended test coverage:
|
|
|
1182
1282
|
* `form-data` endpoints should use `bodyType: "form-data"`.
|
|
1183
1283
|
* Auth tokens are only required for endpoints with `auth: true`.
|
|
1184
1284
|
* Mock data bypasses network calls but still validates responses.
|
|
1285
|
+
* Use `typefetch test --mode schema` for fast contract validation.
|
|
1286
|
+
* Keep detailed release documentation in `docs/releases`.
|
|
1185
1287
|
|
|
1186
1288
|
---
|
|
1187
1289
|
|