Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@podium/client

Package Overview
Dependencies
Maintainers
0
Versions
196
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 5.2.0-next.4 to 5.2.0-next.5

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [5.2.0-next.5](https://github.com/podium-lib/client/compare/v5.2.0-next.4...v5.2.0-next.5) (2024-10-15)
### Features
* replace early hints with header link reading ([4429681](https://github.com/podium-lib/client/commit/44296811441a857fabeaebb583c42da28ec47705))
# [5.2.0-next.4](https://github.com/podium-lib/client/compare/v5.2.0-next.3...v5.2.0-next.4) (2024-09-24)

@@ -2,0 +9,0 @@

2

lib/client.js

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

* @property {import('./resource.js').RequestFilterOptions} [includeBy] Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
* @property {boolean} [earlyHints=true]
*/

@@ -217,3 +216,2 @@

excludeBy: this.#options.excludeBy,
earlyHints: true,
...options,

@@ -220,0 +218,0 @@ };

import { PassThrough } from 'stream';
import assert from 'assert';
import { toPreloadAssetObjects } from './utils.js';
import { toPreloadAssetObjects, filterAssets } from './utils.js';

@@ -73,3 +73,2 @@ /**

#css;
#hintsReceived = false;

@@ -158,3 +157,5 @@ /**

// return the internal js value or, fallback to the manifest for backwards compatibility
return this.#js || this.#manifest.js;
return this.#js && this.#js.length
? this.#js
: filterAssets('content', this.#manifest.js);
}

@@ -168,3 +169,5 @@

// return the internal css value or, fallback to the manifest for backwards compatibility
return this.#css || this.#manifest.css;
return this.#css && this.#css.length
? this.#css
: filterAssets('content', this.#manifest.css);
}

@@ -307,16 +310,2 @@

get hintsReceived() {
return this.#hintsReceived;
}
set hintsReceived(value) {
this.#hintsReceived = value;
if (this.#hintsReceived) {
this.#incoming?.hints?.addReceivedHint(this.#name, {
js: this.js,
css: this.css,
});
}
}
/**

@@ -353,6 +342,14 @@ * Whether the podlet can signal redirects to the layout.

this.push(this.#manifest._fallback);
// @ts-expect-error Internal property
this.js = this.#manifest._js;
// @ts-expect-error Internal property
this.css = this.#manifest._css;
this.js =
// @ts-expect-error Internal property
this.#manifest._js && this.#manifest._js.length
? // @ts-expect-error Internal property
filterAssets('fallback', this.#manifest._js)
: filterAssets('fallback', this.#manifest.js);
this.css =
// @ts-expect-error Internal property
this.#manifest._css && this.#manifest._css.length
? // @ts-expect-error Internal property
filterAssets('fallback', this.#manifest._css)
: filterAssets('fallback', this.#manifest.css);
this.push(null);

@@ -359,0 +356,0 @@ this.#isFallback = true;

@@ -30,3 +30,2 @@ import { pipeline } from 'stream';

* @property {import('abslog').AbstractLoggerOptions} [logger]
* @property {boolean} [earlyHints]
*/

@@ -39,3 +38,2 @@

#http;
#earlyHints;

@@ -51,4 +49,2 @@ /**

this.#log = abslog(options.logger);
this.#earlyHints =
typeof options.earlyHints === 'boolean' ? options.earlyHints : true;
this.#metrics = new Metrics();

@@ -102,6 +98,3 @@ this.#histogram = this.#metrics.histogram({

'beforeStream',
new Response({
js: utils.filterAssets('fallback', outgoing.manifest.js),
css: utils.filterAssets('fallback', outgoing.manifest.css),
}),
new Response({ js: outgoing.js, css: outgoing.css }),
);

@@ -126,6 +119,3 @@ return outgoing;

'beforeStream',
new Response({
js: utils.filterAssets('fallback', outgoing.manifest.js),
css: utils.filterAssets('fallback', outgoing.manifest.css),
}),
new Response({ js: outgoing.js, css: outgoing.css }),
);

@@ -154,22 +144,2 @@ return outgoing;

headers,
onInfo: ({ statusCode, headers }) => {
if (statusCode === 103 && !outgoing.hintsReceived) {
const parsedAssetObjects = parseLinkHeaders(headers.link);
const scriptObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetJs,
);
const styleObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetCss,
);
// set the content js asset objects
outgoing.js = filterAssets('content', scriptObjects);
// set the content css asset objects
outgoing.css = filterAssets('content', styleObjects);
// write the early hints to the browser
if (this.#earlyHints) outgoing.writeEarlyHints();
outgoing.hintsReceived = true;
}
},
};

@@ -198,2 +168,15 @@

const parsedAssetObjects = parseLinkHeaders(hdrs.link);
const scriptObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetJs,
);
const styleObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetCss,
);
// set the content js asset objects
outgoing.js = filterAssets('content', scriptObjects);
// set the content css asset objects
outgoing.css = filterAssets('content', styleObjects);
// Remote responds but with an http error code

@@ -239,12 +222,3 @@ const resError = statusCode >= 400;

'beforeStream',
new Response({
js: utils.filterAssets(
'fallback',
outgoing.manifest.js,
),
css: utils.filterAssets(
'fallback',
outgoing.manifest.css,
),
}),
new Response({ js: outgoing.js, css: outgoing.css }),
);

@@ -298,4 +272,4 @@

headers: outgoing.headers,
js: utils.filterAssets('content', outgoing.manifest.js),
css: utils.filterAssets('content', outgoing.manifest.css),
js: outgoing.js,
css: outgoing.css,
redirect: outgoing.redirect,

@@ -340,6 +314,3 @@ }),

'beforeStream',
new Response({
js: utils.filterAssets('fallback', outgoing.js),
css: utils.filterAssets('fallback', outgoing.css),
}),
new Response({ js: outgoing.js, css: outgoing.css }),
);

@@ -346,0 +317,0 @@

@@ -99,4 +99,2 @@ import abslog from 'abslog';

let hintsReceived = false;
/** @type {import('./http.js').PodiumHttpClientRequestOptions} */

@@ -108,28 +106,2 @@ const reqOptions = {

headers,
onInfo({ statusCode, headers }) {
if (statusCode === 103 && !hintsReceived) {
const parsedAssetObjects = parseLinkHeaders(headers.link);
const scriptObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetJs,
);
const styleObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetCss,
);
// set the content js asset fallback objects
// @ts-expect-error internal property
outgoing.manifest._js = filterAssets(
'fallback',
scriptObjects,
);
// set the fallback css asset fallback objects
// @ts-expect-error internal property
outgoing.manifest._css = filterAssets(
'fallback',
styleObjects,
);
hintsReceived = true;
}
},
};

