rate-limiter-flexible 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/lib/BurstyRateLimiter.js +5 -1
- package/lib/index.d.ts +7 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,18 @@ It uses **fixed window** as it is much faster than rolling window.
|
|
|
42
42
|
|
|
43
43
|
`yarn add rate-limiter-flexible`
|
|
44
44
|
|
|
45
|
+
## Import
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// CommonJS
|
|
49
|
+
const { RateLimiterMemory } = require("rate-limiter-flexible");
|
|
50
|
+
|
|
51
|
+
// or
|
|
52
|
+
|
|
53
|
+
// ECMAScript
|
|
54
|
+
import { RateLimiterMemory } from "rate-limiter-flexible";
|
|
55
|
+
```
|
|
56
|
+
|
|
45
57
|
## Basic Example
|
|
46
58
|
|
|
47
59
|
Points can be consumed by IP address, user ID, authorisation token, API route or any other string.
|
package/lib/BurstyRateLimiter.js
CHANGED
|
@@ -17,9 +17,13 @@ module.exports = class BurstyRateLimiter {
|
|
|
17
17
|
* @param {RateLimiterRes} [blRes] Bursty limiter response
|
|
18
18
|
*/
|
|
19
19
|
_combineRes(rlRes, blRes) {
|
|
20
|
+
if (!rlRes) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
return new RateLimiterRes(
|
|
21
25
|
rlRes.remainingPoints,
|
|
22
|
-
Math.min(rlRes.msBeforeNext, blRes.msBeforeNext),
|
|
26
|
+
Math.min(rlRes.msBeforeNext, blRes ? blRes.msBeforeNext : 0),
|
|
23
27
|
rlRes.consumedPoints,
|
|
24
28
|
rlRes.isFirstInDuration
|
|
25
29
|
)
|
package/lib/index.d.ts
CHANGED
|
@@ -255,6 +255,10 @@ interface IRateLimiterMongoOptions extends IRateLimiterStoreOptions {
|
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
interface IRateLimiterRedisOptions extends IRateLimiterStoreOptions {
|
|
259
|
+
rejectIfRedisNotReady?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
258
262
|
interface ICallbackReady {
|
|
259
263
|
(error?: Error): void;
|
|
260
264
|
}
|
|
@@ -284,7 +288,9 @@ export class RateLimiterClusterMasterPM2 {
|
|
|
284
288
|
constructor(pm2: any);
|
|
285
289
|
}
|
|
286
290
|
|
|
287
|
-
export class RateLimiterRedis extends RateLimiterStoreAbstract {
|
|
291
|
+
export class RateLimiterRedis extends RateLimiterStoreAbstract {
|
|
292
|
+
constructor(opts: IRateLimiterRedisOptions);
|
|
293
|
+
}
|
|
288
294
|
|
|
289
295
|
export interface IRateLimiterMongoFunctionOptions {
|
|
290
296
|
attrs: { [key: string]: any };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rate-limiter-flexible",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Node.js rate limiter by key and protection from DDoS and Brute-Force attacks in process Memory, Redis, MongoDb, Memcached, MySQL, PostgreSQL, Cluster or PM",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|