express-rate-limit 7.1.4 → 7.1.5

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 CHANGED
@@ -666,7 +666,7 @@ var rateLimit = (passedOptions) => {
666
666
  };
667
667
  if (config.skipFailedRequests) {
668
668
  response.on("finish", async () => {
669
- if (!config.requestWasSuccessful(request, response))
669
+ if (!await config.requestWasSuccessful(request, response))
670
670
  await decrementKey();
671
671
  });
672
672
  response.on("close", async () => {
@@ -679,7 +679,7 @@ var rateLimit = (passedOptions) => {
679
679
  }
680
680
  if (config.skipSuccessfulRequests) {
681
681
  response.on("finish", async () => {
682
- if (config.requestWasSuccessful(request, response))
682
+ if (await config.requestWasSuccessful(request, response))
683
683
  await decrementKey();
684
684
  });
685
685
  }
package/dist/index.mjs CHANGED
@@ -638,7 +638,7 @@ var rateLimit = (passedOptions) => {
638
638
  };
639
639
  if (config.skipFailedRequests) {
640
640
  response.on("finish", async () => {
641
- if (!config.requestWasSuccessful(request, response))
641
+ if (!await config.requestWasSuccessful(request, response))
642
642
  await decrementKey();
643
643
  });
644
644
  response.on("close", async () => {
@@ -651,7 +651,7 @@ var rateLimit = (passedOptions) => {
651
651
  }
652
652
  if (config.skipSuccessfulRequests) {
653
653
  response.on("finish", async () => {
654
- if (config.requestWasSuccessful(request, response))
654
+ if (await config.requestWasSuccessful(request, response))
655
655
  await decrementKey();
656
656
  });
657
657
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "7.1.4",
3
+ "version": "7.1.5",
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",
@@ -12,6 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/express-rate-limit/express-rate-limit.git"
14
14
  },
15
+ "funding": "https://github.com/sponsors/express-rate-limit",
15
16
  "keywords": [
16
17
  "express-rate-limit",
17
18
  "express",
@@ -48,11 +49,7 @@
48
49
  "types": "./dist/index.d.ts",
49
50
  "files": [
50
51
  "dist/",
51
- "tsconfig.json",
52
- "package.json",
53
- "readme.md",
54
- "license.md",
55
- "changelog.md"
52
+ "tsconfig.json"
56
53
  ],
57
54
  "engines": {
58
55
  "node": ">= 16"
@@ -94,6 +91,7 @@
94
91
  "husky": "8.0.3",
95
92
  "jest": "29.7.0",
96
93
  "lint-staged": "15.0.2",
94
+ "mintlify": "4.0.63",
97
95
  "npm-run-all": "4.1.5",
98
96
  "ratelimit-header-parser": "0.1.0",
99
97
  "supertest": "6.3.3",
package/changelog.md DELETED
@@ -1,417 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to
7
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
-
9
- ## [7.1.4](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.1.4)
10
-
11
- ### Fixed
12
-
13
- - Ensure header values are strings rather than numbers, for compatibility with
14
- [Bun](https://bun.sh/)
15
-
16
- ## [7.1.3](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.1.3)
17
-
18
- ### Changed
19
-
20
- - Loosened peer dependencies to explicitly allow the Express 5 beta. (See
21
- [#415](https://github.com/express-rate-limit/express-rate-limit/issues/415))
22
-
23
- ## [7.1.2](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.1.2)
24
-
25
- ### Changed
26
-
27
- - Re-organized documentation from readme into docs/ folder and added
28
- documentation website.
29
-
30
- ## [v7.1.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.1.1)
31
-
32
- ### Added
33
-
34
- - Enabled provenance statement generation, see
35
- https://github.com/express-rate-limit/express-rate-limit#406.
36
-
37
- ## [7.1.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.1.0)
38
-
39
- ### Changed
40
-
41
- - The `getKey` method is now always defined. If the store does not have the
42
- required `get` method, `getKey` will throw an error explaining this.
43
-
44
- ## [7.0.2](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.2)
45
-
46
- ### Added
47
-
48
- - Added `cluster-memory-store` to the readme and made a couple of other minor
49
- clarifications.
50
-
51
- ## [7.0.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.1)
52
-
53
- ### Added
54
-
55
- - Added `rate-limit-postgresql` to the `stores` list in the readme.
56
-
57
- ## [7.0.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.0)
58
-
59
- ### Breaking
60
-
61
- - Changed behavior when `max` is set to 0:
62
- - Previously, `max: 0` was treated as a 'disable' flag and would allow all
63
- requests through.
64
- - Starting with v7, all requests will be blocked when max is set to 0.
65
- - To replicate the old behavior, use the
66
- [skip](https://github.com/express-rate-limit/express-rate-limit#skip)
67
- function instead.
68
- - Renamed `req.rateLimit.current` to `req.rateLimit.used`.
69
- - `current` is now a hidden getter that will return the `used` value, but it
70
- will not appear when iterating over the keys or calling `JSON.stringify()`.
71
- - Changed the minimum required Node version from v14 to v16.
72
- - `express-rate-limit` now targets `es2022` in TypeScript/ESBuild.
73
- - Bumped TypeScript from v4 to v5 and `dts-bundle-generator` from v7 to v8.
74
-
75
- ### Deprecated
76
-
77
- - Removed the `draft_polli_ratelimit_headers` option (it was deprecated in v6).
78
- - Use `standardHeaders: 'draft-6'` instead.
79
- - Removed the `onLimitReached` option (it was deprecated in v6).
80
- - [This](<(https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#wrn_erl_deprecated_on_limit_reached)>)
81
- is an example of how to replicate it's behavior with a custom `handler`
82
- option.
83
-
84
- ### Changed
85
-
86
- - The `MemoryStore` now uses precise, per-user reset times rather than a global
87
- window that resets all users at once.
88
- - The `limit` configuration option is now prefered to `max`.
89
- - It still shows the same behavior, and `max` is still supported. The change
90
- was made to better align with terminology used in the IETF standard drafts.
91
-
92
- ### Added
93
-
94
- - The `validate` config option can now be an object with keys to enable or
95
- disable specific validation checks. For more information, see
96
- [this](https://github.com/express-rate-limit/express-rate-limit#validate).
97
-
98
- ## [6.11.2](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.11.2)
99
-
100
- ### Fixed
101
-
102
- - Restored `IncrementResponse ` TypeScript type (See
103
- [#397](https://github.com/express-rate-limit/express-rate-limit/pull/397))
104
-
105
- ## [6.11.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.11.1)
106
-
107
- ### Fixed
108
-
109
- - Check for prefixed keys when validating that the stores have single counted
110
- keys (See
111
- [#395](https://github.com/express-rate-limit/express-rate-limit/issues/395)).
112
-
113
- ## [6.11.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.11.0)
114
-
115
- ### Added
116
-
117
- - Support for retrieving the current hit count and reset time for a given key
118
- from a store (See
119
- [#390](https://github.com/express-rate-limit/express-rate-limit/issues/389)).
120
-
121
- ## [6.10.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.10.0)
122
-
123
- ### Added
124
-
125
- - Support for combined `RateLimit` header from the
126
- [RateLimit header fields for HTTP standardization draft](https://github.com/ietf-wg-httpapi/ratelimit-headers)
127
- adopted by the IETF. Enable by setting `standardHeaders: 'draft-7'`.
128
- - New `standardHeaders: 'draft-6'` option, treated equivalent to
129
- `standardHeaders: true` from previous releases. Note that `true` and `false`
130
- are still supported.
131
- - New `RateLimit-Policy` header added when `standardHeaders` is set to
132
- `'draft-6'`, `'draft-7'`, or `true`.
133
- - Warning when using deprecated `draft_polli_ratelimit_headers` option.
134
- - Warning when using deprecated `onLimitReached` option.
135
- - Warning when `totalHits` value returned from Store is invalid.
136
-
137
- ## [6.9.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.9.0)
138
-
139
- ### Added
140
-
141
- - New validaion check for double-counted requests.
142
- - Added help link to each validation error, directing users to the appropriate
143
- wiki page for more info.
144
-
145
- ### Changed
146
-
147
- - Miscellaneous documenation improvements.
148
-
149
- ## [6.8.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.8.0) & [6.7.2](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.8.0)
150
-
151
- ### Changed
152
-
153
- - Revert 6.7.1 change that bumped typescript from 5.x to 4.x and
154
- dts-bundle-generator from 8.x to 7.x (See
155
- [#360](https://github.com/express-rate-limit/express-rate-limit/issues/360)).
156
-
157
- ## [6.8.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.8.0)
158
-
159
- ### Added
160
-
161
- - Added a set of validation checks that will log an error if failed. See
162
- https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes for
163
- a list of potential errors. Can be disabled by setting `validate: false` in
164
- the configuration. Automatically disables after the first request. (See
165
- [#358](https://github.com/express-rate-limit/express-rate-limit/issues/358)).
166
-
167
- ## [6.7.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.7.1)
168
-
169
- ### Fixed
170
-
171
- - Fixed compatibility with TypeScript's TypeScript new `node16` module
172
- resolution strategy (See
173
- [#355](https://github.com/express-rate-limit/express-rate-limit/issues/355)).
174
-
175
- ### Changed
176
-
177
- - Bumped development dependencies
178
- - This initially include bumping typescript from 4.x to 5.x and
179
- dts-bundle-generator from 7.x to 8.x
180
- - Added `node` 20 to list of versions the CI jobs run on.
181
-
182
- No functional changes.
183
-
184
- ## [6.7.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v6.7.0)
185
-
186
- ### Changed
187
-
188
- - Updated links to point to the new `express-rate-limit` organization on GitHub.
189
- - Added advertisement to `readme.md` for project sponsor
190
- [Zuplo](https://zuplo.link/express-rate-limit).
191
- - Updated to `typescript` version 5 and bumped other dependencies.
192
- - Dropped `node` 12, and added `node` 19 to the list of versions the CI jobs run
193
- on.
194
-
195
- No functional changes.
196
-
197
- ## [6.6.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.6.0)
198
-
199
- ### Added
200
-
201
- - Added `shutdown` method to the Store interface and the MemoryStore.
202
-
203
- ## [6.5.2](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.5.2)
204
-
205
- ### Fixed
206
-
207
- - Fixed an issue with missing types in ESM monorepos.
208
-
209
- ## [6.5.1](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.5.1)
210
-
211
- ### Added
212
-
213
- - The message option can now be a (sync/asynx) function that returns a value
214
- (#311)
215
-
216
- ### Changed
217
-
218
- - Updated all dependencies
219
-
220
- Note: 6.5.0 was not released due to CI automation issues.
221
-
222
- ## [6.4.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.3.0)
223
-
224
- ### Added
225
-
226
- - Adds Express 5 (`5.0.0-beta.1`) as a supported peer dependency (#304)
227
-
228
- ### Changed
229
-
230
- - Tests are now run on Node 12, 14, 16 and 18 on CI (#305)
231
- - Updated all development dependencies (#306)
232
-
233
- ## [6.3.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.3.0)
234
-
235
- ### Changed
236
-
237
- - Changes the build target to es2019 so that ESBuild outputs code that can run
238
- with Node 12.
239
- - Changes the minimum required Node version to 12.9.0.
240
-
241
- ## [6.2.1](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.2.1)
242
-
243
- ### Fixed
244
-
245
- - Use the default value for an option when `undefined` is passed to the rate
246
- limiter.
247
-
248
- ## [6.2.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.2.0)
249
-
250
- ### Added
251
-
252
- - Export the `MemoryStore`, so it can now be imported as a named import
253
- (`import { MemoryStore } from 'express-rate-limit'`).
254
-
255
- ### Fixed
256
-
257
- - Deprecate the `onLimitReached` option (this was supposed to be deprecated in
258
- v6.0.0 itself); developers should use a custom handler function that checks if
259
- the rate limit has been exceeded instead.
260
-
261
- ## [6.1.0](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.1.0)
262
-
263
- ### Added
264
-
265
- - Added a named export `rateLimit` in case the default import does not work.
266
-
267
- ### Fixed
268
-
269
- - Added a named export `default`, so Typescript CommonJS developers can
270
- default-import the library (`import rateLimit from 'express-rate-limit'`).
271
-
272
- ## [6.0.5](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.0.5)
273
-
274
- ### Fixed
275
-
276
- - Use named imports for ExpressJS types so users do not need to enable the
277
- `esModuleInterop` flag in their Typescript compiler configuration.
278
-
279
- ## [6.0.4](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.0.4)
280
-
281
- ### Fixed
282
-
283
- - Upload the built package as a `.tgz` to GitHub releases.
284
-
285
- ### Changed
286
-
287
- - Add ` main` and `module` fields to `package.json`. This helps tools such as
288
- ESLint that do not yet support the `exports` field.
289
- - Bumped the minimum node.js version in `package-lock.json` to match
290
- `package.json`
291
-
292
- ## [6.0.3](https://github.com/nfriedly/express-rate-limit/releases/tag/v6.0.3)
293
-
294
- ### Changed
295
-
296
- - Bumped minimum Node version from 12.9 to 14.5 in `package.json` because the
297
- transpiled output uses the nullish coalescing operator (`??`), which
298
- [isn't supported in node.js prior to 14.x](https://node.green/#ES2020-features--nullish-coalescing-operator-----).
299
-
300
- ## [6.0.2](https://github.com/nfriedly/express-rate-limit/releases/v6.0.2)
301
-
302
- ### Fixed
303
-
304
- - Ensure CommonJS projects can import the module.
305
-
306
- ### Added
307
-
308
- - Add additional tests that test:
309
- - importing the library in `js-cjs`, `js-esm`, `ts-cjs`, `ts-esm`
310
- environments.
311
- - usage of the library with external stores (`redis`, `mongo`, `memcached`,
312
- `precise`).
313
-
314
- ### Changed
315
-
316
- - Use [`esbuild`](https://esbuild.github.io/) to generate ESM and CJS output.
317
- This reduces the size of the built package from 138 kb to 13kb and build time
318
- to 4 ms! :rocket:
319
- - Use [`dts-bundle-generator`](https://github.com/timocov/dts-bundle-generator)
320
- to generate a single Typescript declaration file.
321
-
322
- ## [6.0.1](https://github.com/nfriedly/express-rate-limit/releases/v6.0.1)
323
-
324
- ### Fixed
325
-
326
- - Ensure CommonJS projects can import the module.
327
-
328
- ## [6.0.0](https://github.com/nfriedly/express-rate-limit/releases/v6.0.0)
329
-
330
- ### Added
331
-
332
- - `express` 4.x as a peer dependency.
333
- - Better Typescript support (the library was rewritten in Typescript).
334
- - Export the package as both ESM and CJS.
335
- - Publish the built package (`.tgz` file) on GitHub releases as well as the npm
336
- registry.
337
- - Issue and PR templates.
338
- - A contributing guide.
339
-
340
- ### Changed
341
-
342
- - Rename the `draft_polli_ratelimit_headers` option to `standardHeaders`.
343
- - Rename the `headers` option to `legacyHeaders`.
344
- - `Retry-After` header is now sent if either `legacyHeaders` or
345
- `standardHeaders` is set.
346
- - Allow `keyGenerator` to be an async function/return a promise.
347
- - Change the way custom stores are defined.
348
- - Add the `init` method for stores to set themselves up using options passed
349
- to the middleware.
350
- - Rename the `incr` method to `increment`.
351
- - Allow the `increment`, `decrement`, `resetKey` and `resetAll` methods to
352
- return a promise.
353
- - Old stores will automatically be promisified and used.
354
- - The package can now only be used with NodeJS version 12.9.0 or greater.
355
- - The `onLimitReached` configuration option is now deprecated. Replace it with a
356
- custom `handler` that checks the number of hits.
357
-
358
- ### Removed
359
-
360
- - Remove the deprecated `limiter.resetIp` method (use the `limiter.resetKey`
361
- method instead).
362
- - Remove the deprecated options `delayMs`, `delayAfter` (the delay functionality
363
- was moved to the
364
- [`express-slow-down`](https://github.com/nfriedly/express-slow-down) package)
365
- and `global` (use a key generator that returns a constant value).
366
-
367
- ## [5.x](https://github.com/nfriedly/express-rate-limit/releases/tag/v5.5.1)
368
-
369
- ### Added
370
-
371
- - The middleware ~throws~ logs an error if `request.ip` is undefined.
372
-
373
- ### Removed
374
-
375
- - Removes typescript typings. (See
376
- [#138](https://github.com/nfriedly/express-rate-limit/issues/138))
377
-
378
- ## [4.x](https://github.com/nfriedly/express-rate-limit/releases/tag/v4.0.4)
379
-
380
- ### Changed
381
-
382
- - The library no longer modifies the passed-in options object, it instead makes
383
- a clone of it.
384
-
385
- ## [3.x](https://github.com/nfriedly/express-rate-limit/releases/tag/v3.5.2)
386
-
387
- ### Added
388
-
389
- - Simplifies the default `handler` function so that it no longer changes the
390
- response format. The default handler also uses
391
- [response.send](https://expressjs.com/en/4x/api.html#response.send).
392
-
393
- ### Changes
394
-
395
- - `onLimitReached` now only triggers once for a client and window. However, the
396
- `handle` method is called for every blocked request.
397
-
398
- ### Removed
399
-
400
- - The `delayAfter` and `delayMs` options; they were moved to the
401
- [express-slow-down](https://npmjs.org/package/express-slow-down) package.
402
-
403
- ## [2.x](https://github.com/nfriedly/express-rate-limit/releases/tag/v2.14.2)
404
-
405
- ### Added
406
-
407
- - Support external stores (from version 2.3.0) onwards.
408
- - A `limiter.resetKey()` method to reset the hit counter for a particular client
409
-
410
- ### Changes
411
-
412
- - The rate limiter now uses a less precise but less resource intensive method of
413
- tracking hits from a client.
414
-
415
- ### Removed
416
-
417
- - The `global` option.