export interface EponymeRateLimitPolicy { limit: number; windowMs: number; } export interface EponymeRateLimitResult { allowed: boolean; limit: number; remaining: number; retryAfterSeconds: number; resetAt: Date; } interface PrismaEponymeRateLimitRow { key: string; count: number; expiresAt: Date | string; } export interface PrismaEponymeRateLimitClient { eponymeRateLimit: { upsert(args: { where: { key: string; }; create: { key: string; count: number; expiresAt: Date; }; update: { count: { increment: number; }; }; }): Promise; deleteMany(args: { where: { expiresAt: { lte: Date; }; }; }): Promise<{ count: number; }>; findUnique(args: { where: { key: string; }; }): Promise; }; } /** Counts one hit and reports the new total for its window. */ export interface EponymeRateLimitCounter { /** New count for `key`, which must expire on its own after `ttlMs`. */ increment(key: string, ttlMs: number): Promise; /** Current count for `key` without counting a hit, `0` when the window has none. */ read(key: string): Promise; } /** * Fixed windows shared by every Nitro instance, counted in Redis when one is wired and in PostgreSQL * otherwise. */ export declare class EponymeRateLimitService { private readonly client; private readonly counter?; private nextCleanupAt; private readonly refused; constructor(client: PrismaEponymeRateLimitClient, counter?: EponymeRateLimitCounter | undefined); /** Fails fast at boot when the rate-limit migration or Prisma delegate is missing. */ verify(now?: Date): Promise; consume(scope: string, policy: EponymeRateLimitPolicy, now?: Date): Promise; /** * Reports whether `scope` has already used up its window, without counting a hit. A caller that counts * failures only, such as the per-account login limit, checks this before doing the work it guards. */ peek(scope: string, policy: EponymeRateLimitPolicy, now?: Date): Promise; private read; private isRefused; private remember; private count; private countInDatabase; } /** * The subset of an `ioredis` client this needs, declared structurally so the module never depends on * `ioredis`: the application installs it for the unstorage driver, and Eponyme only ever sees what the * mount hands back. */ export interface EponymeRedisRateLimitClient { incr(key: string): Promise; pexpire(key: string, milliseconds: number): Promise; get(key: string): Promise; } /** Counts in Redis, under `:`. */ export declare function createEponymeRedisRateLimitCounter(client: EponymeRedisRateLimitClient, prefix: string): EponymeRateLimitCounter; export {};