express-rate-limit 7.2.0 → 7.3.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 +15 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +15 -0
- package/package.json +2 -2
- package/readme.md +10 -1
package/dist/index.cjs
CHANGED
|
@@ -99,6 +99,7 @@ var ValidationError = class extends Error {
|
|
|
99
99
|
};
|
|
100
100
|
var ChangeWarning = class extends ValidationError {
|
|
101
101
|
};
|
|
102
|
+
var usedStores = /* @__PURE__ */ new Set();
|
|
102
103
|
var singleCountKeys = /* @__PURE__ */ new WeakMap();
|
|
103
104
|
var validations = {
|
|
104
105
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -182,6 +183,19 @@ var validations = {
|
|
|
182
183
|
);
|
|
183
184
|
}
|
|
184
185
|
},
|
|
186
|
+
/**
|
|
187
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
188
|
+
*/
|
|
189
|
+
unsharedStore(store) {
|
|
190
|
+
if (usedStores.has(store)) {
|
|
191
|
+
const maybeUniquePrefix = store?.localKeys ? "" : " (with a unique prefix)";
|
|
192
|
+
throw new ValidationError(
|
|
193
|
+
"ERR_ERL_STORE_REUSE",
|
|
194
|
+
`A Store instance must not be shared across multiple rate limiters. Create a new instance of ${store.constructor.name}${maybeUniquePrefix} for each limiter instead.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
usedStores.add(store);
|
|
198
|
+
},
|
|
185
199
|
/**
|
|
186
200
|
* Ensures a given key is incremented only once per request.
|
|
187
201
|
*
|
|
@@ -631,6 +645,7 @@ var rateLimit = (passedOptions) => {
|
|
|
631
645
|
const config = parseOptions(passedOptions ?? {});
|
|
632
646
|
const options = getOptionsFromConfig(config);
|
|
633
647
|
config.validations.creationStack();
|
|
648
|
+
config.validations.unsharedStore(config.store);
|
|
634
649
|
if (typeof config.store.init === "function")
|
|
635
650
|
config.store.init(options);
|
|
636
651
|
const middleware = handleAsyncErrors(
|
package/dist/index.d.cts
CHANGED
|
@@ -45,6 +45,10 @@ declare const validations: {
|
|
|
45
45
|
* @param hits {any} - The `totalHits` returned by the store.
|
|
46
46
|
*/
|
|
47
47
|
positiveHits(hits: any): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
50
|
+
*/
|
|
51
|
+
unsharedStore(store: Store): void;
|
|
48
52
|
/**
|
|
49
53
|
* Ensures a given key is incremented only once per request.
|
|
50
54
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -45,6 +45,10 @@ declare const validations: {
|
|
|
45
45
|
* @param hits {any} - The `totalHits` returned by the store.
|
|
46
46
|
*/
|
|
47
47
|
positiveHits(hits: any): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
50
|
+
*/
|
|
51
|
+
unsharedStore(store: Store): void;
|
|
48
52
|
/**
|
|
49
53
|
* Ensures a given key is incremented only once per request.
|
|
50
54
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ declare const validations: {
|
|
|
45
45
|
* @param hits {any} - The `totalHits` returned by the store.
|
|
46
46
|
*/
|
|
47
47
|
positiveHits(hits: any): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
50
|
+
*/
|
|
51
|
+
unsharedStore(store: Store): void;
|
|
48
52
|
/**
|
|
49
53
|
* Ensures a given key is incremented only once per request.
|
|
50
54
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -71,6 +71,7 @@ var ValidationError = class extends Error {
|
|
|
71
71
|
};
|
|
72
72
|
var ChangeWarning = class extends ValidationError {
|
|
73
73
|
};
|
|
74
|
+
var usedStores = /* @__PURE__ */ new Set();
|
|
74
75
|
var singleCountKeys = /* @__PURE__ */ new WeakMap();
|
|
75
76
|
var validations = {
|
|
76
77
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -154,6 +155,19 @@ var validations = {
|
|
|
154
155
|
);
|
|
155
156
|
}
|
|
156
157
|
},
|
|
158
|
+
/**
|
|
159
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
160
|
+
*/
|
|
161
|
+
unsharedStore(store) {
|
|
162
|
+
if (usedStores.has(store)) {
|
|
163
|
+
const maybeUniquePrefix = store?.localKeys ? "" : " (with a unique prefix)";
|
|
164
|
+
throw new ValidationError(
|
|
165
|
+
"ERR_ERL_STORE_REUSE",
|
|
166
|
+
`A Store instance must not be shared across multiple rate limiters. Create a new instance of ${store.constructor.name}${maybeUniquePrefix} for each limiter instead.`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
usedStores.add(store);
|
|
170
|
+
},
|
|
157
171
|
/**
|
|
158
172
|
* Ensures a given key is incremented only once per request.
|
|
159
173
|
*
|
|
@@ -603,6 +617,7 @@ var rateLimit = (passedOptions) => {
|
|
|
603
617
|
const config = parseOptions(passedOptions ?? {});
|
|
604
618
|
const options = getOptionsFromConfig(config);
|
|
605
619
|
config.validations.creationStack();
|
|
620
|
+
config.validations.unsharedStore(config.store);
|
|
606
621
|
if (typeof config.store.init === "function")
|
|
607
622
|
config.store.init(options);
|
|
608
623
|
const middleware = handleAsyncErrors(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-rate-limit",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.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",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"del-cli": "5.1.0",
|
|
88
88
|
"dts-bundle-generator": "8.0.1",
|
|
89
89
|
"esbuild": "0.19.5",
|
|
90
|
-
"express": "4.
|
|
90
|
+
"express": "4.19.2",
|
|
91
91
|
"husky": "8.0.3",
|
|
92
92
|
"jest": "29.7.0",
|
|
93
93
|
"lint-staged": "15.0.2",
|
package/readme.md
CHANGED
|
@@ -71,6 +71,15 @@ Gateway for developers. Add
|
|
|
71
71
|
authentication and more to any API in minutes. Learn more at
|
|
72
72
|
[zuplo.com](https://zuplo.link/express-rate-limit)
|
|
73
73
|
|
|
74
|
+
<p align="center">
|
|
75
|
+
<a href="https://zuplo.link/express-rate-limit">
|
|
76
|
+
<picture width="322">
|
|
77
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/express-rate-limit/express-rate-limit/assets/114976/cd2f6fa7-eae1-4fbb-be7d-b17df4c6f383">
|
|
78
|
+
<img alt="zuplo-logo" src="https://github.com/express-rate-limit/express-rate-limit/assets/114976/66fd75fa-b39e-4a8c-8d7a-52369bf244dc" width="322">
|
|
79
|
+
</picture>
|
|
80
|
+
</a>
|
|
81
|
+
</p>
|
|
82
|
+
|
|
74
83
|
---
|
|
75
84
|
|
|
76
85
|
Thanks to Mintlify for hosting the documentation at
|
|
@@ -90,7 +99,7 @@ Finally, thank you to everyone who's contributed to this project in any way!
|
|
|
90
99
|
|
|
91
100
|
If you encounter a bug or want to see something added/changed, please go ahead
|
|
92
101
|
and
|
|
93
|
-
[open an issue](https://github.com/
|
|
102
|
+
[open an issue](https://github.com/express-rate-limit/express-rate-limit/issues/new)!
|
|
94
103
|
If you need help with something, feel free to
|
|
95
104
|
[start a discussion](https://github.com/express-rate-limit/express-rate-limit/discussions/new)!
|
|
96
105
|
|