From a3d602edb7b615940b82798374afb84f36d47d76 Mon Sep 17 00:00:00 2001 From: Manuchehr Date: Sat, 23 Nov 2024 16:27:47 +0500 Subject: [PATCH] feat: pass context to get tracker fn as second arg --- src/throttler-module-options.interface.ts | 5 ++++- src/throttler.guard.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/throttler-module-options.interface.ts b/src/throttler-module-options.interface.ts index 09858a4f..4d95ef31 100644 --- a/src/throttler-module-options.interface.ts +++ b/src/throttler-module-options.interface.ts @@ -125,7 +125,10 @@ export interface ThrottlerAsyncOptions extends Pick { /** * @publicApi */ -export type ThrottlerGetTrackerFunction = (req: Record) => Promise | string; +export type ThrottlerGetTrackerFunction = ( + req: Record, + context: ExecutionContext, +) => Promise | string; /** * @publicApi diff --git a/src/throttler.guard.ts b/src/throttler.guard.ts index d1d6a117..4646395c 100644 --- a/src/throttler.guard.ts +++ b/src/throttler.guard.ts @@ -165,7 +165,7 @@ export class ThrottlerGuard implements CanActivate { } } } - const tracker = await getTracker(req); + const tracker = await getTracker(req, context); const key = generateKey(context, tracker, throttler.name); const { totalHits, timeToExpire, isBlocked, timeToBlockExpire } = await this.storageService.increment(key, ttl, limit, blockDuration, throttler.name);