@alwatr/fetch 6.0.2 → 6.0.3
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 +4 -0
- package/README.md +17 -18
- package/dist/main.cjs +2 -2
- package/dist/main.mjs +2 -2
- package/package.json +12 -12
- package/src/main.test.js +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.2...@alwatr/fetch@6.0.3) (2025-09-09)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @alwatr/fetch
|
|
9
|
+
|
|
6
10
|
## [6.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/fetch@6.0.1...@alwatr/fetch@6.0.2) (2025-09-08)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @alwatr/fetch
|
package/README.md
CHANGED
|
@@ -52,8 +52,7 @@ async function fetchProducts() {
|
|
|
52
52
|
|
|
53
53
|
const data = await response.json();
|
|
54
54
|
console.log('Products:', data);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
55
|
+
} catch (error) {
|
|
57
56
|
console.error('Failed to fetch products:', error);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
@@ -65,25 +64,25 @@ fetchProducts();
|
|
|
65
64
|
|
|
66
65
|
The `fetch` function takes a `url` string and an `options` object. The options object extends the standard `RequestInit` and adds several custom options for enhanced control.
|
|
67
66
|
|
|
68
|
-
| Option
|
|
69
|
-
|
|
|
70
|
-
| `method`
|
|
71
|
-
| `headers`
|
|
72
|
-
| `timeout`
|
|
73
|
-
| `retry`
|
|
74
|
-
| `retryDelay`
|
|
75
|
-
| `removeDuplicate`
|
|
76
|
-
| `cacheStrategy`
|
|
77
|
-
| `cacheStorageName
|
|
78
|
-
| `revalidateCallback
|
|
79
|
-
| `bodyJson`
|
|
80
|
-
| `queryParams`
|
|
81
|
-
| `bearerToken`
|
|
82
|
-
| `alwatrAuth`
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
| :------------------- | :---------------------------------------------- | :--------------- | :--------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `method` | `HttpMethod` | `'GET'` | The HTTP request method. |
|
|
70
|
+
| `headers` | `HttpRequestHeaders` | `{}` | An object representing the request's headers. |
|
|
71
|
+
| `timeout` | `Duration` | `8_000` (8s) | Request timeout in milliseconds or as a duration string (e.g., `'5s'`). Set to `0` to disable. |
|
|
72
|
+
| `retry` | `number` | `3` | Number of retries if the request fails with a server error (5xx) or times out. |
|
|
73
|
+
| `retryDelay` | `Duration` | `1_000` (1s) | Delay between retry attempts in milliseconds or as a duration string. |
|
|
74
|
+
| `removeDuplicate` | `'never' \| 'always' \| 'until_load' \| 'auto'` | `'never'` | Strategy for handling identical parallel requests. `body` is included for uniqueness. |
|
|
75
|
+
| `cacheStrategy` | `'network_only' \| 'network_first' \| ...` | `'network_only'` | Caching strategy using the browser's Cache API. |
|
|
76
|
+
| `cacheStorageName` | `string` | `'fetch_cache'` | Custom name for the `CacheStorage` instance. |
|
|
77
|
+
| `revalidateCallback` | `(response: Response) => void` | `undefined` | Callback executed with the new response when using `stale_while_revalidate` strategy. |
|
|
78
|
+
| `bodyJson` | `Json` | `undefined` | A JavaScript object sent as the request body. Sets `Content-Type` to `application/json`. |
|
|
79
|
+
| `queryParams` | `Dictionary` | `undefined` | An object of query parameters appended to the URL. |
|
|
80
|
+
| `bearerToken` | `string` | `undefined` | A bearer token added to the `Authorization` header. |
|
|
81
|
+
| `alwatrAuth` | `{userId: string; userToken: string}` | `undefined` | Alwatr-specific authentication credentials. |
|
|
83
82
|
|
|
84
83
|
... and all other standard `RequestInit` properties like `signal`, `credentials`, etc.
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
---
|
|
87
86
|
|
|
88
87
|
## Features in Detail
|
|
89
88
|
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/fetch v6.0.
|
|
1
|
+
/* @alwatr/fetch v6.0.3 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -31,7 +31,7 @@ var import_http_primer = require("@alwatr/http-primer");
|
|
|
31
31
|
var import_logger = require("@alwatr/logger");
|
|
32
32
|
var import_package_tracer = require("@alwatr/package-tracer");
|
|
33
33
|
var import_parse_duration = require("@alwatr/parse-duration");
|
|
34
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/fetch", "6.0.
|
|
34
|
+
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/fetch", "6.0.3");
|
|
35
35
|
var logger_ = /* @__PURE__ */ (0, import_logger.createLogger)("@alwatr/fetch");
|
|
36
36
|
var globalThis_ = /* @__PURE__ */ (0, import_global_this.getGlobalThis)();
|
|
37
37
|
var cacheSupported = /* @__PURE__ */ Object.hasOwn(globalThis_, "caches");
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/fetch v6.0.
|
|
1
|
+
/* @alwatr/fetch v6.0.3 */
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { delay } from "@alwatr/delay";
|
|
@@ -7,7 +7,7 @@ import { HttpStatusCodes, MimeTypes } from "@alwatr/http-primer";
|
|
|
7
7
|
import { createLogger } from "@alwatr/logger";
|
|
8
8
|
import { packageTracer } from "@alwatr/package-tracer";
|
|
9
9
|
import { parseDuration } from "@alwatr/parse-duration";
|
|
10
|
-
__dev_mode__: packageTracer.add("@alwatr/fetch", "6.0.
|
|
10
|
+
__dev_mode__: packageTracer.add("@alwatr/fetch", "6.0.3");
|
|
11
11
|
var logger_ = /* @__PURE__ */ createLogger("@alwatr/fetch");
|
|
12
12
|
var globalThis_ = /* @__PURE__ */ getGlobalThis();
|
|
13
13
|
var cacheSupported = /* @__PURE__ */ Object.hasOwn(globalThis_, "caches");
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/fetch",
|
|
3
3
|
"description": "`@alwatr/fetch` is an enhanced, lightweight, and dependency-free wrapper for the native `fetch` API. It provides modern features like caching strategies, request retries, timeouts, and intelligent duplicate request handling, all in a compact package.",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.3",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@alwatr/delay": "6.0.
|
|
9
|
-
"@alwatr/global-this": "5.5.
|
|
10
|
-
"@alwatr/http-primer": "6.0.
|
|
11
|
-
"@alwatr/logger": "5.5.
|
|
12
|
-
"@alwatr/package-tracer": "5.5.
|
|
13
|
-
"@alwatr/parse-duration": "5.5.
|
|
8
|
+
"@alwatr/delay": "6.0.1",
|
|
9
|
+
"@alwatr/global-this": "5.5.10",
|
|
10
|
+
"@alwatr/http-primer": "6.0.2",
|
|
11
|
+
"@alwatr/logger": "5.5.10",
|
|
12
|
+
"@alwatr/package-tracer": "5.5.10",
|
|
13
|
+
"@alwatr/parse-duration": "5.5.11"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@alwatr/nano-build": "6.1.
|
|
17
|
-
"@alwatr/prettier-config": "5.0.
|
|
18
|
-
"@alwatr/tsconfig-base": "6.0.
|
|
19
|
-
"@alwatr/type-helper": "6.0.
|
|
16
|
+
"@alwatr/nano-build": "6.1.1",
|
|
17
|
+
"@alwatr/prettier-config": "5.0.3",
|
|
18
|
+
"@alwatr/tsconfig-base": "6.0.1",
|
|
19
|
+
"@alwatr/type-helper": "6.0.1",
|
|
20
20
|
"jest": "^30.1.3",
|
|
21
21
|
"typescript": "^5.9.2"
|
|
22
22
|
},
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
},
|
|
86
86
|
"type": "module",
|
|
87
87
|
"types": "./dist/main.d.ts",
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "cd02a1a9fa579930cd54291ba51ed86241313a6d"
|
|
89
89
|
}
|
package/src/main.test.js
CHANGED
|
@@ -28,7 +28,6 @@ describe('fetch with bodyJson', () => {
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
|
|
32
31
|
describe('fetch with timeout', () => {
|
|
33
32
|
it('should throw on timeout', async () => {
|
|
34
33
|
await expect(fetch('http://httpbin.org/delay/1', {timeout: 500, retry: 0})).rejects.toThrow('fetch_timeout');
|
|
@@ -41,11 +40,11 @@ describe('fetch with removeDuplicate', () => {
|
|
|
41
40
|
const [res1, res2] = await Promise.all([
|
|
42
41
|
fetch(url, {
|
|
43
42
|
removeDuplicate: 'always',
|
|
44
|
-
headers: {
|
|
43
|
+
headers: {Req: '1'},
|
|
45
44
|
}),
|
|
46
45
|
fetch(url, {
|
|
47
46
|
removeDuplicate: 'always',
|
|
48
|
-
headers: {
|
|
47
|
+
headers: {Req: '2'},
|
|
49
48
|
}),
|
|
50
49
|
]);
|
|
51
50
|
expect(res1.status).toBe(200);
|