@revley/sandbox-checkout-package 0.3.4 → 0.3.5
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/cjs/index.cjs +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/iife/index.global.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,p,_)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==p&&N(o,m,{get:()=>l[m],enumerable:!(_=F(l,m))||_.enumerable});return o};var X=o=>W(N({},"__esModule",{value:!0}),o);var Q={};module.exports=X(Q);var y=o=>(o!=null?o:0)/100,Y=o=>((o!=null?o:0)/100).toFixed(2);function q(o){return o.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(l,p)=>String.fromCodePoint(Number(p))).replace(/&#x([0-9a-f]+);/gi,(l,p)=>String.fromCodePoint(parseInt(p,16))).replace(/&/g,"&")}function j(o){var m,g,k,O;let l=((m=o.items)!=null?m:[]).map(c=>{var v,C,E,T,U,L,A,S,H,P,x,h,I,d,R,M,D;let a=c.selling_plan_allocation,w=(v=c.line_level_discount_allocations)!=null?v:[];return{variantId:(C=c.variant_id)!=null?C:0,key:(T=c.key)!=null?T:String((E=c.variant_id)!=null?E:""),quantity:(U=c.quantity)!=null?U:0,productTitle:q((A=(L=c.product_title)!=null?L:c.title)!=null?A:""),variantTitle:c.variant_title?q(c.variant_title):void 0,price:Y(c.price),image:(P=(H=(S=c.featured_image)==null?void 0:S.url)!=null?H:c.image)!=null?P:void 0,unitPrice:y(c.price),totalPrice:y((x=c.original_line_price)!=null?x:c.line_price),lineTotalAfterDiscounts:y((h=c.final_line_price)!=null?h:c.line_price),totalDiscountAllocated:y(c.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?y(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?y(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(b=>{var t,e,n;return{title:q((e=(t=b.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:y(b.amount),code:((n=b.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:q((I=a.selling_plan.name)!=null?I:""),priceCents:(d=a.price)!=null?d:0,compareAtCents:(R=a.compare_at_price)!=null?R:0,perDeliveryCents:(M=a.per_delivery_price)!=null?M:0,options:((D=a.selling_plan.options)!=null?D:[]).map(b=>{var t,e;return{name:(t=b.name)!=null?t:"",value:(e=b.value)!=null?e:""}})}:void 0}}),_=((g=o.cart_level_discount_applications)!=null?g:[]).reduce((c,a)=>{var w;return c+y((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:y((O=o.items_subtotal_price)!=null?O:o.total_price),total:y(o.total_price),cartDiscount:_,items:l}}function J(o){let l=new TextEncoder().encode(o),p="";return l.forEach(_=>p+=String.fromCharCode(_)),btoa(p).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=J(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,p=l)=>{var D,b;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let _=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,g=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),O=t=>t.endsWith(".myshopify.com")||t===location.hostname;function c(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function a(t){let e=c(t);if(!e||!O(e.hostname))return!1;let n=k(e.pathname),r=_.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(""")?e.replace(/"/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch{return null}}let v=null,C=0,E=3e4;async function T(){try{return await fetch("/cart.js").then(t=>t.json())}catch{return null}}function U(){v&&Date.now()-C<E||T().then(t=>{t&&(v=t,C=Date.now())})}function L(){v=null,C=0}function A(){return v&&Date.now()-C<E?v:null}function S(){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 H(){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 P(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 L(),n.json()}function x(t,e){let n=H(),r="";if(e)try{let u=$(j(e));u&&(r=`&cart=${u}`)}catch(u){console.error("[revley] slim-cart serialization failed; skipping",u)}let s=`${p.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(s)}async function h({cartSettled:t=!1}={}){if(t){let r=A();if(r){if(!r.item_count){g("cart is empty; skipping checkout redirect");return}let s=r.token?`gid://shopify/Cart/${r.token}`:S();if(s)return x(s,r)}let i=S();if(i)return x(i,null)}let e=A()||await T();if(e&&!e.item_count){g("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:S();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}x(n,e)}let I=!1;function d(t){return I||!a(t)?!1:(I=!0,h({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=d,(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=>{d(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{d(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&&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||a(i.href)&&(n.preventDefault(),n.stopPropagation(),h({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(R(this))return t.call(this);let n=this.getAttribute("action")||"";if(d(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&d("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(R(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(s=>(s==null?void 0:s.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),h({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,s,u){try{typeof r=="string"&&a(r)&&d(r)}catch{}return t.call(this,n,r,!!i,s,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&&a(i)&&d(i)}catch{}return t(n,r)}}let R=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,s,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 f=w(r),B=(u=(s=f==null?void 0:f[0])==null?void 0:s.id)!=null?u:51504147202335;if(!B)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 P(B,1),await h()}catch(f){console.error("Intercepted Buy It Now failed; falling back:",f),window.location.assign("/checkout")}}},!0);{let t={},e;(b=window.kachingCartApi)!=null&&b.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(s=>{var f;s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5";let u=s.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(f=s.parentNode)==null||f.replaceChild(u,s)}),e&&await e.apply(this,i),L(),await Promise.all([new Promise(s=>setTimeout(s,1e4)),h()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,g("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function M(){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",h({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}M(),new MutationObserver(()=>M()).observe(document.body,{childList:!0,subtree:!0});{let t=".custom_checkout_button_landing_page, .custom_checkout_button";document.addEventListener("click",async e=>{var u,f;let n=e.target,r=(u=n==null?void 0:n.closest)==null?void 0:u.call(n,t);if(!r)return;let i=(f=n==null?void 0:n.closest)==null?void 0:f.call(n,"[data-variant-id]"),s=r.getAttribute("data-variant-id")||(i&&r.contains(i)?i.getAttribute("data-variant-id"):null)||null;if(s){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation();try{await P(s,1),await h()}catch(B){console.error("Intercepted Zipify checkout failed:",B)}}},!0)}},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,p=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),_="http://localhost:3000",m="http://localhost:3002",g=p?_:o.dataset.revleyCheckoutHost,k=p?m:o.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||g;l&&g&&z(l,g,k)};G();
|
|
1
|
+
"use strict";var N=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,p,_)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==p&&N(o,m,{get:()=>l[m],enumerable:!(_=F(l,m))||_.enumerable});return o};var X=o=>W(N({},"__esModule",{value:!0}),o);var Q={};module.exports=X(Q);var y=o=>(o!=null?o:0)/100,Y=o=>((o!=null?o:0)/100).toFixed(2);function q(o){return o.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(l,p)=>String.fromCodePoint(Number(p))).replace(/&#x([0-9a-f]+);/gi,(l,p)=>String.fromCodePoint(parseInt(p,16))).replace(/&/g,"&")}function j(o){var m,g,k,O;let l=((m=o.items)!=null?m:[]).map(c=>{var v,C,E,T,U,L,A,S,H,P,x,h,I,d,R,M,D;let a=c.selling_plan_allocation,w=(v=c.line_level_discount_allocations)!=null?v:[];return{variantId:(C=c.variant_id)!=null?C:0,key:(T=c.key)!=null?T:String((E=c.variant_id)!=null?E:""),quantity:(U=c.quantity)!=null?U:0,productTitle:q((A=(L=c.product_title)!=null?L:c.title)!=null?A:""),variantTitle:c.variant_title?q(c.variant_title):void 0,price:Y(c.price),image:(P=(H=(S=c.featured_image)==null?void 0:S.url)!=null?H:c.image)!=null?P:void 0,unitPrice:y(c.price),totalPrice:y((x=c.original_line_price)!=null?x:c.line_price),lineTotalAfterDiscounts:y((h=c.final_line_price)!=null?h:c.line_price),totalDiscountAllocated:y(c.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?y(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?y(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(b=>{var t,e,n;return{title:q((e=(t=b.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:y(b.amount),code:((n=b.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:q((I=a.selling_plan.name)!=null?I:""),priceCents:(d=a.price)!=null?d:0,compareAtCents:(R=a.compare_at_price)!=null?R:0,perDeliveryCents:(M=a.per_delivery_price)!=null?M:0,options:((D=a.selling_plan.options)!=null?D:[]).map(b=>{var t,e;return{name:(t=b.name)!=null?t:"",value:(e=b.value)!=null?e:""}})}:void 0}}),_=((g=o.cart_level_discount_applications)!=null?g:[]).reduce((c,a)=>{var w;return c+y((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:y((O=o.items_subtotal_price)!=null?O:o.total_price),total:y(o.total_price),cartDiscount:_,items:l}}function J(o){let l=new TextEncoder().encode(o),p="";return l.forEach(_=>p+=String.fromCharCode(_)),btoa(p).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=J(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,p=l)=>{var D,b;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let _=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,g=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),O=t=>t.endsWith(".myshopify.com")||t===location.hostname;function c(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch{return null}}function a(t){let e=c(t);if(!e||!O(e.hostname))return!1;let n=k(e.pathname),r=_.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(""")?e.replace(/"/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch{return null}}let v=null,C=0,E=3e4;async function T(){try{return await fetch("/cart.js").then(t=>t.json())}catch{return null}}function U(){v&&Date.now()-C<E||T().then(t=>{t&&(v=t,C=Date.now())})}function L(){v=null,C=0}function A(){return v&&Date.now()-C<E?v:null}function S(){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 H(){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 P(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 L(),n.json()}function x(t,e){let n=H(),r="";if(e)try{let u=$(j(e));u&&(r=`&cart=${u}`)}catch(u){console.error("[revley] slim-cart serialization failed; skipping",u)}let s=`${p.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(s)}async function h({cartSettled:t=!1}={}){if(t){let r=A();if(r&&r.item_count){let s=r.token?`gid://shopify/Cart/${r.token}`:S();if(s)return x(s,r)}let i=S();if(i)return x(i,null)}let e=A()||await T();if(e&&!e.item_count){g("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:S();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}x(n,e)}let I=!1;function d(t){return I||!a(t)?!1:(I=!0,h({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=d,(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=>{d(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{d(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&&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||a(i.href)&&(n.preventDefault(),n.stopPropagation(),h({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(R(this))return t.call(this);let n=this.getAttribute("action")||"";if(d(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&d("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(R(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(s=>(s==null?void 0:s.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),h({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,s,u){try{typeof r=="string"&&a(r)&&d(r)}catch{}return t.call(this,n,r,!!i,s,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&&a(i)&&d(i)}catch{}return t(n,r)}}let R=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,s,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 f=w(r),B=(u=(s=f==null?void 0:f[0])==null?void 0:s.id)!=null?u:51504147202335;if(!B)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 P(B,1),await h()}catch(f){console.error("Intercepted Buy It Now failed; falling back:",f),window.location.assign("/checkout")}}},!0);{let t={},e;(b=window.kachingCartApi)!=null&&b.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(s=>{var f;s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5";let u=s.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(f=s.parentNode)==null||f.replaceChild(u,s)}),e&&await e.apply(this,i),L(),await Promise.all([new Promise(s=>setTimeout(s,1e4)),h()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,g("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function M(){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",h({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}M(),new MutationObserver(()=>M()).observe(document.body,{childList:!0,subtree:!0});{let t=".custom_checkout_button_landing_page, .custom_checkout_button";document.addEventListener("click",async e=>{var u,f;let n=e.target,r=(u=n==null?void 0:n.closest)==null?void 0:u.call(n,t);if(!r)return;let i=(f=n==null?void 0:n.closest)==null?void 0:f.call(n,"[data-variant-id]"),s=r.getAttribute("data-variant-id")||(i&&r.contains(i)?i.getAttribute("data-variant-id"):null)||null;if(s){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation();try{await P(s,1),await h()}catch(B){console.error("Intercepted Zipify checkout failed:",B)}}},!0)}},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,p=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),_="http://localhost:3000",m="http://localhost:3002",g=p?_:o.dataset.revleyCheckoutHost,k=p?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 m=a=>(a??0)/100,B=a=>((a??0)/100).toFixed(2);function w(a){return a.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(u,d)=>String.fromCodePoint(Number(d))).replace(/&#x([0-9a-f]+);/gi,(u,d)=>String.fromCodePoint(parseInt(d,16))).replace(/&/g,"&")}function R(a){let u=(a.items??[]).map(o=>{let
|
|
1
|
+
var m=a=>(a??0)/100,B=a=>((a??0)/100).toFixed(2);function w(a){return a.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(u,d)=>String.fromCodePoint(Number(d))).replace(/&#x([0-9a-f]+);/gi,(u,d)=>String.fromCodePoint(parseInt(d,16))).replace(/&/g,"&")}function R(a){let u=(a.items??[]).map(o=>{let c=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:c?.compare_at_price!=null?m(c.compare_at_price):void 0,perDeliveryPrice:c?.per_delivery_price!=null?m(c.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:c?.selling_plan?{name:w(c.selling_plan.name??""),priceCents:c.price??0,compareAtCents:c.compare_at_price??0,perDeliveryCents:c.per_delivery_price??0,options:(c.selling_plan.options??[]).map(g=>({name:g.name??"",value:g.value??""}))}:void 0}}),f=(a.cart_level_discount_applications??[]).reduce((o,c)=>o+m(c.total_allocated_amount??c.amount),0);return{currency:a.currency??"USD",subtotal:m(a.items_subtotal_price??a.total_price),total:m(a.total_price),cartDiscount:f,items:u}}function q(a){let u=new TextEncoder().encode(a),d="";return u.forEach(f=>d+=String.fromCharCode(f)),btoa(d).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function M(a){let u=q(JSON.stringify(a));return u.length>6e3?null:u}var N=(a,u,d=u)=>{if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],o=!1,c=(...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 y(t){let e=D(t);if(!e||!g(e.hostname))return!1;let r=h(e.pathname),n=f.some(i=>i.test(r));return n&&c("detected checkout-like URL:",String(e)),n}function O(t){let e=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}}let b=null,v=0,S=3e4;async function x(){try{return await fetch("/cart.js").then(t=>t.json())}catch{return null}}function U(){b&&Date.now()-v<S||x().then(t=>{t&&(b=t,v=Date.now())})}function E(){b=null,v=0}function P(){return b&&Date.now()-v<S?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 H(){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 T(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 E(),r.json()}function k(t,e){let r=H(),n="";if(e)try{let l=M(R(e));l&&(n=`&cart=${l}`)}catch(l){console.error("[revley] slim-cart serialization failed; skipping",l)}let s=`${d.replace(/\/+$/,"")}/s/${r}?st=${encodeURIComponent(a)}#c=${encodeURIComponent(t)}${n}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(s)}async function _({cartSettled:t=!1}={}){if(t){let n=P();if(n&&n.item_count){let s=n.token?`gid://shopify/Cart/${n.token}`:C();if(s)return k(s,n)}let i=C();if(i)return k(i,null)}let e=P()||await x();if(e&&!e.item_count){c("cart is empty; skipping checkout redirect");return}let r=e?.token?`gid://shopify/Cart/${e.token}`:C();if(!r){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}k(r,e)}let L=!1;function p(t){return L||!y(t)?!1:(L=!0,_({cartSettled:!0}),!0)}if(window.__isCheckoutLike=y,window.__maybeRedirect=p,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),r=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:n=>{p(n)||e(n)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:n=>{p(n)||r(n)},writable:!0,configurable:!0})}catch(n){c("Could not override location methods, relying on Service Worker:",n)}}{let t=window.open;window.open=function(e,r,n){return e&&p(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&&p(i)))return t(r,n,i)},history.replaceState=function(r,n,i){if(!(i!=null&&p(i)))return e(r,n,i)},addEventListener("popstate",()=>void p(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||y(i.href)&&(r.preventDefault(),r.stopPropagation(),_({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(A(this))return t.call(this);let r=this.getAttribute("action")||"";if(p(r)||Array.from(this.elements).some(i=>i?.name==="checkout")&&p("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",e=>{try{let r=e.target;if(A(r))return;let n=r?.getAttribute("action")||"",i=Array.from(r?.elements||[]);(y(n)||i.some(s=>s?.name==="checkout"))&&(e.preventDefault(),e.stopPropagation(),_({cartSettled:!0}))}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,p(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(r,n,i,s,l){try{typeof n=="string"&&y(n)&&p(n)}catch{}return t.call(this,r,n,!!i,s,l)}}{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&&y(i)&&p(i)}catch{}return t(r,n)}}let A=t=>t?Array.from(t.elements).some(e=>{let r=e;return r.name?.includes("__kaching_bundles")||r.name?.includes("kaching")||t.classList.contains("kaching-form")}):!1;document.addEventListener("click",async t=>{let r=t.target?.closest?.("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 s=O(n)?.[0]?.id??51504147202335;if(!s)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 T(s,1),await _()}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(r,n){return n==="updateTieredPromotionsBar"?async function(...i){throw document.querySelectorAll(".shop-add-to-cart-button.product-form_submit").forEach(s=>{s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5";let l=s.cloneNode(!0);l.disabled=!0,l.style.pointerEvents="none",l.style.opacity="0.5",s.parentNode?.replaceChild(l,s)}),e&&await e.apply(this,i),E(),await Promise.all([new Promise(s=>setTimeout(s,1e4)),_()]),new Error("STOP")}:r[n]},set(r,n,i){return n==="updateTieredPromotionsBar"&&(e=i,c("Kaching updateTieredPromotionsBar captured")),r[n]=i,!0}})}function I(){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})}),t.parentNode?.replaceChild(e,t)}I(),new MutationObserver(()=>I()).observe(document.body,{childList:!0,subtree:!0});{let t=".custom_checkout_button_landing_page, .custom_checkout_button";document.addEventListener("click",async e=>{let r=e.target,n=r?.closest?.(t);if(!n)return;let i=r?.closest?.("[data-variant-id]"),s=n.getAttribute("data-variant-id")||(i&&n.contains(i)?i.getAttribute("data-variant-id"):null)||null;if(s){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation();try{await T(s,1),await _()}catch(l){console.error("Intercepted Zipify checkout failed:",l)}}},!0)}},j=()=>{let a=document.currentScript;if(!a)return;let u=a.dataset.revleyStoreId,d=a.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),f="http://localhost:3000",o="http://localhost:3002",c=d?f:a.dataset.revleyCheckoutHost,h=d?o:a.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||c;u&&c&&N(u,c,h)};j();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var SandboxCheckoutPkg=(()=>{var N=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,p,_)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==p&&N(o,m,{get:()=>l[m],enumerable:!(_=F(l,m))||_.enumerable});return o};var X=o=>W(N({},"__esModule",{value:!0}),o);var Q={};var y=o=>(o!=null?o:0)/100,Y=o=>((o!=null?o:0)/100).toFixed(2);function q(o){return o.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(l,p)=>String.fromCodePoint(Number(p))).replace(/&#x([0-9a-f]+);/gi,(l,p)=>String.fromCodePoint(parseInt(p,16))).replace(/&/g,"&")}function j(o){var m,g,k,O;let l=((m=o.items)!=null?m:[]).map(c=>{var v,C,E,T,U,L,A,S,H,P,x,h,I,d,R,M,D;let a=c.selling_plan_allocation,w=(v=c.line_level_discount_allocations)!=null?v:[];return{variantId:(C=c.variant_id)!=null?C:0,key:(T=c.key)!=null?T:String((E=c.variant_id)!=null?E:""),quantity:(U=c.quantity)!=null?U:0,productTitle:q((A=(L=c.product_title)!=null?L:c.title)!=null?A:""),variantTitle:c.variant_title?q(c.variant_title):void 0,price:Y(c.price),image:(P=(H=(S=c.featured_image)==null?void 0:S.url)!=null?H:c.image)!=null?P:void 0,unitPrice:y(c.price),totalPrice:y((x=c.original_line_price)!=null?x:c.line_price),lineTotalAfterDiscounts:y((h=c.final_line_price)!=null?h:c.line_price),totalDiscountAllocated:y(c.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?y(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?y(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(b=>{var t,e,n;return{title:q((e=(t=b.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:y(b.amount),code:((n=b.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:q((I=a.selling_plan.name)!=null?I:""),priceCents:(d=a.price)!=null?d:0,compareAtCents:(R=a.compare_at_price)!=null?R:0,perDeliveryCents:(M=a.per_delivery_price)!=null?M:0,options:((D=a.selling_plan.options)!=null?D:[]).map(b=>{var t,e;return{name:(t=b.name)!=null?t:"",value:(e=b.value)!=null?e:""}})}:void 0}}),_=((g=o.cart_level_discount_applications)!=null?g:[]).reduce((c,a)=>{var w;return c+y((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:y((O=o.items_subtotal_price)!=null?O:o.total_price),total:y(o.total_price),cartDiscount:_,items:l}}function J(o){let l=new TextEncoder().encode(o),p="";return l.forEach(_=>p+=String.fromCharCode(_)),btoa(p).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=J(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,p=l)=>{var D,b;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let _=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,g=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),O=t=>t.endsWith(".myshopify.com")||t===location.hostname;function c(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch(n){return null}}function a(t){let e=c(t);if(!e||!O(e.hostname))return!1;let n=k(e.pathname),r=_.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(""")?e.replace(/"/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch(r){return null}}let v=null,C=0,E=3e4;async function T(){try{return await fetch("/cart.js").then(t=>t.json())}catch(t){return null}}function U(){v&&Date.now()-C<E||T().then(t=>{t&&(v=t,C=Date.now())})}function L(){v=null,C=0}function A(){return v&&Date.now()-C<E?v:null}function S(){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 H(){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 P(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 L(),n.json()}function x(t,e){let n=H(),r="";if(e)try{let u=$(j(e));u&&(r=`&cart=${u}`)}catch(u){console.error("[revley] slim-cart serialization failed; skipping",u)}let s=`${p.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(s)}async function h({cartSettled:t=!1}={}){if(t){let r=A();if(r){if(!r.item_count){g("cart is empty; skipping checkout redirect");return}let s=r.token?`gid://shopify/Cart/${r.token}`:S();if(s)return x(s,r)}let i=S();if(i)return x(i,null)}let e=A()||await T();if(e&&!e.item_count){g("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:S();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}x(n,e)}let I=!1;function d(t){return I||!a(t)?!1:(I=!0,h({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=d,(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=>{d(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{d(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&&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||a(i.href)&&(n.preventDefault(),n.stopPropagation(),h({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(R(this))return t.call(this);let n=this.getAttribute("action")||"";if(d(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&d("/checkout"))return}catch(n){}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(R(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(s=>(s==null?void 0:s.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),h({cartSettled:!0}))}catch(n){}},!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,s,u){try{typeof r=="string"&&a(r)&&d(r)}catch(f){}return t.call(this,n,r,!!i,s,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&&a(i)&&d(i)}catch(i){}return t(n,r)}}let R=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,s,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 f=w(r),B=(u=(s=f==null?void 0:f[0])==null?void 0:s.id)!=null?u:51504147202335;if(!B)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 P(B,1),await h()}catch(f){console.error("Intercepted Buy It Now failed; falling back:",f),window.location.assign("/checkout")}}},!0);{let t={},e;(b=window.kachingCartApi)!=null&&b.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(s=>{var f;s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5";let u=s.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(f=s.parentNode)==null||f.replaceChild(u,s)}),e&&await e.apply(this,i),L(),await Promise.all([new Promise(s=>setTimeout(s,1e4)),h()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,g("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function M(){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",h({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}M(),new MutationObserver(()=>M()).observe(document.body,{childList:!0,subtree:!0});{let t=".custom_checkout_button_landing_page, .custom_checkout_button";document.addEventListener("click",async e=>{var u,f;let n=e.target,r=(u=n==null?void 0:n.closest)==null?void 0:u.call(n,t);if(!r)return;let i=(f=n==null?void 0:n.closest)==null?void 0:f.call(n,"[data-variant-id]"),s=r.getAttribute("data-variant-id")||(i&&r.contains(i)?i.getAttribute("data-variant-id"):null)||null;if(s){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation();try{await P(s,1),await h()}catch(B){console.error("Intercepted Zipify checkout failed:",B)}}},!0)}},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,p=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),_="http://localhost:3000",m="http://localhost:3002",g=p?_:o.dataset.revleyCheckoutHost,k=p?m:o.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||g;l&&g&&z(l,g,k)};G();return X(Q);})();
|
|
1
|
+
"use strict";var SandboxCheckoutPkg=(()=>{var N=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(o,l,p,_)=>{if(l&&typeof l=="object"||typeof l=="function")for(let m of K(l))!V.call(o,m)&&m!==p&&N(o,m,{get:()=>l[m],enumerable:!(_=F(l,m))||_.enumerable});return o};var X=o=>W(N({},"__esModule",{value:!0}),o);var Q={};var y=o=>(o!=null?o:0)/100,Y=o=>((o!=null?o:0)/100).toFixed(2);function q(o){return o.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/�*39;|'/g,"'").replace(/&#(\d+);/g,(l,p)=>String.fromCodePoint(Number(p))).replace(/&#x([0-9a-f]+);/gi,(l,p)=>String.fromCodePoint(parseInt(p,16))).replace(/&/g,"&")}function j(o){var m,f,k,O;let l=((m=o.items)!=null?m:[]).map(c=>{var v,C,E,T,U,L,A,S,H,P,x,h,I,d,R,M,D;let a=c.selling_plan_allocation,w=(v=c.line_level_discount_allocations)!=null?v:[];return{variantId:(C=c.variant_id)!=null?C:0,key:(T=c.key)!=null?T:String((E=c.variant_id)!=null?E:""),quantity:(U=c.quantity)!=null?U:0,productTitle:q((A=(L=c.product_title)!=null?L:c.title)!=null?A:""),variantTitle:c.variant_title?q(c.variant_title):void 0,price:Y(c.price),image:(P=(H=(S=c.featured_image)==null?void 0:S.url)!=null?H:c.image)!=null?P:void 0,unitPrice:y(c.price),totalPrice:y((x=c.original_line_price)!=null?x:c.line_price),lineTotalAfterDiscounts:y((h=c.final_line_price)!=null?h:c.line_price),totalDiscountAllocated:y(c.total_discount),compareAtPrice:(a==null?void 0:a.compare_at_price)!=null?y(a.compare_at_price):void 0,perDeliveryPrice:(a==null?void 0:a.per_delivery_price)!=null?y(a.per_delivery_price):void 0,discountAllocations:w.length?w.map(b=>{var t,e,n;return{title:q((e=(t=b.discount_application)==null?void 0:t.title)!=null?e:"Discount"),amount:y(b.amount),code:((n=b.discount_application)==null?void 0:n.code)||void 0}}):void 0,sellingPlan:a!=null&&a.selling_plan?{name:q((I=a.selling_plan.name)!=null?I:""),priceCents:(d=a.price)!=null?d:0,compareAtCents:(R=a.compare_at_price)!=null?R:0,perDeliveryCents:(M=a.per_delivery_price)!=null?M:0,options:((D=a.selling_plan.options)!=null?D:[]).map(b=>{var t,e;return{name:(t=b.name)!=null?t:"",value:(e=b.value)!=null?e:""}})}:void 0}}),_=((f=o.cart_level_discount_applications)!=null?f:[]).reduce((c,a)=>{var w;return c+y((w=a.total_allocated_amount)!=null?w:a.amount)},0);return{currency:(k=o.currency)!=null?k:"USD",subtotal:y((O=o.items_subtotal_price)!=null?O:o.total_price),total:y(o.total_price),cartDiscount:_,items:l}}function J(o){let l=new TextEncoder().encode(o),p="";return l.forEach(_=>p+=String.fromCharCode(_)),btoa(p).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $(o){let l=J(JSON.stringify(o));return l.length>6e3?null:l}var z=(o,l,p=l)=>{var D,b;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let _=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts(?:\/|$|\?|#)/i],m=!1,f=(...t)=>m?console.debug("[checkout-intercept]",...t):void 0,k=t=>t.replace(/\/+$/,""),O=t=>t.endsWith(".myshopify.com")||t===location.hostname;function c(t,e=location.origin){try{return t instanceof URL?t:new URL(String(t),e)}catch(n){return null}}function a(t){let e=c(t);if(!e||!O(e.hostname))return!1;let n=k(e.pathname),r=_.some(i=>i.test(n));return r&&f("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(""")?e.replace(/"/g,'"'):e;try{let r=JSON.parse(n);return Array.isArray(r)?r:null}catch(r){return null}}let v=null,C=0,E=3e4;async function T(){try{return await fetch("/cart.js").then(t=>t.json())}catch(t){return null}}function U(){v&&Date.now()-C<E||T().then(t=>{t&&(v=t,C=Date.now())})}function L(){v=null,C=0}function A(){return v&&Date.now()-C<E?v:null}function S(){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 H(){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 P(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 L(),n.json()}function x(t,e){let n=H(),r="";if(e)try{let u=$(j(e));u&&(r=`&cart=${u}`)}catch(u){console.error("[revley] slim-cart serialization failed; skipping",u)}let s=`${p.replace(/\/+$/,"")}/s/${n}?st=${encodeURIComponent(o)}#c=${encodeURIComponent(t)}${r}`;sessionStorage.setItem("__revley_checkout_redirect","1"),location.assign(s)}async function h({cartSettled:t=!1}={}){if(t){let r=A();if(r&&r.item_count){let s=r.token?`gid://shopify/Cart/${r.token}`:S();if(s)return x(s,r)}let i=S();if(i)return x(i,null)}let e=A()||await T();if(e&&!e.item_count){f("cart is empty; skipping checkout redirect");return}let n=e!=null&&e.token?`gid://shopify/Cart/${e.token}`:S();if(!n){console.error("[revley] no cart id available; using native checkout"),location.assign("/checkout");return}x(n,e)}let I=!1;function d(t){return I||!a(t)?!1:(I=!0,h({cartSettled:!0}),!0)}if(window.__isCheckoutLike=a,window.__maybeRedirect=d,(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=>{d(r)||e(r)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:r=>{d(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&&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||a(i.href)&&(n.preventDefault(),n.stopPropagation(),h({cartSettled:!0}))},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(R(this))return t.call(this);let n=this.getAttribute("action")||"";if(d(n)||Array.from(this.elements).some(i=>(i==null?void 0:i.name)==="checkout")&&d("/checkout"))return}catch(n){}return t.call(this)},addEventListener("submit",e=>{try{let n=e.target;if(R(n))return;let r=(n==null?void 0:n.getAttribute("action"))||"",i=Array.from((n==null?void 0:n.elements)||[]);(a(r)||i.some(s=>(s==null?void 0:s.name)==="checkout"))&&(e.preventDefault(),e.stopPropagation(),h({cartSettled:!0}))}catch(n){}},!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,s,u){try{typeof r=="string"&&a(r)&&d(r)}catch(g){}return t.call(this,n,r,!!i,s,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&&a(i)&&d(i)}catch(i){}return t(n,r)}}let R=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,s,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 g=w(r),B=(u=(s=g==null?void 0:g[0])==null?void 0:s.id)!=null?u:51504147202335;if(!B)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 P(B,1),await h()}catch(g){console.error("Intercepted Buy It Now failed; falling back:",g),window.location.assign("/checkout")}}},!0);{let t={},e;(b=window.kachingCartApi)!=null&&b.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(s=>{var g;s.disabled=!0,s.style.pointerEvents="none",s.style.opacity="0.5";let u=s.cloneNode(!0);u.disabled=!0,u.style.pointerEvents="none",u.style.opacity="0.5",(g=s.parentNode)==null||g.replaceChild(u,s)}),e&&await e.apply(this,i),L(),await Promise.all([new Promise(s=>setTimeout(s,1e4)),h()]),new Error("STOP")}:n[r]},set(n,r,i){return r==="updateTieredPromotionsBar"&&(e=i,f("Kaching updateTieredPromotionsBar captured")),n[r]=i,!0}})}function M(){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",h({cartSettled:!0})}),(n=t.parentNode)==null||n.replaceChild(e,t)}M(),new MutationObserver(()=>M()).observe(document.body,{childList:!0,subtree:!0});{let t=".custom_checkout_button_landing_page, .custom_checkout_button";document.addEventListener("click",async e=>{var u,g;let n=e.target,r=(u=n==null?void 0:n.closest)==null?void 0:u.call(n,t);if(!r)return;let i=(g=n==null?void 0:n.closest)==null?void 0:g.call(n,"[data-variant-id]"),s=r.getAttribute("data-variant-id")||(i&&r.contains(i)?i.getAttribute("data-variant-id"):null)||null;if(s){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation();try{await P(s,1),await h()}catch(B){console.error("Intercepted Zipify checkout failed:",B)}}},!0)}},G=()=>{let o=document.currentScript;if(!o)return;let l=o.dataset.revleyStoreId,p=o.dataset.revleyIsDev!==void 0&&new URLSearchParams(location.search).has("dev"),_="http://localhost:3000",m="http://localhost:3002",f=p?_:o.dataset.revleyCheckoutHost,k=p?m:o.dataset.revleyCheckoutDomain||window.__REVLEY_CHECKOUT_DOMAIN__||f;l&&f&&z(l,f,k)};G();return X(Q);})();
|