import * as z from 'zod/mini'; import * as Store from './Store.js'; /** Zod schemas owned by the rate-limit module. */ export declare namespace schema { /** A rate-limit policy; the source of truth for {@link Limit}. */ const Limit: z.ZodMiniObject<{ limit: z.ZodMiniNumber; period: z.ZodMiniUnion, z.ZodMiniLiteral<"second">]>; }, z.core.$strip>; } /** Rate-limit policy. */ export type Limit = z.output; /** Result returned by a rate-limit store. */ export type Result = { /** Whether the request is within quota. */ allowed: boolean; /** Limit applied to the request. */ limit: number; /** Requests remaining in the active window. */ remaining: number; /** Reset timestamp in Unix seconds. */ reset: number; }; /** Rate-limit store. */ export type RateLimitStore = { /** Consumes one request from the active quota window. */ consume(options: RateLimitStore.ConsumeOptions): Promise; }; export declare namespace RateLimitStore { /** Options for consuming one request from a rate-limit store. */ type ConsumeOptions = { /** Quota key. */ key: string; /** Rate-limit policy. */ limit: Limit; }; } /** * Creates a fixed-window rate-limit store over a counter {@link Store.Store}. * * Each consume is a single `Store.increment`, so a backend with a native * counter (e.g. a Durable Object) is one atomic round trip; backends without * one fall back to get + put, acceptable for dev/in-process stores only. * The storage key includes the fixed-window bucket, so backend latency cannot * carry a previous count into a later window. */ export declare function memory(options?: memory.Options): RateLimitStore; export declare namespace memory { /** Options for creating an in-memory fixed-window rate-limit store. */ type Options = { /** Store used to persist counters. */ store?: Store.Store | undefined; /** Clock used to calculate fixed windows. */ now?: (() => Date) | undefined; }; } /** Cloudflare rate-limit binding (per-colo counters). */ export type Binding = { /** Consumes one request; `success: false` when the key is over quota. */ limit(options: { key: string; }): Promise<{ success: boolean; }>; }; /** * Layered edge rate limit over Cloudflare rate-limit bindings. Returns a 429 * when any configured layer denies; fails open when a binding errors. */ export declare function edge(request: Request, options: edge.Options): Promise; export declare namespace edge { /** Layers applied by {@link edge}; omitted layers are skipped. */ type Options = { /** Per-network backstop; catches clients rotating addresses within one ASN. */ asn?: Binding | undefined; /** Fixed-key circuit breaker capping total throughput per colo. */ global?: Binding | undefined; /** Per-client limit, keyed by IPv4 address or IPv6 /64 prefix. */ ip?: Binding | undefined; }; } /** Normalizes an IPv4 address or IPv6 /64 prefix for per-client quotas. */ export declare function normalizeIp(ip: string): string; export { type RateLimitStore as Store }; //# sourceMappingURL=RateLimit.d.ts.map