import { Breadcrumb, BreadcrumbLevel, BreadcrumbType, Json } from '@hawk.so/types'; import { BreadcrumbHint, BreadcrumbInput, BreadcrumbStore } from '@hawk.so/core'; /** * Hint object passed to beforeBreadcrumb callback. * Extends generic {@link BreadcrumbHint} with browser-specific data. */ export interface BrowserBreadcrumbHint extends BreadcrumbHint { /** * Original event that triggered the breadcrumb (if any) */ event?: Event | Response | XMLHttpRequest; /** * Request info for fetch/xhr breadcrumbs */ input?: RequestInfo | URL; /** * Response data for fetch/xhr breadcrumbs */ response?: Response; /** * XHR instance for xhr breadcrumbs */ xhr?: XMLHttpRequest; } /** * Configuration options for breadcrumbs */ export interface BreadcrumbsOptions { /** * Maximum number of breadcrumbs to store (FIFO) * * @default 15 */ maxBreadcrumbs?: number; /** * Hook called before each breadcrumb is stored. * - Return modified breadcrumb — it will be stored instead of the original. * - Return `false` — the breadcrumb will be discarded. * - Any other value is invalid — the original breadcrumb is stored as-is (a warning is logged). */ beforeBreadcrumb?: (breadcrumb: Breadcrumb, hint?: BrowserBreadcrumbHint) => Breadcrumb | false | void; /** * Enable automatic fetch/XHR breadcrumbs * * @default true */ trackFetch?: boolean; /** * Enable automatic navigation breadcrumbs (history API) * * @default true */ trackNavigation?: boolean; /** * Enable automatic UI click breadcrumbs * * @default true */ trackClicks?: boolean; } /** * Browser implementation of BreadcrumbStore. * Singleton that manages breadcrumb collection and storage. */ export declare class BrowserBreadcrumbStore implements BreadcrumbStore { /** * Singleton instance */ private static instance; /** * Breadcrumbs buffer (FIFO) */ private readonly breadcrumbs; /** * Configuration options - all fields are guaranteed to be set (except optional beforeBreadcrumb) */ private options; /** * Initialization flag */ private isInitialized; /** * Original fetch function (for restoration) */ private originalFetch; /** * Original XMLHttpRequest.open (for restoration) */ private originalXHROpen; /** * Original XMLHttpRequest.send (for restoration) */ private originalXHRSend; /** * Original history.pushState (for restoration) */ private originalPushState; /** * Original history.replaceState (for restoration) */ private originalReplaceState; /** * Click event handler reference (for removal) */ private clickHandler; /** * Popstate event handler reference (for removal) */ private popstateHandler; /** * Private constructor to enforce singleton pattern */ private constructor(); /** * Get singleton instance */ static getInstance(): BrowserBreadcrumbStore; /** * Initialize breadcrumbs with options and start auto-capture * * @param options - Configuration options for breadcrumbs */ init(options?: BreadcrumbsOptions): void; /** * Add a breadcrumb to the buffer * * @param breadcrumb - The breadcrumb data to add * @param hint - Optional hint object with original event data (Event, Response, XMLHttpRequest, etc.) * Used by beforeBreadcrumb callback to access original event context */ add(breadcrumb: BreadcrumbInput, hint?: BrowserBreadcrumbHint): void; /** * Get current breadcrumbs snapshot (oldest to newest) */ get(): Breadcrumb[]; /** * Clear all breadcrumbs */ clear(): void; /** * Destroy the manager and restore original functions */ destroy(): void; /** * Monkeypatch fetch API to capture HTTP breadcrumbs */ private monkeypatchFetch; /** * Wrap XMLHttpRequest to capture XHR breadcrumbs */ private wrapXHR; /** * Wrap History API to capture navigation breadcrumbs */ private wrapHistory; /** * Setup click event tracking for UI breadcrumbs */ private setupClickTracking; } /** * Helper function to create a breadcrumb object * * @param message - The breadcrumb message * @param options - Optional breadcrumb configuration */ export declare function createBreadcrumb(message: string, options?: { type?: BreadcrumbType; category?: string; level?: BreadcrumbLevel; data?: Record; }): Breadcrumb;