22// SPDX-License-Identifier: MIT
33
44import type { NextFunction , Request , Response } from 'express'
5- import type { Store } from 'express-rate-limit'
5+ import type { Options as ExpressRateLimitOptions , Store } from 'express-rate-limit'
6+ import type { RedisClientType } from 'redis'
67import type { ICache } from '../providers/caching'
78import type { Logger } from '../providers/logging'
89
@@ -33,7 +34,7 @@ export interface ExtendedRateLimitConfig extends LegacyRateLimitConfig {
3334/** Redis-specific configuration for rate limiting */
3435export interface RedisRateLimitConfig {
3536 /** Redis client instance */
36- client : any
37+ client : RedisClientType
3738 /** Prefix for Redis keys used by the rate limiter */
3839 prefix : string
3940}
@@ -67,7 +68,7 @@ export type RateLimitMiddleware = (req: Request, res: Response, next: NextFuncti
6768/** Base rate limiter class that provides rate limiting functionality using express-rate-limit */
6869declare class RateLimiter {
6970 /** Configuration options for the rate limiter */
70- protected options : any
71+ protected options : RateLimiterOptions
7172
7273 /** Logger instance for rate limiter operations */
7374 protected logger : Logger
@@ -80,7 +81,7 @@ declare class RateLimiter {
8081 *
8182 * @param opts - Configuration options for the rate limiter
8283 */
83- constructor ( opts : any )
84+ constructor ( opts : RateLimiterOptions )
8485
8586 /**
8687 * Initializes the rate limiter with optional store
@@ -104,20 +105,20 @@ declare class RateLimiter {
104105 * @param store - Optional store for rate limit data persistence
105106 * @returns Options object for express-rate-limit
106107 */
107- static buildOptions ( config : any , store ?: Store ) : any
108+ static buildOptions ( config : RateLimitConfig , store ?: Store ) : Partial < ExpressRateLimitOptions >
108109}
109110
110111/** Redis-based rate limiter that extends RateLimiter with Redis persistence */
111112declare class RedisBasedRateLimiter extends RateLimiter {
112113 /** Redis client instance */
113- private _client : any
114+ private _client : RedisClientType | undefined
114115
115116 /**
116117 * Creates a new RedisBasedRateLimiter instance
117118 *
118119 * @param opts - Configuration options including Redis client
119120 */
120- constructor ( opts : any )
121+ constructor ( opts : RateLimiterOptions )
121122
122123 /**
123124 * Initializes the Redis-based rate limiter
@@ -134,13 +135,13 @@ declare class RedisBasedRateLimiter extends RateLimiter {
134135 * @param config - Redis configuration with prefix
135136 * @returns Redis store instance for express-rate-limit
136137 */
137- static buildRedisStore ( client : any , config : any ) : Store
138+ static buildRedisStore ( client : RedisClientType , config : RedisRateLimitConfig ) : Store
138139}
139140
140141/** Abstract base class for middleware delegates that create rate limiting middleware asynchronously */
141142declare abstract class AbstractMiddlewareDelegate {
142143 /** Configuration options for the middleware delegate */
143- protected options : any
144+ protected options : RateLimiterFactoryOptions
144145
145146 /** Logger instance for middleware operations */
146147 protected logger : Logger
@@ -153,7 +154,7 @@ declare abstract class AbstractMiddlewareDelegate {
153154 *
154155 * @param opts - Configuration options for the middleware delegate
155156 */
156- constructor ( opts : any )
157+ constructor ( opts : RateLimiterFactoryOptions )
157158
158159 /**
159160 * Gets the rate limiting middleware function
@@ -203,7 +204,7 @@ declare class BatchApiMiddlewareDelegate extends AbstractMiddlewareDelegate {
203204 * @param opts - Configuration options for the rate limiter
204205 * @returns RateLimiter or RedisBasedRateLimiter instance
205206 */
206- declare function createRateLimiter ( opts : any ) : RateLimiter | RedisBasedRateLimiter
207+ declare function createRateLimiter ( opts : RateLimiterOptions ) : RateLimiter | RedisBasedRateLimiter
207208
208209/**
209210 * Builds rate limiter options from configuration
@@ -214,7 +215,12 @@ declare function createRateLimiter(opts: any): RateLimiter | RedisBasedRateLimit
214215 * @param logger - Logger instance
215216 * @returns Rate limiter options
216217 */
217- declare function buildOpts ( config : LegacyRateLimitConfig , cachingService : ICache , prefix : string , logger ?: Logger ) : any
218+ declare function buildOpts (
219+ config : LegacyRateLimitConfig ,
220+ cachingService : ICache ,
221+ prefix : string ,
222+ logger ?: Logger
223+ ) : RateLimiterOptions
218224
219225/**
220226 * Creates an API rate limiter instance
@@ -241,8 +247,8 @@ declare function createBatchApiLimiter(options?: RateLimiterFactoryOptions): Rat
241247 * @returns Express middleware function for API rate limiting
242248 */
243249declare function setupApiRateLimiterAfterCachingInit (
244- config : any ,
245- cachingService : any ,
250+ config : RateLimiterFactoryOptions [ 'config' ] ,
251+ cachingService : ICache ,
246252 logger ?: Logger
247253) : RateLimitMiddleware
248254
@@ -255,8 +261,8 @@ declare function setupApiRateLimiterAfterCachingInit(
255261 * @returns Express middleware function for batch API rate limiting
256262 */
257263declare function setupBatchApiRateLimiterAfterCachingInit (
258- config : any ,
259- cachingService : any ,
264+ config : RateLimiterFactoryOptions [ 'config' ] ,
265+ cachingService : ICache ,
260266 logger ?: Logger
261267) : RateLimitMiddleware
262268
0 commit comments