UNPKG

humanbehavior-js

Version:

SDK for HumanBehavior session and event recording

117 lines 4.19 kB
export declare const MAX_CHUNK_SIZE_BYTES: number; export declare function isChunkSizeExceeded(currentChunk: any[], newEvent: any, sessionId: string): boolean; export declare function validateSingleEventSize(event: any, sessionId: string): void; export declare function splitLargeEvent(event: any, sessionId: string): any[]; export declare class HumanBehaviorAPI { private apiKey; private baseUrl; private monthlyLimitReached; private sessionId; private endUserId; private cspBlocked; private retryQueue; private persistence; private requestTimeout; private currentBatchSize; constructor({ apiKey, ingestionUrl }: { apiKey: string; ingestionUrl: string; }); /** * Set session and user IDs for tracking context */ setTrackingContext(sessionId: string, endUserId: string | null): void; /** * Load persisted events from storage and send them */ private _loadPersistedEvents; /** * Internal method to send request (used by retry queue) */ private _sendRequestInternal; /** * Handle unload - send pending retries via sendBeacon */ unload(): void; private checkMonthlyLimit; init(sessionId: string, userId: string | null): Promise<{ sessionId: any; endUserId: any; }>; /** * Server detects IP from HTTP requests automatically */ sendEvents(events: any[], sessionId: string, userId: string): Promise<void>; sendEventsChunked(events: any[], sessionId: string, userId?: string, windowId?: string, automaticProperties?: any): Promise<any[]>; /** * Send a chunk of events with retry logic and 413 handling */ private _sendChunkWithRetry; /** * Persist events to storage for retry */ private _persistEvents; sendUserData(userId: string, userData: Record<string, any>, sessionId: string): Promise<any>; sendUserAuth(userId: string, userData: Record<string, any>, sessionId: string, authFields: string[]): Promise<any>; sendBeaconEvents(events: any[], sessionId: string, userId?: string, windowId?: string, automaticProperties?: any): boolean; sendCustomEvent(sessionId: string, eventName: string, eventProperties?: Record<string, any>, endUserId?: string | null): Promise<any>; sendCustomEventBatch(sessionId: string, events: Array<{ eventName: string; eventProperties?: Record<string, any>; }>, endUserId?: string | null): Promise<any>; /** * Send console log (warn/error) to ingestion server */ sendLog(logData: { level: 'warn' | 'error'; message: string; stack?: string; url: string; timestampMs: number; sessionId: string; endUserId: string | null; }): Promise<void>; /** * Send network error to ingestion server */ sendNetworkError(errorData: { requestId: string; url: string; method: string; status: number | null; statusText: string | null; duration: number; timestampMs: number; sessionId: string; endUserId: string | null; errorType: string; errorMessage: string | null; errorName?: string | null; startTimeMs?: number; spanName?: string; spanStatus?: 'error' | 'success' | 'slow'; attributes?: Record<string, any>; }): Promise<void>; /** * Wrapper for fetch that tracks network errors and falls back to sendBeacon on CSP violations * Skips tracking for SDK's own requests to ingestion server */ private trackedFetch; /** * Fallback to sendBeacon when CSP blocks fetch * sendBeacon bypasses CSP connect-src restrictions * Note: sendBeacon is synchronous and fire-and-forget, so we can't await it */ private trackedFetchWithBeaconFallback; /** * Detect if an error is a CSP violation */ private isCSPViolation; /** * Check if network request should be skipped (SDK's own requests) */ private shouldSkipNetworkTracking; private classifyHttpError; private classifyNetworkError; } //# sourceMappingURL=api.d.ts.map