rate-limiter-flexible 2.3.2 → 2.3.6
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
|
@@ -93,10 +93,13 @@ const headers = {
|
|
|
93
93
|
* 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
94
|
* useful `get`, `set`, `block`, `delete`, `penalty` and `reward` methods
|
|
95
95
|
|
|
96
|
-
### Middlewares and
|
|
96
|
+
### Middlewares, plugins and other packages
|
|
97
97
|
* [Express middleware](https://github.com/animir/node-rate-limiter-flexible/wiki/Express-Middleware)
|
|
98
98
|
* [Koa middleware](https://github.com/animir/node-rate-limiter-flexible/wiki/Koa-Middleware)
|
|
99
99
|
* [Hapi plugin](https://github.com/animir/node-rate-limiter-flexible/wiki/Hapi-plugin)
|
|
100
|
+
* GraphQL [graphql-rate-limit-directive](https://www.npmjs.com/package/graphql-rate-limit-directive)
|
|
101
|
+
* NestJS try [nestjs-rate-limiter](https://www.npmjs.com/package/nestjs-rate-limiter)
|
|
102
|
+
* Fastify based NestJS app try [nestjs-fastify-rate-limiter](https://www.npmjs.com/package/nestjs-fastify-rate-limiter)
|
|
100
103
|
|
|
101
104
|
Some copy/paste examples on Wiki:
|
|
102
105
|
* [Minimal protection against password brute-force](https://github.com/animir/node-rate-limiter-flexible/wiki/Overall-example#minimal-protection-against-password-brute-force)
|
package/lib/RateLimiterMongo.js
CHANGED
|
@@ -4,21 +4,22 @@ const RateLimiterRes = require('./RateLimiterRes');
|
|
|
4
4
|
/**
|
|
5
5
|
* Get MongoDB driver version as upsert options differ
|
|
6
6
|
* @params {Object} Client instance
|
|
7
|
-
* @returns {
|
|
7
|
+
* @returns {Object} Version Object containing major, feature & minor versions.
|
|
8
8
|
*/
|
|
9
9
|
function getDriverVersion(client) {
|
|
10
10
|
try {
|
|
11
|
-
|
|
12
|
-
if (client.client) {
|
|
13
|
-
({ version } = client.client.topology.s.options.metadata.driver);
|
|
14
|
-
} else {
|
|
15
|
-
({ version } = client.topology.s.options.metadata.driver);
|
|
16
|
-
}
|
|
17
|
-
const majorVersion = parseInt(version);
|
|
11
|
+
const _client = client.client ? client.client : client;
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
const { version } = _client.topology.s.options.metadata.driver;
|
|
14
|
+
const _v = version.split('.').map(v => parseInt(v));
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
major: _v[0],
|
|
18
|
+
feature: _v[1],
|
|
19
|
+
patch: _v[2],
|
|
20
|
+
};
|
|
20
21
|
} catch (err) {
|
|
21
|
-
return
|
|
22
|
+
return { major: 0, feature: 0, patch: 0 };
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -174,7 +175,12 @@ class RateLimiterMongo extends RateLimiterStoreAbstract {
|
|
|
174
175
|
const upsertOptions = {
|
|
175
176
|
upsert: true,
|
|
176
177
|
};
|
|
177
|
-
if (this._driverVersion >= 4)
|
|
178
|
+
if ((this._driverVersion.major >= 4) ||
|
|
179
|
+
(this._driverVersion.major === 3 &&
|
|
180
|
+
(this._driverVersion.feature >=7) ||
|
|
181
|
+
(this._driverVersion.feature >= 6 &&
|
|
182
|
+
this._driverVersion.patch >= 7 )))
|
|
183
|
+
{
|
|
178
184
|
upsertOptions.returnDocument = 'after';
|
|
179
185
|
} else {
|
|
180
186
|
upsertOptions.returnOriginal = false;
|
package/lib/RateLimiterQueue.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ export class RateLimiterAbstract {
|
|
|
141
141
|
/**
|
|
142
142
|
* Get RateLimiterRes in current duration. It always returns RateLimiterRes.isFirstInDuration=false.
|
|
143
143
|
* @param key is usually IP address or some unique client id
|
|
144
|
+
* @param options
|
|
144
145
|
* @returns Promise, which:
|
|
145
146
|
* - `resolved` with RateLimiterRes if key is set
|
|
146
147
|
* - `resolved` with null if key is NOT set or expired
|
|
@@ -205,6 +206,11 @@ export class RateLimiterAbstract {
|
|
|
205
206
|
|
|
206
207
|
export class RateLimiterStoreAbstract extends RateLimiterAbstract {
|
|
207
208
|
constructor(opts: IRateLimiterStoreOptions);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Cleanup keys blocked in current process memory
|
|
212
|
+
*/
|
|
213
|
+
deleteInMemoryBlockedAll(): void;
|
|
208
214
|
}
|
|
209
215
|
|
|
210
216
|
interface IRateLimiterOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rate-limiter-flexible",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.6",
|
|
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": {
|