express-rate-limit 8.4.1 → 8.5.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/dist/index.cjs CHANGED
@@ -861,7 +861,24 @@ var rateLimit = (passedOptions) => {
861
861
  const options = getOptionsFromConfig(config);
862
862
  config.validations.creationStack(config.store);
863
863
  config.validations.unsharedStore(config.store);
864
- if (typeof config.store.init === "function") config.store.init(options);
864
+ if (typeof config.store.init === "function") {
865
+ try {
866
+ const storeInit = config.store.init(options);
867
+ if (storeInit instanceof Promise) {
868
+ storeInit.catch(
869
+ (error) => config.logger.error(
870
+ error,
871
+ "express-rate-limit: async error during store initialization."
872
+ )
873
+ );
874
+ }
875
+ } catch (error) {
876
+ config.logger.error(
877
+ error,
878
+ "express-rate-limit: error during store initialization."
879
+ );
880
+ }
881
+ }
865
882
  const middleware = handleAsyncErrors(
866
883
  async (request, response, next) => {
867
884
  const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
package/dist/index.d.cts CHANGED
@@ -285,9 +285,15 @@ export type Store = {
285
285
  * Method that initializes the store, and has access to the options passed to
286
286
  * the middleware too.
287
287
  *
288
+ * Called once during initialization.
289
+ *
290
+ * Errors / promise rejections will be caught and logged.
291
+ *
292
+ * Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
293
+ *
288
294
  * @param options {Options} - The options used to setup the middleware.
289
295
  */
290
- init?: (options: Options) => void;
296
+ init?: (options: Options) => void | Promise<void>;
291
297
  /**
292
298
  * Method to fetch a client's hit count and reset time.
293
299
  *
package/dist/index.d.mts CHANGED
@@ -285,9 +285,15 @@ export type Store = {
285
285
  * Method that initializes the store, and has access to the options passed to
286
286
  * the middleware too.
287
287
  *
288
+ * Called once during initialization.
289
+ *
290
+ * Errors / promise rejections will be caught and logged.
291
+ *
292
+ * Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
293
+ *
288
294
  * @param options {Options} - The options used to setup the middleware.
289
295
  */
290
- init?: (options: Options) => void;
296
+ init?: (options: Options) => void | Promise<void>;
291
297
  /**
292
298
  * Method to fetch a client's hit count and reset time.
293
299
  *
package/dist/index.d.ts CHANGED
@@ -285,9 +285,15 @@ export type Store = {
285
285
  * Method that initializes the store, and has access to the options passed to
286
286
  * the middleware too.
287
287
  *
288
+ * Called once during initialization.
289
+ *
290
+ * Errors / promise rejections will be caught and logged.
291
+ *
292
+ * Note that the result is not awaited - other store methods (such as increment) may be called before init returns and/or after it throws/rejects.
293
+ *
288
294
  * @param options {Options} - The options used to setup the middleware.
289
295
  */
290
- init?: (options: Options) => void;
296
+ init?: (options: Options) => void | Promise<void>;
291
297
  /**
292
298
  * Method to fetch a client's hit count and reset time.
293
299
  *
package/dist/index.mjs CHANGED
@@ -832,7 +832,24 @@ var rateLimit = (passedOptions) => {
832
832
  const options = getOptionsFromConfig(config);
833
833
  config.validations.creationStack(config.store);
834
834
  config.validations.unsharedStore(config.store);
835
- if (typeof config.store.init === "function") config.store.init(options);
835
+ if (typeof config.store.init === "function") {
836
+ try {
837
+ const storeInit = config.store.init(options);
838
+ if (storeInit instanceof Promise) {
839
+ storeInit.catch(
840
+ (error) => config.logger.error(
841
+ error,
842
+ "express-rate-limit: async error during store initialization."
843
+ )
844
+ );
845
+ }
846
+ } catch (error) {
847
+ config.logger.error(
848
+ error,
849
+ "express-rate-limit: error during store initialization."
850
+ );
851
+ }
852
+ }
836
853
  const middleware = handleAsyncErrors(
837
854
  async (request, response, next) => {
838
855
  const closePromise = config.skipFailedRequests && new Promise((resolve) => response.once("close", resolve));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-rate-limit",
3
- "version": "8.4.1",
3
+ "version": "8.5.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",
@@ -70,6 +70,7 @@
70
70
  "test:lib": "jest",
71
71
  "test:ext": "cd test/external/ && bash run-all-tests",
72
72
  "test": "run-s lint test:lib",
73
+ "format-test": "run-s format test:lib",
73
74
  "pre-commit": "lint-staged",
74
75
  "prepare": "run-s compile && husky"
75
76
  },