From 0278c068f327c3e3225965be768fded022489161 Mon Sep 17 00:00:00 2001 From: Aideen Nasirishargh Date: Wed, 17 Jul 2019 10:40:36 -0700 Subject: [PATCH] express-rate-limit: Added support for resetKey on the RateLimit object (#36951) * express-rate-limit: Adding resetKey on Instance * express-rate-limit Fixing string quotations --- types/express-rate-limit/express-rate-limit-tests.ts | 1 + types/express-rate-limit/index.d.ts | 5 ++++- types/express-rate-limit/v2/express-rate-limit-tests.ts | 1 + types/express-rate-limit/v2/index.d.ts | 6 +++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/types/express-rate-limit/express-rate-limit-tests.ts b/types/express-rate-limit/express-rate-limit-tests.ts index 4b94ef6b05..064289423e 100644 --- a/types/express-rate-limit/express-rate-limit-tests.ts +++ b/types/express-rate-limit/express-rate-limit-tests.ts @@ -7,6 +7,7 @@ const apiLimiter = new RateLimit({ skipFailedRequests: false, skipSuccessfulRequests: true, }); +apiLimiter.resetKey('testKey'); const apiLimiterWithMaxFn = new RateLimit({ windowMs: 15 * 60 * 1000, diff --git a/types/express-rate-limit/index.d.ts b/types/express-rate-limit/index.d.ts index 9d3459e21b..740ebbeaa4 100644 --- a/types/express-rate-limit/index.d.ts +++ b/types/express-rate-limit/index.d.ts @@ -99,7 +99,10 @@ declare namespace RateLimit { */ windowMs?: number; } + interface Instance extends express.RequestHandler { + resetKey(key: string): void; + } } -declare var RateLimit: new (options: RateLimit.Options) => express.RequestHandler; +declare var RateLimit: new (options: RateLimit.Options) => RateLimit.Instance; export = RateLimit; diff --git a/types/express-rate-limit/v2/express-rate-limit-tests.ts b/types/express-rate-limit/v2/express-rate-limit-tests.ts index aa5c51a016..2314c25cfb 100644 --- a/types/express-rate-limit/v2/express-rate-limit-tests.ts +++ b/types/express-rate-limit/v2/express-rate-limit-tests.ts @@ -5,6 +5,7 @@ const apiLimiter = new RateLimit({ max: 100, delayMs: 0 // disabled }); +apiLimiter.resetKey('testKey'); const apiLimiterWithMessageObject = new RateLimit({ windowMs: 15 * 60 * 1000, // 15 minutes diff --git a/types/express-rate-limit/v2/index.d.ts b/types/express-rate-limit/v2/index.d.ts index b3f074f28d..9918efe3b0 100644 --- a/types/express-rate-limit/v2/index.d.ts +++ b/types/express-rate-limit/v2/index.d.ts @@ -36,7 +36,11 @@ declare namespace RateLimit { onLimitReached?(req: express.Request, res: express.Response, optionsUsed: Options): void; windowMs?: number; } + + interface Instance extends express.RequestHandler { + resetKey(key: string): void; + } } -declare var RateLimit: new (options: RateLimit.Options) => express.RequestHandler; +declare var RateLimit: new (options: RateLimit.Options) => RateLimit.Instance; export = RateLimit;