@upstash/ratelimit 2.2.0 → 2.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/README.md +2 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -1
- package/dist/index.mjs.map +1 -1
- package/docs/algorithms.mdx +169 -0
- package/docs/costs.mdx +112 -0
- package/docs/features.mdx +262 -0
- package/docs/gettingstarted.mdx +220 -0
- package/docs/methods.mdx +206 -0
- package/docs/overview.mdx +159 -0
- package/docs/traffic-protection.mdx +110 -0
- package/package.json +1 -1
- package/src/analytics.ts +110 -0
- package/src/cache.ts +55 -0
- package/src/constants.ts +14 -0
- package/src/deny-list/deny-list.ts +124 -0
- package/src/deny-list/index.ts +1 -0
- package/src/deny-list/ip-deny-list.ts +131 -0
- package/src/deny-list/scripts.ts +26 -0
- package/src/deny-list/time.ts +20 -0
- package/src/duration.ts +37 -0
- package/src/hash.ts +29 -0
- package/src/index.ts +18 -0
- package/src/lua-scripts/hash.ts +95 -0
- package/src/lua-scripts/multi.ts +86 -0
- package/src/lua-scripts/reset.ts +23 -0
- package/src/lua-scripts/single.ts +237 -0
- package/src/multi.ts +610 -0
- package/src/ratelimit.ts +506 -0
- package/src/single.ts +676 -0
- package/src/telemetry.ts +43 -0
- package/src/types.ts +132 -0
- package/src/version.ts +1 -0
package/README.md
CHANGED
|
@@ -78,6 +78,8 @@ For more information on getting started, you can refer to [our documentation](ht
|
|
|
78
78
|
|
|
79
79
|
See [the documentation](https://upstash.com/docs/redis/sdks/ratelimit-ts/overview) for more information details about this package.
|
|
80
80
|
|
|
81
|
+
The npm package includes TypeScript source in `node_modules/@upstash/ratelimit/src/` and documentation in `node_modules/@upstash/ratelimit/docs/`. Start with `src/index.ts` to explore the source.
|
|
82
|
+
|
|
81
83
|
## Telemetry
|
|
82
84
|
|
|
83
85
|
The SDK reports its name and version to Upstash as a header on the requests made
|
package/dist/index.d.mts
CHANGED
|
@@ -133,6 +133,8 @@ type AnalyticsConfig = {
|
|
|
133
133
|
};
|
|
134
134
|
/**
|
|
135
135
|
* The Analytics package is experimental and can change at any time.
|
|
136
|
+
*
|
|
137
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
136
138
|
*/
|
|
137
139
|
declare class Analytics {
|
|
138
140
|
private readonly analytics;
|
|
@@ -306,6 +308,8 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
306
308
|
* }
|
|
307
309
|
* return "Yes"
|
|
308
310
|
* ```
|
|
311
|
+
*
|
|
312
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
309
313
|
*/
|
|
310
314
|
limit: (identifier: string, req?: LimitOptions) => Promise<RatelimitResponse>;
|
|
311
315
|
/**
|
|
@@ -329,8 +333,13 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
329
333
|
* }
|
|
330
334
|
* return "Yes"
|
|
331
335
|
* ```
|
|
336
|
+
*
|
|
337
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
332
338
|
*/
|
|
333
339
|
blockUntilReady: (identifier: string, timeout: number) => Promise<RatelimitResponse>;
|
|
340
|
+
/**
|
|
341
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
342
|
+
*/
|
|
334
343
|
resetUsedTokens: (identifier: string) => Promise<void>;
|
|
335
344
|
/**
|
|
336
345
|
* Returns the remaining token count together with a reset timestamps
|
|
@@ -339,6 +348,8 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
339
348
|
* @returns object with `remaining`, `reset`, and `limit` fields. `remaining` denotes
|
|
340
349
|
* the remaining tokens, `limit` is the effective limit (considering dynamic
|
|
341
350
|
* limits if enabled), and `reset` denotes the timestamp when the tokens reset.
|
|
351
|
+
*
|
|
352
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
342
353
|
*/
|
|
343
354
|
getRemaining: (identifier: string) => Promise<{
|
|
344
355
|
remaining: number;
|
|
@@ -407,6 +418,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
407
418
|
* ```
|
|
408
419
|
*
|
|
409
420
|
* @param options.limit - The new rate limit to apply globally, or false to disable
|
|
421
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
410
422
|
*/
|
|
411
423
|
setDynamicLimit: (options: {
|
|
412
424
|
limit: number | false;
|
|
@@ -421,6 +433,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
421
433
|
* ```
|
|
422
434
|
*
|
|
423
435
|
* @returns Object containing the current global dynamic limit, or null if not set
|
|
436
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
424
437
|
*/
|
|
425
438
|
getDynamicLimit: () => Promise<{
|
|
426
439
|
dynamicLimit: number | null;
|
|
@@ -521,10 +534,14 @@ type MultiRegionRatelimitConfig = {
|
|
|
521
534
|
* })
|
|
522
535
|
*
|
|
523
536
|
* ```
|
|
537
|
+
*
|
|
538
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
524
539
|
*/
|
|
525
540
|
declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
526
541
|
/**
|
|
527
542
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithn of your choice.
|
|
543
|
+
*
|
|
544
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
528
545
|
*/
|
|
529
546
|
constructor(config: MultiRegionRatelimitConfig);
|
|
530
547
|
/**
|
|
@@ -544,6 +561,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
544
561
|
*
|
|
545
562
|
* @param tokens - How many requests a user can make in each time window.
|
|
546
563
|
* @param window - A fixed timeframe
|
|
564
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
547
565
|
*/
|
|
548
566
|
static fixedWindow(
|
|
549
567
|
/**
|
|
@@ -569,6 +587,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
569
587
|
*
|
|
570
588
|
* @param tokens - How many requests a user can make in each time window.
|
|
571
589
|
* @param window - The duration in which the user can max X requests.
|
|
590
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
572
591
|
*/
|
|
573
592
|
static slidingWindow(
|
|
574
593
|
/**
|
|
@@ -689,10 +708,14 @@ type RegionRatelimitConfig = {
|
|
|
689
708
|
* })
|
|
690
709
|
*
|
|
691
710
|
* ```
|
|
711
|
+
*
|
|
712
|
+
* @see node_modules/@upstash/ratelimit/docs/gettingstarted.mdx
|
|
692
713
|
*/
|
|
693
714
|
declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
694
715
|
/**
|
|
695
716
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithm of your choice.
|
|
717
|
+
*
|
|
718
|
+
* @see node_modules/@upstash/ratelimit/docs/gettingstarted.mdx
|
|
696
719
|
*/
|
|
697
720
|
constructor(config: RegionRatelimitConfig);
|
|
698
721
|
/**
|
|
@@ -712,6 +735,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
712
735
|
*
|
|
713
736
|
* @param tokens - How many requests a user can make in each time window.
|
|
714
737
|
* @param window - A fixed timeframe
|
|
738
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
715
739
|
*/
|
|
716
740
|
static fixedWindow(
|
|
717
741
|
/**
|
|
@@ -737,6 +761,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
737
761
|
*
|
|
738
762
|
* @param tokens - How many requests a user can make in each time window.
|
|
739
763
|
* @param window - The duration in which the user can max X requests.
|
|
764
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
740
765
|
*/
|
|
741
766
|
static slidingWindow(
|
|
742
767
|
/**
|
|
@@ -759,6 +784,8 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
759
784
|
* rate.
|
|
760
785
|
* - Allows to set a higher initial burst limit by setting `maxTokens` higher
|
|
761
786
|
* than `refillRate`
|
|
787
|
+
*
|
|
788
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
762
789
|
*/
|
|
763
790
|
static tokenBucket(
|
|
764
791
|
/**
|
|
@@ -800,6 +827,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
800
827
|
*
|
|
801
828
|
* @param tokens - How many requests a user can make in each time window.
|
|
802
829
|
* @param window - A fixed timeframe
|
|
830
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
803
831
|
*/
|
|
804
832
|
static cachedFixedWindow(
|
|
805
833
|
/**
|
|
@@ -834,6 +862,7 @@ declare class ThresholdError extends Error {
|
|
|
834
862
|
* @param ttl time to live in milliseconds for the status flag. Optional. If not
|
|
835
863
|
* passed, ttl is infferred from current time.
|
|
836
864
|
* @returns list of ips which are not in the deny list
|
|
865
|
+
* @see node_modules/@upstash/ratelimit/docs/traffic-protection.mdx
|
|
837
866
|
*/
|
|
838
867
|
declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
839
868
|
/**
|
|
@@ -844,6 +873,7 @@ declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: numb
|
|
|
844
873
|
* @param redis redis instance
|
|
845
874
|
* @param prefix ratelimit prefix
|
|
846
875
|
* @returns
|
|
876
|
+
* @see node_modules/@upstash/ratelimit/docs/traffic-protection.mdx
|
|
847
877
|
*/
|
|
848
878
|
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
849
879
|
|
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,8 @@ type AnalyticsConfig = {
|
|
|
133
133
|
};
|
|
134
134
|
/**
|
|
135
135
|
* The Analytics package is experimental and can change at any time.
|
|
136
|
+
*
|
|
137
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
136
138
|
*/
|
|
137
139
|
declare class Analytics {
|
|
138
140
|
private readonly analytics;
|
|
@@ -306,6 +308,8 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
306
308
|
* }
|
|
307
309
|
* return "Yes"
|
|
308
310
|
* ```
|
|
311
|
+
*
|
|
312
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
309
313
|
*/
|
|
310
314
|
limit: (identifier: string, req?: LimitOptions) => Promise<RatelimitResponse>;
|
|
311
315
|
/**
|
|
@@ -329,8 +333,13 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
329
333
|
* }
|
|
330
334
|
* return "Yes"
|
|
331
335
|
* ```
|
|
336
|
+
*
|
|
337
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
332
338
|
*/
|
|
333
339
|
blockUntilReady: (identifier: string, timeout: number) => Promise<RatelimitResponse>;
|
|
340
|
+
/**
|
|
341
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
342
|
+
*/
|
|
334
343
|
resetUsedTokens: (identifier: string) => Promise<void>;
|
|
335
344
|
/**
|
|
336
345
|
* Returns the remaining token count together with a reset timestamps
|
|
@@ -339,6 +348,8 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
339
348
|
* @returns object with `remaining`, `reset`, and `limit` fields. `remaining` denotes
|
|
340
349
|
* the remaining tokens, `limit` is the effective limit (considering dynamic
|
|
341
350
|
* limits if enabled), and `reset` denotes the timestamp when the tokens reset.
|
|
351
|
+
*
|
|
352
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
342
353
|
*/
|
|
343
354
|
getRemaining: (identifier: string) => Promise<{
|
|
344
355
|
remaining: number;
|
|
@@ -407,6 +418,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
407
418
|
* ```
|
|
408
419
|
*
|
|
409
420
|
* @param options.limit - The new rate limit to apply globally, or false to disable
|
|
421
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
410
422
|
*/
|
|
411
423
|
setDynamicLimit: (options: {
|
|
412
424
|
limit: number | false;
|
|
@@ -421,6 +433,7 @@ declare abstract class Ratelimit<TContext extends Context> {
|
|
|
421
433
|
* ```
|
|
422
434
|
*
|
|
423
435
|
* @returns Object containing the current global dynamic limit, or null if not set
|
|
436
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
424
437
|
*/
|
|
425
438
|
getDynamicLimit: () => Promise<{
|
|
426
439
|
dynamicLimit: number | null;
|
|
@@ -521,10 +534,14 @@ type MultiRegionRatelimitConfig = {
|
|
|
521
534
|
* })
|
|
522
535
|
*
|
|
523
536
|
* ```
|
|
537
|
+
*
|
|
538
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
524
539
|
*/
|
|
525
540
|
declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
526
541
|
/**
|
|
527
542
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithn of your choice.
|
|
543
|
+
*
|
|
544
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
528
545
|
*/
|
|
529
546
|
constructor(config: MultiRegionRatelimitConfig);
|
|
530
547
|
/**
|
|
@@ -544,6 +561,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
544
561
|
*
|
|
545
562
|
* @param tokens - How many requests a user can make in each time window.
|
|
546
563
|
* @param window - A fixed timeframe
|
|
564
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
547
565
|
*/
|
|
548
566
|
static fixedWindow(
|
|
549
567
|
/**
|
|
@@ -569,6 +587,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
|
|
|
569
587
|
*
|
|
570
588
|
* @param tokens - How many requests a user can make in each time window.
|
|
571
589
|
* @param window - The duration in which the user can max X requests.
|
|
590
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
572
591
|
*/
|
|
573
592
|
static slidingWindow(
|
|
574
593
|
/**
|
|
@@ -689,10 +708,14 @@ type RegionRatelimitConfig = {
|
|
|
689
708
|
* })
|
|
690
709
|
*
|
|
691
710
|
* ```
|
|
711
|
+
*
|
|
712
|
+
* @see node_modules/@upstash/ratelimit/docs/gettingstarted.mdx
|
|
692
713
|
*/
|
|
693
714
|
declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
694
715
|
/**
|
|
695
716
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithm of your choice.
|
|
717
|
+
*
|
|
718
|
+
* @see node_modules/@upstash/ratelimit/docs/gettingstarted.mdx
|
|
696
719
|
*/
|
|
697
720
|
constructor(config: RegionRatelimitConfig);
|
|
698
721
|
/**
|
|
@@ -712,6 +735,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
712
735
|
*
|
|
713
736
|
* @param tokens - How many requests a user can make in each time window.
|
|
714
737
|
* @param window - A fixed timeframe
|
|
738
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
715
739
|
*/
|
|
716
740
|
static fixedWindow(
|
|
717
741
|
/**
|
|
@@ -737,6 +761,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
737
761
|
*
|
|
738
762
|
* @param tokens - How many requests a user can make in each time window.
|
|
739
763
|
* @param window - The duration in which the user can max X requests.
|
|
764
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
740
765
|
*/
|
|
741
766
|
static slidingWindow(
|
|
742
767
|
/**
|
|
@@ -759,6 +784,8 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
759
784
|
* rate.
|
|
760
785
|
* - Allows to set a higher initial burst limit by setting `maxTokens` higher
|
|
761
786
|
* than `refillRate`
|
|
787
|
+
*
|
|
788
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
762
789
|
*/
|
|
763
790
|
static tokenBucket(
|
|
764
791
|
/**
|
|
@@ -800,6 +827,7 @@ declare class RegionRatelimit extends Ratelimit<RegionContext> {
|
|
|
800
827
|
*
|
|
801
828
|
* @param tokens - How many requests a user can make in each time window.
|
|
802
829
|
* @param window - A fixed timeframe
|
|
830
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
803
831
|
*/
|
|
804
832
|
static cachedFixedWindow(
|
|
805
833
|
/**
|
|
@@ -834,6 +862,7 @@ declare class ThresholdError extends Error {
|
|
|
834
862
|
* @param ttl time to live in milliseconds for the status flag. Optional. If not
|
|
835
863
|
* passed, ttl is infferred from current time.
|
|
836
864
|
* @returns list of ips which are not in the deny list
|
|
865
|
+
* @see node_modules/@upstash/ratelimit/docs/traffic-protection.mdx
|
|
837
866
|
*/
|
|
838
867
|
declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
|
|
839
868
|
/**
|
|
@@ -844,6 +873,7 @@ declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: numb
|
|
|
844
873
|
* @param redis redis instance
|
|
845
874
|
* @param prefix ratelimit prefix
|
|
846
875
|
* @returns
|
|
876
|
+
* @see node_modules/@upstash/ratelimit/docs/traffic-protection.mdx
|
|
847
877
|
*/
|
|
848
878
|
declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
|
|
849
879
|
|
package/dist/index.js
CHANGED
|
@@ -819,6 +819,8 @@ var Ratelimit = class {
|
|
|
819
819
|
* }
|
|
820
820
|
* return "Yes"
|
|
821
821
|
* ```
|
|
822
|
+
*
|
|
823
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
822
824
|
*/
|
|
823
825
|
limit = async (identifier, req) => {
|
|
824
826
|
let timeoutId = null;
|
|
@@ -856,6 +858,8 @@ var Ratelimit = class {
|
|
|
856
858
|
* }
|
|
857
859
|
* return "Yes"
|
|
858
860
|
* ```
|
|
861
|
+
*
|
|
862
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
859
863
|
*/
|
|
860
864
|
blockUntilReady = async (identifier, timeout) => {
|
|
861
865
|
if (timeout <= 0) {
|
|
@@ -879,6 +883,9 @@ var Ratelimit = class {
|
|
|
879
883
|
}
|
|
880
884
|
return res;
|
|
881
885
|
};
|
|
886
|
+
/**
|
|
887
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
888
|
+
*/
|
|
882
889
|
resetUsedTokens = async (identifier) => {
|
|
883
890
|
const pattern = [this.prefix, identifier].join(":");
|
|
884
891
|
await this.limiter().resetTokens(this.ctx, pattern);
|
|
@@ -890,6 +897,8 @@ var Ratelimit = class {
|
|
|
890
897
|
* @returns object with `remaining`, `reset`, and `limit` fields. `remaining` denotes
|
|
891
898
|
* the remaining tokens, `limit` is the effective limit (considering dynamic
|
|
892
899
|
* limits if enabled), and `reset` denotes the timestamp when the tokens reset.
|
|
900
|
+
*
|
|
901
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
893
902
|
*/
|
|
894
903
|
getRemaining = async (identifier) => {
|
|
895
904
|
const pattern = [this.prefix, identifier].join(":");
|
|
@@ -1027,6 +1036,7 @@ var Ratelimit = class {
|
|
|
1027
1036
|
* ```
|
|
1028
1037
|
*
|
|
1029
1038
|
* @param options.limit - The new rate limit to apply globally, or false to disable
|
|
1039
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
1030
1040
|
*/
|
|
1031
1041
|
setDynamicLimit = async (options) => {
|
|
1032
1042
|
if (!this.dynamicLimits) {
|
|
@@ -1047,6 +1057,7 @@ var Ratelimit = class {
|
|
|
1047
1057
|
* ```
|
|
1048
1058
|
*
|
|
1049
1059
|
* @returns Object containing the current global dynamic limit, or null if not set
|
|
1060
|
+
* @see node_modules/@upstash/ratelimit/docs/methods.mdx
|
|
1050
1061
|
*/
|
|
1051
1062
|
getDynamicLimit = async () => {
|
|
1052
1063
|
if (!this.dynamicLimits) {
|
|
@@ -1061,7 +1072,7 @@ var Ratelimit = class {
|
|
|
1061
1072
|
};
|
|
1062
1073
|
|
|
1063
1074
|
// src/version.ts
|
|
1064
|
-
var VERSION = "2.2.
|
|
1075
|
+
var VERSION = "2.2.1";
|
|
1065
1076
|
|
|
1066
1077
|
// src/telemetry.ts
|
|
1067
1078
|
var taggedClients = /* @__PURE__ */ new WeakSet();
|
|
@@ -1094,6 +1105,8 @@ function randomId() {
|
|
|
1094
1105
|
var MultiRegionRatelimit = class extends Ratelimit {
|
|
1095
1106
|
/**
|
|
1096
1107
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithn of your choice.
|
|
1108
|
+
*
|
|
1109
|
+
* @see node_modules/@upstash/ratelimit/docs/features.mdx
|
|
1097
1110
|
*/
|
|
1098
1111
|
constructor(config) {
|
|
1099
1112
|
super({
|
|
@@ -1136,6 +1149,7 @@ var MultiRegionRatelimit = class extends Ratelimit {
|
|
|
1136
1149
|
*
|
|
1137
1150
|
* @param tokens - How many requests a user can make in each time window.
|
|
1138
1151
|
* @param window - A fixed timeframe
|
|
1152
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1139
1153
|
*/
|
|
1140
1154
|
static fixedWindow(tokens, window) {
|
|
1141
1155
|
const windowDuration = ms(window);
|
|
@@ -1299,6 +1313,7 @@ var MultiRegionRatelimit = class extends Ratelimit {
|
|
|
1299
1313
|
*
|
|
1300
1314
|
* @param tokens - How many requests a user can make in each time window.
|
|
1301
1315
|
* @param window - The duration in which the user can max X requests.
|
|
1316
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1302
1317
|
*/
|
|
1303
1318
|
static slidingWindow(tokens, window) {
|
|
1304
1319
|
const windowSize = ms(window);
|
|
@@ -1467,6 +1482,8 @@ var MultiRegionRatelimit = class extends Ratelimit {
|
|
|
1467
1482
|
var RegionRatelimit = class extends Ratelimit {
|
|
1468
1483
|
/**
|
|
1469
1484
|
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithm of your choice.
|
|
1485
|
+
*
|
|
1486
|
+
* @see node_modules/@upstash/ratelimit/docs/gettingstarted.mdx
|
|
1470
1487
|
*/
|
|
1471
1488
|
constructor(config) {
|
|
1472
1489
|
super({
|
|
@@ -1502,6 +1519,7 @@ var RegionRatelimit = class extends Ratelimit {
|
|
|
1502
1519
|
*
|
|
1503
1520
|
* @param tokens - How many requests a user can make in each time window.
|
|
1504
1521
|
* @param window - A fixed timeframe
|
|
1522
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1505
1523
|
*/
|
|
1506
1524
|
static fixedWindow(tokens, window) {
|
|
1507
1525
|
const windowDuration = ms(window);
|
|
@@ -1593,6 +1611,7 @@ var RegionRatelimit = class extends Ratelimit {
|
|
|
1593
1611
|
*
|
|
1594
1612
|
* @param tokens - How many requests a user can make in each time window.
|
|
1595
1613
|
* @param window - The duration in which the user can max X requests.
|
|
1614
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1596
1615
|
*/
|
|
1597
1616
|
static slidingWindow(tokens, window) {
|
|
1598
1617
|
const windowSize = ms(window);
|
|
@@ -1686,6 +1705,8 @@ var RegionRatelimit = class extends Ratelimit {
|
|
|
1686
1705
|
* rate.
|
|
1687
1706
|
* - Allows to set a higher initial burst limit by setting `maxTokens` higher
|
|
1688
1707
|
* than `refillRate`
|
|
1708
|
+
*
|
|
1709
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1689
1710
|
*/
|
|
1690
1711
|
static tokenBucket(refillRate, interval, maxTokens) {
|
|
1691
1712
|
const intervalDuration = ms(interval);
|
|
@@ -1782,6 +1803,7 @@ var RegionRatelimit = class extends Ratelimit {
|
|
|
1782
1803
|
*
|
|
1783
1804
|
* @param tokens - How many requests a user can make in each time window.
|
|
1784
1805
|
* @param window - A fixed timeframe
|
|
1806
|
+
* @see node_modules/@upstash/ratelimit/docs/algorithms.mdx
|
|
1785
1807
|
*/
|
|
1786
1808
|
static cachedFixedWindow(tokens, window) {
|
|
1787
1809
|
const windowDuration = ms(window);
|