rate-limiter-flexible 2.3.4 → 2.3.7

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)
@@ -93,10 +92,13 @@ const headers = {
93
92
  * works in Cluster or PM2 without additional software [See RateLimiterCluster benchmark and detailed description here](https://github.com/animir/node-rate-limiter-flexible/wiki/Cluster)
94
93
  * useful `get`, `set`, `block`, `delete`, `penalty` and `reward` methods
95
94
 
96
- ### Middlewares and plugins
95
+ ### Middlewares, plugins and other packages
97
96
  * [Express middleware](https://github.com/animir/node-rate-limiter-flexible/wiki/Express-Middleware)
98
97
  * [Koa middleware](https://github.com/animir/node-rate-limiter-flexible/wiki/Koa-Middleware)
99
98
  * [Hapi plugin](https://github.com/animir/node-rate-limiter-flexible/wiki/Hapi-plugin)
99
+ * GraphQL [graphql-rate-limit-directive](https://www.npmjs.com/package/graphql-rate-limit-directive)
100
+ * NestJS try [nestjs-rate-limiter](https://www.npmjs.com/package/nestjs-rate-limiter)
101
+ * Fastify based NestJS app try [nestjs-fastify-rate-limiter](https://www.npmjs.com/package/nestjs-fastify-rate-limiter)
100
102
 
101
103
  Some copy/paste examples on Wiki:
102
104
  * [Minimal protection against password brute-force](https://github.com/animir/node-rate-limiter-flexible/wiki/Overall-example#minimal-protection-against-password-brute-force)
@@ -51,7 +51,7 @@ class RateLimiterQueueInternal {
51
51
  getTokensRemaining() {
52
52
  return this._limiterFlexible.get(this._key)
53
53
  .then((rlRes) => {
54
- return rlRes.remainingPoints
54
+ return rlRes !== null ? rlRes.remainingPoints : this._limiterFlexible.points;
55
55
  })
56
56
  }
57
57
 
@@ -72,6 +72,9 @@ module.exports = class MemoryStorage {
72
72
  */
73
73
  delete(key) {
74
74
  if (this._storage[key]) {
75
+ if (this._storage[key].timeoutId) {
76
+ clearTimeout(this._storage[key].timeoutId);
77
+ }
75
78
  delete this._storage[key];
76
79
  return true;
77
80
  }
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.4",
3
+ "version": "2.3.7",
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": {