import { ApolloClient, InMemoryCache } from '@apollo/client/core'; import { Gateway } from '../config'; /** * Check if the network circuit breaker is currently open (backend unreachable). * Useful for showing "backend offline" banners in the UI. */ export declare function isNetworkCircuitOpen(): boolean; export declare function isAuthProtocolError(error: unknown): boolean; export type { Gateway } from '../config'; export interface CreateClientOptions { /** Gateway type: 'workspace' or 'global' */ gateway: Gateway; /** Optional base URL override (defaults to gateway's defaultBaseUrl) */ baseUrl?: string; /** Authorization token or token getter function */ authToken?: string | (() => string | null); /** Workspace token or getter for X-Workspace-Authorization header (workspace gateway only) */ workspaceToken?: string | (() => string | null); /** Locale code or getter function for Accept-Language header */ locale?: string | (() => string | null); /** Geography getter for x-geo-* headers (country, currency, timezone) */ geography?: () => { country?: string; currency?: string; timezone?: string; } | null; /** Organization ID or getter function for x-org-id header (global gateway) */ organizationId?: string | (() => string | null); /** Product ID or getter function for x-product-id header (for product-level isolation) */ productId?: string | (() => string | null); /** Product slug or getter function for x-product-slug header */ productSlug?: string | (() => string | null); /** Workspace ID or getter function for x-workspace-id header (workspace context) */ workspaceId?: string | (() => string | null); /** Project ID or getter function for x-project-id header (project context) */ projectId?: string | (() => string | null); /** Tenant ID or getter function for x-tenant-id header (tenant context) */ tenantId?: string | (() => string | null); /** Optional cache instance for sharing between clients */ cache?: InMemoryCache; /** Enable SSE subscriptions */ enableSubscriptions?: boolean; /** SSE endpoint URL override (defaults to gateway's sse path) */ sseUrl?: string; /** Callback when authentication error occurs */ onAuthError?: () => void; /** * Callback to attempt token refresh when a 401/UNAUTHENTICATED error occurs. * If provided, the ErrorLink will call this before invoking onAuthError, * and will retry the failed operation with the new token on success. * Should return `true` if refresh succeeded (token updated in storage), * or `false` if refresh failed (triggers onAuthError). */ onRefreshToken?: () => Promise; /** Callback when network error occurs */ onNetworkError?: (error: Error) => void; /** Callback when network status changes (circuit breaker open/closed) */ onNetworkStatusChange?: (isOffline: boolean) => void; /** Callback after a successful mutation response. Used by shells to refresh active UI data. */ onMutationSuccess?: (event: MutationSuccessEvent) => void | Promise; /** Maximum retry attempts for failed requests (default: 3) */ maxRetryAttempts?: number; /** * Maximum number of operations to batch together (default: 10). * Set to 1 to disable batching. */ batchMax?: number; /** * Time window (ms) to collect operations before sending a batch. * Defaults to a longer page-load burst window and a shorter steady-state window. */ batchInterval?: number; /** Enable debug logging */ debug?: boolean; } export interface MutationSuccessEvent { gateway: Gateway; operationName: string; } /** * Creates an Apollo Client configured for a Burdenoff gateway * * @example Basic usage * ```ts * // Workspace gateway client * const workspaceClient = createGraphQLClient({ * gateway: 'workspace', * authToken: 'your-jwt-token', * }); * * // Global gateway client * const globalClient = createGraphQLClient({ * gateway: 'global', * authToken: () => localStorage.getItem('token'), * }); * ``` * * @example With subscriptions * ```ts * const client = createGraphQLClient({ * gateway: 'workspace', * authToken: token, * enableSubscriptions: true, * }); * ``` */ export declare function createGraphQLClient(options: CreateClientOptions): ApolloClient; export interface AppClientConfig { workspaceBaseUrl?: string; globalBaseUrl?: string; authToken?: string | (() => string | null); enableSubscriptions?: boolean; onAuthError?: () => void; debug?: boolean; } /** * Initialize app-level Apollo clients * Call this once during app initialization */ export declare function initializeAppClients(config: AppClientConfig): void; /** * Get the workspace gateway Apollo client */ export declare function getWorkspaceClient(): ApolloClient; /** * Get the global gateway Apollo client */ export declare function getGlobalClient(): ApolloClient; /** * Reset all singleton clients (useful for logout or testing) */ export declare function resetAppClients(): void; //# sourceMappingURL=client.d.ts.map