@vetc-miniapp/ui-react 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 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,158 @@
1
+ {
2
+ "name": "@vetc-miniapp/ui-react",
3
+ "version": "0.0.1",
4
+ "description": "MiniApp Platform UI React",
5
+ "main": "src/index.js",
6
+ "types": "src/apis/index.d.ts",
7
+ "type": "module",
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
+ "@types/node": "^25.2.0",
29
+ "babel-loader": "^10.0.0",
30
+ "rollup": "^4.57.1",
31
+ "ts-loader": "^9.5.4",
32
+ "typescript": "^5.9.3",
33
+ "webpack": "^5.104.1",
34
+ "webpack-cli": "^6.0.1"
35
+ },
36
+ "dependencies": {
37
+ "acorn": "^8.15.0",
38
+ "acorn-import-phases": "^1.0.4",
39
+ "ajv": "^8.17.1",
40
+ "ajv-formats": "^2.1.1",
41
+ "ajv-keywords": "^5.1.0",
42
+ "babel-plugin-polyfill-corejs2": "^0.4.15",
43
+ "babel-plugin-polyfill-corejs3": "^0.14.0",
44
+ "babel-plugin-polyfill-regenerator": "^0.6.6",
45
+ "baseline-browser-mapping": "^2.9.19",
46
+ "browserslist": "^4.28.1",
47
+ "buffer-from": "^1.1.2",
48
+ "caniuse-lite": "^1.0.30001767",
49
+ "chrome-trace-event": "^1.0.4",
50
+ "clone-deep": "^4.0.1",
51
+ "colorette": "^2.0.20",
52
+ "commander": "^2.20.3",
53
+ "commondir": "^1.0.1",
54
+ "convert-source-map": "^2.0.0",
55
+ "core-js-compat": "^3.48.0",
56
+ "cross-spawn": "^7.0.6",
57
+ "debug": "^4.4.3",
58
+ "deepmerge": "^4.3.1",
59
+ "electron-to-chromium": "^1.5.283",
60
+ "enhanced-resolve": "^5.18.4",
61
+ "envinfo": "^7.21.0",
62
+ "es-module-lexer": "^2.0.0",
63
+ "escalade": "^3.2.0",
64
+ "eslint-scope": "^5.1.1",
65
+ "esrecurse": "^4.3.0",
66
+ "estraverse": "^4.3.0",
67
+ "estree-walker": "^2.0.2",
68
+ "esutils": "^2.0.3",
69
+ "events": "^3.3.0",
70
+ "fast-deep-equal": "^3.1.3",
71
+ "fast-uri": "^3.1.0",
72
+ "fastest-levenshtein": "^1.0.16",
73
+ "fdir": "^6.5.0",
74
+ "find-up": "^5.0.0",
75
+ "flat": "^5.0.2",
76
+ "fsevents": "^2.3.3",
77
+ "function-bind": "^1.1.2",
78
+ "gensync": "^1.0.0-beta.2",
79
+ "glob-to-regexp": "^0.4.1",
80
+ "graceful-fs": "^4.2.11",
81
+ "has-flag": "^4.0.0",
82
+ "hasown": "^2.0.2",
83
+ "import-local": "^3.2.0",
84
+ "interpret": "^3.1.1",
85
+ "is-core-module": "^2.16.1",
86
+ "is-module": "^1.0.0",
87
+ "is-plain-object": "^2.0.4",
88
+ "is-reference": "^1.2.1",
89
+ "isexe": "^2.0.0",
90
+ "isobject": "^3.0.1",
91
+ "jest-worker": "^27.5.1",
92
+ "js-tokens": "^4.0.0",
93
+ "jsesc": "^3.1.0",
94
+ "json-parse-even-better-errors": "^2.3.1",
95
+ "json-schema-traverse": "^1.0.0",
96
+ "json5": "^2.2.3",
97
+ "kind-of": "^6.0.3",
98
+ "loader-runner": "^4.3.1",
99
+ "locate-path": "^6.0.0",
100
+ "lodash.debounce": "^4.0.8",
101
+ "lru-cache": "^5.1.1",
102
+ "magic-string": "^0.30.21",
103
+ "merge-stream": "^2.0.0",
104
+ "mime-db": "^1.52.0",
105
+ "mime-types": "^2.1.35",
106
+ "ms": "^2.1.3",
107
+ "neo-async": "^2.6.2",
108
+ "node-releases": "^2.0.27",
109
+ "p-limit": "^3.1.0",
110
+ "p-locate": "^5.0.0",
111
+ "p-try": "^2.2.0",
112
+ "path-exists": "^4.0.0",
113
+ "path-key": "^3.1.1",
114
+ "path-parse": "^1.0.7",
115
+ "picocolors": "^1.1.1",
116
+ "picomatch": "^4.0.3",
117
+ "pkg-dir": "^4.2.0",
118
+ "randombytes": "^2.1.0",
119
+ "rechoir": "^0.8.0",
120
+ "regenerate": "^1.4.2",
121
+ "regenerate-unicode-properties": "^10.2.2",
122
+ "regexpu-core": "^6.4.0",
123
+ "regjsgen": "^0.8.0",
124
+ "regjsparser": "^0.13.0",
125
+ "require-from-string": "^2.0.2",
126
+ "resolve": "^1.22.11",
127
+ "resolve-cwd": "^3.0.0",
128
+ "resolve-from": "^5.0.0",
129
+ "safe-buffer": "^5.2.1",
130
+ "schema-utils": "^4.3.3",
131
+ "semver": "^6.3.1",
132
+ "serialize-javascript": "^6.0.2",
133
+ "shallow-clone": "^3.0.1",
134
+ "shebang-command": "^2.0.0",
135
+ "shebang-regex": "^3.0.0",
136
+ "smob": "^1.5.0",
137
+ "source-map": "^0.6.1",
138
+ "source-map-support": "^0.5.21",
139
+ "supports-color": "^8.1.1",
140
+ "supports-preserve-symlinks-flag": "^1.0.0",
141
+ "tapable": "^2.3.0",
142
+ "terser": "^5.46.0",
143
+ "terser-webpack-plugin": "^5.3.16",
144
+ "undici-types": "^7.16.0",
145
+ "unicode-canonical-property-names-ecmascript": "^2.0.1",
146
+ "unicode-match-property-ecmascript": "^2.0.0",
147
+ "unicode-match-property-value-ecmascript": "^2.2.1",
148
+ "unicode-property-aliases-ecmascript": "^2.2.0",
149
+ "update-browserslist-db": "^1.2.3",
150
+ "watchpack": "^2.5.1",
151
+ "webpack-merge": "^6.0.1",
152
+ "webpack-sources": "^3.3.3",
153
+ "which": "^2.0.2",
154
+ "wildcard": "^2.0.1",
155
+ "yallist": "^3.1.1",
156
+ "yocto-queue": "^0.1.0"
157
+ }
158
+ }
@@ -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["vetc-miniapp/ui-react"]=t():e["vetc-miniapp/ui-react"]=t()}(this,()=>(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},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,{useNavigate:()=>i});const o="undefined"!=typeof window,n=(e,t={})=>{const n=o&&window.flutter_inappwebview?window.flutter_inappwebview:null;return n?n.callHandler("MiniAppBridge",{action:e,payload:t}):Promise.reject(new Error("MiniApp bridge not available"))};function i(){return(e,t={},o={})=>{n("navigate",{type:"native",route:e,params:t,options:o})}}return t})());
@@ -0,0 +1,16 @@
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
+ export 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
+ };
@@ -0,0 +1,43 @@
1
+ /* ================= Types ================= */
2
+
3
+ export interface FlutterInAppWebViewBridge {
4
+ callHandler(
5
+ handlerName: string,
6
+ args?: unknown
7
+ ): Promise<unknown>;
8
+ }
9
+
10
+ declare global {
11
+ interface Window {
12
+ flutter_inappwebview?: FlutterInAppWebViewBridge;
13
+ }
14
+ }
15
+
16
+ /* ================= Runtime helpers ================= */
17
+
18
+ export const isBrowser: boolean = typeof window !== "undefined";
19
+
20
+ export const getBridge = (): FlutterInAppWebViewBridge | null => {
21
+ if (!isBrowser || !window.flutter_inappwebview) {
22
+ return null;
23
+ }
24
+ return window.flutter_inappwebview;
25
+ };
26
+
27
+ /* ================= Core bridge call ================= */
28
+
29
+ export const callHost = <T = unknown>(
30
+ action: string,
31
+ payload: Record<string, unknown> = {}
32
+ ): Promise<T> => {
33
+ const bridge = getBridge();
34
+
35
+ if (!bridge) {
36
+ return Promise.reject(new Error("MiniApp bridge not available"));
37
+ }
38
+
39
+ return bridge.callHandler("MiniAppBridge", {
40
+ action,
41
+ payload,
42
+ }) as Promise<T>;
43
+ };
@@ -0,0 +1,7 @@
1
+ import { callHost } from '../bridge.js';
2
+
3
+ export function useNavigate() {
4
+ return (route, params = {}, options = {}) => {
5
+ callHost("navigate", { type: "native", route, params, options });
6
+ };
7
+ }
@@ -0,0 +1,32 @@
1
+ import { callHost } from "../bridge";
2
+
3
+ /* ================= Types ================= */
4
+
5
+ export type NavigateMode = "push" | "replace";
6
+
7
+ export interface NavigateOptions {
8
+ replace?: boolean;
9
+ popTo?: string;
10
+ }
11
+
12
+ export type NavigateParams = Record<string, unknown>;
13
+
14
+ export type MiniAppRoute = string; // có thể đổi sang union type nếu muốn strict
15
+
16
+ /* ================= Hook ================= */
17
+
18
+ export function useNavigate() {
19
+ return (
20
+ route: MiniAppRoute,
21
+ params: NavigateParams = {},
22
+ options: NavigateOptions = {}
23
+ ): void => {
24
+ // Gửi sang native host
25
+ callHost("navigate", {
26
+ type: "native",
27
+ route,
28
+ params,
29
+ options,
30
+ }).catch(console.error);
31
+ };
32
+ }
@@ -0,0 +1 @@
1
+ export * from './hooks/use-navigate.js';
@@ -0,0 +1 @@
1
+ export * from './hooks/use-navigate';