🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

express-rate-limit

Package Overview
Dependencies
Maintainers
2
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-rate-limit - npm Package Compare versions

Comparing version
8.4.0
to
8.4.1
+33
-9
dist/index.cjs

@@ -204,2 +204,12 @@ "use strict";

// source/console-logger.ts
var ConsoleLogger = {
warn(...args) {
console.warn(...args.reverse());
},
error(...args) {
console.error(...args.reverse());
}
};
// source/headers.ts

@@ -552,3 +562,4 @@ var import_node_buffer = require("node:buffer");

max: true,
passOnStoreError: true
passOnStoreError: true,
logger: true
};

@@ -666,3 +677,11 @@ const validOptions = Object.keys(optionsMap).concat(

};
var getValidations = (_enabled) => {
function validateLogger(logger) {
if (typeof logger !== "object" || typeof logger.error !== "function" || typeof logger.warn !== "function") {
throw new TypeError(
"Provided logger does not implement the Logger interface"
);
}
}
var getValidations = (_enabled, logger) => {
validateLogger(logger);
let enabled;

@@ -693,4 +712,4 @@ if (typeof _enabled === "boolean") {

} catch (error) {
if (error instanceof ChangeWarning) console.warn(error);
else console.error(error);
if (error instanceof ChangeWarning) logger.warn(error);
else logger.error(error);
}

@@ -748,3 +767,7 @@ };

const notUndefinedOptions = omitUndefinedProperties(passedOptions);
const validations2 = getValidations(notUndefinedOptions?.validate ?? true);
const logger = passedOptions.logger ?? ConsoleLogger;
const validations2 = getValidations(
notUndefinedOptions?.validate ?? true,
logger
);
validations2.validationsConfig();

@@ -824,3 +847,4 @@ validations2.knownOptions(passedOptions);

// Print an error to the console if a few known misconfigurations are detected.
validations: validations2
validations: validations2,
logger
};

@@ -867,5 +891,5 @@ if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || config.store.resetAll !== void 0 && typeof config.store.resetAll !== "function" || config.store.init !== void 0 && typeof config.store.init !== "function") {

if (config.passOnStoreError) {
console.error(
"express-rate-limit: error from store, allowing request without rate-limiting.",
error
config.logger.error(
error,
"express-rate-limit: error from store, allowing request without rate-limiting."
);

@@ -872,0 +896,0 @@ next();

@@ -163,2 +163,22 @@ // Generated by dts-bundle-generator v8.1.2

/**
* Basic logging function
*
* @param error {unknown} - The error to log
* @param message {string | undefined} - Additional details about the error
*/
export type LoggerFn = (error: unknown, message?: string) => void;
/**
* Minimal interface for logging warnings and errors
*/
export type Logger = {
/**
* Function to log an error
*/
error: LoggerFn;
/**
* Function to log a warning
*/
warn: LoggerFn;
};
/**
* Callback that fires when a client's hit counter is incremented.

@@ -481,2 +501,6 @@ *

passOnStoreError: boolean;
/**
* The logger to use to log errors. If absent, logs to the console.
*/
logger: Logger;
};

@@ -483,0 +507,0 @@ /**

@@ -163,2 +163,22 @@ // Generated by dts-bundle-generator v8.1.2

/**
* Basic logging function
*
* @param error {unknown} - The error to log
* @param message {string | undefined} - Additional details about the error
*/
export type LoggerFn = (error: unknown, message?: string) => void;
/**
* Minimal interface for logging warnings and errors
*/
export type Logger = {
/**
* Function to log an error
*/
error: LoggerFn;
/**
* Function to log a warning
*/
warn: LoggerFn;
};
/**
* Callback that fires when a client's hit counter is incremented.

@@ -481,2 +501,6 @@ *

passOnStoreError: boolean;
/**
* The logger to use to log errors. If absent, logs to the console.
*/
logger: Logger;
};

@@ -483,0 +507,0 @@ /**

@@ -163,2 +163,22 @@ // Generated by dts-bundle-generator v8.1.2

/**
* Basic logging function
*
* @param error {unknown} - The error to log
* @param message {string | undefined} - Additional details about the error
*/
export type LoggerFn = (error: unknown, message?: string) => void;
/**
* Minimal interface for logging warnings and errors
*/
export type Logger = {
/**
* Function to log an error
*/
error: LoggerFn;
/**
* Function to log a warning
*/
warn: LoggerFn;
};
/**
* Callback that fires when a client's hit counter is incremented.

@@ -481,2 +501,6 @@ *

passOnStoreError: boolean;
/**
* The logger to use to log errors. If absent, logs to the console.
*/
logger: Logger;
};

@@ -483,0 +507,0 @@ /**

@@ -175,2 +175,12 @@ // source/ip-key-generator.ts

// source/console-logger.ts
var ConsoleLogger = {
warn(...args) {
console.warn(...args.reverse());
},
error(...args) {
console.error(...args.reverse());
}
};
// source/headers.ts

@@ -523,3 +533,4 @@ import { Buffer } from "node:buffer";

max: true,
passOnStoreError: true
passOnStoreError: true,
logger: true
};

@@ -637,3 +648,11 @@ const validOptions = Object.keys(optionsMap).concat(

};
var getValidations = (_enabled) => {
function validateLogger(logger) {
if (typeof logger !== "object" || typeof logger.error !== "function" || typeof logger.warn !== "function") {
throw new TypeError(
"Provided logger does not implement the Logger interface"
);
}
}
var getValidations = (_enabled, logger) => {
validateLogger(logger);
let enabled;

@@ -664,4 +683,4 @@ if (typeof _enabled === "boolean") {

} catch (error) {
if (error instanceof ChangeWarning) console.warn(error);
else console.error(error);
if (error instanceof ChangeWarning) logger.warn(error);
else logger.error(error);
}

@@ -719,3 +738,7 @@ };

const notUndefinedOptions = omitUndefinedProperties(passedOptions);
const validations2 = getValidations(notUndefinedOptions?.validate ?? true);
const logger = passedOptions.logger ?? ConsoleLogger;
const validations2 = getValidations(
notUndefinedOptions?.validate ?? true,
logger
);
validations2.validationsConfig();

@@ -795,3 +818,4 @@ validations2.knownOptions(passedOptions);

// Print an error to the console if a few known misconfigurations are detected.
validations: validations2
validations: validations2,
logger
};

@@ -838,5 +862,5 @@ if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || config.store.resetAll !== void 0 && typeof config.store.resetAll !== "function" || config.store.init !== void 0 && typeof config.store.init !== "function") {

if (config.passOnStoreError) {
console.error(
"express-rate-limit: error from store, allowing request without rate-limiting.",
error
config.logger.error(
error,
"express-rate-limit: error from store, allowing request without rate-limiting."
);

@@ -843,0 +867,0 @@ next();

{
"name": "express-rate-limit",
"version": "8.4.0",
"version": "8.4.1",
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",

@@ -5,0 +5,0 @@ "author": {