@upstash/ratelimit 2.0.5-canary → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Aggregate } from '@upstash/core-analytics';
2
- import { Redis as Redis$1 } from '@upstash/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,10 +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 = Redis$1;
101
+ type Redis$1 = Redis$2;
105
102
 
106
103
  type Geo = {
107
104
  country?: string;
@@ -121,7 +118,7 @@ type Event = Geo & {
121
118
  success: EventSuccess;
122
119
  };
123
120
  type AnalyticsConfig = {
124
- redis: Redis;
121
+ redis: Redis$1;
125
122
  prefix?: string;
126
123
  };
127
124
  /**
@@ -248,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
248
245
  protected readonly ctx: TContext;
249
246
  protected readonly prefix: string;
250
247
  protected readonly timeout: number;
251
- protected readonly primaryRedis: Redis;
248
+ protected readonly primaryRedis: Redis$1;
252
249
  protected readonly analytics?: Analytics;
253
250
  protected readonly enableProtection: boolean;
254
251
  protected readonly denyListThreshold: number;
@@ -373,7 +370,7 @@ type MultiRegionRatelimitConfig = {
373
370
  * Instances of `@upstash/redis`
374
371
  * @see https://github.com/upstash/upstash-redis#quick-start
375
372
  */
376
- redis: Redis[];
373
+ redis: Redis$1[];
377
374
  /**
378
375
  * The ratelimiter function to use.
379
376
  *
@@ -500,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
500
497
  window: Duration): Algorithm<MultiRegionContext>;
501
498
  }
502
499
 
500
+ type Redis = Pick<Redis$1, "get" | "set">;
503
501
  type RegionRatelimitConfig = {
504
502
  /**
505
503
  * Instance of `@upstash/redis`
@@ -732,7 +730,7 @@ declare class ThresholdError extends Error {
732
730
  * passed, ttl is infferred from current time.
733
731
  * @returns list of ips which are not in the deny list
734
732
  */
735
- 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[]>;
736
734
  /**
737
735
  * Disables the ip deny list by removing the ip deny list from the all
738
736
  * set and removing the ip deny list. Also sets the status key to disabled
@@ -742,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
742
740
  * @param prefix ratelimit prefix
743
741
  * @returns
744
742
  */
745
- declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
743
+ declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
746
744
 
747
745
  type ipDenyList_ThresholdError = ThresholdError;
748
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$1 } from '@upstash/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,10 +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 = Redis$1;
101
+ type Redis$1 = Redis$2;
105
102
 
106
103
  type Geo = {
107
104
  country?: string;
@@ -121,7 +118,7 @@ type Event = Geo & {
121
118
  success: EventSuccess;
122
119
  };
123
120
  type AnalyticsConfig = {
124
- redis: Redis;
121
+ redis: Redis$1;
125
122
  prefix?: string;
126
123
  };
127
124
  /**
@@ -248,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
248
245
  protected readonly ctx: TContext;
249
246
  protected readonly prefix: string;
250
247
  protected readonly timeout: number;
251
- protected readonly primaryRedis: Redis;
248
+ protected readonly primaryRedis: Redis$1;
252
249
  protected readonly analytics?: Analytics;
253
250
  protected readonly enableProtection: boolean;
254
251
  protected readonly denyListThreshold: number;
@@ -373,7 +370,7 @@ type MultiRegionRatelimitConfig = {
373
370
  * Instances of `@upstash/redis`
374
371
  * @see https://github.com/upstash/upstash-redis#quick-start
375
372
  */
376
- redis: Redis[];
373
+ redis: Redis$1[];
377
374
  /**
378
375
  * The ratelimiter function to use.
379
376
  *
@@ -500,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
500
497
  window: Duration): Algorithm<MultiRegionContext>;
501
498
  }
502
499
 
500
+ type Redis = Pick<Redis$1, "get" | "set">;
503
501
  type RegionRatelimitConfig = {
504
502
  /**
505
503
  * Instance of `@upstash/redis`
@@ -732,7 +730,7 @@ declare class ThresholdError extends Error {
732
730
  * passed, ttl is infferred from current time.
733
731
  * @returns list of ips which are not in the deny list
734
732
  */
735
- 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[]>;
736
734
  /**
737
735
  * Disables the ip deny list by removing the ip deny list from the all
738
736
  * set and removing the ip deny list. Also sets the status key to disabled
@@ -742,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
742
740
  * @param prefix ratelimit prefix
743
741
  * @returns
744
742
  */
745
- declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
743
+ declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
746
744
 
747
745
  type ipDenyList_ThresholdError = ThresholdError;
748
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((item) => Boolean(item));
928
+ return members.filter(Boolean);
929
929
  };
930
930
  };
931
931