/** * @packageDocumentation Main entry point for the Rayfin SDK. * Exposes a browser-oriented RayfinClient (with full Auth support) and a * server/worker-oriented RayfinServerClient (no Auth, token-based auth). */ import { Auth, AuthStorage } from '@microsoft/rayfin-auth'; import { type EntitySchema, createDataApi } from '@microsoft/rayfin-data'; import { createFunctionsApi, type FunctionsSchema } from '@microsoft/rayfin-functions'; import { SdkError, NetworkError } from '@microsoft/rayfin-lib'; import { ApiClient, ApiClientConfig } from '@microsoft/rayfin-lib'; import { type RayfinRuntimeConfig } from './config.js'; /** * Auth error specific to the Rayfin SDK. */ export declare class AuthError extends SdkError { /** * @param message - Human-readable error description. * @param code - Optional stable error code (defaults to `'AUTH_ERROR'`). */ constructor(message: string, code?: string); } /** * Configuration for the browser-oriented {@link RayfinClient}, extending the * base HTTP client configuration with auth-token storage options. */ export interface RayfinClientConfig extends ApiClientConfig { /** * Storage implementation for authentication tokens. * If set to true, localStorage will be used. * If set to false, no storage will be used. * You may also provide your own storage or use browser's built-in Session Storage */ authStorage?: AuthStorage | boolean; /** When false, all storage I/O is skipped — pure in-memory session. Default: true */ persistSession?: boolean; /** When false, session expiration timers are not scheduled and automatic refresh on 401 is disabled. Default: true */ autoRefreshToken?: boolean; /** When false, StorageEvent listener is not registered. Default: auto-detected (true in browser with localStorage). */ multiTabSync?: boolean; /** Values passed through to `resolveRayfinConfig()`'s `runtimeConfig` result when constructed via that helper (e.g. build-time `VITE_*` vars as defaults); exposed as `client.runtimeConfig`. */ runtimeConfig?: RayfinRuntimeConfig; } /** * Configuration for the server/worker-oriented {@link RayfinServerClient}. * Omits the browser-only `getAccessToken` hook in favor of a supplied * access token. */ export interface RayfinServerClientConfig extends Omit { /** Access token (string or function) for Authorization: Bearer . Use the function form to rotate per request. */ accessToken?: string | (() => string | null); /** Values passed through to `resolveRayfinConfig()`'s `runtimeConfig` result when constructed via that helper (e.g. build-time env vars as defaults); exposed as `client.runtimeConfig`. */ runtimeConfig?: RayfinRuntimeConfig; } /** Shared base for Rayfin clients: owns the typed data API and the underlying HTTP client. */ export declare abstract class RayfinClientBase> { /** Typed data API for querying and mutating your entities. */ readonly data: ReturnType>; protected apiClient: ApiClient; protected constructor(config: ApiClientConfig & { runtimeConfig?: RayfinRuntimeConfig; }); /** SDK error classes, exposed for convenient `instanceof` checks. */ static readonly errors: { SdkError: typeof SdkError; AuthError: typeof AuthError; NetworkError: typeof NetworkError; }; } /** * Main SDK class for Rayfin. * This class acts as the primary interface for interacting with Rayfin services, * providing authentication, and GraphQL capabilities through a single entry point. * * @typeParam TSchema - Object type mapping entity names to their types * @example Frontend usage * ```typescript * const client = new RayfinClient<{ * User: User; * Organization: Organization; * }>({ * baseUrl: 'http://localhost:5168', * publishableKey: 'pk-Abc123-def456-GHI78' * }); * * // Authentication operations * await client.auth.signUp({ email: 'user@example.com', password: 'password' }); * * // GraphQL operations * const activeUsers = await client.User * .select(['id', 'name', 'email']) * .where({ isActive: true }) * .execute(); * ``` * * @example ALM-aware deployments — resolve runtime config, then construct * ```typescript * import { RayfinClient, resolveRayfinConfig } from '@microsoft/rayfin-client'; * * const resolved = await resolveRayfinConfig({ baseUrl, publishableKey }); * const client = new RayfinClient({ ...resolved, authStorage: true }); * ``` */ export declare class RayfinClient, TFunctionsSchema extends FunctionsSchema = FunctionsSchema> extends RayfinClientBase { /** Authentication operations (sign up, sign in, sign out, session state). */ readonly auth: Auth; /** Typed, schema-aware accessors for invoking your backend functions. */ readonly functions: ReturnType>; /** All resolved `rayfin.config.json` values, for apps that need more than just `baseUrl`/`publishableKey` (e.g. Fabric embed auth coordinates). */ readonly runtimeConfig?: RayfinRuntimeConfig; /** * Creates a browser Rayfin client and wires up authentication. * * @param config - Client configuration, including optional auth-token storage. */ constructor(config: RayfinClientConfig); } /** * Server / worker (Node.js) Rayfin client. Skips the browser-coupled Auth * module entirely — authentication is supplied via the accessToken config. * * @example * ```typescript * const client = new RayfinServerClient<{ Todo: Todo }>({ * baseUrl: process.env.RAYFIN_API_URL!, * publishableKey: process.env.RAYFIN_PUBLISHABLE_KEY!, * accessToken: () => incomingRequest.headers.authorization, * }); * * const todos = await client.data.Todo.select(['id', 'title']).execute(); * ``` * * @example ALM-aware deployments — resolve runtime config, then construct * ```typescript * import { RayfinServerClient, resolveRayfinConfig } from '@microsoft/rayfin-client'; * * // Node.js/workers have no implicit document origin, so pass an absolute * // configUrl to enable remote config loading. * const resolved = await resolveRayfinConfig( * { baseUrl, publishableKey }, * { configUrl: `${process.env.RAYFIN_API_URL}/rayfin.config.json` } * ); * const client = new RayfinServerClient({ ...resolved, accessToken }); * ``` */ export declare class RayfinServerClient> extends RayfinClientBase { /** * Creates a server/worker Rayfin client using a supplied access token. * * @param config - Client configuration, including the access token (string or * function form for per-request rotation). */ /** All resolved `rayfin.config.json` values, for callers that need more than just `baseUrl`/`publishableKey`. */ readonly runtimeConfig?: RayfinRuntimeConfig; constructor(config: RayfinServerClientConfig); } export default RayfinClient; //# sourceMappingURL=client.d.ts.map