express-rate-limit 6.2.1 → 6.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/changelog.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to
7
7
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
+ ## [6.2.1](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.2.1)
10
+
11
+ ### Fixed
12
+
13
+ - Use the default value for an option when `undefined` is passed to the rate
14
+ limiter.
15
+
9
16
  ## [6.2.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.2.0)
10
17
 
11
18
  ### Added
package/dist/index.cjs CHANGED
@@ -48,7 +48,8 @@ var MemoryStore = class {
48
48
  }
49
49
  }
50
50
  async increment(key) {
51
- const totalHits = (this.hits[key] ?? 0) + 1;
51
+ var _a;
52
+ const totalHits = ((_a = this.hits[key]) != null ? _a : 0) + 1;
52
53
  this.hits[key] = totalHits;
53
54
  return {
54
55
  totalHits,
@@ -101,14 +102,15 @@ var promisifyStore = (passedStore) => {
101
102
  return new PromisifiedStore();
102
103
  };
103
104
  var parseOptions = (passedOptions) => {
105
+ var _a, _b, _c;
104
106
  const notUndefinedOptions = omitUndefinedOptions(passedOptions);
105
107
  const config = {
106
108
  windowMs: 60 * 1e3,
107
109
  max: 5,
108
110
  message: "Too many requests, please try again later.",
109
111
  statusCode: 429,
110
- legacyHeaders: passedOptions.headers ?? true,
111
- standardHeaders: passedOptions.draft_polli_ratelimit_headers ?? false,
112
+ legacyHeaders: (_a = passedOptions.headers) != null ? _a : true,
113
+ standardHeaders: (_b = passedOptions.draft_polli_ratelimit_headers) != null ? _b : false,
112
114
  requestPropertyName: "rateLimit",
113
115
  skipFailedRequests: false,
114
116
  skipSuccessfulRequests: false,
@@ -126,7 +128,7 @@ var parseOptions = (passedOptions) => {
126
128
  onLimitReached: (_request, _response, _optionsUsed) => {
127
129
  },
128
130
  ...notUndefinedOptions,
129
- store: promisifyStore(notUndefinedOptions.store ?? new MemoryStore())
131
+ store: promisifyStore((_c = notUndefinedOptions.store) != null ? _c : new MemoryStore())
130
132
  };
131
133
  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") {
132
134
  throw new TypeError("An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface.");
@@ -141,7 +143,7 @@ var handleAsyncErrors = (fn) => async (request, response, next) => {
141
143
  }
142
144
  };
143
145
  var rateLimit = (passedOptions) => {
144
- const options = parseOptions(passedOptions ?? {});
146
+ const options = parseOptions(passedOptions != null ? passedOptions : {});
145
147
  if (typeof options.store.init === "function")
146
148
  options.store.init(options);
147
149
  const middleware = handleAsyncErrors(async (request, response, next) => {
package/dist/index.mjs CHANGED
@@ -17,7 +17,8 @@ var MemoryStore = class {
17
17
  }
18
18
  }
19
19
  async increment(key) {
20
- const totalHits = (this.hits[key] ?? 0) + 1;
20
+ var _a;
21
+ const totalHits = ((_a = this.hits[key]) != null ? _a : 0) + 1;
21
22
  this.hits[key] = totalHits;
22
23
  return {
23
24
  totalHits,
@@ -70,14 +71,15 @@ var promisifyStore = (passedStore) => {
70
71
  return new PromisifiedStore();
71
72
  };
72
73
  var parseOptions = (passedOptions) => {
74
+ var _a, _b, _c;
73
75
  const notUndefinedOptions = omitUndefinedOptions(passedOptions);
74
76
  const config = {
75
77
  windowMs: 60 * 1e3,
76
78
  max: 5,
77
79
  message: "Too many requests, please try again later.",
78
80
  statusCode: 429,
79
- legacyHeaders: passedOptions.headers ?? true,
80
- standardHeaders: passedOptions.draft_polli_ratelimit_headers ?? false,
81
+ legacyHeaders: (_a = passedOptions.headers) != null ? _a : true,
82
+ standardHeaders: (_b = passedOptions.draft_polli_ratelimit_headers) != null ? _b : false,
81
83
  requestPropertyName: "rateLimit",
82
84
  skipFailedRequests: false,
83
85
  skipSuccessfulRequests: false,
@@ -95,7 +97,7 @@ var parseOptions = (passedOptions) => {
95
97
  onLimitReached: (_request, _response, _optionsUsed) => {
96
98
  },
97
99
  ...notUndefinedOptions,
98
- store: promisifyStore(notUndefinedOptions.store ?? new MemoryStore())
100
+ store: promisifyStore((_c = notUndefinedOptions.store) != null ? _c : new MemoryStore())
99
101
  };
100
102
  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") {
101
103
  throw new TypeError("An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface.");
@@ -110,7 +112,7 @@ var handleAsyncErrors = (fn) => async (request, response, next) => {
110
112
  }
111
113
  };
112
114
  var rateLimit = (passedOptions) => {
113
- const options = parseOptions(passedOptions ?? {});
115
+ const options = parseOptions(passedOptions != null ? passedOptions : {});
114
116
  if (typeof options.store.init === "function")
115
117
  options.store.init(options);
116
118
  const middleware = handleAsyncErrors(async (request, response, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "6.2.1",
3
+ "version": "6.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",
@@ -46,12 +46,12 @@
46
46
  "changelog.md"
47
47
  ],
48
48
  "engines": {
49
- "node": ">= 14.5.0"
49
+ "node": ">= 12.9.0"
50
50
  },
51
51
  "scripts": {
52
52
  "clean": "del-cli dist/ coverage/ *.log *.tmp *.bak *.tgz",
53
- "build:cjs": "esbuild --bundle --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit; module.exports.MemoryStore = MemoryStore;\" source/index.ts",
54
- "build:esm": "esbuild --bundle --format=esm --outfile=dist/index.mjs source/index.ts",
53
+ "build:cjs": "esbuild --bundle --target=es2019 --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit; module.exports.MemoryStore = MemoryStore;\" source/index.ts",
54
+ "build:esm": "esbuild --bundle --target=es2019 --format=esm --outfile=dist/index.mjs source/index.ts",
55
55
  "build:types": "dts-bundle-generator --out-file=dist/index.d.ts source/index.ts",
56
56
  "compile": "run-s clean build:*",
57
57
  "lint:code": "xo --ignore test/external/",