lago-javascript-client
Version:
Lago JavaScript API Client
39 lines (38 loc) • 1.4 kB
TypeScript
/**
* Parses rate limit headers from HTTP responses
*/
export interface RateLimitHeaders {
limit: number | null;
remaining: number | null;
reset: number | null;
}
/**
* Parsed rate limit headers plus the request context they came from.
*
* Delivered to the `onRateLimitInfo` callback after every successful request
* so callers can build observability around the rate limit (warn at thresholds,
* emit metrics, etc.).
*/
export interface RateLimitInfo extends RateLimitHeaders {
/** HTTP method of the call (GET, POST, ...). */
method: string;
/** Request URL. */
url: string;
}
/**
* Returns the fraction of the rate limit currently used in [0.0, 1.0],
* or `null` when the headers aren't usable (missing limit, zero limit,
* missing remaining).
*/
export declare function rateLimitUsagePct(info: RateLimitHeaders): number | null;
/**
* Extract rate limit information from response headers
*/
export declare function parseRateLimitHeaders(headers: Headers): RateLimitHeaders;
/**
* Returns a `RateLimitInfo` (headers + request context), or `null` when no
* `x-ratelimit-*` headers are present (e.g. self-hosted Lago instance with
* limits disabled). Useful for skipping observability emission entirely when
* there's nothing to report.
*/
export declare function parseRateLimitInfo(headers: Headers, method: string, url: string): RateLimitInfo | null;