rate-limiter-flexible 2.3.6 → 2.3.9

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
@@ -1,4 +1,3 @@
1
- [![Build Status](https://travis-ci.org/animir/node-rate-limiter-flexible.png)](https://travis-ci.org/animir/node-rate-limiter-flexible)
2
1
  [![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)
3
2
  [![npm version](https://badge.fury.io/js/rate-limiter-flexible.svg)](https://www.npmjs.com/package/rate-limiter-flexible)
4
3
  ![npm](https://img.shields.io/npm/dm/rate-limiter-flexible.svg)
@@ -43,6 +42,8 @@ It uses **fixed window** as it is much faster than rolling window.
43
42
 
44
43
  ## Basic Example
45
44
 
45
+ Points can be consumed by IP address, user ID, authorisation token, API route or any other string.
46
+
46
47
  ```javascript
47
48
  const opts = {
48
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/lib/index.d.ts CHANGED
@@ -237,6 +237,10 @@ interface IRateLimiterStoreOptions extends IRateLimiterOptions {
237
237
  tableCreated?: boolean;
238
238
  }
239
239
 
240
+ interface IRateLimiterStoreNoAutoExpiryOptions extends IRateLimiterStoreOptions {
241
+ clearExpiredByTimeout?: boolean;
242
+ }
243
+
240
244
  interface IRateLimiterMongoOptions extends IRateLimiterStoreOptions {
241
245
  indexKeyPrefix?: {
242
246
  [key: string]: any;
@@ -326,11 +330,11 @@ export class RateLimiterMongo extends RateLimiterStoreAbstract {
326
330
  }
327
331
 
328
332
  export class RateLimiterMySQL extends RateLimiterStoreAbstract {
329
- constructor(opts: IRateLimiterStoreOptions, cb?: ICallbackReady);
333
+ constructor(opts: IRateLimiterStoreNoAutoExpiryOptions, cb?: ICallbackReady);
330
334
  }
331
335
 
332
336
  export class RateLimiterPostgres extends RateLimiterStoreAbstract {
333
- constructor(opts: IRateLimiterStoreOptions, cb?: ICallbackReady);
337
+ constructor(opts: IRateLimiterStoreNoAutoExpiryOptions, cb?: ICallbackReady);
334
338
  }
335
339
 
336
340
  export class RateLimiterMemcache extends RateLimiterStoreAbstract {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-limiter-flexible",
3
- "version": "2.3.6",
3
+ "version": "2.3.9",
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": {
@@ -51,5 +51,9 @@
51
51
  "mocha": "^5.1.1",
52
52
  "redis-mock": "^0.48.0",
53
53
  "sinon": "^5.0.10"
54
+ },
55
+ "browser": {
56
+ "cluster": false,
57
+ "crypto": false
54
58
  }
55
59
  }