UNPKG

@vigilbase/cli

Version:

Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.

42 lines (41 loc) • 1.79 kB
/** * Cloudflare request budget (spec §F5). * * Cloudflare allows 1,200 API requests per user per rolling 5 minutes, shared * with the user's dashboard; going over blocks every API call for 5 minutes. * The default spends at most 900 per rolling 5 minutes (configurable 100 to * 1,100). A token bucket with capacity `burst` that refills at * `(limit − burst) / 300 s` never admits more than `limit` calls in any * 300-second window: at most `burst` from the full bucket plus the refill. * Local `--version` and `--dry-run` calls are free. */ export declare const DEFAULT_REQUESTS_PER_5MIN = 900; export declare const MIN_REQUESTS_PER_5MIN = 100; export declare const MAX_REQUESTS_PER_5MIN = 1100; export declare const BUDGET_BURST = 8; export declare const BUDGET_WINDOW_MS = 300000; export type Clock = { now(): number; sleep(ms: number): Promise<void>; }; export declare const systemClock: Clock; export declare function parseRequestBudget(raw: string | undefined): number; export declare class RequestBudget { readonly limit: number; private readonly clock; readonly burst: number; private tokens; private updatedAt; private readonly refillPerMs; private queue; constructor(limit?: number, clock?: Clock, burst?: number); private refill; /** Tokens available now (fractional). */ available(): number; /** Wait for one request slot. Callers are served in order. */ acquire(): Promise<void>; /** Seconds the bucket needs for `requests` calls, ignoring network latency. */ estimateSeconds(requests: number): number; } /** Seconds a full bucket needs to admit `requests` calls at `limit` per 5 minutes. */ export declare function estimateBudgetSeconds(limit: number, requests: number, burst?: number): number;