@pwngh/economy-lab
    Preparing search index...

    Interface RateLimiter

    Admission control for the HTTP edge. Each allow call counts one request against key and answers whether it may proceed; the limit and window are the adapter's policy, so the server only ever asks for the verdict. A throwing limiter is treated as absent for that request — the edge fails open, because a down limiter backend should degrade protection, not availability.

    // A fixed-budget limiter: 100 requests per key, refilled by the adapter's own policy.
    const budgets = new Map<string, number>();
    const limiter: RateLimiter = {
    async allow(key) {
    const left = budgets.get(key) ?? 100;
    if (left === 0) return { allowed: false, retryAfterMs: 1_000 };
    budgets.set(key, left - 1);
    return { allowed: true };
    },
    };
    interface RateLimiter {
        allow(key: string): Promise<RateVerdict>;
    }
    Index