import { AuthConfig, OAuthAuth, OuraConfig } from "./config.js"; import { t as OuraDataParams } from "./params-DI5FGh-e.js"; import { Either } from "functype"; //#region src/oura/client.d.ts type OuraErrorKind = "network" | "http" | "parse" | "config" | "auth"; type OuraError = { readonly kind: OuraErrorKind; readonly message: string; readonly status?: number; readonly detail?: unknown; }; type FetchLike = typeof fetch; type RequestDeps = AuthDeps & { readonly fetchFn?: FetchLike; /** Injectable clock so default date ranges are deterministic in tests. */ readonly now?: Date; /** * Bearer-token source. Created once per process in production so OAuth token caching and * single-flight refresh work across requests. Omit and a provider is derived from `config.auth`. */ readonly tokenProvider?: TokenProvider; }; /** Build the fully-qualified Oura request URL for the given (already-validated) params. */ declare const buildUrl: (config: OuraConfig, params: OuraDataParams, now: Date) => string; /** * Perform an Oura API request and return the parsed JSON as `Right`, or a classified * {@link OuraError} as `Left`. Never throws for network/HTTP/parse failures. */ declare const requestOura: (config: OuraConfig, params: OuraDataParams, deps?: RequestDeps) => Promise>; //#endregion //#region src/oura/auth.d.ts /** A persisted set of Oura OAuth tokens. `expiresAt` is epoch milliseconds. */ type TokenSet = { readonly accessToken: string; readonly refreshToken: string; readonly expiresAt: number; }; /** Produces a valid bearer token, hiding whether it came from a PAT or a refreshed OAuth token. */ type TokenProvider = { /** A valid bearer token, refreshing if the cached one is missing or within the expiry margin. */ readonly getToken: () => Promise>; /** Drop the cached access token so the next {@link getToken} forces a refresh (call after a 401). */ readonly invalidate: () => void; }; type AuthDeps = { readonly fetchFn?: typeof fetch; /** Injectable clock (epoch ms) so expiry logic is deterministic in tests. */ readonly now?: () => number; /** Read the token store; resolve to `undefined` when it does not exist. */ readonly readStore?: (path: string) => Promise; /** Persist the token store. Must create parent dirs and write restrictively (0600). */ readonly writeStore?: (path: string, contents: string) => Promise; }; /** * Exchange an authorization code (from the `login` browser flow) for the initial {@link TokenSet}. * `redirectUri` must exactly match the one used to obtain the code and registered with Oura. */ declare const exchangeAuthCode: (auth: OAuthAuth, code: string, redirectUri: string, deps?: AuthDeps) => Promise>; /** Persist a {@link TokenSet} to the store (creates parent dirs, writes 0600). Used by `login`. */ declare const writeTokenStore: (path: string, tokens: TokenSet, deps?: AuthDeps) => Promise; /** * OAuth token provider. Loads the token store lazily, refreshes when the access token is missing * or near expiry, and persists the rotated refresh token BEFORE returning the access token so a * crash can never strand us with a spent refresh token. Refreshes are single-flight: concurrent * callers share one in-flight refresh, so the single-use refresh token is never double-spent. */ declare const createOAuthTokenProvider: (auth: OAuthAuth, deps?: AuthDeps) => TokenProvider; /** Static provider for a personal access token: always returns the key, never refreshes. */ declare const createStaticTokenProvider: (apiKey: string) => TokenProvider; /** Build the right {@link TokenProvider} for the resolved {@link AuthConfig}. */ declare const createTokenProvider: (auth: AuthConfig, deps?: AuthDeps) => TokenProvider; //#endregion export { createStaticTokenProvider as a, writeTokenStore as c, OuraErrorKind as d, RequestDeps as f, createOAuthTokenProvider as i, FetchLike as l, requestOura as m, TokenProvider as n, createTokenProvider as o, buildUrl as p, TokenSet as r, exchangeAuthCode as s, AuthDeps as t, OuraError as u }; //# sourceMappingURL=auth-J8KbkPsW.d.ts.map