express-rate-limit 7.0.0 → 7.0.2

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.
Files changed (3) hide show
  1. package/changelog.md +14 -0
  2. package/package.json +22 -23
  3. package/readme.md +26 -28
package/changelog.md CHANGED
@@ -6,6 +6,19 @@ 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
+ ## [7.0.2](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.2)
10
+
11
+ ### Added
12
+
13
+ - Added `cluster-memory-store` to the readme and made a couple of other minor
14
+ clarifications.
15
+
16
+ ## [7.0.1](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.1)
17
+
18
+ ### Added
19
+
20
+ - Added `rate-limit-postgresql` to the `stores` list in the readme.
21
+
9
22
  ## [7.0.0](https://github.com/express-rate-limit/express-rate-limit/releases/tag/v7.0.0)
10
23
 
11
24
  ### Breaking
@@ -356,6 +369,7 @@ Note: 6.5.0 was not released due to CI automation issues.
356
369
 
357
370
  ### Added
358
371
 
372
+ - Support external stores (from version 2.3.0) onwards.
359
373
  - A `limiter.resetKey()` method to reset the hit counter for a particular client
360
374
 
361
375
  ### Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
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",
@@ -76,28 +76,27 @@
76
76
  "express": "^4 || ^5"
77
77
  },
78
78
  "devDependencies": {
79
- "@express-rate-limit/prettier": "1.1.0",
80
- "@express-rate-limit/tsconfig": "1.0.0",
81
- "@jest/globals": "29.6.4",
82
- "@types/express": "4.17.17",
83
- "@types/jest": "29.5.4",
84
- "@types/node": "20.5.9",
85
- "@types/supertest": "2.0.12",
86
- "cross-env": "7.0.3",
87
- "del-cli": "5.1.0",
88
- "dts-bundle-generator": "8.0.1",
89
- "esbuild": "0.19.2",
90
- "express": "4.18.2",
91
- "husky": "8.0.3",
92
- "jest": "29.6.4",
93
- "lint-staged": "14.0.1",
94
- "npm-run-all": "4.1.5",
95
- "ratelimit-header-parser": "0.1.0",
96
- "supertest": "6.3.3",
97
- "ts-jest": "29.1.1",
98
- "ts-node": "10.9.1",
99
- "typescript": "5.2.2",
100
- "xo": "0.56.0"
79
+ "@express-rate-limit/prettier": "1.1.0",
80
+ "@express-rate-limit/tsconfig": "1.0.0",
81
+ "@jest/globals": "29.6.4",
82
+ "@types/express": "4.17.17",
83
+ "@types/jest": "29.5.4",
84
+ "@types/node": "20.5.9",
85
+ "@types/supertest": "2.0.12",
86
+ "del-cli": "5.1.0",
87
+ "dts-bundle-generator": "8.0.1",
88
+ "esbuild": "0.19.2",
89
+ "express": "4.18.2",
90
+ "husky": "8.0.3",
91
+ "jest": "29.6.4",
92
+ "lint-staged": "14.0.1",
93
+ "npm-run-all": "4.1.5",
94
+ "ratelimit-header-parser": "0.1.0",
95
+ "supertest": "6.3.3",
96
+ "ts-jest": "29.1.1",
97
+ "ts-node": "10.9.1",
98
+ "typescript": "5.2.2",
99
+ "xo": "0.56.0"
101
100
  },
