Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-rate-limiter

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-rate-limiter - npm Package Compare versions

Comparing version 2.6.7 to 2.7.0

2

dist/default-options.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc