@canopypay/checkout-sdk 0.4.1 → 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 B="theme";var T=["accent","background","surface","text","muted","border","radius","font"],U=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})$/,Z=/^(rgb|rgba|hsl|hsla)\(([0-9a-z.,%/ +-]*)\)$/,J=/^[+-]?(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})$/,Q=/^[+-]?(?:[0-9]{1,3}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})%$/,ee=/^(?:0|(?:[0-9]{1,4}(?:\.[0-9]{1,4})?|\.[0-9]{1,4})(?:px|rem|em|%))$/,ne=/^[A-Za-z0-9 ,_-]+$/,te=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}]]),re=new Set(["transparent","currentcolor","inherit","initial","unset","revert","revert-layer"]),oe=new Set(["text","muted","accent"]);function y(t,n,o){return t<n?n:t>o?o:t}function x(t){if(!J.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}function v(t){if(!Q.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 ae(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 ie(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 le(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 se(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 ue(t){let n=Z.exec(t);if(n===null)return null;let o=n[1],r=se(n[2]);if(r===null)return null;let u=1;if(r.length===4){let c=ae(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=ie(r[0]),s=v(r[1]),l=v(r[2]);return d===null||s===null||l===null?null:le(d,y(s,0,1),y(l,0,1),u)}function ce(t){if(!q.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=ce(t);if(n!==null)return n;let o=ue(t);if(o!==null)return o;let r=te.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 N(t){return .2126*O(t.r)+.7152*O(t.g)+.0722*O(t.b)}function L(t,n){let o=N(t),r=N(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 H=3,de={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}]},S={r:255,g:255,b:255,a:1};function fe(t,n){let o=n===null?["light","dark"]:[n],r=[];for(let l=0;l<o.length;l+=1){let c=de[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 pe(t,n,o){let r=fe(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<H&&(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,S);else for(let c=0;c<r.length;c+=1){let f=L(w(s,r[c]),S);f<l&&(l=f)}l<H&&(delete t.accent,n.push({key:"accent",code:"variable_contrast_too_low"}))}}function ge(t,n){return t==="colour"?R(n)!==null:t==="length"?ee.test(n):ne.test(n)}function be(t,n){let o=U.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"&&oe.has(t)&&re.has(n.toLowerCase())?{code:"variable_value_erases_content",value:""}:ge(o.kind,n)?{code:null,value:n}:{code:"variable_value_malformed",value:""}}function j(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=be(l,t[l]);if(c.code!==null){r.push({key:l,code:c.code});continue}o[l]=c.value}pe(o,r,n);let d={};for(let s of T){let l=o[s];if(l===void 0)continue;let c=U.get(s).targets;for(let f=0;f<c.length;f+=1)d[c[f]]=l}return{accepted:o,declarations:d,rejections:r}}function z(t){return t==="light"||t==="dark"?t:null}var W="5";(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=46,s="canopy",l="cnpy_pk_live_";function c(){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 f(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 h(e){if(e!==void 0)return f(e);let a=c();return a?{ok:!0,origin:a}:{ok:!1,code:"canopy_origin_undiscoverable"}}function I(e){let a=new URL("/customer-pay",e.origin);a.searchParams.set("merchant",e.merchant),e.theme!==null&&a.searchParams.set(B,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 K(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 M(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 G(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 V(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=I(e)}catch(i){m(e,"error",{code:"popup_navigation_failed"});return}e.popupWin=a,G(e)}}function X(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);V(e,p)}),e.node.appendChild(a),e.fallbackButton=a,m(e,"fallback_offered",{surface:"popup",reason:"iframe_unavailable"})}function D(e){let a=document.createElement("iframe");a.src=I(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"}),M(e),e.surface==="auto"?X(e):m(e,"error",{code:"iframe_blocked"})},e.handshakeTimeoutMs)}function $(e,a){if(a.origin!==e.origin)return;let i=a.data;if(!(!i||i.source!==s)){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){if(!(i.height>=d))return;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 Y(e){if(typeof e.merchant!="string"||e.merchant.indexOf(l)!==0){try{(e.onEvent||function(){})({type:"error",code:"invalid_merchant_key"})}catch(_){}return{openNow:function(){},destroy:function(){}}}let a=h(e.canopyOrigin);if(!a.ok){try{(e.onEvent||function(){})({type:"error",code:a.code})}catch(_){}return{openNow:function(){},destroy:function(){}}}let i=z(e.theme),p=j(e.variables,i),b=typeof e.target=="string"?document.querySelector(e.target):e.target;if(!b)return{openNow:function(){},destroy:function(){}};let P=E.get(b);if(P)return P;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(_){$(g,_)},window.addEventListener("message",g.messageListener),K(g,p.rejections),(g.surface==="iframe"||g.surface==="auto")&&D(g);let F={openNow:function(_){V(g,_)},destroy:function(){g.destroyed||(g.destroyed=!0,window.removeEventListener("message",g.messageListener),M(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,F),F}let k=window;k.Canopy&&k.Canopy.__version===W||(k.Canopy={mount:Y,__version:W})})();})();
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 = "5";
470
+ var LOADER_VERSION = "6";
471
471
  (function() {
472
472
  "use strict";
473
473
  if (typeof window === "undefined") return;
@@ -479,6 +479,7 @@ var LOADER_VERSION = "5";
479
479
  const MIN_FRAME_HEIGHT_PX = 46;
480
480
  const MESSAGE_SOURCE = "canopy";
481
481
  const PUBLISHABLE_KEY_PREFIX = "cnpy_pk_live_";
482
+ const INTENT_ID_RE = /^[0-9a-f]{32}$/;
482
483
  function resolveOrigin() {
483
484
  const current = document.currentScript;
484
485
  if (current && current.src) {
@@ -538,7 +539,7 @@ var LOADER_VERSION = "5";
538
539
  if (value === void 0) continue;
539
540
  url.searchParams.set(THEME_VARIABLE_PARAM_PREFIX + name, value);
540
541
  }
541
- url.hash = "cap=" + encodeURIComponent(internal.capability || "");
542
+ url.searchParams.set("intent", internal.intentId);
542
543
  return url.toString();
543
544
  }
544
545
  function emit(internal, type, data) {
@@ -548,6 +549,27 @@ var LOADER_VERSION = "5";
548
549
  } catch {
549
550
  }
550
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
+ }
551
573
  function emitThemeRejections(internal, rejections) {
552
574
  for (let i = 0; i < rejections.length; i += 1) {
553
575
  const rejection = rejections[i];
@@ -595,14 +617,6 @@ var LOADER_VERSION = "5";
595
617
  emit(internal, "error", { code: "popup_blocked" });
596
618
  return;
597
619
  }
598
- if (!internal.capability) {
599
- try {
600
- win.close();
601
- } catch {
602
- }
603
- emit(internal, "error", { code: "capability_unavailable" });
604
- return;
605
- }
606
620
  try {
607
621
  win.location.href = buildCheckoutUrl(internal);
608
622
  } catch {
@@ -675,10 +689,17 @@ var LOADER_VERSION = "5";
675
689
  }
676
690
  }, internal.handshakeTimeoutMs);
677
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
+ }
678
699
  function handleMessage(internal, event) {
679
700
  if (event.origin !== internal.origin) return;
680
701
  const data = event.data;
681
- if (!data || data.source !== MESSAGE_SOURCE) return;
702
+ if (!isCheckoutMessage(internal, event, data)) return;
682
703
  if (data.type === "ready") {
683
704
  if (internal.handshakeTimer) {
684
705
  clearTimeout(internal.handshakeTimer);
@@ -696,6 +717,14 @@ var LOADER_VERSION = "5";
696
717
  emit(internal, "paid", data);
697
718
  return;
698
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
+ }
699
728
  if (data.type === "close") {
700
729
  emit(internal, "close");
701
730
  return;
@@ -704,45 +733,26 @@ var LOADER_VERSION = "5";
704
733
  const mounts = /* @__PURE__ */ new WeakMap();
705
734
  function mount2(opts) {
706
735
  if (typeof opts.merchant !== "string" || opts.merchant.indexOf(PUBLISHABLE_KEY_PREFIX) !== 0) {
707
- try {
708
- (opts.onEvent || function() {
709
- })({
710
- type: "error",
711
- code: "invalid_merchant_key"
712
- });
713
- } catch {
714
- }
715
- return { openNow: function() {
716
- }, destroy: function() {
717
- } };
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");
718
740
  }
719
741
  const originResolution = resolveMountOrigin(opts.canopyOrigin);
720
742
  if (!originResolution.ok) {
721
- try {
722
- (opts.onEvent || function() {
723
- })({
724
- type: "error",
725
- code: originResolution.code
726
- });
727
- } catch {
728
- }
729
- return { openNow: function() {
730
- }, destroy: function() {
731
- } };
743
+ return refusedHandle(opts, originResolution.code);
732
744
  }
733
745
  const forcedTheme = normalizeForcedTheme(opts.theme);
734
746
  const themeVariables = resolveThemeVariables(opts.variables, forcedTheme);
735
747
  const node = typeof opts.target === "string" ? document.querySelector(opts.target) : opts.target;
736
748
  if (!node) {
737
- return { openNow: function() {
738
- }, destroy: function() {
739
- } };
749
+ return refusedHandle(opts, "target_not_found");
740
750
  }
741
751
  const existing = mounts.get(node);
742
752
  if (existing) return existing;
743
753
  const internal = {
744
754
  node,
745
- capability: opts.capability,
755
+ intentId: opts.intentId,
746
756
  merchant: opts.merchant,
747
757
  origin: originResolution.origin,
748
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 = "5";
443
+ var LOADER_VERSION = "6";
444
444
  (function() {
445
445
  "use strict";
446
446
  if (typeof window === "undefined") return;
@@ -452,6 +452,7 @@ var LOADER_VERSION = "5";
452
452
  const MIN_FRAME_HEIGHT_PX = 46;
453
453
  const MESSAGE_SOURCE = "canopy";
454
454
  const PUBLISHABLE_KEY_PREFIX = "cnpy_pk_live_";
455
+ const INTENT_ID_RE = /^[0-9a-f]{32}$/;
455
456
  function resolveOrigin() {
456
457
  const current = document.currentScript;
457
458
  if (current && current.src) {
@@ -511,7 +512,7 @@ var LOADER_VERSION = "5";
511
512
  if (value === void 0) continue;
512
513
  url.searchParams.set(THEME_VARIABLE_PARAM_PREFIX + name, value);
513
514
  }
514
- url.hash = "cap=" + encodeURIComponent(internal.capability || "");
515
+ url.searchParams.set("intent", internal.intentId);
515
516
  return url.toString();
516
517
  }
517
518
  function emit(internal, type, data) {
@@ -521,6 +522,27 @@ var LOADER_VERSION = "5";
521
522
  } catch {
522
523
  }
523
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
+ }
524
546
  function emitThemeRejections(internal, rejections) {
525
547
  for (let i = 0; i < rejections.length; i += 1) {
526
548
  const rejection = rejections[i];
@@ -568,14 +590,6 @@ var LOADER_VERSION = "5";
568
590
  emit(internal, "error", { code: "popup_blocked" });
569
591
  return;
570
592
  }
571
- if (!internal.capability) {
572
- try {
573
- win.close();
574
- } catch {
575
- }
576
- emit(internal, "error", { code: "capability_unavailable" });
577
- return;
578
- }
579
593
  try {
580
594
  win.location.href = buildCheckoutUrl(internal);
581
595
  } catch {
@@ -648,10 +662,17 @@ var LOADER_VERSION = "5";
648
662
  }
649
663
  }, internal.handshakeTimeoutMs);
650
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
+ }
651
672
  function handleMessage(internal, event) {
652
673
  if (event.origin !== internal.origin) return;
653
674
  const data = event.data;
654
- if (!data || data.source !== MESSAGE_SOURCE) return;
675
+ if (!isCheckoutMessage(internal, event, data)) return;
655
676
  if (data.type === "ready") {
656
677
  if (internal.handshakeTimer) {
657
678
  clearTimeout(internal.handshakeTimer);
@@ -669,6 +690,14 @@ var LOADER_VERSION = "5";
669
690
  emit(internal, "paid", data);
670
691
  return;
671
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
+ }
672
701
  if (data.type === "close") {
673
702
  emit(internal, "close");
674
703
  return;
@@ -677,45 +706,26 @@ var LOADER_VERSION = "5";
677
706
  const mounts = /* @__PURE__ */ new WeakMap();
678
707
  function mount2(opts) {
679
708
  if (typeof opts.merchant !== "string" || opts.merchant.indexOf(PUBLISHABLE_KEY_PREFIX) !== 0) {
680
- try {
681
- (opts.onEvent || function() {
682
- })({
683
- type: "error",
684
- code: "invalid_merchant_key"
685
- });
686
- } catch {
687
- }
688
- return { openNow: function() {
689
- }, destroy: function() {
690
- } };
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");
691
713
  }
692
714
  const originResolution = resolveMountOrigin(opts.canopyOrigin);
693
715
  if (!originResolution.ok) {
694
- try {
695
- (opts.onEvent || function() {
696
- })({
697
- type: "error",
698
- code: originResolution.code
699
- });
700
- } catch {
701
- }
702
- return { openNow: function() {
703
- }, destroy: function() {
704
- } };
716
+ return refusedHandle(opts, originResolution.code);
705
717
  }
706
718
  const forcedTheme = normalizeForcedTheme(opts.theme);
707
719
  const themeVariables = resolveThemeVariables(opts.variables, forcedTheme);
708
720
  const node = typeof opts.target === "string" ? document.querySelector(opts.target) : opts.target;
709
721
  if (!node) {
710
- return { openNow: function() {
711
- }, destroy: function() {
712
- } };
722
+ return refusedHandle(opts, "target_not_found");
713
723
  }
714
724
  const existing = mounts.get(node);
715
725
  if (existing) return existing;
716
726
  const internal = {
717
727
  node,
718
- capability: opts.capability,
728
+ intentId: opts.intentId,
719
729
  merchant: opts.merchant,
720
730
  origin: originResolution.origin,
721
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.1",
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": "5",
33
+ "loaderVersion": "6",
34
34
  "apiVersion": "2026-09-01"
35
35
  },
36
36
  "publishConfig": {