@gomusdev/web-components 1.57.2 → 1.57.3

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.
@@ -11292,6 +11292,38 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11292
11292
  }
11293
11293
  };
11294
11294
  }
11295
+ const STORAGE_TTL_MS = 15 * 6e4;
11296
+ function isLocalStorageAvailable() {
11297
+ return typeof window !== "undefined" && typeof localStorage !== "undefined";
11298
+ }
11299
+ function saveToLocalStorage(key, data) {
11300
+ if (!isLocalStorageAvailable()) return;
11301
+ try {
11302
+ localStorage.setItem(key, JSON.stringify(data));
11303
+ } catch (e) {
11304
+ console.warn(`Failed to save to localStorage (${key}):`, e);
11305
+ }
11306
+ }
11307
+ function loadFromLocalStorage$1(key) {
11308
+ if (!isLocalStorageAvailable()) return null;
11309
+ try {
11310
+ const item = localStorage.getItem(key);
11311
+ return item ? JSON.parse(item) : null;
11312
+ } catch (e) {
11313
+ console.warn(`Failed to load from localStorage (${key}):`, e);
11314
+ return null;
11315
+ }
11316
+ }
11317
+ function removeFromLocalStorage(key) {
11318
+ if (!isLocalStorageAvailable()) return;
11319
+ try {
11320
+ localStorage.removeItem(key);
11321
+ } catch (e) {
11322
+ console.warn(`Failed to remove from localStorage (${key}):`, e);
11323
+ }
11324
+ }
11325
+ const KEY$6 = "go-cart";
11326
+ const persistCart = (items, coupons) => localStorage.setItem(KEY$6, JSON.stringify({ items, coupons, savedAt: Date.now() }));
11295
11327
  function generateCartItem(cartItem) {
11296
11328
  const type = cartItem.product.type;
11297
11329
  switch (type) {
@@ -11308,11 +11340,12 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11308
11340
  throw new Error(`Unhandled case: ${_exhaustiveCheck}`);
11309
11341
  }
11310
11342
  }
