@basis-theory/web-elements 3.0.0-beta.5 → 3.0.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.
- package/dist/basis-theory-sdk.es.js +2 -2
- package/dist/basis-theory-sdk.umd.js +1 -1
- package/dist/basis-theory-sdk.umd.js.map +1 -1
- package/dist/{create-card-CB_YcP_4.js → create-card-C94szxMV.js} +12 -9
- package/dist/create-card-C94szxMV.js.map +1 -0
- package/dist/{create-card-display-kBupMJwe.js → create-card-display-DsLzA_vl.js} +13 -2
- package/dist/create-card-display-DsLzA_vl.js.map +1 -0
- package/dist/{create-copy-button-2XtKTEo3.js → create-copy-button-Z1s9ao67.js} +37 -12
- package/dist/create-copy-button-Z1s9ao67.js.map +1 -0
- package/dist/{index-Dyy7tm5Z.js → index-DIVQdm8b.js} +117 -23
- package/dist/index-DIVQdm8b.js.map +1 -0
- package/dist/index.d.ts +14 -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 +5 -5
- package/dist/.vite/manifest.json +0 -49
- package/dist/create-card-CB_YcP_4.js.map +0 -1
- package/dist/create-card-display-kBupMJwe.js.map +0 -1
- package/dist/create-copy-button-2XtKTEo3.js.map +0 -1
- package/dist/index-Dyy7tm5Z.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E as ElementError, c as createIframe, a as createPostMessageClient, b as createEventDispatcher, l as log,
|
|
1
|
+
import { E as ElementError, c as createIframe, a as createPostMessageClient, b as bindCoordinatorPort, d as createEventDispatcher, l as log, e as createMounter } from "./index-DIVQdm8b.js";
|
|
2
2
|
const DEFAULT_CARD_STACK_THRESHOLD = 400;
|
|
3
|
-
const createCardElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount) => {
|
|
3
|
+
const createCardElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
4
4
|
let iframe = null;
|
|
5
5
|
let client = null;
|
|
6
6
|
let mounter = null;
|
|
@@ -114,6 +114,12 @@ const createCardElement = (apiKey, sdkConfig, options = {}, coordinatorElementId
|
|
|
114
114
|
try {
|
|
115
115
|
await ensureCoordinatorReady();
|
|
116
116
|
await readyPromise;
|
|
117
|
+
await bindCoordinatorPort({
|
|
118
|
+
elementId: id,
|
|
119
|
+
elementType: type,
|
|
120
|
+
client,
|
|
121
|
+
coordinatorRequest
|
|
122
|
+
});
|
|
117
123
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
118
124
|
elementId: id,
|
|
119
125
|
apiKey,
|
|
@@ -162,14 +168,11 @@ const createCardElement = (apiKey, sdkConfig, options = {}, coordinatorElementId
|
|
|
162
168
|
if (!isMounted) {
|
|
163
169
|
throw ElementError("Element is not mounted");
|
|
164
170
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
log("Failed to notify coordinator of element unmount", {
|
|
169
|
-
error: error.message
|
|
170
|
-
});
|
|
171
|
+
notifyCoordinatorElementUnmount(id).catch((error) => {
|
|
172
|
+
log("Failed to notify coordinator of element unmount", {
|
|
173
|
+
error: error.message
|
|
171
174
|
});
|
|
172
|
-
}
|
|
175
|
+
});
|
|
173
176
|
if (client) {
|
|
174
177
|
client.destroy();
|
|
175
178
|
client = null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-card-C94szxMV.js","sources":["../src/elements/create-card.ts"],"sourcesContent":["/**\n * Card Element Factory (Unified)\n */\n\nimport type { PostMessageClient } from '@basis-theory-elements/postmessage';\nimport { createPostMessageClient } from '@basis-theory-elements/postmessage';\nimport { ElementError, log } from '@basis-theory-elements/shared';\nimport { createMounter } from '../mounter/create-mounter';\nimport type {\n CardElement,\n ElementMounter,\n ElementOptions,\n EventListener,\n EventType,\n SDKConfig,\n SubElementRef,\n} from '../types';\nimport type { CoordinatorRequest } from '../utils/bind-coordinator-port';\nimport { bindCoordinatorPort } from '../utils/bind-coordinator-port';\nimport { createIframe } from '../utils/create-iframe';\nimport { createEventDispatcher } from '../utils/create-event-dispatcher';\n\n/**\n * Default stack threshold in pixels for CardElement auto-layout\n * When container width is below this threshold, card inputs stack vertically\n */\nconst DEFAULT_CARD_STACK_THRESHOLD = 400;\n\n/**\n * Card element options\n */\nexport interface CardElementOptions {\n /** CSS styling */\n style?: Record<string, any>;\n\n /** Placeholder text for each sub-field */\n placeholder?: {\n cardNumber?: string;\n expiryDate?: string;\n cvc?: string;\n };\n\n /** Accessibility label */\n ariaLabel?: string;\n\n /** Disabled state (applies to all 3 sub-fields) */\n disabled?: boolean;\n\n /** Read-only state (applies to all 3 sub-fields) */\n readOnly?: boolean;\n\n /** Layout mode */\n layout?: 'row' | 'column' | 'auto';\n\n /** Stack threshold in pixels (only applies when layout: 'auto') */\n stackAt?: number;\n\n /** Icon position */\n iconPosition?: 'left' | 'right' | 'none';\n\n /** Restrict accepted card brands */\n cardBrands?: string[];\n\n /**\n * BIN enrichment for the card number field. Setting `coBadge` turns enrichment on and\n * overrides this — an explicit `binLookup: false` is ignored when `coBadge` is set.\n */\n binLookup?: boolean | { enabled?: boolean; debounceMs?: number };\n\n /** Co-badge options; forces BIN enrichment on when set, overriding `binLookup`. */\n coBadge?: {\n preferredNetworks?: string[];\n mode?: 'auto' | 'manual';\n };\n}\n\n/**\n * Factory function to create a unified card element\n * No class, pure functional approach with closure-based state\n */\nexport const createCardElement = (\n apiKey: string,\n sdkConfig: SDKConfig,\n options: CardElementOptions = {},\n coordinatorElementId: string,\n ensureCoordinatorReady: () => Promise<void>,\n notifyCoordinatorElementUnmount: (elementId: string) => Promise<void>, // ← Notify coordinator on unmount\n coordinatorRequest: CoordinatorRequest // ← Brokers this element's coordinator port\n): CardElement => {\n // Private state (closure)\n let iframe: HTMLIFrameElement | null = null;\n let client: PostMessageClient | null = null;\n let mounter: ElementMounter | null = null;\n let isMounted = false;\n let container: HTMLElement | null = null;\n let eventDispatcher: ReturnType<typeof createEventDispatcher> | null = null;\n\n // Event target for event emission\n const eventTarget = new EventTarget();\n\n // Use coordinator-generated ID for all references\n const id = coordinatorElementId;\n const type = 'card';\n\n // Setup event dispatcher\n const setupEventListeners = () => {\n if (!client) {\n return;\n }\n\n eventDispatcher = createEventDispatcher({\n elementType: type,\n elementId: id,\n client,\n eventTarget,\n });\n\n eventDispatcher.setupSubscriptions();\n };\n\n /**\n * Create sub-element reference for tokenization\n * These refs are used in bt.tokens.create() data payload\n */\n const createSubElementRef = (subId: string): SubElementRef => ({\n id: subId,\n type: 'card',\n get mounted() {\n return isMounted;\n },\n mount: () => {\n throw ElementError('Sub-field refs cannot be mounted independently');\n },\n unmount: () => {},\n update: () => Promise.resolve(),\n focus: () => {},\n blur: () => {},\n clear: () => {},\n on: () => () => {},\n });\n\n const numberRef = createSubElementRef(`${id}__number`);\n const expiryDateRef = createSubElementRef(`${id}__expiry`);\n const cvcRef = createSubElementRef(`${id}__cvc`);\n\n // Public API (Element interface with sub-field refs)\n const cardElement = {\n id,\n type,\n get mounted() {\n return isMounted;\n },\n get loaded() {\n return isMounted;\n },\n\n // Sub-field references for tokenization\n number: numberRef,\n expiryDate: expiryDateRef,\n cvc: cvcRef,\n\n mount: async (selector: string | HTMLElement) => {\n if (isMounted) {\n throw ElementError('Element is already mounted');\n }\n\n // Resolve container\n container =\n typeof selector === 'string'\n ? document.querySelector(selector)\n : selector;\n\n if (!container) {\n throw ElementError(`Container not found: ${selector}`);\n }\n\n // Create iframe\n const parentOrigin = window.location.origin;\n const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/card.html`);\n iframeUrl.searchParams.set('parentOrigin', parentOrigin);\n iframeUrl.searchParams.set('elementId', id);\n iframeUrl.searchParams.set(\n 'measurePerformance',\n String(sdkConfig.measurePerformance || false)\n );\n iframeUrl.searchParams.set('debug', String(sdkConfig.debug || false));\n\n iframe = createIframe({\n src: iframeUrl.toString(),\n sandbox: 'allow-scripts allow-same-origin',\n title: options.ariaLabel || 'Card Input',\n });\n\n // Add element ID and theme mode attributes\n iframe.setAttribute('data-bt-element-id', id);\n iframe.setAttribute('data-theme-mode', sdkConfig.themeMode || 'auto');\n\n // Create PostMessage client\n client = createPostMessageClient(iframe, {\n targetOrigin: sdkConfig.iframeOrigin,\n timeout: sdkConfig.timeoutMs,\n retries: sdkConfig.retryConfig.maxRetries,\n debug: sdkConfig.debug,\n });\n\n // Create mounter\n mounter = createMounter();\n\n // Set up event listeners\n setupEventListeners();\n\n // Subscribe to 'ready' event BEFORE mounting iframe\n const readyPromise = new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n ElementError(\n `Iframe EVENT_READY not received within ${sdkConfig.timeoutMs}ms`,\n id,\n { elementType: type, timeoutMs: sdkConfig.timeoutMs }\n )\n );\n }, sdkConfig.timeoutMs);\n\n const handleReady = () => {\n clearTimeout(timeout);\n resolve();\n };\n\n eventTarget.addEventListener('ready', handleReady, { once: true });\n });\n\n // Mount iframe to DOM (synchronous)\n mounter.mount(container, iframe, {\n timeoutMs: sdkConfig.timeoutMs,\n });\n\n isMounted = true;\n\n // Wait for coordinator + configuration to complete\n try {\n // Wait for coordinator (loads Core SDK if needed)\n await ensureCoordinatorReady();\n\n // Wait for EVENT_READY\n await readyPromise;\n\n // Bind the private channel before any value can be typed; all three\n // sub-values travel over this one port.\n await bindCoordinatorPort({\n elementId: id,\n elementType: type,\n client: client!,\n coordinatorRequest,\n });\n\n // Send initial configuration with card-specific options.\n // Omit `binLookup` / `coBadge` when undefined so the iframe never receives\n // explicit `undefined` (object literals include own keys with undefined values).\n await client!.sendRequest('CMD_SET_CONFIG', {\n elementId: id,\n apiKey,\n apiTimeout: sdkConfig.timeoutMs,\n apiRetries: sdkConfig.retryConfig.maxRetries,\n theme: sdkConfig.theme,\n darkTheme: sdkConfig.darkTheme,\n themeMode: sdkConfig.themeMode,\n placeholder: options.placeholder,\n ...(options.style !== undefined && { style: options.style }),\n disabled: options.disabled,\n readOnly: options.readOnly,\n layout: options.layout || 'auto',\n stackAt: options.stackAt || DEFAULT_CARD_STACK_THRESHOLD,\n iconPosition: options.iconPosition || 'left',\n ...(options.cardBrands !== undefined && { cardBrands: options.cardBrands }),\n ...(options.binLookup !== undefined && { binLookup: options.binLookup }),\n ...(options.coBadge !== undefined && { coBadge: options.coBadge }),\n debug: sdkConfig.debug,\n });\n\n // Reveal iframe now that theme is fully applied\n if (iframe) iframe.style.opacity = '1';\n } catch (error) {\n // Dispatch error event before cleanup\n if (eventDispatcher) {\n eventDispatcher.dispatchError(\n 'MOUNT_ERROR',\n (error as Error).message,\n error as Error\n );\n }\n\n // Mount failed - clean up and mark as unmounted\n isMounted = false;\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n\n throw error;\n }\n },\n\n unmount: () => {\n if (!isMounted) {\n throw ElementError('Element is not mounted');\n }\n\n // PCI DSS 3.2.1: the coordinator clears every value this element owns\n // (__number, __expiry, __cvc) and releases its port.\n notifyCoordinatorElementUnmount(id).catch((error) => {\n log('Failed to notify coordinator of element unmount', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n isMounted = false;\n },\n\n update: async (newOptions: Partial<ElementOptions> & { themeMode?: string }) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before updating');\n }\n\n const cardOptions = newOptions as Partial<CardElementOptions> & { themeMode?: string };\n\n // Only send fields that are present (matches create-card-number) so we never\n // overwrite iframe config with undefined/null over postMessage.\n const updatePayload: Record<string, any> = {\n elementId: id,\n };\n\n if (cardOptions.placeholder !== undefined) {\n updatePayload.placeholder = cardOptions.placeholder;\n }\n if (cardOptions.style !== undefined) {\n updatePayload.style = cardOptions.style;\n }\n if (cardOptions.disabled !== undefined) {\n updatePayload.disabled = cardOptions.disabled;\n }\n if (cardOptions.readOnly !== undefined) {\n updatePayload.readOnly = cardOptions.readOnly;\n }\n if (cardOptions.layout !== undefined) {\n updatePayload.layout = cardOptions.layout;\n }\n if (cardOptions.stackAt !== undefined) {\n updatePayload.stackAt = cardOptions.stackAt;\n }\n if (cardOptions.iconPosition !== undefined) {\n updatePayload.iconPosition = cardOptions.iconPosition;\n }\n if (cardOptions.cardBrands !== undefined) {\n updatePayload.cardBrands = cardOptions.cardBrands;\n }\n if (cardOptions.binLookup !== undefined) {\n updatePayload.binLookup = cardOptions.binLookup;\n }\n if (cardOptions.coBadge !== undefined) {\n updatePayload.coBadge = cardOptions.coBadge;\n }\n\n if (newOptions.themeMode !== undefined) {\n updatePayload.themeMode = newOptions.themeMode;\n updatePayload.theme = sdkConfig.theme;\n updatePayload.darkTheme = sdkConfig.darkTheme;\n }\n\n await client.sendRequest('CMD_UPDATE_CONFIG', updatePayload);\n },\n\n focus: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before focusing');\n }\n\n client.sendRequest('CMD_FOCUS', {});\n },\n\n blur: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before blurring');\n }\n\n client.sendRequest('CMD_BLUR', {});\n },\n\n clear: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before clearing');\n }\n\n client.sendRequest('CMD_CLEAR', {});\n },\n\n on: (eventType: EventType, listener: EventListener) => {\n eventTarget.addEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n\n // Return unsubscribe function\n return () =>\n eventTarget.removeEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n },\n\n setNetwork: async (network: string) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before setNetwork');\n }\n await client.sendRequest('CMD_SET_NETWORK', { network });\n },\n };\n\n return cardElement as CardElement;\n};\n"],"names":[],"mappings":";AA0BA,MAA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,QAAW;AACvC,sBAAc,YAAY,YAAY;AAAA,MACxC;AACA,UAAI,YAAY,YAAY,QAAW;AACrC,sBAAc,UAAU,YAAY;AAAA,MACtC;AAEA,UAAI,WAAW,cAAc,QAAW;AACtC,sBAAc,YAAY,WAAW;AACrC,sBAAc,QAAQ,UAAU;AAChC,sBAAc,YAAY,UAAU;AAAA,MACtC;AAEA,YAAM,OAAO,YAAY,qBAAqB,aAAa;AAAA,IAC7D;AAAA,IAEA,OAAO,MAAM;AACX,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,yCAAyC;AAAA,MAC9D;AAEA,aAAO,YAAY,aAAa,EAAE;AAAA,IACpC;AAAA,IAEA,MAAM,MAAM;AACV,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,yCAAyC;AAAA,MAC9D;AAEA,aAAO,YAAY,YAAY,EAAE;AAAA,IACnC;AAAA,IAEA,OAAO,MAAM;AACX,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,yCAAyC;AAAA,MAC9D;AAEA,aAAO,YAAY,aAAa,EAAE;AAAA,IACpC;AAAA,IAEA,IAAI,CAAC,WAAsB,aAA4B;AACrD,kBAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAIF,aAAO,MACL,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAAA,IAEN;AAAA,IAEA,YAAY,OAAO,YAAoB;AACrC,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,2CAA2C;AAAA,MAChE;AACA,YAAM,OAAO,YAAY,mBAAmB,EAAE,SAAS;AAAA,IACzD;AAAA,EAAA;AAGF,SAAO;AACT;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as ConfigurationError, E as ElementError, c as createIframe, a as createPostMessageClient, l as log,
|
|
1
|
+
import { C as ConfigurationError, E as ElementError, c as createIframe, a as createPostMessageClient, b as bindCoordinatorPort, l as log, e as createMounter } from "./index-DIVQdm8b.js";
|
|
2
2
|
const SESSION_AUTH_TIMEOUT_MS = 3e4;
|
|
3
|
-
const createCardDisplayElement = (_apiKey, sdkConfig, options, coordinatorElementId, ensureCoordinatorReady,
|
|
3
|
+
const createCardDisplayElement = (_apiKey, sdkConfig, options, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
4
4
|
if (!options.tokenId || typeof options.tokenId !== "string") {
|
|
5
5
|
throw ConfigurationError("tokenId is required for cardDisplay element");
|
|
6
6
|
}
|
|
@@ -168,6 +168,12 @@ const createCardDisplayElement = (_apiKey, sdkConfig, options, coordinatorElemen
|
|
|
168
168
|
try {
|
|
169
169
|
await ensureCoordinatorReady();
|
|
170
170
|
await readyPromise;
|
|
171
|
+
await bindCoordinatorPort({
|
|
172
|
+
elementId: id,
|
|
173
|
+
elementType: type,
|
|
174
|
+
client,
|
|
175
|
+
coordinatorRequest
|
|
176
|
+
});
|
|
171
177
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
172
178
|
elementId: id,
|
|
173
179
|
tokenId: currentTokenId,
|
|
@@ -208,6 +214,11 @@ const createCardDisplayElement = (_apiKey, sdkConfig, options, coordinatorElemen
|
|
|
208
214
|
throw ElementError("Element is not mounted");
|
|
209
215
|
}
|
|
210
216
|
void releaseDisplaySession();
|
|
217
|
+
notifyCoordinatorElementUnmount(id).catch((error) => {
|
|
218
|
+
log("Failed to notify coordinator of element unmount", {
|
|
219
|
+
error: error.message
|
|
220
|
+
});
|
|
221
|
+
});
|
|
211
222
|
if (client) {
|
|
212
223
|
client.sendRequest("CMD_CLEAR", {}).catch((error) => {
|
|
213
224
|
log("Failed to send clear command", {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-card-display-DsLzA_vl.js","sources":["../src/elements/create-card-display.ts"],"sourcesContent":["/**\n * Card Display Element Factory\n *\n * Iframe lifecycle for read-only display of tokenized card data.\n * Token loading is orchestrated by BasisTheory.ts — this factory\n * only handles iframe creation, mounting, config, and events.\n */\n\nimport type { PostMessageClient } from '@basis-theory-elements/postmessage';\nimport { createPostMessageClient } from '@basis-theory-elements/postmessage';\nimport { ConfigurationError, ElementError, log } from '@basis-theory-elements/shared';\nimport { createMounter } from '../mounter/create-mounter';\nimport type {\n CardDisplayElement,\n CardDisplayEventType,\n CardDisplayOptions,\n ElementMounter,\n EventListener,\n SDKConfig,\n} from '../types';\nimport type { CoordinatorRequest } from '../utils/bind-coordinator-port';\nimport { bindCoordinatorPort } from '../utils/bind-coordinator-port';\nimport { createIframe } from '../utils/create-iframe';\n\n/**\n * Factory function to create a card display element\n */\n// Authorization request to the merchant backend can be slow; bound it so a\n// hung endpoint surfaces as an error instead of leaving the element loading.\nconst SESSION_AUTH_TIMEOUT_MS = 30_000;\n\nexport const createCardDisplayElement = (\n _apiKey: string, // Unused - coordinator handles API calls\n sdkConfig: SDKConfig,\n options: CardDisplayOptions,\n coordinatorElementId: string,\n ensureCoordinatorReady: () => Promise<void>,\n notifyCoordinatorElementUnmount: (elementId: string) => Promise<void>,\n coordinatorRequest: CoordinatorRequest\n): CardDisplayElement => {\n // Validate required options\n if (!options.tokenId || typeof options.tokenId !== 'string') {\n throw ConfigurationError('tokenId is required for cardDisplay element');\n }\n\n // Private state (closure)\n let iframe: HTMLIFrameElement | null = null;\n let client: PostMessageClient | null = null;\n let mounter: ElementMounter | null = null;\n let isMounted = false;\n let isLoaded = false;\n let container: HTMLElement | null = null;\n let currentTokenId = options.tokenId;\n\n const eventTarget = new EventTarget();\n const id = coordinatorElementId;\n const type = 'cardDisplay' as const;\n\n /**\n * Dispatch custom event to listeners\n */\n const dispatchEvent = (eventType: CardDisplayEventType, detail: Record<string, unknown>): void => {\n eventTarget.dispatchEvent(new CustomEvent(eventType, {\n detail: {\n elementType: type,\n elementId: id,\n timestamp: Date.now(),\n ...detail,\n },\n }));\n };\n\n /**\n * Dispatch a display-load failure to listeners with a specific error code,\n * mirroring the codes the coordinator broadcasts so the consumer sees one\n * consistent vocabulary regardless of which hop failed.\n */\n const dispatchLoadError = (code: string, error: unknown): void => {\n log('Failed to load display token', {\n elementId: id,\n code,\n error: (error as Error).message,\n });\n\n dispatchEvent('error', { code, message: (error as Error).message });\n };\n\n /**\n * Best-effort release of the coordinator-held session after a parent-side\n * failure (or unmount). Without this the session key would linger in the\n * coordinator until the lazy TTL sweep — undesirable in a PCI context.\n */\n const releaseDisplaySession = async (): Promise<void> => {\n try {\n await coordinatorRequest('CMD_CLEAR_DISPLAY_SESSION', { elementId: id });\n } catch (error) {\n log('Failed to release display session', {\n elementId: id,\n error: (error as Error).message,\n });\n }\n };\n\n /**\n * Drive the display-token flow across the iframe boundary.\n *\n * 1. Ask the coordinator to create a session and return its nonce.\n * 2. Authorize the session against the merchant backend FROM HERE (the parent\n * page). The coordinator iframe's CSP `connect-src` only allows BasisTheory\n * domains, so it can't reach an arbitrary merchant URL — the merchant's own\n * page can, because the merchant controls its CSP and cookies flow here.\n * 3. Tell the coordinator to retrieve the token and broadcast it to the iframe.\n *\n * Fire-and-forget from the caller's perspective: failures surface as an\n * 'error' event rather than rejecting mount()/update().\n */\n const loadDisplayToken = async (tokenId: string): Promise<void> => {\n // Check config before creating a session we couldn't use anyway.\n if (!sdkConfig.sessionAuthorizationUrl) {\n dispatchLoadError(\n 'SESSION_AUTHORIZATION_FAILED',\n ConfigurationError('sessionAuthorizationUrl is required to load cardDisplay data')\n );\n\n return;\n }\n\n // Hop 1: coordinator creates the session, returns the nonce. A null nonce\n // means createDisplaySession already broadcast a DISPLAY_LOAD_ERROR to the\n // element — return without dispatching again so we don't double-report.\n let nonce: string;\n\n try {\n const result = await coordinatorRequest<{ nonce: string | null }>(\n 'CMD_CREATE_DISPLAY_SESSION',\n { tokenId, elementId: id }\n );\n\n if (!result?.nonce) {\n return;\n }\n\n nonce = result.nonce;\n } catch (error) {\n dispatchLoadError('SESSION_CREATION_FAILED', error);\n\n return;\n }\n\n // Hop 2: authorize via the merchant backend (runs in the parent page)\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), SESSION_AUTH_TIMEOUT_MS);\n\n let authResponse: Response;\n\n try {\n authResponse = await fetch(sdkConfig.sessionAuthorizationUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n // No credentials: the request only carries the session nonce, and\n // sending credentials is incompatible with a wildcard CORS origin\n // (Access-Control-Allow-Origin: *), which merchant authorize endpoints\n // commonly use.\n body: JSON.stringify({ nonce }),\n signal: controller.signal,\n });\n } catch (error) {\n // Network failure or timeout abort — release the orphaned coordinator session.\n await releaseDisplaySession();\n dispatchLoadError('NETWORK_ERROR', error);\n\n return;\n } finally {\n clearTimeout(timeout);\n }\n\n if (!authResponse.ok) {\n await releaseDisplaySession();\n dispatchLoadError(\n 'SESSION_AUTHORIZATION_FAILED',\n ElementError(\n `Session authorization failed: ${authResponse.status} ${authResponse.statusText}`,\n id\n )\n );\n\n return;\n }\n\n // Hop 3: coordinator retrieves the token and sends it to the iframe.\n // Card values reach the element over its coordinator port\n // (DISPLAY_VALUE_UPDATED), never through this response — keep it that way\n // for PCI isolation.\n // Retrieval errors are broadcast by the coordinator (throwOnError: false), so\n // a rejection here means the request itself failed to reach the coordinator.\n try {\n await coordinatorRequest('CMD_RETRIEVE_DISPLAY_TOKEN', {\n tokenId,\n elementId: id,\n });\n } catch (error) {\n dispatchLoadError('TOKEN_RETRIEVAL_FAILED', error);\n }\n };\n\n const element: CardDisplayElement = {\n id,\n type,\n\n get mounted() {\n return isMounted;\n },\n\n get loaded() {\n return isLoaded;\n },\n\n mount: async (selector: string | HTMLElement) => {\n if (isMounted) {\n throw ElementError('Element is already mounted', id);\n }\n\n container = typeof selector === 'string'\n ? document.querySelector(selector)\n : selector;\n\n if (!container) {\n throw ElementError(`Container not found: ${selector}`);\n }\n\n // Create iframe URL\n const parentOrigin = window.location.origin;\n const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/card-display.html`);\n iframeUrl.searchParams.set('parentOrigin', parentOrigin);\n iframeUrl.searchParams.set('elementId', id);\n iframeUrl.searchParams.set('debug', String(sdkConfig.debug || false));\n\n iframe = createIframe({\n src: iframeUrl.toString(),\n sandbox: 'allow-scripts allow-same-origin',\n allow: 'clipboard-write',\n title: 'Card Display',\n });\n\n iframe.setAttribute('data-bt-element-id', id);\n\n client = createPostMessageClient(iframe, {\n targetOrigin: sdkConfig.iframeOrigin,\n timeout: sdkConfig.timeoutMs,\n retries: sdkConfig.retryConfig.maxRetries,\n debug: sdkConfig.debug,\n });\n\n mounter = createMounter();\n\n // Subscribe to ready event before mounting\n const readyPromise = new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(ElementError(\n `Iframe EVENT_READY not received within ${sdkConfig.timeoutMs}ms`,\n id,\n { elementType: type, timeoutMs: sdkConfig.timeoutMs }\n ));\n }, sdkConfig.timeoutMs);\n\n const unsubscribe = client!.subscribe('EVENT_READY', () => {\n clearTimeout(timeout);\n unsubscribe();\n resolve();\n });\n });\n\n // Subscribe to iframe events\n client.subscribe('EVENT_CHANGE', (payload: Record<string, unknown>) => {\n if (payload.loaded) {\n isLoaded = true;\n }\n\n dispatchEvent('change', payload);\n });\n\n client.subscribe('EVENT_ERROR', (payload: Record<string, unknown>) => {\n dispatchEvent('error', payload);\n });\n\n // Mount iframe\n mounter.mount(container, iframe, {\n timeoutMs: sdkConfig.timeoutMs,\n });\n\n isMounted = true;\n\n try {\n // Ensure coordinator is ready\n await ensureCoordinatorReady();\n\n // Wait for iframe ready\n await readyPromise;\n\n // Card data arrives on this port, so bind before the token load starts\n await bindCoordinatorPort({\n elementId: id,\n elementType: type,\n client: client!,\n coordinatorRequest,\n });\n\n // Send initial configuration\n await client!.sendRequest('CMD_SET_CONFIG', {\n elementId: id,\n tokenId: currentTokenId,\n theme: sdkConfig.theme,\n darkTheme: sdkConfig.darkTheme,\n themeMode: sdkConfig.themeMode,\n number: options.number,\n cvc: options.cvc,\n expiration: options.expiration,\n debug: sdkConfig.debug,\n });\n\n // Reveal iframe\n if (iframe) iframe.style.opacity = '1';\n\n // Dispatch ready event\n dispatchEvent('ready', {});\n\n // Drive the display-token flow from the parent page (session create ->\n // merchant authorization -> token retrieve). Fire-and-forget: a token\n // load failure surfaces as an 'error' event, not a mount() rejection.\n if (currentTokenId) {\n void loadDisplayToken(currentTokenId);\n }\n\n } catch (error) {\n // Dispatch error event\n dispatchEvent('error', {\n code: 'MOUNT_ERROR',\n message: (error as Error).message,\n });\n\n // Cleanup on failure\n isMounted = false;\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n container = null;\n\n throw error;\n }\n },\n\n unmount: () => {\n if (!isMounted) {\n throw ElementError('Element is not mounted');\n }\n\n // Release any in-flight coordinator-held session so its key doesn't\n // outlive the element (PCI). Fire-and-forget — unmount stays synchronous.\n void releaseDisplaySession();\n\n // Releases this element's coordinator port\n notifyCoordinatorElementUnmount(id).catch((error) => {\n log('Failed to notify coordinator of element unmount', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n // Send clear command for PCI compliance\n if (client) {\n client.sendRequest('CMD_CLEAR', {}).catch((error) => {\n log('Failed to send clear command', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n container = null;\n isMounted = false;\n isLoaded = false;\n },\n\n update: async (newOptions: Partial<CardDisplayOptions> & { themeMode?: string }) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before updating', id);\n }\n\n // If tokenId changed, reset state and re-run the token load\n if (newOptions.tokenId !== undefined && newOptions.tokenId !== currentTokenId) {\n currentTokenId = newOptions.tokenId;\n isLoaded = false;\n\n await client.sendRequest('CMD_CLEAR', {});\n\n // Re-run the parent-driven token load for the new tokenId\n void loadDisplayToken(currentTokenId);\n }\n\n // Update display configurations\n const updatePayload: Record<string, unknown> = {};\n\n if (newOptions.number !== undefined) {\n updatePayload.number = newOptions.number;\n }\n if (newOptions.cvc !== undefined) {\n updatePayload.cvc = newOptions.cvc;\n }\n if (newOptions.expiration !== undefined) {\n updatePayload.expiration = newOptions.expiration;\n }\n\n // Include theme mode update if provided\n if (newOptions.themeMode !== undefined) {\n updatePayload.themeMode = newOptions.themeMode;\n updatePayload.theme = sdkConfig.theme;\n updatePayload.darkTheme = sdkConfig.darkTheme;\n }\n\n if (Object.keys(updatePayload).length > 0) {\n await client.sendRequest('CMD_UPDATE_CONFIG', updatePayload);\n }\n },\n\n on: (eventType: CardDisplayEventType, listener: EventListener) => {\n eventTarget.addEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n\n return () => eventTarget.removeEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n },\n\n // No-ops for API compatibility with Element interface\n focus: () => {},\n blur: () => {},\n clear: () => {},\n };\n\n return element;\n};\n"],"names":[],"mappings":";AA6BA,MAAM,0BAA0B;AAEzB,MAAM,2BAA2B,CACtC,SACA,WACA,SACA,sBACA,wBACA,iCACA,uBACuB;AAEvB,MAAI,CAAC,QAAQ,WAAW,OAAO,QAAQ,YAAY,UAAU;AAC3D,UAAM,mBAAmB,6CAA6C;AAAA,EACxE;AAGA,MAAI,SAAmC;AACvC,MAAI,SAAmC;AACvC,MAAI,UAAiC;AACrC,MAAI,YAAY;AAChB,MAAI,WAAW;AACf,MAAI,YAAgC;AACpC,MAAI,iBAAiB,QAAQ;AAE7B,QAAM,cAAc,IAAI,YAAA;AACxB,QAAM,KAAK;AACX,QAAM,OAAO;AAKb,QAAM,gBAAgB,CAAC,WAAiC,WAA0C;AAChG,gBAAY,cAAc,IAAI,YAAY,WAAW;AAAA,MACnD,QAAQ;AAAA,QACN,aAAa;AAAA,QACb,WAAW;AAAA,QACX,WAAW,KAAK,IAAA;AAAA,QAChB,GAAG;AAAA,MAAA;AAAA,IACL,CACD,CAAC;AAAA,EACJ;AAOA,QAAM,oBAAo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;AACA,UAAI,WAAW,eAAe,QAAW;AACvC,sBAAc,aAAa,WAAW;AAAA,MACxC;AAGA,UAAI,WAAW,cAAc,QAAW;AACtC,sBAAc,YAAY,WAAW;AACrC,sBAAc,QAAQ,UAAU;AAChC,sBAAc,YAAY,UAAU;AAAA,MACtC;AAEA,UAAI,OAAO,KAAK,aAAa,EAAE,SAAS,GAAG;AACzC,cAAM,OAAO,YAAY,qBAAqB,aAAa;AAAA,MAC7D;AAAA,IACF;AAAA,IAEA,IAAI,CAAC,WAAiC,aAA4B;AAChE,kBAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAGF,aAAO,MAAM,YAAY;AAAA,QACvB;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ;AAAA;AAAA,IAGA,OAAO,MAAM;AAAA,IAAC;AAAA,IACd,MAAM,MAAM;AAAA,IAAC;AAAA,IACb,OAAO,MAAM;AAAA,IAAC;AAAA,EAAA;AAGhB,SAAO;AACT;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigurationError, l as log, E as ElementError,
|
|
2
|
-
const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorElementId, ensureCoordinatorReady,
|
|
1
|
+
import { C as ConfigurationError, l as log, E as ElementError, c as createIframe, a as createPostMessageClient, b as bindCoordinatorPort, d as createEventDispatcher, e as createMounter } from "./index-DIVQdm8b.js";
|
|
2
|
+
const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
3
3
|
const options = inputOptions;
|
|
4
4
|
if ((options == null ? void 0 : options.allowClipboard) !== true) {
|
|
5
5
|
throw ConfigurationError(
|
|
@@ -11,6 +11,16 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
11
11
|
}
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
|
+
if (!sdkConfig.allowClipboard) {
|
|
15
|
+
throw ConfigurationError(
|
|
16
|
+
"CopyButton also requires allowClipboard: true on BasisTheory() initialization. The coordinator only honors copy references when clipboard access was enabled at init.",
|
|
17
|
+
{
|
|
18
|
+
received: sdkConfig.allowClipboard,
|
|
19
|
+
expected: true,
|
|
20
|
+
elementType: "copyButton"
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
14
24
|
let iframe = null;
|
|
15
25
|
let client = null;
|
|
16
26
|
let mounter = null;
|
|
@@ -59,12 +69,10 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
59
69
|
if (!container) {
|
|
60
70
|
throw ElementError(`Container not found: ${selector}`);
|
|
61
71
|
}
|
|
62
|
-
const signature = generateId();
|
|
63
72
|
const parentOrigin = window.location.origin;
|
|
64
73
|
const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/copy-button.html`);
|
|
65
74
|
iframeUrl.searchParams.set("parentOrigin", parentOrigin);
|
|
66
75
|
iframeUrl.searchParams.set("elementId", id);
|
|
67
|
-
iframeUrl.searchParams.set("signature", signature);
|
|
68
76
|
iframeUrl.searchParams.set(
|
|
69
77
|
"measurePerformance",
|
|
70
78
|
String(sdkConfig.measurePerformance || false)
|
|
@@ -109,10 +117,14 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
109
117
|
try {
|
|
110
118
|
await ensureCoordinatorReady();
|
|
111
119
|
await readyPromise;
|
|
120
|
+
await bindCoordinatorPort({
|
|
121
|
+
elementId: id,
|
|
122
|
+
elementType: type,
|
|
123
|
+
client,
|
|
124
|
+
coordinatorRequest
|
|
125
|
+
});
|
|
112
126
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
113
127
|
elementId: id,
|
|
114
|
-
signature,
|
|
115
|
-
// Must match URL param signature for iframe to operate
|
|
116
128
|
theme: sdkConfig.theme,
|
|
117
129
|
darkTheme: sdkConfig.darkTheme,
|
|
118
130
|
themeMode: sdkConfig.themeMode,
|
|
@@ -149,6 +161,11 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
149
161
|
if (!isMounted) {
|
|
150
162
|
throw ElementError("Element is not mounted");
|
|
151
163
|
}
|
|
164
|
+
notifyCoordinatorElementUnmount(id).catch((error) => {
|
|
165
|
+
log("Failed to notify coordinator of element unmount", {
|
|
166
|
+
error: error.message
|
|
167
|
+
});
|
|
168
|
+
});
|
|
152
169
|
if (client) {
|
|
153
170
|
client.destroy();
|
|
154
171
|
client = null;
|
|
@@ -210,9 +227,10 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
210
227
|
);
|
|
211
228
|
},
|
|
212
229
|
/**
|
|
213
|
-
* Link this copy button to another element's value
|
|
214
|
-
*
|
|
215
|
-
*
|
|
230
|
+
* Link this copy button to another element's value.
|
|
231
|
+
*
|
|
232
|
+
* Authorized by the coordinator, not the iframe: it checks both ids are ones
|
|
233
|
+
* it registered, then forwards the value over this button's port.
|
|
216
234
|
*/
|
|
217
235
|
setValueRef: async (refElement) => {
|
|
218
236
|
log("setValueRef called", {
|
|
@@ -224,9 +242,16 @@ const createCopyButtonElement = (_apiKey, sdkConfig, inputOptions, coordinatorEl
|
|
|
224
242
|
if (!isMounted || !client) {
|
|
225
243
|
throw ElementError("Element must be mounted before calling setValueRef", id);
|
|
226
244
|
}
|
|
227
|
-
await
|
|
228
|
-
|
|
229
|
-
|
|
245
|
+
const result = await coordinatorRequest(
|
|
246
|
+
"CMD_SET_COPY_REFERENCE",
|
|
247
|
+
{ elementId: id, referenceElementId: refElement.id }
|
|
248
|
+
);
|
|
249
|
+
if (!(result == null ? void 0 : result.success)) {
|
|
250
|
+
throw ElementError(
|
|
251
|
+
`Coordinator rejected the copy reference (${(result == null ? void 0 : result.error) ?? "UNKNOWN"})`,
|
|
252
|
+
id
|
|
253
|
+
);
|
|
254
|
+
}
|
|
230
255
|
}
|
|
231
256
|
};
|
|
232
257
|
return element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-copy-button-Z1s9ao67.js","sources":["../src/elements/create-copy-button.ts"],"sourcesContent":["/**\n * Copy Button Element Factory\n *\n * Creates a secure button that copies values to clipboard.\n * Can copy either a static value or a value from a linked BT element.\n *\n * SECURITY NOTE: This element is opt-in only via allowClipboard: true.\n * Clipboard access for raw card data may not be PCI compliant and must\n * never be enabled inadvertently.\n */\n\nimport type { PostMessageClient } from '@basis-theory-elements/postmessage';\nimport { createPostMessageClient } from '@basis-theory-elements/postmessage';\nimport { ConfigurationError, ElementError, log } from '@basis-theory-elements/shared';\nimport { createMounter } from '../mounter/create-mounter';\nimport type {\n CopyButtonElement,\n CopyButtonOptions,\n Element,\n ElementMounter,\n ElementOptions,\n EventListener,\n EventType,\n SDKConfig,\n} from '../types';\nimport type { CoordinatorRequest } from '../utils/bind-coordinator-port';\nimport { bindCoordinatorPort } from '../utils/bind-coordinator-port';\nimport { createIframe } from '../utils/create-iframe';\nimport { createEventDispatcher } from '../utils/create-event-dispatcher';\n\n/**\n * Factory function to create a copy button element\n *\n * @throws ConfigurationError if allowClipboard is not set to true\n */\nexport const createCopyButtonElement = (\n _apiKey: string, // Reserved for future API calls\n sdkConfig: SDKConfig,\n inputOptions: ElementOptions | CopyButtonOptions | undefined,\n coordinatorElementId: string,\n ensureCoordinatorReady: () => Promise<void>,\n notifyCoordinatorElementUnmount: (elementId: string) => Promise<void>,\n coordinatorRequest: CoordinatorRequest // ← Brokers this button's coordinator port\n): CopyButtonElement => {\n // SECURITY: Defense-in-depth check for allowClipboard flag\n // Primary validation is in validate-element-options.ts, but we keep this\n // as a backup in case the factory is called directly (e.g., lazy loading)\n const options = inputOptions as CopyButtonOptions | undefined;\n if (options?.allowClipboard !== true) {\n throw ConfigurationError(\n 'CopyButton requires allowClipboard: true. ' +\n 'Clipboard access for raw card data may not be PCI compliant ' +\n 'and must be explicitly enabled.',\n {\n received: options?.allowClipboard,\n expected: true,\n elementType: 'copyButton',\n }\n );\n }\n\n // The coordinator freezes clipboard access at initialization and refuses copy\n // references without it, so fail here rather than at setValueRef.\n if (!sdkConfig.allowClipboard) {\n throw ConfigurationError(\n 'CopyButton also requires allowClipboard: true on BasisTheory() ' +\n 'initialization. The coordinator only honors copy references when ' +\n 'clipboard access was enabled at init.',\n {\n received: sdkConfig.allowClipboard,\n expected: true,\n elementType: 'copyButton',\n }\n );\n }\n\n // Private state (closure)\n let iframe: HTMLIFrameElement | null = null;\n let client: PostMessageClient | null = null;\n let mounter: ElementMounter | null = null;\n let isMounted = false;\n let container: HTMLElement | null = null;\n let eventDispatcher: ReturnType<typeof createEventDispatcher> | null = null;\n\n const eventTarget = new EventTarget();\n const id = coordinatorElementId;\n const type = 'copyButton' as const;\n\n // Setup event dispatcher (centralized event mapping logic)\n const setupEventListeners = () => {\n if (!client) return;\n\n eventDispatcher = createEventDispatcher({\n elementType: type,\n elementId: id,\n client,\n eventTarget,\n });\n\n eventDispatcher.setupSubscriptions();\n\n // Subscribe to copy events from the iframe\n client.subscribe('EVENT_COPY', (payload) => {\n const event = new CustomEvent('copy', {\n detail: {\n elementType: type,\n elementId: id,\n timestamp: Date.now(),\n success: payload?.success ?? false,\n error: payload?.error,\n },\n });\n eventTarget.dispatchEvent(event);\n });\n };\n\n const element: CopyButtonElement = {\n id,\n type,\n get mounted() {\n return isMounted;\n },\n get loaded() {\n return isMounted;\n },\n\n mount: async (selector: string | HTMLElement) => {\n if (isMounted) {\n throw ElementError('Element is already mounted', id);\n }\n\n container =\n typeof selector === 'string'\n ? document.querySelector(selector)\n : selector;\n\n if (!container) {\n throw ElementError(`Container not found: ${selector}`);\n }\n\n // Pass parent origin + element ID via URL parameters\n const parentOrigin = window.location.origin;\n const iframeUrl = new URL(`${sdkConfig.elementsBaseUrl}/copy-button.html`);\n iframeUrl.searchParams.set('parentOrigin', parentOrigin);\n iframeUrl.searchParams.set('elementId', id);\n iframeUrl.searchParams.set(\n 'measurePerformance',\n String(sdkConfig.measurePerformance || false)\n );\n iframeUrl.searchParams.set('debug', String(sdkConfig.debug || false));\n\n iframe = createIframe({\n src: iframeUrl.toString(),\n sandbox: 'allow-scripts allow-same-origin',\n // clipboard-write is required for Firefox/Safari clipboard access in iframes\n allow: 'clipboard-write',\n title: 'Copy Button',\n });\n\n // Add element ID attribute for debugging\n iframe.setAttribute('data-bt-element-id', id);\n\n client = createPostMessageClient(iframe, {\n targetOrigin: sdkConfig.iframeOrigin,\n timeout: sdkConfig.timeoutMs,\n retries: sdkConfig.retryConfig.maxRetries,\n debug: sdkConfig.debug,\n });\n\n mounter = createMounter();\n setupEventListeners();\n\n // Subscribe to 'ready' event BEFORE mounting iframe (prevents race condition)\n const readyPromise = new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(\n ElementError(\n `Iframe EVENT_READY not received within ${sdkConfig.timeoutMs}ms`,\n id,\n { elementType: type, timeoutMs: sdkConfig.timeoutMs }\n )\n );\n }, sdkConfig.timeoutMs);\n\n const handleReady = () => {\n clearTimeout(timeout);\n resolve();\n };\n\n eventTarget.addEventListener('ready', handleReady, { once: true });\n });\n\n // Mount iframe to DOM\n mounter.mount(container, iframe, {\n timeoutMs: sdkConfig.timeoutMs,\n });\n\n isMounted = true;\n\n // Wait for coordinator + configuration to complete\n try {\n await ensureCoordinatorReady();\n await readyPromise;\n\n // Referenced values arrive only over this port, so a copy button framed\n // without the SDK has nothing to copy.\n await bindCoordinatorPort({\n elementId: id,\n elementType: type,\n client: client!,\n coordinatorRequest,\n });\n\n await client!.sendRequest('CMD_SET_CONFIG', {\n elementId: id,\n theme: sdkConfig.theme,\n darkTheme: sdkConfig.darkTheme,\n themeMode: sdkConfig.themeMode,\n text: options.text || 'Copy',\n value: options.value,\n disabled: options.disabled,\n debug: sdkConfig.debug,\n });\n\n // Reveal iframe now that theme is applied\n if (iframe) iframe.style.opacity = '1';\n } catch (error) {\n // Dispatch error event before cleanup\n if (eventDispatcher) {\n eventDispatcher.dispatchError(\n 'MOUNT_ERROR',\n (error as Error).message,\n error as Error\n );\n }\n\n // Mount failed - clean up\n isMounted = false;\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n\n throw error;\n }\n },\n\n unmount: () => {\n if (!isMounted) {\n throw ElementError('Element is not mounted');\n }\n\n // Drops the coordinator's copy reference and releases this button's port\n notifyCoordinatorElementUnmount(id).catch((error) => {\n log('Failed to notify coordinator of element unmount', {\n elementId: id,\n error: (error as Error).message,\n });\n });\n\n if (client) {\n client.destroy();\n client = null;\n }\n\n if (mounter && iframe) {\n mounter.unmount(iframe);\n iframe = null;\n mounter = null;\n }\n\n eventDispatcher = null;\n container = null;\n isMounted = false;\n },\n\n update: async (newOptions: Partial<CopyButtonOptions> & { themeMode?: string }) => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before updating', id);\n }\n\n // Only send fields that are present (matches create-card-number) so we never\n // overwrite iframe config with undefined/null over postMessage.\n const updatePayload: Record<string, any> = {};\n\n const copyButtonOptions = newOptions as Partial<CopyButtonOptions> & { themeMode?: string };\n\n if (copyButtonOptions.text !== undefined) {\n updatePayload.text = copyButtonOptions.text;\n }\n if (copyButtonOptions.value !== undefined) {\n updatePayload.value = copyButtonOptions.value;\n }\n if (copyButtonOptions.disabled !== undefined) {\n updatePayload.disabled = copyButtonOptions.disabled;\n }\n\n // Include theme mode update if provided\n if (newOptions.themeMode !== undefined) {\n updatePayload.themeMode = newOptions.themeMode;\n updatePayload.theme = sdkConfig.theme;\n updatePayload.darkTheme = sdkConfig.darkTheme;\n }\n\n await client.sendRequest('CMD_UPDATE_CONFIG', updatePayload);\n },\n\n focus: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before focusing', id);\n }\n\n client.sendRequest('CMD_FOCUS', {});\n },\n\n blur: () => {\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before blurring', id);\n }\n\n client.sendRequest('CMD_BLUR', {});\n },\n\n // No-op for CopyButton (nothing to clear in a button)\n clear: () => {},\n\n on: (eventType: EventType, listener: EventListener) => {\n eventTarget.addEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n\n return () =>\n eventTarget.removeEventListener(\n eventType,\n listener as EventListenerOrEventListenerObject\n );\n },\n\n /**\n * Link this copy button to another element's value.\n *\n * Authorized by the coordinator, not the iframe: it checks both ids are ones\n * it registered, then forwards the value over this button's port.\n */\n setValueRef: async (refElement: Element): Promise<void> => {\n log('setValueRef called', {\n copyButtonId: id,\n refElementId: refElement?.id,\n });\n\n if (!refElement || !refElement.id) {\n throw ElementError('setValueRef requires a valid Element with an ID', id);\n }\n\n if (!isMounted || !client) {\n throw ElementError('Element must be mounted before calling setValueRef', id);\n }\n\n const result = await coordinatorRequest<{ success: boolean; error?: string }>(\n 'CMD_SET_COPY_REFERENCE',\n { elementId: id, referenceElementId: refElement.id }\n );\n\n if (!result?.success) {\n throw ElementError(\n `Coordinator rejected the copy reference (${result?.error ?? 'UNKNOWN'})`,\n id\n );\n }\n },\n };\n\n return element;\n};\n"],"names":[],"mappings":";AAmCO,MAAM,0BAA0B,CACrC,SACA,WACA,cACA,sBACA,wBACA,iCACA,uBACsB;AAItB,QAAM,UAAU;AAChB,OAAI,mCAAS,oBAAmB,MAAM;AACpC,UAAM;AAAA,MACJ;AAAA,MAGA;AAAA,QACE,UAAU,mCAAS;AAAA,QACnB,UAAU;AAAA,QACV,aAAa;AAAA,MAAA;AAAA,IACf;AAAA,EAEJ;AAIA,MAAI,CAAC,UAAU,gBAAgB;AAC7B,UAAM;AAAA,MACJ;AAAA,MAGA;AAAA,QACE,UAAU,UAAU;AAAA,QACpB,UAAU;AAAA,QACV,aAAa;AAAA,MAAA;AAAA,IACf;AAAA,EAEJ;AAGA,MAAI,SAAmC;AACvC,MAAI,SAAmC;AACvC,MAAI,UAAiC;AACrC,MAAI,YAAY;AAChB,MAAI,YAAgC;AACpC,MAAI,kBAAmE;AA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AM,OAAO,YAAY,qBAAqB,aAAa;AAAA,IAC7D;AAAA,IAEA,OAAO,MAAM;AACX,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,2CAA2C,EAAE;AAAA,MAClE;AAEA,aAAO,YAAY,aAAa,EAAE;AAAA,IACpC;AAAA,IAEA,MAAM,MAAM;AACV,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,2CAA2C,EAAE;AAAA,MAClE;AAEA,aAAO,YAAY,YAAY,EAAE;AAAA,IACnC;AAAA;AAAA,IAGA,OAAO,MAAM;AAAA,IAAC;AAAA,IAEd,IAAI,CAAC,WAAsB,aAA4B;AACrD,kBAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAGF,aAAO,MACL,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAAA,IAEN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA,aAAa,OAAO,eAAuC;AACzD,UAAI,sBAAsB;AAAA,QAExB,cAAc,yCAAY;AAAA,MAAA,CAC3B;AAED,UAAI,CAAC,cAAc,CAAC,WAAW,IAAI;AACjC,cAAM,aAAa,mDAAmD,EAAE;AAAA,MAC1E;AAEA,UAAI,CAAC,aAAa,CAAC,QAAQ;AACzB,cAAM,aAAa,sDAAsD,EAAE;AAAA,MAC7E;AAEA,YAAM,SAAS,MAAM;AAAA,QACnB;AAAA,QACA,EAAE,WAAW,IAAI,oBAAoB,WAAW,GAAA;AAAA,MAAG;AAGrD,UAAI,EAAC,iCAAQ,UAAS;AACpB,cAAM;AAAA,UACJ,6CAA4C,iCAAQ,UAAS,SAAS;AAAA,UACtE;AAAA,QAAA;AAAA,MAEJ;AAAA,IACF;AAAA,EAAA;AAGF,SAAO;AACT;"}
|
|
@@ -488,7 +488,7 @@ const createPostMessageClient = (iframe, config) => {
|
|
|
488
488
|
};
|
|
489
489
|
window.addEventListener("message", handleMessage);
|
|
490
490
|
const retryConfig = typeof config.retries === "number" ? { ...DEFAULT_RETRY_CONFIG, maxRetries: config.retries } : typeof config.retries === "object" ? config.retries : DEFAULT_RETRY_CONFIG;
|
|
491
|
-
const sendRequestOnce = (type, payload) => {
|
|
491
|
+
const sendRequestOnce = (type, payload, transfer) => {
|
|
492
492
|
return new Promise((resolve, reject) => {
|
|
493
493
|
const nonce = generateId();
|
|
494
494
|
const timestamp = Date.now();
|
|
@@ -502,15 +502,21 @@ const createPostMessageClient = (iframe, config) => {
|
|
|
502
502
|
}, config.timeout || 5e3);
|
|
503
503
|
pendingRequests.set(nonce, { resolve, reject, timeout, timestamp });
|
|
504
504
|
log2("Sending request", { type, nonce });
|
|
505
|
-
|
|
505
|
+
const message = { type, nonce, timestamp, payload };
|
|
506
|
+
if (transfer == null ? void 0 : transfer.length) {
|
|
507
|
+
iframe.contentWindow.postMessage(message, config.targetOrigin, transfer);
|
|
508
|
+
} else {
|
|
509
|
+
iframe.contentWindow.postMessage(message, config.targetOrigin);
|
|
510
|
+
}
|
|
506
511
|
});
|
|
507
512
|
};
|
|
508
513
|
const sendRequest = async (type, payload, options) => {
|
|
509
|
-
|
|
514
|
+
var _a;
|
|
515
|
+
const maxRetries = ((_a = options == null ? void 0 : options.transfer) == null ? void 0 : _a.length) ? 0 : (options == null ? void 0 : options.retries) !== void 0 ? options.retries : retryConfig.maxRetries;
|
|
510
516
|
let lastError = null;
|
|
511
517
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
512
518
|
try {
|
|
513
|
-
return await sendRequestOnce(type, payload);
|
|
519
|
+
return await sendRequestOnce(type, payload, options == null ? void 0 : options.transfer);
|
|
514
520
|
} catch (error) {
|
|
515
521
|
lastError = error;
|
|
516
522
|
const errorMessage = error.message;
|
|
@@ -608,6 +614,54 @@ const createMounter = () => {
|
|
|
608
614
|
}
|
|
609
615
|
};
|
|
610
616
|
};
|
|
617
|
+
const CMD_REGISTER_ELEMENT = "CMD_REGISTER_ELEMENT";
|
|
618
|
+
const CMD_BIND_ELEMENT_PORT = "CMD_BIND_ELEMENT_PORT";
|
|
619
|
+
const CMD_BIND_COORDINATOR_PORT = "CMD_BIND_COORDINATOR_PORT";
|
|
620
|
+
const bindCoordinatorPort = async ({
|
|
621
|
+
elementId,
|
|
622
|
+
elementType,
|
|
623
|
+
client,
|
|
624
|
+
coordinatorRequest
|
|
625
|
+
}) => {
|
|
626
|
+
await coordinatorRequest(CMD_REGISTER_ELEMENT, {
|
|
627
|
+
elementId,
|
|
628
|
+
type: elementType
|
|
629
|
+
});
|
|
630
|
+
const channel = new MessageChannel();
|
|
631
|
+
const coordinatorBind = await coordinatorRequest(
|
|
632
|
+
CMD_BIND_ELEMENT_PORT,
|
|
633
|
+
{ elementId },
|
|
634
|
+
{ retries: 0, transfer: [channel.port2] }
|
|
635
|
+
);
|
|
636
|
+
if (!(coordinatorBind == null ? void 0 : coordinatorBind.success)) {
|
|
637
|
+
channel.port1.close();
|
|
638
|
+
throw ElementError(
|
|
639
|
+
`Coordinator rejected the element port (${(coordinatorBind == null ? void 0 : coordinatorBind.error) ?? "UNKNOWN"})`,
|
|
640
|
+
elementId,
|
|
641
|
+
{ elementType }
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
const elementBind = await client.sendRequest(
|
|
645
|
+
CMD_BIND_COORDINATOR_PORT,
|
|
646
|
+
{ elementId },
|
|
647
|
+
{ retries: 0, transfer: [channel.port1] }
|
|
648
|
+
).catch((error) => {
|
|
649
|
+
log("Failed to hand coordinator port to element", {
|
|
650
|
+
error: error.message
|
|
651
|
+
});
|
|
652
|
+
return { success: false, error: error.message };
|
|
653
|
+
});
|
|
654
|
+
if (!(elementBind == null ? void 0 : elementBind.success)) {
|
|
655
|
+
await coordinatorRequest("CMD_BROADCAST_ELEMENT_UNMOUNT", {
|
|
656
|
+
elementId
|
|
657
|
+
}).catch(() => void 0);
|
|
658
|
+
throw ElementError(
|
|
659
|
+
`Element rejected the coordinator port (${(elementBind == null ? void 0 : elementBind.error) ?? "UNKNOWN"})`,
|
|
660
|
+
elementId,
|
|
661
|
+
{ elementType }
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
611
665
|
const createIframe = (config) => {
|
|
612
666
|
const iframe = document.createElement("iframe");
|
|
613
667
|
iframe.src = config.src;
|
|
@@ -720,7 +774,7 @@ const createEventDispatcher = (config) => {
|
|
|
720
774
|
dispatchError
|
|
721
775
|
};
|
|
722
776
|
};
|
|
723
|
-
const createCardNumberElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount) => {
|
|
777
|
+
const createCardNumberElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
724
778
|
let iframe = null;
|
|
725
779
|
let client = null;
|
|
726
780
|
let mounter = null;
|
|
@@ -814,6 +868,12 @@ const createCardNumberElement = (apiKey, sdkConfig, options = {}, coordinatorEle
|
|
|
814
868
|
try {
|
|
815
869
|
await ensureCoordinatorReady();
|
|
816
870
|
await readyPromise;
|
|
871
|
+
await bindCoordinatorPort({
|
|
872
|
+
elementId: id,
|
|
873
|
+
elementType: type,
|
|
874
|
+
client,
|
|
875
|
+
coordinatorRequest
|
|
876
|
+
});
|
|
817
877
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
818
878
|
elementId: id,
|
|
819
879
|
// Include element ID for validation
|
|
@@ -942,7 +1002,7 @@ const createCardNumberElement = (apiKey, sdkConfig, options = {}, coordinatorEle
|
|
|
942
1002
|
}
|
|
943
1003
|
};
|
|
944
1004
|
};
|
|
945
|
-
const createCVVElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount) => {
|
|
1005
|
+
const createCVVElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
946
1006
|
let iframe = null;
|
|
947
1007
|
let client = null;
|
|
948
1008
|
let mounter = null;
|
|
@@ -1025,6 +1085,12 @@ const createCVVElement = (apiKey, sdkConfig, options = {}, coordinatorElementId,
|
|
|
1025
1085
|
try {
|
|
1026
1086
|
await ensureCoordinatorReady();
|
|
1027
1087
|
await readyPromise;
|
|
1088
|
+
await bindCoordinatorPort({
|
|
1089
|
+
elementId: id,
|
|
1090
|
+
elementType: type,
|
|
1091
|
+
client,
|
|
1092
|
+
coordinatorRequest
|
|
1093
|
+
});
|
|
1028
1094
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
1029
1095
|
elementId: id,
|
|
1030
1096
|
// Include element ID for validation
|
|
@@ -1135,7 +1201,7 @@ const createCVVElement = (apiKey, sdkConfig, options = {}, coordinatorElementId,
|
|
|
1135
1201
|
}
|
|
1136
1202
|
};
|
|
1137
1203
|
};
|
|
1138
|
-
const createExpiryElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount) => {
|
|
1204
|
+
const createExpiryElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
1139
1205
|
let iframe = null;
|
|
1140
1206
|
let client = null;
|
|
1141
1207
|
let mounter = null;
|
|
@@ -1218,6 +1284,12 @@ const createExpiryElement = (apiKey, sdkConfig, options = {}, coordinatorElement
|
|
|
1218
1284
|
try {
|
|
1219
1285
|
await ensureCoordinatorReady();
|
|
1220
1286
|
await readyPromise;
|
|
1287
|
+
await bindCoordinatorPort({
|
|
1288
|
+
elementId: id,
|
|
1289
|
+
elementType: type,
|
|
1290
|
+
client,
|
|
1291
|
+
coordinatorRequest
|
|
1292
|
+
});
|
|
1221
1293
|
await client.sendRequest("CMD_SET_CONFIG", {
|
|
1222
1294
|
elementId: id,
|
|
1223
1295
|
// Include element ID for validation
|
|
@@ -1324,7 +1396,7 @@ const createExpiryElement = (apiKey, sdkConfig, options = {}, coordinatorElement
|
|
|
1324
1396
|
}
|
|
1325
1397
|
};
|
|
1326
1398
|
};
|
|
1327
|
-
const createTextElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount) => {
|
|
1399
|
+
const createTextElement = (apiKey, sdkConfig, options = {}, coordinatorElementId, ensureCoordinatorReady, notifyCoordinatorElementUnmount, coordinatorRequest) => {
|
|
1328
1400
|
let iframe = null;
|
|
1329
1401
|
let client = null;
|
|
1330
1402
|
let mounter = null;
|
|
@@ -1414,6 +1486,12 @@ const createTextElement = (apiKey, sdkConfig, options = {}, coordinatorElementId
|
|
|
1414
1486
|
try {
|
|
1415
1487
|
await ensureCoordinatorReady();
|
|
1416
1488
|
await readyPromise;
|
|
1489
|
+
await bindCoordinatorPort({
|
|
1490
|
+
elementId: id,
|
|
1491
|
+
elementType: type,
|
|
1492
|
+
client,
|
|
1493
|
+
coordinatorRequest
|
|
1494
|
+
});
|
|
1417
1495
|
const serializedTransform = options.transform ? {
|
|
1418
1496
|
pattern: options.transform[0].source,
|
|
1419
1497
|
flags: options.transform[0].flags,
|
|
@@ -1738,6 +1816,7 @@ const KNOWN_SDK_KEYS = /* @__PURE__ */ new Set([
|
|
|
1738
1816
|
"whitelabelDomain",
|
|
1739
1817
|
"apiBaseUrl",
|
|
1740
1818
|
"debug",
|
|
1819
|
+
"allowClipboard",
|
|
1741
1820
|
"measurePerformance",
|
|
1742
1821
|
"timeoutMs",
|
|
1743
1822
|
"retryConfig",
|
|
@@ -1786,6 +1865,9 @@ const validateSDKConfig = (options = {}) => {
|
|
|
1786
1865
|
if (options.debug !== void 0 && typeof options.debug !== "boolean") {
|
|
1787
1866
|
throw ConfigurationError("debug must be a boolean");
|
|
1788
1867
|
}
|
|
1868
|
+
if (options.allowClipboard !== void 0 && typeof options.allowClipboard !== "boolean") {
|
|
1869
|
+
throw ConfigurationError("allowClipboard must be a boolean");
|
|
1870
|
+
}
|
|
1789
1871
|
if (options.measurePerformance !== void 0 && typeof options.measurePerformance !== "boolean") {
|
|
1790
1872
|
throw ConfigurationError("measurePerformance must be a boolean");
|
|
1791
1873
|
}
|
|
@@ -1846,10 +1928,10 @@ const validateSDKConfig = (options = {}) => {
|
|
|
1846
1928
|
}
|
|
1847
1929
|
throw ConfigurationError("whitelabelDomain must be a valid URL");
|
|
1848
1930
|
}
|
|
1849
|
-
const { pathname } = new URL("https://js.basistheory.com/3.0.0
|
|
1931
|
+
const { pathname } = new URL("https://js.basistheory.com/3.0.0/elements");
|
|
1850
1932
|
resolvedBaseUrl = `${domainOrigin}${pathname}`;
|
|
1851
1933
|
}
|
|
1852
|
-
const finalBaseUrl = resolvedBaseUrl || "https://js.basistheory.com/3.0.0
|
|
1934
|
+
const finalBaseUrl = resolvedBaseUrl || "https://js.basistheory.com/3.0.0/elements";
|
|
1853
1935
|
const iframeOrigin = new URL(finalBaseUrl).origin;
|
|
1854
1936
|
return {
|
|
1855
1937
|
iframeOrigin,
|
|
@@ -1857,6 +1939,7 @@ const validateSDKConfig = (options = {}) => {
|
|
|
1857
1939
|
apiBaseUrl: options.apiBaseUrl,
|
|
1858
1940
|
// Optional - auto-detects if not provided
|
|
1859
1941
|
debug: options.debug ?? false,
|
|
1942
|
+
allowClipboard: options.allowClipboard ?? false,
|
|
1860
1943
|
measurePerformance: options.measurePerformance ?? false,
|
|
1861
1944
|
timeoutMs: options.timeoutMs || 3e4,
|
|
1862
1945
|
// 30s default for slow 3G connections
|
|
@@ -2133,32 +2216,32 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2133
2216
|
});
|
|
2134
2217
|
}
|
|
2135
2218
|
};
|
|
2136
|
-
const sendCoordinatorRequest = async (command, payload) => {
|
|
2219
|
+
const sendCoordinatorRequest = async (command, payload, options2) => {
|
|
2137
2220
|
if (!coordinatorClient) {
|
|
2138
2221
|
throw CoordinatorError("Coordinator not initialized");
|
|
2139
2222
|
}
|
|
2140
|
-
return coordinatorClient.sendRequest(command, payload);
|
|
2223
|
+
return coordinatorClient.sendRequest(command, payload, options2);
|
|
2141
2224
|
};
|
|
2142
2225
|
let cardElementFactory = null;
|
|
2143
2226
|
let copyButtonElementFactory = null;
|
|
2144
2227
|
let cardDisplayElementFactory = null;
|
|
2145
2228
|
const lazyCardElement = async () => {
|
|
2146
2229
|
if (!cardElementFactory) {
|
|
2147
|
-
const module = await import("./create-card-
|
|
2230
|
+
const module = await import("./create-card-C94szxMV.js");
|
|
2148
2231
|
cardElementFactory = module.createCardElement;
|
|
2149
2232
|
}
|
|
2150
2233
|
return cardElementFactory;
|
|
2151
2234
|
};
|
|
2152
2235
|
const lazyCopyButtonElement = async () => {
|
|
2153
2236
|
if (!copyButtonElementFactory) {
|
|
2154
|
-
const module = await import("./create-copy-button-
|
|
2237
|
+
const module = await import("./create-copy-button-Z1s9ao67.js");
|
|
2155
2238
|
copyButtonElementFactory = module.createCopyButtonElement;
|
|
2156
2239
|
}
|
|
2157
2240
|
return copyButtonElementFactory;
|
|
2158
2241
|
};
|
|
2159
2242
|
const lazyCardDisplayElement = async () => {
|
|
2160
2243
|
if (!cardDisplayElementFactory) {
|
|
2161
|
-
const module = await import("./create-card-display-
|
|
2244
|
+
const module = await import("./create-card-display-DsLzA_vl.js");
|
|
2162
2245
|
cardDisplayElementFactory = module.createCardDisplayElement;
|
|
2163
2246
|
}
|
|
2164
2247
|
return cardDisplayElementFactory;
|
|
@@ -2255,6 +2338,9 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2255
2338
|
// Optional - auto-detects if not provided
|
|
2256
2339
|
apiTimeout: 3e4,
|
|
2257
2340
|
apiRetries: 3,
|
|
2341
|
+
// Frozen by the coordinator on this first config; copy references are
|
|
2342
|
+
// refused unless it's enabled here.
|
|
2343
|
+
allowClipboard: config.allowClipboard,
|
|
2258
2344
|
debug: config.debug || false,
|
|
2259
2345
|
theme: config.theme,
|
|
2260
2346
|
darkTheme: config.darkTheme,
|
|
@@ -2280,6 +2366,12 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2280
2366
|
if (elementOptions) {
|
|
2281
2367
|
validateElementOptions(type, elementOptions);
|
|
2282
2368
|
}
|
|
2369
|
+
if (type === "copyButton" && !config.allowClipboard) {
|
|
2370
|
+
throw ConfigurationError(
|
|
2371
|
+
"copyButton requires allowClipboard: true on BasisTheory() initialization. Clipboard access for raw card data may not be PCI compliant and must be enabled explicitly.",
|
|
2372
|
+
{ received: config.allowClipboard, expected: true, elementType: type }
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2283
2375
|
const localElementId = `${type}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
2284
2376
|
log2("Creating element (sync)", {
|
|
2285
2377
|
type,
|
|
@@ -2658,7 +2750,8 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2658
2750
|
log2("proxy invoked", {
|
|
2659
2751
|
method,
|
|
2660
2752
|
hasUrl: !!options2.url,
|
|
2661
|
-
hasProxyKey: !!options2.proxyKey
|
|
2753
|
+
hasProxyKey: !!options2.proxyKey,
|
|
2754
|
+
hasApiKey: !!options2.apiKey
|
|
2662
2755
|
});
|
|
2663
2756
|
if (!coordinatorClient) {
|
|
2664
2757
|
log2("Waiting for coordinator initialization");
|
|
@@ -2677,7 +2770,8 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2677
2770
|
proxyKey: options2.proxyKey,
|
|
2678
2771
|
headers: options2.headers,
|
|
2679
2772
|
body: resolvedBody,
|
|
2680
|
-
includeResponseHeaders: options2.includeResponseHeaders
|
|
2773
|
+
includeResponseHeaders: options2.includeResponseHeaders,
|
|
2774
|
+
apiKey: options2.apiKey
|
|
2681
2775
|
},
|
|
2682
2776
|
{ retries: 0 }
|
|
2683
2777
|
);
|
|
@@ -2866,8 +2960,8 @@ const BasisTheory = (apiKey, options = {}, queuedCommands) => {
|
|
|
2866
2960
|
if (typeof window !== "undefined" && typeof document !== "undefined" && document.currentScript && !window.BasisTheory) {
|
|
2867
2961
|
window.BasisTheory = BasisTheory;
|
|
2868
2962
|
}
|
|
2869
|
-
const version = "3.0.0
|
|
2870
|
-
const buildDate = "2026-
|
|
2963
|
+
const version = "3.0.0";
|
|
2964
|
+
const buildDate = "2026-08-13T19:30:19.198Z";
|
|
2871
2965
|
if (typeof window !== "undefined") {
|
|
2872
2966
|
window.__BasisTheorySDK__ = BasisTheory;
|
|
2873
2967
|
}
|
|
@@ -2876,11 +2970,11 @@ export {
|
|
|
2876
2970
|
ConfigurationError as C,
|
|
2877
2971
|
ElementError as E,
|
|
2878
2972
|
createPostMessageClient as a,
|
|
2879
|
-
|
|
2973
|
+
bindCoordinatorPort as b,
|
|
2880
2974
|
createIframe as c,
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2975
|
+
createEventDispatcher as d,
|
|
2976
|
+
createMounter as e,
|
|
2977
|
+
buildDate as f,
|
|
2884
2978
|
log as l,
|
|
2885
2979
|
version as v
|
|
2886
2980
|
};
|