@alwatr/fetch 7.1.5 → 8.0.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/CHANGELOG.md DELETED
@@ -1,628 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [7.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.1.4...@alwatr/fetch@7.1.5) (2026-03-16)
7
-
8
- ### 🔨 Code Refactoring
9
-
10
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
11
-
12
- ## [7.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.1.3...@alwatr/fetch@7.1.4) (2026-02-18)
13
-
14
- **Note:** Version bump only for package @alwatr/fetch
15
-
16
- ## [7.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.1.2...@alwatr/fetch@7.1.3) (2025-12-23)
17
-
18
- **Note:** Version bump only for package @alwatr/fetch
19
-
20
- ## [7.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.1.1...@alwatr/fetch@7.1.2) (2025-12-13)
21
-
22
- **Note:** Version bump only for package @alwatr/fetch
23
-
24
- ## [7.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.1.0...@alwatr/fetch@7.1.1) (2025-12-10)
25
-
26
- **Note:** Version bump only for package @alwatr/fetch
27
-
28
- ## [7.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.0.3...@alwatr/fetch@7.1.0) (2025-11-18)
29
-
30
- ### ✨ Features
31
-
32
- * add fetchJson function for automatic JSON parsing with error handling ([6cc3e4b](https://github.com/Alwatr/nanolib/commit/6cc3e4b6d854caddb187150126548d9081c91e3c))
33
-
34
- ### 🔨 Code Refactoring
35
-
36
- * improve type definitions for cache strategy and error reasons ([c599f72](https://github.com/Alwatr/nanolib/commit/c599f7254f05dd964ca0378f2017f9e98de2018c))
37
- * separate core funcs ([110db1f](https://github.com/Alwatr/nanolib/commit/110db1f171c5f18eb9a9ab5d62df33447e1c55d6))
38
-
39
- ## [7.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.0.2...@alwatr/fetch@7.0.3) (2025-11-18)
40
-
41
- **Note:** Version bump only for package @alwatr/fetch
42
-
43
- ## [7.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.0.1...@alwatr/fetch@7.0.2) (2025-11-15)
44
-
45
- **Note:** Version bump only for package @alwatr/fetch
46
-
47
- ## [7.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@7.0.0...@alwatr/fetch@7.0.1) (2025-11-15)
48
-
49
- **Note:** Version bump only for package @alwatr/fetch
50
-
51
- ## [7.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.17...@alwatr/fetch@7.0.0) (2025-11-06)
52
-
53
- ### ⚠ BREAKING CHANGES
54
-
55
- * The `fetch` function no longer throws exceptions. Instead, it returns a **tuple** following the Go-style error handling pattern:
56
-
57
- ```typescript
58
- // Old behavior (v1.x)
59
- type FetchResponse = Promise<Response>;
60
-
61
- // New behavior (v2.x)
62
- type FetchResponse = Promise<[Response, null] | [null, Error | FetchError]>;
63
- ```
64
-
65
- ### Why This Change?
66
-
67
- 1. **Explicit Error Handling**: Forces developers to handle errors at the call site
68
- 2. **Type Safety**: TypeScript can track whether you've handled errors
69
- 3. **No Try-Catch Boilerplate**: Cleaner, more readable code
70
- 4. **Better Error Context**: `FetchError` provides detailed error reasons and response data
71
- 5. **Consistent Patterns**: Aligns with modern error handling practices (Go, Rust Result types)
72
-
73
- ### Migration Guide
74
-
75
- #### Before (v1.x)
76
-
77
- ```typescript
78
- import {fetch} from '@alwatr/fetch';
79
-
80
- async function getUser(id: string) {
81
- try {
82
- const response = await fetch(`/api/users/${id}`);
83
-
84
- if (!response.ok) {
85
- throw new Error(`HTTP error! status: ${response.status}`);
86
- }
87
-
88
- return await response.json();
89
- }
90
- catch (error) {
91
- console.error('Failed to fetch user:', error);
92
- throw error;
93
- }
94
- }
95
- ```
96
-
97
- #### After (v2.x)
98
-
99
- ```typescript
100
- import {fetch, FetchError} from '@alwatr/fetch';
101
-
102
- async function getUser(id: string) {
103
- const [response, error] = await fetch(`/api/users/${id}`);
104
-
105
- if (error) {
106
- console.error('Failed to fetch user:', error.message, error.response);
107
- return null; // or throw, or return a default value
108
- }
109
-
110
- // response is guaranteed to be ok here
111
- return await response.json();
112
- }
113
- ```
114
-
115
- * enhance error handling in README with Go-style tuple pattern and FetchError examples ([e1091ec](https://github.com/Alwatr/nanolib/commit/e1091eca2c27cf3aa03e046fed3ccfad6ce704ed))
116
-
117
- ### ✨ Features
118
-
119
- * add custom FetchError class for enhanced error handling in fetch requests ([31891de](https://github.com/Alwatr/nanolib/commit/31891de09437ddb86fd2101124120bf78a9552eb))
120
- * enhance FetchError handling with specific reasons for fetch failures ([cc6569d](https://github.com/Alwatr/nanolib/commit/cc6569de16c27f2adaecefe3bef2c76ead29ffb8))
121
- * enhance FetchResponse type to include FetchError for improved error handling ([dd6a0ff](https://github.com/Alwatr/nanolib/commit/dd6a0ff31ddbcd6ccdfd6f65eccbbe83b9cce237))
122
-
123
- ### 🐛 Bug Fixes
124
-
125
- * add 'cache_not_found' reason to FetchErrorReason type for improved error categorization ([14dddd5](https://github.com/Alwatr/nanolib/commit/14dddd5750140f60ed4305d21226eb348795c0a3))
126
- * add @alwatr/has-own dependency and update tsconfig references ([1bb1c71](https://github.com/Alwatr/nanolib/commit/1bb1c71bb8e7f6c2ffb0d6a563893e37183ec54b))
127
- * add missing type import from @alwatr/type-helper ([2326335](https://github.com/Alwatr/nanolib/commit/23263352c2698738c5a43a5deebdf1744268e8ce))
128
- * export error handling types from error.js ([bb88521](https://github.com/Alwatr/nanolib/commit/bb8852197cf0878f3ca62b14d3bd046a031e52a1))
129
- * improve error handling in fetch function to parse response body as JSON or fallback to text ([8e02ba8](https://github.com/Alwatr/nanolib/commit/8e02ba8b4733005e52095dc9833e1e36d1f3e94a))
130
- * refine error handling for fetch timeout and abort scenarios ([b5ac722](https://github.com/Alwatr/nanolib/commit/b5ac7229d713897f4d39d0c406dd3839792de680))
131
- * replace Object.hasOwn with hasOwn import and enhance FetchError handling for better error reporting ([c320420](https://github.com/Alwatr/nanolib/commit/c320420689543aab1eebd46fe7dd601bda281002))
132
- * set default options for fetch function ([7bda786](https://github.com/Alwatr/nanolib/commit/7bda786a8754d876e49d42ea1e5e7379ad70170d))
133
- * support nodejs ([fb6d993](https://github.com/Alwatr/nanolib/commit/fb6d993fe6af56a468c73fa31a960aa601279b75))
134
- * timeout abort issue ([bb3845d](https://github.com/Alwatr/nanolib/commit/bb3845d2b4cec705a8021f5c65de658fefc51e21))
135
- * update error handling in README to reference FetchError consistently ([1f6e240](https://github.com/Alwatr/nanolib/commit/1f6e240c946a07b7ce9c4489a509597fec8705f9))
136
- * update fetch function to return a tuple and add options processing ([d05bfb5](https://github.com/Alwatr/nanolib/commit/d05bfb59260be5eae5aeab7bd816aa2f613dd643))
137
- * update fetch function to return FetchResponse and handle FetchError for improved error reporting ([ddf47e0](https://github.com/Alwatr/nanolib/commit/ddf47e07510bb0cd38fa75c8921a3d64ed370afc))
138
- * update FetchError data type to ensure consistent error handling ([954b79a](https://github.com/Alwatr/nanolib/commit/954b79a7ba3954565c7d09db6b188b79f1fd8fa2))
139
- * update FetchResponse type to ensure consistent error handling ([8da0b3a](https://github.com/Alwatr/nanolib/commit/8da0b3a8ac2801494ffa214a99792215a403b16e))
140
-
141
- ### 🧹 Miscellaneous Chores
142
-
143
- * reorder jest dependency in package.json ([a098ecf](https://github.com/Alwatr/nanolib/commit/a098ecf0489596104908627c759c8dcb092d2424))
144
-
145
- ### 🔗 Dependencies update
146
-
147
- * add @jest/globals dependency and remove types from tsconfig ([47ee79a](https://github.com/Alwatr/nanolib/commit/47ee79a234a026ce28ab5671f84f72aea61d8508))
148
-
149
- ## [6.0.17](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.16...@alwatr/fetch@6.0.17) (2025-11-04)
150
-
151
- **Note:** Version bump only for package @alwatr/fetch
152
-
153
- ## [6.0.16](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.15...@alwatr/fetch@6.0.16) (2025-10-06)
154
-
155
- ### 🔗 Dependencies update
156
-
157
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
158
-
159
- ## [6.0.15](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.14...@alwatr/fetch@6.0.15) (2025-09-27)
160
-
161
- ### 🧹 Miscellaneous Chores
162
-
163
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
164
-
165
- ## [6.0.14](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.13...@alwatr/fetch@6.0.14) (2025-09-22)
166
-
167
- **Note:** Version bump only for package @alwatr/fetch
168
-
169
- ## [6.0.13](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.12...@alwatr/fetch@6.0.13) (2025-09-22)
170
-
171
- **Note:** Version bump only for package @alwatr/fetch
172
-
173
- ## [6.0.12](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.11...@alwatr/fetch@6.0.12) (2025-09-21)
174
-
175
- **Note:** Version bump only for package @alwatr/fetch
176
-
177
- ## [6.0.11](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.10...@alwatr/fetch@6.0.11) (2025-09-20)
178
-
179
- ### 🐛 Bug Fixes
180
-
181
- * add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
182
- * add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
183
- * remove unnecessary pure annotations ([adeb916](https://github.com/Alwatr/nanolib/commit/adeb9166f8e911f59269032b76c36cb1888332cf))
184
-
185
- ### 🧹 Miscellaneous Chores
186
-
187
- * remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
188
-
189
- ## [6.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.9...@alwatr/fetch@6.0.10) (2025-09-19)
190
-
191
- **Note:** Version bump only for package @alwatr/fetch
192
-
193
- ## [6.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.8...@alwatr/fetch@6.0.9) (2025-09-19)
194
-
195
- **Note:** Version bump only for package @alwatr/fetch
196
-
197
- ## [6.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.7...@alwatr/fetch@6.0.8) (2025-09-15)
198
-
199
- **Note:** Version bump only for package @alwatr/fetch
200
-
201
- ## [6.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.6...@alwatr/fetch@6.0.7) (2025-09-14)
202
-
203
- **Note:** Version bump only for package @alwatr/fetch
204
-
205
- ## [6.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.5...@alwatr/fetch@6.0.6) (2025-09-13)
206
-
207
- **Note:** Version bump only for package @alwatr/fetch
208
-
209
- ## [6.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.4...@alwatr/fetch@6.0.5) (2025-09-13)
210
-
211
- ### 🧹 Miscellaneous Chores
212
-
213
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
214
-
215
- ## [6.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.3...@alwatr/fetch@6.0.4) (2025-09-13)
216
-
217
- **Note:** Version bump only for package @alwatr/fetch
218
-
219
- ## [6.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.2...@alwatr/fetch@6.0.3) (2025-09-09)
220
-
221
- **Note:** Version bump only for package @alwatr/fetch
222
-
223
- ## [6.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.1...@alwatr/fetch@6.0.2) (2025-09-08)
224
-
225
- **Note:** Version bump only for package @alwatr/fetch
226
-
227
- ## [6.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.0...@alwatr/fetch@6.0.1) (2025-09-06)
228
-
229
- ### 🔨 Code Refactoring
230
-
231
- * update bodyJson type definition to use JsonValue for consistency ([ca18953](https://github.com/Alwatr/nanolib/commit/ca1895314e918a157610a554fefcabcb71de97b6))
232
-
233
- ## [6.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.7...@alwatr/fetch@6.0.0) (2025-09-06)
234
-
235
- ### ⚠ BREAKING CHANGES
236
-
237
- * Removed fetchJson; refactored fetch to accept url as a separate parameter, matching the web standard API.
238
-
239
- ### 🐛 Bug Fixes
240
-
241
- * include request body in cache key for duplicate request handling ([a891ceb](https://github.com/Alwatr/nanolib/commit/a891ceb7300b26101f5cd982409477815dad500e))
242
- * update query parameter encoding in fetch function for proper URL formatting ([ae30c1e](https://github.com/Alwatr/nanolib/commit/ae30c1ef13eae5070c0c2865180dfa7b89aa1eba))
243
-
244
- ### 🔨 Code Refactoring
245
-
246
- * enhance FetchOptions type and improve fetch function handling ([a35e8e4](https://github.com/Alwatr/nanolib/commit/a35e8e495336448531b9b4ca755520517b3e3e2c))
247
- * enhance logging in fetch and cache strategy functions for better traceability ([db0c51b](https://github.com/Alwatr/nanolib/commit/db0c51b4e5bafbba64c511dda4686226a3fcb842))
248
- * improve documentation for fetch options and caching strategies ([d114290](https://github.com/Alwatr/nanolib/commit/d114290755d13ac5ca06a19ffe827e39b70ff92a))
249
- * rename FetchOptions_ to AlwatrFetchOptions_ for consistency ([978947a](https://github.com/Alwatr/nanolib/commit/978947a52196f711ffc452a84edd9f34c95341b3))
250
- * rewrite fetch module ([d245cce](https://github.com/Alwatr/nanolib/commit/d245cce8c99b345989dd18c373f682dd89ef3319))
251
- * update fetch calls to use consistent parameters and improve response handling ([49436e6](https://github.com/Alwatr/nanolib/commit/49436e685fe8c81c78649918f3455282106bd754))
252
- * update FetchOptions interface to enforce required properties ([4423740](https://github.com/Alwatr/nanolib/commit/4423740b3424c3d819e6c59ade183fcd303116c8))
253
- * update FetchOptions type to AlwatrFetchOptions_ for consistency ([6c1ff26](https://github.com/Alwatr/nanolib/commit/6c1ff264a0a3937bcd6abd58010b92d53f3d76ea))
254
-
255
- ## [5.6.7](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.6...@alwatr/fetch@5.6.7) (2025-09-05)
256
-
257
- ### 🔗 Dependencies update
258
-
259
- * update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
260
-
261
- ## [5.6.6](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.5...@alwatr/fetch@5.6.6) (2025-09-01)
262
-
263
- ### 🔗 Dependencies update
264
-
265
- * update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
266
-
267
- ## [5.6.5](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.4...@alwatr/fetch@5.6.5) (2025-08-23)
268
-
269
- **Note:** Version bump only for package @alwatr/fetch
270
-
271
- ## [5.6.4](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.2...@alwatr/fetch@5.6.4) (2025-08-23)
272
-
273
- ### 🐛 Bug Fixes
274
-
275
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
276
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
277
-
278
- ### 🔨 Code Refactoring
279
-
280
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
281
-
282
- ### 🧹 Miscellaneous Chores
283
-
284
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
285
-
286
- ### 🔗 Dependencies update
287
-
288
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
289
-
290
- ## [5.6.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.2...@alwatr/fetch@5.6.3) (2025-08-23)
291
-
292
- ### Code Refactoring
293
-
294
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
295
-
296
- ## [5.6.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.6.1...@alwatr/fetch@5.6.2) (2025-04-20)
297
-
298
- **Note:** Version bump only for package @alwatr/fetch
299
-
300
- ## <small>5.6.1 (2025-04-15)</small>
301
-
302
- **Note:** Version bump only for package @alwatr/fetch
303
-
304
- ## [5.6.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.5.2...@alwatr/fetch@5.6.0) (2025-04-15)
305
-
306
- ### Features
307
-
308
- * **fetchJson:** include responseText in error logging for better debugging ([168aa1c](https://github.com/Alwatr/nanolib/commit/168aa1cf72fa7668a92be87711656bbd5f1b784c)) by @alimd
309
-
310
- ### Bug Fixes
311
-
312
- * **fetchJson:** update return type of fetchJson to be more generic ([9db5234](https://github.com/Alwatr/nanolib/commit/9db5234c16fc4574386c555bd068b4ab0382a364)) by @alimd
313
-
314
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.5.1...@alwatr/fetch@5.5.2) (2025-04-01)
315
-
316
- **Note:** Version bump only for package @alwatr/fetch
317
-
318
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.5.0...@alwatr/fetch@5.5.1) (2025-03-18)
319
-
320
- **Note:** Version bump only for package @alwatr/fetch
321
-
322
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@5.4.0...@alwatr/fetch@5.5.0) (2025-03-06)
323
-
324
- ### Miscellaneous Chores
325
-
326
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
327
-
328
- ### Dependencies update
329
-
330
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
331
-
332
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.2.1...@alwatr/fetch@5.4.0) (2025-02-18)
333
-
334
- ## 5.3.0 (2025-02-03)
335
-
336
- ### Miscellaneous Chores
337
-
338
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
339
-
340
- ### Dependencies update
341
-
342
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
343
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
344
-
345
- ## 5.2.1 (2024-11-07)
346
-
347
- ### Bug Fixes
348
-
349
- * **fetch:** refine error handling in fetchJson to improve response error structure ([2942563](https://github.com/Alwatr/nanolib/commit/29425639c268f091711ab195a4285e49b762e497)) by @
350
-
351
- ## 5.2.0 (2024-11-06)
352
-
353
- ### Features
354
-
355
- * **fetch:** improve error handling for fetch responses and JSON parsing ([8692bb1](https://github.com/Alwatr/nanolib/commit/8692bb1123e8b3a6d6f8aea20464c55b344da9d2)) by @
356
-
357
- ## 5.0.0 (2024-11-02)
358
-
359
- ### ⚠ BREAKING CHANGES
360
-
361
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
362
-
363
- ### Code Refactoring
364
-
365
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
366
-
367
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
368
-
369
- ### Miscellaneous Chores
370
-
371
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
372
-
373
- ### Dependencies update
374
-
375
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
376
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
377
-
378
- ## [5.2.1](https://github.com/Alwatr/nanolib/compare/v5.2.0...v5.2.1) (2024-11-07)
379
-
380
- ### Bug Fixes
381
-
382
- * **fetch:** refine error handling in fetchJson to improve response error structure ([2942563](https://github.com/Alwatr/nanolib/commit/29425639c268f091711ab195a4285e49b762e497)) by @
383
-
384
- ## [5.2.0](https://github.com/Alwatr/nanolib/compare/v5.1.0...v5.2.0) (2024-11-06)
385
-
386
- ### Features
387
-
388
- * **fetch:** improve error handling for fetch responses and JSON parsing ([8692bb1](https://github.com/Alwatr/nanolib/commit/8692bb1123e8b3a6d6f8aea20464c55b344da9d2)) by @alimd
389
-
390
- ## 5.0.0 (2024-11-02)
391
-
392
- ### ⚠ BREAKING CHANGES
393
-
394
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
395
- * **fetch:** queryParametters renamed to queryParams
396
- * **fetch:** remove serviceRequest
397
-
398
- Co-authored-by: Ali Mihandoost <ali@mihandoost.com>
399
-
400
- ### Features
401
-
402
- * **fetch:** alwatrAuth ([28e365c](https://github.com/Alwatr/nanolib/commit/28e365c839b0ea80060c0f44ed4dc4473468d5c4)) by @
403
- * **fetch:** fetch json ([b089f12](https://github.com/Alwatr/nanolib/commit/b089f12cef6f1f3b60bc7559dc5e9b8b63c57273)) by @
404
- * **fetch:** move from last repo ([4b86bb5](https://github.com/Alwatr/nanolib/commit/4b86bb542af296c91bc1db36b4e08fdbad501db2)) by @
405
- * **fetch:** Update fetch type definitions with document ([38398cc](https://github.com/Alwatr/nanolib/commit/38398cc33f311a569a53cc3e06c3191e17dbd45b)) by @
406
- * **fetch:** use @alwatr/http-primer for types and http codes ([6fe993a](https://github.com/Alwatr/nanolib/commit/6fe993ac0f395a4c0c6ad3b2caa48a2986cc850f)) by @
407
- * use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @
408
-
409
- ### Bug Fixes
410
-
411
- * all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @
412
- * exported types by add .js extensions to all imports ([fc3d83e](https://github.com/Alwatr/nanolib/commit/fc3d83e8f375da97ba276314b2e6966aa82c9b3f)) by @
413
- * **fetch:** better error handling on handleRetryPattern_ when user is offline ([b867f30](https://github.com/Alwatr/nanolib/commit/b867f30b3eba529ec1aae0026f0ded252ce54332)) by @
414
- * **fetch:** remove unused import from fetch core module ([28ec726](https://github.com/Alwatr/nanolib/commit/28ec7269322f90dba02fbb33e4e622db42169368)) by @
415
-
416
- ### Code Refactoring
417
-
418
- * **fetch:** handle fetchJson error responses properly ([ae8fe24](https://github.com/Alwatr/nanolib/commit/ae8fe244aca17f235c4347ff1fd10070a410340c)) by @
419
- * **fetch:** review and update everything ([61ec38b](https://github.com/Alwatr/nanolib/commit/61ec38b2fde28ba26a7973fcd60a30c861faf4dd)) by @
420
- * **fetch:** separate core files ([c7e6b09](https://github.com/Alwatr/nanolib/commit/c7e6b096d747f868a2a1bfde1ffd3fd2a64dc7f3)) by @
421
- * **fetch:** update fetch package to use @alwatr/parse-duration for timeout and retryDelay durations ([1108c54](https://github.com/Alwatr/nanolib/commit/1108c547e43f2c65f46d65b58dd19cee9abd2fd7)) by @
422
- * **fetch:** update HTTP headers content-type to use MimeTypes constant ([c3862fc](https://github.com/Alwatr/nanolib/commit/c3862fc6a643da97dacbd15bcf5d3351caaaf269)) by @
423
- * **fetch:** Update logger import and initialization ([1f0451c](https://github.com/Alwatr/nanolib/commit/1f0451c9fec81b875736135778cdd4150556ba97)) by @
424
- * **fetch:** update query parameters handling ([939b3d5](https://github.com/Alwatr/nanolib/commit/939b3d52998ec7b3f5c32ff5438b649148109ede)) by @
425
- * **fetch:** use new DictionaryReq type ([a8149cf](https://github.com/Alwatr/nanolib/commit/a8149cff114da7c7ce9a335c837ae794904fa3ca)) by @
426
- * prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
427
- * update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @
428
- * use new `global-this` package ([42510b9](https://github.com/Alwatr/nanolib/commit/42510b9ae0e385206a902db093d188949f1cb84e)) by @
429
- * use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
430
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
431
- * **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @
432
-
433
- ### Miscellaneous Chores
434
-
435
- * **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @
436
- * **fetch:** change the license to AGPL-3.0 ([edf9069](https://github.com/Alwatr/nanolib/commit/edf9069608bd276b85c9ac937e33ad225c5921a9)) by @
437
- * include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
438
- * Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
439
- * Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
440
-
441
- ### Dependencies update
442
-
443
- * bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @
444
- * bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
445
- * bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
446
- * upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
447
- * update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @
448
- * update all ([53342f6](https://github.com/Alwatr/nanolib/commit/53342f67a8a013127f073540bc11929f1813c05c)) by @
449
- * update all ([a828818](https://github.com/Alwatr/nanolib/commit/a828818c1b37ad5f6dd3698a53fb14624f633f35)) by @
450
- * update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
451
- * update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
452
- * upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @
453
-
454
- ## [4.2.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.2.0...@alwatr/fetch@4.2.1) (2024-11-02)
455
-
456
- **Note:** Version bump only for package @alwatr/fetch
457
-
458
- ## [4.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.7...@alwatr/fetch@4.2.0) (2024-10-28)
459
-
460
- ### Features
461
-
462
- * **fetch:** use @alwatr/http-primer for types and http codes ([6fe993a](https://github.com/Alwatr/nanolib/commit/6fe993ac0f395a4c0c6ad3b2caa48a2986cc850f)) by @alimd
463
-
464
- ### Code Refactoring
465
-
466
- * **fetch:** update HTTP headers content-type to use MimeTypes constant ([c3862fc](https://github.com/Alwatr/nanolib/commit/c3862fc6a643da97dacbd15bcf5d3351caaaf269)) by @alimd
467
-
468
- ## [4.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.6...@alwatr/fetch@4.1.7) (2024-10-25)
469
-
470
- **Note:** Version bump only for package @alwatr/fetch
471
-
472
- ## [4.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.5...@alwatr/fetch@4.1.6) (2024-10-12)
473
-
474
- **Note:** Version bump only for package @alwatr/fetch
475
-
476
- ## [4.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.4...@alwatr/fetch@4.1.5) (2024-10-11)
477
-
478
- ### Code Refactoring
479
-
480
- - prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
481
- - use new `global-this` package ([42510b9](https://github.com/Alwatr/nanolib/commit/42510b9ae0e385206a902db093d188949f1cb84e)) by @mohammadhonarvar
482
-
483
- ## [4.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.3...@alwatr/fetch@4.1.4) (2024-10-11)
484
-
485
- ### Miscellaneous Chores
486
-
487
- - include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
488
-
489
- ## [4.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.2...@alwatr/fetch@4.1.3) (2024-10-11)
490
-
491
- **Note:** Version bump only for package @alwatr/fetch
492
-
493
- ## [4.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.1...@alwatr/fetch@4.1.2) (2024-10-10)
494
-
495
- ### Dependencies update
496
-
497
- - bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
498
-
499
- ## [4.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.1.0...@alwatr/fetch@4.1.1) (2024-10-08)
500
-
501
- **Note:** Version bump only for package @alwatr/fetch
502
-
503
- ## [4.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.0.1...@alwatr/fetch@4.1.0) (2024-09-29)
504
-
505
- ### Features
506
-
507
- - use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @mohammadhonarvar
508
-
509
- ### Bug Fixes
510
-
511
- - all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @mohammadhonarvar
512
- - **fetch:** remove unused import from fetch core module ([28ec726](https://github.com/Alwatr/nanolib/commit/28ec7269322f90dba02fbb33e4e622db42169368)) by @alimd
513
-
514
- ### Code Refactoring
515
-
516
- - **fetch:** update fetch package to use @alwatr/parse-duration for timeout and retryDelay durations ([1108c54](https://github.com/Alwatr/nanolib/commit/1108c547e43f2c65f46d65b58dd19cee9abd2fd7)) by @alimd
517
- - **fetch:** Update logger import and initialization ([1f0451c](https://github.com/Alwatr/nanolib/commit/1f0451c9fec81b875736135778cdd4150556ba97)) by @alimd
518
- - **fetch:** use new DictionaryReq type ([a8149cf](https://github.com/Alwatr/nanolib/commit/a8149cff114da7c7ce9a335c837ae794904fa3ca)) by @alimd
519
- - update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @alimd
520
- - use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
521
- - **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @alimd
522
-
523
- ### Miscellaneous Chores
524
-
525
- - **fetch:** change the license to AGPL-3.0 ([edf9069](https://github.com/Alwatr/nanolib/commit/edf9069608bd276b85c9ac937e33ad225c5921a9)) by @ArmanAsadian
526
- - Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
527
-
528
- ### Dependencies update
529
-
530
- - bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @dependabot[bot]
531
-
532
- ## [4.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@4.0.0...@alwatr/fetch@4.0.1) (2024-09-21)
533
-
534
- **Note:** Version bump only for package @alwatr/fetch
535
-
536
- ## [4.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.8...@alwatr/fetch@4.0.0) (2024-09-15)
537
-
538
- ### ⚠ BREAKING CHANGES
539
-
540
- - **fetch:** queryParametters renamed to queryParams
541
-
542
- ### Code Refactoring
543
-
544
- - **fetch:** handle fetchJson error responses properly ([ae8fe24](https://github.com/Alwatr/nanolib/commit/ae8fe244aca17f235c4347ff1fd10070a410340c)) by @alimd
545
- - **fetch:** update query parameters handling ([939b3d5](https://github.com/Alwatr/nanolib/commit/939b3d52998ec7b3f5c32ff5438b649148109ede)) by @alimd
546
-
547
- ### Dependencies update
548
-
549
- - bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
550
- - update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @alimd
551
-
552
- ## [3.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.7...@alwatr/fetch@3.1.8) (2024-08-31)
553
-
554
- ### Miscellaneous Chores
555
-
556
- - Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
557
-
558
- ## [3.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.6...@alwatr/fetch@3.1.7) (2024-08-31)
559
-
560
- **Note:** Version bump only for package @alwatr/fetch
561
-
562
- ## [3.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.5...@alwatr/fetch@3.1.6) (2024-08-31)
563
-
564
- ### Dependencies update
565
-
566
- - update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
567
-
568
- ## [3.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.4...@alwatr/fetch@3.1.5) (2024-07-04)
569
-
570
- ### Dependencies update
571
-
572
- - update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
573
-
574
- ## [3.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.3...@alwatr/fetch@3.1.4) (2024-05-12)
575
-
576
- ### Dependencies update
577
-
578
- - upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @alimd
579
-
580
- ## [3.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.2...@alwatr/fetch@3.1.3) (2024-04-25)
581
-
582
- **Note:** Version bump only for package @alwatr/fetch
583
-
584
- ## [3.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.1...@alwatr/fetch@3.1.2) (2024-03-28)
585
-
586
- **Note:** Version bump only for package @alwatr/fetch
587
-
588
- ## [3.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.1.0...@alwatr/fetch@3.1.1) (2024-01-31)
589
-
590
- ### Bug Fixes
591
-
592
- - exported types by add .js extensions to all imports ([fc3d83e](https://github.com/Alwatr/nanolib/commit/fc3d83e8f375da97ba276314b2e6966aa82c9b3f)) by @alimd
593
-
594
- ### Miscellaneous Chores
595
-
596
- - **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @alimd
597
-
598
- ## [3.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@3.0.0...@alwatr/fetch@3.1.0) (2024-01-24)
599
-
600
- ### Features
601
-
602
- - **fetch:** fetch json ([b089f12](https://github.com/Alwatr/nanolib/commit/b089f12cef6f1f3b60bc7559dc5e9b8b63c57273)) by @njfamirm
603
-
604
- ### Bug Fixes
605
-
606
- - **fetch:** better error handling on handleRetryPattern\_ when user is offline ([b867f30](https://github.com/Alwatr/nanolib/commit/b867f30b3eba529ec1aae0026f0ded252ce54332)) by @alimd
607
-
608
- ### Code Refactoring
609
-
610
- - **fetch:** separate core files ([c7e6b09](https://github.com/Alwatr/nanolib/commit/c7e6b096d747f868a2a1bfde1ffd3fd2a64dc7f3)) by @njfamirm
611
-
612
- ## 3.0.0 (2024-01-20)
613
-
614
- ### ⚠ BREAKING CHANGES
615
-
616
- - **fetch:** remove serviceRequest
617
-
618
- Co-authored-by: Ali Mihandoost <ali@mihandoost.com>
619
-
620
- ### Features
621
-
622
- - **fetch:** alwatrAuth ([28e365c](https://github.com/Alwatr/nanolib/commit/28e365c839b0ea80060c0f44ed4dc4473468d5c4)) by @alimd
623
- - **fetch:** move from last repo ([4b86bb5](https://github.com/Alwatr/nanolib/commit/4b86bb542af296c91bc1db36b4e08fdbad501db2)) by @njfamirm
624
- - **fetch:** Update fetch type definitions with document ([38398cc](https://github.com/Alwatr/nanolib/commit/38398cc33f311a569a53cc3e06c3191e17dbd45b)) by @alimd
625
-
626
- ### Code Refactoring
627
-
628
- - **fetch:** review and update everything ([61ec38b](https://github.com/Alwatr/nanolib/commit/61ec38b2fde28ba26a7973fcd60a30c861faf4dd)) by @alimd
package/dist/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/fetch v7.1.5 */
2
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{FetchError:()=>FetchError,cacheSupported:()=>cacheSupported,fetch:()=>fetch,fetchJson:()=>fetchJson});module.exports=__toCommonJS(main_exports);var import_delay=require("@alwatr/delay");var import_global_this=require("@alwatr/global-this");var import_has_own=require("@alwatr/has-own");var import_http_primer=require("@alwatr/http-primer");var import_logger=require("@alwatr/logger");var import_parse_duration=require("@alwatr/parse-duration");var FetchError=class extends Error{constructor(reason,message,response,data){super(message);this.name="FetchError";this.reason=reason;this.response=response;this.data=data}};var logger_=(0,import_logger.createLogger)("@alwatr/fetch");var globalThis_=(0,import_global_this.getGlobalThis)();var cacheSupported=(0,import_has_own.hasOwn)(globalThis_,"caches");var duplicateRequestStorage_={};var defaultFetchOptions={method:"GET",headers:{},timeout:8e3,retry:3,retryDelay:1e3,removeDuplicate:"never",cacheStrategy:"network_only",cacheStorageName:"fetch_cache"};function _processOptions(url,options){logger_.logMethodArgs?.("_processOptions",{url,options});const options_={...defaultFetchOptions,...options,url};options_.window??=null;if(options_.removeDuplicate==="auto"){options_.removeDuplicate=cacheSupported?"until_load":"always"}if(options_.url.lastIndexOf("?")===-1&&options_.queryParams!=null){const queryParams=options_.queryParams;const queryArray=Object.keys(queryParams).map(key=>`${encodeURIComponent(key)}=${encodeURIComponent(String(queryParams[key]))}`);if(queryArray.length>0){options_.url+="?"+queryArray.join("&")}}if(options_.bodyJson!==void 0){options_.body=JSON.stringify(options_.bodyJson);options_.headers["content-type"]=import_http_primer.MimeTypes.JSON}if(options_.bearerToken!==void 0){options_.headers.authorization=`Bearer ${options_.bearerToken}`}else if(options_.alwatrAuth!==void 0){options_.headers.authorization=`Alwatr ${options_.alwatrAuth.userId}:${options_.alwatrAuth.userToken}`}logger_.logProperty?.("fetch.options",options_);return options_}async function handleCacheStrategy_(options){if(options.cacheStrategy==="network_only"){return handleRemoveDuplicate_(options)}logger_.logMethod?.("handleCacheStrategy_");if(!cacheSupported){logger_.incident?.("fetch","fetch_cache_strategy_unsupported",{cacheSupported});options.cacheStrategy="network_only";return handleRemoveDuplicate_(options)}const cacheStorage=await caches.open(options.cacheStorageName);const request=new Request(options.url,options);switch(options.cacheStrategy){case"cache_first":{const cachedResponse=await cacheStorage.match(request);if(cachedResponse!=null){return cachedResponse}const response=await handleRemoveDuplicate_(options);if(response.ok){cacheStorage.put(request,response.clone())}return response}case"cache_only":{const cachedResponse=await cacheStorage.match(request);if(cachedResponse==null){throw new FetchError("cache_not_found","Resource not found in cache")}return cachedResponse}case"network_first":{try{const networkResponse=await handleRemoveDuplicate_(options);if(networkResponse.ok){cacheStorage.put(request,networkResponse.clone())}return networkResponse}catch(err){const cachedResponse=await cacheStorage.match(request);if(cachedResponse!=null){return cachedResponse}throw err}}case"update_cache":{const networkResponse=await handleRemoveDuplicate_(options);if(networkResponse.ok){cacheStorage.put(request,networkResponse.clone())}return networkResponse}case"stale_while_revalidate":{const cachedResponse=await cacheStorage.match(request);const fetchedResponsePromise=handleRemoveDuplicate_(options).then(networkResponse=>{if(networkResponse.ok){cacheStorage.put(request,networkResponse.clone());if(typeof options.revalidateCallback==="function"){setTimeout(options.revalidateCallback,0,networkResponse.clone())}}return networkResponse});return cachedResponse??fetchedResponsePromise}default:{return handleRemoveDuplicate_(options)}}}async function handleRemoveDuplicate_(options){if(options.removeDuplicate==="never"){return handleRetryPattern_(options)}logger_.logMethod?.("handleRemoveDuplicate_");const bodyString=typeof options.body==="string"?options.body:"";const cacheKey=`${options.method} ${options.url} ${bodyString}`;duplicateRequestStorage_[cacheKey]??=handleRetryPattern_(options);try{const response=await duplicateRequestStorage_[cacheKey];if(duplicateRequestStorage_[cacheKey]!=null){if(response.ok!==true||options.removeDuplicate==="until_load"){delete duplicateRequestStorage_[cacheKey]}}return response.clone()}catch(err){delete duplicateRequestStorage_[cacheKey];throw err}}async function handleRetryPattern_(options){if(!(options.retry>1)){return handleTimeout_(options)}logger_.logMethod?.("handleRetryPattern_");options.retry--;const externalAbortSignal=options.signal;try{const response=await handleTimeout_(options);if(!response.ok&&response.status>=import_http_primer.HttpStatusCodes.Error_Server_500_Internal_Server_Error){throw new FetchError("http_error",`HTTP error! status: ${response.status} ${response.statusText}`,response)}return response}catch(err){logger_.accident("fetch","fetch_failed_retry",err);if(globalThis_.navigator?.onLine===false){logger_.accident("handleRetryPattern_","offline","Skip retry because offline");throw err}await import_delay.delay.by(options.retryDelay);options.signal=externalAbortSignal;return handleRetryPattern_(options)}}function handleTimeout_(options){if(options.timeout===0){return globalThis_.fetch(options.url,options)}logger_.logMethod?.("handleTimeout_");return new Promise((resolved,reject)=>{const abortController=typeof AbortController==="function"?new AbortController:null;const externalAbortSignal=options.signal;options.signal=abortController?.signal;if(abortController!==null&&externalAbortSignal!=null){externalAbortSignal.addEventListener("abort",()=>abortController.abort(),{once:true})}const timeoutId=setTimeout(()=>{reject(new FetchError("timeout","fetch_timeout"));abortController?.abort("fetch_timeout")},(0,import_parse_duration.parseDuration)(options.timeout));globalThis_.fetch(options.url,options).then(response=>resolved(response)).catch(reason=>reject(reason)).finally(()=>{clearTimeout(timeoutId)})})}async function fetch(url,options={}){logger_.logMethodArgs?.("fetch",{url,options});const options_=_processOptions(url,options);try{const response=await handleCacheStrategy_(options_);if(!response.ok){throw new FetchError("http_error",`HTTP error! status: ${response.status} ${response.statusText}`,response)}return[response,null]}catch(err){let error;if(err instanceof FetchError){error=err;if(error.response!==void 0&&error.data===void 0){const bodyText=await error.response.text().catch(()=>"");if(bodyText.trim().length>0){try{error.data=JSON.parse(bodyText)}catch{error.data=bodyText}}}}else if(err instanceof Error){if(err.name==="AbortError"){error=new FetchError("aborted",err.message)}else{error=new FetchError("network_error",err.message)}}else{error=new FetchError("unknown_error",String(err??"unknown_error"))}logger_.error("fetch",error.reason,{error});return[null,error]}}async function fetchJson(url,options={}){logger_.logMethodArgs?.("fetchJson",{url,options});const[response,error]=await fetch(url,options);if(error){return[null,error]}const bodyText=await response.text().catch(()=>"");if(bodyText.trim().length===0){const parseError=new FetchError("json_parse_error","Response body is empty, cannot parse JSON",response,bodyText);logger_.error("fetchJson",parseError.reason,{error:parseError});return[null,parseError]}try{const data=JSON.parse(bodyText);if(options.requireJsonResponseWithOkTrue&&data.ok!==true){const parseError=new FetchError("json_response_error",'Response JSON "ok" property is not true',response,data);logger_.error("fetchJson",parseError.reason,{error:parseError});return[null,parseError]}return[data,null]}catch(err){const parseError=new FetchError("json_parse_error",err instanceof Error?err.message:"Failed to parse JSON response",response,bodyText);logger_.error("fetchJson",parseError.reason,{error:parseError});return[null,parseError]}}0&&(module.exports={FetchError,cacheSupported,fetch,fetchJson});
3
- //# sourceMappingURL=main.cjs.map