express-rate-limit 8.3.1 → 8.3.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.
package/dist/index.cjs CHANGED
@@ -840,6 +840,9 @@ var rateLimit = (passedOptions) => {
840
840
  if (typeof config.store.init === "function") config.store.init(options);
841
841
  const middleware = handleAsyncErrors(
842
842
  async (request, response, next) => {
843
+ const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
844
+ const finishPromise = (config.skipFailedRequests || config.skipSuccessfulRequests) && new Promise((resolve) => response.once("finish", resolve));
845
+ const errorPromise = config.skipFailedRequests && new Promise((resolve) => response.once("error", resolve));
843
846
  const skip = await config.skip(request, response);
844
847
  if (skip) {
845
848
  next();
@@ -918,22 +921,30 @@ var rateLimit = (passedOptions) => {
918
921
  }
919
922
  };
920
923
  if (config.skipFailedRequests) {
921
- response.on("finish", async () => {
922
- if (!await config.requestWasSuccessful(request, response))
924
+ if (finishPromise) {
925
+ void finishPromise.then(async () => {
926
+ if (!await config.requestWasSuccessful(request, response))
927
+ await decrementKey();
928
+ });
929
+ }
930
+ if (closePromise) {
931
+ void closePromise.then(async () => {
932
+ if (!response.writableEnded) await decrementKey();
933
+ });
934
+ }
935
+ if (errorPromise) {
936
+ void errorPromise.then(async () => {
923
937
  await decrementKey();
924
- });
925
- response.on("close", async () => {
926
- if (!response.writableEnded) await decrementKey();
927
- });
928
- response.on("error", async () => {
929
- await decrementKey();
930
- });
938
+ });
939
+ }
931
940
  }
932
941
  if (config.skipSuccessfulRequests) {
933
- response.on("finish", async () => {
934
- if (await config.requestWasSuccessful(request, response))
935
- await decrementKey();
936
- });
942
+ if (finishPromise) {
943
+ void finishPromise.then(async () => {
944
+ if (await config.requestWasSuccessful(request, response))
945
+ await decrementKey();
946
+ });
947
+ }
937
948
  }
938
949
  }
939
950
  config.validations.disable();
package/dist/index.mjs CHANGED
@@ -811,6 +811,9 @@ var rateLimit = (passedOptions) => {
811
811
  if (typeof config.store.init === "function") config.store.init(options);
812
812
  const middleware = handleAsyncErrors(
813
813
  async (request, response, next) => {
814
+ const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
815
+ const finishPromise = (config.skipFailedRequests || config.skipSuccessfulRequests) && new Promise((resolve) => response.once("finish", resolve));
816
+ const errorPromise = config.skipFailedRequests && new Promise((resolve) => response.once("error", resolve));
814
817
  const skip = await config.skip(request, response);
815
818
  if (skip) {
816
819
  next();
@@ -889,22 +892,30 @@ var rateLimit = (passedOptions) => {
889
892
  }
890
893
  };
891
894
  if (config.skipFailedRequests) {
892
- response.on("finish", async () => {
893
- if (!await config.requestWasSuccessful(request, response))
895
+ if (finishPromise) {
896
+ void finishPromise.then(async () => {
897
+ if (!await config.requestWasSuccessful(request, response))
898
+ await decrementKey();
899
+ });
900
+ }
901
+ if (closePromise) {
902
+ void closePromise.then(async () => {
903
+ if (!response.writableEnded) await decrementKey();
904
+ });
905
+ }
906
+ if (errorPromise) {
907
+ void errorPromise.then(async () => {
894
908
  await decrementKey();
895
- });
896
- response.on("close", async () => {
897
- if (!response.writableEnded) await decrementKey();
898
- });
899
- response.on("error", async () => {
900
- await decrementKey();
901
- });
909
+ });
910
+ }
902
911
  }
903
912
  if (config.skipSuccessfulRequests) {
904
- response.on("finish", async () => {
905
- if (await config.requestWasSuccessful(request, response))
906
- await decrementKey();
907
- });
913
+ if (finishPromise) {
914
+ void finishPromise.then(async () => {
915
+ if (await config.requestWasSuccessful(request, response))
916
+ await decrementKey();
917
+ });
918
+ }
908
919
  }
909
920
  }
910
921
  config.validations.disable();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "8.3.1",
3
+ "version": "8.3.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",
@@ -83,19 +83,19 @@
83
83
  "@biomejs/biome": "2.4.6",
84
84
  "@express-rate-limit/prettier": "1.1.1",
85
85
  "@express-rate-limit/tsconfig": "1.0.2",
86
- "@jest/globals": "30.2.0",
86
+ "@jest/globals": "30.3.0",
87
87
  "@types/express": "5.0.6",
88
88
  "@types/jest": "30.0.0",
89
- "@types/node": "25.3.3",
89
+ "@types/node": "25.5.0",
90
90
  "@types/supertest": "7.2.0",
91
91
  "del-cli": "7.0.0",
92
92
  "dts-bundle-generator": "8.1.2",
93
- "esbuild": "0.27.3",
93
+ "esbuild": "0.27.4",
94
94
  "express": "5.2.1",
95
95
  "husky": "9.1.7",
96
- "jest": "30.2.0",
97
- "lint-staged": "16.3.2",
98
- "mintlify": "4.2.392",
96
+ "jest": "30.3.0",
97
+ "lint-staged": "16.4.0",
98
+ "mintlify": "4.2.446",
99
99
  "npm-run-all": "4.1.5",
100
100
  "prettier": "3.8.1",
101
101
  "ratelimit-header-parser": "0.1.0",
package/readme.md CHANGED
@@ -69,21 +69,6 @@ default values.
69
69
 
70
70
  ## Thank You
71
71
 
72
- Sponsored by [Zuplo](https://zuplo.link/express-rate-limit) a fully-managed API
73
- Gateway for developers. Add
74
- [dynamic rate-limiting](https://zuplo.link/dynamic-rate-limiting),
75
- authentication and more to any API in minutes. Learn more at
76
- [zuplo.com](https://zuplo.link/express-rate-limit)
77
-
78
- <p align="center">
79
- <a href="https://zuplo.link/express-rate-limit">
80
- <picture width="322">
81
- <source media="(prefers-color-scheme: dark)" srcset="https://github.com/express-rate-limit/express-rate-limit/assets/114976/cd2f6fa7-eae1-4fbb-be7d-b17df4c6f383">
82
- <img alt="zuplo-logo" src="https://github.com/express-rate-limit/express-rate-limit/assets/114976/66fd75fa-b39e-4a8c-8d7a-52369bf244dc" width="322">
83
- </picture>
84
- </a>
85
- </p>
86
-
87
72
  ---
88
73
 
89
74
  Thanks to Mintlify for hosting the documentation at
@@ -97,7 +82,7 @@ Thanks to Mintlify for hosting the documentation at
97
82
 
98
83
  ---
99
84
 
100
- Finally, thank you to everyone who's contributed to this project in any way! 🫶
85
+ And thank you to everyone who's contributed to this project in any way! 🫶
101
86
 
102
87
  ## Issues and Contributing
103
88