@shoppexio/storefront 1.0.101 → 1.0.102

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/index.js CHANGED
@@ -2663,6 +2663,16 @@ function isSafeHttpsRedirectTemplateUrl(url) {
2663
2663
  }
2664
2664
  }
2665
2665
 
2666
+ // ../contracts/src/storefront-consent-choice.ts
2667
+ var COOKIE_CONSENT_VERSION = 1;
2668
+ var COOKIE_CONSENT_COOKIE = "shoppex_consent";
2669
+ var COOKIE_CONSENT_CHECKOUT_HASH_KEY = "shoppex_consent";
2670
+ var COOKIE_CONSENT_VALUE = new RegExp(`^v${COOKIE_CONSENT_VERSION}\\.f([01])\\.a([01])\\.m([01])$`);
2671
+ function parseCookieConsentValue(value) {
2672
+ const match = value ? COOKIE_CONSENT_VALUE.exec(value) : null;
2673
+ return match ? { functional: match[1] === "1", analytics: match[2] === "1", marketing: match[3] === "1" } : null;
2674
+ }
2675
+
2666
2676
  // ../sdk/src/modules/checkout.ts
2667
2677
  var CheckoutCreateError = class _CheckoutCreateError extends Error {
2668
2678
  constructor(message, options = {}) {
@@ -2827,10 +2837,16 @@ function buildCheckoutUrlFromInvoiceId(checkoutBaseUrl, invoiceId) {
2827
2837
  return null;
2828
2838
  }
2829
2839
  }
2840
+ function readStorefrontConsentValue() {
2841
+ if (typeof document === "undefined" || typeof document.cookie !== "string") return null;
2842
+ const value = document.cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(`${COOKIE_CONSENT_COOKIE}=`))?.slice(COOKIE_CONSENT_COOKIE.length + 1);
2843
+ return parseCookieConsentValue(value) ? value : null;
2844
+ }
2830
2845
  function appendCheckoutUrlOptions(checkoutUrl, options) {
2831
2846
  const normalizedEmail = normalizeEmail(options.email);
2832
2847
  const normalizedLocale = typeof options.locale === "string" ? options.locale.trim() : "";
2833
- if (!normalizedEmail && !normalizedLocale) {
2848
+ const consent = readStorefrontConsentValue();
2849
+ if (!normalizedEmail && !normalizedLocale && !consent) {
2834
2850
  return checkoutUrl;
2835
2851
  }
2836
2852
  try {
@@ -2838,9 +2854,10 @@ function appendCheckoutUrlOptions(checkoutUrl, options) {
2838
2854
  if (normalizedLocale) {
2839
2855
  parsedCheckoutUrl.searchParams.set("locale", normalizedLocale);
2840
2856
  }
2841
- if (normalizedEmail) {
2857
+ if (normalizedEmail || consent) {
2842
2858
  const hashParams = new URLSearchParams(parsedCheckoutUrl.hash.startsWith("#") ? parsedCheckoutUrl.hash.slice(1) : parsedCheckoutUrl.hash);
2843
- hashParams.set(CHECKOUT_PREFILL_EMAIL_HASH_KEY, normalizedEmail);
2859
+ if (normalizedEmail) hashParams.set(CHECKOUT_PREFILL_EMAIL_HASH_KEY, normalizedEmail);
2860
+ if (consent) hashParams.set(COOKIE_CONSENT_CHECKOUT_HASH_KEY, consent);
2844
2861
  parsedCheckoutUrl.hash = hashParams.toString();
2845
2862
  }
2846
2863
  return parsedCheckoutUrl.toString();