@upstash/ratelimit 2.0.4 → 2.0.5
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.mts +9 -19
- package/dist/index.d.ts +9 -19
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Aggregate } from '@upstash/core-analytics';
|
|
2
|
-
import { Redis as Redis$
|
|
2
|
+
import { Redis as Redis$2 } from '@upstash/redis';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* EphemeralCache is used to block certain identifiers right away in case they have already exceeded the ratelimit.
|
|
@@ -18,7 +18,7 @@ type EphemeralCache = {
|
|
|
18
18
|
size: () => number;
|
|
19
19
|
};
|
|
20
20
|
type RegionContext = {
|
|
21
|
-
redis: Redis;
|
|
21
|
+
redis: Redis$1;
|
|
22
22
|
cache?: EphemeralCache;
|
|
23
23
|
};
|
|
24
24
|
type MultiRegionContext = {
|
|
@@ -98,18 +98,7 @@ type LimitOptions = {
|
|
|
98
98
|
userAgent?: string;
|
|
99
99
|
country?: string;
|
|
100
100
|
};
|
|
101
|
-
|
|
102
|
-
* This is all we need from the redis sdk.
|
|
103
|
-
*/
|
|
104
|
-
type Redis = {
|
|
105
|
-
sadd: Redis$1["sadd"];
|
|
106
|
-
hset: Redis$1["hset"];
|
|
107
|
-
eval: Redis$1["eval"];
|
|
108
|
-
evalsha: Redis$1["evalsha"];
|
|
109
|
-
scriptLoad: Redis$1["scriptLoad"];
|
|
110
|
-
smismember: Redis$1["smismember"];
|
|
111
|
-
multi: Redis$1["multi"];
|
|
112
|
-
};
|
|
101
|
+
type Redis$1 = Redis$2;
|
|
113
102
|
|
|
114
103
|
type Geo = {
|
|
115
104
|
country?: string;
|
|
@@ -129,7 +118,7 @@ type Event = Geo & {
|
|
|
129
118
|
success: EventSuccess;
|
|
130
119
|
};
|
|
131
120
|
type AnalyticsConfig = {
|
|
132
|
-
redis: Redis;
|
|
121
|
+
redis: Redis$1;
|
|
133
122
|
prefix?: string;
|
|
134
123
|
};
|
|
135
124
|
/**
|
|
@@ -256,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
256
245
|
protected readonly ctx: TContext;
|
|
257
246
|
protected readonly prefix: string;
|
|
258
247
|
protected readonly timeout: number;
|
|
259
|
-
protected readonly primaryRedis: Redis;
|
|
248
|
+
protected readonly primaryRedis: Redis$1;
|
|
260
249
|
protected readonly analytics?: Analytics;
|
|
261
250
|
protected readonly enableProtection: boolean;
|
|
262
251
|
protected readonly denyListThreshold: number;
|
|
@@ -381,7 +370,7 @@ type MultiRegionRatelimitConfig = {
|
|
|
381
370
|
* Instances of `@upstash/redis`
|
|
382
371
|
* @see https://github.com/upstash/upstash-redis#quick-start
|
|
383
372
|
*/
|
|
384
|
-
redis: Redis[];
|
|
373
|
+
redis: Redis$1[];
|
|
385
374
|
/**
|
|
386
375
|
* The ratelimiter function to use.
|
|
387
376
|
*
|
|
@@ -508,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
508
497
|
window: Duration): Algorithm<MultiRegionContext>;
|
|
509
498
|
}
|
|
510
499
|
|
|
500
|
+
type Redis = Pick<Redis$1, "get" | "set">;
|
|
511
501
|
type RegionRatelimitConfig = {
|
|
512
502
|
/**
|
|
513
503
|
* Instance of `@upstash/redis`
|
|
@@ -740,7 +730,7 @@ declare class ThresholdError extends Error {
|
|
|
740
730
|
* passed, ttl is infferred from current time.
|
|
741
731
|
* @returns list of ips which are not in the deny list
|
|
742
732
|
*/
|
|
743
|
-
declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
733
|
+
declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
744
734
|
/**
|
|
745
735
|
* Disables the ip deny list by removing the ip deny list from the all
|
|
746
736
|
* set and removing the ip deny list. Also sets the status key to disabled
|
|
@@ -750,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
|
|
|
750
740
|
* @param prefix ratelimit prefix
|
|
751
741
|
* @returns
|
|
752
742
|
*/
|
|
753
|
-
declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
|
|
743
|
+
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
754
744
|
|
|
755
745
|
type ipDenyList_ThresholdError = ThresholdError;
|
|
756
746
|
declare const ipDenyList_ThresholdError: typeof ThresholdError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Aggregate } from '@upstash/core-analytics';
|
|
2
|
-
import { Redis as Redis$
|
|
2
|
+
import { Redis as Redis$2 } from '@upstash/redis';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* EphemeralCache is used to block certain identifiers right away in case they have already exceeded the ratelimit.
|
|
@@ -18,7 +18,7 @@ type EphemeralCache = {
|
|
|
18
18
|
size: () => number;
|
|
19
19
|
};
|
|
20
20
|
type RegionContext = {
|
|
21
|
-
redis: Redis;
|
|
21
|
+
redis: Redis$1;
|
|
22
22
|
cache?: EphemeralCache;
|
|
23
23
|
};
|
|
24
24
|
type MultiRegionContext = {
|
|
@@ -98,18 +98,7 @@ type LimitOptions = {
|
|
|
98
98
|
userAgent?: string;
|
|
99
99
|
country?: string;
|
|
100
100
|
};
|
|
101
|
-
|
|
102
|
-
* This is all we need from the redis sdk.
|
|
103
|
-
*/
|
|
104
|
-
type Redis = {
|
|
105
|
-
sadd: Redis$1["sadd"];
|
|
106
|
-
hset: Redis$1["hset"];
|
|
107
|
-
eval: Redis$1["eval"];
|
|
108
|
-
evalsha: Redis$1["evalsha"];
|
|
109
|
-
scriptLoad: Redis$1["scriptLoad"];
|
|
110
|
-
smismember: Redis$1["smismember"];
|
|
111
|
-
multi: Redis$1["multi"];
|
|
112
|
-
};
|
|
101
|
+
type Redis$1 = Redis$2;
|
|
113
102
|
|
|
114
103
|
type Geo = {
|
|
115
104
|
country?: string;
|
|
@@ -129,7 +118,7 @@ type Event = Geo & {
|
|
|
129
118
|
success: EventSuccess;
|
|
130
119
|
};
|
|
131
120
|
type AnalyticsConfig = {
|
|
132
|
-
redis: Redis;
|
|
121
|
+
redis: Redis$1;
|
|
133
122
|
prefix?: string;
|
|
134
123
|
};
|
|
135
124
|
/**
|
|
@@ -256,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
256
245
|
protected readonly ctx: TContext;
|
|
257
246
|
protected readonly prefix: string;
|
|
258
247
|
protected readonly timeout: number;
|
|
259
|
-
protected readonly primaryRedis: Redis;
|
|
248
|
+
protected readonly primaryRedis: Redis$1;
|
|
260
249
|
protected readonly analytics?: Analytics;
|
|
261
250
|
protected readonly enableProtection: boolean;
|
|
262
251
|
protected readonly denyListThreshold: number;
|
|
@@ -381,7 +370,7 @@ type MultiRegionRatelimitConfig = {
|
|
|
381
370
|
* Instances of `@upstash/redis`
|
|
382
371
|
* @see https://github.com/upstash/upstash-redis#quick-start
|
|
383
372
|
*/
|
|
384
|
-
redis: Redis[];
|
|
373
|
+
redis: Redis$1[];
|
|
385
374
|
/**
|
|
386
375
|
* The ratelimiter function to use.
|
|
387
376
|
*
|
|
@@ -508,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
508
497
|
window: Duration): Algorithm<MultiRegionContext>;
|
|
509
498
|
}
|
|
510
499
|
|
|
500
|
+
type Redis = Pick<Redis$1, "get" | "set">;
|
|
511
501
|
type RegionRatelimitConfig = {
|
|
512
502
|
/**
|
|
513
503
|
* Instance of `@upstash/redis`
|
|
@@ -740,7 +730,7 @@ declare class ThresholdError extends Error {
|
|
|
740
730
|
* passed, ttl is infferred from current time.
|
|
741
731
|
* @returns list of ips which are not in the deny list
|
|
742
732
|
*/
|
|
743
|
-
declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
733
|
+
declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
744
734
|
/**
|
|
745
735
|
* Disables the ip deny list by removing the ip deny list from the all
|
|
746
736
|
* set and removing the ip deny list. Also sets the status key to disabled
|
|
@@ -750,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
|
|
|
750
740
|
* @param prefix ratelimit prefix
|
|
751
741
|
* @returns
|
|
752
742
|
*/
|
|
753
|
-
declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
|
|
743
|
+
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
754
744
|
|
|
755
745
|
type ipDenyList_ThresholdError = ThresholdError;
|
|
756
746
|
declare const ipDenyList_ThresholdError: typeof ThresholdError;
|
package/dist/index.js
CHANGED
|
@@ -925,7 +925,7 @@ var Ratelimit = class {
|
|
|
925
925
|
*/
|
|
926
926
|
getDefinedMembers = (identifier, req) => {
|
|
927
927
|
const members = [identifier, req?.ip, req?.userAgent, req?.country];
|
|
928
|
-
return members.filter(
|
|
928
|
+
return members.filter(Boolean);
|
|
929
929
|
};
|
|
930
930
|
};
|
|
931
931
|
|