@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
50 lines • 2.35 kB
TypeScript
/**
* Default ceiling on the number of distinct IPs tracked at once. The limiter is
* the only state the public client-error endpoint keeps, so it MUST stay bounded
* — an attacker rotating source IPs (or sitting behind a large CGNAT/proxy pool)
* could otherwise grow the map without limit. At the cap we evict the OLDEST
* inserted IP, the one least likely to still be mid-burst, which is the right
* bias for a short-window rate limiter.
*/
declare const DEFAULT_MAX_TRACKED_IPS = 10000;
/**
* A bounded, in-memory, per-IP token-bucket rate limiter for the PUBLIC
* client-error endpoint. Per-pod by design (no cross-process coordination): in a
* multi-replica deployment the same client may get up to `perMinute` requests
* PER POD — see the caveat in {@link ClientErrorsOptions.rateLimit}. The intent
* is cheap abuse-dampening on a public surface, not a hard global quota.
*
* Each IP gets a bucket holding at most `perMinute` tokens that refills linearly
* at `perMinute / 60_000` tokens per ms. A request consumes one token; an empty
* bucket means "over the limit". The bucket map is capped (insertion-order
* eviction of the oldest IP) so memory can't grow without bound.
*/
export declare class ClientErrorRateLimiter {
private readonly buckets;
private readonly perMinute;
private readonly maxTrackedIps;
private readonly refillPerMs;
private readonly now;
constructor(options: {
perMinute: number;
maxTrackedIps?: number;
/** Wall-clock seam (ms). Defaults to `Date.now`. */
now?: () => number;
});
/**
* Try to spend one token for `ip`. Returns `true` when the request is allowed
* (a token was available and consumed), `false` when the bucket is empty (over
* the limit). Refills the bucket continuously based on elapsed time so the
* effective rate is exactly `perMinute` without a coarse fixed window.
*/
tryConsume(ip: string): boolean;
/** Number of tracked IPs (test/observability seam). */
get size(): number;
/**
* Insert a fresh bucket, evicting the oldest tracked IP first when at the cap.
* `Map` iterates in insertion order, so the first key is the oldest inserted.
*/
private insert;
}
export { DEFAULT_MAX_TRACKED_IPS };
//# sourceMappingURL=client-error-rate-limiter.d.ts.map