@@ -10,11 +10,10 @@ import {
10
10
import { CallHandler , ExecutionContext , Injectable , Logger , NestInterceptor } from '@nestjs/common' ;
11
11
import { Reflector } from '@nestjs/core' ;
12
12
import {
13
- GetFeatureFlagService ,
14
- GetFeatureFlagCommand ,
15
13
Instrument ,
16
14
HttpRequestHeaderKeysEnum ,
17
15
HttpResponseHeaderKeysEnum ,
16
+ FeatureFlagsService ,
18
17
} from '@novu/application-generic' ;
19
18
import {
20
19
ApiAuthSchemeEnum ,
@@ -45,7 +44,7 @@ export class ApiRateLimitInterceptor extends ThrottlerGuard implements NestInter
45
44
@InjectThrottlerStorage ( ) protected readonly storageService : ThrottlerStorage ,
46
45
reflector : Reflector ,
47
46
private evaluateApiRateLimit : EvaluateApiRateLimit ,
48
- private getFeatureFlag : GetFeatureFlagService
47
+ private featureFlagService : FeatureFlagsService
49
48
) {
50
49
super ( options , storageService , reflector ) ;
51
50
}
@@ -73,14 +72,13 @@ export class ApiRateLimitInterceptor extends ThrottlerGuard implements NestInter
73
72
const user = this . getReqUser ( context ) ;
74
73
const { organizationId, environmentId, _id } = user ;
75
74
76
- const isEnabled = await this . getFeatureFlag . getBoolean (
77
- GetFeatureFlagCommand . create ( {
78
- environment : { _id : environmentId } as EnvironmentEntity ,
79
- organization : { _id : organizationId } as OrganizationEntity ,
80
- user : { _id } as UserEntity ,
81
- key : FeatureFlagsKeysEnum . IS_API_RATE_LIMITING_ENABLED ,
82
- } )
83
- ) ;
75
+ const isEnabled = await this . featureFlagService . getFlag ( {
76
+ key : FeatureFlagsKeysEnum . IS_API_RATE_LIMITING_ENABLED ,
77
+ defaultValue : false ,
78
+ environment : { _id : environmentId } as EnvironmentEntity ,
79
+ organization : { _id : organizationId } as OrganizationEntity ,
80
+ user : { _id } as UserEntity ,
81
+ } ) ;
84
82
85
83
return ! isEnabled ;
86
84
}
@@ -128,14 +126,13 @@ export class ApiRateLimitInterceptor extends ThrottlerGuard implements NestInter
128
126
* The purpose of the dry run is to allow us to observe how
129
127
* the rate limiting would behave without actually enforcing it.
130
128
*/
131
- const isDryRun = await this . getFeatureFlag . getBoolean (
132
- GetFeatureFlagCommand . create ( {
133
- environment : { _id : environmentId } as EnvironmentEntity ,
134
- organization : { _id : organizationId } as OrganizationEntity ,
135
- user : { _id } as UserEntity ,
136
- key : FeatureFlagsKeysEnum . IS_API_RATE_LIMITING_DRY_RUN_ENABLED ,
137
- } )
138
- ) ;
129
+ const isDryRun = await this . featureFlagService . getFlag ( {
130
+ environment : { _id : environmentId } as EnvironmentEntity ,
131
+ organization : { _id : organizationId } as OrganizationEntity ,
132
+ user : { _id } as UserEntity ,
133
+ key : FeatureFlagsKeysEnum . IS_API_RATE_LIMITING_DRY_RUN_ENABLED ,
134
+ defaultValue : false ,
135
+ } ) ;
139
136
140
137
res . header ( HttpResponseHeaderKeysEnum . RATELIMIT_REMAINING , remaining ) ;
141
138
res . header ( HttpResponseHeaderKeysEnum . RATELIMIT_LIMIT , limit ) ;
0 commit comments