rate-limiter-flexible
Advanced tools
Comparing version 0.16.3 to 0.16.4
{ | ||
"name": "rate-limiter-flexible", | ||
"version": "0.16.3", | ||
"version": "0.16.4", | ||
"description": "Flexible API rate limiter backed by Redis for distributed node.js applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -59,3 +59,3 @@ [![Build Status](https://travis-ci.org/animir/node-rate-limiter-flexible.png)](https://travis-ci.org/animir/node-rate-limiter-flexible) | ||
* [RateLimiterMemory](#ratelimitermemory) | ||
* [RateLimiterUnion](#ratelimiterunion) Combine 2 or more limiters to act as single | ||
* [RateLimiterUnion](https://github.com/animir/node-rate-limiter-flexible/wiki/RateLimiterUnion) Combine 2 or more limiters to act as single | ||
* [Express middleware](#express-middleware) | ||
@@ -332,44 +332,2 @@ * [Koa middleware](#koa-middleware) | ||
### RateLimiterUnion | ||
Combine 2 or more rate limiters to act as single | ||
Any rate limiters from this `rate-limiter-flexible` can be united | ||
Useful for authorization, which must be protected from password brute force | ||
For example, not more than once per second and only 5 points per minute | ||
`keyPrefix` is necessary as resolved and rejected results depend on it | ||
```javascript | ||
const limiter1 = new RateLimiterMemory({ | ||
keyPrefix: 'limit1', | ||
points: 1, | ||
duration: 1, | ||
}); | ||
const limiter2 = new RateLimiterMemory({ | ||
keyPrefix: 'limit2', | ||
points: 5, | ||
duration: 60, | ||
}); | ||
const rateLimiterUnion = new RateLimiterUnion(limiter1, limiter2); | ||
rateLimiterUnion.consume(remoteAddress) | ||
.then((res) => { | ||
// Returns object with 2 RateLimiterRes objects | ||
res['limit1'].remainingPoints; | ||
res['limit2'].remainingPoints; | ||
}) | ||
.catch((rej) => { | ||
/* Returns object with RateLimiterRes objects only for rejected limiters | ||
* For example: | ||
* { limit1: RateLimiterRes { ... } } | ||
* | ||
* It may be Error if you use any limiter without insurance except Memory | ||
* { limit2: Error } | ||
*/ | ||
}); | ||
``` | ||
### Express middleware | ||
@@ -376,0 +334,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
64730
374