Socket
Socket
Sign inDemoInstall

rate-limiter-flexible

Package Overview
Dependencies
Maintainers
1
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rate-limiter-flexible - npm Package Compare versions

Comparing version 2.3.10 to 2.3.11

8

lib/index.d.ts

@@ -232,3 +232,11 @@ export interface IRateLimiterRes {

storeType?: string;
inMemoryBlockOnConsumed?: number;
inMemoryBlockDuration?: number;
/**
* @deprecated Use camelCased inMemoryBlockOnConsumed option
*/
inmemoryBlockOnConsumed?: number;
/**
* @deprecated Use camelCased inMemoryBlockOnConsumed option
*/
inmemoryBlockDuration?: number;

@@ -235,0 +243,0 @@ insuranceLimiter?: RateLimiterAbstract;

126

lib/RateLimiterStoreAbstract.js

@@ -11,4 +11,4 @@ const RateLimiterAbstract = require('./RateLimiterAbstract');

*
* inmemoryBlockOnConsumed: 40, // Number of points when key is blocked
* inmemoryBlockDuration: 10, // Block duration in seconds
* inMemoryBlockOnConsumed: 40, // Number of points when key is blocked
* inMemoryBlockDuration: 10, // Block duration in seconds
* insuranceLimiter: RateLimiterAbstract

@@ -20,6 +20,6 @@ * }

this.inmemoryBlockOnConsumed = opts.inmemoryBlockOnConsumed;
this.inmemoryBlockDuration = opts.inmemoryBlockDuration;
this.inMemoryBlockOnConsumed = opts.inMemoryBlockOnConsumed || opts.inmemoryBlockOnConsumed;
this.inMemoryBlockDuration = opts.inMemoryBlockDuration || opts.inmemoryBlockDuration;
this.insuranceLimiter = opts.insuranceLimiter;
this._inmemoryBlockedKeys = new BlockedKeys();
this._inMemoryBlockedKeys = new BlockedKeys();
}

@@ -55,6 +55,6 @@

