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 0.15.4 to 0.15.5

2

CLUSTER.md

@@ -5,3 +5,3 @@ ## RateLimiterCluster

Endpoint is pure NodeJS endpoint launched in `node:10.5.0-jessie` and `redis:4.0.10-alpine` Docker containers with 4 workers
Endpoint is pure NodeJS endpoint launched in `node:10.5.0-jessie` Docker containers with 4 workers

@@ -8,0 +8,0 @@ Endpoint is limited by `RateLimiterCluster` with config:

@@ -17,8 +17,12 @@ const RateLimiterStoreAbstract = require('./RateLimiterStoreAbstract');

this.mongo = opts.mongo;
if (typeof this.mongo.then === 'function') {
if (opts.mongo) {
this.client = opts.mongo;
} else {
this.client = opts.storeClient;
}
if (typeof this.client.then === 'function') {
// If Promise
this.mongo
this.client
.then((conn) => {
this.mongo = conn;
this.client = conn;
this._initCollection();

@@ -35,11 +39,11 @@ });

get mongo() {
return this._mongo;
get client() {
return this._client;
}
set mongo(value) {
set client(value) {
if (typeof value === 'undefined') {
throw new Error('mongo is not set');
}
this._mongo = value;
this._client = value;
}

@@ -49,6 +53,6 @@

let collection;
if (typeof this.mongo.db === 'function') {
collection = this.mongo.db(RateLimiterMongo.getDbName()).collection(this.keyPrefix);
if (typeof this.client.db === 'function') {
collection = this.client.db(RateLimiterMongo.getDbName()).collection(this.keyPrefix);
} else {
collection = this.mongo.db.collection(this.keyPrefix);
collection = this.client.db.collection(this.keyPrefix);
}

@@ -55,0 +59,0 @@ collection.ensureIndex({ expire: -1 }, { expireAfterSeconds: 0 });

@@ -16,15 +16,18 @@ const RateLimiterStoreAbstract = require('./RateLimiterStoreAbstract');

super(opts);
this.redis = opts.redis;
if (opts.redis) {
this.client = opts.redis;
} else {
this.client = opts.storeClient;
}
}
get redis() {
return this._redis;
get client() {
return this._client;
}
set redis(value) {
set client(value) {
if (typeof value === 'undefined') {
throw new Error('redis is not set');
}
this._redis = value;
this._client = value;
}

@@ -47,3 +50,3 @@

res.msBeforeNext = this.duration;
this.redis.expire(rlKey, this.duration);
this.client.expire(rlKey, this.duration);
} else {

@@ -60,3 +63,3 @@ res.msBeforeNext = resTtlMs;

if (forceExpire) {
this.redis.multi()
this.client.multi()
.set(rlKey, points, 'EX', secDuration)

@@ -72,3 +75,3 @@ .pttl(rlKey)

} else {
this.redis.multi()
this.client.multi()
.set(rlKey, 0, 'EX', secDuration, 'NX')

@@ -90,3 +93,3 @@ .incrby(rlKey, points)

return new Promise((resolve, reject) => {
this.redis.multi()
this.client.multi()
.get(rlKey)

@@ -93,0 +96,0 @@ .pttl(rlKey)

{
"name": "rate-limiter-flexible",
"version": "0.15.4",
"version": "0.15.5",
"description": "Flexible API rate limiter backed by Redis for distributed node.js applications",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -95,2 +95,4 @@ [![Build Status](https://travis-ci.org/animir/node-rate-limiter-flexible.png)](https://travis-ci.org/animir/node-rate-limiter-flexible)

* `storeClient` `Required` Have to be `redis`, `ioredis`, `mongodb`, `pg`, `mysql2`, `mysql` or any other related pool or connection.
* `inmemoryBlockOnConsumed` `Default: 0` Against DDoS attacks. Blocked key isn't checked by requesting Redis, MySQL or Mongo.

@@ -112,4 +114,2 @@ In-memory blocking works in **current process memory**.

* `storeClient` `Required` Have to be `pg`, `mysql2` or `mysql` pool or connection
* `tableName` `Default: equals to 'keyPrefix' option` By default, limiter creates table for each unique `keyPrefix`.

@@ -230,3 +230,3 @@ All limits for all limiters are stored in one table if custom name is set.

// Basic options
redis: redisClient,
storeClient: redisClient,
points: 5, // Number of points

@@ -318,3 +318,3 @@ duration: 5, // Per second(s)

const opts = {
mongo: mongoConn,
storeClient: mongoConn,
points: 10, // Number of points

@@ -344,3 +344,3 @@ duration: 1, // Per second(s)

const opts = {
mongo: mongoConn,
storeClient: mongoConn,
points: 10, // Number of points

@@ -347,0 +347,0 @@ duration: 1, // Per second(s)

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