@podium/client 5.0.0-next.13 → 5.0.0-next.15
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 +137 -0
- package/README.md +31 -9
- package/client.d.ts +140 -0
- package/lib/http-outgoing.js +16 -0
- package/lib/resolver.content.js +30 -2
- package/lib/resource.js +3 -3
- package/lib/utils.js +40 -0
- package/package.json +21 -18
- package/index.d.ts +0 -63
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,140 @@
|
|
|
1
|
+
# [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)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency readable-stream to v4 ([d3aff96](https://github.com/podium-lib/client/commit/d3aff9608ebfefc294ab0b79563a96670019311f))
|
|
7
|
+
* **deps:** update dependency readable-stream to v4 ([9c7303a](https://github.com/podium-lib/client/commit/9c7303aea267f951a8359f3d0640588d8d82b21a))
|
|
8
|
+
|
|
9
|
+
# [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)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07))
|
|
15
|
+
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43))
|
|
16
|
+
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73))
|
|
17
|
+
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838))
|
|
18
|
+
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af))
|
|
19
|
+
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc))
|
|
20
|
+
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900))
|
|
21
|
+
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57))
|
|
22
|
+
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb))
|
|
23
|
+
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd))
|
|
24
|
+
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099))
|
|
25
|
+
* 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))
|
|
26
|
+
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5))
|
|
32
|
+
|
|
33
|
+
## [4.6.1](https://github.com/podium-lib/client/compare/v4.6.0...v4.6.1) (2023-11-20)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb))
|
|
39
|
+
|
|
40
|
+
# [4.6.0](https://github.com/podium-lib/client/compare/v4.5.35...v4.6.0) (2023-11-16)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
|
|
45
|
+
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5))
|
|
46
|
+
|
|
47
|
+
## [4.5.35](https://github.com/podium-lib/client/compare/v4.5.34...v4.5.35) (2023-10-19)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Bug Fixes
|
|
51
|
+
|
|
52
|
+
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57))
|
|
53
|
+
|
|
54
|
+
## [4.5.34](https://github.com/podium-lib/client/compare/v4.5.33...v4.5.34) (2023-10-09)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Bug Fixes
|
|
58
|
+
|
|
59
|
+
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146))
|
|
60
|
+
|
|
61
|
+
## [4.5.33](https://github.com/podium-lib/client/compare/v4.5.32...v4.5.33) (2023-09-19)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Bug Fixes
|
|
65
|
+
|
|
66
|
+
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43))
|
|
67
|
+
|
|
68
|
+
## [4.5.32](https://github.com/podium-lib/client/compare/v4.5.31...v4.5.32) (2023-09-14)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Bug Fixes
|
|
72
|
+
|
|
73
|
+
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07))
|
|
74
|
+
|
|
75
|
+
## [4.5.31](https://github.com/podium-lib/client/compare/v4.5.30...v4.5.31) (2023-05-11)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Bug Fixes
|
|
79
|
+
|
|
80
|
+
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd))
|
|
81
|
+
|
|
82
|
+
## [4.5.30](https://github.com/podium-lib/client/compare/v4.5.29...v4.5.30) (2023-02-15)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099))
|
|
88
|
+
|
|
89
|
+
## [4.5.29](https://github.com/podium-lib/client/compare/v4.5.28...v4.5.29) (2023-01-04)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Bug Fixes
|
|
93
|
+
|
|
94
|
+
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900))
|
|
95
|
+
|
|
96
|
+
## [4.5.28](https://github.com/podium-lib/client/compare/v4.5.27...v4.5.28) (2023-01-04)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Bug Fixes
|
|
100
|
+
|
|
101
|
+
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838))
|
|
102
|
+
|
|
103
|
+
## [4.5.27](https://github.com/podium-lib/client/compare/v4.5.26...v4.5.27) (2022-12-07)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Bug Fixes
|
|
107
|
+
|
|
108
|
+
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc))
|
|
109
|
+
|
|
110
|
+
## [4.5.26](https://github.com/podium-lib/client/compare/v4.5.25...v4.5.26) (2022-11-14)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### Bug Fixes
|
|
114
|
+
|
|
115
|
+
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af))
|
|
116
|
+
|
|
117
|
+
## [4.5.25](https://github.com/podium-lib/client/compare/v4.5.24...v4.5.25) (2022-11-14)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Bug Fixes
|
|
121
|
+
|
|
122
|
+
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73))
|
|
123
|
+
|
|
124
|
+
## [4.5.24](https://github.com/podium-lib/client/compare/v4.5.23...v4.5.24) (2022-10-18)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### Bug Fixes
|
|
128
|
+
|
|
129
|
+
* 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))
|
|
130
|
+
|
|
131
|
+
## [4.5.23](https://github.com/podium-lib/client/compare/v4.5.22...v4.5.23) (2022-09-01)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Bug Fixes
|
|
135
|
+
|
|
136
|
+
* 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))
|
|
137
|
+
|
|
1
138
|
# [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)
|
|
2
139
|
|
|
3
140
|
|
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/resolver.content.js
CHANGED
|
@@ -70,6 +70,13 @@ export default class PodletClientContentResolver {
|
|
|
70
70
|
);
|
|
71
71
|
outgoing.success = true;
|
|
72
72
|
outgoing.pushFallback();
|
|
73
|
+
outgoing.emit(
|
|
74
|
+
'beforeStream',
|
|
75
|
+
new Response({
|
|
76
|
+
js: utils.filterAssets("fallback", outgoing.manifest.js),
|
|
77
|
+
css: utils.filterAssets("fallback", outgoing.manifest.css),
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
73
80
|
return outgoing;
|
|
74
81
|
}
|
|
75
82
|
|
|
@@ -86,6 +93,13 @@ export default class PodletClientContentResolver {
|
|
|
86
93
|
);
|
|
87
94
|
outgoing.success = true;
|
|
88
95
|
outgoing.pushFallback();
|
|
96
|
+
outgoing.emit(
|
|
97
|
+
'beforeStream',
|
|
98
|
+
new Response({
|
|
99
|
+
js: utils.filterAssets("fallback", outgoing.manifest.js),
|
|
100
|
+
css: utils.filterAssets("fallback", outgoing.manifest.css),
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
89
103
|
return outgoing;
|
|
90
104
|
}
|
|
91
105
|
|
|
@@ -166,6 +180,13 @@ export default class PodletClientContentResolver {
|
|
|
166
180
|
);
|
|
167
181
|
outgoing.success = true;
|
|
168
182
|
outgoing.pushFallback();
|
|
183
|
+
outgoing.emit(
|
|
184
|
+
'beforeStream',
|
|
185
|
+
new Response({
|
|
186
|
+
js: utils.filterAssets("fallback", outgoing.manifest.js),
|
|
187
|
+
css: utils.filterAssets("fallback", outgoing.manifest.css),
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
169
190
|
return outgoing;
|
|
170
191
|
}
|
|
171
192
|
|
|
@@ -209,8 +230,8 @@ export default class PodletClientContentResolver {
|
|
|
209
230
|
'beforeStream',
|
|
210
231
|
new Response({
|
|
211
232
|
headers: outgoing.headers,
|
|
212
|
-
js: outgoing.manifest.js,
|
|
213
|
-
css: outgoing.manifest.css,
|
|
233
|
+
js: utils.filterAssets("content", outgoing.manifest.js),
|
|
234
|
+
css: utils.filterAssets("content", outgoing.manifest.css),
|
|
214
235
|
redirect: outgoing.redirect,
|
|
215
236
|
}),
|
|
216
237
|
);
|
|
@@ -253,6 +274,13 @@ export default class PodletClientContentResolver {
|
|
|
253
274
|
outgoing.success = true;
|
|
254
275
|
|
|
255
276
|
outgoing.pushFallback();
|
|
277
|
+
outgoing.emit(
|
|
278
|
+
'beforeStream',
|
|
279
|
+
new Response({
|
|
280
|
+
js: utils.filterAssets("fallback", outgoing.manifest.js),
|
|
281
|
+
css: utils.filterAssets("fallback", outgoing.manifest.css),
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
256
284
|
|
|
257
285
|
return outgoing;
|
|
258
286
|
}
|
package/lib/resource.js
CHANGED
|
@@ -62,7 +62,7 @@ export default class PodiumClientResource {
|
|
|
62
62
|
|
|
63
63
|
this.#state.setInitializingState();
|
|
64
64
|
|
|
65
|
-
const { manifest, headers, redirect } = await this.#resolver.resolve(
|
|
65
|
+
const { manifest, headers, redirect, isFallback } = await this.#resolver.resolve(
|
|
66
66
|
outgoing,
|
|
67
67
|
);
|
|
68
68
|
|
|
@@ -79,8 +79,8 @@ export default class PodiumClientResource {
|
|
|
79
79
|
return new Response({
|
|
80
80
|
headers,
|
|
81
81
|
content,
|
|
82
|
-
css: manifest.css,
|
|
83
|
-
js: manifest.js,
|
|
82
|
+
css: utils.filterAssets(isFallback ? "fallback" : "content", manifest.css),
|
|
83
|
+
js: utils.filterAssets(isFallback ? "fallback" : "content", manifest.js),
|
|
84
84
|
redirect,
|
|
85
85
|
});
|
|
86
86
|
}
|
package/lib/utils.js
CHANGED
|
@@ -32,4 +32,44 @@ export const hasManifestChange = item => {
|
|
|
32
32
|
return oldVersion !== newVersion;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a value is a HttpIncoming object or not. If not, it
|
|
38
|
+
* assume the incoming value is a context
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} incoming A object
|
|
41
|
+
*
|
|
42
|
+
* @returns {HttpIncoming}
|
|
43
|
+
*/
|
|
35
44
|
export const validateIncoming = (incoming = {}) => (Object.prototype.toString.call(incoming) === '[object PodiumHttpIncoming]');
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {import("@podium/utils").AssetCss | import("@podium/utils").AssetJs} Asset
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Filter assets array based on scope.
|
|
52
|
+
* If scope property is not present, asset will be included (backwards compatibility)
|
|
53
|
+
* If scope property is set to "all", asset will be included.
|
|
54
|
+
* If scope is set to "content" and asset scope property is set to "fallback", asset will not be included
|
|
55
|
+
* If scope is set to "fallback" and asset scope property is set to "content", asset will not be included
|
|
56
|
+
* @param {"content" | "fallback" | "all"} scope
|
|
57
|
+
* @param {Asset[]} assets
|
|
58
|
+
* @returns {Asset[]}
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```
|
|
62
|
+
* // plain objects work
|
|
63
|
+
* const assets = filterAssets("content", [{..., scope: "content"}, {..., scope: "fallback"}]);
|
|
64
|
+
* // as do AssetJs and AssetCSS objects
|
|
65
|
+
* const assets = filterAssets("content", [new AssetCss(), new AssetCss()]);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const filterAssets = (scope, assets) => {
|
|
69
|
+
// if undefined or null, passthrough
|
|
70
|
+
if (!assets) return assets;
|
|
71
|
+
// if a non array value is given, throw
|
|
72
|
+
if (!Array.isArray(assets)) throw new TypeError(`Asset definition must be of type array. Got ${typeof assets}`);
|
|
73
|
+
// filter the array of asset definitions to matchin scope or anything with all. Treat no scope the same as "all" for backwards compatibility.
|
|
74
|
+
return assets.filter(asset => !asset.scope || asset.scope === scope || asset.scope === "all");
|
|
75
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podium/client",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"package.json",
|
|
23
23
|
"CHANGELOG.md",
|
|
24
|
-
"
|
|
24
|
+
"client.d.ts",
|
|
25
25
|
"README.md",
|
|
26
26
|
"LICENSE",
|
|
27
27
|
"dist",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"lint": "eslint .",
|
|
34
34
|
"lint:fix": "eslint --fix .",
|
|
35
|
-
"test": "tap --
|
|
35
|
+
"test": "tap --disable-coverage --allow-empty-coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@hapi/boom": "^10.0.0",
|
|
39
|
-
"@metrics/client": "2.5.
|
|
40
|
-
"@podium/schemas": "5.0.0
|
|
41
|
-
"@podium/utils": "5.0.0
|
|
39
|
+
"@metrics/client": "2.5.2",
|
|
40
|
+
"@podium/schemas": "5.0.0",
|
|
41
|
+
"@podium/utils": "5.0.0",
|
|
42
42
|
"abslog": "2.4.0",
|
|
43
43
|
"http-cache-semantics": "^4.0.3",
|
|
44
44
|
"lodash.clonedeep": "^4.5.0",
|
|
@@ -47,22 +47,25 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@podium/test-utils": "2.5.2",
|
|
50
|
-
"@semantic-release/changelog": "6.0.
|
|
50
|
+
"@semantic-release/changelog": "6.0.3",
|
|
51
51
|
"@semantic-release/git": "10.0.1",
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
52
|
+
"@babel/eslint-parser": "7.23.3",
|
|
53
|
+
"@semantic-release/github": "8.1.0",
|
|
54
|
+
"@semantic-release/npm": "8.0.3",
|
|
55
|
+
"@semantic-release/release-notes-generator": "10.0.3",
|
|
56
|
+
"@sinonjs/fake-timers": "11.2.2",
|
|
54
57
|
"benchmark": "2.1.4",
|
|
55
|
-
"eslint": "8.
|
|
58
|
+
"eslint": "8.54.0",
|
|
56
59
|
"eslint-config-airbnb-base": "15.0.0",
|
|
57
|
-
"eslint-config-prettier": "
|
|
58
|
-
"eslint-plugin-import": "2.
|
|
59
|
-
"eslint-plugin-prettier": "
|
|
60
|
-
"express": "4.18.
|
|
61
|
-
"get-stream": "
|
|
60
|
+
"eslint-config-prettier": "9.0.0",
|
|
61
|
+
"eslint-plugin-import": "2.29.0",
|
|
62
|
+
"eslint-plugin-prettier": "5.0.1",
|
|
63
|
+
"express": "4.18.2",
|
|
64
|
+
"get-stream": "8.0.1",
|
|
62
65
|
"http-proxy": "1.18.1",
|
|
63
66
|
"is-stream": "3.0.0",
|
|
64
|
-
"prettier": "
|
|
65
|
-
"semantic-release": "
|
|
66
|
-
"tap": "
|
|
67
|
+
"prettier": "3.1.0",
|
|
68
|
+
"semantic-release": "22.0.8",
|
|
69
|
+
"tap": "18.6.1"
|
|
67
70
|
}
|
|
68
71
|
}
|
package/index.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { HttpIncoming, AssetJs, AssetCss } from '@podium/utils';
|
|
2
|
-
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
|
3
|
-
|
|
4
|
-
declare interface PodiumClientResourceOptions {
|
|
5
|
-
pathname?: string;
|
|
6
|
-
headers?: OutgoingHttpHeaders;
|
|
7
|
-
query?: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare interface PodiumClientResponse {
|
|
11
|
-
readonly redirect: PodiumRedirect;
|
|
12
|
-
readonly content: string;
|
|
13
|
-
readonly headers: IncomingHttpHeaders;
|
|
14
|
-
readonly js: Array<AssetJs>;
|
|
15
|
-
readonly css: Array<AssetCss>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class PodiumClientResource {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
|
|
21
|
-
readonly uri: string;
|
|
22
|
-
|
|
23
|
-
fetch(
|
|
24
|
-
incoming: HttpIncoming,
|
|
25
|
-
options?: PodiumClientResourceOptions,
|
|
26
|
-
): Promise<PodiumClientResponse>;
|
|
27
|
-
|
|
28
|
-
stream(
|
|
29
|
-
incoming: HttpIncoming,
|
|
30
|
-
options?: PodiumClientResourceOptions,
|
|
31
|
-
): ReadableStream<PodiumClientResponse>;
|
|
32
|
-
|
|
33
|
-
refresh(): Promise<boolean>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
declare interface RegisterOptions {
|
|
37
|
-
uri: string;
|
|
38
|
-
name: string;
|
|
39
|
-
retries?: number;
|
|
40
|
-
timeout?: number;
|
|
41
|
-
throwable?: boolean;
|
|
42
|
-
redirectable?: boolean;
|
|
43
|
-
resolveJs?: boolean;
|
|
44
|
-
resolveCss?: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare interface PodiumRedirect {
|
|
48
|
-
readonly statusCode: number;
|
|
49
|
-
readonly location: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default class PodiumClient {
|
|
53
|
-
readonly state:
|
|
54
|
-
| 'instantiated'
|
|
55
|
-
| 'initializing'
|
|
56
|
-
| 'unstable'
|
|
57
|
-
| 'stable'
|
|
58
|
-
| 'unhealthy';
|
|
59
|
-
|
|
60
|
-
register(options: RegisterOptions): PodiumClientResource;
|
|
61
|
-
|
|
62
|
-
refreshManifests(): void;
|
|
63
|
-
}
|