@alwatr/fetch 1.1.3 → 2.0.1
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 +173 -155
- package/fetch.d.ts +0 -2
- package/fetch.d.ts.map +1 -1
- package/fetch.js +0 -38
- package/fetch.js.map +1 -1
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,17 +3,35 @@
|
|
|
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
|
+
## [2.0.1](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/fetch@2.0.0...@alwatr/fetch@2.0.1) (2023-09-19)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* package repo urls ([466cbe9](https://github.com/AliMD/alwatr-eslib/commit/466cbe9188f24e1a1bc36d879a95b52538a58f16)) by @AliMD
|
|
11
|
+
|
|
12
|
+
# [2.0.0](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/fetch@1.1.3...@alwatr/fetch@2.0.0) (2023-09-19)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **fetch:** remove @alwatr/signal ([03d947b](https://github.com/AliMD/alwatr-eslib/commit/03d947be3889d63805eabb7f4be618fed6da0d55)) by @AliMD
|
|
17
|
+
|
|
18
|
+
* fix(fetch)!: remove fetchContext ([eba9cf0](https://github.com/AliMD/alwatr-eslib/commit/eba9cf0a443564478b5b985a69d0f54fbd514440)) by @AliMD
|
|
19
|
+
|
|
20
|
+
### BREAKING CHANGES
|
|
21
|
+
|
|
22
|
+
* fetchContext method removed
|
|
23
|
+
|
|
6
24
|
## 1.1.3 (2023-09-19)
|
|
7
25
|
|
|
8
26
|
### Bug Fixes
|
|
9
27
|
|
|
10
|
-
* cleanup extra packages ([dfc0bd2](https://github.com/AliMD/alwatr/commit/dfc0bd2b42d49e1094ae0303d34e653aa289d358)) by @AliMD
|
|
28
|
+
* cleanup extra packages ([dfc0bd2](https://github.com/AliMD/alwatr-eslib/commit/dfc0bd2b42d49e1094ae0303d34e653aa289d358)) by @AliMD
|
|
11
29
|
|
|
12
|
-
## [1.1.2](https://github.com/AliMD/alwatr/compare/@alwatr/fetch@1.1.1...@alwatr/fetch@1.1.2) (2023-09-12)
|
|
30
|
+
## [1.1.2](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/fetch@1.1.1...@alwatr/fetch@1.1.2) (2023-09-12)
|
|
13
31
|
|
|
14
32
|
**Note:** Version bump only for package @alwatr/fetch
|
|
15
33
|
|
|
16
|
-
## [1.1.1](https://github.com/AliMD/alwatr/compare/@alwatr/fetch@1.1.0...@alwatr/fetch@1.1.1) (2023-09-12)
|
|
34
|
+
## [1.1.1](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/fetch@1.1.0...@alwatr/fetch@1.1.1) (2023-09-12)
|
|
17
35
|
|
|
18
36
|
**Note:** Version bump only for package @alwatr/fetch
|
|
19
37
|
|
|
@@ -25,51 +43,51 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
25
43
|
|
|
26
44
|
### Bug Fixes
|
|
27
45
|
|
|
28
|
-
- **fetch:** serviceRequest type ([44c1086](https://github.com/AliMD/alwatr/commit/44c10866e1c630bc3cf85b3e9be38b268b5b0c31))
|
|
29
|
-
- **fetch:** userAuth in StringifyableFetchOptions ([f554b57](https://github.com/AliMD/alwatr/commit/f554b575584cb1464d48fbe8a8c4006125365853))
|
|
46
|
+
- **fetch:** serviceRequest type ([44c1086](https://github.com/AliMD/alwatr-eslib/commit/44c10866e1c630bc3cf85b3e9be38b268b5b0c31))
|
|
47
|
+
- **fetch:** userAuth in StringifyableFetchOptions ([f554b57](https://github.com/AliMD/alwatr-eslib/commit/f554b575584cb1464d48fbe8a8c4006125365853))
|
|
30
48
|
|
|
31
49
|
# 0.31.0 (2023-05-08)
|
|
32
50
|
|
|
33
51
|
### Bug Fixes
|
|
34
52
|
|
|
35
|
-
- **fetch.ts:** compatible with node ([c3acb53](https://github.com/AliMD/alwatr/commit/c3acb53effd4a79e389bc4de1567b0285c03d71d))
|
|
36
|
-
- **fetch:** bodyJson type ([5740467](https://github.com/AliMD/alwatr/commit/57404673e7f031a73d1cf23501e6fa8d89759769))
|
|
37
|
-
- **fetch:** check node_mode before use navigator.online ([a688f48](https://github.com/AliMD/alwatr/commit/a688f48e9ce4b103c25ffd50f1b8c96e89c205d1))
|
|
38
|
-
- **fetch:** serviceRequest generic type ([074ef38](https://github.com/AliMD/alwatr/commit/074ef3876086f93486753559d8e3db0b60c52a0e))
|
|
39
|
-
- **fetch:** suppress fetch_cache_not_found extra error ([c04f609](https://github.com/AliMD/alwatr/commit/c04f60944106dbd8d1bf2fb5ce0e7be644c3abc6))
|
|
40
|
-
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
53
|
+
- **fetch.ts:** compatible with node ([c3acb53](https://github.com/AliMD/alwatr-eslib/commit/c3acb53effd4a79e389bc4de1567b0285c03d71d))
|
|
54
|
+
- **fetch:** bodyJson type ([5740467](https://github.com/AliMD/alwatr-eslib/commit/57404673e7f031a73d1cf23501e6fa8d89759769))
|
|
55
|
+
- **fetch:** check node_mode before use navigator.online ([a688f48](https://github.com/AliMD/alwatr-eslib/commit/a688f48e9ce4b103c25ffd50f1b8c96e89c205d1))
|
|
56
|
+
- **fetch:** serviceRequest generic type ([074ef38](https://github.com/AliMD/alwatr-eslib/commit/074ef3876086f93486753559d8e3db0b60c52a0e))
|
|
57
|
+
- **fetch:** suppress fetch_cache_not_found extra error ([c04f609](https://github.com/AliMD/alwatr-eslib/commit/c04f60944106dbd8d1bf2fb5ce0e7be644c3abc6))
|
|
58
|
+
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr-eslib/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
41
59
|
|
|
42
60
|
### Features
|
|
43
61
|
|
|
44
|
-
- **fetch:** add user auth ([811fbc0](https://github.com/AliMD/alwatr/commit/811fbc018c2b4e3b808704e8623bd5dff2b2f3f7))
|
|
45
|
-
- **fetch:** StringifyableFetchOptions type ([e13fdb2](https://github.com/AliMD/alwatr/commit/e13fdb2550cf3a2102c331aa7980234ca6f86e08))
|
|
62
|
+
- **fetch:** add user auth ([811fbc0](https://github.com/AliMD/alwatr-eslib/commit/811fbc018c2b4e3b808704e8623bd5dff2b2f3f7))
|
|
63
|
+
- **fetch:** StringifyableFetchOptions type ([e13fdb2](https://github.com/AliMD/alwatr-eslib/commit/e13fdb2550cf3a2102c331aa7980234ca6f86e08))
|
|
46
64
|
|
|
47
65
|
# 0.30.0 (2023-03-06)
|
|
48
66
|
|
|
49
67
|
### Bug Fixes
|
|
50
68
|
|
|
51
|
-
- **fetch:** fetchContext duplicate setSignalValue ([8aa9b00](https://github.com/AliMD/alwatr/commit/8aa9b003a2d7b7ffc8243ff7092d9560763d7273))
|
|
52
|
-
- **fetch:** getClientId in nodejs ([c99e41c](https://github.com/AliMD/alwatr/commit/c99e41c9e9a979ca50cc01aeb5371a3487d9da2e))
|
|
69
|
+
- **fetch:** fetchContext duplicate setSignalValue ([8aa9b00](https://github.com/AliMD/alwatr-eslib/commit/8aa9b003a2d7b7ffc8243ff7092d9560763d7273))
|
|
70
|
+
- **fetch:** getClientId in nodejs ([c99e41c](https://github.com/AliMD/alwatr-eslib/commit/c99e41c9e9a979ca50cc01aeb5371a3487d9da2e))
|
|
53
71
|
|
|
54
72
|
### Features
|
|
55
73
|
|
|
56
|
-
- **fetch:** enhance fetchContext with dispatchOptions and only cache_only request in first time ([1f6b575](https://github.com/AliMD/alwatr/commit/1f6b575437104d64ede8a2c23d141160360d2cd5))
|
|
57
|
-
- **fetch:** fetchContext ([d63d17e](https://github.com/AliMD/alwatr/commit/d63d17ecb58221159dc45a473fdd1c992d306d2b))
|
|
58
|
-
- **fetch:** fetchContext skip online request when offline ([7c2b649](https://github.com/AliMD/alwatr/commit/7c2b6491f78acb961cdc0583112e3c709a177b79))
|
|
59
|
-
- **fetch:** fetchContext work on background ([2e12bfd](https://github.com/AliMD/alwatr/commit/2e12bfde0a0636c30e60906c4812ec66b2d36742))
|
|
60
|
-
- **fetch:** handle offline for all requests ([6a8d7b7](https://github.com/AliMD/alwatr/commit/6a8d7b7159732d834be052191935580331e36962))
|
|
74
|
+
- **fetch:** enhance fetchContext with dispatchOptions and only cache_only request in first time ([1f6b575](https://github.com/AliMD/alwatr-eslib/commit/1f6b575437104d64ede8a2c23d141160360d2cd5))
|
|
75
|
+
- **fetch:** fetchContext ([d63d17e](https://github.com/AliMD/alwatr-eslib/commit/d63d17ecb58221159dc45a473fdd1c992d306d2b))
|
|
76
|
+
- **fetch:** fetchContext skip online request when offline ([7c2b649](https://github.com/AliMD/alwatr-eslib/commit/7c2b6491f78acb961cdc0583112e3c709a177b79))
|
|
77
|
+
- **fetch:** fetchContext work on background ([2e12bfd](https://github.com/AliMD/alwatr-eslib/commit/2e12bfde0a0636c30e60906c4812ec66b2d36742))
|
|
78
|
+
- **fetch:** handle offline for all requests ([6a8d7b7](https://github.com/AliMD/alwatr-eslib/commit/6a8d7b7159732d834be052191935580331e36962))
|
|
61
79
|
|
|
62
80
|
# 0.29.0 (2023-02-10)
|
|
63
81
|
|
|
64
82
|
### Bug Fixes
|
|
65
83
|
|
|
66
|
-
- **fetch:** device id to client id ([077e467](https://github.com/AliMD/alwatr/commit/077e4671d804d43c8f61a9d163d8d51d7a69134e))
|
|
67
|
-
- **fetch:** headers type ([cd4b14e](https://github.com/AliMD/alwatr/commit/cd4b14e46b5090b6df8cb4f89d22b53966b9151e))
|
|
84
|
+
- **fetch:** device id to client id ([077e467](https://github.com/AliMD/alwatr-eslib/commit/077e4671d804d43c8f61a9d163d8d51d7a69134e))
|
|
85
|
+
- **fetch:** headers type ([cd4b14e](https://github.com/AliMD/alwatr-eslib/commit/cd4b14e46b5090b6df8cb4f89d22b53966b9151e))
|
|
68
86
|
|
|
69
87
|
### Features
|
|
70
88
|
|
|
71
|
-
- **fetch:** add update_cache to CacheStrategy ([e1406b1](https://github.com/AliMD/alwatr/commit/e1406b12e1276de3295c47506c8102ab3f8bfa79))
|
|
72
|
-
- **fetch:** clientId on service request ([9575a1d](https://github.com/AliMD/alwatr/commit/9575a1d595a0a4757581a29a66837cbe4be46ed3))
|
|
89
|
+
- **fetch:** add update_cache to CacheStrategy ([e1406b1](https://github.com/AliMD/alwatr-eslib/commit/e1406b12e1276de3295c47506c8102ab3f8bfa79))
|
|
90
|
+
- **fetch:** clientId on service request ([9575a1d](https://github.com/AliMD/alwatr-eslib/commit/9575a1d595a0a4757581a29a66837cbe4be46ed3))
|
|
73
91
|
|
|
74
92
|
# 0.28.0 (2023-01-20)
|
|
75
93
|
|
|
@@ -77,308 +95,308 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
77
95
|
|
|
78
96
|
### Bug Fixes
|
|
79
97
|
|
|
80
|
-
- review issue ([e5d192c](https://github.com/AliMD/alwatr/commit/e5d192cbee6917c2de01146cf8bd026895724ab8))
|
|
98
|
+
- review issue ([e5d192c](https://github.com/AliMD/alwatr-eslib/commit/e5d192cbee6917c2de01146cf8bd026895724ab8))
|
|
81
99
|
|
|
82
100
|
### Features
|
|
83
101
|
|
|
84
|
-
- **type:** add types ([2de3842](https://github.com/AliMD/alwatr/commit/2de384297b70b9818ec8d62ce8d31be4822d95a4))
|
|
102
|
+
- **type:** add types ([2de3842](https://github.com/AliMD/alwatr-eslib/commit/2de384297b70b9818ec8d62ce8d31be4822d95a4))
|
|
85
103
|
|
|
86
104
|
# 0.26.0 (2022-12-22)
|
|
87
105
|
|
|
88
106
|
### Bug Fixes
|
|
89
107
|
|
|
90
|
-
- all import without .js ([fa739ab](https://github.com/AliMD/alwatr/commit/fa739ab23f67bae1d10bfcc146920b71377a26fc))
|
|
91
|
-
- **
|
|
92
|
-
- **fetch:** always call revalidateCallback ([444edc5](https://github.com/AliMD/alwatr/commit/444edc52b6dd5de5418ae8630e1f2270f0114372))
|
|
93
|
-
- **fetch:** enhance handle and report errors in serviceRequest ([dbfc7ff](https://github.com/AliMD/alwatr/commit/dbfc7ff2a036216498dc8e2ff58b74b7eb8d9bc0))
|
|
94
|
-
- **fetch:** fetch_cache_not_found is not error ([3d1aa4e](https://github.com/AliMD/alwatr/commit/3d1aa4e572fbf4bc7b0a527a3fdcf4c521af18dd))
|
|
95
|
-
- **fetch:** fetch_failed error message ([3e98bd9](https://github.com/AliMD/alwatr/commit/3e98bd926a495c13d476f2f1cfb9e546a059d4d8))
|
|
96
|
-
- **fetch:** remove extra \_options ([ad24c81](https://github.com/AliMD/alwatr/commit/ad24c8104b944ebda52308e60d41976ac1eeee81))
|
|
97
|
-
- **fetch:** revalidateCallback issue ([7207909](https://github.com/AliMD/alwatr/commit/72079098edb438c28256dad03d7802bc2fab0858))
|
|
98
|
-
- set correct path ([d01ce6f](https://github.com/AliMD/alwatr/commit/d01ce6ffa749a5e3e0e11e35b4ed61d75d61fec9))
|
|
99
|
-
- **storage-engine:** AlwatrDocumentStorage ([ca9a7bf](https://github.com/AliMD/alwatr/commit/ca9a7bf5e17b333538e749ada5d481a06c847101))
|
|
100
|
-
- tsconfig ([e96dcd3](https://github.com/AliMD/alwatr/commit/e96dcd30774a9f06f7d051e0504192cbbe019e35))
|
|
101
|
-
- tsconfig refrences ([cea0562](https://github.com/AliMD/alwatr/commit/cea05621ecfa499476c5b10a412e60f27ba6a06d))
|
|
108
|
+
- all import without .js ([fa739ab](https://github.com/AliMD/alwatr-eslib/commit/fa739ab23f67bae1d10bfcc146920b71377a26fc))
|
|
109
|
+
- **packages/fetch:** tsconfig refrences ([e6b9542](https://github.com/AliMD/alwatr-eslib/commit/e6b9542284e67b67600da4dcebd19daedb031c9c))
|
|
110
|
+
- **fetch:** always call revalidateCallback ([444edc5](https://github.com/AliMD/alwatr-eslib/commit/444edc52b6dd5de5418ae8630e1f2270f0114372))
|
|
111
|
+
- **fetch:** enhance handle and report errors in serviceRequest ([dbfc7ff](https://github.com/AliMD/alwatr-eslib/commit/dbfc7ff2a036216498dc8e2ff58b74b7eb8d9bc0))
|
|
112
|
+
- **fetch:** fetch_cache_not_found is not error ([3d1aa4e](https://github.com/AliMD/alwatr-eslib/commit/3d1aa4e572fbf4bc7b0a527a3fdcf4c521af18dd))
|
|
113
|
+
- **fetch:** fetch_failed error message ([3e98bd9](https://github.com/AliMD/alwatr-eslib/commit/3e98bd926a495c13d476f2f1cfb9e546a059d4d8))
|
|
114
|
+
- **fetch:** remove extra \_options ([ad24c81](https://github.com/AliMD/alwatr-eslib/commit/ad24c8104b944ebda52308e60d41976ac1eeee81))
|
|
115
|
+
- **fetch:** revalidateCallback issue ([7207909](https://github.com/AliMD/alwatr-eslib/commit/72079098edb438c28256dad03d7802bc2fab0858))
|
|
116
|
+
- set correct path ([d01ce6f](https://github.com/AliMD/alwatr-eslib/commit/d01ce6ffa749a5e3e0e11e35b4ed61d75d61fec9))
|
|
117
|
+
- **storage-engine:** AlwatrDocumentStorage ([ca9a7bf](https://github.com/AliMD/alwatr-eslib/commit/ca9a7bf5e17b333538e749ada5d481a06c847101))
|
|
118
|
+
- tsconfig ([e96dcd3](https://github.com/AliMD/alwatr-eslib/commit/e96dcd30774a9f06f7d051e0504192cbbe019e35))
|
|
119
|
+
- tsconfig refrences ([cea0562](https://github.com/AliMD/alwatr-eslib/commit/cea05621ecfa499476c5b10a412e60f27ba6a06d))
|
|
102
120
|
|
|
103
121
|
### Features
|
|
104
122
|
|
|
105
|
-
- **fetch:** add AlwatrDocumentStorage type ([44b84f0](https://github.com/AliMD/alwatr/commit/44b84f0754169a707472655811020f6e542a6e5d))
|
|
106
|
-
- **fetch:** serviceRequest ([b0b5478](https://github.com/AliMD/alwatr/commit/b0b5478d16b2cb590cfc29d644006e4a459dd6d6))
|
|
107
|
-
- **fetch:** serviceRequest ([#513](https://github.com/AliMD/alwatr/issues/513)) ([113ee49](https://github.com/AliMD/alwatr/commit/113ee498c778d9efc00cc4807bfef09e52336a31))
|
|
108
|
-
- improve accident debugging ([d697e6c](https://github.com/AliMD/alwatr/commit/d697e6c4c7d0a4172f4dba9caf6fbd478f79de9c))
|
|
109
|
-
- improve error debugging ([1fba504](https://github.com/AliMD/alwatr/commit/1fba50400a1e8ececc10bbe8ea11cc8dcea2289c))
|
|
123
|
+
- **fetch:** add AlwatrDocumentStorage type ([44b84f0](https://github.com/AliMD/alwatr-eslib/commit/44b84f0754169a707472655811020f6e542a6e5d))
|
|
124
|
+
- **fetch:** serviceRequest ([b0b5478](https://github.com/AliMD/alwatr-eslib/commit/b0b5478d16b2cb590cfc29d644006e4a459dd6d6))
|
|
125
|
+
- **fetch:** serviceRequest ([#513](https://github.com/AliMD/alwatr-eslib/issues/513)) ([113ee49](https://github.com/AliMD/alwatr-eslib/commit/113ee498c778d9efc00cc4807bfef09e52336a31))
|
|
126
|
+
- improve accident debugging ([d697e6c](https://github.com/AliMD/alwatr-eslib/commit/d697e6c4c7d0a4172f4dba9caf6fbd478f79de9c))
|
|
127
|
+
- improve error debugging ([1fba504](https://github.com/AliMD/alwatr-eslib/commit/1fba50400a1e8ececc10bbe8ea11cc8dcea2289c))
|
|
110
128
|
|
|
111
|
-
# [1.0.0](https://github.com/AliMD/alwatr/compare/v0.32.0...v1.0.0) (2023-06-14)
|
|
129
|
+
# [1.0.0](https://github.com/AliMD/alwatr-eslib/compare/v0.32.0...v1.0.0) (2023-06-14)
|
|
112
130
|
|
|
113
131
|
**Note:** Version bump only for package @alwatr/fetch
|
|
114
132
|
|
|
115
|
-
# [0.32.0](https://github.com/AliMD/alwatr/compare/v0.31.0...v0.32.0) (2023-05-27)
|
|
133
|
+
# [0.32.0](https://github.com/AliMD/alwatr-eslib/compare/v0.31.0...v0.32.0) (2023-05-27)
|
|
116
134
|
|
|
117
135
|
### Bug Fixes
|
|
118
136
|
|
|
119
|
-
- **fetch:** serviceRequest type ([44c1086](https://github.com/AliMD/alwatr/commit/44c10866e1c630bc3cf85b3e9be38b268b5b0c31))
|
|
120
|
-
- **fetch:** userAuth in StringifyableFetchOptions ([f554b57](https://github.com/AliMD/alwatr/commit/f554b575584cb1464d48fbe8a8c4006125365853))
|
|
137
|
+
- **fetch:** serviceRequest type ([44c1086](https://github.com/AliMD/alwatr-eslib/commit/44c10866e1c630bc3cf85b3e9be38b268b5b0c31))
|
|
138
|
+
- **fetch:** userAuth in StringifyableFetchOptions ([f554b57](https://github.com/AliMD/alwatr-eslib/commit/f554b575584cb1464d48fbe8a8c4006125365853))
|
|
121
139
|
|
|
122
|
-
# [0.31.0](https://github.com/AliMD/alwatr/compare/v0.30.0...v0.31.0) (2023-05-08)
|
|
140
|
+
# [0.31.0](https://github.com/AliMD/alwatr-eslib/compare/v0.30.0...v0.31.0) (2023-05-08)
|
|
123
141
|
|
|
124
142
|
### Bug Fixes
|
|
125
143
|
|
|
126
|
-
- **fetch.ts:** compatible with node ([c3acb53](https://github.com/AliMD/alwatr/commit/c3acb53effd4a79e389bc4de1567b0285c03d71d))
|
|
127
|
-
- **fetch:** bodyJson type ([5740467](https://github.com/AliMD/alwatr/commit/57404673e7f031a73d1cf23501e6fa8d89759769))
|
|
128
|
-
- **fetch:** check node_mode before use navigator.online ([a688f48](https://github.com/AliMD/alwatr/commit/a688f48e9ce4b103c25ffd50f1b8c96e89c205d1))
|
|
129
|
-
- **fetch:** serviceRequest generic type ([074ef38](https://github.com/AliMD/alwatr/commit/074ef3876086f93486753559d8e3db0b60c52a0e))
|
|
130
|
-
- **fetch:** suppress fetch_cache_not_found extra error ([c04f609](https://github.com/AliMD/alwatr/commit/c04f60944106dbd8d1bf2fb5ce0e7be644c3abc6))
|
|
131
|
-
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
144
|
+
- **fetch.ts:** compatible with node ([c3acb53](https://github.com/AliMD/alwatr-eslib/commit/c3acb53effd4a79e389bc4de1567b0285c03d71d))
|
|
145
|
+
- **fetch:** bodyJson type ([5740467](https://github.com/AliMD/alwatr-eslib/commit/57404673e7f031a73d1cf23501e6fa8d89759769))
|
|
146
|
+
- **fetch:** check node_mode before use navigator.online ([a688f48](https://github.com/AliMD/alwatr-eslib/commit/a688f48e9ce4b103c25ffd50f1b8c96e89c205d1))
|
|
147
|
+
- **fetch:** serviceRequest generic type ([074ef38](https://github.com/AliMD/alwatr-eslib/commit/074ef3876086f93486753559d8e3db0b60c52a0e))
|
|
148
|
+
- **fetch:** suppress fetch_cache_not_found extra error ([c04f609](https://github.com/AliMD/alwatr-eslib/commit/c04f60944106dbd8d1bf2fb5ce0e7be644c3abc6))
|
|
149
|
+
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr-eslib/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
|
|
132
150
|
|
|
133
151
|
### Features
|
|
134
152
|
|
|
135
|
-
- **fetch:** add user auth ([811fbc0](https://github.com/AliMD/alwatr/commit/811fbc018c2b4e3b808704e8623bd5dff2b2f3f7))
|
|
136
|
-
- **fetch:** StringifyableFetchOptions type ([e13fdb2](https://github.com/AliMD/alwatr/commit/e13fdb2550cf3a2102c331aa7980234ca6f86e08))
|
|
153
|
+
- **fetch:** add user auth ([811fbc0](https://github.com/AliMD/alwatr-eslib/commit/811fbc018c2b4e3b808704e8623bd5dff2b2f3f7))
|
|
154
|
+
- **fetch:** StringifyableFetchOptions type ([e13fdb2](https://github.com/AliMD/alwatr-eslib/commit/e13fdb2550cf3a2102c331aa7980234ca6f86e08))
|
|
137
155
|
|
|
138
|
-
# [0.30.0](https://github.com/AliMD/alwatr/compare/v0.29.0...v0.30.0) (2023-03-06)
|
|
156
|
+
# [0.30.0](https://github.com/AliMD/alwatr-eslib/compare/v0.29.0...v0.30.0) (2023-03-06)
|
|
139
157
|
|
|
140
158
|
### Bug Fixes
|
|
141
159
|
|
|
142
|
-
- **fetch:** fetchContext duplicate setSignalValue ([8aa9b00](https://github.com/AliMD/alwatr/commit/8aa9b003a2d7b7ffc8243ff7092d9560763d7273))
|
|
143
|
-
- **fetch:** getClientId in nodejs ([c99e41c](https://github.com/AliMD/alwatr/commit/c99e41c9e9a979ca50cc01aeb5371a3487d9da2e))
|
|
160
|
+
- **fetch:** fetchContext duplicate setSignalValue ([8aa9b00](https://github.com/AliMD/alwatr-eslib/commit/8aa9b003a2d7b7ffc8243ff7092d9560763d7273))
|
|
161
|
+
- **fetch:** getClientId in nodejs ([c99e41c](https://github.com/AliMD/alwatr-eslib/commit/c99e41c9e9a979ca50cc01aeb5371a3487d9da2e))
|
|
144
162
|
|
|
145
163
|
### Features
|
|
146
164
|
|
|
147
|
-
- **fetch:** enhance fetchContext with dispatchOptions and only cache_only request in first time ([1f6b575](https://github.com/AliMD/alwatr/commit/1f6b575437104d64ede8a2c23d141160360d2cd5))
|
|
148
|
-
- **fetch:** fetchContext ([d63d17e](https://github.com/AliMD/alwatr/commit/d63d17ecb58221159dc45a473fdd1c992d306d2b))
|
|
149
|
-
- **fetch:** fetchContext skip online request when offline ([7c2b649](https://github.com/AliMD/alwatr/commit/7c2b6491f78acb961cdc0583112e3c709a177b79))
|
|
150
|
-
- **fetch:** fetchContext work on background ([2e12bfd](https://github.com/AliMD/alwatr/commit/2e12bfde0a0636c30e60906c4812ec66b2d36742))
|
|
151
|
-
- **fetch:** handle offline for all requests ([6a8d7b7](https://github.com/AliMD/alwatr/commit/6a8d7b7159732d834be052191935580331e36962))
|
|
165
|
+
- **fetch:** enhance fetchContext with dispatchOptions and only cache_only request in first time ([1f6b575](https://github.com/AliMD/alwatr-eslib/commit/1f6b575437104d64ede8a2c23d141160360d2cd5))
|
|
166
|
+
- **fetch:** fetchContext ([d63d17e](https://github.com/AliMD/alwatr-eslib/commit/d63d17ecb58221159dc45a473fdd1c992d306d2b))
|
|
167
|
+
- **fetch:** fetchContext skip online request when offline ([7c2b649](https://github.com/AliMD/alwatr-eslib/commit/7c2b6491f78acb961cdc0583112e3c709a177b79))
|
|
168
|
+
- **fetch:** fetchContext work on background ([2e12bfd](https://github.com/AliMD/alwatr-eslib/commit/2e12bfde0a0636c30e60906c4812ec66b2d36742))
|
|
169
|
+
- **fetch:** handle offline for all requests ([6a8d7b7](https://github.com/AliMD/alwatr-eslib/commit/6a8d7b7159732d834be052191935580331e36962))
|
|
152
170
|
|
|
153
|
-
# [0.29.0](https://github.com/AliMD/alwatr/compare/v0.28.0...v0.29.0) (2023-02-10)
|
|
171
|
+
# [0.29.0](https://github.com/AliMD/alwatr-eslib/compare/v0.28.0...v0.29.0) (2023-02-10)
|
|
154
172
|
|
|
155
173
|
### Bug Fixes
|
|
156
174
|
|
|
157
|
-
- **fetch:** device id to client id ([077e467](https://github.com/AliMD/alwatr/commit/077e4671d804d43c8f61a9d163d8d51d7a69134e))
|
|
158
|
-
- **fetch:** headers type ([cd4b14e](https://github.com/AliMD/alwatr/commit/cd4b14e46b5090b6df8cb4f89d22b53966b9151e))
|
|
175
|
+
- **fetch:** device id to client id ([077e467](https://github.com/AliMD/alwatr-eslib/commit/077e4671d804d43c8f61a9d163d8d51d7a69134e))
|
|
176
|
+
- **fetch:** headers type ([cd4b14e](https://github.com/AliMD/alwatr-eslib/commit/cd4b14e46b5090b6df8cb4f89d22b53966b9151e))
|
|
159
177
|
|
|
160
178
|
### Features
|
|
161
179
|
|
|
162
|
-
- **fetch:** add update_cache to CacheStrategy ([e1406b1](https://github.com/AliMD/alwatr/commit/e1406b12e1276de3295c47506c8102ab3f8bfa79))
|
|
163
|
-
- **fetch:** clientId on service request ([9575a1d](https://github.com/AliMD/alwatr/commit/9575a1d595a0a4757581a29a66837cbe4be46ed3))
|
|
180
|
+
- **fetch:** add update_cache to CacheStrategy ([e1406b1](https://github.com/AliMD/alwatr-eslib/commit/e1406b12e1276de3295c47506c8102ab3f8bfa79))
|
|
181
|
+
- **fetch:** clientId on service request ([9575a1d](https://github.com/AliMD/alwatr-eslib/commit/9575a1d595a0a4757581a29a66837cbe4be46ed3))
|
|
164
182
|
|
|
165
|
-
# [0.28.0](https://github.com/AliMD/alwatr/compare/v0.27.0...v0.28.0) (2023-01-20)
|
|
183
|
+
# [0.28.0](https://github.com/AliMD/alwatr-eslib/compare/v0.27.0...v0.28.0) (2023-01-20)
|
|
166
184
|
|
|
167
185
|
### Bug Fixes
|
|
168
186
|
|
|
169
|
-
- review issue ([e5d192c](https://github.com/AliMD/alwatr/commit/e5d192cbee6917c2de01146cf8bd026895724ab8))
|
|
187
|
+
- review issue ([e5d192c](https://github.com/AliMD/alwatr-eslib/commit/e5d192cbee6917c2de01146cf8bd026895724ab8))
|
|
170
188
|
|
|
171
189
|
### Features
|
|
172
190
|
|
|
173
|
-
- **type:** add types ([2de3842](https://github.com/AliMD/alwatr/commit/2de384297b70b9818ec8d62ce8d31be4822d95a4))
|
|
191
|
+
- **type:** add types ([2de3842](https://github.com/AliMD/alwatr-eslib/commit/2de384297b70b9818ec8d62ce8d31be4822d95a4))
|
|
174
192
|
|
|
175
|
-
# [0.27.0](https://github.com/AliMD/alwatr/compare/v0.26.0...v0.27.0) (2022-12-29)
|
|
193
|
+
# [0.27.0](https://github.com/AliMD/alwatr-eslib/compare/v0.26.0...v0.27.0) (2022-12-29)
|
|
176
194
|
|
|
177
195
|
**Note:** Version bump only for package @alwatr/fetch
|
|
178
196
|
|
|
179
|
-
# [0.26.0](https://github.com/AliMD/alwatr/compare/v0.25.0...v0.26.0) (2022-12-22)
|
|
197
|
+
# [0.26.0](https://github.com/AliMD/alwatr-eslib/compare/v0.25.0...v0.26.0) (2022-12-22)
|
|
180
198
|
|
|
181
199
|
### Bug Fixes
|
|
182
200
|
|
|
183
|
-
- all import without .js ([fa739ab](https://github.com/AliMD/alwatr/commit/fa739ab23f67bae1d10bfcc146920b71377a26fc))
|
|
184
|
-
- **
|
|
185
|
-
- **fetch:** always call revalidateCallback ([444edc5](https://github.com/AliMD/alwatr/commit/444edc52b6dd5de5418ae8630e1f2270f0114372))
|
|
186
|
-
- **fetch:** enhance handle and report errors in serviceRequest ([dbfc7ff](https://github.com/AliMD/alwatr/commit/dbfc7ff2a036216498dc8e2ff58b74b7eb8d9bc0))
|
|
187
|
-
- **fetch:** fetch_cache_not_found is not error ([3d1aa4e](https://github.com/AliMD/alwatr/commit/3d1aa4e572fbf4bc7b0a527a3fdcf4c521af18dd))
|
|
188
|
-
- **fetch:** fetch_failed error message ([3e98bd9](https://github.com/AliMD/alwatr/commit/3e98bd926a495c13d476f2f1cfb9e546a059d4d8))
|
|
189
|
-
- **fetch:** remove extra \_options ([ad24c81](https://github.com/AliMD/alwatr/commit/ad24c8104b944ebda52308e60d41976ac1eeee81))
|
|
190
|
-
- **fetch:** revalidateCallback issue ([7207909](https://github.com/AliMD/alwatr/commit/72079098edb438c28256dad03d7802bc2fab0858))
|
|
191
|
-
- set correct path ([d01ce6f](https://github.com/AliMD/alwatr/commit/d01ce6ffa749a5e3e0e11e35b4ed61d75d61fec9))
|
|
192
|
-
- **storage-engine:** AlwatrDocumentStorage ([ca9a7bf](https://github.com/AliMD/alwatr/commit/ca9a7bf5e17b333538e749ada5d481a06c847101))
|
|
193
|
-
- tsconfig ([e96dcd3](https://github.com/AliMD/alwatr/commit/e96dcd30774a9f06f7d051e0504192cbbe019e35))
|
|
194
|
-
- tsconfig refrences ([cea0562](https://github.com/AliMD/alwatr/commit/cea05621ecfa499476c5b10a412e60f27ba6a06d))
|
|
201
|
+
- all import without .js ([fa739ab](https://github.com/AliMD/alwatr-eslib/commit/fa739ab23f67bae1d10bfcc146920b71377a26fc))
|
|
202
|
+
- **packages/fetch:** tsconfig refrences ([e6b9542](https://github.com/AliMD/alwatr-eslib/commit/e6b9542284e67b67600da4dcebd19daedb031c9c))
|
|
203
|
+
- **fetch:** always call revalidateCallback ([444edc5](https://github.com/AliMD/alwatr-eslib/commit/444edc52b6dd5de5418ae8630e1f2270f0114372))
|
|
204
|
+
- **fetch:** enhance handle and report errors in serviceRequest ([dbfc7ff](https://github.com/AliMD/alwatr-eslib/commit/dbfc7ff2a036216498dc8e2ff58b74b7eb8d9bc0))
|
|
205
|
+
- **fetch:** fetch_cache_not_found is not error ([3d1aa4e](https://github.com/AliMD/alwatr-eslib/commit/3d1aa4e572fbf4bc7b0a527a3fdcf4c521af18dd))
|
|
206
|
+
- **fetch:** fetch_failed error message ([3e98bd9](https://github.com/AliMD/alwatr-eslib/commit/3e98bd926a495c13d476f2f1cfb9e546a059d4d8))
|
|
207
|
+
- **fetch:** remove extra \_options ([ad24c81](https://github.com/AliMD/alwatr-eslib/commit/ad24c8104b944ebda52308e60d41976ac1eeee81))
|
|
208
|
+
- **fetch:** revalidateCallback issue ([7207909](https://github.com/AliMD/alwatr-eslib/commit/72079098edb438c28256dad03d7802bc2fab0858))
|
|
209
|
+
- set correct path ([d01ce6f](https://github.com/AliMD/alwatr-eslib/commit/d01ce6ffa749a5e3e0e11e35b4ed61d75d61fec9))
|
|
210
|
+
- **storage-engine:** AlwatrDocumentStorage ([ca9a7bf](https://github.com/AliMD/alwatr-eslib/commit/ca9a7bf5e17b333538e749ada5d481a06c847101))
|
|
211
|
+
- tsconfig ([e96dcd3](https://github.com/AliMD/alwatr-eslib/commit/e96dcd30774a9f06f7d051e0504192cbbe019e35))
|
|
212
|
+
- tsconfig refrences ([cea0562](https://github.com/AliMD/alwatr-eslib/commit/cea05621ecfa499476c5b10a412e60f27ba6a06d))
|
|
195
213
|
|
|
196
214
|
### Features
|
|
197
215
|
|
|
198
|
-
- **fetch:** add AlwatrDocumentStorage type ([44b84f0](https://github.com/AliMD/alwatr/commit/44b84f0754169a707472655811020f6e542a6e5d))
|
|
199
|
-
- **fetch:** serviceRequest ([b0b5478](https://github.com/AliMD/alwatr/commit/b0b5478d16b2cb590cfc29d644006e4a459dd6d6))
|
|
200
|
-
- **fetch:** serviceRequest ([#513](https://github.com/AliMD/alwatr/issues/513)) ([113ee49](https://github.com/AliMD/alwatr/commit/113ee498c778d9efc00cc4807bfef09e52336a31))
|
|
201
|
-
- improve accident debugging ([d697e6c](https://github.com/AliMD/alwatr/commit/d697e6c4c7d0a4172f4dba9caf6fbd478f79de9c))
|
|
202
|
-
- improve error debugging ([1fba504](https://github.com/AliMD/alwatr/commit/1fba50400a1e8ececc10bbe8ea11cc8dcea2289c))
|
|
216
|
+
- **fetch:** add AlwatrDocumentStorage type ([44b84f0](https://github.com/AliMD/alwatr-eslib/commit/44b84f0754169a707472655811020f6e542a6e5d))
|
|
217
|
+
- **fetch:** serviceRequest ([b0b5478](https://github.com/AliMD/alwatr-eslib/commit/b0b5478d16b2cb590cfc29d644006e4a459dd6d6))
|
|
218
|
+
- **fetch:** serviceRequest ([#513](https://github.com/AliMD/alwatr-eslib/issues/513)) ([113ee49](https://github.com/AliMD/alwatr-eslib/commit/113ee498c778d9efc00cc4807bfef09e52336a31))
|
|
219
|
+
- improve accident debugging ([d697e6c](https://github.com/AliMD/alwatr-eslib/commit/d697e6c4c7d0a4172f4dba9caf6fbd478f79de9c))
|
|
220
|
+
- improve error debugging ([1fba504](https://github.com/AliMD/alwatr-eslib/commit/1fba50400a1e8ececc10bbe8ea11cc8dcea2289c))
|
|
203
221
|
|
|
204
|
-
# [0.25.0](https://github.com/AliMD/alwatr/compare/v0.24.1...v0.25.0) (2022-12-07)
|
|
222
|
+
# [0.25.0](https://github.com/AliMD/alwatr-eslib/compare/v0.24.1...v0.25.0) (2022-12-07)
|
|
205
223
|
|
|
206
224
|
**Note:** Version bump only for package @alwatr/fetch
|
|
207
225
|
|
|
208
|
-
## [0.24.1](https://github.com/AliMD/alwatr/compare/v0.24.0...v0.24.1) (2022-12-01)
|
|
226
|
+
## [0.24.1](https://github.com/AliMD/alwatr-eslib/compare/v0.24.0...v0.24.1) (2022-12-01)
|
|
209
227
|
|
|
210
228
|
**Note:** Version bump only for package @alwatr/fetch
|
|
211
229
|
|
|
212
|
-
# [0.24.0](https://github.com/AliMD/alwatr/compare/v0.23.0...v0.24.0) (2022-11-28)
|
|
230
|
+
# [0.24.0](https://github.com/AliMD/alwatr-eslib/compare/v0.23.0...v0.24.0) (2022-11-28)
|
|
213
231
|
|
|
214
232
|
### Bug Fixes
|
|
215
233
|
|
|
216
|
-
- **fetch:** AlwatrServiceResponseSuccessWithMeta types ([b46f3f2](https://github.com/AliMD/alwatr/commit/b46f3f22a7c5a671385b0a8f58d0881501ce1b94))
|
|
217
|
-
- **fetch:** use nre method type ([1c63eca](https://github.com/AliMD/alwatr/commit/1c63eca994582c241112c3e5ae79bac49831532f))
|
|
218
|
-
- update types ([44cc57f](https://github.com/AliMD/alwatr/commit/44cc57f97a99ed810dae3fde39c9525bd0e8ff3c))
|
|
219
|
-
- use ~ for package version ([4e027ff](https://github.com/AliMD/alwatr/commit/4e027ff63875e03b088ebcdc1bdf2495f4494eec))
|
|
234
|
+
- **fetch:** AlwatrServiceResponseSuccessWithMeta types ([b46f3f2](https://github.com/AliMD/alwatr-eslib/commit/b46f3f22a7c5a671385b0a8f58d0881501ce1b94))
|
|
235
|
+
- **fetch:** use nre method type ([1c63eca](https://github.com/AliMD/alwatr-eslib/commit/1c63eca994582c241112c3e5ae79bac49831532f))
|
|
236
|
+
- update types ([44cc57f](https://github.com/AliMD/alwatr-eslib/commit/44cc57f97a99ed810dae3fde39c9525bd0e8ff3c))
|
|
237
|
+
- use ~ for package version ([4e027ff](https://github.com/AliMD/alwatr-eslib/commit/4e027ff63875e03b088ebcdc1bdf2495f4494eec))
|
|
220
238
|
|
|
221
|
-
# [0.23.0](https://github.com/AliMD/alwatr/compare/v0.22.1...v0.23.0) (2022-11-23)
|
|
239
|
+
# [0.23.0](https://github.com/AliMD/alwatr-eslib/compare/v0.22.1...v0.23.0) (2022-11-23)
|
|
222
240
|
|
|
223
241
|
### Bug Fixes
|
|
224
242
|
|
|
225
|
-
- **fetch:** types ([4ce81a7](https://github.com/AliMD/alwatr/commit/4ce81a7b82d01ab938754bc5e483ccb074671e33))
|
|
243
|
+
- **fetch:** types ([4ce81a7](https://github.com/AliMD/alwatr-eslib/commit/4ce81a7b82d01ab938754bc5e483ccb074671e33))
|
|
226
244
|
|
|
227
245
|
### Features
|
|
228
246
|
|
|
229
|
-
- **fetch:** set token in options ([033a638](https://github.com/AliMD/alwatr/commit/033a63846f8c43b86c7d0a662e4bb6aa7cae3af5))
|
|
247
|
+
- **fetch:** set token in options ([033a638](https://github.com/AliMD/alwatr-eslib/commit/033a63846f8c43b86c7d0a662e4bb6aa7cae3af5))
|
|
230
248
|
|
|
231
|
-
## [0.22.1](https://github.com/AliMD/alwatr/compare/v0.22.0...v0.22.1) (2022-11-21)
|
|
249
|
+
## [0.22.1](https://github.com/AliMD/alwatr-eslib/compare/v0.22.0...v0.22.1) (2022-11-21)
|
|
232
250
|
|
|
233
251
|
**Note:** Version bump only for package @alwatr/fetch
|
|
234
252
|
|
|
235
|
-
# [0.22.0](https://github.com/AliMD/alwatr/compare/v0.21.0...v0.22.0) (2022-11-20)
|
|
253
|
+
# [0.22.0](https://github.com/AliMD/alwatr-eslib/compare/v0.21.0...v0.22.0) (2022-11-20)
|
|
236
254
|
|
|
237
255
|
### Bug Fixes
|
|
238
256
|
|
|
239
|
-
- **fetch:** \_handleRetryPattern ([fe4ac12](https://github.com/AliMD/alwatr/commit/fe4ac12b4ad3086d44e545591c767cb322e32b8d))
|
|
240
|
-
- **fetch:** bodyJson issue ([5d8d6fa](https://github.com/AliMD/alwatr/commit/5d8d6fa4a0f608c2c5ed583aa54de9b836daaa5f))
|
|
257
|
+
- **fetch:** \_handleRetryPattern ([fe4ac12](https://github.com/AliMD/alwatr-eslib/commit/fe4ac12b4ad3086d44e545591c767cb322e32b8d))
|
|
258
|
+
- **fetch:** bodyJson issue ([5d8d6fa](https://github.com/AliMD/alwatr-eslib/commit/5d8d6fa4a0f608c2c5ed583aa54de9b836daaa5f))
|
|
241
259
|
|
|
242
260
|
### Features
|
|
243
261
|
|
|
244
|
-
- **fetch:** support nodejs ([2ed2ef4](https://github.com/AliMD/alwatr/commit/2ed2ef42e9f204d4896ada4e20b839cfabdc7284))
|
|
262
|
+
- **fetch:** support nodejs ([2ed2ef4](https://github.com/AliMD/alwatr-eslib/commit/2ed2ef42e9f204d4896ada4e20b839cfabdc7284))
|
|
245
263
|
|
|
246
264
|
### Performance Improvements
|
|
247
265
|
|
|
248
|
-
- **fetch:** Improve performance and decrease memory usage ([7c29333](https://github.com/AliMD/alwatr/commit/7c293339215bea3a5013effe4aea5b6267a7a75e))
|
|
266
|
+
- **fetch:** Improve performance and decrease memory usage ([7c29333](https://github.com/AliMD/alwatr-eslib/commit/7c293339215bea3a5013effe4aea5b6267a7a75e))
|
|
249
267
|
|
|
250
|
-
# [0.21.0](https://github.com/AliMD/alwatr/compare/v0.20.0...v0.21.0) (2022-11-13)
|
|
268
|
+
# [0.21.0](https://github.com/AliMD/alwatr-eslib/compare/v0.20.0...v0.21.0) (2022-11-13)
|
|
251
269
|
|
|
252
270
|
**Note:** Version bump only for package @alwatr/fetch
|
|
253
271
|
|
|
254
|
-
# [0.20.0](https://github.com/AliMD/alwatr/compare/v0.19.0...v0.20.0) (2022-11-05)
|
|
272
|
+
# [0.20.0](https://github.com/AliMD/alwatr-eslib/compare/v0.19.0...v0.20.0) (2022-11-05)
|
|
255
273
|
|
|
256
274
|
### Bug Fixes
|
|
257
275
|
|
|
258
|
-
- **fetch:** \_handleRemoveDuplicate ([6207b48](https://github.com/AliMD/alwatr/commit/6207b4867935d05a0e5a1c795de9efab4ff77c68))
|
|
259
|
-
- **fetch:** cacheStorageName issue ([e641ff7](https://github.com/AliMD/alwatr/commit/e641ff740055a68b6397f00bf46f1d05943c348a))
|
|
260
|
-
- **fetch:** method type and case ([8d4ba77](https://github.com/AliMD/alwatr/commit/8d4ba77e56ecfe2aeaa459dcd26039c38c4b2199))
|
|
261
|
-
- **fetch:** prevent duplicate revalidateCallback on first time ([2da7dc5](https://github.com/AliMD/alwatr/commit/2da7dc579e4850af06914590a231548cd469cd75))
|
|
276
|
+
- **fetch:** \_handleRemoveDuplicate ([6207b48](https://github.com/AliMD/alwatr-eslib/commit/6207b4867935d05a0e5a1c795de9efab4ff77c68))
|
|
277
|
+
- **fetch:** cacheStorageName issue ([e641ff7](https://github.com/AliMD/alwatr-eslib/commit/e641ff740055a68b6397f00bf46f1d05943c348a))
|
|
278
|
+
- **fetch:** method type and case ([8d4ba77](https://github.com/AliMD/alwatr-eslib/commit/8d4ba77e56ecfe2aeaa459dcd26039c38c4b2199))
|
|
279
|
+
- **fetch:** prevent duplicate revalidateCallback on first time ([2da7dc5](https://github.com/AliMD/alwatr-eslib/commit/2da7dc579e4850af06914590a231548cd469cd75))
|
|
262
280
|
|
|
263
281
|
### Features
|
|
264
282
|
|
|
265
|
-
- **fetch:** add retryDelay ([28e3244](https://github.com/AliMD/alwatr/commit/28e3244a2d35e7a1a91f9a5a4942f1bb4a56d981))
|
|
266
|
-
- **fetch:** revalidate callback for `stale_while_revalidate` cache strategy. ([8976cc4](https://github.com/AliMD/alwatr/commit/8976cc424b2a9e96e4cfa69941d5378a6640af6f))
|
|
267
|
-
- **fetch:** simple memory caching for remove duplicate/parallel requests ([74cd7f1](https://github.com/AliMD/alwatr/commit/74cd7f1500d730021a0f577c0ecfd7a2460fdb15))
|
|
283
|
+
- **fetch:** add retryDelay ([28e3244](https://github.com/AliMD/alwatr-eslib/commit/28e3244a2d35e7a1a91f9a5a4942f1bb4a56d981))
|
|
284
|
+
- **fetch:** revalidate callback for `stale_while_revalidate` cache strategy. ([8976cc4](https://github.com/AliMD/alwatr-eslib/commit/8976cc424b2a9e96e4cfa69941d5378a6640af6f))
|
|
285
|
+
- **fetch:** simple memory caching for remove duplicate/parallel requests ([74cd7f1](https://github.com/AliMD/alwatr-eslib/commit/74cd7f1500d730021a0f577c0ecfd7a2460fdb15))
|
|
268
286
|
|
|
269
|
-
# [0.19.0](https://github.com/AliMD/alwatr/compare/v0.18.0...v0.19.0) (2022-11-01)
|
|
287
|
+
# [0.19.0](https://github.com/AliMD/alwatr-eslib/compare/v0.18.0...v0.19.0) (2022-11-01)
|
|
270
288
|
|
|
271
289
|
**Note:** Version bump only for package @alwatr/fetch
|
|
272
290
|
|
|
273
|
-
# [0.18.0](https://github.com/AliMD/alwatr/compare/v0.17.0...v0.18.0) (2022-10-22)
|
|
291
|
+
# [0.18.0](https://github.com/AliMD/alwatr-eslib/compare/v0.17.0...v0.18.0) (2022-10-22)
|
|
274
292
|
|
|
275
293
|
### Bug Fixes
|
|
276
294
|
|
|
277
|
-
- **fetch:** update cache on network_first ([54b59cd](https://github.com/AliMD/alwatr/commit/54b59cdc64a543a0afcd09d2ec78d20661f3a06d))
|
|
295
|
+
- **fetch:** update cache on network_first ([54b59cd](https://github.com/AliMD/alwatr-eslib/commit/54b59cdc64a543a0afcd09d2ec78d20661f3a06d))
|
|
278
296
|
|
|
279
297
|
### Features
|
|
280
298
|
|
|
281
|
-
- **fetch:** cache strategy ([106eabd](https://github.com/AliMD/alwatr/commit/106eabdd10574b24f9919049d0b509ae40168a9a))
|
|
282
|
-
- **fetch:** optional cacheStorageName ([f2bd8f2](https://github.com/AliMD/alwatr/commit/f2bd8f2a899466628417294cb269fd569b87e17a))
|
|
283
|
-
- **fetch:** stale_while_revalidate cache strategy ([f758f49](https://github.com/AliMD/alwatr/commit/f758f495efb42ce7441e8f2058c1b67de0615a8c))
|
|
299
|
+
- **fetch:** cache strategy ([106eabd](https://github.com/AliMD/alwatr-eslib/commit/106eabdd10574b24f9919049d0b509ae40168a9a))
|
|
300
|
+
- **fetch:** optional cacheStorageName ([f2bd8f2](https://github.com/AliMD/alwatr-eslib/commit/f2bd8f2a899466628417294cb269fd569b87e17a))
|
|
301
|
+
- **fetch:** stale_while_revalidate cache strategy ([f758f49](https://github.com/AliMD/alwatr-eslib/commit/f758f495efb42ce7441e8f2058c1b67de0615a8c))
|
|
284
302
|
|
|
285
|
-
# [0.17.0](https://github.com/AliMD/alwatr/compare/v0.16.1...v0.17.0) (2022-10-21)
|
|
303
|
+
# [0.17.0](https://github.com/AliMD/alwatr-eslib/compare/v0.16.1...v0.17.0) (2022-10-21)
|
|
286
304
|
|
|
287
305
|
### Bug Fixes
|
|
288
306
|
|
|
289
|
-
- **fetch:** not ok retry condition ([0da1edd](https://github.com/AliMD/alwatr/commit/0da1edda64ec5abf70a83361d159e207691e368e))
|
|
307
|
+
- **fetch:** not ok retry condition ([0da1edd](https://github.com/AliMD/alwatr-eslib/commit/0da1edda64ec5abf70a83361d159e207691e368e))
|
|
290
308
|
|
|
291
309
|
### Features
|
|
292
310
|
|
|
293
|
-
- **fetch:** docs & pattern ([459ad1c](https://github.com/AliMD/alwatr/commit/459ad1c5996f851769306639136d79c0f7270770))
|
|
294
|
-
- **fetch:** logger & jsdocs ([36f652d](https://github.com/AliMD/alwatr/commit/36f652d5dad23b2aeb824af77d1b0e442119c6e8))
|
|
295
|
-
- **fetch:** retry pattern ([5350d1a](https://github.com/AliMD/alwatr/commit/5350d1a81b9134d598f46006a1baa880b280ea98))
|
|
311
|
+
- **fetch:** docs & pattern ([459ad1c](https://github.com/AliMD/alwatr-eslib/commit/459ad1c5996f851769306639136d79c0f7270770))
|
|
312
|
+
- **fetch:** logger & jsdocs ([36f652d](https://github.com/AliMD/alwatr-eslib/commit/36f652d5dad23b2aeb824af77d1b0e442119c6e8))
|
|
313
|
+
- **fetch:** retry pattern ([5350d1a](https://github.com/AliMD/alwatr-eslib/commit/5350d1a81b9134d598f46006a1baa880b280ea98))
|
|
296
314
|
|
|
297
315
|
### Performance Improvements
|
|
298
316
|
|
|
299
|
-
- **fetch:** syntax ([1fdd02e](https://github.com/AliMD/alwatr/commit/1fdd02ec8b52e32a124b8d7c1d1c7fd7c993e3af))
|
|
317
|
+
- **fetch:** syntax ([1fdd02e](https://github.com/AliMD/alwatr-eslib/commit/1fdd02ec8b52e32a124b8d7c1d1c7fd7c993e3af))
|
|
300
318
|
|
|
301
|
-
# [0.16.0](https://github.com/AliMD/alwatr/compare/v0.15.0...v0.16.0) (2022-09-08)
|
|
319
|
+
# [0.16.0](https://github.com/AliMD/alwatr-eslib/compare/v0.15.0...v0.16.0) (2022-09-08)
|
|
302
320
|
|
|
303
321
|
**Note:** Version bump only for package @alwatr/fetch
|
|
304
322
|
|
|
305
|
-
# [0.15.0](https://github.com/AliMD/alwatr/compare/v0.14.0...v0.15.0) (2022-09-01)
|
|
323
|
+
# [0.15.0](https://github.com/AliMD/alwatr-eslib/compare/v0.14.0...v0.15.0) (2022-09-01)
|
|
306
324
|
|
|
307
325
|
**Note:** Version bump only for package @alwatr/fetch
|
|
308
326
|
|
|
309
|
-
# [0.14.0](https://github.com/AliMD/alwatr/compare/v0.13.0...v0.14.0) (2022-08-19)
|
|
327
|
+
# [0.14.0](https://github.com/AliMD/alwatr-eslib/compare/v0.13.0...v0.14.0) (2022-08-19)
|
|
310
328
|
|
|
311
329
|
**Note:** Version bump only for package @alwatr/fetch
|
|
312
330
|
|
|
313
|
-
# [0.13.0](https://github.com/AliMD/alwatr/compare/v0.12.0...v0.13.0) (2022-08-06)
|
|
331
|
+
# [0.13.0](https://github.com/AliMD/alwatr-eslib/compare/v0.12.0...v0.13.0) (2022-08-06)
|
|
314
332
|
|
|
315
333
|
**Note:** Version bump only for package @alwatr/fetch
|
|
316
334
|
|
|
317
|
-
# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)
|
|
335
|
+
# [0.12.0](https://github.com/AliMD/alwatr-eslib/compare/v0.11.0...v0.12.0) (2022-07-22)
|
|
318
336
|
|
|
319
337
|
### Bug Fixes
|
|
320
338
|
|
|
321
|
-
- **fetch:** compatible with new ts types AbortSignal ([949655a](https://github.com/AliMD/alwatr/commit/949655a257852aaaaa311e32603ecc0819eedf51))
|
|
339
|
+
- **fetch:** compatible with new ts types AbortSignal ([949655a](https://github.com/AliMD/alwatr-eslib/commit/949655a257852aaaaa311e32603ecc0819eedf51))
|
|
322
340
|
|
|
323
|
-
# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)
|
|
341
|
+
# [0.11.0](https://github.com/AliMD/alwatr-eslib/compare/v0.10.1...v0.11.0) (2022-04-16)
|
|
324
342
|
|
|
325
343
|
**Note:** Version bump only for package @alwatr/fetch
|
|
326
344
|
|
|
327
|
-
# [0.10.0](https://github.com/AliMD/alwatr/compare/v0.9.0...v0.10.0) (2022-04-02)
|
|
345
|
+
# [0.10.0](https://github.com/AliMD/alwatr-eslib/compare/v0.9.0...v0.10.0) (2022-04-02)
|
|
328
346
|
|
|
329
347
|
**Note:** Version bump only for package @alwatr/fetch
|
|
330
348
|
|
|
331
|
-
# [0.9.0](https://github.com/AliMD/alwatr/compare/v0.8.0...v0.9.0) (2022-03-22)
|
|
349
|
+
# [0.9.0](https://github.com/AliMD/alwatr-eslib/compare/v0.8.0...v0.9.0) (2022-03-22)
|
|
332
350
|
|
|
333
351
|
**Note:** Version bump only for package @alwatr/fetch
|
|
334
352
|
|
|
335
|
-
# [0.8.0](https://github.com/AliMD/alwatr/compare/v0.7.2...v0.8.0) (2022-03-14)
|
|
353
|
+
# [0.8.0](https://github.com/AliMD/alwatr-eslib/compare/v0.7.2...v0.8.0) (2022-03-14)
|
|
336
354
|
|
|
337
355
|
**Note:** Version bump only for package @alwatr/fetch
|
|
338
356
|
|
|
339
|
-
## [0.7.2](https://github.com/AliMD/alwatr/compare/v0.7.1...v0.7.2) (2022-03-12)
|
|
357
|
+
## [0.7.2](https://github.com/AliMD/alwatr-eslib/compare/v0.7.1...v0.7.2) (2022-03-12)
|
|
340
358
|
|
|
341
359
|
**Note:** Version bump only for package @alwatr/fetch
|
|
342
360
|
|
|
343
|
-
# [0.7.0](https://github.com/AliMD/alwatr/compare/v0.6.1...v0.7.0) (2022-03-12)
|
|
361
|
+
# [0.7.0](https://github.com/AliMD/alwatr-eslib/compare/v0.6.1...v0.7.0) (2022-03-12)
|
|
344
362
|
|
|
345
363
|
**Note:** Version bump only for package @alwatr/fetch
|
|
346
364
|
|
|
347
|
-
# [0.6.0](https://github.com/AliMD/alwatr/compare/v0.5.0...v0.6.0) (2022-03-11)
|
|
365
|
+
# [0.6.0](https://github.com/AliMD/alwatr-eslib/compare/v0.5.0...v0.6.0) (2022-03-11)
|
|
348
366
|
|
|
349
367
|
### Bug Fixes
|
|
350
368
|
|
|
351
|
-
- alalwatr ([898aa6e](https://github.com/AliMD/alwatr/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
|
|
352
|
-
- **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
|
|
369
|
+
- alalwatr ([898aa6e](https://github.com/AliMD/alwatr-eslib/commit/898aa6ed0888eab9265c83b96a50f1b8c216d143))
|
|
370
|
+
- **packages:** duplicate alwatr keyword ([77d4aa2](https://github.com/AliMD/alwatr-eslib/commit/77d4aa2105ad47515c3eee251fd6b8c281d0d1fc))
|
|
353
371
|
|
|
354
|
-
# [0.5.0](https://github.com/AliMD/alwatr/compare/v0.4.0...v0.5.0) (2022-03-11)
|
|
372
|
+
# [0.5.0](https://github.com/AliMD/alwatr-eslib/compare/v0.4.0...v0.5.0) (2022-03-11)
|
|
355
373
|
|
|
356
374
|
**Note:** Version bump only for package @alwatr/fetch
|
|
357
375
|
|
|
358
|
-
# [0.4.0](https://github.com/AliMD/alwatr/compare/v0.3.0...v0.4.0) (2022-03-11)
|
|
376
|
+
# [0.4.0](https://github.com/AliMD/alwatr-eslib/compare/v0.3.0...v0.4.0) (2022-03-11)
|
|
359
377
|
|
|
360
378
|
### Bug Fixes
|
|
361
379
|
|
|
362
|
-
- **fetch:** build issue [#73](https://github.com/AliMD/alwatr/issues/73) ([fb74463](https://github.com/AliMD/alwatr/commit/fb74463d367393706d16e482488a565bdfef70a1))
|
|
380
|
+
- **fetch:** build issue [#73](https://github.com/AliMD/alwatr-eslib/issues/73) ([fb74463](https://github.com/AliMD/alwatr-eslib/commit/fb74463d367393706d16e482488a565bdfef70a1))
|
|
363
381
|
|
|
364
|
-
# [0.3.0](https://github.com/AliMD/alwatr/compare/v0.2.1...v0.3.0) (2022-03-06)
|
|
382
|
+
# [0.3.0](https://github.com/AliMD/alwatr-eslib/compare/v0.2.1...v0.3.0) (2022-03-06)
|
|
365
383
|
|
|
366
384
|
**Note:** Version bump only for package @alwatr/fetch
|
|
367
385
|
|
|
368
|
-
## [0.2.1](https://github.com/AliMD/alwatr/compare/v0.2.0...v0.2.1) (2022-03-05)
|
|
386
|
+
## [0.2.1](https://github.com/AliMD/alwatr-eslib/compare/v0.2.0...v0.2.1) (2022-03-05)
|
|
369
387
|
|
|
370
388
|
**Note:** Version bump only for package @alwatr/fetch
|
|
371
389
|
|
|
372
|
-
# [0.2.0](https://github.com/AliMD/alwatr/compare/v0.1.2...v0.2.0) (2022-03-05)
|
|
390
|
+
# [0.2.0](https://github.com/AliMD/alwatr-eslib/compare/v0.1.2...v0.2.0) (2022-03-05)
|
|
373
391
|
|
|
374
392
|
### Bug Fixes
|
|
375
393
|
|
|
376
|
-
- **fetch:** error codes ([4e0be80](https://github.com/AliMD/alwatr/commit/4e0be80786b6667035ae82750f2351bd2da4f341))
|
|
394
|
+
- **fetch:** error codes ([4e0be80](https://github.com/AliMD/alwatr-eslib/commit/4e0be80786b6667035ae82750f2351bd2da4f341))
|
|
377
395
|
|
|
378
396
|
### Features
|
|
379
397
|
|
|
380
|
-
- **fetch:** add getData ([4a627c4](https://github.com/AliMD/alwatr/commit/4a627c43d2ad07acb340f058f02d41ce57288405))
|
|
381
|
-
- **fetch:** add postData and fetchJson ([b0262b8](https://github.com/AliMD/alwatr/commit/b0262b83b5b7d8b7c376dce68aae3e16bd8e2610))
|
|
382
|
-
- **fetch:** base fetch api ([925cdab](https://github.com/AliMD/alwatr/commit/925cdab8700ffb801e1d836ffc5d3245b66815cf))
|
|
383
|
-
- **fetch:** FetchOptions type ([dd2d141](https://github.com/AliMD/alwatr/commit/dd2d1418d090387e1afa8277f78ae88ace17fd17))
|
|
384
|
-
- **fetch:** new enhanced fetch package ([7e90472](https://github.com/AliMD/alwatr/commit/7e904720c983372317358ce107f6ad0f79c65647))
|
|
398
|
+
- **fetch:** add getData ([4a627c4](https://github.com/AliMD/alwatr-eslib/commit/4a627c43d2ad07acb340f058f02d41ce57288405))
|
|
399
|
+
- **fetch:** add postData and fetchJson ([b0262b8](https://github.com/AliMD/alwatr-eslib/commit/b0262b83b5b7d8b7c376dce68aae3e16bd8e2610))
|
|
400
|
+
- **fetch:** base fetch api ([925cdab](https://github.com/AliMD/alwatr-eslib/commit/925cdab8700ffb801e1d836ffc5d3245b66815cf))
|
|
401
|
+
- **fetch:** FetchOptions type ([dd2d141](https://github.com/AliMD/alwatr-eslib/commit/dd2d1418d090387e1afa8277f78ae88ace17fd17))
|
|
402
|
+
- **fetch:** new enhanced fetch package ([7e90472](https://github.com/AliMD/alwatr-eslib/commit/7e904720c983372317358ce107f6ad0f79c65647))
|
package/fetch.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { type DispatchOptions } from '@alwatr/signal';
|
|
2
1
|
import type { FetchOptions } from './type.js';
|
|
3
2
|
import type { AlwatrServiceResponse } from '@alwatr/type';
|
|
4
3
|
export type * from './type.js';
|
|
5
|
-
export declare function fetchContext(contextName: string, fetchOption: FetchOptions, dispatchOptions?: Partial<DispatchOptions>): Promise<void>;
|
|
6
4
|
/**
|
|
7
5
|
* Fetch from alwatr services and return standard response.
|
|
8
6
|
*/
|
package/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["src/fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["src/fetch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAExD,mBAAmB,WAAW,CAAC;AAc/B;;GAEG;AACH,wBAAsB,cAAc,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB,EACxF,OAAO,EAAE,YAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CAwDZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI9D"}
|
package/fetch.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createLogger, globalAlwatr, NODE_MODE } from '@alwatr/logger';
|
|
2
|
-
import { contextProvider } from '@alwatr/signal';
|
|
3
2
|
import { getClientId, delay } from '@alwatr/util';
|
|
4
3
|
const logger = createLogger('alwatr/fetch');
|
|
5
4
|
globalAlwatr.registeredList.push({
|
|
@@ -9,43 +8,6 @@ globalAlwatr.registeredList.push({
|
|
|
9
8
|
let alwatrCacheStorage;
|
|
10
9
|
const cacheSupported = 'caches' in globalThis;
|
|
11
10
|
const duplicateRequestStorage = {};
|
|
12
|
-
export async function fetchContext(contextName, fetchOption, dispatchOptions = { debounce: 'Timeout' }) {
|
|
13
|
-
logger.logMethodArgs?.('fetchContext', { contextName });
|
|
14
|
-
if (cacheSupported && contextProvider.getValue(contextName) == null) {
|
|
15
|
-
try {
|
|
16
|
-
fetchOption.cacheStrategy = 'cache_only';
|
|
17
|
-
const response = await serviceRequest(fetchOption);
|
|
18
|
-
contextProvider.setValue(contextName, response, dispatchOptions);
|
|
19
|
-
if (navigator.onLine === false) {
|
|
20
|
-
logger.logOther?.('fetchContext:', 'offline');
|
|
21
|
-
// retry on online
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
if (err.message === 'fetch_cache_not_found') {
|
|
27
|
-
logger.logOther?.('fetchContext:', 'fetch_cache_not_found');
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
logger.error('fetchContext', 'fetch_failed', err);
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
fetchOption.cacheStrategy = 'update_cache';
|
|
37
|
-
const response = await serviceRequest(fetchOption);
|
|
38
|
-
if (response.meta?.lastUpdated === undefined || // skip lastUpdated check
|
|
39
|
-
response.meta?.lastUpdated !== contextProvider.getValue(contextName)?.meta?.lastUpdated) {
|
|
40
|
-
logger.logOther?.('fetchContext:', 'contextProvider.setValue(new-received-context)', { contextName });
|
|
41
|
-
contextProvider.setValue(contextName, response, dispatchOptions);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
logger.error('fetchContext', 'fetch_failed', err);
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
11
|
/**
|
|
50
12
|
* Fetch from alwatr services and return standard response.
|
|
51
13
|
*/
|
package/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAC,eAAe,EAAuB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAC,WAAW,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AAOhD,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAE5C,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,gBAAgB;CAC1B,CAAC,CAAC;AAEH,IAAI,kBAAyB,CAAC;AAC9B,MAAM,cAAc,GAAG,QAAQ,IAAI,UAAU,CAAC;AAE9C,MAAM,uBAAuB,GAAsC,EAAE,CAAC;AAEtE,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,WAAmB,EACnB,WAAyB,EACzB,kBAA4C,EAAC,QAAQ,EAAE,SAAS,EAAC;IAEnE,MAA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;aACtC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACjC,OAAO,CAAC,GAAG,EAAE;YACZ,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,sCAAsC;YAC7D,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {createLogger, globalAlwatr, NODE_MODE} from '@alwatr/logger';\nimport {contextProvider, type DispatchOptions} from '@alwatr/signal';\nimport {getClientId, delay} from '@alwatr/util';\n\nimport type {FetchOptions} from './type.js';\nimport type {AlwatrServiceResponse} from '@alwatr/type';\n\nexport type * from './type.js';\n\nconst logger = createLogger('alwatr/fetch');\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/fetch',\n version: _ALWATR_VERSION_,\n});\n\nlet alwatrCacheStorage: Cache;\nconst cacheSupported = 'caches' in globalThis;\n\nconst duplicateRequestStorage: Record<string, Promise<Response>> = {};\n\nexport async function fetchContext(\n contextName: string,\n fetchOption: FetchOptions,\n dispatchOptions: Partial<DispatchOptions> = {debounce: 'Timeout'},\n): Promise<void> {\n logger.logMethodArgs?.('fetchContext', {contextName});\n if (cacheSupported && contextProvider.getValue(contextName) == null) {\n try {\n fetchOption.cacheStrategy = 'cache_only';\n const response = await serviceRequest(fetchOption);\n contextProvider.setValue<typeof response>(contextName, response, dispatchOptions);\n if (navigator.onLine === false) {\n logger.logOther?.('fetchContext:', 'offline');\n // retry on online\n return;\n }\n }\n catch (err) {\n if ((err as Error).message === 'fetch_cache_not_found') {\n logger.logOther?.('fetchContext:', 'fetch_cache_not_found');\n }\n else {\n logger.error('fetchContext', 'fetch_failed', err);\n throw err;\n }\n }\n }\n\n try {\n fetchOption.cacheStrategy = 'update_cache';\n const response = await serviceRequest(fetchOption);\n if (\n response.meta?.lastUpdated === undefined || // skip lastUpdated check\n response.meta?.lastUpdated !== contextProvider.getValue<typeof response>(contextName)?.meta?.lastUpdated\n ) {\n logger.logOther?.('fetchContext:', 'contextProvider.setValue(new-received-context)', {contextName});\n contextProvider.setValue<typeof response>(contextName, response, dispatchOptions);\n }\n }\n catch (err) {\n logger.error('fetchContext', 'fetch_failed', err);\n throw err;\n }\n}\n\n/**\n * Fetch from alwatr services and return standard response.\n */\nexport async function serviceRequest<T extends AlwatrServiceResponse = AlwatrServiceResponse>(\n options: FetchOptions,\n): Promise<T> {\n logger.logMethodArgs?.('serviceRequest', {url: options.url});\n\n if (!NODE_MODE) {\n options.headers ??= {};\n if (!options.headers['client-id']) {\n options.headers['client-id'] = getClientId();\n }\n }\n\n let response: Response;\n try {\n response = await fetch(options);\n }\n catch (err) {\n const errMessage = (err as Error).message;\n if (errMessage !== 'fetch_cache_not_found') {\n logger.error('serviceRequest', (err as Error).message || 'fetch_failed', err, options);\n }\n throw err;\n }\n\n let responseText: string;\n try {\n responseText = await response.text();\n }\n catch (err) {\n logger.error('serviceRequest', 'invalid_response', err, {\n response,\n });\n throw err;\n }\n\n let responseJson: T;\n try {\n responseJson = JSON.parse(responseText);\n }\n catch (err) {\n logger.error('serviceRequest', 'invalid_json', err, {responseText});\n throw err;\n }\n\n if (responseJson.ok !== true) {\n if (typeof responseJson.errorCode === 'string') {\n logger.accident('serviceRequest', responseJson.errorCode, 'fetch response not ok', {responseJson});\n throw new Error(responseJson.errorCode);\n }\n else {\n logger.error('serviceRequest', 'fetch_nok', 'fetch response not ok', {responseJson});\n throw new Error('fetch_nok');\n }\n }\n\n // TODO: generate fetch signals hook (for easier handle loading and show error toast)\n\n return responseJson;\n}\n\n/**\n * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy,\n * remove duplicates, etc.\n *\n * Example:\n *\n * ```ts\n * const response = await fetch({\n * url: '/api/products',\n * queryParameters: {limit: 10},\n * timeout: 10_000,\n * retry: 3,\n * cacheStrategy: 'stale_while_revalidate',\n * cacheDuplicate: 'auto',\n * });\n * ```\n */\nexport function fetch(options: FetchOptions): Promise<Response> {\n options = _processOptions(options);\n logger.logMethodArgs?.('fetch', {options});\n return _handleCacheStrategy(options as Required<FetchOptions>);\n}\n\n/**\n * Process fetch options and set defaults, etc.\n */\nfunction _processOptions(options: FetchOptions): Required<FetchOptions> {\n options.method ??= 'GET';\n options.window ??= null;\n\n options.timeout ??= 10_000;\n options.retry ??= 3;\n options.retryDelay ??= 1_000;\n options.cacheStrategy ??= 'network_only';\n options.removeDuplicate ??= 'never';\n options.headers ??= {};\n\n if (options.cacheStrategy !== 'network_only' && cacheSupported !== true) {\n logger.incident?.('fetch', 'fetch_cache_strategy_ignore', 'Cache storage not support in this browser', {\n cacheSupported,\n });\n options.cacheStrategy = 'network_only';\n }\n\n if (options.removeDuplicate === 'auto') {\n options.removeDuplicate = cacheSupported ? 'until_load' : 'always';\n }\n\n if (options.url.lastIndexOf('?') === -1 && options.queryParameters != null) {\n const queryParameters = options.queryParameters;\n // prettier-ignore\n const queryArray = Object\n .keys(queryParameters)\n .map((key) => `${key}=${String(queryParameters[key])}`);\n\n if (queryArray.length > 0) {\n options.url += '?' + queryArray.join('&');\n }\n }\n\n if (options.bodyJson != null) {\n options.body = JSON.stringify(options.bodyJson);\n options.headers['Content-Type'] = 'application/json';\n }\n\n if (options.token != null) {\n options.headers.Authorization = `Bearer ${options.token}`;\n }\n\n if (options.userAuth != null) {\n options.headers.Authorization = `Bearer ${options.userAuth.id}/${options.userAuth.token}`;\n }\n\n return options as Required<FetchOptions>;\n}\n\n/**\n * Handle Cache Strategy over `_handleRemoveDuplicate`.\n */\nasync function _handleCacheStrategy(options: Required<FetchOptions>): Promise<Response> {\n if (options.cacheStrategy === 'network_only') {\n return _handleRemoveDuplicate(options);\n }\n // else handle cache strategies!\n logger.logMethod?.('_handleCacheStrategy');\n\n if (alwatrCacheStorage == null && options.cacheStorageName == null) {\n alwatrCacheStorage = await caches.open('alwatr_fetch_cache');\n }\n\n const cacheStorage =\n options.cacheStorageName != null ? await caches.open(options.cacheStorageName) : alwatrCacheStorage;\n\n const request = new Request(options.url, options);\n\n switch (options.cacheStrategy) {\n case 'cache_first': {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse != null) {\n return cachedResponse;\n }\n // else\n const response = await _handleRemoveDuplicate(options);\n if (response.ok) {\n cacheStorage.put(request, response.clone());\n }\n return response;\n }\n\n case 'cache_only': {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse == null) {\n logger.accident(\n '_handleCacheStrategy',\n 'fetch_cache_not_found',\n 'cacheStorage is cache_only but no cache found',\n {url: request.url},\n );\n throw new Error('fetch_cache_not_found');\n }\n // else\n return cachedResponse;\n }\n\n case 'network_first': {\n try {\n const networkResponse = await _handleRemoveDuplicate(options);\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n }\n return networkResponse;\n }\n catch (err) {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse != null) {\n return cachedResponse;\n }\n // else\n throw err;\n }\n }\n\n case 'update_cache': {\n const networkResponse = await _handleRemoveDuplicate(options);\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n }\n return networkResponse;\n }\n\n case 'stale_while_revalidate': {\n const cachedResponse = await cacheStorage.match(request);\n const fetchedResponsePromise = _handleRemoveDuplicate(options).then((networkResponse) => {\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n if (typeof options.revalidateCallback === 'function') {\n setTimeout(options.revalidateCallback, 0, networkResponse.clone());\n }\n }\n return networkResponse;\n });\n\n return cachedResponse ?? fetchedResponsePromise;\n }\n\n default: {\n return _handleRemoveDuplicate(options);\n }\n }\n}\n\n/**\n * Handle Remove Duplicates over `_handleRetryPattern`.\n */\nasync function _handleRemoveDuplicate(options: Required<FetchOptions>): Promise<Response> {\n if (options.removeDuplicate === 'never') return _handleRetryPattern(options);\n\n logger.logMethod?.('_handleRemoveDuplicate');\n\n const cacheKey = options.method + ' ' + options.url;\n\n // We must cache fetch promise without await for handle other parallel requests.\n duplicateRequestStorage[cacheKey] ??= _handleRetryPattern(options);\n\n try {\n // For all requests need to await for clone responses.\n const response = await duplicateRequestStorage[cacheKey];\n\n if (duplicateRequestStorage[cacheKey] != null) {\n if (response.ok !== true || options.removeDuplicate === 'until_load') {\n delete duplicateRequestStorage[cacheKey];\n }\n }\n\n return response.clone();\n }\n catch (err) {\n // clean cache on any error.\n delete duplicateRequestStorage[cacheKey];\n throw err;\n }\n}\n\n/**\n * Handle retry pattern over `_handleTimeout`.\n */\nasync function _handleRetryPattern(options: Required<FetchOptions>): Promise<Response> {\n if (!(options.retry > 1)) return _handleTimeout(options);\n\n logger.logMethod?.('_handleRetryPattern');\n options.retry--;\n\n const externalAbortSignal = options.signal;\n\n try {\n const response = await _handleTimeout(options);\n\n if (response.status < 500) {\n return response;\n }\n // else\n throw new Error('fetch_server_error');\n }\n catch (err) {\n logger.accident('fetch', 'fetch_failed_retry', (err as Error)?.message || 'fetch failed and retry', err);\n\n if (globalThis.navigator?.onLine === false) {\n throw new Error('offline');\n }\n\n await delay(options.retryDelay);\n\n options.signal = externalAbortSignal;\n return _handleRetryPattern(options);\n }\n}\n\n/**\n * It's a wrapper around the browser's `fetch` with timeout.\n */\nfunction _handleTimeout(options: FetchOptions): Promise<Response> {\n if (options.timeout === 0) {\n return globalThis.fetch(options.url, options);\n }\n // else\n logger.logMethod?.('_handleTimeout');\n return new Promise((resolved, reject) => {\n // TODO: AbortController polyfill\n const abortController = new AbortController();\n const externalAbortSignal = options.signal;\n options.signal = abortController.signal;\n\n const timeoutId = setTimeout(() => {\n reject(new Error('fetch_timeout'));\n abortController.abort('fetch_timeout');\n }, options.timeout);\n\n if (externalAbortSignal != null) {\n // Respect external abort signal\n externalAbortSignal.addEventListener('abort', () => abortController.abort(), {once: true});\n }\n\n // abortController.signal.addEventListener('abort', () => {\n // logger.incident('fetch', 'fetch_abort_signal', 'fetch abort signal received', {\n // reason: abortController.signal.reason,\n // });\n // });\n\n globalThis\n .fetch(options.url, options)\n .then((response) => resolved(response))\n .catch((reason) => reject(reason))\n .finally(() => {\n delete options.signal; // try to avoid memory leak in nodejs!\n clearTimeout(timeoutId);\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAC,WAAW,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AAOhD,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAE5C,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,gBAAgB;CAC1B,CAAC,CAAC;AAEH,IAAI,kBAAyB,CAAC;AAC9B,MAAM,cAAc,GAAG,QAAQ,IAAI,UAAU,CAAC;AAE9C,MAAM,uBAAuB,GAAsC,EAAE,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAChC,OAAqB;IAEvB,MAAM,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE,EAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAC,CAAC,CAAC;IAE7D,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,CAAC,OAAO,KAAf,OAAO,CAAC,OAAO,GAAK,EAAE,EAAC;QACvB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACjC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,EAAE,CAAC;SAC9C;KACF;IAED,IAAI,QAAkB,CAAC;IACvB,IAAI;QACF,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;KACjC;IACD,OAAO,GAAG,EAAE;QACV,MAAM,UAAU,GAAI,GAAa,CAAC,OAAO,CAAC;QAC1C,IAAI,UAAU,KAAK,uBAAuB,EAAE;YAC1C,MAAM,CAAC,KAAK,CAA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CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB,IAAI,mBAAmB,IAAI,IAAI,EAAE;YAC/B,gCAAgC;YAChC,mBAAmB,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;SAC5F;QAED,2DAA2D;QAC3D,oFAAoF;QACpF,6CAA6C;QAC7C,QAAQ;QACR,MAAM;QAEN,UAAU;aACL,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;aAC3B,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACtC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACjC,OAAO,CAAC,GAAG,EAAE;YACZ,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,sCAAsC;YAC7D,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {createLogger, globalAlwatr, NODE_MODE} from '@alwatr/logger';\nimport {getClientId, delay} from '@alwatr/util';\n\nimport type {FetchOptions} from './type.js';\nimport type {AlwatrServiceResponse} from '@alwatr/type';\n\nexport type * from './type.js';\n\nconst logger = createLogger('alwatr/fetch');\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/fetch',\n version: _ALWATR_VERSION_,\n});\n\nlet alwatrCacheStorage: Cache;\nconst cacheSupported = 'caches' in globalThis;\n\nconst duplicateRequestStorage: Record<string, Promise<Response>> = {};\n\n/**\n * Fetch from alwatr services and return standard response.\n */\nexport async function serviceRequest<T extends AlwatrServiceResponse = AlwatrServiceResponse>(\n options: FetchOptions,\n): Promise<T> {\n logger.logMethodArgs?.('serviceRequest', {url: options.url});\n\n if (!NODE_MODE) {\n options.headers ??= {};\n if (!options.headers['client-id']) {\n options.headers['client-id'] = getClientId();\n }\n }\n\n let response: Response;\n try {\n response = await fetch(options);\n }\n catch (err) {\n const errMessage = (err as Error).message;\n if (errMessage !== 'fetch_cache_not_found') {\n logger.error('serviceRequest', (err as Error).message || 'fetch_failed', err, options);\n }\n throw err;\n }\n\n let responseText: string;\n try {\n responseText = await response.text();\n }\n catch (err) {\n logger.error('serviceRequest', 'invalid_response', err, {\n response,\n });\n throw err;\n }\n\n let responseJson: T;\n try {\n responseJson = JSON.parse(responseText);\n }\n catch (err) {\n logger.error('serviceRequest', 'invalid_json', err, {responseText});\n throw err;\n }\n\n if (responseJson.ok !== true) {\n if (typeof responseJson.errorCode === 'string') {\n logger.accident('serviceRequest', responseJson.errorCode, 'fetch response not ok', {responseJson});\n throw new Error(responseJson.errorCode);\n }\n else {\n logger.error('serviceRequest', 'fetch_nok', 'fetch response not ok', {responseJson});\n throw new Error('fetch_nok');\n }\n }\n\n // TODO: generate fetch signals hook (for easier handle loading and show error toast)\n\n return responseJson;\n}\n\n/**\n * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy,\n * remove duplicates, etc.\n *\n * Example:\n *\n * ```ts\n * const response = await fetch({\n * url: '/api/products',\n * queryParameters: {limit: 10},\n * timeout: 10_000,\n * retry: 3,\n * cacheStrategy: 'stale_while_revalidate',\n * cacheDuplicate: 'auto',\n * });\n * ```\n */\nexport function fetch(options: FetchOptions): Promise<Response> {\n options = _processOptions(options);\n logger.logMethodArgs?.('fetch', {options});\n return _handleCacheStrategy(options as Required<FetchOptions>);\n}\n\n/**\n * Process fetch options and set defaults, etc.\n */\nfunction _processOptions(options: FetchOptions): Required<FetchOptions> {\n options.method ??= 'GET';\n options.window ??= null;\n\n options.timeout ??= 10_000;\n options.retry ??= 3;\n options.retryDelay ??= 1_000;\n options.cacheStrategy ??= 'network_only';\n options.removeDuplicate ??= 'never';\n options.headers ??= {};\n\n if (options.cacheStrategy !== 'network_only' && cacheSupported !== true) {\n logger.incident?.('fetch', 'fetch_cache_strategy_ignore', 'Cache storage not support in this browser', {\n cacheSupported,\n });\n options.cacheStrategy = 'network_only';\n }\n\n if (options.removeDuplicate === 'auto') {\n options.removeDuplicate = cacheSupported ? 'until_load' : 'always';\n }\n\n if (options.url.lastIndexOf('?') === -1 && options.queryParameters != null) {\n const queryParameters = options.queryParameters;\n // prettier-ignore\n const queryArray = Object\n .keys(queryParameters)\n .map((key) => `${key}=${String(queryParameters[key])}`);\n\n if (queryArray.length > 0) {\n options.url += '?' + queryArray.join('&');\n }\n }\n\n if (options.bodyJson != null) {\n options.body = JSON.stringify(options.bodyJson);\n options.headers['Content-Type'] = 'application/json';\n }\n\n if (options.token != null) {\n options.headers.Authorization = `Bearer ${options.token}`;\n }\n\n if (options.userAuth != null) {\n options.headers.Authorization = `Bearer ${options.userAuth.id}/${options.userAuth.token}`;\n }\n\n return options as Required<FetchOptions>;\n}\n\n/**\n * Handle Cache Strategy over `_handleRemoveDuplicate`.\n */\nasync function _handleCacheStrategy(options: Required<FetchOptions>): Promise<Response> {\n if (options.cacheStrategy === 'network_only') {\n return _handleRemoveDuplicate(options);\n }\n // else handle cache strategies!\n logger.logMethod?.('_handleCacheStrategy');\n\n if (alwatrCacheStorage == null && options.cacheStorageName == null) {\n alwatrCacheStorage = await caches.open('alwatr_fetch_cache');\n }\n\n const cacheStorage =\n options.cacheStorageName != null ? await caches.open(options.cacheStorageName) : alwatrCacheStorage;\n\n const request = new Request(options.url, options);\n\n switch (options.cacheStrategy) {\n case 'cache_first': {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse != null) {\n return cachedResponse;\n }\n // else\n const response = await _handleRemoveDuplicate(options);\n if (response.ok) {\n cacheStorage.put(request, response.clone());\n }\n return response;\n }\n\n case 'cache_only': {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse == null) {\n logger.accident(\n '_handleCacheStrategy',\n 'fetch_cache_not_found',\n 'cacheStorage is cache_only but no cache found',\n {url: request.url},\n );\n throw new Error('fetch_cache_not_found');\n }\n // else\n return cachedResponse;\n }\n\n case 'network_first': {\n try {\n const networkResponse = await _handleRemoveDuplicate(options);\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n }\n return networkResponse;\n }\n catch (err) {\n const cachedResponse = await cacheStorage.match(request);\n if (cachedResponse != null) {\n return cachedResponse;\n }\n // else\n throw err;\n }\n }\n\n case 'update_cache': {\n const networkResponse = await _handleRemoveDuplicate(options);\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n }\n return networkResponse;\n }\n\n case 'stale_while_revalidate': {\n const cachedResponse = await cacheStorage.match(request);\n const fetchedResponsePromise = _handleRemoveDuplicate(options).then((networkResponse) => {\n if (networkResponse.ok) {\n cacheStorage.put(request, networkResponse.clone());\n if (typeof options.revalidateCallback === 'function') {\n setTimeout(options.revalidateCallback, 0, networkResponse.clone());\n }\n }\n return networkResponse;\n });\n\n return cachedResponse ?? fetchedResponsePromise;\n }\n\n default: {\n return _handleRemoveDuplicate(options);\n }\n }\n}\n\n/**\n * Handle Remove Duplicates over `_handleRetryPattern`.\n */\nasync function _handleRemoveDuplicate(options: Required<FetchOptions>): Promise<Response> {\n if (options.removeDuplicate === 'never') return _handleRetryPattern(options);\n\n logger.logMethod?.('_handleRemoveDuplicate');\n\n const cacheKey = options.method + ' ' + options.url;\n\n // We must cache fetch promise without await for handle other parallel requests.\n duplicateRequestStorage[cacheKey] ??= _handleRetryPattern(options);\n\n try {\n // For all requests need to await for clone responses.\n const response = await duplicateRequestStorage[cacheKey];\n\n if (duplicateRequestStorage[cacheKey] != null) {\n if (response.ok !== true || options.removeDuplicate === 'until_load') {\n delete duplicateRequestStorage[cacheKey];\n }\n }\n\n return response.clone();\n }\n catch (err) {\n // clean cache on any error.\n delete duplicateRequestStorage[cacheKey];\n throw err;\n }\n}\n\n/**\n * Handle retry pattern over `_handleTimeout`.\n */\nasync function _handleRetryPattern(options: Required<FetchOptions>): Promise<Response> {\n if (!(options.retry > 1)) return _handleTimeout(options);\n\n logger.logMethod?.('_handleRetryPattern');\n options.retry--;\n\n const externalAbortSignal = options.signal;\n\n try {\n const response = await _handleTimeout(options);\n\n if (response.status < 500) {\n return response;\n }\n // else\n throw new Error('fetch_server_error');\n }\n catch (err) {\n logger.accident('fetch', 'fetch_failed_retry', (err as Error)?.message || 'fetch failed and retry', err);\n\n if (globalThis.navigator?.onLine === false) {\n throw new Error('offline');\n }\n\n await delay(options.retryDelay);\n\n options.signal = externalAbortSignal;\n return _handleRetryPattern(options);\n }\n}\n\n/**\n * It's a wrapper around the browser's `fetch` with timeout.\n */\nfunction _handleTimeout(options: FetchOptions): Promise<Response> {\n if (options.timeout === 0) {\n return globalThis.fetch(options.url, options);\n }\n // else\n logger.logMethod?.('_handleTimeout');\n return new Promise((resolved, reject) => {\n // TODO: AbortController polyfill\n const abortController = new AbortController();\n const externalAbortSignal = options.signal;\n options.signal = abortController.signal;\n\n const timeoutId = setTimeout(() => {\n reject(new Error('fetch_timeout'));\n abortController.abort('fetch_timeout');\n }, options.timeout);\n\n if (externalAbortSignal != null) {\n // Respect external abort signal\n externalAbortSignal.addEventListener('abort', () => abortController.abort(), {once: true});\n }\n\n // abortController.signal.addEventListener('abort', () => {\n // logger.incident('fetch', 'fetch_abort_signal', 'fetch abort signal received', {\n // reason: abortController.signal.reason,\n // });\n // });\n\n globalThis\n .fetch(options.url, options)\n .then((response) => resolved(response))\n .catch((reason) => reject(reason))\n .finally(() => {\n delete options.signal; // try to avoid memory leak in nodejs!\n clearTimeout(timeoutId);\n });\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/fetch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Enhanced fetch API with cache strategy, retry pattern, timeout, helper methods and enhanced types written in tiny TypeScript, ES module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -26,18 +26,17 @@
|
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/AliMD/alwatr",
|
|
30
|
-
"directory": "
|
|
29
|
+
"url": "https://github.com/AliMD/alwatr-eslib",
|
|
30
|
+
"directory": "packages/fetch"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/AliMD/alwatr/tree/
|
|
32
|
+
"homepage": "https://github.com/AliMD/alwatr-eslib/tree/next/packages/fetch#readme",
|
|
33
33
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/AliMD/alwatr/issues"
|
|
34
|
+
"url": "https://github.com/AliMD/alwatr-eslib/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@alwatr/logger": "^1.1.
|
|
38
|
-
"@alwatr/
|
|
39
|
-
"@alwatr/util": "^1.2.1",
|
|
37
|
+
"@alwatr/logger": "^1.1.5",
|
|
38
|
+
"@alwatr/util": "^1.2.3",
|
|
40
39
|
"tslib": "^2.6.2"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f223974f90666c18eab94dfefcc6b01d7c9e8f63"
|
|
43
42
|
}
|