@podium/client
Version:
Client for fetching podium component fragments over HTTP.
180 lines (179 loc) • 5.73 kB
TypeScript
/**
* @typedef {object} PodiumClientHttpOutgoingOptions
* @property {string} name
* @property {string} uri To the podlet's `manifest.json`
* @property {number} timeout In milliseconds
* @property {number} maxAge
* @property {number} [retries=4]
* @property {boolean} [throwable=false]
* @property {boolean} [redirectable=false]
* @property {boolean} [rejectUnauthorized=true]
*/
/**
* @typedef {object} PodiumClientResourceOptions
* @property {string} [pathname]
* @property {import('http').IncomingHttpHeaders} [headers]
* @property {object} [query]
*/
/**
* @typedef {object} PodiumRedirect
* @property {number} statusCode;
* @property {string} location;
*/
/**
* @typedef {object} PodletProxySchema
* @property {string} target
* @property {string} name
*/
/**
* @typedef {object} PodletManifest Similar to the schema's manifest, but with instances of AssetCss and AssetJs from `@podium/utils` and default values.
* @property {string} name
* @property {string} version
* @property {string} content
* @property {string} fallback
* @property {Array<import('@podium/utils').AssetJs>} js
* @property {Array<import('@podium/utils').AssetCss>} css
* @property {Record<string, string> | Array<PodletProxySchema>} proxy
* @property {string} team
*/
export default class PodletClientHttpOutgoing extends PassThrough {
/**
* @constructor
* @param {PodiumClientHttpOutgoingOptions} options
* @param {PodiumClientResourceOptions} [reqOptions]
* @param {import('@podium/utils').HttpIncoming} [incoming]
*/
constructor(options?: PodiumClientHttpOutgoingOptions, reqOptions?: PodiumClientResourceOptions, incoming?: import("@podium/utils").HttpIncoming);
set js(value: any);
get js(): any;
set css(value: any);
get css(): any;
get rejectUnauthorized(): boolean;
get reqOptions(): {
pathname: string;
headers: import("http").IncomingHttpHeaders;
query: object;
};
get throwable(): boolean;
set manifest(obj: PodletManifest);
get manifest(): PodletManifest;
set fallback(value: any);
get fallback(): any;
get timeout(): number;
set success(value: boolean);
get success(): boolean;
get context(): Record<string, unknown>;
set headers(value: {});
get headers(): {};
set maxAge(value: number);
get maxAge(): number;
set status(value: "empty" | "fresh" | "cached" | "stale");
/**
* What status the manifest is in. This is used to tell what actions need to
* be performed throughout the resolving process to complete a request.
*
* The different statuses can be:
* - `"empty"` - there is no manifest available - we are in process of fetching it
* - `"fresh"` - the manifest has been fetched but is not stored in cache yet
* - `"cached"` - the manifest was retrieved from cache
* - `"stale"` - the manifest is outdated, a new manifest needs to be fetched
*/
get status(): "empty" | "fresh" | "cached" | "stale";
get name(): string;
get manifestUri(): string;
get fallbackUri(): string;
get contentUri(): string;
/**
* Kill switch for breaking the recursive promise chain in case it is never able to completely resolve.
* This is true if the number of recursions matches the threshold.
*/
get kill(): boolean;
/**
* Set the number of recursions before the request should be {@link kill}ed
*/
set recursions(value: number);
/**
* The number of recursions before the request should be {@link kill}ed
*/
get recursions(): number;
set redirect(value: PodiumRedirect);
/**
* When {@link redirectable} is `true` this is populated with redirect information so you can send a redirect response to the browser from your layout.
*
* @see https://podium-lib.io/docs/layout/handling_redirects
*/
get redirect(): PodiumRedirect;
set redirectable(value: boolean);
/**
* Whether the podlet can signal redirects to the layout.
*
* @see https://podium-lib.io/docs/layout/handling_redirects
*/
get redirectable(): boolean;
/**
* True if the client has returned the podlet's fallback.
*
* @example
*
* ```js
* if (outgoing.isFallback) console.log("Fallback!");
* ```
*
* @see https://podium-lib.io/docs/podlet/fallbacks
*/
get isFallback(): boolean;
pushFallback(): void;
hintsReceived: boolean;
writeEarlyHints(cb?: () => void): void;
get [Symbol.toStringTag](): string;
#private;
}
export type PodiumClientHttpOutgoingOptions = {
name: string;
/**
* To the podlet's `manifest.json`
*/
uri: string;
/**
* In milliseconds
*/
timeout: number;
maxAge: number;
retries?: number;
throwable?: boolean;
redirectable?: boolean;
rejectUnauthorized?: boolean;
};
export type PodiumClientResourceOptions = {
pathname?: string;
headers?: import("http").IncomingHttpHeaders;
query?: object;
};
export type PodiumRedirect = {
/**
* ;
*/
statusCode: number;
/**
* ;
*/
location: string;
};
export type PodletProxySchema = {
target: string;
name: string;
};
/**
* Similar to the schema's manifest, but with instances of AssetCss and AssetJs from `@podium/utils` and default values.
*/
export type PodletManifest = {
name: string;
version: string;
content: string;
fallback: string;
js: Array<import("@podium/utils").AssetJs>;
css: Array<import("@podium/utils").AssetCss>;
proxy: Record<string, string> | Array<PodletProxySchema>;
team: string;
};
import { PassThrough } from 'stream';