Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
114 lines (94 loc) · 2.42 KB
/
Copy pathindex.d.ts
File metadata and controls
114 lines (94 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Request, Response, NextFunction } from 'express';
declare namespace vigil {
interface RateLimitHeaders {
remaining: string;
reset: string;
limit: string;
}
interface StorageOptions {
type: 'memory' | 'redis';
redis?: any;
prefix?: string;
}
interface RateLimitOptions {
/**
* Mode of operation: 'LIVE' for actual rate limiting, 'TEST' to bypass
* @default 'LIVE'
*/
mode?: 'LIVE' | 'TEST';
/**
* Identifier for rate limiting. Can be:
* - 'ip': Use IP address
* - 'userId': Use user ID from request
* - A custom function that returns a string key
* @default 'ip'
*/
by?: string | ((req: Request) => string);
/**
* Number of tokens to add per interval
* @default 5
*/
refillRate?: number;
/**
* Interval in seconds between token refills
* @default 10
*/
interval?: number;
/**
* Maximum token capacity
* @default 10
*/
capacity?: number;
/**
* Custom function to generate rate limit key
*/
keyGenerator?: (req: Request) => string;
/**
* Whether to skip counting successful requests
* @default false
*/
skipSuccessfulRequests?: boolean;
/**
* Whether to skip counting failed requests
* @default false
*/
skipFailedRequests?: boolean;
/**
* Custom handler for when rate limit is exceeded
*/
handler?: (req: Request, res: Response) => void;
/**
* Custom header names
*/
headers?: RateLimitHeaders;
/**
* Disable starting token count at capacity
* @default false
*/
disableStart?: boolean;
/**
* Storage options
*/
storage?: StorageOptions;
}
interface RateLimitInfo {
tokens: number;
lastRefill: number;
}
}
declare function vigil(options?: vigil.RateLimitOptions): (req: Request, res: Response, next: NextFunction) => void;
declare namespace vigil {
/**
* Reset rate limit for a specific key or all keys
*/
export function reset(key?: string): void;
/**
* Get current rate limit info for a key
*/
export function getRateLimitInfo(key: string): RateLimitInfo | null;
/**
* Create a rate limiter with pre-configured options
*/
export function create(options: RateLimitOptions): (req: Request, res: Response, next: NextFunction) => void;
}
export = vigil;