@@ -147,6 +119,22 @@

);
const { statusCode, body } = await this.#http.request(
outgoing.fallbackUri,
reqOptions,
const {
statusCode,
body,
headers: resHeaders,
} = await this.#http.request(outgoing.fallbackUri, reqOptions);
const parsedAssetObjects = parseLinkHeaders(resHeaders.link);
const scriptObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetJs,
);
const styleObjects = parsedAssetObjects.filter(
(asset) => asset instanceof AssetCss,
);
// set the content js asset fallback objects
// @ts-expect-error internal property
outgoing.manifest._js = filterAssets('fallback', scriptObjects);
// set the fallback css asset fallback objects
// @ts-expect-error internal property
outgoing.manifest._css = filterAssets('fallback', styleObjects);

@@ -153,0 +141,0 @@ // Remote responds but with an http error code

@@ -108,6 +108,2 @@ import Metrics from '@metrics/client';

);
// add the name of this resource as expecting a hint to be received
// we use this to track across resources and emit a hint completion event once
// all hints from all resources have been received.
incoming.hints.addExpectedHint(this.#options.name);
const outgoing = new HttpOutgoing(this.#options, reqOptions, incoming);

@@ -167,4 +163,3 @@

const { headers, redirect, isFallback } =
await this.#resolver.resolve(outgoing);
const { headers, redirect } = await this.#resolver.resolve(outgoing);

@@ -184,10 +179,4 @@ const chunks = [];

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

@@ -194,0 +183,0 @@ });

{
"name": "@podium/client",
"version": "5.2.0-next.4",
"version": "5.2.0-next.5",
"type": "module",

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

"devDependencies": {
"@podium/test-utils": "3.1.0-next.3",
"@podium/test-utils": "3.1.0-next.5",
"@semantic-release/changelog": "6.0.3",

@@ -64,3 +64,3 @@ "@semantic-release/git": "10.0.1",

"eslint-plugin-prettier": "5.1.3",
"express": "4.19.2",
"express": "4.21.1",
"get-stream": "9.0.1",

@@ -74,4 +74,4 @@ "globals": "15.8.0",

"tap": "18.7.2",
"typescript": "5.4.5"
"typescript": "5.6.3"
}
}

@@ -1,2 +0,1 @@

/// <reference types="node" resolution-mode="require"/>
/**

@@ -32,3 +31,2 @@ * @typedef {import('./resource.js').default} PodiumClientResource

* @property {import('./resource.js').RequestFilterOptions} [includeBy] Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
* @property {boolean} [earlyHints=true]
*/

