@basis-theory/web-elements 3.0.0-beta.4 → 3.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.vite/manifest.json +22 -11
- package/dist/basis-theory-sdk.es.js +1 -1
- package/dist/basis-theory-sdk.umd.js +1 -1
- package/dist/basis-theory-sdk.umd.js.map +1 -1
- package/dist/{create-card-B5zEHyRg.js → create-card-CB_YcP_4.js} +10 -6
- package/dist/create-card-CB_YcP_4.js.map +1 -0
- package/dist/create-card-display-kBupMJwe.js +280 -0
- package/dist/create-card-display-kBupMJwe.js.map +1 -0
- package/dist/{create-copy-button-DrAz8g0m.js → create-copy-button-2XtKTEo3.js} +5 -2
- package/dist/create-copy-button-2XtKTEo3.js.map +1 -0
- package/dist/{index-BOedIhUN.js → index-Dyy7tm5Z.js} +325 -108
- package/dist/index-Dyy7tm5Z.js.map +1 -0
- package/dist/index.d.ts +1119 -0
- package/dist/loader/basis-theory.min.js +1 -1
- package/dist/sri.json +9 -9
- package/dist/stats.html +1 -1
- package/package.json +12 -12
- package/dist/api-client/src/api-client.d.ts +0 -11
- package/dist/api-client/src/api-client.d.ts.map +0 -1
- package/dist/api-client/src/bin-lookup-transform.d.ts +0 -35
- package/dist/api-client/src/bin-lookup-transform.d.ts.map +0 -1
- package/dist/api-client/src/http-client.d.ts +0 -24
- package/dist/api-client/src/http-client.d.ts.map +0 -1
- package/dist/api-client/src/index.d.ts +0 -9
- package/dist/api-client/src/index.d.ts.map +0 -1
- package/dist/api-client/src/services/sessions.d.ts +0 -19
- package/dist/api-client/src/services/sessions.d.ts.map +0 -1
- package/dist/api-client/src/services/token-intents.d.ts +0 -17
- package/dist/api-client/src/services/token-intents.d.ts.map +0 -1
- package/dist/api-client/src/services/tokens.d.ts +0 -19
- package/dist/api-client/src/services/tokens.d.ts.map +0 -1
- package/dist/api-client/src/types.d.ts +0 -421
- package/dist/api-client/src/types.d.ts.map +0 -1
- package/dist/create-card-B5zEHyRg.js.map +0 -1
- package/dist/create-copy-button-DrAz8g0m.js.map +0 -1
- package/dist/index-BOedIhUN.js.map +0 -1
- package/dist/postmessage/src/client.d.ts +0 -7
- package/dist/postmessage/src/client.d.ts.map +0 -1
- package/dist/postmessage/src/event-map.d.ts +0 -139
- package/dist/postmessage/src/event-map.d.ts.map +0 -1
- package/dist/postmessage/src/index.d.ts +0 -9
- package/dist/postmessage/src/index.d.ts.map +0 -1
- package/dist/postmessage/src/server.d.ts +0 -11
- package/dist/postmessage/src/server.d.ts.map +0 -1
- package/dist/postmessage/src/types.d.ts +0 -75
- package/dist/postmessage/src/types.d.ts.map +0 -1
- package/dist/shared/src/api-url-resolver.d.ts +0 -22
- package/dist/shared/src/api-url-resolver.d.ts.map +0 -1
- package/dist/shared/src/debug-logger.d.ts +0 -16
- package/dist/shared/src/debug-logger.d.ts.map +0 -1
- package/dist/shared/src/deep-sanitization.d.ts +0 -24
- package/dist/shared/src/deep-sanitization.d.ts.map +0 -1
- package/dist/shared/src/errors.d.ts +0 -93
- package/dist/shared/src/errors.d.ts.map +0 -1
- package/dist/shared/src/generate-id.d.ts +0 -13
- package/dist/shared/src/generate-id.d.ts.map +0 -1
- package/dist/shared/src/index.d.ts +0 -14
- package/dist/shared/src/index.d.ts.map +0 -1
- package/dist/shared/src/logger-context.d.ts +0 -25
- package/dist/shared/src/logger-context.d.ts.map +0 -1
- package/dist/shared/src/proxy-validation.d.ts +0 -93
- package/dist/shared/src/proxy-validation.d.ts.map +0 -1
- package/dist/web-elements/src/BasisTheory.d.ts +0 -47
- package/dist/web-elements/src/BasisTheory.d.ts.map +0 -1
- package/dist/web-elements/src/basis-theory.d.ts +0 -85
- package/dist/web-elements/src/basis-theory.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-card-number.d.ts +0 -15
- package/dist/web-elements/src/elements/create-card-number.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-card.d.ts +0 -50
- package/dist/web-elements/src/elements/create-card.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-copy-button.d.ts +0 -19
- package/dist/web-elements/src/elements/create-copy-button.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-cvv.d.ts +0 -11
- package/dist/web-elements/src/elements/create-cvv.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-expiry.d.ts +0 -11
- package/dist/web-elements/src/elements/create-expiry.d.ts.map +0 -1
- package/dist/web-elements/src/elements/create-text.d.ts +0 -14
- package/dist/web-elements/src/elements/create-text.d.ts.map +0 -1
- package/dist/web-elements/src/index.d.ts +0 -27
- package/dist/web-elements/src/index.d.ts.map +0 -1
- package/dist/web-elements/src/mounter/create-mounter.d.ts +0 -11
- package/dist/web-elements/src/mounter/create-mounter.d.ts.map +0 -1
- package/dist/web-elements/src/theme/default-theme.d.ts +0 -22
- package/dist/web-elements/src/theme/default-theme.d.ts.map +0 -1
- package/dist/web-elements/src/theme/inject-theme-dark.d.ts +0 -13
- package/dist/web-elements/src/theme/inject-theme-dark.d.ts.map +0 -1
- package/dist/web-elements/src/theme/inject-theme.d.ts +0 -20
- package/dist/web-elements/src/theme/inject-theme.d.ts.map +0 -1
- package/dist/web-elements/src/types/events.d.ts +0 -165
- package/dist/web-elements/src/types/events.d.ts.map +0 -1
- package/dist/web-elements/src/types/theme.d.ts +0 -91
- package/dist/web-elements/src/types/theme.d.ts.map +0 -1
- package/dist/web-elements/src/types.d.ts +0 -667
- package/dist/web-elements/src/types.d.ts.map +0 -1
- package/dist/web-elements/src/utils/create-event-dispatcher.d.ts +0 -47
- package/dist/web-elements/src/utils/create-event-dispatcher.d.ts.map +0 -1
- package/dist/web-elements/src/utils/create-iframe.d.ts +0 -10
- package/dist/web-elements/src/utils/create-iframe.d.ts.map +0 -1
- package/dist/web-elements/src/utils/resolve-element-references.d.ts +0 -20
- package/dist/web-elements/src/utils/resolve-element-references.d.ts.map +0 -1
- package/dist/web-elements/src/utils/validate-element-options.d.ts +0 -11
- package/dist/web-elements/src/utils/validate-element-options.d.ts.map +0 -1
- package/dist/web-elements/src/utils/validate-sdk-config.d.ts +0 -15
- package/dist/web-elements/src/utils/validate-sdk-config.d.ts.map +0 -1
- package/dist/web-elements/src/utils/warn-unknown-keys.d.ts +0 -15
- package/dist/web-elements/src/utils/warn-unknown-keys.d.ts.map +0 -1
- package/dist/web-elements/src/version.d.ts +0 -25
- package/dist/web-elements/src/version.d.ts.map +0 -1
package/dist/.vite/manifest.json
CHANGED
|
@@ -1,38 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_index-
|
|
3
|
-
"file": "index-
|
|
2
|
+
"_index-Dyy7tm5Z.js": {
|
|
3
|
+
"file": "index-Dyy7tm5Z.js",
|
|
4
4
|
"name": "index",
|
|
5
5
|
"dynamicImports": [
|
|
6
6
|
"src/elements/create-card.ts",
|
|
7
|
-
"src/elements/create-copy-button.ts"
|
|
7
|
+
"src/elements/create-copy-button.ts",
|
|
8
|
+
"src/elements/create-card-display.ts"
|
|
8
9
|
],
|
|
9
|
-
"integrity": "sha384-
|
|
10
|
+
"integrity": "sha384-M2jrVOhhjwRzXsG2I/lanaZncm6AV/aifIEmqgvrgdCr0wXYmwZYfdwQ24Zm7o3s"
|
|
11
|
+
},
|
|
12
|
+
"src/elements/create-card-display.ts": {
|
|
13
|
+
"file": "create-card-display-kBupMJwe.js",
|
|
14
|
+
"name": "create-card-display",
|
|
15
|
+
"src": "src/elements/create-card-display.ts",
|
|
16
|
+
"isDynamicEntry": true,
|
|
17
|
+
"imports": [
|
|
18
|
+
"_index-Dyy7tm5Z.js"
|
|
19
|
+
],
|
|
20
|
+
"integrity": "sha384-lRKu5AhFJkymqmbtKOOOkBLlnNIjoguNvZS6UngLlYU9xf4Wx8ma3BqMaq82vcTx"
|
|
10
21
|
},
|
|
11
22
|
"src/elements/create-card.ts": {
|
|
12
|
-
"file": "create-card-
|
|
23
|
+
"file": "create-card-CB_YcP_4.js",
|
|
13
24
|
"name": "create-card",
|
|
14
25
|
"src": "src/elements/create-card.ts",
|
|
15
26
|
"isDynamicEntry": true,
|
|
16
27
|
"imports": [
|
|
17
|
-
"_index-
|
|
28
|
+
"_index-Dyy7tm5Z.js"
|
|
18
29
|
],
|
|
19
|
-
"integrity": "sha384
|
|
30
|
+
"integrity": "sha384-V+kTMzqYkErz3zSmpYck1AFuFVhfVHPCgRJYmJReu9ReqKm01KTye7MqFSbwdefL"
|
|
20
31
|
},
|
|
21
32
|
"src/elements/create-copy-button.ts": {
|
|
22
|
-
"file": "create-copy-button-
|
|
33
|
+
"file": "create-copy-button-2XtKTEo3.js",
|
|
23
34
|
"name": "create-copy-button",
|
|
24
35
|
"src": "src/elements/create-copy-button.ts",
|
|
25
36
|
"isDynamicEntry": true,
|
|
26
37
|
"imports": [
|
|
27
|
-
"_index-
|
|
38
|
+
"_index-Dyy7tm5Z.js"
|
|
28
39
|
],
|
|
29
|
-
"integrity": "sha384-
|
|
40
|
+
"integrity": "sha384-Bvsrig3Whx+7LYKewueojAjhiVfxA29x00104M9ojnuJRgI/358haIe4ncDq88ln"
|
|
30
41
|
},
|
|
31
42
|
"src/index.ts": {
|
|
32
43
|
"file": "basis-theory-sdk.umd.js",
|
|
33
44
|
"name": "index",
|
|
34
45
|
"src": "src/index.ts",
|
|
35
46
|
"isEntry": true,
|
|
36
|
-
"integrity": "sha384-
|
|
47
|
+
"integrity": "sha384-Zptgd8epTAPnOZIG55DndYPbNDe0jEYJfUHaaAwGlNA5rZjSHVV/ka6/weNv00Cv"
|
|
37
48
|
}
|
|
38
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BasisTheory={})}(this,function(e){"use strict";const t=[/cardnumber/i,/^pan$/i,/accountnumber/i,/^number$/i],r=[/cvv/i,/cvc/i,/cvv2/i,/securitycode/i,/pin/i,/password/i,/secret/i,/token/i,/ssn/i,/track/i],o=e=>t.some(t=>t.test(e)),n=e=>r.some(t=>t.test(e)),a=e=>{const t=e.replace(/\D/g,"");if(t.length<10)return"***";const r=t.substring(0,6),o=t.substring(t.length-4),n=Math.max(t.length-10,6);return`${r}${"*".repeat(n)}${o}`},i=e=>{const t=e.replace(/[\s-]/g,"");return/^\d{13,19}$/.test(t)},s=(e,t)=>null==t?t:"function"==typeof t?"[Function]":"symbol"==typeof t?"[Symbol]":t instanceof RegExp?"[RegExp]":t instanceof Date?t:o(e)?"string"==typeof t?a(t):"***":n(e)?"***":"string"==typeof t&&i(t)?a(t):t,l=(e,t=0,r=new WeakSet)=>{if(t>=5)return"[Max Depth]";if(null==e)return e;if("string"==typeof e)return i(e)?a(e):e;if("object"!=typeof e)return e;if(e instanceof RegExp)return"[RegExp]";if(e instanceof Date)return e;if(r.has(e))return"[Circular]";let o;if(r.add(e),Array.isArray(e))o=e.map(e=>l(e,t+1,r));else{const n={};for(const[o,a]of Object.entries(e)){const e=s(o,a);n[o]=null!==e&&"object"==typeof e?l(e,t+1,r):e}o=n}return r.delete(e),o},d=(e,t)=>t?(t,r)=>{const a=(()=>{const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`})(),i=r?(e=>{const t={};for(const[r,a]of Object.entries(e))if(o(r)||n(r)){const e="string"==typeof a?a.length:"number"==typeof a?String(a).length:0;t[`${r}_length`]=e}else t[r]=l(a);return t})(r):{};console.log(`🔍 [${a}] [${e}] ${t}`,i)}:()=>{},u=(e,t,r)=>{const o=new Error(t);return o.name="BasisTheoryError",o.code=e,o.details=r,Error.captureStackTrace&&Error.captureStackTrace(o,u),o.toJSON=()=>({name:o.name,code:o.code,message:o.message,...o.details&&{details:o.details}}),o},m=(e,t,r)=>{const o=u(e,t,r);return o.name="BasisTheoryError",o},c=(e,t,r)=>{const o=u("VALIDATION_ERROR",e,t?{field:t,...r}:r);return o.name="ValidationError",o.field=t,o},f=(e,t)=>{const r=u("COORDINATOR_ERROR",e,t);return r.name="CoordinatorError",r},h=(e,t,r)=>{const o=u("ELEMENT_ERROR",e,t?{elementId:t,...r}:r);return o.name="ElementError",o.elementId=t,o},p=(e,t)=>{const r=u("CONFIGURATION_ERROR",e,t);return r.name="ConfigurationError",r},y=new Set(["https:"]),g=new Set(["GET","POST","PUT","PATCH","DELETE"]),b=new Set(["host","content-length","transfer-encoding","te","trailer","connection","upgrade","keep-alive","proxy-connection","via","proxy-authorization","bt-api-key","bt-proxy-key","bt-proxy-url","bt-idempotency-key","x-forwarded-for","x-forwarded-host","x-real-ip","content-type"]),w=e=>{const t=e.replace(/^\[|\]$/g,"");if(/^(0x[\da-f]+|\d+)$/i.test(t)){const e=t.toLowerCase().startsWith("0x")?parseInt(t,16):parseInt(t,10);return e>=0&&e<=4294967295?[e>>>24&255,e>>>16&255,e>>>8&255,255&e]:null}const r=t.split(".");if(4!==r.length)return null;const o=[];for(const n of r){let e;if(e=n.toLowerCase().startsWith("0x")?parseInt(n,16):n.startsWith("0")&&n.length>1&&!/[89]/.test(n)?parseInt(n,8):parseInt(n,10),isNaN(e)||e<0||e>255)return null;o.push(e)}return o},E=e=>{const t=e[0],r=e[1];return void 0===t||void 0===r||127===t||10===t||172===t&&r>=16&&r<=31||192===t&&168===r||169===t&&254===r||0===t},v=e=>{const t=e.replace(/^\[|\]$/g,"").toLowerCase();if("::1"===t||"0:0:0:0:0:0:0:1"===t||"0000:0000:0000:0000:0000:0000:0000:0001"===t)return!0;if(t.startsWith("fe8")||t.startsWith("fe9")||t.startsWith("fea")||t.startsWith("feb"))return!0;if(t.startsWith("fc")||t.startsWith("fd"))return!0;const r=t.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);if(r){const e=r[1];if(e){const t=w(e);if(t&&E(t))return!0}}const o=t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);if(o){const e=o[1],t=o[2];if(!e||!t)return!0;const r=parseInt(e,16),n=parseInt(t,16);if(E([r>>>8&255,255&r,n>>>8&255,255&n]))return!0}return!1},T=e=>{if(void 0!==e&&("object"!=typeof e||null===e))throw c("Proxy options must be a plain object","options");if(void 0!==(null==e?void 0:e.method)&&!g.has(e.method))throw c(`Method '${e.method}' is not allowed`,"method");((e,t)=>{const r="string"==typeof e&&e.length>0;if(r===("string"==typeof t&&t.length>0))throw c("Specify exactly one of url or proxyKey","url/proxyKey");r&&(e=>{let t;try{t=new URL(e)}catch{throw c("Invalid URL format","url")}if(!y.has(t.protocol))throw c(`URL scheme '${t.protocol}' is not allowed. Only https: is permitted`,"url");(e=>{const t=e.hostname.toLowerCase();if(e.username||e.password)throw c("URL must not contain userinfo (username/password)","url");if("localhost"===t)throw c("URL must not target localhost","url");if((t.startsWith("[")||v(t))&&v(t))throw c("URL must not target loopback or link-local IPv6 addresses","url");const r=w(t);if(r&&E(r))throw c("URL must not target private or internal IP addresses","url")})(t)})(e)})(null==e?void 0:e.url,null==e?void 0:e.proxyKey),(e=>{if(e)for(const[t,r]of Object.entries(e)){if(/[\r\n]/.test(r))throw c(`Header '${t}' value contains illegal CRLF`,"headers");if(/[\r\n]/.test(t))throw c(`Header name '${t}' contains illegal CRLF`,"headers");if(b.has(t.toLowerCase().trim()))throw c(`Header '${t}' is not allowed in proxy requests`,"headers")}})(null==e?void 0:e.headers)},M={maxRetries:2,initialDelay:500,maxDelay:3e3,backoffFactor:2},R=(e,t)=>{const r=t.initialDelay*Math.pow(t.backoffFactor,e);return Math.min(r,t.maxDelay)},C=e=>new Promise(t=>setTimeout(t,e)),k=(e,t)=>{const r=new Map,o=new Map,n=d("PostMessageClient",t.debug||!1),a=a=>{const{nonce:i,type:s,payload:l,error:d}=a.data||{};if(!s)return;if(a.origin!==t.targetOrigin)return void n("Rejected message (origin mismatch)",{receivedOrigin:a.origin,expectedOrigin:t.targetOrigin,messageType:s});if(a.source!==e.contentWindow)return;if(i){const e=r.get(i);if(e){if(n("Message received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i}),clearTimeout(e.timeout),r.delete(i),d){const t=m(d.code,`[${d.code}] ${d.message}`);Object.assign(t,{...void 0!==d.status&&{status:d.status},...void 0!==d.statusCode&&{statusCode:d.statusCode},...d.validationErrors&&{validationErrors:d.validationErrors},...d.body&&{body:d.body},...void 0!==d.retryCount&&{retryCount:d.retryCount},...d.details&&{details:d.details}}),e.reject(t)}else e.resolve(l);return}return}const u=o.get(s);u&&u.size>0?(n("Event received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i,subscriberCount:u.size}),u.forEach(e=>{try{e(l)}catch(r){t.debug&&console.error(`[PostMessage Client] Error in event subscriber for ${s}:`,r)}})):i||n("Event received but no subscribers",{type:s,availableSubscribers:Array.from(o.keys())})};window.addEventListener("message",a);const i="number"==typeof t.retries?{...M,maxRetries:t.retries}:"object"==typeof t.retries?t.retries:M,s=(o,a)=>new Promise((i,s)=>{const l=crypto.randomUUID(),d=Date.now();if(!e.contentWindow)return void s(m("IFRAME_NOT_READY","Iframe not ready"));const u=setTimeout(()=>{r.delete(l),s(m("REQUEST_TIMEOUT",`Request timeout: ${o} (${t.timeout||5e3}ms)`))},t.timeout||5e3);r.set(l,{resolve:i,reject:s,timeout:u,timestamp:d}),n("Sending request",{type:o,nonce:l}),e.contentWindow.postMessage({type:o,nonce:l,timestamp:d,payload:a},t.targetOrigin)});return{sendRequest:async(e,t,r)=>{const o=void 0!==(null==r?void 0:r.retries)?r.retries:i.maxRetries;let a=null;for(let d=0;d<=o;d++)try{return await s(e,t)}catch(l){a=l;const e=l.message;if(e.startsWith("[HANDLER_ERROR]")||"Client destroyed"===e||"Iframe not ready"===e)throw n("Not retrying error",{error:e,reason:"Non-retriable error"}),l;if(d<o){const t=R(d,i);n("Retrying request",{attempt:d+1,maxRetries:o,delayMs:t,error:e}),await C(t)}}throw a||new Error(`Request failed after ${o} retries: ${e}`)},ping:async(o=1e3)=>{const a=Date.now();n("Starting health check",{timeoutMs:o,iframeReady:!!e.contentWindow,targetOrigin:t.targetOrigin});try{await s("SYS_PING",void 0);const e=Date.now()-a;return n("Health check passed",{latencyMs:e}),e}catch(i){const e=`Health check failed after ${Date.now()-a}ms: ${i.message}. Target: ${t.targetOrigin}`;throw t.debug&&(n(`❌ [PostMessage Client] ${e}`),n(`📊 [PostMessage Client] Pending requests: ${r.size}`)),m("HEALTH_CHECK_FAILED",e)}},subscribe:(e,t)=>(o.has(e)||o.set(e,new Set),o.get(e).add(t),()=>{const r=o.get(e);r&&(r.delete(t),0===r.size&&o.delete(e))}),destroy:()=>{window.removeEventListener("message",a),r.forEach(({timeout:e,reject:t})=>{clearTimeout(e),t(m("CLIENT_DESTROYED","Client destroyed"))}),r.clear(),o.clear()},getPendingCount:()=>r.size}},x=e=>{const t=document.createElement("iframe");return t.src=e.src,t.setAttribute("sandbox",e.sandbox),t.title=e.title,t.setAttribute("allow",e.allow??"payment *"),t.setAttribute("importance","high"),t.style.opacity="0",t},O=e=>{const{elementType:t,elementId:r,client:o,eventTarget:n}=e,a=(e,o)=>{const a=new CustomEvent(e,{detail:{elementType:t,elementId:r,timestamp:Date.now(),...o}});n.dispatchEvent(a)};return{setupSubscriptions:()=>{o.subscribe("EVENT_READY",()=>{a("ready",{})}),o.subscribe("EVENT_VALUE_CHANGED",e=>{const r={isValid:e.isValid,isEmpty:e.isEmpty,error:e.error||null};if("cardNumber"===t){const t={...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,cvvLengths:e.cvvLengths,potentialBrands:e.potentialBrands,matchStrength:e.matchStrength,networks:e.networks,selectedNetwork:e.selectedNetwork};a("change",t)}else a("change","card"===t?{...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,networks:e.networks,selectedNetwork:e.selectedNetwork,errors:e.errors||null}:r)}),o.subscribe("EVENT_NETWORK_CHANGED",e=>{if("cardNumber"!==t&&"card"!==t)return;const r={network:e.network,previousNetwork:e.previousNetwork,availableNetworks:e.availableNetworks??[],selectionMode:e.selectionMode??"auto"};a("networkChanged",r)}),o.subscribe("EVENT_FOCUS",()=>{a("focus",{})}),o.subscribe("EVENT_BLUR",()=>{a("blur",{})}),o.subscribe("EVENT_ERROR",e=>{a("error",{code:e.code,message:e.message,status:e.status,validationErrors:e.validationErrors,metadata:e.metadata||{}})})},dispatchError:(e,t,r)=>{a("error",{code:e,message:t,metadata:{source:"initialization",originalError:r}})}}},_=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,f=o,p="cardNumber";return{id:f,type:p,get mounted(){return d},mount:async o=>{if(d)throw h("Element is already mounted");if(u="string"==typeof o?document.querySelector(o):o,!u)throw h(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/card-number.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",f),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=x({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Number Input"}),i.setAttribute("data-bt-element-id",f),i.setAttribute("data-theme-mode",t.themeMode||"auto"),s=k(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=O({elementType:p,elementId:f,client:s,eventTarget:c}),m.setupSubscriptions(),s.subscribe("EVENT_CONTENT_HEIGHT",e=>{const t=null==e?void 0:e.heightPx;i&&"number"==typeof t&&t>0&&(i.style.height=`${Math.ceil(t)}px`)}));const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,f,{elementType:p,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:f,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug,binLookup:r.binLookup,coBadge:r.coBadge}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw h("Element is not mounted");a(f).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(i.style.height="",l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw h("Element must be mounted before updating");const r={elementId:f};void 0!==e.placeholder&&(r.placeholder=e.placeholder),void 0!==e.disabled&&(r.disabled=e.disabled),void 0!==e.readOnly&&(r.readOnly=e.readOnly),void 0!==e.binLookup&&(r.binLookup=e.binLookup),void 0!==e.coBadge&&(r.coBadge=e.coBadge),void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw h("Element must be mounted before focusing");s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw h("Element must be mounted before blurring");s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw h("Element must be mounted before clearing");s.sendRequest("CMD_CLEAR",{})},setNetwork:async e=>{if(!d||!s)throw h("Element must be mounted before setNetwork");await s.sendRequest("CMD_SET_NETWORK",{network:e})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},S=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,f=o,p="cvv";return{id:f,type:p,get mounted(){return d},mount:async o=>{if(d)throw h("Element is already mounted",f);if(u="string"==typeof o?document.querySelector(o):o,!u)throw h(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/cvv.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",f),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=x({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"CVV Input"}),i.setAttribute("data-bt-element-id",f),s=k(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=O({elementType:p,elementId:f,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,f,{elementType:p,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:f,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,showToggle:r.showToggle,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw h("Element is not mounted");a(f).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw h("Element must be mounted before updating",f);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,cardBrand:e.cardBrand,cvvLengths:e.cvvLengths};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw h("Element must be mounted before focusing",f);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw h("Element must be mounted before blurring",f);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw h("Element must be mounted before clearing",f);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},I=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,f=o,p="expiry";return{id:f,type:p,get mounted(){return d},mount:async o=>{if(d)throw h("Element is already mounted",f);if(u="string"==typeof o?document.querySelector(o):o,!u)throw h(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/expiry.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",f),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=x({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Expiry Date Input"}),i.setAttribute("data-bt-element-id",f),s=k(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=O({elementType:p,elementId:f,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,f,{elementType:p,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:f,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw h("Element is not mounted");a(f).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw h("Element must be mounted before updating",f);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw h("Element must be mounted before focusing",f);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw h("Element must be mounted before blurring",f);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw h("Element must be mounted before clearing",f);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},L=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,f=o,p="text";if(r.transform&&!(Array.isArray(r.transform)&&2===r.transform.length&&r.transform[0]instanceof RegExp&&"string"==typeof r.transform[1]))throw new TypeError('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]');return{id:f,type:p,get mounted(){return d},mount:async o=>{if(d)throw h("Element is already mounted",f);if(u="string"==typeof o?document.querySelector(o):o,!u)throw h(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/text.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",f),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=x({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Text Input"}),i.setAttribute("data-bt-element-id",f),s=k(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=O({elementType:p,elementId:f,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,f,{elementType:p,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g;const o=r.transform?{pattern:r.transform[0].source,flags:r.transform[0].flags,replacement:r.transform[1]}:void 0,a=r.mask?r.mask.map(e=>"string"==typeof e?e:e instanceof RegExp?{source:e.source,flags:e.flags}:e):void 0;await s.sendRequest("CMD_SET_CONFIG",{elementId:f,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,validation:r.validation,required:r.required,maxLength:r.maxLength,password:r.password,inputMode:r.inputMode,mask:a,transform:o,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw h("Element is not mounted");a(f).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw h("Element must be mounted before updating",f);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,required:e.required,maxLength:e.maxLength,password:e.password,inputMode:e.inputMode};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw h("Element must be mounted before focusing",f);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw h("Element must be mounted before blurring",f);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw h("Element must be mounted before clearing",f);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},P=e=>{if((e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e)(e))return e;if((e=>{if("object"!=typeof e||null===e)return!1;const t=e;return"function"==typeof t.mount&&"function"==typeof t.update&&"function"==typeof t.on})(e)){if(!e.id)throw h("Element is missing id property. Ensure createElement is called after the SDK loads and all elements are mounted before calling tokenize().");return e.id}if(Array.isArray(e))return e.map(P);if("object"==typeof e&&null!==e){const t={};for(const[r,o]of Object.entries(e))t[r]=P(o);return t}return e},D={colors:{primary:"#3b82f6",error:"#ef4444",success:"#10b981",text:{primary:"#1f2937",secondary:"#6b7280",placeholder:"#9ca3af",disabled:"#d1d5db"},background:{default:"#ffffff",hover:"#f9fafb",focus:"#eff6ff",disabled:"#f9fafb"},border:{default:"#d1d5db",hover:"#9ca3af",focus:"#3b82f6",error:"#ef4444"}},typography:{fontFamily:'"Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:{sm:"14px",base:"16px",lg:"18px"},fontWeight:{normal:"400",medium:"500",semibold:"600"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.75"}},spacing:{xs:"4px",sm:"8px",md:"12px",lg:"16px",xl:"24px"},borders:{radius:{none:"0",sm:"2px",base:"4px",md:"6px",lg:"8px",full:"9999px"},width:{thin:"1px",base:"2px",thick:"3px"}},shadows:{none:"none",sm:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",base:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",lg:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",focus:"0 0 0 3px rgba(59, 130, 246, 0.1)"},transitions:{fast:"150ms cubic-bezier(0.4, 0, 0.2, 1)",base:"200ms cubic-bezier(0.4, 0, 0.2, 1)",slow:"300ms cubic-bezier(0.4, 0, 0.2, 1)"}},B=e=>{var t,r,o,n,a,i,s,l,d,u,m;return e?{colors:{primary:(null==(t=e.colors)?void 0:t.primary)??D.colors.primary,error:(null==(r=e.colors)?void 0:r.error)??D.colors.error,success:(null==(o=e.colors)?void 0:o.success)??D.colors.success,text:{...D.colors.text,...null==(n=e.colors)?void 0:n.text},background:{...D.colors.background,...null==(a=e.colors)?void 0:a.background},border:{...D.colors.border,...null==(i=e.colors)?void 0:i.border}},typography:{...D.typography,...e.typography,fontSize:{...D.typography.fontSize,...null==(s=e.typography)?void 0:s.fontSize},fontWeight:{...D.typography.fontWeight,...null==(l=e.typography)?void 0:l.fontWeight},lineHeight:{...D.typography.lineHeight,...null==(d=e.typography)?void 0:d.lineHeight}},spacing:{...D.spacing,...e.spacing},borders:{radius:{...D.borders.radius,...null==(u=e.borders)?void 0:u.radius},width:{...D.borders.width,...null==(m=e.borders)?void 0:m.width}},shadows:{...D.shadows,...e.shadows},transitions:{...D.transitions,...e.transitions}}:D},U=(e,t,r,o)=>{for(const n of Object.keys(t))r.has(n)||((null==o?void 0:o.has(n))?console.warn(`[BasisTheory] Deprecated option "${n}" in ${e}. ${o.get(n)}`):console.warn(`[BasisTheory] Unknown option "${n}" in ${e}. This option will be ignored. See https://developers.basistheory.com/docs/ for supported options.`))},N=new Set(["elementsBaseUrl","apiBaseUrl","debug","measurePerformance","timeoutMs","retryConfig","themeMode","theme","darkTheme"]),A=new Map([["iframeOrigin",'Use "elementsBaseUrl" instead.']]),q=new Set(["placeholder","ariaLabel","disabled","readOnly"]),$={cardNumber:new Set([...q,"binLookup","coBadge"]),cvv:new Set([...q,"cardBrand","cvvLengths"]),expiry:new Set([...q]),text:new Set([...q,"validation","required","maxLength","password","inputMode","mask","transform"]),card:new Set([...q,"layout","stackAt","iconPosition","cardBrands","binLookup","coBadge"]),copyButton:new Set(["allowClipboard","value","text","disabled"])},z=(e,t={},r)=>{(e=>{if(!e||"string"!=typeof e||0===e.trim().length)throw p("API key is required")})(e);const o=((e={})=>{var t,r,o;U("SDKOptions",e,N,A);const n=e.elementsBaseUrl||e.iframeOrigin;if(void 0!==n){if("string"!=typeof n||0===n.trim().length)throw p("elementsBaseUrl must be a non-empty string");try{new URL(n)}catch{throw p("elementsBaseUrl must be a valid URL")}}if(void 0!==e.apiBaseUrl){if("string"!=typeof e.apiBaseUrl||0===e.apiBaseUrl.trim().length)throw p("apiBaseUrl must be a non-empty string");try{new URL(e.apiBaseUrl)}catch{throw p("apiBaseUrl must be a valid URL")}}if(void 0!==e.debug&&"boolean"!=typeof e.debug)throw p("debug must be a boolean");if(void 0!==e.measurePerformance&&"boolean"!=typeof e.measurePerformance)throw p("measurePerformance must be a boolean");if(void 0!==e.timeoutMs&&("number"!=typeof e.timeoutMs||e.timeoutMs<=0))throw p("timeoutMs must be a positive number");const a={maxRetries:(null==(t=e.retryConfig)?void 0:t.maxRetries)??3,delayMs:(null==(r=e.retryConfig)?void 0:r.delayMs)??1e3,backoffFactor:(null==(o=e.retryConfig)?void 0:o.backoffFactor)??2};if("number"!=typeof a.maxRetries||a.maxRetries<0)throw p("maxRetries must be a non-negative number");if("number"!=typeof a.delayMs||a.delayMs<=0)throw p("retryConfig.delayMs must be a positive number");if("number"!=typeof a.backoffFactor||a.backoffFactor<1)throw p("retryConfig.backoffFactor must be >= 1");const i=e.themeMode||"auto";if(!["light","dark","auto"].includes(i))throw p('themeMode must be "light", "dark", or "auto"');const s=n||"https://js.basistheory.com/3.0.0-beta.4/elements";return{iframeOrigin:new URL(s).origin,elementsBaseUrl:s,apiBaseUrl:e.apiBaseUrl,debug:e.debug??!1,measurePerformance:e.measurePerformance??!1,timeoutMs:e.timeoutMs||3e4,themeMode:i,theme:B(e.theme),darkTheme:e.darkTheme?B(e.darkTheme):void 0,retryConfig:a}})(t),n=d("SDK",o.debug||!1);n("SDK initialized",{apiKeyPrefix:e.substring(0,7)+"...",elementsBaseUrl:o.elementsBaseUrl,iframeOrigin:o.iframeOrigin,debug:o.debug||!1});const a=new Map;let i=null,s=null,l=null,u=!1,m=t.themeMode||"auto";const y=async e=>{if(s)try{await s.sendRequest("CMD_BROADCAST_ELEMENT_UNMOUNT",{elementId:e}),n("Notified coordinator of element unmount",{elementId:e})}catch(t){n("Failed to notify coordinator of element unmount",{elementId:e,error:t.message})}else n("Cannot notify coordinator of unmount - coordinator not initialized",{elementId:e})};let g=null,b=null;const w={cardNumber:_,cvv:S,expiry:I,text:L},E={card:async()=>{if(!g){const e=await Promise.resolve().then(()=>F);g=e.createCardElement}return g},copyButton:async()=>{if(!b){const e=await Promise.resolve().then(()=>K);b=e.createCopyButtonElement}return b}},v=()=>l||(u||(u=!0,l=M()),l),M=async()=>{if(i)return void n("Coordinator already initialized",{loaded:null!==i.contentWindow});n("Initializing coordinator iframe",{elementsBaseUrl:o.elementsBaseUrl}),i=document.createElement("iframe"),i.setAttribute("name","bt-coordinator"),i.setAttribute("title","BasisTheory Coordinator"),i.setAttribute("role","none"),i.style.border="none",i.style.width="0",i.style.height="0",i.style.position="absolute",i.style.top="-9999px",i.style.left="-9999px";const t=o.elementsBaseUrl.endsWith("/")?o.elementsBaseUrl:`${o.elementsBaseUrl}/`,r=new URL("coordinator.html",t);r.searchParams.set("parentOrigin",window.location.origin),i.src=r.toString(),document.body.appendChild(i),n("Coordinator iframe mounted",{url:i.src}),await new Promise((e,t)=>{const r=setTimeout(()=>{t(new Error(`Coordinator load timeout (${o.timeoutMs}ms). Try increasing timeoutMs for slow connections.`))},o.timeoutMs);i.addEventListener("load",()=>{clearTimeout(r),n("Coordinator iframe loaded"),e()},{once:!0})}),s=k(i,{targetOrigin:new URL(o.elementsBaseUrl).origin,timeout:3e4,retries:3,debug:o.debug||!1}),n("Coordinator PostMessage client created"),await s.sendRequest("CMD_SET_CONFIG",{apiKey:e,apiBaseUrl:o.apiBaseUrl,apiTimeout:3e4,apiRetries:3,debug:o.debug||!1,theme:o.theme,darkTheme:o.darkTheme,themeMode:o.themeMode}),n("Coordinator initialized successfully")},R={createElement:(t,r)=>{const s=w[t],l=E[t];if(!s&&!l)throw p(`Unknown element type: ${t}`);r&&((e,t={})=>{if(U(`ElementOptions (${e})`,t,$[e]),void 0!==t.placeholder)if("card"===e){if("object"!=typeof t.placeholder||null===t.placeholder)throw p("placeholder for card element must be an object with cardNumber, expiryDate, and cvv keys")}else if("string"!=typeof t.placeholder)throw p("placeholder must be a string");if(void 0!==t.disabled&&"boolean"!=typeof t.disabled)throw p("disabled must be a boolean");if(void 0!==t.readOnly&&"boolean"!=typeof t.readOnly)throw p("readOnly must be a boolean");if(void 0!==t.ariaLabel&&"string"!=typeof t.ariaLabel)throw p("ariaLabel must be a string");if("text"===e){if(void 0!==t.maxLength&&("number"!=typeof t.maxLength||t.maxLength<=0))throw p("maxLength must be a positive number");if(void 0!==t.password&&"boolean"!=typeof t.password)throw p("password must be a boolean");if(void 0!==t.required&&"boolean"!=typeof t.required)throw p("required must be a boolean");if(void 0!==t.validation&&!(t.validation instanceof RegExp))throw p("validation must be a RegExp");if(t.transform&&!(Array.isArray(t.transform)&&2===t.transform.length&&t.transform[0]instanceof RegExp&&"string"==typeof t.transform[1]))throw p('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]')}if("copyButton"===e&&!0!==t.allowClipboard)throw p("CopyButton requires allowClipboard: true. Clipboard access for raw card data may not be PCI compliant and must be explicitly enabled.");if("card"===e){const e=t;if(void 0!==e.layout&&!["row","column","auto"].includes(e.layout))throw p('layout must be "row", "column", or "auto"');if(void 0!==e.stackAt&&("number"!=typeof e.stackAt||e.stackAt<=0))throw p("stackAt must be a positive number");if(void 0!==e.iconPosition&&!["left","right","none"].includes(e.iconPosition))throw p('iconPosition must be "left", "right", or "none"');if(void 0!==e.cardBrands){if(!Array.isArray(e.cardBrands))throw p("cardBrands must be an array of strings");if(e.cardBrands.some(e=>"string"!=typeof e))throw p("All cardBrands must be strings")}}})(t,r);const d=`${t}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;let u;if(n("Creating element (sync)",{type:t,elementId:d,coordinatorInitialized:null!==i,isLazyLoaded:!!l}),s)u=s(e,o,r,d,v,y);else{let n=null,a=null;const i=async()=>{a||(a=(async()=>{const t=await l();n=t(e,o,r,d,v,y)})()),await a};u={id:d,type:t,get mounted(){return(null==n?void 0:n.mounted)??!1},get fields(){return null==n?void 0:n.fields},mount:async e=>(await i(),n.mount(e)),unmount:()=>{if(!n)throw h("Element not initialized");return n.unmount()},update:async e=>{if(!n)throw h("Element not initialized");return n.update(e)},focus:()=>{if(!n)throw h("Element not initialized");return n.focus()},blur:()=>{if(!n)throw h("Element not initialized");return n.blur()},clear:()=>{if(!n)throw h("Element not initialized");return n.clear()},on:(e,t)=>n?n.on(e,t):(i().then(()=>n.on(e,t)),()=>{}),setValueRef:async e=>{if(n||await i(),n&&"setValueRef"in n&&"function"==typeof n.setValueRef)return n.setValueRef(e);throw h("setValueRef not available on this element type")}}}return a.set(u.id,u),"cardNumber"===t&&u.on("change",e=>{const{cardBrand:t,cvvLengths:r}=e.detail;if(n("Card number change event received",{cardBrand:t,cvvLengths:r,cvvElementsCount:Array.from(a.values()).filter(e=>"cvv"===e.type).length}),t&&"Unknown"!==t&&r)for(const[o,i]of a)"cvv"===i.type&&i.mounted&&(n("Coordinating CVV element with card brand",{cvvElementId:o,cardBrand:t,cvvLengths:r,mounted:i.mounted}),i.update({cardBrand:t,cvvLengths:r}).catch(e=>{n("Failed to update CVV element with card brand",{cvvElementId:o,cardBrand:t,error:e.message})}))}),u},tokenize:async(e,t)=>{if(n("tokenize called",{hasPayload:!!e,hasOptions:!!t,coordinatorReady:!!s}),s||(n("Waiting for coordinator initialization"),await M()),!s)throw f("Coordinator failed to initialize");try{const r=e?P(e):{};n("Element references resolved",{originalPayload:!!e,resolvedPayload:!!r}),n("Delegating tokenization to coordinator");const o=await s.sendRequest("CMD_TOKENIZE",{payload:r,options:t});return n("tokenize successful",{tokenId:o.id}),o}catch(r){throw n("tokenize failed",{error:r.message}),r}},tokens:{create:async e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw c("Token data must be a non-null object");if(n("tokens.create called",{type:e.type,hasData:!!e.data}),s||(n("Waiting for coordinator initialization"),await M()),!s)throw new Error("Coordinator failed to initialize");try{const t={...e,data:P(e.data)};n("Element references resolved for tokens.create",{resolvedData:!!t});const r=await s.sendRequest("CMD_TOKENS_CREATE",{data:t});return n("tokens.create successful",{tokenId:r.id}),r}catch(t){throw n("tokens.create failed",{error:t.message}),t}},retrieve:async(e,t)=>{if(n("tokens.retrieve called",{tokenId:e,hasSessionKey:!!(null==t?void 0:t.apiKey)}),s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKENS_RETRIEVE",{id:e,apiKey:null==t?void 0:t.apiKey});return n("tokens.retrieve successful",{tokenId:r.id}),r}catch(r){throw n("tokens.retrieve failed",{error:r.message}),r}},update:async(e,t)=>{if(n("tokens.update called",{tokenId:e}),s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const r=t.data?{...t,data:P(t.data)}:t,o=await s.sendRequest("CMD_TOKENS_UPDATE",{id:e,data:r});return n("tokens.update successful",{tokenId:o.id}),o}catch(r){throw n("tokens.update failed",{error:r.message}),r}},encrypt:async(e,t,r)=>{if(n("tokens.encrypt called",{isSingleToken:"type"in e&&"data"in e,keyId:r}),!e||"object"!=typeof e)throw c("tokenData must be an object");if(!t||"string"!=typeof t)throw c("publicKeyPEM is required");if(!r||"string"!=typeof r)throw c("keyId is required");if(s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const o=P(e);n("Element references resolved for tokens.encrypt",{originalData:!!e,resolvedData:!!o});const a=await s.sendRequest("CMD_TOKENS_ENCRYPT",{tokenRequests:o,publicKeyPEM:t,keyId:r});return n("tokens.encrypt successful",{isSingleToken:"encrypted"in a&&"type"in a}),a}catch(o){throw n("tokens.encrypt failed",{error:o.message}),o}}},sessions:{create:async()=>{if(n("sessions.create called"),s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const e=await s.sendRequest("CMD_SESSIONS_CREATE",{});return n("sessions.create successful",{nonce:e.nonce,expiresAt:e.expires_at}),e}catch(e){throw n("sessions.create failed",{error:e.message}),e}}},tokenIntents:{create:async(e,t)=>{if(n("tokenIntents.create called",{type:e.type,hasData:!!e.data,hasOptions:!!t}),s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const r=P(e.data);n("Element references resolved for token intent");const o=await s.sendRequest("CMD_TOKEN_INTENTS_CREATE",{type:e.type,data:r,options:t});return n("tokenIntents.create successful",{intentId:o.id}),o}catch(r){throw n("tokenIntents.create failed",{error:r.message}),r}},get:async(e,t)=>{if(n("tokenIntents.get called",{intentId:e}),s||await M(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKEN_INTENTS_GET",{id:e,options:t});return n("tokenIntents.get successful",{intentId:r.id}),r}catch(r){throw n("tokenIntents.get failed",{error:r.message}),r}}},proxy:(()=>{const e=e=>t=>(async(e,t={})=>{if(T({...t,method:e}),n("proxy invoked",{method:e,hasUrl:!!t.url,hasProxyKey:!!t.proxyKey}),s||(n("Waiting for coordinator initialization"),await M()),!s)throw f("Coordinator failed to initialize");const r=void 0!==t.body?P(t.body):void 0;try{const o=await s.sendRequest("CMD_PROXY",{method:e,url:t.url,proxyKey:t.proxyKey,headers:t.headers,body:r,includeResponseHeaders:t.includeResponseHeaders},{retries:0});return n("proxy successful",{method:e}),o}catch(o){throw n("proxy failed",{method:e,error:o.message}),o}})(e,t??{});return{get:e("GET"),post:e("POST"),put:e("PUT"),patch:e("PATCH"),delete:e("DELETE")}})(),updateThemeMode:async e=>{n("updateThemeMode called",{oldMode:m,newMode:e,mountedElements:Array.from(a.values()).filter(e=>e.mounted).length}),m=e;const t=[];for(const[r,o]of a)if(o.mounted){n("Sending theme mode update to element",{elementId:r,elementType:o.type,mode:e});const a=document.querySelector(`iframe[data-bt-element-id="${o.id}"]`);a&&a.setAttribute("data-theme-mode",e);const i=o.update({themeMode:e}).catch(e=>{n("Failed to update theme mode for element",{elementId:r,error:e.message})});t.push(i)}await Promise.all(t),n("Theme mode updated for all mounted elements",{mode:e,updatedCount:Array.from(a.values()).filter(e=>e.mounted).length})}};if(r&&r.length>0){n("Draining command queue from loader",{queueLength:r.length,commands:r.map(e=>e.method)});for(const e of r)try{const t=R[e.method];if(!t)throw new Error(`Unknown method: ${e.method}`);n("Replaying queued command",{method:e.method,argsCount:e.args.length});const r=t(...e.args);r&&"function"==typeof r.then?r.then(t=>{n("Queued command completed (async)",{method:e.method}),e.resolve(t)}).catch(t=>{n("Queued command failed (async)",{method:e.method,error:t.message}),e.reject(t)}):(n("Queued command completed (sync)",{method:e.method}),e.resolve(r))}catch(C){n("Queued command failed (sync)",{method:e.method,error:C.message}),e.reject(C)}n("Command queue drain complete",{processedCount:r.length})}return R};"undefined"!=typeof window&&"undefined"!=typeof document&&document.currentScript&&!window.BasisTheory&&(window.BasisTheory=z),"undefined"!=typeof window&&(window.__BasisTheorySDK__=z);const F=Object.freeze(Object.defineProperty({__proto__:null,createCardElement:(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,f=o,p="card",y=e=>({id:e,type:"card",get mounted(){return d},mount:()=>{throw h("Sub-field refs cannot be mounted independently")},unmount:()=>{},update:()=>Promise.resolve(),focus:()=>{},blur:()=>{},clear:()=>{},on:()=>()=>{}});return{id:f,type:p,get mounted(){return d},fields:{number:y(`${f}__number`),expiryDate:y(`${f}__expiry`),cvc:y(`${f}__cvc`)},mount:async o=>{if(d)throw h("Element is already mounted");if(u="string"==typeof o?document.querySelector(o):o,!u)throw h(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/card.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",f),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=x({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Input"}),i.setAttribute("data-bt-element-id",f),i.setAttribute("data-theme-mode",t.themeMode||"auto"),s=k(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=O({elementType:p,elementId:f,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,f,{elementType:p,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:f,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,...void 0!==r.style&&{style:r.style},disabled:r.disabled,readOnly:r.readOnly,layout:r.layout||"auto",stackAt:r.stackAt||400,iconPosition:r.iconPosition||"left",...void 0!==r.cardBrands&&{cardBrands:r.cardBrands},...void 0!==r.binLookup&&{binLookup:r.binLookup},...void 0!==r.coBadge&&{coBadge:r.coBadge},debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw h("Element is not mounted");const e=["__number","__expiry","__cvc"];for(const t of e)a(`${f}${t}`).catch(e=>{e.message});s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw h("Element must be mounted before updating");const r=e,o={elementId:f};void 0!==r.placeholder&&(o.placeholder=r.placeholder),void 0!==r.style&&(o.style=r.style),void 0!==r.disabled&&(o.disabled=r.disabled),void 0!==r.readOnly&&(o.readOnly=r.readOnly),void 0!==r.layout&&(o.layout=r.layout),void 0!==r.stackAt&&(o.stackAt=r.stackAt),void 0!==r.iconPosition&&(o.iconPosition=r.iconPosition),void 0!==r.cardBrands&&(o.cardBrands=r.cardBrands),void 0!==r.binLookup&&(o.binLookup=r.binLookup),void 0!==r.coBadge&&(o.coBadge=r.coBadge),void 0!==e.themeMode&&(o.themeMode=e.themeMode,o.theme=t.theme,o.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",o)},focus:()=>{if(!d||!s)throw h("Element must be mounted before focusing");s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw h("Element must be mounted before blurring");s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw h("Element must be mounted before clearing");s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t)),setNetwork:async e=>{if(!d||!s)throw h("Element must be mounted before setNetwork");await s.sendRequest("CMD_SET_NETWORK",{network:e})}}}},Symbol.toStringTag,{value:"Module"})),K=Object.freeze(Object.defineProperty({__proto__:null,createCopyButtonElement:(e,t,r,o,n,a)=>{const i=r;if(!0!==(null==i?void 0:i.allowClipboard))throw p("CopyButton requires allowClipboard: true. Clipboard access for raw card data may not be PCI compliant and must be explicitly enabled.",{received:null==i?void 0:i.allowClipboard,expected:!0,elementType:"copyButton"});let s=null,l=null,d=null,u=!1,m=null,c=null;const f=new EventTarget,y=o,g="copyButton";return{id:y,type:g,get mounted(){return u},mount:async e=>{if(u)throw h("Element is already mounted",y);if(m="string"==typeof e?document.querySelector(e):e,!m)throw h(`Container not found: ${e}`);const r=crypto.randomUUID(),o=window.location.origin,a=new URL(`${t.elementsBaseUrl}/copy-button.html`);a.searchParams.set("parentOrigin",o),a.searchParams.set("elementId",y),a.searchParams.set("signature",r),a.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),a.searchParams.set("debug",String(t.debug||!1)),s=x({src:a.toString(),sandbox:"allow-scripts allow-same-origin",allow:"clipboard-write",title:"Copy Button"}),s.setAttribute("data-bt-element-id",y),l=k(s,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),d={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},l&&(c=O({elementType:g,elementId:y,client:l,eventTarget:f}),c.setupSubscriptions(),l.subscribe("EVENT_COPY",e=>{const t=new CustomEvent("copy",{detail:{elementType:g,elementId:y,timestamp:Date.now(),success:(null==e?void 0:e.success)??!1,error:null==e?void 0:e.error}});f.dispatchEvent(t)}));const p=new Promise((e,r)=>{const o=setTimeout(()=>{r(h(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,y,{elementType:g,timeoutMs:t.timeoutMs}))},t.timeoutMs);f.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});d.mount(m,s,{timeoutMs:t.timeoutMs}),u=!0;try{await n(),await p,await l.sendRequest("CMD_SET_CONFIG",{elementId:y,signature:r,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,text:i.text||"Copy",value:i.value,disabled:i.disabled,debug:t.debug}),s&&(s.style.opacity="1")}catch(b){throw c&&c.dispatchError("MOUNT_ERROR",b.message,b),u=!1,l&&(l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),c=null,m=null,b}},unmount:()=>{if(!u)throw h("Element is not mounted");l&&(l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),c=null,m=null,u=!1},update:async e=>{if(!u||!l)throw h("Element must be mounted before updating",y);const r={},o=e;void 0!==o.text&&(r.text=o.text),void 0!==o.value&&(r.value=o.value),void 0!==o.disabled&&(r.disabled=o.disabled),void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await l.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!u||!l)throw h("Element must be mounted before focusing",y);l.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!u||!l)throw h("Element must be mounted before blurring",y);l.sendRequest("CMD_BLUR",{})},clear:()=>{},on:(e,t)=>(f.addEventListener(e,t),()=>f.removeEventListener(e,t)),setValueRef:async e=>{if(null==e||e.id,!e||!e.id)throw h("setValueRef requires a valid Element with an ID",y);if(!u||!l)throw h("Element must be mounted before calling setValueRef",y);await l.sendRequest("CMD_SET_VALUE_REF",{referenceElementId:e.id})}}}},Symbol.toStringTag,{value:"Module"}));e.buildDate="2026-06-09T15:35:24.276Z",e.default=z,e.version="3.0.0-beta.4",Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BasisTheory={})}(this,function(e){"use strict";const t=[/cardnumber/i,/^pan$/i,/accountnumber/i,/^number$/i],r=[/cvv/i,/cvc/i,/cvv2/i,/securitycode/i,/pin/i,/password/i,/secret/i,/token/i,/ssn/i,/track/i,/session_key/i,/^apikey$/i],o=e=>t.some(t=>t.test(e)),n=e=>r.some(t=>t.test(e)),a=e=>{const t=e.replace(/\D/g,"");if(t.length<10)return"***";const r=t.substring(0,6),o=t.substring(t.length-4),n=Math.max(t.length-10,6);return`${r}${"*".repeat(n)}${o}`},i=e=>{const t=e.replace(/[\s-]/g,"");return/^\d{13,19}$/.test(t)},s=(e,t)=>null==t?t:"function"==typeof t?"[Function]":"symbol"==typeof t?"[Symbol]":t instanceof RegExp?"[RegExp]":t instanceof Date?t:o(e)?"string"==typeof t?a(t):"***":n(e)?"***":"string"==typeof t&&i(t)?a(t):t,l=(e,t=0,r=new WeakSet)=>{if(t>=5)return"[Max Depth]";if(null==e)return e;if("string"==typeof e)return i(e)?a(e):e;if("object"!=typeof e)return e;if(e instanceof RegExp)return"[RegExp]";if(e instanceof Date)return e;if(r.has(e))return"[Circular]";let o;if(r.add(e),Array.isArray(e))o=e.map(e=>l(e,t+1,r));else{const n={};for(const[o,a]of Object.entries(e)){const e=s(o,a);n[o]=null!==e&&"object"==typeof e?l(e,t+1,r):e}o=n}return r.delete(e),o},d=(e,t)=>t?(t,r)=>{const a=(()=>{const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`})(),i=r?(e=>{const t={};for(const[r,a]of Object.entries(e))if(o(r)||n(r)){const e="string"==typeof a?a.length:"number"==typeof a?String(a).length:0;t[`${r}_length`]=e}else t[r]=l(a);return t})(r):{};console.log(`🔍 [${a}] [${e}] ${t}`,i)}:()=>{},u=()=>{if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();const e=()=>Math.random().toString(36).substring(2),t=(e()+e()+e()+e()).substring(0,32);return`${t.substring(0,8)}-${t.substring(8,12)}-${t.substring(12,16)}-${t.substring(16,20)}-${t.substring(20,32)}`},m=(e,t,r)=>{const o=new Error(t);return o.name="BasisTheoryError",o.code=e,o.details=r,Error.captureStackTrace&&Error.captureStackTrace(o,m),o.toJSON=()=>({name:o.name,code:o.code,message:o.message,...o.details&&{details:o.details}}),o},c=(e,t,r)=>{const o=m(e,t,r);return o.name="BasisTheoryError",o},h=(e,t,r)=>{const o=m("VALIDATION_ERROR",e,t?{field:t,...r}:r);return o.name="ValidationError",o.field=t,o},f=(e,t)=>{const r=m("COORDINATOR_ERROR",e,t);return r.name="CoordinatorError",r},p=(e,t,r)=>{const o=m("ELEMENT_ERROR",e,t?{elementId:t,...r}:r);return o.name="ElementError",o.elementId=t,o},y=(e,t)=>{const r=m("CONFIGURATION_ERROR",e,t);return r.name="ConfigurationError",r},g=new Set(["https:"]),b=new Set(["GET","POST","PUT","PATCH","DELETE"]),w=new Set(["host","content-length","transfer-encoding","te","trailer","connection","upgrade","keep-alive","proxy-connection","via","proxy-authorization","bt-api-key","bt-proxy-key","bt-proxy-url","bt-idempotency-key","x-forwarded-for","x-forwarded-host","x-real-ip","content-type"]),E=e=>{const t=e.replace(/^\[|\]$/g,"");if(/^(0x[\da-f]+|\d+)$/i.test(t)){const e=t.toLowerCase().startsWith("0x")?parseInt(t,16):parseInt(t,10);return e>=0&&e<=4294967295?[e>>>24&255,e>>>16&255,e>>>8&255,255&e]:null}const r=t.split(".");if(4!==r.length)return null;const o=[];for(const n of r){let e;if(e=n.toLowerCase().startsWith("0x")?parseInt(n,16):n.startsWith("0")&&n.length>1&&!/[89]/.test(n)?parseInt(n,8):parseInt(n,10),isNaN(e)||e<0||e>255)return null;o.push(e)}return o},v=e=>{const t=e[0],r=e[1];return void 0===t||void 0===r||127===t||10===t||172===t&&r>=16&&r<=31||192===t&&168===r||169===t&&254===r||0===t},T=e=>{const t=e.replace(/^\[|\]$/g,"").toLowerCase();if("::1"===t||"0:0:0:0:0:0:0:1"===t||"0000:0000:0000:0000:0000:0000:0000:0001"===t)return!0;if(t.startsWith("fe8")||t.startsWith("fe9")||t.startsWith("fea")||t.startsWith("feb"))return!0;if(t.startsWith("fc")||t.startsWith("fd"))return!0;const r=t.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);if(r){const e=r[1];if(e){const t=E(e);if(t&&v(t))return!0}}const o=t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);if(o){const e=o[1],t=o[2];if(!e||!t)return!0;const r=parseInt(e,16),n=parseInt(t,16);if(v([r>>>8&255,255&r,n>>>8&255,255&n]))return!0}return!1},R=e=>{if(void 0!==e&&("object"!=typeof e||null===e))throw h("Proxy options must be a plain object","options");if(void 0!==(null==e?void 0:e.method)&&!b.has(e.method))throw h(`Method '${e.method}' is not allowed`,"method");((e,t)=>{const r="string"==typeof e&&e.length>0;if(r===("string"==typeof t&&t.length>0))throw h("Specify exactly one of url or proxyKey","url/proxyKey");r&&(e=>{let t;try{t=new URL(e)}catch{throw h("Invalid URL format","url")}if(!g.has(t.protocol))throw h(`URL scheme '${t.protocol}' is not allowed. Only https: is permitted`,"url");(e=>{const t=e.hostname.toLowerCase();if(e.username||e.password)throw h("URL must not contain userinfo (username/password)","url");if("localhost"===t)throw h("URL must not target localhost","url");if((t.startsWith("[")||T(t))&&T(t))throw h("URL must not target loopback or link-local IPv6 addresses","url");const r=E(t);if(r&&v(r))throw h("URL must not target private or internal IP addresses","url")})(t)})(e)})(null==e?void 0:e.url,null==e?void 0:e.proxyKey),(e=>{if(e)for(const[t,r]of Object.entries(e)){if(/[\r\n]/.test(r))throw h(`Header '${t}' value contains illegal CRLF`,"headers");if(/[\r\n]/.test(t))throw h(`Header name '${t}' contains illegal CRLF`,"headers");if(w.has(t.toLowerCase().trim()))throw h(`Header '${t}' is not allowed in proxy requests`,"headers")}})(null==e?void 0:e.headers)},C={maxRetries:2,initialDelay:500,maxDelay:3e3,backoffFactor:2},M=(e,t)=>{const r=t.initialDelay*Math.pow(t.backoffFactor,e);return Math.min(r,t.maxDelay)},k=e=>new Promise(t=>setTimeout(t,e)),O=(e,t)=>{const r=new Map,o=new Map,n=d("PostMessageClient",t.debug||!1),a=a=>{const{nonce:i,type:s,payload:l,error:d}=a.data||{};if(!s)return;if(a.origin!==t.targetOrigin)return void n("Rejected message (origin mismatch)",{receivedOrigin:a.origin,expectedOrigin:t.targetOrigin,messageType:s});if(a.source!==e.contentWindow)return;if(i){const e=r.get(i);if(e){if(n("Message received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i}),clearTimeout(e.timeout),r.delete(i),d){const t=c(d.code,`[${d.code}] ${d.message}`);Object.assign(t,{...void 0!==d.status&&{status:d.status},...void 0!==d.statusCode&&{statusCode:d.statusCode},...d.validationErrors&&{validationErrors:d.validationErrors},...d.body&&{body:d.body},...void 0!==d.retryCount&&{retryCount:d.retryCount},...d.details&&{details:d.details}}),e.reject(t)}else e.resolve(l);return}return}const u=o.get(s);u&&u.size>0?(n("Event received",{origin:a.origin,expectedOrigin:t.targetOrigin,type:s,nonce:i,subscriberCount:u.size}),u.forEach(e=>{try{e(l)}catch(t){n("Error in event subscriber",{type:s,error:t.message})}})):i||n("Event received but no subscribers",{type:s,availableSubscribers:Array.from(o.keys())})};window.addEventListener("message",a);const i="number"==typeof t.retries?{...C,maxRetries:t.retries}:"object"==typeof t.retries?t.retries:C,s=(o,a)=>new Promise((i,s)=>{const l=u(),d=Date.now();if(!e.contentWindow)return void s(c("IFRAME_NOT_READY","Iframe not ready"));const m=setTimeout(()=>{r.delete(l),s(c("REQUEST_TIMEOUT",`Request timeout: ${o} (${t.timeout||5e3}ms)`))},t.timeout||5e3);r.set(l,{resolve:i,reject:s,timeout:m,timestamp:d}),n("Sending request",{type:o,nonce:l}),e.contentWindow.postMessage({type:o,nonce:l,timestamp:d,payload:a},t.targetOrigin)});return{sendRequest:async(e,t,r)=>{const o=void 0!==(null==r?void 0:r.retries)?r.retries:i.maxRetries;let a=null;for(let d=0;d<=o;d++)try{return await s(e,t)}catch(l){a=l;const e=l.message;if(e.startsWith("[HANDLER_ERROR]")||"Client destroyed"===e||"Iframe not ready"===e)throw n("Not retrying error",{error:e,reason:"Non-retriable error"}),l;if(d<o){const t=M(d,i);n("Retrying request",{attempt:d+1,maxRetries:o,delayMs:t,error:e}),await k(t)}}throw a||new Error(`Request failed after ${o} retries: ${e}`)},ping:async(o=1e3)=>{const a=Date.now();n("Starting health check",{timeoutMs:o,iframeReady:!!e.contentWindow,targetOrigin:t.targetOrigin});try{await s("SYS_PING",void 0);const e=Date.now()-a;return n("Health check passed",{latencyMs:e}),e}catch(i){const e=`Health check failed after ${Date.now()-a}ms: ${i.message}. Target: ${t.targetOrigin}`;throw t.debug&&(n(`❌ [PostMessage Client] ${e}`),n(`📊 [PostMessage Client] Pending requests: ${r.size}`)),c("HEALTH_CHECK_FAILED",e)}},subscribe:(e,t)=>(o.has(e)||o.set(e,new Set),o.get(e).add(t),()=>{const r=o.get(e);r&&(r.delete(t),0===r.size&&o.delete(e))}),destroy:()=>{window.removeEventListener("message",a),r.forEach(({timeout:e,reject:t})=>{clearTimeout(e),t(c("CLIENT_DESTROYED","Client destroyed"))}),r.clear(),o.clear()},getPendingCount:()=>r.size}},_=e=>{const t=document.createElement("iframe");return t.src=e.src,t.setAttribute("sandbox",e.sandbox),t.title=e.title,t.setAttribute("allow",e.allow??"payment *"),t.setAttribute("importance","high"),t.style.opacity="0",t},x=e=>{const{elementType:t,elementId:r,client:o,eventTarget:n}=e,a=(e,o)=>{const a=new CustomEvent(e,{detail:{elementType:t,elementId:r,timestamp:Date.now(),...o}});n.dispatchEvent(a)};return{setupSubscriptions:()=>{o.subscribe("EVENT_READY",()=>{a("ready",{})}),o.subscribe("EVENT_VALUE_CHANGED",e=>{const r={isValid:e.isValid,isEmpty:e.isEmpty,error:e.error||null};if("cardNumber"===t){const t={...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,cvvLengths:e.cvvLengths,potentialBrands:e.potentialBrands,matchStrength:e.matchStrength,networks:e.networks,selectedNetwork:e.selectedNetwork};a("change",t)}else a("change","card"===t?{...r,cardBrand:e.cardBrand,last4:e.last4,bin:e.bin,networks:e.networks,selectedNetwork:e.selectedNetwork,errors:e.errors||null}:r)}),o.subscribe("EVENT_NETWORK_CHANGED",e=>{if("cardNumber"!==t&&"card"!==t)return;const r={network:e.network,previousNetwork:e.previousNetwork,availableNetworks:e.availableNetworks??[],selectionMode:e.selectionMode??"auto"};a("networkChanged",r)}),o.subscribe("EVENT_FOCUS",()=>{a("focus",{})}),o.subscribe("EVENT_BLUR",()=>{a("blur",{})}),o.subscribe("EVENT_ERROR",e=>{a("error",{code:e.code,message:e.message,status:e.status,validationErrors:e.validationErrors,metadata:e.metadata||{}})})},dispatchError:(e,t,r)=>{a("error",{code:e,message:t,metadata:{source:"initialization",originalError:r}})}}},S=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,h=o,f="cardNumber";return{id:h,type:f,get mounted(){return d},get loaded(){return d},mount:async o=>{if(d)throw p("Element is already mounted");if(u="string"==typeof o?document.querySelector(o):o,!u)throw p(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/card-number.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",h),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=_({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Number Input"}),i.setAttribute("data-bt-element-id",h),i.setAttribute("data-theme-mode",t.themeMode||"auto"),s=O(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=x({elementType:f,elementId:h,client:s,eventTarget:c}),m.setupSubscriptions(),s.subscribe("EVENT_CONTENT_HEIGHT",e=>{const t=null==e?void 0:e.heightPx;i&&"number"==typeof t&&t>0&&(i.style.height=`${Math.ceil(t)}px`)}));const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,h,{elementType:f,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:h,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug,binLookup:r.binLookup,coBadge:r.coBadge}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw p("Element is not mounted");a(h).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(i.style.height="",l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw p("Element must be mounted before updating");const r={elementId:h};void 0!==e.placeholder&&(r.placeholder=e.placeholder),void 0!==e.disabled&&(r.disabled=e.disabled),void 0!==e.readOnly&&(r.readOnly=e.readOnly),void 0!==e.binLookup&&(r.binLookup=e.binLookup),void 0!==e.coBadge&&(r.coBadge=e.coBadge),void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw p("Element must be mounted before focusing");s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw p("Element must be mounted before blurring");s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw p("Element must be mounted before clearing");s.sendRequest("CMD_CLEAR",{})},setNetwork:async e=>{if(!d||!s)throw p("Element must be mounted before setNetwork");await s.sendRequest("CMD_SET_NETWORK",{network:e})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},I=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,h=o,f="cvv";return{id:h,type:f,get mounted(){return d},get loaded(){return d},mount:async o=>{if(d)throw p("Element is already mounted",h);if(u="string"==typeof o?document.querySelector(o):o,!u)throw p(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/cvv.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",h),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=_({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"CVV Input"}),i.setAttribute("data-bt-element-id",h),s=O(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=x({elementType:f,elementId:h,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,h,{elementType:f,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:h,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,showToggle:r.showToggle,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw p("Element is not mounted");a(h).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw p("Element must be mounted before updating",h);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,cardBrand:e.cardBrand,cvvLengths:e.cvvLengths};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw p("Element must be mounted before focusing",h);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw p("Element must be mounted before blurring",h);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw p("Element must be mounted before clearing",h);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},D=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,h=o,f="expiry";return{id:h,type:f,get mounted(){return d},get loaded(){return d},mount:async o=>{if(d)throw p("Element is already mounted",h);if(u="string"==typeof o?document.querySelector(o):o,!u)throw p(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/expiry.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",h),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=_({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Expiry Date Input"}),i.setAttribute("data-bt-element-id",h),s=O(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=x({elementType:f,elementId:h,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,h,{elementType:f,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:h,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw p("Element is not mounted");a(h).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw p("Element must be mounted before updating",h);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw p("Element must be mounted before focusing",h);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw p("Element must be mounted before blurring",h);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw p("Element must be mounted before clearing",h);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},L=(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,h=o,f="text";if(r.transform&&!(Array.isArray(r.transform)&&2===r.transform.length&&r.transform[0]instanceof RegExp&&"string"==typeof r.transform[1]))throw new TypeError('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]');return{id:h,type:f,get mounted(){return d},get loaded(){return d},mount:async o=>{if(d)throw p("Element is already mounted",h);if(u="string"==typeof o?document.querySelector(o):o,!u)throw p(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/text.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",h),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=_({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Text Input"}),i.setAttribute("data-bt-element-id",h),s=O(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=x({elementType:f,elementId:h,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,h,{elementType:f,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g;const o=r.transform?{pattern:r.transform[0].source,flags:r.transform[0].flags,replacement:r.transform[1]}:void 0,a=r.mask?r.mask.map(e=>"string"==typeof e?e:e instanceof RegExp?{source:e.source,flags:e.flags}:e):void 0;await s.sendRequest("CMD_SET_CONFIG",{elementId:h,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,placeholder:r.placeholder,disabled:r.disabled,readOnly:r.readOnly,validation:r.validation,required:r.required,maxLength:r.maxLength,password:r.password,inputMode:r.inputMode,mask:a,transform:o,debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw p("Element is not mounted");a(h).catch(e=>{e.message}),s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw p("Element must be mounted before updating",h);const r={placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readOnly,required:e.required,maxLength:e.maxLength,password:e.password,inputMode:e.inputMode};void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!d||!s)throw p("Element must be mounted before focusing",h);s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw p("Element must be mounted before blurring",h);s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw p("Element must be mounted before clearing",h);s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t))}},A=e=>{if((e=>null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e)(e))return e;if((e=>{if("object"!=typeof e||null===e)return!1;const t=e;return"function"==typeof t.mount&&"function"==typeof t.update&&"function"==typeof t.on})(e)){if(!e.id)throw p("Element is missing id property. Ensure createElement is called after the SDK loads and all elements are mounted before calling tokenize().");return e.id}if(Array.isArray(e))return e.map(A);if("object"==typeof e&&null!==e){const t={};for(const[r,o]of Object.entries(e))t[r]=A(o);return t}return e},P={colors:{primary:"#3b82f6",error:"#ef4444",success:"#10b981",text:{primary:"#1f2937",secondary:"#6b7280",placeholder:"#9ca3af",disabled:"#d1d5db"},background:{default:"#ffffff",hover:"#f9fafb",focus:"#eff6ff",disabled:"#f9fafb"},border:{default:"#d1d5db",hover:"#9ca3af",focus:"#3b82f6",error:"#ef4444"}},typography:{fontFamily:'"Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:{sm:"14px",base:"16px",lg:"18px"},fontWeight:{normal:"400",medium:"500",semibold:"600"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.75"}},spacing:{xs:"4px",sm:"8px",md:"12px",lg:"16px",xl:"24px"},borders:{radius:{none:"0",sm:"2px",base:"4px",md:"6px",lg:"8px",full:"9999px"},width:{thin:"1px",base:"2px",thick:"3px"}},shadows:{none:"none",sm:"0 1px 2px 0 rgba(0, 0, 0, 0.05)",base:"0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",lg:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",focus:"0 0 0 3px rgba(59, 130, 246, 0.1)"},transitions:{fast:"150ms cubic-bezier(0.4, 0, 0.2, 1)",base:"200ms cubic-bezier(0.4, 0, 0.2, 1)",slow:"300ms cubic-bezier(0.4, 0, 0.2, 1)"}},U=e=>{var t,r,o,n,a,i,s,l,d,u,m;return e?{colors:{primary:(null==(t=e.colors)?void 0:t.primary)??P.colors.primary,error:(null==(r=e.colors)?void 0:r.error)??P.colors.error,success:(null==(o=e.colors)?void 0:o.success)??P.colors.success,text:{...P.colors.text,...null==(n=e.colors)?void 0:n.text},background:{...P.colors.background,...null==(a=e.colors)?void 0:a.background},border:{...P.colors.border,...null==(i=e.colors)?void 0:i.border}},typography:{...P.typography,...e.typography,fontSize:{...P.typography.fontSize,...null==(s=e.typography)?void 0:s.fontSize},fontWeight:{...P.typography.fontWeight,...null==(l=e.typography)?void 0:l.fontWeight},lineHeight:{...P.typography.lineHeight,...null==(d=e.typography)?void 0:d.lineHeight}},spacing:{...P.spacing,...e.spacing},borders:{radius:{...P.borders.radius,...null==(u=e.borders)?void 0:u.radius},width:{...P.borders.width,...null==(m=e.borders)?void 0:m.width}},shadows:{...P.shadows,...e.shadows},transitions:{...P.transitions,...e.transitions}}:P},N=(e,t,r,o)=>{for(const n of Object.keys(t))r.has(n)||((null==o?void 0:o.has(n))?console.warn(`[BasisTheory] Deprecated option "${n}" in ${e}. ${o.get(n)}`):console.warn(`[BasisTheory] Unknown option "${n}" in ${e}. This option will be ignored. See https://developers.basistheory.com/docs/ for supported options.`))},B=new Set(["elementsBaseUrl","whitelabelDomain","apiBaseUrl","debug","measurePerformance","timeoutMs","retryConfig","themeMode","theme","darkTheme","sessionAuthorizationUrl"]),$=new Map([["iframeOrigin",'Use "elementsBaseUrl" instead.']]),q=new Set(["placeholder","ariaLabel","disabled","readOnly"]),z={cardNumber:new Set([...q,"binLookup","coBadge"]),cvv:new Set([...q,"cardBrand","cvvLengths"]),expiry:new Set([...q]),text:new Set([...q,"validation","required","maxLength","password","inputMode","mask","transform"]),card:new Set([...q,"layout","stackAt","iconPosition","cardBrands","binLookup","coBadge"]),copyButton:new Set(["allowClipboard","value","text","disabled"]),cardDisplay:new Set(["tokenId","number","cvc","expiration"])},F=(e,t={},r)=>{(e=>{if(!e||"string"!=typeof e||0===e.trim().length)throw y("API key is required")})(e);const o=((e={})=>{var t,r,o;N("SDKOptions",e,B,$);const n=e.elementsBaseUrl||e.iframeOrigin;if(void 0!==n){if("string"!=typeof n||0===n.trim().length)throw y("elementsBaseUrl must be a non-empty string");try{new URL(n)}catch{throw y("elementsBaseUrl must be a valid URL")}}if(void 0!==e.apiBaseUrl){if("string"!=typeof e.apiBaseUrl||0===e.apiBaseUrl.trim().length)throw y("apiBaseUrl must be a non-empty string");try{new URL(e.apiBaseUrl)}catch{throw y("apiBaseUrl must be a valid URL")}}if(void 0!==e.debug&&"boolean"!=typeof e.debug)throw y("debug must be a boolean");if(void 0!==e.measurePerformance&&"boolean"!=typeof e.measurePerformance)throw y("measurePerformance must be a boolean");if(void 0!==e.timeoutMs&&("number"!=typeof e.timeoutMs||e.timeoutMs<=0))throw y("timeoutMs must be a positive number");const a={maxRetries:(null==(t=e.retryConfig)?void 0:t.maxRetries)??3,delayMs:(null==(r=e.retryConfig)?void 0:r.delayMs)??1e3,backoffFactor:(null==(o=e.retryConfig)?void 0:o.backoffFactor)??2};if("number"!=typeof a.maxRetries||a.maxRetries<0)throw y("maxRetries must be a non-negative number");if("number"!=typeof a.delayMs||a.delayMs<=0)throw y("retryConfig.delayMs must be a positive number");if("number"!=typeof a.backoffFactor||a.backoffFactor<1)throw y("retryConfig.backoffFactor must be >= 1");const i=e.themeMode||"auto";if(!["light","dark","auto"].includes(i))throw y('themeMode must be "light", "dark", or "auto"');if(void 0!==e.sessionAuthorizationUrl){if("string"!=typeof e.sessionAuthorizationUrl||""===e.sessionAuthorizationUrl.trim())throw y("sessionAuthorizationUrl must be a non-empty string");try{const t=new URL(e.sessionAuthorizationUrl,window.location.origin);if("http:"===t.protocol&&"localhost"!==t.hostname&&"127.0.0.1"!==t.hostname)throw y("sessionAuthorizationUrl must use https://.")}catch(d){if(d instanceof Error&&"ConfigurationError"===d.name)throw d}}let s=n;if(void 0===s&&void 0!==e.whitelabelDomain){const{whitelabelDomain:t}=e;if("string"!=typeof t||0===t.trim().length)throw y("whitelabelDomain must be a non-empty string");let r;try{const e=new URL(t);if("https:"!==e.protocol)throw y("whitelabelDomain must use https://");r=e.origin}catch(d){if(d instanceof Error&&"ConfigurationError"===d.name)throw d;throw y("whitelabelDomain must be a valid URL")}const{pathname:o}=new URL("https://js.basistheory.com/3.0.0-beta.5/elements");s=`${r}${o}`}const l=s||"https://js.basistheory.com/3.0.0-beta.5/elements";return{iframeOrigin:new URL(l).origin,elementsBaseUrl:l,apiBaseUrl:e.apiBaseUrl,debug:e.debug??!1,measurePerformance:e.measurePerformance??!1,timeoutMs:e.timeoutMs||3e4,themeMode:i,theme:U(e.theme),darkTheme:e.darkTheme?U(e.darkTheme):void 0,retryConfig:a,sessionAuthorizationUrl:e.sessionAuthorizationUrl}})(t),n=d("SDK",o.debug||!1);n("SDK initialized",{apiKeyPrefix:e.substring(0,7)+"...",elementsBaseUrl:o.elementsBaseUrl,iframeOrigin:o.iframeOrigin,debug:o.debug||!1});const a=new Map;let i=null,s=null,l=null,u=!1,m=null,c=null,g=!1;const b=()=>{if(g)throw y("SDK instance has been destroyed. Create a new instance with BasisTheory()")},w=e=>async(...t)=>(b(),e(...t));let E=t.themeMode||"auto";const v=async e=>{if(s)try{await s.sendRequest("CMD_BROADCAST_ELEMENT_UNMOUNT",{elementId:e}),n("Notified coordinator of element unmount",{elementId:e})}catch(t){n("Failed to notify coordinator of element unmount",{elementId:e,error:t.message})}else n("Cannot notify coordinator of unmount - coordinator not initialized",{elementId:e})},T=async(e,t)=>{if(!s)throw f("Coordinator not initialized");return s.sendRequest(e,t)};let C=null,M=null,k=null;const _={cardNumber:S,cvv:I,expiry:D,text:L},x={card:async()=>{if(!C){const e=await Promise.resolve().then(()=>K);C=e.createCardElement}return C},copyButton:async()=>{if(!M){const e=await Promise.resolve().then(()=>V);M=e.createCopyButtonElement}return M},cardDisplay:async()=>{if(!k){const e=await Promise.resolve().then(()=>j);k=e.createCardDisplayElement}return k}},P=()=>l||(u||(u=!0,l=q()),l),q=async()=>{if(i)return void n("Coordinator already initialized",{loaded:null!==i.contentWindow});n("Initializing coordinator iframe",{elementsBaseUrl:o.elementsBaseUrl}),i=document.createElement("iframe"),i.setAttribute("name","bt-coordinator"),i.setAttribute("title","BasisTheory Coordinator"),i.setAttribute("role","none"),i.style.border="none",i.style.width="0",i.style.height="0",i.style.position="absolute",i.style.top="-9999px",i.style.left="-9999px";const t=o.elementsBaseUrl.endsWith("/")?o.elementsBaseUrl:`${o.elementsBaseUrl}/`,r=new URL("coordinator.html",t);r.searchParams.set("parentOrigin",window.location.origin),i.src=r.toString(),document.body.appendChild(i),n("Coordinator iframe mounted",{url:i.src}),await new Promise((e,t)=>{c=t,m=setTimeout(()=>{m=null,c=null,t(new Error(`Coordinator load timeout (${o.timeoutMs}ms). Try increasing timeoutMs for slow connections.`))},o.timeoutMs),i.addEventListener("load",()=>{null!==m&&clearTimeout(m),m=null,c=null,n("Coordinator iframe loaded"),e()},{once:!0})}),g?n("Coordinator load resolved after destroy — aborting init"):(s=O(i,{targetOrigin:new URL(o.elementsBaseUrl).origin,timeout:3e4,retries:3,debug:o.debug||!1}),n("Coordinator PostMessage client created"),await s.sendRequest("CMD_SET_CONFIG",{apiKey:e,apiBaseUrl:o.apiBaseUrl,apiTimeout:3e4,apiRetries:3,debug:o.debug||!1,theme:o.theme,darkTheme:o.darkTheme,themeMode:o.themeMode}),n("Coordinator initialized successfully"))},F={createElement:(W=(t,r)=>{const s=_[t],l=x[t];if(!s&&!l)throw y(`Unknown element type: ${t}`);r&&((e,t={})=>{if(N(`ElementOptions (${e})`,t,z[e]),void 0!==t.placeholder)if("card"===e){if("object"!=typeof t.placeholder||null===t.placeholder)throw y("placeholder for card element must be an object with cardNumber, expiryDate, and cvv keys")}else if("string"!=typeof t.placeholder)throw y("placeholder must be a string");if(void 0!==t.disabled&&"boolean"!=typeof t.disabled)throw y("disabled must be a boolean");if(void 0!==t.readOnly&&"boolean"!=typeof t.readOnly)throw y("readOnly must be a boolean");if(void 0!==t.ariaLabel&&"string"!=typeof t.ariaLabel)throw y("ariaLabel must be a string");if("text"===e){if(void 0!==t.maxLength&&("number"!=typeof t.maxLength||t.maxLength<=0))throw y("maxLength must be a positive number");if(void 0!==t.password&&"boolean"!=typeof t.password)throw y("password must be a boolean");if(void 0!==t.required&&"boolean"!=typeof t.required)throw y("required must be a boolean");if(void 0!==t.validation&&!(t.validation instanceof RegExp))throw y("validation must be a RegExp");if(t.transform&&!(Array.isArray(t.transform)&&2===t.transform.length&&t.transform[0]instanceof RegExp&&"string"==typeof t.transform[1]))throw y('transform must be a tuple of [RegExp, string]. Example: [/-/g, ""]')}if("copyButton"===e&&!0!==t.allowClipboard)throw y("CopyButton requires allowClipboard: true. Clipboard access for raw card data may not be PCI compliant and must be explicitly enabled.");if("card"===e){const e=t;if(void 0!==e.layout&&!["row","column","auto"].includes(e.layout))throw y('layout must be "row", "column", or "auto"');if(void 0!==e.stackAt&&("number"!=typeof e.stackAt||e.stackAt<=0))throw y("stackAt must be a positive number");if(void 0!==e.iconPosition&&!["left","right","none"].includes(e.iconPosition))throw y('iconPosition must be "left", "right", or "none"');if(void 0!==e.cardBrands){if(!Array.isArray(e.cardBrands))throw y("cardBrands must be an array of strings");if(e.cardBrands.some(e=>"string"!=typeof e))throw y("All cardBrands must be strings")}}})(t,r);const d=`${t}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;let u;return n("Creating element (sync)",{type:t,elementId:d,coordinatorInitialized:null!==i,isLazyLoaded:!!l}),u=s?s(e,o,r,d,P,v,T):((e,t,r,o,n,a,i,s,l)=>{let d=null,u=null;const m=async()=>{u||(u=(async()=>{const t=await e();d=t(o,n,a,r,i,s,l)})()),await u},c=()=>{if(!d)throw p("Element not initialized");return d},h={id:r,type:t,get mounted(){return(null==d?void 0:d.mounted)??!1},get loaded(){return(null==d?void 0:d.loaded)??!1},mount:async e=>(await m(),d.mount(e)),unmount:()=>c().unmount(),update:async e=>c().update(e),focus:()=>c().focus(),blur:()=>c().blur(),clear:()=>c().clear(),on:(e,t)=>{if(!d){let r=null,o=!1;return m().then(()=>{o||(r=d.on(e,t))}),()=>{o=!0,null==r||r()}}return d.on(e,t)},setValueRef:async e=>{if(d||await m(),d&&"setValueRef"in d&&"function"==typeof d.setValueRef)return d.setValueRef(e);throw p("setValueRef not available on this element type")}};return"card"===t&&Object.defineProperties(h,{number:{get:()=>null==d?void 0:d.number,enumerable:!0},expiryDate:{get:()=>null==d?void 0:d.expiryDate,enumerable:!0},cvc:{get:()=>null==d?void 0:d.cvc,enumerable:!0}}),h})(l,t,d,e,o,r,P,v,T),a.set(u.id,u),"cardNumber"===t&&u.on("change",e=>{const{cardBrand:t,cvvLengths:r}=e.detail;if(n("Card number change event received",{cardBrand:t,cvvLengths:r,cvvElementsCount:Array.from(a.values()).filter(e=>"cvv"===e.type).length}),t&&"Unknown"!==t&&r)for(const[o,i]of a)"cvv"===i.type&&i.mounted&&(n("Coordinating CVV element with card brand",{cvvElementId:o,cardBrand:t,cvvLengths:r,mounted:i.mounted}),i.update({cardBrand:t,cvvLengths:r}).catch(e=>{n("Failed to update CVV element with card brand",{cvvElementId:o,cardBrand:t,error:e.message})}))}),u},(...e)=>(b(),W(...e))),tokenize:w(async(e,t)=>{if(n("tokenize called",{hasPayload:!!e,hasOptions:!!t,coordinatorReady:!!s}),s||(n("Waiting for coordinator initialization"),await q()),!s)throw f("Coordinator failed to initialize");try{const r=e?A(e):{};n("Element references resolved",{originalPayload:!!e,resolvedPayload:!!r}),n("Delegating tokenization to coordinator");const o=await s.sendRequest("CMD_TOKENIZE",{payload:r,options:t});return n("tokenize successful",{tokenId:o.id}),o}catch(r){throw n("tokenize failed",{error:r.message}),r}}),tokens:{create:w(async e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw h("Token data must be a non-null object");if(n("tokens.create called",{type:e.type,hasData:!!e.data}),s||(n("Waiting for coordinator initialization"),await q()),!s)throw new Error("Coordinator failed to initialize");try{const t={...e,data:A(e.data)};n("Element references resolved for tokens.create",{resolvedData:!!t});const r=await s.sendRequest("CMD_TOKENS_CREATE",{data:t});return n("tokens.create successful",{tokenId:r.id}),r}catch(t){throw n("tokens.create failed",{error:t.message}),t}}),retrieve:w(async(e,t)=>{if(n("tokens.retrieve called",{tokenId:e,hasSessionKey:!!(null==t?void 0:t.apiKey)}),s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKENS_RETRIEVE",{id:e,apiKey:null==t?void 0:t.apiKey});return n("tokens.retrieve successful",{tokenId:r.id}),r}catch(r){throw n("tokens.retrieve failed",{error:r.message}),r}}),update:w(async(e,t)=>{if(n("tokens.update called",{tokenId:e}),s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const r=t.data?{...t,data:A(t.data)}:t,o=await s.sendRequest("CMD_TOKENS_UPDATE",{id:e,data:r});return n("tokens.update successful",{tokenId:o.id}),o}catch(r){throw n("tokens.update failed",{error:r.message}),r}}),encrypt:w(async(e,t,r)=>{if(n("tokens.encrypt called",{isSingleToken:"type"in e&&"data"in e,keyId:r}),!e||"object"!=typeof e)throw h("tokenData must be an object");if(!t||"string"!=typeof t)throw h("publicKeyPEM is required");if(!r||"string"!=typeof r)throw h("keyId is required");if(s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const o=A(e);n("Element references resolved for tokens.encrypt",{originalData:!!e,resolvedData:!!o});const a=await s.sendRequest("CMD_TOKENS_ENCRYPT",{tokenRequests:o,publicKeyPEM:t,keyId:r});return n("tokens.encrypt successful",{isSingleToken:"encrypted"in a&&"type"in a}),a}catch(o){throw n("tokens.encrypt failed",{error:o.message}),o}})},sessions:{create:w(async()=>{if(n("sessions.create called"),s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const e=await s.sendRequest("CMD_SESSIONS_CREATE",{});return n("sessions.create successful",{nonce:e.nonce,expiresAt:e.expires_at}),e}catch(e){throw n("sessions.create failed",{error:e.message}),e}})},tokenIntents:{create:w(async(e,t)=>{if(n("tokenIntents.create called",{type:e.type,hasData:!!e.data,hasOptions:!!t}),s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const r=A(e.data);n("Element references resolved for token intent");const o=await s.sendRequest("CMD_TOKEN_INTENTS_CREATE",{type:e.type,data:r,options:t});return n("tokenIntents.create successful",{intentId:o.id}),o}catch(r){throw n("tokenIntents.create failed",{error:r.message}),r}}),get:w(async(e,t)=>{if(n("tokenIntents.get called",{intentId:e}),s||await q(),!s)throw new Error("Coordinator failed to initialize");try{const r=await s.sendRequest("CMD_TOKEN_INTENTS_GET",{id:e,options:t});return n("tokenIntents.get successful",{intentId:r.id}),r}catch(r){throw n("tokenIntents.get failed",{error:r.message}),r}})},proxy:(()=>{const e=w(async(e,t={})=>{if(R({...t,method:e}),n("proxy invoked",{method:e,hasUrl:!!t.url,hasProxyKey:!!t.proxyKey}),s||(n("Waiting for coordinator initialization"),await q()),!s)throw f("Coordinator failed to initialize");const r=void 0!==t.body?A(t.body):void 0;try{const o=await s.sendRequest("CMD_PROXY",{method:e,url:t.url,proxyKey:t.proxyKey,headers:t.headers,body:r,includeResponseHeaders:t.includeResponseHeaders},{retries:0});return n("proxy successful",{method:e}),o}catch(o){throw n("proxy failed",{method:e,error:o.message}),o}}),t=t=>r=>e(t,r??{});return{get:t("GET"),post:t("POST"),put:t("PUT"),patch:t("PATCH"),delete:t("DELETE")}})(),updateThemeMode:w(async e=>{n("updateThemeMode called",{oldMode:E,newMode:e,mountedElements:Array.from(a.values()).filter(e=>e.mounted).length}),E=e;const t=[];for(const[r,o]of a)if(o.mounted){n("Sending theme mode update to element",{elementId:r,elementType:o.type,mode:e});const a=document.querySelector(`iframe[data-bt-element-id="${o.id}"]`);a&&a.setAttribute("data-theme-mode",e);const i=o.update({themeMode:e}).catch(e=>{n("Failed to update theme mode for element",{elementId:r,error:e.message})});t.push(i)}await Promise.all(t),n("Theme mode updated for all mounted elements",{mode:e,updatedCount:Array.from(a.values()).filter(e=>e.mounted).length})}),destroy:async()=>{if(!g){g=!0,n("Destroying SDK instance",{elementCount:a.size,hasCoordinator:null!==i});for(const[t,r]of a)if(r.mounted)try{r.unmount()}catch(e){n("Failed to unmount element during destroy",{elementId:t,error:e.message})}if(a.clear(),null!==m&&(clearTimeout(m),m=null),c&&(c(y("SDK instance has been destroyed. Create a new instance with BasisTheory()")),c=null),s){const e=2e3,t=s.sendRequest("CMD_CLEAR_ALL_CACHE",{},{retries:0}).catch(e=>{n("Failed to clear coordinator cache during destroy",{error:e.message})});let r;const o=new Promise(t=>{r=setTimeout(()=>{n("Coordinator cache-clear timed out during destroy",{timeoutMs:e}),t()},e)});await Promise.race([t,o]),void 0!==r&&clearTimeout(r)}s&&(s.destroy(),s=null),i&&(i.remove(),i=null),l=null,u=!1,n("SDK instance destroyed")}}};var W;if(r&&r.length>0){n("Draining command queue from loader",{queueLength:r.length,commands:r.map(e=>e.method)});for(const e of r)try{const t=F[e.method];if(!t)throw new Error(`Unknown method: ${e.method}`);n("Replaying queued command",{method:e.method,argsCount:e.args.length});const r=t(...e.args);r&&"function"==typeof r.then?r.then(t=>{n("Queued command completed (async)",{method:e.method}),e.resolve(t)}).catch(t=>{n("Queued command failed (async)",{method:e.method,error:t.message}),e.reject(t)}):(n("Queued command completed (sync)",{method:e.method}),e.resolve(r))}catch(H){n("Queued command failed (sync)",{method:e.method,error:H.message}),e.reject(H)}n("Command queue drain complete",{processedCount:r.length})}return F};"undefined"!=typeof window&&"undefined"!=typeof document&&document.currentScript&&!window.BasisTheory&&(window.BasisTheory=F),"undefined"!=typeof window&&(window.__BasisTheorySDK__=F);const K=Object.freeze(Object.defineProperty({__proto__:null,createCardElement:(e,t,r={},o,n,a)=>{let i=null,s=null,l=null,d=!1,u=null,m=null;const c=new EventTarget,h=o,f="card",y=e=>({id:e,type:"card",get mounted(){return d},mount:()=>{throw p("Sub-field refs cannot be mounted independently")},unmount:()=>{},update:()=>Promise.resolve(),focus:()=>{},blur:()=>{},clear:()=>{},on:()=>()=>{}}),g=y(`${h}__number`),b=y(`${h}__expiry`),w=y(`${h}__cvc`);return{id:h,type:f,get mounted(){return d},get loaded(){return d},number:g,expiryDate:b,cvc:w,mount:async o=>{if(d)throw p("Element is already mounted");if(u="string"==typeof o?document.querySelector(o):o,!u)throw p(`Container not found: ${o}`);const a=window.location.origin,y=new URL(`${t.elementsBaseUrl}/card.html`);y.searchParams.set("parentOrigin",a),y.searchParams.set("elementId",h),y.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),y.searchParams.set("debug",String(t.debug||!1)),i=_({src:y.toString(),sandbox:"allow-scripts allow-same-origin",title:r.ariaLabel||"Card Input"}),i.setAttribute("data-bt-element-id",h),i.setAttribute("data-theme-mode",t.themeMode||"auto"),s=O(i,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),l={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},s&&(m=x({elementType:f,elementId:h,client:s,eventTarget:c}),m.setupSubscriptions());const g=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,h,{elementType:f,timeoutMs:t.timeoutMs}))},t.timeoutMs);c.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});l.mount(u,i,{timeoutMs:t.timeoutMs}),d=!0;try{await n(),await g,await s.sendRequest("CMD_SET_CONFIG",{elementId:h,apiKey:e,apiTimeout:t.timeoutMs,apiRetries:t.retryConfig.maxRetries,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,placeholder:r.placeholder,...void 0!==r.style&&{style:r.style},disabled:r.disabled,readOnly:r.readOnly,layout:r.layout||"auto",stackAt:r.stackAt||400,iconPosition:r.iconPosition||"left",...void 0!==r.cardBrands&&{cardBrands:r.cardBrands},...void 0!==r.binLookup&&{binLookup:r.binLookup},...void 0!==r.coBadge&&{coBadge:r.coBadge},debug:t.debug}),i&&(i.style.opacity="1")}catch(b){throw m&&m.dispatchError("MOUNT_ERROR",b.message,b),d=!1,s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,b}},unmount:()=>{if(!d)throw p("Element is not mounted");const e=["__number","__expiry","__cvc"];for(const t of e)a(`${h}${t}`).catch(e=>{e.message});s&&(s.destroy(),s=null),l&&i&&(l.unmount(i),i=null,l=null),m=null,u=null,d=!1},update:async e=>{if(!d||!s)throw p("Element must be mounted before updating");const r=e,o={elementId:h};void 0!==r.placeholder&&(o.placeholder=r.placeholder),void 0!==r.style&&(o.style=r.style),void 0!==r.disabled&&(o.disabled=r.disabled),void 0!==r.readOnly&&(o.readOnly=r.readOnly),void 0!==r.layout&&(o.layout=r.layout),void 0!==r.stackAt&&(o.stackAt=r.stackAt),void 0!==r.iconPosition&&(o.iconPosition=r.iconPosition),void 0!==r.cardBrands&&(o.cardBrands=r.cardBrands),void 0!==r.binLookup&&(o.binLookup=r.binLookup),void 0!==r.coBadge&&(o.coBadge=r.coBadge),void 0!==e.themeMode&&(o.themeMode=e.themeMode,o.theme=t.theme,o.darkTheme=t.darkTheme),await s.sendRequest("CMD_UPDATE_CONFIG",o)},focus:()=>{if(!d||!s)throw p("Element must be mounted before focusing");s.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!d||!s)throw p("Element must be mounted before blurring");s.sendRequest("CMD_BLUR",{})},clear:()=>{if(!d||!s)throw p("Element must be mounted before clearing");s.sendRequest("CMD_CLEAR",{})},on:(e,t)=>(c.addEventListener(e,t),()=>c.removeEventListener(e,t)),setNetwork:async e=>{if(!d||!s)throw p("Element must be mounted before setNetwork");await s.sendRequest("CMD_SET_NETWORK",{network:e})}}}},Symbol.toStringTag,{value:"Module"})),V=Object.freeze(Object.defineProperty({__proto__:null,createCopyButtonElement:(e,t,r,o,n,a)=>{const i=r;if(!0!==(null==i?void 0:i.allowClipboard))throw y("CopyButton requires allowClipboard: true. Clipboard access for raw card data may not be PCI compliant and must be explicitly enabled.",{received:null==i?void 0:i.allowClipboard,expected:!0,elementType:"copyButton"});let s=null,l=null,d=null,m=!1,c=null,h=null;const f=new EventTarget,g=o,b="copyButton";return{id:g,type:b,get mounted(){return m},get loaded(){return m},mount:async e=>{if(m)throw p("Element is already mounted",g);if(c="string"==typeof e?document.querySelector(e):e,!c)throw p(`Container not found: ${e}`);const r=u(),o=window.location.origin,a=new URL(`${t.elementsBaseUrl}/copy-button.html`);a.searchParams.set("parentOrigin",o),a.searchParams.set("elementId",g),a.searchParams.set("signature",r),a.searchParams.set("measurePerformance",String(t.measurePerformance||!1)),a.searchParams.set("debug",String(t.debug||!1)),s=_({src:a.toString(),sandbox:"allow-scripts allow-same-origin",allow:"clipboard-write",title:"Copy Button"}),s.setAttribute("data-bt-element-id",g),l=O(s,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),d={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}},l&&(h=x({elementType:b,elementId:g,client:l,eventTarget:f}),h.setupSubscriptions(),l.subscribe("EVENT_COPY",e=>{const t=new CustomEvent("copy",{detail:{elementType:b,elementId:g,timestamp:Date.now(),success:(null==e?void 0:e.success)??!1,error:null==e?void 0:e.error}});f.dispatchEvent(t)}));const y=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,g,{elementType:b,timeoutMs:t.timeoutMs}))},t.timeoutMs);f.addEventListener("ready",()=>{clearTimeout(o),e()},{once:!0})});d.mount(c,s,{timeoutMs:t.timeoutMs}),m=!0;try{await n(),await y,await l.sendRequest("CMD_SET_CONFIG",{elementId:g,signature:r,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,text:i.text||"Copy",value:i.value,disabled:i.disabled,debug:t.debug}),s&&(s.style.opacity="1")}catch(w){throw h&&h.dispatchError("MOUNT_ERROR",w.message,w),m=!1,l&&(l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),h=null,c=null,w}},unmount:()=>{if(!m)throw p("Element is not mounted");l&&(l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),h=null,c=null,m=!1},update:async e=>{if(!m||!l)throw p("Element must be mounted before updating",g);const r={},o=e;void 0!==o.text&&(r.text=o.text),void 0!==o.value&&(r.value=o.value),void 0!==o.disabled&&(r.disabled=o.disabled),void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),await l.sendRequest("CMD_UPDATE_CONFIG",r)},focus:()=>{if(!m||!l)throw p("Element must be mounted before focusing",g);l.sendRequest("CMD_FOCUS",{})},blur:()=>{if(!m||!l)throw p("Element must be mounted before blurring",g);l.sendRequest("CMD_BLUR",{})},clear:()=>{},on:(e,t)=>(f.addEventListener(e,t),()=>f.removeEventListener(e,t)),setValueRef:async e=>{if(null==e||e.id,!e||!e.id)throw p("setValueRef requires a valid Element with an ID",g);if(!m||!l)throw p("Element must be mounted before calling setValueRef",g);await l.sendRequest("CMD_SET_VALUE_REF",{referenceElementId:e.id})}}}},Symbol.toStringTag,{value:"Module"})),j=Object.freeze(Object.defineProperty({__proto__:null,createCardDisplayElement:(e,t,r,o,n,a,i)=>{if(!r.tokenId||"string"!=typeof r.tokenId)throw y("tokenId is required for cardDisplay element");let s=null,l=null,d=null,u=!1,m=!1,c=null,h=r.tokenId;const f=new EventTarget,g=o,b="cardDisplay",w=(e,t)=>{f.dispatchEvent(new CustomEvent(e,{detail:{elementType:b,elementId:g,timestamp:Date.now(),...t}}))},E=(e,t)=>{t.message,w("error",{code:e,message:t.message})},v=async()=>{try{await i("CMD_CLEAR_DISPLAY_SESSION",{elementId:g})}catch(e){e.message}},T=async e=>{if(!t.sessionAuthorizationUrl)return void E("SESSION_AUTHORIZATION_FAILED",y("sessionAuthorizationUrl is required to load cardDisplay data"));let r;try{const t=await i("CMD_CREATE_DISPLAY_SESSION",{tokenId:e,elementId:g});if(!(null==t?void 0:t.nonce))return;r=t.nonce}catch(s){return void E("SESSION_CREATION_FAILED",s)}const o=new AbortController,n=setTimeout(()=>o.abort(),3e4);let a;try{a=await fetch(t.sessionAuthorizationUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nonce:r}),signal:o.signal})}catch(s){return await v(),void E("NETWORK_ERROR",s)}finally{clearTimeout(n)}if(!a.ok)return await v(),void E("SESSION_AUTHORIZATION_FAILED",p(`Session authorization failed: ${a.status} ${a.statusText}`,g));try{await i("CMD_RETRIEVE_DISPLAY_TOKEN",{tokenId:e,elementId:g})}catch(s){E("TOKEN_RETRIEVAL_FAILED",s)}};return{id:g,type:b,get mounted(){return u},get loaded(){return m},mount:async e=>{if(u)throw p("Element is already mounted",g);if(c="string"==typeof e?document.querySelector(e):e,!c)throw p(`Container not found: ${e}`);const o=window.location.origin,a=new URL(`${t.elementsBaseUrl}/card-display.html`);a.searchParams.set("parentOrigin",o),a.searchParams.set("elementId",g),a.searchParams.set("debug",String(t.debug||!1)),s=_({src:a.toString(),sandbox:"allow-scripts allow-same-origin",allow:"clipboard-write",title:"Card Display"}),s.setAttribute("data-bt-element-id",g),l=O(s,{targetOrigin:t.iframeOrigin,timeout:t.timeoutMs,retries:t.retryConfig.maxRetries,debug:t.debug}),d={mount:async(e,t,r)=>{(e=>{e.style.border="none",e.style.width="100%",e.style.height="100%",e.style.display="block"})(t),e.appendChild(t)},unmount:e=>{e.remove()}};const i=new Promise((e,r)=>{const o=setTimeout(()=>{r(p(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`,g,{elementType:b,timeoutMs:t.timeoutMs}))},t.timeoutMs),n=l.subscribe("EVENT_READY",()=>{clearTimeout(o),n(),e()})});l.subscribe("EVENT_CHANGE",e=>{e.loaded&&(m=!0),w("change",e)}),l.subscribe("EVENT_ERROR",e=>{w("error",e)}),d.mount(c,s,{timeoutMs:t.timeoutMs}),u=!0;try{await n(),await i,await l.sendRequest("CMD_SET_CONFIG",{elementId:g,tokenId:h,theme:t.theme,darkTheme:t.darkTheme,themeMode:t.themeMode,number:r.number,cvc:r.cvc,expiration:r.expiration,debug:t.debug}),s&&(s.style.opacity="1"),w("ready",{}),h&&T(h)}catch(f){throw w("error",{code:"MOUNT_ERROR",message:f.message}),u=!1,l&&(l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),c=null,f}},unmount:()=>{if(!u)throw p("Element is not mounted");v(),l&&(l.sendRequest("CMD_CLEAR",{}).catch(e=>{e.message}),l.destroy(),l=null),d&&s&&(d.unmount(s),s=null,d=null),c=null,u=!1,m=!1},update:async e=>{if(!u||!l)throw p("Element must be mounted before updating",g);void 0!==e.tokenId&&e.tokenId!==h&&(h=e.tokenId,m=!1,await l.sendRequest("CMD_CLEAR",{}),T(h));const r={};void 0!==e.number&&(r.number=e.number),void 0!==e.cvc&&(r.cvc=e.cvc),void 0!==e.expiration&&(r.expiration=e.expiration),void 0!==e.themeMode&&(r.themeMode=e.themeMode,r.theme=t.theme,r.darkTheme=t.darkTheme),Object.keys(r).length>0&&await l.sendRequest("CMD_UPDATE_CONFIG",r)},on:(e,t)=>(f.addEventListener(e,t),()=>f.removeEventListener(e,t)),focus:()=>{},blur:()=>{},clear:()=>{}}}},Symbol.toStringTag,{value:"Module"}));e.buildDate="2026-07-16T14:24:00.230Z",e.default=F,e.version="3.0.0-beta.5",Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|