@canopypay/checkout-sdk 0.4.0 → 0.5.0

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 S="theme";var T=["accent","background","surface","text","muted","border","radius","font"],B=new Map([["accent",{kind:"colour",targets:["--leaf","--primary","--accent","--ring"]}],["background",{kind:"colour",targets:["--paper","--background","background"]}],["surface",{kind:"colour",targets:["--surface","--card","--popover","--secondary"]}],["text",{kind:"colour",targets:["--ink","--foreground","--card-foreground","--popover-foreground","--secondary-foreground"]}],["muted",{kind:"colour",targets:["--ink-muted","--muted-foreground"]}],["border",{kind:"colour",targets:["--line","--border","--input"]}],["radius",{kind:"length",targets:["--radius"]}],["font",{kind:"font",targets:["--font-sans"]}]]),Y=/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,q=/^(rgb|rgba|hsl|hsla)\(([0-9a-z.,%/ +-]*)\)$/,Z=/^[+-]?(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})$/,J=/^[+-]?(?:[0-9]{1,3}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})%$/,Q=/^(?:0|(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})(?:px|rem|em|%))$/,ee=/^[A-Za-z0-9 ,_-]+$/,ne=new Map([["transparent",{r:0,g:0,b:0,a:0}],["black",{r:0,g:0,b:0,a:1}],["white",{r:255,g:255,b:255,a:1}],["silver",{r:192,g:192,b:192,a:1}],["gray",{r:128,g:128,b:128,a:1}],["grey",{r:128,g:128,b:128,a:1}],["maroon",{r:128,g:0,b:0,a:1}],["red",{r:255,g:0,b:0,a:1}],["purple",{r:128,g:0,b:128,a:1}],["fuchsia",{r:255,g:0,b:255,a:1}],["magenta",{r:255,g:0,b:255,a:1}],["green",{r:0,g:128,b:0,a:1}],["lime",{r:0,g:255,b:0,a:1}],["olive",{r:128,g:128,b:0,a:1}],["yellow",{r:255,g:255,b:0,a:1}],["navy",{r:0,g:0,b:128,a:1}],["blue",{r:0,g:0,b:255,a:1}],["teal",{r:0,g:128,b:128,a:1}],["aqua",{r:0,g:255,b:255,a:1}],["cyan",{r:0,g:255,b:255,a:1}],["orange",{r:255,g:165,b:0,a:1}],["pink",{r:255,g:192,b:203,a:1}],["brown",{r:165,g:42,b:42,a:1}],["beige",{r:245,g:245,b:220,a:1}],["ivory",{r:255,g:255,b:240,a:1}],["indigo",{r:75,g:0,b:130,a:1}],["violet",{r:238,g:130,b:238,a:1}],["gold",{r:255,g:215,b:0,a:1}],["crimson",{r:220,g:20,b:60,a:1}],["salmon",{r:250,g:128,b:114,a:1}],["khaki",{r:240,g:230,b:140,a:1}],["lavender",{r:230,g:230,b:250,a:1}],["turquoise",{r:64,g:224,b:208,a:1}],["tan",{r:210,g:180,b:140,a:1}],["plum",{r:221,g:160,b:221,a:1}],["orchid",{r:218,g:112,b:214,a:1}],["coral",{r:255,g:127,b:80,a:1}],["tomato",{r:255,g:99,b:71,a:1}],["chocolate",{r:210,g:105,b:30,a:1}],["snow",{r:255,g:250,b:250,a:1}],["linen",{r:250,g:240,b:230,a:1}],["azure",{r:240,g:255,b:255,a:1}],["wheat",{r:245,g:222,b:179,a:1}],["thistle",{r:216,g:191,b:216,a:1}]]),te=new Set(["transparent","currentcolor","inherit","initial","unset","revert","revert-layer"]),re=new Set(["text","muted","accent"]);function y(t,n,o){return t<n?n:t>o?o:t}function x(t){if(!Z.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function v(t){if(!J.test(t))return null;let n=Number(t.slice(0,t.length-1));return Number.isFinite(n)?n/100:null}function A(t){let n=v(t);if(n!==null)return y(n,0,1)*255;let o=x(t);return o===null?null:y(o,0,255)}function oe(t){let n=v(t);if(n!==null)return y(n,0,1);let o=x(t);return o===null?null:y(o,0,1)}function ae(t){let n=t,o=1;n.endsWith("deg")?n=n.slice(0,n.length-3):n.endsWith("grad")?(n=n.slice(0,n.length-4),o=360/400):n.endsWith("turn")?(n=n.slice(0,n.length-4),o=360):n.endsWith("rad")&&(n=n.slice(0,n.length-3),o=180/Math.PI);let r=x(n);return r===null?null:(r*o%360+360)%360}function C(t,n,o){let r=o;return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+(n-t)*6*r:r<1/2?n:r<2/3?t+(n-t)*(2/3-r)*6:t}function ie(t,n,o,r){if(n===0){let l=o*255;return{r:l,g:l,b:l,a:r}}let u=o<.5?o*(1+n):o+n-o*n,d=2*o-u,s=t/360;return{r:C(d,u,s+1/3)*255,g:C(d,u,s)*255,b:C(d,u,s-1/3)*255,a:r}}function le(t){let n=t.trim();if(n==="")return null;if(n.indexOf(",")>=0){if(n.indexOf("/")>=0)return null;let d=n.split(",").map(function(s){return s.trim()});return d.length!==3&&d.length!==4?null:d}let o=n.split("/");if(o.length>2)return null;let r=o[0].trim().split(/ +/);if(r.length!==3)return null;if(o.length===1)return r;let u=o[1].trim();return u===""||u.indexOf(" ")>=0?null:r.concat([u])}function se(t){let n=q.exec(t);if(n===null)return null;let o=n[1],r=le(n[2]);if(r===null)return null;let u=1;if(r.length===4){let c=oe(r[3]);if(c===null)return null;u=c}if(o==="rgb"||o==="rgba"){let c=A(r[0]),f=A(r[1]),h=A(r[2]);return c===null||f===null||h===null?null:{r:c,g:f,b:h,a:u}}let d=ae(r[0]),s=v(r[1]),l=v(r[2]);return d===null||s===null||l===null?null:ie(d,y(s,0,1),y(l,0,1),u)}function ue(t){if(!Y.test(t))return null;let n=t.slice(1),o=n.length===3||n.length===4,r=o?1:2,u=function(s){let l=n.slice(s*r,s*r+r);return parseInt(o?l+l:l,16)},d=n.length===4||n.length===8;return{r:u(0),g:u(1),b:u(2),a:d?u(3)/255:1}}function R(t){let n=ue(t);if(n!==null)return n;let o=se(t);if(o!==null)return o;let r=ne.get(t.toLowerCase());return r===void 0?null:r}function O(t){let n=t/255;return n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4)}function F(t){return .2126*O(t.r)+.7152*O(t.g)+.0722*O(t.b)}function L(t,n){let o=F(t),r=F(n),u=o>r?o:r,d=o>r?r:o;return(u+.05)/(d+.05)}function w(t,n){return t.a>=1?t:{r:t.r*t.a+n.r*(1-t.a),g:t.g*t.a+n.g*(1-t.a),b:t.b*t.a+n.b*(1-t.a),a:1}}var N=3,ce={light:[{r:243,g:250,b:246,a:1},{r:255,g:255,b:255,a:1}],dark:[{r:10,g:22,b:40,a:1},{r:26,g:40,b:60,a:1}]},H={r:255,g:255,b:255,a:1};function de(t,n){let o=n===null?["light","dark"]:[n],r=[];for(let l=0;l<o.length;l+=1){let c=ce[o[l]];for(let f=0;f<c.length;f+=1)r.push(c[f])}let u=[],d=["surface","background"];for(let l=0;l<d.length;l+=1){let c=t[d[l]];if(c===void 0)continue;let f=R(c);f!==null&&u.push(f)}if(u.length===0)return r;let s=[];for(let l=0;l<u.length;l+=1){let c=u[l];if(c.a>=1){s.push(c);continue}for(let f=0;f<r.length;f+=1)s.push(w(c,r[f]))}return s}function fe(t,n,o){let r=de(t,o),u=t.text;if(u!==void 0){let s=R(u),l=1/0;if(s===null)l=0;else for(let c=0;c<r.length;c+=1){let f=r[c],h=L(w(s,f),f);h<l&&(l=h)}l<N&&(delete t.text,n.push({key:"text",code:"variable_contrast_too_low"}))}let d=t.accent;if(d!==void 0){let s=R(d),l=1/0;if(s===null)l=0;else if(s.a>=1)l=L(s,H);else for(let c=0;c<r.length;c+=1){let f=L(w(s,r[c]),H);f<l&&(l=f)}l<N&&(delete t.accent,n.push({key:"accent",code:"variable_contrast_too_low"}))}}function pe(t,n){return t==="colour"?R(n)!==null:t==="length"?Q.test(n):ee.test(n)}function ge(t,n){let o=B.get(t);return o===void 0?{code:"unknown_variable",value:""}:typeof n!="string"?{code:"variable_not_a_string",value:""}:n.length>64?{code:"variable_value_too_long",value:""}:o.kind==="colour"&&re.has(t)&&te.has(n.toLowerCase())?{code:"variable_value_erases_content",value:""}:pe(o.kind,n)?{code:null,value:n}:{code:"variable_value_malformed",value:""}}function U(t,n=null){let o={},r=[];if(t===null||typeof t!="object"||Array.isArray(t))return{accepted:{},declarations:{},rejections:[]};let u=Object.keys(t);for(let s=0;s<u.length;s+=1){let l=u[s];if(s>=12){r.push({key:l,code:"too_many_variables"});break}let c=ge(l,t[l]);if(c.code!==null){r.push({key:l,code:c.code});continue}o[l]=c.value}fe(o,r,n);let d={};for(let s of T){let l=o[s];if(l===void 0)continue;let c=B.get(s).targets;for(let f=0;f<c.length;f+=1)d[c[f]]=l}return{accepted:o,declarations:d,rejections:r}}function j(t){return t==="light"||t==="dark"?t:null}var z="4";(function(){"use strict";if(typeof window=="undefined")return;let t="width=460,height=640",n=2500,o="Pay with Canopy",r=500,u=420,d="canopy",s="cnpy_pk_live_";function l(){let e=document.currentScript;if(e&&e.src)try{return new URL(e.src).origin}catch(i){}let a=document.getElementsByTagName("script");for(let i=0;i<a.length;i+=1){let p=a[i].src;if(p&&/\/v1\/(?:[^/]+\/)?canopy\.js(?:[?#].*)?$/.test(p))try{return new URL(p).origin}catch(b){}}return null}function c(e){let a;try{a=new URL(e)}catch(b){return{ok:!1,code:"canopy_origin_invalid"}}if(!((a.pathname===""||a.pathname==="/")&&a.search===""&&a.hash===""))return{ok:!1,code:"canopy_origin_not_bare"};let p=a.hostname==="localhost"||a.hostname==="127.0.0.1";return a.protocol!=="https:"&&!p?{ok:!1,code:"canopy_origin_insecure"}:{ok:!0,origin:a.origin}}function f(e){if(e!==void 0)return c(e);let a=l();return a?{ok:!0,origin:a}:{ok:!1,code:"canopy_origin_undiscoverable"}}function h(e){let a=new URL("/customer-pay",e.origin);a.searchParams.set("merchant",e.merchant),e.theme!==null&&a.searchParams.set(S,e.theme);for(let i=0;i<T.length;i+=1){let p=T[i],b=e.themeVariables[p];b!==void 0&&a.searchParams.set("v."+p,b)}return a.hash="cap="+encodeURIComponent(e.capability||""),a.toString()}function m(e,a,i){if(!e.destroyed)try{e.onEvent(Object.assign({type:a},i))}catch(p){}}function W(e,a){for(let i=0;i<a.length;i+=1){let p=a[i];m(e,"error",{code:p.code,variable:p.key})}}function I(e){e.handshakeTimer&&(clearTimeout(e.handshakeTimer),e.handshakeTimer=null),e.resizeObserver&&(e.resizeObserver.disconnect(),e.resizeObserver=null),e.frame&&(e.frame.parentNode&&e.frame.parentNode.removeChild(e.frame),e.frame=null),e.lastHeight=null}function K(e){e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=setInterval(function(){try{e.popupWin&&e.popupWin.closed&&(e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=null,e.popupWin=null,m(e,"close",{via:"popup"}))}catch(a){e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=null}},r)}function M(e,a){if(!e.destroyed){if(!a){m(e,"error",{code:"popup_blocked"});return}if(!e.capability){try{a.close()}catch(i){}m(e,"error",{code:"capability_unavailable"});return}try{a.location.href=h(e)}catch(i){m(e,"error",{code:"popup_navigation_failed"});return}e.popupWin=a,K(e)}}function G(e){let a=document.createElement("button");a.type="button",a.textContent=e.fallbackLabel;let i=a.style;i.background="#1A7A4C",i.color="#FFFFFF",i.border="none",i.borderRadius="8px",i.height="48px",i.padding="0 20px",i.fontSize="16px",i.fontFamily="inherit",i.cursor="pointer",i.maxWidth="100%",i.overflow="hidden",i.textOverflow="ellipsis",i.whiteSpace="nowrap",i.display="inline-block",a.addEventListener("click",function(){let p=window.open("","canopy_checkout",t);M(e,p)}),e.node.appendChild(a),e.fallbackButton=a,m(e,"fallback_offered",{surface:"popup",reason:"iframe_unavailable"})}function X(e){let a=document.createElement("iframe");a.src=h(e),a.style.width="100%",a.style.border="none",a.setAttribute("allow","clipboard-write"),a.setAttribute("title","Canopy checkout"),a.style.height=u+"px",e.node.appendChild(a),e.frame=a,typeof ResizeObserver!="undefined"&&(e.resizeObserver=new ResizeObserver(function(i){for(let p=0;p<i.length;p+=1){let b=Math.round(i[p].contentRect.height);b>0&&b!==e.lastHeight&&(e.lastHeight=b,m(e,"resize",{height:b}))}}),e.resizeObserver.observe(a)),e.handshakeTimer=setTimeout(function(){e.handshakeTimer=null,m(e,"surface_unavailable",{attempted:"iframe"}),I(e),e.surface==="auto"?G(e):m(e,"error",{code:"iframe_blocked"})},e.handshakeTimeoutMs)}function D(e,a){if(a.origin!==e.origin)return;let i=a.data;if(!(!i||i.source!==d)){if(i.type==="ready"){e.handshakeTimer&&(clearTimeout(e.handshakeTimer),e.handshakeTimer=null),m(e,"ready");return}if(i.type==="resize"&&typeof i.height=="number"&&e.frame){e.frame.style.height=i.height+"px";return}if(i.type==="paid"){m(e,"paid",i);return}if(i.type==="close"){m(e,"close");return}}}let E=new WeakMap;function $(e){if(typeof e.merchant!="string"||e.merchant.indexOf(s)!==0){try{(e.onEvent||function(){})({type:"error",code:"invalid_merchant_key"})}catch(_){}return{openNow:function(){},destroy:function(){}}}let a=f(e.canopyOrigin);if(!a.ok){try{(e.onEvent||function(){})({type:"error",code:a.code})}catch(_){}return{openNow:function(){},destroy:function(){}}}let i=j(e.theme),p=U(e.variables,i),b=typeof e.target=="string"?document.querySelector(e.target):e.target;if(!b)return{openNow:function(){},destroy:function(){}};let V=E.get(b);if(V)return V;let g={node:b,capability:e.capability,merchant:e.merchant,origin:a.origin,theme:i,themeVariables:p.accepted,surface:e.surface||"popup",handshakeTimeoutMs:e.handshakeTimeoutMs||n,fallbackLabel:e.fallbackLabel||o,onEvent:e.onEvent||function(){},destroyed:!1,messageListener:function(){},handshakeTimer:null,resizeObserver:null,frame:null,fallbackButton:null,lastHeight:null,popupWin:null,popupPollTimer:null};g.messageListener=function(_){D(g,_)},window.addEventListener("message",g.messageListener),W(g,p.rejections),(g.surface==="iframe"||g.surface==="auto")&&X(g);let P={openNow:function(_){M(g,_)},destroy:function(){g.destroyed||(g.destroyed=!0,window.removeEventListener("message",g.messageListener),I(g),g.popupPollTimer&&(clearInterval(g.popupPollTimer),g.popupPollTimer=null),g.fallbackButton&&(g.fallbackButton.parentNode&&g.fallbackButton.parentNode.removeChild(g.fallbackButton),g.fallbackButton=null),E.delete(b))}};return E.set(b,P),P}let k=window;k.Canopy&&k.Canopy.__version===z||(k.Canopy={mount:$,__version:z})})();})();
1
+ "use strict";(()=>{var U="theme";var v=["accent","background","surface","text","muted","border","radius","font"],j=new Map([["accent",{kind:"colour",targets:["--leaf","--primary","--accent","--ring"]}],["background",{kind:"colour",targets:["--paper","--background","background"]}],["surface",{kind:"colour",targets:["--surface","--card","--popover","--secondary"]}],["text",{kind:"colour",targets:["--ink","--foreground","--card-foreground","--popover-foreground","--secondary-foreground"]}],["muted",{kind:"colour",targets:["--ink-muted","--muted-foreground"]}],["border",{kind:"colour",targets:["--line","--border","--input"]}],["radius",{kind:"length",targets:["--radius"]}],["font",{kind:"font",targets:["--font-sans"]}]]),Q=/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,ee=/^(rgb|rgba|hsl|hsla)\(([0-9a-z.,%/ +-]*)\)$/,ne=/^[+-]?(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})$/,te=/^[+-]?(?:[0-9]{1,3}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})%$/,re=/^(?:0|(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})(?:px|rem|em|%))$/,oe=/^[A-Za-z0-9 ,_-]+$/,ae=new Map([["transparent",{r:0,g:0,b:0,a:0}],["black",{r:0,g:0,b:0,a:1}],["white",{r:255,g:255,b:255,a:1}],["silver",{r:192,g:192,b:192,a:1}],["gray",{r:128,g:128,b:128,a:1}],["grey",{r:128,g:128,b:128,a:1}],["maroon",{r:128,g:0,b:0,a:1}],["red",{r:255,g:0,b:0,a:1}],["purple",{r:128,g:0,b:128,a:1}],["fuchsia",{r:255,g:0,b:255,a:1}],["magenta",{r:255,g:0,b:255,a:1}],["green",{r:0,g:128,b:0,a:1}],["lime",{r:0,g:255,b:0,a:1}],["olive",{r:128,g:128,b:0,a:1}],["yellow",{r:255,g:255,b:0,a:1}],["navy",{r:0,g:0,b:128,a:1}],["blue",{r:0,g:0,b:255,a:1}],["teal",{r:0,g:128,b:128,a:1}],["aqua",{r:0,g:255,b:255,a:1}],["cyan",{r:0,g:255,b:255,a:1}],["orange",{r:255,g:165,b:0,a:1}],["pink",{r:255,g:192,b:203,a:1}],["brown",{r:165,g:42,b:42,a:1}],["beige",{r:245,g:245,b:220,a:1}],["ivory",{r:255,g:255,b:240,a:1}],["indigo",{r:75,g:0,b:130,a:1}],["violet",{r:238,g:130,b:238,a:1}],["gold",{r:255,g:215,b:0,a:1}],["crimson",{r:220,g:20,b:60,a:1}],["salmon",{r:250,g:128,b:114,a:1}],["khaki",{r:240,g:230,b:140,a:1}],["lavender",{r:230,g:230,b:250,a:1}],["turquoise",{r:64,g:224,b:208,a:1}],["tan",{r:210,g:180,b:140,a:1}],["plum",{r:221,g:160,b:221,a:1}],["orchid",{r:218,g:112,b:214,a:1}],["coral",{r:255,g:127,b:80,a:1}],["tomato",{r:255,g:99,b:71,a:1}],["chocolate",{r:210,g:105,b:30,a:1}],["snow",{r:255,g:250,b:250,a:1}],["linen",{r:250,g:240,b:230,a:1}],["azure",{r:240,g:255,b:255,a:1}],["wheat",{r:245,g:222,b:179,a:1}],["thistle",{r:216,g:191,b:216,a:1}]]),ie=new Set(["transparent","currentcolor","inherit","initial","unset","revert","revert-layer"]),se=new Set(["text","muted","accent"]);function y(t,n,a){return t<n?n:t>a?a:t}function L(t){if(!ne.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function T(t){if(!te.test(t))return null;let n=Number(t.slice(0,t.length-1));return Number.isFinite(n)?n/100:null}function C(t){let n=T(t);if(n!==null)return y(n,0,1)*255;let a=L(t);return a===null?null:y(a,0,255)}function le(t){let n=T(t);if(n!==null)return y(n,0,1);let a=L(t);return a===null?null:y(a,0,1)}function ue(t){let n=t,a=1;n.endsWith("deg")?n=n.slice(0,n.length-3):n.endsWith("grad")?(n=n.slice(0,n.length-4),a=360/400):n.endsWith("turn")?(n=n.slice(0,n.length-4),a=360):n.endsWith("rad")&&(n=n.slice(0,n.length-3),a=180/Math.PI);let o=L(n);return o===null?null:(o*a%360+360)%360}function I(t,n,a){let o=a;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?t+(n-t)*6*o:o<1/2?n:o<2/3?t+(n-t)*(2/3-o)*6:t}function ce(t,n,a,o){if(n===0){let s=a*255;return{r:s,g:s,b:s,a:o}}let u=a<.5?a*(1+n):a+n-a*n,f=2*a-u,l=t/360;return{r:I(f,u,l+1/3)*255,g:I(f,u,l)*255,b:I(f,u,l-1/3)*255,a:o}}function de(t){let n=t.trim();if(n==="")return null;if(n.indexOf(",")>=0){if(n.indexOf("/")>=0)return null;let f=n.split(",").map(function(l){return l.trim()});return f.length!==3&&f.length!==4?null:f}let a=n.split("/");if(a.length>2)return null;let o=a[0].trim().split(/ +/);if(o.length!==3)return null;if(a.length===1)return o;let u=a[1].trim();return u===""||u.indexOf(" ")>=0?null:o.concat([u])}function fe(t){let n=ee.exec(t);if(n===null)return null;let a=n[1],o=de(n[2]);if(o===null)return null;let u=1;if(o.length===4){let c=le(o[3]);if(c===null)return null;u=c}if(a==="rgb"||a==="rgba"){let c=C(o[0]),g=C(o[1]),h=C(o[2]);return c===null||g===null||h===null?null:{r:c,g,b:h,a:u}}let f=ue(o[0]),l=T(o[1]),s=T(o[2]);return f===null||l===null||s===null?null:ce(f,y(l,0,1),y(s,0,1),u)}function ge(t){if(!Q.test(t))return null;let n=t.slice(1),a=n.length===3||n.length===4,o=a?1:2,u=function(l){let s=n.slice(l*o,l*o+o);return parseInt(a?s+s:s,16)},f=n.length===4||n.length===8;return{r:u(0),g:u(1),b:u(2),a:f?u(3)/255:1}}function R(t){let n=ge(t);if(n!==null)return n;let a=fe(t);if(a!==null)return a;let o=ae.get(t.toLowerCase());return o===void 0?null:o}function O(t){let n=t/255;return n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4)}function H(t){return .2126*O(t.r)+.7152*O(t.g)+.0722*O(t.b)}function M(t,n){let a=H(t),o=H(n),u=a>o?a:o,f=a>o?o:a;return(u+.05)/(f+.05)}function w(t,n){return t.a>=1?t:{r:t.r*t.a+n.r*(1-t.a),g:t.g*t.a+n.g*(1-t.a),b:t.b*t.a+n.b*(1-t.a),a:1}}var S=3,pe={light:[{r:243,g:250,b:246,a:1},{r:255,g:255,b:255,a:1}],dark:[{r:10,g:22,b:40,a:1},{r:26,g:40,b:60,a:1}]},B={r:255,g:255,b:255,a:1};function me(t,n){let a=n===null?["light","dark"]:[n],o=[];for(let s=0;s<a.length;s+=1){let c=pe[a[s]];for(let g=0;g<c.length;g+=1)o.push(c[g])}let u=[],f=["surface","background"];for(let s=0;s<f.length;s+=1){let c=t[f[s]];if(c===void 0)continue;let g=R(c);g!==null&&u.push(g)}if(u.length===0)return o;let l=[];for(let s=0;s<u.length;s+=1){let c=u[s];if(c.a>=1){l.push(c);continue}for(let g=0;g<o.length;g+=1)l.push(w(c,o[g]))}return l}function be(t,n,a){let o=me(t,a),u=t.text;if(u!==void 0){let l=R(u),s=1/0;if(l===null)s=0;else for(let c=0;c<o.length;c+=1){let g=o[c],h=M(w(l,g),g);h<s&&(s=h)}s<S&&(delete t.text,n.push({key:"text",code:"variable_contrast_too_low"}))}let f=t.accent;if(f!==void 0){let l=R(f),s=1/0;if(l===null)s=0;else if(l.a>=1)s=M(l,B);else for(let c=0;c<o.length;c+=1){let g=M(w(l,o[c]),B);g<s&&(s=g)}s<S&&(delete t.accent,n.push({key:"accent",code:"variable_contrast_too_low"}))}}function he(t,n){return t==="colour"?R(n)!==null:t==="length"?re.test(n):oe.test(n)}function ye(t,n){let a=j.get(t);return a===void 0?{code:"unknown_variable",value:""}:typeof n!="string"?{code:"variable_not_a_string",value:""}:n.length>64?{code:"variable_value_too_long",value:""}:a.kind==="colour"&&se.has(t)&&ie.has(n.toLowerCase())?{code:"variable_value_erases_content",value:""}:he(a.kind,n)?{code:null,value:n}:{code:"variable_value_malformed",value:""}}function W(t,n=null){let a={},o=[];if(t===null||typeof t!="object"||Array.isArray(t))return{accepted:{},declarations:{},rejections:[]};let u=Object.keys(t);for(let l=0;l<u.length;l+=1){let s=u[l];if(l>=12){o.push({key:s,code:"too_many_variables"});break}let c=ye(s,t[s]);if(c.code!==null){o.push({key:s,code:c.code});continue}a[s]=c.value}be(a,o,n);let f={};for(let l of v){let s=a[l];if(s===void 0)continue;let c=j.get(l).targets;for(let g=0;g<c.length;g+=1)f[c[g]]=s}return{accepted:a,declarations:f,rejections:o}}function z(t){return t==="light"||t==="dark"?t:null}var K="6";(function(){"use strict";if(typeof window=="undefined")return;let t="width=460,height=640",n=2500,a="Pay with Canopy",o=500,u=420,f=46,l="canopy",s="cnpy_pk_live_",c=/^[0-9a-f]{32}$/;function g(){let e=document.currentScript;if(e&&e.src)try{return new URL(e.src).origin}catch(i){}let r=document.getElementsByTagName("script");for(let i=0;i<r.length;i+=1){let d=r[i].src;if(d&&/\/v1\/(?:[^/]+\/)?canopy\.js(?:[?#].*)?$/.test(d))try{return new URL(d).origin}catch(m){}}return null}function h(e){let r;try{r=new URL(e)}catch(m){return{ok:!1,code:"canopy_origin_invalid"}}if(!((r.pathname===""||r.pathname==="/")&&r.search===""&&r.hash===""))return{ok:!1,code:"canopy_origin_not_bare"};let d=r.hostname==="localhost"||r.hostname==="127.0.0.1";return r.protocol!=="https:"&&!d?{ok:!1,code:"canopy_origin_insecure"}:{ok:!0,origin:r.origin}}function G(e){if(e!==void 0)return h(e);let r=g();return r?{ok:!0,origin:r}:{ok:!1,code:"canopy_origin_undiscoverable"}}function x(e){let r=new URL("/customer-pay",e.origin);r.searchParams.set("merchant",e.merchant),e.theme!==null&&r.searchParams.set(U,e.theme);for(let i=0;i<v.length;i+=1){let d=v[i],m=e.themeVariables[d];m!==void 0&&r.searchParams.set("v."+d,m)}return r.searchParams.set("intent",e.intentId),r.toString()}function b(e,r,i){if(!e.destroyed)try{e.onEvent(Object.assign({type:r},i))}catch(d){}}function _(e,r){function i(){try{(e.onEvent||function(){})({type:"error",code:r})}catch(d){}}return i(),{openNow:function(d){try{d&&d.close()}catch(m){}i()},destroy:function(){}}}function X(e,r){for(let i=0;i<r.length;i+=1){let d=r[i];b(e,"error",{code:d.code,variable:d.key})}}function V(e){e.handshakeTimer&&(clearTimeout(e.handshakeTimer),e.handshakeTimer=null),e.resizeObserver&&(e.resizeObserver.disconnect(),e.resizeObserver=null),e.frame&&(e.frame.parentNode&&e.frame.parentNode.removeChild(e.frame),e.frame=null),e.lastHeight=null}function D(e){e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=setInterval(function(){try{e.popupWin&&e.popupWin.closed&&(e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=null,e.popupWin=null,b(e,"close",{via:"popup"}))}catch(r){e.popupPollTimer&&clearInterval(e.popupPollTimer),e.popupPollTimer=null}},o)}function P(e,r){if(!e.destroyed){if(!r){b(e,"error",{code:"popup_blocked"});return}try{r.location.href=x(e)}catch(i){b(e,"error",{code:"popup_navigation_failed"});return}e.popupWin=r,D(e)}}function $(e){let r=document.createElement("button");r.type="button",r.textContent=e.fallbackLabel;let i=r.style;i.background="#1A7A4C",i.color="#FFFFFF",i.border="none",i.borderRadius="8px",i.height="48px",i.padding="0 20px",i.fontSize="16px",i.fontFamily="inherit",i.cursor="pointer",i.maxWidth="100%",i.overflow="hidden",i.textOverflow="ellipsis",i.whiteSpace="nowrap",i.display="inline-block",r.addEventListener("click",function(){let d=window.open("","canopy_checkout",t);P(e,d)}),e.node.appendChild(r),e.fallbackButton=r,b(e,"fallback_offered",{surface:"popup",reason:"iframe_unavailable"})}function Y(e){let r=document.createElement("iframe");r.src=x(e),r.style.width="100%",r.style.border="none",r.setAttribute("allow","clipboard-write"),r.setAttribute("title","Canopy checkout"),r.style.height=u+"px",e.node.appendChild(r),e.frame=r,typeof ResizeObserver!="undefined"&&(e.resizeObserver=new ResizeObserver(function(i){for(let d=0;d<i.length;d+=1){let m=Math.round(i[d].contentRect.height);m>0&&m!==e.lastHeight&&(e.lastHeight=m,b(e,"resize",{height:m}))}}),e.resizeObserver.observe(r)),e.handshakeTimer=setTimeout(function(){e.handshakeTimer=null,b(e,"surface_unavailable",{attempted:"iframe"}),V(e),e.surface==="auto"?$(e):b(e,"error",{code:"iframe_blocked"})},e.handshakeTimeoutMs)}function q(e,r,i){if(!i||i.source!==l)return!1;let d=e.frame?e.frame.contentWindow:null;return!(e.popupWin||d)||!r.source?!0:r.source===e.popupWin||r.source===d}function Z(e,r){if(r.origin!==e.origin)return;let i=r.data;if(q(e,r,i)){if(i.type==="ready"){e.handshakeTimer&&(clearTimeout(e.handshakeTimer),e.handshakeTimer=null),b(e,"ready");return}if(i.type==="resize"&&typeof i.height=="number"&&e.frame){if(!(i.height>=f))return;e.frame.style.height=i.height+"px";return}if(i.type==="paid"){b(e,"paid",i);return}if(i.type==="error"&&typeof i.code=="string"){e.handshakeTimer&&(clearTimeout(e.handshakeTimer),e.handshakeTimer=null),b(e,"error",{code:i.code});return}if(i.type==="close"){b(e,"close");return}}}let E=new WeakMap;function J(e){if(typeof e.merchant!="string"||e.merchant.indexOf(s)!==0)return _(e,"invalid_merchant_key");if(typeof e.intentId!="string"||!c.test(e.intentId))return _(e,"invalid_intent_id");let r=G(e.canopyOrigin);if(!r.ok)return _(e,r.code);let i=z(e.theme),d=W(e.variables,i),m=typeof e.target=="string"?document.querySelector(e.target):e.target;if(!m)return _(e,"target_not_found");let F=E.get(m);if(F)return F;let p={node:m,intentId:e.intentId,merchant:e.merchant,origin:r.origin,theme:i,themeVariables:d.accepted,surface:e.surface||"popup",handshakeTimeoutMs:e.handshakeTimeoutMs||n,fallbackLabel:e.fallbackLabel||a,onEvent:e.onEvent||function(){},destroyed:!1,messageListener:function(){},handshakeTimer:null,resizeObserver:null,frame:null,fallbackButton:null,lastHeight:null,popupWin:null,popupPollTimer:null};p.messageListener=function(A){Z(p,A)},window.addEventListener("message",p.messageListener),X(p,d.rejections),(p.surface==="iframe"||p.surface==="auto")&&Y(p);let N={openNow:function(A){P(p,A)},destroy:function(){p.destroyed||(p.destroyed=!0,window.removeEventListener("message",p.messageListener),V(p),p.popupPollTimer&&(clearInterval(p.popupPollTimer),p.popupPollTimer=null),p.fallbackButton&&(p.fallbackButton.parentNode&&p.fallbackButton.parentNode.removeChild(p.fallbackButton),p.fallbackButton=null),E.delete(m))}};return E.set(m,N),N}let k=window;k.Canopy&&k.Canopy.__version===K||(k.Canopy={mount:J,__version:K})})();})();
package/dist/index.cjs CHANGED
@@ -467,7 +467,7 @@ function normalizeForcedTheme(raw) {
467
467
  }
468
468
 
469
469
  // src/loader.ts
470
- var LOADER_VERSION = "4";
470
+ var LOADER_VERSION = "6";
471
471
  (function() {
472
472
  "use strict";
473
473
  if (typeof window === "undefined") return;
@@ -476,8 +476,10 @@ var LOADER_VERSION = "4";
476
476
  const DEFAULT_FALLBACK_LABEL = "Pay with Canopy";
477
477
  const POPUP_POLL_INTERVAL_MS = 500;
478
478
  const INITIAL_FRAME_HEIGHT_PX = 420;
479
+ const MIN_FRAME_HEIGHT_PX = 46;
479
480
  const MESSAGE_SOURCE = "canopy";
480
481
  const PUBLISHABLE_KEY_PREFIX = "cnpy_pk_live_";
482
+ const INTENT_ID_RE = /^[0-9a-f]{32}$/;
481
483
  function resolveOrigin() {
482
484
  const current = document.currentScript;
483
485
  if (current && current.src) {
@@ -537,7 +539,7 @@ var LOADER_VERSION = "4";
537
539
  if (value === void 0) continue;
538
540
  url.searchParams.set(THEME_VARIABLE_PARAM_PREFIX + name, value);
539
541
  }
540
- url.hash = "cap=" + encodeURIComponent(internal.capability || "");
542
+ url.searchParams.set("intent", internal.intentId);
541
543
  return url.toString();
542
544
  }
543
545
  function emit(internal, type, data) {
@@ -547,6 +549,27 @@ var LOADER_VERSION = "4";
547
549
  } catch {
548
550
  }
549
551
  }
552
+ function refusedHandle(opts, code) {
553
+ function report() {
554
+ try {
555
+ (opts.onEvent || function() {
556
+ })({ type: "error", code });
557
+ } catch {
558
+ }
559
+ }
560
+ report();
561
+ return {
562
+ openNow: function(win) {
563
+ try {
564
+ if (win) win.close();
565
+ } catch {
566
+ }
567
+ report();
568
+ },
569
+ destroy: function() {
570
+ }
571
+ };
572
+ }
550
573
  function emitThemeRejections(internal, rejections) {
551
574
  for (let i = 0; i < rejections.length; i += 1) {
552
575
  const rejection = rejections[i];
@@ -594,14 +617,6 @@ var LOADER_VERSION = "4";
594
617
  emit(internal, "error", { code: "popup_blocked" });
595
618
  return;
596
619
  }
597
- if (!internal.capability) {
598
- try {
599
- win.close();
600
- } catch {
601
- }
602
- emit(internal, "error", { code: "capability_unavailable" });
603
- return;
604
- }
605
620
  try {
606
621
  win.location.href = buildCheckoutUrl(internal);
607
622
  } catch {
@@ -674,10 +689,17 @@ var LOADER_VERSION = "4";
674
689
  }
675
690
  }, internal.handshakeTimeoutMs);
676
691
  }
692
+ function isCheckoutMessage(internal, event, data) {
693
+ if (!data || data.source !== MESSAGE_SOURCE) return false;
694
+ const frameWin = internal.frame ? internal.frame.contentWindow : null;
695
+ const known = internal.popupWin || frameWin;
696
+ if (!known || !event.source) return true;
697
+ return event.source === internal.popupWin || event.source === frameWin;
698
+ }
677
699
  function handleMessage(internal, event) {
678
700
  if (event.origin !== internal.origin) return;
679
701
  const data = event.data;
680
- if (!data || data.source !== MESSAGE_SOURCE) return;
702
+ if (!isCheckoutMessage(internal, event, data)) return;
681
703
  if (data.type === "ready") {
682
704
  if (internal.handshakeTimer) {
683
705
  clearTimeout(internal.handshakeTimer);
@@ -687,6 +709,7 @@ var LOADER_VERSION = "4";
687
709
  return;
688
710
  }
689
711
  if (data.type === "resize" && typeof data.height === "number" && internal.frame) {
712
+ if (!(data.height >= MIN_FRAME_HEIGHT_PX)) return;
690
713
  internal.frame.style.height = data.height + "px";
691
714
  return;
692
715
  }
@@ -694,6 +717,14 @@ var LOADER_VERSION = "4";
694
717
  emit(internal, "paid", data);
695
718
  return;
696
719
  }
720
+ if (data.type === "error" && typeof data.code === "string") {
721
+ if (internal.handshakeTimer) {
722
+ clearTimeout(internal.handshakeTimer);
723
+ internal.handshakeTimer = null;
724
+ }
725
+ emit(internal, "error", { code: data.code });
726
+ return;
727
+ }
697
728
  if (data.type === "close") {
698
729
  emit(internal, "close");
699
730
  return;
@@ -702,45 +733,26 @@ var LOADER_VERSION = "4";
702
733
  const mounts = /* @__PURE__ */ new WeakMap();
703
734
  function mount2(opts) {
704
735
  if (typeof opts.merchant !== "string" || opts.merchant.indexOf(PUBLISHABLE_KEY_PREFIX) !== 0) {
705
- try {
706
- (opts.onEvent || function() {
707
- })({
708
- type: "error",
709
- code: "invalid_merchant_key"
710
- });
711
- } catch {
712
- }
713
- return { openNow: function() {
714
- }, destroy: function() {
715
- } };
736
+ return refusedHandle(opts, "invalid_merchant_key");
737
+ }
738
+ if (typeof opts.intentId !== "string" || !INTENT_ID_RE.test(opts.intentId)) {
739
+ return refusedHandle(opts, "invalid_intent_id");
716
740
  }
717
741
  const originResolution = resolveMountOrigin(opts.canopyOrigin);
718
742
  if (!originResolution.ok) {
719
- try {
720
- (opts.onEvent || function() {
721
- })({
722
- type: "error",
723
- code: originResolution.code
724
- });
725
- } catch {
726
- }
727
- return { openNow: function() {
728
- }, destroy: function() {
729
- } };
743
+ return refusedHandle(opts, originResolution.code);
730
744
  }
731
745
  const forcedTheme = normalizeForcedTheme(opts.theme);
732
746
  const themeVariables = resolveThemeVariables(opts.variables, forcedTheme);
733
747
  const node = typeof opts.target === "string" ? document.querySelector(opts.target) : opts.target;
734
748
  if (!node) {
735
- return { openNow: function() {
736
- }, destroy: function() {
737
- } };
749
+ return refusedHandle(opts, "target_not_found");
738
750
  }
739
751
  const existing = mounts.get(node);
740
752
  if (existing) return existing;
741
753
  const internal = {
742
754
  node,
743
- capability: opts.capability,
755
+ intentId: opts.intentId,
744
756
  merchant: opts.merchant,
745
757
  origin: originResolution.origin,
746
758
  theme: forcedTheme,
package/dist/index.d.cts CHANGED
@@ -36,16 +36,23 @@ type CanopyThemeVariables = Partial<Record<CanopyThemeVariable, string>>;
36
36
  /**
37
37
  * Canopy checkout SDK loader.
38
38
  *
39
- * The whole merchant integration:
39
+ * The whole merchant integration. Their server already created the payment
40
+ * intent with `POST /api/v1/intents`; its `intentId` is the only thing that
41
+ * crosses into the browser. There is no second server call, and no short-lived
42
+ * secret for the merchant to hold or forward -- price, destination, fee and
43
+ * supported chains all resolve server-side from the id.
44
+ *
45
+ * This sample is transcribed verbatim into `components/docs/examples.ts`'s
46
+ * `SDK_LOADER_HTML`, which the docs pages render. Keep the two in sync.
40
47
  *
41
48
  * ```html
42
49
  * <script src="https://canopy.example/v1/canopy.js"></script>
43
50
  * <script type="module">
44
- * const { capability } = await (await fetch("/my-server/create-canopy-intent")).json();
51
+ * const { intentId } = await (await fetch("/my-server/create-canopy-intent")).json();
45
52
  *
46
53
  * const handle = Canopy.mount({
47
54
  * target: "#checkout",
48
- * capability,
55
+ * intentId,
49
56
  * merchant: "cnpy_pk_live_abc123",
50
57
  * onEvent: (e) => {
51
58
  * // `paid` is advisory only -- it drives UI, never fulfilment.
@@ -84,7 +91,15 @@ type CanopyEvent = {
84
91
  type Surface = "popup" | "iframe" | "auto";
85
92
  type MountOptions = {
86
93
  target: string | Element;
87
- capability?: string;
94
+ /**
95
+ * The id of a payment intent the merchant's own server already created with
96
+ * `POST /api/v1/intents`. 32 lowercase hex characters. REQUIRED -- it is the
97
+ * whole integration: everything else about the checkout (price, destination,
98
+ * platform fee, supported chains) resolves server-side from this id, so
99
+ * there is nothing else for the merchant to fetch, hold or forward. The
100
+ * server validates the same shape independently.
101
+ */
102
+ intentId: string;
88
103
  merchant: string;
89
104
  surface?: Surface;
90
105
  onEvent?: (event: CanopyEvent) => void;
package/dist/index.d.ts CHANGED
@@ -36,16 +36,23 @@ type CanopyThemeVariables = Partial<Record<CanopyThemeVariable, string>>;
36
36
  /**
37
37
  * Canopy checkout SDK loader.
38
38
  *
39
- * The whole merchant integration:
39
+ * The whole merchant integration. Their server already created the payment
40
+ * intent with `POST /api/v1/intents`; its `intentId` is the only thing that
41
+ * crosses into the browser. There is no second server call, and no short-lived
42
+ * secret for the merchant to hold or forward -- price, destination, fee and
43
+ * supported chains all resolve server-side from the id.
44
+ *
45
+ * This sample is transcribed verbatim into `components/docs/examples.ts`'s
46
+ * `SDK_LOADER_HTML`, which the docs pages render. Keep the two in sync.
40
47
  *
41
48
  * ```html
42
49
  * <script src="https://canopy.example/v1/canopy.js"></script>
43
50
  * <script type="module">
44
- * const { capability } = await (await fetch("/my-server/create-canopy-intent")).json();
51
+ * const { intentId } = await (await fetch("/my-server/create-canopy-intent")).json();
45
52
  *
46
53
  * const handle = Canopy.mount({
47
54
  * target: "#checkout",
48
- * capability,
55
+ * intentId,
49
56
  * merchant: "cnpy_pk_live_abc123",
50
57
  * onEvent: (e) => {
51
58
  * // `paid` is advisory only -- it drives UI, never fulfilment.
@@ -84,7 +91,15 @@ type CanopyEvent = {
84
91
  type Surface = "popup" | "iframe" | "auto";
85
92
  type MountOptions = {
86
93
  target: string | Element;
87
- capability?: string;
94
+ /**
95
+ * The id of a payment intent the merchant's own server already created with
96
+ * `POST /api/v1/intents`. 32 lowercase hex characters. REQUIRED -- it is the
97
+ * whole integration: everything else about the checkout (price, destination,
98
+ * platform fee, supported chains) resolves server-side from this id, so
99
+ * there is nothing else for the merchant to fetch, hold or forward. The
100
+ * server validates the same shape independently.
101
+ */
102
+ intentId: string;
88
103
  merchant: string;
89
104
  surface?: Surface;
90
105
  onEvent?: (event: CanopyEvent) => void;
package/dist/index.js CHANGED
@@ -440,7 +440,7 @@ function normalizeForcedTheme(raw) {
440
440
  }
441
441
 
442
442
  // src/loader.ts
443
- var LOADER_VERSION = "4";
443
+ var LOADER_VERSION = "6";
444
444
  (function() {
445
445
  "use strict";
446
446
  if (typeof window === "undefined") return;
@@ -449,8 +449,10 @@ var LOADER_VERSION = "4";
449
449
  const DEFAULT_FALLBACK_LABEL = "Pay with Canopy";
450
450
  const POPUP_POLL_INTERVAL_MS = 500;
451
451
  const INITIAL_FRAME_HEIGHT_PX = 420;
452
+ const MIN_FRAME_HEIGHT_PX = 46;
452
453
  const MESSAGE_SOURCE = "canopy";
453
454
  const PUBLISHABLE_KEY_PREFIX = "cnpy_pk_live_";
455
+ const INTENT_ID_RE = /^[0-9a-f]{32}$/;
454
456
  function resolveOrigin() {
455
457
  const current = document.currentScript;
456
458
  if (current && current.src) {
@@ -510,7 +512,7 @@ var LOADER_VERSION = "4";
510
512
  if (value === void 0) continue;
511
513
  url.searchParams.set(THEME_VARIABLE_PARAM_PREFIX + name, value);
512
514
  }
513
- url.hash = "cap=" + encodeURIComponent(internal.capability || "");
515
+ url.searchParams.set("intent", internal.intentId);
514
516
  return url.toString();
515
517
  }
516
518
  function emit(internal, type, data) {
@@ -520,6 +522,27 @@ var LOADER_VERSION = "4";
520
522
  } catch {
521
523
  }
522
524
  }
525
+ function refusedHandle(opts, code) {
526
+ function report() {
527
+ try {
528
+ (opts.onEvent || function() {
529
+ })({ type: "error", code });
530
+ } catch {
531
+ }
532
+ }
533
+ report();
534
+ return {
535
+ openNow: function(win) {
536
+ try {
537
+ if (win) win.close();
538
+ } catch {
539
+ }
540
+ report();
541
+ },
542
+ destroy: function() {
543
+ }
544
+ };
545
+ }
523
546
  function emitThemeRejections(internal, rejections) {
524
547
  for (let i = 0; i < rejections.length; i += 1) {
525
548
  const rejection = rejections[i];
@@ -567,14 +590,6 @@ var LOADER_VERSION = "4";
567
590
  emit(internal, "error", { code: "popup_blocked" });
568
591
  return;
569
592
  }
570
- if (!internal.capability) {
571
- try {
572
- win.close();
573
- } catch {
574
- }
575
- emit(internal, "error", { code: "capability_unavailable" });
576
- return;
577
- }
578
593
  try {
579
594
  win.location.href = buildCheckoutUrl(internal);
580
595
  } catch {
@@ -647,10 +662,17 @@ var LOADER_VERSION = "4";
647
662
  }
648
663
  }, internal.handshakeTimeoutMs);
649
664
  }
665
+ function isCheckoutMessage(internal, event, data) {
666
+ if (!data || data.source !== MESSAGE_SOURCE) return false;
667
+ const frameWin = internal.frame ? internal.frame.contentWindow : null;
668
+ const known = internal.popupWin || frameWin;
669
+ if (!known || !event.source) return true;
670
+ return event.source === internal.popupWin || event.source === frameWin;
671
+ }
650
672
  function handleMessage(internal, event) {
651
673
  if (event.origin !== internal.origin) return;
652
674
  const data = event.data;
653
- if (!data || data.source !== MESSAGE_SOURCE) return;
675
+ if (!isCheckoutMessage(internal, event, data)) return;
654
676
  if (data.type === "ready") {
655
677
  if (internal.handshakeTimer) {
656
678
  clearTimeout(internal.handshakeTimer);
@@ -660,6 +682,7 @@ var LOADER_VERSION = "4";
660
682
  return;
661
683
  }
662
684
  if (data.type === "resize" && typeof data.height === "number" && internal.frame) {
685
+ if (!(data.height >= MIN_FRAME_HEIGHT_PX)) return;
663
686
  internal.frame.style.height = data.height + "px";
664
687
  return;
665
688
  }
@@ -667,6 +690,14 @@ var LOADER_VERSION = "4";
667
690
  emit(internal, "paid", data);
668
691
  return;
669
692
  }
693
+ if (data.type === "error" && typeof data.code === "string") {
694
+ if (internal.handshakeTimer) {
695
+ clearTimeout(internal.handshakeTimer);
696
+ internal.handshakeTimer = null;
697
+ }
698
+ emit(internal, "error", { code: data.code });
699
+ return;
700
+ }
670
701
  if (data.type === "close") {
671
702
  emit(internal, "close");
672
703
  return;
@@ -675,45 +706,26 @@ var LOADER_VERSION = "4";
675
706
  const mounts = /* @__PURE__ */ new WeakMap();
676
707
  function mount2(opts) {
677
708
  if (typeof opts.merchant !== "string" || opts.merchant.indexOf(PUBLISHABLE_KEY_PREFIX) !== 0) {
678
- try {
679
- (opts.onEvent || function() {
680
- })({
681
- type: "error",
682
- code: "invalid_merchant_key"
683
- });
684
- } catch {
685
- }
686
- return { openNow: function() {
687
- }, destroy: function() {
688
- } };
709
+ return refusedHandle(opts, "invalid_merchant_key");
710
+ }
711
+ if (typeof opts.intentId !== "string" || !INTENT_ID_RE.test(opts.intentId)) {
712
+ return refusedHandle(opts, "invalid_intent_id");
689
713
  }
690
714
  const originResolution = resolveMountOrigin(opts.canopyOrigin);
691
715
  if (!originResolution.ok) {
692
- try {
693
- (opts.onEvent || function() {
694
- })({
695
- type: "error",
696
- code: originResolution.code
697
- });
698
- } catch {
699
- }
700
- return { openNow: function() {
701
- }, destroy: function() {
702
- } };
716
+ return refusedHandle(opts, originResolution.code);
703
717
  }
704
718
  const forcedTheme = normalizeForcedTheme(opts.theme);
705
719
  const themeVariables = resolveThemeVariables(opts.variables, forcedTheme);
706
720
  const node = typeof opts.target === "string" ? document.querySelector(opts.target) : opts.target;
707
721
  if (!node) {
708
- return { openNow: function() {
709
- }, destroy: function() {
710
- } };
722
+ return refusedHandle(opts, "target_not_found");
711
723
  }
712
724
  const existing = mounts.get(node);
713
725
  if (existing) return existing;
714
726
  const internal = {
715
727
  node,
716
- capability: opts.capability,
728
+ intentId: opts.intentId,
717
729
  merchant: opts.merchant,
718
730
  origin: originResolution.origin,
719
731
  theme: forcedTheme,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canopypay/checkout-sdk",
3
3
  "private": false,
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "prepublishOnly": "npm --prefix ../.. run sdk:build && npm run build:npm"
31
31
  },
32
32
  "canopy": {
33
- "loaderVersion": "4",
33
+ "loaderVersion": "6",
34
34
  "apiVersion": "2026-09-01"
35
35
  },
36
36
  "publishConfig": {