@@ -67,10 +65,10 @@ export default class PodiumClient extends EventEmitter<[never]> {

}
export type PodiumClientResource = import('./resource.js').default;
export type PodiumClientResourceOptions = import('./resource.js').PodiumClientResourceOptions;
export type PodiumClientResponse = import('./response.js').default;
export type PodiumRedirect = import('./http-outgoing.js').PodiumRedirect;
export type PodletManifest = import('@podium/schemas').PodletManifestSchema;
export type PodiumClientResource = import("./resource.js").default;
export type PodiumClientResourceOptions = import("./resource.js").PodiumClientResourceOptions;
export type PodiumClientResponse = import("./response.js").default;
export type PodiumRedirect = import("./http-outgoing.js").PodiumRedirect;
export type PodletManifest = import("@podium/schemas").PodletManifestSchema;
export type PodiumClientOptions = {
name: string;
logger?: import('abslog').AbstractLoggerOptions;
logger?: import("abslog").AbstractLoggerOptions;
retries?: number;

@@ -85,4 +83,4 @@ /**

resolveMax?: number;
httpAgent?: import('http').Agent;
httpsAgent?: import('https').Agent;
httpAgent?: import("http").Agent;
httpsAgent?: import("https").Agent;
};

@@ -117,10 +115,9 @@ export type RegisterOptions = {

*/
excludeBy?: import('./resource.js').RequestFilterOptions;
excludeBy?: import("./resource.js").RequestFilterOptions;
/**
* Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
*/
includeBy?: import('./resource.js').RequestFilterOptions;
earlyHints?: boolean;
includeBy?: import("./resource.js").RequestFilterOptions;
};
import EventEmitter from 'events';
import Metrics from '@metrics/client';

@@ -48,3 +48,3 @@ /**

*/
constructor(options?: PodiumClientHttpOutgoingOptions, reqOptions?: PodiumClientResourceOptions, incoming?: import('@podium/utils').HttpIncoming);
constructor(options?: PodiumClientHttpOutgoingOptions, reqOptions?: PodiumClientResourceOptions, incoming?: import("@podium/utils").HttpIncoming);
set js(value: any);

@@ -57,3 +57,3 @@ get js(): any;

pathname: string;
headers: import('http').IncomingHttpHeaders;
headers: import("http").IncomingHttpHeaders;
query: object;

@@ -110,4 +110,2 @@ };

get redirect(): PodiumRedirect;
set hintsReceived(value: boolean);
get hintsReceived(): boolean;
set redirectable(value: boolean);

