import { type AuthSession, type SignInOptions, type SyncAuthOptions } from './types.ts'; export type Listener = (session: AuthSession | null) => void; /** * Framework-agnostic Sync Server auth client. One instance per server; share it * across your app. Works as an external store (`subscribe` + `getSnapshot`) so it * plugs into React's `useSyncExternalStore`, Vue's `shallowRef`, Svelte stores, * nanostores, or a plain callback. */ export declare class SyncAuth { #private; readonly server: string; constructor(options: SyncAuthOptions); /** Current session, or `null` when signed out or expired. */ get session(): AuthSession | null; get isSignedIn(): boolean; /** Current token or `null`. Convenience for `transformRequest`-style hooks. */ get token(): string | null; get user(): import("./types.ts").SyncUser | null; /** `useSyncExternalStore`-compatible snapshot (same reference until the session changes). */ getSnapshot: () => AuthSession | null; /** For SSR frameworks: there is never a session on the server. */ getServerSnapshot: () => AuthSession | null; /** Listen for sign-in / sign-out / expiry. Returns an unsubscribe function. */ subscribe: (listener: Listener) => (() => void); /** * Sign in. **Call from a user gesture** (a click) or browsers will block the * popup. In the default `'auto'` mode a blocked popup falls back to a * full-page redirect; `'redirect'` skips the popup entirely. Concurrent * calls share one popup. A redirect unloads the page, so the returned * promise then never settles — the session is picked up by the `SyncAuth` * created on the next load. */ signIn(options?: SignInOptions): Promise; /** * Navigate this window to the sign-in page. The server sends the user back * to `returnTo` with the session in the URL fragment, which the next * `SyncAuth` instance consumes. Never resolves; rejects with `redirecting` * only when there is no window to navigate. */ signInWithRedirect(returnTo?: string | undefined): Promise; /** Resolve with the current session, or sign in if there isn't one. */ ensureSignedIn(): Promise; /** Drop the current session and sign in again. Single-flight: a burst of 401s opens one popup. */ reauthenticate(): Promise; /** * Clear the local session (this is what revokes your app's access), then * best-effort end the server session so the next popup asks for credentials. * Already-issued tokens stay valid until they expire. */ signOut(): Promise; /** * URL of the server's sign-in page, with the popup-complete page as `callbackUrl`. * `returnTo` rides along so a magic link opened in another tab (no opener) * can still finish by redirecting back to the app. */ signInUrl(returnTo?: string): string; /** URL of the server's sign-in page for the redirect flow: completes at `/api/v0/auth/complete` and returns to `returnTo`. */ redirectSignInUrl(returnTo: string): string; /** Append `?token=` to a Sync Server URL. Returns other URLs unchanged. */ withToken(url: string | URL): string; /** * `fetch` that signs in if needed, attaches the bearer token, and on 401/403/499 * re-authenticates once (opening a single popup even under a burst) and retries. * Pass `{ interactive: false }` to fail instead of opening a popup. */ fetch(input: string | URL, init?: RequestInit & { interactive?: boolean; }): Promise; /** Base URL of a table's FeatureServer: `{server}/api/v0/rest/services/{baseId}/{table}/FeatureServer`. */ featureServerUrl(baseId: string | number, tableName?: string): string; /** Base URL of a table's VectorTileServer. */ vectorTileServerUrl(baseId: string | number, tableName: string): string; /** Whole-table GeoJSON shortcut: `{server}/api/v0/{baseId}/{table}.geojson`. */ geojsonUrl(baseId: string | number, tableName: string): string; /** Remove listeners. Call when tearing down (HMR, tests). */ destroy(): void; } /** Create a client. Equivalent to `new SyncAuth(options)`. */ export declare function createSyncAuth(options: SyncAuthOptions): SyncAuth; //# sourceMappingURL=client.d.ts.map