rate-limiter-flexible 2.4.1 → 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 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.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-limiter-flexible",
3
- "version": "2.4.1",
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": {