11311
- function loadFromLocalStorage$1(cart) {
11343
+ function loadFromLocalStorage(cart) {
11312
11344
  let lsItems = [];
11313
11345
  let lsCoupons = [];
11346
+ let savedAt;
11314
11347
  try {
11315
- const content = localStorage.getItem("go-cart");
11348
+ const content = localStorage.getItem(KEY$6);
11316
11349
  if (!content) return [];
11317
11350
  const parsed = JSON.parse(content);
11318
11351
  if (Array.isArray(parsed)) {
@@ -11321,10 +11354,18 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11321
11354
  } else if (typeof parsed === "object" && parsed !== null) {
11322
11355
  lsItems = parsed.items || [];
11323
11356
  lsCoupons = parsed.coupons || [];
11357
+ savedAt = parsed.savedAt;
11324
11358
  } else {
11325
11359
  console.dir({ parsed, content });
11326
11360
  throw new Error("go-cart has invalid format");
11327
11361
  }
11362
+ const expired = !!savedAt && Date.now() - savedAt > STORAGE_TTL_MS;
11363
+ if (expired) {
11364
+ cart.clearItems();
11365
+ cart.clearCoupons();
11366
+ persistCart([], []);
11367
+ return [];
11368
+ }
11328
11369
  if (lsItems.length === 0) {
11329
11370
  cart.clearItems();
11330
11371
  } else {
@@ -11335,20 +11376,20 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11335
11376
  return cart.items;
11336
11377
  } catch (e) {
11337
11378
  console.error(e);
11338
- localStorage.setItem("go-cart", JSON.stringify({ items: [], coupons: [] }));
11379
+ persistCart([], []);
11339
11380
  return [];
11340
11381
  }
11341
11382
  }
11342
11383
  function syncCartToLocalStorage(cart) {
11343
- loadFromLocalStorage$1(cart);
11384
+ loadFromLocalStorage(cart);
11344
11385
  let lastWritten = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11345
- localStorage.setItem("go-cart", lastWritten);
11386
+ persistCart(cart.items || [], cart.coupons || []);
11346
11387
  effect_root(() => {
11347
11388
  user_effect(() => {
11348
11389
  const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11349
11390
  if (content === lastWritten) return;
11350
11391
  lastWritten = content;
11351
- localStorage.setItem("go-cart", content);
11392
+ persistCart(cart.items || [], cart.coupons || []);
11352
11393
  });
11353
11394
  });
11354
11395
  }
@@ -11443,47 +11484,24 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11443
11484
  dispatchCartEvents(cart);
11444
11485
  return cart;
11445
11486
  }
11446
- function isLocalStorageAvailable() {
11447
- return typeof window !== "undefined" && typeof localStorage !== "undefined";
11448
- }
11449
- function saveToLocalStorage(key, data) {
11450
- if (!isLocalStorageAvailable()) return;
11451
- try {
11452
- localStorage.setItem(key, JSON.stringify(data));
11453
- } catch (e) {
11454
- console.warn(`Failed to save to localStorage (${key}):`, e);
11455
- }
11456
- }
11457
- function loadFromLocalStorage(key) {
11458
- if (!isLocalStorageAvailable()) return null;
11459
- try {
11460
- const item = localStorage.getItem(key);
11461
- return item ? JSON.parse(item) : null;
11462
- } catch (e) {
11463
- console.warn(`Failed to load from localStorage (${key}):`, e);
11464
- return null;
11465
- }
11466
- }
11467
- function removeFromLocalStorage(key) {
11468
- if (!isLocalStorageAvailable()) return;
11469
- try {
11470
- localStorage.removeItem(key);
11471
- } catch (e) {
11472
- console.warn(`Failed to remove from localStorage (${key}):`, e);
11473
- }
11474
- }
11475
11487
  const KEY$5 = "go-capacity";
11476
11488
  function saveCapacityToLocalStorage(allSeats, allQuotas) {
11477
- const existing = loadFromLocalStorage(KEY$5);
11489
+ const existing = loadFromLocalStorage$1(KEY$5);
11478
11490
  const merged = {
11479
11491
  allSeats: { ...existing?.allSeats || {}, ...allSeats },
11480
- allQuotas: { ...existing?.allQuotas || {}, ...allQuotas }
11492
+ allQuotas: { ...existing?.allQuotas || {}, ...allQuotas },
11493
+ savedAt: Date.now()
11481
11494
  };
11482
11495
  saveToLocalStorage(KEY$5, merged);
11483
11496
  }
11484
11497
  function loadCapacityFromLocalStorage(manager) {
11485
- const data = loadFromLocalStorage(KEY$5);
11498
+ const data = loadFromLocalStorage$1(KEY$5);
11486
11499
  if (!data) return;
11500
+ const expired = !data.savedAt || Date.now() - data.savedAt > STORAGE_TTL_MS;
11501
+ if (expired) {
11502
+ removeFromLocalStorage(KEY$5);
11503
+ return;
11504
+ }
11487
11505
  if (data.allSeats) {
11488
11506
  for (const dateId in data.allSeats) {
11489
11507
  const did = parseInt(dateId);
@@ -11501,7 +11519,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11501
11519
  loadCapacityFromLocalStorage(manager);
11502
11520
  }
11503
11521
  if (event2.key === "go-cart") {
11504
- const cart = loadFromLocalStorage("go-cart");
11522
+ const cart = loadFromLocalStorage$1("go-cart");
11505
11523
  const cartEmpty = !cart || !cart.items || cart.items.length === 0;
11506
11524
  if (cartEmpty) removeFromLocalStorage(KEY$5);
11507
11525
  }
@@ -11292,6 +11292,38 @@ function createCartItem(product, options) {
11292
11292
  }
11293
11293
  };
11294
11294
  }
11295
+ const STORAGE_TTL_MS = 15 * 6e4;
11296
+ function isLocalStorageAvailable() {
11297
+ return typeof window !== "undefined" && typeof localStorage !== "undefined";
11298
+ }
11299
+ function saveToLocalStorage(key, data) {
11300
+ if (!isLocalStorageAvailable()) return;
11301
+ try {
11302
+ localStorage.setItem(key, JSON.stringify(data));
11303
+ } catch (e) {
11304
+ console.warn(`Failed to save to localStorage (${key}):`, e);
11305
+ }
11306
+ }
11307
+ function loadFromLocalStorage$1(key) {
11308
+ if (!isLocalStorageAvailable()) return null;
11309
+ try {
11310
+ const item = localStorage.getItem(key);
11311
+ return item ? JSON.parse(item) : null;
11312
+ } catch (e) {
11313
+ console.warn(`Failed to load from localStorage (${key}):`, e);
11314
+ return null;
11315
+ }
11316
+ }
11317
+ function removeFromLocalStorage(key) {
11318
+ if (!isLocalStorageAvailable()) return;
11319
+ try {
11320
+ localStorage.removeItem(key);
11321
+ } catch (e) {
11322
+ console.warn(`Failed to remove from localStorage (${key}):`, e);
11323
+ }
11324
+ }
11325
+ const KEY$6 = "go-cart";
11326
+ const persistCart = (items, coupons) => localStorage.setItem(KEY$6, JSON.stringify({ items, coupons, savedAt: Date.now() }));
11295
11327
  function generateCartItem(cartItem) {
11296
11328
  const type = cartItem.product.type;
11297
11329
  switch (type) {
@@ -11308,11 +11340,12 @@ function generateCartItem(cartItem) {
11308
11340
  throw new Error(`Unhandled case: ${_exhaustiveCheck}`);
11309
11341
  }
11310
11342
  }
11311
- function loadFromLocalStorage$1(cart) {
11343
+ function loadFromLocalStorage(cart) {
11312
11344
  let lsItems = [];
11313
11345
  let lsCoupons = [];
11346
+ let savedAt;
11314
11347
  try {
11315
- const content = localStorage.getItem("go-cart");
11348
+ const content = localStorage.getItem(KEY$6);
11316
11349
  if (!content) return [];
11317
11350
  const parsed = JSON.parse(content);
11318
11351
  if (Array.isArray(parsed)) {
@@ -11321,10 +11354,18 @@ function loadFromLocalStorage$1(cart) {
11321
11354
  } else if (typeof parsed === "object" && parsed !== null) {
11322
11355
  lsItems = parsed.items || [];
11323
11356
  lsCoupons = parsed.coupons || [];
11357
+ savedAt = parsed.savedAt;
11324
11358
  } else {
11325
11359
  console.dir({ parsed, content });
11326
11360
  throw new Error("go-cart has invalid format");
11327
11361
  }
11362
+ const expired = !!savedAt && Date.now() - savedAt > STORAGE_TTL_MS;
11363
+ if (expired) {
11364
+ cart.clearItems();
11365
+ cart.clearCoupons();
11366
+ persistCart([], []);
11367
+ return [];
11368
+ }
11328
11369
  if (lsItems.length === 0) {
11329
11370
  cart.clearItems();
11330
11371
  } else {
@@ -11335,20 +11376,20 @@ function loadFromLocalStorage$1(cart) {
11335
11376
  return cart.items;
11336
11377
  } catch (e) {
11337
11378
  console.error(e);
11338
- localStorage.setItem("go-cart", JSON.stringify({ items: [], coupons: [] }));
11379
+ persistCart([], []);
11339
11380
  return [];
11340
11381
  }
11341
11382
  }
11342
11383
  function syncCartToLocalStorage(cart) {
11343
- loadFromLocalStorage$1(cart);
11384
+ loadFromLocalStorage(cart);
11344
11385
  let lastWritten = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11345
- localStorage.setItem("go-cart", lastWritten);
11386
+ persistCart(cart.items || [], cart.coupons || []);
11346
11387
  effect_root(() => {
11347
11388
  user_effect(() => {
11348
11389
  const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11349
11390
  if (content === lastWritten) return;
11350
11391
  lastWritten = content;
11351
- localStorage.setItem("go-cart", content);
11392
+ persistCart(cart.items || [], cart.coupons || []);
11352
11393
  });
11353
11394
  });
11354
11395
  }
@@ -11443,47 +11484,24 @@ function createMainCart() {
11443
11484
  dispatchCartEvents(cart);
11444
11485
  return cart;
11445
11486
  }
11446
- function isLocalStorageAvailable() {
11447
- return typeof window !== "undefined" && typeof localStorage !== "undefined";
11448
- }
11449
- function saveToLocalStorage(key, data) {
11450
- if (!isLocalStorageAvailable()) return;
11451
- try {
11452
- localStorage.setItem(key, JSON.stringify(data));
11453
- } catch (e) {
11454
- console.warn(`Failed to save to localStorage (${key}):`, e);
11455
- }
11456
- }
11457
- function loadFromLocalStorage(key) {
11458
- if (!isLocalStorageAvailable()) return null;
11459
- try {
11460
- const item = localStorage.getItem(key);
11461
- return item ? JSON.parse(item) : null;
11462
- } catch (e) {
11463
- console.warn(`Failed to load from localStorage (${key}):`, e);
11464
- return null;
11465
- }
11466
- }
11467
- function removeFromLocalStorage(key) {
11468
- if (!isLocalStorageAvailable()) return;
11469
- try {
11470
- localStorage.removeItem(key);
11471
- } catch (e) {
11472
- console.warn(`Failed to remove from localStorage (${key}):`, e);
11473
- }
11474
- }
11475
11487
  const KEY$5 = "go-capacity";
11476
11488
  function saveCapacityToLocalStorage(allSeats, allQuotas) {
11477
- const existing = loadFromLocalStorage(KEY$5);
11489
+ const existing = loadFromLocalStorage$1(KEY$5);
11478
11490
  const merged = {
11479
11491
  allSeats: { ...existing?.allSeats || {}, ...allSeats },
11480
- allQuotas: { ...existing?.allQuotas || {}, ...allQuotas }
11492
+ allQuotas: { ...existing?.allQuotas || {}, ...allQuotas },
11493
+ savedAt: Date.now()
11481
11494
  };
11482
11495
  saveToLocalStorage(KEY$5, merged);
11483
11496
  }
11484
11497
  function loadCapacityFromLocalStorage(manager) {
11485
- const data = loadFromLocalStorage(KEY$5);
11498
+ const data = loadFromLocalStorage$1(KEY$5);
11486
11499
  if (!data) return;
11500
+ const expired = !data.savedAt || Date.now() - data.savedAt > STORAGE_TTL_MS;
11501
+ if (expired) {
11502
+ removeFromLocalStorage(KEY$5);
11503
+ return;
11504
+ }
11487
11505
  if (data.allSeats) {
11488
11506
  for (const dateId in data.allSeats) {
11489
11507
  const did = parseInt(dateId);
@@ -11501,7 +11519,7 @@ function syncCapacityAcrossTabs(manager) {
11501
11519
  loadCapacityFromLocalStorage(manager);
11502
11520
  }
11503
11521
  if (event2.key === "go-cart") {
11504
- const cart = loadFromLocalStorage("go-cart");
11522
+ const cart = loadFromLocalStorage$1("go-cart");
11505
11523
  const cartEmpty = !cart || !cart.items || cart.items.length === 0;
11506
11524
  if (cartEmpty) removeFromLocalStorage(KEY$5);
11507
11525
  }
@@ -1,3 +1,4 @@
1
+ export declare const STORAGE_TTL_MS: number;
1
2
  export declare function isLocalStorageAvailable(): boolean;
2
3
  export declare function saveToLocalStorage(key: string, data: any): void;
3
4
  export declare function loadFromLocalStorage<T>(key: string): T | null;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Giantmonkey GmbH"
5
5
  },
6
6
  "license": "MIT",
7
- "version": "1.57.2",
7
+ "version": "1.57.3",
8
8
  "type": "module",
9
9
  "main": "./dist-js/gomus-webcomponents.iife.js",
10
10
  "module": "./dist-js/gomus-webcomponents.iife.js",