@podium/client 5.0.0-next.9 → 5.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 +252 -0
- package/README.md +31 -9
- package/client.d.ts +140 -0
- package/lib/http-outgoing.js +16 -0
- package/lib/http.js +23 -0
- package/lib/resolver.content.js +213 -203
- package/lib/resolver.fallback.js +90 -100
- package/lib/resolver.js +5 -3
- package/lib/resolver.manifest.js +164 -137
- package/lib/resource.js +9 -16
- package/lib/response.js +5 -9
- package/lib/utils.js +40 -0
- package/package.json +24 -21
- package/index.d.ts +0 -63
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,253 @@
|
|
|
1
|
+
## [5.0.1](https://github.com/podium-lib/client/compare/v5.0.0...v5.0.1) (2023-11-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* set correct types file ([6d08e50](https://github.com/podium-lib/client/commit/6d08e501728745e180c7a5d436f238c468dec136))
|
|
7
|
+
|
|
8
|
+
# [5.0.0](https://github.com/podium-lib/client/compare/v4.6.1...v5.0.0) (2023-11-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency readable-stream to v4 ([d3aff96](https://github.com/podium-lib/client/commit/d3aff9608ebfefc294ab0b79563a96670019311f))
|
|
14
|
+
* **deps:** update dependency readable-stream to v4 ([9c7303a](https://github.com/podium-lib/client/commit/9c7303aea267f951a8359f3d0640588d8d82b21a))
|
|
15
|
+
* Fix inspect method on response object ([#294](https://github.com/podium-lib/client/issues/294)) ([94d1485](https://github.com/podium-lib/client/commit/94d14856ca2280888aa50e9cb7e7f782cd49666a))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* Convert to ESM ([#206](https://github.com/podium-lib/client/issues/206)) ([d31298f](https://github.com/podium-lib/client/commit/d31298fac7e1b84dc401c5832bce132a68a84943))
|
|
21
|
+
* Drop node 10.x support ([a71c3b0](https://github.com/podium-lib/client/commit/a71c3b08198f9a20de5e6af042d5a78f85c33c4f))
|
|
22
|
+
* Make HttpIncoming required first argument to .fetch() and .stream() ([9b80ee7](https://github.com/podium-lib/client/commit/9b80ee715397e780d2df267483b6bc2db32b1c62))
|
|
23
|
+
* Remove .js() and .css() methods ([#128](https://github.com/podium-lib/client/issues/128)) ([db6d306](https://github.com/podium-lib/client/commit/db6d30617160db76d85e8839c7f896ef3dc97b41))
|
|
24
|
+
* Remove deprecated 'change' and 'dispose' events ([#129](https://github.com/podium-lib/client/issues/129)) ([449fff1](https://github.com/podium-lib/client/commit/449fff13323d4f7f76fd406dbee1f2532701916b))
|
|
25
|
+
* replace request with undici for http requests ([31163db](https://github.com/podium-lib/client/commit/31163db538d87cb797135d7febcc6cc244eac17a))
|
|
26
|
+
* Support new proxy structure in manifest ([#295](https://github.com/podium-lib/client/issues/295)) ([d8aa28a](https://github.com/podium-lib/client/commit/d8aa28a59c8ab3fe66b146eecaaf487717599972))
|
|
27
|
+
* Use ES private properties instead of Symbols and defineProperty for privacy ([#131](https://github.com/podium-lib/client/issues/131)) ([2787a6c](https://github.com/podium-lib/client/commit/2787a6c406f9fb2bb2e85583082b818c2c247b63))
|
|
28
|
+
* Use native streams ([#215](https://github.com/podium-lib/client/issues/215)) ([f949c9c](https://github.com/podium-lib/client/commit/f949c9cc0d66431685138ca2c0367aec622bce78))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### BREAKING CHANGES
|
|
32
|
+
|
|
33
|
+
* Convert from CommonJS to ESM
|
|
34
|
+
|
|
35
|
+
* fix: Remove outcommented code
|
|
36
|
+
|
|
37
|
+
Co-authored-by: Trygve Lie <trygve.lie@finn.no>
|
|
38
|
+
* Due to dropping node 10.x support we use ES private properties instead of Symbols and `.defineProperty()`.
|
|
39
|
+
|
|
40
|
+
We've been using Symbols and `.defineProperty()` to define private properties in classes up until now. This has the downside that they are not true private and in later versions of node.js one would see these Symbols when inspecting an object. What we want is proper private properties.
|
|
41
|
+
|
|
42
|
+
This PR does also add a pretty printer which outputs an object literal or the object so when debugging one can see the getters and setters of the object.
|
|
43
|
+
|
|
44
|
+
Example: printing a object with `console.log()` would previously print the following:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
PodiumClientResponse {
|
|
48
|
+
[Symbol(podium:client:response:redirect)]: '',
|
|
49
|
+
[Symbol(podium:client:response:content)]: '',
|
|
50
|
+
[Symbol(podium:client:response:headers)]: {},
|
|
51
|
+
[Symbol(podium:client:response:css)]: [],
|
|
52
|
+
[Symbol(podium:client:response:js)]: []
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Now the following will be printed:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
{
|
|
60
|
+
redirect: '',
|
|
61
|
+
content: '',
|
|
62
|
+
headers: {},
|
|
63
|
+
css: [],
|
|
64
|
+
js: []
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Co-authored-by: Trygve Lie <trygve.lie@finn.no>
|
|
69
|
+
* This removes the deprecated `change` and `dispose` events.
|
|
70
|
+
|
|
71
|
+
Resolves: https://github.com/podium-lib/issues/issues/24
|
|
72
|
+
|
|
73
|
+
* chore: lint love
|
|
74
|
+
|
|
75
|
+
Co-authored-by: Trygve Lie <trygve.lie@finn.no>
|
|
76
|
+
* Remove .js() and .css() methods to retrieve fetched js and css for all podlets. Also removes the `resolveJs` and `resolveCss` arguments when registering a podlet.
|
|
77
|
+
|
|
78
|
+
Resolves: https://github.com/podium-lib/issues/issues/25
|
|
79
|
+
|
|
80
|
+
Co-authored-by: Trygve Lie <trygve.lie@finn.no>
|
|
81
|
+
* Only support node 12 and 14.
|
|
82
|
+
* `HttpIncoming` must now be passed as the first argument to .fetch() and .stream()
|
|
83
|
+
|
|
84
|
+
# [5.0.0-next.15](https://github.com/podium-lib/client/compare/v5.0.0-next.14...v5.0.0-next.15) (2023-11-28)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Bug Fixes
|
|
88
|
+
|
|
89
|
+
* **deps:** update dependency readable-stream to v4 ([d3aff96](https://github.com/podium-lib/client/commit/d3aff9608ebfefc294ab0b79563a96670019311f))
|
|
90
|
+
* **deps:** update dependency readable-stream to v4 ([9c7303a](https://github.com/podium-lib/client/commit/9c7303aea267f951a8359f3d0640588d8d82b21a))
|
|
91
|
+
|
|
92
|
+
# [5.0.0-next.14](https://github.com/podium-lib/client/compare/v5.0.0-next.13...v5.0.0-next.14) (2023-11-28)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Bug Fixes
|
|
96
|
+
|
|
97
|
+
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07))
|
|
98
|
+
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43))
|
|
99
|
+
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73))
|
|
100
|
+
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838))
|
|
101
|
+
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af))
|
|
102
|
+
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc))
|
|
103
|
+
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900))
|
|
104
|
+
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57))
|
|
105
|
+
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb))
|
|
106
|
+
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd))
|
|
107
|
+
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099))
|
|
108
|
+
* Set log level for network errors to debug when throwable ([#298](https://github.com/podium-lib/client/issues/298)) ([3ba5d67](https://github.com/podium-lib/client/commit/3ba5d67192f417b4627d9f411a1fe4ffd2c98775))
|
|
109
|
+
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
### Features
|
|
113
|
+
|
|
114
|
+
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5))
|
|
115
|
+
|
|
116
|
+
## [4.6.1](https://github.com/podium-lib/client/compare/v4.6.0...v4.6.1) (2023-11-20)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### Bug Fixes
|
|
120
|
+
|
|
121
|
+
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb))
|
|
122
|
+
|
|
123
|
+
# [4.6.0](https://github.com/podium-lib/client/compare/v4.5.35...v4.6.0) (2023-11-16)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
### Features
|
|
127
|
+
|
|
128
|
+
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5))
|
|
129
|
+
|
|
130
|
+
## [4.5.35](https://github.com/podium-lib/client/compare/v4.5.34...v4.5.35) (2023-10-19)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### Bug Fixes
|
|
134
|
+
|
|
135
|
+
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57))
|
|
136
|
+
|
|
137
|
+
## [4.5.34](https://github.com/podium-lib/client/compare/v4.5.33...v4.5.34) (2023-10-09)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
### Bug Fixes
|
|
141
|
+
|
|
142
|
+
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146))
|
|
143
|
+
|
|
144
|
+
## [4.5.33](https://github.com/podium-lib/client/compare/v4.5.32...v4.5.33) (2023-09-19)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### Bug Fixes
|
|
148
|
+
|
|
149
|
+
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43))
|
|
150
|
+
|
|
151
|
+
## [4.5.32](https://github.com/podium-lib/client/compare/v4.5.31...v4.5.32) (2023-09-14)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### Bug Fixes
|
|
155
|
+
|
|
156
|
+
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07))
|
|
157
|
+
|
|
158
|
+
## [4.5.31](https://github.com/podium-lib/client/compare/v4.5.30...v4.5.31) (2023-05-11)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
### Bug Fixes
|
|
162
|
+
|
|
163
|
+
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd))
|
|
164
|
+
|
|
165
|
+
## [4.5.30](https://github.com/podium-lib/client/compare/v4.5.29...v4.5.30) (2023-02-15)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
### Bug Fixes
|
|
169
|
+
|
|
170
|
+
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099))
|
|
171
|
+
|
|
172
|
+
## [4.5.29](https://github.com/podium-lib/client/compare/v4.5.28...v4.5.29) (2023-01-04)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### Bug Fixes
|
|
176
|
+
|
|
177
|
+
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900))
|
|
178
|
+
|
|
179
|
+
## [4.5.28](https://github.com/podium-lib/client/compare/v4.5.27...v4.5.28) (2023-01-04)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
### Bug Fixes
|
|
183
|
+
|
|
184
|
+
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838))
|
|
185
|
+
|
|
186
|
+
## [4.5.27](https://github.com/podium-lib/client/compare/v4.5.26...v4.5.27) (2022-12-07)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
### Bug Fixes
|
|
190
|
+
|
|
191
|
+
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc))
|
|
192
|
+
|
|
193
|
+
## [4.5.26](https://github.com/podium-lib/client/compare/v4.5.25...v4.5.26) (2022-11-14)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### Bug Fixes
|
|
197
|
+
|
|
198
|
+
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af))
|
|
199
|
+
|
|
200
|
+
## [4.5.25](https://github.com/podium-lib/client/compare/v4.5.24...v4.5.25) (2022-11-14)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
### Bug Fixes
|
|
204
|
+
|
|
205
|
+
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73))
|
|
206
|
+
|
|
207
|
+
## [4.5.24](https://github.com/podium-lib/client/compare/v4.5.23...v4.5.24) (2022-10-18)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
### Bug Fixes
|
|
211
|
+
|
|
212
|
+
* Set log level for network errors to debug when throwable ([#298](https://github.com/podium-lib/client/issues/298)) ([3ba5d67](https://github.com/podium-lib/client/commit/3ba5d67192f417b4627d9f411a1fe4ffd2c98775))
|
|
213
|
+
|
|
214
|
+
## [4.5.23](https://github.com/podium-lib/client/compare/v4.5.22...v4.5.23) (2022-09-01)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
### Bug Fixes
|
|
218
|
+
|
|
219
|
+
* Lower log level when throwable is true ([#291](https://github.com/podium-lib/client/issues/291)) ([c0d779b](https://github.com/podium-lib/client/commit/c0d779b3e22b671e5f7c6496c504b38cd9da5125))
|
|
220
|
+
|
|
221
|
+
# [5.0.0-next.13](https://github.com/podium-lib/client/compare/v5.0.0-next.12...v5.0.0-next.13) (2022-09-21)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
### Features
|
|
225
|
+
|
|
226
|
+
* Support new proxy structure in manifest ([#295](https://github.com/podium-lib/client/issues/295)) ([d8aa28a](https://github.com/podium-lib/client/commit/d8aa28a59c8ab3fe66b146eecaaf487717599972))
|
|
227
|
+
|
|
228
|
+
# [5.0.0-next.12](https://github.com/podium-lib/client/compare/v5.0.0-next.11...v5.0.0-next.12) (2022-09-20)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
### Features
|
|
232
|
+
|
|
233
|
+
* replace request with undici for http requests ([31163db](https://github.com/podium-lib/client/commit/31163db538d87cb797135d7febcc6cc244eac17a))
|
|
234
|
+
|
|
235
|
+
# [5.0.0-next.11](https://github.com/podium-lib/client/compare/v5.0.0-next.10...v5.0.0-next.11) (2022-09-08)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
### Bug Fixes
|
|
239
|
+
|
|
240
|
+
* Fix inspect method on response object ([#294](https://github.com/podium-lib/client/issues/294)) ([94d1485](https://github.com/podium-lib/client/commit/94d14856ca2280888aa50e9cb7e7f782cd49666a))
|
|
241
|
+
|
|
242
|
+
# [5.0.0-next.10](https://github.com/podium-lib/client/compare/v5.0.0-next.9...v5.0.0-next.10) (2022-09-07)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
### Bug Fixes
|
|
246
|
+
|
|
247
|
+
* Lower log level when throwable is true ([#291](https://github.com/podium-lib/client/issues/291)) ([c0d779b](https://github.com/podium-lib/client/commit/c0d779b3e22b671e5f7c6496c504b38cd9da5125))
|
|
248
|
+
|
|
1
249
|
# [5.0.0-next.9](https://github.com/podium-lib/client/compare/v5.0.0-next.8...v5.0.0-next.9) (2022-05-09)
|
|
250
|
+
## [4.5.23](https://github.com/podium-lib/client/compare/v4.5.22...v4.5.23) (2022-09-01)
|
|
2
251
|
|
|
3
252
|
|
|
4
253
|
### Bug Fixes
|
|
@@ -46,6 +295,9 @@
|
|
|
46
295
|
* Support mixed protocols ([#228](https://github.com/podium-lib/client/issues/228)) ([f1e42fe](https://github.com/podium-lib/client/commit/f1e42feb298e755b1274e5cf79cf77243457c538))
|
|
47
296
|
|
|
48
297
|
# [5.0.0-next.8](https://github.com/podium-lib/client/compare/v5.0.0-next.7...v5.0.0-next.8) (2021-05-17)
|
|
298
|
+
|
|
299
|
+
* Lower log level when throwable is true ([#291](https://github.com/podium-lib/client/issues/291)) ([c0d779b](https://github.com/podium-lib/client/commit/c0d779b3e22b671e5f7c6496c504b38cd9da5125))
|
|
300
|
+
|
|
49
301
|
## [4.5.22](https://github.com/podium-lib/client/compare/v4.5.21...v4.5.22) (2022-03-23)
|
|
50
302
|
|
|
51
303
|
|
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ const component = client.register({
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
const stream = component.stream(new HttpIncoming());
|
|
34
|
-
stream.once('beforeStream', res => {
|
|
34
|
+
stream.once('beforeStream', (res) => {
|
|
35
35
|
console.log(res.headers);
|
|
36
36
|
console.log(res.css);
|
|
37
37
|
console.log(res.js);
|
|
38
38
|
});
|
|
39
|
-
stream.on('error', error => {
|
|
39
|
+
stream.on('error', (error) => {
|
|
40
40
|
console.log(error);
|
|
41
41
|
});
|
|
42
42
|
stream.pipe(process.stdout);
|
|
@@ -58,13 +58,13 @@ const component = client.register({
|
|
|
58
58
|
|
|
59
59
|
component
|
|
60
60
|
.fetch(new HttpIncoming())
|
|
61
|
-
.then(res => {
|
|
61
|
+
.then((res) => {
|
|
62
62
|
console.log(res.content);
|
|
63
63
|
console.log(res.headers);
|
|
64
64
|
console.log(res.css);
|
|
65
65
|
console.log(res.js);
|
|
66
66
|
})
|
|
67
|
-
.catch(error => {
|
|
67
|
+
.catch((error) => {
|
|
68
68
|
console.log(error);
|
|
69
69
|
});
|
|
70
70
|
```
|
|
@@ -299,7 +299,7 @@ When there is a change in state. See the section
|
|
|
299
299
|
|
|
300
300
|
```js
|
|
301
301
|
const client = new Client();
|
|
302
|
-
client.on('state', state => {
|
|
302
|
+
client.on('state', (state) => {
|
|
303
303
|
console.log(state);
|
|
304
304
|
});
|
|
305
305
|
|
|
@@ -330,7 +330,7 @@ Emits the new manifest.
|
|
|
330
330
|
|
|
331
331
|
```js
|
|
332
332
|
const client = new Client();
|
|
333
|
-
client.on('change', manifest => {
|
|
333
|
+
client.on('change', (manifest) => {
|
|
334
334
|
console.log(manifest);
|
|
335
335
|
});
|
|
336
336
|
|
|
@@ -384,6 +384,8 @@ the content of the component. Before the stream starts flowing a `beforeStream`
|
|
|
384
384
|
with a Response object, containing `headers`, `css` and `js` references is
|
|
385
385
|
emitted.
|
|
386
386
|
|
|
387
|
+
**Note:** If the podlet is unavailable, the client will not receive `headers` and therefore will not set `headers` on the response.
|
|
388
|
+
|
|
387
389
|
#### incoming (required)
|
|
388
390
|
|
|
389
391
|
A HttpIncoming object. See https://github.com/podium-lib/utils/blob/master/lib/http-incoming.js
|
|
@@ -421,13 +423,33 @@ otherwise `css` will be an empty string.
|
|
|
421
423
|
|
|
422
424
|
```js
|
|
423
425
|
const stream = component.stream();
|
|
424
|
-
stream.once('beforeStream', data => {
|
|
426
|
+
stream.once('beforeStream', (data) => {
|
|
425
427
|
console.log(data.headers);
|
|
426
428
|
console.log(data.css);
|
|
427
429
|
console.log(data.js);
|
|
428
430
|
});
|
|
429
431
|
```
|
|
430
432
|
|
|
433
|
+
**Note:** If the podlet is unavailable, the client will not receive `headers` and therefore `data.headers` will be undefined.
|
|
434
|
+
|
|
435
|
+
### Asset Scope
|
|
436
|
+
|
|
437
|
+
Both the .fetch() method and the .stream() method give you access to podlet asset objects and these CSS and JS asset objects will be filtered if the asset objects contain a `scope` property and that `scope` property matches the current response type (either content or fallback).
|
|
438
|
+
|
|
439
|
+
For example, if the podlet manifest contains a JavaScript asset definition of the form:
|
|
440
|
+
```
|
|
441
|
+
{
|
|
442
|
+
js: [{ value: "https://assets.com/path/to/file.js", scope: "content" }],
|
|
443
|
+
}
|
|
444
|
+
```
|
|
445
|
+
And the client performs a fetch like so:
|
|
446
|
+
```js
|
|
447
|
+
const result = await component.fetch();
|
|
448
|
+
```
|
|
449
|
+
Then, if the podlet successfully responds from its content route, the `result.js` property will contain the asset defined above. If, however, the podlet's content route errors and the client is forced to use the podlet's fallback content, then `result.js` property will be an empty array.
|
|
450
|
+
|
|
451
|
+
Possible `scope` values are `content`, `fallback` and `all`. For backwards compatibility reasons, when assets do not provide a `scope` property, they will always be included in both `content` and `fallback` responses.
|
|
452
|
+
|
|
431
453
|
## Controlling caching of the manifest
|
|
432
454
|
|
|
433
455
|
The client has an internal cache where it keeps a cached version of the manifest
|
|
@@ -492,10 +514,10 @@ const bar = client.register({
|
|
|
492
514
|
});
|
|
493
515
|
|
|
494
516
|
Promise.all([foo.fetch(), bar.fetch()])
|
|
495
|
-
.then(res => {
|
|
517
|
+
.then((res) => {
|
|
496
518
|
console.log(res.content);
|
|
497
519
|
})
|
|
498
|
-
.catch(error => {
|
|
520
|
+
.catch((error) => {
|
|
499
521
|
console.log(error);
|
|
500
522
|
});
|
|
501
523
|
```
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import MetricsClient from '@metrics/client';
|
|
2
|
+
import { HttpIncoming, AssetJs, AssetCss } from '@podium/utils';
|
|
3
|
+
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
4
|
+
import { Agent as HttpAgent } from 'http';
|
|
5
|
+
import { Agent as HttpsAgent } from 'https';
|
|
6
|
+
|
|
7
|
+
declare class PodiumClient {
|
|
8
|
+
constructor(options?: PodiumClient.PodiumClientOptions);
|
|
9
|
+
|
|
10
|
+
readonly metrics: MetricsClient;
|
|
11
|
+
readonly state:
|
|
12
|
+
| 'instantiated'
|
|
13
|
+
| 'initializing'
|
|
14
|
+
| 'unstable'
|
|
15
|
+
| 'stable'
|
|
16
|
+
| 'unhealthy';
|
|
17
|
+
|
|
18
|
+
register(
|
|
19
|
+
options: PodiumClient.RegisterOptions,
|
|
20
|
+
): PodiumClient.PodiumClientResource;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Refreshes the manifests of all registered resources. Does so by calling the
|
|
24
|
+
* `.refresh()` method on all resources under the hood.
|
|
25
|
+
*/
|
|
26
|
+
refreshManifests(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* This method will refresh a resource by reading its manifest and fallback
|
|
29
|
+
* if defined in the manifest. The method will not call the URI to the content
|
|
30
|
+
* of a component.
|
|
31
|
+
*/
|
|
32
|
+
refresh(): Promise<number>;
|
|
33
|
+
|
|
34
|
+
js(): Array<AssetJs>;
|
|
35
|
+
css(): Array<AssetCss>;
|
|
36
|
+
/**
|
|
37
|
+
* @returns An array of all loaded manifests ready to be used by `.load()`
|
|
38
|
+
*/
|
|
39
|
+
dump(): PodiumClient.PodletManifest[];
|
|
40
|
+
/**
|
|
41
|
+
* Loads an Array of manifests (provided by `.dump()`) into the proxy. If any of
|
|
42
|
+
* the items in the loaded Array contains a key which is already in the cache, the
|
|
43
|
+
* entry in the cache will be overwritten.
|
|
44
|
+
*
|
|
45
|
+
* If any of the entries in the loaded Array are not compatible with the format
|
|
46
|
+
* which `.dump()` exports, they will not be inserted into the cache.
|
|
47
|
+
*
|
|
48
|
+
* @returns An Array with the keys which were inserted into the cache.
|
|
49
|
+
*/
|
|
50
|
+
load(manifests: PodiumClient.PodletManifest[]): string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare namespace PodiumClient {
|
|
54
|
+
export type PodletManifest = {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string;
|
|
57
|
+
content: string;
|
|
58
|
+
fallback?: string;
|
|
59
|
+
proxy?: Record<string, string>;
|
|
60
|
+
assets?: {
|
|
61
|
+
js?: string[];
|
|
62
|
+
css?: string[];
|
|
63
|
+
};
|
|
64
|
+
css?: string[];
|
|
65
|
+
js?: string[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type AbsLogger = {
|
|
69
|
+
trace: LogFunction;
|
|
70
|
+
debug: LogFunction;
|
|
71
|
+
info: LogFunction;
|
|
72
|
+
warn: LogFunction;
|
|
73
|
+
error: LogFunction;
|
|
74
|
+
fatal: LogFunction;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type LogFunction = (...args: any) => void;
|
|
78
|
+
|
|
79
|
+
export type PodiumClientOptions = {
|
|
80
|
+
name?: string;
|
|
81
|
+
logger?: AbsLogger | Console;
|
|
82
|
+
retries?: number;
|
|
83
|
+
timeout?: number;
|
|
84
|
+
maxAge?: number;
|
|
85
|
+
rejectUnauthorized?: boolean;
|
|
86
|
+
resolveThreshold?: number;
|
|
87
|
+
resolveMax?: number;
|
|
88
|
+
httpAgent?: HttpAgent;
|
|
89
|
+
httpsAgent?: HttpsAgent;
|
|
90
|
+
};
|
|
91
|
+
export interface PodiumClientResourceOptions {
|
|
92
|
+
pathname?: string;
|
|
93
|
+
headers?: OutgoingHttpHeaders;
|
|
94
|
+
query?: any;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface PodiumClientResponse {
|
|
98
|
+
readonly redirect: PodiumRedirect;
|
|
99
|
+
readonly content: string;
|
|
100
|
+
readonly headers: IncomingHttpHeaders;
|
|
101
|
+
readonly js: Array<AssetJs>;
|
|
102
|
+
readonly css: Array<AssetCss>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class PodiumClientResource {
|
|
106
|
+
readonly name: string;
|
|
107
|
+
|
|
108
|
+
readonly uri: string;
|
|
109
|
+
|
|
110
|
+
fetch(
|
|
111
|
+
incoming: HttpIncoming,
|
|
112
|
+
options?: PodiumClientResourceOptions,
|
|
113
|
+
): Promise<PodiumClientResponse>;
|
|
114
|
+
|
|
115
|
+
stream(
|
|
116
|
+
incoming: HttpIncoming,
|
|
117
|
+
options?: PodiumClientResourceOptions,
|
|
118
|
+
): ReadableStream<PodiumClientResponse>;
|
|
119
|
+
|
|
120
|
+
refresh(): Promise<boolean>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface RegisterOptions {
|
|
124
|
+
uri: string;
|
|
125
|
+
name: string;
|
|
126
|
+
retries?: number;
|
|
127
|
+
timeout?: number;
|
|
128
|
+
throwable?: boolean;
|
|
129
|
+
redirectable?: boolean;
|
|
130
|
+
resolveJs?: boolean;
|
|
131
|
+
resolveCss?: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface PodiumRedirect {
|
|
135
|
+
readonly statusCode: number;
|
|
136
|
+
readonly location: string;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export = PodiumClient;
|
package/lib/http-outgoing.js
CHANGED
|
@@ -9,6 +9,7 @@ export default class PodletClientHttpOutgoing extends PassThrough {
|
|
|
9
9
|
#killThreshold;
|
|
10
10
|
#redirectable;
|
|
11
11
|
#reqOptions;
|
|
12
|
+
#isFallback;
|
|
12
13
|
#throwable;
|
|
13
14
|
#manifest;
|
|
14
15
|
#incoming;
|
|
@@ -103,6 +104,9 @@ export default class PodletClientHttpOutgoing extends PassThrough {
|
|
|
103
104
|
// When redirectable is true, this object should be populated with redirect information
|
|
104
105
|
// such that a user can perform manual redirection
|
|
105
106
|
this.#redirect = null;
|
|
107
|
+
|
|
108
|
+
// When isfallback is true, content fetch has failed and fallback will be served instead
|
|
109
|
+
this.#isFallback = false;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
get rejectUnauthorized() {
|
|
@@ -217,9 +221,21 @@ export default class PodletClientHttpOutgoing extends PassThrough {
|
|
|
217
221
|
this.#redirectable = value;
|
|
218
222
|
}
|
|
219
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Boolean getter that indicates whether the client is responding with a content or fallback payload.
|
|
226
|
+
* @example
|
|
227
|
+
* ```
|
|
228
|
+
* if (outgoing.isFallback) console.log("Fallback!");
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
get isFallback() {
|
|
232
|
+
return this.#isFallback;
|
|
233
|
+
}
|
|
234
|
+
|
|
220
235
|
pushFallback() {
|
|
221
236
|
this.push(this.#manifest._fallback);
|
|
222
237
|
this.push(null);
|
|
238
|
+
this.#isFallback = true;
|
|
223
239
|
}
|
|
224
240
|
|
|
225
241
|
get [Symbol.toStringTag]() {
|
package/lib/http.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Client } from 'undici';
|
|
2
|
+
|
|
3
|
+
export default class HTTP {
|
|
4
|
+
// #client;
|
|
5
|
+
|
|
6
|
+
// constructor() {
|
|
7
|
+
// // this.#client = { request };
|
|
8
|
+
// }
|
|
9
|
+
|
|
10
|
+
async request(url, options) {
|
|
11
|
+
const u = new URL(url);
|
|
12
|
+
const client = new Client(u.origin, {
|
|
13
|
+
...options,
|
|
14
|
+
connect: { rejectUnauthorized: options.rejectUnauthorized },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { statusCode, headers, body } = await client.request({
|
|
18
|
+
...options,
|
|
19
|
+
path: u.pathname,
|
|
20
|
+
});
|
|
21
|
+
return { statusCode, headers, body };
|
|
22
|
+
}
|
|
23
|
+
}
|