@vetc-miniapp/apis 0.0.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/README.md +25 -0
- package/package.json +32 -0
- package/src/apis/common/index.d.ts +9 -0
- package/src/apis/common/index.js +0 -0
- package/src/apis/index.d.ts +107 -0
- package/src/apis/index.js +75 -0
- package/src/dist/apis/index.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# MiniApp JS SDK
|
|
2
|
+
|
|
3
|
+
SDK giúp Mini App giao tiếp với Super App host thông qua JS Bridge.
|
|
4
|
+
|
|
5
|
+
## Cài đặt
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @yourcompany/miniapp-sdk
|
|
9
|
+
```
|
|
10
|
+
## Sử dụng
|
|
11
|
+
|
|
12
|
+
import MiniApp from "@vetc/miniapp-sdk";
|
|
13
|
+
|
|
14
|
+
MiniApp.getScopedToken().then(console.log);
|
|
15
|
+
|
|
16
|
+
MiniApp.pickImage({ source: "camera" }).then(console.log);
|
|
17
|
+
|
|
18
|
+
MiniApp.on("TOKEN_REFRESH", data => {
|
|
19
|
+
console.log("Token updated:", data);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
npm run build
|
|
23
|
+
npm publish --access public
|
|
24
|
+
|
|
25
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vetc-miniapp/apis",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "MiniApp Platform JS SDK",
|
|
5
|
+
"main": "src/apis/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "src/apis/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "webpack"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"miniapp",
|
|
16
|
+
"superapp",
|
|
17
|
+
"bridge",
|
|
18
|
+
"sdk"
|
|
19
|
+
],
|
|
20
|
+
"author": "Hieuth052@gmail.com",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/core": "^7.29.0",
|
|
24
|
+
"@babel/preset-env": "^7.29.0",
|
|
25
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
26
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
27
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
28
|
+
"babel-loader": "^10.0.0",
|
|
29
|
+
"rollup": "^4.57.1",
|
|
30
|
+
"webpack-cli": "^6.0.1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IVETCMiniAppResponse<T = any> {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
data?: T;
|
|
4
|
+
error?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
export type IVETCPlatform = 'ios' | 'android' | 'macos' | 'windows' | 'web' | 'native' | ({} & string);
|
|
8
|
+
export type IVETCSystem = 'Android' | 'iOS' | 'iPhone OS' | 'iPadOS' | ({} & string);
|
|
9
|
+
export type IVETCLocale = 'en' | 'vi' | ({} & string);
|
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export interface IVETCMiniAppResponse<T = any> {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
data?: T;
|
|
4
|
+
error?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/* ================= Permissions ================= */
|
|
9
|
+
|
|
10
|
+
export type MiniAppPermission =
|
|
11
|
+
| "location"
|
|
12
|
+
| "camera"
|
|
13
|
+
| "microphone"
|
|
14
|
+
| "photos"
|
|
15
|
+
| "contacts"
|
|
16
|
+
| "bluetooth"
|
|
17
|
+
| "nfc";
|
|
18
|
+
|
|
19
|
+
/* ================= Core Payloads ================= */
|
|
20
|
+
|
|
21
|
+
export interface NavigateParams {
|
|
22
|
+
title?: string;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ================= Main SDK ================= */
|
|
28
|
+
|
|
29
|
+
export interface MiniAppSDK {
|
|
30
|
+
confirmBeforeExit(
|
|
31
|
+
title?: string,
|
|
32
|
+
message?: string,
|
|
33
|
+
success?: Function,
|
|
34
|
+
fail?: Function,
|
|
35
|
+
complete?: Function
|
|
36
|
+
): Promise<IVETCMiniAppResponse>;
|
|
37
|
+
|
|
38
|
+
exitMiniApp(
|
|
39
|
+
success?: Function,
|
|
40
|
+
fail?: Function,
|
|
41
|
+
complete?: Function
|
|
42
|
+
): Promise<IVETCMiniAppResponse>;
|
|
43
|
+
|
|
44
|
+
openAppSetting(
|
|
45
|
+
success?: Function,
|
|
46
|
+
fail?: Function,
|
|
47
|
+
complete?: Function
|
|
48
|
+
): Promise<IVETCMiniAppResponse>;
|
|
49
|
+
|
|
50
|
+
openNativeAppStore(
|
|
51
|
+
appleStoreId?: string,
|
|
52
|
+
googlePlayId?: string,
|
|
53
|
+
success?: Function,
|
|
54
|
+
fail?: Function,
|
|
55
|
+
complete?: Function
|
|
56
|
+
): Promise<IVETCMiniAppResponse>;
|
|
57
|
+
|
|
58
|
+
shareApp(
|
|
59
|
+
title?: string,
|
|
60
|
+
description?: string,
|
|
61
|
+
path?: string,
|
|
62
|
+
url?: string,
|
|
63
|
+
success?: Function,
|
|
64
|
+
fail?: Function,
|
|
65
|
+
complete?: Function
|
|
66
|
+
): Promise<IVETCMiniAppResponse>;
|
|
67
|
+
|
|
68
|
+
getAuthCode(
|
|
69
|
+
scopes?: string[],
|
|
70
|
+
success?: Function,
|
|
71
|
+
fail?: Function,
|
|
72
|
+
complete?: Function
|
|
73
|
+
): Promise<IVETCMiniAppResponse<{ code: string }>>;
|
|
74
|
+
|
|
75
|
+
getUserInfo(
|
|
76
|
+
success?: Function,
|
|
77
|
+
fail?: Function,
|
|
78
|
+
complete?: Function
|
|
79
|
+
): Promise<IVETCMiniAppResponse<Record<string, any>>>;
|
|
80
|
+
|
|
81
|
+
navigate(
|
|
82
|
+
screen: string,
|
|
83
|
+
params?: NavigateParams
|
|
84
|
+
): Promise<IVETCMiniAppResponse>;
|
|
85
|
+
|
|
86
|
+
close(result?: any): Promise<IVETCMiniAppResponse>;
|
|
87
|
+
|
|
88
|
+
requestPermission(
|
|
89
|
+
permission: MiniAppPermission,
|
|
90
|
+
reason?: string
|
|
91
|
+
): Promise<IVETCMiniAppResponse>;
|
|
92
|
+
|
|
93
|
+
requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
94
|
+
requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
95
|
+
requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
96
|
+
requestPhotos(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
97
|
+
requestContacts(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
98
|
+
requestBluetooth(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
99
|
+
requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
100
|
+
|
|
101
|
+
on(event: string, callback: (data: any) => void): void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Default export */
|
|
105
|
+
declare const MiniApp: MiniAppSDK;
|
|
106
|
+
export default MiniApp;
|
|
107
|
+
export { MiniApp };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const isBrowser = typeof window !== "undefined";
|
|
2
|
+
|
|
3
|
+
const getBridge = () => {
|
|
4
|
+
if (!isBrowser || !window.flutter_inappwebview) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return window.flutter_inappwebview;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const callHost = (action, payload = {}) => {
|
|
11
|
+
const bridge = getBridge();
|
|
12
|
+
if (!bridge) {
|
|
13
|
+
return Promise.reject(new Error("MiniApp bridge not available"));
|
|
14
|
+
}
|
|
15
|
+
return bridge.callHandler("MiniAppBridge", { action, payload });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const MiniApp = {
|
|
19
|
+
confirmBeforeExit(title, message, success, fail, complete) {
|
|
20
|
+
return callHost("confirmBeforeExit", { title, message, success, fail, complete });
|
|
21
|
+
},
|
|
22
|
+
exitMiniApp(success, fail, complete) {
|
|
23
|
+
return callHost("exitMiniApp", { success, fail, complete });
|
|
24
|
+
},
|
|
25
|
+
openAppSetting(success, fail, complete) {
|
|
26
|
+
return callHost("openAppSetting", { success, fail, complete });
|
|
27
|
+
},
|
|
28
|
+
openNativeAppStore(appleStoreId, googlePlayId, success, fail, complete) {
|
|
29
|
+
return callHost("openNativeAppStore", { appleStoreId, googlePlayId, success, fail, complete });
|
|
30
|
+
},
|
|
31
|
+
shareApp(title, description, path, url, success, fail, complete) {
|
|
32
|
+
return callHost("shareApp", { title, description, path, url, success, fail, complete });
|
|
33
|
+
},
|
|
34
|
+
getAuthCode(scopes, success, fail, complete) {
|
|
35
|
+
return callHost("getAuthCode", { scopes, success, fail, complete });
|
|
36
|
+
},
|
|
37
|
+
getUserInfo(success, fail, complete) {
|
|
38
|
+
return callHost("getUserInfo", { success, fail, complete });
|
|
39
|
+
},
|
|
40
|
+
navigate(screen, params = {}) {
|
|
41
|
+
return callHost("navigate", { type: "native", screen, params });
|
|
42
|
+
},
|
|
43
|
+
close(result = {}) {
|
|
44
|
+
return callHost("close", { result });
|
|
45
|
+
},
|
|
46
|
+
requestPermission(permission, reason) {
|
|
47
|
+
return callHost("requestPermission", { permission, reason });
|
|
48
|
+
},
|
|
49
|
+
requestLocation(reason) { return MiniApp.requestPermission("location", reason); },
|
|
50
|
+
requestCamera(reason) { return MiniApp.requestPermission("camera", reason); },
|
|
51
|
+
requestMicrophone(reason) { return MiniApp.requestPermission("microphone", reason); },
|
|
52
|
+
requestPhotos(reason) { return MiniApp.requestPermission("photos", reason); },
|
|
53
|
+
requestContacts(reason) { return MiniApp.requestPermission("contacts", reason); },
|
|
54
|
+
requestBluetooth(reason) { return MiniApp.requestPermission("bluetooth", reason); },
|
|
55
|
+
requestNFC(reason) { return MiniApp.requestPermission("nfc", reason); },
|
|
56
|
+
|
|
57
|
+
_listeners: {},
|
|
58
|
+
on(event, callback) {
|
|
59
|
+
if (!MiniApp._listeners[event]) MiniApp._listeners[event] = [];
|
|
60
|
+
MiniApp._listeners[event].push(callback);
|
|
61
|
+
},
|
|
62
|
+
_emit(event, data) {
|
|
63
|
+
(MiniApp._listeners[event] || []).forEach((cb) => cb(data));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Gắn listener CHỈ khi có window
|
|
68
|
+
if (isBrowser) {
|
|
69
|
+
window.addEventListener("miniapp_event", (e) => {
|
|
70
|
+
const { type, data } = e.detail || {};
|
|
71
|
+
MiniApp._emit(type, data);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default MiniApp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MiniApp=t():e.MiniApp=t()}(this,()=>(()=>{"use strict";var e={d:(t,o)=>{for(var s in o)e.o(o,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:o[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{MiniApp:()=>i,default:()=>r});const o="undefined"!=typeof window,s=(e,t={})=>{const s=o&&window.flutter_inappwebview?window.flutter_inappwebview:null;return s?s.callHandler("MiniAppBridge",{action:e,payload:t}):Promise.reject(new Error("MiniApp bridge not available"))},i={confirmBeforeExit:(e,t,o,i,r)=>s("confirmBeforeExit",{title:e,message:t,success:o,fail:i,complete:r}),exitMiniApp:(e,t,o)=>s("exitMiniApp",{success:e,fail:t,complete:o}),openAppSetting:(e,t,o)=>s("openAppSetting",{success:e,fail:t,complete:o}),openNativeAppStore:(e,t,o,i,r)=>s("openNativeAppStore",{appleStoreId:e,googlePlayId:t,success:o,fail:i,complete:r}),shareApp:(e,t,o,i,r,n,p)=>s("shareApp",{title:e,description:t,path:o,url:i,success:r,fail:n,complete:p}),getAuthCode:(e,t,o,i)=>s("getAuthCode",{scopes:e,success:t,fail:o,complete:i}),getUserInfo:(e,t,o)=>s("getUserInfo",{success:e,fail:t,complete:o}),navigate:(e,t={})=>s("navigate",{type:"native",screen:e,params:t}),close:(e={})=>s("close",{result:e}),requestPermission:(e,t)=>s("requestPermission",{permission:e,reason:t}),requestLocation:e=>i.requestPermission("location",e),requestCamera:e=>i.requestPermission("camera",e),requestMicrophone:e=>i.requestPermission("microphone",e),requestPhotos:e=>i.requestPermission("photos",e),requestContacts:e=>i.requestPermission("contacts",e),requestBluetooth:e=>i.requestPermission("bluetooth",e),requestNFC:e=>i.requestPermission("nfc",e),_listeners:{},on(e,t){i._listeners[e]||(i._listeners[e]=[]),i._listeners[e].push(t)},_emit(e,t){(i._listeners[e]||[]).forEach(e=>e(t))}};o&&window.addEventListener("miniapp_event",e=>{const{type:t,data:o}=e.detail||{};i._emit(t,o)});const r=i;return t})());
|