import express from 'express'; type CacheResponseConfig = { endpoint: string; ignoreQueryParams?: string[]; ttlSeconds?: number; }; type CacheRule = { ignoreQueryParams?: string[]; ttlSeconds?: number; }; /** * Generates a stable cache key based on the URL and caching rules. * Sorts query parameters to ensure consistency. */ export declare function buildCacheKeyFromRule(url: URL, cfg: CacheRule): string; /** * Determines if a request should be served from cache and returns the cache key and TTL. * Only GET requests matching configured endpoints are candidates for caching. */ export declare function getCacheInfoForRequest(method: string | undefined, url: URL, cacheRulesByKey: Map): { key: string; ttlSeconds: number; } | null; type CachedEntry = { status: number; headers: Record; bodyB64: string; }; /** * Filters headers from the incoming request to include only those safe/allowed to forward upstream. * Ensures a default Accept header is present. */ export declare function filterOutgoingRequestHeaders(reqHeaders: express.Request['headers']): Headers; /** * Filters headers from the upstream response to exclude hop-by-hop headers * and others that should be recomputed by the express server (like content-length). */ export declare function filterIncomingResponseHeaders(headers: Headers): Record; /** * Reads the request body into a buffer for forwarding. * Returns undefined for GET/HEAD requests. */ export declare function readRequestBody(req: express.Request): Promise; /** * Determines if a proxy error should be suppressed from logs. * PostHog 502 Bad Gateway errors are common and can be noisy. */ export declare function shouldSuppressProxyError(error: unknown, endpoint?: string): boolean; /** * Fetches the upstream resource, optionally utilizing the cache. * * This function encapsulates the logic for: * 1. Performing the upstream fetch. * 2. Caching successful (status 200) responses if cacheInfo is provided. * 3. Handling cases where the response is not cacheable but should still be returned. * * @param endpoint The upstream URL to fetch. * @param method The HTTP method to use. * @param headers The headers to forward. * @param body The request body (if any). * @param cacheInfo Cache configuration (key, TTL) or null to skip caching. * @returns A Promise resolving to the CachedEntry. */ export declare function fetchUpstreamWithCache(endpoint: string, method: string, headers: Headers, body: Buffer | undefined, cacheInfo: { key: string; ttlSeconds: number; } | null): Promise; /** * Creates an Express request handler that proxies requests to a target base URL. * Supports caching for specific endpoints to mitigate rate limiting. * * Caching: * PostHog rate limits by IP. Since this is a server-side proxy and we don't forward client IPs, * all requests appear to come from our server's IP, triggering their limits. Caching high-volume, * non-personalized endpoints (like configuration) helps stay within these limits. */ export declare function createProxyHandler(opts: { targetBase: string; stripPrefix: string; cacheConfig?: CacheResponseConfig[]; }): express.RequestHandler; export type AnalyticsRouterOptions = { posthogKey: string; ingestBase?: string; assetsBase?: string; }; /** * Creates an Express router configured to proxy analytics requests to PostHog. * Sets up routes for static assets and ingestion endpoints. */ export declare function makeAnalyticsRouter(options: AnalyticsRouterOptions): express.Router; export {}; //# sourceMappingURL=router.d.ts.map