@moon-x/react-native-sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -3
- package/dist/index.mjs +58 -3
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,7 @@ declare class WebViewBridge {
|
|
|
27
27
|
register<Payload>(type: PostMessageType, method: PostMessageMethod | string, handler: IncomingMessageHandler<Payload>): () => void;
|
|
28
28
|
isReady(): boolean;
|
|
29
29
|
send<Payload, Response>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): Promise<Response>;
|
|
30
|
+
private sendOnce;
|
|
30
31
|
sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
|
|
31
32
|
cleanup(reason?: string): void;
|
|
32
33
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ declare class WebViewBridge {
|
|
|
27
27
|
register<Payload>(type: PostMessageType, method: PostMessageMethod | string, handler: IncomingMessageHandler<Payload>): () => void;
|
|
28
28
|
isReady(): boolean;
|
|
29
29
|
send<Payload, Response>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): Promise<Response>;
|
|
30
|
+
private sendOnce;
|
|
30
31
|
sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
|
|
31
32
|
cleanup(reason?: string): void;
|
|
32
33
|
}
|
package/dist/index.js
CHANGED
|
@@ -361,6 +361,28 @@ var import_utils4 = require("@moon-x/core/utils");
|
|
|
361
361
|
// src/transport/webview-bridge.ts
|
|
362
362
|
var import_utils3 = require("@moon-x/core/utils");
|
|
363
363
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
364
|
+
var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
|
|
365
|
+
"GET_APP_CONFIG",
|
|
366
|
+
"GET_BALANCE",
|
|
367
|
+
"GET_CURRENT_SESSION",
|
|
368
|
+
"GET_TOKEN_ACCOUNTS_BY_OWNER",
|
|
369
|
+
"GET_USER",
|
|
370
|
+
"GET_WALLET",
|
|
371
|
+
"GET_WALLETS",
|
|
372
|
+
"IS_AUTHENTICATED",
|
|
373
|
+
"GET_PASSKEY_STATUS",
|
|
374
|
+
"GET_DEK_INFO",
|
|
375
|
+
"LIST_EPHEMERAL_SIGNERS"
|
|
376
|
+
]);
|
|
377
|
+
var RETRY_ATTEMPT_TIMEOUTS_MS = [5e3, 1e4, REQUEST_TIMEOUT_MS];
|
|
378
|
+
var RETRY_BACKOFF_MS = [200, 400];
|
|
379
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
380
|
+
var TimeoutError = class extends Error {
|
|
381
|
+
constructor(message) {
|
|
382
|
+
super(message);
|
|
383
|
+
this.name = "TimeoutError";
|
|
384
|
+
}
|
|
385
|
+
};
|
|
364
386
|
var generateUUID = () => {
|
|
365
387
|
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
366
388
|
return crypto.randomUUID();
|
|
@@ -470,7 +492,36 @@ var WebViewBridge = class {
|
|
|
470
492
|
return !!this.webViewRef.current;
|
|
471
493
|
}
|
|
472
494
|
// Request/response. Same envelope as @moon-x/core PostMessageClient.
|
|
473
|
-
|
|
495
|
+
// Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
|
|
496
|
+
// ride out the iframe-app mount race; everything else makes a single attempt.
|
|
497
|
+
async send(type, method, payload) {
|
|
498
|
+
if (!RETRYABLE_METHODS.has(method)) {
|
|
499
|
+
return this.sendOnce(
|
|
500
|
+
type,
|
|
501
|
+
method,
|
|
502
|
+
payload,
|
|
503
|
+
REQUEST_TIMEOUT_MS
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
let lastError;
|
|
507
|
+
for (let attempt = 0; attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length; attempt++) {
|
|
508
|
+
try {
|
|
509
|
+
return await this.sendOnce(
|
|
510
|
+
type,
|
|
511
|
+
method,
|
|
512
|
+
payload,
|
|
513
|
+
RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
|
|
514
|
+
);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
lastError = error;
|
|
517
|
+
if (!(error instanceof TimeoutError)) throw error;
|
|
518
|
+
const backoff = RETRY_BACKOFF_MS[attempt];
|
|
519
|
+
if (backoff !== void 0) await sleep(backoff);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
throw lastError;
|
|
523
|
+
}
|
|
524
|
+
sendOnce(type, method, payload, timeoutMs) {
|
|
474
525
|
const ref = this.webViewRef.current;
|
|
475
526
|
if (!ref) {
|
|
476
527
|
return Promise.reject(new Error("webview_not_ready"));
|
|
@@ -479,8 +530,12 @@ var WebViewBridge = class {
|
|
|
479
530
|
return new Promise((resolve, reject) => {
|
|
480
531
|
const timeoutId = setTimeout(() => {
|
|
481
532
|
this.pending.delete(id);
|
|
482
|
-
reject(
|
|
483
|
-
|
|
533
|
+
reject(
|
|
534
|
+
new TimeoutError(
|
|
535
|
+
`Timeout: no response from WebView for ${type}:${method} after ${timeoutMs}ms`
|
|
536
|
+
)
|
|
537
|
+
);
|
|
538
|
+
}, timeoutMs);
|
|
484
539
|
this.pending.set(id, {
|
|
485
540
|
resolve,
|
|
486
541
|
reject,
|
package/dist/index.mjs
CHANGED
|
@@ -335,6 +335,28 @@ import {
|
|
|
335
335
|
FORWARDED_ERROR_FIELDS
|
|
336
336
|
} from "@moon-x/core/utils";
|
|
337
337
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
338
|
+
var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
|
|
339
|
+
"GET_APP_CONFIG",
|
|
340
|
+
"GET_BALANCE",
|
|
341
|
+
"GET_CURRENT_SESSION",
|
|
342
|
+
"GET_TOKEN_ACCOUNTS_BY_OWNER",
|
|
343
|
+
"GET_USER",
|
|
344
|
+
"GET_WALLET",
|
|
345
|
+
"GET_WALLETS",
|
|
346
|
+
"IS_AUTHENTICATED",
|
|
347
|
+
"GET_PASSKEY_STATUS",
|
|
348
|
+
"GET_DEK_INFO",
|
|
349
|
+
"LIST_EPHEMERAL_SIGNERS"
|
|
350
|
+
]);
|
|
351
|
+
var RETRY_ATTEMPT_TIMEOUTS_MS = [5e3, 1e4, REQUEST_TIMEOUT_MS];
|
|
352
|
+
var RETRY_BACKOFF_MS = [200, 400];
|
|
353
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
354
|
+
var TimeoutError = class extends Error {
|
|
355
|
+
constructor(message) {
|
|
356
|
+
super(message);
|
|
357
|
+
this.name = "TimeoutError";
|
|
358
|
+
}
|
|
359
|
+
};
|
|
338
360
|
var generateUUID = () => {
|
|
339
361
|
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
340
362
|
return crypto.randomUUID();
|
|
@@ -444,7 +466,36 @@ var WebViewBridge = class {
|
|
|
444
466
|
return !!this.webViewRef.current;
|
|
445
467
|
}
|
|
446
468
|
// Request/response. Same envelope as @moon-x/core PostMessageClient.
|
|
447
|
-
|
|
469
|
+
// Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
|
|
470
|
+
// ride out the iframe-app mount race; everything else makes a single attempt.
|
|
471
|
+
async send(type, method, payload) {
|
|
472
|
+
if (!RETRYABLE_METHODS.has(method)) {
|
|
473
|
+
return this.sendOnce(
|
|
474
|
+
type,
|
|
475
|
+
method,
|
|
476
|
+
payload,
|
|
477
|
+
REQUEST_TIMEOUT_MS
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
let lastError;
|
|
481
|
+
for (let attempt = 0; attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length; attempt++) {
|
|
482
|
+
try {
|
|
483
|
+
return await this.sendOnce(
|
|
484
|
+
type,
|
|
485
|
+
method,
|
|
486
|
+
payload,
|
|
487
|
+
RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
|
|
488
|
+
);
|
|
489
|
+
} catch (error) {
|
|
490
|
+
lastError = error;
|
|
491
|
+
if (!(error instanceof TimeoutError)) throw error;
|
|
492
|
+
const backoff = RETRY_BACKOFF_MS[attempt];
|
|
493
|
+
if (backoff !== void 0) await sleep(backoff);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
throw lastError;
|
|
497
|
+
}
|
|
498
|
+
sendOnce(type, method, payload, timeoutMs) {
|
|
448
499
|
const ref = this.webViewRef.current;
|
|
449
500
|
if (!ref) {
|
|
450
501
|
return Promise.reject(new Error("webview_not_ready"));
|
|
@@ -453,8 +504,12 @@ var WebViewBridge = class {
|
|
|
453
504
|
return new Promise((resolve, reject) => {
|
|
454
505
|
const timeoutId = setTimeout(() => {
|
|
455
506
|
this.pending.delete(id);
|
|
456
|
-
reject(
|
|
457
|
-
|
|
507
|
+
reject(
|
|
508
|
+
new TimeoutError(
|
|
509
|
+
`Timeout: no response from WebView for ${type}:${method} after ${timeoutMs}ms`
|
|
510
|
+
)
|
|
511
|
+
);
|
|
512
|
+
}, timeoutMs);
|
|
458
513
|
this.pending.set(id, {
|
|
459
514
|
resolve,
|
|
460
515
|
reject,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moon-x/react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "MoonX React Native SDK — WebView-backed transport, react-native-passkeys, AsyncStorage. Mobile parity with @moon-x/react-sdk + @moon-x/core-sdk.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript": "5.9.3"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@moon-x/core": "0.
|
|
52
|
+
"@moon-x/core": "0.11.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@expo/config-plugins": ">=10.0.0",
|