@@ -133,2 +131,3 @@ /**

pushFallback(): void;
hintsReceived: boolean;
writeEarlyHints(cb?: () => void): void;

@@ -153,8 +152,8 @@ get [Symbol.toStringTag](): string;

rejectUnauthorized?: boolean;
httpAgent?: import('http').Agent;
httpsAgent?: import('https').Agent;
httpAgent?: import("http").Agent;
httpsAgent?: import("https").Agent;
};
export type PodiumClientResourceOptions = {
pathname?: string;
headers?: import('http').IncomingHttpHeaders;
headers?: import("http").IncomingHttpHeaders;
query?: object;

@@ -184,4 +183,4 @@ };

fallback: string;
js: Array<import('@podium/utils').AssetJs>;
css: Array<import('@podium/utils').AssetCss>;
js: Array<import("@podium/utils").AssetJs>;
css: Array<import("@podium/utils").AssetCss>;
proxy: Record<string, string> | Array<PodletProxySchema>;

@@ -188,0 +187,0 @@ team: string;

@@ -20,6 +20,6 @@ /**

*/
request(url: string, options: PodiumHttpClientRequestOptions): Promise<Pick<import('undici').Dispatcher.ResponseData, 'statusCode' | 'headers' | 'body'>>;
request(url: string, options: PodiumHttpClientRequestOptions): Promise<Pick<import("undici").Dispatcher.ResponseData, "statusCode" | "headers" | "body">>;
}
export type PodiumHttpClientRequestOptions = {
method: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
method: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
json?: boolean;

@@ -30,3 +30,3 @@ rejectUnauthorized?: boolean;

query?: object;
headers?: import('http').IncomingHttpHeaders;
headers?: import("http").IncomingHttpHeaders;
onInfo?: (info: {

@@ -33,0 +33,0 @@ statusCode: number;

@@ -18,3 +18,3 @@ /**

*/
load(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
load(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
/**

@@ -26,3 +26,3 @@ * Saves the podlet's manifest to the cache

*/
save(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
save(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
get [Symbol.toStringTag](): string;

@@ -32,3 +32,3 @@ #private;

export type PodletClientCacheResolverOptions = {
logger?: import('abslog').AbstractLoggerOptions;
logger?: import("abslog").AbstractLoggerOptions;
};

@@ -6,3 +6,2 @@ /**

* @property {import('abslog').AbstractLoggerOptions} [logger]
* @property {boolean} [earlyHints]
*/

@@ -22,3 +21,3 @@ export default class PodletClientContentResolver {

*/
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
resolve(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
get [Symbol.toStringTag](): string;

@@ -29,6 +28,5 @@ #private;

clientName: string;
http?: import('./http.js').default;
logger?: import('abslog').AbstractLoggerOptions;
earlyHints?: boolean;
http?: import("./http.js").default;
logger?: import("abslog").AbstractLoggerOptions;
};
import Metrics from '@metrics/client';

@@ -21,3 +21,3 @@ /**

*/
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
resolve(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
/**

@@ -29,3 +29,3 @@ * Refresh the podlet's cached manifest and fallback

*/
refresh(outgoing: import('./http-outgoing.js').default): Promise<boolean>;
refresh(outgoing: import("./http-outgoing.js").default): Promise<boolean>;
get [Symbol.toStringTag](): string;

@@ -36,5 +36,5 @@ #private;

clientName: string;
logger?: import('abslog').AbstractLoggerOptions;
logger?: import("abslog").AbstractLoggerOptions;
earlyHints?: boolean;
};
import Metrics from '@metrics/client';

@@ -20,3 +20,3 @@ /**

*/
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
resolve(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
get [Symbol.toStringTag](): string;

@@ -27,5 +27,5 @@ #private;

clientName: string;
http?: import('./http.js').default;
logger?: import('abslog').AbstractLoggerOptions;
http?: import("./http.js").default;
logger?: import("abslog").AbstractLoggerOptions;
};
import Metrics from '@metrics/client';

@@ -18,3 +18,3 @@ /**

*/
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
resolve(outgoing: import("./http-outgoing.js").default): Promise<import("./http-outgoing.js").default>;
get [Symbol.toStringTag](): string;

@@ -25,5 +25,5 @@ #private;

clientName: string;
logger?: import('abslog').AbstractLoggerOptions;
http?: import('./http.js').default;
logger?: import("abslog").AbstractLoggerOptions;
http?: import("./http.js").default;
};
import Metrics from '@metrics/client';

@@ -29,3 +29,3 @@ /**

*/
constructor(registry: any, state: import('./state.js').default, options?: PodiumClientResourceOptions);
constructor(registry: any, state: import("./state.js").default, options?: PodiumClientResourceOptions);
get metrics(): Metrics;

@@ -49,3 +49,3 @@ get name(): string;

*/
fetch(incoming: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): Promise<import('./response.js').default>;
fetch(incoming: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): Promise<import("./response.js").default>;
/**

@@ -58,3 +58,3 @@ * Stream the podlet's content, or fallback if the podlet is unavailable.

*/
stream(incoming: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): import('./http-outgoing.js').default;
stream(incoming: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): import("./http-outgoing.js").default;
/**

@@ -67,3 +67,3 @@ * Refresh the podlet's manifest and fallback in the cache.

*/
refresh(incoming?: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): Promise<boolean>;
refresh(incoming?: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): Promise<boolean>;
[inspect](): {

@@ -84,3 +84,3 @@ metrics: Metrics;

export type PodiumClientResourceOptions = {
logger?: import('abslog').AbstractLoggerOptions;
logger?: import("abslog").AbstractLoggerOptions;
clientName: string;

@@ -101,4 +101,4 @@ name: string;

rejectUnauthorized?: boolean;
httpAgent?: import('http').Agent;
httpsAgent?: import('https').Agent;
httpAgent?: import("http").Agent;
httpsAgent?: import("https").Agent;
/**

@@ -105,0 +105,0 @@ * Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.

@@ -42,7 +42,7 @@ /**

headers?: object;
js?: Array<import('@podium/utils').AssetJs>;
css?: Array<import('@podium/utils').AssetCss>;
redirect?: import('./http-outgoing.js').PodiumRedirect | null;
js?: Array<import("@podium/utils").AssetJs>;
css?: Array<import("@podium/utils").AssetCss>;
redirect?: import("./http-outgoing.js").PodiumRedirect | null;
};
declare const inspect: unique symbol;
export {};

@@ -1,2 +0,1 @@

/// <reference types="node" resolution-mode="require"/>
/**

@@ -3,0 +2,0 @@ * @typedef {object} PodiumClientStateOptions

export function isHeaderDefined(headers: object, header: string): boolean;
export function hasManifestChange(item: object): boolean;
export function validateIncoming(incoming?: object): boolean;
export function filterAssets<T extends AssetCss | AssetJs>(scope: "content" | "fallback" | "all", assets: T[]): T[];
export function filterAssets<T extends import("@podium/utils").AssetCss | import("@podium/utils").AssetJs>(scope: "content" | "fallback" | "all", assets: T[]): T[];
export function parseLinkHeaders(headers: any): any[];
export function toPreloadAssetObjects(assetObjects: any): any;
import { AssetCss } from '@podium/utils';
import { AssetJs } from '@podium/utils';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc