File: /var/www/quadcode.com/node_modules/sveltekit-rate-limiter/dist/server/index.d.ts
import type { Cookies, RequestEvent } from '@sveltejs/kit';
export type RateUnit = 'ms' | '100ms' | '250ms' | '500ms' | 's' | '2s' | '5s' | '10s' | '15s' | '30s' | '45s' | 'm' | '15m' | '30m' | 'h' | '2h' | '6h' | '12h' | 'd';
export type Rate = [number, RateUnit];
export interface RateLimiterStore {
add: (hash: string, unit: RateUnit) => Promise<number>;
clear: () => Promise<void>;
}
export interface RateLimiterPlugin {
hash: (event: RequestEvent) => Promise<string | boolean | null>;
get rate(): Rate;
}
type CookieSerializeOptions = NonNullable<Parameters<Cookies['set']>[2]>;
type CookieRateLimiterOptions = {
name: string;
secret: string;
rate: Rate;
preflight: boolean;
serializeOptions?: CookieSerializeOptions;
hashFunction?: HashFunction;
};
declare class CookieRateLimiter implements RateLimiterPlugin {
readonly rate: Rate;
private readonly cookieOptions;
private readonly secret;
private readonly requirePreflight;
private readonly cookieId;
private readonly hashFunction;
constructor(options: CookieRateLimiterOptions);
hash(event: RequestEvent): Promise<string | false>;
preflight(event: RequestEvent): Promise<string>;
private userIdFromCookie;
}
type HashFunction = (input: string) => Promise<string>;
export type RateLimiterOptions = Partial<{
plugins: RateLimiterPlugin[];
store: RateLimiterStore;
maxItems: number;
onLimited: (event: RequestEvent, reason: 'rate' | 'rejected') => Promise<void | boolean> | void | boolean;
/**
* @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;
IPUA?: 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;
static TTLTime(unit: RateUnit): number;
/**
* Check if a request event is rate limited.
* @param {RequestEvent} event
* @returns {Promise<boolean>} true if request is limited, false otherwise
*/
isLimited(event: RequestEvent): Promise<boolean>;
/**
* Clear all rate limits.
*/
clear(): Promise<void>;
/**
* Check if a request event is rate limited.
* @param {RequestEvent} event
* @returns {Promise<boolean>} true if request is limited, false otherwise
*/
protected _isLimited(event: RequestEvent): Promise<{
limited: boolean;
hash: string | null;
unit: RateUnit;
}>;
constructor(options?: RateLimiterOptions);
}
export declare class RetryAfterRateLimiter extends RateLimiter {
private readonly retryAfter;
constructor(options?: RateLimiterOptions, retryAfterStore?: RateLimiterStore);
private static toSeconds;
private static unitToSeconds;
/**
* Clear all rate limits.
*/
clear(): Promise<void>;
/**
* Check if a request event is rate limited.
* @param {RequestEvent} event
* @returns {Promise<limited: boolean, retryAfter: number>} Rate limit status for the event.
*/
check(event: RequestEvent): Promise<{
limited: boolean;
retryAfter: number;
}>;
}
export {};