@vetc-miniapp/apis 0.0.23 → 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.23",
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,9 +34,12 @@
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
  }
33
- }
45
+ }
@@ -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,121 +0,0 @@
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
- scanQr(patterns: string[]): Promise<IVETCMiniAppResponse>;
82
-
83
- pushEvent(eventName: string, properties: {[key: string]: any;} ): Promise<IVETCMiniAppResponse>;
84
-
85
- closeScanQr(): Promise<IVETCMiniAppResponse>;
86
-
87
- navigate(
88
- screen: string,
89
- params?: NavigateParams
90
- ): Promise<IVETCMiniAppResponse>;
91
-
92
- close(result?: any): Promise<IVETCMiniAppResponse>;
93
-
94
- openTel(phone?: string): Promise<IVETCMiniAppResponse>;
95
-
96
- getBase64ByPath({ path: string }): : Promise<IVETCMiniAppResponse>;
97
-
98
- chooseImage({ count?: number, includeBase64: boolean, sourceType?: ("camera" | "album")[], success?: Function, fail?: Function, complete?: Function }):Promise<IVETCMiniAppResponse<ChooseImageFile[]>
99
-
100
- initPayment({ merchantOrderId: string, merchantService: string, amount: double, productName: string, midName: string, mid: string, tid?: string, orderDesc?: string, requestDate: string, serviceType: string, signature: string, ipnUrl?: string, callbackUrl?: string, extraData: {[key: string]: any;}, onResult: Function }): Promise<IVETCMiniAppResponse>;
101
-
102
- requestPermission(
103
- permission: MiniAppPermission,
104
- reason?: string
105
- ): Promise<IVETCMiniAppResponse>;
106
-
107
- requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
108
- requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
109
- requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
110
- requestPhotos(reason?: string): Promise<IVETCMiniAppResponse>;
111
- requestContacts(reason?: string): Promise<IVETCMiniAppResponse>;
112
- requestBluetooth(reason?: string): Promise<IVETCMiniAppResponse>;
113
- requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
114
-
115
- on(event: string, callback: (data: any) => void): void;
116
- }
117
-
118
- /* Default export */
119
- declare const MiniApp: MiniAppSDK;
120
- export default MiniApp;
121
- export { MiniApp };
package/src/apis/index.js DELETED
@@ -1,127 +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
- requestPermission(permission, reason) {
99
- return callHost("requestPermission", { permission, reason });
100
- },
101
- requestLocation(reason) { return MiniApp.requestPermission("location", reason); },
102
- requestCamera(reason) { return MiniApp.requestPermission("camera", reason); },
103
- requestMicrophone(reason) { return MiniApp.requestPermission("microphone", reason); },
104
- requestPhotos(reason) { return MiniApp.requestPermission("photos", reason); },
105
- requestContacts(reason) { return MiniApp.requestPermission("contacts", reason); },
106
- requestBluetooth(reason) { return MiniApp.requestPermission("bluetooth", reason); },
107
- requestNFC(reason) { return MiniApp.requestPermission("nfc", reason); },
108
-
109
- _listeners: {},
110
- on(event, callback) {
111
- if (!MiniApp._listeners[event]) MiniApp._listeners[event] = [];
112
- MiniApp._listeners[event].push(callback);
113
- },
114
- _emit(event, data) {
115
- (MiniApp._listeners[event] || []).forEach((cb) => cb(data));
116
- },
117
- };
118
-
119
- // Gắn listener CHỈ khi có window
120
- if (isBrowser) {
121
- window.addEventListener("miniapp_event", (e) => {
122
- const { type, data } = e.detail || {};
123
- MiniApp._emit(type, data);
124
- });
125
- }
126
-
127
- 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:()=>i,callHost:()=>a,default:()=>o});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"}}},i={confirmBeforeExit:(e,t,r,i,o)=>a("confirmBeforeExit",{title:e,message:t,success:r,fail:i,complete:o}),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,i,o)=>a("openNativeAppStore",{appleStoreId:e,googlePlayId:t,success:r,fail:i,complete:o}),shareApp:(e,t,r,i,o,s,n)=>a("shareApp",{title:e,description:t,path:r,url:i,success:o,fail:s,complete:n}),getAuthCode:(e,t,r,i)=>a("getAuthCode",{scopes:e,success:t,fail:r,complete:i}),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:i,fail:o,complete:s}={})=>a("chooseImage",{count:e,includeBase64:t,sourceType:r,success:i,fail:o,complete:s}),getBase64ByPath:({path:e}={})=>a("getBase64ByPath",{path:e}),addWatermarkImage:({originalPath:e,watermarkUrl:t,opacity:r,fileName:i,watermarkWidth:o,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}={})=>a("addWatermarkImage",{originalPath:e,watermarkUrl:t,opacity:r,fileName:i,watermarkWidth:o,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}),compressImage:({path:e,quality:t,minWidth:r,minHeight:i}={})=>a("compressImage",{path:e,quality:t,minWidth:r,minHeight:i}),getImageInfo:({path:e}={})=>a("getImageInfo",{path:e}),uploadFile:({path:e,url:t,headers:r,extraData:i,fieldName:o,method:s}={})=>a("uploadFile",{path:e,url:t,headers:r,extraData:i,fieldName:o,method:s}),uploadFileMinio:({path:e,url:t,headers:r,extraData:i,fieldName:o,method:s}={})=>a("uploadFileMinio",{path:e,url:t,headers:r,extraData:i,fieldName:o,method:s}),initPayment:({merchantOrderId:e,merchantService:t,amount:r,productName:i,midName:o,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:i,midName:o,mid:s,tid:n,orderDesc:p,requestDate:l,serviceType:c,signature:m,extraData:u,onResult:d,ipnUrl:h,callbackUrl:f}),requestPermission:(e,t)=>a("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))}};r&&window.addEventListener("miniapp_event",e=>{const{type:t,data:r}=e.detail||{};i._emit(t,r)});const o=i;return t})());