@datalyr/web 1.6.0 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @datalyr/web v1.6.0
2
+ * @datalyr/web v1.6.2
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2026 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -243,15 +243,21 @@ class SafeStorage {
243
243
  this.prefix = 'dl_';
244
244
  // Test if storage is available
245
245
  try {
246
+ if (!storage)
247
+ throw new Error('no storage'); // server / SSR
246
248
  const testKey = 'dl_test__' + Math.random();
247
249
  storage.setItem(testKey, '1');
248
250
  storage.removeItem(testKey);
249
251
  this.storage = storage;
250
252
  }
251
253
  catch (_a) {
252
- // Storage not available (Safari private mode, etc.)
254
+ // Storage not available (server-side render, Safari private mode, etc.)
253
255
  this.storage = null;
254
- console.warn('[Datalyr] Storage not available, using memory fallback');
256
+ // Only warn in the browser on the server there's intentionally no
257
+ // storage and the SDK does no real work until init() runs client-side.
258
+ if (typeof window !== 'undefined') {
259
+ console.warn('[Datalyr] Storage not available, using memory fallback');
260
+ }
255
261
  }
256
262
  }
257
263
  get(key, defaultValue = null) {
@@ -560,9 +566,16 @@ class CookieStorage {
560
566
  return '';
561
567
  }
562
568
  }
563
- // Export singleton instances for storage
564
- const storage = new SafeStorage(window.localStorage);
565
- new SafeStorage(window.sessionStorage);
569
+ // Export singleton instances for storage.
570
+ // Guard the browser globals so importing the SDK on the server (SSR / Node)
571
+ // doesn't throw `window is not defined`. On the server these fall back to
572
+ // in-memory storage; real storage is wired when the module re-evaluates in the
573
+ // browser. (Without this, any static `import` of the SDK in a Next.js client
574
+ // component crashes server rendering.)
575
+ const browserLocalStorage = typeof window !== 'undefined' ? window.localStorage : undefined;
576
+ const browserSessionStorage = typeof window !== 'undefined' ? window.sessionStorage : undefined;
577
+ const storage = new SafeStorage(browserLocalStorage);
578
+ new SafeStorage(browserSessionStorage);
566
579
  // Default cookie instance for backwards compatibility
567
580
  const cookies = new CookieStorage();
568
581
 
@@ -4319,5 +4332,5 @@ if (typeof window !== 'undefined') {
4319
4332
  window.datalyr = datalyr;
4320
4333
  }
4321
4334
 
4322
- export { datalyr as default };
4335
+ export { datalyr, datalyr as default };
4323
4336
  //# sourceMappingURL=datalyr.esm.js.map