rate-limiter-flexible 2.3.7 → 2.3.8

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,8 @@ It uses **fixed window** as it is much faster than rolling window.
42
42
 
43
43
  ## Basic Example
44
44
 
45
+ Points can be consumed by IP address, user ID, authorisation token, API route or any other string.
46
+
45
47
  ```javascript
46
48
  const opts = {
47
49
  points: 6, // 6 points
@@ -48,7 +48,7 @@ class RateLimiterMemory extends RateLimiterAbstract {
48
48
  return new Promise((resolve) => {
49
49
  const secDuration = this._getKeySecDuration(options);
50
50
  const res = this._memoryStorage.incrby(rlKey, points, secDuration);
51
- res.remainingPoints = this.points - res.consumedPoints;
51
+ res.remainingPoints = Math.max(this.points - res.consumedPoints, 0);
52
52
  resolve(res);
53
53
  });
54
54
  }
@@ -58,7 +58,7 @@ class RateLimiterMemory extends RateLimiterAbstract {
58
58
  return new Promise((resolve) => {
59
59
  const secDuration = this._getKeySecDuration(options);
60
60
  const res = this._memoryStorage.incrby(rlKey, -points, secDuration);
61
- res.remainingPoints = this.points - res.consumedPoints;
61
+ res.remainingPoints = Math.max(this.points - res.consumedPoints, 0);
62
62
  resolve(res);
63
63
  });
64
64
  }
@@ -91,7 +91,7 @@ class RateLimiterMemory extends RateLimiterAbstract {
91
91
  get(key) {
92
92
  const res = this._memoryStorage.get(this.getKey(key));
93
93
  if (res !== null) {
94
- res.remainingPoints = this.points - res.consumedPoints;
94
+ res.remainingPoints = Math.max(this.points - res.consumedPoints, 0);
95
95
  }
96
96
 
97
97
  return Promise.resolve(res);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-limiter-flexible",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
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": {