ui.shipaid.com 0.3.181 → 0.3.183

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/dist/widget.es.js CHANGED
@@ -3722,21 +3722,63 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3722
3722
  console.error("Error during the query ====>", error);
3723
3723
  }
3724
3724
  }
3725
- _getProductFieldFromCookie(handle, field) {
3726
- const cookieName = `${handle}-${field}`;
3727
- const cookie = document.cookie.split("; ").find((row) => row.startsWith(cookieName + "="));
3728
- if (!cookie) return null;
3725
+ // Get cached product field from Session
3726
+ _getProductFieldFromStorage(handle, field) {
3727
+ const storageKey = `shipaid_product_${handle}_${field}`;
3729
3728
  try {
3730
- return decodeURIComponent(cookie.split("=")[1]);
3731
- } catch {
3729
+ return sessionStorage.getItem(storageKey);
3730
+ } catch (e3) {
3731
+ console.warn("[ShipAid] Failed to read from sessionStorage:", e3);
3732
3732
  return null;
3733
3733
  }
3734
3734
  }
3735
- _storeProductFieldInCookie(handle, field, val) {
3736
- const cookieName = `${handle}-${field}`;
3737
- const expires = /* @__PURE__ */ new Date();
3738
- expires.setDate(expires.getDate() + 1);
3739
- document.cookie = `${cookieName}=${encodeURIComponent(val)}; path=/; expires=${expires.toUTCString()}`;
3735
+ // Store product field in Session
3736
+ _storeProductFieldInStorage(handle, field, val) {
3737
+ const storageKey = `shipaid_product_${handle}_${field}`;
3738
+ try {
3739
+ sessionStorage.setItem(storageKey, val);
3740
+ } catch (e3) {
3741
+ console.warn("[ShipAid] SessionStorage full, attempting cleanup");
3742
+ this._cleanupOldProductCache();
3743
+ try {
3744
+ sessionStorage.setItem(storageKey, val);
3745
+ } catch (retryError) {
3746
+ console.error("[ShipAid] Failed to store product data after cleanup");
3747
+ }
3748
+ }
3749
+ }
3750
+ // Cleanup old product cache entries from Session
3751
+ _cleanupOldProductCache() {
3752
+ try {
3753
+ const keys = Object.keys(sessionStorage);
3754
+ const shipaidKeys = keys.filter((k2) => k2.startsWith("shipaid_product_"));
3755
+ const keysToRemove = shipaidKeys.slice(0, Math.floor(shipaidKeys.length / 4));
3756
+ keysToRemove.forEach((key) => {
3757
+ try {
3758
+ sessionStorage.removeItem(key);
3759
+ } catch (e3) {
3760
+ }
3761
+ });
3762
+ console.log(`[ShipAid] Cleaned up ${keysToRemove.length} cached product entries`);
3763
+ } catch (e3) {
3764
+ console.error("[ShipAid] Failed to cleanup product cache:", e3);
3765
+ }
3766
+ }
3767
+ // Migrate product data from cookies to Session
3768
+ _migrateFromCookiesToSessionStorage() {
3769
+ try {
3770
+ document.cookie.split(";").forEach((c2) => {
3771
+ const cookieName = c2.split("=")[0].trim();
3772
+ if (cookieName.endsWith("-tags") || cookieName.endsWith("-virtual") || cookieName.includes("product_tags") || cookieName.startsWith("shipaid_")) {
3773
+ document.cookie = `${cookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;`;
3774
+ document.cookie = `${cookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/cart;`;
3775
+ document.cookie = `${cookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;`;
3776
+ }
3777
+ });
3778
+ console.log("[ShipAid] Successfully migrated from cookies to sessionStorage");
3779
+ } catch (e3) {
3780
+ console.error("[ShipAid] Error during cookie cleanup:", e3);
3781
+ }
3740
3782
  }
3741
3783
  async _fetchProductJSON(handle) {
3742
3784
  try {
@@ -3764,8 +3806,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3764
3806
  const cart = await this._fetch.get("/cart.js");
3765
3807
  if (cart && cart.items) {
3766
3808
  for (const item of cart.items) {
3767
- const cachedProductTags = this._getProductFieldFromCookie(item.handle, "tags");
3768
- const isVirtualProduct = this._getProductFieldFromCookie(item.handle, "virtual");
3809
+ const cachedProductTags = this._getProductFieldFromStorage(item.handle, "tags");
3810
+ const isVirtualProduct = this._getProductFieldFromStorage(item.handle, "virtual");
3769
3811
  if (cachedProductTags || isVirtualProduct) {
3770
3812
  item.tags = (cachedProductTags || "").split(",").map((t2) => t2.trim());
3771
3813
  if (isVirtualProduct) {
@@ -3777,13 +3819,13 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3777
3819
  if (product) {
3778
3820
  if (product.tags) {
3779
3821
  item.tags = (product.tags || "").split(",").map((t2) => t2.trim());
3780
- this._storeProductFieldInCookie(item.handle, "tags", product.tags);
3822
+ this._storeProductFieldInStorage(item.handle, "tags", product.tags);
3781
3823
  }
3782
3824
  item.isVirtualProduct = (product.variants || []).every(
3783
3825
  (variant) => !variant.requires_shipping
3784
3826
  );
3785
3827
  if (item.isVirtualProduct) {
3786
- this._storeProductFieldInCookie(item.handle, "virtual", "yes");
3828
+ this._storeProductFieldInStorage(item.handle, "virtual", "yes");
3787
3829
  }
3788
3830
  }
3789
3831
  }
@@ -3884,8 +3926,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3884
3926
  cart = await this._fetch.post("/cart/add.js", payload);
3885
3927
  if (cart && cart.items) {
3886
3928
  for (const item of cart.items) {
3887
- const cachedProductTags = this._getProductFieldFromCookie(item.handle, "tags");
3888
- const isVirtualProduct = this._getProductFieldFromCookie(item.handle, "virtual");
3929
+ const cachedProductTags = this._getProductFieldFromStorage(item.handle, "tags");
3930
+ const isVirtualProduct = this._getProductFieldFromStorage(item.handle, "virtual");
3889
3931
  if (cachedProductTags || isVirtualProduct) {
3890
3932
  item.tags = (cachedProductTags || "").split(",").map((t2) => t2.trim());
3891
3933
  if (isVirtualProduct) {
@@ -3897,13 +3939,13 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3897
3939
  if (product) {
3898
3940
  if (product.tags) {
3899
3941
  item.tags = (product.tags || "").split(",").map((t2) => t2.trim());
3900
- this._storeProductFieldInCookie(item.handle, "tags", product.tags);
3942
+ this._storeProductFieldInStorage(item.handle, "tags", product.tags);
3901
3943
  }
3902
3944
  item.isVirtualProduct = (product.variants || []).every(
3903
3945
  (variant) => !variant.requires_shipping
3904
3946
  );
3905
3947
  if (item.isVirtualProduct) {
3906
- this._storeProductFieldInCookie(item.handle, "virtual", "yes");
3948
+ this._storeProductFieldInStorage(item.handle, "virtual", "yes");
3907
3949
  }
3908
3950
  }
3909
3951
  }
@@ -3943,8 +3985,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3943
3985
  cart = await this._fetch.post("/cart/change.js", payload);
3944
3986
  if (cart && cart.items) {
3945
3987
  for (const item of cart.items) {
3946
- const cachedProductTags = this._getProductFieldFromCookie(item.handle, "tags");
3947
- const isVirtualProduct = this._getProductFieldFromCookie(item.handle, "virtual");
3988
+ const cachedProductTags = this._getProductFieldFromStorage(item.handle, "tags");
3989
+ const isVirtualProduct = this._getProductFieldFromStorage(item.handle, "virtual");
3948
3990
  if (cachedProductTags || isVirtualProduct) {
3949
3991
  item.tags = (cachedProductTags || "").split(",").map((t2) => t2.trim());
3950
3992
  if (isVirtualProduct) {
@@ -3956,13 +3998,13 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
3956
3998
  if (product) {
3957
3999
  if (product.tags) {
3958
4000
  item.tags = (product.tags || "").split(",").map((t2) => t2.trim());
3959
- this._storeProductFieldInCookie(item.handle, "tags", product.tags);
4001
+ this._storeProductFieldInStorage(item.handle, "tags", product.tags);
3960
4002
  }
3961
4003
  item.isVirtualProduct = (product.variants || []).every(
3962
4004
  (variant) => !variant.requires_shipping
3963
4005
  );
3964
4006
  if (item.isVirtualProduct) {
3965
- this._storeProductFieldInCookie(item.handle, "virtual", "yes");
4007
+ this._storeProductFieldInStorage(item.handle, "virtual", "yes");
3966
4008
  }
3967
4009
  }
3968
4010
  }
@@ -4355,17 +4397,19 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
4355
4397
  return null;
4356
4398
  }
4357
4399
  _renderBenefitsSection(isGreenProtectionEnabled, isFreeGiftEnabled) {
4400
+ var _a, _b;
4401
+ const benefitsStyles = ((_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.benefitsStyles) || {};
4358
4402
  return x`
4359
- <div class="shipaid-benefits-container ${this._isBenefitsOpen ? "open" : ""}">
4360
- <div class="shipaid-benefits">
4361
- <div class="shipaid-benefits__header">
4362
- <span>${translate("plus.benefits.title")}</span>
4403
+ <div class="shipaid-benefits-container ${this._isBenefitsOpen ? "open" : ""}" style="${(benefitsStyles == null ? void 0 : benefitsStyles.container) || ""}">
4404
+ <div class="shipaid-benefits" style="${(benefitsStyles == null ? void 0 : benefitsStyles.benefits) || ""}">
4405
+ <div class="shipaid-benefits__header" style="${(benefitsStyles == null ? void 0 : benefitsStyles.header) || ""}">
4406
+ <span style="${(benefitsStyles == null ? void 0 : benefitsStyles.title) || ""}">${translate("plus.benefits.title")}</span>
4363
4407
  <a href="#" class="shipaid-benefits__link" @click=${this._handleSeeDetails}>${translate("plus.see-details")}</a>
4364
4408
  </div>
4365
- <ul>
4366
- <li>${ProtectedIcon}${translate("plus.benefits.protected")}</li>
4367
- ${isFreeGiftEnabled ? x`<li>${GiftIcon}${translate("plus.benefits.free-gift")}</li>` : A}
4368
- ${isGreenProtectionEnabled ? x`<li>${TreeIcon}${translate("plus.benefits.tree")}</li>` : A}
4409
+ <ul style="${(benefitsStyles == null ? void 0 : benefitsStyles.list) || ""}">
4410
+ <li style="${(benefitsStyles == null ? void 0 : benefitsStyles.item) || ""}">${ProtectedIcon}${translate("plus.benefits.protected")}</li>
4411
+ ${isFreeGiftEnabled ? x`<li style="${(benefitsStyles == null ? void 0 : benefitsStyles.item) || ""}">${GiftIcon}${translate("plus.benefits.free-gift")}</li>` : A}
4412
+ ${isGreenProtectionEnabled ? x`<li style="${(benefitsStyles == null ? void 0 : benefitsStyles.item) || ""}">${TreeIcon}${translate("plus.benefits.tree")}</li>` : A}
4369
4413
  </ul>
4370
4414
  </div>
4371
4415
  </div>
@@ -4669,7 +4713,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
4669
4713
  */
4670
4714
  _renderDefaultCheckoutButton(originalClasses, protectionPrice, cartTotal, isGreenProtectionEnabled, isFreeGiftEnabled, impactActive, loading2) {
4671
4715
  var _a, _b, _c, _d, _e, _f, _g, _h;
4672
- const { logo, title: title2 = "", linkContinueText } = ((_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.checkoutPlus) || { logo: null, title: null, linkContinueText: null };
4716
+ const { logo, title: title2 = "", checkoutText, linkContinueText } = ((_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.checkoutPlus) || { logo: null, title: null, checkoutText: null, linkContinueText: null };
4673
4717
  return x`
4674
4718
  <style>
4675
4719
  :host {
@@ -4892,8 +4936,9 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
4892
4936
  window.location.href = `/checkout?attributes[_shipaid-internal]=1&updates[${(_b2 = this._protectionVariant) == null ? void 0 : _b2.id}]=1`;
4893
4937
  }}
4894
4938
  >
4895
- ${this.buttonTitle || x`<slot name="checkout-button-text">CHECKOUT+</slot>
4896
- ${cartTotal ? this._currencyFormat(cartTotal) : loading2}`}
4939
+ ${this.buttonTitle || (checkoutText ? x`<span>${checkoutText}</span>
4940
+ ${cartTotal ? this._currencyFormat(cartTotal) : loading2}` : x`<slot name="checkout-button-text">CHECKOUT+</slot>
4941
+ ${cartTotal ? this._currencyFormat(cartTotal) : loading2}`)}
4897
4942
  </button>
4898
4943
  ` : x`
4899
4944
  <a
@@ -5318,15 +5363,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
5318
5363
  render() {
5319
5364
  useOnce(this, async () => {
5320
5365
  var _a, _b, _c, _d, _e, _f;
5321
- (() => {
5322
- document.cookie.split(";").forEach(function(c2) {
5323
- const n2 = c2.split("=")[0].trim();
5324
- if (n2.endsWith("product_tags")) {
5325
- document.cookie = n2 + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
5326
- document.cookie = n2 + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
5327
- }
5328
- });
5329
- })();
5366
+ this._migrateFromCookiesToSessionStorage();
5330
5367
  const linkEl = document.createElement("link");
5331
5368
  linkEl.setAttribute(
5332
5369
  "href",