You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@podium/client

Package Overview
Dependencies
Maintainers
6
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@podium/client - npm Package Compare versions

Comparing version

to
5.1.0-beta.1

8

CHANGELOG.md

@@ -0,1 +1,9 @@

# [5.1.0-beta.1](https://github.com/podium-lib/client/compare/v5.0.7...v5.1.0-beta.1) (2024-03-20)
### Features
* add new options to register and use them in fetch ([5aed9d6](https://github.com/podium-lib/client/commit/5aed9d6303681910fc95413535345643bbfa8d62))
* add support for includeBy and excludeBy options in Resource ([51eb442](https://github.com/podium-lib/client/commit/51eb442398a15b487970ebabe51a5c33f3aede29))
## [5.0.7](https://github.com/podium-lib/client/compare/v5.0.6...v5.0.7) (2024-02-01)

@@ -2,0 +10,0 @@

@@ -132,3 +132,8 @@ import MetricsClient from '@metrics/client';

resolveCss?: boolean;
includeBy?: RequestFilterOptions;
excludeBy?: RequestFilterOptions;
}
export type RequestFilterOptions = {
deviceType?: Array<string>;
};

@@ -135,0 +140,0 @@ export interface PodiumRedirect {

4

lib/client.js

@@ -65,2 +65,4 @@ import EventEmitter from 'events';

httpsAgent: HTTPS_AGENT,
includeBy: undefined,
excludeBy: undefined,
...options,

@@ -156,2 +158,4 @@ };

maxAge: this.#options.maxAge,
includeBy: this.#options.includeBy,
excludeBy: this.#options.excludeBy,
httpsAgent: this.#options.httpsAgent,

@@ -158,0 +162,0 @@ httpAgent: this.#options.httpAgent,

@@ -37,3 +37,3 @@ /* eslint-disable no-param-reassign */

this.#metrics.on('error', error => {
this.#metrics.on('error', (error) => {
log.error(

@@ -61,10 +61,62 @@ 'Error emitted by metric stream in @podium/client module',

async fetch(incoming = {}, reqOptions = {}) {
if (!utils.validateIncoming(incoming)) throw new TypeError('you must pass an instance of "HttpIncoming" as the first argument to the .fetch() method');
if (!utils.validateIncoming(incoming))
throw new TypeError(
'you must pass an instance of "HttpIncoming" as the first argument to the .fetch() method',
);
const outgoing = new HttpOutgoing(this.#options, reqOptions, incoming);
if (this.#options.excludeBy) {
/**
* @type {string[] | undefined}
*/
const exclucedDeviceTypes = this.#options.excludeBy.deviceType;
if (Array.isArray(exclucedDeviceTypes)) {
const deviceTypeHeader =
incoming.request.headers['x-podium-device-type'];
for (let i = 0; i < exclucedDeviceTypes.length; i += 1) {
const shouldSkip =
exclucedDeviceTypes[i] === deviceTypeHeader;
if (shouldSkip) {
return new Response({
headers: {},
content: '',
css: [],
js: [],
redirect: '',
});
}
}
}
}
if (this.#options.includeBy) {
/**
* @type {string[] | undefined}
*/
const includeDeviceTypes = this.#options.includeBy.deviceType;
if (Array.isArray(includeDeviceTypes)) {
const deviceTypeHeader =
incoming.request.headers['x-podium-device-type'];
const shouldRequest =
!deviceTypeHeader ||
includeDeviceTypes.includes(deviceTypeHeader);
if (!shouldRequest) {
return new Response({
headers: {},
content: '',
css: [],
js: [],
redirect: '',
});
}
}
}
this.#state.setInitializingState();
const { manifest, headers, redirect, isFallback } = await this.#resolver.resolve(
outgoing,
);
const { manifest, headers, redirect, isFallback } =
await this.#resolver.resolve(outgoing);

@@ -74,3 +126,3 @@ const chunks = [];

for await (const chunk of outgoing) {
chunks.push(chunk)
chunks.push(chunk);
}

@@ -85,4 +137,10 @@

content,
css: utils.filterAssets(isFallback ? "fallback" : "content", manifest.css),
js: utils.filterAssets(isFallback ? "fallback" : "content", manifest.js),
css: utils.filterAssets(
isFallback ? 'fallback' : 'content',
manifest.css,
),
js: utils.filterAssets(
isFallback ? 'fallback' : 'content',
manifest.js,
),
redirect,

@@ -93,3 +151,6 @@ });

stream(incoming = {}, reqOptions = {}) {
if (!utils.validateIncoming(incoming)) throw new TypeError('you must pass an instance of "HttpIncoming" as the first argument to the .stream() method');
if (!utils.validateIncoming(incoming))
throw new TypeError(
'you must pass an instance of "HttpIncoming" as the first argument to the .stream() method',
);
const outgoing = new HttpOutgoing(this.#options, reqOptions, incoming);

@@ -104,3 +165,3 @@ this.#state.setInitializingState();

this.#state.setInitializingState();
return this.#resolver.refresh(outgoing).then(obj => obj);
return this.#resolver.refresh(outgoing).then((obj) => obj);
}

@@ -119,2 +180,2 @@

}
};
}

10

package.json
{
"name": "@podium/client",
"version": "5.0.7",
"version": "5.1.0-beta.1",
"type": "module",

@@ -58,3 +58,3 @@ "license": "MIT",

"benchmark": "2.1.4",
"eslint": "8.56.0",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",

@@ -64,10 +64,10 @@ "eslint-config-prettier": "9.1.0",

"eslint-plugin-prettier": "5.1.3",
"express": "4.18.2",
"express": "4.18.3",
"get-stream": "8.0.1",
"http-proxy": "1.18.1",
"is-stream": "3.0.0",
"prettier": "3.2.4",
"semantic-release": "23.0.0",
"prettier": "3.2.5",
"semantic-release": "23.0.2",
"tap": "18.7.0"
}
}

@@ -155,3 +155,28 @@ # @podium/client v5

- `resolveCss` - {Boolean} - Defines whether to resolve a relative CSS uri for a component to be an absolute uri. Defaults to `false` - Optional.
- `excludeBy` - {Object} - Lets you define a set of rules where a `fetch` call will not be resolved if it matches. - Optional.
- `includeBy` - {Object} - Inverse of `excludeBy`. - Optional.
##### `excludeBy` and `includeBy`
These options are used by `fetch` to conditionally skip fetching the podlet content based on values on the request. It's an alternative to conditionally fetching podlets in your request handler.
Allowed options:
- `deviceType` - {Array<String>} - List of values for the `x-podium-device-type` header. - Optional.
Example: exclude a header and footer in a hybrid web view.
```js
import Client from '@podium/client';
const client = new Client();
const footer = client.register({
uri: 'http://footer.site.com/manifest.json',
name: 'footer',
excludeBy: {
deviceType: ["hybrid-ios", "hybrid-android"], // when footer.fetch(incoming) is called, if the incoming request has the header `x-podium-device-type: hybrid-ios`, `fetch` will return an empty response.
},
});
```
### .js()

@@ -158,0 +183,0 @@