import { Buffer } from 'node:buffer'; /** * Server-side caches for upstream proxy fetches. * * ## Why * * Proxy URLs arriving from the client carry per-request auth artefacts (`sig`, * `_pt`, `_ts`) that change across renders. CDNs key on full URL so each * rotation produces a unique edge cache entry and upstream origins take the hit * on every render. Caching the *upstream response* here — keyed on the inner * resource URL (or normalized param set) — dedupes those fetches across every * request that resolves to the same upstream, regardless of how the caller * authenticated. * * Safe because `withSigning` runs before any cache path: unsigned requests 403 * before they can do a cache lookup. Cache stores hold only responses produced * from legitimately-authenticated requests. * * ## Binary payloads * * Image/blob responses are stored as base64 strings so they round-trip cleanly * through every unstorage driver (memory, filesystem, redis, cloudflare kv). * The 33% size overhead is tolerable; the alternative is relying on each driver * to preserve Buffer/ArrayBuffer which is not universal. */ export interface CachedBinaryResponse { base64: string; contentType: string | null; } export interface CachedBinaryFetchOptions { headers?: Record; timeout?: number; redirect?: 'follow' | 'manual'; ignoreResponseError?: boolean; } export interface CachedBinaryResult extends CachedBinaryResponse { body: Buffer; status: number; } /** * Cache upstream binary/image fetches. Returns a helper that restores the * response body as a Buffer so the handler can pipe it straight to the client. */ export declare function createCachedBinaryFetch(name: string, maxAge: number): (url: string, opts?: CachedBinaryFetchOptions) => Promise; /** * Cache upstream JSON/text fetches. `getKey` is caller-controlled so handlers * can normalize on whichever inner params identify the resource (tweet ID, * post URL, query hash). */ export declare function createCachedJsonFetch(name: string, maxAge: number, getKey: (url: string, opts?: { headers?: Record; }) => string): (url: string, opts?: { headers?: Record; timeout?: number; }) => Promise;