Skip to content

lib/auth/rate-limit

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.

_Key

The type of key used to identify individual token buckets.

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.

number

The maximum number of tokens the bucket can hold.

number

The duration in seconds after which tokens expire.

ExpiringTokenBucket<_Key>

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.

_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(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.

_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.

_Key

The key associated with the token bucket to reset.

void


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.

_Key

The type of key used to identify individual token buckets.

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.

number

The maximum number of tokens the bucket can hold.

number

The refill interval in seconds.

RefillingTokenBucket<_Key>

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: 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.

_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(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.

_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.

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.

_Key

The type of key used to identify throttling counters.

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.

number[]

Array of timeout durations in seconds for each consecutive attempt.

Throttler<_Key>

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(key: _Key): boolean

Defined in: studiocms/packages/studiocms/src/lib/auth/rate-limit.ts:124

Attempts to consume an action for the specified key.

_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.

_Key

The key associated with the throttling counter to reset.

void