import { RedirectOptions } from './app/auth/types/config'; import { HttpClient } from './app/http/types'; import { ExtendedLabels } from './app/auth/ui/core/types'; import { BetterAuthClientInstance } from './app/auth/types/better-auth-client'; export interface EdgeSparkOptions { /** * Backend base URL. * For fullstack (same-origin) deploys, omit this — defaults to window.location.origin. * For cross-origin (BaaS) deploys, set to your backend URL. * @example "https://api.example.com" */ baseUrl?: string; /** * Fetch credentials mode, defaults to "include" */ fetchCredentials?: RequestCredentials; } export interface LoginUIOptions { /** Custom labels for the login UI */ labels?: Partial; /** Simple redirect - where to go after any successful auth */ redirectTo?: string; /** Fine-grained redirects (advanced, overrides redirectTo) */ redirects?: RedirectOptions; /** Called on successful login with the logged-in user object */ onLogin?: (user: { id: string; email: string; name?: string; [key: string]: unknown; }) => void; /** Called on auth error */ onError?: (error: unknown) => void; } /** * EdgeSpark Auth - better-auth client + EdgeSpark additions. * * All better-auth methods work directly. Plus EdgeSpark additions. * * @see https://www.better-auth.com/docs/client */ export type EdgeSparkAuth = BetterAuthClientInstance & { /** Render managed login UI (EdgeSpark addition) */ renderAuthUI(container: HTMLElement, options?: LoginUIOptions): Promise; /** Subscribe to auth state changes, returns unsubscribe function */ onAuthStateChange(listener: () => void): () => void; }; export interface EdgeSparkApi { /** Fetch with auto-injected auth token. Same as native fetch(). */ fetch: HttpClient; } export interface EdgeSparkClient { /** * Authentication - better-auth client + EdgeSpark additions. * * All better-auth methods work. Plus EdgeSpark additions. * * @see https://www.better-auth.com/docs/client * * @example * ```ts * // better-auth methods (LLMs know these) * await client.auth.signIn.email({ email, password, callbackURL: "/dashboard" }); * await client.auth.signUp.email({ name, email, password }); * await client.auth.forgetPassword.emailOtp({ email }); * await client.auth.getSession(); * * // EdgeSpark additions * await client.auth.renderAuthUI(container, { redirectTo: "/dashboard" }); * const unsubscribe = client.auth.onAuthStateChange(() => console.log("Auth state changed")); * // ... * unsubscribe(); * ``` */ auth: EdgeSparkAuth; /** * HTTP client - just fetch() with auto-injected auth token. * @example * ```ts * const res = await client.api.fetch("/api/users"); * const users = await res.json(); * ``` */ api: EdgeSparkApi; /** * Cleanup client resources. */ destroy(options?: { clearToken?: boolean; }): void; } /** * Create an EdgeSpark client - unified entry point for auth + API. * * - Initialization is **synchronous** * - `client.auth` IS the better-auth client (pure, no wrapper) * - Token management is automatic * * @example * ```ts * import { createEdgeSpark } from "@edgespark/client"; * * const client = createEdgeSpark({ baseUrl: "https://api.example.com" }); * * // Auth - IS better-auth client (LLMs know this API) * await client.auth.signIn.email({ email, password, callbackURL: "/dashboard" }); * await client.auth.signUp.email({ name, email, password }); * await client.auth.forgetPassword.emailOtp({ email }); * await client.auth.getSession(); * * // Managed login UI (EdgeSpark addition) * await client.auth.renderAuthUI(container, { redirectTo: "/dashboard" }); * * // API - just fetch() with auth token * const res = await client.api.fetch("/api/users"); * const users = await res.json(); * ``` */ export declare function createEdgeSpark(options?: EdgeSparkOptions): EdgeSparkClient;