express-rate-limit 6.5.2 → 6.6.0
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/dist/index.cjs +7 -6
- package/dist/index.d.ts +15 -0
- package/dist/index.mjs +7 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,12 +37,11 @@ var MemoryStore = class {
|
|
|
37
37
|
this.windowMs = options.windowMs;
|
|
38
38
|
this.resetTime = calculateNextResetTime(this.windowMs);
|
|
39
39
|
this.hits = {};
|
|
40
|
-
|
|
40
|
+
this.interval = setInterval(async () => {
|
|
41
41
|
await this.resetAll();
|
|
42
42
|
}, this.windowMs);
|
|
43
|
-
if (interval.unref)
|
|
44
|
-
interval.unref();
|
|
45
|
-
}
|
|
43
|
+
if (this.interval.unref)
|
|
44
|
+
this.interval.unref();
|
|
46
45
|
}
|
|
47
46
|
async increment(key) {
|
|
48
47
|
var _a;
|
|
@@ -55,9 +54,8 @@ var MemoryStore = class {
|
|
|
55
54
|
}
|
|
56
55
|
async decrement(key) {
|
|
57
56
|
const current = this.hits[key];
|
|
58
|
-
if (current)
|
|
57
|
+
if (current)
|
|
59
58
|
this.hits[key] = current - 1;
|
|
60
|
-
}
|
|
61
59
|
}
|
|
62
60
|
async resetKey(key) {
|
|
63
61
|
delete this.hits[key];
|
|
@@ -66,6 +64,9 @@ var MemoryStore = class {
|
|
|
66
64
|
this.hits = {};
|
|
67
65
|
this.resetTime = calculateNextResetTime(this.windowMs);
|
|
68
66
|
}
|
|
67
|
+
shutdown() {
|
|
68
|
+
clearInterval(this.interval);
|
|
69
|
+
}
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
// source/lib.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,10 @@ export interface Store {
|
|
|
126
126
|
* Method to reset everyone's hit counter.
|
|
127
127
|
*/
|
|
128
128
|
resetAll?: () => Promise<void> | void;
|
|
129
|
+
/**
|
|
130
|
+
* Method to shutdown the store, stop timers, and release all resources.
|
|
131
|
+
*/
|
|
132
|
+
shutdown?: () => Promise<void> | void;
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
135
|
* The configuration options for the rate limiter.
|
|
@@ -297,6 +301,10 @@ export declare class MemoryStore implements Store {
|
|
|
297
301
|
* The time at which all hit counts will be reset.
|
|
298
302
|
*/
|
|
299
303
|
resetTime: Date;
|
|
304
|
+
/**
|
|
305
|
+
* Reference to the active timer.
|
|
306
|
+
*/
|
|
307
|
+
interval?: NodeJS.Timer;
|
|
300
308
|
/**
|
|
301
309
|
* Method that initializes the store.
|
|
302
310
|
*
|
|
@@ -335,6 +343,13 @@ export declare class MemoryStore implements Store {
|
|
|
335
343
|
* @public
|
|
336
344
|
*/
|
|
337
345
|
resetAll(): Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Method to stop the timer (if currently running) and prevent any memory
|
|
348
|
+
* leaks.
|
|
349
|
+
*
|
|
350
|
+
* @public
|
|
351
|
+
*/
|
|
352
|
+
shutdown(): void;
|
|
338
353
|
}
|
|
339
354
|
|
|
340
355
|
export {
|
package/dist/index.mjs
CHANGED
|
@@ -9,12 +9,11 @@ var MemoryStore = class {
|
|
|
9
9
|
this.windowMs = options.windowMs;
|
|
10
10
|
this.resetTime = calculateNextResetTime(this.windowMs);
|
|
11
11
|
this.hits = {};
|
|
12
|
-
|
|
12
|
+
this.interval = setInterval(async () => {
|
|
13
13
|
await this.resetAll();
|
|
14
14
|
}, this.windowMs);
|
|
15
|
-
if (interval.unref)
|
|
16
|
-
interval.unref();
|
|
17
|
-
}
|
|
15
|
+
if (this.interval.unref)
|
|
16
|
+
this.interval.unref();
|
|
18
17
|
}
|
|
19
18
|
async increment(key) {
|
|
20
19
|
var _a;
|
|
@@ -27,9 +26,8 @@ var MemoryStore = class {
|
|
|
27
26
|
}
|
|
28
27
|
async decrement(key) {
|
|
29
28
|
const current = this.hits[key];
|
|
30
|
-
if (current)
|
|
29
|
+
if (current)
|
|
31
30
|
this.hits[key] = current - 1;
|
|
32
|
-
}
|
|
33
31
|
}
|
|
34
32
|
async resetKey(key) {
|
|
35
33
|
delete this.hits[key];
|
|
@@ -38,6 +36,9 @@ var MemoryStore = class {
|
|
|
38
36
|
this.hits = {};
|
|
39
37
|
this.resetTime = calculateNextResetTime(this.windowMs);
|
|
40
38
|
}
|
|
39
|
+
shutdown() {
|
|
40
|
+
clearInterval(this.interval);
|
|
41
|
+
}
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
// source/lib.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-rate-limit",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Nathan Friedly",
|