@vetc-miniapp/apis 0.0.23 → 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 +2 -2
- package/src/apis/index.d.ts +93 -81
- package/src/apis/index.js +4 -1
- package/src/dist/apis/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vetc-miniapp/apis",
|
|
3
|
-
"version": "0.0.
|
|
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
|
+
}
|
package/src/apis/index.d.ts
CHANGED
|
@@ -5,105 +5,113 @@ export interface IVETCMiniAppResponse<T = any> {
|
|
|
5
5
|
message?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
/* ================= Permissions ================= */
|
|
9
|
-
|
|
10
8
|
export type MiniAppPermission =
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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>;
|
|
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>;
|
|
84
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>;
|
|
85
95
|
closeScanQr(): Promise<IVETCMiniAppResponse>;
|
|
86
96
|
|
|
87
|
-
|
|
88
|
-
screen: string,
|
|
89
|
-
params?: NavigateParams
|
|
90
|
-
): Promise<IVETCMiniAppResponse>;
|
|
97
|
+
pushEvent(eventName: string, properties?: Record<string, any>): Promise<IVETCMiniAppResponse>;
|
|
91
98
|
|
|
99
|
+
navigate(screen: string, params?: NavigateParams): Promise<IVETCMiniAppResponse>;
|
|
92
100
|
close(result?: any): Promise<IVETCMiniAppResponse>;
|
|
93
101
|
|
|
94
|
-
openTel(phone
|
|
95
|
-
|
|
96
|
-
getBase64ByPath({ path: string }): : Promise<IVETCMiniAppResponse>;
|
|
102
|
+
openTel(phone: string): Promise<IVETCMiniAppResponse>;
|
|
97
103
|
|
|
98
|
-
chooseImage(
|
|
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 }>>;
|
|
99
110
|
|
|
100
|
-
initPayment(
|
|
101
|
-
|
|
102
|
-
requestPermission(
|
|
103
|
-
permission: MiniAppPermission,
|
|
104
|
-
reason?: string
|
|
105
|
-
): Promise<IVETCMiniAppResponse>;
|
|
111
|
+
initPayment(options: InitPaymentOptions): Promise<IVETCMiniAppResponse>;
|
|
106
112
|
|
|
113
|
+
getCurrentLocation(): Promise<IVETCMiniAppResponse>;
|
|
114
|
+
requestPermission(permission: MiniAppPermission, reason?: string): Promise<IVETCMiniAppResponse>;
|
|
107
115
|
requestLocation(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
108
116
|
requestCamera(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
109
117
|
requestMicrophone(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
@@ -113,9 +121,13 @@ export interface MiniAppSDK {
|
|
|
113
121
|
requestNFC(reason?: string): Promise<IVETCMiniAppResponse>;
|
|
114
122
|
|
|
115
123
|
on(event: string, callback: (data: any) => void): void;
|
|
124
|
+
_emit(event: string, data?: any): void;
|
|
125
|
+
_listeners: Record<string, ((data: any) => void)[]>;
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
/* Default export */
|
|
119
128
|
declare const MiniApp: MiniAppSDK;
|
|
120
129
|
export default MiniApp;
|
|
121
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
|
@@ -92,9 +92,12 @@ export const MiniApp = {
|
|
|
92
92
|
uploadFileMinio({ path, url, headers, extraData, fieldName, method } = {}) {
|
|
93
93
|
return callHost("uploadFileMinio", { path, url, headers, extraData, fieldName, method });
|
|
94
94
|
},
|
|
95
|
-
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 } = {}) {
|
|
96
96
|
return callHost("initPayment", { merchantOrderId, merchantService, amount, productName, midName, mid, tid, orderDesc, requestDate, serviceType, signature, extraData, onResult, ipnUrl, callbackUrl });
|
|
97
97
|
},
|
|
98
|
+
getCurrentLocation() {
|
|
99
|
+
return callHost("getCurrentLocation", {});
|
|
100
|
+
},
|
|
98
101
|
requestPermission(permission, reason) {
|
|
99
102
|
return callHost("requestPermission", { permission, reason });
|
|
100
103
|
},
|
package/src/dist/apis/index.js
CHANGED
|
@@ -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,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:()=>
|
|
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})());
|