express-rate-limit 6.2.0 → 6.2.1
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 +17 -7
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +17 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -101,9 +101,9 @@ var promisifyStore = (passedStore) => {
|
|
|
101
101
|
return new PromisifiedStore();
|
|
102
102
|
};
|
|
103
103
|
var parseOptions = (passedOptions) => {
|
|
104
|
-
const
|
|
104
|
+
const notUndefinedOptions = omitUndefinedOptions(passedOptions);
|
|
105
|
+
const config = {
|
|
105
106
|
windowMs: 60 * 1e3,
|
|
106
|
-
store: new MemoryStore(),
|
|
107
107
|
max: 5,
|
|
108
108
|
message: "Too many requests, please try again later.",
|
|
109
109
|
statusCode: 429,
|
|
@@ -121,17 +121,17 @@ var parseOptions = (passedOptions) => {
|
|
|
121
121
|
return request.ip;
|
|
122
122
|
},
|
|
123
123
|
handler: (_request, response, _next, _optionsUsed) => {
|
|
124
|
-
response.status(
|
|
124
|
+
response.status(config.statusCode).send(config.message);
|
|
125
125
|
},
|
|
126
126
|
onLimitReached: (_request, _response, _optionsUsed) => {
|
|
127
127
|
},
|
|
128
|
-
...
|
|
128
|
+
...notUndefinedOptions,
|
|
129
|
+
store: promisifyStore(notUndefinedOptions.store ?? new MemoryStore())
|
|
129
130
|
};
|
|
130
|
-
if (typeof
|
|
131
|
+
if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || typeof config.store.resetAll !== "undefined" && typeof config.store.resetAll !== "function" || typeof config.store.init !== "undefined" && typeof config.store.init !== "function") {
|
|
131
132
|
throw new TypeError("An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface.");
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
return options;
|
|
134
|
+
return config;
|
|
135
135
|
};
|
|
136
136
|
var handleAsyncErrors = (fn) => async (request, response, next) => {
|
|
137
137
|
try {
|
|
@@ -220,6 +220,16 @@ var rateLimit = (passedOptions) => {
|
|
|
220
220
|
middleware.resetKey = options.store.resetKey.bind(options.store);
|
|
221
221
|
return middleware;
|
|
222
222
|
};
|
|
223
|
+
var omitUndefinedOptions = (passedOptions) => {
|
|
224
|
+
const omittedOptions = {};
|
|
225
|
+
for (const k of Object.keys(passedOptions)) {
|
|
226
|
+
const key = k;
|
|
227
|
+
if (passedOptions[key] !== void 0) {
|
|
228
|
+
omittedOptions[key] = passedOptions[key];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return omittedOptions;
|
|
232
|
+
};
|
|
223
233
|
var lib_default = rateLimit;
|
|
224
234
|
module.exports = __toCommonJS(source_exports);
|
|
225
235
|
module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit; module.exports.MemoryStore = MemoryStore;
|
package/dist/index.d.ts
CHANGED
|
@@ -233,7 +233,7 @@ export interface Options {
|
|
|
233
233
|
*
|
|
234
234
|
* By default, the built-in `MemoryStore` will be used.
|
|
235
235
|
*/
|
|
236
|
-
store: Store;
|
|
236
|
+
store: Store | LegacyStore;
|
|
237
237
|
/**
|
|
238
238
|
* Whether to send `X-RateLimit-*` headers with the rate limit and the number
|
|
239
239
|
* of requests.
|
|
@@ -276,9 +276,7 @@ export interface RateLimitInfo {
|
|
|
276
276
|
*
|
|
277
277
|
* @public
|
|
278
278
|
*/
|
|
279
|
-
export declare const rateLimit: (passedOptions?:
|
|
280
|
-
store?: LegacyStore | Store | undefined;
|
|
281
|
-
}) | undefined) => RateLimitRequestHandler;
|
|
279
|
+
export declare const rateLimit: (passedOptions?: Partial<Options> | undefined) => RateLimitRequestHandler;
|
|
282
280
|
/**
|
|
283
281
|
* A `Store` that stores the hit count for each client in memory.
|
|
284
282
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -70,9 +70,9 @@ var promisifyStore = (passedStore) => {
|
|
|
70
70
|
return new PromisifiedStore();
|
|
71
71
|
};
|
|
72
72
|
var parseOptions = (passedOptions) => {
|
|
73
|
-
const
|
|
73
|
+
const notUndefinedOptions = omitUndefinedOptions(passedOptions);
|
|
74
|
+
const config = {
|
|
74
75
|
windowMs: 60 * 1e3,
|
|
75
|
-
store: new MemoryStore(),
|
|
76
76
|
max: 5,
|
|
77
77
|
message: "Too many requests, please try again later.",
|
|
78
78
|
statusCode: 429,
|
|
@@ -90,17 +90,17 @@ var parseOptions = (passedOptions) => {
|
|
|
90
90
|
return request.ip;
|
|
91
91
|
},
|
|
92
92
|
handler: (_request, response, _next, _optionsUsed) => {
|
|
93
|
-
response.status(
|
|
93
|
+
response.status(config.statusCode).send(config.message);
|
|
94
94
|
},
|
|
95
95
|
onLimitReached: (_request, _response, _optionsUsed) => {
|
|
96
96
|
},
|
|
97
|
-
...
|
|
97
|
+
...notUndefinedOptions,
|
|
98
|
+
store: promisifyStore(notUndefinedOptions.store ?? new MemoryStore())
|
|
98
99
|
};
|
|
99
|
-
if (typeof
|
|
100
|
+
if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || typeof config.store.resetAll !== "undefined" && typeof config.store.resetAll !== "function" || typeof config.store.init !== "undefined" && typeof config.store.init !== "function") {
|
|
100
101
|
throw new TypeError("An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface.");
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
-
return options;
|
|
103
|
+
return config;
|
|
104
104
|
};
|
|
105
105
|
var handleAsyncErrors = (fn) => async (request, response, next) => {
|
|
106
106
|
try {
|
|
@@ -189,6 +189,16 @@ var rateLimit = (passedOptions) => {
|
|
|
189
189
|
middleware.resetKey = options.store.resetKey.bind(options.store);
|
|
190
190
|
return middleware;
|
|
191
191
|
};
|
|
192
|
+
var omitUndefinedOptions = (passedOptions) => {
|
|
193
|
+
const omittedOptions = {};
|
|
194
|
+
for (const k of Object.keys(passedOptions)) {
|
|
195
|
+
const key = k;
|
|
196
|
+
if (passedOptions[key] !== void 0) {
|
|
197
|
+
omittedOptions[key] = passedOptions[key];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return omittedOptions;
|
|
201
|
+
};
|
|
192
202
|
var lib_default = rateLimit;
|
|
193
203
|
export {
|
|
194
204
|
MemoryStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-rate-limit",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.1",
|
|
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",
|