cryptique-sdk 1.2.5 → 1.2.7

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.
package/lib/cjs/index.js CHANGED
@@ -4302,31 +4302,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4302
4302
 
4303
4303
  };
4304
4304
 
4305
- // ============================================================================
4306
- // SECTION 13: API COMMUNICATION
4307
- // ============================================================================
4308
- // PURPOSE: Unified API client for all backend communication. Handles sending
4309
- // session data, custom events, and UTM events.
4310
- //
4311
- // KEY PRINCIPLES:
4312
- // 1. Unified API client for all endpoints
4313
- // 2. Transforms data using DataTransformer before sending
4314
- // 3. Handles retries and errors gracefully
4315
- // 4. Uses sendBeacon for beforeunload (last resort)
4316
- // 5. Uses fetch with keepalive for regular sends
4317
- // 6. Comprehensive error handling and logging
4318
- //
4319
- // BENEFITS:
4320
- // - Single place to handle all API communication
4321
- // - Consistent error handling
4322
- // - Retry logic for reliability
4323
- // - Proper use of sendBeacon vs fetch
4324
- // ============================================================================
4325
-
4326
- // Throttle network error logs (e.g. "Failed to fetch" from ad blockers) - log at most once per 30s
4327
- let _lastNetworkErrorLog = 0;
4328
- const _NETWORK_ERROR_THROTTLE_MS = 30000;
4329
-
4330
4305
  /**
4331
4306
  * APIClient - Unified API communication
4332
4307
  *
@@ -4502,17 +4477,24 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4502
4477
  }
4503
4478
 
4504
4479
  // Handle AbortError gracefully (timeout or page unload)
4505
- if (error.name === 'AbortError' || error.message?.includes('aborted') || error.message?.includes('signal is aborted')) {
4480
+ if (
4481
+ error.name === 'AbortError' ||
4482
+ error.message?.includes('aborted') ||
4483
+ error.message?.includes('signal is aborted')
4484
+ ) {
4506
4485
  // Don't log as error - this is expected behavior for timeouts or page unloads
4507
4486
  // Don't retry aborted requests - they were intentionally cancelled
4508
4487
  return; // Silently return, don't throw
4509
4488
  }
4510
4489
 
4511
- // Throttle "Failed to fetch" logs (common with ad blockers, CORS, network issues)
4512
- const isNetworkError = error.name === 'TypeError' && (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4513
- const now = Date.now();
4514
- if (isNetworkError && (now - _lastNetworkErrorLog) < _NETWORK_ERROR_THROTTLE_MS) ; else {
4515
- if (isNetworkError) _lastNetworkErrorLog = now;
4490
+ // Treat common network issues (ad blockers, CORS, offline, etc.) as silent failures.
4491
+ // We still retry according to the "retries" option, but we do not log these to the console.
4492
+ const isNetworkError =
4493
+ error.name === 'TypeError' &&
4494
+ (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4495
+
4496
+ // Only log unexpected / non‑network errors
4497
+ if (!isNetworkError) {
4516
4498
  console.error('❌ Error sending data:', error);
4517
4499
  }
4518
4500
 
@@ -4522,7 +4504,11 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4522
4504
  return this.send(endpoint, data, { ...options, retries: retries - 1 });
4523
4505
  }
4524
4506
 
4525
- throw error;
4507
+ // For non‑network errors that made it this far, surface to callers
4508
+ if (!isNetworkError) {
4509
+ throw error;
4510
+ }
4511
+ // For network errors, fail silently after retries are exhausted
4526
4512
  }
4527
4513
  },
4528
4514
 
@@ -4548,9 +4534,12 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4548
4534
  const transformedData = DataTransformer.toBackendFormat(sessionDataToSend);
4549
4535
 
4550
4536
  // Send to track endpoint
4537
+ // Use a more generous timeout for session tracking so requests are
4538
+ // very unlikely to be aborted under normal conditions.
4551
4539
  await this.send(CONFIG.API.TRACK, { sessionData: transformedData }, {
4552
4540
  transform: false, // Already transformed
4553
- retries: 2
4541
+ retries: 2,
4542
+ timeout: 15000
4554
4543
  });
4555
4544
  } catch (error) {
4556
4545
  console.error('❌ Error sending session data:', error);
package/lib/esm/index.js CHANGED
@@ -4300,31 +4300,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4300
4300
 
4301
4301
  };
4302
4302
 
4303
- // ============================================================================
4304
- // SECTION 13: API COMMUNICATION
4305
- // ============================================================================
4306
- // PURPOSE: Unified API client for all backend communication. Handles sending
4307
- // session data, custom events, and UTM events.
4308
- //
4309
- // KEY PRINCIPLES:
4310
- // 1. Unified API client for all endpoints
4311
- // 2. Transforms data using DataTransformer before sending
4312
- // 3. Handles retries and errors gracefully
4313
- // 4. Uses sendBeacon for beforeunload (last resort)
4314
- // 5. Uses fetch with keepalive for regular sends
4315
- // 6. Comprehensive error handling and logging
4316
- //
4317
- // BENEFITS:
4318
- // - Single place to handle all API communication
4319
- // - Consistent error handling
4320
- // - Retry logic for reliability
4321
- // - Proper use of sendBeacon vs fetch
4322
- // ============================================================================
4323
-
4324
- // Throttle network error logs (e.g. "Failed to fetch" from ad blockers) - log at most once per 30s
4325
- let _lastNetworkErrorLog = 0;
4326
- const _NETWORK_ERROR_THROTTLE_MS = 30000;
4327
-
4328
4303
  /**
4329
4304
  * APIClient - Unified API communication
4330
4305
  *
@@ -4500,17 +4475,24 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4500
4475
  }
4501
4476
 
4502
4477
  // Handle AbortError gracefully (timeout or page unload)
4503
- if (error.name === 'AbortError' || error.message?.includes('aborted') || error.message?.includes('signal is aborted')) {
4478
+ if (
4479
+ error.name === 'AbortError' ||
4480
+ error.message?.includes('aborted') ||
4481
+ error.message?.includes('signal is aborted')
4482
+ ) {
4504
4483
  // Don't log as error - this is expected behavior for timeouts or page unloads
4505
4484
  // Don't retry aborted requests - they were intentionally cancelled
4506
4485
  return; // Silently return, don't throw
4507
4486
  }
4508
4487
 
4509
- // Throttle "Failed to fetch" logs (common with ad blockers, CORS, network issues)
4510
- const isNetworkError = error.name === 'TypeError' && (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4511
- const now = Date.now();
4512
- if (isNetworkError && (now - _lastNetworkErrorLog) < _NETWORK_ERROR_THROTTLE_MS) ; else {
4513
- if (isNetworkError) _lastNetworkErrorLog = now;
4488
+ // Treat common network issues (ad blockers, CORS, offline, etc.) as silent failures.
4489
+ // We still retry according to the "retries" option, but we do not log these to the console.
4490
+ const isNetworkError =
4491
+ error.name === 'TypeError' &&
4492
+ (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4493
+
4494
+ // Only log unexpected / non‑network errors
4495
+ if (!isNetworkError) {
4514
4496
  console.error('❌ Error sending data:', error);
4515
4497
  }
4516
4498
 
@@ -4520,7 +4502,11 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4520
4502
  return this.send(endpoint, data, { ...options, retries: retries - 1 });
4521
4503
  }
4522
4504
 
4523
- throw error;
4505
+ // For non‑network errors that made it this far, surface to callers
4506
+ if (!isNetworkError) {
4507
+ throw error;
4508
+ }
4509
+ // For network errors, fail silently after retries are exhausted
4524
4510
  }
4525
4511
  },
4526
4512
 
@@ -4546,9 +4532,12 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
4546
4532
  const transformedData = DataTransformer.toBackendFormat(sessionDataToSend);
4547
4533
 
4548
4534
  // Send to track endpoint
4535
+ // Use a more generous timeout for session tracking so requests are
4536
+ // very unlikely to be aborted under normal conditions.
4549
4537
  await this.send(CONFIG.API.TRACK, { sessionData: transformedData }, {
4550
4538
  transform: false, // Already transformed
4551
- retries: 2
4539
+ retries: 2,
4540
+ timeout: 15000
4552
4541
  });
4553
4542
  } catch (error) {
4554
4543
  console.error('❌ Error sending session data:', error);
package/lib/umd/index.js CHANGED
@@ -4306,31 +4306,6 @@
4306
4306
 
4307
4307
  };
4308
4308
 
4309
- // ============================================================================
4310
- // SECTION 13: API COMMUNICATION
4311
- // ============================================================================
4312
- // PURPOSE: Unified API client for all backend communication. Handles sending
4313
- // session data, custom events, and UTM events.
4314
- //
4315
- // KEY PRINCIPLES:
4316
- // 1. Unified API client for all endpoints
4317
- // 2. Transforms data using DataTransformer before sending
4318
- // 3. Handles retries and errors gracefully
4319
- // 4. Uses sendBeacon for beforeunload (last resort)
4320
- // 5. Uses fetch with keepalive for regular sends
4321
- // 6. Comprehensive error handling and logging
4322
- //
4323
- // BENEFITS:
4324
- // - Single place to handle all API communication
4325
- // - Consistent error handling
4326
- // - Retry logic for reliability
4327
- // - Proper use of sendBeacon vs fetch
4328
- // ============================================================================
4329
-
4330
- // Throttle network error logs (e.g. "Failed to fetch" from ad blockers) - log at most once per 30s
4331
- let _lastNetworkErrorLog = 0;
4332
- const _NETWORK_ERROR_THROTTLE_MS = 30000;
4333
-
4334
4309
  /**
4335
4310
  * APIClient - Unified API communication
4336
4311
  *
@@ -4506,17 +4481,24 @@
4506
4481
  }
4507
4482
 
4508
4483
  // Handle AbortError gracefully (timeout or page unload)
4509
- if (error.name === 'AbortError' || error.message?.includes('aborted') || error.message?.includes('signal is aborted')) {
4484
+ if (
4485
+ error.name === 'AbortError' ||
4486
+ error.message?.includes('aborted') ||
4487
+ error.message?.includes('signal is aborted')
4488
+ ) {
4510
4489
  // Don't log as error - this is expected behavior for timeouts or page unloads
4511
4490
  // Don't retry aborted requests - they were intentionally cancelled
4512
4491
  return; // Silently return, don't throw
4513
4492
  }
4514
4493
 
4515
- // Throttle "Failed to fetch" logs (common with ad blockers, CORS, network issues)
4516
- const isNetworkError = error.name === 'TypeError' && (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4517
- const now = Date.now();
4518
- if (isNetworkError && (now - _lastNetworkErrorLog) < _NETWORK_ERROR_THROTTLE_MS) ; else {
4519
- if (isNetworkError) _lastNetworkErrorLog = now;
4494
+ // Treat common network issues (ad blockers, CORS, offline, etc.) as silent failures.
4495
+ // We still retry according to the "retries" option, but we do not log these to the console.
4496
+ const isNetworkError =
4497
+ error.name === 'TypeError' &&
4498
+ (error.message === 'Failed to fetch' || error.message?.includes('fetch'));
4499
+
4500
+ // Only log unexpected / non‑network errors
4501
+ if (!isNetworkError) {
4520
4502
  console.error('❌ Error sending data:', error);
4521
4503
  }
4522
4504
 
@@ -4526,7 +4508,11 @@
4526
4508
  return this.send(endpoint, data, { ...options, retries: retries - 1 });
4527
4509
  }
4528
4510
 
4529
- throw error;
4511
+ // For non‑network errors that made it this far, surface to callers
4512
+ if (!isNetworkError) {
4513
+ throw error;
4514
+ }
4515
+ // For network errors, fail silently after retries are exhausted
4530
4516
  }
4531
4517
  },
4532
4518
 
@@ -4552,9 +4538,12 @@
4552
4538
  const transformedData = DataTransformer.toBackendFormat(sessionDataToSend);
4553
4539
 
4554
4540
  // Send to track endpoint
4541
+ // Use a more generous timeout for session tracking so requests are
4542
+ // very unlikely to be aborted under normal conditions.
4555
4543
  await this.send(CONFIG.API.TRACK, { sessionData: transformedData }, {
4556
4544
  transform: false, // Already transformed
4557
- retries: 2
4545
+ retries: 2,
4546
+ timeout: 15000
4558
4547
  });
4559
4548
  } catch (error) {
4560
4549
  console.error('❌ Error sending session data:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cryptique-sdk",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "description": "Cryptique Analytics SDK - Comprehensive web analytics and user tracking for modern web applications",
6
6
  "main": "lib/cjs/index.js",