Skip to main content
Version: 1.x

ViolationTracker

ViolationTracker

Tracks repeated violations and computes escalating cooldowns.

Signature
class ViolationTracker {
constructor(storage: RateLimitStorage)
getState(key: string) => Promise<ViolationState | null>;
checkCooldown(key: string) => Promise<ViolationState | null>;
recordViolation(key: string, baseRetryAfterMs: number, options?: ViolationOptions) => Promise<ViolationState>;
reset(key: string) => Promise<void>;
}

constructor

method
(storage: RateLimitStorage) => ViolationTracker

Create a violation tracker bound to a storage backend.

getState

method
(key: string) => Promise<ViolationState | null>

Read stored violation state for a key, if present.

checkCooldown

method
(key: string) => Promise<ViolationState | null>

Check if a cooldown is currently active for this key.

recordViolation

method
(key: string, baseRetryAfterMs: number, options?: ViolationOptions) => Promise<ViolationState>

Record a violation and return the updated state for callers.

reset

method
(key: string) => Promise<void>

Clear stored violation state for a key.