@tracelog/lib 2.3.1 → 2.4.0-rc.85.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,7 +66,7 @@ type MetadataType = MetadataPrimitive | string[] | MetadataNestedObject | Metada
66
66
  * Result returned by tracelog.init()
67
67
  *
68
68
  * Contains the session identifier generated during initialization.
69
- * The sessionId is empty string in edge cases (SSR, disabled, race condition).
69
+ * The sessionId is empty string in edge cases (SSR, disabled).
70
70
  *
71
71
  * @example
72
72
  * ```typescript
@@ -445,6 +445,8 @@ interface Config {
445
445
  * Only applies when webVitalsMode is set. Overrides default thresholds for the selected mode.
446
446
  */
447
447
  webVitalsThresholds?: Partial<Record<WebVitalType, number>>;
448
+ /** Interval in milliseconds between event batch sends. @default 10000 (10 seconds) */
449
+ sendIntervalMs?: number;
448
450
  /** Optional configuration for third-party integrations. */
449
451
  integrations?: {
450
452
  /** TraceLog integration options. */
@@ -464,6 +466,14 @@ interface Config {
464
466
  * @example { 'X-Brand': 'my-brand', 'X-Tenant-Id': 'tenant-123' }
465
467
  */
466
468
  headers?: Record<string, string>;
469
+ /**
470
+ * Controls whether cookies and credentials are sent with fetch requests.
471
+ * - `'include'`: Always send cookies (even cross-origin) — required for cookie-based auth
472
+ * - `'same-origin'`: Only send cookies for same-origin requests
473
+ * - `'omit'`: Never send cookies
474
+ * @default 'include'
475
+ */
476
+ fetchCredentials?: RequestCredentials;
467
477
  };
468
478
  };
469
479
  }
@@ -1180,7 +1190,7 @@ declare class StorageManager {
1180
1190
  *
1181
1191
  * **Core Functionality**:
1182
1192
  * - **Event Tracking**: Captures all user interactions (clicks, scrolls, page views, custom events, web vitals, errors)
1183
- * - **Queue Management**: Batches events with 10-second intervals to optimize network requests
1193
+ * - **Queue Management**: Batches events with 10-second base intervals (exponential backoff on failure) to optimize network requests
1184
1194
  * - **Deduplication**: LRU cache with 1000-entry fingerprint storage prevents duplicate events
1185
1195
  * - **Rate Limiting**: Client-side limits (50 events/second global, 60/minute per event name)
1186
1196
  * - **Per-Session Caps**: Configurable limits prevent runaway generation (1000 total, type-specific limits)
@@ -1243,8 +1253,9 @@ declare class EventManager extends StateManager {
1243
1253
  private readonly perEventRateLimits;
1244
1254
  private eventsQueue;
1245
1255
  private pendingEventsBuffer;
1246
- private sendIntervalId;
1256
+ private sendTimeoutId;
1247
1257
  private sendInProgress;
1258
+ private consecutiveSendFailures;
1248
1259
  private rateLimitCounter;
1249
1260
  private rateLimitWindowStart;
1250
1261
  private lastSessionId;
@@ -1262,8 +1273,9 @@ declare class EventManager extends StateManager {
1262
1273
  * @param transformers - Optional event transformation hooks
1263
1274
  * @param staticHeaders - Optional static HTTP headers for custom backend (from config)
1264
1275
  * @param customHeadersProvider - Optional callback for dynamic headers
1276
+ * @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
1265
1277
  */
1266
- constructor(storeManager: StorageManager, emitter?: Emitter | null, transformers?: TransformerMap, staticHeaders?: Record<string, string>, customHeadersProvider?: CustomHeadersProvider);
1278
+ constructor(storeManager: StorageManager, emitter?: Emitter | null, transformers?: TransformerMap, staticHeaders?: Record<string, string>, customHeadersProvider?: CustomHeadersProvider, fetchCredentials?: RequestCredentials);
1267
1279
  /**
1268
1280
  * Recovers persisted events from localStorage after a crash or page reload.
1269
1281
  *
@@ -1356,7 +1368,7 @@ declare class EventManager extends StateManager {
1356
1368
  * and allow subsequent init() → destroy() → init() cycles.
1357
1369
  *
1358
1370
  * **Cleanup Actions**:
1359
- * 1. **Clear send interval**: Stops periodic 10-second queue flush timer
1371
+ * 1. **Clear send timeout**: Cancels pending queue flush timeout and resets backoff state
1360
1372
  * 2. **Clear all queues and buffers**:
1361
1373
  * - `eventsQueue`: Discarded (not sent)
1362
1374
  * - `pendingEventsBuffer`: Discarded (events before session init)
@@ -1366,8 +1378,8 @@ declare class EventManager extends StateManager {
1366
1378
  * 6. **Stop SenderManagers**: Calls `stop()` on all SenderManager instances
1367
1379
  *
1368
1380
  * **Important Behavior**:
1369
- * - **No final flush**: Events in queue are NOT sent before stopping
1370
- * - For flush before destroy, call `flushImmediatelySync()` first
1381
+ * - **No final flush**: `stop()` itself does NOT send queued events
1382
+ * - `App.destroy()` calls `flushImmediatelySync()` before `stop()` automatically
1371
1383
  *
1372
1384
  * **Multi-Integration**:
1373
1385
  * - Stops all SenderManager instances (SaaS + Custom)
@@ -1388,7 +1400,7 @@ declare class EventManager extends StateManager {
1388
1400
  * Flushes all events in the queue asynchronously.
1389
1401
  *
1390
1402
  * **Purpose**: Force immediate sending of queued events without waiting for
1391
- * the 10-second periodic flush timer.
1403
+ * the scheduled queue flush timeout.
1392
1404
  *
1393
1405
  * **Use Cases**:
1394
1406
  * - Manual flush triggered by user action
@@ -1553,7 +1565,7 @@ declare class EventManager extends StateManager {
1553
1565
  * @see src/managers/README.md (lines 5-75) for pending buffer details
1554
1566
  */
1555
1567
  flushPendingEvents(): void;
1556
- private clearSendInterval;
1568
+ private clearSendTimeout;
1557
1569
  private isSuccessfulResult;
1558
1570
  private flushEvents;
1559
1571
  private sendEventsQueue;
@@ -1564,7 +1576,8 @@ declare class EventManager extends StateManager {
1564
1576
  private createEventFingerprint;
1565
1577
  private createEventSignature;
1566
1578
  private addToQueue;
1567
- private startSendInterval;
1579
+ private scheduleSendTimeout;
1580
+ private calculateSendDelay;
1568
1581
  private shouldSample;
1569
1582
  private checkRateLimit;
1570
1583
  private checkPerEventRateLimit;
@@ -66,7 +66,7 @@ type MetadataType = MetadataPrimitive | string[] | MetadataNestedObject | Metada
66
66
  * Result returned by tracelog.init()
67
67
  *
68
68
  * Contains the session identifier generated during initialization.
69
- * The sessionId is empty string in edge cases (SSR, disabled, race condition).
69
+ * The sessionId is empty string in edge cases (SSR, disabled).
70
70
  *
71
71
  * @example
72
72
  * ```typescript
