lib/auth/rate-limit
Esta página aún no está disponible en tu idioma.
Classes
Section titled “Classes”ExpiringTokenBucket<_Key>
Section titled “ExpiringTokenBucket<_Key>”Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:161
Represents a token bucket with tokens that expire after a specified duration. Used to control access to resources with tokens that reset after expiration.
Type Parameters
Section titled “Type Parameters”_Key
The type of key used to identify individual token buckets.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExpiringTokenBucket<_Key>(max: number, expiresInSeconds: number): ExpiringTokenBucket<_Key>
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:186
Initializes a new instance of the ExpiringTokenBucket class.
Parameters
Section titled “Parameters”number
The maximum number of tokens the bucket can hold.
expiresInSeconds
Section titled “expiresInSeconds”number
The duration in seconds after which tokens expire.
Returns
Section titled “Returns”ExpiringTokenBucket
<_Key
>
Properties
Section titled “Properties”expiresInSeconds
Section titled “expiresInSeconds”expiresInSeconds: number;
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:172
The duration (in seconds) after which tokens in the bucket expire.
max: number;
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:166
The maximum number of tokens the bucket can hold.
Methods
Section titled “Methods”check()
Section titled “check()”check(key: _Key, cost: number): boolean
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:198
Checks if there are enough tokens available in the bucket for the specified key and cost.
Parameters
Section titled “Parameters”_Key
The key associated with the token bucket.
number
The number of tokens required.
Returns
Section titled “Returns”boolean
- Returns
true
if there are enough tokens or if the tokens have expired; otherwise,false
.
consume()
Section titled “consume()”consume(key: _Key, cost: number): boolean
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:217
Consumes tokens from the bucket for the specified key and cost.
Parameters
Section titled “Parameters”_Key
The key associated with the token bucket.
number
The number of tokens to consume.
Returns
Section titled “Returns”boolean
- Returns
true
if tokens were successfully consumed; otherwise,false
.
reset()
Section titled “reset()”reset(key: _Key): void
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:244
Resets the token bucket for a specified key, removing all tokens.
Parameters
Section titled “Parameters”_Key
The key associated with the token bucket to reset.
Returns
Section titled “Returns”void
RefillingTokenBucket<_Key>
Section titled “RefillingTokenBucket<_Key>”Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:10
Represents a token bucket that refills tokens at a specified interval. Used to control access to resources by limiting the number of tokens that can be consumed over time.
Type Parameters
Section titled “Type Parameters”_Key
The type of key used to identify individual token buckets.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RefillingTokenBucket<_Key>(max: number, refillIntervalSeconds: number): RefillingTokenBucket<_Key>
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:29
Initializes a new instance of the RefillingTokenBucket class.
Parameters
Section titled “Parameters”number
The maximum number of tokens the bucket can hold.
refillIntervalSeconds
Section titled “refillIntervalSeconds”number
The refill interval in seconds.
Returns
Section titled “Returns”RefillingTokenBucket
<_Key
>
Properties
Section titled “Properties”max: number;
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:15
The maximum number of tokens that the bucket can hold.
refillIntervalSeconds
Section titled “refillIntervalSeconds”refillIntervalSeconds: number;
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:21
The interval in seconds at which tokens are refilled.
Methods
Section titled “Methods”check()
Section titled “check()”check(key: _Key, cost: number): boolean
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:47
Checks if there are enough tokens available in the bucket for the specified key and cost.
Parameters
Section titled “Parameters”_Key
The key associated with the token bucket.
number
The number of tokens required.
Returns
Section titled “Returns”boolean
- Returns
true
if there are enough tokens; otherwise,false
.
consume()
Section titled “consume()”consume(key: _Key, cost: number): boolean
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:67
Consumes tokens from the bucket for the specified key and cost.
Parameters
Section titled “Parameters”_Key
The key associated with the token bucket.
number
The number of tokens to consume.
Returns
Section titled “Returns”boolean
- Returns
true
if tokens were successfully consumed; otherwise,false
.
Throttler<_Key>
Section titled “Throttler<_Key>”Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:96
Represents a throttler that limits the frequency of actions performed with a specified key. Uses incremental timeouts to delay repeated actions.
Type Parameters
Section titled “Type Parameters”_Key
The type of key used to identify throttling counters.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Throttler<_Key>(timeoutSeconds: number[]): Throttler<_Key>
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:114
Initializes a new instance of the Throttler class.
Parameters
Section titled “Parameters”timeoutSeconds
Section titled “timeoutSeconds”number
[]
Array of timeout durations in seconds for each consecutive attempt.
Returns
Section titled “Returns”Throttler
<_Key
>
Properties
Section titled “Properties”timeoutSeconds
Section titled “timeoutSeconds”timeoutSeconds: number[];
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:101
Array of timeout durations (in seconds) for each consecutive attempt.
Methods
Section titled “Methods”consume()
Section titled “consume()”consume(key: _Key): boolean
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:124
Attempts to consume an action for the specified key.
Parameters
Section titled “Parameters”_Key
The key associated with the throttling counter.
Returns
Section titled “Returns”boolean
- Returns
true
if the action is allowed; otherwise,false
.
reset()
Section titled “reset()”reset(key: _Key): void
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:150
Resets the throttling counter for a specified key.
Parameters
Section titled “Parameters”_Key
The key associated with the throttling counter to reset.
Returns
Section titled “Returns”void