express-rate-limit 7.5.1 → 8.0.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 +262 -191
- package/dist/index.d.cts +56 -20
- package/dist/index.d.mts +56 -20
- package/dist/index.d.ts +56 -20
- package/dist/index.mjs +249 -189
- package/package.json +33 -53
- package/readme.md +5 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
3
|
+
import { NextFunction, Request as Request$1, RequestHandler, Response as Response$1 } from 'express';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
|
7
|
+
*
|
|
8
|
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
|
9
|
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
|
10
|
+
*
|
|
11
|
+
* For more infomration, {@see Options.ipv6Subnet}.
|
|
12
|
+
*
|
|
13
|
+
* @param ip {string} - The IP address to process, usually request.ip.
|
|
14
|
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} - The key generated from the IP address
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
|
21
|
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
22
|
+
"draft-6",
|
|
23
|
+
"draft-7",
|
|
24
|
+
"draft-8"
|
|
25
|
+
];
|
|
5
26
|
declare const validations: {
|
|
6
27
|
enabled: {
|
|
7
28
|
[key: string]: boolean;
|
|
@@ -117,13 +138,11 @@ declare const validations: {
|
|
|
117
138
|
* store (or any other store with localKeys.)
|
|
118
139
|
*/
|
|
119
140
|
creationStack(store: Store): void;
|
|
141
|
+
ipv6Subnet(ipv6Subnet?: any): void;
|
|
142
|
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
|
143
|
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
|
120
144
|
};
|
|
121
145
|
export type Validations = typeof validations;
|
|
122
|
-
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
123
|
-
"draft-6",
|
|
124
|
-
"draft-7",
|
|
125
|
-
"draft-8"
|
|
126
|
-
];
|
|
127
146
|
/**
|
|
128
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
129
148
|
*
|
|
@@ -280,7 +299,8 @@ export type Store = {
|
|
|
280
299
|
/**
|
|
281
300
|
* Optional value that the store prepends to keys
|
|
282
301
|
*
|
|
283
|
-
* Used by the double-count check to avoid false-positives when a key is counted
|
|
302
|
+
* Used by the double-count check to avoid false-positives when a key is counted
|
|
303
|
+
* twice, but with different prefixes.
|
|
284
304
|
*/
|
|
285
305
|
prefix?: string;
|
|
286
306
|
};
|
|
@@ -372,6 +392,21 @@ export type Options = {
|
|
|
372
392
|
* By default, the client's IP address is used.
|
|
373
393
|
*/
|
|
374
394
|
keyGenerator: ValueDeterminingMiddleware<string>;
|
|
395
|
+
/**
|
|
396
|
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
|
397
|
+
*
|
|
398
|
+
* Default is 56. The valid range is technically 1-128 but the value should
|
|
399
|
+
* generally be in the 32-64 range.
|
|
400
|
+
*
|
|
401
|
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
|
402
|
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
|
403
|
+
*
|
|
404
|
+
* May also be set to a function that returns a number based on the request.
|
|
405
|
+
*
|
|
406
|
+
* See the documentation for more info:
|
|
407
|
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
|
408
|
+
*/
|
|
409
|
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
|
375
410
|
/**
|
|
376
411
|
* Express request handler that sends back a response when a client is
|
|
377
412
|
* rate-limited.
|
|
@@ -387,7 +422,7 @@ export type Options = {
|
|
|
387
422
|
*/
|
|
388
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
389
424
|
/**
|
|
390
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
391
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
392
427
|
*
|
|
393
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -443,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
443
478
|
used: number;
|
|
444
479
|
remaining: number;
|
|
445
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
446
482
|
};
|
|
447
|
-
/**
|
|
448
|
-
*
|
|
449
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
450
|
-
*
|
|
451
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
452
|
-
*
|
|
453
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
454
|
-
*
|
|
455
|
-
* @public
|
|
456
|
-
*/
|
|
457
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
458
483
|
/**
|
|
459
484
|
* The record that stores information about a client - namely, how many times
|
|
460
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -580,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
580
605
|
*/
|
|
581
606
|
private clearExpired;
|
|
582
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
*
|
|
610
|
+
* Create an instance of IP rate-limiting middleware for Express.
|
|
611
|
+
*
|
|
612
|
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
613
|
+
*
|
|
614
|
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
615
|
+
*
|
|
616
|
+
* @public
|
|
617
|
+
*/
|
|
618
|
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
583
619
|
|
|
584
620
|
export {
|
|
585
621
|
rateLimit as default,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
3
|
+
import { NextFunction, Request as Request$1, RequestHandler, Response as Response$1 } from 'express';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
|
7
|
+
*
|
|
8
|
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
|
9
|
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
|
10
|
+
*
|
|
11
|
+
* For more infomration, {@see Options.ipv6Subnet}.
|
|
12
|
+
*
|
|
13
|
+
* @param ip {string} - The IP address to process, usually request.ip.
|
|
14
|
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} - The key generated from the IP address
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
|
21
|
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
22
|
+
"draft-6",
|
|
23
|
+
"draft-7",
|
|
24
|
+
"draft-8"
|
|
25
|
+
];
|
|
5
26
|
declare const validations: {
|
|
6
27
|
enabled: {
|
|
7
28
|
[key: string]: boolean;
|
|
@@ -117,13 +138,11 @@ declare const validations: {
|
|
|
117
138
|
* store (or any other store with localKeys.)
|
|
118
139
|
*/
|
|
119
140
|
creationStack(store: Store): void;
|
|
141
|
+
ipv6Subnet(ipv6Subnet?: any): void;
|
|
142
|
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
|
143
|
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
|
120
144
|
};
|
|
121
145
|
export type Validations = typeof validations;
|
|
122
|
-
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
123
|
-
"draft-6",
|
|
124
|
-
"draft-7",
|
|
125
|
-
"draft-8"
|
|
126
|
-
];
|
|
127
146
|
/**
|
|
128
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
129
148
|
*
|
|
@@ -280,7 +299,8 @@ export type Store = {
|
|
|
280
299
|
/**
|
|
281
300
|
* Optional value that the store prepends to keys
|
|
282
301
|
*
|
|
283
|
-
* Used by the double-count check to avoid false-positives when a key is counted
|
|
302
|
+
* Used by the double-count check to avoid false-positives when a key is counted
|
|
303
|
+
* twice, but with different prefixes.
|
|
284
304
|
*/
|
|
285
305
|
prefix?: string;
|
|
286
306
|
};
|
|
@@ -372,6 +392,21 @@ export type Options = {
|
|
|
372
392
|
* By default, the client's IP address is used.
|
|
373
393
|
*/
|
|
374
394
|
keyGenerator: ValueDeterminingMiddleware<string>;
|
|
395
|
+
/**
|
|
396
|
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
|
397
|
+
*
|
|
398
|
+
* Default is 56. The valid range is technically 1-128 but the value should
|
|
399
|
+
* generally be in the 32-64 range.
|
|
400
|
+
*
|
|
401
|
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
|
402
|
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
|
403
|
+
*
|
|
404
|
+
* May also be set to a function that returns a number based on the request.
|
|
405
|
+
*
|
|
406
|
+
* See the documentation for more info:
|
|
407
|
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
|
408
|
+
*/
|
|
409
|
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
|
375
410
|
/**
|
|
376
411
|
* Express request handler that sends back a response when a client is
|
|
377
412
|
* rate-limited.
|
|
@@ -387,7 +422,7 @@ export type Options = {
|
|
|
387
422
|
*/
|
|
388
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
389
424
|
/**
|
|
390
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
391
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
392
427
|
*
|
|
393
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -443,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
443
478
|
used: number;
|
|
444
479
|
remaining: number;
|
|
445
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
446
482
|
};
|
|
447
|
-
/**
|
|
448
|
-
*
|
|
449
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
450
|
-
*
|
|
451
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
452
|
-
*
|
|
453
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
454
|
-
*
|
|
455
|
-
* @public
|
|
456
|
-
*/
|
|
457
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
458
483
|
/**
|
|
459
484
|
* The record that stores information about a client - namely, how many times
|
|
460
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -580,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
580
605
|
*/
|
|
581
606
|
private clearExpired;
|
|
582
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
*
|
|
610
|
+
* Create an instance of IP rate-limiting middleware for Express.
|
|
611
|
+
*
|
|
612
|
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
613
|
+
*
|
|
614
|
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
615
|
+
*
|
|
616
|
+
* @public
|
|
617
|
+
*/
|
|
618
|
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
583
619
|
|
|
584
620
|
export {
|
|
585
621
|
rateLimit as default,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
3
|
+
import { NextFunction, Request as Request$1, RequestHandler, Response as Response$1 } from 'express';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the IP address itself for IPv4, or a CIDR-notation subnet for IPv6.
|
|
7
|
+
*
|
|
8
|
+
* If you write a custom keyGenerator that allows a fallback to IP address for
|
|
9
|
+
* unauthenticated users, return ipKeyGenerator(req.ip) rather than just req.ip.
|
|
10
|
+
*
|
|
11
|
+
* For more infomration, {@see Options.ipv6Subnet}.
|
|
12
|
+
*
|
|
13
|
+
* @param ip {string} - The IP address to process, usually request.ip.
|
|
14
|
+
* @param ipv6Subnet {number | false} - The subnet mask for IPv6 addresses.
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} - The key generated from the IP address
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function ipKeyGenerator(ip: string, ipv6Subnet?: number | false): string;
|
|
21
|
+
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
22
|
+
"draft-6",
|
|
23
|
+
"draft-7",
|
|
24
|
+
"draft-8"
|
|
25
|
+
];
|
|
5
26
|
declare const validations: {
|
|
6
27
|
enabled: {
|
|
7
28
|
[key: string]: boolean;
|
|
@@ -117,13 +138,11 @@ declare const validations: {
|
|
|
117
138
|
* store (or any other store with localKeys.)
|
|
118
139
|
*/
|
|
119
140
|
creationStack(store: Store): void;
|
|
141
|
+
ipv6Subnet(ipv6Subnet?: any): void;
|
|
142
|
+
ipv6SubnetOrKeyGenerator(options: Partial<Options>): void;
|
|
143
|
+
keyGeneratorIpFallback(keyGenerator?: ValueDeterminingMiddleware<string>): void;
|
|
120
144
|
};
|
|
121
145
|
export type Validations = typeof validations;
|
|
122
|
-
declare const SUPPORTED_DRAFT_VERSIONS: readonly [
|
|
123
|
-
"draft-6",
|
|
124
|
-
"draft-7",
|
|
125
|
-
"draft-8"
|
|
126
|
-
];
|
|
127
146
|
/**
|
|
128
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
129
148
|
*
|
|
@@ -280,7 +299,8 @@ export type Store = {
|
|
|
280
299
|
/**
|
|
281
300
|
* Optional value that the store prepends to keys
|
|
282
301
|
*
|
|
283
|
-
* Used by the double-count check to avoid false-positives when a key is counted
|
|
302
|
+
* Used by the double-count check to avoid false-positives when a key is counted
|
|
303
|
+
* twice, but with different prefixes.
|
|
284
304
|
*/
|
|
285
305
|
prefix?: string;
|
|
286
306
|
};
|
|
@@ -372,6 +392,21 @@ export type Options = {
|
|
|
372
392
|
* By default, the client's IP address is used.
|
|
373
393
|
*/
|
|
374
394
|
keyGenerator: ValueDeterminingMiddleware<string>;
|
|
395
|
+
/**
|
|
396
|
+
* IPv6 subnet mask applied to IPv6 addresses in the default keyGenerator.
|
|
397
|
+
*
|
|
398
|
+
* Default is 56. The valid range is technically 1-128 but the value should
|
|
399
|
+
* generally be in the 32-64 range.
|
|
400
|
+
*
|
|
401
|
+
* Smaller numbers are more aggressive, larger numbers are more lenient. Try
|
|
402
|
+
* bumping to 60 or 64 if you see evidence of users being blocked incorrectly.
|
|
403
|
+
*
|
|
404
|
+
* May also be set to a function that returns a number based on the request.
|
|
405
|
+
*
|
|
406
|
+
* See the documentation for more info:
|
|
407
|
+
* https://express-rate-limit.mintlify.app/reference/configuration#ipv6subnet.
|
|
408
|
+
*/
|
|
409
|
+
ipv6Subnet: 64 | 60 | 56 | 52 | 50 | 48 | 32 | number | ValueDeterminingMiddleware<number> | false;
|
|
375
410
|
/**
|
|
376
411
|
* Express request handler that sends back a response when a client is
|
|
377
412
|
* rate-limited.
|
|
@@ -387,7 +422,7 @@ export type Options = {
|
|
|
387
422
|
*/
|
|
388
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
389
424
|
/**
|
|
390
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
391
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
392
427
|
*
|
|
393
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -443,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
443
478
|
used: number;
|
|
444
479
|
remaining: number;
|
|
445
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
446
482
|
};
|
|
447
|
-
/**
|
|
448
|
-
*
|
|
449
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
450
|
-
*
|
|
451
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
452
|
-
*
|
|
453
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
454
|
-
*
|
|
455
|
-
* @public
|
|
456
|
-
*/
|
|
457
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
458
483
|
/**
|
|
459
484
|
* The record that stores information about a client - namely, how many times
|
|
460
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -580,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
580
605
|
*/
|
|
581
606
|
private clearExpired;
|
|
582
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
*
|
|
610
|
+
* Create an instance of IP rate-limiting middleware for Express.
|
|
611
|
+
*
|
|
612
|
+
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
613
|
+
*
|
|
614
|
+
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
615
|
+
*
|
|
616
|
+
* @public
|
|
617
|
+
*/
|
|
618
|
+
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
583
619
|
|
|
584
620
|
export {
|
|
585
621
|
rateLimit as default,
|