@@ -445,6 +445,8 @@ interface Config {
445
445
  * Only applies when webVitalsMode is set. Overrides default thresholds for the selected mode.
446
446
  */
447
447
  webVitalsThresholds?: Partial<Record<WebVitalType, number>>;
448
+ /** Interval in milliseconds between event batch sends. @default 10000 (10 seconds) */
449
+ sendIntervalMs?: number;
448
450
  /** Optional configuration for third-party integrations. */
449
451
  integrations?: {
450
452
  /** TraceLog integration options. */
@@ -464,6 +466,14 @@ interface Config {
464
466
  * @example { 'X-Brand': 'my-brand', 'X-Tenant-Id': 'tenant-123' }
465
467
  */
466
468
  headers?: Record<string, string>;
469
+ /**
470
+ * Controls whether cookies and credentials are sent with fetch requests.
471
+ * - `'include'`: Always send cookies (even cross-origin) — required for cookie-based auth
472
+ * - `'same-origin'`: Only send cookies for same-origin requests
473
+ * - `'omit'`: Never send cookies
474
+ * @default 'include'
475
+ */
476
+ fetchCredentials?: RequestCredentials;
467
477
  };
468
478
  };
469
479
  }
@@ -1180,7 +1190,7 @@ declare class StorageManager {
1180
1190
  *
1181
1191
  * **Core Functionality**:
1182
1192
  * - **Event Tracking**: Captures all user interactions (clicks, scrolls, page views, custom events, web vitals, errors)
1183
- * - **Queue Management**: Batches events with 10-second intervals to optimize network requests
1193
+ * - **Queue Management**: Batches events with 10-second base intervals (exponential backoff on failure) to optimize network requests
1184
1194
  * - **Deduplication**: LRU cache with 1000-entry fingerprint storage prevents duplicate events
1185
1195
  * - **Rate Limiting**: Client-side limits (50 events/second global, 60/minute per event name)
1186
1196
  * - **Per-Session Caps**: Configurable limits prevent runaway generation (1000 total, type-specific limits)
@@ -1243,8 +1253,9 @@ declare class EventManager extends StateManager {
1243
1253
  private readonly perEventRateLimits;
1244
1254
  private eventsQueue;
1245
1255
  private pendingEventsBuffer;
1246
- private sendIntervalId;
1256
+ private sendTimeoutId;
1247
1257
  private sendInProgress;
1258
+ private consecutiveSendFailures;
1248
1259
  private rateLimitCounter;
1249
1260
  private rateLimitWindowStart;
1250
1261
  private lastSessionId;
@@ -1262,8 +1273,9 @@ declare class EventManager extends StateManager {
1262
1273
  * @param transformers - Optional event transformation hooks
1263
1274
  * @param staticHeaders - Optional static HTTP headers for custom backend (from config)
1264
1275
  * @param customHeadersProvider - Optional callback for dynamic headers
1276
+ * @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
1265
1277
  */
1266
- constructor(storeManager: StorageManager, emitter?: Emitter | null, transformers?: TransformerMap, staticHeaders?: Record<string, string>, customHeadersProvider?: CustomHeadersProvider);
1278
+ constructor(storeManager: StorageManager, emitter?: Emitter | null, transformers?: TransformerMap, staticHeaders?: Record<string, string>, customHeadersProvider?: CustomHeadersProvider, fetchCredentials?: RequestCredentials);
1267
1279
  /**
1268
1280
  * Recovers persisted events from localStorage after a crash or page reload.
1269
1281
  *
@@ -1356,7 +1368,7 @@ declare class EventManager extends StateManager {
1356
1368
  * and allow subsequent init() → destroy() → init() cycles.
1357
1369
  *
1358
1370
  * **Cleanup Actions**:
1359
- * 1. **Clear send interval**: Stops periodic 10-second queue flush timer
1371
+ * 1. **Clear send timeout**: Cancels pending queue flush timeout and resets backoff state
1360
1372
  * 2. **Clear all queues and buffers**:
1361
1373
  * - `eventsQueue`: Discarded (not sent)
1362
1374
  * - `pendingEventsBuffer`: Discarded (events before session init)
@@ -1366,8 +1378,8 @@ declare class EventManager extends StateManager {
1366
1378
  * 6. **Stop SenderManagers**: Calls `stop()` on all SenderManager instances
1367
1379
  *
1368
1380
  * **Important Behavior**:
1369
- * - **No final flush**: Events in queue are NOT sent before stopping
1370
- * - For flush before destroy, call `flushImmediatelySync()` first
1381
+ * - **No final flush**: `stop()` itself does NOT send queued events
1382
+ * - `App.destroy()` calls `flushImmediatelySync()` before `stop()` automatically
1371
1383
  *
1372
1384
  * **Multi-Integration**:
1373
1385
  * - Stops all SenderManager instances (SaaS + Custom)
@@ -1388,7 +1400,7 @@ declare class EventManager extends StateManager {
1388
1400
  * Flushes all events in the queue asynchronously.
1389
1401
  *
1390
1402
  * **Purpose**: Force immediate sending of queued events without waiting for
1391
- * the 10-second periodic flush timer.
1403
+ * the scheduled queue flush timeout.
1392
1404
  *
1393
1405
  * **Use Cases**:
1394
1406
  * - Manual flush triggered by user action
@@ -1553,7 +1565,7 @@ declare class EventManager extends StateManager {
1553
1565
  * @see src/managers/README.md (lines 5-75) for pending buffer details
1554
1566
  */
1555
1567
  flushPendingEvents(): void;
1556
- private clearSendInterval;
1568
+ private clearSendTimeout;
1557
1569
  private isSuccessfulResult;
1558
1570
  private flushEvents;
1559
1571
  private sendEventsQueue;
@@ -1564,7 +1576,8 @@ declare class EventManager extends StateManager {
1564
1576
  private createEventFingerprint;
1565
1577
  private createEventSignature;
1566
1578
  private addToQueue;
1567
- private startSendInterval;
1579
+ private scheduleSendTimeout;
1580
+ private calculateSendDelay;
1568
1581
  private shouldSample;
1569
1582
  private checkRateLimit;
1570
1583
  private checkPerEventRateLimit;