if (this.inmemoryBlockOnConsumed > 0 && !(this.inmemoryBlockDuration > 0)
&& res.consumedPoints >= this.inmemoryBlockOnConsumed
if (this.inMemoryBlockOnConsumed > 0 && !(this.inMemoryBlockDuration > 0)
&& res.consumedPoints >= this.inMemoryBlockOnConsumed
) {
this._inmemoryBlockedKeys.addMs(rlKey, res.msBeforeNext);
this._inMemoryBlockedKeys.addMs(rlKey, res.msBeforeNext);
if (res.consumedPoints > this.points) {

@@ -73,6 +73,6 @@ return reject(res);

if (this.inmemoryBlockOnConsumed > 0 && res.consumedPoints >= this.inmemoryBlockOnConsumed) {
// Block key for this.inmemoryBlockDuration seconds
this._inmemoryBlockedKeys.add(rlKey, this.inmemoryBlockDuration);
res.msBeforeNext = this.msInmemoryBlockDuration;
if (this.inMemoryBlockOnConsumed > 0 && res.consumedPoints >= this.inMemoryBlockOnConsumed) {
// Block key for this.inMemoryBlockDuration seconds
this._inMemoryBlockedKeys.add(rlKey, this.inMemoryBlockDuration);
res.msBeforeNext = this.msInMemoryBlockDuration;
}

@@ -113,36 +113,94 @@

/**
* @deprecated Use camelCase version
* @returns {BlockedKeys}
* @private
*/
get _inmemoryBlockedKeys() {
return this._inMemoryBlockedKeys
}
/**
* @deprecated Use camelCase version
* @param rlKey
* @returns {number}
*/
getInmemoryBlockMsBeforeExpire(rlKey) {
if (this.inmemoryBlockOnConsumed > 0) {
return this._inmemoryBlockedKeys.msBeforeExpire(rlKey);
}
return 0;
return this.getInMemoryBlockMsBeforeExpire(rlKey)
}
/**
* @deprecated Use camelCase version
* @returns {number|number}
*/
get inmemoryBlockOnConsumed() {
return this._inmemoryBlockOnConsumed;
return this.inMemoryBlockOnConsumed;
}
/**
* @deprecated Use camelCase version
* @param value
*/
set inmemoryBlockOnConsumed(value) {
this._inmemoryBlockOnConsumed = value ? parseInt(value) : 0;
if (this.inmemoryBlockOnConsumed > 0 && this.points > this.inmemoryBlockOnConsumed) {
throw new Error('inmemoryBlockOnConsumed option must be greater or equal "points" option');
}
this.inMemoryBlockOnConsumed = value;
}
/**
* @deprecated Use camelCase version
* @returns {number|number}
*/
get inmemoryBlockDuration() {
return this._inmemoryBlockDuration;
return this.inMemoryBlockDuration;
}
/**
* @deprecated Use camelCase version
* @param value
*/
set inmemoryBlockDuration(value) {
this._inmemoryBlockDuration = value ? parseInt(value) : 0;
if (this.inmemoryBlockDuration > 0 && this.inmemoryBlockOnConsumed === 0) {
throw new Error('inmemoryBlockOnConsumed option must be set up');
}
this.inMemoryBlockDuration = value
}
/**
* @deprecated Use camelCase version
* @returns {number}
*/
get msInmemoryBlockDuration() {
return this._inmemoryBlockDuration * 1000;
return this.inMemoryBlockDuration * 1000;
}
getInMemoryBlockMsBeforeExpire(rlKey) {
if (this.inMemoryBlockOnConsumed > 0) {
return this._inMemoryBlockedKeys.msBeforeExpire(rlKey);
}
return 0;
}
get inMemoryBlockOnConsumed() {
return this._inMemoryBlockOnConsumed;
}
set inMemoryBlockOnConsumed(value) {
this._inMemoryBlockOnConsumed = value ? parseInt(value) : 0;
if (this.inMemoryBlockOnConsumed > 0 && this.points > this.inMemoryBlockOnConsumed) {
throw new Error('inMemoryBlockOnConsumed option must be greater or equal "points" option');
}
}
get inMemoryBlockDuration() {
return this._inMemoryBlockDuration;
}
set inMemoryBlockDuration(value) {
this._inMemoryBlockDuration = value ? parseInt(value) : 0;
if (this.inMemoryBlockDuration > 0 && this.inMemoryBlockOnConsumed === 0) {
throw new Error('inMemoryBlockOnConsumed option must be set up');
}
}
get msInMemoryBlockDuration() {
return this._inMemoryBlockDuration * 1000;
}
get insuranceLimiter() {

@@ -203,5 +261,5 @@ return this._insuranceLimiter;

const inmemoryBlockMsBeforeExpire = this.getInmemoryBlockMsBeforeExpire(rlKey);
if (inmemoryBlockMsBeforeExpire > 0) {
return reject(new RateLimiterRes(0, inmemoryBlockMsBeforeExpire));
const inMemoryBlockMsBeforeExpire = this.getInMemoryBlockMsBeforeExpire(rlKey);
if (inMemoryBlockMsBeforeExpire > 0) {
return reject(new RateLimiterRes(0, inMemoryBlockMsBeforeExpire));
}

@@ -293,3 +351,3 @@

.then((res) => {
this._inmemoryBlockedKeys.delete(rlKey);
this._inMemoryBlockedKeys.delete(rlKey);
resolve(res);

@@ -307,3 +365,3 @@ })

deleteInMemoryBlockedAll() {
this._inmemoryBlockedKeys.delete();
this._inMemoryBlockedKeys.delete();
}

@@ -389,5 +447,5 @@

*/
_upsert() {
_upsert(rlKey, points, msDuration, forceExpire = false, options = {}) {
throw new Error("You have to implement the method '_upsert'!");
}
};
{
"name": "rate-limiter-flexible",
"version": "2.3.10",
"version": "2.3.11",
"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,0 +5,0 @@ "main": "index.js",

@@ -32,3 +32,3 @@ [![Coverage Status](https://coveralls.io/repos/animir/node-rate-limiter-flexible/badge.svg?branch=master)](https://coveralls.io/r/animir/node-rate-limiter-flexible?branch=master)

**In memory blocks.** Avoid extra requests to store with [inmemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed).
**In memory blocks.** Avoid extra requests to store with [inMemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed).

@@ -168,4 +168,4 @@ **Deno compatible** See [this example](https://gist.github.com/animir/d06ca92931677f330d3f2d4c6c3108e4)

* [blockDuration](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#blockduration) Block for N seconds, if consumed more than points.
* [inmemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed) Avoid extra requests to store.
* [inmemoryBlockDuration](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockduration)
* [inMemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed) Avoid extra requests to store.
* [inMemoryBlockDuration](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockduration)
* [insuranceLimiter](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#insurancelimiter) Make it more stable with less efforts.

@@ -220,3 +220,3 @@ * [storeType](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#storetype) Have to be set to `knex`, if you use it.

Note, you can speed up limiters with [inmemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed) option.
Note, you can speed up limiters with [inMemoryBlockOnConsumed](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#inmemoryblockonconsumed) option.

@@ -223,0 +223,0 @@ ## Contribution

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc