@ooneex/rate-limit 1.1.3 → 1.2.1
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.d.ts +48 -8
- package/dist/index.js +3622 -9
- package/dist/index.js.map +10 -5
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
constructor(message: string, data?: Record<string, unknown>);
|
|
4
|
-
}
|
|
5
|
-
import { AppEnv } from "@ooneex/app-env";
|
|
1
|
+
import { EContainerScope } from "@ooneex/container";
|
|
2
|
+
import { Duration } from "@upstash/ratelimit";
|
|
6
3
|
type RateLimiterClassType = new (...args: any[]) => IRateLimiter;
|
|
7
4
|
type RedisRateLimiterOptionsType = {
|
|
8
5
|
connectionString?: string;
|
|
@@ -14,6 +11,27 @@ type RedisRateLimiterOptionsType = {
|
|
|
14
11
|
enableAutoPipelining?: boolean;
|
|
15
12
|
tls?: boolean | object;
|
|
16
13
|
};
|
|
14
|
+
type UpstashAlgorithmType = {
|
|
15
|
+
type: "fixedWindow";
|
|
16
|
+
limit: number;
|
|
17
|
+
window: Duration;
|
|
18
|
+
} | {
|
|
19
|
+
type: "slidingWindow";
|
|
20
|
+
limit: number;
|
|
21
|
+
window: Duration;
|
|
22
|
+
} | {
|
|
23
|
+
type: "tokenBucket";
|
|
24
|
+
refillRate: number;
|
|
25
|
+
interval: Duration;
|
|
26
|
+
maxTokens: number;
|
|
27
|
+
};
|
|
28
|
+
type UpstashRedisRateLimiterOptionsType = {
|
|
29
|
+
url?: string;
|
|
30
|
+
token?: string;
|
|
31
|
+
algorithm?: UpstashAlgorithmType;
|
|
32
|
+
prefix?: string;
|
|
33
|
+
analytics?: boolean;
|
|
34
|
+
};
|
|
17
35
|
type RateLimitResultType = {
|
|
18
36
|
limited: boolean;
|
|
19
37
|
remaining: number;
|
|
@@ -21,18 +39,40 @@ type RateLimitResultType = {
|
|
|
21
39
|
resetAt: Date;
|
|
22
40
|
};
|
|
23
41
|
interface IRateLimiter {
|
|
24
|
-
check: (key: string
|
|
42
|
+
check: (key: string) => Promise<RateLimitResultType>;
|
|
43
|
+
isLimited: (key: string) => Promise<boolean>;
|
|
25
44
|
reset: (key: string) => Promise<boolean>;
|
|
26
45
|
getCount: (key: string) => Promise<number>;
|
|
27
46
|
}
|
|
47
|
+
declare const decorator: {
|
|
48
|
+
rateLimit: (scope?: EContainerScope) => (target: RateLimiterClassType) => void;
|
|
49
|
+
};
|
|
50
|
+
import { Exception } from "@ooneex/exception";
|
|
51
|
+
declare class RateLimitException extends Exception {
|
|
52
|
+
constructor(message: string, key: string, data?: Record<string, unknown>);
|
|
53
|
+
}
|
|
54
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
28
55
|
declare class RedisRateLimiter implements IRateLimiter {
|
|
29
56
|
private readonly env;
|
|
30
57
|
private client;
|
|
31
58
|
constructor(env: AppEnv, options?: RedisRateLimiterOptionsType);
|
|
32
59
|
private connect;
|
|
33
60
|
private getKey;
|
|
34
|
-
check(key: string
|
|
61
|
+
check(key: string): Promise<RateLimitResultType>;
|
|
62
|
+
isLimited(key: string): Promise<boolean>;
|
|
63
|
+
reset(key: string): Promise<boolean>;
|
|
64
|
+
getCount(key: string): Promise<number>;
|
|
65
|
+
}
|
|
66
|
+
import { AppEnv as AppEnv2 } from "@ooneex/app-env";
|
|
67
|
+
declare class UpstashRedisRateLimiter implements IRateLimiter {
|
|
68
|
+
private readonly env;
|
|
69
|
+
private ratelimit;
|
|
70
|
+
private static readonly DEFAULT_ALGORITHM;
|
|
71
|
+
constructor(env: AppEnv2, options?: UpstashRedisRateLimiterOptionsType);
|
|
72
|
+
private buildLimiter;
|
|
73
|
+
check(key: string): Promise<RateLimitResultType>;
|
|
74
|
+
isLimited(key: string): Promise<boolean>;
|
|
35
75
|
reset(key: string): Promise<boolean>;
|
|
36
76
|
getCount(key: string): Promise<number>;
|
|
37
77
|
}
|
|
38
|
-
export { RedisRateLimiterOptionsType, RedisRateLimiter, RateLimiterClassType, RateLimitResultType, RateLimitException, IRateLimiter };
|
|
78
|
+
export { decorator, UpstashRedisRateLimiterOptionsType, UpstashRedisRateLimiter, UpstashAlgorithmType, RedisRateLimiterOptionsType, RedisRateLimiter, RateLimiterClassType, RateLimitResultType, RateLimitException, IRateLimiter };
|