@upstash/ratelimit 0.0.0-ci.83783060c0ea8611b51e2859446139ff81848e1c-20241006175725 → 0.0.0-ci.942fb8d4eb8e5aba7ee8c6829881b0d27b71599a-20241207000554
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 -22
- package/dist/index.d.ts +9 -22
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- 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 {
|
|
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 = {
|
|
@@ -90,7 +90,6 @@ type Algorithm<TContext> = () => {
|
|
|
90
90
|
}>;
|
|
91
91
|
resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
|
|
92
92
|
};
|
|
93
|
-
type IsDenied = 0 | 1;
|
|
94
93
|
type DeniedValue = string | undefined;
|
|
95
94
|
type LimitOptions = {
|
|
96
95
|
geo?: Geo;
|
|
@@ -99,20 +98,7 @@ type LimitOptions = {
|
|
|
99
98
|
userAgent?: string;
|
|
100
99
|
country?: string;
|
|
101
100
|
};
|
|
102
|
-
|
|
103
|
-
* This is all we need from the redis sdk.
|
|
104
|
-
*/
|
|
105
|
-
type Redis = {
|
|
106
|
-
sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
|
|
107
|
-
hset: <TValue>(key: string, obj: {
|
|
108
|
-
[key: string]: TValue;
|
|
109
|
-
}) => Promise<number>;
|
|
110
|
-
eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
|
|
111
|
-
evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
|
|
112
|
-
scriptLoad: (...args: [script: string]) => Promise<string>;
|
|
113
|
-
smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
|
|
114
|
-
multi: () => Pipeline;
|
|
115
|
-
};
|
|
101
|
+
type Redis$1 = Redis$2;
|
|
116
102
|
|
|
117
103
|
type Geo = {
|
|
118
104
|
country?: string;
|
|
@@ -132,7 +118,7 @@ type Event = Geo & {
|
|
|
132
118
|
success: EventSuccess;
|
|
133
119
|
};
|
|
134
120
|
type AnalyticsConfig = {
|
|
135
|
-
redis: Redis;
|
|
121
|
+
redis: Redis$1;
|
|
136
122
|
prefix?: string;
|
|
137
123
|
};
|
|
138
124
|
/**
|
|
@@ -259,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
259
245
|
protected readonly ctx: TContext;
|
|
260
246
|
protected readonly prefix: string;
|
|
261
247
|
protected readonly timeout: number;
|
|
262
|
-
protected readonly primaryRedis: Redis;
|
|
248
|
+
protected readonly primaryRedis: Redis$1;
|
|
263
249
|
protected readonly analytics?: Analytics;
|
|
264
250
|
protected readonly enableProtection: boolean;
|
|
265
251
|
protected readonly denyListThreshold: number;
|
|
@@ -384,7 +370,7 @@ type MultiRegionRatelimitConfig = {
|
|
|
384
370
|
* Instances of `@upstash/redis`
|
|
385
371
|
* @see https://github.com/upstash/upstash-redis#quick-start
|
|
386
372
|
*/
|
|
387
|
-
redis: Redis[];
|
|
373
|
+
redis: Redis$1[];
|
|
388
374
|
/**
|
|
389
375
|
* The ratelimiter function to use.
|
|
390
376
|
*
|
|
@@ -511,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
511
497
|
window: Duration): Algorithm<MultiRegionContext>;
|
|
512
498
|
}
|
|
513
499
|
|
|
500
|
+
type Redis = Pick<Redis$1, "get" | "set">;
|
|
514
501
|
type RegionRatelimitConfig = {
|
|
515
502
|
/**
|
|
516
503
|
* Instance of `@upstash/redis`
|
|
@@ -743,7 +730,7 @@ declare class ThresholdError extends Error {
|
|
|
743
730
|
* passed, ttl is infferred from current time.
|
|
744
731
|
* @returns list of ips which are not in the deny list
|
|
745
732
|
*/
|
|
746
|
-
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[]>;
|
|
747
734
|
/**
|
|
748
735
|
* Disables the ip deny list by removing the ip deny list from the all
|
|
749
736
|
* set and removing the ip deny list. Also sets the status key to disabled
|
|
@@ -753,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
|
|
|
753
740
|
* @param prefix ratelimit prefix
|
|
754
741
|
* @returns
|
|
755
742
|
*/
|
|
756
|
-
declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
|
|
743
|
+
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
757
744
|
|
|
758
745
|
type ipDenyList_ThresholdError = ThresholdError;
|
|
759
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 {
|
|
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 = {
|
|
@@ -90,7 +90,6 @@ type Algorithm<TContext> = () => {
|
|
|
90
90
|
}>;
|
|
91
91
|
resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
|
|
92
92
|
};
|
|
93
|
-
type IsDenied = 0 | 1;
|
|
94
93
|
type DeniedValue = string | undefined;
|
|
95
94
|
type LimitOptions = {
|
|
96
95
|
geo?: Geo;
|
|
@@ -99,20 +98,7 @@ type LimitOptions = {
|
|
|
99
98
|
userAgent?: string;
|
|
100
99
|
country?: string;
|
|
101
100
|
};
|
|
102
|
-
|
|
103
|
-
* This is all we need from the redis sdk.
|
|
104
|
-
*/
|
|
105
|
-
type Redis = {
|
|
106
|
-
sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
|
|
107
|
-
hset: <TValue>(key: string, obj: {
|
|
108
|
-
[key: string]: TValue;
|
|
109
|
-
}) => Promise<number>;
|
|
110
|
-
eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
|
|
111
|
-
evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
|
|
112
|
-
scriptLoad: (...args: [script: string]) => Promise<string>;
|
|
113
|
-
smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
|
|
114
|
-
multi: () => Pipeline;
|
|
115
|
-
};
|
|
101
|
+
type Redis$1 = Redis$2;
|
|
116
102
|
|
|
117
103
|
type Geo = {
|
|
118
104
|
country?: string;
|
|
@@ -132,7 +118,7 @@ type Event = Geo & {
|
|
|
132
118
|
success: EventSuccess;
|
|
133
119
|
};
|
|
134
120
|
type AnalyticsConfig = {
|
|
135
|
-
redis: Redis;
|
|
121
|
+
redis: Redis$1;
|
|
136
122
|
prefix?: string;
|
|
137
123
|
};
|
|
138
124
|
/**
|
|
@@ -259,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
259
245
|
protected readonly ctx: TContext;
|
|
260
246
|
protected readonly prefix: string;
|
|
261
247
|
protected readonly timeout: number;
|
|
262
|
-
protected readonly primaryRedis: Redis;
|
|
248
|
+
protected readonly primaryRedis: Redis$1;
|
|
263
249
|
protected readonly analytics?: Analytics;
|
|
264
250
|
protected readonly enableProtection: boolean;
|
|
265
251
|
protected readonly denyListThreshold: number;
|
|
@@ -384,7 +370,7 @@ type MultiRegionRatelimitConfig = {
|
|
|
384
370
|
* Instances of `@upstash/redis`
|
|
385
371
|
* @see https://github.com/upstash/upstash-redis#quick-start
|
|
386
372
|
*/
|
|
387
|
-
redis: Redis[];
|
|
373
|
+
redis: Redis$1[];
|
|
388
374
|
/**
|
|
389
375
|
* The ratelimiter function to use.
|
|
390
376
|
*
|
|
@@ -511,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
511
497
|
window: Duration): Algorithm<MultiRegionContext>;
|
|
512
498
|
}
|
|
513
499
|
|
|
500
|
+
type Redis = Pick<Redis$1, "get" | "set">;
|
|
514
501
|
type RegionRatelimitConfig = {
|
|
515
502
|
/**
|
|
516
503
|
* Instance of `@upstash/redis`
|
|
@@ -743,7 +730,7 @@ declare class ThresholdError extends Error {
|
|
|
743
730
|
* passed, ttl is infferred from current time.
|
|
744
731
|
* @returns list of ips which are not in the deny list
|
|
745
732
|
*/
|
|
746
|
-
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[]>;
|
|
747
734
|
/**
|
|
748
735
|
* Disables the ip deny list by removing the ip deny list from the all
|
|
749
736
|
* set and removing the ip deny list. Also sets the status key to disabled
|
|
@@ -753,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
|
|
|
753
740
|
* @param prefix ratelimit prefix
|
|
754
741
|
* @returns
|
|
755
742
|
*/
|
|
756
|
-
declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
|
|
743
|
+
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
757
744
|
|
|
758
745
|
type ipDenyList_ThresholdError = ThresholdError;
|
|
759
746
|
declare const ipDenyList_ThresholdError: typeof ThresholdError;
|
package/dist/index.js
CHANGED
|
@@ -600,7 +600,7 @@ var updateIpDenyList = async (redis, prefix, threshold, ttl) => {
|
|
|
600
600
|
const transaction = redis.multi();
|
|
601
601
|
transaction.sdiffstore(allDenyLists, allDenyLists, ipDenyList);
|
|
602
602
|
transaction.del(ipDenyList);
|
|
603
|
-
transaction.sadd(ipDenyList, ...allIps);
|
|
603
|
+
transaction.sadd(ipDenyList, allIps.at(0), ...allIps.slice(1));
|
|
604
604
|
transaction.sdiffstore(ipDenyList, ipDenyList, allDenyLists);
|
|
605
605
|
transaction.sunionstore(allDenyLists, allDenyLists, ipDenyList);
|
|
606
606
|
transaction.set(statusKey, "valid", { px: ttl ?? getIpListTTL() });
|
|
@@ -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
|
|