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 3.0.0 to 3.1.0

3

dist/rate-limiter.guard.d.ts

@@ -14,2 +14,5 @@ import { Reflector } from '@nestjs/core';

canActivate(context: ExecutionContext): Promise<boolean>;
protected getIpFromRequest(request: {
ip: string;
}): string;
private httpHandler;

@@ -16,0 +19,0 @@ private setResponseHeaders;

8

dist/rate-limiter.guard.js

@@ -160,3 +160,3 @@ "use strict";

canActivate(context) {
var _a, _b, _c, _d;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {

@@ -177,3 +177,3 @@ let points = ((_a = this.specificOptions) === null || _a === void 0 ? void 0 : _a.points) || this.options.points;

const rateLimiter = yield this.getRateLimiter(reflectedOptions);
const key = (_d = (_c = request.ip) === null || _c === void 0 ? void 0 : _c.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)) === null || _d === void 0 ? void 0 : _d[0];
const key = this.getIpFromRequest(request);
yield this.responseHandler(response, key, rateLimiter, points, pointsConsumed);

@@ -183,2 +183,6 @@ return true;

}
getIpFromRequest(request) {
var _a, _b;
return (_b = (_a = request.ip) === null || _a === void 0 ? void 0 : _a.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)) === null || _b === void 0 ? void 0 : _b[0];
}
httpHandler(context) {

@@ -185,0 +189,0 @@ if (this.options.for === 'ExpressGraphql') {

{
"name": "nestjs-rate-limiter",
"version": "3.0.0",
"version": "3.1.0",
"description": "Highly configurable and extensible rate limiter library",

@@ -5,0 +5,0 @@ "repository": {

@@ -52,2 +52,3 @@ <p align="center">

- [customResponseSchema](https://github.com/ozkanonur/nestjs-rate-limiter#-customResponseSchema)
- [Override Functions](https://github.com/ozkanonur/nestjs-rate-limiter#override-functions)
- [Benchmarks](https://github.com/ozkanonur/nestjs-rate-limiter#benchmarks)

@@ -469,2 +470,18 @@ - [TODO List](https://github.com/ozkanonur/nestjs-rate-limiter#todo)

customResponseSchema option allows to provide customizable response schemas
# Override Functions
#### It's possible to override <code> getIpFromRequest </code> function by extending <code> RateLimiterGuard </code> class.
```ts
import { RateLimiterGuard } from 'nestjs-rate-limiter'
import type { Request } from 'express'
class ExampleRateLimiterGuard extends RateLimiterGuard {
protected getIpFromRequest(request: Request): string {
return request.get('x-forwarded-for');
}
}
```
# Benchmarks

@@ -471,0 +488,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