import { AttributionData, TrackableEventTypes, ApiTypes } from '@fluid-app/api-client'; export { AttributionData } from '@fluid-app/api-client'; import { StorageManager } from '@fluid-app/storage-manager'; /** * Configuration options for FairShare */ interface FairshareConfig { /** Fluid shop identifier */ fluidShop: string; /** Debug mode */ debug?: boolean; /** Custom API endpoint for all Fluid API requests (e.g., "https://api.staging.fluid.app") */ apiEndpoint?: string; /** Maximum number of events to send in a single batch */ batchSize?: number; /** Time in ms to wait before sending a batch */ batchInterval?: number; /** Maximum number of events to store in the queue */ maxQueueSize?: number; /** Interval in ms for automatically flushing the event queue (0 to disable) */ flushIntervalMs?: number; /** Attribution override that overrides URL-based attribution */ attributionOverride?: AttributionData; } interface CheckoutStartedEventWithData { eventName: (typeof TrackableEventTypes)["CHECKOUT_STARTED"]; data: ApiTypes["checkout-started"]["request"]; } type TrackableEventWithData = CheckoutStartedEventWithData; /** * Core implementation of the FairShare tracking library */ declare class FairShareCore { private static instance; protected config: FairshareConfig; protected sessionToken: string | null; protected fingerprint: string | null; private initialized; private lastPageUrl; private navigationIntervalId?; private initializationPromise; private resolveInitialization?; private storageManager; private fingerPrintManager; private sessionManager; private attributionManager; private eventManager; private constructor(); /** * Get the existing FairShare instance * @returns The FairShare instance * @throws Error if FairShare is not initialized */ static getInstance(): FairShareCore; /** * Create and initialize a new FairShare instance * @param config The FairShare configuration * @returns The initialized FairShare instance */ static createInstance(config: FairshareConfig): FairShareCore; /** * Create a new instance of FairShareCore, replacing any existing instance * For internal use by the reset function */ static resetInstance(): void; /** * Initialize the FairShare SDK core functionality * @param config Configuration options * @private Used internally by initializeFairshare and createInstance */ private initializeCore; /** * Initialize the FairShare SDK * @param config Configuration options */ initializeFairshare(config: FairshareConfig): void; /** * Start tracking navigation changes for automatic page visit tracking */ private startNavigationTracking; /** * Stop tracking navigation changes */ private stopNavigationTracking; /** * Bound version of handleUrlChange for use in event listeners */ private boundHandleUrlChange; /** * Check if the URL has changed and handle it if it has */ private checkUrlChange; /** * Handle URL changes and track page visits when the URL changes */ private handleUrlChange; protected initSession(): Promise; getSessionToken(): string | null; protected createSession(): Promise; protected generateFingerprint(): Promise; protected storeFingerprint(fingerprint: string): void; protected getStoredFingerprint(): string | null; /** * Capture attribution data from the URL * @returns The captured attribution data or null if not found * @deprecated Server-side attribution is now handled via settings API. * This method maintained for backward compatibility but may return null. */ captureAttribution(): AttributionData | null; /** * Get attribution data from the current URL * @returns The attribution data from URL or null if not found * @deprecated Server-side attribution is now handled via settings API. * Use getEffectiveAttribution() instead for current attribution data. */ getAttribution(): AttributionData | null; trackFairshareEvent(event: TrackableEventWithData): void; /** * Track a checkout started event using the specific EventManager method * This ensures proper metadata building and processing * @param data Checkout started event data */ trackCheckoutStarted(data: { cart_token: string; }): void; /** * Track a checkout started event synchronously * Returns a promise that resolves when the API request completes * @param data Checkout started event data */ trackCheckoutStartedSync(data: { cart_token: string; }): Promise; /** * Flush all pending events in the queue * @param sync Whether to wait for all events to complete processing before returning * @param timeoutMs Maximum time to wait for events to complete (only applies when sync=true) * @returns Promise that resolves when events are processed */ flushEvents(sync?: boolean, timeoutMs?: number): Promise; /** * Flush all pending events using navigator.sendBeacon for reliable delivery during page unload * @returns Promise that resolves when events are processed with beacon */ flushEventsWithBeacon(): Promise; protected getUserId(): string; protected debug(message: string, ...args: unknown[]): void; protected retry(fn: () => Promise, attempts: number, delay?: number): Promise; reset(): void; /** * Get the initialization Promise * @returns Promise that resolves when initialization is complete */ getInitializationPromise(): Promise; } /** * Interface for attribution override configuration * This allows setting attribution that overrides server-calculated attribution */ interface AttributionOverride { attribution?: AttributionData; } /** * Attribution manager that handles attribution from settings API * and supports attribution overrides with priority handling */ declare class AttributionManager { private storageManager; private urlAttributionCache; private static TTL; constructor(storageManager: StorageManager); private getCacheKey; private getPersistentCache; private setPersistentCache; private isCacheValid; /** * Store attribution data from settings API response * @param url The URL this attribution data is for * @param attribution Attribution data from settings API (API client format) */ storeServerAttribution(url: string, attribution: AttributionData | null): void; /** * Get effective attribution data respecting priority: * 1. Attribution override (highest priority) * 2. Server-calculated attribution * 3. Fallback (null) */ getEffectiveAttribution({ url, useCachedAttribution, }?: { url?: string; useCachedAttribution?: boolean; }): AttributionData | null; /** * Get server-calculated attribution for the current or specified URL */ getServerAttribution(url?: string): AttributionData | null; /** * Set attribution override that overrides server-calculated attribution */ setAttributionOverride(attributionOverride: AttributionOverride): void; /** * Clear attribution override, falling back to server-calculated attribution */ clearAttributionOverride(): void; /** * Get attribution override if set */ getAttributionOverride(): AttributionData | null; /** * Check if attribution data needs refresh for the current URL */ needsRefresh(url: string): boolean; /** * Clear attribution data for a specific URL or all URLs */ clearAttribution(url?: string): void; /** * Get attribution source information for debugging */ getAttributionSource(): "attribution-override" | "server" | "none" | "cookie"; } /** * Get the FairShare instance * @returns The FairShare instance * @throws Error if FairShare is not initialized */ declare function getInstance(): FairShareCore; /** * Initialize the FairShare SDK * @param config Configuration options * @returns Promise that resolves when initialization is complete */ declare function initializeFairshare(config: FairshareConfig): Promise; /** * Track a custom event * @param eventName Event name * @param properties Event properties * @param options Event options * @returns A promise that resolves when the event is tracked */ declare function trackFairshareEvent(event: TrackableEventWithData): void; /** * Track a checkout started event specifically using the proper EventManager method * This ensures proper metadata building and processing * @param data Checkout started event data */ declare function trackCheckoutStarted(data: { cart_token: string; }): void; /** * Track a checkout started event synchronously * Returns a promise that resolves when the API request completes * @param data Checkout started event data */ declare function trackCheckoutStartedSync(data: { cart_token: string; }): Promise; /** * Reset the SDK state */ declare function reset(): void; declare function getSessionToken(): string; declare function getAttribution(): AttributionData | null; /** * Check if a session token is available without throwing an error * @returns true if session token is available, false otherwise */ declare function hasSessionToken(): boolean; /** * Get session token if available, otherwise return null * @returns session token string or null if not available */ declare function getSessionTokenSafe(): string | null; /** * Flush all pending events in the queue * @param sync Whether to wait for all events to complete processing * @param timeoutMs Maximum time to wait for events to complete (only applies when sync=true) * @returns Promise that resolves when events are processed */ declare function flushEvents(sync?: boolean, timeoutMs?: number): Promise; /** * Flush all pending events using navigator.sendBeacon for reliable delivery during page unload * @returns Promise that resolves when events are processed with beacon */ declare function flushEventsWithBeacon(): Promise; export { AttributionManager, type AttributionOverride, type FairshareConfig, type TrackableEventWithData, flushEvents, flushEventsWithBeacon, getAttribution, getInstance, getSessionToken, getSessionTokenSafe, hasSessionToken, initializeFairshare, reset, trackCheckoutStarted, trackCheckoutStartedSync, trackFairshareEvent };