rate-limiter-flexible 11.1.0 → 11.1.1

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.
@@ -68,11 +68,19 @@ module.exports = class RateLimiterAbstract {
68
68
  }
69
69
 
70
70
  get execEvenlyMinDelayMs() {
71
- return this._execEvenlyMinDelayMs;
71
+ return this._execEvenlyMinDelayMs === undefined
72
+ ? this._getExecEvenlyMinDelayMsDefault()
73
+ : this._execEvenlyMinDelayMs;
72
74
  }
73
75
 
74
76
  set execEvenlyMinDelayMs(value) {
75
- this._execEvenlyMinDelayMs = typeof value === 'undefined' ? Math.ceil(this.msDuration / this.points) : value;
77
+ this._execEvenlyMinDelayMs = value;
78
+ }
79
+
80
+ _getExecEvenlyMinDelayMsDefault() {
81
+ return this.points > 0
82
+ ? Math.ceil(this.msDuration / this.points)
83
+ : 0;
76
84
  }
77
85
 
78
86
  get keyPrefix() {
@@ -29,7 +29,7 @@ class RateLimiterMemory extends RateLimiterAbstract {
29
29
  res = this._memoryStorage.set(rlKey, res.consumedPoints, this.blockDuration);
30
30
  }
31
31
  reject(res);
32
- } else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) {
32
+ } else if (this.execEvenly && this.points > 0 && res.msBeforeNext > 0 && !res.isFirstInDuration) {
33
33
  // Execute evenly
34
34
  let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2));
35
35
  if (delay < this.execEvenlyMinDelayMs) {
@@ -79,7 +79,7 @@ module.exports = class RateLimiterStoreAbstract extends RateLimiterInsuredAbstra
79
79
  .catch((err) => {
80
80
  reject(err);
81
81
  });
82
- } else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) {
82
+ } else if (this.execEvenly && this.points > 0 && res.msBeforeNext > 0 && !res.isFirstInDuration) {
83
83
  let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2));
84
84
  if (delay < this.execEvenlyMinDelayMs) {
85
85
  delay = res.consumedPoints * this.execEvenlyMinDelayMs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-limiter-flexible",
3
- "version": "11.1.0",
3
+ "version": "11.1.1",
4
4
  "description": "Node.js atomic and non-atomic counters, rate limiting tools, protection from DoS and brute-force attacks at scale",
5
5
  "main": "index.js",
6
6
  "scripts": {