express-rate-limiter-ts
Version:
A powerful, flexible and modern rate limiter middleware for Express.js written in TypeScript.
32 lines (31 loc) • 950 B
TypeScript
import { IRateLimitStore, RateLimitInfo, RateLimitStats } from '../types/rateLimiter';
export declare class PostgresStore implements IRateLimitStore {
private client;
private windowMs;
constructor(options: {
connectionString: string;
windowMs: number;
});
private connect;
incr(key: string): Promise<RateLimitInfo>;
get(key: string): Promise<{
count: number;
resetTime: number;
} | undefined>;
reset(key: string): Promise<void>;
recordStat(route: string): Promise<void>;
getStats(): Promise<RateLimitStats>;
ban(key: string, seconds: number, reason: string): Promise<void>;
isBanned(key: string): Promise<{
banned: boolean;
banExpiresAt?: Date;
reason?: string;
}>;
getBanned(): Promise<{
[key: string]: {
banExpiresAt: Date;
reason: string;
};
}>;
unban(key: string): Promise<void>;
}