avancement planning
This commit is contained in:
+614
-421
File diff suppressed because it is too large
Load Diff
+105
-21
@@ -1,7 +1,28 @@
|
||||
// Generated by dts-bundle-generator v8.0.1
|
||||
// Generated by dts-bundle-generator v8.1.2
|
||||
|
||||
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
||||
|
||||
/**
|
||||
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
||||
*
|
||||
* If you write a custom keyGenerator that allows a fallback to IP address for
|
||||
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
||||
*
|
||||
* For more information, {@see Options.ipv6Subnet}.
|
||||
*
|
||||
* @param ip {string} - The IP address to process, usually request.ip.
|
||||
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
||||
*
|
||||
* @returns {string} - The key generated from the IP address
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
declare const validations: {
|
||||
enabled: {
|
||||
[key: string]: boolean;
|
||||
@@ -39,6 +60,14 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
xForwardedForHeader(request: Request): void;
|
||||
/**
|
||||
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
||||
*
|
||||
* @param request {Request} - The Express request object.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
forwardedHeader(request: Request): void;
|
||||
/**
|
||||
* Ensures totalHits value from store is a positive integer.
|
||||
*
|
||||
@@ -103,12 +132,13 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
headersResetTime(resetTime?: Date): void;
|
||||
knownOptions(passedOptions?: Partial<Options>): void;
|
||||
/**
|
||||
* Checks the options.validate setting to ensure that only recognized
|
||||
* validations are enabled or disabled.
|
||||
*
|
||||
* If any unrecognized values are found, an error is logged that
|
||||
* includes the list of supported vaidations.
|
||||
* includes the list of supported validations.
|
||||
*/
|
||||
validationsConfig(): void;
|
||||
/**
|
||||
@@ -117,13 +147,38 @@ declare const validations: {
|
||||
* store (or any other store with localKeys.)
|
||||
*/
|
||||
creationStack(store: Store): void;
|
||||
ipv6Subnet(ipv6Subnet?: any): void;
|
||||
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
||||
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
||||
/**
|
||||
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
||||
* called by the default MemoryStore, since it uses Node's setInterval method.
|
||||
*
|
||||
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
||||
*/
|
||||
windowMs(windowMs: number): void;
|
||||
};
|
||||
export type Validations = typeof validations;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@@ -230,9 +285,15 @@ export type Store = {
|
||||
* Method that initializes the store, and has access to the options passed to
|
||||
* the middleware too.
|
||||
*
|
||||
* Called once during initialization.
|
||||
*
|
||||
* Errors / promise rejections will be caught and logged.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param options {Options} - The options used to setup the middleware.
|
||||
*/
|
||||
init?: (options: Options) => void;
|
||||
init?: (options: Options) => void | Promise<void>;
|
||||
/**
|
||||
* Method to fetch a client's hit count and reset time.
|
||||
*
|
||||
@@ -280,7 +341,8 @@ export type Store = {
|
||||
/**
|
||||
* Optional value that the store prepends to keys
|
||||
*
|
||||
* Used by the double-count check to avoid false-positives when a key is counted twice, but with different prefixes
|
||||
* Used by the double-count check to avoid false-positives when a key is counted
|
||||
* twice, but with different prefixes.
|
||||
*/
|
||||
prefix?: string;
|
||||
};
|
||||
@@ -372,6 +434,21 @@ export type Options = {
|
||||
* By default, the client's IP address is used.
|
||||
*/
|
||||
keyGenerator: ValueDeterminingMiddleware<string>;
|
||||
/**
|
||||
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
||||
*
|
||||
* Default is 56. The valid range is technically 1-128 but the value should
|
||||
* generally be in the 32-64 range.
|
||||
*
|
||||
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
||||
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
||||
*
|
||||
* May also be set to a function that returns a number based on the request.
|
||||
*
|
||||
* See the documentation for more info:
|
||||
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
||||
*/
|
||||
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
||||
/**
|
||||
* Express request handler that sends back a response when a client is
|
||||
* rate-limited.
|
||||
@@ -387,7 +464,7 @@ export type Options = {
|
||||
*/
|
||||
skip: ValueDeterminingMiddleware<boolean>;
|
||||
/**
|
||||
* Method to determine whether or not the request counts as 'succesful'. Used
|
||||
* Method to determine whether or not the request counts as 'successful'. Used
|
||||
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
||||
*
|
||||
* By default, requests with a response status code less than 400 are considered
|
||||
@@ -426,6 +503,10 @@ export type Options = {
|
||||
* If the Store generates an error, allow the request to pass.
|
||||
*/
|
||||
passOnStoreError: boolean;
|
||||
/**
|
||||
* The logger to use to log errors. If absent, logs to the console.
|
||||
*/
|
||||
logger: Logger;
|
||||
};
|
||||
/**
|
||||
* The extended request object that includes information about the client's
|
||||
@@ -443,18 +524,8 @@ export type RateLimitInfo = {
|
||||
used: number;
|
||||
remaining: number;
|
||||
resetTime: Date | undefined;
|
||||
key: string;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
/**
|
||||
* The record that stores information about a client - namely, how many times
|
||||
* they have hit the endpoint, and when their hit count resets.
|
||||
@@ -471,6 +542,7 @@ export type Client = {
|
||||
* @public
|
||||
*/
|
||||
export declare class MemoryStore implements Store {
|
||||
private validations?;
|
||||
/**
|
||||
* The duration of time before which all hit counts are reset (in milliseconds).
|
||||
*/
|
||||
@@ -496,6 +568,7 @@ export declare class MemoryStore implements Store {
|
||||
* cannot affect other instances.
|
||||
*/
|
||||
localKeys: boolean;
|
||||
constructor(validations?: Validations | undefined);
|
||||
/**
|
||||
* Method that initializes the store.
|
||||
*
|
||||
@@ -580,6 +653,17 @@ export declare class MemoryStore implements Store {
|
||||
*/
|
||||
private clearExpired;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
|
||||
export {
|
||||
rateLimit as default,
|
||||
|
||||
+105
-21
@@ -1,7 +1,28 @@
|
||||
// Generated by dts-bundle-generator v8.0.1
|
||||
// Generated by dts-bundle-generator v8.1.2
|
||||
|
||||
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
||||
|
||||
/**
|
||||
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
||||
*
|
||||
* If you write a custom keyGenerator that allows a fallback to IP address for
|
||||
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
||||
*
|
||||
* For more information, {@see Options.ipv6Subnet}.
|
||||
*
|
||||
* @param ip {string} - The IP address to process, usually request.ip.
|
||||
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
||||
*
|
||||
* @returns {string} - The key generated from the IP address
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
declare const validations: {
|
||||
enabled: {
|
||||
[key: string]: boolean;
|
||||
@@ -39,6 +60,14 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
xForwardedForHeader(request: Request): void;
|
||||
/**
|
||||
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
||||
*
|
||||
* @param request {Request} - The Express request object.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
forwardedHeader(request: Request): void;
|
||||
/**
|
||||
* Ensures totalHits value from store is a positive integer.
|
||||
*
|
||||
@@ -103,12 +132,13 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
headersResetTime(resetTime?: Date): void;
|
||||
knownOptions(passedOptions?: Partial<Options>): void;
|
||||
/**
|
||||
* Checks the options.validate setting to ensure that only recognized
|
||||
* validations are enabled or disabled.
|
||||
*
|
||||
* If any unrecognized values are found, an error is logged that
|
||||
* includes the list of supported vaidations.
|
||||
* includes the list of supported validations.
|
||||
*/
|
||||
validationsConfig(): void;
|
||||
/**
|
||||
@@ -117,13 +147,38 @@ declare const validations: {
|
||||
* store (or any other store with localKeys.)
|
||||
*/
|
||||
creationStack(store: Store): void;
|
||||
ipv6Subnet(ipv6Subnet?: any): void;
|
||||
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
||||
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
||||
/**
|
||||
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
||||
* called by the default MemoryStore, since it uses Node's setInterval method.
|
||||
*
|
||||
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
||||
*/
|
||||
windowMs(windowMs: number): void;
|
||||
};
|
||||
export type Validations = typeof validations;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@@ -230,9 +285,15 @@ export type Store = {
|
||||
* Method that initializes the store, and has access to the options passed to
|
||||
* the middleware too.
|
||||
*
|
||||
* Called once during initialization.
|
||||
*
|
||||
* Errors / promise rejections will be caught and logged.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param options {Options} - The options used to setup the middleware.
|
||||
*/
|
||||
init?: (options: Options) => void;
|
||||
init?: (options: Options) => void | Promise<void>;
|
||||
/**
|
||||
* Method to fetch a client's hit count and reset time.
|
||||
*
|
||||
@@ -280,7 +341,8 @@ export type Store = {
|
||||
/**
|
||||
* Optional value that the store prepends to keys
|
||||
*
|
||||
* Used by the double-count check to avoid false-positives when a key is counted twice, but with different prefixes
|
||||
* Used by the double-count check to avoid false-positives when a key is counted
|
||||
* twice, but with different prefixes.
|
||||
*/
|
||||
prefix?: string;
|
||||
};
|
||||
@@ -372,6 +434,21 @@ export type Options = {
|
||||
* By default, the client's IP address is used.
|
||||
*/
|
||||
keyGenerator: ValueDeterminingMiddleware<string>;
|
||||
/**
|
||||
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
||||
*
|
||||
* Default is 56. The valid range is technically 1-128 but the value should
|
||||
* generally be in the 32-64 range.
|
||||
*
|
||||
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
||||
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
||||
*
|
||||
* May also be set to a function that returns a number based on the request.
|
||||
*
|
||||
* See the documentation for more info:
|
||||
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
||||
*/
|
||||
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
||||
/**
|
||||
* Express request handler that sends back a response when a client is
|
||||
* rate-limited.
|
||||
@@ -387,7 +464,7 @@ export type Options = {
|
||||
*/
|
||||
skip: ValueDeterminingMiddleware<boolean>;
|
||||
/**
|
||||
* Method to determine whether or not the request counts as 'succesful'. Used
|
||||
* Method to determine whether or not the request counts as 'successful'. Used
|
||||
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
||||
*
|
||||
* By default, requests with a response status code less than 400 are considered
|
||||
@@ -426,6 +503,10 @@ export type Options = {
|
||||
* If the Store generates an error, allow the request to pass.
|
||||
*/
|
||||
passOnStoreError: boolean;
|
||||
/**
|
||||
* The logger to use to log errors. If absent, logs to the console.
|
||||
*/
|
||||
logger: Logger;
|
||||
};
|
||||
/**
|
||||
* The extended request object that includes information about the client's
|
||||
@@ -443,18 +524,8 @@ export type RateLimitInfo = {
|
||||
used: number;
|
||||
remaining: number;
|
||||
resetTime: Date | undefined;
|
||||
key: string;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
/**
|
||||
* The record that stores information about a client - namely, how many times
|
||||
* they have hit the endpoint, and when their hit count resets.
|
||||
@@ -471,6 +542,7 @@ export type Client = {
|
||||
* @public
|
||||
*/
|
||||
export declare class MemoryStore implements Store {
|
||||
private validations?;
|
||||
/**
|
||||
* The duration of time before which all hit counts are reset (in milliseconds).
|
||||
*/
|
||||
@@ -496,6 +568,7 @@ export declare class MemoryStore implements Store {
|
||||
* cannot affect other instances.
|
||||
*/
|
||||
localKeys: boolean;
|
||||
constructor(validations?: Validations | undefined);
|
||||
/**
|
||||
* Method that initializes the store.
|
||||
*
|
||||
@@ -580,6 +653,17 @@ export declare class MemoryStore implements Store {
|
||||
*/
|
||||
private clearExpired;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
|
||||
export {
|
||||
rateLimit as default,
|
||||
|
||||
+105
-21
@@ -1,7 +1,28 @@
|
||||
// Generated by dts-bundle-generator v8.0.1
|
||||
// Generated by dts-bundle-generator v8.1.2
|
||||
|
||||
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
||||
|
||||
/**
|
||||
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
||||
*
|
||||
* If you write a custom keyGenerator that allows a fallback to IP address for
|
||||
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
||||
*
|
||||
* For more information, {@see Options.ipv6Subnet}.
|
||||
*
|
||||
* @param ip {string} - The IP address to process, usually request.ip.
|
||||
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
||||
*
|
||||
* @returns {string} - The key generated from the IP address
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
declare const validations: {
|
||||
enabled: {
|
||||
[key: string]: boolean;
|
||||
@@ -39,6 +60,14 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
xForwardedForHeader(request: Request): void;
|
||||
/**
|
||||
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
||||
*
|
||||
* @param request {Request} - The Express request object.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
forwardedHeader(request: Request): void;
|
||||
/**
|
||||
* Ensures totalHits value from store is a positive integer.
|
||||
*
|
||||
@@ -103,12 +132,13 @@ declare const validations: {
|
||||
* @returns {void}
|
||||
*/
|
||||
headersResetTime(resetTime?: Date): void;
|
||||
knownOptions(passedOptions?: Partial<Options>): void;
|
||||
/**
|
||||
* Checks the options.validate setting to ensure that only recognized
|
||||
* validations are enabled or disabled.
|
||||
*
|
||||
* If any unrecognized values are found, an error is logged that
|
||||
* includes the list of supported vaidations.
|
||||
* includes the list of supported validations.
|
||||
*/
|
||||
validationsConfig(): void;
|
||||
/**
|
||||
@@ -117,13 +147,38 @@ declare const validations: {
|
||||
* store (or any other store with localKeys.)
|
||||
*/
|
||||
creationStack(store: Store): void;
|
||||
ipv6Subnet(ipv6Subnet?: any): void;
|
||||
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
||||
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
||||
/**
|
||||
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
||||
* called by the default MemoryStore, since it uses Node's setInterval method.
|
||||
*
|
||||
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
||||
*/
|
||||
windowMs(windowMs: number): void;
|
||||
};
|
||||
export type Validations = typeof validations;
|
||||
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
||||
"draft-6",
|
||||
"draft-7",
|
||||
"draft-8"
|
||||
];
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@@ -230,9 +285,15 @@ export type Store = {
|
||||
* Method that initializes the store, and has access to the options passed to
|
||||
* the middleware too.
|
||||
*
|
||||
* Called once during initialization.
|
||||
*
|
||||
* Errors / promise rejections will be caught and logged.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param options {Options} - The options used to setup the middleware.
|
||||
*/
|
||||
init?: (options: Options) => void;
|
||||
init?: (options: Options) => void | Promise<void>;
|
||||
/**
|
||||
* Method to fetch a client's hit count and reset time.
|
||||
*
|
||||
@@ -280,7 +341,8 @@ export type Store = {
|
||||
/**
|
||||
* Optional value that the store prepends to keys
|
||||
*
|
||||
* Used by the double-count check to avoid false-positives when a key is counted twice, but with different prefixes
|
||||
* Used by the double-count check to avoid false-positives when a key is counted
|
||||
* twice, but with different prefixes.
|
||||
*/
|
||||
prefix?: string;
|
||||
};
|
||||
@@ -372,6 +434,21 @@ export type Options = {
|
||||
* By default, the client's IP address is used.
|
||||
*/
|
||||
keyGenerator: ValueDeterminingMiddleware<string>;
|
||||
/**
|
||||
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
||||
*
|
||||
* Default is 56. The valid range is technically 1-128 but the value should
|
||||
* generally be in the 32-64 range.
|
||||
*
|
||||
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
||||
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
||||
*
|
||||
* May also be set to a function that returns a number based on the request.
|
||||
*
|
||||
* See the documentation for more info:
|
||||
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
||||
*/
|
||||
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
||||
/**
|
||||
* Express request handler that sends back a response when a client is
|
||||
* rate-limited.
|
||||
@@ -387,7 +464,7 @@ export type Options = {
|
||||
*/
|
||||
skip: ValueDeterminingMiddleware<boolean>;
|
||||
/**
|
||||
* Method to determine whether or not the request counts as 'succesful'. Used
|
||||
* Method to determine whether or not the request counts as 'successful'. Used
|
||||
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
||||
*
|
||||
* By default, requests with a response status code less than 400 are considered
|
||||
@@ -426,6 +503,10 @@ export type Options = {
|
||||
* If the Store generates an error, allow the request to pass.
|
||||
*/
|
||||
passOnStoreError: boolean;
|
||||
/**
|
||||
* The logger to use to log errors. If absent, logs to the console.
|
||||
*/
|
||||
logger: Logger;
|
||||
};
|
||||
/**
|
||||
* The extended request object that includes information about the client's
|
||||
@@ -443,18 +524,8 @@ export type RateLimitInfo = {
|
||||
used: number;
|
||||
remaining: number;
|
||||
resetTime: Date | undefined;
|
||||
key: string;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
/**
|
||||
* The record that stores information about a client - namely, how many times
|
||||
* they have hit the endpoint, and when their hit count resets.
|
||||
@@ -471,6 +542,7 @@ export type Client = {
|
||||
* @public
|
||||
*/
|
||||
export declare class MemoryStore implements Store {
|
||||
private validations?;
|
||||
/**
|
||||
* The duration of time before which all hit counts are reset (in milliseconds).
|
||||
*/
|
||||
@@ -496,6 +568,7 @@ export declare class MemoryStore implements Store {
|
||||
* cannot affect other instances.
|
||||
*/
|
||||
localKeys: boolean;
|
||||
constructor(validations?: Validations | undefined);
|
||||
/**
|
||||
* Method that initializes the store.
|
||||
*
|
||||
@@ -580,6 +653,17 @@ export declare class MemoryStore implements Store {
|
||||
*/
|
||||
private clearExpired;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Create an instance of IP rate-limiting middleware for Express.
|
||||
*
|
||||
* @param passedOptions {Options} - Options to configure the rate limiter.
|
||||
*
|
||||
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
||||
|
||||
export {
|
||||
rateLimit as default,
|
||||
|
||||
+613
-421
File diff suppressed because it is too large
Load Diff
+33
-53
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "express-rate-limit",
|
||||
"version": "7.5.1",
|
||||
"version": "8.5.2",
|
||||
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",
|
||||
"author": {
|
||||
"name": "Nathan Friedly",
|
||||
@@ -56,78 +56,58 @@
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "del-cli dist/ coverage/ *.log *.tmp *.bak *.tgz",
|
||||
"build:cjs": "esbuild --platform=node --bundle --target=es2022 --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = rateLimit; module.exports.default = rateLimit; module.exports.rateLimit = rateLimit; module.exports.MemoryStore = MemoryStore;\" source/index.ts",
|
||||
"build:esm": "esbuild --platform=node --bundle --target=es2022 --format=esm --outfile=dist/index.mjs source/index.ts",
|
||||
"build:cjs": "esbuild --packages=external --platform=node --bundle --target=es2022 --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = Object.assign(rateLimit, module.exports);\" source/index.ts",
|
||||
"build:esm": "esbuild --packages=external --platform=node --bundle --target=es2022 --format=esm --outfile=dist/index.mjs source/index.ts",
|
||||
"build:types": "dts-bundle-generator --out-file=dist/index.d.ts source/index.ts && cp dist/index.d.ts dist/index.d.cts && cp dist/index.d.ts dist/index.d.mts",
|
||||
"compile": "run-s clean build:*",
|
||||
"docs": "cd docs && mintlify dev",
|
||||
"lint:code": "xo",
|
||||
"lint:rest": "prettier --check .",
|
||||
"lint:code": "biome check",
|
||||
"lint:docs": "prettier --check docs/ *.md",
|
||||
"lint": "run-s lint:*",
|
||||
"format:code": "xo --fix",
|
||||
"format:rest": "prettier --write .",
|
||||
"format:code": "biome check --write",
|
||||
"format:docs": "prettier --write docs/ *.md",
|
||||
"format": "run-s format:*",
|
||||
"test:lib": "jest",
|
||||
"test:ext": "cd test/external/ && bash run-all-tests",
|
||||
"test": "run-s lint test:lib",
|
||||
"format-test": "run-s format test:lib",
|
||||
"pre-commit": "lint-staged",
|
||||
"prepare": "run-s compile && husky install config/husky"
|
||||
"prepare": "run-s compile && husky"
|
||||
},
|
||||
"dependencies": {
|
||||
"ip-address": "^10.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"express": ">= 4.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "2.4.6",
|
||||
"@express-rate-limit/prettier": "1.1.1",
|
||||
"@express-rate-limit/tsconfig": "1.0.2",
|
||||
"@jest/globals": "29.7.0",
|
||||
"@types/express": "4.17.20",
|
||||
"@types/jest": "29.5.6",
|
||||
"@types/node": "20.8.7",
|
||||
"@types/supertest": "2.0.15",
|
||||
"del-cli": "5.1.0",
|
||||
"dts-bundle-generator": "8.0.1",
|
||||
"esbuild": "0.25.0",
|
||||
"express": "4.21.1",
|
||||
"husky": "8.0.3",
|
||||
"jest": "29.7.0",
|
||||
"lint-staged": "15.0.2",
|
||||
"mintlify": "4.0.63",
|
||||
"@jest/globals": "30.4.1",
|
||||
"@types/express": "5.0.6",
|
||||
"@types/jest": "30.0.0",
|
||||
"@types/node": "25.7.0",
|
||||
"@types/supertest": "7.2.0",
|
||||
"del-cli": "7.0.0",
|
||||
"dts-bundle-generator": "8.1.2",
|
||||
"esbuild": "0.28.0",
|
||||
"express": "5.2.1",
|
||||
"husky": "9.1.7",
|
||||
"jest": "30.4.2",
|
||||
"lint-staged": "17.0.4",
|
||||
"mintlify": "4.2.559",
|
||||
"npm-run-all": "4.1.5",
|
||||
"prettier": "3.8.3",
|
||||
"ratelimit-header-parser": "0.1.0",
|
||||
"supertest": "6.3.3",
|
||||
"ts-jest": "29.1.1",
|
||||
"ts-node": "10.9.1",
|
||||
"typescript": "5.2.2",
|
||||
"xo": "0.56.0"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"@typescript-eslint/no-empty-function": 0,
|
||||
"@typescript-eslint/no-dynamic-delete": 0,
|
||||
"@typescript-eslint/no-confusing-void-expression": 0,
|
||||
"@typescript-eslint/consistent-indexed-object-style": [
|
||||
"error",
|
||||
"index-signature"
|
||||
],
|
||||
"n/no-unsupported-features/es-syntax": 0
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/library/*.ts",
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unsafe-argument": 0,
|
||||
"@typescript-eslint/no-unsafe-assignment": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"ignore": [
|
||||
"test/external"
|
||||
]
|
||||
"supertest": "7.2.2",
|
||||
"ts-jest": "29.4.9",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.9.3"
|
||||
},
|
||||
"prettier": "@express-rate-limit/prettier",
|
||||
"lint-staged": {
|
||||
"{source,test}/**/*.ts": "xo --fix",
|
||||
"**/*.{json,yaml,md}": "prettier --write "
|
||||
"*.{js,ts,json}": "biome check --write",
|
||||
"*.{md,yaml}": "prettier --write"
|
||||
}
|
||||
}
|
||||
|
||||
+10
-18
@@ -28,6 +28,7 @@ const limiter = rateLimit({
|
||||
limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
|
||||
standardHeaders: 'draft-8', // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
|
||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
|
||||
ipv6Subnet: 56, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
|
||||
// store: ... , // Redis, Memcached, etc. See below.
|
||||
})
|
||||
|
||||
@@ -58,30 +59,17 @@ default values.
|
||||
| [`store`] | `Store` | Use a custom store to share hit counts across multiple nodes. |
|
||||
| [`passOnStoreError`] | `boolean` | Allow (`true`) or block (`false`, default) traffic if the store becomes unavailable. |
|
||||
| [`keyGenerator`] | `function` | Identify users (defaults to IP address). |
|
||||
| [`ipv6Subnet`] | `number` (32-64) \| `function` \| `false` | How many bits of IPv6 addresses to use in default `keyGenerator` |
|
||||
| [`requestPropertyName`] | `string` | Add rate limit info to the `req` object. |
|
||||
| [`skip`] | `function` | Return `true` to bypass the limiter for the given request. |
|
||||
| [`skipSuccessfulRequests`] | `boolean` | Uncount 1xx/2xx/3xx responses. |
|
||||
| [`skipFailedRequests`] | `boolean` | Uncount 4xx/5xx responses. |
|
||||
| [`requestWasSuccessful`] | `function` | Used by `skipSuccessfulRequests` and `skipFailedRequests`. |
|
||||
| [`validate`] | `boolean` \| `object` | Enable or disable built-in validation checks. |
|
||||
| [`logger`] | `Logger` | Custom logger |
|
||||
|
||||
## Thank You
|
||||
|
||||
Sponsored by [Zuplo](https://zuplo.link/express-rate-limit) a fully-managed API
|
||||
Gateway for developers. Add
|
||||
[dynamic rate-limiting](https://zuplo.link/dynamic-rate-limiting),
|
||||
authentication and more to any API in minutes. Learn more at
|
||||
[zuplo.com](https://zuplo.link/express-rate-limit)
|
||||
|
||||
<p align="center">
|
||||
<a href="https://zuplo.link/express-rate-limit">
|
||||
<picture width="322">
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/express-rate-limit/express-rate-limit/assets/114976/cd2f6fa7-eae1-4fbb-be7d-b17df4c6f383">
|
||||
<img alt="zuplo-logo" src="https://github.com/express-rate-limit/express-rate-limit/assets/114976/66fd75fa-b39e-4a8c-8d7a-52369bf244dc" width="322">
|
||||
</picture>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
Thanks to Mintlify for hosting the documentation at
|
||||
@@ -95,7 +83,7 @@ Thanks to Mintlify for hosting the documentation at
|
||||
|
||||
---
|
||||
|
||||
Finally, thank you to everyone who's contributed to this project in any way! 🫶
|
||||
And thank you to everyone who's contributed to this project in any way! 🫶
|
||||
|
||||
## Issues and Contributing
|
||||
|
||||
@@ -106,7 +94,7 @@ If you need help with something, feel free to
|
||||
[start a discussion](https://github.com/express-rate-limit/express-rate-limit/discussions/new)!
|
||||
|
||||
If you wish to contribute to the library, thanks! First, please read
|
||||
[the contributing guide](https://express-rate-limit.mintlify.app/docs/guides/contributing.mdx).
|
||||
[the contributing guide](https://express-rate-limit.mintlify.app/guides/contributing).
|
||||
Then you can pick up any issue and fix/implement it!
|
||||
|
||||
## License
|
||||
@@ -131,9 +119,11 @@ MIT © [Nathan Friedly](http://nfriedly.com/),
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#identifier
|
||||
[`store`]: https://express-rate-limit.mintlify.app/reference/configuration#store
|
||||
[`passOnStoreError`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#passOnStoreError
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#passonstoreerror
|
||||
[`keyGenerator`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#keygenerator
|
||||
[`ipv6Subnet`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet
|
||||
[`requestPropertyName`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#requestpropertyname
|
||||
[`skip`]: https://express-rate-limit.mintlify.app/reference/configuration#skip
|
||||
@@ -145,3 +135,5 @@ MIT © [Nathan Friedly](http://nfriedly.com/),
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#requestwassuccessful
|
||||
[`validate`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#validate
|
||||
[`logger`]:
|
||||
https://express-rate-limit.mintlify.app/reference/configuration#logger
|
||||
|
||||
Reference in New Issue
Block a user