@revley/sandbox-checkout-package 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Package for redirecting browser
2
-
3
- ### How to make a change
4
-
5
- #### TODO: make this a github action
6
-
7
- 1. Make the code change
8
- 2. update the package.json version number
9
- 3. run `npm run build`
10
- 4. run `npm publish --public`
1
+ # Package for redirecting browser
2
+
3
+ ### How to make a change
4
+
5
+ #### TODO: make this a github action
6
+
7
+ 1. Make the code change
8
+ 2. update the package.json version number
9
+ 3. run `npm run build`
10
+ 4. run `npm publish --public`
@@ -1 +1 @@
1
- "use strict";var R=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var H=(d,l,h,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let u of x(l))!U.call(d,u)&&u!==h&&R(d,u,{get:()=>l[u],enumerable:!(f=A(l,u))||f.enumerable});return d};var M=d=>H(R({},"__esModule",{value:!0}),d);var S={};module.exports=M(S);window.initRevleyCheckout=(d,l)=>{var w;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let h=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],f=!1,u=(...i)=>f?console.debug("[checkout-intercept]",...i):void 0,k=i=>i.replace(/\/+$/,""),E=i=>i.endsWith(".myshopify.com")||i===location.hostname;function P(i,r=location.origin){try{return i instanceof URL?i:new URL(String(i),r)}catch{return null}}function p(i){let r=P(i);if(!r||!E(r.hostname))return!1;let e=k(r.pathname),t=h.some(n=>n.test(e));return t&&u("detected checkout-like URL:",String(r)),t}async function g(){let r=await(await fetch("/cart.js")).json(),e=r.discount_codes||[],t=(r.items||[]).map(o=>({variantId:o==null?void 0:o.variant_id,quantity:(o==null?void 0:o.quantity)||0,sellingPlanAllocation:(o==null?void 0:o.selling_plan_allocation)||null})).filter(o=>!!o.variantId&&o.quantity>0),n={},a=["_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_"],c=o=>a.some(m=>o===m||o.startsWith(m)||o.includes(m));document.cookie&&document.cookie.split(";").forEach(o=>{let m=o.trim();if(m){let[y,...T]=m.split("="),L=T.join("=");y&&L&&c(y)&&(n[y]=L)}});let _=await(await fetch(`${l}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variants:t,storeId:d,cookies:n})})).text();if(console.log("checkoutUrl",_),_)location.assign(_);else{console.error("No checkout ID received from backend");return}}let v=!1;function s(i){return v||!p(i)?!1:(v=!0,g(),!0)}if(window.__isCheckoutLike=p,window.__maybeRedirect=s,!((w=window.Shopify)!=null&&w.designMode)){{let i=window.location,r=i.assign.bind(i),e=i.replace.bind(i);try{Object.defineProperty(i,"assign",{value:t=>{s(t)||r(t)},writable:!0,configurable:!0}),Object.defineProperty(i,"replace",{value:t=>{s(t)||e(t)},writable:!0,configurable:!0})}catch(t){u("Could not override location methods, relying on Service Worker:",t)}}{let i=window.open;window.open=function(r,e,t){return r&&s(r)?null:i.call(window,r,e,t)}}{let i=history.pushState.bind(history),r=history.replaceState.bind(history);history.pushState=function(e,t,n){if(!(n!=null&&s(n)))return i(e,t,n)},history.replaceState=function(e,t,n){if(!(n!=null&&s(n)))return r(e,t,n)},addEventListener("popstate",()=>void s(location.href),!0)}{let i=r=>r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||r.button!==0;addEventListener("click",r=>{let e=r;if(e.defaultPrevented||i(e))return;let t=r.target;for(;t&&t.nodeType===1&&t.tagName!=="A";)t=t.parentElement;let n=t;!n||!n.href||p(n.href)&&(e.preventDefault(),e.stopPropagation(),g())},!0)}{let i=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{let e=this.getAttribute("action")||"";if(s(e)||Array.from(this.elements).some(n=>(n==null?void 0:n.name)==="checkout")&&s("/checkout"))return}catch{}return i.call(this)},addEventListener("submit",r=>{try{let e=r.target,t=(e==null?void 0:e.getAttribute("action"))||"",n=Array.from((e==null?void 0:e.elements)||[]);(p(t)||n.some(a=>(a==null?void 0:a.name)==="checkout"))&&(r.preventDefault(),r.stopPropagation(),g())}catch{}},!0)}{let i=location.href;setInterval(()=>{location.href!==i&&(i=location.href,s(i))},250)}{let i=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,t,n,a,c){try{typeof t=="string"&&p(t)&&s(t)}catch{}return i.call(this,e,t,!!n,a,c)}}{let i=window.fetch.bind(window);window.fetch=function(e,t){try{let n=typeof e=="string"||e instanceof URL?String(e):e.url;n&&p(n)&&s(n)}catch{}return i(e,t)}}{let i=e=>{var n;return(((n=e.textContent)==null?void 0:n.trim().toUpperCase())||"")==="BUY NOW"};async function r(e){let t=new FormData(e),n=await fetch("/cart/add.js",{method:"POST",body:t,credentials:"same-origin",headers:{Accept:"application/json"}});if(!n.ok){let a=await n.text().catch(()=>"");throw new Error(`Add to cart failed: ${n.status} ${a}`)}return n.json().catch(()=>({}))}document.addEventListener("click",async e=>{var c,b;let t=(b=(c=e.target)==null?void 0:c.closest)==null?void 0:b.call(c,'button[type="submit"], input[type="submit"]');if(!t||!i(t))return;let n=t.form||t.closest("form");if(!(!n||!(n.getAttribute("action")||"").toLowerCase().includes("/cart/add"))){e.preventDefault(),e.stopImmediatePropagation();try{await r(n),g()}catch(_){console.error("[BUY NOW override] failed, falling back:",_),n.submit()}}},!0),document.addEventListener("submit",e=>{let t=e.target;!(t instanceof HTMLFormElement)||!(t.getAttribute("action")||"").toLowerCase().includes("/cart/add")||!Array.from(t.querySelectorAll('button[type="submit"],input[type="submit"]')).some(i)||(e.preventDefault(),e.stopImmediatePropagation(),r(t).then(()=>g()).catch(c=>{console.error("[BUY NOW override] submit path failed:",c),t.submit()}))},!0)}}};
1
+ "use strict";var T=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var I=(c,a,f,g)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of S(a))!C.call(c,s)&&s!==f&&T(c,s,{get:()=>a[s],enumerable:!(g=x(a,s))||g.enumerable});return c};var H=c=>I(T({},"__esModule",{value:!0}),c);var M={};module.exports=H(M);window.initRevleyCheckout=(c,a)=>{var k,v;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],g=!1,s=(...t)=>g?console.debug("[checkout-intercept]",...t):void 0,A=t=>t.replace(/\/+$/,""),U=t=>t.endsWith(".myshopify.com")||t===location.hostname;function b(t,i=location.origin){try{return t instanceof URL?t:new URL(String(t),i)}catch{return null}}function u(t){let i=b(t);if(!i||!U(i.hostname))return!1;let n=A(i.pathname),e=f.some(r=>r.test(n));return e&&s("detected checkout-like URL:",String(i)),e}async function _(){let i=await(await fetch("/cart.js")).json(),n={},e=["_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_"],r=p=>e.some(d=>p===d||p.startsWith(d)||p.includes(d));document.cookie&&document.cookie.split(";").forEach(p=>{let d=p.trim();if(d){let[h,...E]=d.split("="),P=E.join("=");h&&P&&r(h)&&(n[h]=P)}});let l=`gid://shopify/Cart/${i.token}`,m=await(await fetch(`${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:c,cartId:l,cookies:n})})).text();if(console.log("checkoutUrl",m),!m){console.error("No checkout ID received from backend");return}let L=b(m);if(!L){console.error("Invalid checkout URL received from backend:",m);return}location.assign(L.href)}let y=!1;function o(t){return y||!u(t)?!1:(y=!0,_(),!0)}if(window.__isCheckoutLike=u,window.__maybeRedirect=o,(k=window.Shopify)!=null&&k.designMode)return;{let t=window.location,i=t.assign.bind(t),n=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:e=>{o(e)||i(e)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:e=>{o(e)||n(e)},writable:!0,configurable:!0})}catch(e){s("Could not override location methods, relying on Service Worker:",e)}}{let t=window.open;window.open=function(i,n,e){return i&&o(i)?null:t.call(window,i,n,e)}}{let t=history.pushState.bind(history),i=history.replaceState.bind(history);history.pushState=function(n,e,r){if(!(r!=null&&o(r)))return t(n,e,r)},history.replaceState=function(n,e,r){if(!(r!=null&&o(r)))return i(n,e,r)},addEventListener("popstate",()=>void o(location.href),!0)}{let t=i=>i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||i.button!==0;addEventListener("click",i=>{let n=i;if(n.defaultPrevented||t(n))return;let e=i.target;for(;e&&e.nodeType===1&&e.tagName!=="A";)e=e.parentElement;let r=e;!r||!r.href||u(r.href)&&(n.preventDefault(),n.stopPropagation(),_())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(w(this))return t.call(this);let n=this.getAttribute("action")||"";if(o(n)||Array.from(this.elements).some(r=>(r==null?void 0:r.name)==="checkout")&&o("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",i=>{try{let n=i.target;if(w(n))return;let e=(n==null?void 0:n.getAttribute("action"))||"",r=Array.from((n==null?void 0:n.elements)||[]);(u(e)||r.some(l=>(l==null?void 0:l.name)==="checkout"))&&(i.preventDefault(),i.stopPropagation(),_())}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,o(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,e,r,l,R){try{typeof e=="string"&&u(e)&&o(e)}catch{}return t.call(this,n,e,!!r,l,R)}}{let t=window.fetch.bind(window);window.fetch=function(n,e){try{let r=typeof n=="string"||n instanceof URL?String(n):n.url;r&&u(r)&&o(r)}catch{}return t(n,e)}}let w=t=>t?Array.from(t.elements).some(i=>{var e,r;let n=i;return((e=n.name)==null?void 0:e.includes("__kaching_bundles"))||((r=n.name)==null?void 0:r.includes("kaching"))||t.classList.contains("kaching-form")}):!1;{let t={},i;(v=window.kachingCartApi)!=null&&v.updateTieredPromotionsBar&&(i=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(n,e){return e==="updateTieredPromotionsBar"?async function(...r){i&&await i.apply(this,r),_()}:n[e]},set(n,e,r){return e==="updateTieredPromotionsBar"&&(i=r,s("Kaching updateTieredPromotionsBar captured")),n[e]=r,!0}})}};
@@ -1,6 +1,9 @@
1
1
  declare global {
2
2
  interface Window {
3
3
  initRevleyCheckout: (storeId: string, checkoutHost: string) => void;
4
+ kachingCartApi: {
5
+ updateTieredPromotionsBar: () => void;
6
+ };
4
7
  }
5
8
  }
6
9
 
@@ -46,7 +49,10 @@ interface Item {
46
49
  line_price?: number;
47
50
  original_line_price?: number;
48
51
  total_discount?: number;
49
- discounts?: any[];
52
+ discounts?: {
53
+ amount: number;
54
+ title: string;
55
+ }[];
50
56
  sku?: string;
51
57
  grams?: number;
52
58
  vendor?: string;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- window.initRevleyCheckout=(h,b)=>{if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let y=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],v=!1,g=(...e)=>v?console.debug("[checkout-intercept]",...e):void 0,w=e=>e.replace(/\/+$/,""),L=e=>e.endsWith(".myshopify.com")||e===location.hostname;function R(e,r=location.origin){try{return e instanceof URL?e:new URL(String(e),r)}catch{return null}}function l(e){let r=R(e);if(!r||!L(r.hostname))return!1;let n=w(r.pathname),t=y.some(i=>i.test(n));return t&&g("detected checkout-like URL:",String(r)),t}async function d(){let r=await(await fetch("/cart.js")).json(),n=r.discount_codes||[],t=(r.items||[]).map(s=>({variantId:s?.variant_id,quantity:s?.quantity||0,sellingPlanAllocation:s?.selling_plan_allocation||null})).filter(s=>!!s.variantId&&s.quantity>0),i={},a=["_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_"],c=s=>a.some(u=>s===u||s.startsWith(u)||s.includes(u));document.cookie&&document.cookie.split(";").forEach(s=>{let u=s.trim();if(u){let[m,...k]=u.split("="),f=k.join("=");m&&f&&c(m)&&(i[m]=f)}});let p=await(await fetch(`${b}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variants:t,storeId:h,cookies:i})})).text();if(console.log("checkoutUrl",p),p)location.assign(p);else{console.error("No checkout ID received from backend");return}}let _=!1;function o(e){return _||!l(e)?!1:(_=!0,d(),!0)}if(window.__isCheckoutLike=l,window.__maybeRedirect=o,!window.Shopify?.designMode){{let e=window.location,r=e.assign.bind(e),n=e.replace.bind(e);try{Object.defineProperty(e,"assign",{value:t=>{o(t)||r(t)},writable:!0,configurable:!0}),Object.defineProperty(e,"replace",{value:t=>{o(t)||n(t)},writable:!0,configurable:!0})}catch(t){g("Could not override location methods, relying on Service Worker:",t)}}{let e=window.open;window.open=function(r,n,t){return r&&o(r)?null:e.call(window,r,n,t)}}{let e=history.pushState.bind(history),r=history.replaceState.bind(history);history.pushState=function(n,t,i){if(!(i!=null&&o(i)))return e(n,t,i)},history.replaceState=function(n,t,i){if(!(i!=null&&o(i)))return r(n,t,i)},addEventListener("popstate",()=>void o(location.href),!0)}{let e=r=>r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||r.button!==0;addEventListener("click",r=>{let n=r;if(n.defaultPrevented||e(n))return;let t=r.target;for(;t&&t.nodeType===1&&t.tagName!=="A";)t=t.parentElement;let i=t;!i||!i.href||l(i.href)&&(n.preventDefault(),n.stopPropagation(),d())},!0)}{let e=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{let n=this.getAttribute("action")||"";if(o(n)||Array.from(this.elements).some(i=>i?.name==="checkout")&&o("/checkout"))return}catch{}return e.call(this)},addEventListener("submit",r=>{try{let n=r.target,t=n?.getAttribute("action")||"",i=Array.from(n?.elements||[]);(l(t)||i.some(a=>a?.name==="checkout"))&&(r.preventDefault(),r.stopPropagation(),d())}catch{}},!0)}{let e=location.href;setInterval(()=>{location.href!==e&&(e=location.href,o(e))},250)}{let e=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(n,t,i,a,c){try{typeof t=="string"&&l(t)&&o(t)}catch{}return e.call(this,n,t,!!i,a,c)}}{let e=window.fetch.bind(window);window.fetch=function(n,t){try{let i=typeof n=="string"||n instanceof URL?String(n):n.url;i&&l(i)&&o(i)}catch{}return e(n,t)}}{let e=n=>(n.textContent?.trim().toUpperCase()||"")==="BUY NOW";async function r(n){let t=new FormData(n),i=await fetch("/cart/add.js",{method:"POST",body:t,credentials:"same-origin",headers:{Accept:"application/json"}});if(!i.ok){let a=await i.text().catch(()=>"");throw new Error(`Add to cart failed: ${i.status} ${a}`)}return i.json().catch(()=>({}))}document.addEventListener("click",async n=>{let t=n.target?.closest?.('button[type="submit"], input[type="submit"]');if(!t||!e(t))return;let i=t.form||t.closest("form");if(!(!i||!(i.getAttribute("action")||"").toLowerCase().includes("/cart/add"))){n.preventDefault(),n.stopImmediatePropagation();try{await r(i),d()}catch(c){console.error("[BUY NOW override] failed, falling back:",c),i.submit()}}},!0),document.addEventListener("submit",n=>{let t=n.target;!(t instanceof HTMLFormElement)||!(t.getAttribute("action")||"").toLowerCase().includes("/cart/add")||!Array.from(t.querySelectorAll('button[type="submit"],input[type="submit"]')).some(e)||(n.preventDefault(),n.stopImmediatePropagation(),r(t).then(()=>d()).catch(c=>{console.error("[BUY NOW override] submit path failed:",c),t.submit()}))},!0)}}};
1
+ window.initRevleyCheckout=(w,k)=>{if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let v=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],R=!1,p=(...t)=>R?console.debug("[checkout-intercept]",...t):void 0,L=t=>t.replace(/\/+$/,""),P=t=>t.endsWith(".myshopify.com")||t===location.hostname;function m(t,n=location.origin){try{return t instanceof URL?t:new URL(String(t),n)}catch{return null}}function s(t){let n=m(t);if(!n||!P(n.hostname))return!1;let i=L(n.pathname),e=v.some(r=>r.test(i));return e&&p("detected checkout-like URL:",String(n)),e}async function u(){let n=await(await fetch("/cart.js")).json(),i={},e=["_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_"],r=l=>e.some(a=>l===a||l.startsWith(a)||l.includes(a));document.cookie&&document.cookie.split(";").forEach(l=>{let a=l.trim();if(a){let[g,...T]=a.split("="),y=T.join("=");g&&y&&r(g)&&(i[g]=y)}});let c=`gid://shopify/Cart/${n.token}`,d=await(await fetch(`${k}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:w,cartId:c,cookies:i})})).text();if(console.log("checkoutUrl",d),!d){console.error("No checkout ID received from backend");return}let b=m(d);if(!b){console.error("Invalid checkout URL received from backend:",d);return}location.assign(b.href)}let _=!1;function o(t){return _||!s(t)?!1:(_=!0,u(),!0)}if(window.__isCheckoutLike=s,window.__maybeRedirect=o,window.Shopify?.designMode)return;{let t=window.location,n=t.assign.bind(t),i=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:e=>{o(e)||n(e)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:e=>{o(e)||i(e)},writable:!0,configurable:!0})}catch(e){p("Could not override location methods, relying on Service Worker:",e)}}{let t=window.open;window.open=function(n,i,e){return n&&o(n)?null:t.call(window,n,i,e)}}{let t=history.pushState.bind(history),n=history.replaceState.bind(history);history.pushState=function(i,e,r){if(!(r!=null&&o(r)))return t(i,e,r)},history.replaceState=function(i,e,r){if(!(r!=null&&o(r)))return n(i,e,r)},addEventListener("popstate",()=>void o(location.href),!0)}{let t=n=>n.metaKey||n.ctrlKey||n.shiftKey||n.altKey||n.button!==0;addEventListener("click",n=>{let i=n;if(i.defaultPrevented||t(i))return;let e=n.target;for(;e&&e.nodeType===1&&e.tagName!=="A";)e=e.parentElement;let r=e;!r||!r.href||s(r.href)&&(i.preventDefault(),i.stopPropagation(),u())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(f(this))return t.call(this);let i=this.getAttribute("action")||"";if(o(i)||Array.from(this.elements).some(r=>r?.name==="checkout")&&o("/checkout"))return}catch{}return t.call(this)},addEventListener("submit",n=>{try{let i=n.target;if(f(i))return;let e=i?.getAttribute("action")||"",r=Array.from(i?.elements||[]);(s(e)||r.some(c=>c?.name==="checkout"))&&(n.preventDefault(),n.stopPropagation(),u())}catch{}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,o(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(i,e,r,c,h){try{typeof e=="string"&&s(e)&&o(e)}catch{}return t.call(this,i,e,!!r,c,h)}}{let t=window.fetch.bind(window);window.fetch=function(i,e){try{let r=typeof i=="string"||i instanceof URL?String(i):i.url;r&&s(r)&&o(r)}catch{}return t(i,e)}}let f=t=>t?Array.from(t.elements).some(n=>{let i=n;return i.name?.includes("__kaching_bundles")||i.name?.includes("kaching")||t.classList.contains("kaching-form")}):!1;{let t={},n;window.kachingCartApi?.updateTieredPromotionsBar&&(n=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(i,e){return e==="updateTieredPromotionsBar"?async function(...r){n&&await n.apply(this,r),u()}:i[e]},set(i,e,r){return e==="updateTieredPromotionsBar"&&(n=r,p("Kaching updateTieredPromotionsBar captured")),i[e]=r,!0}})}};
@@ -1 +1 @@
1
- "use strict";var SandboxCheckoutPkg=(()=>{var R=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var H=(d,l,b,f)=>{if(l&&typeof l=="object"||typeof l=="function")for(let u of x(l))!U.call(d,u)&&u!==b&&R(d,u,{get:()=>l[u],enumerable:!(f=A(l,u))||f.enumerable});return d};var M=d=>H(R({},"__esModule",{value:!0}),d);var S={};window.initRevleyCheckout=(d,l)=>{var w;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let b=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],f=!1,u=(...i)=>f?console.debug("[checkout-intercept]",...i):void 0,k=i=>i.replace(/\/+$/,""),E=i=>i.endsWith(".myshopify.com")||i===location.hostname;function P(i,r=location.origin){try{return i instanceof URL?i:new URL(String(i),r)}catch(e){return null}}function p(i){let r=P(i);if(!r||!E(r.hostname))return!1;let e=k(r.pathname),t=b.some(n=>n.test(e));return t&&u("detected checkout-like URL:",String(r)),t}async function g(){let r=await(await fetch("/cart.js")).json(),e=r.discount_codes||[],t=(r.items||[]).map(o=>({variantId:o==null?void 0:o.variant_id,quantity:(o==null?void 0:o.quantity)||0,sellingPlanAllocation:(o==null?void 0:o.selling_plan_allocation)||null})).filter(o=>!!o.variantId&&o.quantity>0),n={},a=["_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_"],c=o=>a.some(m=>o===m||o.startsWith(m)||o.includes(m));document.cookie&&document.cookie.split(";").forEach(o=>{let m=o.trim();if(m){let[y,...T]=m.split("="),L=T.join("=");y&&L&&c(y)&&(n[y]=L)}});let _=await(await fetch(`${l}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variants:t,storeId:d,cookies:n})})).text();if(console.log("checkoutUrl",_),_)location.assign(_);else{console.error("No checkout ID received from backend");return}}let v=!1;function s(i){return v||!p(i)?!1:(v=!0,g(),!0)}if(window.__isCheckoutLike=p,window.__maybeRedirect=s,!((w=window.Shopify)!=null&&w.designMode)){{let i=window.location,r=i.assign.bind(i),e=i.replace.bind(i);try{Object.defineProperty(i,"assign",{value:t=>{s(t)||r(t)},writable:!0,configurable:!0}),Object.defineProperty(i,"replace",{value:t=>{s(t)||e(t)},writable:!0,configurable:!0})}catch(t){u("Could not override location methods, relying on Service Worker:",t)}}{let i=window.open;window.open=function(r,e,t){return r&&s(r)?null:i.call(window,r,e,t)}}{let i=history.pushState.bind(history),r=history.replaceState.bind(history);history.pushState=function(e,t,n){if(!(n!=null&&s(n)))return i(e,t,n)},history.replaceState=function(e,t,n){if(!(n!=null&&s(n)))return r(e,t,n)},addEventListener("popstate",()=>void s(location.href),!0)}{let i=r=>r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||r.button!==0;addEventListener("click",r=>{let e=r;if(e.defaultPrevented||i(e))return;let t=r.target;for(;t&&t.nodeType===1&&t.tagName!=="A";)t=t.parentElement;let n=t;!n||!n.href||p(n.href)&&(e.preventDefault(),e.stopPropagation(),g())},!0)}{let i=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{let e=this.getAttribute("action")||"";if(s(e)||Array.from(this.elements).some(n=>(n==null?void 0:n.name)==="checkout")&&s("/checkout"))return}catch(e){}return i.call(this)},addEventListener("submit",r=>{try{let e=r.target,t=(e==null?void 0:e.getAttribute("action"))||"",n=Array.from((e==null?void 0:e.elements)||[]);(p(t)||n.some(a=>(a==null?void 0:a.name)==="checkout"))&&(r.preventDefault(),r.stopPropagation(),g())}catch(e){}},!0)}{let i=location.href;setInterval(()=>{location.href!==i&&(i=location.href,s(i))},250)}{let i=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,t,n,a,c){try{typeof t=="string"&&p(t)&&s(t)}catch(h){}return i.call(this,e,t,!!n,a,c)}}{let i=window.fetch.bind(window);window.fetch=function(e,t){try{let n=typeof e=="string"||e instanceof URL?String(e):e.url;n&&p(n)&&s(n)}catch(n){}return i(e,t)}}{let i=e=>{var n;return(((n=e.textContent)==null?void 0:n.trim().toUpperCase())||"")==="BUY NOW"};async function r(e){let t=new FormData(e),n=await fetch("/cart/add.js",{method:"POST",body:t,credentials:"same-origin",headers:{Accept:"application/json"}});if(!n.ok){let a=await n.text().catch(()=>"");throw new Error(`Add to cart failed: ${n.status} ${a}`)}return n.json().catch(()=>({}))}document.addEventListener("click",async e=>{var c,h;let t=(h=(c=e.target)==null?void 0:c.closest)==null?void 0:h.call(c,'button[type="submit"], input[type="submit"]');if(!t||!i(t))return;let n=t.form||t.closest("form");if(!(!n||!(n.getAttribute("action")||"").toLowerCase().includes("/cart/add"))){e.preventDefault(),e.stopImmediatePropagation();try{await r(n),g()}catch(_){console.error("[BUY NOW override] failed, falling back:",_),n.submit()}}},!0),document.addEventListener("submit",e=>{let t=e.target;!(t instanceof HTMLFormElement)||!(t.getAttribute("action")||"").toLowerCase().includes("/cart/add")||!Array.from(t.querySelectorAll('button[type="submit"],input[type="submit"]')).some(i)||(e.preventDefault(),e.stopImmediatePropagation(),r(t).then(()=>g()).catch(c=>{console.error("[BUY NOW override] submit path failed:",c),t.submit()}))},!0)}}};return M(S);})();
1
+ "use strict";var SandboxCheckoutPkg=(()=>{var T=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var I=(c,a,f,_)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of S(a))!C.call(c,s)&&s!==f&&T(c,s,{get:()=>a[s],enumerable:!(_=x(a,s))||_.enumerable});return c};var H=c=>I(T({},"__esModule",{value:!0}),c);var M={};window.initRevleyCheckout=(c,a)=>{var k,v;if(window.__checkoutInterceptInstalled)return;window.__checkoutInterceptInstalled=!0;let f=[/^\/(?:cart\/)?checkout(?:[?#]|$)/i,/^\/checkouts\/[a-z0-9]{32}(?:[\/?#]|$)/i],_=!1,s=(...t)=>_?console.debug("[checkout-intercept]",...t):void 0,A=t=>t.replace(/\/+$/,""),U=t=>t.endsWith(".myshopify.com")||t===location.hostname;function b(t,i=location.origin){try{return t instanceof URL?t:new URL(String(t),i)}catch(e){return null}}function u(t){let i=b(t);if(!i||!U(i.hostname))return!1;let e=A(i.pathname),n=f.some(r=>r.test(e));return n&&s("detected checkout-like URL:",String(i)),n}async function m(){let i=await(await fetch("/cart.js")).json(),e={},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_"],r=g=>n.some(d=>g===d||g.startsWith(d)||g.includes(d));document.cookie&&document.cookie.split(";").forEach(g=>{let d=g.trim();if(d){let[h,...E]=d.split("="),P=E.join("=");h&&P&&r(h)&&(e[h]=P)}});let l=`gid://shopify/Cart/${i.token}`,p=await(await fetch(`${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:c,cartId:l,cookies:e})})).text();if(console.log("checkoutUrl",p),!p){console.error("No checkout ID received from backend");return}let L=b(p);if(!L){console.error("Invalid checkout URL received from backend:",p);return}location.assign(L.href)}let y=!1;function o(t){return y||!u(t)?!1:(y=!0,m(),!0)}if(window.__isCheckoutLike=u,window.__maybeRedirect=o,(k=window.Shopify)!=null&&k.designMode)return;{let t=window.location,i=t.assign.bind(t),e=t.replace.bind(t);try{Object.defineProperty(t,"assign",{value:n=>{o(n)||i(n)},writable:!0,configurable:!0}),Object.defineProperty(t,"replace",{value:n=>{o(n)||e(n)},writable:!0,configurable:!0})}catch(n){s("Could not override location methods, relying on Service Worker:",n)}}{let t=window.open;window.open=function(i,e,n){return i&&o(i)?null:t.call(window,i,e,n)}}{let t=history.pushState.bind(history),i=history.replaceState.bind(history);history.pushState=function(e,n,r){if(!(r!=null&&o(r)))return t(e,n,r)},history.replaceState=function(e,n,r){if(!(r!=null&&o(r)))return i(e,n,r)},addEventListener("popstate",()=>void o(location.href),!0)}{let t=i=>i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||i.button!==0;addEventListener("click",i=>{let e=i;if(e.defaultPrevented||t(e))return;let n=i.target;for(;n&&n.nodeType===1&&n.tagName!=="A";)n=n.parentElement;let r=n;!r||!r.href||u(r.href)&&(e.preventDefault(),e.stopPropagation(),m())},!0)}{let t=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){try{if(w(this))return t.call(this);let e=this.getAttribute("action")||"";if(o(e)||Array.from(this.elements).some(r=>(r==null?void 0:r.name)==="checkout")&&o("/checkout"))return}catch(e){}return t.call(this)},addEventListener("submit",i=>{try{let e=i.target;if(w(e))return;let n=(e==null?void 0:e.getAttribute("action"))||"",r=Array.from((e==null?void 0:e.elements)||[]);(u(n)||r.some(l=>(l==null?void 0:l.name)==="checkout"))&&(i.preventDefault(),i.stopPropagation(),m())}catch(e){}},!0)}{let t=location.href;setInterval(()=>{location.href!==t&&(t=location.href,o(t))},250)}{let t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,n,r,l,R){try{typeof n=="string"&&u(n)&&o(n)}catch(p){}return t.call(this,e,n,!!r,l,R)}}{let t=window.fetch.bind(window);window.fetch=function(e,n){try{let r=typeof e=="string"||e instanceof URL?String(e):e.url;r&&u(r)&&o(r)}catch(r){}return t(e,n)}}let w=t=>t?Array.from(t.elements).some(i=>{var n,r;let e=i;return((n=e.name)==null?void 0:n.includes("__kaching_bundles"))||((r=e.name)==null?void 0:r.includes("kaching"))||t.classList.contains("kaching-form")}):!1;{let t={},i;(v=window.kachingCartApi)!=null&&v.updateTieredPromotionsBar&&(i=window.kachingCartApi.updateTieredPromotionsBar,Object.assign(t,window.kachingCartApi)),window.kachingCartApi=new Proxy(t,{get(e,n){return n==="updateTieredPromotionsBar"?async function(...r){i&&await i.apply(this,r),m()}:e[n]},set(e,n,r){return n==="updateTieredPromotionsBar"&&(i=r,s("Kaching updateTieredPromotionsBar captured")),e[n]=r,!0}})}};return H(M);})();
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@revley/sandbox-checkout-package",
3
- "version": "0.2.0",
4
- "description": "Tiny TS package optimized for browsers with modern & legacy outputs",
5
- "type": "module",
6
- "main": "./dist/cjs/index.cjs",
7
- "module": "./dist/esm/index.js",
8
- "types": "./dist/esm/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/esm/index.d.ts",
12
- "import": "./dist/esm/index.js",
13
- "require": "./dist/cjs/index.cjs",
14
- "browser": "./dist/esm/index.js",
15
- "default": "./dist/esm/index.js"
16
- },
17
- "./iife": {
18
- "default": "./dist/iife/index.global.js"
19
- }
20
- },
21
- "sideEffects": false,
22
- "scripts": {
23
- "build": "tsup",
24
- "clean": "git clean -fdX dist || true",
25
- "prepublishOnly": "npm run build"
26
- },
27
- "keywords": [
28
- "typescript",
29
- "browser",
30
- "vite",
31
- "tsup",
32
- "checkout"
33
- ],
34
- "author": "You",
35
- "license": "MIT",
36
- "engines": {
37
- "node": ">=18.0.0"
38
- },
39
- "files": [
40
- "dist"
41
- ],
42
- "publishConfig": {
43
- "access": "public"
44
- },
45
- "devDependencies": {
46
- "@types/node": "^22.0.0",
47
- "tsup": "^8.0.0",
48
- "typescript": "^5.6.0"
49
- }
50
- }
1
+ {
2
+ "name": "@revley/sandbox-checkout-package",
3
+ "version": "0.2.1",
4
+ "description": "Tiny TS package optimized for browsers with modern & legacy outputs",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "import": "./dist/esm/index.js",
13
+ "require": "./dist/cjs/index.cjs",
14
+ "browser": "./dist/esm/index.js",
15
+ "default": "./dist/esm/index.js"
16
+ },
17
+ "./iife": {
18
+ "default": "./dist/iife/index.global.js"
19
+ }
20
+ },
21
+ "sideEffects": false,
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "clean": "git clean -fdX dist || true",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "typescript",
29
+ "browser",
30
+ "vite",
31
+ "tsup",
32
+ "checkout"
33
+ ],
34
+ "author": "You",
35
+ "license": "MIT",
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.0.0",
47
+ "tsup": "^8.0.0",
48
+ "typescript": "^5.6.0"
49
+ }
50
+ }