UNPKG

nest-ratelimiter

Version:

Distributed consistent flexible NestJS rate limiter based on Redis

18 lines (17 loc) 932 B
import { ExecutionContext } from '@nestjs/common'; import { FactoryProvider, ModuleMetadata } from '@nestjs/common/interfaces'; import { LimiterInfo, LimiterOption } from 'ratelimiter'; export declare const DECORATOR_PARAMS_TOKEN: unique symbol; export type RateLimiterParams = Pick<LimiterOption, 'max' | 'duration'> & { createErrorBody?: CreateErrorBodyFn; } & ({ getId: GetIdFn; } | { id: string; } | object); export type GetIdFn = (context: ExecutionContext) => string | Promise<string>; export type CreateErrorBodyFn = (limit: LimiterInfo) => unknown; export declare const MODULE_PARAMS_TOKEN: unique symbol; export type RateLimiterModuleParams = Partial<RateLimiterParams> & Pick<LimiterOption, 'db'>; export interface RateLimiterModuleParamsAsync extends Pick<ModuleMetadata, 'imports' | 'providers'>, Pick<FactoryProvider<RateLimiterModuleParams | Promise<RateLimiterModuleParams>>, 'useFactory' | 'inject'> { }