lib/auth/rate-limit
ExpiringTokenBucket<_Key>
'Read the “', ExpiringTokenBucket<_Key>, '” section'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
'Read the “', Type Parameters, '” section'• _Key
The type of key used to identify individual token buckets.
Constructors
'Read the “', Constructors, '” section'new ExpiringTokenBucket()
'Read the “', new ExpiringTokenBucket(), '” section'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
'Read the “', Parameters, '” section'number
The maximum number of tokens the bucket can hold.
expiresInSeconds
'Read the “', expiresInSeconds, '” section'number
The duration in seconds after which tokens expire.
ExpiringTokenBucket
<_Key
>
Properties
'Read the “', Properties, '” section'expiresInSeconds
'Read the “', expiresInSeconds, '” section'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.
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
'Read the “', Parameters, '” section'_Key
The key associated with the token bucket.
number
The number of tokens required.
boolean
- Returns
true
if there are enough tokens or if the tokens have expired; otherwise,false
.
consume()
'Read the “', consume(), '” section'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
'Read the “', Parameters, '” section'_Key
The key associated with the token bucket.
number
The number of tokens to consume.
boolean
- Returns
true
if tokens were successfully consumed; otherwise,false
.
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
'Read the “', Parameters, '” section'_Key
The key associated with the token bucket to reset.
void
RefillingTokenBucket<_Key>
'Read the “', RefillingTokenBucket<_Key>, '” section'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
'Read the “', Type Parameters, '” section'• _Key
The type of key used to identify individual token buckets.
Constructors
'Read the “', Constructors, '” section'new RefillingTokenBucket()
'Read the “', new RefillingTokenBucket(), '” section'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
'Read the “', Parameters, '” section'number
The maximum number of tokens the bucket can hold.
refillIntervalSeconds
'Read the “', refillIntervalSeconds, '” section'number
The refill interval in seconds.
RefillingTokenBucket
<_Key
>
Properties
'Read the “', Properties, '” section'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
'Read the “', refillIntervalSeconds, '” section'refillIntervalSeconds: number;
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:21
The interval in seconds at which tokens are refilled.
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
'Read the “', Parameters, '” section'_Key
The key associated with the token bucket.
number
The number of tokens required.
boolean
- Returns
true
if there are enough tokens; otherwise,false
.
consume()
'Read the “', consume(), '” section'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
'Read the “', Parameters, '” section'_Key
The key associated with the token bucket.
number
The number of tokens to consume.
boolean
- Returns
true
if tokens were successfully consumed; otherwise,false
.
Throttler<_Key>
'Read the “', Throttler<_Key>, '” section'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
'Read the “', Type Parameters, '” section'• _Key
The type of key used to identify throttling counters.
Constructors
'Read the “', Constructors, '” section'new Throttler()
'Read the “', new Throttler(), '” section'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
'Read the “', Parameters, '” section'timeoutSeconds
'Read the “', timeoutSeconds, '” section'number
[]
Array of timeout durations in seconds for each consecutive attempt.
Throttler
<_Key
>
Properties
'Read the “', Properties, '” section'timeoutSeconds
'Read the “', timeoutSeconds, '” section'timeoutSeconds: number[];
Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:101
Array of timeout durations (in seconds) for each consecutive attempt.
consume()
'Read the “', consume(), '” section'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
'Read the “', Parameters, '” section'_Key
The key associated with the throttling counter.
boolean
- Returns
true
if the action is allowed; otherwise,false
.
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
'Read the “', Parameters, '” section'_Key
The key associated with the throttling counter to reset.
void