/// /** * Config for the parser * * @property {boolean | string[]} allowSurrogateDelegation - Allows Surrogate Delegation * If boolean and the Request has valid Surrogate Delegation headers then no parsing will take place and requests will be sent onwards * If Array of strings then each string is treated as an IP Address. If the originally connecting IP matches one of those IPs then Delegation will happen * @property {string[]} contentTypes - Array of strings of content types that the parser should parse for ESI Tags * Note: That these are case sensitive. See - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type * @property {boolean} disableThirdPartyIncludes - Whether or not to enable third party includes (includes from other domains) * @property {number} [recursionLimit] - Levels of recursion the parser is allowed to include before bailing out * think includes that include themselves causing recursion * @default 10 * @property {string} surrogateControlHeader - Name of the header that the library will check for Surrogate-Control * We allow customisation as Cloudflare priorities Surrogate-Control over Cache-Control * @property {string[]} thirdPartyIncludesDomainWhitelist - If third party includes are disabled you can white list them by including domains here * @property {string[]} varsCookieBlacklist - Array of strings of cookies that will be blacklisted from being expanded in esi VARs. */ export type ESIConfig = { allowSurrogateDelegation?: boolean | string[]; contentTypes?: string[]; disableThirdPartyIncludes?: boolean; recursionLimit?: number; surrogateControlHeader?: string; thirdPartyIncludesDomainWhitelist?: string[] | null; varsCookieBlacklist?: string[] | null; }; export type ESIVars = { headers: { [key: string]: string; }; method: string; esiArgs: URLSearchParams; url: URL; }; /** * ESI Event Data for the Current Request * * @property {ESIConfig} config - ESIConfig when class was created * @property {object} headers - All headers of the request in uppercase * @property {string} method - Method of the request * @property {URLSearchParams} esiArgs - Any ESI Arguments extracted from the URL Search params of the original request * Will be a URLSearchParam encoded object * @property {customESIVars} customVars - If a custom ESI Vars function is supplied this will be the result of that function * @property {URL} url - URL Object of the Request with ESI Args removed * @property {Request} request - Request object after ESI Args have been removed * @property {number} recursion - Recursion level we're currently at */ export type ESIEventData = { /** * {ESIConfig} for the current Request */ config: FullESIConfig; /** * All headers of the current Request in {Object} * All headers are in uppercase and - is converted to _ */ headers: { [key: string]: string; }; /** * Request Method */ method: string; /** * Any ESI Arguments */ esiArgs: URLSearchParams; /** * If a custom ESI Vars function is supplied this will be the result of that function * * @default false */ customVars?: customESIVars; /** * {URL} Object of the Request with any ESI Args removed */ url: URL; /** * Mutatable {Request} object with the ESI Args removed */ request: Request; /** * Level of recursion the function is currently at * * @default 0 */ recursion: number; }; export type customESIVars = { [key: string]: string | { [key: string]: string; }; }; export type customESIVarsFunction = (request: Request) => Promise | customESIVars; export type fetchFunction = (request: Request, ctx: Request[]) => Promise; export type postBodyFunction = () => void | Promise; export type FullESIConfig = Required; export declare class esi { options: FullESIConfig; esiFunction?: customESIVarsFunction; fetcher: fetchFunction; postBodyFunction?: postBodyFunction; ctx: Request[]; constructor(options?: ESIConfig, customESIFunction?: customESIVarsFunction, fetcher?: fetchFunction, ctx?: Request[], postBodyFunction?: postBodyFunction); parse(origRequest: Request, recursion?: number): Promise; handleESI(eventData: ESIEventData, text: string): Promise; handleTEXT(eventData: ESIEventData, text: string): Promise; streamBody(eventData: ESIEventData, readable: ReadableStream, writable: WritableStream): void; validContentType(response: Response): boolean; validSurrogateControl(response: Response): boolean; } export declare const esiArgsPrefix = "esi_"; /** * Returns Processor Token string for Surrogate headers * eg "ESI" * * @returns {string} - supported procesor token */ export declare function getProcessorToken(): string; /** * Returns Processor Version as a number for Surrogate headers * eg 1.0 * * @returns {number} - processor supported version */ export declare function getProcessorVersion(): number; /** * Returns Processor Version as a string for Surrogate headers * eg "1.0" * * @returns {string} - processor supported version */ export declare function getProcessorVersionString(): string; export default esi;