@podium/client
Version:
Client for fetching podium component fragments over HTTP.
110 lines (109 loc) • 4.55 kB
TypeScript
/**
* @typedef {object} RequestFilterOptions
* @property {string[]} [deviceType] List of values for the `x-podium-device-type` HTTP request header.
*/
/**
* @typedef {object} PodiumClientResourceOptions
* @property {import('abslog').AbstractLoggerOptions} [logger]
* @property {string} clientName
* @property {string} name
* @property {string} uri To the podlet's `manifest.json`
* @property {number} timeout In milliseconds
* @property {number} maxAge
* @property {number} [retries]
* @property {boolean} [throwable]
* @property {boolean} [redirectable]
* @property {boolean} [rejectUnauthorized]
* @property {import('http').Agent} [httpAgent]
* @property {import('https').Agent} [httpsAgent]
* @property {RequestFilterOptions} [excludeBy] Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
* @property {RequestFilterOptions} [includeBy] Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
*/
export default class PodiumClientResource {
/**
* @constructor
* @param {import('ttl-mem-cache').default} registry
* @param {import('./state.js').default} state
* @param {PodiumClientResourceOptions} options
*/
constructor(registry: any, state: import("./state.js").default, options?: PodiumClientResourceOptions);
get metrics(): Metrics;
get name(): string;
get uri(): string;
/**
* Fetch the podlet's content, or fallback if the podlet is unavailable.
* The podlet response includes references to its CSS and JS assets which should be included in the final HTML document.
*
* @param {import('@podium/utils').HttpIncoming} incoming Instance of HttpIncoming
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}] Optional parameters to the HTTP request, such as query parameters or HTTP request headers.
* @returns {Promise<import('./response.js').default>}
*
* @example
* ```js
* const incoming = res.locals.podium; // Express server example
* const header = await headerPodlet.fetch(incoming);
* incoming.podlets = [header]; // Register the podlet's JS and CSS assets with the layout's HTML template
* ```
*/
fetch(incoming: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): Promise<import("./response.js").default>;
/**
* Stream the podlet's content, or fallback if the podlet is unavailable.
*
* @param {import('@podium/utils').HttpIncoming} incoming
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}]
* @returns {import('./http-outgoing.js').default}
*/
stream(incoming: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): import("./http-outgoing.js").default;
/**
* Refresh the podlet's manifest and fallback in the cache.
*
* @param {import('@podium/utils').HttpIncoming} [incoming]
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}]
* @returns {Promise<boolean>} `true` if succesful
*/
refresh(incoming?: import("@podium/utils").HttpIncoming, reqOptions?: import("./http-outgoing.js").PodiumClientResourceOptions): Promise<boolean>;
[inspect](): {
metrics: Metrics;
name: string;
uri: string;
};
get [Symbol.toStringTag](): string;
#private;
}
export type RequestFilterOptions = {
/**
* List of values for the `x-podium-device-type` HTTP request header.
*/
deviceType?: string[];
};
export type PodiumClientResourceOptions = {
logger?: import("abslog").AbstractLoggerOptions;
clientName: string;
name: string;
/**
* To the podlet's `manifest.json`
*/
uri: string;
/**
* In milliseconds
*/
timeout: number;
maxAge: number;
retries?: number;
throwable?: boolean;
redirectable?: boolean;
rejectUnauthorized?: boolean;
httpAgent?: import("http").Agent;
httpsAgent?: import("https").Agent;
/**
* Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
*/
excludeBy?: RequestFilterOptions;
/**
* Used by `fetch` to conditionally skip fetching the podlet content based on values on the request.
*/
includeBy?: RequestFilterOptions;
};
import Metrics from '@metrics/client';
declare const inspect: unique symbol;
export {};