@vetc-miniapp/apis 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/apis/index.js +20 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vetc-miniapp/apis",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "MiniApp Platform JS SDK",
5
5
  "main": "src/apis/index.js",
6
6
  "type": "module",
package/src/apis/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  const isBrowser = typeof window !== "undefined";
2
2
 
3
+ const getBridge = () => {
4
+ if (!isBrowser || !window.flutter_inappwebview) {
5
+ return null;
6
+ }
7
+ return window.flutter_inappwebview;
8
+ };
9
+ const isBrowser = typeof window !== "undefined";
10
+
3
11
  const getBridge = () => {
4
12
  if (!isBrowser || !window.flutter_inappwebview) {
5
13
  return null;
@@ -7,12 +15,22 @@ const getBridge = () => {
7
15
  return window.flutter_inappwebview;
8
16
  };
9
17
 
10
- const callHost = (action, payload = {}) => {
18
+ export const callHost = async (action, payload = {}) => {
11
19
  const bridge = getBridge();
12
20
  if (!bridge) {
13
21
  return Promise.reject(new Error("MiniApp bridge not available"));
14
22
  }
15
- return bridge.callHandler("MiniAppBridge", { action, payload });
23
+ try {
24
+ const response = await bridge.callHandler("MiniAppBridge", {
25
+ action,
26
+ payload,
27
+ });
28
+
29
+ return response;
30
+ } catch (error) {
31
+ console.error("Bridge error:", error);
32
+ throw error;
33
+ }
16
34
  };
17
35
 
18
36
  export const MiniApp = {