@openrails/billing-ui 0.252.1 → 0.253.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +15 -4
  3. package/dist/admin/context.d.ts +4 -4
  4. package/dist/admin/lib/api/endpoints.d.ts +2 -2
  5. package/dist/admin/lib/api/index.d.ts +1 -1
  6. package/dist/admin/lib/mutations.d.ts +1 -1
  7. package/dist/{admin-detail-DG-YaHhS.js → admin-detail-DAOjLNL9.js} +2 -2
  8. package/dist/admin-detail-DAOjLNL9.js.map +1 -0
  9. package/dist/{admin-orders-8XzHf7b-.js → admin-orders-DMSOum9t.js} +2 -2
  10. package/dist/admin-orders-DMSOum9t.js.map +1 -0
  11. package/dist/admin-utils-DnVY5fYd.js.map +1 -1
  12. package/dist/admin.js +2 -2
  13. package/dist/buy-button.d.ts +4 -1
  14. package/dist/cart.d.ts +4 -1
  15. package/dist/client/generated/error-codes.d.ts +1 -1
  16. package/dist/client/generated/routes.d.ts +4 -4
  17. package/dist/client/generated/wire.d.ts +8 -3
  18. package/dist/client/types.d.ts +13 -7
  19. package/dist/{client-imFR1UCe.js → client-Di2a3HGM.js} +4 -3
  20. package/dist/client-Di2a3HGM.js.map +1 -0
  21. package/dist/client.js +1 -1
  22. package/dist/components/platform-card-form.d.ts +8 -0
  23. package/dist/create-card-BEILS1VB-DeyyfyFD.js +140 -0
  24. package/dist/create-card-BEILS1VB-DeyyfyFD.js.map +1 -0
  25. package/dist/create-card-display-Dv5pcpzc-BWB6vzo2.js +166 -0
  26. package/dist/create-card-display-Dv5pcpzc-BWB6vzo2.js.map +1 -0
  27. package/dist/create-copy-button-CAYmfugS-qNapojfj.js +125 -0
  28. package/dist/create-copy-button-CAYmfugS-qNapojfj.js.map +1 -0
  29. package/dist/embedded-payment.d.ts +4 -1
  30. package/dist/fallbacks.d.ts +25 -0
  31. package/dist/{hooks-C9JkHcRt.js → hooks-Bx0aLyvy.js} +2 -2
  32. package/dist/{hooks-C9JkHcRt.js.map → hooks-Bx0aLyvy.js.map} +1 -1
  33. package/dist/index-rGw83t5v-BE6naeQR.js +1801 -0
  34. package/dist/index-rGw83t5v-BE6naeQR.js.map +1 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +1128 -975
  37. package/dist/index.js.map +1 -1
  38. package/dist/order-payment.d.ts +8 -1
  39. package/dist/product-list.d.ts +4 -1
  40. package/dist/react.js +1 -1
  41. package/package.json +2 -1
  42. package/dist/admin-detail-DG-YaHhS.js.map +0 -1
  43. package/dist/admin-orders-8XzHf7b-.js.map +0 -1
  44. package/dist/client-imFR1UCe.js.map +0 -1
