@revley/sandbox-checkout-package 0.3.2 → 0.3.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.
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var H=(c,l,p,y)=>{if(l&&typeof l=="object"||typeof l=="function")for(let d of U(l))!x.call(c,d)&&d!==p&&P(c,d,{get:()=>l[d],enumerable:!(y=M(l,d))||y.enumerable});return c};var j=c=>H(P({},"__esModule",{value:!0}),c);var N={};module.exports=j(N);var B=(c,l)=>{var R,T;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let p=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],y=!1,d=(...t)=>y?console.debug("[checkout-intercept]",...t):void 0,S=t=>t.replace(/\/+$/,""),A=t=>t.endsWith(".myshopify.com")||t===location.hostname;function w(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function m(t){let e=w(t);if(!e||!A(e.hostname))return!1;let r=S(e.pathname),n=p.some(i=>i.test(r));return n&&d("detected checkout-like URL:",String(e)),n}function C(t){let e=t==null?void 0:t.getAttribute("variant-params");if(!e)return null;let r=e.includes(""")?e.replace(/"/g,'"'):e;try{let n=JSON.parse(r);return Array.isArray(n)?n:null}catch{return null}}async function I(t,e=1){let r=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!r.ok){let n=await r.text().catch(()=>"");throw new Error(`cart/add.js failed (${r.status}): ${n}`)}return r.json()}async function g(){let e=await(await fetch("/cart.js")).json(),r={},n=["_fbp","_fbc","_fbq","_ig_","_igbp","_igshid","_igsh","_ig_visitor_id","_gclid","_gcl_au","_gcl_aw","_gcl_dc","_gcl_gb","_ttp","_tt_enable_cookie","_scid","_sctr","_pin_unauth","_pin_id","_twitter_ads_id","_li_ss","_uetsid","_uetvid","_amzn","_amzn_ads_","_yclid","_ycl_","_rdt_uid","_quora_","_tb_","_ob_","_criteo_","_adobe_","_ttd_","_dv360_","_fbcv","_shopify_pixel_"],i=_=>n.some(h=>_===h||_.startsWith(h)||_.includes(h));document.cookie&&document.cookie.split(";").forEach(_=>{let h=_.trim();if(h){let[b,...O]=h.split("="),E=O.join("=");b&&E&&i(b)&&(r[b]=E)}});let o=`gid://shopify/Cart/${e.token}`,a=await(await fetch(`${l}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:c,cartId:o,cookies:r})})).text();if(console.log("checkoutUrl",a),!a){console.error("No checkout ID received from backend");return}let f=w(a);if(!f){console.error("Invalid checkout URL received from backend:",a);return}sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(f.href)}let v=!1;function s(t){return v||!m(t)?!1:(v=!0,g(),!0)}if(window.__isCheckoutLike=m,window.__maybeRedirect=s,(R=window.Shopify)!=null&&R.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())});{let t=window.location,e=t.assign.bind(t),r=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:n=>{s(n)||e(n)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:n=>{s(n)||r(n)},writable:!0,configurable:!0})}catch(n){d("Could not override location methods, relying on Service Worker:",n)}}{let t=window.open;window.open=function(e,r,n){return e&&s(e)?null:t.call(window,e,r,n)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(r,n,i){if(!(i!=null&&s(i)))return t(r,n,i)},history.replaceState=function(r,n,i){if(!(i!=null&&s(i)))return e(r,n,i)},addEventListener("popstate",()=>void s(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let r=e;if(r.defaultPrevented||t(r))return;let n=e.target;for(;n&&n.nodeType===1&&n.tagName!=="A";)n=n.parentElement;let i=n;!i||!i.href||m(i.href)&&(r.preventDefault(),r.stopPropagation(),g())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(k(this))return t.call(this);let r=this.getAttribute("action")||"";if(s(r)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&s("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let r=e.target;if(k(r))return;let n=(r==null?void 0:r.getAttribute("action"))||"",i=Array.from((r==null?void 0:r.elements)||[]);(m(n)||i.some(o=>(o==null?void 0:o.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),g())}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,s(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(r,n,i,o,u){try{typeof n=="string"&&m(n)&&s(n)}catch{}return t.call(this,r,n,!!i,o,u)}}{let t=window.fetch.bind(window);window.fetch=function(r,n){try{let i=typeof r=="string"||r instanceof URL?String(r):r.url;i&&m(i)&&s(i)}catch{}return t(r,n)}}let k=t=>t?Array.from(t.elements).some(e=>{var n,i;let r=e;return((n=r.name)==null?void 0:n.includes("__kaching_bundles"))||((i=r.name)==null?void 0:i.includes("kaching"))||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{var i,o,u;let e=t.target,r=(i=e==null?void 0:e.closest)==null?void 0:i.call(e,"button.shopify-payment-button__button");if(!r)return;let n=r.closest("shopify-accelerated-checkout");if(n){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let a=C(n),f=(u=(o=a==null?void 0:a[0])==null?void 0:o.id)!=null?u:51504147202335;if(!f)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch{console.log("Failed to prevent upcart from opening")}await I(f,1),await g()}catch(a){console.error("Intercepted Buy It Now failed; falling back:",a),window.location.assign("/checkout")}}},!0);{let t={},e;(T=window.kachingCartApi)!=null&&T.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(r,n){return n==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(o=>{var a;o.disabled=!0,o.style.pointerEvents="none",o.style.opacity="0.5";let u=o.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(a=o.parentNode)==null||a.replaceChild(u,o)}),e&&await e.apply(this,i),await Promise.all([new Promise(o=>setTimeout(o,1e4)),g()]),new Error("STOP")}:r[n]},set(r,n,i){return n==="updateTieredPromotionsBar"&&(e=i,d("Kaching updateTieredPromotionsBar captured")),r[n]=i,!0}})}function L(){var r;let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(n=>n.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",g()}),(r=t.parentNode)==null||r.replaceChild(e,t)}L(),new MutationObserver(()=>L()).observe(document.body,{childList:!0,subtree:!0})},q=()=>{let c=document.currentScript;if(!c)return;let l=c.dataset.revleyStoreId,p=c.dataset.revleyCheckoutHost;l&&p&&B(l,p)};q();
1
+ "use strict";var j=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,d,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==d&&j(o,m,{get:()=>l[m],enumerable:!(f=F(l,m))||f.enumerable});return o};var X=o=>W(j({},"__esModule",{value:!0}),o);var Q={};module.exports=X(Q);var h=o=>(o!=null?o:0)/100,J=o=>((o!=null?o:0)/100).toFixed(2);function B(o){return o.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#0*39;|&apos;/g,"'").replace(/&#(\d+);/g,(l,d)=>String.fromCodePoint(Number(d))).replace(/&#x([0-9a-f]+);/gi,(l,d)=>String.fromCodePoint(parseInt(d,16))).replace(/&amp;/g,"&")}function N(o){var m,g,k,M;let l=((m=o.items)!=null?m:[]).map(s=>{var b,C,A,E,U,T,L,x,O,H,S,_,P,u,I,R,D;let a=s.selling_plan_allocation,w=(b=s.line_level_discount_allocations)!=null?b:[];return{variantId:(C=s.variant_id)!=null?C:0,key:(E=s.key)!=null?E:String((A=s.variant_id)!=null?A:""),quantity:(U=s.quantity)!=null?U:0,productTitle:B((L=(T=s.product_title)!=null?T:s.title)!=null?L:""),variantTitle:s.variant_title?B(s.variant_title):void 0,price:J(s.price),image:(H=(O=(x=s.featured_image)==null?void 0:x.url)!=null?O:s.image)!=null?H:void 0,unitPrice:h(s.price),totalPrice:h((S=s.original_line_price)!=null?S:s.line_price),lineTotalAfterDiscounts:h((_=s.final_line_price)!=null?_:s.line_price),totalDiscountAllocated:h(s.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?h(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?h(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(y=>{var t,e,n;return{title:B((e=(t=y.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:h(y.amount),code:((n=y.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:B((P=a.selling_plan.name)!=null?P:""),priceCents:(u=a.price)!=null?u:0,compareAtCents:(I=a.compare_at_price)!=null?I:0,perDeliveryCents:(R=a.per_delivery_price)!=null?R:0,options:((D=a.selling_plan.options)!=null?D:[]).map(y=>{var t,e;return{name:(t=y.name)!=null?t:"",value:(e=y.value)!=null?e:""}})}:void 0}}),f=((g=o.cart_level_discount_applications)!=null?g:[]).reduce((s,a)=>{var w;return s+h((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:h((M=o.items_subtotal_price)!=null?M:o.total_price),total:h(o.total_price),cartDiscount:f,items:l}}function Y(o){let l=new TextEncoder().encode(o),d="";return l.forEach(f=>d+=String.fromCharCode(f)),btoa(d).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=Y(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,d=l)=>{var D,y;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,g=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),M=t=>t.endsWith(".myshopify.com")||t===location.hostname;function s(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function a(t){let e=s(t);if(!e||!M(e.hostname))return!1;let n=k(e.pathname),r=f.some(i=>i.test(n));return r&&g("detected checkout-like URL:",String(e)),r}function w(t){let e=t==null?void 0:t.getAttribute("variant-params");if(!e)return null;let n=e.includes("&quot;")?e.replace(/&quot;/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch{return null}}let b=null,C=0,A=3e4;async function E(){try{return await fetch("/cart.js").then(t=>t.json())}catch{return null}}function U(){b&&Date.now()-C<A||E().then(t=>{t&&(b=t,C=Date.now())})}function T(){b=null,C=0}function L(){return b&&Date.now()-C<A?b:null}function x(){var e;let t=(e=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith("cart=")))==null?void 0:e.slice(5);return t?`gid://shopify/Cart/${decodeURIComponent(t)}`:null}function O(){try{return crypto.randomUUID()}catch{return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}}async function H(t,e=1){let n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!n.ok){let r=await n.text().catch(()=>"");throw new Error(`cart/add.js failed (${n.status}): ${r}`)}return T(),n.json()}function S(t,e){let n=O(),r="";if(e)try{let p=$(N(e));p&&(r=`&cart=${p}`)}catch(p){console.error("[revley] slim-cart serialization failed; skipping",p)}let c=`${d.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(c)}async function _({cartSettled:t=!1}={}){if(t){let r=L();if(r){if(!r.item_count){g("cart is empty; skipping checkout redirect");return}let c=r.token?`gid://shopify/Cart/${r.token}`:x();if(c)return S(c,r)}let i=x();if(i)return S(i,null)}let e=L()||await E();if(e&&!e.item_count){g("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:x();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}S(n,e)}let P=!1;function u(t){return P||!a(t)?!1:(P=!0,_({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=u,(D=window.Shopify)!=null&&D.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())}),document.addEventListener("pointerdown",U,{capture:!0,passive:!0});{let t=window.location,e=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:r=>{u(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{u(r)||n(r)},writable:!0,configurable:!0})}catch(r){g("Could not override location methods, relying on Service Worker:",r)}}{let t=window.open;window.open=function(e,n,r){return e&&u(e)?null:t.call(window,e,n,r)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(n,r,i){if(!(i!=null&&u(i)))return t(n,r,i)},history.replaceState=function(n,r,i){if(!(i!=null&&u(i)))return e(n,r,i)},addEventListener("popstate",()=>void u(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let n=e;if(n.defaultPrevented||t(n))return;let r=e.target;for(;r&&r.nodeType===1&&r.tagName!=="A";)r=r.parentElement;let i=r;!i||!i.href||a(i.href)&&(n.preventDefault(),n.stopPropagation(),_({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(I(this))return t.call(this);let n=this.getAttribute("action")||"";if(u(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&u("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(I(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(c=>(c==null?void 0:c.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),_({cartSettled:!0}))}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,u(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,r,i,c,p){try{typeof r=="string"&&a(r)&&u(r)}catch{}return t.call(this,n,r,!!i,c,p)}}{let t=window.fetch.bind(window);window.fetch=function(n,r){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&a(i)&&u(i)}catch{}return t(n,r)}}let I=t=>t?Array.from(t.elements).some(e=>{var r,i;let n=e;return((r=n.name)==null?void 0:r.includes("__kaching_bundles"))||((i=n.name)==null?void 0:i.includes("kaching"))||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{var i,c,p;let e=t.target,n=(i=e==null?void 0:e.closest)==null?void 0:i.call(e,"button.shopify-payment-button__button");if(!n)return;let r=n.closest("shopify-accelerated-checkout");if(r){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let v=w(r),q=(p=(c=v==null?void 0:v[0])==null?void 0:c.id)!=null?p:51504147202335;if(!q)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch{console.log("Failed to prevent upcart from opening")}await H(q,1),await _()}catch(v){console.error("Intercepted Buy It Now failed; falling back:",v),window.location.assign("/checkout")}}},!0);{let t={},e;(y=window.kachingCartApi)!=null&&y.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,r){return r==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(c=>{var v;c.disabled=!0,c.style.pointerEvents="none",c.style.opacity="0.5";let p=c.cloneNode(!0);p.disabled=!0,p.style.pointerEvents="none",p.style.opacity="0.5",(v=c.parentNode)==null||v.replaceChild(p,c)}),e&&await e.apply(this,i),T(),await Promise.all([new Promise(c=>setTimeout(c,1e4)),_()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,g("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function R(){var n;let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(r=>r.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",_({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}R(),new MutationObserver(()=>R()).observe(document.body,{childList:!0,subtree:!0})},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,d=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),f="http://localhost:3000",m="http://localhost:3002",g=d?f:o.dataset.revleyCheckoutHost,k=d?m:o.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||g;l&&g&&z(l,g,k)};G();
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var C=(d,m)=>{if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let g=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],P=!1,f=(...t)=>P?console.debug("[checkout-intercept]",...t):void 0,R=t=>t.replace(/\/+$/,""),T=t=>t.endsWith(".myshopify.com")||t===location.hostname;function y(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function c(t){let e=y(t);if(!e||!T(e.hostname))return!1;let n=R(e.pathname),r=g.some(i=>i.test(n));return r&&f("detected checkout-like URL:",String(e)),r}function E(t){let e=t?.getAttribute("variant-params");if(!e)return null;let n=e.includes("&quot;")?e.replace(/&quot;/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch{return null}}async function S(t,e=1){let n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!n.ok){let r=await n.text().catch(()=>"");throw new Error(`cart/add.js failed (${n.status}): ${r}`)}return n.json()}async function l(){let e=await(await fetch("/cart.js")).json(),n={},r=["_fbp","_fbc","_fbq","_ig_","_igbp","_igshid","_igsh","_ig_visitor_id","_gclid","_gcl_au","_gcl_aw","_gcl_dc","_gcl_gb","_ttp","_tt_enable_cookie","_scid","_sctr","_pin_unauth","_pin_id","_twitter_ads_id","_li_ss","_uetsid","_uetvid","_amzn","_amzn_ads_","_yclid","_ycl_","_rdt_uid","_quora_","_tb_","_ob_","_criteo_","_adobe_","_ttd_","_dv360_","_fbcv","_shopify_pixel_"],i=p=>r.some(u=>p===u||p.startsWith(u)||p.includes(u));document.cookie&&document.cookie.split(";").forEach(p=>{let u=p.trim();if(u){let[h,...A]=u.split("="),L=A.join("=");h&&L&&i(h)&&(n[h]=L)}});let o=`gid://shopify/Cart/${e.token}`,_=await(await fetch(`${m}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:d,cartId:o,cookies:n})})).text();if(console.log("checkoutUrl",_),!_){console.error("No checkout ID received from backend");return}let k=y(_);if(!k){console.error("Invalid checkout URL received from backend:",_);return}sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(k.href)}let b=!1;function a(t){return b||!c(t)?!1:(b=!0,l(),!0)}if(window.__isCheckoutLike=c,window.__maybeRedirect=a,window.Shopify?.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())});{let t=window.location,e=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:r=>{a(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{a(r)||n(r)},writable:!0,configurable:!0})}catch(r){f("Could not override location methods, relying on Service Worker:",r)}}{let t=window.open;window.open=function(e,n,r){return e&&a(e)?null:t.call(window,e,n,r)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(n,r,i){if(!(i!=null&&a(i)))return t(n,r,i)},history.replaceState=function(n,r,i){if(!(i!=null&&a(i)))return e(n,r,i)},addEventListener("popstate",()=>void a(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let n=e;if(n.defaultPrevented||t(n))return;let r=e.target;for(;r&&r.nodeType===1&&r.tagName!=="A";)r=r.parentElement;let i=r;!i||!i.href||c(i.href)&&(n.preventDefault(),n.stopPropagation(),l())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(w(this))return t.call(this);let n=this.getAttribute("action")||"";if(a(n)||Array.from(this.elements).some(i=>i?.name==="checkout")&&a("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(w(n))return;let r=n?.getAttribute("action")||"",i=Array.from(n?.elements||[]);(c(r)||i.some(o=>o?.name==="checkout"))&&(e.preventDefault(),e.stopPropagation(),l())}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,a(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,r,i,o,s){try{typeof r=="string"&&c(r)&&a(r)}catch{}return t.call(this,n,r,!!i,o,s)}}{let t=window.fetch.bind(window);window.fetch=function(n,r){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&c(i)&&a(i)}catch{}return t(n,r)}}let w=t=>t?Array.from(t.elements).some(e=>{let n=e;return n.name?.includes("__kaching_bundles")||n.name?.includes("kaching")||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{let n=t.target?.closest?.("button.shopify-payment-button__button");if(!n)return;let r=n.closest("shopify-accelerated-checkout");if(r){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let o=E(r)?.[0]?.id??51504147202335;if(!o)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch{console.log("Failed to prevent upcart from opening")}await S(o,1),await l()}catch(i){console.error("Intercepted Buy It Now failed; falling back:",i),window.location.assign("/checkout")}}},!0);{let t={},e;window.kachingCartApi?.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,r){return r==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(o=>{o.disabled=!0,o.style.pointerEvents="none",o.style.opacity="0.5";let s=o.cloneNode(!0);s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5",o.parentNode?.replaceChild(s,o)}),e&&await e.apply(this,i),await Promise.all([new Promise(o=>setTimeout(o,1e4)),l()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,f("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function v(){let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(n=>n.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",l()}),t.parentNode?.replaceChild(e,t)}v(),new MutationObserver(()=>v()).observe(document.body,{childList:!0,subtree:!0})},I=()=>{let d=document.currentScript;if(!d)return;let m=d.dataset.revleyStoreId,g=d.dataset.revleyCheckoutHost;m&&g&&C(m,g)};I();
1
+ var m=a=>(a??0)/100,B=a=>((a??0)/100).toFixed(2);function w(a){return a.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#0*39;|&apos;/g,"'").replace(/&#(\d+);/g,(l,u)=>String.fromCodePoint(Number(u))).replace(/&#x([0-9a-f]+);/gi,(l,u)=>String.fromCodePoint(parseInt(u,16))).replace(/&amp;/g,"&")}function I(a){let l=(a.items??[]).map(o=>{let s=o.selling_plan_allocation,h=o.line_level_discount_allocations??[];return{variantId:o.variant_id??0,key:o.key??String(o.variant_id??""),quantity:o.quantity??0,productTitle:w(o.product_title??o.title??""),variantTitle:o.variant_title?w(o.variant_title):void 0,price:B(o.price),image:o.featured_image?.url??o.image??void 0,unitPrice:m(o.price),totalPrice:m(o.original_line_price??o.line_price),lineTotalAfterDiscounts:m(o.final_line_price??o.line_price),totalDiscountAllocated:m(o.total_discount),compareAtPrice:s?.compare_at_price!=null?m(s.compare_at_price):void 0,perDeliveryPrice:s?.per_delivery_price!=null?m(s.per_delivery_price):void 0,discountAllocations:h.length?h.map(g=>({title:w(g.discount_application?.title??"Discount"),amount:m(g.amount),code:g.discount_application?.code||void 0})):void 0,sellingPlan:s?.selling_plan?{name:w(s.selling_plan.name??""),priceCents:s.price??0,compareAtCents:s.compare_at_price??0,perDeliveryCents:s.per_delivery_price??0,options:(s.selling_plan.options??[]).map(g=>({name:g.name??"",value:g.value??""}))}:void 0}}),f=(a.cart_level_discount_applications??[]).reduce((o,s)=>o+m(s.total_allocated_amount??s.amount),0);return{currency:a.currency??"USD",subtotal:m(a.items_subtotal_price??a.total_price),total:m(a.total_price),cartDiscount:f,items:l}}function q(a){let l=new TextEncoder().encode(a),u="";return l.forEach(f=>u+=String.fromCharCode(f)),btoa(u).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function R(a){let l=q(JSON.stringify(a));return l.length>6e3?null:l}var j=(a,l,u=l)=>{if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],o=!1,s=(...t)=>o?console.debug("[checkout-intercept]",...t):void 0,h=t=>t.replace(/\/+$/,""),g=t=>t.endsWith(".myshopify.com")||t===location.hostname;function D(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function _(t){let e=D(t);if(!e||!g(e.hostname))return!1;let n=h(e.pathname),r=f.some(i=>i.test(n));return r&&s("detected checkout-like URL:",String(e)),r}function M(t){let e=t?.getAttribute("variant-params");if(!e)return null;let n=e.includes("&quot;")?e.replace(/&quot;/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch{return null}}let b=null,v=0,x=3e4;async function S(){try{return await fetch("/cart.js").then(t=>t.json())}catch{return null}}function U(){b&&Date.now()-v<x||S().then(t=>{t&&(b=t,v=Date.now())})}function P(){b=null,v=0}function A(){return b&&Date.now()-v<x?b:null}function C(){let t=document.cookie.split(";").map(e=>e.trim()).find(e=>e.startsWith("cart="))?.slice(5);return t?`gid://shopify/Cart/${decodeURIComponent(t)}`:null}function O(){try{return crypto.randomUUID()}catch{return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}}async function H(t,e=1){let n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!n.ok){let r=await n.text().catch(()=>"");throw new Error(`cart/add.js failed (${n.status}): ${r}`)}return P(),n.json()}function k(t,e){let n=O(),r="";if(e)try{let p=R(I(e));p&&(r=`&cart=${p}`)}catch(p){console.error("[revley] slim-cart serialization failed; skipping",p)}let c=`${u.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(a)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(c)}async function y({cartSettled:t=!1}={}){if(t){let r=A();if(r){if(!r.item_count){s("cart is empty; skipping checkout redirect");return}let c=r.token?`gid://shopify/Cart/${r.token}`:C();if(c)return k(c,r)}let i=C();if(i)return k(i,null)}let e=A()||await S();if(e&&!e.item_count){s("cart is empty; skipping checkout redirect");return}let n=e?.token?`gid://shopify/Cart/${e.token}`:C();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}k(n,e)}let E=!1;function d(t){return E||!_(t)?!1:(E=!0,y({cartSettled:!0}),!0)}if(window.__isCheckoutLike=_,window.__maybeRedirect=d,window.Shopify?.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())}),document.addEventListener("pointerdown",U,{capture:!0,passive:!0});{let t=window.location,e=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:r=>{d(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{d(r)||n(r)},writable:!0,configurable:!0})}catch(r){s("Could not override location methods, relying on Service Worker:",r)}}{let t=window.open;window.open=function(e,n,r){return e&&d(e)?null:t.call(window,e,n,r)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(n,r,i){if(!(i!=null&&d(i)))return t(n,r,i)},history.replaceState=function(n,r,i){if(!(i!=null&&d(i)))return e(n,r,i)},addEventListener("popstate",()=>void d(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let n=e;if(n.defaultPrevented||t(n))return;let r=e.target;for(;r&&r.nodeType===1&&r.tagName!=="A";)r=r.parentElement;let i=r;!i||!i.href||_(i.href)&&(n.preventDefault(),n.stopPropagation(),y({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(T(this))return t.call(this);let n=this.getAttribute("action")||"";if(d(n)||Array.from(this.elements).some(i=>i?.name==="checkout")&&d("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(T(n))return;let r=n?.getAttribute("action")||"",i=Array.from(n?.elements||[]);(_(r)||i.some(c=>c?.name==="checkout"))&&(e.preventDefault(),e.stopPropagation(),y({cartSettled:!0}))}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,d(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,r,i,c,p){try{typeof r=="string"&&_(r)&&d(r)}catch{}return t.call(this,n,r,!!i,c,p)}}{let t=window.fetch.bind(window);window.fetch=function(n,r){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&_(i)&&d(i)}catch{}return t(n,r)}}let T=t=>t?Array.from(t.elements).some(e=>{let n=e;return n.name?.includes("__kaching_bundles")||n.name?.includes("kaching")||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{let n=t.target?.closest?.("button.shopify-payment-button__button");if(!n)return;let r=n.closest("shopify-accelerated-checkout");if(r){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let c=M(r)?.[0]?.id??51504147202335;if(!c)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch{console.log("Failed to prevent upcart from opening")}await H(c,1),await y()}catch(i){console.error("Intercepted Buy It Now failed; falling back:",i),window.location.assign("/checkout")}}},!0);{let t={},e;window.kachingCartApi?.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,r){return r==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(c=>{c.disabled=!0,c.style.pointerEvents="none",c.style.opacity="0.5";let p=c.cloneNode(!0);p.disabled=!0,p.style.pointerEvents="none",p.style.opacity="0.5",c.parentNode?.replaceChild(p,c)}),e&&await e.apply(this,i),P(),await Promise.all([new Promise(c=>setTimeout(c,1e4)),y()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,s("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function L(){let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(n=>n.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",y({cartSettled:!0})}),t.parentNode?.replaceChild(e,t)}L(),new MutationObserver(()=>L()).observe(document.body,{childList:!0,subtree:!0})},N=()=>{let a=document.currentScript;if(!a)return;let l=a.dataset.revleyStoreId,u=a.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),f="http://localhost:3000",o="http://localhost:3002",s=u?f:a.dataset.revleyCheckoutHost,h=u?o:a.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||s;l&&s&&j(l,s,h)};N();
@@ -1 +1 @@
1
- "use strict";var SandboxCheckoutPkg=(()=>{var P=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var H=(c,l,p,y)=>{if(l&&typeof l=="object"||typeof l=="function")for(let d of U(l))!x.call(c,d)&&d!==p&&P(c,d,{get:()=>l[d],enumerable:!(y=M(l,d))||y.enumerable});return c};var j=c=>H(P({},"__esModule",{value:!0}),c);var N={};var B=(c,l)=>{var R,T;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let p=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],y=!1,d=(...t)=>y?console.debug("[checkout-intercept]",...t):void 0,S=t=>t.replace(/\/+$/,""),A=t=>t.endsWith(".myshopify.com")||t===location.hostname;function w(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch(n){return null}}function m(t){let e=w(t);if(!e||!A(e.hostname))return!1;let n=S(e.pathname),r=p.some(i=>i.test(n));return r&&d("detected checkout-like URL:",String(e)),r}function C(t){let e=t==null?void 0:t.getAttribute("variant-params");if(!e)return null;let n=e.includes("&quot;")?e.replace(/&quot;/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch(r){return null}}async function I(t,e=1){let n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!n.ok){let r=await n.text().catch(()=>"");throw new Error(`cart/add.js failed (${n.status}): ${r}`)}return n.json()}async function g(){let e=await(await fetch("/cart.js")).json(),n={},r=["_fbp","_fbc","_fbq","_ig_","_igbp","_igshid","_igsh","_ig_visitor_id","_gclid","_gcl_au","_gcl_aw","_gcl_dc","_gcl_gb","_ttp","_tt_enable_cookie","_scid","_sctr","_pin_unauth","_pin_id","_twitter_ads_id","_li_ss","_uetsid","_uetvid","_amzn","_amzn_ads_","_yclid","_ycl_","_rdt_uid","_quora_","_tb_","_ob_","_criteo_","_adobe_","_ttd_","_dv360_","_fbcv","_shopify_pixel_"],i=_=>r.some(h=>_===h||_.startsWith(h)||_.includes(h));document.cookie&&document.cookie.split(";").forEach(_=>{let h=_.trim();if(h){let[b,...O]=h.split("="),E=O.join("=");b&&E&&i(b)&&(n[b]=E)}});let o=`gid://shopify/Cart/${e.token}`,a=await(await fetch(`${l}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:c,cartId:o,cookies:n})})).text();if(console.log("checkoutUrl",a),!a){console.error("No checkout ID received from backend");return}let f=w(a);if(!f){console.error("Invalid checkout URL received from backend:",a);return}sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(f.href)}let v=!1;function s(t){return v||!m(t)?!1:(v=!0,g(),!0)}if(window.__isCheckoutLike=m,window.__maybeRedirect=s,(R=window.Shopify)!=null&&R.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())});{let t=window.location,e=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:r=>{s(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{s(r)||n(r)},writable:!0,configurable:!0})}catch(r){d("Could not override location methods, relying on Service Worker:",r)}}{let t=window.open;window.open=function(e,n,r){return e&&s(e)?null:t.call(window,e,n,r)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(n,r,i){if(!(i!=null&&s(i)))return t(n,r,i)},history.replaceState=function(n,r,i){if(!(i!=null&&s(i)))return e(n,r,i)},addEventListener("popstate",()=>void s(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let n=e;if(n.defaultPrevented||t(n))return;let r=e.target;for(;r&&r.nodeType===1&&r.tagName!=="A";)r=r.parentElement;let i=r;!i||!i.href||m(i.href)&&(n.preventDefault(),n.stopPropagation(),g())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(k(this))return t.call(this);let n=this.getAttribute("action")||"";if(s(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&s("/checkout"))return}catch(n){}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(k(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(m(r)||i.some(o=>(o==null?void 0:o.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),g())}catch(n){}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,s(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,r,i,o,u){try{typeof r=="string"&&m(r)&&s(r)}catch(a){}return t.call(this,n,r,!!i,o,u)}}{let t=window.fetch.bind(window);window.fetch=function(n,r){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&m(i)&&s(i)}catch(i){}return t(n,r)}}let k=t=>t?Array.from(t.elements).some(e=>{var r,i;let n=e;return((r=n.name)==null?void 0:r.includes("__kaching_bundles"))||((i=n.name)==null?void 0:i.includes("kaching"))||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{var i,o,u;let e=t.target,n=(i=e==null?void 0:e.closest)==null?void 0:i.call(e,"button.shopify-payment-button__button");if(!n)return;let r=n.closest("shopify-accelerated-checkout");if(r){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let a=C(r),f=(u=(o=a==null?void 0:a[0])==null?void 0:o.id)!=null?u:51504147202335;if(!f)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch(_){console.log("Failed to prevent upcart from opening")}await I(f,1),await g()}catch(a){console.error("Intercepted Buy It Now failed; falling back:",a),window.location.assign("/checkout")}}},!0);{let t={},e;(T=window.kachingCartApi)!=null&&T.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,r){return r==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(o=>{var a;o.disabled=!0,o.style.pointerEvents="none",o.style.opacity="0.5";let u=o.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(a=o.parentNode)==null||a.replaceChild(u,o)}),e&&await e.apply(this,i),await Promise.all([new Promise(o=>setTimeout(o,1e4)),g()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,d("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function L(){var n;let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(r=>r.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",g()}),(n=t.parentNode)==null||n.replaceChild(e,t)}L(),new MutationObserver(()=>L()).observe(document.body,{childList:!0,subtree:!0})},q=()=>{let c=document.currentScript;if(!c)return;let l=c.dataset.revleyStoreId,p=c.dataset.revleyCheckoutHost;l&&p&&B(l,p)};q();return j(N);})();
1
+ "use strict";var SandboxCheckoutPkg=(()=>{var j=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,d,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==d&&j(o,m,{get:()=>l[m],enumerable:!(f=F(l,m))||f.enumerable});return o};var X=o=>W(j({},"__esModule",{value:!0}),o);var Q={};var h=o=>(o!=null?o:0)/100,J=o=>((o!=null?o:0)/100).toFixed(2);function B(o){return o.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#0*39;|&apos;/g,"'").replace(/&#(\d+);/g,(l,d)=>String.fromCodePoint(Number(d))).replace(/&#x([0-9a-f]+);/gi,(l,d)=>String.fromCodePoint(parseInt(d,16))).replace(/&amp;/g,"&")}function N(o){var m,g,k,M;let l=((m=o.items)!=null?m:[]).map(s=>{var v,C,A,E,U,T,L,x,O,H,S,_,P,u,I,R,D;let a=s.selling_plan_allocation,w=(v=s.line_level_discount_allocations)!=null?v:[];return{variantId:(C=s.variant_id)!=null?C:0,key:(E=s.key)!=null?E:String((A=s.variant_id)!=null?A:""),quantity:(U=s.quantity)!=null?U:0,productTitle:B((L=(T=s.product_title)!=null?T:s.title)!=null?L:""),variantTitle:s.variant_title?B(s.variant_title):void 0,price:J(s.price),image:(H=(O=(x=s.featured_image)==null?void 0:x.url)!=null?O:s.image)!=null?H:void 0,unitPrice:h(s.price),totalPrice:h((S=s.original_line_price)!=null?S:s.line_price),lineTotalAfterDiscounts:h((_=s.final_line_price)!=null?_:s.line_price),totalDiscountAllocated:h(s.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?h(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?h(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(y=>{var t,e,n;return{title:B((e=(t=y.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:h(y.amount),code:((n=y.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:B((P=a.selling_plan.name)!=null?P:""),priceCents:(u=a.price)!=null?u:0,compareAtCents:(I=a.compare_at_price)!=null?I:0,perDeliveryCents:(R=a.per_delivery_price)!=null?R:0,options:((D=a.selling_plan.options)!=null?D:[]).map(y=>{var t,e;return{name:(t=y.name)!=null?t:"",value:(e=y.value)!=null?e:""}})}:void 0}}),f=((g=o.cart_level_discount_applications)!=null?g:[]).reduce((s,a)=>{var w;return s+h((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:h((M=o.items_subtotal_price)!=null?M:o.total_price),total:h(o.total_price),cartDiscount:f,items:l}}function Y(o){let l=new TextEncoder().encode(o),d="";return l.forEach(f=>d+=String.fromCharCode(f)),btoa(d).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=Y(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,d=l)=>{var D,y;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,g=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),M=t=>t.endsWith(".myshopify.com")||t===location.hostname;function s(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch(n){return null}}function a(t){let e=s(t);if(!e||!M(e.hostname))return!1;let n=k(e.pathname),r=f.some(i=>i.test(n));return r&&g("detected checkout-like URL:",String(e)),r}function w(t){let e=t==null?void 0:t.getAttribute("variant-params");if(!e)return null;let n=e.includes("&quot;")?e.replace(/&quot;/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch(r){return null}}let v=null,C=0,A=3e4;async function E(){try{return await fetch("/cart.js").then(t=>t.json())}catch(t){return null}}function U(){v&&Date.now()-C<A||E().then(t=>{t&&(v=t,C=Date.now())})}function T(){v=null,C=0}function L(){return v&&Date.now()-C<A?v:null}function x(){var e;let t=(e=document.cookie.split(";").map(n=>n.trim()).find(n=>n.startsWith("cart=")))==null?void 0:e.slice(5);return t?`gid://shopify/Cart/${decodeURIComponent(t)}`:null}function O(){try{return crypto.randomUUID()}catch(t){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}}async function H(t,e=1){let n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:Number(t),quantity:e}]}),credentials:"same-origin"});if(!n.ok){let r=await n.text().catch(()=>"");throw new Error(`cart/add.js failed (${n.status}): ${r}`)}return T(),n.json()}function S(t,e){let n=O(),r="";if(e)try{let p=$(N(e));p&&(r=`&cart=${p}`)}catch(p){console.error("[revley] slim-cart serialization failed; skipping",p)}let c=`${d.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(c)}async function _({cartSettled:t=!1}={}){if(t){let r=L();if(r){if(!r.item_count){g("cart is empty; skipping checkout redirect");return}let c=r.token?`gid://shopify/Cart/${r.token}`:x();if(c)return S(c,r)}let i=x();if(i)return S(i,null)}let e=L()||await E();if(e&&!e.item_count){g("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:x();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}S(n,e)}let P=!1;function u(t){return P||!a(t)?!1:(P=!0,_({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=u,(D=window.Shopify)!=null&&D.designMode)return;window.addEventListener("pageshow",t=>{t.persisted&&sessionStorage.getItem("__revley_checkout_redirect")&&(sessionStorage.removeItem("__revley_checkout_redirect"),location.reload())}),document.addEventListener("pointerdown",U,{capture:!0,passive:!0});{let t=window.location,e=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:r=>{u(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{u(r)||n(r)},writable:!0,configurable:!0})}catch(r){g("Could not override location methods, relying on Service Worker:",r)}}{let t=window.open;window.open=function(e,n,r){return e&&u(e)?null:t.call(window,e,n,r)}}{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(n,r,i){if(!(i!=null&&u(i)))return t(n,r,i)},history.replaceState=function(n,r,i){if(!(i!=null&&u(i)))return e(n,r,i)},addEventListener("popstate",()=>void u(location.href),!0)}{let t=e=>e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0;addEventListener("click",e=>{let n=e;if(n.defaultPrevented||t(n))return;let r=e.target;for(;r&&r.nodeType===1&&r.tagName!=="A";)r=r.parentElement;let i=r;!i||!i.href||a(i.href)&&(n.preventDefault(),n.stopPropagation(),_({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(I(this))return t.call(this);let n=this.getAttribute("action")||"";if(u(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&u("/checkout"))return}catch(n){}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(I(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(c=>(c==null?void 0:c.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),_({cartSettled:!0}))}catch(n){}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,u(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,r,i,c,p){try{typeof r=="string"&&a(r)&&u(r)}catch(b){}return t.call(this,n,r,!!i,c,p)}}{let t=window.fetch.bind(window);window.fetch=function(n,r){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&a(i)&&u(i)}catch(i){}return t(n,r)}}let I=t=>t?Array.from(t.elements).some(e=>{var r,i;let n=e;return((r=n.name)==null?void 0:r.includes("__kaching_bundles"))||((i=n.name)==null?void 0:i.includes("kaching"))||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{var i,c,p;let e=t.target,n=(i=e==null?void 0:e.closest)==null?void 0:i.call(e,"button.shopify-payment-button__button");if(!n)return;let r=n.closest("shopify-accelerated-checkout");if(r){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation();try{let b=w(r),q=(p=(c=b==null?void 0:b[0])==null?void 0:c.id)!=null?p:51504147202335;if(!q)throw new Error("Could not determine variant id");try{window.upcartOpenOnAddToCartOverride=!1,window.upcartShouldOpenOnAddToCartBackgroundNetworkCall=!1}catch(Z){console.log("Failed to prevent upcart from opening")}await H(q,1),await _()}catch(b){console.error("Intercepted Buy It Now failed; falling back:",b),window.location.assign("/checkout")}}},!0);{let t={},e;(y=window.kachingCartApi)!=null&&y.updateTieredPromotionsBar&&(e=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,r){return r==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(c=>{var b;c.disabled=!0,c.style.pointerEvents="none",c.style.opacity="0.5";let p=c.cloneNode(!0);p.disabled=!0,p.style.pointerEvents="none",p.style.opacity="0.5",(b=c.parentNode)==null||b.replaceChild(p,c)}),e&&await e.apply(this,i),T(),await Promise.all([new Promise(c=>setTimeout(c,1e4)),_()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,g("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function R(){var n;let t=document.querySelector("#kaching-cart__checkout-button");if(!t||t.dataset.revleyReplaced)return;let e=t.cloneNode(!0);e.querySelectorAll(".kaching-cart__loading-spinner").forEach(r=>r.remove()),e.dataset.revleyReplaced="true",e.addEventListener("click",r=>{r.preventDefault(),r.stopPropagation(),e.disabled=!0,e.style.pointerEvents="none",e.style.opacity="0.5",_({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}R(),new MutationObserver(()=>R()).observe(document.body,{childList:!0,subtree:!0})},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,d=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),f="http://localhost:3000",m="http://localhost:3002",g=d?f:o.dataset.revleyCheckoutHost,k=d?m:o.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||g;l&&g&&z(l,g,k)};G();return X(Q);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revley/sandbox-checkout-package",
3
- "version": "0.3.02",
3
+ "version": "0.3.03",
4
4
  "description": "Tiny TS package optimized for browsers with modern & legacy outputs",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",