import { QueryClient, Query } from '@tanstack/react-query'; /** * Query metadata for additional context */ interface QueryMeta { /** Custom error message */ errorMessage?: string; /** Custom success message */ successMessage?: string; /** Whether to show error toast (default: true) */ showErrorToast?: boolean; /** Whether query is retryable (default: true) */ retryable?: boolean; /** Mark as critical - will persist and retry more aggressively */ critical?: boolean; /** Cache tag for grouped invalidation */ cacheTag?: string; } /** * Configuration for query client factory */ export interface QueryClientConfig { /** Default stale time in ms (default: 5 minutes) */ defaultStaleTime?: number; /** Default garbage collection time in ms (default: 30 minutes) */ defaultGcTime?: number; /** Maximum retry attempts (default: 3) */ maxRetries?: number; /** Enable request deduplication (default: true) */ deduplication?: boolean; /** Enable background refetching on window focus (default: false) */ backgroundRefetch?: boolean; /** Global error handler */ onError?: (error: unknown, query?: Query) => void; /** Global success handler */ onSuccess?: (data: unknown, query?: Query) => void; /** Enable offline-first mode (default: true) */ offlineFirst?: boolean; } /** * Create a configured query client instance * * @example * ```tsx * const queryClient = createQueryClient({ * defaultStaleTime: 10 * 60 * 1000, // 10 minutes * maxRetries: 5, * onError: (error) => Sentry.captureException(error), * }); * ``` */ export declare function createQueryClient(config?: QueryClientConfig): QueryClient; /** * Default query client instance */ export declare const queryClient: QueryClient; /** * Type-safe query key factory for consistent key generation * * @example * ```tsx * // Use in queries * useQuery({ * queryKey: queryKeys.users.detail('user-123'), * queryFn: () => fetchUser('user-123'), * }); * * // Use for invalidation * queryClient.invalidateQueries({ queryKey: queryKeys.users.all }); * ``` */ export declare const queryKeys: { readonly all: readonly ["all"]; readonly dashboard: { readonly all: readonly ["dashboard"]; readonly stats: () => readonly ["dashboard", "stats"]; readonly charts: (range: string) => readonly ["dashboard", "charts", string]; readonly activity: (page: number) => readonly ["dashboard", "activity", number]; readonly summary: () => readonly ["dashboard", "summary"]; }; readonly users: { readonly all: readonly ["users"]; readonly list: (filters?: Record) => readonly ["users", "list", Record | undefined]; readonly detail: (id: string) => readonly ["users", "detail", string]; readonly profile: () => readonly ["users", "profile"]; readonly preferences: () => readonly ["users", "preferences"]; }; readonly reports: { readonly all: readonly ["reports"]; readonly list: (filters?: Record) => readonly ["reports", "list", Record | undefined]; readonly detail: (id: string) => readonly ["reports", "detail", string]; readonly summary: (range: string) => readonly ["reports", "summary", string]; readonly export: (id: string) => readonly ["reports", "export", string]; }; readonly notifications: { readonly all: readonly ["notifications"]; readonly list: (page?: number) => readonly ["notifications", "list", number | undefined]; readonly unreadCount: () => readonly ["notifications", "unread-count"]; }; readonly settings: { readonly all: readonly ["settings"]; readonly app: () => readonly ["settings", "app"]; readonly user: () => readonly ["settings", "user"]; }; }; export type QueryKeys = typeof queryKeys; /** * Prefetch common queries on app initialization using apiClient * @throws {ApiError} When any prefetch request fails */ export declare function prefetchCommonQueries(): Promise; /** * Clear all query caches (useful for logout) */ export declare function clearQueryCache(): void; /** * Invalidate all queries (force refetch) */ export declare function invalidateAll(): Promise; /** * Invalidate queries by tag */ export declare function invalidateByTag(tag: string): Promise; /** * Set query data directly (for optimistic updates) */ export declare function setQueryData(queryKey: readonly unknown[], updater: T | ((old: T | undefined) => T)): T | undefined; /** * Get query data from cache */ export declare function getQueryData(queryKey: readonly unknown[]): T | undefined; /** * Remove query from cache */ export declare function removeQuery(queryKey: readonly unknown[]): void; /** * Create optimistic update handlers for mutations * * @example * ```tsx * const mutation = useMutation({ * mutationFn: updateUser, * ...createOptimisticHandlers( * queryKeys.users.detail(userId), * (old, variables) => ({ ...old, ...variables }), * ), * }); * ``` */ export declare function createOptimisticHandlers(queryKey: readonly unknown[], optimisticUpdater: (oldData: TData | undefined, variables: TVariables) => TData): { onMutate: (variables: TVariables) => Promise<{ previousData: TData | undefined; }>; onError: (_error: unknown, _variables: TVariables, context: { previousData: TData | undefined; } | undefined) => void; onSettled: () => void; }; export type { QueryMeta };