@podium/client
Advanced tools
Comparing version 5.0.0-next.13 to 5.0.0-next.14
129
CHANGELOG.md
@@ -0,1 +1,130 @@ | ||
# [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) | ||
### Bug Fixes | ||
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07)) | ||
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43)) | ||
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73)) | ||
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838)) | ||
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af)) | ||
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc)) | ||
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900)) | ||
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57)) | ||
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb)) | ||
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd)) | ||
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099)) | ||
* 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)) | ||
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146)) | ||
### Features | ||
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5)) | ||
## [4.6.1](https://github.com/podium-lib/client/compare/v4.6.0...v4.6.1) (2023-11-20) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/utils to v4.5.1 ([3632899](https://github.com/podium-lib/client/commit/3632899f76254f78baf6e76430659dc0d507d3eb)) | ||
# [4.6.0](https://github.com/podium-lib/client/compare/v4.5.35...v4.6.0) (2023-11-16) | ||
### Features | ||
* use manifest asset scope field to filter assets ([fd83d64](https://github.com/podium-lib/client/commit/fd83d6486f9454f4fef2cdbcf3a05b86c81205c5)) | ||
## [4.5.35](https://github.com/podium-lib/client/compare/v4.5.34...v4.5.35) (2023-10-19) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/utils to v4.4.41 ([e316c43](https://github.com/podium-lib/client/commit/e316c4328c2e66706a1b9c09ede50cdf75537b57)) | ||
## [4.5.34](https://github.com/podium-lib/client/compare/v4.5.33...v4.5.34) (2023-10-09) | ||
### Bug Fixes | ||
* update type definitions ([d63a621](https://github.com/podium-lib/client/commit/d63a621762909e01acd6d29629c6061a757df146)) | ||
## [4.5.33](https://github.com/podium-lib/client/compare/v4.5.32...v4.5.33) (2023-09-19) | ||
### Bug Fixes | ||
* **deps:** update dependency @metrics/client to v2.5.2 ([764886f](https://github.com/podium-lib/client/commit/764886fe374bc364c9b3efd83a35d3fd041e6c43)) | ||
## [4.5.32](https://github.com/podium-lib/client/compare/v4.5.31...v4.5.32) (2023-09-14) | ||
### Bug Fixes | ||
* **deps:** update dependency @metrics/client to v2.5.1 ([c7f6b5b](https://github.com/podium-lib/client/commit/c7f6b5b1f22f700e17b86b031412955a77fdbc07)) | ||
## [4.5.31](https://github.com/podium-lib/client/compare/v4.5.30...v4.5.31) (2023-05-11) | ||
### Bug Fixes | ||
* Replace .abort() with .destroy() ([a41f44a](https://github.com/podium-lib/client/commit/a41f44a6c4aff7aec8201d05ce220dbdbb648cfd)) | ||
## [4.5.30](https://github.com/podium-lib/client/compare/v4.5.29...v4.5.30) (2023-02-15) | ||
### Bug Fixes | ||
* return correct type in typescript definition. ([#311](https://github.com/podium-lib/client/issues/311)) ([e06f610](https://github.com/podium-lib/client/commit/e06f6103413b1c87761ad5cfde5fbb0488dd1099)) | ||
## [4.5.29](https://github.com/podium-lib/client/compare/v4.5.28...v4.5.29) (2023-01-04) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/utils to v4.4.39 ([39289a0](https://github.com/podium-lib/client/commit/39289a02098950c54b1049e17f0269b8f85aa900)) | ||
## [4.5.28](https://github.com/podium-lib/client/compare/v4.5.27...v4.5.28) (2023-01-04) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/schemas to v4.1.34 ([e95650f](https://github.com/podium-lib/client/commit/e95650f178192fdbd086cc82afa5fc22bdc5d838)) | ||
## [4.5.27](https://github.com/podium-lib/client/compare/v4.5.26...v4.5.27) (2022-12-07) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/utils to v4.4.38 ([05b14df](https://github.com/podium-lib/client/commit/05b14dfdb20609c461b0a91aae4a6d7faf358dbc)) | ||
## [4.5.26](https://github.com/podium-lib/client/compare/v4.5.25...v4.5.26) (2022-11-14) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/utils to v4.4.37 ([6d7fa24](https://github.com/podium-lib/client/commit/6d7fa2474ba5ea17d548783365a6cbe51c3e51af)) | ||
## [4.5.25](https://github.com/podium-lib/client/compare/v4.5.24...v4.5.25) (2022-11-14) | ||
### Bug Fixes | ||
* **deps:** update dependency @podium/schemas to v4.1.33 ([9ee1fba](https://github.com/podium-lib/client/commit/9ee1fba908ed68cba8db8b98b6bf06b4f9a90e73)) | ||
## [4.5.24](https://github.com/podium-lib/client/compare/v4.5.23...v4.5.24) (2022-10-18) | ||
### Bug Fixes | ||
* 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)) | ||
## [4.5.23](https://github.com/podium-lib/client/compare/v4.5.22...v4.5.23) (2022-09-01) | ||
### Bug Fixes | ||
* 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)) | ||
# [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,0 +131,0 @@ |
@@ -12,2 +12,3 @@ /* eslint-disable no-underscore-dangle */ | ||
#reqOptions; | ||
#isFallback; | ||
#throwable; | ||
@@ -107,2 +108,5 @@ #manifest; | ||
this.#redirect = null; | ||
// When isfallback is true, content fetch has failed and fallback will be served instead | ||
this.#isFallback = false; | ||
} | ||
@@ -222,5 +226,17 @@ | ||
/** | ||
* Boolean getter that indicates whether the client is responding with a content or fallback payload. | ||
* @example | ||
* ``` | ||
* if (outgoing.isFallback) console.log("Fallback!"); | ||
* ``` | ||
*/ | ||
get isFallback() { | ||
return this.#isFallback; | ||
} | ||
pushFallback() { | ||
this.push(this.#manifest._fallback); | ||
this.push(null); | ||
this.#isFallback = true; | ||
} | ||
@@ -227,0 +243,0 @@ |
@@ -73,2 +73,9 @@ /* eslint-disable no-param-reassign */ | ||
outgoing.pushFallback(); | ||
outgoing.emit( | ||
'beforeStream', | ||
new Response({ | ||
js: utils.filterAssets("fallback", outgoing.manifest.js), | ||
css: utils.filterAssets("fallback", outgoing.manifest.css), | ||
}), | ||
); | ||
return outgoing; | ||
@@ -90,2 +97,9 @@ } | ||
outgoing.pushFallback(); | ||
outgoing.emit( | ||
'beforeStream', | ||
new Response({ | ||
js: utils.filterAssets("fallback", outgoing.manifest.js), | ||
css: utils.filterAssets("fallback", outgoing.manifest.css), | ||
}), | ||
); | ||
return outgoing; | ||
@@ -171,2 +185,9 @@ } | ||
outgoing.pushFallback(); | ||
outgoing.emit( | ||
'beforeStream', | ||
new Response({ | ||
js: utils.filterAssets("fallback", outgoing.manifest.js), | ||
css: utils.filterAssets("fallback", outgoing.manifest.css), | ||
}), | ||
); | ||
return outgoing; | ||
@@ -215,4 +236,4 @@ } | ||
headers: outgoing.headers, | ||
js: outgoing.manifest.js, | ||
css: outgoing.manifest.css, | ||
js: utils.filterAssets("content", outgoing.manifest.js), | ||
css: utils.filterAssets("content", outgoing.manifest.css), | ||
redirect: outgoing.redirect, | ||
@@ -260,2 +281,9 @@ }), | ||
outgoing.pushFallback(); | ||
outgoing.emit( | ||
'beforeStream', | ||
new Response({ | ||
js: utils.filterAssets("fallback", outgoing.manifest.js), | ||
css: utils.filterAssets("fallback", outgoing.manifest.css), | ||
}), | ||
); | ||
@@ -262,0 +290,0 @@ return outgoing; |
@@ -65,3 +65,3 @@ /* eslint-disable no-param-reassign */ | ||
const { manifest, headers, redirect } = await this.#resolver.resolve( | ||
const { manifest, headers, redirect, isFallback } = await this.#resolver.resolve( | ||
outgoing, | ||
@@ -83,4 +83,4 @@ ); | ||
content, | ||
css: manifest.css, | ||
js: manifest.js, | ||
css: utils.filterAssets(isFallback ? "fallback" : "content", manifest.css), | ||
js: utils.filterAssets(isFallback ? "fallback" : "content", manifest.js), | ||
redirect, | ||
@@ -87,0 +87,0 @@ }); |
@@ -35,2 +35,42 @@ /** | ||
/** | ||
* Check if a value is a HttpIncoming object or not. If not, it | ||
* assume the incoming value is a context | ||
* | ||
* @param {Object} incoming A object | ||
* | ||
* @returns {HttpIncoming} | ||
*/ | ||
export const validateIncoming = (incoming = {}) => (Object.prototype.toString.call(incoming) === '[object PodiumHttpIncoming]'); | ||
/** | ||
* @typedef {import("@podium/utils").AssetCss | import("@podium/utils").AssetJs} Asset | ||
*/ | ||
/** | ||
* Filter assets array based on scope. | ||
* If scope property is not present, asset will be included (backwards compatibility) | ||
* If scope property is set to "all", asset will be included. | ||
* If scope is set to "content" and asset scope property is set to "fallback", asset will not be included | ||
* If scope is set to "fallback" and asset scope property is set to "content", asset will not be included | ||
* @param {"content" | "fallback" | "all"} scope | ||
* @param {Asset[]} assets | ||
* @returns {Asset[]} | ||
* | ||
* @example | ||
* ``` | ||
* // plain objects work | ||
* const assets = filterAssets("content", [{..., scope: "content"}, {..., scope: "fallback"}]); | ||
* // as do AssetJs and AssetCSS objects | ||
* const assets = filterAssets("content", [new AssetCss(), new AssetCss()]); | ||
* ``` | ||
*/ | ||
export const filterAssets = (scope, assets) => { | ||
// if undefined or null, passthrough | ||
if (!assets) return assets; | ||
// if a non array value is given, throw | ||
if (!Array.isArray(assets)) throw new TypeError(`Asset definition must be of type array. Got ${typeof assets}`); | ||
// filter the array of asset definitions to matchin scope or anything with all. Treat no scope the same as "all" for backwards compatibility. | ||
return assets.filter(asset => !asset.scope || asset.scope === scope || asset.scope === "all"); | ||
}; |
{ | ||
"name": "@podium/client", | ||
"version": "5.0.0-next.13", | ||
"version": "5.0.0-next.14", | ||
"type": "module", | ||
@@ -24,3 +24,3 @@ "license": "MIT", | ||
"CHANGELOG.md", | ||
"index.d.ts", | ||
"client.d.ts", | ||
"README.md", | ||
@@ -36,9 +36,9 @@ "LICENSE", | ||
"lint:fix": "eslint --fix .", | ||
"test": "tap --no-check-coverage" | ||
"test": "tap --disable-coverage --allow-empty-coverage" | ||
}, | ||
"dependencies": { | ||
"@hapi/boom": "^10.0.0", | ||
"@metrics/client": "2.5.0", | ||
"@podium/schemas": "5.0.0-next.4", | ||
"@podium/utils": "5.0.0-next.6", | ||
"@metrics/client": "2.5.2", | ||
"@podium/schemas": "5.0.0", | ||
"@podium/utils": "5.0.0", | ||
"abslog": "2.4.0", | ||
@@ -52,20 +52,20 @@ "http-cache-semantics": "^4.0.3", | ||
"@podium/test-utils": "2.5.2", | ||
"@semantic-release/changelog": "6.0.1", | ||
"@semantic-release/changelog": "6.0.3", | ||
"@semantic-release/git": "10.0.1", | ||
"@sinonjs/fake-timers": "9.1.2", | ||
"@babel/eslint-parser": "7.18.9", | ||
"@sinonjs/fake-timers": "11.2.2", | ||
"@babel/eslint-parser": "7.23.3", | ||
"benchmark": "2.1.4", | ||
"eslint": "8.23.0", | ||
"eslint": "8.54.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"express": "4.18.1", | ||
"get-stream": "6.0.1", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-import": "2.29.0", | ||
"eslint-plugin-prettier": "5.0.1", | ||
"express": "4.18.2", | ||
"get-stream": "8.0.1", | ||
"http-proxy": "1.18.1", | ||
"is-stream": "3.0.0", | ||
"prettier": "2.7.1", | ||
"semantic-release": "19.0.5", | ||
"tap": "16.3.0" | ||
"prettier": "3.1.0", | ||
"semantic-release": "22.0.8", | ||
"tap": "18.6.1" | ||
} | ||
} |
@@ -34,3 +34,3 @@ # @podium/client v5 | ||
const stream = component.stream(new HttpIncoming()); | ||
stream.once('beforeStream', res => { | ||
stream.once('beforeStream', (res) => { | ||
console.log(res.headers); | ||
@@ -40,3 +40,3 @@ console.log(res.css); | ||
}); | ||
stream.on('error', error => { | ||
stream.on('error', (error) => { | ||
console.log(error); | ||
@@ -63,3 +63,3 @@ }); | ||
.fetch(new HttpIncoming()) | ||
.then(res => { | ||
.then((res) => { | ||
console.log(res.content); | ||
@@ -70,3 +70,3 @@ console.log(res.headers); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -306,3 +306,3 @@ }); | ||
const client = new Client(); | ||
client.on('state', state => { | ||
client.on('state', (state) => { | ||
console.log(state); | ||
@@ -338,3 +338,3 @@ }); | ||
const client = new Client(); | ||
client.on('change', manifest => { | ||
client.on('change', (manifest) => { | ||
console.log(manifest); | ||
@@ -393,2 +393,4 @@ }); | ||
**Note:** If the podlet is unavailable, the client will not receive `headers` and therefore will not set `headers` on the response. | ||
#### incoming (required) | ||
@@ -431,3 +433,3 @@ | ||
const stream = component.stream(); | ||
stream.once('beforeStream', data => { | ||
stream.once('beforeStream', (data) => { | ||
console.log(data.headers); | ||
@@ -439,2 +441,22 @@ console.log(data.css); | ||
**Note:** If the podlet is unavailable, the client will not receive `headers` and therefore `data.headers` will be undefined. | ||
### Asset Scope | ||
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). | ||
For example, if the podlet manifest contains a JavaScript asset definition of the form: | ||
``` | ||
{ | ||
js: [{ value: "https://assets.com/path/to/file.js", scope: "content" }], | ||
} | ||
``` | ||
And the client performs a fetch like so: | ||
```js | ||
const result = await component.fetch(); | ||
``` | ||
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. | ||
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. | ||
## Controlling caching of the manifest | ||
@@ -504,6 +526,6 @@ | ||
Promise.all([foo.fetch(), bar.fetch()]) | ||
.then(res => { | ||
.then((res) => { | ||
console.log(res.content); | ||
}) | ||
.catch(error => { | ||
.catch((error) => { | ||
console.log(error); | ||
@@ -510,0 +532,0 @@ }); |
117671
1533
663
+ Added@metrics/client@2.5.2(transitive)
+ Added@podium/schemas@5.0.0(transitive)
+ Added@podium/utils@5.0.0(transitive)
+ Addedajv@8.12.0(transitive)
+ Addedajv-formats@2.1.1(transitive)
+ Addedcamelcase@6.3.0(transitive)
+ Addedconvert-hrtime@3.0.0(transitive)
+ Addedtime-span@4.0.0(transitive)
- Removed@metrics/client@2.5.0(transitive)
- Removed@podium/schemas@5.0.0-next.4(transitive)
- Removed@podium/utils@5.0.0-next.6(transitive)
- Removedajv@8.1.0(transitive)
- Removedajv-formats@2.0.2(transitive)
- Removedcamelcase@6.2.0(transitive)
- Removedconvert-hrtime@2.0.0(transitive)
- Removedforwarded-parse@2.1.2(transitive)
- Removedoriginal-url@1.2.3(transitive)
- Removedtime-span@3.1.0(transitive)
Updated@metrics/client@2.5.2
Updated@podium/schemas@5.0.0
Updated@podium/utils@5.0.0