import type { EponymeCdnProvider, EponymeCdnPurgeRequest } from '../../types/cdn.js'; /** * Kept free of Nitro so it can be exercised on its own: the plugin `eponyme-cdn` wires it to the hooks, * the runtime config and the environment. */ /** A purge the adapter chose not to send, which retrying would not change. */ export declare class EponymeCdnSkip extends Error { } /** A refusal retrying cannot fix, a rejected token for instance. */ export declare class EponymeCdnPermanentError extends Error { } export interface EponymeCdnAdapter { provider: EponymeCdnProvider; /** Tags one call can carry. Larger purges are split. */ maxTagsPerRequest: number; /** * Called synchronously while the triggering request is still in scope, for adapters whose API lives in * the request context. Batches only merge purges that captured the same value. */ capture?: () => unknown; purge: (request: EponymeCdnPurgeRequest, captured: unknown) => Promise; } /** What `@vercel/functions` reads, read here directly so the package is not a dependency. */ export interface VercelRequestContext { waitUntil?: (promise: Promise) => void; addCacheTag?: (tag: string | string[]) => Promise; purge?: { invalidateByTag: (tag: string | string[]) => Promise; dangerouslyDeleteByTag: (tag: string | string[], options?: Record) => Promise; }; } export declare function getVercelRequestContext(): VercelRequestContext | undefined; export interface VercelAdapterOptions { /** `invalidate` marks entries stale and serves them once more while they regenerate; `delete` drops them. */ mode?: 'invalidate' | 'delete'; /** Whether the deployment runs on Vercel. Defaults to `process.env.VERCEL`. */ onVercel?: () => boolean; } export declare function createVercelAdapter({ mode, onVercel }?: VercelAdapterOptions): EponymeCdnAdapter; export interface CloudflareAdapterOptions { zoneId: string; apiToken: string; /** Defaults to the global `fetch`. */ fetch?: typeof fetch; timeoutMs?: number; } export declare function createCloudflareAdapter({ zoneId, apiToken, fetch: fetcher, timeoutMs }: CloudflareAdapterOptions): EponymeCdnAdapter; export declare function createCustomAdapter(callPurgeHook: (request: EponymeCdnPurgeRequest) => Promise): EponymeCdnAdapter; export interface EponymeCdnPurgerOptions { /** How long a purge waits for others to merge with, in milliseconds. */ debounceMs?: number; /** Further attempts after a failed one. */ retries?: number; /** Delay before the first retry, doubled each time. */ retryDelayMs?: number; /** Longest an attempt may take before it counts as failed. */ timeoutMs?: number; onPurged?: (request: EponymeCdnPurgeRequest) => void | Promise; onFailed?: (request: EponymeCdnPurgeRequest, error: unknown, attempts: number) => void | Promise; onSkipped?: (request: EponymeCdnPurgeRequest, reason: string) => void; logger?: Pick; } /** * Merges the purges that arrive within `debounceMs` of each other into one call, retries a failed call, * and never rejects: a purge that does not go through leaves the CDN to its expiry, it does not undo a * write that already succeeded. */ export declare class EponymeCdnPurger { private readonly adapter; private readonly batches; private readonly options; constructor(adapter: EponymeCdnAdapter, options?: EponymeCdnPurgerOptions); get provider(): EponymeCdnProvider; /** Resolves once the batch this request joined was sent, or given up on. */ enqueue(request: EponymeCdnPurgeRequest): Promise; /** Sends every pending batch now. */ flush(): Promise; private send; private attempt; private notify; }