RateLimiterService

Client-side rate limiter with per-key policies. Supports token-bucket (smooth limiting with burst capacity) and sliding-window (strict max operations per time window). Signal-based state for reactive UIs.

TypeScriptexample.ts
import { RateLimiterService } from '@angular-helpers/security'

# Methods

MethodSignatureReturnsDescription
configureconfigure(key: string, policy: RateLimitPolicy): Promise<void>Promise<void>Registers or updates the policy for `key`. Re-configuring an existing key resets its state.
consumeconsume(key: string, tokens: any): Promise<void>Promise<void>Attempts to consume `tokens` units from the bucket. Resolves on success; rejects with when the bucket is exhausted. For undeclared keys, this method resolves immediately without consuming anything (fail-open behaviour — intentional to avoid silent failures when a policy is missing).
canExecutecanExecute(key: string): Signal<boolean>Signal<boolean>Reactive signal indicating whether a single unit can be consumed from `key` right now. For undeclared keys, returns `signal(true)`.
remainingremaining(key: string): Signal<number>Signal<number>Reactive signal holding the remaining capacity for `key`. For undeclared keys, returns `signal(Infinity)`.
resetreset(key: string): Promise<void>Promise<void>Resets the counter for `key` to its maximum. No-op for undeclared keys.
LCP N/A
CLS N/A
INP N/A