@vetc-miniapp/apis 0.0.22 → 0.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vetc-miniapp/apis",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "MiniApp Platform JS SDK",
5
5
  "main": "src/apis/index.js",
6
6
  "type": "module",
@@ -30,4 +30,4 @@
30
30
  "webpack": "^5.104.1",
31
31
  "webpack-cli": "^6.0.1"
32
32
  }
33
- }
33
+ }
@@ -5,103 +5,113 @@ export interface IVETCMiniAppResponse<T = any> {
5
5
  message?: string;
6
6
  }
7
7
 
8
- /* ================= Permissions ================= */
9
-
10
8
  export type MiniAppPermission =
11
- | "location"
12
- | "camera"
13
- | "microphone"
14
- | "photos"
15
- | "contacts"
16
- | "bluetooth"
17
- | "nfc";
18
-
19
- /* ================= Core Payloads ================= */
9
+ | 'location'
10
+ | 'camera'
11
+ | 'microphone'
12
+ | 'photos'
13
+ | 'contacts'
14
+ | 'bluetooth'
15
+ | 'nfc';
20
16
 
21
17
  export interface NavigateParams {
22
18
  title?: string;
23
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
+ }
24
40
 
41
+ export interface GetImageInfoOptions {
42
+ path: string;
25
43
  }
26
44
 
27
- /* ================= Main SDK ================= */
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
+ }
28
83
 
29
84
  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>;
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>;
82
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>;
83
95
  closeScanQr(): Promise<IVETCMiniAppResponse>;
84
96
 
85
- navigate(
86
- screen: string,
87
- params?: NavigateParams
88
- ): Promise<IVETCMiniAppResponse>;
97
+ pushEvent(eventName: string, properties?: Record<string, any>): Promise<IVETCMiniAppResponse>;
89
98
 
99
+ navigate(screen: string, params?: NavigateParams): Promise<IVETCMiniAppResponse>;
90
100
  close(result?: any): Promise<IVETCMiniAppResponse>;
91
101
 
92
- openTel(phone?: string): Promise<IVETCMiniAppResponse>;
93
-
94
- getBase64ByPath({ path: string }): : Promise<IVETCMiniAppResponse>;
102
+ openTel(phone: string): Promise<IVETCMiniAppResponse>;
95
103
 
96
- chooseImage({ count?: number, includeBase64: boolean, sourceType?: ("camera" | "album")[], success?: Function, fail?: Function, complete?: Function }):Promise<IVETCMiniAppResponse<ChooseImageFile[]>
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 }>>;
97
110
 
98
- 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>;
99
-
100
- requestPermission(
101
- permission: MiniAppPermission,
102
- reason?: string
103
- ): Promise<IVETCMiniAppResponse>;
111
+ initPayment(options: InitPaymentOptions): Promise<IVETCMiniAppResponse>;
104
112
 
113
+ getCurrentLocation(): Promise<IVETCMiniAppResponse>;
114
+ requestPermission(permission: MiniAppPermission, reason?: string): Promise<IVETCMiniAppResponse>;
105
115
  requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
106
116
  requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
107
117
  requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
@@ -111,9 +121,13 @@ export interface MiniAppSDK {
111
121
  requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
112
122
 
113
123
  on(event: string, callback: (data: any) => void): void;
124
+ _emit(event: string, data?: any): void;
125
+ _listeners: Record<string, ((data: any) => void)[]>;
114
126
  }
115
127
 
116
- /* Default export */
117
128
  declare const MiniApp: MiniAppSDK;
118
129
  export default MiniApp;