@@ -0,0 +1,1801 @@
1
+ //#region node_modules/.pnpm/@basis-theory+web-elements@3.2.0/node_modules/@basis-theory/web-elements/dist/index-rGw83t5v.js
2
+ var e = [
3
+ /cardnumber/i,
4
+ /^pan$/i,
5
+ /accountnumber/i,
6
+ /^number$/i
7
+ ], t = [
8
+ /cvv/i,
9
+ /cvc/i,
10
+ /cvv2/i,
11
+ /securitycode/i,
12
+ /pin/i,
13
+ /password/i,
14
+ /secret/i,
15
+ /token/i,
16
+ /ssn/i,
17
+ /track/i,
18
+ /session_key/i,
19
+ /^apikey$/i
20
+ ], n = (t) => e.some((e) => e.test(t)), r = (e) => t.some((t) => t.test(e)), i = (e) => {
21
+ let t = e.replace(/\D/g, "");
22
+ if (t.length < 10) return "***";
23
+ let n = t.substring(0, 6), r = t.substring(t.length - 4), i = Math.max(t.length - 10, 6);
24
+ return `${n}${"*".repeat(i)}${r}`;
25
+ }, a = (e) => {
26
+ let t = e.replace(/[\s-]/g, "");
27
+ return /^\d{13,19}$/.test(t);
28
+ }, o = (e, t) => t == null ? t : typeof t == "function" ? "[Function]" : typeof t == "symbol" ? "[Symbol]" : t instanceof RegExp ? "[RegExp]" : t instanceof Date ? t : n(e) ? typeof t == "string" ? i(t) : "***" : r(e) ? "***" : typeof t == "string" && a(t) ? i(t) : t, s = (e, t = 0, n = /* @__PURE__ */ new WeakSet()) => {
29
+ if (t >= 5) return "[Max Depth]";
30
+ if (e == null) return e;
31
+ if (typeof e == "string") return a(e) ? i(e) : e;
32
+ if (typeof e != "object") return e;
33
+ if (e instanceof RegExp) return "[RegExp]";
34
+ if (e instanceof Date) return e;
35
+ if (n.has(e)) return "[Circular]";
36
+ n.add(e);
37
+ let r;
38
+ if (Array.isArray(e)) r = e.map((e) => s(e, t + 1, n));
39
+ else {
40
+ let i = {};
41
+ for (let [r, a] of Object.entries(e)) {
42
+ let e = o(r, a);
43
+ i[r] = typeof e == "object" && e ? s(e, t + 1, n) : e;
44
+ }
45
+ r = i;
46
+ }
47
+ return n.delete(e), r;
48
+ }, c = (e) => {
49
+ let t = {};
50
+ for (let [i, a] of Object.entries(e)) if (n(i) || r(i)) {
51
+ let e = typeof a == "string" ? a.length : typeof a == "number" ? String(a).length : 0;
52
+ t[`${i}_length`] = e;
53
+ } else t[i] = s(a);
54
+ return t;
55
+ }, l = () => {
56
+ let e = /* @__PURE__ */ new Date();
57
+ 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")}`;
58
+ }, u = (e, t) => t ? (t, n) => {
59
+ let r = l(), i = n ? c(n) : {};
60
+ console.log(`🔍 [${r}] [${e}] ${t}`, i);
61
+ } : () => {}, d = () => {
62
+ if (typeof crypto < "u" && crypto.randomUUID) return crypto.randomUUID();
63
+ let e = () => Math.random().toString(36).substring(2), t = (e() + e() + e() + e()).substring(0, 32);
64
+ return `${t.substring(0, 8)}-${t.substring(8, 12)}-${t.substring(12, 16)}-${t.substring(16, 20)}-${t.substring(20, 32)}`;
65
+ }, f = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{1,8})*$/, p = (e) => typeof e == "string" && f.test(e), m = (e, t) => {}, h = (e, t, n) => {
66
+ let r = Error(t);
67
+ return r.name = "BasisTheoryError", r.code = e, r.details = n, Error.captureStackTrace && Error.captureStackTrace(r, h), r.toJSON = () => ({
68
+ name: r.name,
69
+ code: r.code,
70
+ message: r.message,
71
+ ...r.details && { details: r.details }
72
+ }), r;
73
+ }, g = (e, t, n) => {
74
+ let r = h(e, t, n);
75
+ return r.name = "BasisTheoryError", r;
76
+ }, _ = (e, t, n) => {
77
+ let r = h("VALIDATION_ERROR", e, t ? {
78
+ field: t,
79
+ ...n
80
+ } : n);
81
+ return r.name = "ValidationError", r.field = t, r;
82
+ }, v = (e, t) => {
83
+ let n = h("COORDINATOR_ERROR", e, t);
84
+ return n.name = "CoordinatorError", n;
85
+ }, y = (e, t, n) => {
86
+ let r = h("ELEMENT_ERROR", e, t ? {
87
+ elementId: t,
88
+ ...n
89
+ } : n);
90
+ return r.name = "ElementError", r.elementId = t, r;
91
+ }, b = (e, t) => {
92
+ let n = h("CONFIGURATION_ERROR", e, t);
93
+ return n.name = "ConfigurationError", n;
94
+ }, ee = (e, t, n, r) => {
95
+ let i = h("HTTP_CLIENT_ERROR", e, { status: t });
96
+ return i.name = "HttpClientError", i.status = t, i.data = n, i.headers = r, i;
97
+ }, x = /* @__PURE__ */ new Set(["https:"]), S = /* @__PURE__ */ new Set([
98
+ "GET",
99
+ "POST",
100
+ "PUT",
101
+ "PATCH",
102
+ "DELETE"
103
+ ]), C = /* @__PURE__ */ new Set([
104
+ "host",
105
+ "content-length",
106
+ "transfer-encoding",
107
+ "te",
108
+ "trailer",
109
+ "connection",
110
+ "upgrade",
111
+ "keep-alive",
112
+ "proxy-connection",
113
+ "via",
114
+ "proxy-authorization",
115
+ "bt-api-key",
116
+ "bt-proxy-key",
117
+ "bt-proxy-url",
118
+ "bt-idempotency-key",
119
+ "x-forwarded-for",
120
+ "x-forwarded-host",
121
+ "x-real-ip",
122
+ "content-type"
123
+ ]), w = (e) => {
124
+ if (e) for (let [t, n] of Object.entries(e)) {
125
+ if (/[\r\n]/.test(n)) throw _(`Header '${t}' value contains illegal CRLF`, "headers");
126
+ if (/[\r\n]/.test(t)) throw _(`Header name '${t}' contains illegal CRLF`, "headers");
127
+ if (C.has(t.toLowerCase().trim())) throw _(`Header '${t}' is not allowed in proxy requests`, "headers");
128
+ }
129
+ }, T = (e) => {
130
+ let t = e.replace(/^\[|\]$/g, "");
131
+ if (/^(0x[\da-f]+|\d+)$/i.test(t)) {
132
+ let e = t.toLowerCase().startsWith("0x") ? parseInt(t, 16) : parseInt(t, 10);
133
+ return e >= 0 && e <= 4294967295 ? [
134
+ e >>> 24 & 255,
135
+ e >>> 16 & 255,
136
+ e >>> 8 & 255,
137
+ e & 255
138
+ ] : null;
139
+ }
140
+ let n = t.split(".");
141
+ if (n.length !== 4) return null;
142
+ let r = [];
143
+ for (let e of n) {
144
+ let t;
145
+ if (t = e.toLowerCase().startsWith("0x") ? parseInt(e, 16) : e.startsWith("0") && e.length > 1 && !/[89]/.test(e) ? parseInt(e, 8) : parseInt(e, 10), isNaN(t) || t < 0 || t > 255) return null;
146
+ r.push(t);
147
+ }
148
+ return r;
149
+ }, E = (e) => {
150
+ let t = e[0], n = e[1];
151
+ return t === void 0 || n === void 0 || t === 127 || t === 10 || t === 172 && n >= 16 && n <= 31 || t === 192 && n === 168 || t === 169 && n === 254 || t === 0;
152
+ }, D = (e) => {
153
+ let t = e.replace(/^\[|\]$/g, "").toLowerCase();
154
+ if (t === "::1" || t === "0:0:0:0:0:0:0:1" || t === "0000:0000:0000:0000:0000:0000:0000:0001" || t.startsWith("fe8") || t.startsWith("fe9") || t.startsWith("fea") || t.startsWith("feb") || t.startsWith("fc") || t.startsWith("fd")) return !0;
155
+ let n = t.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
156
+ if (n) {
157
+ let e = n[1];
158
+ if (e) {
159
+ let t = T(e);
160
+ if (t && E(t)) return !0;
161
+ }
162
+ }
163
+ let r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
164
+ if (r) {
165
+ let e = r[1], t = r[2];
166
+ if (!e || !t) return !0;
167
+ let n = parseInt(e, 16), i = parseInt(t, 16);
168
+ if (E([
169
+ n >>> 8 & 255,
170
+ n & 255,
171
+ i >>> 8 & 255,
172
+ i & 255
173
+ ])) return !0;
174
+ }
175
+ return !1;
176
+ }, O = (e) => {
177
+ let t = e.hostname.toLowerCase();
178
+ if (e.username || e.password) throw _("URL must not contain userinfo (username/password)", "url");
179
+ if (t === "localhost") throw _("URL must not target localhost", "url");
180
+ if ((t.startsWith("[") || D(t)) && D(t)) throw _("URL must not target loopback or link-local IPv6 addresses", "url");
181
+ let n = T(t);
182
+ if (n && E(n)) throw _("URL must not target private or internal IP addresses", "url");
183
+ }, k = (e) => {
184
+ let t;
185
+ try {
186
+ t = new URL(e);
187
+ } catch {
188
+ throw _("Invalid URL format", "url");
189
+ }
190
+ if (!x.has(t.protocol)) throw _(`URL scheme '${t.protocol}' is not allowed. Only https: is permitted`, "url");
191
+ O(t);
192
+ }, A = (e, t) => {
193
+ let n = typeof e == "string" && e.length > 0;
194
+ if (n === (typeof t == "string" && t.length > 0)) throw _("Specify exactly one of url or proxyKey", "url/proxyKey");
195
+ n && k(e);
196
+ }, j = new Set([...C].filter((e) => e !== "content-type")), M = (e) => {
197
+ if (e) for (let [t, n] of Object.entries(e)) {
198
+ if (/[\r\n]/.test(n)) throw _(`Header '${t}' value contains illegal CRLF`, "headers");
199
+ if (/[\r\n]/.test(t)) throw _(`Header name '${t}' contains illegal CRLF`, "headers");
200
+ if (j.has(t.toLowerCase().trim())) throw _(`Header '${t}' is not allowed in HTTP client requests`, "headers");
201
+ }
202
+ }, te = (e) => {
203
+ if (e !== void 0 && (typeof e != "object" || !e)) throw _("HTTP client options must be a plain object", "options");
204
+ if (e?.method !== void 0 && !S.has(e.method)) throw _(`Method '${e.method}' is not allowed`, "method");
205
+ if (typeof e?.url != "string" || e.url.length === 0) throw _("url is required", "url");
206
+ k(e.url), M(e?.headers);
207
+ }, ne = (e) => {
208
+ if (e !== void 0 && (typeof e != "object" || !e)) throw _("Proxy options must be a plain object", "options");
209
+ if (e?.method !== void 0 && !S.has(e.method)) throw _(`Method '${e.method}' is not allowed`, "method");
210
+ A(e?.url, e?.proxyKey), w(e?.headers);
211
+ }, N = {
212
+ maxRetries: 2,
213
+ initialDelay: 500,
214
+ maxDelay: 3e3,
215
+ backoffFactor: 2
216
+ }, P = (e, t) => {
217
+ let n = t.initialDelay * t.backoffFactor ** +e;
218
+ return Math.min(n, t.maxDelay);
219
+ }, F = (e) => new Promise((t) => setTimeout(t, e)), I = (e, t) => {
220
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = u("PostMessageClient", t.debug || !1), a = (e) => e === t.targetOrigin, o = (o) => {
221
+ let { nonce: s, type: c, payload: l, error: u } = o.data || {};
222
+ if (!c) return;
223
+ if (!a(o.origin)) {
224
+ i("Rejected message (origin mismatch)", {
225
+ receivedOrigin: o.origin,
226
+ expectedOrigin: t.targetOrigin,
227
+ messageType: c
228
+ });
229
+ return;
230
+ }
231
+ if (o.source !== e.contentWindow) return;
232
+ if (s) {
233
+ let e = n.get(s);
234
+ if (e) {
235
+ if (i("Message received", {
236
+ origin: o.origin,
237
+ expectedOrigin: t.targetOrigin,
238
+ type: c,
239
+ nonce: s
240
+ }), clearTimeout(e.timeout), n.delete(s), u) {
241
+ let t = g(u.code, `[${u.code}] ${u.message}`);
242
+ Object.assign(t, {
243
+ ...u.status !== void 0 && { status: u.status },
244
+ ...u.statusCode !== void 0 && { statusCode: u.statusCode },
245
+ ...u.validationErrors && { validationErrors: u.validationErrors },
246
+ ...u.body && { body: u.body },
247
+ ...u.retryCount !== void 0 && { retryCount: u.retryCount },
248
+ ...u.data !== void 0 && { data: u.data },
249
+ ...u.headers && { headers: u.headers },
250
+ ...u.details && { details: u.details }
251
+ }), e.reject(t);
252
+ } else e.resolve(l);
253
+ return;
254
+ }
255
+ return;
256
+ }
257
+ let d = r.get(c);
258
+ d && d.size > 0 ? (i("Event received", {
259
+ origin: o.origin,
260
+ expectedOrigin: t.targetOrigin,
261
+ type: c,
262
+ nonce: s,
263
+ subscriberCount: d.size
264
+ }), d.forEach((e) => {
265
+ try {
266
+ e(l);
267
+ } catch (e) {
268
+ i("Error in event subscriber", {
269
+ type: c,
270
+ error: e.message
271
+ });
272
+ }
273
+ })) : s || i("Event received but no subscribers", {
274
+ type: c,
275
+ availableSubscribers: Array.from(r.keys())
276
+ });
277
+ };
278
+ window.addEventListener("message", o);
279
+ let s = typeof t.retries == "number" ? {
280
+ ...N,
281
+ maxRetries: t.retries
282
+ } : typeof t.retries == "object" ? t.retries : N, c = (r, a, o) => new Promise((s, c) => {
283
+ let l = d(), u = Date.now();
284
+ if (!e.contentWindow) {
285
+ c(g("IFRAME_NOT_READY", "Iframe not ready"));
286
+ return;
287
+ }
288
+ let f = setTimeout(() => {
289
+ n.delete(l), c(g("REQUEST_TIMEOUT", `Request timeout: ${r} (${t.timeout || 5e3}ms)`));
290
+ }, t.timeout || 5e3);
291
+ n.set(l, {
292
+ resolve: s,
293
+ reject: c,
294
+ timeout: f,
295
+ timestamp: u
296
+ }), i("Sending request", {
297
+ type: r,
298
+ nonce: l
299
+ });
300
+ let p = {
301
+ type: r,
302
+ nonce: l,
303
+ timestamp: u,
304
+ payload: a
305
+ };
306
+ o?.length ? e.contentWindow.postMessage(p, t.targetOrigin, o) : e.contentWindow.postMessage(p, t.targetOrigin);
307
+ });
308
+ return {
309
+ sendRequest: async (e, t, n) => {
310
+ let r = n?.transfer?.length ? 0 : n?.retries === void 0 ? s.maxRetries : n.retries, a = null;
311
+ for (let o = 0; o <= r; o++) try {
312
+ return await c(e, t, n?.transfer);
313
+ } catch (e) {
314
+ a = e;
315
+ let t = e.message;
316
+ if (t.startsWith("[HANDLER_ERROR]") || t === "Client destroyed" || t === "Iframe not ready") throw i("Not retrying error", {
317
+ error: t,
318
+ reason: "Non-retriable error"
319
+ }), e;
320
+ if (o < r) {
321
+ let e = P(o, s);
322
+ i("Retrying request", {
323
+ attempt: o + 1,
324
+ maxRetries: r,
325
+ delayMs: e,
326
+ error: t
327
+ }), await F(e);
328
+ }
329
+ }
330
+ throw a || /* @__PURE__ */ Error(`Request failed after ${r} retries: ${e}`);
331
+ },
332
+ ping: async (r = 1e3) => {
333
+ let a = Date.now();
334
+ i("Starting health check", {
335
+ timeoutMs: r,
336
+ iframeReady: !!e.contentWindow,
337
+ targetOrigin: t.targetOrigin
338
+ });
339
+ try {
340
+ await c("SYS_PING", void 0);
341
+ let e = Date.now() - a;
342
+ return i("Health check passed", { latencyMs: e }), e;
343
+ } catch (e) {
344
+ let r = `Health check failed after ${Date.now() - a}ms: ${e.message}. Target: ${t.targetOrigin}`;
345
+ throw t.debug && (i(`❌ [PostMessage Client] ${r}`), i(`📊 [PostMessage Client] Pending requests: ${n.size}`)), g("HEALTH_CHECK_FAILED", r);
346
+ }
347
+ },
348
+ subscribe: (e, t) => (r.has(e) || r.set(e, /* @__PURE__ */ new Set()), r.get(e).add(t), () => {
349
+ let n = r.get(e);
350
+ n && (n.delete(t), n.size === 0 && r.delete(e));
351
+ }),
352
+ destroy: () => {
353
+ window.removeEventListener("message", o), n.forEach(({ timeout: e, reject: t }) => {
354
+ clearTimeout(e), t(g("CLIENT_DESTROYED", "Client destroyed"));
355
+ }), n.clear(), r.clear();
356
+ },
357
+ getPendingCount: () => n.size
358
+ };
359
+ }, L = () => {
360
+ let e = (e) => {
361
+ e.style.border = "none", e.style.width = "100%", e.style.height = "100%", e.style.display = "block";
362
+ };
363
+ return {
364
+ mount: async (t, n, r) => {
365
+ e(n), t.appendChild(n);
366
+ },
367
+ unmount: (e) => {
368
+ e.remove();
369
+ }
370
+ };
371
+ }, re = "CMD_REGISTER_ELEMENT", ie = "CMD_BIND_ELEMENT_PORT", ae = "CMD_BIND_COORDINATOR_PORT", R = async ({ elementId: e, elementType: t, client: n, coordinatorRequest: r }) => {
372
+ await r(re, {
373
+ elementId: e,
374
+ type: t
375
+ });
376
+ let i = new MessageChannel(), a = await r(ie, { elementId: e }, {
377
+ retries: 0,
378
+ transfer: [i.port2]
379
+ });
380
+ if (!a?.success) throw i.port1.close(), y(`Coordinator rejected the element port (${a?.error ?? "UNKNOWN"})`, e, { elementType: t });
381
+ let o = await n.sendRequest(ae, { elementId: e }, {
382
+ retries: 0,
383
+ transfer: [i.port1]
384
+ }).catch((e) => (e.message, {
385
+ success: !1,
386
+ error: e.message
387
+ }));
388
+ if (!o?.success) throw await r("CMD_BROADCAST_ELEMENT_UNMOUNT", { elementId: e }).catch(() => void 0), y(`Element rejected the coordinator port (${o?.error ?? "UNKNOWN"})`, e, { elementType: t });
389
+ }, z = (e) => {
390
+ let t = document.createElement("iframe");
391
+ 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;
392
+ }, B = (e) => {
393
+ let { elementType: t, elementId: n, client: r, eventTarget: i } = e, a = () => ({
394
+ elementType: t,
395
+ elementId: n,
396
+ timestamp: Date.now()
397
+ }), o = (e, t) => {
398
+ let n = new CustomEvent(e, { detail: {
399
+ ...a(),
400
+ ...t
401
+ } });
402
+ i.dispatchEvent(n);
403
+ };
404
+ return {
405
+ setupSubscriptions: () => {
406
+ r.subscribe("EVENT_READY", () => {
407
+ o("ready", {});
408
+ }), r.subscribe("EVENT_VALUE_CHANGED", (e) => {
409
+ let n = {
410
+ isValid: e.isValid,
411
+ isEmpty: e.isEmpty,
412
+ error: e.error || null
413
+ };
414
+ if (t === "cardNumber") {
415
+ let t = {
416
+ ...n,
417
+ cardBrand: e.cardBrand,
418
+ last4: e.last4,
419
+ bin: e.bin,
420
+ cvvLengths: e.cvvLengths,
421
+ potentialBrands: e.potentialBrands,
422
+ matchStrength: e.matchStrength,
423
+ networks: e.networks,
424
+ selectedNetwork: e.selectedNetwork,
425
+ binDetails: e.binDetails
426
+ };
427
+ o("change", t);
428
+ } else t === "card" ? o("change", {
429
+ ...n,
430
+ cardBrand: e.cardBrand,
431
+ last4: e.last4,
432
+ bin: e.bin,
433
+ networks: e.networks,
434
+ selectedNetwork: e.selectedNetwork,
435
+ binDetails: e.binDetails,
436
+ errors: e.errors || null
437
+ }) : o("change", n);
438
+ }), r.subscribe("EVENT_NETWORK_CHANGED", (e) => {
439
+ if (t !== "cardNumber" && t !== "card") return;
440
+ let n = {
441
+ network: e.network,
442
+ previousNetwork: e.previousNetwork,
443
+ availableNetworks: e.availableNetworks ?? [],
444
+ selectionMode: e.selectionMode ?? "auto"
445
+ };
446
+ o("networkChanged", n);
447
+ }), r.subscribe("EVENT_FOCUS", () => {
448
+ o("focus", {});
449
+ }), r.subscribe("EVENT_BLUR", () => {
450
+ o("blur", {});
451
+ }), r.subscribe("EVENT_ERROR", (e) => {
452
+ o("error", {
453
+ code: e.code,
454
+ message: e.message,
455
+ status: e.status,
456
+ validationErrors: e.validationErrors,
457
+ metadata: e.metadata || {}
458
+ });
459
+ });
460
+ },
461
+ dispatchError: (e, t, n) => {
462
+ o("error", {
463
+ code: e,
464
+ message: t,
465
+ metadata: {
466
+ source: "initialization",
467
+ originalError: n
468
+ }
469
+ });
470
+ }
471
+ };
472
+ }, oe = (e, t, n = {}, r, i, a, o) => {
473
+ let s = null, c = null, l = null, u = !1, d = null, f = null, p = new EventTarget(), m = r, h = "cardNumber", g = () => {
474
+ c && (f = B({
475
+ elementType: h,
476
+ elementId: m,
477
+ client: c,
478
+ eventTarget: p
479
+ }), f.setupSubscriptions(), c.subscribe("EVENT_CONTENT_HEIGHT", (e) => {
480
+ let t = e?.heightPx;
481
+ s && typeof t == "number" && t > 0 && (s.style.height = `${Math.ceil(t)}px`);
482
+ }));
483
+ };
484
+ return {
485
+ id: m,
486
+ type: h,
487
+ get mounted() {
488
+ return u;
489
+ },
490
+ get loaded() {
491
+ return u;
492
+ },
493
+ mount: async (r) => {
494
+ if (u) throw y("Element is already mounted");
495
+ if (d = typeof r == "string" ? document.querySelector(r) : r, !d) throw y(`Container not found: ${r}`);
496
+ let a = window.location.origin, _ = new URL(`${t.elementsBaseUrl}/card-number.html`);
497
+ _.searchParams.set("parentOrigin", a), _.searchParams.set("elementId", m), _.searchParams.set("measurePerformance", String(t.measurePerformance || !1)), _.searchParams.set("debug", String(t.debug || !1)), s = z({
498
+ src: _.toString(),
499
+ sandbox: "allow-scripts allow-same-origin",
500
+ title: n.ariaLabel || "Card Number Input"
501
+ }), s.setAttribute("data-bt-element-id", m), s.setAttribute("data-theme-mode", t.themeMode || "auto"), c = I(s, {
502
+ targetOrigin: t.iframeOrigin,
503
+ timeout: t.timeoutMs,
504
+ retries: t.retryConfig.maxRetries,
505
+ debug: t.debug
506
+ }), l = L(), g();
507
+ let v = new Promise((e, n) => {
508
+ let r = setTimeout(() => {
509
+ n(y(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`, m, {
510
+ elementType: h,
511
+ timeoutMs: t.timeoutMs
512
+ }));
513
+ }, t.timeoutMs);
514
+ p.addEventListener("ready", () => {
515
+ clearTimeout(r), e();
516
+ }, { once: !0 });
517
+ });
518
+ l.mount(d, s, { timeoutMs: t.timeoutMs }), u = !0;
519
+ try {
520
+ await i(), await v, await R({
521
+ elementId: m,
522
+ elementType: h,
523
+ client: c,
524
+ coordinatorRequest: o
525
+ }), await c.sendRequest("CMD_SET_CONFIG", {
526
+ elementId: m,
527
+ apiKey: e,
528
+ environment: t.environment,
529
+ apiTimeout: t.timeoutMs,
530
+ apiRetries: t.retryConfig.maxRetries,
531
+ theme: t.theme,
532
+ darkTheme: t.darkTheme,
533
+ themeMode: t.themeMode,
534
+ direction: t.direction,
535
+ language: t.language,
536
+ placeholder: n.placeholder,
537
+ disabled: n.disabled,
538
+ readOnly: n.readOnly,
539
+ debug: t.debug,
540
+ binLookup: n.binLookup,
541
+ coBadge: n.coBadge,
542
+ enterKeyHint: n.enterKeyHint,
543
+ iconPosition: n.iconPosition || "right"
544
+ }), s && (s.style.opacity = "1");
545
+ } catch (e) {
546
+ throw f && f.dispatchError("MOUNT_ERROR", e.message, e), u = !1, c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, e;
547
+ }
548
+ },
549
+ unmount: () => {
550
+ if (!u) throw y("Element is not mounted");
551
+ a(m).catch((e) => {
552
+ e.message;
553
+ }), c &&= (c.destroy(), null), l && s && (s.style.height = "", l.unmount(s), s = null, l = null), f = null, d = null, u = !1;
554
+ },
555
+ update: async (e) => {
556
+ if (!u || !c) throw y("Element must be mounted before updating");
557
+ let n = { elementId: m };
558
+ e.placeholder !== void 0 && (n.placeholder = e.placeholder), e.disabled !== void 0 && (n.disabled = e.disabled), e.readOnly !== void 0 && (n.readOnly = e.readOnly), e.binLookup !== void 0 && (n.binLookup = e.binLookup), e.coBadge !== void 0 && (n.coBadge = e.coBadge), e.iconPosition !== void 0 && (n.iconPosition = e.iconPosition), "enterKeyHint" in e && (n.enterKeyHint = e.enterKeyHint), e.themeMode !== void 0 && (n.themeMode = e.themeMode, n.theme = t.theme, n.darkTheme = t.darkTheme), await c.sendRequest("CMD_UPDATE_CONFIG", n);
559
+ },
560
+ focus: () => {
561
+ if (!u || !c) throw y("Element must be mounted before focusing");
562
+ c.sendRequest("CMD_FOCUS", {});
563
+ },
564
+ blur: () => {
565
+ if (!u || !c) throw y("Element must be mounted before blurring");
566
+ c.sendRequest("CMD_BLUR", {});
567
+ },
568
+ clear: () => {
569
+ if (!u || !c) throw y("Element must be mounted before clearing");
570
+ c.sendRequest("CMD_CLEAR", {});
571
+ },
572
+ setNetwork: async (e) => {
573
+ if (!u || !c) throw y("Element must be mounted before setNetwork");
574
+ await c.sendRequest("CMD_SET_NETWORK", { network: e });
575
+ },
576
+ on: (e, t) => (p.addEventListener(e, t), () => p.removeEventListener(e, t))
577
+ };
578
+ }, se = (e, t, n = {}, r, i, a, o) => {
579
+ let s = null, c = null, l = null, u = !1, d = null, f = null, p = new EventTarget(), m = r, h = () => {
580
+ c && (f = B({
581
+ elementType: "cvv",
582
+ elementId: m,
583
+ client: c,
584
+ eventTarget: p
585
+ }), f.setupSubscriptions());
586
+ };
587
+ return {
588
+ id: m,
589
+ type: "cvv",
590
+ get mounted() {
591
+ return u;
592
+ },
593
+ get loaded() {
594
+ return u;
595
+ },
596
+ mount: async (r) => {
597
+ if (u) throw y("Element is already mounted", m);
598
+ if (d = typeof r == "string" ? document.querySelector(r) : r, !d) throw y(`Container not found: ${r}`);
599
+ let a = window.location.origin, g = new URL(`${t.elementsBaseUrl}/cvv.html`);
600
+ g.searchParams.set("parentOrigin", a), g.searchParams.set("elementId", m), g.searchParams.set("measurePerformance", String(t.measurePerformance || !1)), g.searchParams.set("debug", String(t.debug || !1)), s = z({
601
+ src: g.toString(),
602
+ sandbox: "allow-scripts allow-same-origin",
603
+ title: n.ariaLabel || "CVV Input"
604
+ }), s.setAttribute("data-bt-element-id", m), c = I(s, {
605
+ targetOrigin: t.iframeOrigin,
606
+ timeout: t.timeoutMs,
607
+ retries: t.retryConfig.maxRetries,
608
+ debug: t.debug
609
+ }), l = L(), h();
610
+ let _ = new Promise((e, n) => {
611
+ let r = setTimeout(() => {
612
+ n(y(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`, m, {
613
+ elementType: "cvv",
614
+ timeoutMs: t.timeoutMs
615
+ }));
616
+ }, t.timeoutMs);
617
+ p.addEventListener("ready", () => {
618
+ clearTimeout(r), e();
619
+ }, { once: !0 });
620
+ });
621
+ l.mount(d, s, { timeoutMs: t.timeoutMs }), u = !0;
622
+ try {
623
+ await i(), await _, await R({
624
+ elementId: m,
625
+ elementType: "cvv",
626
+ client: c,
627
+ coordinatorRequest: o
628
+ }), await c.sendRequest("CMD_SET_CONFIG", {
629
+ elementId: m,
630
+ theme: t.theme,
631
+ darkTheme: t.darkTheme,
632
+ themeMode: t.themeMode,
633
+ direction: t.direction,
634
+ language: t.language,
635
+ apiKey: e,
636
+ environment: t.environment,
637
+ apiTimeout: t.timeoutMs,
638
+ apiRetries: t.retryConfig.maxRetries,
639
+ placeholder: n.placeholder,
640
+ disabled: n.disabled,
641
+ readOnly: n.readOnly,
642
+ showToggle: n.showToggle,
643
+ conceal: n.conceal,
644
+ enterKeyHint: n.enterKeyHint,
645
+ debug: t.debug
646
+ }), s && (s.style.opacity = "1");
647
+ } catch (e) {
648
+ throw f && f.dispatchError("MOUNT_ERROR", e.message, e), u = !1, c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, e;
649
+ }
650
+ },
651
+ unmount: () => {
652
+ if (!u) throw y("Element is not mounted");
653
+ a(m).catch((e) => {
654
+ e.message;
655
+ }), c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, u = !1;
656
+ },
657
+ update: async (e) => {
658
+ if (!u || !c) throw y("Element must be mounted before updating", m);
659
+ let n = {
660
+ placeholder: e.placeholder,
661
+ disabled: e.disabled,
662
+ readOnly: e.readOnly,
663
+ ..."enterKeyHint" in e && { enterKeyHint: e.enterKeyHint },
664
+ ..."conceal" in e && { conceal: e.conceal },
665
+ cardBrand: e.cardBrand,
666
+ cvvLengths: e.cvvLengths
667
+ };
668
+ e.themeMode !== void 0 && (n.themeMode = e.themeMode, n.theme = t.theme, n.darkTheme = t.darkTheme), await c.sendRequest("CMD_UPDATE_CONFIG", n);
669
+ },
670
+ focus: () => {
671
+ if (!u || !c) throw y("Element must be mounted before focusing", m);
672
+ c.sendRequest("CMD_FOCUS", {});
673
+ },
674
+ blur: () => {
675
+ if (!u || !c) throw y("Element must be mounted before blurring", m);
676
+ c.sendRequest("CMD_BLUR", {});
677
+ },
678
+ clear: () => {
679
+ if (!u || !c) throw y("Element must be mounted before clearing", m);
680
+ c.sendRequest("CMD_CLEAR", {});
681
+ },
682
+ on: (e, t) => (p.addEventListener(e, t), () => p.removeEventListener(e, t))
683
+ };
684
+ }, ce = (e, t, n = {}, r, i, a, o) => {
685
+ let s = null, c = null, l = null, u = !1, d = null, f = null, p = new EventTarget(), m = r, h = "expiry", g = () => {
686
+ c && (f = B({
687
+ elementType: h,
688
+ elementId: m,
689
+ client: c,
690
+ eventTarget: p
691
+ }), f.setupSubscriptions());
692
+ };
693
+ return {
694
+ id: m,
695
+ type: h,
696
+ get mounted() {
697
+ return u;
698
+ },
699
+ get loaded() {
700
+ return u;
701
+ },
702
+ mount: async (r) => {
703
+ if (u) throw y("Element is already mounted", m);
704
+ if (d = typeof r == "string" ? document.querySelector(r) : r, !d) throw y(`Container not found: ${r}`);
705
+ let a = window.location.origin, _ = new URL(`${t.elementsBaseUrl}/expiry.html`);
706
+ _.searchParams.set("parentOrigin", a), _.searchParams.set("elementId", m), _.searchParams.set("measurePerformance", String(t.measurePerformance || !1)), _.searchParams.set("debug", String(t.debug || !1)), s = z({
707
+ src: _.toString(),
708
+ sandbox: "allow-scripts allow-same-origin",
709
+ title: n.ariaLabel || "Expiry Date Input"
710
+ }), s.setAttribute("data-bt-element-id", m), c = I(s, {
711
+ targetOrigin: t.iframeOrigin,
712
+ timeout: t.timeoutMs,
713
+ retries: t.retryConfig.maxRetries,
714
+ debug: t.debug
715
+ }), l = L(), g();
716
+ let v = new Promise((e, n) => {
717
+ let r = setTimeout(() => {
718
+ n(y(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`, m, {
719
+ elementType: h,
720
+ timeoutMs: t.timeoutMs
721
+ }));
722
+ }, t.timeoutMs);
723
+ p.addEventListener("ready", () => {
724
+ clearTimeout(r), e();
725
+ }, { once: !0 });
726
+ });
727
+ l.mount(d, s, { timeoutMs: t.timeoutMs }), u = !0;
728
+ try {
729
+ await i(), await v, await R({
730
+ elementId: m,
731
+ elementType: h,
732
+ client: c,
733
+ coordinatorRequest: o
734
+ }), await c.sendRequest("CMD_SET_CONFIG", {
735
+ elementId: m,
736
+ theme: t.theme,
737
+ darkTheme: t.darkTheme,
738
+ themeMode: t.themeMode,
739
+ direction: t.direction,
740
+ language: t.language,
741
+ apiKey: e,
742
+ environment: t.environment,
743
+ apiTimeout: t.timeoutMs,
744
+ apiRetries: t.retryConfig.maxRetries,
745
+ placeholder: n.placeholder,
746
+ disabled: n.disabled,
747
+ readOnly: n.readOnly,
748
+ enterKeyHint: n.enterKeyHint,
749
+ debug: t.debug
750
+ }), s && (s.style.opacity = "1");
751
+ } catch (e) {
752
+ throw f && f.dispatchError("MOUNT_ERROR", e.message, e), u = !1, c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, e;
753
+ }
754
+ },
755
+ unmount: () => {
756
+ if (!u) throw y("Element is not mounted");
757
+ a(m).catch((e) => {
758
+ e.message;
759
+ }), c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, u = !1;
760
+ },
761
+ update: async (e) => {
762
+ if (!u || !c) throw y("Element must be mounted before updating", m);
763
+ let n = {
764
+ placeholder: e.placeholder,
765
+ disabled: e.disabled,
766
+ readOnly: e.readOnly,
767
+ ..."enterKeyHint" in e && { enterKeyHint: e.enterKeyHint }
768
+ };
769
+ e.themeMode !== void 0 && (n.themeMode = e.themeMode, n.theme = t.theme, n.darkTheme = t.darkTheme), await c.sendRequest("CMD_UPDATE_CONFIG", n);
770
+ },
771
+ focus: () => {
772
+ if (!u || !c) throw y("Element must be mounted before focusing", m);
773
+ c.sendRequest("CMD_FOCUS", {});
774
+ },
775
+ blur: () => {
776
+ if (!u || !c) throw y("Element must be mounted before blurring", m);
777
+ c.sendRequest("CMD_BLUR", {});
778
+ },
779
+ clear: () => {
780
+ if (!u || !c) throw y("Element must be mounted before clearing", m);
781
+ c.sendRequest("CMD_CLEAR", {});
782
+ },
783
+ on: (e, t) => (p.addEventListener(e, t), () => p.removeEventListener(e, t))
784
+ };
785
+ }, le = (e, t, n = {}, r, i, a, o) => {
786
+ let s = null, c = null, l = null, u = !1, d = null, f = null, p = new EventTarget(), m = r, h = "text";
787
+ if (n.transform && (!Array.isArray(n.transform) || n.transform.length !== 2 || !(n.transform[0] instanceof RegExp) || typeof n.transform[1] != "string")) throw TypeError("transform must be a tuple of [RegExp, string]. Example: [/-/g, \"\"]");
788
+ let g = () => {
789
+ c && (f = B({
790
+ elementType: h,
791
+ elementId: m,
792
+ client: c,
793
+ eventTarget: p
794
+ }), f.setupSubscriptions());
795
+ };
796
+ return {
797
+ id: m,
798
+ type: h,
799
+ get mounted() {
800
+ return u;
801
+ },
802
+ get loaded() {
803
+ return u;
804
+ },
805
+ mount: async (r) => {
806
+ if (u) throw y("Element is already mounted", m);
807
+ if (d = typeof r == "string" ? document.querySelector(r) : r, !d) throw y(`Container not found: ${r}`);
808
+ let a = window.location.origin, _ = new URL(`${t.elementsBaseUrl}/text.html`);
809
+ _.searchParams.set("parentOrigin", a), _.searchParams.set("elementId", m), _.searchParams.set("measurePerformance", String(t.measurePerformance || !1)), _.searchParams.set("debug", String(t.debug || !1)), s = z({
810
+ src: _.toString(),
811
+ sandbox: "allow-scripts allow-same-origin",
812
+ title: n.ariaLabel || "Text Input"
813
+ }), s.setAttribute("data-bt-element-id", m), c = I(s, {
814
+ targetOrigin: t.iframeOrigin,
815
+ timeout: t.timeoutMs,
816
+ retries: t.retryConfig.maxRetries,
817
+ debug: t.debug
818
+ }), l = L(), g();
819
+ let v = new Promise((e, n) => {
820
+ let r = setTimeout(() => {
821
+ n(y(`Iframe EVENT_READY not received within ${t.timeoutMs}ms`, m, {
822
+ elementType: h,
823
+ timeoutMs: t.timeoutMs
824
+ }));
825
+ }, t.timeoutMs);
826
+ p.addEventListener("ready", () => {
827
+ clearTimeout(r), e();
828
+ }, { once: !0 });
829
+ });
830
+ l.mount(d, s, { timeoutMs: t.timeoutMs }), u = !0;
831
+ try {
832
+ await i(), await v, await R({
833
+ elementId: m,
834
+ elementType: h,
835
+ client: c,
836
+ coordinatorRequest: o
837
+ });
838
+ let r = n.transform ? {
839
+ pattern: n.transform[0].source,
840
+ flags: n.transform[0].flags,
841
+ replacement: n.transform[1]
842
+ } : void 0, a = n.mask ? n.mask.map((e) => typeof e == "string" ? e : e instanceof RegExp ? {
843
+ source: e.source,
844
+ flags: e.flags
845
+ } : e) : void 0;
846
+ await c.sendRequest("CMD_SET_CONFIG", {
847
+ elementId: m,
848
+ theme: t.theme,
849
+ darkTheme: t.darkTheme,
850
+ themeMode: t.themeMode,
851
+ direction: t.direction,
852
+ language: t.language,
853
+ apiKey: e,
854
+ environment: t.environment,
855
+ apiTimeout: t.timeoutMs,
856
+ apiRetries: t.retryConfig.maxRetries,
857
+ placeholder: n.placeholder,
858
+ disabled: n.disabled,
859
+ readOnly: n.readOnly,
860
+ validation: n.validation,
861
+ required: n.required,
862
+ maxLength: n.maxLength,
863
+ password: n.password,
864
+ inputMode: n.inputMode,
865
+ enterKeyHint: n.enterKeyHint,
866
+ mask: a,
867
+ transform: r,
868
+ debug: t.debug
869
+ }), s && (s.style.opacity = "1");
870
+ } catch (e) {
871
+ throw f && f.dispatchError("MOUNT_ERROR", e.message, e), u = !1, c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, e;
872
+ }
873
+ },
874
+ unmount: () => {
875
+ if (!u) throw y("Element is not mounted");
876
+ a(m).catch((e) => {
877
+ e.message;
878
+ }), c &&= (c.destroy(), null), l && s && (l.unmount(s), s = null, l = null), f = null, d = null, u = !1;
879
+ },
880
+ update: async (e) => {
881
+ if (!u || !c) throw y("Element must be mounted before updating", m);
882
+ let n = {
883
+ placeholder: e.placeholder,
884
+ disabled: e.disabled,
885
+ readOnly: e.readOnly,
886
+ required: e.required,
887
+ maxLength: e.maxLength,
888
+ password: e.password,
889
+ inputMode: e.inputMode,
890
+ ..."enterKeyHint" in e && { enterKeyHint: e.enterKeyHint }
891
+ };
892
+ e.themeMode !== void 0 && (n.themeMode = e.themeMode, n.theme = t.theme, n.darkTheme = t.darkTheme), await c.sendRequest("CMD_UPDATE_CONFIG", n);
893
+ },
894
+ focus: () => {
895
+ if (!u || !c) throw y("Element must be mounted before focusing", m);
896
+ c.sendRequest("CMD_FOCUS", {});
897
+ },
898
+ blur: () => {
899
+ if (!u || !c) throw y("Element must be mounted before blurring", m);
900
+ c.sendRequest("CMD_BLUR", {});
901
+ },
902
+ clear: () => {
903
+ if (!u || !c) throw y("Element must be mounted before clearing", m);
904
+ c.sendRequest("CMD_CLEAR", {});
905
+ },
906
+ on: (e, t) => (p.addEventListener(e, t), () => p.removeEventListener(e, t))
907
+ };
908
+ }, ue = (e) => e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean", de = (e) => {
909
+ if (typeof e != "object" || !e) return !1;
910
+ let t = e;
911
+ return typeof t.mount == "function" && typeof t.update == "function" && typeof t.on == "function";
912
+ }, V = (e) => {
913
+ if (ue(e)) return e;
914
+ if (de(e)) {
915
+ if (!e.id) throw y("Element is missing id property. Ensure createElement is called after the SDK loads and all elements are mounted before calling tokenize().");
916
+ return e.id;
917
+ }
918
+ if (Array.isArray(e)) return e.map(V);
919
+ if (typeof e == "object" && e) {
920
+ let t = {};
921
+ for (let [n, r] of Object.entries(e)) t[n] = V(r);
922
+ return t;
923
+ }
924
+ return e;
925
+ }, H = {
926
+ colors: {
927
+ primary: "#3b82f6",
928
+ error: "#ef4444",
929
+ success: "#10b981",
930
+ text: {
931
+ primary: "#1f2937",
932
+ secondary: "#6b7280",
933
+ placeholder: "#9ca3af",
934
+ disabled: "#d1d5db"
935
+ },
936
+ background: {
937
+ default: "#ffffff",
938
+ hover: "#f9fafb",
939
+ focus: "#eff6ff",
940
+ disabled: "#f9fafb"
941
+ },
942
+ border: {
943
+ default: "#d1d5db",
944
+ hover: "#9ca3af",
945
+ focus: "#3b82f6",
946
+ error: "#ef4444"
947
+ }
948
+ },
949
+ typography: {
950
+ fontFamily: "\"Inter\", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif",
951
+ fontSize: {
952
+ sm: "14px",
953
+ base: "16px",
954
+ lg: "18px"
955
+ },
956
+ fontWeight: {
957
+ normal: "400",
958
+ medium: "500",
959
+ semibold: "600"
960
+ },
961
+ lineHeight: {
962
+ tight: "1.25",
963
+ normal: "1.5",
964
+ relaxed: "1.75"
965
+ }
966
+ },
967
+ spacing: {
968
+ xs: "4px",
969
+ sm: "8px",
970
+ md: "12px",
971
+ lg: "16px",
972
+ xl: "24px"
973
+ },
974
+ borders: {
975
+ radius: {
976
+ none: "0",
977
+ sm: "2px",
978
+ base: "4px",
979
+ md: "6px",
980
+ lg: "8px",
981
+ full: "9999px"
982
+ },
983
+ width: {
984
+ thin: "1px",
985
+ base: "2px",
986
+ thick: "3px"
987
+ }
988
+ },
989
+ shadows: {
990
+ none: "none",
991
+ sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
992
+ base: "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",
993
+ md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
994
+ lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
995
+ focus: "0 0 0 3px rgba(59, 130, 246, 0.1)"
996
+ },
997
+ transitions: {
998
+ fast: "150ms cubic-bezier(0.4, 0, 0.2, 1)",
999
+ base: "200ms cubic-bezier(0.4, 0, 0.2, 1)",
1000
+ slow: "300ms cubic-bezier(0.4, 0, 0.2, 1)"
1001
+ }
1002
+ }, U = (e) => e ? {
1003
+ colors: {
1004
+ primary: e.colors?.primary ?? H.colors.primary,
1005
+ error: e.colors?.error ?? H.colors.error,
1006
+ success: e.colors?.success ?? H.colors.success,
1007
+ text: {
1008
+ ...H.colors.text,
1009
+ ...e.colors?.text
1010
+ },
1011
+ background: {
1012
+ ...H.colors.background,
1013
+ ...e.colors?.background
1014
+ },
1015
+ border: {
1016
+ ...H.colors.border,
1017
+ ...e.colors?.border
1018
+ }
1019
+ },
1020
+ typography: {
1021
+ ...H.typography,
1022
+ ...e.typography,
1023
+ fontSize: {
1024
+ ...H.typography.fontSize,
1025
+ ...e.typography?.fontSize
1026
+ },
1027
+ fontWeight: {
1028
+ ...H.typography.fontWeight,
1029
+ ...e.typography?.fontWeight
1030
+ },
1031
+ lineHeight: {
1032
+ ...H.typography.lineHeight,
1033
+ ...e.typography?.lineHeight
1034
+ }
1035
+ },
1036
+ spacing: {
1037
+ ...H.spacing,
1038
+ ...e.spacing
1039
+ },
1040
+ borders: {
1041
+ radius: {
1042
+ ...H.borders.radius,
1043
+ ...e.borders?.radius
1044
+ },
1045
+ width: {
1046
+ ...H.borders.width,
1047
+ ...e.borders?.width
1048
+ }
1049
+ },
1050
+ shadows: {
1051
+ ...H.shadows,
1052
+ ...e.shadows
1053
+ },
1054
+ transitions: {
1055
+ ...H.transitions,
1056
+ ...e.transitions
1057
+ }
1058
+ } : H, W = (e, t, n, r) => {
1059
+ for (let i of Object.keys(t)) if (!n.has(i)) {
1060
+ if (r?.has(i)) {
1061
+ console.warn(`[BasisTheory] Deprecated option "${i}" in ${e}. ${r.get(i)}`);
1062
+ continue;
1063
+ }
1064
+ console.warn(`[BasisTheory] Unknown option "${i}" in ${e}. This option will be ignored. See https://developers.basistheory.com/docs/ for supported options.`);
1065
+ }
1066
+ }, G = [
1067
+ "us",
1068
+ "eu",
1069
+ "test"
1070
+ ], fe = /* @__PURE__ */ new Set([
1071
+ "elementsBaseUrl",
1072
+ "whitelabelDomain",
1073
+ "apiBaseUrl",
1074
+ "environment",
1075
+ "debug",
1076
+ "allowClipboard",
1077
+ "allowHttpClient",
1078
+ "measurePerformance",
1079
+ "timeoutMs",
1080
+ "retryConfig",
1081
+ "themeMode",
1082
+ "direction",
1083
+ "language",
1084
+ "theme",
1085
+ "darkTheme",
1086
+ "sessionAuthorizationUrl"
1087
+ ]), pe = /* @__PURE__ */ new Map([["iframeOrigin", "Use \"elementsBaseUrl\" instead."]]), K = (e) => {
1088
+ if (!e || typeof e != "string" || e.trim().length === 0) throw b("API key is required");
1089
+ }, me = (e = {}) => {
1090
+ W("SDKOptions", e, fe, pe);
1091
+ let t = e.elementsBaseUrl || e.iframeOrigin;
1092
+ if (t !== void 0) {
1093
+ if (typeof t != "string" || t.trim().length === 0) throw b("elementsBaseUrl must be a non-empty string");
1094
+ try {
1095
+ new URL(t);
1096
+ } catch {
1097
+ throw b("elementsBaseUrl must be a valid URL");
1098
+ }
1099
+ }
1100
+ if (e.apiBaseUrl !== void 0) {
1101
+ if (typeof e.apiBaseUrl != "string" || e.apiBaseUrl.trim().length === 0) throw b("apiBaseUrl must be a non-empty string");
1102
+ try {
1103
+ new URL(e.apiBaseUrl);
1104
+ } catch {
1105
+ throw b("apiBaseUrl must be a valid URL");
1106
+ }
1107
+ }
1108
+ if (e.debug !== void 0 && typeof e.debug != "boolean") throw b("debug must be a boolean");
1109
+ if (e.allowClipboard !== void 0 && typeof e.allowClipboard != "boolean") throw b("allowClipboard must be a boolean");
1110
+ if (e.allowHttpClient !== void 0 && typeof e.allowHttpClient != "boolean") throw b("allowHttpClient must be a boolean");
1111
+ if (e.measurePerformance !== void 0 && typeof e.measurePerformance != "boolean") throw b("measurePerformance must be a boolean");
1112
+ if (e.timeoutMs !== void 0 && (typeof e.timeoutMs != "number" || e.timeoutMs <= 0)) throw b("timeoutMs must be a positive number");
1113
+ let n = {
1114
+ maxRetries: e.retryConfig?.maxRetries ?? 3,
1115
+ delayMs: e.retryConfig?.delayMs ?? 1e3,
1116
+ backoffFactor: e.retryConfig?.backoffFactor ?? 2
1117
+ };
1118
+ if (typeof n.maxRetries != "number" || n.maxRetries < 0) throw b("maxRetries must be a non-negative number");
1119
+ if (typeof n.delayMs != "number" || n.delayMs <= 0) throw b("retryConfig.delayMs must be a positive number");
1120
+ if (typeof n.backoffFactor != "number" || n.backoffFactor < 1) throw b("retryConfig.backoffFactor must be >= 1");
1121
+ let r = e.themeMode || "auto";
1122
+ if (![
1123
+ "light",
1124
+ "dark",
1125
+ "auto"
1126
+ ].includes(r)) throw b("themeMode must be \"light\", \"dark\", or \"auto\"");
1127
+ if (e.environment !== void 0 && !G.includes(e.environment)) throw b(`environment must be ${G.map((e) => `"${e}"`).join(", ")}`);
1128
+ let i = e.direction ?? "ltr";
1129
+ if (!["ltr", "rtl"].includes(i)) throw b("direction must be \"ltr\" or \"rtl\"");
1130
+ if (e.language !== void 0 && !p(e.language)) throw b("language must be a BCP 47 language tag");
1131
+ if (e.sessionAuthorizationUrl !== void 0) {
1132
+ if (typeof e.sessionAuthorizationUrl != "string" || e.sessionAuthorizationUrl.trim() === "") throw b("sessionAuthorizationUrl must be a non-empty string");
1133
+ try {
1134
+ let t = new URL(e.sessionAuthorizationUrl, window.location.origin);
1135
+ if (t.protocol === "http:" && t.hostname !== "localhost" && t.hostname !== "127.0.0.1") throw b("sessionAuthorizationUrl must use https://.");
1136
+ } catch (e) {
1137
+ if (e instanceof Error && e.name === "ConfigurationError") throw e;
1138
+ }
1139
+ }
1140
+ let a = t;
1141
+ if (a === void 0 && e.whitelabelDomain !== void 0) {
1142
+ let { whitelabelDomain: t } = e;
1143
+ if (typeof t != "string" || t.trim().length === 0) throw b("whitelabelDomain must be a non-empty string");
1144
+ let n;
1145
+ try {
1146
+ let e = new URL(t);
1147
+ if (e.protocol !== "https:") throw b("whitelabelDomain must use https://");
1148
+ n = e.origin;
1149
+ } catch (e) {
1150
+ throw e instanceof Error && e.name === "ConfigurationError" ? e : b("whitelabelDomain must be a valid URL");
1151
+ }
1152
+ let { pathname: r } = new URL("https://js.basistheory.com/3.2.0/elements");
1153
+ a = `${n}${r}`;
1154
+ }
1155
+ let o = a || "https://js.basistheory.com/3.2.0/elements";
1156
+ return {
1157
+ iframeOrigin: new URL(o).origin,
1158
+ elementsBaseUrl: o,
1159
+ apiBaseUrl: e.apiBaseUrl,
1160
+ environment: e.environment,
1161
+ debug: e.debug ?? !1,
1162
+ allowClipboard: e.allowClipboard ?? !1,
1163
+ allowHttpClient: e.allowHttpClient ?? !1,
1164
+ measurePerformance: e.measurePerformance ?? !1,
1165
+ timeoutMs: e.timeoutMs || 3e4,
1166
+ themeMode: r,
1167
+ direction: i,
1168
+ language: e.language,
1169
+ theme: U(e.theme),
1170
+ darkTheme: e.darkTheme ? U(e.darkTheme) : void 0,
1171
+ retryConfig: n,
1172
+ sessionAuthorizationUrl: e.sessionAuthorizationUrl
1173
+ };
1174
+ }, q = /* @__PURE__ */ new Set([
1175
+ "placeholder",
1176
+ "ariaLabel",
1177
+ "disabled",
1178
+ "readOnly",
1179
+ "enterKeyHint"
1180
+ ]), J = /* @__PURE__ */ new Set([
1181
+ "enter",
1182
+ "done",
1183
+ "go",
1184
+ "next",
1185
+ "previous",
1186
+ "search",
1187
+ "send"
1188
+ ]), Y = /* @__PURE__ */ new Set([
1189
+ "cardNumber",
1190
+ "expiryDate",
1191
+ "cvv",
1192
+ "cvc"
1193
+ ]), X = (e, t) => {
1194
+ if (typeof e != "string" || !J.has(e)) throw b(`${t} must be one of: ${Array.from(J).join(", ")}`);
1195
+ }, he = {
1196
+ cardNumber: /* @__PURE__ */ new Set([
1197
+ ...q,
1198
+ "binLookup",
1199
+ "coBadge",
1200
+ "iconPosition"
1201
+ ]),
1202
+ cvv: /* @__PURE__ */ new Set([
1203
+ ...q,
1204
+ "showToggle",
1205
+ "conceal",
1206
+ "cardBrand",
1207
+ "cvvLengths"
1208
+ ]),
1209
+ expiry: /* @__PURE__ */ new Set([...q]),
1210
+ text: /* @__PURE__ */ new Set([
1211
+ ...q,
1212
+ "validation",
1213
+ "required",
1214
+ "maxLength",
1215
+ "password",
1216
+ "inputMode",
1217
+ "mask",
1218
+ "transform"
1219
+ ]),
1220
+ card: /* @__PURE__ */ new Set([
1221
+ ...q,
1222
+ "layout",
1223
+ "stackAt",
1224
+ "iconPosition",
1225
+ "cardBrands",
1226
+ "agentTools",
1227
+ "cvvRequired",
1228
+ "binLookup",
1229
+ "coBadge"
1230
+ ]),
1231
+ copyButton: /* @__PURE__ */ new Set([
1232
+ "allowClipboard",
1233
+ "value",
1234
+ "text",
1235
+ "disabled"
1236
+ ]),
1237
+ cardDisplay: /* @__PURE__ */ new Set([
1238
+ "tokenId",
1239
+ "number",
1240
+ "cvc",
1241
+ "expiration",
1242
+ "layout",
1243
+ "fieldOrder",
1244
+ "showToggle",
1245
+ "allowClipboard"
1246
+ ])
1247
+ }, Z = [
1248
+ "number",
1249
+ "expiration",
1250
+ "cvc"
1251
+ ], Q = 100, ge = (e, t = {}) => {
1252
+ let n = he[e];
1253
+ if (W(`ElementOptions (${e})`, t, n), t.placeholder !== void 0) {
1254
+ if (e === "card") {
1255
+ if (typeof t.placeholder != "object" || t.placeholder === null) throw b("placeholder for card element must be an object with cardNumber, expiryDate, and cvv keys");
1256
+ } else if (typeof t.placeholder != "string") throw b("placeholder must be a string");
1257
+ }
1258
+ if (t.disabled !== void 0 && typeof t.disabled != "boolean") throw b("disabled must be a boolean");
1259
+ if (t.readOnly !== void 0 && typeof t.readOnly != "boolean") throw b("readOnly must be a boolean");
1260
+ if (t.ariaLabel !== void 0 && typeof t.ariaLabel != "string") throw b("ariaLabel must be a string");
1261
+ if (t.iconPosition !== void 0 && ![
1262
+ "left",
1263
+ "right",
1264
+ "none"
1265
+ ].includes(t.iconPosition)) throw b("iconPosition must be \"left\", \"right\", or \"none\"");
1266
+ if (t.enterKeyHint !== void 0) {
1267
+ let n = t.enterKeyHint;
1268
+ e === "card" && typeof n == "object" && n && !Array.isArray(n) ? (W("enterKeyHint", n, Y), Object.entries(n).filter(([e]) => Y.has(e)).forEach(([e, t]) => {
1269
+ t !== void 0 && X(t, `enterKeyHint.${e}`);
1270
+ })) : X(n, "enterKeyHint");
1271
+ }
1272
+ if (e === "cvv") {
1273
+ let e = ["showToggle", "conceal"].find((e) => t[e] !== void 0 && typeof t[e] != "boolean");
1274
+ if (e) throw b(`${e} must be a boolean`);
1275
+ }
1276
+ if (e === "text") {
1277
+ if (t.maxLength !== void 0 && (typeof t.maxLength != "number" || t.maxLength <= 0)) throw b("maxLength must be a positive number");
1278
+ if (t.password !== void 0 && typeof t.password != "boolean") throw b("password must be a boolean");
1279
+ if (t.required !== void 0 && typeof t.required != "boolean") throw b("required must be a boolean");
1280
+ if (t.validation !== void 0 && !(t.validation instanceof RegExp)) throw b("validation must be a RegExp");
1281
+ if (t.transform && (!Array.isArray(t.transform) || t.transform.length !== 2 || !(t.transform[0] instanceof RegExp) || typeof t.transform[1] != "string")) throw b("transform must be a tuple of [RegExp, string]. Example: [/-/g, \"\"]");
1282
+ }
1283
+ if (e === "copyButton" && t.allowClipboard !== !0) throw b("CopyButton requires allowClipboard: true. Clipboard access for raw card data may not be PCI compliant and must be explicitly enabled.");
1284
+ if (e === "cardDisplay") {
1285
+ let e = t;
1286
+ if (e.layout !== void 0 && !["stacked", "inline"].includes(e.layout)) throw b("layout must be \"stacked\" or \"inline\"");
1287
+ if (e.fieldOrder !== void 0) {
1288
+ if (!Array.isArray(e.fieldOrder)) throw b("fieldOrder must be an array of card display fields");
1289
+ if (e.fieldOrder.find((e) => !Z.includes(e)) !== void 0) throw b("fieldOrder entries must be \"number\", \"expiration\", or \"cvc\"");
1290
+ if (new Set(e.fieldOrder).size !== e.fieldOrder.length) throw b("fieldOrder must not contain duplicate fields");
1291
+ }
1292
+ if (e.showToggle !== void 0 && typeof e.showToggle != "boolean") throw b("showToggle must be a boolean");
1293
+ if (e.allowClipboard !== void 0 && typeof e.allowClipboard != "boolean") throw b("allowClipboard must be a boolean");
1294
+ Z.forEach((t) => {
1295
+ let n = e[t];
1296
+ if (n !== void 0) {
1297
+ if (typeof n != "object" || !n) throw b(`${t} must be a field display configuration object`);
1298
+ if (n.display !== void 0 && ![
1299
+ "masked",
1300
+ "hidden",
1301
+ "visible"
1302
+ ].includes(n.display)) throw b(`${t}.display must be "masked", "hidden", or "visible"`);
1303
+ if (n.label !== void 0 && n.label !== !1 && typeof n.label != "string") throw b(`${t}.label must be a string or false`);
1304
+ if (typeof n.label == "string" && n.label.length > Q) throw b(`${t}.label must be ${Q} characters or fewer`);
1305
+ }
1306
+ });
1307
+ }
1308
+ if (e === "card") {
1309
+ let e = t;
1310
+ if (e.layout !== void 0 && ![
1311
+ "row",
1312
+ "column",
1313
+ "auto"
1314
+ ].includes(e.layout)) throw b("layout must be \"row\", \"column\", or \"auto\"");
1315
+ if (e.stackAt !== void 0 && (typeof e.stackAt != "number" || e.stackAt <= 0)) throw b("stackAt must be a positive number");
1316
+ if (e.cardBrands !== void 0) {
1317
+ if (!Array.isArray(e.cardBrands)) throw b("cardBrands must be an array of strings");
1318
+ if (e.cardBrands.some((e) => typeof e != "string")) throw b("All cardBrands must be strings");
1319
+ }
1320
+ if (e.agentTools !== void 0 && typeof e.agentTools != "boolean") throw b("agentTools must be a boolean");
1321
+ if (e.cvvRequired !== void 0 && typeof e.cvvRequired != "boolean") throw b("cvvRequired must be a boolean");
1322
+ }
1323
+ }, $ = (e, t = {}, n) => {
1324
+ K(e);
1325
+ let r = me(t), i = u("SDK", r.debug || !1);
1326
+ i("SDK initialized", {
1327
+ apiKeyPrefix: e.substring(0, 7) + "...",
1328
+ elementsBaseUrl: r.elementsBaseUrl,
1329
+ iframeOrigin: r.iframeOrigin,
1330
+ debug: r.debug || !1
1331
+ });
1332
+ let a = /* @__PURE__ */ new Map(), o = null, s = null, c = null, l = !1, d = null, f = null, p = !1, m = () => {
1333
+ if (p) throw b("SDK instance has been destroyed. Create a new instance with BasisTheory()");
1334
+ }, h = (e) => (...t) => (m(), e(...t)), g = (e) => async (...t) => (m(), e(...t)), x = t.themeMode || "auto", S = (e, t, n, r, i, a, o, s, c) => {
1335
+ let l = null, u = null, d = async () => {
1336
+ u ||= (async () => {
1337
+ l = (await e())(r, i, a, n, o, s, c);
1338
+ })(), await u;
1339
+ }, f = () => {
1340
+ if (!l) throw y("Element not initialized");
1341
+ return l;
1342
+ }, p = {
1343
+ id: n,
1344
+ type: t,
1345
+ get mounted() {
1346
+ return l?.mounted ?? !1;
1347
+ },
1348
+ get loaded() {
1349
+ return l?.loaded ?? !1;
1350
+ },
1351
+ mount: async (e) => (await d(), l.mount(e)),
1352
+ unmount: () => f().unmount(),
1353
+ update: async (e) => f().update(e),
1354
+ focus: () => f().focus(),
1355
+ blur: () => f().blur(),
1356
+ clear: () => f().clear(),
1357
+ on: (e, t) => {
1358
+ if (!l) {
1359
+ let n = null, r = !1;
1360
+ return d().then(() => {
1361
+ r || (n = l.on(e, t));
1362
+ }), () => {
1363
+ r = !0, n?.();
1364
+ };
1365
+ }
1366
+ return l.on(e, t);
1367
+ },
1368
+ setValueRef: async (e) => {
1369
+ if (l || await d(), l && "setValueRef" in l && typeof l.setValueRef == "function") return l.setValueRef(e);
1370
+ throw y("setValueRef not available on this element type");
1371
+ }
1372
+ };
1373
+ return t === "card" && Object.defineProperties(p, {
1374
+ number: {
1375
+ get: () => l?.number,
1376
+ enumerable: !0
1377
+ },
1378
+ expiryDate: {
1379
+ get: () => l?.expiryDate,
1380
+ enumerable: !0
1381
+ },
1382
+ cvc: {
1383
+ get: () => l?.cvc,
1384
+ enumerable: !0
1385
+ }
1386
+ }), p;
1387
+ }, C = async (e) => {
1388
+ if (!s) {
1389
+ i("Cannot notify coordinator of unmount - coordinator not initialized", { elementId: e });
1390
+ return;
1391
+ }
1392
+ try {
1393
+ await s.sendRequest("CMD_BROADCAST_ELEMENT_UNMOUNT", { elementId: e }), i("Notified coordinator of element unmount", { elementId: e });
1394
+ } catch (t) {
1395
+ i("Failed to notify coordinator of element unmount", {
1396
+ elementId: e,
1397
+ error: t.message
1398
+ });
1399
+ }
1400
+ }, w = async (e, t, n) => {
1401
+ if (!s) throw v("Coordinator not initialized");
1402
+ return s.sendRequest(e, t, n);
1403
+ }, T = null, E = null, D = null, O = async () => (T ||= (await import("./create-card-BEILS1VB-DeyyfyFD.js")).createCardElement, T), k = async () => (E ||= (await import("./create-copy-button-CAYmfugS-qNapojfj.js")).createCopyButtonElement, E), A = async () => (D ||= (await import("./create-card-display-Dv5pcpzc-BWB6vzo2.js")).createCardDisplayElement, D), j = {
1404
+ cardNumber: oe,
1405
+ cvv: se,
1406
+ expiry: ce,
1407
+ text: le
1408
+ }, M = {
1409
+ card: O,
1410
+ copyButton: k,
1411
+ cardDisplay: A
1412
+ }, N = () => c || l ? c : (l = !0, c = P(), c), P = async () => {
1413
+ if (o) {
1414
+ i("Coordinator already initialized", { loaded: o.contentWindow !== null });
1415
+ return;
1416
+ }
1417
+ i("Initializing coordinator iframe", { elementsBaseUrl: r.elementsBaseUrl }), o = document.createElement("iframe"), o.setAttribute("name", "bt-coordinator"), o.setAttribute("title", "BasisTheory Coordinator"), o.setAttribute("role", "none"), o.style.border = "none", o.style.width = "0", o.style.height = "0", o.style.position = "absolute", o.style.top = "-9999px", o.style.left = "-9999px";
1418
+ let t = r.elementsBaseUrl.endsWith("/") ? r.elementsBaseUrl : `${r.elementsBaseUrl}/`, n = new URL("coordinator.html", t);
1419
+ if (n.searchParams.set("parentOrigin", window.location.origin), o.src = n.toString(), document.body.appendChild(o), i("Coordinator iframe mounted", { url: o.src }), await new Promise((e, t) => {
1420
+ f = t, d = setTimeout(() => {
1421
+ d = null, f = null, t(/* @__PURE__ */ Error(`Coordinator load timeout (${r.timeoutMs}ms). Try increasing timeoutMs for slow connections.`));
1422
+ }, r.timeoutMs), o.addEventListener("load", () => {
1423
+ d !== null && clearTimeout(d), d = null, f = null, i("Coordinator iframe loaded"), e();
1424
+ }, { once: !0 });
1425
+ }), p) {
1426
+ i("Coordinator load resolved after destroy — aborting init");
1427
+ return;
1428
+ }
1429
+ s = I(o, {
1430
+ targetOrigin: new URL(r.elementsBaseUrl).origin,
1431
+ timeout: 3e4,
1432
+ retries: 3,
1433
+ debug: r.debug || !1
1434
+ }), i("Coordinator PostMessage client created"), await s.sendRequest("CMD_SET_CONFIG", {
1435
+ apiKey: e,
1436
+ apiBaseUrl: r.apiBaseUrl,
1437
+ environment: r.environment,
1438
+ apiTimeout: 3e4,
1439
+ apiRetries: 3,
1440
+ allowClipboard: r.allowClipboard,
1441
+ allowHttpClient: r.allowHttpClient,
1442
+ debug: r.debug || !1,
1443
+ theme: r.theme,
1444
+ darkTheme: r.darkTheme,
1445
+ themeMode: r.themeMode
1446
+ }), i("Coordinator initialized successfully");
1447
+ }, F = {
1448
+ createElement: h((t, n) => {
1449
+ let s = j[t], c = M[t];
1450
+ if (!s && !c) throw b(`Unknown element type: ${t}`);
1451
+ if (n && ge(t, n), t === "copyButton" && !r.allowClipboard) throw b("copyButton requires allowClipboard: true on BasisTheory() initialization. Clipboard access for raw card data may not be PCI compliant and must be enabled explicitly.", {
1452
+ received: r.allowClipboard,
1453
+ expected: !0,
1454
+ elementType: t
1455
+ });
1456
+ if (t === "cardDisplay" && n?.allowClipboard === !0 && !r.allowClipboard) throw b("cardDisplay clipboard access requires allowClipboard: true on BasisTheory() initialization. Clipboard access for raw card data may not be PCI compliant and must be enabled explicitly.", {
1457
+ received: r.allowClipboard,
1458
+ expected: !0,
1459
+ elementType: t
1460
+ });
1461
+ let l = `${t}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
1462
+ i("Creating element (sync)", {
1463
+ type: t,
1464
+ elementId: l,
1465
+ coordinatorInitialized: o !== null,
1466
+ isLazyLoaded: !!c
1467
+ });
1468
+ let u;
1469
+ return u = s ? s(e, r, n, l, N, C, w) : S(c, t, l, e, r, n, N, C, w), a.set(u.id, u), t === "cardNumber" && u.on("change", (e) => {
1470
+ let { cardBrand: t, cvvLengths: n } = e.detail;
1471
+ if (i("Card number change event received", {
1472
+ cardBrand: t,
1473
+ cvvLengths: n,
1474
+ cvvElementsCount: Array.from(a.values()).filter((e) => e.type === "cvv").length
1475
+ }), t && t !== "Unknown" && n) for (let [e, r] of a) r.type === "cvv" && r.mounted && (i("Coordinating CVV element with card brand", {
1476
+ cvvElementId: e,
1477
+ cardBrand: t,
1478
+ cvvLengths: n,
1479
+ mounted: r.mounted
1480
+ }), r.update({
1481
+ cardBrand: t,
1482
+ cvvLengths: n
1483
+ }).catch((n) => {
1484
+ i("Failed to update CVV element with card brand", {
1485
+ cvvElementId: e,
1486
+ cardBrand: t,
1487
+ error: n.message
1488
+ });
1489
+ }));
1490
+ }), u;
1491
+ }),
1492
+ tokenize: g(async (e, t) => {
1493
+ if (i("tokenize called", {
1494
+ hasPayload: !!e,
1495
+ hasOptions: !!t,
1496
+ coordinatorReady: !!s
1497
+ }), s || (i("Waiting for coordinator initialization"), await P()), !s) throw v("Coordinator failed to initialize");
1498
+ try {
1499
+ let n = e ? V(e) : {};
1500
+ i("Element references resolved", {
1501
+ originalPayload: !!e,
1502
+ resolvedPayload: !!n
1503
+ }), i("Delegating tokenization to coordinator");
1504
+ let r = await s.sendRequest("CMD_TOKENIZE", {
1505
+ payload: n,
1506
+ options: t
1507
+ });
1508
+ return i("tokenize successful", { tokenId: r.id }), r;
1509
+ } catch (e) {
1510
+ throw i("tokenize failed", { error: e.message }), e;
1511
+ }
1512
+ }),
1513
+ tokens: {
1514
+ create: g(async (e) => {
1515
+ if (!e || typeof e != "object" || Array.isArray(e)) throw _("Token data must be a non-null object");
1516
+ if (i("tokens.create called", {
1517
+ type: e.type,
1518
+ hasData: !!e.data
1519
+ }), s || (i("Waiting for coordinator initialization"), await P()), !s) throw Error("Coordinator failed to initialize");
1520
+ try {
1521
+ let t = {
1522
+ ...e,
1523
+ data: V(e.data)
1524
+ };
1525
+ i("Element references resolved for tokens.create", { resolvedData: !!t });
1526
+ let n = await s.sendRequest("CMD_TOKENS_CREATE", { data: t });
1527
+ return i("tokens.create successful", { tokenId: n.id }), n;
1528
+ } catch (e) {
1529
+ throw i("tokens.create failed", { error: e.message }), e;
1530
+ }
1531
+ }),
1532
+ retrieve: g(async (e, t) => {
1533
+ if (i("tokens.retrieve called", {
1534
+ tokenId: e,
1535
+ hasSessionKey: !!t?.apiKey
1536
+ }), s || await P(), !s) throw Error("Coordinator failed to initialize");
1537
+ try {
1538
+ let n = await s.sendRequest("CMD_TOKENS_RETRIEVE", {
1539
+ id: e,
1540
+ apiKey: t?.apiKey
1541
+ });
1542
+ return i("tokens.retrieve successful", { tokenId: n.id }), n;
1543
+ } catch (e) {
1544
+ throw i("tokens.retrieve failed", { error: e.message }), e;
1545
+ }
1546
+ }),
1547
+ update: g(async (e, t) => {
1548
+ if (i("tokens.update called", { tokenId: e }), s || await P(), !s) throw Error("Coordinator failed to initialize");
1549
+ try {
1550
+ let n = t.data ? {
1551
+ ...t,
1552
+ data: V(t.data)
1553
+ } : t, r = await s.sendRequest("CMD_TOKENS_UPDATE", {
1554
+ id: e,
1555
+ data: n
1556
+ });
1557
+ return i("tokens.update successful", { tokenId: r.id }), r;
1558
+ } catch (e) {
1559
+ throw i("tokens.update failed", { error: e.message }), e;
1560
+ }
1561
+ }),
1562
+ encrypt: g(async (e, t, n) => {
1563
+ if (i("tokens.encrypt called", {
1564
+ isSingleToken: "type" in e && "data" in e,
1565
+ keyId: n
1566
+ }), !e || typeof e != "object") throw _("tokenData must be an object");
1567
+ if (!t || typeof t != "string") throw _("publicKeyPEM is required");
1568
+ if (!n || typeof n != "string") throw _("keyId is required");
1569
+ if (s || await P(), !s) throw Error("Coordinator failed to initialize");
1570
+ try {
1571
+ let r = V(e);
1572
+ i("Element references resolved for tokens.encrypt", {
1573
+ originalData: !!e,
1574
+ resolvedData: !!r
1575
+ });
1576
+ let a = await s.sendRequest("CMD_TOKENS_ENCRYPT", {
1577
+ tokenRequests: r,
1578
+ publicKeyPEM: t,
1579
+ keyId: n
1580
+ });
1581
+ return i("tokens.encrypt successful", { isSingleToken: "encrypted" in a && "type" in a }), a;
1582
+ } catch (e) {
1583
+ throw i("tokens.encrypt failed", { error: e.message }), e;
1584
+ }
1585
+ })
1586
+ },
1587
+ sessions: { create: g(async () => {
1588
+ if (i("sessions.create called"), s || await P(), !s) throw Error("Coordinator failed to initialize");
1589
+ try {
1590
+ let e = await s.sendRequest("CMD_SESSIONS_CREATE", {});
1591
+ return i("sessions.create successful", {
1592
+ nonce: e.nonce,
1593
+ expiresAt: e.expires_at
1594
+ }), e;
1595
+ } catch (e) {
1596
+ throw i("sessions.create failed", { error: e.message }), e;
1597
+ }
1598
+ }) },
1599
+ tokenIntents: {
1600
+ create: g(async (e, t) => {
1601
+ if (i("tokenIntents.create called", {
1602
+ type: e.type,
1603
+ hasData: !!e.data,
1604
+ hasOptions: !!t
1605
+ }), s || await P(), !s) throw Error("Coordinator failed to initialize");
1606
+ try {
1607
+ let n = V(e.data);
1608
+ i("Element references resolved for token intent");
1609
+ let r = await s.sendRequest("CMD_TOKEN_INTENTS_CREATE", {
1610
+ type: e.type,
1611
+ data: n,
1612
+ options: t
1613
+ });
1614
+ return i("tokenIntents.create successful", { intentId: r.id }), r;
1615
+ } catch (e) {
1616
+ throw i("tokenIntents.create failed", { error: e.message }), e;
1617
+ }
1618
+ }),
1619
+ get: g(async (e, t) => {
1620
+ if (i("tokenIntents.get called", { intentId: e }), s || await P(), !s) throw Error("Coordinator failed to initialize");
1621
+ try {
1622
+ let n = await s.sendRequest("CMD_TOKEN_INTENTS_GET", {
1623
+ id: e,
1624
+ options: t
1625
+ });
1626
+ return i("tokenIntents.get successful", { intentId: n.id }), n;
1627
+ } catch (e) {
1628
+ throw i("tokenIntents.get failed", { error: e.message }), e;
1629
+ }
1630
+ })
1631
+ },
1632
+ proxy: (() => {
1633
+ let e = g(async (e, t = {}) => {
1634
+ if (ne({
1635
+ ...t,
1636
+ method: e
1637
+ }), i("proxy invoked", {
1638
+ method: e,
1639
+ hasUrl: !!t.url,
1640
+ hasProxyKey: !!t.proxyKey,
1641
+ hasApiKey: !!t.apiKey
1642
+ }), s || (i("Waiting for coordinator initialization"), await P()), !s) throw v("Coordinator failed to initialize");
1643
+ let n = t.body === void 0 ? void 0 : V(t.body);
1644
+ try {
1645
+ let r = await s.sendRequest("CMD_PROXY", {
1646
+ method: e,
1647
+ url: t.url,
1648
+ proxyKey: t.proxyKey,
1649
+ headers: t.headers,
1650
+ body: n,
1651
+ includeResponseHeaders: t.includeResponseHeaders,
1652
+ apiKey: t.apiKey
1653
+ }, { retries: 0 });
1654
+ return i("proxy successful", { method: e }), r;
1655
+ } catch (t) {
1656
+ throw i("proxy failed", {
1657
+ method: e,
1658
+ error: t.message
1659
+ }), t;
1660
+ }
1661
+ }), t = (t) => (n) => e(t, n ?? {});
1662
+ return {
1663
+ get: t("GET"),
1664
+ post: t("POST"),
1665
+ put: t("PUT"),
1666
+ patch: t("PATCH"),
1667
+ delete: t("DELETE")
1668
+ };
1669
+ })(),
1670
+ client: (() => {
1671
+ let e = g(async (e, t, n, a = {}) => {
1672
+ if (!r.allowHttpClient) throw b("bt.client requires allowHttpClient: true on BasisTheory() initialization. Sending card data to a third party may affect PCI scope and must be enabled deliberately.", {
1673
+ received: r.allowHttpClient,
1674
+ expected: !0
1675
+ });
1676
+ if (te({
1677
+ url: t,
1678
+ method: e,
1679
+ headers: a?.headers
1680
+ }), i("client invoked", {
1681
+ method: e,
1682
+ hasBody: n !== void 0
1683
+ }), s || (i("Waiting for coordinator initialization"), await P()), !s) throw v("Coordinator failed to initialize");
1684
+ let o = n === void 0 ? void 0 : V(n);
1685
+ try {
1686
+ let n = await s.sendRequest("CMD_HTTP_CLIENT", {
1687
+ method: e,
1688
+ url: t,
1689
+ headers: a?.headers,
1690
+ body: o
1691
+ }, { retries: 0 });
1692
+ return i("client successful", { method: e }), n;
1693
+ } catch (t) {
1694
+ i("client failed", {
1695
+ method: e,
1696
+ error: t.message
1697
+ });
1698
+ let n = t;
1699
+ throw n.code === "HTTP_CLIENT_ERROR" ? ee(n.message.replace(/^\[HTTP_CLIENT_ERROR\] /, ""), n.status ?? -1, n.data, n.headers) : t;
1700
+ }
1701
+ }), t = (t) => (n, r, i) => e(t, n, r, i ?? {}), n = (t) => (n, r) => e(t, n, void 0, r ?? {});
1702
+ return {
1703
+ get: n("GET"),
1704
+ post: t("POST"),
1705
+ put: t("PUT"),
1706
+ patch: t("PATCH"),
1707
+ delete: n("DELETE")
1708
+ };
1709
+ })(),
1710
+ updateThemeMode: g(async (e) => {
1711
+ i("updateThemeMode called", {
1712
+ oldMode: x,
1713
+ newMode: e,
1714
+ mountedElements: Array.from(a.values()).filter((e) => e.mounted).length
1715
+ }), x = e;
1716
+ let t = [];
1717
+ for (let [n, r] of a) if (r.mounted) {
1718
+ i("Sending theme mode update to element", {
1719
+ elementId: n,
1720
+ elementType: r.type,
1721
+ mode: e
1722
+ });
1723
+ let a = document.querySelector(`iframe[data-bt-element-id="${r.id}"]`);
1724
+ a && a.setAttribute("data-theme-mode", e);
1725
+ let o = r.update({ themeMode: e }).catch((e) => {
1726
+ i("Failed to update theme mode for element", {
1727
+ elementId: n,
1728
+ error: e.message
1729
+ });
1730
+ });
1731
+ t.push(o);
1732
+ }
1733
+ await Promise.all(t), i("Theme mode updated for all mounted elements", {
1734
+ mode: e,
1735
+ updatedCount: Array.from(a.values()).filter((e) => e.mounted).length
1736
+ });
1737
+ }),
1738
+ destroy: async () => {
1739
+ if (!p) {
1740
+ p = !0, i("Destroying SDK instance", {
1741
+ elementCount: a.size,
1742
+ hasCoordinator: o !== null
1743
+ });
1744
+ for (let [e, t] of a) if (t.mounted) try {
1745
+ t.unmount();
1746
+ } catch (t) {
1747
+ i("Failed to unmount element during destroy", {
1748
+ elementId: e,
1749
+ error: t.message
1750
+ });
1751
+ }
1752
+ if (a.clear(), d !== null && (clearTimeout(d), d = null), f &&= (f(b("SDK instance has been destroyed. Create a new instance with BasisTheory()")), null), s) {
1753
+ let e = 2e3, t = s.sendRequest("CMD_CLEAR_ALL_CACHE", {}, { retries: 0 }).catch((e) => {
1754
+ i("Failed to clear coordinator cache during destroy", { error: e.message });
1755
+ }), n, r = new Promise((t) => {
1756
+ n = setTimeout(() => {
1757
+ i("Coordinator cache-clear timed out during destroy", { timeoutMs: e }), t();
1758
+ }, e);
1759
+ });
1760
+ await Promise.race([t, r]), n !== void 0 && clearTimeout(n);
1761
+ }
1762
+ s &&= (s.destroy(), null), o &&= (o.remove(), null), c = null, l = !1, i("SDK instance destroyed");
1763
+ }
1764
+ }
1765
+ };
1766
+ if (n && n.length > 0) {
1767
+ i("Draining command queue from loader", {
1768
+ queueLength: n.length,
1769
+ commands: n.map((e) => e.method)
1770
+ });
1771
+ for (let e of n) try {
1772
+ let t = F[e.method];
1773
+ if (!t) throw Error(`Unknown method: ${e.method}`);
1774
+ i("Replaying queued command", {
1775
+ method: e.method,
1776
+ argsCount: e.args.length
1777
+ });
1778
+ let n = t(...e.args);
1779
+ n && typeof n.then == "function" ? n.then((t) => {
1780
+ i("Queued command completed (async)", { method: e.method }), e.resolve(t);
1781
+ }).catch((t) => {
1782
+ i("Queued command failed (async)", {
1783
+ method: e.method,
1784
+ error: t.message
1785
+ }), e.reject(t);
1786
+ }) : (i("Queued command completed (sync)", { method: e.method }), e.resolve(n));
1787
+ } catch (t) {
1788
+ i("Queued command failed (sync)", {
1789
+ method: e.method,
1790
+ error: t.message
1791
+ }), e.reject(t);
1792
+ }
1793
+ i("Command queue drain complete", { processedCount: n.length });
1794
+ }
1795
+ return F;
1796
+ };
1797
+ typeof window < "u" && typeof document < "u" && document.currentScript && !window.BasisTheory && (window.BasisTheory = $), typeof window < "u" && (window.__BasisTheorySDK__ = $);
1798
+ //#endregion
1799
+ export { B as a, I as c, R as i, m as l, b as n, z as o, y as r, L as s, $ as t };
1800
+
1801
+ //# sourceMappingURL=index-rGw83t5v-BE6naeQR.js.map