@moonpay/platform-sdk-react-native 0.2.2 → 0.3.0-next.1

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/index.cjs CHANGED
@@ -181,12 +181,17 @@ function MoonPayProvider({
181
181
  });
182
182
  return { promise, transport };
183
183
  }
184
- async function getConnection() {
184
+ async function getConnection(options = {}) {
185
185
  const { privateKey, publicKey } = (0, import_platform_sdk_core.generateKeyPair)();
186
186
  const channelId = `check-${Date.now()}`;
187
187
  const url = (0, import_platform_sdk_core.buildFrameUrl)(
188
188
  import_platform_sdk_core.FRAME_PATHS.checkConnection,
189
- { sessionToken, channelId, publicKey },
189
+ {
190
+ sessionToken,
191
+ channelId,
192
+ publicKey,
193
+ ...options.skipKyc && { skipKyc: true }
194
+ },
190
195
  { frameBaseUrl }
191
196
  );
192
197
  try {
@@ -287,6 +292,66 @@ function MoonPayProvider({
287
292
  });
288
293
  }
289
294
  }
295
+ async function setupAuth(opts) {
296
+ const clientToken = core.context.clientToken;
297
+ if (!clientToken) {
298
+ return (0, import_platform_protocol.err)({
299
+ kind: "configurationError",
300
+ message: 'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
301
+ });
302
+ }
303
+ const { privateKey, publicKey } = (0, import_platform_sdk_core.generateKeyPair)();
304
+ const channelId = `auth-${Date.now()}`;
305
+ const url = (0, import_platform_sdk_core.buildFrameUrl)(
306
+ import_platform_sdk_core.FRAME_PATHS.auth,
307
+ { clientToken, channelId, publicKey },
308
+ { frameBaseUrl }
309
+ );
310
+ try {
311
+ const { promise } = createManagedFrame({ url, channelId, hidden: false });
312
+ const { handle, slotId } = await promise;
313
+ return new Promise((resolve) => {
314
+ handle.onMessage((msg) => {
315
+ if (msg.kind === "ready") {
316
+ opts.onEvent?.({ kind: "ready" });
317
+ return;
318
+ }
319
+ if (msg.kind === "error") {
320
+ const payload = msg.payload;
321
+ opts.onEvent?.({ kind: "error", payload });
322
+ handle.dispose();
323
+ removeSlot(slotId);
324
+ resolve((0, import_platform_protocol.err)({ kind: "genericError", message: "Auth frame error" }));
325
+ return;
326
+ }
327
+ if (msg.kind === "complete") {
328
+ const connection = msg.payload;
329
+ if (connection.status === import_platform_protocol.ConnectionStatus.active) {
330
+ const creds = (0, import_platform_sdk_core.decryptCredentials)(connection.credentials, privateKey);
331
+ core.context.setAccessToken(creds.accessToken);
332
+ core.context.setClientToken(creds.clientToken);
333
+ }
334
+ if (connection.status === import_platform_protocol.ConnectionStatus.active || connection.status === import_platform_protocol.ConnectionStatus.termsAcceptanceRequired) {
335
+ opts.onEvent?.({ kind: "complete", payload: connection });
336
+ }
337
+ resolve(
338
+ (0, import_platform_protocol.ok)({
339
+ dispose: () => {
340
+ handle.dispose();
341
+ removeSlot(slotId);
342
+ }
343
+ })
344
+ );
345
+ }
346
+ });
347
+ });
348
+ } catch (e) {
349
+ return (0, import_platform_protocol.err)({
350
+ kind: "genericError",
351
+ message: e instanceof Error ? e.message : "Auth setup failed"
352
+ });
353
+ }
354
+ }
290
355
  async function setupWidget(opts) {
291
356
  const channelId = `widget-${Date.now()}`;
292
357
  const url = (0, import_platform_sdk_core.buildFrameUrl)(
@@ -601,16 +666,23 @@ function MoonPayProvider({
601
666
  }
602
667
  }
603
668
  async function setupChallenge(opts) {
604
- let channelId;
669
+ let url;
605
670
  try {
606
- channelId = new URL(opts.url).searchParams.get("channelId") ?? "";
607
- if (!channelId)
608
- throw new Error("missing channelId");
671
+ url = new URL(opts.url);
609
672
  } catch {
610
- return (0, import_platform_protocol.err)({ kind: "configurationError", message: "Challenge URL is missing channelId" });
673
+ return (0, import_platform_protocol.err)({ kind: "configurationError", message: "Invalid challenge URL" });
674
+ }
675
+ let channelId = url.searchParams.get("channelId") ?? "";
676
+ if (!channelId) {
677
+ channelId = `challenge-${Date.now()}`;
678
+ url.searchParams.set("channelId", channelId);
611
679
  }
612
680
  try {
613
- const { promise } = createManagedFrame({ url: opts.url, channelId, hidden: false });
681
+ const { promise } = createManagedFrame({
682
+ url: url.toString(),
683
+ channelId,
684
+ hidden: false
685
+ });
614
686
  const { handle, slotId } = await promise;
615
687
  handle.onMessage((msg) => {
616
688
  switch (msg.kind) {
@@ -689,6 +761,7 @@ function MoonPayProvider({
689
761
  return {
690
762
  getConnection,
691
763
  connect,
764
+ setupAuth,
692
765
  getPaymentMethods: () => core.getPaymentMethods(),
693
766
  getQuote: (params) => core.getQuote(params),
694
767
  listTransactions: (params) => core.listTransactions(params),
@@ -699,7 +772,13 @@ function MoonPayProvider({
699
772
  setupBuyButton,
700
773
  setupGooglePay,
701
774
  setupChallenge,
702
- setupAddCard
775
+ setupAddCard,
776
+ createIdentity: (body) => core.createIdentity(body),
777
+ getIdentity: (id) => core.getIdentity(id),
778
+ updateIdentity: (id, body) => core.updateIdentity(id, body),
779
+ verifyIdentity: (id) => core.verifyIdentity(id),
780
+ getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),
781
+ submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
703
782
  };
704
783
  }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
705
784
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(MoonPayContext.Provider, { value: { client }, children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/frame-component.tsx","../src/provider.tsx","../src/webview-transport.ts"],"sourcesContent":["// Re-export commonly used protocol types for convenience\nexport type {\n AddCardEvent,\n ApplePayEvent,\n BuyButtonEvent,\n BuyEvent,\n CardResponse,\n ChallengeCancellation,\n ChallengeCompleteResult,\n ChallengeEvent,\n ConnectEvent,\n Connection,\n ConnectionStatus,\n GetQuoteParams,\n GooglePayEvent,\n PaymentMethodConfig,\n Quote,\n Result,\n StoredPaymentMethod,\n Transaction,\n TransactionWithStages,\n WidgetEvent,\n} from '@moonpay/platform-protocol';\n\nexport {\n MoonPayFrame,\n type MoonPayFrameProps,\n} from './frame-component.js';\nexport {\n type AddCardFrame,\n type ApplePayFrame,\n type BuyButtonFrame,\n type BuyFrame,\n type ChallengeFrame,\n type ConnectFrame,\n type ConnectOptions,\n type GooglePayFrame,\n MoonPayProvider,\n type MoonPayProviderProps,\n type RNClient,\n type SetupAddCardOptions,\n type SetupApplePayOptions,\n type SetupBuyButtonOptions,\n type SetupBuyOptions,\n type SetupChallengeOptions,\n type SetupGooglePayOptions,\n type SetupWidgetOptions,\n useMoonPay,\n type WidgetFrame,\n} from './provider.js';\nexport { WebViewTransport } from './webview-transport.js';\n","import { useEffect, useRef } from 'react';\nimport { View, type ViewStyle } from 'react-native';\nimport WebView, { type WebViewMessageEvent } from 'react-native-webview';\nimport type { WebViewTransport } from './webview-transport.js';\n\nexport interface MoonPayFrameProps {\n /** The transport instance managing this frame's communication. */\n transport: WebViewTransport;\n /** Whether this is a hidden utility frame (zero height). */\n hidden?: boolean;\n /** Optional style overrides for the container view. */\n style?: ViewStyle;\n}\n\n/**\n * Reusable React Native component that renders a MoonPay frame as a WebView.\n * Bridges the WebViewTransport to the actual WebView instance.\n */\nexport function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null {\n const webViewRef = useRef<WebView>(null);\n\n useEffect(() => {\n transport.attachWebView(webViewRef);\n return () => {\n // Don't dispose — the orchestrator manages lifecycle\n };\n }, [transport]);\n\n const url = transport.url;\n if (!url) return null;\n\n const handleMessage = (event: WebViewMessageEvent) => {\n transport.handleWebViewMessage(event.nativeEvent.data);\n };\n\n const containerStyle: ViewStyle = hidden\n ? { width: 0, height: 0, overflow: 'hidden' }\n : { flex: 1, ...style };\n\n return (\n <View style={containerStyle}>\n <WebView\n ref={webViewRef}\n source={{ uri: url }}\n onMessage={handleMessage}\n allowsInlineMediaPlayback\n javaScriptEnabled\n domStorageEnabled\n style={{ flex: 1 }}\n />\n </View>\n );\n}\n","import {\n type AddCardEvent,\n type ApplePayEvent,\n type BuyButtonEvent,\n type BuyEvent,\n type CardResponse,\n type ChallengeCancellation,\n type ChallengeCompleteResult,\n type ChallengeEvent,\n type ConnectError,\n type ConnectEvent,\n type Connection,\n ConnectionStatus,\n err,\n type GetConnectionError,\n type GetPaymentMethodsError,\n type GetQuoteError,\n type GetQuoteParams,\n type GetTransactionsError,\n type GooglePayEvent,\n type GooglePayInboundMessageMap,\n type ListPaymentMethodsResponse,\n ok,\n type PaginationInfo,\n type ProtocolMessage,\n type Quote,\n type Result,\n type SetupAddCardError,\n type SetupApplePayError,\n type SetupBuyButtonError,\n type SetupBuyError,\n type SetupChallengeError,\n type SetupGooglePayError,\n type SetupWidgetError,\n type Transaction,\n type TransactionWithStages,\n type WidgetEvent,\n} from '@moonpay/platform-protocol';\nimport {\n buildFrameUrl,\n type CoreClient,\n createClientCore,\n createFrameOrchestrator,\n decryptCredentials,\n FRAME_PATHS,\n type FrameHandle,\n generateKeyPair,\n type ListTransactionsParams,\n} from '@moonpay/platform-sdk-core';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { MoonPayFrame } from './frame-component.js';\nimport { WebViewTransport } from './webview-transport.js';\n\n// ---------------------------------------------------------------------------\n// Frame slot — represents a frame the provider needs to render\n// ---------------------------------------------------------------------------\n\ninterface FrameSlot {\n id: string;\n transport: WebViewTransport;\n hidden: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface ConnectOptions {\n /** Theme options for the connect frame. */\n theme?: { appearance?: 'light' | 'dark' };\n /** Callback for connect lifecycle events. */\n onEvent?: (event: ConnectEvent) => void;\n}\n\nexport interface ConnectFrame {\n dispose(): void;\n}\n\nexport interface SetupWidgetOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for widget lifecycle events. */\n onEvent?: (event: WidgetEvent) => void;\n}\n\nexport interface WidgetFrame {\n dispose(): void;\n}\n\nexport interface SetupApplePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for Apple Pay lifecycle events. */\n onEvent?: (event: ApplePayEvent) => void;\n}\n\nexport interface ApplePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for buy frame lifecycle events. */\n onEvent?: (event: BuyEvent) => void;\n}\n\nexport interface BuyFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyButtonOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for buy-button frame lifecycle events. */\n onEvent?: (event: BuyButtonEvent) => void;\n}\n\nexport interface BuyButtonFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupGooglePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for Google Pay lifecycle events. */\n onEvent?: (event: GooglePayEvent) => void;\n}\n\nexport interface GooglePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupChallengeOptions {\n /** Full challenge URL received from a frame's `challenge` event. */\n url: string;\n /** Callback for challenge frame lifecycle events. */\n onEvent?: (event: ChallengeEvent) => void;\n}\n\nexport interface ChallengeFrame {\n dispose(): void;\n}\n\nexport interface SetupAddCardOptions {\n /** Callback for add-card frame lifecycle events. */\n onEvent?: (event: AddCardEvent) => void;\n}\n\nexport interface AddCardFrame {\n dispose(): void;\n}\n\nexport interface RNClient {\n getConnection(): Promise<Result<Connection, GetConnectionError>>;\n connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;\n getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;\n getQuote(params: GetQuoteParams): Promise<Result<{ data: Quote }, GetQuoteError>>;\n listTransactions(\n params?: ListTransactionsParams,\n ): Promise<Result<{ data: Transaction[]; pageInfo: PaginationInfo }, GetTransactionsError>>;\n getTransaction(\n id: string,\n ): Promise<Result<{ data: TransactionWithStages }, GetTransactionsError>>;\n setupWidget(options: SetupWidgetOptions): Promise<Result<WidgetFrame, SetupWidgetError>>;\n setupApplePay(options: SetupApplePayOptions): Promise<Result<ApplePayFrame, SetupApplePayError>>;\n setupBuy(options: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>>;\n setupBuyButton(\n options: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>>;\n setupGooglePay(\n options: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>>;\n setupChallenge(\n options: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>>;\n setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface MoonPayContextValue {\n client: RNClient;\n}\n\nconst MoonPayContext = createContext<MoonPayContextValue | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface MoonPayProviderProps {\n sessionToken: string;\n apiBaseUrl?: string;\n frameBaseUrl?: string;\n children: ReactNode;\n}\n\nlet slotCounter = 0;\n\nexport function MoonPayProvider({\n sessionToken,\n apiBaseUrl,\n frameBaseUrl,\n children,\n}: MoonPayProviderProps): JSX.Element {\n const [frameSlots, setFrameSlots] = useState<FrameSlot[]>([]);\n\n // Stable refs for addSlot/removeSlot so client methods don't re-create\n const addSlot = useCallback((slot: FrameSlot) => {\n setFrameSlots((prev) => [...prev, slot]);\n }, []);\n\n const removeSlot = useCallback((id: string) => {\n setFrameSlots((prev) => prev.filter((s) => s.id !== id));\n }, []);\n\n // Keep a ref to core so it's stable across renders\n const coreRef = useRef<CoreClient | null>(null);\n if (!coreRef.current) {\n coreRef.current = createClientCore({\n apiBaseUrl,\n frameBaseUrl,\n createTransport: () => new WebViewTransport(),\n });\n }\n const core = coreRef.current;\n\n const client = useMemo<RNClient>(() => {\n // Helper: create a transport + slot, wait for orchestrator handshake\n function createManagedFrame(opts: {\n url: string;\n channelId: string;\n hidden: boolean;\n handshakeTimeout?: number;\n }): { promise: Promise<{ handle: FrameHandle; slotId: string }>; transport: WebViewTransport } {\n const transport = new WebViewTransport();\n const slotId = `slot-${++slotCounter}`;\n\n const promise = new Promise<{ handle: FrameHandle; slotId: string }>((resolve, reject) => {\n // Defer adding the slot to allow the transport to be fully set up\n // before the WebView renders\n transport.create(opts.url, { container: null, hidden: opts.hidden });\n\n addSlot({ id: slotId, transport, hidden: opts.hidden });\n\n createFrameOrchestrator({\n transport,\n channelId: opts.channelId,\n url: opts.url,\n container: null,\n hidden: opts.hidden,\n handshakeTimeout: opts.handshakeTimeout ?? 15_000,\n })\n .then((handle) => resolve({ handle, slotId }))\n .catch((e) => {\n removeSlot(slotId);\n reject(e);\n });\n });\n\n return { promise, transport };\n }\n\n // ------- getConnection (hidden frame) -------\n async function getConnection(): Promise<Result<Connection, GetConnectionError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `check-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.checkConnection,\n { sessionToken, channelId, publicKey },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({\n url,\n channelId,\n hidden: true,\n handshakeTimeout: 10_000,\n });\n\n const { handle, slotId } = await promise;\n\n return new Promise<Result<Connection, GetConnectionError>>((resolve) => {\n const timeout = setTimeout(() => {\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Get connection timed out' }));\n }, 10_000);\n\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'error') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const payload = msg.payload as { message: string };\n resolve(err({ message: payload.message }));\n return;\n }\n\n if (msg.kind === 'complete') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n resolve(ok(connection));\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Failed to check connection',\n });\n }\n }\n\n // ------- connect (visible frame) -------\n async function connect(opts: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `connect-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.connect,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(opts.theme?.appearance && { appearance: opts.theme.appearance }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<ConnectFrame, ConnectError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Connection error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n opts.onEvent?.({ kind: 'complete', payload: connection });\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Connect failed',\n });\n }\n }\n\n // ------- setupWidget -------\n async function setupWidget(\n opts: SetupWidgetOptions,\n ): Promise<Result<WidgetFrame, SetupWidgetError>> {\n const channelId = `widget-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.widget,\n {\n flow: 'buy',\n clientToken: core.context.clientToken,\n quoteSignature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'transactionCreated':\n opts.onEvent?.({\n kind: 'transactionCreated',\n payload: msg.payload as { transaction: { id: string; status: string } },\n });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as {\n code: 'configurationError' | 'apiError' | 'generic';\n message: string;\n };\n opts.onEvent?.({\n kind: 'error',\n payload: { code: payload.code, message: payload.message },\n });\n break;\n }\n case 'close':\n opts.onEvent?.({ kind: 'close' });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Widget setup failed',\n });\n }\n }\n\n // ------- setupApplePay -------\n async function setupApplePay(\n opts: SetupApplePayOptions,\n ): Promise<Result<ApplePayFrame, SetupApplePayError>> {\n const channelId = `applepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.applePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'applePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as\n | 'configurationError'\n | 'invalidQuote'\n | 'oneTapApplePaySecondFactorRequired'\n | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Apple Pay setup failed',\n });\n }\n }\n\n // ------- setupBuy (hidden frame) -------\n async function setupBuy(opts: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>> {\n const channelId = `buy-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buy,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: true });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy setup failed',\n });\n }\n }\n\n // ------- setupBuyButton -------\n async function setupBuyButton(\n opts: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>> {\n const channelId = `buy-button-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buyButton,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy button setup failed',\n });\n }\n }\n\n // ------- setupGooglePay -------\n async function setupGooglePay(\n opts: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>> {\n const channelId = `googlepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.googlePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as GooglePayInboundMessageMap['challenge'],\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'googlePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as 'configurationError' | 'invalidQuote' | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Google Pay setup failed',\n });\n }\n }\n\n // ------- setupChallenge -------\n async function setupChallenge(\n opts: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>> {\n let channelId: string;\n try {\n channelId = new URL(opts.url).searchParams.get('channelId') ?? '';\n if (!channelId) throw new Error('missing channelId');\n } catch {\n return err({ kind: 'configurationError', message: 'Challenge URL is missing channelId' });\n }\n\n try {\n const { promise } = createManagedFrame({ url: opts.url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as ChallengeCompleteResult,\n });\n break;\n case 'cancelled':\n opts.onEvent?.({\n kind: 'cancelled',\n payload: msg.payload as ChallengeCancellation,\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Challenge setup failed',\n });\n }\n }\n\n // ------- setupAddCard -------\n async function setupAddCard(\n opts: SetupAddCardOptions,\n ): Promise<Result<AddCardFrame, SetupAddCardError>> {\n const channelId = `add-card-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.addCard,\n { channelId, clientToken: core.context.clientToken },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({ kind: 'complete', payload: msg.payload as { card: CardResponse } });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as {\n code: 'generic' | 'configurationError';\n message: string;\n },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Add card setup failed',\n });\n }\n }\n\n return {\n getConnection,\n connect,\n getPaymentMethods: () => core.getPaymentMethods(),\n getQuote: (params) => core.getQuote(params),\n listTransactions: (params) => core.listTransactions(params),\n getTransaction: (id) => core.getTransaction(id),\n setupWidget,\n setupApplePay,\n setupBuy,\n setupBuyButton,\n setupGooglePay,\n setupChallenge,\n setupAddCard,\n };\n }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);\n\n return (\n <MoonPayContext.Provider value={{ client }}>\n {children}\n {frameSlots.map((slot) => (\n <MoonPayFrame key={slot.id} transport={slot.transport} hidden={slot.hidden} />\n ))}\n </MoonPayContext.Provider>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useMoonPay(): MoonPayContextValue {\n const ctx = useContext(MoonPayContext);\n if (!ctx) {\n throw new Error('useMoonPay must be used within a <MoonPayProvider>');\n }\n return ctx;\n}\n","import type { ProtocolMessage } from '@moonpay/platform-protocol';\nimport type { FrameOptions, FrameTransport } from '@moonpay/platform-sdk-core';\nimport type { RefObject } from 'react';\nimport type WebView from 'react-native-webview';\n\n/**\n * FrameTransport implementation for React Native using react-native-webview.\n *\n * Unlike the web IframeTransport, the WebView is rendered declaratively via\n * React components. This transport bridges the imperative FrameTransport\n * interface to a WebView ref.\n */\nexport class WebViewTransport implements FrameTransport {\n private webViewRef: RefObject<WebView | null> | null = null;\n private handlers: Array<(msg: ProtocolMessage) => void> = [];\n private _url: string = '';\n private _options: FrameOptions | null = null;\n\n /** Called by the frame component when it mounts the WebView. */\n attachWebView(ref: RefObject<WebView | null>): void {\n this.webViewRef = ref;\n }\n\n /** Called by the WebView's onMessage prop to route incoming messages. */\n handleWebViewMessage(data: string): void {\n try {\n const msg: ProtocolMessage = JSON.parse(data);\n if (!msg.kind) return;\n for (const handler of this.handlers) {\n handler(msg);\n }\n } catch {\n // Ignore non-protocol messages\n }\n }\n\n get url(): string {\n return this._url;\n }\n\n get options(): FrameOptions | null {\n return this._options;\n }\n\n // FrameTransport interface\n\n create(url: string, options: FrameOptions): void {\n this._url = url;\n this._options = options;\n // The actual WebView rendering is handled by React components.\n // This method stores the URL and options for the component to read.\n }\n\n sendMessage(message: ProtocolMessage): void {\n if (!this.webViewRef?.current) {\n throw new Error('Cannot send message: WebView not attached');\n }\n const js = `\n window.postMessage(${JSON.stringify(JSON.stringify(message))}, '*');\n true;\n `;\n this.webViewRef.current.injectJavaScript(js);\n }\n\n onMessage(handler: (msg: ProtocolMessage) => void): () => void {\n this.handlers.push(handler);\n return () => {\n const idx = this.handlers.indexOf(handler);\n if (idx >= 0) this.handlers.splice(idx, 1);\n };\n }\n\n dispose(): void {\n this.handlers.length = 0;\n this.webViewRef = null;\n this._url = '';\n this._options = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkC;AAClC,0BAAqC;AACrC,kCAAkD;AAuC5C;AAvBC,SAAS,aAAa,EAAE,WAAW,QAAQ,MAAM,GAA0C;AAChG,QAAM,iBAAa,qBAAgB,IAAI;AAEvC,8BAAU,MAAM;AACd,cAAU,cAAc,UAAU;AAClC,WAAO,MAAM;AAAA,IAEb;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,QAAM,MAAM,UAAU;AACtB,MAAI,CAAC;AAAK,WAAO;AAEjB,QAAM,gBAAgB,CAAC,UAA+B;AACpD,cAAU,qBAAqB,MAAM,YAAY,IAAI;AAAA,EACvD;AAEA,QAAM,iBAA4B,SAC9B,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,SAAS,IAC1C,EAAE,MAAM,GAAG,GAAG,MAAM;AAExB,SACE,4CAAC,4BAAK,OAAO,gBACX;AAAA,IAAC,4BAAAA;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ,EAAE,KAAK,IAAI;AAAA,MACnB,WAAW;AAAA,MACX,2BAAyB;AAAA,MACzB,mBAAiB;AAAA,MACjB,mBAAiB;AAAA,MACjB,OAAO,EAAE,MAAM,EAAE;AAAA;AAAA,EACnB,GACF;AAEJ;;;ACpDA,+BAqCO;AACP,+BAUO;AACP,IAAAC,gBAQO;;;AC7CA,IAAM,mBAAN,MAAiD;AAAA,EAC9C,aAA+C;AAAA,EAC/C,WAAkD,CAAC;AAAA,EACnD,OAAe;AAAA,EACf,WAAgC;AA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AACH,mBAAK,UAAU,EAAE,MAAM,YAAY,SAAS,IAAI,QAAkC,CAAC;AACnF;AAAA,YACF,KAAK;AACH,mBAAK,UAAU;AAAA,gBACb,MAAM;AAAA,gBACN,SAAS,IAAI;AAAA,cAIf,CAAC;AACD;AAAA,UACJ;AAAA,QACF,CAAC;AAED,mBAAO,6BAAG;AAAA,UACR,SAAS,MAAM;AACb,mBAAO,QAAQ;AACf,uBAAW,MAAM;AAAA,UACnB;AAAA,QACF,CAAC;AAAA,MACH,SAAS,GAAG;AACV,mBAAO,8BAAI;AAAA,UACT,MAAM;AAAA,UACN,SAAS,aAAa,QAAQ,EAAE,UAAU;AAAA,QAC5C,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,mBAAmB,MAAM,KAAK,kBAAkB;AAAA,MAChD,UAAU,CAAC,WAAW,KAAK,SAAS,MAAM;AAAA,MAC1C,kBAAkB,CAAC,WAAW,KAAK,iBAAiB,MAAM;AAAA,MAC1D,gBAAgB,CAAC,OAAO,KAAK,eAAe,EAAE;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,cAAc,cAAc,MAAM,SAAS,UAAU,CAAC;AAE1D,SACE,8CAAC,eAAe,UAAf,EAAwB,OAAO,EAAE,OAAO,GACtC;AAAA;AAAA,IACA,WAAW,IAAI,CAAC,SACf,6CAAC,gBAA2B,WAAW,KAAK,WAAW,QAAQ,KAAK,UAAjD,KAAK,EAAoD,CAC7E;AAAA,KACH;AAEJ;AAMO,SAAS,aAAkC;AAChD,QAAM,UAAM,0BAAW,cAAc;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;","names":["WebView","import_react","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/frame-component.tsx","../src/provider.tsx","../src/webview-transport.ts"],"sourcesContent":["// Re-export commonly used protocol types for convenience\nexport type {\n AddCardEvent,\n ApplePayEvent,\n AuthEvent,\n BuyButtonEvent,\n BuyEvent,\n CardResponse,\n ChallengeCancellation,\n ChallengeCompleteResult,\n ChallengeEvent,\n ConnectEvent,\n Connection,\n ConnectionStatus,\n GetQuoteParams,\n GooglePayEvent,\n PaymentMethodConfig,\n Quote,\n Result,\n StoredPaymentMethod,\n Transaction,\n TransactionWithStages,\n WidgetEvent,\n} from '@moonpay/platform-protocol';\n\nexport {\n MoonPayFrame,\n type MoonPayFrameProps,\n} from './frame-component.js';\nexport {\n type AddCardFrame,\n type ApplePayFrame,\n type AuthFrame,\n type BuyButtonFrame,\n type BuyFrame,\n type ChallengeFrame,\n type ConnectFrame,\n type ConnectOptions,\n type GetConnectionOptions,\n type GooglePayFrame,\n MoonPayProvider,\n type MoonPayProviderProps,\n type RNClient,\n type SetupAddCardOptions,\n type SetupApplePayOptions,\n type SetupAuthOptions,\n type SetupBuyButtonOptions,\n type SetupBuyOptions,\n type SetupChallengeOptions,\n type SetupGooglePayOptions,\n type SetupWidgetOptions,\n useMoonPay,\n type WidgetFrame,\n} from './provider.js';\nexport { WebViewTransport } from './webview-transport.js';\n","import { useEffect, useRef } from 'react';\nimport { View, type ViewStyle } from 'react-native';\nimport WebView, { type WebViewMessageEvent } from 'react-native-webview';\nimport type { WebViewTransport } from './webview-transport.js';\n\nexport interface MoonPayFrameProps {\n /** The transport instance managing this frame's communication. */\n transport: WebViewTransport;\n /** Whether this is a hidden utility frame (zero height). */\n hidden?: boolean;\n /** Optional style overrides for the container view. */\n style?: ViewStyle;\n}\n\n/**\n * Reusable React Native component that renders a MoonPay frame as a WebView.\n * Bridges the WebViewTransport to the actual WebView instance.\n */\nexport function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null {\n const webViewRef = useRef<WebView>(null);\n\n useEffect(() => {\n transport.attachWebView(webViewRef);\n return () => {\n // Don't dispose — the orchestrator manages lifecycle\n };\n }, [transport]);\n\n const url = transport.url;\n if (!url) return null;\n\n const handleMessage = (event: WebViewMessageEvent) => {\n transport.handleWebViewMessage(event.nativeEvent.data);\n };\n\n const containerStyle: ViewStyle = hidden\n ? { width: 0, height: 0, overflow: 'hidden' }\n : { flex: 1, ...style };\n\n return (\n <View style={containerStyle}>\n <WebView\n ref={webViewRef}\n source={{ uri: url }}\n onMessage={handleMessage}\n allowsInlineMediaPlayback\n javaScriptEnabled\n domStorageEnabled\n style={{ flex: 1 }}\n />\n </View>\n );\n}\n","import {\n type AddCardEvent,\n type ApplePayEvent,\n type AuthEvent,\n type BuyButtonEvent,\n type BuyEvent,\n type CardResponse,\n type ChallengeCancellation,\n type ChallengeCompleteResult,\n type ChallengeEvent,\n type ConnectError,\n type ConnectEvent,\n type Connection,\n ConnectionStatus,\n type CreateIdentityError,\n type CreateIdentityRequestBody,\n err,\n type GetConnectionError,\n type GetIdentityError,\n type GetIdentityUploadUrlError,\n type GetPaymentMethodsError,\n type GetQuoteError,\n type GetQuoteParams,\n type GetTransactionsError,\n type GooglePayEvent,\n type GooglePayInboundMessageMap,\n type Identity,\n type IdentityFileUploadUrl,\n type IdentityFileUploadUrlRequestBody,\n type IdentityVerificationResponse,\n type ListPaymentMethodsResponse,\n ok,\n type PaginationInfo,\n type ProtocolMessage,\n type Quote,\n type Result,\n type SetupAddCardError,\n type SetupApplePayError,\n type SetupAuthError,\n type SetupBuyButtonError,\n type SetupBuyError,\n type SetupChallengeError,\n type SetupGooglePayError,\n type SetupWidgetError,\n type SubmitIdentityFilesError,\n type SubmitIdentityFilesRequestBody,\n type Transaction,\n type TransactionWithStages,\n type UpdateIdentityError,\n type UpdateIdentityRequestBody,\n type VerifyIdentityError,\n type WidgetEvent,\n} from '@moonpay/platform-protocol';\nimport {\n buildFrameUrl,\n type CoreClient,\n createClientCore,\n createFrameOrchestrator,\n decryptCredentials,\n FRAME_PATHS,\n type FrameHandle,\n generateKeyPair,\n type ListTransactionsParams,\n} from '@moonpay/platform-sdk-core';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { MoonPayFrame } from './frame-component.js';\nimport { WebViewTransport } from './webview-transport.js';\n\n// ---------------------------------------------------------------------------\n// Frame slot — represents a frame the provider needs to render\n// ---------------------------------------------------------------------------\n\ninterface FrameSlot {\n id: string;\n transport: WebViewTransport;\n hidden: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface GetConnectionOptions {\n /**\n * Pass `true` for headless / Identity-API integrations so the check\n * frame opts out of KYC-based statuses. Legal (`termsAcceptanceRequired`)\n * is always surfaced regardless. Defaults to `false`.\n */\n skipKyc?: boolean;\n}\n\nexport interface ConnectOptions {\n /** Theme options for the connect frame. */\n theme?: { appearance?: 'light' | 'dark' };\n /** Callback for connect lifecycle events. */\n onEvent?: (event: ConnectEvent) => void;\n}\n\nexport interface ConnectFrame {\n dispose(): void;\n}\n\nexport interface SetupWidgetOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for widget lifecycle events. */\n onEvent?: (event: WidgetEvent) => void;\n}\n\nexport interface WidgetFrame {\n dispose(): void;\n}\n\nexport interface SetupApplePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for Apple Pay lifecycle events. */\n onEvent?: (event: ApplePayEvent) => void;\n}\n\nexport interface ApplePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for buy frame lifecycle events. */\n onEvent?: (event: BuyEvent) => void;\n}\n\nexport interface BuyFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyButtonOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for buy-button frame lifecycle events. */\n onEvent?: (event: BuyButtonEvent) => void;\n}\n\nexport interface BuyButtonFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupGooglePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for Google Pay lifecycle events. */\n onEvent?: (event: GooglePayEvent) => void;\n}\n\nexport interface GooglePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupChallengeOptions {\n /** Full challenge URL received from a frame's `challenge` event. */\n url: string;\n /** Callback for challenge frame lifecycle events. */\n onEvent?: (event: ChallengeEvent) => void;\n}\n\nexport interface ChallengeFrame {\n dispose(): void;\n}\n\nexport interface SetupAddCardOptions {\n /** Callback for add-card frame lifecycle events. */\n onEvent?: (event: AddCardEvent) => void;\n}\n\nexport interface AddCardFrame {\n dispose(): void;\n}\n\nexport interface SetupAuthOptions {\n /** Callback for auth frame lifecycle events. */\n onEvent?: (event: AuthEvent) => void;\n}\n\nexport interface AuthFrame {\n dispose(): void;\n}\n\nexport interface RNClient {\n getConnection(options?: GetConnectionOptions): Promise<Result<Connection, GetConnectionError>>;\n connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;\n /**\n * Launch the auth frame — the lighter-weight counterpart to `connect()`\n * for headless / Identity-API partners. Requires a `clientToken` to be\n * present in the client's context, which is populated automatically by a\n * prior `getConnection()` call that returned `connectionRequired`.\n * Call `getConnection()` first; if its status is `connectionRequired`,\n * call `setupAuth()` to drive the customer through email/OTP.\n */\n setupAuth(options: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>>;\n getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;\n getQuote(params: GetQuoteParams): Promise<Result<{ data: Quote }, GetQuoteError>>;\n listTransactions(\n params?: ListTransactionsParams,\n ): Promise<Result<{ data: Transaction[]; pageInfo: PaginationInfo }, GetTransactionsError>>;\n getTransaction(\n id: string,\n ): Promise<Result<{ data: TransactionWithStages }, GetTransactionsError>>;\n setupWidget(options: SetupWidgetOptions): Promise<Result<WidgetFrame, SetupWidgetError>>;\n setupApplePay(options: SetupApplePayOptions): Promise<Result<ApplePayFrame, SetupApplePayError>>;\n setupBuy(options: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>>;\n setupBuyButton(\n options: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>>;\n setupGooglePay(\n options: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>>;\n setupChallenge(\n options: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>>;\n setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;\n\n // Identity API\n createIdentity(\n body: CreateIdentityRequestBody,\n ): Promise<Result<{ data: Identity | null }, CreateIdentityError>>;\n getIdentity(id: string): Promise<Result<{ data: Identity }, GetIdentityError>>;\n updateIdentity(\n id: string,\n body: UpdateIdentityRequestBody,\n ): Promise<Result<{ data: Identity }, UpdateIdentityError>>;\n verifyIdentity(\n id: string,\n ): Promise<Result<{ data: IdentityVerificationResponse }, VerifyIdentityError>>;\n getIdentityUploadUrl(\n id: string,\n body: IdentityFileUploadUrlRequestBody,\n ): Promise<Result<{ data: IdentityFileUploadUrl }, GetIdentityUploadUrlError>>;\n submitIdentityFiles(\n id: string,\n body: SubmitIdentityFilesRequestBody,\n ): Promise<Result<{ data: Identity }, SubmitIdentityFilesError>>;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface MoonPayContextValue {\n client: RNClient;\n}\n\nconst MoonPayContext = createContext<MoonPayContextValue | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface MoonPayProviderProps {\n sessionToken: string;\n apiBaseUrl?: string;\n frameBaseUrl?: string;\n children: ReactNode;\n}\n\nlet slotCounter = 0;\n\nexport function MoonPayProvider({\n sessionToken,\n apiBaseUrl,\n frameBaseUrl,\n children,\n}: MoonPayProviderProps): JSX.Element {\n const [frameSlots, setFrameSlots] = useState<FrameSlot[]>([]);\n\n // Stable refs for addSlot/removeSlot so client methods don't re-create\n const addSlot = useCallback((slot: FrameSlot) => {\n setFrameSlots((prev) => [...prev, slot]);\n }, []);\n\n const removeSlot = useCallback((id: string) => {\n setFrameSlots((prev) => prev.filter((s) => s.id !== id));\n }, []);\n\n // Keep a ref to core so it's stable across renders\n const coreRef = useRef<CoreClient | null>(null);\n if (!coreRef.current) {\n coreRef.current = createClientCore({\n apiBaseUrl,\n frameBaseUrl,\n createTransport: () => new WebViewTransport(),\n });\n }\n const core = coreRef.current;\n\n const client = useMemo<RNClient>(() => {\n // Helper: create a transport + slot, wait for orchestrator handshake\n function createManagedFrame(opts: {\n url: string;\n channelId: string;\n hidden: boolean;\n handshakeTimeout?: number;\n }): { promise: Promise<{ handle: FrameHandle; slotId: string }>; transport: WebViewTransport } {\n const transport = new WebViewTransport();\n const slotId = `slot-${++slotCounter}`;\n\n const promise = new Promise<{ handle: FrameHandle; slotId: string }>((resolve, reject) => {\n // Defer adding the slot to allow the transport to be fully set up\n // before the WebView renders\n transport.create(opts.url, { container: null, hidden: opts.hidden });\n\n addSlot({ id: slotId, transport, hidden: opts.hidden });\n\n createFrameOrchestrator({\n transport,\n channelId: opts.channelId,\n url: opts.url,\n container: null,\n hidden: opts.hidden,\n handshakeTimeout: opts.handshakeTimeout ?? 15_000,\n })\n .then((handle) => resolve({ handle, slotId }))\n .catch((e) => {\n removeSlot(slotId);\n reject(e);\n });\n });\n\n return { promise, transport };\n }\n\n // ------- getConnection (hidden frame) -------\n async function getConnection(\n options: GetConnectionOptions = {},\n ): Promise<Result<Connection, GetConnectionError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `check-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.checkConnection,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(options.skipKyc && { skipKyc: true }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({\n url,\n channelId,\n hidden: true,\n handshakeTimeout: 10_000,\n });\n\n const { handle, slotId } = await promise;\n\n return new Promise<Result<Connection, GetConnectionError>>((resolve) => {\n const timeout = setTimeout(() => {\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Get connection timed out' }));\n }, 10_000);\n\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'error') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const payload = msg.payload as { message: string };\n resolve(err({ message: payload.message }));\n return;\n }\n\n if (msg.kind === 'complete') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n resolve(ok(connection));\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Failed to check connection',\n });\n }\n }\n\n // ------- connect (visible frame) -------\n async function connect(opts: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `connect-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.connect,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(opts.theme?.appearance && { appearance: opts.theme.appearance }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<ConnectFrame, ConnectError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Connection error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n opts.onEvent?.({ kind: 'complete', payload: connection });\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Connect failed',\n });\n }\n }\n\n // ------- setupAuth (visible frame) -------\n async function setupAuth(opts: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>> {\n const clientToken = core.context.clientToken;\n if (!clientToken) {\n return err({\n kind: 'configurationError',\n message:\n 'No clientToken in context — call getConnection() first and ensure it resolved with status \"connectionRequired\".',\n });\n }\n\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `auth-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.auth,\n { clientToken, channelId, publicKey },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<AuthFrame, SetupAuthError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ kind: 'genericError', message: 'Auth frame error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n if (\n connection.status === ConnectionStatus.active ||\n connection.status === ConnectionStatus.termsAcceptanceRequired\n ) {\n opts.onEvent?.({ kind: 'complete', payload: connection });\n }\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Auth setup failed',\n });\n }\n }\n\n // ------- setupWidget -------\n async function setupWidget(\n opts: SetupWidgetOptions,\n ): Promise<Result<WidgetFrame, SetupWidgetError>> {\n const channelId = `widget-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.widget,\n {\n flow: 'buy',\n clientToken: core.context.clientToken,\n quoteSignature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'transactionCreated':\n opts.onEvent?.({\n kind: 'transactionCreated',\n payload: msg.payload as { transaction: { id: string; status: string } },\n });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as {\n code: 'configurationError' | 'apiError' | 'generic';\n message: string;\n };\n opts.onEvent?.({\n kind: 'error',\n payload: { code: payload.code, message: payload.message },\n });\n break;\n }\n case 'close':\n opts.onEvent?.({ kind: 'close' });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Widget setup failed',\n });\n }\n }\n\n // ------- setupApplePay -------\n async function setupApplePay(\n opts: SetupApplePayOptions,\n ): Promise<Result<ApplePayFrame, SetupApplePayError>> {\n const channelId = `applepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.applePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'applePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as\n | 'configurationError'\n | 'invalidQuote'\n | 'oneTapApplePaySecondFactorRequired'\n | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Apple Pay setup failed',\n });\n }\n }\n\n // ------- setupBuy (hidden frame) -------\n async function setupBuy(opts: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>> {\n const channelId = `buy-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buy,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: true });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy setup failed',\n });\n }\n }\n\n // ------- setupBuyButton -------\n async function setupBuyButton(\n opts: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>> {\n const channelId = `buy-button-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buyButton,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy button setup failed',\n });\n }\n }\n\n // ------- setupGooglePay -------\n async function setupGooglePay(\n opts: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>> {\n const channelId = `googlepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.googlePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as GooglePayInboundMessageMap['challenge'],\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'googlePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as 'configurationError' | 'invalidQuote' | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Google Pay setup failed',\n });\n }\n }\n\n // ------- setupChallenge -------\n async function setupChallenge(\n opts: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>> {\n let url: URL;\n try {\n url = new URL(opts.url);\n } catch {\n return err({ kind: 'configurationError', message: 'Invalid challenge URL' });\n }\n\n let channelId = url.searchParams.get('channelId') ?? '';\n if (!channelId) {\n channelId = `challenge-${Date.now()}`;\n url.searchParams.set('channelId', channelId);\n }\n\n try {\n const { promise } = createManagedFrame({\n url: url.toString(),\n channelId,\n hidden: false,\n });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as ChallengeCompleteResult,\n });\n break;\n case 'cancelled':\n opts.onEvent?.({\n kind: 'cancelled',\n payload: msg.payload as ChallengeCancellation,\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Challenge setup failed',\n });\n }\n }\n\n // ------- setupAddCard -------\n async function setupAddCard(\n opts: SetupAddCardOptions,\n ): Promise<Result<AddCardFrame, SetupAddCardError>> {\n const channelId = `add-card-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.addCard,\n { channelId, clientToken: core.context.clientToken },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({ kind: 'complete', payload: msg.payload as { card: CardResponse } });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as {\n code: 'generic' | 'configurationError';\n message: string;\n },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Add card setup failed',\n });\n }\n }\n\n return {\n getConnection,\n connect,\n setupAuth,\n getPaymentMethods: () => core.getPaymentMethods(),\n getQuote: (params) => core.getQuote(params),\n listTransactions: (params) => core.listTransactions(params),\n getTransaction: (id) => core.getTransaction(id),\n setupWidget,\n setupApplePay,\n setupBuy,\n setupBuyButton,\n setupGooglePay,\n setupChallenge,\n setupAddCard,\n\n createIdentity: (body) => core.createIdentity(body),\n getIdentity: (id) => core.getIdentity(id),\n updateIdentity: (id, body) => core.updateIdentity(id, body),\n verifyIdentity: (id) => core.verifyIdentity(id),\n getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),\n submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body),\n };\n }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);\n\n return (\n <MoonPayContext.Provider value={{ client }}>\n {children}\n {frameSlots.map((slot) => (\n <MoonPayFrame key={slot.id} transport={slot.transport} hidden={slot.hidden} />\n ))}\n </MoonPayContext.Provider>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useMoonPay(): MoonPayContextValue {\n const ctx = useContext(MoonPayContext);\n if (!ctx) {\n throw new Error('useMoonPay must be used within a <MoonPayProvider>');\n }\n return ctx;\n}\n","import type { ProtocolMessage } from '@moonpay/platform-protocol';\nimport type { FrameOptions, FrameTransport } from '@moonpay/platform-sdk-core';\nimport type { RefObject } from 'react';\nimport type WebView from 'react-native-webview';\n\n/**\n * FrameTransport implementation for React Native using react-native-webview.\n *\n * Unlike the web IframeTransport, the WebView is rendered declaratively via\n * React components. This transport bridges the imperative FrameTransport\n * interface to a WebView ref.\n */\nexport class WebViewTransport implements FrameTransport {\n private webViewRef: RefObject<WebView | null> | null = null;\n private handlers: Array<(msg: ProtocolMessage) => void> = [];\n private _url: string = '';\n private _options: FrameOptions | null = null;\n\n /** Called by the frame component when it mounts the WebView. */\n attachWebView(ref: RefObject<WebView | null>): void {\n this.webViewRef = ref;\n }\n\n /** Called by the WebView's onMessage prop to route incoming messages. */\n handleWebViewMessage(data: string): void {\n try {\n const msg: ProtocolMessage = JSON.parse(data);\n if (!msg.kind) return;\n for (const handler of this.handlers) {\n handler(msg);\n }\n } catch {\n // Ignore non-protocol messages\n }\n }\n\n get url(): string {\n return this._url;\n }\n\n get options(): FrameOptions | null {\n return this._options;\n }\n\n // FrameTransport interface\n\n create(url: string, options: FrameOptions): void {\n this._url = url;\n this._options = options;\n // The actual WebView rendering is handled by React components.\n // This method stores the URL and options for the component to read.\n }\n\n sendMessage(message: ProtocolMessage): void {\n if (!this.webViewRef?.current) {\n throw new Error('Cannot send message: WebView not attached');\n }\n const js = `\n window.postMessage(${JSON.stringify(JSON.stringify(message))}, '*');\n true;\n `;\n this.webViewRef.current.injectJavaScript(js);\n }\n\n onMessage(handler: (msg: ProtocolMessage) => void): () => void {\n this.handlers.push(handler);\n return () => {\n const idx = this.handlers.indexOf(handler);\n if (idx >= 0) this.handlers.splice(idx, 1);\n };\n }\n\n dispose(): void {\n this.handlers.length = 0;\n this.webViewRef = null;\n this._url = '';\n this._options = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkC;AAClC,0BAAqC;AACrC,kCAAkD;AAuC5C;AAvBC,SAAS,aAAa,EAAE,WAAW,QAAQ,MAAM,GAA0C;AAChG,QAAM,iBAAa,qBAAgB,IAAI;AAEvC,8BAAU,MAAM;AACd,cAAU,cAAc,UAAU;AAClC,WAAO,MAAM;AAAA,IAEb;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,QAAM,MAAM,UAAU;AACtB,MAAI,CAAC;A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AK,WAAW,QAAQ,KAAK,UAAjD,KAAK,EAAoD,CAC7E;AAAA,KACH;AAEJ;AAMO,SAAS,aAAkC;AAChD,QAAM,UAAM,0BAAW,cAAc;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;","names":["WebView","import_react","import_jsx_runtime"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { ProtocolMessage, ConnectEvent, Result, Connection, GetConnectionError, ConnectError, ListPaymentMethodsResponse, GetPaymentMethodsError, GetQuoteParams, Quote, GetQuoteError, Transaction, PaginationInfo, GetTransactionsError, TransactionWithStages, WidgetEvent, SetupWidgetError, ApplePayEvent, SetupApplePayError, BuyEvent, SetupBuyError, BuyButtonEvent, SetupBuyButtonError, GooglePayEvent, SetupGooglePayError, ChallengeEvent, SetupChallengeError, AddCardEvent, SetupAddCardError } from '@moonpay/platform-protocol';
2
- export { AddCardEvent, ApplePayEvent, BuyButtonEvent, BuyEvent, CardResponse, ChallengeCancellation, ChallengeCompleteResult, ChallengeEvent, ConnectEvent, Connection, ConnectionStatus, GetQuoteParams, GooglePayEvent, PaymentMethodConfig, Quote, Result, StoredPaymentMethod, Transaction, TransactionWithStages, WidgetEvent } from '@moonpay/platform-protocol';
1
+ import { ProtocolMessage, ConnectEvent, Result, Connection, GetConnectionError, ConnectError, AuthEvent, SetupAuthError, ListPaymentMethodsResponse, GetPaymentMethodsError, GetQuoteParams, Quote, GetQuoteError, Transaction, PaginationInfo, GetTransactionsError, TransactionWithStages, WidgetEvent, SetupWidgetError, ApplePayEvent, SetupApplePayError, BuyEvent, SetupBuyError, BuyButtonEvent, SetupBuyButtonError, GooglePayEvent, SetupGooglePayError, ChallengeEvent, SetupChallengeError, AddCardEvent, SetupAddCardError, CreateIdentityRequestBody, Identity, CreateIdentityError, GetIdentityError, UpdateIdentityRequestBody, UpdateIdentityError, IdentityVerificationResponse, VerifyIdentityError, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, GetIdentityUploadUrlError, SubmitIdentityFilesRequestBody, SubmitIdentityFilesError } from '@moonpay/platform-protocol';
2
+ export { AddCardEvent, ApplePayEvent, AuthEvent, BuyButtonEvent, BuyEvent, CardResponse, ChallengeCancellation, ChallengeCompleteResult, ChallengeEvent, ConnectEvent, Connection, ConnectionStatus, GetQuoteParams, GooglePayEvent, PaymentMethodConfig, Quote, Result, StoredPaymentMethod, Transaction, TransactionWithStages, WidgetEvent } from '@moonpay/platform-protocol';
3
3
  import { ViewStyle } from 'react-native';
4
4
  import { FrameTransport, FrameOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
5
5
  import { RefObject, ReactNode } from 'react';
@@ -43,6 +43,14 @@ interface MoonPayFrameProps {
43
43
  */
44
44
  declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
45
45
 
46
+ interface GetConnectionOptions {
47
+ /**
48
+ * Pass `true` for headless / Identity-API integrations so the check
49
+ * frame opts out of KYC-based statuses. Legal (`termsAcceptanceRequired`)
50
+ * is always surfaced regardless. Defaults to `false`.
51
+ */
52
+ skipKyc?: boolean;
53
+ }
46
54
  interface ConnectOptions {
47
55
  /** Theme options for the connect frame. */
48
56
  theme?: {
@@ -127,9 +135,25 @@ interface SetupAddCardOptions {
127
135
  interface AddCardFrame {
128
136
  dispose(): void;
129
137
  }
138
+ interface SetupAuthOptions {
139
+ /** Callback for auth frame lifecycle events. */
140
+ onEvent?: (event: AuthEvent) => void;
141
+ }
142
+ interface AuthFrame {
143
+ dispose(): void;
144
+ }
130
145
  interface RNClient {
131
- getConnection(): Promise<Result<Connection, GetConnectionError>>;
146
+ getConnection(options?: GetConnectionOptions): Promise<Result<Connection, GetConnectionError>>;
132
147
  connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;
148
+ /**
149
+ * Launch the auth frame — the lighter-weight counterpart to `connect()`
150
+ * for headless / Identity-API partners. Requires a `clientToken` to be
151
+ * present in the client's context, which is populated automatically by a
152
+ * prior `getConnection()` call that returned `connectionRequired`.
153
+ * Call `getConnection()` first; if its status is `connectionRequired`,
154
+ * call `setupAuth()` to drive the customer through email/OTP.
155
+ */
156
+ setupAuth(options: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>>;
133
157
  getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;
134
158
  getQuote(params: GetQuoteParams): Promise<Result<{
135
159
  data: Quote;
@@ -148,6 +172,24 @@ interface RNClient {
148
172
  setupGooglePay(options: SetupGooglePayOptions): Promise<Result<GooglePayFrame, SetupGooglePayError>>;
149
173
  setupChallenge(options: SetupChallengeOptions): Promise<Result<ChallengeFrame, SetupChallengeError>>;
150
174
  setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;
175
+ createIdentity(body: CreateIdentityRequestBody): Promise<Result<{
176
+ data: Identity | null;
177
+ }, CreateIdentityError>>;
178
+ getIdentity(id: string): Promise<Result<{
179
+ data: Identity;
180
+ }, GetIdentityError>>;
181
+ updateIdentity(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
182
+ data: Identity;
183
+ }, UpdateIdentityError>>;
184
+ verifyIdentity(id: string): Promise<Result<{
185
+ data: IdentityVerificationResponse;
186
+ }, VerifyIdentityError>>;
187
+ getIdentityUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
188
+ data: IdentityFileUploadUrl;
189
+ }, GetIdentityUploadUrlError>>;
190
+ submitIdentityFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
191
+ data: Identity;
192
+ }, SubmitIdentityFilesError>>;
151
193
  }
152
194
  interface MoonPayContextValue {
153
195
  client: RNClient;
@@ -161,4 +203,4 @@ interface MoonPayProviderProps {
161
203
  declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, children, }: MoonPayProviderProps): JSX.Element;
162
204
  declare function useMoonPay(): MoonPayContextValue;
163
205
 
164
- export { type AddCardFrame, type ApplePayFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type GooglePayFrame, MoonPayFrame, type MoonPayFrameProps, MoonPayProvider, type MoonPayProviderProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
206
+ export { type AddCardFrame, type ApplePayFrame, type AuthFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type GetConnectionOptions, type GooglePayFrame, MoonPayFrame, type MoonPayFrameProps, MoonPayProvider, type MoonPayProviderProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupAuthOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ProtocolMessage, ConnectEvent, Result, Connection, GetConnectionError, ConnectError, ListPaymentMethodsResponse, GetPaymentMethodsError, GetQuoteParams, Quote, GetQuoteError, Transaction, PaginationInfo, GetTransactionsError, TransactionWithStages, WidgetEvent, SetupWidgetError, ApplePayEvent, SetupApplePayError, BuyEvent, SetupBuyError, BuyButtonEvent, SetupBuyButtonError, GooglePayEvent, SetupGooglePayError, ChallengeEvent, SetupChallengeError, AddCardEvent, SetupAddCardError } from '@moonpay/platform-protocol';
2
- export { AddCardEvent, ApplePayEvent, BuyButtonEvent, BuyEvent, CardResponse, ChallengeCancellation, ChallengeCompleteResult, ChallengeEvent, ConnectEvent, Connection, ConnectionStatus, GetQuoteParams, GooglePayEvent, PaymentMethodConfig, Quote, Result, StoredPaymentMethod, Transaction, TransactionWithStages, WidgetEvent } from '@moonpay/platform-protocol';
1
+ import { ProtocolMessage, ConnectEvent, Result, Connection, GetConnectionError, ConnectError, AuthEvent, SetupAuthError, ListPaymentMethodsResponse, GetPaymentMethodsError, GetQuoteParams, Quote, GetQuoteError, Transaction, PaginationInfo, GetTransactionsError, TransactionWithStages, WidgetEvent, SetupWidgetError, ApplePayEvent, SetupApplePayError, BuyEvent, SetupBuyError, BuyButtonEvent, SetupBuyButtonError, GooglePayEvent, SetupGooglePayError, ChallengeEvent, SetupChallengeError, AddCardEvent, SetupAddCardError, CreateIdentityRequestBody, Identity, CreateIdentityError, GetIdentityError, UpdateIdentityRequestBody, UpdateIdentityError, IdentityVerificationResponse, VerifyIdentityError, IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, GetIdentityUploadUrlError, SubmitIdentityFilesRequestBody, SubmitIdentityFilesError } from '@moonpay/platform-protocol';
2
+ export { AddCardEvent, ApplePayEvent, AuthEvent, BuyButtonEvent, BuyEvent, CardResponse, ChallengeCancellation, ChallengeCompleteResult, ChallengeEvent, ConnectEvent, Connection, ConnectionStatus, GetQuoteParams, GooglePayEvent, PaymentMethodConfig, Quote, Result, StoredPaymentMethod, Transaction, TransactionWithStages, WidgetEvent } from '@moonpay/platform-protocol';
3
3
  import { ViewStyle } from 'react-native';
4
4
  import { FrameTransport, FrameOptions, ListTransactionsParams } from '@moonpay/platform-sdk-core';
5
5
  import { RefObject, ReactNode } from 'react';
@@ -43,6 +43,14 @@ interface MoonPayFrameProps {
43
43
  */
44
44
  declare function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null;
45
45
 
46
+ interface GetConnectionOptions {
47
+ /**
48
+ * Pass `true` for headless / Identity-API integrations so the check
49
+ * frame opts out of KYC-based statuses. Legal (`termsAcceptanceRequired`)
50
+ * is always surfaced regardless. Defaults to `false`.
51
+ */
52
+ skipKyc?: boolean;
53
+ }
46
54
  interface ConnectOptions {
47
55
  /** Theme options for the connect frame. */
48
56
  theme?: {
@@ -127,9 +135,25 @@ interface SetupAddCardOptions {
127
135
  interface AddCardFrame {
128
136
  dispose(): void;
129
137
  }
138
+ interface SetupAuthOptions {
139
+ /** Callback for auth frame lifecycle events. */
140
+ onEvent?: (event: AuthEvent) => void;
141
+ }
142
+ interface AuthFrame {
143
+ dispose(): void;
144
+ }
130
145
  interface RNClient {
131
- getConnection(): Promise<Result<Connection, GetConnectionError>>;
146
+ getConnection(options?: GetConnectionOptions): Promise<Result<Connection, GetConnectionError>>;
132
147
  connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;
148
+ /**
149
+ * Launch the auth frame — the lighter-weight counterpart to `connect()`
150
+ * for headless / Identity-API partners. Requires a `clientToken` to be
151
+ * present in the client's context, which is populated automatically by a
152
+ * prior `getConnection()` call that returned `connectionRequired`.
153
+ * Call `getConnection()` first; if its status is `connectionRequired`,
154
+ * call `setupAuth()` to drive the customer through email/OTP.
155
+ */
156
+ setupAuth(options: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>>;
133
157
  getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;
134
158
  getQuote(params: GetQuoteParams): Promise<Result<{
135
159
  data: Quote;
@@ -148,6 +172,24 @@ interface RNClient {
148
172
  setupGooglePay(options: SetupGooglePayOptions): Promise<Result<GooglePayFrame, SetupGooglePayError>>;
149
173
  setupChallenge(options: SetupChallengeOptions): Promise<Result<ChallengeFrame, SetupChallengeError>>;
150
174
  setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;
175
+ createIdentity(body: CreateIdentityRequestBody): Promise<Result<{
176
+ data: Identity | null;
177
+ }, CreateIdentityError>>;
178
+ getIdentity(id: string): Promise<Result<{
179
+ data: Identity;
180
+ }, GetIdentityError>>;
181
+ updateIdentity(id: string, body: UpdateIdentityRequestBody): Promise<Result<{
182
+ data: Identity;
183
+ }, UpdateIdentityError>>;
184
+ verifyIdentity(id: string): Promise<Result<{
185
+ data: IdentityVerificationResponse;
186
+ }, VerifyIdentityError>>;
187
+ getIdentityUploadUrl(id: string, body: IdentityFileUploadUrlRequestBody): Promise<Result<{
188
+ data: IdentityFileUploadUrl;
189
+ }, GetIdentityUploadUrlError>>;
190
+ submitIdentityFiles(id: string, body: SubmitIdentityFilesRequestBody): Promise<Result<{
191
+ data: Identity;
192
+ }, SubmitIdentityFilesError>>;
151
193
  }
152
194
  interface MoonPayContextValue {
153
195
  client: RNClient;
@@ -161,4 +203,4 @@ interface MoonPayProviderProps {
161
203
  declare function MoonPayProvider({ sessionToken, apiBaseUrl, frameBaseUrl, children, }: MoonPayProviderProps): JSX.Element;
162
204
  declare function useMoonPay(): MoonPayContextValue;
163
205
 
164
- export { type AddCardFrame, type ApplePayFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type GooglePayFrame, MoonPayFrame, type MoonPayFrameProps, MoonPayProvider, type MoonPayProviderProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
206
+ export { type AddCardFrame, type ApplePayFrame, type AuthFrame, type BuyButtonFrame, type BuyFrame, type ChallengeFrame, type ConnectFrame, type ConnectOptions, type GetConnectionOptions, type GooglePayFrame, MoonPayFrame, type MoonPayFrameProps, MoonPayProvider, type MoonPayProviderProps, type RNClient, type SetupAddCardOptions, type SetupApplePayOptions, type SetupAuthOptions, type SetupBuyButtonOptions, type SetupBuyOptions, type SetupChallengeOptions, type SetupGooglePayOptions, type SetupWidgetOptions, WebViewTransport, type WidgetFrame, useMoonPay };
package/dist/index.js CHANGED
@@ -160,12 +160,17 @@ function MoonPayProvider({
160
160
  });
161
161
  return { promise, transport };
162
162
  }
163
- async function getConnection() {
163
+ async function getConnection(options = {}) {
164
164
  const { privateKey, publicKey } = generateKeyPair();
165
165
  const channelId = `check-${Date.now()}`;
166
166
  const url = buildFrameUrl(
167
167
  FRAME_PATHS.checkConnection,
168
- { sessionToken, channelId, publicKey },
168
+ {
169
+ sessionToken,
170
+ channelId,
171
+ publicKey,
172
+ ...options.skipKyc && { skipKyc: true }
173
+ },
169
174
  { frameBaseUrl }
170
175
  );
171
176
  try {
@@ -266,6 +271,66 @@ function MoonPayProvider({
266
271
  });
267
272
  }
268
273
  }
274
+ async function setupAuth(opts) {
275
+ const clientToken = core.context.clientToken;
276
+ if (!clientToken) {
277
+ return err({
278
+ kind: "configurationError",
279
+ message: 'No clientToken in context \u2014 call getConnection() first and ensure it resolved with status "connectionRequired".'
280
+ });
281
+ }
282
+ const { privateKey, publicKey } = generateKeyPair();
283
+ const channelId = `auth-${Date.now()}`;
284
+ const url = buildFrameUrl(
285
+ FRAME_PATHS.auth,
286
+ { clientToken, channelId, publicKey },
287
+ { frameBaseUrl }
288
+ );
289
+ try {
290
+ const { promise } = createManagedFrame({ url, channelId, hidden: false });
291
+ const { handle, slotId } = await promise;
292
+ return new Promise((resolve) => {
293
+ handle.onMessage((msg) => {
294
+ if (msg.kind === "ready") {
295
+ opts.onEvent?.({ kind: "ready" });
296
+ return;
297
+ }
298
+ if (msg.kind === "error") {
299
+ const payload = msg.payload;
300
+ opts.onEvent?.({ kind: "error", payload });
301
+ handle.dispose();
302
+ removeSlot(slotId);
303
+ resolve(err({ kind: "genericError", message: "Auth frame error" }));
304
+ return;
305
+ }
306
+ if (msg.kind === "complete") {
307
+ const connection = msg.payload;
308
+ if (connection.status === ConnectionStatus.active) {
309
+ const creds = decryptCredentials(connection.credentials, privateKey);
310
+ core.context.setAccessToken(creds.accessToken);
311
+ core.context.setClientToken(creds.clientToken);
312
+ }
313
+ if (connection.status === ConnectionStatus.active || connection.status === ConnectionStatus.termsAcceptanceRequired) {
314
+ opts.onEvent?.({ kind: "complete", payload: connection });
315
+ }
316
+ resolve(
317
+ ok({
318
+ dispose: () => {
319
+ handle.dispose();
320
+ removeSlot(slotId);
321
+ }
322
+ })
323
+ );
324
+ }
325
+ });
326
+ });
327
+ } catch (e) {
328
+ return err({
329
+ kind: "genericError",
330
+ message: e instanceof Error ? e.message : "Auth setup failed"
331
+ });
332
+ }
333
+ }
269
334
  async function setupWidget(opts) {
270
335
  const channelId = `widget-${Date.now()}`;
271
336
  const url = buildFrameUrl(
@@ -580,16 +645,23 @@ function MoonPayProvider({
580
645
  }
581
646
  }
582
647
  async function setupChallenge(opts) {
583
- let channelId;
648
+ let url;
584
649
  try {
585
- channelId = new URL(opts.url).searchParams.get("channelId") ?? "";
586
- if (!channelId)
587
- throw new Error("missing channelId");
650
+ url = new URL(opts.url);
588
651
  } catch {
589
- return err({ kind: "configurationError", message: "Challenge URL is missing channelId" });
652
+ return err({ kind: "configurationError", message: "Invalid challenge URL" });
653
+ }
654
+ let channelId = url.searchParams.get("channelId") ?? "";
655
+ if (!channelId) {
656
+ channelId = `challenge-${Date.now()}`;
657
+ url.searchParams.set("channelId", channelId);
590
658
  }
591
659
  try {
592
- const { promise } = createManagedFrame({ url: opts.url, channelId, hidden: false });
660
+ const { promise } = createManagedFrame({
661
+ url: url.toString(),
662
+ channelId,
663
+ hidden: false
664
+ });
593
665
  const { handle, slotId } = await promise;
594
666
  handle.onMessage((msg) => {
595
667
  switch (msg.kind) {
@@ -668,6 +740,7 @@ function MoonPayProvider({
668
740
  return {
669
741
  getConnection,
670
742
  connect,
743
+ setupAuth,
671
744
  getPaymentMethods: () => core.getPaymentMethods(),
672
745
  getQuote: (params) => core.getQuote(params),
673
746
  listTransactions: (params) => core.listTransactions(params),
@@ -678,7 +751,13 @@ function MoonPayProvider({
678
751
  setupBuyButton,
679
752
  setupGooglePay,
680
753
  setupChallenge,
681
- setupAddCard
754
+ setupAddCard,
755
+ createIdentity: (body) => core.createIdentity(body),
756
+ getIdentity: (id) => core.getIdentity(id),
757
+ updateIdentity: (id, body) => core.updateIdentity(id, body),
758
+ verifyIdentity: (id) => core.verifyIdentity(id),
759
+ getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),
760
+ submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body)
682
761
  };
683
762
  }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);
684
763
  return /* @__PURE__ */ jsxs(MoonPayContext.Provider, { value: { client }, children: [
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/frame-component.tsx","../src/provider.tsx","../src/webview-transport.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { View, type ViewStyle } from 'react-native';\nimport WebView, { type WebViewMessageEvent } from 'react-native-webview';\nimport type { WebViewTransport } from './webview-transport.js';\n\nexport interface MoonPayFrameProps {\n /** The transport instance managing this frame's communication. */\n transport: WebViewTransport;\n /** Whether this is a hidden utility frame (zero height). */\n hidden?: boolean;\n /** Optional style overrides for the container view. */\n style?: ViewStyle;\n}\n\n/**\n * Reusable React Native component that renders a MoonPay frame as a WebView.\n * Bridges the WebViewTransport to the actual WebView instance.\n */\nexport function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null {\n const webViewRef = useRef<WebView>(null);\n\n useEffect(() => {\n transport.attachWebView(webViewRef);\n return () => {\n // Don't dispose — the orchestrator manages lifecycle\n };\n }, [transport]);\n\n const url = transport.url;\n if (!url) return null;\n\n const handleMessage = (event: WebViewMessageEvent) => {\n transport.handleWebViewMessage(event.nativeEvent.data);\n };\n\n const containerStyle: ViewStyle = hidden\n ? { width: 0, height: 0, overflow: 'hidden' }\n : { flex: 1, ...style };\n\n return (\n <View style={containerStyle}>\n <WebView\n ref={webViewRef}\n source={{ uri: url }}\n onMessage={handleMessage}\n allowsInlineMediaPlayback\n javaScriptEnabled\n domStorageEnabled\n style={{ flex: 1 }}\n />\n </View>\n );\n}\n","import {\n type AddCardEvent,\n type ApplePayEvent,\n type BuyButtonEvent,\n type BuyEvent,\n type CardResponse,\n type ChallengeCancellation,\n type ChallengeCompleteResult,\n type ChallengeEvent,\n type ConnectError,\n type ConnectEvent,\n type Connection,\n ConnectionStatus,\n err,\n type GetConnectionError,\n type GetPaymentMethodsError,\n type GetQuoteError,\n type GetQuoteParams,\n type GetTransactionsError,\n type GooglePayEvent,\n type GooglePayInboundMessageMap,\n type ListPaymentMethodsResponse,\n ok,\n type PaginationInfo,\n type ProtocolMessage,\n type Quote,\n type Result,\n type SetupAddCardError,\n type SetupApplePayError,\n type SetupBuyButtonError,\n type SetupBuyError,\n type SetupChallengeError,\n type SetupGooglePayError,\n type SetupWidgetError,\n type Transaction,\n type TransactionWithStages,\n type WidgetEvent,\n} from '@moonpay/platform-protocol';\nimport {\n buildFrameUrl,\n type CoreClient,\n createClientCore,\n createFrameOrchestrator,\n decryptCredentials,\n FRAME_PATHS,\n type FrameHandle,\n generateKeyPair,\n type ListTransactionsParams,\n} from '@moonpay/platform-sdk-core';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { MoonPayFrame } from './frame-component.js';\nimport { WebViewTransport } from './webview-transport.js';\n\n// ---------------------------------------------------------------------------\n// Frame slot — represents a frame the provider needs to render\n// ---------------------------------------------------------------------------\n\ninterface FrameSlot {\n id: string;\n transport: WebViewTransport;\n hidden: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface ConnectOptions {\n /** Theme options for the connect frame. */\n theme?: { appearance?: 'light' | 'dark' };\n /** Callback for connect lifecycle events. */\n onEvent?: (event: ConnectEvent) => void;\n}\n\nexport interface ConnectFrame {\n dispose(): void;\n}\n\nexport interface SetupWidgetOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for widget lifecycle events. */\n onEvent?: (event: WidgetEvent) => void;\n}\n\nexport interface WidgetFrame {\n dispose(): void;\n}\n\nexport interface SetupApplePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for Apple Pay lifecycle events. */\n onEvent?: (event: ApplePayEvent) => void;\n}\n\nexport interface ApplePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for buy frame lifecycle events. */\n onEvent?: (event: BuyEvent) => void;\n}\n\nexport interface BuyFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyButtonOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for buy-button frame lifecycle events. */\n onEvent?: (event: BuyButtonEvent) => void;\n}\n\nexport interface BuyButtonFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupGooglePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for Google Pay lifecycle events. */\n onEvent?: (event: GooglePayEvent) => void;\n}\n\nexport interface GooglePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupChallengeOptions {\n /** Full challenge URL received from a frame's `challenge` event. */\n url: string;\n /** Callback for challenge frame lifecycle events. */\n onEvent?: (event: ChallengeEvent) => void;\n}\n\nexport interface ChallengeFrame {\n dispose(): void;\n}\n\nexport interface SetupAddCardOptions {\n /** Callback for add-card frame lifecycle events. */\n onEvent?: (event: AddCardEvent) => void;\n}\n\nexport interface AddCardFrame {\n dispose(): void;\n}\n\nexport interface RNClient {\n getConnection(): Promise<Result<Connection, GetConnectionError>>;\n connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;\n getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;\n getQuote(params: GetQuoteParams): Promise<Result<{ data: Quote }, GetQuoteError>>;\n listTransactions(\n params?: ListTransactionsParams,\n ): Promise<Result<{ data: Transaction[]; pageInfo: PaginationInfo }, GetTransactionsError>>;\n getTransaction(\n id: string,\n ): Promise<Result<{ data: TransactionWithStages }, GetTransactionsError>>;\n setupWidget(options: SetupWidgetOptions): Promise<Result<WidgetFrame, SetupWidgetError>>;\n setupApplePay(options: SetupApplePayOptions): Promise<Result<ApplePayFrame, SetupApplePayError>>;\n setupBuy(options: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>>;\n setupBuyButton(\n options: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>>;\n setupGooglePay(\n options: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>>;\n setupChallenge(\n options: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>>;\n setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface MoonPayContextValue {\n client: RNClient;\n}\n\nconst MoonPayContext = createContext<MoonPayContextValue | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface MoonPayProviderProps {\n sessionToken: string;\n apiBaseUrl?: string;\n frameBaseUrl?: string;\n children: ReactNode;\n}\n\nlet slotCounter = 0;\n\nexport function MoonPayProvider({\n sessionToken,\n apiBaseUrl,\n frameBaseUrl,\n children,\n}: MoonPayProviderProps): JSX.Element {\n const [frameSlots, setFrameSlots] = useState<FrameSlot[]>([]);\n\n // Stable refs for addSlot/removeSlot so client methods don't re-create\n const addSlot = useCallback((slot: FrameSlot) => {\n setFrameSlots((prev) => [...prev, slot]);\n }, []);\n\n const removeSlot = useCallback((id: string) => {\n setFrameSlots((prev) => prev.filter((s) => s.id !== id));\n }, []);\n\n // Keep a ref to core so it's stable across renders\n const coreRef = useRef<CoreClient | null>(null);\n if (!coreRef.current) {\n coreRef.current = createClientCore({\n apiBaseUrl,\n frameBaseUrl,\n createTransport: () => new WebViewTransport(),\n });\n }\n const core = coreRef.current;\n\n const client = useMemo<RNClient>(() => {\n // Helper: create a transport + slot, wait for orchestrator handshake\n function createManagedFrame(opts: {\n url: string;\n channelId: string;\n hidden: boolean;\n handshakeTimeout?: number;\n }): { promise: Promise<{ handle: FrameHandle; slotId: string }>; transport: WebViewTransport } {\n const transport = new WebViewTransport();\n const slotId = `slot-${++slotCounter}`;\n\n const promise = new Promise<{ handle: FrameHandle; slotId: string }>((resolve, reject) => {\n // Defer adding the slot to allow the transport to be fully set up\n // before the WebView renders\n transport.create(opts.url, { container: null, hidden: opts.hidden });\n\n addSlot({ id: slotId, transport, hidden: opts.hidden });\n\n createFrameOrchestrator({\n transport,\n channelId: opts.channelId,\n url: opts.url,\n container: null,\n hidden: opts.hidden,\n handshakeTimeout: opts.handshakeTimeout ?? 15_000,\n })\n .then((handle) => resolve({ handle, slotId }))\n .catch((e) => {\n removeSlot(slotId);\n reject(e);\n });\n });\n\n return { promise, transport };\n }\n\n // ------- getConnection (hidden frame) -------\n async function getConnection(): Promise<Result<Connection, GetConnectionError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `check-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.checkConnection,\n { sessionToken, channelId, publicKey },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({\n url,\n channelId,\n hidden: true,\n handshakeTimeout: 10_000,\n });\n\n const { handle, slotId } = await promise;\n\n return new Promise<Result<Connection, GetConnectionError>>((resolve) => {\n const timeout = setTimeout(() => {\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Get connection timed out' }));\n }, 10_000);\n\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'error') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const payload = msg.payload as { message: string };\n resolve(err({ message: payload.message }));\n return;\n }\n\n if (msg.kind === 'complete') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n resolve(ok(connection));\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Failed to check connection',\n });\n }\n }\n\n // ------- connect (visible frame) -------\n async function connect(opts: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `connect-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.connect,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(opts.theme?.appearance && { appearance: opts.theme.appearance }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<ConnectFrame, ConnectError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Connection error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n opts.onEvent?.({ kind: 'complete', payload: connection });\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Connect failed',\n });\n }\n }\n\n // ------- setupWidget -------\n async function setupWidget(\n opts: SetupWidgetOptions,\n ): Promise<Result<WidgetFrame, SetupWidgetError>> {\n const channelId = `widget-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.widget,\n {\n flow: 'buy',\n clientToken: core.context.clientToken,\n quoteSignature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'transactionCreated':\n opts.onEvent?.({\n kind: 'transactionCreated',\n payload: msg.payload as { transaction: { id: string; status: string } },\n });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as {\n code: 'configurationError' | 'apiError' | 'generic';\n message: string;\n };\n opts.onEvent?.({\n kind: 'error',\n payload: { code: payload.code, message: payload.message },\n });\n break;\n }\n case 'close':\n opts.onEvent?.({ kind: 'close' });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Widget setup failed',\n });\n }\n }\n\n // ------- setupApplePay -------\n async function setupApplePay(\n opts: SetupApplePayOptions,\n ): Promise<Result<ApplePayFrame, SetupApplePayError>> {\n const channelId = `applepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.applePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'applePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as\n | 'configurationError'\n | 'invalidQuote'\n | 'oneTapApplePaySecondFactorRequired'\n | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Apple Pay setup failed',\n });\n }\n }\n\n // ------- setupBuy (hidden frame) -------\n async function setupBuy(opts: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>> {\n const channelId = `buy-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buy,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: true });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy setup failed',\n });\n }\n }\n\n // ------- setupBuyButton -------\n async function setupBuyButton(\n opts: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>> {\n const channelId = `buy-button-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buyButton,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy button setup failed',\n });\n }\n }\n\n // ------- setupGooglePay -------\n async function setupGooglePay(\n opts: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>> {\n const channelId = `googlepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.googlePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as GooglePayInboundMessageMap['challenge'],\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'googlePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as 'configurationError' | 'invalidQuote' | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Google Pay setup failed',\n });\n }\n }\n\n // ------- setupChallenge -------\n async function setupChallenge(\n opts: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>> {\n let channelId: string;\n try {\n channelId = new URL(opts.url).searchParams.get('channelId') ?? '';\n if (!channelId) throw new Error('missing channelId');\n } catch {\n return err({ kind: 'configurationError', message: 'Challenge URL is missing channelId' });\n }\n\n try {\n const { promise } = createManagedFrame({ url: opts.url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as ChallengeCompleteResult,\n });\n break;\n case 'cancelled':\n opts.onEvent?.({\n kind: 'cancelled',\n payload: msg.payload as ChallengeCancellation,\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Challenge setup failed',\n });\n }\n }\n\n // ------- setupAddCard -------\n async function setupAddCard(\n opts: SetupAddCardOptions,\n ): Promise<Result<AddCardFrame, SetupAddCardError>> {\n const channelId = `add-card-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.addCard,\n { channelId, clientToken: core.context.clientToken },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({ kind: 'complete', payload: msg.payload as { card: CardResponse } });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as {\n code: 'generic' | 'configurationError';\n message: string;\n },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Add card setup failed',\n });\n }\n }\n\n return {\n getConnection,\n connect,\n getPaymentMethods: () => core.getPaymentMethods(),\n getQuote: (params) => core.getQuote(params),\n listTransactions: (params) => core.listTransactions(params),\n getTransaction: (id) => core.getTransaction(id),\n setupWidget,\n setupApplePay,\n setupBuy,\n setupBuyButton,\n setupGooglePay,\n setupChallenge,\n setupAddCard,\n };\n }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);\n\n return (\n <MoonPayContext.Provider value={{ client }}>\n {children}\n {frameSlots.map((slot) => (\n <MoonPayFrame key={slot.id} transport={slot.transport} hidden={slot.hidden} />\n ))}\n </MoonPayContext.Provider>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useMoonPay(): MoonPayContextValue {\n const ctx = useContext(MoonPayContext);\n if (!ctx) {\n throw new Error('useMoonPay must be used within a <MoonPayProvider>');\n }\n return ctx;\n}\n","import type { ProtocolMessage } from '@moonpay/platform-protocol';\nimport type { FrameOptions, FrameTransport } from '@moonpay/platform-sdk-core';\nimport type { RefObject } from 'react';\nimport type WebView from 'react-native-webview';\n\n/**\n * FrameTransport implementation for React Native using react-native-webview.\n *\n * Unlike the web IframeTransport, the WebView is rendered declaratively via\n * React components. This transport bridges the imperative FrameTransport\n * interface to a WebView ref.\n */\nexport class WebViewTransport implements FrameTransport {\n private webViewRef: RefObject<WebView | null> | null = null;\n private handlers: Array<(msg: ProtocolMessage) => void> = [];\n private _url: string = '';\n private _options: FrameOptions | null = null;\n\n /** Called by the frame component when it mounts the WebView. */\n attachWebView(ref: RefObject<WebView | null>): void {\n this.webViewRef = ref;\n }\n\n /** Called by the WebView's onMessage prop to route incoming messages. */\n handleWebViewMessage(data: string): void {\n try {\n const msg: ProtocolMessage = JSON.parse(data);\n if (!msg.kind) return;\n for (const handler of this.handlers) {\n handler(msg);\n }\n } catch {\n // Ignore non-protocol messages\n }\n }\n\n get url(): string {\n return this._url;\n }\n\n get options(): FrameOptions | null {\n return this._options;\n }\n\n // FrameTransport interface\n\n create(url: string, options: FrameOptions): void {\n this._url = url;\n this._options = options;\n // The actual WebView rendering is handled by React components.\n // This method stores the URL and options for the component to read.\n }\n\n sendMessage(message: ProtocolMessage): void {\n if (!this.webViewRef?.current) {\n throw new Error('Cannot send message: WebView not attached');\n }\n const js = `\n window.postMessage(${JSON.stringify(JSON.stringify(message))}, '*');\n true;\n `;\n this.webViewRef.current.injectJavaScript(js);\n }\n\n onMessage(handler: (msg: ProtocolMessage) => void): () => void {\n this.handlers.push(handler);\n return () => {\n const idx = this.handlers.indexOf(handler);\n if (idx >= 0) this.handlers.splice(idx, 1);\n };\n }\n\n dispose(): void {\n this.handlers.length = 0;\n this.webViewRef = null;\n this._url = '';\n this._options = null;\n }\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,YAA4B;AACrC,OAAO,aAA2C;AAuC5C;AAvBC,SAAS,aAAa,EAAE,WAAW,QAAQ,MAAM,GAA0C;AAChG,QAAM,aAAa,OAAgB,IAAI;AAEvC,YAAU,MAAM;AACd,cAAU,cAAc,UAAU;AAClC,WAAO,MAAM;AAAA,IAEb;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,QAAM,MAAM,UAAU;AACtB,MAAI,CAAC;AAAK,WAAO;AAEjB,QAAM,gBAAgB,CAAC,UAA+B;AACpD,cAAU,qBAAqB,MAAM,YAAY,IAAI;AAAA,EACvD;AAEA,QAAM,iBAA4B,SAC9B,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,SAAS,IAC1C,EAAE,MAAM,GAAG,GAAG,MAAM;AAExB,SACE,oBAAC,QAAK,OAAO,gBACX;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ,EAAE,KAAK,IAAI;AAAA,MACnB,WAAW;AAAA,MACX,2BAAyB;AAAA,MACzB,mBAAiB;AAAA,MACjB,mBAAiB;AAAA,MACjB,OAAO,EAAE,MAAM,EAAE;AAAA;AAAA,EACnB,GACF;AAEJ;;;ACpDA;AAAA,EAYE;AAAA,EACA;AAAA,EASA;AAAA,OAeK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAAA;AAAA,EACA;AAAA,OACK;;;AC7CA,IAAM,mBAAN,MAAiD;AAAA,EAC9C,aAA+C;AAAA,EAC/C,WAAkD,CAAC;AAAA,EACnD,OAAe;AAAA,EACf,WAAgC;AAAA;AAAA,EAGxC,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AA,YACF,KAAK;AACH,mBAAK,UAAU;AAAA,gBACb,MAAM;AAAA,gBACN,SAAS,IAAI;AAAA,cAIf,CAAC;AACD;AAAA,UACJ;AAAA,QACF,CAAC;AAED,eAAO,GAAG;AAAA,UACR,SAAS,MAAM;AACb,mBAAO,QAAQ;AACf,uBAAW,MAAM;AAAA,UACnB;AAAA,QACF,CAAC;AAAA,MACH,SAAS,GAAG;AACV,eAAO,IAAI;AAAA,UACT,MAAM;AAAA,UACN,SAAS,aAAa,QAAQ,EAAE,UAAU;AAAA,QAC5C,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,mBAAmB,MAAM,KAAK,kBAAkB;AAAA,MAChD,UAAU,CAAC,WAAW,KAAK,SAAS,MAAM;AAAA,MAC1C,kBAAkB,CAAC,WAAW,KAAK,iBAAiB,MAAM;AAAA,MAC1D,gBAAgB,CAAC,OAAO,KAAK,eAAe,EAAE;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,cAAc,cAAc,MAAM,SAAS,UAAU,CAAC;AAE1D,SACE,qBAAC,eAAe,UAAf,EAAwB,OAAO,EAAE,OAAO,GACtC;AAAA;AAAA,IACA,WAAW,IAAI,CAAC,SACf,gBAAAD,KAAC,gBAA2B,WAAW,KAAK,WAAW,QAAQ,KAAK,UAAjD,KAAK,EAAoD,CAC7E;AAAA,KACH;AAEJ;AAMO,SAAS,aAAkC;AAChD,QAAM,MAAM,WAAW,cAAc;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;","names":["useRef","jsx","useRef"]}
1
+ {"version":3,"sources":["../src/frame-component.tsx","../src/provider.tsx","../src/webview-transport.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { View, type ViewStyle } from 'react-native';\nimport WebView, { type WebViewMessageEvent } from 'react-native-webview';\nimport type { WebViewTransport } from './webview-transport.js';\n\nexport interface MoonPayFrameProps {\n /** The transport instance managing this frame's communication. */\n transport: WebViewTransport;\n /** Whether this is a hidden utility frame (zero height). */\n hidden?: boolean;\n /** Optional style overrides for the container view. */\n style?: ViewStyle;\n}\n\n/**\n * Reusable React Native component that renders a MoonPay frame as a WebView.\n * Bridges the WebViewTransport to the actual WebView instance.\n */\nexport function MoonPayFrame({ transport, hidden, style }: MoonPayFrameProps): JSX.Element | null {\n const webViewRef = useRef<WebView>(null);\n\n useEffect(() => {\n transport.attachWebView(webViewRef);\n return () => {\n // Don't dispose — the orchestrator manages lifecycle\n };\n }, [transport]);\n\n const url = transport.url;\n if (!url) return null;\n\n const handleMessage = (event: WebViewMessageEvent) => {\n transport.handleWebViewMessage(event.nativeEvent.data);\n };\n\n const containerStyle: ViewStyle = hidden\n ? { width: 0, height: 0, overflow: 'hidden' }\n : { flex: 1, ...style };\n\n return (\n <View style={containerStyle}>\n <WebView\n ref={webViewRef}\n source={{ uri: url }}\n onMessage={handleMessage}\n allowsInlineMediaPlayback\n javaScriptEnabled\n domStorageEnabled\n style={{ flex: 1 }}\n />\n </View>\n );\n}\n","import {\n type AddCardEvent,\n type ApplePayEvent,\n type AuthEvent,\n type BuyButtonEvent,\n type BuyEvent,\n type CardResponse,\n type ChallengeCancellation,\n type ChallengeCompleteResult,\n type ChallengeEvent,\n type ConnectError,\n type ConnectEvent,\n type Connection,\n ConnectionStatus,\n type CreateIdentityError,\n type CreateIdentityRequestBody,\n err,\n type GetConnectionError,\n type GetIdentityError,\n type GetIdentityUploadUrlError,\n type GetPaymentMethodsError,\n type GetQuoteError,\n type GetQuoteParams,\n type GetTransactionsError,\n type GooglePayEvent,\n type GooglePayInboundMessageMap,\n type Identity,\n type IdentityFileUploadUrl,\n type IdentityFileUploadUrlRequestBody,\n type IdentityVerificationResponse,\n type ListPaymentMethodsResponse,\n ok,\n type PaginationInfo,\n type ProtocolMessage,\n type Quote,\n type Result,\n type SetupAddCardError,\n type SetupApplePayError,\n type SetupAuthError,\n type SetupBuyButtonError,\n type SetupBuyError,\n type SetupChallengeError,\n type SetupGooglePayError,\n type SetupWidgetError,\n type SubmitIdentityFilesError,\n type SubmitIdentityFilesRequestBody,\n type Transaction,\n type TransactionWithStages,\n type UpdateIdentityError,\n type UpdateIdentityRequestBody,\n type VerifyIdentityError,\n type WidgetEvent,\n} from '@moonpay/platform-protocol';\nimport {\n buildFrameUrl,\n type CoreClient,\n createClientCore,\n createFrameOrchestrator,\n decryptCredentials,\n FRAME_PATHS,\n type FrameHandle,\n generateKeyPair,\n type ListTransactionsParams,\n} from '@moonpay/platform-sdk-core';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { MoonPayFrame } from './frame-component.js';\nimport { WebViewTransport } from './webview-transport.js';\n\n// ---------------------------------------------------------------------------\n// Frame slot — represents a frame the provider needs to render\n// ---------------------------------------------------------------------------\n\ninterface FrameSlot {\n id: string;\n transport: WebViewTransport;\n hidden: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface GetConnectionOptions {\n /**\n * Pass `true` for headless / Identity-API integrations so the check\n * frame opts out of KYC-based statuses. Legal (`termsAcceptanceRequired`)\n * is always surfaced regardless. Defaults to `false`.\n */\n skipKyc?: boolean;\n}\n\nexport interface ConnectOptions {\n /** Theme options for the connect frame. */\n theme?: { appearance?: 'light' | 'dark' };\n /** Callback for connect lifecycle events. */\n onEvent?: (event: ConnectEvent) => void;\n}\n\nexport interface ConnectFrame {\n dispose(): void;\n}\n\nexport interface SetupWidgetOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for widget lifecycle events. */\n onEvent?: (event: WidgetEvent) => void;\n}\n\nexport interface WidgetFrame {\n dispose(): void;\n}\n\nexport interface SetupApplePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for Apple Pay lifecycle events. */\n onEvent?: (event: ApplePayEvent) => void;\n}\n\nexport interface ApplePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for buy frame lifecycle events. */\n onEvent?: (event: BuyEvent) => void;\n}\n\nexport interface BuyFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupBuyButtonOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Callback for buy-button frame lifecycle events. */\n onEvent?: (event: BuyButtonEvent) => void;\n}\n\nexport interface BuyButtonFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupGooglePayOptions {\n /** Quote signature from getQuote(). */\n quote: string;\n /** Partner-assigned identifier for this transaction attempt. */\n externalTransactionId?: string;\n /** Callback for Google Pay lifecycle events. */\n onEvent?: (event: GooglePayEvent) => void;\n}\n\nexport interface GooglePayFrame {\n /** Update the quote (e.g., after expiry). */\n setQuote(signature: string): void;\n dispose(): void;\n}\n\nexport interface SetupChallengeOptions {\n /** Full challenge URL received from a frame's `challenge` event. */\n url: string;\n /** Callback for challenge frame lifecycle events. */\n onEvent?: (event: ChallengeEvent) => void;\n}\n\nexport interface ChallengeFrame {\n dispose(): void;\n}\n\nexport interface SetupAddCardOptions {\n /** Callback for add-card frame lifecycle events. */\n onEvent?: (event: AddCardEvent) => void;\n}\n\nexport interface AddCardFrame {\n dispose(): void;\n}\n\nexport interface SetupAuthOptions {\n /** Callback for auth frame lifecycle events. */\n onEvent?: (event: AuthEvent) => void;\n}\n\nexport interface AuthFrame {\n dispose(): void;\n}\n\nexport interface RNClient {\n getConnection(options?: GetConnectionOptions): Promise<Result<Connection, GetConnectionError>>;\n connect(options: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>>;\n /**\n * Launch the auth frame — the lighter-weight counterpart to `connect()`\n * for headless / Identity-API partners. Requires a `clientToken` to be\n * present in the client's context, which is populated automatically by a\n * prior `getConnection()` call that returned `connectionRequired`.\n * Call `getConnection()` first; if its status is `connectionRequired`,\n * call `setupAuth()` to drive the customer through email/OTP.\n */\n setupAuth(options: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>>;\n getPaymentMethods(): Promise<Result<ListPaymentMethodsResponse, GetPaymentMethodsError>>;\n getQuote(params: GetQuoteParams): Promise<Result<{ data: Quote }, GetQuoteError>>;\n listTransactions(\n params?: ListTransactionsParams,\n ): Promise<Result<{ data: Transaction[]; pageInfo: PaginationInfo }, GetTransactionsError>>;\n getTransaction(\n id: string,\n ): Promise<Result<{ data: TransactionWithStages }, GetTransactionsError>>;\n setupWidget(options: SetupWidgetOptions): Promise<Result<WidgetFrame, SetupWidgetError>>;\n setupApplePay(options: SetupApplePayOptions): Promise<Result<ApplePayFrame, SetupApplePayError>>;\n setupBuy(options: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>>;\n setupBuyButton(\n options: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>>;\n setupGooglePay(\n options: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>>;\n setupChallenge(\n options: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>>;\n setupAddCard(options: SetupAddCardOptions): Promise<Result<AddCardFrame, SetupAddCardError>>;\n\n // Identity API\n createIdentity(\n body: CreateIdentityRequestBody,\n ): Promise<Result<{ data: Identity | null }, CreateIdentityError>>;\n getIdentity(id: string): Promise<Result<{ data: Identity }, GetIdentityError>>;\n updateIdentity(\n id: string,\n body: UpdateIdentityRequestBody,\n ): Promise<Result<{ data: Identity }, UpdateIdentityError>>;\n verifyIdentity(\n id: string,\n ): Promise<Result<{ data: IdentityVerificationResponse }, VerifyIdentityError>>;\n getIdentityUploadUrl(\n id: string,\n body: IdentityFileUploadUrlRequestBody,\n ): Promise<Result<{ data: IdentityFileUploadUrl }, GetIdentityUploadUrlError>>;\n submitIdentityFiles(\n id: string,\n body: SubmitIdentityFilesRequestBody,\n ): Promise<Result<{ data: Identity }, SubmitIdentityFilesError>>;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface MoonPayContextValue {\n client: RNClient;\n}\n\nconst MoonPayContext = createContext<MoonPayContextValue | null>(null);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport interface MoonPayProviderProps {\n sessionToken: string;\n apiBaseUrl?: string;\n frameBaseUrl?: string;\n children: ReactNode;\n}\n\nlet slotCounter = 0;\n\nexport function MoonPayProvider({\n sessionToken,\n apiBaseUrl,\n frameBaseUrl,\n children,\n}: MoonPayProviderProps): JSX.Element {\n const [frameSlots, setFrameSlots] = useState<FrameSlot[]>([]);\n\n // Stable refs for addSlot/removeSlot so client methods don't re-create\n const addSlot = useCallback((slot: FrameSlot) => {\n setFrameSlots((prev) => [...prev, slot]);\n }, []);\n\n const removeSlot = useCallback((id: string) => {\n setFrameSlots((prev) => prev.filter((s) => s.id !== id));\n }, []);\n\n // Keep a ref to core so it's stable across renders\n const coreRef = useRef<CoreClient | null>(null);\n if (!coreRef.current) {\n coreRef.current = createClientCore({\n apiBaseUrl,\n frameBaseUrl,\n createTransport: () => new WebViewTransport(),\n });\n }\n const core = coreRef.current;\n\n const client = useMemo<RNClient>(() => {\n // Helper: create a transport + slot, wait for orchestrator handshake\n function createManagedFrame(opts: {\n url: string;\n channelId: string;\n hidden: boolean;\n handshakeTimeout?: number;\n }): { promise: Promise<{ handle: FrameHandle; slotId: string }>; transport: WebViewTransport } {\n const transport = new WebViewTransport();\n const slotId = `slot-${++slotCounter}`;\n\n const promise = new Promise<{ handle: FrameHandle; slotId: string }>((resolve, reject) => {\n // Defer adding the slot to allow the transport to be fully set up\n // before the WebView renders\n transport.create(opts.url, { container: null, hidden: opts.hidden });\n\n addSlot({ id: slotId, transport, hidden: opts.hidden });\n\n createFrameOrchestrator({\n transport,\n channelId: opts.channelId,\n url: opts.url,\n container: null,\n hidden: opts.hidden,\n handshakeTimeout: opts.handshakeTimeout ?? 15_000,\n })\n .then((handle) => resolve({ handle, slotId }))\n .catch((e) => {\n removeSlot(slotId);\n reject(e);\n });\n });\n\n return { promise, transport };\n }\n\n // ------- getConnection (hidden frame) -------\n async function getConnection(\n options: GetConnectionOptions = {},\n ): Promise<Result<Connection, GetConnectionError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `check-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.checkConnection,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(options.skipKyc && { skipKyc: true }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({\n url,\n channelId,\n hidden: true,\n handshakeTimeout: 10_000,\n });\n\n const { handle, slotId } = await promise;\n\n return new Promise<Result<Connection, GetConnectionError>>((resolve) => {\n const timeout = setTimeout(() => {\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Get connection timed out' }));\n }, 10_000);\n\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'error') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const payload = msg.payload as { message: string };\n resolve(err({ message: payload.message }));\n return;\n }\n\n if (msg.kind === 'complete') {\n clearTimeout(timeout);\n handle.dispose();\n removeSlot(slotId);\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n resolve(ok(connection));\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Failed to check connection',\n });\n }\n }\n\n // ------- connect (visible frame) -------\n async function connect(opts: ConnectOptions): Promise<Result<ConnectFrame, ConnectError>> {\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `connect-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.connect,\n {\n sessionToken,\n channelId,\n publicKey,\n ...(opts.theme?.appearance && { appearance: opts.theme.appearance }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<ConnectFrame, ConnectError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ message: 'Connection error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n opts.onEvent?.({ kind: 'complete', payload: connection });\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n message: e instanceof Error ? e.message : 'Connect failed',\n });\n }\n }\n\n // ------- setupAuth (visible frame) -------\n async function setupAuth(opts: SetupAuthOptions): Promise<Result<AuthFrame, SetupAuthError>> {\n const clientToken = core.context.clientToken;\n if (!clientToken) {\n return err({\n kind: 'configurationError',\n message:\n 'No clientToken in context — call getConnection() first and ensure it resolved with status \"connectionRequired\".',\n });\n }\n\n const { privateKey, publicKey } = generateKeyPair();\n const channelId = `auth-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.auth,\n { clientToken, channelId, publicKey },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n return new Promise<Result<AuthFrame, SetupAuthError>>((resolve) => {\n handle.onMessage((msg: ProtocolMessage) => {\n if (msg.kind === 'ready') {\n opts.onEvent?.({ kind: 'ready' });\n return;\n }\n\n if (msg.kind === 'error') {\n const payload = msg.payload as import('@moonpay/platform-protocol').ConnectionError;\n opts.onEvent?.({ kind: 'error', payload });\n handle.dispose();\n removeSlot(slotId);\n resolve(err({ kind: 'genericError', message: 'Auth frame error' }));\n return;\n }\n\n if (msg.kind === 'complete') {\n const connection = msg.payload as Connection;\n\n if (connection.status === ConnectionStatus.active) {\n const creds = decryptCredentials(connection.credentials, privateKey);\n core.context.setAccessToken(creds.accessToken);\n core.context.setClientToken(creds.clientToken);\n }\n\n if (\n connection.status === ConnectionStatus.active ||\n connection.status === ConnectionStatus.termsAcceptanceRequired\n ) {\n opts.onEvent?.({ kind: 'complete', payload: connection });\n }\n resolve(\n ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n }),\n );\n }\n });\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Auth setup failed',\n });\n }\n }\n\n // ------- setupWidget -------\n async function setupWidget(\n opts: SetupWidgetOptions,\n ): Promise<Result<WidgetFrame, SetupWidgetError>> {\n const channelId = `widget-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.widget,\n {\n flow: 'buy',\n clientToken: core.context.clientToken,\n quoteSignature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'transactionCreated':\n opts.onEvent?.({\n kind: 'transactionCreated',\n payload: msg.payload as { transaction: { id: string; status: string } },\n });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as {\n code: 'configurationError' | 'apiError' | 'generic';\n message: string;\n };\n opts.onEvent?.({\n kind: 'error',\n payload: { code: payload.code, message: payload.message },\n });\n break;\n }\n case 'close':\n opts.onEvent?.({ kind: 'close' });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Widget setup failed',\n });\n }\n }\n\n // ------- setupApplePay -------\n async function setupApplePay(\n opts: SetupApplePayOptions,\n ): Promise<Result<ApplePayFrame, SetupApplePayError>> {\n const channelId = `applepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.applePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'applePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as\n | 'configurationError'\n | 'invalidQuote'\n | 'oneTapApplePaySecondFactorRequired'\n | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Apple Pay setup failed',\n });\n }\n }\n\n // ------- setupBuy (hidden frame) -------\n async function setupBuy(opts: SetupBuyOptions): Promise<Result<BuyFrame, SetupBuyError>> {\n const channelId = `buy-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buy,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: true });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy setup failed',\n });\n }\n }\n\n // ------- setupBuyButton -------\n async function setupBuyButton(\n opts: SetupBuyButtonOptions,\n ): Promise<Result<BuyButtonFrame, SetupBuyButtonError>> {\n const channelId = `buy-button-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.buyButton,\n {\n channelId,\n clientToken: core.context.clientToken,\n signature: opts.quote,\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as { kind: string; url: string },\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Buy button setup failed',\n });\n }\n }\n\n // ------- setupGooglePay -------\n async function setupGooglePay(\n opts: SetupGooglePayOptions,\n ): Promise<Result<GooglePayFrame, SetupGooglePayError>> {\n const channelId = `googlepay-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.googlePay,\n {\n clientToken: core.context.clientToken,\n signature: opts.quote,\n channelId,\n ...(opts.externalTransactionId && { externalTransactionId: opts.externalTransactionId }),\n },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n const setQuote = (signature: string) => {\n handle.sendMessage({\n version: 2,\n meta: { channelId },\n kind: 'setQuote',\n payload: { quote: { signature } },\n });\n };\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as {\n transaction: import('@moonpay/platform-protocol').FrameTransaction;\n },\n });\n break;\n case 'challenge':\n opts.onEvent?.({\n kind: 'challenge',\n payload: msg.payload as GooglePayInboundMessageMap['challenge'],\n });\n break;\n case 'error': {\n const payload = msg.payload as { code: string; message: string };\n if (payload.code === 'quoteExpired') {\n opts.onEvent?.({ kind: 'quoteExpired', payload: { setQuote } });\n } else if (payload.code === 'googlePayUnavailable') {\n opts.onEvent?.({ kind: 'unsupported' });\n } else {\n const kind =\n payload.code === 'generic'\n ? 'genericError'\n : (payload.code as 'configurationError' | 'invalidQuote' | 'genericError');\n opts.onEvent?.({\n kind: 'error',\n payload: { kind, message: payload.message },\n });\n }\n break;\n }\n }\n });\n\n return ok({\n setQuote,\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Google Pay setup failed',\n });\n }\n }\n\n // ------- setupChallenge -------\n async function setupChallenge(\n opts: SetupChallengeOptions,\n ): Promise<Result<ChallengeFrame, SetupChallengeError>> {\n let url: URL;\n try {\n url = new URL(opts.url);\n } catch {\n return err({ kind: 'configurationError', message: 'Invalid challenge URL' });\n }\n\n let channelId = url.searchParams.get('channelId') ?? '';\n if (!channelId) {\n channelId = `challenge-${Date.now()}`;\n url.searchParams.set('channelId', channelId);\n }\n\n try {\n const { promise } = createManagedFrame({\n url: url.toString(),\n channelId,\n hidden: false,\n });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'ready':\n opts.onEvent?.({ kind: 'ready' });\n break;\n case 'complete':\n opts.onEvent?.({\n kind: 'complete',\n payload: msg.payload as ChallengeCompleteResult,\n });\n break;\n case 'cancelled':\n opts.onEvent?.({\n kind: 'cancelled',\n payload: msg.payload as ChallengeCancellation,\n });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as { code: string; message: string },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Challenge setup failed',\n });\n }\n }\n\n // ------- setupAddCard -------\n async function setupAddCard(\n opts: SetupAddCardOptions,\n ): Promise<Result<AddCardFrame, SetupAddCardError>> {\n const channelId = `add-card-${Date.now()}`;\n\n const url = buildFrameUrl(\n FRAME_PATHS.addCard,\n { channelId, clientToken: core.context.clientToken },\n { frameBaseUrl },\n );\n\n try {\n const { promise } = createManagedFrame({ url, channelId, hidden: false });\n const { handle, slotId } = await promise;\n\n handle.onMessage((msg: ProtocolMessage) => {\n switch (msg.kind) {\n case 'complete':\n opts.onEvent?.({ kind: 'complete', payload: msg.payload as { card: CardResponse } });\n break;\n case 'error':\n opts.onEvent?.({\n kind: 'error',\n payload: msg.payload as {\n code: 'generic' | 'configurationError';\n message: string;\n },\n });\n break;\n }\n });\n\n return ok({\n dispose: () => {\n handle.dispose();\n removeSlot(slotId);\n },\n });\n } catch (e) {\n return err({\n kind: 'genericError',\n message: e instanceof Error ? e.message : 'Add card setup failed',\n });\n }\n }\n\n return {\n getConnection,\n connect,\n setupAuth,\n getPaymentMethods: () => core.getPaymentMethods(),\n getQuote: (params) => core.getQuote(params),\n listTransactions: (params) => core.listTransactions(params),\n getTransaction: (id) => core.getTransaction(id),\n setupWidget,\n setupApplePay,\n setupBuy,\n setupBuyButton,\n setupGooglePay,\n setupChallenge,\n setupAddCard,\n\n createIdentity: (body) => core.createIdentity(body),\n getIdentity: (id) => core.getIdentity(id),\n updateIdentity: (id, body) => core.updateIdentity(id, body),\n verifyIdentity: (id) => core.verifyIdentity(id),\n getIdentityUploadUrl: (id, body) => core.getIdentityUploadUrl(id, body),\n submitIdentityFiles: (id, body) => core.submitIdentityFiles(id, body),\n };\n }, [sessionToken, frameBaseUrl, core, addSlot, removeSlot]);\n\n return (\n <MoonPayContext.Provider value={{ client }}>\n {children}\n {frameSlots.map((slot) => (\n <MoonPayFrame key={slot.id} transport={slot.transport} hidden={slot.hidden} />\n ))}\n </MoonPayContext.Provider>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useMoonPay(): MoonPayContextValue {\n const ctx = useContext(MoonPayContext);\n if (!ctx) {\n throw new Error('useMoonPay must be used within a <MoonPayProvider>');\n }\n return ctx;\n}\n","import type { ProtocolMessage } from '@moonpay/platform-protocol';\nimport type { FrameOptions, FrameTransport } from '@moonpay/platform-sdk-core';\nimport type { RefObject } from 'react';\nimport type WebView from 'react-native-webview';\n\n/**\n * FrameTransport implementation for React Native using react-native-webview.\n *\n * Unlike the web IframeTransport, the WebView is rendered declaratively via\n * React components. This transport bridges the imperative FrameTransport\n * interface to a WebView ref.\n */\nexport class WebViewTransport implements FrameTransport {\n private webViewRef: RefObject<WebView | null> | null = null;\n private handlers: Array<(msg: ProtocolMessage) => void> = [];\n private _url: string = '';\n private _options: FrameOptions | null = null;\n\n /** Called by the frame component when it mounts the WebView. */\n attachWebView(ref: RefObject<WebView | null>): void {\n this.webViewRef = ref;\n }\n\n /** Called by the WebView's onMessage prop to route incoming messages. */\n handleWebViewMessage(data: string): void {\n try {\n const msg: ProtocolMessage = JSON.parse(data);\n if (!msg.kind) return;\n for (const handler of this.handlers) {\n handler(msg);\n }\n } catch {\n // Ignore non-protocol messages\n }\n }\n\n get url(): string {\n return this._url;\n }\n\n get options(): FrameOptions | null {\n return this._options;\n }\n\n // FrameTransport interface\n\n create(url: string, options: FrameOptions): void {\n this._url = url;\n this._options = options;\n // The actual WebView rendering is handled by React components.\n // This method stores the URL and options for the component to read.\n }\n\n sendMessage(message: ProtocolMessage): void {\n if (!this.webViewRef?.current) {\n throw new Error('Cannot send message: WebView not attached');\n }\n const js = `\n window.postMessage(${JSON.stringify(JSON.stringify(message))}, '*');\n true;\n `;\n this.webViewRef.current.injectJavaScript(js);\n }\n\n onMessage(handler: (msg: ProtocolMessage) => void): () => void {\n this.handlers.push(handler);\n return () => {\n const idx = this.handlers.indexOf(handler);\n if (idx >= 0) this.handlers.splice(idx, 1);\n };\n }\n\n dispose(): void {\n this.handlers.length = 0;\n this.webViewRef = null;\n this._url = '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ACxC,gBAAgB,CAAC,IAAI,SAAS,KAAK,eAAe,IAAI,IAAI;AAAA,MAC1D,gBAAgB,CAAC,OAAO,KAAK,eAAe,EAAE;AAAA,MAC9C,sBAAsB,CAAC,IAAI,SAAS,KAAK,qBAAqB,IAAI,IAAI;AAAA,MACtE,qBAAqB,CAAC,IAAI,SAAS,KAAK,oBAAoB,IAAI,IAAI;AAAA,IACtE;AAAA,EACF,GAAG,CAAC,cAAc,cAAc,MAAM,SAAS,UAAU,CAAC;AAE1D,SACE,qBAAC,eAAe,UAAf,EAAwB,OAAO,EAAE,OAAO,GACtC;AAAA;AAAA,IACA,WAAW,IAAI,CAAC,SACf,gBAAAD,KAAC,gBAA2B,WAAW,KAAK,WAAW,QAAQ,KAAK,UAAjD,KAAK,EAAoD,CAC7E;AAAA,KACH;AAEJ;AAMO,SAAS,aAAkC;AAChD,QAAM,MAAM,WAAW,cAAc;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;","names":["useRef","jsx","useRef"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moonpay/platform-sdk-react-native",
3
- "version": "0.2.2",
3
+ "version": "0.3.0-next.1",
4
4
  "description": "MoonPay Developer Platform SDK for React Native",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,8 +28,8 @@
28
28
  "clean": "rm -rf dist"
29
29
  },
30
30
  "dependencies": {
31
- "@moonpay/platform-protocol": "0.2.2",
32
- "@moonpay/platform-sdk-core": "0.2.2"
31
+ "@moonpay/platform-protocol": "0.3.0-next.1",
32
+ "@moonpay/platform-sdk-core": "0.3.0-next.1"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "18.2.0",