lago-javascript-client
Version:
Lago JavaScript API Client
34 lines (33 loc) • 1.18 kB
TypeScript
import type { RateLimitInfoCallback } from "./rate_limit_fetch.js";
/**
* Default usage thresholds (80%, 90%, 95%) at which the observer emits a log.
*/
export declare const DEFAULT_RATE_LIMIT_THRESHOLDS: readonly number[];
/**
* Configuration for the LoggingRateLimitObserver.
*/
export interface LoggingRateLimitObserverOptions {
/** Usage fractions (0.0 - 1.0) that should produce a log line. */
thresholds?: readonly number[];
/**
* Function used to emit the log line. Defaults to `console.warn`.
* Useful when injecting a structured logger.
*/
log?: (message: string) => void;
}
/**
* Returns a ready-to-use `onRateLimitInfo` callback that logs a warning each
* time rate limit usage crosses one of the configured thresholds.
*
* Example:
*
* ```ts
* import { Client } from "@getlago/lago-javascript-client";
* import { loggingRateLimitObserver } from "@getlago/lago-javascript-client";
*
* const client = Client(apiKey, {
* rateLimitRetry: { onRateLimitInfo: loggingRateLimitObserver() },
* });
* ```
*/
export declare function loggingRateLimitObserver(options?: LoggingRateLimitObserverOptions): RateLimitInfoCallback;