119
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 CHANGED
@@ -56,6 +56,9 @@ export const MiniApp = {
56
56
  scanQr(patterns = []) {
57
57
  return callHost("scanQr", { patterns });
58
58
  },
59
+ pushEvent(eventName, properties = {}) {
60
+ return callHost("pushEvent", { eventName, properties });
61
+ },
59
62
  closeScanQr() {
60
63
  return callHost("closeScanQr", {});
61
64
  },
@@ -89,9 +92,12 @@ export const MiniApp = {
89
92
  uploadFileMinio({ path, url, headers, extraData, fieldName, method } = {}) {
90
93
  return callHost("uploadFileMinio", { path, url, headers, extraData, fieldName, method });
91
94
  },
92
- initPayment({ merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl } = {}) {
95
+ initPayment({ merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl } = {}) {
93
96
  return callHost("initPayment", { merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl });
94
97
  },
98
+ getCurrentLocation() {
99
+ return callHost("getCurrentLocation", {});
100
+ },
95
101
  requestPermission(permission, reason) {
96
102
  return callHost("requestPermission", { permission, reason });
97
103
  },
@@ -1 +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,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},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:()=>r,default:()=>o});const a="undefined"!=typeof window,r=async(e,t={})=>{const r=a&&window.flutter_inappwebview&&window.flutter_inappwebview.callHandler&&"function"==typeof window.flutter_inappwebview.callHandler?window.flutter_inappwebview:null;if(!r)return{ok:!1,error:"BRIDGE_CALL_FAILED"};try{const a=await r.callHandler("MiniAppBridge",{action:e,payload:t});return console.log("Bridge response:",a),a}catch(e){return console.error("Bridge error:",e),{ok:!1,error:"BRIDGE_CALL_FAILED"}}},i={confirmBeforeExit:(e,t,a,i,o)=>r("confirmBeforeExit",{title:e,message:t,success:a,fail:i,complete:o}),exitMiniApp:(e,t,a)=>r("exitMiniApp",{success:e,fail:t,complete:a}),openAppSetting:(e,t,a)=>r("openAppSetting",{success:e,fail:t,complete:a}),openNativeAppStore:(e,t,a,i,o)=>r("openNativeAppStore",{appleStoreId:e,googlePlayId:t,success:a,fail:i,complete:o}),shareApp:(e,t,a,i,o,s,n)=>r("shareApp",{title:e,description:t,path:a,url:i,success:o,fail:s,complete:n}),getAuthCode:(e,t,a,i)=>r("getAuthCode",{scopes:e,success:t,fail:a,complete:i}),getUserInfo:(e,t,a)=>r("getUserInfo",{success:e,fail:t,complete:a}),scanQr:(e=[])=>r("scanQr",{patterns:e}),closeScanQr:()=>r("closeScanQr",{}),navigate:(e,t={})=>r("navigate",{type:"native",screen:e,params:t}),close:(e={})=>r("close",{result:e}),openTel:e=>r("openTel",{phone:e}),chooseImage:({count:e,includeBase64:t,sourceType:a,success:i,fail:o,complete:s}={})=>r("chooseImage",{count:e,includeBase64:t,sourceType:a,success:i,fail:o,complete:s}),getBase64ByPath:({path:e}={})=>r("getBase64ByPath",{path:e}),addWatermarkImage:({originalPath:e,watermarkUrl:t,opacity:a,fileName:i,watermarkWidth:o,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}={})=>r("addWatermarkImage",{originalPath:e,watermarkUrl:t,opacity:a,fileName:i,watermarkWidth:o,watermarkHeight:s,positionWatermarkX:n,positionWatermarkY:p,scale:l}),compressImage:({path:e,quality:t,minWidth:a,minHeight:i}={})=>r("compressImage",{path:e,quality:t,minWidth:a,minHeight:i}),getImageInfo:({path:e}={})=>r("getImageInfo",{path:e}),uploadFile:({path:e,url:t,headers:a,extraData:i,fieldName:o,method:s}={})=>r("uploadFile",{path:e,url:t,headers:a,extraData:i,fieldName:o,method:s}),uploadFileMinio:({path:e,url:t,headers:a,extraData:i,fieldName:o,method:s}={})=>r("uploadFileMinio",{path:e,url:t,headers:a,extraData:i,fieldName:o,method:s}),initPayment:({merchantOrderId:e,merchantService:t,amount:a,productName:i,midName:o,mid:s,tid:n,orderDesc:p,requestDate:l,serviceType:c,signature:m,extraData:u,onResult:d,ipnUrl:h,callbackUrl:f}={})=>r("initPayment",{merchantOrderId:e,merchantService:t,amount:a,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)=>r("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))}};a&&window.addEventListener("miniapp_event",e=>{const{type:t,data:a}=e.detail||{};i._emit(t,a)});const o=i;return t})());
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})());