@vetc-miniapp/apis 0.0.24 → 0.0.25

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 ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e="undefined"!=typeof window,t=async(t,r={})=>{const a=e&&window.flutter_inappwebview&&"function"==typeof window.flutter_inappwebview.callHandler?window.flutter_inappwebview:null;if(!a)return{ok:!1,error:"BRIDGE_CALL_FAILED"};try{const e=await a.callHandler("MiniAppBridge",{action:t,payload:r});return console.log("Bridge response:",e),e}catch(e){return console.error("Bridge error:",e),{ok:!1,error:"BRIDGE_CALL_FAILED"}}},r={confirmBeforeExit:(e,r)=>t("confirmBeforeExit",{title:e,message:r}),exitMiniApp:()=>t("exitMiniApp",{}),openAppSetting:()=>t("openAppSetting",{}),openNativeAppStore:(e,r)=>t("openNativeAppStore",{appleStoreId:e,googlePlayId:r}),shareApp:(e,r,a,i)=>t("shareApp",{title:e,description:r,path:a,url:i}),getAuthCode:e=>t("getAuthCode",{scopes:e}),getUserInfo:()=>t("getUserInfo",{}),scanQr:(e=[])=>t("scanQr",{patterns:e}),closeScanQr:()=>t("closeScanQr",{}),pushEvent:(e,r={})=>t("pushEvent",{eventName:e,properties:r}),navigate:(e,r={})=>t("navigate",{type:"native",screen:e,params:r}),close:(e={})=>t("close",{result:e}),openTel:e=>t("openTel",{phone:e}),chooseImage:({count:e,includeBase64:r,sourceType:a}={})=>t("chooseImage",{count:e,includeBase64:r,sourceType:a}),getBase64ByPath:({path:e})=>t("getBase64ByPath",{path:e}),addWatermarkImage:({originalPath:e,watermarkUrl:r,opacity:a,fileName:i,watermarkWidth:o,watermarkHeight:n,positionWatermarkX:s,positionWatermarkY:p,scale:l})=>t("addWatermarkImage",{originalPath:e,watermarkUrl:r,opacity:a,fileName:i,watermarkWidth:o,watermarkHeight:n,positionWatermarkX:s,positionWatermarkY:p,scale:l}),compressImage:({path:e,quality:r,minWidth:a,minHeight:i})=>t("compressImage",{path:e,quality:r,minWidth:a,minHeight:i}),getImageInfo:({path:e})=>t("getImageInfo",{path:e}),uploadFile:({path:e,url:r,headers:a,extraData:i,fieldName:o,method:n})=>t("uploadFile",{path:e,url:r,headers:a,extraData:i,fieldName:o,method:n}),uploadFileMinio:({path:e,url:r,headers:a,extraData:i,fieldName:o,method:n})=>t("uploadFileMinio",{path:e,url:r,headers:a,extraData:i,fieldName:o,method:n}),initPayment:({merchantOrderId:e,merchantService:r,amount:a,productName:i,midName:o,mid:n,tid:s,orderDesc:p,requestDate:l,serviceType:m,signature:c,extraData:u,onResult:d,ipnUrl:h,callbackUrl:g})=>t("initPayment",{merchantOrderId:e,merchantService:r,amount:a,productName:i,midName:o,mid:n,tid:s,orderDesc:p,requestDate:l,serviceType:m,signature:c,extraData:u,onResult:d,ipnUrl:h,callbackUrl:g}),getCurrentLocation:()=>t("getCurrentLocation",{}),requestPermission:(e,r)=>t("requestPermission",{permission:e,reason:r}),requestLocation:e=>r.requestPermission("location",e),requestCamera:e=>r.requestPermission("camera",e),requestMicrophone:e=>r.requestPermission("microphone",e),requestPhotos:e=>r.requestPermission("photos",e),requestContacts:e=>r.requestPermission("contacts",e),requestBluetooth:e=>r.requestPermission("bluetooth",e),requestNFC:e=>r.requestPermission("nfc",e),_listeners:{},on(e,t){r._listeners[e]||(r._listeners[e]=[]),r._listeners[e].push(t)},_emit(e,t){(r._listeners[e]||[]).forEach(e=>e(t))}};e&&window.addEventListener("miniapp_event",e=>{const{type:t,data:a}=e.detail||{};r._emit(t,a)}),exports.MiniApp=r,exports.callHost=t,exports.default=r;
@@ -0,0 +1,128 @@
1
+ export interface IVETCMiniAppResponse<T = any> {
2
+ ok: boolean;
3
+ data?: T;
4
+ error?: string;
5
+ message?: string;
6
+ }
7
+ export type MiniAppPermission = 'location' | 'camera' | 'microphone' | 'photos' | 'contacts' | 'bluetooth' | 'nfc';
8
+ export interface NavigateParams {
9
+ title?: string;
10
+ [key: string]: any;
11
+ }
12
+ export interface ChooseImageFile {
13
+ path: string;
14
+ mimeType: string;
15
+ base64?: string;
16
+ }
17
+ export interface ChooseImageOptions {
18
+ count?: number;
19
+ includeBase64?: boolean;
20
+ sourceType?: ('camera' | 'album')[];
21
+ }
22
+ export interface CompressImageOptions {
23
+ path: string;
24
+ quality: number;
25
+ minWidth?: number;
26
+ minHeight?: number;
27
+ }
28
+ export interface GetImageInfoOptions {
29
+ path: string;
30
+ }
31
+ export interface AddWatermarkOptions {
32
+ originalPath: string;
33
+ watermarkUrl: string;
34
+ fileName: string;
35
+ scale: number;
36
+ positionWatermarkX: number;
37
+ positionWatermarkY: number;
38
+ opacity?: number;
39
+ watermarkWidth?: number;
40
+ watermarkHeight?: number;
41
+ }
42
+ export interface UploadFileOptions {
43
+ path: string;
44
+ url: string;
45
+ method: string;
46
+ headers?: Record<string, string>;
47
+ fieldName?: string;
48
+ extraData?: Record<string, any>;
49
+ }
50
+ export interface InitPaymentOptions {
51
+ merchantOrderId: string;
52
+ merchantService: string;
53
+ amount: number;
54
+ productName: string;
55
+ midName?: string;
56
+ mid: string;
57
+ tid?: string;
58
+ orderDesc?: string;
59
+ requestDate: string;
60
+ serviceType: string;
61
+ signature: string;
62
+ ipnUrl?: string;
63
+ callbackUrl?: string;
64
+ extraData?: Record<string, any>;
65
+ onResult: (res: IVETCMiniAppResponse) => void;
66
+ }
67
+ export interface MiniAppSDK {
68
+ confirmBeforeExit(title?: string, message?: string): Promise<IVETCMiniAppResponse>;
69
+ exitMiniApp(): Promise<IVETCMiniAppResponse>;
70
+ openAppSetting(): Promise<IVETCMiniAppResponse>;
71
+ openNativeAppStore(appleStoreId?: string, googlePlayId?: string): Promise<IVETCMiniAppResponse>;
72
+ shareApp(title?: string, description?: string, path?: string, url?: string): Promise<IVETCMiniAppResponse>;
73
+ getAuthCode(scopes?: string[]): Promise<IVETCMiniAppResponse<{
74
+ authCode: string;
75
+ scopes: string[];
76
+ }>>;
77
+ getUserInfo(): Promise<IVETCMiniAppResponse<{
78
+ uid: string;
79
+ name: string;
80
+ [key: string]: any;
81
+ }>>;
82
+ scanQr(patterns?: string[]): Promise<IVETCMiniAppResponse>;
83
+ closeScanQr(): Promise<IVETCMiniAppResponse>;
84
+ pushEvent(eventName: string, properties?: Record<string, any>): Promise<IVETCMiniAppResponse>;
85
+ navigate(screen: string, params?: NavigateParams): Promise<IVETCMiniAppResponse>;
86
+ close(result?: any): Promise<IVETCMiniAppResponse>;
87
+ openTel(phone: string): Promise<IVETCMiniAppResponse>;
88
+ chooseImage(options?: ChooseImageOptions): Promise<IVETCMiniAppResponse<ChooseImageFile[]>>;
89
+ getImageInfo(options: GetImageInfoOptions): Promise<IVETCMiniAppResponse<{
90
+ path: string;
91
+ name: string;
92
+ ext: string;
93
+ mimeType: string;
94
+ size: number;
95
+ width: number;
96
+ height: number;
97
+ }>>;
98
+ compressImage(options: CompressImageOptions): Promise<IVETCMiniAppResponse<{
99
+ path: string;
100
+ name: string;
101
+ }[]>>;
102
+ addWatermarkImage(options: AddWatermarkOptions): Promise<IVETCMiniAppResponse<{
103
+ path: string;
104
+ }[]>>;
105
+ uploadFile(options: UploadFileOptions): Promise<IVETCMiniAppResponse>;
106
+ uploadFileMinio(options: UploadFileOptions): Promise<IVETCMiniAppResponse>;
107
+ getBase64ByPath(options: {
108
+ path: string;
109
+ }): Promise<IVETCMiniAppResponse<{
110
+ base64: string;
111
+ }>>;
112
+ initPayment(options: InitPaymentOptions): Promise<IVETCMiniAppResponse>;
113
+ getCurrentLocation(): Promise<IVETCMiniAppResponse>;
114
+ requestPermission(permission: MiniAppPermission, reason?: string): Promise<IVETCMiniAppResponse>;
115
+ requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
116
+ requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
117
+ requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
118
+ requestPhotos(reason?: string): Promise<IVETCMiniAppResponse>;
119
+ requestContacts(reason?: string): Promise<IVETCMiniAppResponse>;
120
+ requestBluetooth(reason?: string): Promise<IVETCMiniAppResponse>;
121
+ requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
122
+ on(event: string, callback: (data: any) => void): void;
123
+ _emit(event: string, data?: any): void;
124
+ _listeners: Record<string, ((data: any) => void)[]>;
125
+ }
126
+ export declare const callHost: (action: string, payload?: Record<string, any>) => Promise<IVETCMiniAppResponse>;
127
+ export declare const MiniApp: MiniAppSDK;
128
+ export default MiniApp;
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ const e="undefined"!=typeof window,t=async(t,a={})=>{const r=e&&window.flutter_inappwebview&&"function"==typeof window.flutter_inappwebview.callHandler?window.flutter_inappwebview:null;if(!r)return{ok:!1,error:"BRIDGE_CALL_FAILED"};try{const e=await r.callHandler("MiniAppBridge",{action:t,payload:a});return console.log("Bridge response:",e),e}catch(e){return console.error("Bridge error:",e),{ok:!1,error:"BRIDGE_CALL_FAILED"}}},a={confirmBeforeExit:(e,a)=>t("confirmBeforeExit",{title:e,message:a}),exitMiniApp:()=>t("exitMiniApp",{}),openAppSetting:()=>t("openAppSetting",{}),openNativeAppStore:(e,a)=>t("openNativeAppStore",{appleStoreId:e,googlePlayId:a}),shareApp:(e,a,r,i)=>t("shareApp",{title:e,description:a,path:r,url:i}),getAuthCode:e=>t("getAuthCode",{scopes:e}),getUserInfo:()=>t("getUserInfo",{}),scanQr:(e=[])=>t("scanQr",{patterns:e}),closeScanQr:()=>t("closeScanQr",{}),pushEvent:(e,a={})=>t("pushEvent",{eventName:e,properties:a}),navigate:(e,a={})=>t("navigate",{type:"native",screen:e,params:a}),close:(e={})=>t("close",{result:e}),openTel:e=>t("openTel",{phone:e}),chooseImage:({count:e,includeBase64:a,sourceType:r}={})=>t("chooseImage",{count:e,includeBase64:a,sourceType:r}),getBase64ByPath:({path:e})=>t("getBase64ByPath",{path:e}),addWatermarkImage:({originalPath:e,watermarkUrl:a,opacity:r,fileName:i,watermarkWidth:o,watermarkHeight:n,positionWatermarkX:s,positionWatermarkY:p,scale:l})=>t("addWatermarkImage",{originalPath:e,watermarkUrl:a,opacity:r,fileName:i,watermarkWidth:o,watermarkHeight:n,positionWatermarkX:s,positionWatermarkY:p,scale:l}),compressImage:({path:e,quality:a,minWidth:r,minHeight:i})=>t("compressImage",{path:e,quality:a,minWidth:r,minHeight:i}),getImageInfo:({path:e})=>t("getImageInfo",{path:e}),uploadFile:({path:e,url:a,headers:r,extraData:i,fieldName:o,method:n})=>t("uploadFile",{path:e,url:a,headers:r,extraData:i,fieldName:o,method:n}),uploadFileMinio:({path:e,url:a,headers:r,extraData:i,fieldName:o,method:n})=>t("uploadFileMinio",{path:e,url:a,headers:r,extraData:i,fieldName:o,method:n}),initPayment:({merchantOrderId:e,merchantService:a,amount:r,productName:i,midName:o,mid:n,tid:s,orderDesc:p,requestDate:l,serviceType:m,signature:c,extraData:d,onResult:u,ipnUrl:h,callbackUrl:g})=>t("initPayment",{merchantOrderId:e,merchantService:a,amount:r,productName:i,midName:o,mid:n,tid:s,orderDesc:p,requestDate:l,serviceType:m,signature:c,extraData:d,onResult:u,ipnUrl:h,callbackUrl:g}),getCurrentLocation:()=>t("getCurrentLocation",{}),requestPermission:(e,a)=>t("requestPermission",{permission:e,reason:a}),requestLocation:e=>a.requestPermission("location",e),requestCamera:e=>a.requestPermission("camera",e),requestMicrophone:e=>a.requestPermission("microphone",e),requestPhotos:e=>a.requestPermission("photos",e),requestContacts:e=>a.requestPermission("contacts",e),requestBluetooth:e=>a.requestPermission("bluetooth",e),requestNFC:e=>a.requestPermission("nfc",e),_listeners:{},on(e,t){a._listeners[e]||(a._listeners[e]=[]),a._listeners[e].push(t)},_emit(e,t){(a._listeners[e]||[]).forEach(e=>e(t))}};e&&window.addEventListener("miniapp_event",e=>{const{type:t,data:r}=e.detail||{};a._emit(t,r)});export{a as MiniApp,t as callHost,a as default};
package/package.json CHANGED
@@ -1,15 +1,24 @@
1
1
  {
2
2
  "name": "@vetc-miniapp/apis",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "MiniApp Platform JS SDK",
5
- "main": "src/apis/index.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
6
7
  "type": "module",
7
- "types": "src/apis/index.d.ts",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
8
16
  "files": [
9
- "src"
17
+ "dist"
10
18
  ],
11
19
  "scripts": {
12
- "build": "webpack"
20
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && rollup -c",
21
+ "build:webpack": "webpack"
13
22
  },
14
23
  "keywords": [
15
24
  "miniapp",
@@ -25,8 +34,11 @@
25
34
  "@rollup/plugin-commonjs": "^29.0.0",
26
35
  "@rollup/plugin-node-resolve": "^16.0.3",
27
36
  "@rollup/plugin-terser": "^0.4.4",
37
+ "@rollup/plugin-typescript": "^12.3.0",
28
38
  "babel-loader": "^10.0.0",
29
39
  "rollup": "^4.57.1",
40
+ "tslib": "^2.8.1",
41
+ "typescript": "^5.9.3",
30
42
  "webpack": "^5.104.1",
31
43
  "webpack-cli": "^6.0.1"
32
44
  }
@@ -1,9 +0,0 @@
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
@@ -1,133 +0,0 @@
1
- export interface IVETCMiniAppResponse<T = any> {
2
- ok: boolean;
3
- data?: T;
4
- error?: string;
5
- message?: string;
6
- }
7
-
8
- export type MiniAppPermission =
9
- | 'location'
10
- | 'camera'
11
- | 'microphone'
12
- | 'photos'
13
- | 'contacts'
14
- | 'bluetooth'
15
- | 'nfc';
16
-
17
- export interface NavigateParams {
18
- title?: string;
19
- [key: string]: any;
20
- }
21
-
22
- export interface ChooseImageFile {
23
- path: string;
24
- mimeType: string;
25
- base64?: string;
26
- }
27
-
28
- export interface ChooseImageOptions {
29
- count?: number;
30
- includeBase64?: boolean;
31
- sourceType?: ('camera' | 'album')[];
32
- }
33
-
34
- export interface CompressImageOptions {
35
- path: string;
36
- quality: number;
37
- minWidth?: number;
38
- minHeight?: number;
39
- }
40
-
41
- export interface GetImageInfoOptions {
42
- path: string;
43
- }
44
-
45
- export interface AddWatermarkOptions {
46
- originalPath: string;
47
- watermarkUrl: string;
48
- fileName: string;
49
- scale: number;
50
- positionWatermarkX: number;
51
- positionWatermarkY: number;
52
- opacity?: number;
53
- watermarkWidth?: number;
54
- watermarkHeight?: number;
55
- }
56
-
57
- export interface UploadFileOptions {
58
- path: string;
59
- url: string;
60
- method: string;
61
- headers?: Record<string, string>;
62
- fieldName?: string;
63
- extraData?: Record<string, any>;
64
- }
65
-
66
- export interface InitPaymentOptions {
67
- merchantOrderId: string;
68
- merchantService: string;
69
- amount: number;
70
- productName: string;
71
- midName?: string;
72
- mid: string;
73
- tid?: string;
74
- orderDesc?: string;
75
- requestDate: string;
76
- serviceType: string;
77
- signature: string;
78
- ipnUrl?: string;
79
- callbackUrl?: string;
80
- extraData?: Record<string, any>;
81
- onResult: (res: IVETCMiniAppResponse) => void;
82
- }
83
-
84
- export interface MiniAppSDK {
85
- confirmBeforeExit(title?: string, message?: string): Promise<IVETCMiniAppResponse>;
86
- exitMiniApp(): Promise<IVETCMiniAppResponse>;
87
- openAppSetting(): Promise<IVETCMiniAppResponse>;
88
- openNativeAppStore(appleStoreId?: string, googlePlayId?: string): Promise<IVETCMiniAppResponse>;
89
- shareApp(title?: string, description?: string, path?: string, url?: string): Promise<IVETCMiniAppResponse>;
90
-
91
- getAuthCode(scopes?: string[]): Promise<IVETCMiniAppResponse<{ authCode: string; scopes: string[] }>>;
92
- getUserInfo(): Promise<IVETCMiniAppResponse<{ uid: string; name: string;[key: string]: any }>>;
93
-
94
- scanQr(patterns?: string[]): Promise<IVETCMiniAppResponse>;
95
- closeScanQr(): Promise<IVETCMiniAppResponse>;
96
-
97
- pushEvent(eventName: string, properties?: Record<string, any>): Promise<IVETCMiniAppResponse>;
98
-
99
- navigate(screen: string, params?: NavigateParams): Promise<IVETCMiniAppResponse>;
100
- close(result?: any): Promise<IVETCMiniAppResponse>;
101
-
102
- openTel(phone: string): Promise<IVETCMiniAppResponse>;
103
-
104
- chooseImage(options?: ChooseImageOptions): Promise<IVETCMiniAppResponse<ChooseImageFile[]>>;
105
- getImageInfo(options: GetImageInfoOptions): Promise<IVETCMiniAppResponse<{ path: string; name: string; ext: string; mimeType: string; size: number; width: number; height: number }>>;
106
- compressImage(options: CompressImageOptions): Promise<IVETCMiniAppResponse<{ path: string; name: string }[]>>;
107
- addWatermarkImage(options: AddWatermarkOptions): Promise<IVETCMiniAppResponse<{ path: string }[]>>;
108
- uploadFile(options: UploadFileOptions): Promise<IVETCMiniAppResponse>;
109
- getBase64ByPath(options: { path: string }): Promise<IVETCMiniAppResponse<{ base64: string }>>;
110
-
111
- initPayment(options: InitPaymentOptions): Promise<IVETCMiniAppResponse>;
112
-
113
- getCurrentLocation(): Promise<IVETCMiniAppResponse>;
114
- requestPermission(permission: MiniAppPermission, reason?: string): Promise<IVETCMiniAppResponse>;
115
- requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
116
- requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
117
- requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
118
- requestPhotos(reason?: string): Promise<IVETCMiniAppResponse>;
119
- requestContacts(reason?: string): Promise<IVETCMiniAppResponse>;
120
- requestBluetooth(reason?: string): Promise<IVETCMiniAppResponse>;
121
- requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
122
-
123
- on(event: string, callback: (data: any) => void): void;
124
- _emit(event: string, data?: any): void;
125
- _listeners: Record<string, ((data: any) => void)[]>;
126
- }
127
-
128
- declare const MiniApp: MiniAppSDK;
129
- export default MiniApp;
130
- export { MiniApp };
131
-
132
- /** Low-level bridge call — dùng cho action chưa có wrapper trong MiniAppSDK */
133
- export declare function callHost(action: string, payload?: Record<string, any>): Promise<IVETCMiniAppResponse>;
package/src/apis/index.js DELETED
@@ -1,130 +0,0 @@
1
- const isBrowser = typeof window !== "undefined";
2
-
3
- const getBridge = () => {
4
- if (!isBrowser || !window.flutter_inappwebview || !window.flutter_inappwebview.callHandler || typeof window.flutter_inappwebview.callHandler != "function") {
5
- return null;
6
- }
7
- return window.flutter_inappwebview;
8
- };
9
- export const callHost = async (action, payload = {}) => {
10
- const bridge = getBridge();
11
- if (!bridge) {
12
- return {
13
- ok: false,
14
- error: "BRIDGE_CALL_FAILED"
15
- };
16
- }
17
- try {
18
- const response = await bridge.callHandler("MiniAppBridge", {
19
- action,
20
- payload,
21
- });
22
- console.log("Bridge response:", response);
23
-
24
- return response;
25
- } catch (error) {
26
- console.error("Bridge error:", error);
27
- return {
28
- ok: false,
29
- error: "BRIDGE_CALL_FAILED"
30
- };
31
- }
32
- };
33
-
34
- export const MiniApp = {
35
- confirmBeforeExit(title, message, success, fail, complete) {
36
- return callHost("confirmBeforeExit", { title, message, success, fail, complete });
37
- },
38
- exitMiniApp(success, fail, complete) {
39
- return callHost("exitMiniApp", { success, fail, complete });
40
- },
41
- openAppSetting(success, fail, complete) {
42
- return callHost("openAppSetting", { success, fail, complete });
43
- },
44
- openNativeAppStore(appleStoreId, googlePlayId, success, fail, complete) {
45
- return callHost("openNativeAppStore", { appleStoreId, googlePlayId, success, fail, complete });
46
- },
47
- shareApp(title, description, path, url, success, fail, complete) {
48
- return callHost("shareApp", { title, description, path, url, success, fail, complete });
49
- },
50
- getAuthCode(scopes, success, fail, complete) {
51
- return callHost("getAuthCode", { scopes, success, fail, complete });
52
- },
53
- getUserInfo(success, fail, complete) {
54
- return callHost("getUserInfo", { success, fail, complete });
55
- },
56
- scanQr(patterns = []) {
57
- return callHost("scanQr", { patterns });
58
- },
59
- pushEvent(eventName, properties = {}) {
60
- return callHost("pushEvent", { eventName, properties });
61
- },
62
- closeScanQr() {
63
- return callHost("closeScanQr", {});
64
- },
65
- navigate(screen, params = {}) {
66
- return callHost("navigate", { type: "native", screen, params });
67
- },
68
- close(result = {}) {
69
- return callHost("close", { result });
70
- },
71
- openTel(phone) {
72
- return callHost("openTel", { phone });
73
- },
74
- chooseImage({ count, includeBase64, sourceType, success, fail, complete } = {}) {
75
- return callHost("chooseImage", { count, includeBase64, sourceType, success, fail, complete });
76
- },
77
- getBase64ByPath({ path } = {}) {
78
- return callHost("getBase64ByPath", { path });
79
- },
80
- addWatermarkImage({ originalPath, watermarkUrl, opacity, fileName, watermarkWidth, watermarkHeight, positionWatermarkX, positionWatermarkY, scale } = {}) {
81
- return callHost("addWatermarkImage", { originalPath, watermarkUrl, opacity, fileName, watermarkWidth, watermarkHeight, positionWatermarkX, positionWatermarkY, scale });
82
- },
83
- compressImage({ path, quality, minWidth, minHeight } = {}) {
84
- return callHost("compressImage", { path, quality, minWidth, minHeight });
85
- },
86
- getImageInfo({ path } = {}) {
87
- return callHost("getImageInfo", { path });
88
- },
89
- uploadFile({ path, url, headers, extraData, fieldName, method } = {}) {
90
- return callHost("uploadFile", { path, url, headers, extraData, fieldName, method });
91
- },
92
- uploadFileMinio({ path, url, headers, extraData, fieldName, method } = {}) {
93
- return callHost("uploadFileMinio", { path, url, headers, extraData, fieldName, method });
94
- },
95
- initPayment({ merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl } = {}) {
96
- return callHost("initPayment", { merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl });
97
- },
98
- getCurrentLocation() {
99
- return callHost("getCurrentLocation", {});
100
- },
101
- requestPermission(permission, reason) {
102
- return callHost("requestPermission", { permission, reason });
103
- },
104
- requestLocation(reason) { return MiniApp.requestPermission("location", reason); },
105
- requestCamera(reason) { return MiniApp.requestPermission("camera", reason); },
106
- requestMicrophone(reason) { return MiniApp.requestPermission("microphone", reason); },
107
- requestPhotos(reason) { return MiniApp.requestPermission("photos", reason); },
108
- requestContacts(reason) { return MiniApp.requestPermission("contacts", reason); },
109
- requestBluetooth(reason) { return MiniApp.requestPermission("bluetooth", reason); },
110
- requestNFC(reason) { return MiniApp.requestPermission("nfc", reason); },
111
-
112
- _listeners: {},
113
- on(event, callback) {
114
- if (!MiniApp._listeners[event]) MiniApp._listeners[event] = [];
115
- MiniApp._listeners[event].push(callback);
116
- },
117
- _emit(event, data) {
118
- (MiniApp._listeners[event] || []).forEach((cb) => cb(data));
119
- },
120
- };
121
-
122
- // Gắn listener CHỈ khi có window
123
- if (isBrowser) {
124
- window.addEventListener("miniapp_event", (e) => {
125
- const { type, data } = e.detail || {};
126
- MiniApp._emit(type, data);
127
- });
128
- }
129
-
130
- export default MiniApp;
@@ -1 +0,0 @@
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,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},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:()=>o,callHost:()=>a,default:()=>i});const r="undefined"!=typeof window,a=async(e,t={})=>{const a=r&&window.flutter_inappwebview&&window.flutter_inappwebview.callHandler&&"function"==typeof window.flutter_inappwebview.callHandler?window.flutter_inappwebview:null;if(!a)return{ok:!1,error:"BRIDGE_CALL_FAILED"};try{const r=await a.callHandler("MiniAppBridge",{action:e,payload:t});return console.log("Bridge response:",r),r}catch(e){return console.error("Bridge error:",e),{ok:!1,error:"BRIDGE_CALL_FAILED"}}},o={confirmBeforeExit:(e,t,r,o,i)=>a("confirmBeforeExit",{title:e,message:t,success:r,fail:o,complete:i}),exitMiniApp:(e,t,r)=>a("exitMiniApp",{success:e,fail:t,complete:r}),openAppSetting:(e,t,r)=>a("openAppSetting",{success:e,fail:t,complete:r}),openNativeAppStore:(e,t,r,o,i)=>a("openNativeAppStore",{appleStoreId:e,googlePlayId:t,success:r,fail:o,complete:i}),shareApp:(e,t,r,o,i,s,n)=>a("shareApp",{title:e,description:t,path:r,url:o,success:i,fail:s,complete:n}),getAuthCode:(e,t,r,o)=>a("getAuthCode",{scopes:e,success:t,fail:r,complete:o}),getUserInfo:(e,t,r)=>a("getUserInfo",{success:e,fail:t,complete:r}),scanQr:(e=[])=>a("scanQr",{patterns:e}),pushEvent:(e,t={})=>a("pushEvent",{eventName:e,properties:t}),closeScanQr:()=>a("closeScanQr",{}),navigate:(e,t={})=>a("navigate",{type:"native",screen:e,params:t}),close:(e={})=>a("close",{result:e}),openTel:e=>a("openTel",{phone:e}),chooseImage:({count:e,includeBase64:t,sourceType:r,success:o,fail:i,complete:s}={})=>a("chooseImage",{count:e,includeBase64:t,sourceType:r,success:o,fail:i,complete:s}),getBase64ByPath:({path:e}={})=>a("getBase64ByPath",{path:e}),addWatermarkImage:({originalPath:e,watermarkUrl:t,opacity:r,fileName:o,watermarkWidth:i,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}={})=>a("addWatermarkImage",{originalPath:e,watermarkUrl:t,opacity:r,fileName:o,watermarkWidth:i,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}),compressImage:({path:e,quality:t,minWidth:r,minHeight:o}={})=>a("compressImage",{path:e,quality:t,minWidth:r,minHeight:o}),getImageInfo:({path:e}={})=>a("getImageInfo",{path:e}),uploadFile:({path:e,url:t,headers:r,extraData:o,fieldName:i,method:s}={})=>a("uploadFile",{path:e,url:t,headers:r,extraData:o,fieldName:i,method:s}),uploadFileMinio:({path:e,url:t,headers:r,extraData:o,fieldName:i,method:s}={})=>a("uploadFileMinio",{path:e,url:t,headers:r,extraData:o,fieldName:i,method:s}),initPayment:({merchantOrderId:e,merchantService:t,amount:r,productName:o,midName:i,mid:s,tid:n,orderDesc:p,requestDate:l,serviceType:c,signature:m,extraData:u,onResult:d,ipnUrl:h,callbackUrl:f}={})=>a("initPayment",{merchantOrderId:e,merchantService:t,amount:r,productName:o,midName:i,mid:s,tid:n,orderDesc:p,requestDate:l,serviceType:c,signature:m,extraData:u,onResult:d,ipnUrl:h,callbackUrl:f}),getCurrentLocation:()=>a("getCurrentLocation",{}),requestPermission:(e,t)=>a("requestPermission",{permission:e,reason:t}),requestLocation:e=>o.requestPermission("location",e),requestCamera:e=>o.requestPermission("camera",e),requestMicrophone:e=>o.requestPermission("microphone",e),requestPhotos:e=>o.requestPermission("photos",e),requestContacts:e=>o.requestPermission("contacts",e),requestBluetooth:e=>o.requestPermission("bluetooth",e),requestNFC:e=>o.requestPermission("nfc",e),_listeners:{},on(e,t){o._listeners[e]||(o._listeners[e]=[]),o._listeners[e].push(t)},_emit(e,t){(o._listeners[e]||[]).forEach(e=>e(t))}};r&&window.addEventListener("miniapp_event",e=>{const{type:t,data:r}=e.detail||{};o._emit(t,r)});const i=o;return t})());