102
101
  "xo": {
103
102
  "prettier": true,
package/readme.md CHANGED
@@ -34,14 +34,18 @@ The default `MemoryStore` is probably fine.
34
34
 
35
35
  ### API Rate Limit Enforcement
36
36
 
37
- You may want to switch to a different [store](#store), especially if you have
38
- multiple servers or processes (for example, with the
39
- [node:cluster](https://nodejs.org/api/cluster.html) module). Using an external
40
- data store to syhcnronize hits
41
- ([redis](https://npmjs.com/package/rate-limit-redis),
42
- [memcached](https://npmjs.org/package/rate-limit-memcached), [etc.](#store))
43
- guarentees the expected result even if some requests get handled by different
44
- servers/processes or a server is restarted.
37
+ The default `MemoryStore` stores the hit counts for clients in memory, and is
38
+ thus unsuitable for use when running multiple servers or processes.
39
+
40
+ If you have multiple processes on a single server (via the
41
+ [node:cluster](https://nodejs.org/api/cluster.html) module), the
42
+ [`cluster-memory-store`](https://npmjs.com/package/@express-rate-limit/cluster-memory-store)
43
+ will keep them all in sync without needing an external data store.
44
+
45
+ If you have multiple servers, or want to maintain state across app restarts, use
46
+ an external data store such as
47
+ [redis](https://npmjs.com/package/rate-limit-redis),
48
+ [memcached](https://npmjs.org/package/rate-limit-memcached), [etc.](#store).
45
49
 
46
50
  ### Alternate Rate Limiters
47
51
 
@@ -422,17 +426,6 @@ const limiter = rateLimit({
422
426
  })
423
427
  ```
424
428
 
425
- ### `onLimitReached`
426
-
427
- > `function`
428
-
429
- A (sync/async) function that accepts the Express `req` and `res` objects that is
430
- called the on the request where a client has just exceeded their rate limit.
431
-
432
- This method was
433
- [deprecated in v6](https://github.com/express-rate-limit/express-rate-limit/releases/v6.0.0) -
434
- Please use a custom `handler` that checks the number of hits instead.
435
-
436
429
  ### `skip`
437
430
 
438
431
  > `function`
@@ -524,13 +517,15 @@ By default, the [`memory-store`](source/memory-store.ts) is used.
524
517
 
525
518
  Here is a list of external stores:
526
519
 
527
- | Name | Description | Legacy/Modern |
528
- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------- |
529
- | [`memory-store`](source/memory-store.ts) | _(default)_ Simple in-memory option. Does not share state when app has multiple processes or servers. | Modern as of v6.0.0 |
530
- | [`rate-limit-redis`](https://npmjs.com/package/rate-limit-redis) | A [Redis](http://redis.io/)-backed store, more suitable for large or demanding deployments. | Modern as of v3.0.0 |
531
- | [`rate-limit-memcached`](https://npmjs.org/package/rate-limit-memcached) | A [Memcached](https://memcached.org/)-backed store. | Legacy |
532
- | [`rate-limit-mongo`](https://www.npmjs.com/package/rate-limit-mongo) | A [MongoDB](https://www.mongodb.com/)-backed store. | Legacy |
533
- | [`precise-memory-rate-limit`](https://www.npmjs.com/package/precise-memory-rate-limit) | A memory store similar to the built-in one, except that it stores a distinct timestamp for each key. | Modern as of v2.0.0 |
520
+ | Name | Description | Legacy/Modern |
521
+ | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
522
+ | [`memory-store`](source/memory-store.ts) | _(default)_ Simple in-memory option. Does not share state when app has multiple processes or servers. | Modern as of v6.0.0 |
523
+ | [`cluster-memory-store`](https://npmjs.com/package/@express-rate-limit/cluster-memory-store) | A memory-store wrapper that shares state across all processes on a server via the [node:cluster](https://nodejs.org/api/cluster.html) module. | Modern |
524
+ | [`rate-limit-redis`](https://npmjs.com/package/rate-limit-redis) | A [Redis](http://redis.io/)-backed store, more suitable for large or demanding deployments. | Modern as of v3.0.0 |
525
+ | [`rate-limit-memcached`](https://npmjs.org/package/rate-limit-memcached) | A [Memcached](https://memcached.org/)-backed store. | Modern as of v1.0.0 |
526
+ | [`rate-limit-mongo`](https://www.npmjs.com/package/rate-limit-mongo) | A [MongoDB](https://www.mongodb.com/)-backed store. | Legacy |
527
+ | [`precise-memory-rate-limit`](https://www.npmjs.com/package/precise-memory-rate-limit) | A memory store similar to the built-in one, except that it stores a distinct timestamp for each key. | Modern as of v2.0.0 |
528
+ | [`rate-limit-postgresql`](https://www.npmjs.com/package/@acpr/rate-limit-postgresql) | A [PostgreSQL](https://www.postgresql.org/)-backed store. | Modern as of v1.1.0 |
534
529
 
535
530
  Take a look at
536
531
  [this guide](https://github.com/express-rate-limit/express-rate-limit/wiki/Creating-Your-Own-Store)
@@ -553,8 +548,11 @@ The property name can be configured with the configuration option
553
548
  ### `resetKey(key)`
554
549
 
555
550
  Resets the rate limiting for a given key. An example use case is to allow users
556
- to complete a captcha or whatever to reset their rate limit, then call this
557
- method.
551
+ to complete a captcha to reset their rate limit, then call this function.
552
+
553
+ ### `getKey(key)`
554
+
555
+ Retrieves the hit count and reset time from the store for a given key.
558
556
 
559
557
  ## Issues and Contributing
560
558