@moon-x/react-native-sdk 0.28.0 → 0.28.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.d.mts CHANGED
@@ -84,6 +84,7 @@ declare class WebViewBridge {
84
84
  private sendOnce;
85
85
  sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
86
86
  rejectAllPending(reason: string): void;
87
+ retryPendingReads(): void;
87
88
  private rejectPending;
88
89
  cleanup(reason?: string): void;
89
90
  }
package/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ declare class WebViewBridge {
84
84
  private sendOnce;
85
85
  sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
86
86
  rejectAllPending(reason: string): void;
87
+ retryPendingReads(): void;
87
88
  private rejectPending;
88
89
  cleanup(reason?: string): void;
89
90
  }
package/dist/index.js CHANGED
@@ -1488,6 +1488,11 @@ var RETRY_ATTEMPT_TIMEOUTS_MS = [
1488
1488
  import_utils4.POST_MESSAGE_REQUEST_TIMEOUT_MS
1489
1489
  ];
1490
1490
  var RETRY_BACKOFF_MS = [200, 400];
1491
+ var isRetryableRead = (method, payload) => {
1492
+ const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1493
+ const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1494
+ return RETRYABLE_METHODS.has(method) && !isSigningPreparation && !isResumeCheck;
1495
+ };
1491
1496
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1492
1497
  var TimeoutError = class extends Error {
1493
1498
  constructor(message) {
@@ -1623,9 +1628,7 @@ var WebViewBridge = class {
1623
1628
  // Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
1624
1629
  // ride out the iframe-app mount race; everything else makes a single attempt.
1625
1630
  async send(type, method, payload) {
1626
- const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1627
- const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1628
- if (isSigningPreparation || isResumeCheck || !RETRYABLE_METHODS.has(method)) {
1631
+ if (!isRetryableRead(method, payload)) {
1629
1632
  return this.sendOnce(
1630
1633
  type,
1631
1634
  method,
@@ -1640,7 +1643,8 @@ var WebViewBridge = class {
1640
1643
  type,
1641
1644
  method,
1642
1645
  payload,
1643
- RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
1646
+ RETRY_ATTEMPT_TIMEOUTS_MS[attempt],
1647
+ attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length - 1
1644
1648
  );
1645
1649
  } catch (error) {
1646
1650
  lastError = error;
@@ -1651,7 +1655,7 @@ var WebViewBridge = class {
1651
1655
  }
1652
1656
  throw lastError;
1653
1657
  }
1654
- sendOnce(type, method, payload, timeoutMs) {
1658
+ sendOnce(type, method, payload, timeoutMs, retryOnReady = false) {
1655
1659
  const ref = this.webViewRef.current;
1656
1660
  if (!ref) {
1657
1661
  return Promise.reject(new Error("webview_not_ready"));
@@ -1671,7 +1675,8 @@ var WebViewBridge = class {
1671
1675
  reject,
1672
1676
  timeoutId,
1673
1677
  type,
1674
- method
1678
+ method,
1679
+ retryOnReady
1675
1680
  });
1676
1681
  const envelope = { id, type, method, payload };
1677
1682
  try {
@@ -1712,8 +1717,15 @@ var WebViewBridge = class {
1712
1717
  rejectAllPending(reason) {
1713
1718
  this.rejectPending(() => new TimeoutError(reason));
1714
1719
  }
1715
- rejectPending(createError) {
1720
+ retryPendingReads() {
1721
+ this.rejectPending(
1722
+ () => new TimeoutError("webview_ready"),
1723
+ (resolver) => resolver.retryOnReady
1724
+ );
1725
+ }
1726
+ rejectPending(createError, shouldReject = () => true) {
1716
1727
  for (const [id, resolver] of this.pending.entries()) {
1728
+ if (!shouldReject(resolver)) continue;
1717
1729
  clearTimeout(resolver.timeoutId);
1718
1730
  resolver.reject(createError());
1719
1731
  this.pending.delete(id);
@@ -2487,15 +2499,22 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2487
2499
  }, [bridge, session]);
2488
2500
  (0, import_react3.useEffect)(() => {
2489
2501
  let cancelled = false;
2502
+ let readinessSource = "pending";
2490
2503
  const unregister = bridge.register(
2491
2504
  import_utils6.PostMessageType.INIT,
2492
2505
  import_utils6.PostMessageMethod.READY,
2493
2506
  () => {
2494
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2507
+ if (cancelled || readinessSource === "page") return;
2508
+ const retryPendingReads = readinessSource === "fallback";
2509
+ readinessSource = "page";
2510
+ dispatchWebViewLifecycle({ type: "ready" });
2511
+ if (retryPendingReads) bridge.retryPendingReads();
2495
2512
  }
2496
2513
  );
2497
2514
  const fallback = setTimeout(() => {
2498
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2515
+ if (cancelled || readinessSource !== "pending") return;
2516
+ readinessSource = "fallback";
2517
+ dispatchWebViewLifecycle({ type: "ready" });
2499
2518
  }, 2e3);
2500
2519
  return () => {
2501
2520
  cancelled = true;
package/dist/index.mjs CHANGED
@@ -1483,6 +1483,11 @@ var RETRY_ATTEMPT_TIMEOUTS_MS = [
1483
1483
  POST_MESSAGE_REQUEST_TIMEOUT_MS
1484
1484
  ];
1485
1485
  var RETRY_BACKOFF_MS = [200, 400];
1486
+ var isRetryableRead = (method, payload) => {
1487
+ const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1488
+ const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1489
+ return RETRYABLE_METHODS.has(method) && !isSigningPreparation && !isResumeCheck;
1490
+ };
1486
1491
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1487
1492
  var TimeoutError = class extends Error {
1488
1493
  constructor(message) {
@@ -1618,9 +1623,7 @@ var WebViewBridge = class {
1618
1623
  // Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
1619
1624
  // ride out the iframe-app mount race; everything else makes a single attempt.
1620
1625
  async send(type, method, payload) {
1621
- const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1622
- const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1623
- if (isSigningPreparation || isResumeCheck || !RETRYABLE_METHODS.has(method)) {
1626
+ if (!isRetryableRead(method, payload)) {
1624
1627
  return this.sendOnce(
1625
1628
  type,
1626
1629
  method,
@@ -1635,7 +1638,8 @@ var WebViewBridge = class {
1635
1638
  type,
1636
1639
  method,
1637
1640
  payload,
1638
- RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
1641
+ RETRY_ATTEMPT_TIMEOUTS_MS[attempt],
1642
+ attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length - 1
1639
1643
  );
1640
1644
  } catch (error) {
1641
1645
  lastError = error;
@@ -1646,7 +1650,7 @@ var WebViewBridge = class {
1646
1650
  }
1647
1651
  throw lastError;
1648
1652
  }
1649
- sendOnce(type, method, payload, timeoutMs) {
1653
+ sendOnce(type, method, payload, timeoutMs, retryOnReady = false) {
1650
1654
  const ref = this.webViewRef.current;
1651
1655
  if (!ref) {
1652
1656
  return Promise.reject(new Error("webview_not_ready"));
@@ -1666,7 +1670,8 @@ var WebViewBridge = class {
1666
1670
  reject,
1667
1671
  timeoutId,
1668
1672
  type,
1669
- method
1673
+ method,
1674
+ retryOnReady
1670
1675
  });
1671
1676
  const envelope = { id, type, method, payload };
1672
1677
  try {
@@ -1707,8 +1712,15 @@ var WebViewBridge = class {
1707
1712
  rejectAllPending(reason) {
1708
1713
  this.rejectPending(() => new TimeoutError(reason));
1709
1714
  }
1710
- rejectPending(createError) {
1715
+ retryPendingReads() {
1716
+ this.rejectPending(
1717
+ () => new TimeoutError("webview_ready"),
1718
+ (resolver) => resolver.retryOnReady
1719
+ );
1720
+ }
1721
+ rejectPending(createError, shouldReject = () => true) {
1711
1722
  for (const [id, resolver] of this.pending.entries()) {
1723
+ if (!shouldReject(resolver)) continue;
1712
1724
  clearTimeout(resolver.timeoutId);
1713
1725
  resolver.reject(createError());
1714
1726
  this.pending.delete(id);
@@ -2488,15 +2500,22 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2488
2500
  }, [bridge, session]);
2489
2501
  useEffect3(() => {
2490
2502
  let cancelled = false;
2503
+ let readinessSource = "pending";
2491
2504
  const unregister = bridge.register(
2492
2505
  PostMessageType4.INIT,
2493
2506
  PostMessageMethod4.READY,
2494
2507
  () => {
2495
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2508
+ if (cancelled || readinessSource === "page") return;
2509
+ const retryPendingReads = readinessSource === "fallback";
2510
+ readinessSource = "page";
2511
+ dispatchWebViewLifecycle({ type: "ready" });
2512
+ if (retryPendingReads) bridge.retryPendingReads();
2496
2513
  }
2497
2514
  );
2498
2515
  const fallback = setTimeout(() => {
2499
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2516
+ if (cancelled || readinessSource !== "pending") return;
2517
+ readinessSource = "fallback";
2518
+ dispatchWebViewLifecycle({ type: "ready" });
2500
2519
  }, 2e3);
2501
2520
  return () => {
2502
2521
  cancelled = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moon-x/react-native-sdk",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "Headless MoonX React Native SDK with WebView-backed transport, native passkeys, and app-owned UI.",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -63,7 +63,7 @@
63
63
  "vitest": "4.1.0"
64
64
  },
65
65
  "dependencies": {
66
- "@moon-x/core": "0.37.0"
66
+ "@moon-x/core": "0.39.0"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@expo/config-plugins": ">=10.0.0",