import type { CredentialRestorer } from "./credentialRestorer"; import { type RetryPolicy } from "./retry"; export declare class LightconeHttp { private readonly normalizedBaseUrl; private authToken; private credentialRestorer; /** * The in-flight restoration, shared by every request that 401s while it * runs — concurrent 401s await the same promise (bounded by the timeout) * instead of failing fast. Cleared when the restoration settles. */ private restorationPromise; /** * Abort handle for the in-flight restoration, set and cleared with * `restorationPromise`. Fired when the restoration's deadline abandons it: * promises cannot be cancelled, so this is the signal a well-behaved * restorer uses to stop instead of running on concurrently with the next * restoration. */ private restorationAbort; /** * The restoration's own deadline, created WITH the restoration and shared * by every waiter. Racing each waiter against its own fresh timer instead * would let a late joiner outlive the leader's timeout and accept a `true` * from a zombie restorer while a replacement restoration is already * running. */ private restorationDeadline; /** * Bumped after every completed restoration. A request captures the epoch * when it starts; if the epoch moved by the time its 401 gets to restore, * another request already restored and the stored outcome is reused. */ private restorationEpoch; private lastRestoreOutcome; /** Overridable for tests (hung-restorer coverage at test speed). */ private credentialRestoreTimeoutMs; constructor(baseUrl: string); /** * Run — or share — a credential restoration for a logical request that * began at `startEpoch`. Returns whether replaying is worthwhile. Restorer * rejections count as "not restored" so the caller's original 401 is * preserved (a callback failure must not replace the auth error). */ private restoreCredentialsShared; /** * True when `url` shares the configured API origin. Session credentials are * only injected — and the credential restorer only consulted — for * same-origin requests: a foreign URL that answers 401 must be able to * neither trigger a restoration nor receive the restored cookie on a * replay. Unparseable URLs count as foreign. */ private isApiOrigin; baseUrl(): string; clearAuthToken(): Promise; /** * Register (or replace) the credential restorer consulted on HTTP 401 — * see {@link CredentialRestorer}. Pass through * `LightconeClient.setCredentialRestorer` in normal use. */ setCredentialRestorer(restorer: CredentialRestorer): void; /** Remove the credential restorer; 401s propagate to callers unchanged. */ clearCredentialRestorer(): void; authTokenRef(): () => Promise; get(url: string, retry: RetryPolicy): Promise; post(url: string, body: B, retry: RetryPolicy): Promise; delete(url: string, retry: RetryPolicy): Promise; postWithCookies(url: string, body: B, retry: RetryPolicy, cookieHeader: string): Promise; deleteWithCookies(url: string, retry: RetryPolicy, cookieHeader: string): Promise; /** * POST with the 401 credential-restore-and-replay disabled. For * credential-management endpoints (login, logout): they are the machinery * restoration would re-run, so replaying them after restoring credentials * is at best a no-op and at worst re-consumes single-use state (the login * nonce is consumed server-side before the signature is verified, so a * replayed login deterministically fails). */ postWithoutCredentialRestore(url: string, body: B, retry: RetryPolicy): Promise; /** * GET with retry, forwarding an explicit per-call raw `Cookie` header * (e.g. `privy-token=…; lightcone-token=…`) instead of the SDK's process-wide * cookie store. Intended for server-side cookie forwarding (SSR / server * functions) where the per-request browser cookies can't propagate to the * shared client. In a browser context this is equivalent to {@link get} — the * runtime is already attaching cookies via `credentials: "include"`. */ getWithCookies(url: string, retry: RetryPolicy, cookieHeader: string): Promise; /** * GET with the 401 credential restoration disabled. Use this (and * {@link postWithoutCredentialRestore}) inside credential restorers for any * SDK calls the restorer itself makes: a restore-enabled call from inside a * restorer ends up awaiting its own restoration and only the restoration * timeout rescues it. */ getWithoutCredentialRestore(url: string, retry: RetryPolicy): Promise; private requestWithRetry; private shouldRetry; private sendRequest; private captureCookies; private cookieHeader; private mapStatusError; private statusErrorToSdk; } //# sourceMappingURL=client.d.ts.map