import { C as ConcurrencyGuard, j as UnifiedAdmitter, k as UnifiedAxis } from './unified-D0OOwfM-.cjs'; import { C as Clock, D as Decision } from './types-DKirIBQt.cjs'; import { a as CommonAdapterOptions, L as LimiterOrStrategy } from './core-CS9fzc6a.cjs'; import './store-BZNM-FbH.cjs'; /** * SvelteKit adapter. Builds a server `handle` hook that gates every request: on allow it forwards to * `resolve(event)` and copies the standards headers onto the response; on deny it returns a `429` * with `Retry-After`; a fail-closed store outage returns `503`. The limit key defaults to * SvelteKit's `event.getClientAddress()` (the platform-resolved client IP). The `RequestEvent`/ * `Handle` shapes are modeled structurally, so a real `@sveltejs/kit` `Handle` satisfies them with no * dependency. See THROTTLEKIT.md ยงยง14,15. * * Also exposes {@link sveltekitUnifiedAdmission} and {@link sveltekitAdaptiveConcurrency} (0.9.2, * TK-1326) that wrap the resolved Response body for release lifecycle. */ /** The slice of a SvelteKit `RequestEvent` the adapter reads. */ interface SvelteKitRequestEvent { request: Request; /** SvelteKit's platform-resolved client address (respects the adapter's trust configuration). */ getClientAddress(): string; } /** SvelteKit's `resolve(event)` continuation. */ type SvelteKitResolve = (event: SvelteKitRequestEvent) => Response | Promise; /** The input to a SvelteKit `handle` hook. */ interface SvelteKitHandleInput { event: SvelteKitRequestEvent; resolve: SvelteKitResolve; } /** A SvelteKit server `handle` hook. */ type SvelteKitHandle = (input: SvelteKitHandleInput) => Promise; type SvelteKitRateLimitOptions = LimiterOrStrategy & CommonAdapterOptions & { /** Cost of a request in limiter units. A function computes it per event. Default 1. */ cost?: number | ((event: SvelteKitRequestEvent) => number); /** Derive the limit key from the event. Default: `event.getClientAddress()`. */ key?: (event: SvelteKitRequestEvent) => string; /** Observability hook fired on every denial. */ onLimited?: (event: SvelteKitRequestEvent, decision: Decision) => void; /** Observability hook fired when the store throws (before the fail policy is applied). */ onError?: (event: SvelteKitRequestEvent, err: unknown) => void; /** Custom 429 responder. When provided, it fully owns the denial response. */ handler?: (event: SvelteKitRequestEvent, decision: Decision) => Response | Promise; }; /** * Build a SvelteKit `handle` hook that rate-limits requests. * * @example * ```ts * // src/hooks.server.ts * import { sveltekitRateLimit } from "throttlekit/sveltekit"; * import { gcra } from "throttlekit"; * export const handle = sveltekitRateLimit({ strategy: gcra({ limit: 60, periodMs: 60_000 }) }); * ``` */ declare function sveltekitRateLimit(options: SvelteKitRateLimitOptions): SvelteKitHandle; /** Per-axis Decision snapshot from `admitter.lastDecisions()`. */ type AxisSnapshot = Readonly>>; /** Options for {@link sveltekitUnifiedAdmission}. */ type SvelteKitUnifiedAdmissionOptions = Pick & { admitter: UnifiedAdmitter; cost?: number | ((event: SvelteKitRequestEvent) => number); key?: (event: SvelteKitRequestEvent) => string; clock?: Clock; dropOn5xx?: boolean; onLimited?: (event: SvelteKitRequestEvent, decision: Decision, axes: AxisSnapshot) => void; onError?: (event: SvelteKitRequestEvent, err: unknown) => void; handler?: (event: SvelteKitRequestEvent, decision: Decision, axes: AxisSnapshot) => Response | Promise; }; /** Build a SvelteKit `handle` hook enforcing a {@link UnifiedAdmitter}. */ declare function sveltekitUnifiedAdmission(options: SvelteKitUnifiedAdmissionOptions): SvelteKitHandle; /** Options for {@link sveltekitAdaptiveConcurrency}. */ type SvelteKitAdaptiveConcurrencyOptions = Pick & { guard: ConcurrencyGuard; clock?: Clock; dropOn5xx?: boolean; onLimited?: (event: SvelteKitRequestEvent, decision: Decision) => void; handler?: (event: SvelteKitRequestEvent, decision: Decision) => Response | Promise; }; /** Build a SvelteKit `handle` hook enforcing an adaptive {@link ConcurrencyGuard}. */ declare function sveltekitAdaptiveConcurrency(options: SvelteKitAdaptiveConcurrencyOptions): SvelteKitHandle; export { CommonAdapterOptions, LimiterOrStrategy, type SvelteKitAdaptiveConcurrencyOptions, type SvelteKitHandle, type SvelteKitHandleInput, type SvelteKitRateLimitOptions, type SvelteKitRequestEvent, type SvelteKitResolve, type SvelteKitUnifiedAdmissionOptions, sveltekitAdaptiveConcurrency, sveltekitRateLimit, sveltekitUnifiedAdmission };