@thavguard/arc-pay 0.1.25 → 0.1.26
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 +6 -3
- package/dist/cdn/arcpay.global.js +1 -1
- package/dist/cdn/arcpay.global.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.cjs +23 -5
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.mjs +23 -5
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,9 +116,10 @@ and checkout sessions.
|
|
|
116
116
|
|
|
117
117
|
Mutating server-client methods require an explicit `{ idempotencyKey }`:
|
|
118
118
|
`createPayment`, `createCardSetup`, `executePayment`, `capturePayment`, `voidPayment`,
|
|
119
|
-
`createRefund`, `chargeSavedCard`, `createLink`,
|
|
120
|
-
`createCheckoutSession`. Missing idempotency raises
|
|
121
|
-
`code="missing_idempotency_key"` before any HTTP request is
|
|
119
|
+
`createRefund`, `chargeSavedCard`, `completeThreeDSMethod`, `createLink`,
|
|
120
|
+
`cancelLink`, and `createCheckoutSession`. Missing idempotency raises
|
|
121
|
+
`ArcPayError` with `code="missing_idempotency_key"` before any HTTP request is
|
|
122
|
+
sent.
|
|
122
123
|
|
|
123
124
|
H2H card payments require HTTPS `success_url` and `fail_url` on
|
|
124
125
|
`createPayment`. Arc Pay stores those URLs on the payment and redirects the
|
|
@@ -146,10 +147,12 @@ const result = await fetch(`/api/payments/${paymentId}/execute`, {
|
|
|
146
147
|
|
|
147
148
|
await runThreeDSBrowserFlow(result.next_action, {
|
|
148
149
|
async completeThreeDSMethod(completion) {
|
|
150
|
+
const idempotencyKey = crypto.randomUUID();
|
|
149
151
|
const response = await fetch(`/api/payments/${paymentId}/complete-3ds-method`, {
|
|
150
152
|
method: "POST",
|
|
151
153
|
headers: {
|
|
152
154
|
"Content-Type": "application/json",
|
|
155
|
+
"Idempotency-Key": idempotencyKey,
|
|
153
156
|
},
|
|
154
157
|
body: JSON.stringify(completion),
|
|
155
158
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var ArcPay=(function(exports){'use strict';var i=class extends Error{constructor(t){super(t.message),this.name="ArcPayError",this.type=t.type,this.code=t.code,this.param=t.param,this.paymentId=t.paymentId,this.declineCode=t.declineCode,this.retryable=t.retryable,this.requestId=t.requestId;}},O=e=>e instanceof i&&e.type==="validation_error";var N=e=>e instanceof i&&e.type==="authentication_error",U=e=>e instanceof i&&e.type==="authorization_error",W=e=>e instanceof i&&e.type==="state_error",$=e=>e instanceof i&&e.type==="rate_limit_error",K=e=>e instanceof i&&e.type==="api_error",q=e=>e instanceof i&&e.type==="network_error",V=e=>e instanceof i&&e.type==="challenge_aborted";var S=e=>e.startsWith("pk_test_")?"sandbox":"live",D=e=>{if(typeof e!="string"||e.length===0)throw new i({type:"validation_error",code:"invalid_publishable_key",message:"Publishable key must be a non-empty string",retryable:false});if(!e.startsWith("pk_test_")&&!e.startsWith("pk_live_"))throw new i({type:"validation_error",code:"invalid_publishable_key",message:"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.",retryable:false})};var k="data-arcpay-sandbox-banner",B=()=>{if(typeof document=="undefined"||document.querySelector(`[${k}]`))return;let e=document.createElement("div");e.setAttribute(k,""),e.style.cssText="position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);";let t=document.createElement("span");t.textContent="ARC PAY TEST MODE \u2014 payments are simulated",e.appendChild(t);let r=document.createElement("button");r.type="button",r.setAttribute("data-arcpay-banner-dismiss",""),r.textContent="\xD7",r.setAttribute("aria-label","Dismiss test mode banner"),r.style.cssText="margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;",r.addEventListener("click",()=>e.remove()),e.appendChild(r),document.body.appendChild(e);};var Y="arcpay:",j=e=>typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string"&&e.type.startsWith(Y),x=(e,t,r)=>{if(r==="*")throw new i({type:"validation_error",code:"wildcard_origin_forbidden",message:"postToIframe: targetOrigin cannot be '*'",retryable:false});if(!e.contentWindow)throw new i({type:"validation_error",code:"iframe_not_loaded",message:"postToIframe: iframe.contentWindow is null (iframe not mounted)",retryable:false});e.contentWindow.postMessage(t,r);};var w=(e,t)=>e.origin!==t||!j(e.data)?null:e.data;var X=new Set(["--arcpay-placeholder-color","background-color","caret-color","color","font-family","font-size","font-style","font-weight","letter-spacing","line-height","opacity","text-align","text-decoration","text-transform"]),G={base:{"font-family":'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',"font-size":"16px","line-height":"24px",color:"#111827","--arcpay-placeholder-color":"#9ca3af","caret-color":"#111827"},focus:{color:"#111827"},invalid:{color:"#dc2626"},complete:{color:"#111827"},empty:{color:"#111827"}},u=(e,t)=>{if(!(!e&&!t))return {...e!=null?e:{},...t!=null?t:{}}},y=(e,t,r)=>{r!==void 0&&(e[t]=r);},J=e=>{if(!(e===void 0||e==="none"||e==="arcpay"))throw new i({type:"validation_error",code:"invalid_hosted_fields_theme",message:`Unsupported Hosted Fields appearance theme: ${String(e)}`,retryable:false})},h=e=>{let t={};for(let[r,o]of Object.entries(e)){let n=r.toLowerCase();X.has(n)&&(t[n]=o);}return t},Q=e=>{let t={base:h(e.base)};return e.invalid!==void 0&&(t.invalid=h(e.invalid)),e.focus!==void 0&&(t.focus=h(e.focus)),e.complete!==void 0&&(t.complete=h(e.complete)),e.empty!==void 0&&(t.empty=h(e.empty)),t},P=e=>{var p;J(e==null?void 0:e.theme);let t=(e==null?void 0:e.theme)==="arcpay"?G:{base:{}},r={base:{}},o=e==null?void 0:e.variables;o&&(y(r.base,"font-family",o.fontFamily),y(r.base,"font-size",o.fontSize),y(r.base,"font-weight",o.fontWeight),y(r.base,"font-style",o.fontStyle),y(r.base,"line-height",o.lineHeight),y(r.base,"letter-spacing",o.letterSpacing),y(r.base,"text-align",o.textAlign),y(r.base,"color",o.colorText),y(r.base,"--arcpay-placeholder-color",o.colorPlaceholder),y(r.base,"background-color",o.colorBackground),y(r.base,"caret-color",o.caretColor),o.colorDanger!==void 0&&(r.invalid={color:o.colorDanger}),o.colorSuccess!==void 0&&(r.complete={color:o.colorSuccess}));let n=e==null?void 0:e.rules,s={base:{...t.base,...r.base,...(p=n==null?void 0:n.base)!=null?p:{}}},d=u(u(t.focus,r.focus),n==null?void 0:n.focus),l=u(u(t.invalid,r.invalid),n==null?void 0:n.invalid),m=u(u(t.complete,r.complete),n==null?void 0:n.complete),c=u(u(t.empty,r.empty),n==null?void 0:n.empty);return d!==void 0&&(s.focus=d),l!==void 0&&(s.invalid=l),m!==void 0&&(s.complete=m),c!==void 0&&(s.empty=c),Q(s)};var M={cardNumber:"Arc Pay card number",cardExpiry:"Arc Pay card expiration date",cardCvv:"Arc Pay card security code"},T=class{constructor(t,r,o){this.field=t;this.options=r;this.context=o;this.iframe=null;this.listeners={ready:new Set,change:new Set,error:new Set};this.status="pending";this.messageHandler=null;}mount(t){if(this.iframe)throw new i({type:"validation_error",code:"already_mounted",message:`Element ${this.field} is already mounted`,retryable:false});let r=typeof t=="string"?document.querySelector(t):t;if(!(r instanceof HTMLElement))throw new i({type:"validation_error",code:"mount_target_not_found",message:`mount target not found: ${String(t)}`,retryable:false});let o=document.createElement("iframe");o.src=`${this.context.iframeBase}/iframe/${this.field}`,o.style.cssText="border:0;width:100%;height:100%;display:block;",o.setAttribute("allow","payment"),o.setAttribute("data-arcpay-element",this.field),o.setAttribute("title",M[this.field]),o.setAttribute("aria-label",M[this.field]),r.appendChild(o),this.iframe=o;let n=new URL(this.context.iframeBase).origin;this.messageHandler=s=>{var l;if(s.source!==((l=this.iframe)==null?void 0:l.contentWindow))return;let d=w(s,n);d&&this.handleMessage(d);},window.addEventListener("message",this.messageHandler),o.addEventListener("load",()=>{if(!this.iframe)return;let s={type:"arcpay:hello",origin:window.location.origin,publishableKey:this.context.publishableKey,channelId:this.context.channelId};x(this.iframe,s,n);},{once:true});}handleMessage(t){t.type==="arcpay:ready"?(this.status="ready",this.options.appearance&&this.send({type:"arcpay:style",payload:P(this.options.appearance)}),this.options.placeholder&&this.send({type:"arcpay:placeholder",field:this.field,placeholder:this.options.placeholder}),this.emit({type:"ready"})):t.type==="arcpay:rejected"?(this.status="error",this.emit({type:"error",reason:t.reason})):t.type==="arcpay:change"&&t.field===this.field&&this.emit({type:"change",isValid:t.isValid,isEmpty:t.isEmpty,isComplete:t.isComplete,brand:t.brand,lastFour:t.lastFour});}update(t){t.appearance&&this.send({type:"arcpay:style",payload:P(t.appearance)}),t.placeholder&&this.send({type:"arcpay:placeholder",field:this.field,placeholder:t.placeholder});}destroy(){this.iframe&&(this.iframe.remove(),this.iframe=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null);for(let t of Object.values(this.listeners))t.clear();this.status="pending";}on(t,r){return this.listeners[t].add(r),()=>this.listeners[t].delete(r)}focus(){this.send({type:"arcpay:focus"});}clear(){this.send({type:"arcpay:clear"});}isReady(){return this.status==="ready"}getIframeContentWindow(){var t,r;return (r=(t=this.iframe)==null?void 0:t.contentWindow)!=null?r:null}send(t){if(!this.iframe)throw new i({type:"validation_error",code:"not_mounted",message:`Element ${this.field} is not mounted`,retryable:false});x(this.iframe,t,new URL(this.context.iframeBase).origin);}emit(t){for(let r of this.listeners[t.type])r(t);}};var Z="https://sdk.arcpay.space",ee=()=>{var e;if(!((e=globalThis.crypto)!=null&&e.randomUUID))throw new i({type:"validation_error",code:"crypto_unavailable",message:"crypto.randomUUID is required for Hosted Fields",retryable:false});return globalThis.crypto.randomUUID()},f=class{constructor(t){this.elementMap=new Map;this.tokenizeInFlight=false;var r;this.publishableKey=t.publishableKey,this.iframeBase=(r=t.iframeBase)!=null?r:Z,this.channelId=ee(),this.appearance=t.appearance;}create(t,r={}){var s;if(this.elementMap.has(t))throw new i({type:"validation_error",code:"duplicate_element",message:`Element for ${t} already created`,retryable:false});let o={iframeBase:this.iframeBase,publishableKey:this.publishableKey,channelId:this.channelId},n=new T(t,{...r,appearance:(s=r.appearance)!=null?s:this.appearance},o);return this.elementMap.set(t,n),n}async tokenize(t,r){if(this.tokenizeInFlight)throw new i({type:"validation_error",code:"tokenize_in_progress",message:"A tokenize() call is already in progress for this Elements instance",retryable:false});let o=this.elementMap.get("cardNumber"),n=this.elementMap.get("cardExpiry"),s=this.elementMap.get("cardCvv");if(!o||!n||!s)throw new i({type:"validation_error",code:"incomplete_elements",message:"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()",retryable:false});if(!o.isReady()||!n.isReady()||!s.isReady())throw new i({type:"validation_error",code:"elements_not_ready",message:"Wait for all elements to fire 'ready' event before tokenize()",retryable:false});this.tokenizeInFlight=true;try{return await this.doTokenize(o,t,r)}finally{this.tokenizeInFlight=false;}}doTokenize(t,r,o){let n=new URL(this.iframeBase).origin,s=t.getIframeContentWindow();return new Promise((d,l)=>{let m=window.setTimeout(()=>{window.removeEventListener("message",c),l(new i({type:"network_error",code:"tokenize_timeout",message:"tokenize() timed out after 30 seconds",retryable:true,paymentId:r}));},3e4),c=p=>{if(s!==null&&p.source!==s)return;let a=w(p,n);a&&(a.type==="arcpay:tokenize-result"?(clearTimeout(m),window.removeEventListener("message",c),d({cardTokenId:a.cardTokenId,cardMask:a.cardMask,cardScheme:a.cardScheme,cardBin:a.cardBin,expiresIn:a.expiresIn,expiresAt:a.expiresAt})):a.type==="arcpay:tokenize-error"&&(clearTimeout(m),window.removeEventListener("message",c),l(new i({type:a.errorType==="validation_error"||a.errorType==="configuration_error"||a.errorType==="network_error"||a.errorType==="api_error"?a.errorType:"api_error",code:a.code,message:a.message,retryable:false,paymentId:r}))));};window.addEventListener("message",c),t.send({type:"arcpay:tokenize",paymentId:r,idempotencyKey:o});})}destroy(){for(let t of this.elementMap.values())t.destroy();this.elementMap.clear();}};var te=D,A=new Map,re=e=>(S(e)==="sandbox"&&B(),{publishableKey:e,environment:S(e),elements:(t={})=>new f({publishableKey:e,...t})});function oe(e){try{te(e);}catch(n){return Promise.reject(n)}let t=e,r=A.get(t);if(r)return r;let o=Promise.resolve(re(e));return A.set(t,o),o}var ne=()=>{A.clear();},se={load:oe,__resetForTests:ne};var ie=[1,4,8,15,16,24,32,48],ae=e=>ie.includes(e)?e:24,le=e=>e>=1e3?"05":e>=600?"04":e>=500?"03":e>=390?"02":"01",R=(e="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")=>{if(typeof window=="undefined"||typeof navigator=="undefined"||typeof screen=="undefined")throw new Error("collectBrowserInfo must be called in a browser environment");return {accept_header:e,language:navigator.language||"en",screen_width:screen.width,screen_height:screen.height,color_depth:ae(screen.colorDepth),timezone_offset_minutes:new Date().getTimezoneOffset(),java_enabled:false,user_agent:navigator.userAgent,window_size:le(window.innerWidth||screen.width)}},v=e=>e!=null?e:null,E=e=>(e==null?void 0:e.type)==="three_ds_method"&&e.three_ds.phase==="method",_=e=>(e==null?void 0:e.type)==="three_ds_challenge"&&e.three_ds.phase==="challenge",b=e=>({action:e.three_ds.submit.url,method:e.three_ds.submit.method,target:e.three_ds.submit.target,fields:e.three_ds.submit.fields}),z=e=>{let t;try{t=new URL(e);}catch(r){throw new Error("3DS form action must be an absolute HTTPS URL")}if(t.protocol!=="https:")throw new Error("3DS form action must use HTTPS")},C=e=>{let t=v(e);return t?{kind:t.three_ds.phase,protocolVersion:t.three_ds.version,form:b(t),completionEndpoint:t.three_ds.completion_endpoint,threeDSServerTransId:t.three_ds.three_ds_server_trans_id}:null},I=(e,t="Y")=>{if(!E(e)||!e.three_ds.three_ds_server_trans_id)throw new Error("nextAction must be a three_ds_method action with three_ds_server_trans_id");return {completion_indicator:t,three_ds_server_trans_id:e.three_ds.three_ds_server_trans_id}},de=e=>{if(e)return e;if(typeof document=="undefined")throw new Error("3DS browser helpers must be called in a browser environment");return document},ce=e=>{e.submit();},g=(e,t={})=>{var m,c;let r=de(t.document),o=(m=t.container)!=null?m:r.body,n=b(e);z(n.action);let s=r.createElement("form"),d=n.target==="hidden_iframe"?`arcpay-three-ds-method-${crypto.randomUUID()}`:(c=t.challengeTarget)!=null?c:"_self",l;s.method=n.method,s.action=n.action,s.target=d,s.hidden=true;for(let p of n.fields){let a=r.createElement("input");a.type="hidden",a.name=p.name,a.value=p.value,s.append(a);}return n.target==="hidden_iframe"&&(l=r.createElement("iframe"),l.name=d,l.title="3-D Secure method",l.hidden=true,o.append(l)),o.append(s),{form:s,iframe:l,submit:()=>{var p;return ((p=t.submitter)!=null?p:ce)(s)},remove:()=>{s.remove(),l==null||l.remove();}}},pe=(e,t,r)=>new Promise((o,n)=>{if(!e.iframe){o("loaded");return}if(r!=null&&r.aborted){n(new DOMException("The operation was aborted","AbortError"));return}let s=false,d=()=>{var a;(a=e.iframe)==null||a.removeEventListener("load",m),r==null||r.removeEventListener("abort",c),clearTimeout(p);},l=a=>{s||(s=true,d(),o(a));},m=()=>l("loaded"),c=()=>{s||(s=true,d(),n(new DOMException("The operation was aborted","AbortError")));},p=setTimeout(()=>l("timeout"),t);e.iframe.addEventListener("load",m,{once:true}),r==null||r.addEventListener("abort",c,{once:true});}),H=async(e,t)=>{var n,s;if(!e)return {status:"no_action"};if(_(e)){let d=g(e,t);return d.submit(),{status:"challenge_submitted",action:e,mounted:d}}if(!E(e))return {status:"no_action"};let r=t.completeThreeDSMethod;if(!r)throw new Error("completeThreeDSMethod is required for 3DS Method actions");let o=g(e,t);try{o.submit();let d=await pe(o,(n=t.methodTimeoutMs)!=null?n:1e4,t.signal),l=(s=t.methodCompletionIndicator)!=null?s:d==="loaded"?"Y":"N",m=await r(I(e,l),e),c=v(m.next_action);if(c&&_(c)){let p=g(c,t);return p.submit(),{status:"challenge_submitted",action:c,response:m,mounted:p,methodResult:d}}return {status:"method_completed",response:m,methodResult:d}}finally{o.remove();}},F=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),L=e=>{let t=b(e);z(t.action);let r=t.target==="hidden_iframe"?"arcpay-three-ds-method":"_self",o=t.fields.map(s=>`<input type="hidden" name="${F(s.name)}" value="${F(s.value)}">`).join("");return `<!doctype html><html><head><meta charset="utf-8"></head><body>${t.target==="hidden_iframe"?'<iframe name="arcpay-three-ds-method" title="3-D Secure method" hidden></iframe>':""}<form method="POST" action="${F(t.action)}" target="${r}">${o}</form><script>document.forms[0].submit();</script></body></html>`};var ze="0.1.25";
|
|
1
|
+
var ArcPay=(function(exports){'use strict';var i=class extends Error{constructor(t){super(t.message),this.name="ArcPayError",this.type=t.type,this.code=t.code,this.param=t.param,this.paymentId=t.paymentId,this.declineCode=t.declineCode,this.retryable=t.retryable,this.requestId=t.requestId;}},O=e=>e instanceof i&&e.type==="validation_error";var N=e=>e instanceof i&&e.type==="authentication_error",U=e=>e instanceof i&&e.type==="authorization_error",W=e=>e instanceof i&&e.type==="state_error",$=e=>e instanceof i&&e.type==="rate_limit_error",K=e=>e instanceof i&&e.type==="api_error",q=e=>e instanceof i&&e.type==="network_error",V=e=>e instanceof i&&e.type==="challenge_aborted";var S=e=>e.startsWith("pk_test_")?"sandbox":"live",D=e=>{if(typeof e!="string"||e.length===0)throw new i({type:"validation_error",code:"invalid_publishable_key",message:"Publishable key must be a non-empty string",retryable:false});if(!e.startsWith("pk_test_")&&!e.startsWith("pk_live_"))throw new i({type:"validation_error",code:"invalid_publishable_key",message:"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.",retryable:false})};var k="data-arcpay-sandbox-banner",B=()=>{if(typeof document=="undefined"||document.querySelector(`[${k}]`))return;let e=document.createElement("div");e.setAttribute(k,""),e.style.cssText="position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);";let t=document.createElement("span");t.textContent="ARC PAY TEST MODE \u2014 payments are simulated",e.appendChild(t);let r=document.createElement("button");r.type="button",r.setAttribute("data-arcpay-banner-dismiss",""),r.textContent="\xD7",r.setAttribute("aria-label","Dismiss test mode banner"),r.style.cssText="margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;",r.addEventListener("click",()=>e.remove()),e.appendChild(r),document.body.appendChild(e);};var Y="arcpay:",j=e=>typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string"&&e.type.startsWith(Y),x=(e,t,r)=>{if(r==="*")throw new i({type:"validation_error",code:"wildcard_origin_forbidden",message:"postToIframe: targetOrigin cannot be '*'",retryable:false});if(!e.contentWindow)throw new i({type:"validation_error",code:"iframe_not_loaded",message:"postToIframe: iframe.contentWindow is null (iframe not mounted)",retryable:false});e.contentWindow.postMessage(t,r);};var w=(e,t)=>e.origin!==t||!j(e.data)?null:e.data;var X=new Set(["--arcpay-placeholder-color","background-color","caret-color","color","font-family","font-size","font-style","font-weight","letter-spacing","line-height","opacity","text-align","text-decoration","text-transform"]),G={base:{"font-family":'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',"font-size":"16px","line-height":"24px",color:"#111827","--arcpay-placeholder-color":"#9ca3af","caret-color":"#111827"},focus:{color:"#111827"},invalid:{color:"#dc2626"},complete:{color:"#111827"},empty:{color:"#111827"}},u=(e,t)=>{if(!(!e&&!t))return {...e!=null?e:{},...t!=null?t:{}}},y=(e,t,r)=>{r!==void 0&&(e[t]=r);},J=e=>{if(!(e===void 0||e==="none"||e==="arcpay"))throw new i({type:"validation_error",code:"invalid_hosted_fields_theme",message:`Unsupported Hosted Fields appearance theme: ${String(e)}`,retryable:false})},h=e=>{let t={};for(let[r,o]of Object.entries(e)){let n=r.toLowerCase();X.has(n)&&(t[n]=o);}return t},Q=e=>{let t={base:h(e.base)};return e.invalid!==void 0&&(t.invalid=h(e.invalid)),e.focus!==void 0&&(t.focus=h(e.focus)),e.complete!==void 0&&(t.complete=h(e.complete)),e.empty!==void 0&&(t.empty=h(e.empty)),t},P=e=>{var p;J(e==null?void 0:e.theme);let t=(e==null?void 0:e.theme)==="arcpay"?G:{base:{}},r={base:{}},o=e==null?void 0:e.variables;o&&(y(r.base,"font-family",o.fontFamily),y(r.base,"font-size",o.fontSize),y(r.base,"font-weight",o.fontWeight),y(r.base,"font-style",o.fontStyle),y(r.base,"line-height",o.lineHeight),y(r.base,"letter-spacing",o.letterSpacing),y(r.base,"text-align",o.textAlign),y(r.base,"color",o.colorText),y(r.base,"--arcpay-placeholder-color",o.colorPlaceholder),y(r.base,"background-color",o.colorBackground),y(r.base,"caret-color",o.caretColor),o.colorDanger!==void 0&&(r.invalid={color:o.colorDanger}),o.colorSuccess!==void 0&&(r.complete={color:o.colorSuccess}));let n=e==null?void 0:e.rules,s={base:{...t.base,...r.base,...(p=n==null?void 0:n.base)!=null?p:{}}},d=u(u(t.focus,r.focus),n==null?void 0:n.focus),l=u(u(t.invalid,r.invalid),n==null?void 0:n.invalid),m=u(u(t.complete,r.complete),n==null?void 0:n.complete),c=u(u(t.empty,r.empty),n==null?void 0:n.empty);return d!==void 0&&(s.focus=d),l!==void 0&&(s.invalid=l),m!==void 0&&(s.complete=m),c!==void 0&&(s.empty=c),Q(s)};var M={cardNumber:"Arc Pay card number",cardExpiry:"Arc Pay card expiration date",cardCvv:"Arc Pay card security code"},T=class{constructor(t,r,o){this.field=t;this.options=r;this.context=o;this.iframe=null;this.listeners={ready:new Set,change:new Set,error:new Set};this.status="pending";this.messageHandler=null;}mount(t){if(this.iframe)throw new i({type:"validation_error",code:"already_mounted",message:`Element ${this.field} is already mounted`,retryable:false});let r=typeof t=="string"?document.querySelector(t):t;if(!(r instanceof HTMLElement))throw new i({type:"validation_error",code:"mount_target_not_found",message:`mount target not found: ${String(t)}`,retryable:false});let o=document.createElement("iframe");o.src=`${this.context.iframeBase}/iframe/${this.field}`,o.style.cssText="border:0;width:100%;height:100%;display:block;",o.setAttribute("allow","payment"),o.setAttribute("data-arcpay-element",this.field),o.setAttribute("title",M[this.field]),o.setAttribute("aria-label",M[this.field]),r.appendChild(o),this.iframe=o;let n=new URL(this.context.iframeBase).origin;this.messageHandler=s=>{var l;if(s.source!==((l=this.iframe)==null?void 0:l.contentWindow))return;let d=w(s,n);d&&this.handleMessage(d);},window.addEventListener("message",this.messageHandler),o.addEventListener("load",()=>{if(!this.iframe)return;let s={type:"arcpay:hello",origin:window.location.origin,publishableKey:this.context.publishableKey,channelId:this.context.channelId};x(this.iframe,s,n);},{once:true});}handleMessage(t){t.type==="arcpay:ready"?(this.status="ready",this.options.appearance&&this.send({type:"arcpay:style",payload:P(this.options.appearance)}),this.options.placeholder&&this.send({type:"arcpay:placeholder",field:this.field,placeholder:this.options.placeholder}),this.emit({type:"ready"})):t.type==="arcpay:rejected"?(this.status="error",this.emit({type:"error",reason:t.reason})):t.type==="arcpay:change"&&t.field===this.field&&this.emit({type:"change",isValid:t.isValid,isEmpty:t.isEmpty,isComplete:t.isComplete,brand:t.brand,lastFour:t.lastFour});}update(t){t.appearance&&this.send({type:"arcpay:style",payload:P(t.appearance)}),t.placeholder&&this.send({type:"arcpay:placeholder",field:this.field,placeholder:t.placeholder});}destroy(){this.iframe&&(this.iframe.remove(),this.iframe=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null);for(let t of Object.values(this.listeners))t.clear();this.status="pending";}on(t,r){return this.listeners[t].add(r),()=>this.listeners[t].delete(r)}focus(){this.send({type:"arcpay:focus"});}clear(){this.send({type:"arcpay:clear"});}isReady(){return this.status==="ready"}getIframeContentWindow(){var t,r;return (r=(t=this.iframe)==null?void 0:t.contentWindow)!=null?r:null}send(t){if(!this.iframe)throw new i({type:"validation_error",code:"not_mounted",message:`Element ${this.field} is not mounted`,retryable:false});x(this.iframe,t,new URL(this.context.iframeBase).origin);}emit(t){for(let r of this.listeners[t.type])r(t);}};var Z="https://sdk.arcpay.space",ee=()=>{var e;if(!((e=globalThis.crypto)!=null&&e.randomUUID))throw new i({type:"validation_error",code:"crypto_unavailable",message:"crypto.randomUUID is required for Hosted Fields",retryable:false});return globalThis.crypto.randomUUID()},f=class{constructor(t){this.elementMap=new Map;this.tokenizeInFlight=false;var r;this.publishableKey=t.publishableKey,this.iframeBase=(r=t.iframeBase)!=null?r:Z,this.channelId=ee(),this.appearance=t.appearance;}create(t,r={}){var s;if(this.elementMap.has(t))throw new i({type:"validation_error",code:"duplicate_element",message:`Element for ${t} already created`,retryable:false});let o={iframeBase:this.iframeBase,publishableKey:this.publishableKey,channelId:this.channelId},n=new T(t,{...r,appearance:(s=r.appearance)!=null?s:this.appearance},o);return this.elementMap.set(t,n),n}async tokenize(t,r){if(this.tokenizeInFlight)throw new i({type:"validation_error",code:"tokenize_in_progress",message:"A tokenize() call is already in progress for this Elements instance",retryable:false});let o=this.elementMap.get("cardNumber"),n=this.elementMap.get("cardExpiry"),s=this.elementMap.get("cardCvv");if(!o||!n||!s)throw new i({type:"validation_error",code:"incomplete_elements",message:"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()",retryable:false});if(!o.isReady()||!n.isReady()||!s.isReady())throw new i({type:"validation_error",code:"elements_not_ready",message:"Wait for all elements to fire 'ready' event before tokenize()",retryable:false});this.tokenizeInFlight=true;try{return await this.doTokenize(o,t,r)}finally{this.tokenizeInFlight=false;}}doTokenize(t,r,o){let n=new URL(this.iframeBase).origin,s=t.getIframeContentWindow();return new Promise((d,l)=>{let m=window.setTimeout(()=>{window.removeEventListener("message",c),l(new i({type:"network_error",code:"tokenize_timeout",message:"tokenize() timed out after 30 seconds",retryable:true,paymentId:r}));},3e4),c=p=>{if(s!==null&&p.source!==s)return;let a=w(p,n);a&&(a.type==="arcpay:tokenize-result"?(clearTimeout(m),window.removeEventListener("message",c),d({cardTokenId:a.cardTokenId,cardMask:a.cardMask,cardScheme:a.cardScheme,cardBin:a.cardBin,expiresIn:a.expiresIn,expiresAt:a.expiresAt})):a.type==="arcpay:tokenize-error"&&(clearTimeout(m),window.removeEventListener("message",c),l(new i({type:a.errorType==="validation_error"||a.errorType==="configuration_error"||a.errorType==="network_error"||a.errorType==="api_error"?a.errorType:"api_error",code:a.code,message:a.message,retryable:false,paymentId:r}))));};window.addEventListener("message",c),t.send({type:"arcpay:tokenize",paymentId:r,idempotencyKey:o});})}destroy(){for(let t of this.elementMap.values())t.destroy();this.elementMap.clear();}};var te=D,A=new Map,re=e=>(S(e)==="sandbox"&&B(),{publishableKey:e,environment:S(e),elements:(t={})=>new f({publishableKey:e,...t})});function oe(e){try{te(e);}catch(n){return Promise.reject(n)}let t=e,r=A.get(t);if(r)return r;let o=Promise.resolve(re(e));return A.set(t,o),o}var ne=()=>{A.clear();},se={load:oe,__resetForTests:ne};var ie=[1,4,8,15,16,24,32,48],ae=e=>ie.includes(e)?e:24,le=e=>e>=1e3?"05":e>=600?"04":e>=500?"03":e>=390?"02":"01",R=(e="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")=>{if(typeof window=="undefined"||typeof navigator=="undefined"||typeof screen=="undefined")throw new Error("collectBrowserInfo must be called in a browser environment");return {accept_header:e,language:navigator.language||"en",screen_width:screen.width,screen_height:screen.height,color_depth:ae(screen.colorDepth),timezone_offset_minutes:new Date().getTimezoneOffset(),java_enabled:false,user_agent:navigator.userAgent,window_size:le(window.innerWidth||screen.width)}},v=e=>e!=null?e:null,E=e=>(e==null?void 0:e.type)==="three_ds_method"&&e.three_ds.phase==="method",_=e=>(e==null?void 0:e.type)==="three_ds_challenge"&&e.three_ds.phase==="challenge",b=e=>({action:e.three_ds.submit.url,method:e.three_ds.submit.method,target:e.three_ds.submit.target,fields:e.three_ds.submit.fields}),z=e=>{let t;try{t=new URL(e);}catch(r){throw new Error("3DS form action must be an absolute HTTPS URL")}if(t.protocol!=="https:")throw new Error("3DS form action must use HTTPS")},C=e=>{let t=v(e);return t?{kind:t.three_ds.phase,protocolVersion:t.three_ds.version,form:b(t),completionEndpoint:t.three_ds.completion_endpoint,threeDSServerTransId:t.three_ds.three_ds_server_trans_id}:null},I=(e,t="Y")=>{if(!E(e)||!e.three_ds.three_ds_server_trans_id)throw new Error("nextAction must be a three_ds_method action with three_ds_server_trans_id");return {completion_indicator:t,three_ds_server_trans_id:e.three_ds.three_ds_server_trans_id}},de=e=>{if(e)return e;if(typeof document=="undefined")throw new Error("3DS browser helpers must be called in a browser environment");return document},ce=e=>{e.submit();},g=(e,t={})=>{var m,c;let r=de(t.document),o=(m=t.container)!=null?m:r.body,n=b(e);z(n.action);let s=r.createElement("form"),d=n.target==="hidden_iframe"?`arcpay-three-ds-method-${crypto.randomUUID()}`:(c=t.challengeTarget)!=null?c:"_self",l;s.method=n.method,s.action=n.action,s.target=d,s.hidden=true;for(let p of n.fields){let a=r.createElement("input");a.type="hidden",a.name=p.name,a.value=p.value,s.append(a);}return n.target==="hidden_iframe"&&(l=r.createElement("iframe"),l.name=d,l.title="3-D Secure method",l.hidden=true,o.append(l)),o.append(s),{form:s,iframe:l,submit:()=>{var p;return ((p=t.submitter)!=null?p:ce)(s)},remove:()=>{s.remove(),l==null||l.remove();}}},pe=(e,t,r)=>new Promise((o,n)=>{if(!e.iframe){o("loaded");return}if(r!=null&&r.aborted){n(new DOMException("The operation was aborted","AbortError"));return}let s=false,d=()=>{var a;(a=e.iframe)==null||a.removeEventListener("load",m),r==null||r.removeEventListener("abort",c),clearTimeout(p);},l=a=>{s||(s=true,d(),o(a));},m=()=>l("loaded"),c=()=>{s||(s=true,d(),n(new DOMException("The operation was aborted","AbortError")));},p=setTimeout(()=>l("timeout"),t);e.iframe.addEventListener("load",m,{once:true}),r==null||r.addEventListener("abort",c,{once:true});}),H=async(e,t)=>{var n,s;if(!e)return {status:"no_action"};if(_(e)){let d=g(e,t);return d.submit(),{status:"challenge_submitted",action:e,mounted:d}}if(!E(e))return {status:"no_action"};let r=t.completeThreeDSMethod;if(!r)throw new Error("completeThreeDSMethod is required for 3DS Method actions");let o=g(e,t);try{o.submit();let d=await pe(o,(n=t.methodTimeoutMs)!=null?n:1e4,t.signal),l=(s=t.methodCompletionIndicator)!=null?s:d==="loaded"?"Y":"N",m=await r(I(e,l),e),c=v(m.next_action);if(c&&_(c)){let p=g(c,t);return p.submit(),{status:"challenge_submitted",action:c,response:m,mounted:p,methodResult:d}}return {status:"method_completed",response:m,methodResult:d}}finally{o.remove();}},F=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),L=e=>{let t=b(e);z(t.action);let r=t.target==="hidden_iframe"?"arcpay-three-ds-method":"_self",o=t.fields.map(s=>`<input type="hidden" name="${F(s.name)}" value="${F(s.value)}">`).join("");return `<!doctype html><html><head><meta charset="utf-8"></head><body>${t.target==="hidden_iframe"?'<iframe name="arcpay-three-ds-method" title="3-D Secure method" hidden></iframe>':""}<form method="POST" action="${F(t.action)}" target="${r}">${o}</form><script>document.forms[0].submit();</script></body></html>`};var ze="0.1.26";
|
|
2
2
|
exports.ArcPay=se;exports.ArcPayError=i;exports.Elements=f;exports.SDK_VERSION=ze;exports.buildThreeDSAutoSubmitHtml=L;exports.buildThreeDSBrowserForm=b;exports.buildThreeDSBrowserStep=C;exports.buildThreeDSMethodCompletion=I;exports.collectBrowserInfo=R;exports.getThreeDSAction=v;exports.isApiError=K;exports.isAuthenticationError=N;exports.isAuthorizationError=U;exports.isChallengeAborted=V;exports.isNetworkError=q;exports.isRateLimitError=$;exports.isStateError=W;exports.isThreeDSChallengeAction=_;exports.isThreeDSMethodAction=E;exports.isValidationError=O;exports.mountThreeDSBrowserForm=g;exports.runThreeDSBrowserFlow=H;return exports;})({});//# sourceMappingURL=arcpay.global.js.map
|
|
3
3
|
//# sourceMappingURL=arcpay.global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/errors.ts","../../src/core/env.ts","../../src/core/sandbox-banner.ts","../../src/elements/postmessage.ts","../../src/elements/style.ts","../../src/elements/element.ts","../../src/elements/elements.ts","../../src/core/arcpay.ts","../../src/three-ds/actions.ts","../../src/index.ts"],"names":["ArcPayError","init","isValidationError","isAuthenticationError","isAuthorizationError","isStateError","isRateLimitError","isApiError","isNetworkError","isChallengeAborted","detectEnvironment","publishableKey","validatePublishableKey","key","BANNER_ATTR","showSandboxBanner","bar","text","dismiss","ARCPAY_TYPE_PREFIX","isArcpayMessage","data","postToIframe","iframe","message","targetOrigin","parseIncoming","event","expectedOrigin","ALLOWED_PROPERTIES","ARCPAY_THEME","mergeBlock","target","source","setIfPresent","block","value","assertKnownTheme","theme","sanitizeBlock","out","normalizedKey","sanitizeStyle","style","result","buildStyleFromAppearance","appearance","_a","themeStyle","variableStyle","variables","rules","combined","focus","invalid","complete","empty","FIELD_TITLES","Element","field","options","context","container","hello","listeners","callback","_b","listener","DEFAULT_IFRAME_BASE","createChannelId","Elements","opts","ctx","element","paymentId","idempotencyKey","cardNumber","cardExpiry","cardCvv","iframeOrigin","cardIframeWindow","resolve","reject","timer","onMessage","el","cache","buildInstance","load","err","existing","promise","resetForTests","ArcPay","supportedColorDepths","normalizeColorDepth","resolveWindowSize","width","collectBrowserInfo","acceptHeader","getThreeDSAction","nextAction","isThreeDSMethodAction","isThreeDSChallengeAction","buildThreeDSBrowserForm","assertHTTPSActionURL","action","parsed","e","buildThreeDSBrowserStep","buildThreeDSMethodCompletion","completionIndicator","requireDocument","explicitDocument","defaultSubmitter","form","mountThreeDSBrowserForm","doc","formDescriptor","input","waitForMethodFrame","mounted","timeoutMs","signal","settled","cleanup","onLoad","onAbort","settle","runThreeDSBrowserFlow","completeThreeDSMethod","methodResult","indicator","response","followUpAction","challengeMounted","htmlEscape","buildThreeDSAutoSubmitHtml","inputs","SDK_VERSION"],"mappings":"2CAsBO,IAAMA,EAAN,cAA0B,KAAM,CASrC,WAAA,CAAYC,EAAuB,CACjC,KAAA,CAAMA,CAAAA,CAAK,OAAO,EAClB,IAAA,CAAK,IAAA,CAAO,aAAA,CACZ,IAAA,CAAK,KAAOA,CAAAA,CAAK,IAAA,CACjB,IAAA,CAAK,IAAA,CAAOA,EAAK,IAAA,CACjB,IAAA,CAAK,KAAA,CAAQA,CAAAA,CAAK,MAClB,IAAA,CAAK,SAAA,CAAYA,CAAAA,CAAK,SAAA,CACtB,KAAK,WAAA,CAAcA,CAAAA,CAAK,YACxB,IAAA,CAAK,SAAA,CAAYA,EAAK,SAAA,CACtB,IAAA,CAAK,SAAA,CAAYA,CAAAA,CAAK,UACxB,CACF,CAAA,CAEaC,CAAAA,CAAqB,CAAA,EAChC,aAAaF,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,uBAG5BG,CAAAA,CAAyB,CAAA,EACpC,CAAA,YAAaH,CAAAA,EAAe,EAAE,IAAA,GAAS,sBAAA,CAC5BI,CAAAA,CAAwB,CAAA,EACnC,aAAaJ,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,qBAAA,CAC5BK,EAAgB,CAAA,EAC3B,CAAA,YAAaL,CAAAA,EAAe,CAAA,CAAE,OAAS,aAAA,CAC5BM,CAAAA,CAAoB,GAC/B,CAAA,YAAaN,CAAAA,EAAe,EAAE,IAAA,GAAS,kBAAA,CAC5BO,CAAAA,CAAc,CAAA,EACzB,aAAaP,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,WAAA,CAC5BQ,EAAkB,CAAA,EAC7B,CAAA,YAAaR,CAAAA,EAAe,CAAA,CAAE,OAAS,eAAA,CAC5BS,CAAAA,CAAsB,CAAA,EAC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CACpK,MCxSaC,EAAAA,CAAc","file":"arcpay.global.js","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"configuration_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\ninterface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nconst isConfigurationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"configuration_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError } from \"./errors\";\n\nexport type Environment = \"sandbox\" | \"live\";\n\nexport const detectEnvironment = (publishableKey: string): Environment =>\n publishableKey.startsWith(\"pk_test_\") ? \"sandbox\" : \"live\";\n\nexport const validatePublishableKey = (key: unknown): asserts key is string => {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message: \"Publishable key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"pk_test_\") && !key.startsWith(\"pk_live_\")) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message:\n \"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.\",\n retryable: false,\n });\n }\n};\n","const BANNER_ATTR = \"data-arcpay-sandbox-banner\";\n\nexport const showSandboxBanner = (): void => {\n if (typeof document === \"undefined\") return;\n if (document.querySelector(`[${BANNER_ATTR}]`)) return;\n\n const bar = document.createElement(\"div\");\n bar.setAttribute(BANNER_ATTR, \"\");\n bar.style.cssText =\n \"position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);\";\n\n const text = document.createElement(\"span\");\n text.textContent = \"ARC PAY TEST MODE — payments are simulated\";\n bar.appendChild(text);\n\n const dismiss = document.createElement(\"button\");\n dismiss.type = \"button\";\n dismiss.setAttribute(\"data-arcpay-banner-dismiss\", \"\");\n dismiss.textContent = \"×\";\n dismiss.setAttribute(\"aria-label\", \"Dismiss test mode banner\");\n dismiss.style.cssText =\n \"margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;\";\n dismiss.addEventListener(\"click\", () => bar.remove());\n bar.appendChild(dismiss);\n\n document.body.appendChild(bar);\n};\n","import { ArcPayError } from \"../core/errors\";\n\nexport type FieldType = \"cardNumber\" | \"cardExpiry\" | \"cardCvv\";\n\n// Parent → iframe\nexport type ParentToIframe =\n | { type: \"arcpay:hello\"; origin: string; publishableKey: string; channelId: string }\n | { type: \"arcpay:style\"; payload: StyleSubset }\n | { type: \"arcpay:placeholder\"; field: FieldType; placeholder: string }\n | { type: \"arcpay:focus\" }\n | { type: \"arcpay:clear\" }\n | { type: \"arcpay:tokenize\"; paymentId: string; idempotencyKey: string };\n\n// iframe → parent\nexport type IframeToParent =\n | { type: \"arcpay:ready\" }\n | { type: \"arcpay:rejected\"; reason: string }\n | {\n type: \"arcpay:change\";\n field: FieldType;\n isValid: boolean;\n isEmpty: boolean;\n isComplete: boolean;\n brand?: string;\n lastFour?: string;\n }\n | {\n type: \"arcpay:tokenize-result\";\n cardTokenId: string;\n cardMask: string;\n cardScheme: string;\n cardBin: string;\n expiresIn: number;\n expiresAt: string;\n }\n | { type: \"arcpay:tokenize-error\"; errorType: string; code?: string; message: string };\n\nexport interface StyleSubset {\n base: Record<string, string>;\n invalid?: Record<string, string>;\n focus?: Record<string, string>;\n complete?: Record<string, string>;\n empty?: Record<string, string>;\n}\n\ntype TokenizeErrorType = \"validation_error\" | \"configuration_error\" | \"network_error\" | \"api_error\";\n\nconst ARCPAY_TYPE_PREFIX = \"arcpay:\";\n\nconst isArcpayMessage = (data: unknown): data is { type: string } =>\n typeof data === \"object\" &&\n data !== null &&\n \"type\" in data &&\n typeof (data as { type: unknown }).type === \"string\" &&\n (data as { type: string }).type.startsWith(ARCPAY_TYPE_PREFIX);\n\nexport const postToIframe = (\n iframe: HTMLIFrameElement,\n message: ParentToIframe,\n targetOrigin: string,\n): void => {\n if (targetOrigin === \"*\") {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"wildcard_origin_forbidden\",\n message: \"postToIframe: targetOrigin cannot be '*'\",\n retryable: false,\n });\n }\n if (!iframe.contentWindow) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"iframe_not_loaded\",\n message: \"postToIframe: iframe.contentWindow is null (iframe not mounted)\",\n retryable: false,\n });\n }\n iframe.contentWindow.postMessage(message, targetOrigin);\n};\n\nexport const postToParent = (message: IframeToParent, targetOrigin: string): void => {\n if (targetOrigin === \"*\") {\n throw new Error(\"postToParent: targetOrigin cannot be '*'\");\n }\n window.parent.postMessage(message, targetOrigin);\n};\n\nexport const parseIncoming = <T extends { type: string }>(\n event: MessageEvent,\n expectedOrigin: string,\n): T | null => {\n if (event.origin !== expectedOrigin) return null;\n if (!isArcpayMessage(event.data)) return null;\n return event.data as T;\n};\n","import type { StyleSubset } from \"./postmessage\";\nimport { ArcPayError } from \"../core/errors\";\n\nexport type HostedFieldsTheme = \"none\" | \"arcpay\";\n\nexport interface HostedFieldsAppearanceVariables {\n fontFamily?: string;\n fontSize?: string;\n fontWeight?: string;\n fontStyle?: string;\n lineHeight?: string;\n letterSpacing?: string;\n textAlign?: string;\n colorText?: string;\n colorPlaceholder?: string;\n colorDanger?: string;\n colorSuccess?: string;\n colorBackground?: string;\n caretColor?: string;\n}\n\nexport type HostedFieldsAppearanceRule = \"base\" | \"focus\" | \"invalid\" | \"complete\" | \"empty\";\n\nexport interface HostedFieldsAppearance {\n theme?: HostedFieldsTheme;\n variables?: HostedFieldsAppearanceVariables;\n rules?: Partial<Record<HostedFieldsAppearanceRule, Record<string, string>>>;\n}\n\nconst ALLOWED_PROPERTIES = new Set([\n \"--arcpay-placeholder-color\",\n \"background-color\",\n \"caret-color\",\n \"color\",\n \"font-family\",\n \"font-size\",\n \"font-style\",\n \"font-weight\",\n \"letter-spacing\",\n \"line-height\",\n \"opacity\",\n \"text-align\",\n \"text-decoration\",\n \"text-transform\",\n]);\n\nconst ARCPAY_THEME: StyleSubset = {\n base: {\n \"font-family\":\n 'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n \"font-size\": \"16px\",\n \"line-height\": \"24px\",\n color: \"#111827\",\n \"--arcpay-placeholder-color\": \"#9ca3af\",\n \"caret-color\": \"#111827\",\n },\n focus: {\n color: \"#111827\",\n },\n invalid: {\n color: \"#dc2626\",\n },\n complete: {\n color: \"#111827\",\n },\n empty: {\n color: \"#111827\",\n },\n};\n\nconst mergeBlock = (\n target: Record<string, string> | undefined,\n source: Record<string, string> | undefined,\n): Record<string, string> | undefined => {\n if (!target && !source) return undefined;\n return { ...(target ?? {}), ...(source ?? {}) };\n};\n\nconst setIfPresent = (\n block: Record<string, string>,\n key: string,\n value: string | undefined,\n): void => {\n if (value !== undefined) block[key] = value;\n};\n\nconst assertKnownTheme = (theme: HostedFieldsTheme | undefined): void => {\n if (theme === undefined || theme === \"none\" || theme === \"arcpay\") return;\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_hosted_fields_theme\",\n message: `Unsupported Hosted Fields appearance theme: ${String(theme)}`,\n retryable: false,\n });\n};\n\nconst sanitizeBlock = (block: Record<string, string>): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(block)) {\n const normalizedKey = key.toLowerCase();\n if (!ALLOWED_PROPERTIES.has(normalizedKey)) {\n continue;\n }\n out[normalizedKey] = value;\n }\n return out;\n};\n\nexport const sanitizeStyle = (style: StyleSubset): StyleSubset => {\n const result: StyleSubset = { base: sanitizeBlock(style.base) };\n if (style.invalid !== undefined) result.invalid = sanitizeBlock(style.invalid);\n if (style.focus !== undefined) result.focus = sanitizeBlock(style.focus);\n if (style.complete !== undefined) result.complete = sanitizeBlock(style.complete);\n if (style.empty !== undefined) result.empty = sanitizeBlock(style.empty);\n return result;\n};\n\nexport const buildStyleFromAppearance = (appearance?: HostedFieldsAppearance): StyleSubset => {\n assertKnownTheme(appearance?.theme);\n const themeStyle: StyleSubset = appearance?.theme === \"arcpay\" ? ARCPAY_THEME : { base: {} };\n const variableStyle: StyleSubset = { base: {} };\n const variables = appearance?.variables;\n\n if (variables) {\n setIfPresent(variableStyle.base, \"font-family\", variables.fontFamily);\n setIfPresent(variableStyle.base, \"font-size\", variables.fontSize);\n setIfPresent(variableStyle.base, \"font-weight\", variables.fontWeight);\n setIfPresent(variableStyle.base, \"font-style\", variables.fontStyle);\n setIfPresent(variableStyle.base, \"line-height\", variables.lineHeight);\n setIfPresent(variableStyle.base, \"letter-spacing\", variables.letterSpacing);\n setIfPresent(variableStyle.base, \"text-align\", variables.textAlign);\n setIfPresent(variableStyle.base, \"color\", variables.colorText);\n setIfPresent(variableStyle.base, \"--arcpay-placeholder-color\", variables.colorPlaceholder);\n setIfPresent(variableStyle.base, \"background-color\", variables.colorBackground);\n setIfPresent(variableStyle.base, \"caret-color\", variables.caretColor);\n\n if (variables.colorDanger !== undefined) {\n variableStyle.invalid = { color: variables.colorDanger };\n }\n if (variables.colorSuccess !== undefined) {\n variableStyle.complete = { color: variables.colorSuccess };\n }\n }\n\n const rules = appearance?.rules;\n const combined: StyleSubset = {\n base: {\n ...themeStyle.base,\n ...variableStyle.base,\n ...(rules?.base ?? {}),\n },\n };\n\n const focus = mergeBlock(mergeBlock(themeStyle.focus, variableStyle.focus), rules?.focus);\n const invalid = mergeBlock(mergeBlock(themeStyle.invalid, variableStyle.invalid), rules?.invalid);\n const complete = mergeBlock(\n mergeBlock(themeStyle.complete, variableStyle.complete),\n rules?.complete,\n );\n const empty = mergeBlock(mergeBlock(themeStyle.empty, variableStyle.empty), rules?.empty);\n\n if (focus !== undefined) combined.focus = focus;\n if (invalid !== undefined) combined.invalid = invalid;\n if (complete !== undefined) combined.complete = complete;\n if (empty !== undefined) combined.empty = empty;\n\n return sanitizeStyle(combined);\n};\n","import { ArcPayError } from \"../core/errors\";\nimport {\n type FieldType,\n type ParentToIframe,\n type IframeToParent,\n postToIframe,\n parseIncoming,\n} from \"./postmessage\";\nimport { buildStyleFromAppearance, type HostedFieldsAppearance } from \"./style\";\n\nexport interface ElementOptions {\n /** Iframe-safe input appearance. Container layout remains merchant-owned CSS. */\n appearance?: HostedFieldsAppearance;\n placeholder?: string;\n}\n\nexport type ElementEvent =\n | { type: \"ready\" }\n | {\n type: \"change\";\n isValid: boolean;\n isEmpty: boolean;\n isComplete: boolean;\n brand?: string;\n lastFour?: string;\n }\n | { type: \"error\"; reason: string };\n\ntype Listener = (event: ElementEvent) => void;\ntype ElementEventName = ElementEvent[\"type\"];\n\nconst FIELD_TITLES: Record<FieldType, string> = {\n cardNumber: \"Arc Pay card number\",\n cardExpiry: \"Arc Pay card expiration date\",\n cardCvv: \"Arc Pay card security code\",\n};\n\nexport interface ElementContext {\n iframeBase: string;\n publishableKey: string;\n channelId: string;\n}\n\nexport class Element {\n private iframe: HTMLIFrameElement | null = null;\n private readonly listeners: Record<ElementEventName, Set<Listener>> = {\n ready: new Set<Listener>(),\n change: new Set<Listener>(),\n error: new Set<Listener>(),\n };\n private status: \"pending\" | \"ready\" | \"error\" = \"pending\";\n private messageHandler: ((e: MessageEvent) => void) | null = null;\n\n constructor(\n public readonly field: FieldType,\n private readonly options: ElementOptions,\n private readonly context: ElementContext,\n ) {}\n\n mount(target: string | HTMLElement): void {\n if (this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"already_mounted\",\n message: `Element ${this.field} is already mounted`,\n retryable: false,\n });\n }\n const container = typeof target === \"string\" ? document.querySelector(target) : target;\n if (!(container instanceof HTMLElement)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"mount_target_not_found\",\n message: `mount target not found: ${String(target)}`,\n retryable: false,\n });\n }\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = `${this.context.iframeBase}/iframe/${this.field}`;\n iframe.style.cssText = \"border:0;width:100%;height:100%;display:block;\";\n iframe.setAttribute(\"allow\", \"payment\");\n iframe.setAttribute(\"data-arcpay-element\", this.field);\n iframe.setAttribute(\"title\", FIELD_TITLES[this.field]);\n iframe.setAttribute(\"aria-label\", FIELD_TITLES[this.field]);\n container.appendChild(iframe);\n this.iframe = iframe;\n\n const expectedOrigin = new URL(this.context.iframeBase).origin;\n\n this.messageHandler = (event: MessageEvent) => {\n // C1: source guard — only accept messages from this element's own iframe.\n // Without this, any iframe at the same origin (e.g. cardExpiry, cardCvv)\n // could trigger handlers on cardNumber and vice-versa.\n if (event.source !== this.iframe?.contentWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, expectedOrigin);\n if (!data) return;\n this.handleMessage(data);\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n iframe.addEventListener(\n \"load\",\n () => {\n if (!this.iframe) return;\n const hello: ParentToIframe = {\n type: \"arcpay:hello\",\n origin: window.location.origin,\n publishableKey: this.context.publishableKey,\n channelId: this.context.channelId,\n };\n postToIframe(this.iframe, hello, expectedOrigin);\n },\n { once: true },\n );\n }\n\n private handleMessage(data: IframeToParent): void {\n if (data.type === \"arcpay:ready\") {\n this.status = \"ready\";\n if (this.options.appearance) {\n this.send({\n type: \"arcpay:style\",\n payload: buildStyleFromAppearance(this.options.appearance),\n });\n }\n if (this.options.placeholder) {\n this.send({\n type: \"arcpay:placeholder\",\n field: this.field,\n placeholder: this.options.placeholder,\n });\n }\n this.emit({ type: \"ready\" });\n } else if (data.type === \"arcpay:rejected\") {\n this.status = \"error\";\n this.emit({ type: \"error\", reason: data.reason });\n } else if (data.type === \"arcpay:change\" && data.field === this.field) {\n this.emit({\n type: \"change\",\n isValid: data.isValid,\n isEmpty: data.isEmpty,\n isComplete: data.isComplete,\n brand: data.brand,\n lastFour: data.lastFour,\n });\n }\n // arcpay:tokenize-result / arcpay:tokenize-error handled by Elements factory (Task 9).\n }\n\n update(options: { appearance?: HostedFieldsAppearance; placeholder?: string }): void {\n if (options.appearance) {\n this.send({\n type: \"arcpay:style\",\n payload: buildStyleFromAppearance(options.appearance),\n });\n }\n if (options.placeholder) {\n this.send({\n type: \"arcpay:placeholder\",\n field: this.field,\n placeholder: options.placeholder,\n });\n }\n }\n\n destroy(): void {\n if (this.iframe) {\n this.iframe.remove();\n this.iframe = null;\n }\n if (this.messageHandler) {\n window.removeEventListener(\"message\", this.messageHandler);\n this.messageHandler = null;\n }\n for (const listeners of Object.values(this.listeners)) {\n listeners.clear();\n }\n this.status = \"pending\";\n }\n\n on(event: ElementEventName, callback: Listener): () => void {\n this.listeners[event].add(callback);\n return () => this.listeners[event].delete(callback);\n }\n\n focus(): void {\n this.send({ type: \"arcpay:focus\" });\n }\n\n clear(): void {\n this.send({ type: \"arcpay:clear\" });\n }\n\n isReady(): boolean {\n return this.status === \"ready\";\n }\n\n /**\n * Internal: returns the iframe's contentWindow for source-filtering in\n * Elements.doTokenize(). Returns null when the iframe is not yet mounted\n * or when jsdom has not yet populated contentWindow (test environment).\n */\n getIframeContentWindow(): Window | null {\n return this.iframe?.contentWindow ?? null;\n }\n\n /** Internal: used by Elements factory to send tokenize commands. */\n send(message: ParentToIframe): void {\n if (!this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"not_mounted\",\n message: `Element ${this.field} is not mounted`,\n retryable: false,\n });\n }\n postToIframe(this.iframe, message, new URL(this.context.iframeBase).origin);\n }\n\n private emit(event: ElementEvent): void {\n for (const listener of this.listeners[event.type]) {\n listener(event);\n }\n }\n}\n","import { ArcPayError } from \"../core/errors\";\nimport { Element, type ElementContext, type ElementOptions } from \"./element\";\nimport type { FieldType, IframeToParent } from \"./postmessage\";\nimport { parseIncoming } from \"./postmessage\";\nimport type { TokenizeResult } from \"../tokenize/tokenize\";\nimport type { HostedFieldsAppearance } from \"./style\";\n\nexport type {};\n\nexport interface ElementsOptions {\n /** Default iframe-safe input appearance applied to elements created by this factory. */\n appearance?: HostedFieldsAppearance;\n}\n\nconst DEFAULT_IFRAME_BASE = \"https://sdk.arcpay.space\";\n\nconst createChannelId = (): string => {\n if (!globalThis.crypto?.randomUUID) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"crypto_unavailable\",\n message: \"crypto.randomUUID is required for Hosted Fields\",\n retryable: false,\n });\n }\n return globalThis.crypto.randomUUID();\n};\n\nexport class Elements {\n private readonly elementMap = new Map<FieldType, Element>();\n private readonly iframeBase: string;\n private readonly publishableKey: string;\n private readonly channelId: string;\n private tokenizeInFlight = false;\n private readonly appearance?: HostedFieldsAppearance;\n\n constructor(opts: {\n publishableKey: string;\n iframeBase?: string;\n appearance?: HostedFieldsAppearance;\n }) {\n this.publishableKey = opts.publishableKey;\n this.iframeBase = opts.iframeBase ?? DEFAULT_IFRAME_BASE;\n this.channelId = createChannelId();\n this.appearance = opts.appearance;\n }\n\n create(field: FieldType, options: ElementOptions = {}): Element {\n if (this.elementMap.has(field)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"duplicate_element\",\n message: `Element for ${field} already created`,\n retryable: false,\n });\n }\n const ctx: ElementContext = {\n iframeBase: this.iframeBase,\n publishableKey: this.publishableKey,\n channelId: this.channelId,\n };\n const element = new Element(\n field,\n {\n ...options,\n appearance: options.appearance ?? this.appearance,\n },\n ctx,\n );\n this.elementMap.set(field, element);\n return element;\n }\n\n async tokenize(paymentId: string, idempotencyKey: string): Promise<TokenizeResult> {\n // C2: concurrent-call guard — only one tokenize() may be in-flight at a time.\n if (this.tokenizeInFlight) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"tokenize_in_progress\",\n message: \"A tokenize() call is already in progress for this Elements instance\",\n retryable: false,\n });\n }\n\n const cardNumber = this.elementMap.get(\"cardNumber\");\n const cardExpiry = this.elementMap.get(\"cardExpiry\");\n const cardCvv = this.elementMap.get(\"cardCvv\");\n\n if (!cardNumber || !cardExpiry || !cardCvv) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"incomplete_elements\",\n message:\n \"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()\",\n retryable: false,\n });\n }\n if (!cardNumber.isReady() || !cardExpiry.isReady() || !cardCvv.isReady()) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"elements_not_ready\",\n message: \"Wait for all elements to fire 'ready' event before tokenize()\",\n retryable: false,\n });\n }\n\n this.tokenizeInFlight = true;\n try {\n return await this.doTokenize(cardNumber, paymentId, idempotencyKey);\n } finally {\n this.tokenizeInFlight = false;\n }\n }\n\n private doTokenize(\n cardNumber: Element,\n paymentId: string,\n idempotencyKey: string,\n ): Promise<TokenizeResult> {\n const iframeOrigin = new URL(this.iframeBase).origin;\n // C1: obtain reference to the cardNumber iframe's contentWindow before\n // registering the listener so we can filter by source.\n const cardIframeWindow = cardNumber.getIframeContentWindow();\n\n return new Promise<TokenizeResult>((resolve, reject) => {\n // C3: 30-second timeout — rejects and cleans up if no result arrives.\n const timer = window.setTimeout(() => {\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type: \"network_error\",\n code: \"tokenize_timeout\",\n message: \"tokenize() timed out after 30 seconds\",\n retryable: true,\n paymentId,\n }),\n );\n }, 30_000);\n\n const onMessage = (event: MessageEvent) => {\n // C1: source guard — only accept messages from the cardNumber iframe.\n if (cardIframeWindow !== null && event.source !== cardIframeWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, iframeOrigin);\n if (!data) return;\n\n if (data.type === \"arcpay:tokenize-result\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n resolve({\n cardTokenId: data.cardTokenId,\n cardMask: data.cardMask,\n cardScheme: data.cardScheme,\n cardBin: data.cardBin,\n expiresIn: data.expiresIn,\n expiresAt: data.expiresAt,\n });\n } else if (data.type === \"arcpay:tokenize-error\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type:\n data.errorType === \"validation_error\" ||\n data.errorType === \"configuration_error\" ||\n data.errorType === \"network_error\" ||\n data.errorType === \"api_error\"\n ? data.errorType\n : \"api_error\",\n code: data.code,\n message: data.message,\n retryable: false,\n paymentId,\n }),\n );\n }\n };\n\n window.addEventListener(\"message\", onMessage);\n cardNumber.send({ type: \"arcpay:tokenize\", paymentId, idempotencyKey });\n });\n }\n\n destroy(): void {\n for (const el of this.elementMap.values()) {\n el.destroy();\n }\n this.elementMap.clear();\n }\n}\n","import {\n detectEnvironment,\n type Environment,\n validatePublishableKey as _validatePublishableKey,\n} from \"./env\";\nimport { showSandboxBanner } from \"./sandbox-banner\";\nimport { Elements, type ElementsOptions } from \"../elements/elements\";\n\nconst validatePublishableKey: (key: unknown) => asserts key is string = _validatePublishableKey;\n\nexport interface ArcPayLoadOptions {\n readonly _reserved?: never;\n}\n\nexport interface ArcPayInstance {\n readonly publishableKey: string;\n readonly environment: Environment;\n elements: (opts?: ElementsOptions) => Elements;\n}\n\nconst cache = new Map<string, Promise<ArcPayInstance>>();\n\nconst buildInstance = (publishableKey: string): ArcPayInstance => {\n if (detectEnvironment(publishableKey) === \"sandbox\") {\n showSandboxBanner();\n }\n return {\n publishableKey,\n environment: detectEnvironment(publishableKey),\n elements: (opts = {}) => new Elements({ publishableKey, ...opts }),\n };\n};\n\nfunction load(publishableKey: string): Promise<ArcPayInstance> {\n try {\n validatePublishableKey(publishableKey);\n } catch (err) {\n return Promise.reject(err);\n }\n const key = publishableKey;\n const existing = cache.get(key);\n if (existing) return existing;\n const promise = Promise.resolve(buildInstance(publishableKey));\n cache.set(key, promise);\n return promise;\n}\n\nconst resetForTests = (): void => {\n cache.clear();\n};\n\nexport const ArcPay = {\n load,\n __resetForTests: resetForTests,\n};\n","import type { CardBrowserInfo, ExecutePaymentResponse, PaymentNextAction } from \"../server/types\";\n\nexport type ThreeDSAction = PaymentNextAction;\nexport type BrowserInfo = CardBrowserInfo;\n\nexport interface BrowserFormField {\n name: string;\n value: string;\n}\n\nexport interface BrowserPostForm {\n action: string;\n method: \"POST\";\n target: \"hidden_iframe\" | \"browser\";\n fields: BrowserFormField[];\n}\n\nexport interface ThreeDSBrowserStep {\n kind: \"method\" | \"challenge\";\n protocolVersion: \"1\" | \"2\";\n form: BrowserPostForm;\n completionEndpoint?: string;\n threeDSServerTransId?: string;\n}\n\nexport interface MountedThreeDSForm {\n form: HTMLFormElement;\n iframe?: HTMLIFrameElement;\n submit: () => void;\n remove: () => void;\n}\n\nexport interface ThreeDSMountOptions {\n document?: Document;\n container?: HTMLElement;\n challengeTarget?: \"_self\";\n submitter?: (form: HTMLFormElement) => void;\n}\n\nexport interface RunThreeDSBrowserFlowOptions extends ThreeDSMountOptions {\n completeThreeDSMethod?: (\n completion: ReturnType<typeof buildThreeDSMethodCompletion>,\n nextAction: PaymentNextAction,\n ) => Promise<ExecutePaymentResponse>;\n methodCompletionIndicator?: \"Y\" | \"N\" | \"U\";\n methodTimeoutMs?: number;\n signal?: AbortSignal;\n}\n\nexport type ThreeDSBrowserFlowResult =\n | {\n status: \"no_action\";\n response?: ExecutePaymentResponse;\n }\n | {\n status: \"method_completed\";\n response: ExecutePaymentResponse;\n methodResult: \"loaded\" | \"timeout\";\n }\n | {\n status: \"challenge_submitted\";\n action: PaymentNextAction;\n response?: ExecutePaymentResponse;\n mounted: MountedThreeDSForm;\n methodResult?: \"loaded\" | \"timeout\";\n };\n\nconst supportedColorDepths = [1, 4, 8, 15, 16, 24, 32, 48] as const;\n\nconst normalizeColorDepth = (value: number): BrowserInfo[\"color_depth\"] =>\n supportedColorDepths.includes(value as BrowserInfo[\"color_depth\"])\n ? (value as BrowserInfo[\"color_depth\"])\n : 24;\n\nconst resolveWindowSize = (width: number): NonNullable<BrowserInfo[\"window_size\"]> => {\n if (width >= 1000) return \"05\";\n if (width >= 600) return \"04\";\n if (width >= 500) return \"03\";\n if (width >= 390) return \"02\";\n return \"01\";\n};\n\nexport const collectBrowserInfo = (\n acceptHeader = \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n): BrowserInfo => {\n if (\n typeof window === \"undefined\" ||\n typeof navigator === \"undefined\" ||\n typeof screen === \"undefined\"\n ) {\n throw new Error(\"collectBrowserInfo must be called in a browser environment\");\n }\n return {\n accept_header: acceptHeader,\n language: navigator.language || \"en\",\n screen_width: screen.width,\n screen_height: screen.height,\n color_depth: normalizeColorDepth(screen.colorDepth),\n timezone_offset_minutes: new Date().getTimezoneOffset(),\n java_enabled: false,\n user_agent: navigator.userAgent,\n window_size: resolveWindowSize(window.innerWidth || screen.width),\n };\n};\n\nexport const getThreeDSAction = (nextAction?: PaymentNextAction): PaymentNextAction | null => {\n return nextAction ?? null;\n};\n\nexport const isThreeDSMethodAction = (nextAction?: PaymentNextAction): boolean => {\n return nextAction?.type === \"three_ds_method\" && nextAction.three_ds.phase === \"method\";\n};\n\nexport const isThreeDSChallengeAction = (nextAction?: PaymentNextAction): boolean => {\n return nextAction?.type === \"three_ds_challenge\" && nextAction.three_ds.phase === \"challenge\";\n};\n\nexport const buildThreeDSBrowserForm = (nextAction: PaymentNextAction): BrowserPostForm => ({\n action: nextAction.three_ds.submit.url,\n method: nextAction.three_ds.submit.method,\n target: nextAction.three_ds.submit.target,\n fields: nextAction.three_ds.submit.fields,\n});\n\nconst assertHTTPSActionURL = (action: string): void => {\n let parsed: URL;\n try {\n parsed = new URL(action);\n } catch {\n throw new Error(\"3DS form action must be an absolute HTTPS URL\");\n }\n if (parsed.protocol !== \"https:\") {\n throw new Error(\"3DS form action must use HTTPS\");\n }\n};\n\nexport const buildThreeDSBrowserStep = (\n nextAction?: PaymentNextAction,\n): ThreeDSBrowserStep | null => {\n const action = getThreeDSAction(nextAction);\n if (!action) return null;\n return {\n kind: action.three_ds.phase,\n protocolVersion: action.three_ds.version,\n form: buildThreeDSBrowserForm(action),\n completionEndpoint: action.three_ds.completion_endpoint,\n threeDSServerTransId: action.three_ds.three_ds_server_trans_id,\n };\n};\n\nexport const buildThreeDSMethodCompletion = (\n nextAction: PaymentNextAction,\n completionIndicator: \"Y\" | \"N\" | \"U\" = \"Y\",\n): { completion_indicator: \"Y\" | \"N\" | \"U\"; three_ds_server_trans_id: string } => {\n if (!isThreeDSMethodAction(nextAction) || !nextAction.three_ds.three_ds_server_trans_id) {\n throw new Error(\"nextAction must be a three_ds_method action with three_ds_server_trans_id\");\n }\n return {\n completion_indicator: completionIndicator,\n three_ds_server_trans_id: nextAction.three_ds.three_ds_server_trans_id,\n };\n};\n\nconst requireDocument = (explicitDocument?: Document): Document => {\n if (explicitDocument) return explicitDocument;\n if (typeof document === \"undefined\") {\n throw new Error(\"3DS browser helpers must be called in a browser environment\");\n }\n return document;\n};\n\nconst defaultSubmitter = (form: HTMLFormElement): void => {\n form.submit();\n};\n\nexport const mountThreeDSBrowserForm = (\n nextAction: PaymentNextAction,\n options: ThreeDSMountOptions = {},\n): MountedThreeDSForm => {\n const doc = requireDocument(options.document);\n const container = options.container ?? doc.body;\n const formDescriptor = buildThreeDSBrowserForm(nextAction);\n assertHTTPSActionURL(formDescriptor.action);\n const form = doc.createElement(\"form\");\n const target =\n formDescriptor.target === \"hidden_iframe\"\n ? `arcpay-three-ds-method-${crypto.randomUUID()}`\n : (options.challengeTarget ?? \"_self\");\n let iframe: HTMLIFrameElement | undefined;\n\n form.method = formDescriptor.method;\n form.action = formDescriptor.action;\n form.target = target;\n form.hidden = true;\n\n for (const field of formDescriptor.fields) {\n const input = doc.createElement(\"input\");\n input.type = \"hidden\";\n input.name = field.name;\n input.value = field.value;\n form.append(input);\n }\n\n if (formDescriptor.target === \"hidden_iframe\") {\n iframe = doc.createElement(\"iframe\");\n iframe.name = target;\n iframe.title = \"3-D Secure method\";\n iframe.hidden = true;\n container.append(iframe);\n }\n\n container.append(form);\n\n return {\n form,\n iframe,\n submit: () => (options.submitter ?? defaultSubmitter)(form),\n remove: () => {\n form.remove();\n iframe?.remove();\n },\n };\n};\n\nconst waitForMethodFrame = (\n mounted: MountedThreeDSForm,\n timeoutMs: number,\n signal?: AbortSignal,\n): Promise<\"loaded\" | \"timeout\"> =>\n new Promise((resolve, reject) => {\n if (!mounted.iframe) {\n resolve(\"loaded\");\n return;\n }\n if (signal?.aborted) {\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n return;\n }\n\n let settled = false;\n const cleanup = () => {\n mounted.iframe?.removeEventListener(\"load\", onLoad);\n signal?.removeEventListener(\"abort\", onAbort);\n clearTimeout(timer);\n };\n const settle = (result: \"loaded\" | \"timeout\") => {\n if (settled) return;\n settled = true;\n cleanup();\n resolve(result);\n };\n const onLoad = () => settle(\"loaded\");\n const onAbort = () => {\n if (settled) return;\n settled = true;\n cleanup();\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n };\n const timer = setTimeout(() => settle(\"timeout\"), timeoutMs);\n\n mounted.iframe.addEventListener(\"load\", onLoad, { once: true });\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n\nexport const runThreeDSBrowserFlow = async (\n nextAction: PaymentNextAction | undefined,\n options: RunThreeDSBrowserFlowOptions,\n): Promise<ThreeDSBrowserFlowResult> => {\n if (!nextAction) return { status: \"no_action\" };\n\n if (isThreeDSChallengeAction(nextAction)) {\n const mounted = mountThreeDSBrowserForm(nextAction, options);\n mounted.submit();\n return { status: \"challenge_submitted\", action: nextAction, mounted };\n }\n\n if (!isThreeDSMethodAction(nextAction)) return { status: \"no_action\" };\n const completeThreeDSMethod = options.completeThreeDSMethod;\n if (!completeThreeDSMethod) {\n throw new Error(\"completeThreeDSMethod is required for 3DS Method actions\");\n }\n\n const mounted = mountThreeDSBrowserForm(nextAction, options);\n try {\n mounted.submit();\n const methodResult = await waitForMethodFrame(\n mounted,\n options.methodTimeoutMs ?? 10_000,\n options.signal,\n );\n const indicator = options.methodCompletionIndicator ?? (methodResult === \"loaded\" ? \"Y\" : \"N\");\n const response = await completeThreeDSMethod(\n buildThreeDSMethodCompletion(nextAction, indicator),\n nextAction,\n );\n const followUpAction = getThreeDSAction(response.next_action);\n if (followUpAction && isThreeDSChallengeAction(followUpAction)) {\n const challengeMounted = mountThreeDSBrowserForm(followUpAction, options);\n challengeMounted.submit();\n return {\n status: \"challenge_submitted\",\n action: followUpAction,\n response,\n mounted: challengeMounted,\n methodResult,\n };\n }\n return { status: \"method_completed\", response, methodResult };\n } finally {\n mounted.remove();\n }\n};\n\nconst htmlEscape = (value: string): string =>\n value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n\nexport const buildThreeDSAutoSubmitHtml = (nextAction: PaymentNextAction): string => {\n const form = buildThreeDSBrowserForm(nextAction);\n assertHTTPSActionURL(form.action);\n const target = form.target === \"hidden_iframe\" ? \"arcpay-three-ds-method\" : \"_self\";\n const inputs = form.fields\n .map(\n (field) =>\n `<input type=\"hidden\" name=\"${htmlEscape(field.name)}\" value=\"${htmlEscape(field.value)}\">`,\n )\n .join(\"\");\n const iframe =\n form.target === \"hidden_iframe\"\n ? '<iframe name=\"arcpay-three-ds-method\" title=\"3-D Secure method\" hidden></iframe>'\n : \"\";\n return `<!doctype html><html><head><meta charset=\"utf-8\"></head><body>${iframe}<form method=\"POST\" action=\"${htmlEscape(form.action)}\" target=\"${target}\">${inputs}</form><script>document.forms[0].submit();</script></body></html>`;\n};\n","export { ArcPay } from \"./core/arcpay\";\nexport type { ArcPayInstance, ArcPayLoadOptions } from \"./core/arcpay\";\nexport {\n ArcPayError,\n isValidationError,\n isAuthenticationError,\n isAuthorizationError,\n isStateError,\n isRateLimitError,\n isApiError,\n isNetworkError,\n isChallengeAborted,\n} from \"./core/errors\";\nexport type { ArcPayErrorType } from \"./core/errors\";\nexport type { Environment } from \"./core/env\";\nexport type { TokenizeResult } from \"./tokenize/tokenize\";\nexport type { CardScheme } from \"./tokenize/scheme\";\nexport {\n buildThreeDSAutoSubmitHtml,\n buildThreeDSBrowserForm,\n buildThreeDSBrowserStep,\n buildThreeDSMethodCompletion,\n collectBrowserInfo,\n getThreeDSAction,\n isThreeDSChallengeAction,\n isThreeDSMethodAction,\n mountThreeDSBrowserForm,\n runThreeDSBrowserFlow,\n} from \"./three-ds\";\nexport type {\n BrowserFormField,\n BrowserInfo,\n BrowserPostForm,\n MountedThreeDSForm,\n RunThreeDSBrowserFlowOptions,\n ThreeDSAction,\n ThreeDSBrowserStep,\n ThreeDSBrowserFlowResult,\n ThreeDSMountOptions,\n} from \"./three-ds\";\nexport const SDK_VERSION = \"0.1.25\";\n\nexport type { FieldType } from \"./elements/postmessage\";\nexport type { ElementOptions, ElementEvent } from \"./elements/element\";\nexport { Elements } from \"./elements/elements\";\nexport type { ElementsOptions } from \"./elements/elements\";\nexport type {\n HostedFieldsAppearance,\n HostedFieldsAppearanceRule,\n HostedFieldsAppearanceVariables,\n HostedFieldsTheme,\n} from \"./elements/style\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/core/env.ts","../../src/core/sandbox-banner.ts","../../src/elements/postmessage.ts","../../src/elements/style.ts","../../src/elements/element.ts","../../src/elements/elements.ts","../../src/core/arcpay.ts","../../src/three-ds/actions.ts","../../src/index.ts"],"names":["ArcPayError","init","isValidationError","isAuthenticationError","isAuthorizationError","isStateError","isRateLimitError","isApiError","isNetworkError","isChallengeAborted","detectEnvironment","publishableKey","validatePublishableKey","key","BANNER_ATTR","showSandboxBanner","bar","text","dismiss","ARCPAY_TYPE_PREFIX","isArcpayMessage","data","postToIframe","iframe","message","targetOrigin","parseIncoming","event","expectedOrigin","ALLOWED_PROPERTIES","ARCPAY_THEME","mergeBlock","target","source","setIfPresent","block","value","assertKnownTheme","theme","sanitizeBlock","out","normalizedKey","sanitizeStyle","style","result","buildStyleFromAppearance","appearance","_a","themeStyle","variableStyle","variables","rules","combined","focus","invalid","complete","empty","FIELD_TITLES","Element","field","options","context","container","hello","listeners","callback","_b","listener","DEFAULT_IFRAME_BASE","createChannelId","Elements","opts","ctx","element","paymentId","idempotencyKey","cardNumber","cardExpiry","cardCvv","iframeOrigin","cardIframeWindow","resolve","reject","timer","onMessage","el","cache","buildInstance","load","err","existing","promise","resetForTests","ArcPay","supportedColorDepths","normalizeColorDepth","resolveWindowSize","width","collectBrowserInfo","acceptHeader","getThreeDSAction","nextAction","isThreeDSMethodAction","isThreeDSChallengeAction","buildThreeDSBrowserForm","assertHTTPSActionURL","action","parsed","e","buildThreeDSBrowserStep","buildThreeDSMethodCompletion","completionIndicator","requireDocument","explicitDocument","defaultSubmitter","form","mountThreeDSBrowserForm","doc","formDescriptor","input","waitForMethodFrame","mounted","timeoutMs","signal","settled","cleanup","onLoad","onAbort","settle","runThreeDSBrowserFlow","completeThreeDSMethod","methodResult","indicator","response","followUpAction","challengeMounted","htmlEscape","buildThreeDSAutoSubmitHtml","inputs","SDK_VERSION"],"mappings":"2CAsBO,IAAMA,EAAN,cAA0B,KAAM,CASrC,WAAA,CAAYC,EAAuB,CACjC,KAAA,CAAMA,CAAAA,CAAK,OAAO,EAClB,IAAA,CAAK,IAAA,CAAO,aAAA,CACZ,IAAA,CAAK,KAAOA,CAAAA,CAAK,IAAA,CACjB,IAAA,CAAK,IAAA,CAAOA,EAAK,IAAA,CACjB,IAAA,CAAK,KAAA,CAAQA,CAAAA,CAAK,MAClB,IAAA,CAAK,SAAA,CAAYA,CAAAA,CAAK,SAAA,CACtB,KAAK,WAAA,CAAcA,CAAAA,CAAK,YACxB,IAAA,CAAK,SAAA,CAAYA,EAAK,SAAA,CACtB,IAAA,CAAK,SAAA,CAAYA,CAAAA,CAAK,UACxB,CACF,CAAA,CAEaC,CAAAA,CAAqB,CAAA,EAChC,aAAaF,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,uBAG5BG,CAAAA,CAAyB,CAAA,EACpC,CAAA,YAAaH,CAAAA,EAAe,EAAE,IAAA,GAAS,sBAAA,CAC5BI,CAAAA,CAAwB,CAAA,EACnC,aAAaJ,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,qBAAA,CAC5BK,EAAgB,CAAA,EAC3B,CAAA,YAAaL,CAAAA,EAAe,CAAA,CAAE,OAAS,aAAA,CAC5BM,CAAAA,CAAoB,GAC/B,CAAA,YAAaN,CAAAA,EAAe,EAAE,IAAA,GAAS,kBAAA,CAC5BO,CAAAA,CAAc,CAAA,EACzB,aAAaP,CAAAA,EAAe,CAAA,CAAE,IAAA,GAAS,WAAA,CAC5BQ,EAAkB,CAAA,EAC7B,CAAA,YAAaR,CAAAA,EAAe,CAAA,CAAE,OAAS,eAAA,CAC5BS,CAAAA,CAAsB,CAAA,EACjC,CAAA,YA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C,EAAAA,CAAc","file":"arcpay.global.js","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"configuration_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\ninterface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nconst isConfigurationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"configuration_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError } from \"./errors\";\n\nexport type Environment = \"sandbox\" | \"live\";\n\nexport const detectEnvironment = (publishableKey: string): Environment =>\n publishableKey.startsWith(\"pk_test_\") ? \"sandbox\" : \"live\";\n\nexport const validatePublishableKey = (key: unknown): asserts key is string => {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message: \"Publishable key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"pk_test_\") && !key.startsWith(\"pk_live_\")) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_publishable_key\",\n message:\n \"Publishable key must start with pk_test_ or pk_live_. Secret keys (sk_*) cannot be used in browser.\",\n retryable: false,\n });\n }\n};\n","const BANNER_ATTR = \"data-arcpay-sandbox-banner\";\n\nexport const showSandboxBanner = (): void => {\n if (typeof document === \"undefined\") return;\n if (document.querySelector(`[${BANNER_ATTR}]`)) return;\n\n const bar = document.createElement(\"div\");\n bar.setAttribute(BANNER_ATTR, \"\");\n bar.style.cssText =\n \"position:fixed;top:0;left:0;right:0;z-index:2147483647;background:#ffd166;color:#222;font:13px/1.4 system-ui,sans-serif;padding:6px 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,0.1);\";\n\n const text = document.createElement(\"span\");\n text.textContent = \"ARC PAY TEST MODE — payments are simulated\";\n bar.appendChild(text);\n\n const dismiss = document.createElement(\"button\");\n dismiss.type = \"button\";\n dismiss.setAttribute(\"data-arcpay-banner-dismiss\", \"\");\n dismiss.textContent = \"×\";\n dismiss.setAttribute(\"aria-label\", \"Dismiss test mode banner\");\n dismiss.style.cssText =\n \"margin-left:12px;background:transparent;border:0;font-size:18px;cursor:pointer;color:inherit;\";\n dismiss.addEventListener(\"click\", () => bar.remove());\n bar.appendChild(dismiss);\n\n document.body.appendChild(bar);\n};\n","import { ArcPayError } from \"../core/errors\";\n\nexport type FieldType = \"cardNumber\" | \"cardExpiry\" | \"cardCvv\";\n\n// Parent → iframe\nexport type ParentToIframe =\n | { type: \"arcpay:hello\"; origin: string; publishableKey: string; channelId: string }\n | { type: \"arcpay:style\"; payload: StyleSubset }\n | { type: \"arcpay:placeholder\"; field: FieldType; placeholder: string }\n | { type: \"arcpay:focus\" }\n | { type: \"arcpay:clear\" }\n | { type: \"arcpay:tokenize\"; paymentId: string; idempotencyKey: string };\n\n// iframe → parent\nexport type IframeToParent =\n | { type: \"arcpay:ready\" }\n | { type: \"arcpay:rejected\"; reason: string }\n | {\n type: \"arcpay:change\";\n field: FieldType;\n isValid: boolean;\n isEmpty: boolean;\n isComplete: boolean;\n brand?: string;\n lastFour?: string;\n }\n | {\n type: \"arcpay:tokenize-result\";\n cardTokenId: string;\n cardMask: string;\n cardScheme: string;\n cardBin: string;\n expiresIn: number;\n expiresAt: string;\n }\n | { type: \"arcpay:tokenize-error\"; errorType: string; code?: string; message: string };\n\nexport interface StyleSubset {\n base: Record<string, string>;\n invalid?: Record<string, string>;\n focus?: Record<string, string>;\n complete?: Record<string, string>;\n empty?: Record<string, string>;\n}\n\ntype TokenizeErrorType = \"validation_error\" | \"configuration_error\" | \"network_error\" | \"api_error\";\n\nconst ARCPAY_TYPE_PREFIX = \"arcpay:\";\n\nconst isArcpayMessage = (data: unknown): data is { type: string } =>\n typeof data === \"object\" &&\n data !== null &&\n \"type\" in data &&\n typeof (data as { type: unknown }).type === \"string\" &&\n (data as { type: string }).type.startsWith(ARCPAY_TYPE_PREFIX);\n\nexport const postToIframe = (\n iframe: HTMLIFrameElement,\n message: ParentToIframe,\n targetOrigin: string,\n): void => {\n if (targetOrigin === \"*\") {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"wildcard_origin_forbidden\",\n message: \"postToIframe: targetOrigin cannot be '*'\",\n retryable: false,\n });\n }\n if (!iframe.contentWindow) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"iframe_not_loaded\",\n message: \"postToIframe: iframe.contentWindow is null (iframe not mounted)\",\n retryable: false,\n });\n }\n iframe.contentWindow.postMessage(message, targetOrigin);\n};\n\nexport const postToParent = (message: IframeToParent, targetOrigin: string): void => {\n if (targetOrigin === \"*\") {\n throw new Error(\"postToParent: targetOrigin cannot be '*'\");\n }\n window.parent.postMessage(message, targetOrigin);\n};\n\nexport const parseIncoming = <T extends { type: string }>(\n event: MessageEvent,\n expectedOrigin: string,\n): T | null => {\n if (event.origin !== expectedOrigin) return null;\n if (!isArcpayMessage(event.data)) return null;\n return event.data as T;\n};\n","import type { StyleSubset } from \"./postmessage\";\nimport { ArcPayError } from \"../core/errors\";\n\nexport type HostedFieldsTheme = \"none\" | \"arcpay\";\n\nexport interface HostedFieldsAppearanceVariables {\n fontFamily?: string;\n fontSize?: string;\n fontWeight?: string;\n fontStyle?: string;\n lineHeight?: string;\n letterSpacing?: string;\n textAlign?: string;\n colorText?: string;\n colorPlaceholder?: string;\n colorDanger?: string;\n colorSuccess?: string;\n colorBackground?: string;\n caretColor?: string;\n}\n\nexport type HostedFieldsAppearanceRule = \"base\" | \"focus\" | \"invalid\" | \"complete\" | \"empty\";\n\nexport interface HostedFieldsAppearance {\n theme?: HostedFieldsTheme;\n variables?: HostedFieldsAppearanceVariables;\n rules?: Partial<Record<HostedFieldsAppearanceRule, Record<string, string>>>;\n}\n\nconst ALLOWED_PROPERTIES = new Set([\n \"--arcpay-placeholder-color\",\n \"background-color\",\n \"caret-color\",\n \"color\",\n \"font-family\",\n \"font-size\",\n \"font-style\",\n \"font-weight\",\n \"letter-spacing\",\n \"line-height\",\n \"opacity\",\n \"text-align\",\n \"text-decoration\",\n \"text-transform\",\n]);\n\nconst ARCPAY_THEME: StyleSubset = {\n base: {\n \"font-family\":\n 'Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n \"font-size\": \"16px\",\n \"line-height\": \"24px\",\n color: \"#111827\",\n \"--arcpay-placeholder-color\": \"#9ca3af\",\n \"caret-color\": \"#111827\",\n },\n focus: {\n color: \"#111827\",\n },\n invalid: {\n color: \"#dc2626\",\n },\n complete: {\n color: \"#111827\",\n },\n empty: {\n color: \"#111827\",\n },\n};\n\nconst mergeBlock = (\n target: Record<string, string> | undefined,\n source: Record<string, string> | undefined,\n): Record<string, string> | undefined => {\n if (!target && !source) return undefined;\n return { ...(target ?? {}), ...(source ?? {}) };\n};\n\nconst setIfPresent = (\n block: Record<string, string>,\n key: string,\n value: string | undefined,\n): void => {\n if (value !== undefined) block[key] = value;\n};\n\nconst assertKnownTheme = (theme: HostedFieldsTheme | undefined): void => {\n if (theme === undefined || theme === \"none\" || theme === \"arcpay\") return;\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_hosted_fields_theme\",\n message: `Unsupported Hosted Fields appearance theme: ${String(theme)}`,\n retryable: false,\n });\n};\n\nconst sanitizeBlock = (block: Record<string, string>): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(block)) {\n const normalizedKey = key.toLowerCase();\n if (!ALLOWED_PROPERTIES.has(normalizedKey)) {\n continue;\n }\n out[normalizedKey] = value;\n }\n return out;\n};\n\nexport const sanitizeStyle = (style: StyleSubset): StyleSubset => {\n const result: StyleSubset = { base: sanitizeBlock(style.base) };\n if (style.invalid !== undefined) result.invalid = sanitizeBlock(style.invalid);\n if (style.focus !== undefined) result.focus = sanitizeBlock(style.focus);\n if (style.complete !== undefined) result.complete = sanitizeBlock(style.complete);\n if (style.empty !== undefined) result.empty = sanitizeBlock(style.empty);\n return result;\n};\n\nexport const buildStyleFromAppearance = (appearance?: HostedFieldsAppearance): StyleSubset => {\n assertKnownTheme(appearance?.theme);\n const themeStyle: StyleSubset = appearance?.theme === \"arcpay\" ? ARCPAY_THEME : { base: {} };\n const variableStyle: StyleSubset = { base: {} };\n const variables = appearance?.variables;\n\n if (variables) {\n setIfPresent(variableStyle.base, \"font-family\", variables.fontFamily);\n setIfPresent(variableStyle.base, \"font-size\", variables.fontSize);\n setIfPresent(variableStyle.base, \"font-weight\", variables.fontWeight);\n setIfPresent(variableStyle.base, \"font-style\", variables.fontStyle);\n setIfPresent(variableStyle.base, \"line-height\", variables.lineHeight);\n setIfPresent(variableStyle.base, \"letter-spacing\", variables.letterSpacing);\n setIfPresent(variableStyle.base, \"text-align\", variables.textAlign);\n setIfPresent(variableStyle.base, \"color\", variables.colorText);\n setIfPresent(variableStyle.base, \"--arcpay-placeholder-color\", variables.colorPlaceholder);\n setIfPresent(variableStyle.base, \"background-color\", variables.colorBackground);\n setIfPresent(variableStyle.base, \"caret-color\", variables.caretColor);\n\n if (variables.colorDanger !== undefined) {\n variableStyle.invalid = { color: variables.colorDanger };\n }\n if (variables.colorSuccess !== undefined) {\n variableStyle.complete = { color: variables.colorSuccess };\n }\n }\n\n const rules = appearance?.rules;\n const combined: StyleSubset = {\n base: {\n ...themeStyle.base,\n ...variableStyle.base,\n ...(rules?.base ?? {}),\n },\n };\n\n const focus = mergeBlock(mergeBlock(themeStyle.focus, variableStyle.focus), rules?.focus);\n const invalid = mergeBlock(mergeBlock(themeStyle.invalid, variableStyle.invalid), rules?.invalid);\n const complete = mergeBlock(\n mergeBlock(themeStyle.complete, variableStyle.complete),\n rules?.complete,\n );\n const empty = mergeBlock(mergeBlock(themeStyle.empty, variableStyle.empty), rules?.empty);\n\n if (focus !== undefined) combined.focus = focus;\n if (invalid !== undefined) combined.invalid = invalid;\n if (complete !== undefined) combined.complete = complete;\n if (empty !== undefined) combined.empty = empty;\n\n return sanitizeStyle(combined);\n};\n","import { ArcPayError } from \"../core/errors\";\nimport {\n type FieldType,\n type ParentToIframe,\n type IframeToParent,\n postToIframe,\n parseIncoming,\n} from \"./postmessage\";\nimport { buildStyleFromAppearance, type HostedFieldsAppearance } from \"./style\";\n\nexport interface ElementOptions {\n /** Iframe-safe input appearance. Container layout remains merchant-owned CSS. */\n appearance?: HostedFieldsAppearance;\n placeholder?: string;\n}\n\nexport type ElementEvent =\n | { type: \"ready\" }\n | {\n type: \"change\";\n isValid: boolean;\n isEmpty: boolean;\n isComplete: boolean;\n brand?: string;\n lastFour?: string;\n }\n | { type: \"error\"; reason: string };\n\ntype Listener = (event: ElementEvent) => void;\ntype ElementEventName = ElementEvent[\"type\"];\n\nconst FIELD_TITLES: Record<FieldType, string> = {\n cardNumber: \"Arc Pay card number\",\n cardExpiry: \"Arc Pay card expiration date\",\n cardCvv: \"Arc Pay card security code\",\n};\n\nexport interface ElementContext {\n iframeBase: string;\n publishableKey: string;\n channelId: string;\n}\n\nexport class Element {\n private iframe: HTMLIFrameElement | null = null;\n private readonly listeners: Record<ElementEventName, Set<Listener>> = {\n ready: new Set<Listener>(),\n change: new Set<Listener>(),\n error: new Set<Listener>(),\n };\n private status: \"pending\" | \"ready\" | \"error\" = \"pending\";\n private messageHandler: ((e: MessageEvent) => void) | null = null;\n\n constructor(\n public readonly field: FieldType,\n private readonly options: ElementOptions,\n private readonly context: ElementContext,\n ) {}\n\n mount(target: string | HTMLElement): void {\n if (this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"already_mounted\",\n message: `Element ${this.field} is already mounted`,\n retryable: false,\n });\n }\n const container = typeof target === \"string\" ? document.querySelector(target) : target;\n if (!(container instanceof HTMLElement)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"mount_target_not_found\",\n message: `mount target not found: ${String(target)}`,\n retryable: false,\n });\n }\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = `${this.context.iframeBase}/iframe/${this.field}`;\n iframe.style.cssText = \"border:0;width:100%;height:100%;display:block;\";\n iframe.setAttribute(\"allow\", \"payment\");\n iframe.setAttribute(\"data-arcpay-element\", this.field);\n iframe.setAttribute(\"title\", FIELD_TITLES[this.field]);\n iframe.setAttribute(\"aria-label\", FIELD_TITLES[this.field]);\n container.appendChild(iframe);\n this.iframe = iframe;\n\n const expectedOrigin = new URL(this.context.iframeBase).origin;\n\n this.messageHandler = (event: MessageEvent) => {\n // C1: source guard — only accept messages from this element's own iframe.\n // Without this, any iframe at the same origin (e.g. cardExpiry, cardCvv)\n // could trigger handlers on cardNumber and vice-versa.\n if (event.source !== this.iframe?.contentWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, expectedOrigin);\n if (!data) return;\n this.handleMessage(data);\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n iframe.addEventListener(\n \"load\",\n () => {\n if (!this.iframe) return;\n const hello: ParentToIframe = {\n type: \"arcpay:hello\",\n origin: window.location.origin,\n publishableKey: this.context.publishableKey,\n channelId: this.context.channelId,\n };\n postToIframe(this.iframe, hello, expectedOrigin);\n },\n { once: true },\n );\n }\n\n private handleMessage(data: IframeToParent): void {\n if (data.type === \"arcpay:ready\") {\n this.status = \"ready\";\n if (this.options.appearance) {\n this.send({\n type: \"arcpay:style\",\n payload: buildStyleFromAppearance(this.options.appearance),\n });\n }\n if (this.options.placeholder) {\n this.send({\n type: \"arcpay:placeholder\",\n field: this.field,\n placeholder: this.options.placeholder,\n });\n }\n this.emit({ type: \"ready\" });\n } else if (data.type === \"arcpay:rejected\") {\n this.status = \"error\";\n this.emit({ type: \"error\", reason: data.reason });\n } else if (data.type === \"arcpay:change\" && data.field === this.field) {\n this.emit({\n type: \"change\",\n isValid: data.isValid,\n isEmpty: data.isEmpty,\n isComplete: data.isComplete,\n brand: data.brand,\n lastFour: data.lastFour,\n });\n }\n // arcpay:tokenize-result / arcpay:tokenize-error handled by Elements factory (Task 9).\n }\n\n update(options: { appearance?: HostedFieldsAppearance; placeholder?: string }): void {\n if (options.appearance) {\n this.send({\n type: \"arcpay:style\",\n payload: buildStyleFromAppearance(options.appearance),\n });\n }\n if (options.placeholder) {\n this.send({\n type: \"arcpay:placeholder\",\n field: this.field,\n placeholder: options.placeholder,\n });\n }\n }\n\n destroy(): void {\n if (this.iframe) {\n this.iframe.remove();\n this.iframe = null;\n }\n if (this.messageHandler) {\n window.removeEventListener(\"message\", this.messageHandler);\n this.messageHandler = null;\n }\n for (const listeners of Object.values(this.listeners)) {\n listeners.clear();\n }\n this.status = \"pending\";\n }\n\n on(event: ElementEventName, callback: Listener): () => void {\n this.listeners[event].add(callback);\n return () => this.listeners[event].delete(callback);\n }\n\n focus(): void {\n this.send({ type: \"arcpay:focus\" });\n }\n\n clear(): void {\n this.send({ type: \"arcpay:clear\" });\n }\n\n isReady(): boolean {\n return this.status === \"ready\";\n }\n\n /**\n * Internal: returns the iframe's contentWindow for source-filtering in\n * Elements.doTokenize(). Returns null when the iframe is not yet mounted\n * or when jsdom has not yet populated contentWindow (test environment).\n */\n getIframeContentWindow(): Window | null {\n return this.iframe?.contentWindow ?? null;\n }\n\n /** Internal: used by Elements factory to send tokenize commands. */\n send(message: ParentToIframe): void {\n if (!this.iframe) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"not_mounted\",\n message: `Element ${this.field} is not mounted`,\n retryable: false,\n });\n }\n postToIframe(this.iframe, message, new URL(this.context.iframeBase).origin);\n }\n\n private emit(event: ElementEvent): void {\n for (const listener of this.listeners[event.type]) {\n listener(event);\n }\n }\n}\n","import { ArcPayError } from \"../core/errors\";\nimport { Element, type ElementContext, type ElementOptions } from \"./element\";\nimport type { FieldType, IframeToParent } from \"./postmessage\";\nimport { parseIncoming } from \"./postmessage\";\nimport type { TokenizeResult } from \"../tokenize/tokenize\";\nimport type { HostedFieldsAppearance } from \"./style\";\n\nexport type {};\n\nexport interface ElementsOptions {\n /** Default iframe-safe input appearance applied to elements created by this factory. */\n appearance?: HostedFieldsAppearance;\n}\n\nconst DEFAULT_IFRAME_BASE = \"https://sdk.arcpay.space\";\n\nconst createChannelId = (): string => {\n if (!globalThis.crypto?.randomUUID) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"crypto_unavailable\",\n message: \"crypto.randomUUID is required for Hosted Fields\",\n retryable: false,\n });\n }\n return globalThis.crypto.randomUUID();\n};\n\nexport class Elements {\n private readonly elementMap = new Map<FieldType, Element>();\n private readonly iframeBase: string;\n private readonly publishableKey: string;\n private readonly channelId: string;\n private tokenizeInFlight = false;\n private readonly appearance?: HostedFieldsAppearance;\n\n constructor(opts: {\n publishableKey: string;\n iframeBase?: string;\n appearance?: HostedFieldsAppearance;\n }) {\n this.publishableKey = opts.publishableKey;\n this.iframeBase = opts.iframeBase ?? DEFAULT_IFRAME_BASE;\n this.channelId = createChannelId();\n this.appearance = opts.appearance;\n }\n\n create(field: FieldType, options: ElementOptions = {}): Element {\n if (this.elementMap.has(field)) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"duplicate_element\",\n message: `Element for ${field} already created`,\n retryable: false,\n });\n }\n const ctx: ElementContext = {\n iframeBase: this.iframeBase,\n publishableKey: this.publishableKey,\n channelId: this.channelId,\n };\n const element = new Element(\n field,\n {\n ...options,\n appearance: options.appearance ?? this.appearance,\n },\n ctx,\n );\n this.elementMap.set(field, element);\n return element;\n }\n\n async tokenize(paymentId: string, idempotencyKey: string): Promise<TokenizeResult> {\n // C2: concurrent-call guard — only one tokenize() may be in-flight at a time.\n if (this.tokenizeInFlight) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"tokenize_in_progress\",\n message: \"A tokenize() call is already in progress for this Elements instance\",\n retryable: false,\n });\n }\n\n const cardNumber = this.elementMap.get(\"cardNumber\");\n const cardExpiry = this.elementMap.get(\"cardExpiry\");\n const cardCvv = this.elementMap.get(\"cardCvv\");\n\n if (!cardNumber || !cardExpiry || !cardCvv) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"incomplete_elements\",\n message:\n \"All three elements (cardNumber, cardExpiry, cardCvv) must be created and mounted before tokenize()\",\n retryable: false,\n });\n }\n if (!cardNumber.isReady() || !cardExpiry.isReady() || !cardCvv.isReady()) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"elements_not_ready\",\n message: \"Wait for all elements to fire 'ready' event before tokenize()\",\n retryable: false,\n });\n }\n\n this.tokenizeInFlight = true;\n try {\n return await this.doTokenize(cardNumber, paymentId, idempotencyKey);\n } finally {\n this.tokenizeInFlight = false;\n }\n }\n\n private doTokenize(\n cardNumber: Element,\n paymentId: string,\n idempotencyKey: string,\n ): Promise<TokenizeResult> {\n const iframeOrigin = new URL(this.iframeBase).origin;\n // C1: obtain reference to the cardNumber iframe's contentWindow before\n // registering the listener so we can filter by source.\n const cardIframeWindow = cardNumber.getIframeContentWindow();\n\n return new Promise<TokenizeResult>((resolve, reject) => {\n // C3: 30-second timeout — rejects and cleans up if no result arrives.\n const timer = window.setTimeout(() => {\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type: \"network_error\",\n code: \"tokenize_timeout\",\n message: \"tokenize() timed out after 30 seconds\",\n retryable: true,\n paymentId,\n }),\n );\n }, 30_000);\n\n const onMessage = (event: MessageEvent) => {\n // C1: source guard — only accept messages from the cardNumber iframe.\n if (cardIframeWindow !== null && event.source !== cardIframeWindow) return;\n // C4: use parseIncoming for origin + arcpay: prefix guard.\n const data = parseIncoming<IframeToParent>(event, iframeOrigin);\n if (!data) return;\n\n if (data.type === \"arcpay:tokenize-result\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n resolve({\n cardTokenId: data.cardTokenId,\n cardMask: data.cardMask,\n cardScheme: data.cardScheme,\n cardBin: data.cardBin,\n expiresIn: data.expiresIn,\n expiresAt: data.expiresAt,\n });\n } else if (data.type === \"arcpay:tokenize-error\") {\n clearTimeout(timer);\n window.removeEventListener(\"message\", onMessage);\n reject(\n new ArcPayError({\n type:\n data.errorType === \"validation_error\" ||\n data.errorType === \"configuration_error\" ||\n data.errorType === \"network_error\" ||\n data.errorType === \"api_error\"\n ? data.errorType\n : \"api_error\",\n code: data.code,\n message: data.message,\n retryable: false,\n paymentId,\n }),\n );\n }\n };\n\n window.addEventListener(\"message\", onMessage);\n cardNumber.send({ type: \"arcpay:tokenize\", paymentId, idempotencyKey });\n });\n }\n\n destroy(): void {\n for (const el of this.elementMap.values()) {\n el.destroy();\n }\n this.elementMap.clear();\n }\n}\n","import {\n detectEnvironment,\n type Environment,\n validatePublishableKey as _validatePublishableKey,\n} from \"./env\";\nimport { showSandboxBanner } from \"./sandbox-banner\";\nimport { Elements, type ElementsOptions } from \"../elements/elements\";\n\nconst validatePublishableKey: (key: unknown) => asserts key is string = _validatePublishableKey;\n\nexport interface ArcPayLoadOptions {\n readonly _reserved?: never;\n}\n\nexport interface ArcPayInstance {\n readonly publishableKey: string;\n readonly environment: Environment;\n elements: (opts?: ElementsOptions) => Elements;\n}\n\nconst cache = new Map<string, Promise<ArcPayInstance>>();\n\nconst buildInstance = (publishableKey: string): ArcPayInstance => {\n if (detectEnvironment(publishableKey) === \"sandbox\") {\n showSandboxBanner();\n }\n return {\n publishableKey,\n environment: detectEnvironment(publishableKey),\n elements: (opts = {}) => new Elements({ publishableKey, ...opts }),\n };\n};\n\nfunction load(publishableKey: string): Promise<ArcPayInstance> {\n try {\n validatePublishableKey(publishableKey);\n } catch (err) {\n return Promise.reject(err);\n }\n const key = publishableKey;\n const existing = cache.get(key);\n if (existing) return existing;\n const promise = Promise.resolve(buildInstance(publishableKey));\n cache.set(key, promise);\n return promise;\n}\n\nconst resetForTests = (): void => {\n cache.clear();\n};\n\nexport const ArcPay = {\n load,\n __resetForTests: resetForTests,\n};\n","import type { CardBrowserInfo, ExecutePaymentResponse, PaymentNextAction } from \"../server/types\";\n\nexport type ThreeDSAction = PaymentNextAction;\nexport type BrowserInfo = CardBrowserInfo;\n\nexport interface BrowserFormField {\n name: string;\n value: string;\n}\n\nexport interface BrowserPostForm {\n action: string;\n method: \"POST\";\n target: \"hidden_iframe\" | \"browser\";\n fields: BrowserFormField[];\n}\n\nexport interface ThreeDSBrowserStep {\n kind: \"method\" | \"challenge\";\n protocolVersion: \"1\" | \"2\";\n form: BrowserPostForm;\n completionEndpoint?: string;\n threeDSServerTransId?: string;\n}\n\nexport interface MountedThreeDSForm {\n form: HTMLFormElement;\n iframe?: HTMLIFrameElement;\n submit: () => void;\n remove: () => void;\n}\n\nexport interface ThreeDSMountOptions {\n document?: Document;\n container?: HTMLElement;\n challengeTarget?: \"_self\";\n submitter?: (form: HTMLFormElement) => void;\n}\n\nexport interface RunThreeDSBrowserFlowOptions extends ThreeDSMountOptions {\n completeThreeDSMethod?: (\n completion: ReturnType<typeof buildThreeDSMethodCompletion>,\n nextAction: PaymentNextAction,\n ) => Promise<ExecutePaymentResponse>;\n methodCompletionIndicator?: \"Y\" | \"N\" | \"U\";\n methodTimeoutMs?: number;\n signal?: AbortSignal;\n}\n\nexport type ThreeDSBrowserFlowResult =\n | {\n status: \"no_action\";\n response?: ExecutePaymentResponse;\n }\n | {\n status: \"method_completed\";\n response: ExecutePaymentResponse;\n methodResult: \"loaded\" | \"timeout\";\n }\n | {\n status: \"challenge_submitted\";\n action: PaymentNextAction;\n response?: ExecutePaymentResponse;\n mounted: MountedThreeDSForm;\n methodResult?: \"loaded\" | \"timeout\";\n };\n\nconst supportedColorDepths = [1, 4, 8, 15, 16, 24, 32, 48] as const;\n\nconst normalizeColorDepth = (value: number): BrowserInfo[\"color_depth\"] =>\n supportedColorDepths.includes(value as BrowserInfo[\"color_depth\"])\n ? (value as BrowserInfo[\"color_depth\"])\n : 24;\n\nconst resolveWindowSize = (width: number): NonNullable<BrowserInfo[\"window_size\"]> => {\n if (width >= 1000) return \"05\";\n if (width >= 600) return \"04\";\n if (width >= 500) return \"03\";\n if (width >= 390) return \"02\";\n return \"01\";\n};\n\nexport const collectBrowserInfo = (\n acceptHeader = \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n): BrowserInfo => {\n if (\n typeof window === \"undefined\" ||\n typeof navigator === \"undefined\" ||\n typeof screen === \"undefined\"\n ) {\n throw new Error(\"collectBrowserInfo must be called in a browser environment\");\n }\n return {\n accept_header: acceptHeader,\n language: navigator.language || \"en\",\n screen_width: screen.width,\n screen_height: screen.height,\n color_depth: normalizeColorDepth(screen.colorDepth),\n timezone_offset_minutes: new Date().getTimezoneOffset(),\n java_enabled: false,\n user_agent: navigator.userAgent,\n window_size: resolveWindowSize(window.innerWidth || screen.width),\n };\n};\n\nexport const getThreeDSAction = (nextAction?: PaymentNextAction): PaymentNextAction | null => {\n return nextAction ?? null;\n};\n\nexport const isThreeDSMethodAction = (nextAction?: PaymentNextAction): boolean => {\n return nextAction?.type === \"three_ds_method\" && nextAction.three_ds.phase === \"method\";\n};\n\nexport const isThreeDSChallengeAction = (nextAction?: PaymentNextAction): boolean => {\n return nextAction?.type === \"three_ds_challenge\" && nextAction.three_ds.phase === \"challenge\";\n};\n\nexport const buildThreeDSBrowserForm = (nextAction: PaymentNextAction): BrowserPostForm => ({\n action: nextAction.three_ds.submit.url,\n method: nextAction.three_ds.submit.method,\n target: nextAction.three_ds.submit.target,\n fields: nextAction.three_ds.submit.fields,\n});\n\nconst assertHTTPSActionURL = (action: string): void => {\n let parsed: URL;\n try {\n parsed = new URL(action);\n } catch {\n throw new Error(\"3DS form action must be an absolute HTTPS URL\");\n }\n if (parsed.protocol !== \"https:\") {\n throw new Error(\"3DS form action must use HTTPS\");\n }\n};\n\nexport const buildThreeDSBrowserStep = (\n nextAction?: PaymentNextAction,\n): ThreeDSBrowserStep | null => {\n const action = getThreeDSAction(nextAction);\n if (!action) return null;\n return {\n kind: action.three_ds.phase,\n protocolVersion: action.three_ds.version,\n form: buildThreeDSBrowserForm(action),\n completionEndpoint: action.three_ds.completion_endpoint,\n threeDSServerTransId: action.three_ds.three_ds_server_trans_id,\n };\n};\n\nexport const buildThreeDSMethodCompletion = (\n nextAction: PaymentNextAction,\n completionIndicator: \"Y\" | \"N\" | \"U\" = \"Y\",\n): { completion_indicator: \"Y\" | \"N\" | \"U\"; three_ds_server_trans_id: string } => {\n if (!isThreeDSMethodAction(nextAction) || !nextAction.three_ds.three_ds_server_trans_id) {\n throw new Error(\"nextAction must be a three_ds_method action with three_ds_server_trans_id\");\n }\n return {\n completion_indicator: completionIndicator,\n three_ds_server_trans_id: nextAction.three_ds.three_ds_server_trans_id,\n };\n};\n\nconst requireDocument = (explicitDocument?: Document): Document => {\n if (explicitDocument) return explicitDocument;\n if (typeof document === \"undefined\") {\n throw new Error(\"3DS browser helpers must be called in a browser environment\");\n }\n return document;\n};\n\nconst defaultSubmitter = (form: HTMLFormElement): void => {\n form.submit();\n};\n\nexport const mountThreeDSBrowserForm = (\n nextAction: PaymentNextAction,\n options: ThreeDSMountOptions = {},\n): MountedThreeDSForm => {\n const doc = requireDocument(options.document);\n const container = options.container ?? doc.body;\n const formDescriptor = buildThreeDSBrowserForm(nextAction);\n assertHTTPSActionURL(formDescriptor.action);\n const form = doc.createElement(\"form\");\n const target =\n formDescriptor.target === \"hidden_iframe\"\n ? `arcpay-three-ds-method-${crypto.randomUUID()}`\n : (options.challengeTarget ?? \"_self\");\n let iframe: HTMLIFrameElement | undefined;\n\n form.method = formDescriptor.method;\n form.action = formDescriptor.action;\n form.target = target;\n form.hidden = true;\n\n for (const field of formDescriptor.fields) {\n const input = doc.createElement(\"input\");\n input.type = \"hidden\";\n input.name = field.name;\n input.value = field.value;\n form.append(input);\n }\n\n if (formDescriptor.target === \"hidden_iframe\") {\n iframe = doc.createElement(\"iframe\");\n iframe.name = target;\n iframe.title = \"3-D Secure method\";\n iframe.hidden = true;\n container.append(iframe);\n }\n\n container.append(form);\n\n return {\n form,\n iframe,\n submit: () => (options.submitter ?? defaultSubmitter)(form),\n remove: () => {\n form.remove();\n iframe?.remove();\n },\n };\n};\n\nconst waitForMethodFrame = (\n mounted: MountedThreeDSForm,\n timeoutMs: number,\n signal?: AbortSignal,\n): Promise<\"loaded\" | \"timeout\"> =>\n new Promise((resolve, reject) => {\n if (!mounted.iframe) {\n resolve(\"loaded\");\n return;\n }\n if (signal?.aborted) {\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n return;\n }\n\n let settled = false;\n const cleanup = () => {\n mounted.iframe?.removeEventListener(\"load\", onLoad);\n signal?.removeEventListener(\"abort\", onAbort);\n clearTimeout(timer);\n };\n const settle = (result: \"loaded\" | \"timeout\") => {\n if (settled) return;\n settled = true;\n cleanup();\n resolve(result);\n };\n const onLoad = () => settle(\"loaded\");\n const onAbort = () => {\n if (settled) return;\n settled = true;\n cleanup();\n reject(new DOMException(\"The operation was aborted\", \"AbortError\"));\n };\n const timer = setTimeout(() => settle(\"timeout\"), timeoutMs);\n\n mounted.iframe.addEventListener(\"load\", onLoad, { once: true });\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n\nexport const runThreeDSBrowserFlow = async (\n nextAction: PaymentNextAction | undefined,\n options: RunThreeDSBrowserFlowOptions,\n): Promise<ThreeDSBrowserFlowResult> => {\n if (!nextAction) return { status: \"no_action\" };\n\n if (isThreeDSChallengeAction(nextAction)) {\n const mounted = mountThreeDSBrowserForm(nextAction, options);\n mounted.submit();\n return { status: \"challenge_submitted\", action: nextAction, mounted };\n }\n\n if (!isThreeDSMethodAction(nextAction)) return { status: \"no_action\" };\n const completeThreeDSMethod = options.completeThreeDSMethod;\n if (!completeThreeDSMethod) {\n throw new Error(\"completeThreeDSMethod is required for 3DS Method actions\");\n }\n\n const mounted = mountThreeDSBrowserForm(nextAction, options);\n try {\n mounted.submit();\n const methodResult = await waitForMethodFrame(\n mounted,\n options.methodTimeoutMs ?? 10_000,\n options.signal,\n );\n const indicator = options.methodCompletionIndicator ?? (methodResult === \"loaded\" ? \"Y\" : \"N\");\n const response = await completeThreeDSMethod(\n buildThreeDSMethodCompletion(nextAction, indicator),\n nextAction,\n );\n const followUpAction = getThreeDSAction(response.next_action);\n if (followUpAction && isThreeDSChallengeAction(followUpAction)) {\n const challengeMounted = mountThreeDSBrowserForm(followUpAction, options);\n challengeMounted.submit();\n return {\n status: \"challenge_submitted\",\n action: followUpAction,\n response,\n mounted: challengeMounted,\n methodResult,\n };\n }\n return { status: \"method_completed\", response, methodResult };\n } finally {\n mounted.remove();\n }\n};\n\nconst htmlEscape = (value: string): string =>\n value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n\nexport const buildThreeDSAutoSubmitHtml = (nextAction: PaymentNextAction): string => {\n const form = buildThreeDSBrowserForm(nextAction);\n assertHTTPSActionURL(form.action);\n const target = form.target === \"hidden_iframe\" ? \"arcpay-three-ds-method\" : \"_self\";\n const inputs = form.fields\n .map(\n (field) =>\n `<input type=\"hidden\" name=\"${htmlEscape(field.name)}\" value=\"${htmlEscape(field.value)}\">`,\n )\n .join(\"\");\n const iframe =\n form.target === \"hidden_iframe\"\n ? '<iframe name=\"arcpay-three-ds-method\" title=\"3-D Secure method\" hidden></iframe>'\n : \"\";\n return `<!doctype html><html><head><meta charset=\"utf-8\"></head><body>${iframe}<form method=\"POST\" action=\"${htmlEscape(form.action)}\" target=\"${target}\">${inputs}</form><script>document.forms[0].submit();</script></body></html>`;\n};\n","export { ArcPay } from \"./core/arcpay\";\nexport type { ArcPayInstance, ArcPayLoadOptions } from \"./core/arcpay\";\nexport {\n ArcPayError,\n isValidationError,\n isAuthenticationError,\n isAuthorizationError,\n isStateError,\n isRateLimitError,\n isApiError,\n isNetworkError,\n isChallengeAborted,\n} from \"./core/errors\";\nexport type { ArcPayErrorType } from \"./core/errors\";\nexport type { Environment } from \"./core/env\";\nexport type { TokenizeResult } from \"./tokenize/tokenize\";\nexport type { CardScheme } from \"./tokenize/scheme\";\nexport {\n buildThreeDSAutoSubmitHtml,\n buildThreeDSBrowserForm,\n buildThreeDSBrowserStep,\n buildThreeDSMethodCompletion,\n collectBrowserInfo,\n getThreeDSAction,\n isThreeDSChallengeAction,\n isThreeDSMethodAction,\n mountThreeDSBrowserForm,\n runThreeDSBrowserFlow,\n} from \"./three-ds\";\nexport type {\n BrowserFormField,\n BrowserInfo,\n BrowserPostForm,\n MountedThreeDSForm,\n RunThreeDSBrowserFlowOptions,\n ThreeDSAction,\n ThreeDSBrowserStep,\n ThreeDSBrowserFlowResult,\n ThreeDSMountOptions,\n} from \"./three-ds\";\nexport const SDK_VERSION = \"0.1.26\";\n\nexport type { FieldType } from \"./elements/postmessage\";\nexport type { ElementOptions, ElementEvent } from \"./elements/element\";\nexport { Elements } from \"./elements/elements\";\nexport type { ElementsOptions } from \"./elements/elements\";\nexport type {\n HostedFieldsAppearance,\n HostedFieldsAppearanceRule,\n HostedFieldsAppearanceVariables,\n HostedFieldsTheme,\n} from \"./elements/style\";\n"]}
|