nestjs-rate-limiter
Advanced tools
Comparing version 2.6.7 to 2.7.0
@@ -29,3 +29,3 @@ "use strict"; | ||
errorMessage: 'Rate limit exceeded', | ||
createErrorBody: undefined | ||
customResponseSchema: undefined | ||
}; |
@@ -41,4 +41,4 @@ "use strict"; | ||
expect(default_options_1.defaultRateLimiterOptions.errorMessage).toBe('Rate limit exceeded'); | ||
expect(default_options_1.defaultRateLimiterOptions.createErrorBody).toBeUndefined(); | ||
expect(default_options_1.defaultRateLimiterOptions.customResponseSchema).toBeUndefined(); | ||
})); | ||
}); |
@@ -189,3 +189,3 @@ "use strict"; | ||
responseHandler(response, key, rateLimiter, points, pointsConsumed) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -205,7 +205,8 @@ try { | ||
response.header('Retry-After', Math.ceil(rateLimiterResponse.msBeforeNext / 1000)); | ||
if (typeof this.options.createErrorBody === 'function') { | ||
throw new common_1.HttpException(this.options.createErrorBody(rateLimiterResponse), common_1.HttpStatus.TOO_MANY_REQUESTS); | ||
if (typeof ((_b = this.spesificOptions) === null || _b === void 0 ? void 0 : _b.customResponseSchema) === 'function' || typeof this.options.customResponseSchema === 'function') { | ||
var errorBody = ((_c = this.spesificOptions) === null || _c === void 0 ? void 0 : _c.customResponseSchema) || this.options.customResponseSchema; | ||
throw new common_1.HttpException(errorBody(rateLimiterResponse), common_1.HttpStatus.TOO_MANY_REQUESTS); | ||
} | ||
else { | ||
throw new common_1.HttpException(((_b = this.spesificOptions) === null || _b === void 0 ? void 0 : _b.errorMessage) || this.options.errorMessage, common_1.HttpStatus.TOO_MANY_REQUESTS); | ||
throw new common_1.HttpException(((_d = this.spesificOptions) === null || _d === void 0 ? void 0 : _d.errorMessage) || this.options.errorMessage, common_1.HttpStatus.TOO_MANY_REQUESTS); | ||
} | ||
@@ -212,0 +213,0 @@ } |
@@ -29,3 +29,3 @@ import { Provider } from '@nestjs/common'; | ||
errorMessage?: string; | ||
createErrorBody?: (rateLimiterResponse: RateLimiterRes) => {}; | ||
customResponseSchema?: (rateLimiterResponse: RateLimiterRes) => {}; | ||
} | ||
@@ -32,0 +32,0 @@ export interface RateLimiterOptionsFactory { |
{ | ||
"name": "nestjs-rate-limiter", | ||
"version": "2.6.7", | ||
"version": "2.7.0", | ||
"description": "Highly configurable rate limiter library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -150,3 +150,8 @@ <p align="center"> | ||
@RateLimit({ keyPrefix: () => programmaticFuncThatReturnsValue(), points: 1, duration: 60, errorMessage: 'You can only request 1 in a minute by giving access token' }) | ||
@RateLimit({ | ||
keyPrefix: () => programmaticFuncThatReturnsValue(), | ||
points: 1, | ||
duration: 60, | ||
customResponseSchema: () => { return { timestamp: '1611479696', message: 'Request has been blocked' }} | ||
}) | ||
@Get('/example') | ||
@@ -190,3 +195,4 @@ public async example() { | ||
maxQueueSize: 100, | ||
errorMessage: 'Rate limit exceeded' | ||
errorMessage: 'Rate limit exceeded', | ||
customResponseSchema: undefined | ||
}), | ||
@@ -436,2 +442,9 @@ ], | ||
#### ● customResponseSchema | ||
<code> Default: undefined </code> | ||
<br> | ||
<code> Type: string</code> | ||
<br> | ||
customResponseSchema option allows to provide customizable response schemas | ||
# Benchmarks | ||
@@ -438,0 +451,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52304
619
470
0