@zap-studio/fetch 0.4.6 → 0.4.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @zap-studio/fetch
2
2
 
3
+ ## 0.4.7
4
+
5
+ ### Patch Changes
6
+
7
+ - e26293e: Updated dependencies.
8
+ - @zap-studio/validation@0.3.2
9
+
3
10
  ## 0.4.6
4
11
 
5
12
  ### Patch Changes
@@ -7,7 +14,6 @@
7
14
  - 5ea3d3b: Updated dependencies.
8
15
  - @zap-studio/validation@0.3.1
9
16
 
10
-
11
17
  ## 0.4.5
12
18
 
13
19
  ### Dependencies
package/bin/intent.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ // Auto-generated by @tanstack/intent setup
3
+ // Exposes the intent end-user CLI for consumers of this library.
4
+ await import("@tanstack/intent/intent-library");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-studio/fetch",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -34,12 +34,15 @@
34
34
  "files": [
35
35
  "dist",
36
36
  "CHANGELOG.md",
37
- "LICENSE.md",
38
- "README.md"
37
+ "LICENSE",
38
+ "README.md",
39
+ "skills",
40
+ "bin",
41
+ "!skills/_artifacts"
39
42
  ],
40
43
  "dependencies": {
41
44
  "@standard-schema/spec": "^1.1.0",
42
- "@zap-studio/validation": "0.3.1"
45
+ "@zap-studio/validation": "0.3.2"
43
46
  },
44
47
  "devDependencies": {
45
48
  "@types/node": "^25.0.2",
@@ -50,9 +53,9 @@
50
53
  "valibot": "^1.2.0",
51
54
  "vitest": "^4.0.18",
52
55
  "zod": "^4.2.0",
53
- "@zap-studio/vitest-config": "0.0.0",
56
+ "@zap-studio/tsdown-config": "0.0.0",
54
57
  "@zap-studio/typescript-config": "0.0.0",
55
- "@zap-studio/tsdown-config": "0.0.0"
58
+ "@zap-studio/vitest-config": "0.0.0"
56
59
  },
57
60
  "exports": {
58
61
  ".": "./dist/index.mjs",
@@ -65,6 +68,9 @@
65
68
  "main": "./dist/index.mjs",
66
69
  "module": "./dist/index.mjs",
67
70
  "types": "./dist/index.d.mts",
71
+ "bin": {
72
+ "intent": "./bin/intent.js"
73
+ },
68
74
  "scripts": {
69
75
  "build": "tsdown --config tsdown.config.ts",
70
76
  "typecheck": "tsc --noEmit",
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: zap-fetch-typed-http
3
+ description: >
4
+ Implement type-safe HTTP requests with @zap-studio/fetch using $fetch,
5
+ api.get/post/put/patch/delete, createFetch defaults, searchParams merging,
6
+ and throwOnFetchError/throwOnValidationError return modes.
7
+ type: core
8
+ library: '@zap-studio/fetch'
9
+ library_version: '0.4.6'
10
+ sources:
11
+ - 'zap-studio/monorepo:packages/fetch/README.md'
12
+ - 'zap-studio/monorepo:packages/fetch/src/index.ts'
13
+ - 'zap-studio/monorepo:packages/fetch/src/utils.ts'
14
+ ---
15
+
16
+ # @zap-studio/fetch — Typed HTTP Client
17
+
18
+ ## Setup
19
+
20
+ ```ts
21
+ import { createFetch } from '@zap-studio/fetch';
22
+ import { z } from 'zod';
23
+
24
+ const UserSchema = z.object({
25
+ id: z.number(),
26
+ name: z.string(),
27
+ email: z.string().email(),
28
+ });
29
+
30
+ const { api } = createFetch({
31
+ baseURL: 'https://api.example.com',
32
+ headers: { Authorization: 'Bearer token' },
33
+ searchParams: { locale: 'en' },
34
+ });
35
+
36
+ const user = await api.get('/users/1', UserSchema);
37
+ ```
38
+
39
+ ## Core Patterns
40
+
41
+ ### Return raw `Response` when no schema is provided
42
+
43
+ ```ts
44
+ import { $fetch } from '@zap-studio/fetch';
45
+
46
+ const response = await $fetch('https://api.example.com/health');
47
+ const data = await response.json();
48
+ ```
49
+
50
+ ### Request validated payload via schema
51
+
52
+ ```ts
53
+ import { api } from '@zap-studio/fetch';
54
+ import { z } from 'zod';
55
+
56
+ const PostSchema = z.object({ id: z.number(), title: z.string() });
57
+ const post = await api.get('https://api.example.com/posts/1', PostSchema);
58
+ ```
59
+
60
+ ### Handle non-throw validation mode explicitly
61
+
62
+ ```ts
63
+ import { $fetch } from '@zap-studio/fetch';
64
+ import { z } from 'zod';
65
+
66
+ const UserSchema = z.object({ id: z.number() });
67
+
68
+ const result = await $fetch('/users/1', UserSchema, {
69
+ throwOnValidationError: false,
70
+ });
71
+
72
+ if (result.issues) {
73
+ throw new Error('Invalid response payload');
74
+ }
75
+
76
+ console.log(result.value.id);
77
+ ```
78
+
79
+ ## Common Mistakes
80
+
81
+ ### HIGH Assuming `api.get` returns raw `Response`
82
+
83
+ Wrong:
84
+
85
+ ```ts
86
+ const res = await api.get('/users/1', { headers: { Authorization: token } });
87
+ const body = await res.json();
88
+ ```
89
+
90
+ Correct:
91
+
92
+ ```ts
93
+ const user = await api.get('/users/1', UserSchema, {
94
+ headers: { Authorization: token },
95
+ });
96
+ console.log(user.id);
97
+ ```
98
+
99
+ `api.*` overloads are schema-based helpers; they return validated payloads, not a `Response`.
100
+
101
+ Source: zap-studio/monorepo:packages/fetch/src/index.ts
102
+
103
+ ### HIGH Ignoring validation result branch
104
+
105
+ Wrong:
106
+
107
+ ```ts
108
+ const user = await $fetch('/users/1', UserSchema, {
109
+ throwOnValidationError: false,
110
+ });
111
+ console.log(user.id);
112
+ ```
113
+
114
+ Correct:
115
+
116
+ ```ts
117
+ const result = await $fetch('/users/1', UserSchema, {
118
+ throwOnValidationError: false,
119
+ });
120
+
121
+ if (result.issues) throw new Error('Invalid payload');
122
+ console.log(result.value.id);
123
+ ```
124
+
125
+ With `throwOnValidationError: false`, return type is `{ value?, issues? }` and must be narrowed.
126
+
127
+ Source: zap-studio/monorepo:packages/fetch/src/index.ts
128
+
129
+ ### MEDIUM Relying on implicit body semantics for non-JSON inputs
130
+
131
+ Wrong:
132
+
133
+ ```ts
134
+ await api.post('/users', UserSchema, {
135
+ body: new URLSearchParams({ name: 'Ada' }),
136
+ });
137
+ ```
138
+
139
+ Correct:
140
+
141
+ ```ts
142
+ await api.post('/users', UserSchema, {
143
+ body: { name: 'Ada' },
144
+ headers: { 'Content-Type': 'application/json' },
145
+ });
146
+ ```
147
+
148
+ Only plain object bodies are auto-JSON-stringified; other `BodyInit` forms keep their native encoding behavior.
149
+
150
+ Source: zap-studio/monorepo:packages/fetch/src/utils.ts
151
+
152
+ See also: zap-validation-standard-schema/SKILL.md — response validation result handling.
File without changes