app/lib/rate-limit.mjs
16 lines and 1 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| limitHit | 15 to 17 | 1 | 33% | OkCRAP 1.3 | No data: no mutants in this code |
Imports
It imports no other module of this repo. Imported by app/lib/carrel/site-api.server.ts, app/lib/operator/auth.server.ts, app/lib/preview-links.server.ts, app/lib/search/ask-guard.server.ts, app/lib/smoke.server.ts, app/routes/api.csp-report.ts, app/routes/api.health.ts, app/routes/webmention.ts.
Source
import { limit } from "@dustinedwards/site-runtime/rate-limit";
/**
* One use of a fixed-window limit keyed by `key`, counted exactly by the ASK_BUDGET namespace, which
* is the whole site's limiter. This site refuses when the counter is unavailable, on every call: a
* guard that passes silently when its counter is gone is never noticed. The verdict carries the time
* left in the window (`retryAfterSeconds`), which is what a refusal sends as Retry-After.
*
* @param {Env} env
* @param {string} key
* @param {number} maxHits
* @param {number} windowSeconds
* @returns {ReturnType<typeof limit>}
*/
export function limitHit(env, key, maxHits, windowSeconds) {
return limit(env.ASK_BUDGET, key, [{ limit: maxHits, windowSeconds }], { onUnavailable: "refuse" });
}