Per-token log throttling utility that limits repeated log lines within a time window.
// Source: https://github.com/upstash/context7 | License: MIT | Copyright 2021 Upstash, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { createHash } from "node:crypto";
/**
* A log line about a token that repeats on every request while the condition
* lasts (an OAuth JWT without an `aud`, sent by a client at hundreds of
* requests a minute) is written at most once per token per window. The line
* that does get written carries how many were suppressed since the previous
* one, so the rate stays readable from the log. The verdict the line reports
* is still taken on every request; only the line is deduplicated.
*
* Keyed by the SHA-256 of the token so a heap dump or a debug print of the
* map never exposes a usable credential. Map insertion order doubl
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key