/** * WHOOP API HTTP client. * * Thin wrapper around native `fetch` that injects the OAuth Bearer token, * prepends the WHOOP API base URL, parses JSON responses, and throws * typed errors for non-2xx status codes. */ import type { Logger } from "../logging/logger.js"; import { MemoryCache } from "../cache/memory-cache.js"; /** Options for creating a WHOOP API client */ export interface WhoopClientOptions { accessToken: string; /** Override base URL — useful for testing. Defaults to WHOOP_API_BASE_URL. */ baseUrl?: string; /** Callback to refresh the access token on 401. Returns a new access token. */ onTokenRefresh?: () => Promise; /** * Optional structured logger for API call observability. * Successful calls log at `debug` with `durationMs`; 429 responses log at * `warn`; timeouts/network errors log at `error`. */ logger?: Logger; /** Optional request ID propagated to all log entries for this client. */ requestId?: string; /** * Optional shared cache. When provided, callers can opt individual GETs into * caching via the `cache` option on {@link WhoopClient.get}. Without it, * caching is a no-op and every GET hits the network. */ cache?: MemoryCache; } /** Per-request options for {@link WhoopClient.get}. */ export interface WhoopGetOptions { /** When true (and a cache is configured), serve from / store in the cache. */ cache?: boolean; /** TTL override in milliseconds for this cached entry. Defaults to the cache default. */ ttlMs?: number; } /** WHOOP API client returned by createWhoopClient */ export interface WhoopClient { /** Send a GET request and parse the JSON response as T */ get(path: string, options?: WhoopGetOptions): Promise; } /** Error thrown when the WHOOP API returns a non-2xx response */ export declare class WhoopApiError extends Error { readonly statusCode: number; readonly statusText: string; readonly body: unknown; readonly name = "WhoopApiError"; constructor(statusCode: number, statusText: string, body: unknown); } /** Error thrown when a network-level failure prevents reaching the WHOOP API */ export declare class WhoopNetworkError extends Error { readonly name = "WhoopNetworkError"; constructor(cause: unknown); } /** Error thrown when token refresh fails during automatic 401 recovery */ export declare class WhoopAuthError extends Error { readonly name = "WhoopAuthError"; constructor(cause: unknown); } /** * Build a deterministic cache key for a GET request. * Query parameters are sorted so that semantically identical paths collapse to * the same key (e.g. `?a=1&b=2` and `?b=2&a=1`). No auth data is included. */ export declare function cacheKey(path: string): string; /** * Create a WHOOP API client. * * The client prepends the base URL to all paths, injects the Bearer token, * parses JSON responses, retries 429 rate limit responses with backoff, * and throws typed errors for non-2xx status codes. */ export declare function createWhoopClient(options: WhoopClientOptions): WhoopClient; //# sourceMappingURL=client.d.ts.map