import { CookieRateLimiter, type CookieRateLimiterOptions } from './limiters/cookieRateLimiter.js'; import type { RequestEvent } from '@sveltejs/kit'; import { type HashFunction } from './hashFunction.js'; import { type RateLimiterPlugin } from './limiters/rateLimiterPlugin.js'; import { type Rate } from './rate.js'; import type { RateLimiterStore } from './stores/rateLimiterStore.js'; export type RateLimiterOptions = Partial<{ plugins: RateLimiterPlugin[]; store: RateLimiterStore; maxItems: number; onLimited: (event: RequestEvent, reason: 'rate' | 'rejected') => void | boolean | Promise; /** * @deprecated Add the IP/IPUA/cookie rates to the main object, no need for "rates". */ rates: { /** * @deprecated Add the IP option to the main object, no need for "rates". */ IP?: Rate; /** * @deprecated Add the IPUA option to the main object, no need for "rates". */ IPUA?: Rate; /** * @deprecated Add cookie option to the main object, no need for "rates". */ cookie?: CookieRateLimiterOptions; }; IP: Rate | Rate[]; IPUA: Rate | Rate[]; cookie: CookieRateLimiterOptions; hashFunction: HashFunction; }>; export declare class RateLimiter { private readonly store; private readonly plugins; private readonly onLimited; private readonly hashFunction; readonly cookieLimiter: CookieRateLimiter | undefined; /** * Check if a request event is rate limited. * @param {RequestEvent} event * @returns {Promise} true if request is limited, false otherwise */ isLimited(event: [Extra] extends [never] ? RequestEvent : { missing_extraData: Extra; }): Promise; /** * Check if a request event is rate limited, supplying extra data that will be available for plugins. * @param {RequestEvent} event * @returns {Promise} true if request is limited, false otherwise */ isLimited(event: RequestEvent, extraData: Extra): Promise; /** * Clear all rate limits. */ clear(): Promise; /** * Check if a request event is rate limited. * @param {RequestEvent} event * @returns {Promise} Rate limit status for the event. */ check(event: RequestEvent, extraData?: Extra): Promise<{ limited: false; } | { limited: true; reason: 'IP' | 'IPUA' | 'cookie' | number; }>; /** * Check if a request event is rate limited. * @param {RequestEvent} event * @returns {Promise} true if request is limited, false otherwise */ protected _isLimited(event: RequestEvent, extraData: Extra): Promise<{ limited: false; hash: string | null; ttl: number; } | { limited: true; hash: string | null; ttl: number; reason: 'IP' | 'IPUA' | 'cookie' | number; }>; protected limitReason(plugin: RateLimiterPlugin, index: number): 'IP' | 'IPUA' | 'cookie' | number; constructor(options?: RateLimiterOptions); }