rate-limiter-flexible
Advanced tools
Comparing version 0.25.1 to 0.25.2
@@ -54,2 +54,9 @@ const RateLimiterAbstract = require('./RateLimiterAbstract'); | ||
if (res.consumedPoints > this.points) { | ||
let blockPromise = Promise.resolve(); | ||
// Block only first time when consumed more than points | ||
if (this.blockDuration > 0 && res.consumedPoints <= (this.points + changedPoints)) { | ||
res.msBeforeNext = this.msBlockDuration; | ||
blockPromise = this._block(rlKey, res.consumedPoints, this.msBlockDuration, options); | ||
} | ||
if (this.inmemoryBlockOnConsumed > 0 && res.consumedPoints >= this.inmemoryBlockOnConsumed) { | ||
@@ -59,17 +66,11 @@ // Block key for this.inmemoryBlockDuration seconds | ||
res.msBeforeNext = this.msInmemoryBlockDuration; | ||
} | ||
reject(res); | ||
// Block only first time when consumed more than points | ||
} else if (this.blockDuration > 0 && res.consumedPoints <= (this.points + changedPoints)) { | ||
this._block(rlKey, res.consumedPoints, this.msBlockDuration, options) | ||
.then(() => { | ||
res.msBeforeNext = this.msBlockDuration; | ||
reject(res); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
} else { | ||
reject(res); | ||
} | ||
blockPromise | ||
.then(() => { | ||
reject(res); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
} else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) { | ||
@@ -124,6 +125,2 @@ let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2)); | ||
get msInmemoryBlockDuration() { | ||
return this._inmemoryBlockDuration * 1000; | ||
} | ||
set inmemoryBlockDuration(value) { | ||
@@ -136,2 +133,6 @@ this._inmemoryBlockDuration = value ? parseInt(value) : 0; | ||
get msInmemoryBlockDuration() { | ||
return this._inmemoryBlockDuration * 1000; | ||
} | ||
get insuranceLimiter() { | ||
@@ -138,0 +139,0 @@ return this._insuranceLimiter; |
{ | ||
"name": "rate-limiter-flexible", | ||
"version": "0.25.1", | ||
"version": "0.25.2", | ||
"description": "Flexible API rate limiter backed by Redis for distributed node.js applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
96264