express-rate-limit 7.5.0 → 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 +292 -236
- package/dist/index.d.cts +56 -16
- package/dist/index.d.mts +56 -16
- package/dist/index.d.ts +56 -16
- package/dist/index.mjs +277 -232
- package/package.json +34 -54
- 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,9 +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: string[];
|
|
123
146
|
/**
|
|
124
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
125
148
|
*
|
|
@@ -276,7 +299,8 @@ export type Store = {
|
|
|
276
299
|
/**
|
|
277
300
|
* Optional value that the store prepends to keys
|
|
278
301
|
*
|
|
279
|
-
* 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.
|
|
280
304
|
*/
|
|
281
305
|
prefix?: string;
|
|
282
306
|
};
|
|
@@ -368,6 +392,21 @@ export type Options = {
|
|
|
368
392
|
* By default, the client's IP address is used.
|
|
369
393
|
*/
|
|
370
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;
|
|
371
410
|
/**
|
|
372
411
|
* Express request handler that sends back a response when a client is
|
|
373
412
|
* rate-limited.
|
|
@@ -383,7 +422,7 @@ export type Options = {
|
|
|
383
422
|
*/
|
|
384
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
385
424
|
/**
|
|
386
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
387
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
388
427
|
*
|
|
389
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -439,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
439
478
|
used: number;
|
|
440
479
|
remaining: number;
|
|
441
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
442
482
|
};
|
|
443
|
-
/**
|
|
444
|
-
*
|
|
445
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
446
|
-
*
|
|
447
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
448
|
-
*
|
|
449
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
450
|
-
*
|
|
451
|
-
* @public
|
|
452
|
-
*/
|
|
453
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
454
483
|
/**
|
|
455
484
|
* The record that stores information about a client - namely, how many times
|
|
456
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -576,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
576
605
|
*/
|
|
577
606
|
private clearExpired;
|
|
578
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;
|
|
579
619
|
|
|
580
620
|
export {
|
|
581
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,9 +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: string[];
|
|
123
146
|
/**
|
|
124
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
125
148
|
*
|
|
@@ -276,7 +299,8 @@ export type Store = {
|
|
|
276
299
|
/**
|
|
277
300
|
* Optional value that the store prepends to keys
|
|
278
301
|
*
|
|
279
|
-
* 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.
|
|
280
304
|
*/
|
|
281
305
|
prefix?: string;
|
|
282
306
|
};
|
|
@@ -368,6 +392,21 @@ export type Options = {
|
|
|
368
392
|
* By default, the client's IP address is used.
|
|
369
393
|
*/
|
|
370
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;
|
|
371
410
|
/**
|
|
372
411
|
* Express request handler that sends back a response when a client is
|
|
373
412
|
* rate-limited.
|
|
@@ -383,7 +422,7 @@ export type Options = {
|
|
|
383
422
|
*/
|
|
384
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
385
424
|
/**
|
|
386
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
387
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
388
427
|
*
|
|
389
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -439,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
439
478
|
used: number;
|
|
440
479
|
remaining: number;
|
|
441
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
442
482
|
};
|
|
443
|
-
/**
|
|
444
|
-
*
|
|
445
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
446
|
-
*
|
|
447
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
448
|
-
*
|
|
449
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
450
|
-
*
|
|
451
|
-
* @public
|
|
452
|
-
*/
|
|
453
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
454
483
|
/**
|
|
455
484
|
* The record that stores information about a client - namely, how many times
|
|
456
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -576,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
576
605
|
*/
|
|
577
606
|
private clearExpired;
|
|
578
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;
|
|
579
619
|
|
|
580
620
|
export {
|
|
581
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,9 +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: string[];
|
|
123
146
|
/**
|
|
124
147
|
* Callback that fires when a client's hit counter is incremented.
|
|
125
148
|
*
|
|
@@ -276,7 +299,8 @@ export type Store = {
|
|
|
276
299
|
/**
|
|
277
300
|
* Optional value that the store prepends to keys
|
|
278
301
|
*
|
|
279
|
-
* 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.
|
|
280
304
|
*/
|
|
281
305
|
prefix?: string;
|
|
282
306
|
};
|
|
@@ -368,6 +392,21 @@ export type Options = {
|
|
|
368
392
|
* By default, the client's IP address is used.
|
|
369
393
|
*/
|
|
370
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;
|
|
371
410
|
/**
|
|
372
411
|
* Express request handler that sends back a response when a client is
|
|
373
412
|
* rate-limited.
|
|
@@ -383,7 +422,7 @@ export type Options = {
|
|
|
383
422
|
*/
|
|
384
423
|
skip: ValueDeterminingMiddleware<boolean>;
|
|
385
424
|
/**
|
|
386
|
-
* Method to determine whether or not the request counts as '
|
|
425
|
+
* Method to determine whether or not the request counts as 'successful'. Used
|
|
387
426
|
* when either `skipSuccessfulRequests` or `skipFailedRequests` is set to true.
|
|
388
427
|
*
|
|
389
428
|
* By default, requests with a response status code less than 400 are considered
|
|
@@ -439,18 +478,8 @@ export type RateLimitInfo = {
|
|
|
439
478
|
used: number;
|
|
440
479
|
remaining: number;
|
|
441
480
|
resetTime: Date | undefined;
|
|
481
|
+
key: string;
|
|
442
482
|
};
|
|
443
|
-
/**
|
|
444
|
-
*
|
|
445
|
-
* Create an instance of IP rate-limiting middleware for Express.
|
|
446
|
-
*
|
|
447
|
-
* @param passedOptions {Options} - Options to configure the rate limiter.
|
|
448
|
-
*
|
|
449
|
-
* @returns {RateLimitRequestHandler} - The middleware that rate-limits clients based on your configuration.
|
|
450
|
-
*
|
|
451
|
-
* @public
|
|
452
|
-
*/
|
|
453
|
-
export declare const rateLimit: (passedOptions?: Partial<Options>) => RateLimitRequestHandler;
|
|
454
483
|
/**
|
|
455
484
|
* The record that stores information about a client - namely, how many times
|
|
456
485
|
* they have hit the endpoint, and when their hit count resets.
|
|
@@ -576,6 +605,17 @@ export declare class MemoryStore implements Store {
|
|
|
576
605
|
*/
|
|
577
606
|
private clearExpired;
|
|
578
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;
|
|
579
619
|
|
|
580
620
|
export {
|
|
581
621
|
rateLimit as default,
|