@jolibox/implement 1.1.4-beta.4
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/.eslintrc.js +3 -0
- package/.rush/temp/package-deps_build.json +104 -0
- package/.rush/temp/shrinkwrap-deps.json +79 -0
- package/README.md +1 -0
- package/dist/common/api-factory/index.d.ts +21 -0
- package/dist/common/api-factory/validator/__tests__/validate/any.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/array.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/arraybuffer.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/boolean.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/enum.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/function.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/literal.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/nullish.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/number.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/object.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/or.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/record.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/string.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/symbol.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/tuple.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/type-asserts.test.d.ts +1 -0
- package/dist/common/api-factory/validator/__tests__/validate/utils.test.d.ts +1 -0
- package/dist/common/api-factory/validator/index.d.ts +29 -0
- package/dist/common/api-factory/validator/validate.d.ts +119 -0
- package/dist/common/can-i-use.d.ts +2 -0
- package/dist/common/context/index.d.ts +16 -0
- package/dist/common/context/types.d.ts +5 -0
- package/dist/common/context/url-parse.d.ts +22 -0
- package/dist/common/http/index.d.ts +13 -0
- package/dist/common/http/uuid.d.ts +2 -0
- package/dist/common/http/xua.d.ts +17 -0
- package/dist/common/report/base-tracker.d.ts +13 -0
- package/dist/common/report/create-trace.d.ts +7 -0
- package/dist/common/report/errors/error-types.d.ts +122 -0
- package/dist/common/report/errors/index.d.ts +13 -0
- package/dist/common/report/errors/report/index.d.ts +51 -0
- package/dist/common/report/errors/report/listeners.d.ts +1 -0
- package/dist/common/report/index.d.ts +3 -0
- package/dist/common/report/task-track/index.d.ts +23 -0
- package/dist/common/report/track.d.ts +3 -0
- package/dist/common/report/types.d.ts +75 -0
- package/dist/h5/ads/ads-action-detection.d.ts +6 -0
- package/dist/h5/ads/anti-cheating.d.ts +61 -0
- package/dist/h5/ads/index.d.ts +275 -0
- package/dist/h5/api/base.d.ts +13 -0
- package/dist/h5/api/get-system-info.d.ts +1 -0
- package/dist/h5/api/index.d.ts +4 -0
- package/dist/h5/api/lifecycle.d.ts +1 -0
- package/dist/h5/api/storage.d.ts +27 -0
- package/dist/h5/api/task.d.ts +1 -0
- package/dist/h5/bootstrap/index.d.ts +1 -0
- package/dist/h5/http/index.d.ts +33 -0
- package/dist/h5/http/utils/__tests__/uuid.test.d.ts +1 -0
- package/dist/h5/http/utils/__tests__/xua.test.d.ts +1 -0
- package/dist/h5/http/utils/index.d.ts +14 -0
- package/dist/h5/http/utils/session.d.ts +1 -0
- package/dist/h5/report/errors/index.d.ts +4 -0
- package/dist/h5/report/event-tracker.d.ts +8 -0
- package/dist/h5/report/index.d.ts +10 -0
- package/dist/h5/report/task-tracker.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5026 -0
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +3743 -0
- package/dist/native/api/base.d.ts +13 -0
- package/dist/native/api/get-system-info.d.ts +1 -0
- package/dist/native/api/index.d.ts +7 -0
- package/dist/native/api/keyboard.d.ts +3 -0
- package/dist/native/api/lifecycle.d.ts +1 -0
- package/dist/native/api/login.d.ts +1 -0
- package/dist/native/api/request.d.ts +1 -0
- package/dist/native/api/storage.d.ts +25 -0
- package/dist/native/api/task.d.ts +1 -0
- package/dist/native/bootstrap/bridge.d.ts +4 -0
- package/dist/native/bootstrap/index.d.ts +1 -0
- package/dist/native/js-bridge/const.d.ts +5 -0
- package/dist/native/js-bridge/index.d.ts +2 -0
- package/dist/native/js-bridge/invoke.d.ts +21 -0
- package/dist/native/js-bridge/js-bridge.d.ts +6 -0
- package/dist/native/js-bridge/report.d.ts +63 -0
- package/dist/native/js-bridge/subscribe.d.ts +8 -0
- package/dist/native/js-bridge/types.d.ts +14 -0
- package/dist/native/js-bridge/utils.d.ts +17 -0
- package/dist/native/js-core/index.d.ts +3 -0
- package/dist/native/js-core/jolibox-js-core.d.ts +45 -0
- package/dist/native/js-core/message-port.d.ts +12 -0
- package/dist/native/js-core/utils.d.ts +7 -0
- package/dist/native/network/create-fetch.d.ts +27 -0
- package/dist/native/network/index.d.ts +11 -0
- package/dist/native/network/report.d.ts +15 -0
- package/dist/native/network/types.d.ts +61 -0
- package/dist/native/network/utils.d.ts +9 -0
- package/dist/native/report/errors/index.d.ts +4 -0
- package/dist/native/report/index.d.ts +10 -0
- package/dist/native/report/task-tracker.d.ts +20 -0
- package/dist/utils/index.d.ts +0 -0
- package/esbuild.config.js +66 -0
- package/implement.build.log +9 -0
- package/package.json +30 -0
- package/src/common/api-factory/index.ts +188 -0
- package/src/common/api-factory/validator/__tests__/validate/any.test.ts +68 -0
- package/src/common/api-factory/validator/__tests__/validate/array.test.ts +402 -0
- package/src/common/api-factory/validator/__tests__/validate/arraybuffer.test.ts +48 -0
- package/src/common/api-factory/validator/__tests__/validate/boolean.test.ts +27 -0
- package/src/common/api-factory/validator/__tests__/validate/enum.test.ts +106 -0
- package/src/common/api-factory/validator/__tests__/validate/function.test.ts +54 -0
- package/src/common/api-factory/validator/__tests__/validate/literal.test.ts +130 -0
- package/src/common/api-factory/validator/__tests__/validate/nullish.test.ts +41 -0
- package/src/common/api-factory/validator/__tests__/validate/number.test.ts +147 -0
- package/src/common/api-factory/validator/__tests__/validate/object.test.ts +131 -0
- package/src/common/api-factory/validator/__tests__/validate/or.test.ts +96 -0
- package/src/common/api-factory/validator/__tests__/validate/record.test.ts +274 -0
- package/src/common/api-factory/validator/__tests__/validate/string.test.ts +187 -0
- package/src/common/api-factory/validator/__tests__/validate/symbol.test.ts +23 -0
- package/src/common/api-factory/validator/__tests__/validate/tuple.test.ts +86 -0
- package/src/common/api-factory/validator/__tests__/validate/type-asserts.test.ts +13 -0
- package/src/common/api-factory/validator/__tests__/validate/utils.test.ts +44 -0
- package/src/common/api-factory/validator/index.ts +107 -0
- package/src/common/api-factory/validator/validate.ts +639 -0
- package/src/common/can-i-use.ts +19 -0
- package/src/common/context/index.ts +91 -0
- package/src/common/context/types.ts +5 -0
- package/src/common/context/url-parse.ts +63 -0
- package/src/common/http/index.ts +29 -0
- package/src/common/http/uuid.ts +11 -0
- package/src/common/http/xua.ts +79 -0
- package/src/common/report/base-tracker.ts +134 -0
- package/src/common/report/create-trace.ts +17 -0
- package/src/common/report/errors/error-types.ts +206 -0
- package/src/common/report/errors/index.ts +20 -0
- package/src/common/report/errors/report/index.ts +63 -0
- package/src/common/report/errors/report/listeners.ts +80 -0
- package/src/common/report/index.ts +3 -0
- package/src/common/report/task-track/index.ts +97 -0
- package/src/common/report/track.ts +49 -0
- package/src/common/report/types.ts +90 -0
- package/src/h5/ads/ads-action-detection.ts +31 -0
- package/src/h5/ads/anti-cheating.ts +244 -0
- package/src/h5/ads/index.ts +641 -0
- package/src/h5/api/base.ts +9 -0
- package/src/h5/api/get-system-info.ts +55 -0
- package/src/h5/api/index.ts +4 -0
- package/src/h5/api/lifecycle.ts +110 -0
- package/src/h5/api/storage.ts +173 -0
- package/src/h5/api/task.ts +197 -0
- package/src/h5/bootstrap/index.ts +16 -0
- package/src/h5/http/index.ts +189 -0
- package/src/h5/http/utils/__tests__/uuid.test.ts +16 -0
- package/src/h5/http/utils/__tests__/xua.test.ts +27 -0
- package/src/h5/http/utils/index.ts +19 -0
- package/src/h5/http/utils/session.ts +10 -0
- package/src/h5/report/errors/index.ts +40 -0
- package/src/h5/report/event-tracker.ts +40 -0
- package/src/h5/report/index.ts +56 -0
- package/src/h5/report/task-tracker.ts +35 -0
- package/src/index.native.ts +7 -0
- package/src/index.ts +9 -0
- package/src/native/api/base.ts +8 -0
- package/src/native/api/get-system-info.ts +41 -0
- package/src/native/api/index.ts +7 -0
- package/src/native/api/keyboard.ts +75 -0
- package/src/native/api/lifecycle.ts +76 -0
- package/src/native/api/login.ts +71 -0
- package/src/native/api/request.ts +154 -0
- package/src/native/api/storage.ts +287 -0
- package/src/native/api/task.ts +267 -0
- package/src/native/bootstrap/bridge.ts +59 -0
- package/src/native/bootstrap/index.ts +58 -0
- package/src/native/js-bridge/const.ts +11 -0
- package/src/native/js-bridge/index.ts +2 -0
- package/src/native/js-bridge/invoke.ts +210 -0
- package/src/native/js-bridge/js-bridge.ts +23 -0
- package/src/native/js-bridge/report.ts +311 -0
- package/src/native/js-bridge/subscribe.ts +50 -0
- package/src/native/js-bridge/types.ts +26 -0
- package/src/native/js-bridge/utils.ts +116 -0
- package/src/native/js-core/index.ts +4 -0
- package/src/native/js-core/jolibox-js-core.ts +188 -0
- package/src/native/js-core/message-port.ts +52 -0
- package/src/native/js-core/utils.ts +9 -0
- package/src/native/network/create-fetch.ts +237 -0
- package/src/native/network/index.ts +15 -0
- package/src/native/network/report.ts +58 -0
- package/src/native/network/types.ts +77 -0
- package/src/native/network/utils.ts +90 -0
- package/src/native/report/errors/index.ts +27 -0
- package/src/native/report/index.ts +51 -0
- package/src/native/report/task-tracker.ts +64 -0
- package/src/native/types/global.d.ts +26 -0
- package/src/native/types/native-method-map.d.ts +282 -0
- package/src/native/types/native-method.d.ts +30 -0
- package/src/utils/index.ts +0 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,3743 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
|
|
30
|
+
// src/native/js-bridge/utils.ts
|
|
31
|
+
function isNativeBuffers(x2) {
|
|
32
|
+
return Boolean(x2?.__nativeBuffers__);
|
|
33
|
+
}
|
|
34
|
+
function unpack(data) {
|
|
35
|
+
if (typeof data === "string") {
|
|
36
|
+
try {
|
|
37
|
+
data = JSON.parse(data);
|
|
38
|
+
} catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof data !== "object" || data === null) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
if (!isNativeBuffers(data)) return data;
|
|
46
|
+
const nativeBuffers = data.__nativeBuffers__;
|
|
47
|
+
delete data.__nativeBuffers__;
|
|
48
|
+
if (nativeBuffers) {
|
|
49
|
+
for (let i = 0; i < nativeBuffers.length; i++) {
|
|
50
|
+
const item = nativeBuffers[i];
|
|
51
|
+
if (item) {
|
|
52
|
+
let tmp;
|
|
53
|
+
if (item.value) {
|
|
54
|
+
tmp = item.value;
|
|
55
|
+
} else if (item.base64) {
|
|
56
|
+
tmp = decodeFromUi8Base64(item.base64);
|
|
57
|
+
}
|
|
58
|
+
if (typeof tmp !== "undefined" && tmp instanceof ArrayBuffer) {
|
|
59
|
+
data[item.key] = tmp;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
function pack(_data = {}, useArrayBuffer = false) {
|
|
67
|
+
const data = _data;
|
|
68
|
+
const needTransAttrs = [];
|
|
69
|
+
for (const [key, item] of Object.entries(data)) {
|
|
70
|
+
if (item !== void 0 && item instanceof ArrayBuffer && item.byteLength !== void 0) {
|
|
71
|
+
const obj = useArrayBuffer ? { value: item, key } : {
|
|
72
|
+
base64: encodeToUi8Base64(item),
|
|
73
|
+
key
|
|
74
|
+
};
|
|
75
|
+
needTransAttrs.push(obj);
|
|
76
|
+
delete data[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (needTransAttrs.length > 0) {
|
|
80
|
+
data.__nativeBuffers__ = needTransAttrs;
|
|
81
|
+
}
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
var decodeFromUi8Base64, encodeToUi8Base64;
|
|
85
|
+
var init_utils = __esm({
|
|
86
|
+
"src/native/js-bridge/utils.ts"() {
|
|
87
|
+
"use strict";
|
|
88
|
+
decodeFromUi8Base64 = (string) => {
|
|
89
|
+
const base64String = atob(string);
|
|
90
|
+
const len = base64String.length;
|
|
91
|
+
const ui8aReader = new Uint8Array(len);
|
|
92
|
+
for (let i = 0; i < len; i++) {
|
|
93
|
+
ui8aReader[i] = base64String.charCodeAt(i);
|
|
94
|
+
}
|
|
95
|
+
return ui8aReader.buffer;
|
|
96
|
+
};
|
|
97
|
+
encodeToUi8Base64 = (arrayBuffer) => {
|
|
98
|
+
let string = "";
|
|
99
|
+
const ui8aReader = new Uint8Array(arrayBuffer);
|
|
100
|
+
const len = ui8aReader.byteLength;
|
|
101
|
+
for (let i = 0; i < len; i++) {
|
|
102
|
+
string += String.fromCharCode(ui8aReader[i]);
|
|
103
|
+
}
|
|
104
|
+
return btoa(string);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// ../common/dist/index.es.js
|
|
110
|
+
function M(n2) {
|
|
111
|
+
return new Promise((e) => {
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
e();
|
|
114
|
+
}, n2);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function b(n2) {
|
|
118
|
+
return typeof n2 == "string";
|
|
119
|
+
}
|
|
120
|
+
function ie(n2) {
|
|
121
|
+
return typeof n2 == "object" && n2 !== null && !Array.isArray(n2) && !(n2 instanceof RegExp) && !(n2 instanceof Date);
|
|
122
|
+
}
|
|
123
|
+
function Ce(n2) {
|
|
124
|
+
return typeof n2 == "object" && Array.isArray(n2);
|
|
125
|
+
}
|
|
126
|
+
function se(n2) {
|
|
127
|
+
return typeof n2 > "u";
|
|
128
|
+
}
|
|
129
|
+
function N(n2) {
|
|
130
|
+
return se(n2) || n2 === null;
|
|
131
|
+
}
|
|
132
|
+
function A(n2) {
|
|
133
|
+
return typeof n2 == "function";
|
|
134
|
+
}
|
|
135
|
+
function Oe(n2) {
|
|
136
|
+
return ie(n2) && A(n2.then);
|
|
137
|
+
}
|
|
138
|
+
function x(n2) {
|
|
139
|
+
let e = n2, r = null, t3 = function(...o) {
|
|
140
|
+
return r || (r = new e(...o)), r;
|
|
141
|
+
};
|
|
142
|
+
return t3.prototype = e.prototype, t3;
|
|
143
|
+
}
|
|
144
|
+
function ke(n2, e, r) {
|
|
145
|
+
if (typeof r != "function") throw new Error("[Jolibox SDK]Customizer must be a function");
|
|
146
|
+
function t3(o, i) {
|
|
147
|
+
for (let s in i) if (Object.prototype.hasOwnProperty.call(i, s)) {
|
|
148
|
+
let l = o[s], a = i[s], c = r(l, a, s, o, i);
|
|
149
|
+
c !== void 0 ? o[s] = c : U(a) && U(l) ? o[s] = t3({ ...l }, a) : Array.isArray(a) && Array.isArray(l) ? o[s] = [...l, ...a] : o[s] = a;
|
|
150
|
+
}
|
|
151
|
+
return o;
|
|
152
|
+
}
|
|
153
|
+
return t3(n2, e);
|
|
154
|
+
}
|
|
155
|
+
function U(n2) {
|
|
156
|
+
return n2 && typeof n2 == "object" && n2.constructor === Object;
|
|
157
|
+
}
|
|
158
|
+
function Le(n2, e) {
|
|
159
|
+
if (Array.isArray(n2)) return n2.concat(e);
|
|
160
|
+
}
|
|
161
|
+
function Ue(n2, e, r = {}) {
|
|
162
|
+
let t3 = null, o, i, s, { leading: l = false, trailing: a = true } = r, c = () => (s = n2.apply(i, o), o = void 0, i = void 0, s), I = function(...te) {
|
|
163
|
+
o = te, i = this;
|
|
164
|
+
let w = l && !t3;
|
|
165
|
+
if (t3 && clearTimeout(t3), t3 = setTimeout(() => {
|
|
166
|
+
t3 = null, a && !w && c();
|
|
167
|
+
}, e), w) return c();
|
|
168
|
+
};
|
|
169
|
+
return I.cancel = () => {
|
|
170
|
+
t3 && clearTimeout(t3), t3 = null, o = i = void 0;
|
|
171
|
+
}, I.flush = () => {
|
|
172
|
+
if (t3) return clearTimeout(t3), t3 = null, c();
|
|
173
|
+
}, I;
|
|
174
|
+
}
|
|
175
|
+
function de(n2, e) {
|
|
176
|
+
return (...r) => e(n2, ...r);
|
|
177
|
+
}
|
|
178
|
+
function He(n2) {
|
|
179
|
+
return (e) => de(e, function(r, ...t3) {
|
|
180
|
+
if (typeof r == "function") try {
|
|
181
|
+
return r.apply(this, t3);
|
|
182
|
+
} catch (o) {
|
|
183
|
+
n2(new v(`${o}`));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function R(n2) {
|
|
188
|
+
return (...e) => {
|
|
189
|
+
(globalThis.VConsole?.[n2] ?? globalThis.console[n2])(...e);
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function ce(n2) {
|
|
193
|
+
return new Promise((e) => ee(n2)(e));
|
|
194
|
+
}
|
|
195
|
+
function ee(n2) {
|
|
196
|
+
return (e, r = null) => {
|
|
197
|
+
let t3 = false;
|
|
198
|
+
return n2((i) => {
|
|
199
|
+
if (!t3) return t3 = true, e.call(r, i);
|
|
200
|
+
}, null);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function pe(n2, e) {
|
|
204
|
+
return ((t3) => {
|
|
205
|
+
let o, i = { onWillAddFirstListener() {
|
|
206
|
+
o = t3(s.fire, s);
|
|
207
|
+
} }, s = new u(i);
|
|
208
|
+
return s.event;
|
|
209
|
+
})((t3, o = null) => n2((i) => e(i) && t3.call(o, i), null));
|
|
210
|
+
}
|
|
211
|
+
function ne(n2, e) {
|
|
212
|
+
let r = Math.min(n2.length, e.length);
|
|
213
|
+
for (let t3 = 0; t3 < r; t3++) Ee(n2[t3], e[t3]);
|
|
214
|
+
}
|
|
215
|
+
function Ee(n2, e) {
|
|
216
|
+
if (b(e)) {
|
|
217
|
+
if (typeof n2 !== e) throw new Error(`argument does not match constraint: typeof ${e}`);
|
|
218
|
+
} else if (A(e)) {
|
|
219
|
+
try {
|
|
220
|
+
if (n2 instanceof e) return;
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
if (!N(n2) && n2.constructor === e || e.length === 1 && e.call(void 0, n2) === true) return;
|
|
224
|
+
throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function Vn() {
|
|
228
|
+
if (globalThis[P]) return globalThis[P];
|
|
229
|
+
let n2 = new p(), e = new y(), r = { registerCommand(t3, o, i) {
|
|
230
|
+
n2.registerCommand({ id: t3, handler: o, metadata: i });
|
|
231
|
+
}, executeCommand(t3, ...o) {
|
|
232
|
+
return e.executeCommand(t3, ...o);
|
|
233
|
+
}, excuteCommandSync(t3, ...o) {
|
|
234
|
+
return e.executeCommandThowErr(t3, ...o);
|
|
235
|
+
} };
|
|
236
|
+
return globalThis[P] = r, r;
|
|
237
|
+
}
|
|
238
|
+
var k, re, oe, g, L, ae, T, m, f, v, H, J, z, B, $, Q, X, Y, q, Z, me, Be, d, C, le, E, u, _, h, ue, O, fe, En, p, y, P;
|
|
239
|
+
var init_index_es = __esm({
|
|
240
|
+
"../common/dist/index.es.js"() {
|
|
241
|
+
"use strict";
|
|
242
|
+
k = Object.defineProperty;
|
|
243
|
+
re = Object.getOwnPropertyDescriptor;
|
|
244
|
+
oe = (n2, e) => {
|
|
245
|
+
for (var r in e) k(n2, r, { get: e[r], enumerable: true });
|
|
246
|
+
};
|
|
247
|
+
g = (n2, e, r, t3) => {
|
|
248
|
+
for (var o = t3 > 1 ? void 0 : t3 ? re(e, r) : e, i = n2.length - 1, s; i >= 0; i--) (s = n2[i]) && (o = (t3 ? s(e, r, o) : s(o)) || o);
|
|
249
|
+
return t3 && o && k(e, r, o), o;
|
|
250
|
+
};
|
|
251
|
+
L = class {
|
|
252
|
+
constructor() {
|
|
253
|
+
this.state = "pending";
|
|
254
|
+
this.promise = new Promise((e, r) => {
|
|
255
|
+
this.resolve = (t3) => {
|
|
256
|
+
this.state === "pending" && (this.state = "fulfilled", e(t3));
|
|
257
|
+
}, this.reject = (t3) => {
|
|
258
|
+
this.state === "pending" && (this.state = "rejected", r(t3));
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
ae = ((a) => (a[a.DEVELOPER_FILE_NOT_FOUND = 0] = "DEVELOPER_FILE_NOT_FOUND", a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG = 1] = "INTERNAL_IOS_CAN_NOT_FOUND_PKG", a[a.USER_IOS_LOAD_TIMEOUT = 2] = "USER_IOS_LOAD_TIMEOUT", a[a.INTERNAL_IOS_PKG_LOAD_ERROR = 3] = "INTERNAL_IOS_PKG_LOAD_ERROR", a[a.INTERNAL_IOS_PKG_PARSE_FAIL = 4] = "INTERNAL_IOS_PKG_PARSE_FAIL", a[a.USER_IOS_GET_EMPTY_DATA = 5] = "USER_IOS_GET_EMPTY_DATA", a[a.USER_ANDROID_GET_PKG_FAIL = 6] = "USER_ANDROID_GET_PKG_FAIL", a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE = 7] = "DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE", a))(ae || {});
|
|
264
|
+
T = class extends Error {
|
|
265
|
+
constructor(e) {
|
|
266
|
+
if (typeof e == "string") {
|
|
267
|
+
super(e), this.priority = "P1";
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
super(e.message), this.priority = "P1", this.stack = e.stack, this.raw = e;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
m = class extends T {
|
|
274
|
+
constructor() {
|
|
275
|
+
super(...arguments);
|
|
276
|
+
this.kind = "INTERNAL_ERROR";
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
f = class extends T {
|
|
280
|
+
constructor() {
|
|
281
|
+
super(...arguments);
|
|
282
|
+
this.kind = "USER_ERROR";
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
v = class extends f {
|
|
286
|
+
constructor(r, t3, o) {
|
|
287
|
+
super(r);
|
|
288
|
+
this.message = r;
|
|
289
|
+
this.errNo = t3;
|
|
290
|
+
this.name = "USER_CUSTOM_ERROR";
|
|
291
|
+
this.errMsg = r, o && (this.extra = Object.assign({}, this.extra, o));
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
H = class extends m {
|
|
295
|
+
constructor() {
|
|
296
|
+
super(...arguments);
|
|
297
|
+
this.name = "INTERNAL_SCHEMA_PARSE_ERROR";
|
|
298
|
+
this.priority = "P0";
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
J = class extends m {
|
|
302
|
+
constructor() {
|
|
303
|
+
super(...arguments);
|
|
304
|
+
this.name = "INTERNAL_INVOKE_NATIVE_ERROR";
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
z = class extends m {
|
|
308
|
+
constructor(r, t3, o, i) {
|
|
309
|
+
super(r);
|
|
310
|
+
this.errNo = t3;
|
|
311
|
+
this.name = "INTERNAL_APPLY_NATIVE_ERROR";
|
|
312
|
+
this.errorType = o, this.errorCode = i;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
B = class extends m {
|
|
316
|
+
constructor() {
|
|
317
|
+
super(...arguments);
|
|
318
|
+
this.name = "INTERNAL_JSCORE_ERROR";
|
|
319
|
+
this.priority = "P0";
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
$ = class extends m {
|
|
323
|
+
constructor(r, t3) {
|
|
324
|
+
super(r);
|
|
325
|
+
this.message = r;
|
|
326
|
+
this.name = "INTERNAL_CONTEXT_ERROR";
|
|
327
|
+
this.property = t3;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
Q = class extends T {
|
|
331
|
+
constructor(r, t3, o, i, s) {
|
|
332
|
+
super(r);
|
|
333
|
+
this.message = r;
|
|
334
|
+
this.code = t3;
|
|
335
|
+
this.kind = "API_ERROR";
|
|
336
|
+
this.name = "API_ERROR";
|
|
337
|
+
o && (this.errorType = o), i !== void 0 && (this.stack = i), s && (this.priority = s);
|
|
338
|
+
}
|
|
339
|
+
toJSON() {
|
|
340
|
+
return { message: this.message, stack: this.stack, name: this.name, code: this.code, errorType: this.errorType };
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
X = class extends m {
|
|
344
|
+
constructor() {
|
|
345
|
+
super(...arguments);
|
|
346
|
+
this.name = "INTERNAL_METRIC_REPORT_ERROR";
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
Y = class extends m {
|
|
350
|
+
constructor() {
|
|
351
|
+
super(...arguments);
|
|
352
|
+
this.name = "INTERNAL_REPORTER_ERROR";
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
q = { log: R("log"), warn: R("warn"), info: R("info"), error: R("error"), debug: R("debug") };
|
|
356
|
+
Object.assign(globalThis, { logger: q });
|
|
357
|
+
Z = Symbol.for("Jolibox.canIUseMap");
|
|
358
|
+
me = {};
|
|
359
|
+
globalThis[Z] = me;
|
|
360
|
+
Be = { get config() {
|
|
361
|
+
return globalThis[Z];
|
|
362
|
+
} };
|
|
363
|
+
d = class n {
|
|
364
|
+
static {
|
|
365
|
+
this.Undefined = new n(void 0);
|
|
366
|
+
}
|
|
367
|
+
constructor(e) {
|
|
368
|
+
this.element = e, this.next = n.Undefined, this.prev = n.Undefined;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
C = class {
|
|
372
|
+
constructor() {
|
|
373
|
+
this._first = d.Undefined;
|
|
374
|
+
this._last = d.Undefined;
|
|
375
|
+
this._size = 0;
|
|
376
|
+
}
|
|
377
|
+
get size() {
|
|
378
|
+
return this._size;
|
|
379
|
+
}
|
|
380
|
+
isEmpty() {
|
|
381
|
+
return this._first === d.Undefined;
|
|
382
|
+
}
|
|
383
|
+
clear() {
|
|
384
|
+
let e = this._first;
|
|
385
|
+
for (; e !== d.Undefined; ) {
|
|
386
|
+
let r = e.next;
|
|
387
|
+
e.prev = d.Undefined, e.next = d.Undefined, e = r;
|
|
388
|
+
}
|
|
389
|
+
this._first = d.Undefined, this._last = d.Undefined, this._size = 0;
|
|
390
|
+
}
|
|
391
|
+
unshift(e) {
|
|
392
|
+
return this._insert(e, false);
|
|
393
|
+
}
|
|
394
|
+
push(e) {
|
|
395
|
+
return this._insert(e, true);
|
|
396
|
+
}
|
|
397
|
+
_insert(e, r) {
|
|
398
|
+
let t3 = new d(e);
|
|
399
|
+
if (this._first === d.Undefined) this._first = t3, this._last = t3;
|
|
400
|
+
else if (r) {
|
|
401
|
+
let i = this._last;
|
|
402
|
+
this._last = t3, t3.prev = i, i.next = t3;
|
|
403
|
+
} else {
|
|
404
|
+
let i = this._first;
|
|
405
|
+
this._first = t3, t3.next = i, i.prev = t3;
|
|
406
|
+
}
|
|
407
|
+
this._size += 1;
|
|
408
|
+
let o = false;
|
|
409
|
+
return () => {
|
|
410
|
+
o || (o = true, this._remove(t3));
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
shift() {
|
|
414
|
+
if (this._first !== d.Undefined) {
|
|
415
|
+
let e = this._first.element;
|
|
416
|
+
return this._remove(this._first), e;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
pop() {
|
|
420
|
+
if (this._last !== d.Undefined) {
|
|
421
|
+
let e = this._last.element;
|
|
422
|
+
return this._remove(this._last), e;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
_remove(e) {
|
|
426
|
+
if (e.prev !== d.Undefined && e.next !== d.Undefined) {
|
|
427
|
+
let r = e.prev;
|
|
428
|
+
r.next = e.next, e.next.prev = r;
|
|
429
|
+
} else e.prev === d.Undefined && e.next === d.Undefined ? (this._first = d.Undefined, this._last = d.Undefined) : e.next === d.Undefined ? (this._last = this._last.prev, this._last.next = d.Undefined) : e.prev === d.Undefined && (this._first = this._first.next, this._first.prev = d.Undefined);
|
|
430
|
+
this._size -= 1;
|
|
431
|
+
}
|
|
432
|
+
*[Symbol.iterator]() {
|
|
433
|
+
let e = this._first;
|
|
434
|
+
for (; e !== d.Undefined; ) yield e.element, e = e.next;
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
le = 0;
|
|
438
|
+
E = class {
|
|
439
|
+
constructor(e) {
|
|
440
|
+
this.value = e;
|
|
441
|
+
this.id = le++;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
u = class {
|
|
445
|
+
constructor(e) {
|
|
446
|
+
this.options = e;
|
|
447
|
+
this._size = 0;
|
|
448
|
+
}
|
|
449
|
+
dispose(e) {
|
|
450
|
+
this._disposed || (this._disposed = true, this._listeners && (e ? (this._listeners instanceof E && (this._listeners = [this._listeners]), this._listeners = this._listeners.filter((r) => r?.value === e)) : (this._listeners = void 0, this._size = 0)), this.options?.onDidRemoveLastListener?.());
|
|
451
|
+
}
|
|
452
|
+
get event() {
|
|
453
|
+
return this._event ??= (e, r) => {
|
|
454
|
+
if (this._disposed) return () => {
|
|
455
|
+
console.info("[Jolibox SDK] Emitter is _disposed");
|
|
456
|
+
};
|
|
457
|
+
r && (e = e.bind(r));
|
|
458
|
+
let t3 = new E(e);
|
|
459
|
+
this._listeners ? this._listeners instanceof E ? this._listeners = [this._listeners, t3] : this._listeners.push(t3) : (this.options?.onWillAddFirstListener?.(this), this._listeners = t3, this.options?.onDidFirstListener?.(this)), this.options?.onDidAddListener?.(this), this._size++;
|
|
460
|
+
}, this._event;
|
|
461
|
+
}
|
|
462
|
+
_deliver(e, r) {
|
|
463
|
+
if (!e) return;
|
|
464
|
+
let t3 = this.options?.onListenerError || Error.constructor;
|
|
465
|
+
if (!t3) {
|
|
466
|
+
e.value(r);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
e.value(r);
|
|
471
|
+
} catch (o) {
|
|
472
|
+
t3(o);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
fire(e) {
|
|
476
|
+
this._listeners && (this._listeners instanceof E ? this._deliver(this._listeners, e) : this._listeners.forEach((r) => this._deliver(r, e)));
|
|
477
|
+
}
|
|
478
|
+
hasListeners() {
|
|
479
|
+
return this._size > 0;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
_ = class {
|
|
483
|
+
constructor() {
|
|
484
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
485
|
+
this.listerHandlerMap = /* @__PURE__ */ new WeakMap();
|
|
486
|
+
this.cachedEventQueue = /* @__PURE__ */ new Map();
|
|
487
|
+
}
|
|
488
|
+
on(e, r) {
|
|
489
|
+
let t3 = this.listeners.get(e) ?? new u(), o = (s) => r(...s.args);
|
|
490
|
+
this.listerHandlerMap.set(r, o), t3.event(o), this.listeners.set(e, t3);
|
|
491
|
+
let i = this.cachedEventQueue.get(e);
|
|
492
|
+
if (i) for (; i.size > 0; ) t3.fire({ event: e, ...i.shift() });
|
|
493
|
+
}
|
|
494
|
+
off(e, r) {
|
|
495
|
+
let t3 = this.listeners.get(e);
|
|
496
|
+
if (t3) {
|
|
497
|
+
let o = this.listerHandlerMap.get(r);
|
|
498
|
+
t3.dispose(o);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
emit(e, ...r) {
|
|
502
|
+
let t3 = this.listeners.get(e);
|
|
503
|
+
if (t3) t3.fire({ event: e, args: r });
|
|
504
|
+
else {
|
|
505
|
+
let o = this.cachedEventQueue.get(e);
|
|
506
|
+
o || (o = new C(), this.cachedEventQueue.set(e, o)), o.push({ args: r });
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
h = {};
|
|
511
|
+
oe(h, { None: () => ue, filter: () => pe, once: () => ee, toPromise: () => ce });
|
|
512
|
+
ue = () => {
|
|
513
|
+
console.log("[Jolibox SDK] None Event");
|
|
514
|
+
};
|
|
515
|
+
O = Symbol.for("Jolibox.hostEmitter");
|
|
516
|
+
fe = () => {
|
|
517
|
+
let n2 = new _();
|
|
518
|
+
return globalThis[O] || (globalThis[O] = { on: n2.on.bind(n2), off: n2.off.bind(n2), emit: n2.emit.bind(n2) }), globalThis[O];
|
|
519
|
+
};
|
|
520
|
+
En = fe();
|
|
521
|
+
p = class {
|
|
522
|
+
constructor() {
|
|
523
|
+
this._commands = /* @__PURE__ */ new Map();
|
|
524
|
+
this._onDidRegisterCommand = new u();
|
|
525
|
+
this.onDidRegisterCommand = this._onDidRegisterCommand.event;
|
|
526
|
+
console.log("[Jolibox SDK] command registry");
|
|
527
|
+
}
|
|
528
|
+
registerCommand(e) {
|
|
529
|
+
if (!e) throw new Error("invalid command");
|
|
530
|
+
if (e.metadata && Array.isArray(e.metadata.args)) {
|
|
531
|
+
let o = [];
|
|
532
|
+
for (let s of e.metadata.args) o.push(s.constraint);
|
|
533
|
+
let i = e.handler;
|
|
534
|
+
e.handler = function(...s) {
|
|
535
|
+
return ne(s, o), i(...s);
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
let { id: r } = e;
|
|
539
|
+
this._commands.get(r) && console.info(`[Jolibox SDK] duplicated command is registered ${r}`), this._commands.set(r, e), this._onDidRegisterCommand.fire(r);
|
|
540
|
+
}
|
|
541
|
+
getCommand(e) {
|
|
542
|
+
return this._commands.get(e);
|
|
543
|
+
}
|
|
544
|
+
getCommands() {
|
|
545
|
+
let e = /* @__PURE__ */ new Map();
|
|
546
|
+
for (let r of this._commands.keys()) {
|
|
547
|
+
let t3 = this.getCommand(r);
|
|
548
|
+
t3 && e.set(r, t3);
|
|
549
|
+
}
|
|
550
|
+
return e;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
p = g([x], p);
|
|
554
|
+
y = class {
|
|
555
|
+
constructor() {
|
|
556
|
+
this._onWillExecuteCommand = new u();
|
|
557
|
+
this.onWillExecuteCommand = this._onWillExecuteCommand.event;
|
|
558
|
+
this._onDidExecuteCommand = new u();
|
|
559
|
+
this.onDidExecuteCommand = this._onDidExecuteCommand.event;
|
|
560
|
+
this.registry = new p();
|
|
561
|
+
this._starActivation = null;
|
|
562
|
+
}
|
|
563
|
+
_activateStar() {
|
|
564
|
+
return this._starActivation || (this._starActivation = M(3e4)), this._starActivation;
|
|
565
|
+
}
|
|
566
|
+
async executeCommand(e, ...r) {
|
|
567
|
+
return this.registry.getCommand(e) ? this._tryExecuteCommand(e, r) : (await Promise.all([Promise.race([this._activateStar(), h.toPromise(h.filter(this.registry.onDidRegisterCommand, (o) => o === e))])]), this._tryExecuteCommand(e, r));
|
|
568
|
+
}
|
|
569
|
+
executeCommandThowErr(e, ...r) {
|
|
570
|
+
if (!!!this.registry.getCommand(e)) throw new Error(`command '${e}' not found`);
|
|
571
|
+
let o = this.registry.getCommand(e);
|
|
572
|
+
this._onWillExecuteCommand.fire({ commandId: e, args: r });
|
|
573
|
+
let i = this.invokeFunction(o.handler, ...r);
|
|
574
|
+
return this._onDidExecuteCommand.fire({ commandId: e, args: r }), i;
|
|
575
|
+
}
|
|
576
|
+
_tryExecuteCommand(e, r) {
|
|
577
|
+
let t3 = this.registry.getCommand(e);
|
|
578
|
+
if (!t3) return Promise.reject(new Error(`command '${e}' not found`));
|
|
579
|
+
try {
|
|
580
|
+
this._onWillExecuteCommand.fire({ commandId: e, args: r });
|
|
581
|
+
let o = this.invokeFunction(t3.handler, ...r);
|
|
582
|
+
return this._onDidExecuteCommand.fire({ commandId: e, args: r }), Promise.resolve(o);
|
|
583
|
+
} catch (o) {
|
|
584
|
+
return Promise.reject(o);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
invokeFunction(e, ...r) {
|
|
588
|
+
let t3 = false;
|
|
589
|
+
try {
|
|
590
|
+
return e(...r);
|
|
591
|
+
} finally {
|
|
592
|
+
t3 = true;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
y = g([x], y);
|
|
597
|
+
P = Symbol.for("Jolibox.commands");
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// src/common/report/errors/report/index.ts
|
|
602
|
+
function reportError(error, options = {}) {
|
|
603
|
+
errorReportCollector.emit("ERROR_REPORT", {
|
|
604
|
+
error,
|
|
605
|
+
options
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
var errorReportCollector, errorReportEmitter;
|
|
609
|
+
var init_report = __esm({
|
|
610
|
+
"src/common/report/errors/report/index.ts"() {
|
|
611
|
+
"use strict";
|
|
612
|
+
init_index_es();
|
|
613
|
+
init_index_es();
|
|
614
|
+
errorReportCollector = new _();
|
|
615
|
+
errorReportEmitter = new _();
|
|
616
|
+
reportError.debounce = Ue(reportError, 50, { leading: true });
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// src/common/report/errors/index.ts
|
|
621
|
+
function formatErrorCode(method, code) {
|
|
622
|
+
return `[${method}]:${code}`;
|
|
623
|
+
}
|
|
624
|
+
var createAPIError, createUserAPIError;
|
|
625
|
+
var init_errors = __esm({
|
|
626
|
+
"src/common/report/errors/index.ts"() {
|
|
627
|
+
"use strict";
|
|
628
|
+
init_report();
|
|
629
|
+
init_index_es();
|
|
630
|
+
init_report();
|
|
631
|
+
createAPIError = (error, params) => {
|
|
632
|
+
return new Q(params?.errMsg ?? error.msg ?? "", error.code, error.type);
|
|
633
|
+
};
|
|
634
|
+
createUserAPIError = (msg) => {
|
|
635
|
+
return new v(msg);
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// src/native/js-bridge/const.ts
|
|
641
|
+
var BUFFER_METHODS, BACKGROUND_FORBIDDEN_METHODS, SYNC_METHODS;
|
|
642
|
+
var init_const = __esm({
|
|
643
|
+
"src/native/js-bridge/const.ts"() {
|
|
644
|
+
"use strict";
|
|
645
|
+
BUFFER_METHODS = [];
|
|
646
|
+
BACKGROUND_FORBIDDEN_METHODS = [];
|
|
647
|
+
SYNC_METHODS = ["env", "createRequestTask", "login"];
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// src/native/js-bridge/report.ts
|
|
652
|
+
function createReportInvokeMetrics(jsCore2, onNative2) {
|
|
653
|
+
if (!monitorHasInitialized) {
|
|
654
|
+
invokeMonitor = new MetricsMonitor({
|
|
655
|
+
eventName: "jolibox_invoke",
|
|
656
|
+
tagNameOrder: ["status", "method", "errNo", "errMsg", "isForeground"],
|
|
657
|
+
metricName: "duration",
|
|
658
|
+
reporter(data) {
|
|
659
|
+
jsCore2.invoke("track", JSON.stringify({ event: "reportMetrics", data }), -1);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
invokeJSToNativeMonitor = new MetricsMonitor({
|
|
663
|
+
eventName: "jolibox_invoke_js2native",
|
|
664
|
+
tagNameOrder: ["status", "method", "isForeground"],
|
|
665
|
+
metricName: "duration",
|
|
666
|
+
reporter(data) {
|
|
667
|
+
jsCore2.invoke("track", JSON.stringify({ event: "reportMetrics", data }), -1);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
invokeNativeToJSMonitor = new MetricsMonitor({
|
|
671
|
+
eventName: "jolibox_invoke_native2js",
|
|
672
|
+
tagNameOrder: ["status", "method", "isForeground"],
|
|
673
|
+
metricName: "duration",
|
|
674
|
+
reporter(data) {
|
|
675
|
+
jsCore2.invoke("track", JSON.stringify({ event: "reportMetrics", data }), -1);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
onNative2("onJoliboxEnterBackground", () => {
|
|
679
|
+
invokeMonitor.flush();
|
|
680
|
+
invokeJSToNativeMonitor.flush();
|
|
681
|
+
invokeNativeToJSMonitor.flush();
|
|
682
|
+
});
|
|
683
|
+
monitorHasInitialized = true;
|
|
684
|
+
}
|
|
685
|
+
function report(invokeMetrics) {
|
|
686
|
+
const {
|
|
687
|
+
method,
|
|
688
|
+
args,
|
|
689
|
+
startTime,
|
|
690
|
+
isForeground,
|
|
691
|
+
errMsg = `${method}:fail no errMsg`,
|
|
692
|
+
errNo = 0,
|
|
693
|
+
__timing = {
|
|
694
|
+
receiveJSInvoke: 0,
|
|
695
|
+
invokeCallback: 0
|
|
696
|
+
}
|
|
697
|
+
} = invokeMetrics;
|
|
698
|
+
const { receiveJSInvoke, invokeCallback } = __timing;
|
|
699
|
+
const status = errMsg.match(/\S:(\S+)\s?/)?.[1] ?? "fail";
|
|
700
|
+
invokeMonitor.report({
|
|
701
|
+
status,
|
|
702
|
+
method: normalizeMethod2(method, args),
|
|
703
|
+
errNo: `${errNo}`,
|
|
704
|
+
errMsg,
|
|
705
|
+
isForeground,
|
|
706
|
+
duration: Date.now() - startTime
|
|
707
|
+
});
|
|
708
|
+
if (startTime && receiveJSInvoke && invokeCallback) {
|
|
709
|
+
invokeJSToNativeMonitor.report({
|
|
710
|
+
status,
|
|
711
|
+
method,
|
|
712
|
+
isForeground,
|
|
713
|
+
duration: Number((receiveJSInvoke - startTime).toFixed(3))
|
|
714
|
+
});
|
|
715
|
+
invokeNativeToJSMonitor.report({
|
|
716
|
+
status,
|
|
717
|
+
method,
|
|
718
|
+
isForeground,
|
|
719
|
+
duration: Number((Date.now() - invokeCallback).toFixed(3))
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function normalizeMethod2(method, args) {
|
|
724
|
+
if (method === "callHostMethod" || method === "callHostMethodSync") {
|
|
725
|
+
if (args?.method) {
|
|
726
|
+
return `${method}-${args.method}`;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return method;
|
|
730
|
+
}
|
|
731
|
+
return report;
|
|
732
|
+
}
|
|
733
|
+
var getType, MetricsMonitor, monitorHasInitialized, invokeMonitor, invokeJSToNativeMonitor, invokeNativeToJSMonitor;
|
|
734
|
+
var init_report2 = __esm({
|
|
735
|
+
"src/native/js-bridge/report.ts"() {
|
|
736
|
+
"use strict";
|
|
737
|
+
init_index_es();
|
|
738
|
+
getType = (type) => {
|
|
739
|
+
if (type === "pv") return type;
|
|
740
|
+
return "default";
|
|
741
|
+
};
|
|
742
|
+
MetricsMonitor = class {
|
|
743
|
+
constructor(config2) {
|
|
744
|
+
this.interval = 30;
|
|
745
|
+
this.lastReportTime = 0;
|
|
746
|
+
this.cache = {};
|
|
747
|
+
const { reporter, interval = 30, eventName, tagNameOrder, metricName, type } = config2;
|
|
748
|
+
this.reporter = reporter;
|
|
749
|
+
this.interval = interval;
|
|
750
|
+
this.eventName = eventName;
|
|
751
|
+
this.tagNameOrder = tagNameOrder;
|
|
752
|
+
this.metricName = metricName;
|
|
753
|
+
this.type = getType(type);
|
|
754
|
+
}
|
|
755
|
+
report(point) {
|
|
756
|
+
if (this.type === "pv") {
|
|
757
|
+
this.addPVPoint(point);
|
|
758
|
+
} else {
|
|
759
|
+
this.addPoint(point);
|
|
760
|
+
}
|
|
761
|
+
this.tryReport(false);
|
|
762
|
+
}
|
|
763
|
+
flush() {
|
|
764
|
+
this.tryReport(true);
|
|
765
|
+
}
|
|
766
|
+
tryReport(force) {
|
|
767
|
+
if (!Object.keys(this.cache).length) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (force) {
|
|
771
|
+
this.reporter(this.processPoints(this.cache));
|
|
772
|
+
this.clearPoints();
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
this.lastReportTime = this.lastReportTime || Date.now();
|
|
776
|
+
if (Date.now() - this.lastReportTime >= this.interval * 1e3) {
|
|
777
|
+
this.reporter(this.processPoints(this.cache));
|
|
778
|
+
this.clearPoints();
|
|
779
|
+
this.lastReportTime = Date.now();
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
addPoint(point) {
|
|
783
|
+
const safeSetVal = (target, props, metricName, point2) => {
|
|
784
|
+
const currentProp = props.shift();
|
|
785
|
+
if (currentProp) {
|
|
786
|
+
const currentVal = point2[currentProp];
|
|
787
|
+
if (!target[currentVal]) target[currentVal] = {};
|
|
788
|
+
safeSetVal(target[currentVal], props, metricName, point2);
|
|
789
|
+
} else {
|
|
790
|
+
if (!target[metricName]) target[metricName] = [];
|
|
791
|
+
target[metricName].push(point2[metricName]);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
safeSetVal(this.cache, [...this.tagNameOrder], this.metricName, point);
|
|
795
|
+
}
|
|
796
|
+
addPVPoint(point) {
|
|
797
|
+
const safeSetVal = (target, props, metricName, relation) => {
|
|
798
|
+
const currentProp = props.shift();
|
|
799
|
+
if (!currentProp && ie(relation)) {
|
|
800
|
+
throw new X(
|
|
801
|
+
`report value failed to match tagNameOrder, ${JSON.stringify(originParams)}`
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
if (currentProp) {
|
|
805
|
+
const keys = [];
|
|
806
|
+
if (ie(relation)) {
|
|
807
|
+
keys.push(...Object.keys(relation));
|
|
808
|
+
} else if (b(relation)) {
|
|
809
|
+
if (props.length > 0) {
|
|
810
|
+
throw new X(
|
|
811
|
+
`report value failed to match tagNameOrder, ${JSON.stringify(originParams)}`
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
keys.push(relation);
|
|
815
|
+
} else {
|
|
816
|
+
throw new X(
|
|
817
|
+
`expected metric value to be a string, but got a(n) ${typeof relation}, ${JSON.stringify(
|
|
818
|
+
originParams
|
|
819
|
+
)}`
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
keys.forEach((key) => {
|
|
823
|
+
if (!target[key]) target[key] = {};
|
|
824
|
+
const value = ie(relation) ? relation[key] : relation;
|
|
825
|
+
safeSetVal(target[key], [...props], metricName, value);
|
|
826
|
+
});
|
|
827
|
+
} else {
|
|
828
|
+
if (!target[metricName]) {
|
|
829
|
+
target[metricName] = 1;
|
|
830
|
+
} else {
|
|
831
|
+
target[metricName]++;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
const originParams = {
|
|
836
|
+
point,
|
|
837
|
+
metricName: this.metricName,
|
|
838
|
+
tagNameOrder: this.tagNameOrder
|
|
839
|
+
};
|
|
840
|
+
safeSetVal(this.cache, [...this.tagNameOrder], this.metricName, point);
|
|
841
|
+
}
|
|
842
|
+
processPoints(points) {
|
|
843
|
+
return {
|
|
844
|
+
eventName: this.eventName,
|
|
845
|
+
tagNameOrder: this.tagNameOrder,
|
|
846
|
+
metricName: this.metricName,
|
|
847
|
+
metricAggregateType: this.type === "pv" ? "itoa" : "arr",
|
|
848
|
+
data: points
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
clearPoints() {
|
|
852
|
+
this.cache = {};
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
monitorHasInitialized = false;
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
// src/native/js-bridge/invoke.ts
|
|
860
|
+
function createInvoke(jsCore2, onNative2) {
|
|
861
|
+
let resolveId = 0;
|
|
862
|
+
let IS_FOREGROUND = true;
|
|
863
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
864
|
+
const reportInvokeMetrics = createReportInvokeMetrics(jsCore2, onNative2);
|
|
865
|
+
onNative2("onJoliboxEnterBackground", () => {
|
|
866
|
+
IS_FOREGROUND = false;
|
|
867
|
+
});
|
|
868
|
+
onNative2("onJoliboxEnterForeground", () => {
|
|
869
|
+
IS_FOREGROUND = true;
|
|
870
|
+
asyncInvokes.forEach(async ({ method, args, resolve }) => {
|
|
871
|
+
const res = await invokeNative2(method, args);
|
|
872
|
+
resolve(res);
|
|
873
|
+
});
|
|
874
|
+
asyncInvokes.length = 0;
|
|
875
|
+
});
|
|
876
|
+
const invokeHandler2 = (resolveId2, data) => {
|
|
877
|
+
q.info("----resolveId", resolveId2, data);
|
|
878
|
+
const resolve = resolveMap.get(Number(resolveId2));
|
|
879
|
+
if (!resolve) return;
|
|
880
|
+
const response = unpack(data);
|
|
881
|
+
resolve(response);
|
|
882
|
+
resolveMap.delete(Number(resolveId2));
|
|
883
|
+
};
|
|
884
|
+
const invokeNative2 = (method, args) => {
|
|
885
|
+
const startTime = Date.now();
|
|
886
|
+
const isForeground = `${IS_FOREGROUND}`;
|
|
887
|
+
resolveId += 1;
|
|
888
|
+
const deferred = new L();
|
|
889
|
+
resolveMap.set(resolveId, deferred.resolve);
|
|
890
|
+
if (!IS_FOREGROUND && BACKGROUND_FORBIDDEN_METHODS.includes(method)) {
|
|
891
|
+
return new Promise((resolve) => {
|
|
892
|
+
asyncInvokes.push({ method, args, resolve });
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
const basicReportParam = {
|
|
896
|
+
method,
|
|
897
|
+
startTime,
|
|
898
|
+
args,
|
|
899
|
+
isForeground
|
|
900
|
+
};
|
|
901
|
+
const invokeReportParam = {
|
|
902
|
+
...basicReportParam,
|
|
903
|
+
invokeType: "js-bridge"
|
|
904
|
+
};
|
|
905
|
+
const useArrayBuffer = !NOT_SUPPORT_ARRAY_BUFFER && BUFFER_METHODS.includes(method);
|
|
906
|
+
const payload = pack(args, useArrayBuffer);
|
|
907
|
+
const params = useArrayBuffer ? payload : JSON.stringify(payload);
|
|
908
|
+
let response;
|
|
909
|
+
if (method.endsWith("Sync") || SYNC_METHODS.includes(method)) {
|
|
910
|
+
response = jsCore2.call?.(method, payload, resolveId);
|
|
911
|
+
} else {
|
|
912
|
+
if (typeof params === "string") {
|
|
913
|
+
console.log("-----params", method, resolveId);
|
|
914
|
+
response = jsCore2.invoke(method, params, resolveId);
|
|
915
|
+
} else {
|
|
916
|
+
response = jsCore2.call?.(method, params, resolveId);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (response) {
|
|
920
|
+
try {
|
|
921
|
+
if (typeof response === "string") {
|
|
922
|
+
response = JSON.parse(response);
|
|
923
|
+
}
|
|
924
|
+
response = unpack(response);
|
|
925
|
+
} catch (error) {
|
|
926
|
+
q.error(error);
|
|
927
|
+
}
|
|
928
|
+
resolveMap.delete(resolveId);
|
|
929
|
+
if (response.errorCode) {
|
|
930
|
+
response.errorCode = formatErrorCode(method, response.errorCode);
|
|
931
|
+
}
|
|
932
|
+
reportInvokeMetrics({ ...invokeReportParam, ...response });
|
|
933
|
+
return response;
|
|
934
|
+
}
|
|
935
|
+
if (method.endsWith("Sync")) {
|
|
936
|
+
resolveMap.delete(resolveId);
|
|
937
|
+
}
|
|
938
|
+
return deferred.promise.then((response2) => {
|
|
939
|
+
if (response2.errorCode) {
|
|
940
|
+
response2.errorCode = formatErrorCode(method, response2.errorCode);
|
|
941
|
+
}
|
|
942
|
+
reportInvokeMetrics({ ...invokeReportParam, ...response2 });
|
|
943
|
+
return response2;
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
const applyNative3 = (method, arg) => {
|
|
947
|
+
const res = invokeNative2(method, arg);
|
|
948
|
+
if (Oe(res)) {
|
|
949
|
+
return res.then(
|
|
950
|
+
(r) => ifThrowError(
|
|
951
|
+
method,
|
|
952
|
+
r
|
|
953
|
+
)
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
return ifThrowError(method, res);
|
|
957
|
+
};
|
|
958
|
+
return {
|
|
959
|
+
invokeNative: invokeNative2,
|
|
960
|
+
applyNative: applyNative3,
|
|
961
|
+
invokeHandler: invokeHandler2
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function ifThrowError(method, res) {
|
|
965
|
+
if (!ie(res)) {
|
|
966
|
+
q.warn(`[Jolibox SDK]${method} no response value`);
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const { errMsg, errNo, errorType, errorCode, ...data } = res;
|
|
970
|
+
if (errMsg && errMsg !== `${method}:ok`) {
|
|
971
|
+
throw new z(errMsg, errNo, errorType, errorCode);
|
|
972
|
+
}
|
|
973
|
+
return data;
|
|
974
|
+
}
|
|
975
|
+
var asyncInvokes, NOT_SUPPORT_ARRAY_BUFFER;
|
|
976
|
+
var init_invoke = __esm({
|
|
977
|
+
"src/native/js-bridge/invoke.ts"() {
|
|
978
|
+
"use strict";
|
|
979
|
+
init_utils();
|
|
980
|
+
init_index_es();
|
|
981
|
+
init_errors();
|
|
982
|
+
init_const();
|
|
983
|
+
init_report2();
|
|
984
|
+
asyncInvokes = [];
|
|
985
|
+
NOT_SUPPORT_ARRAY_BUFFER = false;
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
// src/native/js-bridge/subscribe.ts
|
|
990
|
+
function createSubscribe(jsCore2) {
|
|
991
|
+
const nativeEmitter = new _();
|
|
992
|
+
const publishMonitor = new MetricsMonitor({
|
|
993
|
+
eventName: "jolibox_publish",
|
|
994
|
+
tagNameOrder: ["type", "event"],
|
|
995
|
+
metricName: "duration",
|
|
996
|
+
reporter(data) {
|
|
997
|
+
jsCore2.invoke("track", JSON.stringify({ event: "reportMetrics", data }), -1);
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
nativeEmitter.on("onJoliboxEnterBackground", () => {
|
|
1001
|
+
publishMonitor.flush();
|
|
1002
|
+
});
|
|
1003
|
+
return {
|
|
1004
|
+
onNative: nativeEmitter.on.bind(nativeEmitter),
|
|
1005
|
+
offNative: nativeEmitter.off.bind(nativeEmitter),
|
|
1006
|
+
subscribeHandler(event, data, webviewId) {
|
|
1007
|
+
const unpackedData = unpack(data);
|
|
1008
|
+
let originalParams;
|
|
1009
|
+
if (unpackedData.__extra) {
|
|
1010
|
+
originalParams = unpackedData.params;
|
|
1011
|
+
const { type, startTime } = unpackedData.__extra;
|
|
1012
|
+
publishMonitor.report({
|
|
1013
|
+
type,
|
|
1014
|
+
event,
|
|
1015
|
+
duration: Date.now() - startTime
|
|
1016
|
+
// ms
|
|
1017
|
+
});
|
|
1018
|
+
} else {
|
|
1019
|
+
originalParams = unpackedData;
|
|
1020
|
+
}
|
|
1021
|
+
nativeEmitter.emit(event, originalParams, webviewId);
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
var init_subscribe = __esm({
|
|
1026
|
+
"src/native/js-bridge/subscribe.ts"() {
|
|
1027
|
+
"use strict";
|
|
1028
|
+
init_index_es();
|
|
1029
|
+
init_utils();
|
|
1030
|
+
init_report2();
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
// src/native/js-bridge/js-bridge.ts
|
|
1035
|
+
function createBridge(jsCore2) {
|
|
1036
|
+
const { subscribeHandler: subscribeHandler2, onNative: onNative2, offNative: offNative2 } = createSubscribe(jsCore2);
|
|
1037
|
+
const { invokeNative: invokeNative2, invokeHandler: invokeHandler2, applyNative: applyNative3 } = createInvoke(jsCore2, onNative2);
|
|
1038
|
+
return {
|
|
1039
|
+
// 宿主调用
|
|
1040
|
+
invokeHandler: invokeHandler2,
|
|
1041
|
+
subscribeHandler: subscribeHandler2,
|
|
1042
|
+
applyNative: applyNative3,
|
|
1043
|
+
invokeNative: invokeNative2,
|
|
1044
|
+
onNative: onNative2,
|
|
1045
|
+
offNative: offNative2
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
var init_js_bridge = __esm({
|
|
1049
|
+
"src/native/js-bridge/js-bridge.ts"() {
|
|
1050
|
+
"use strict";
|
|
1051
|
+
init_invoke();
|
|
1052
|
+
init_subscribe();
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
// src/native/js-bridge/types.ts
|
|
1057
|
+
var init_types = __esm({
|
|
1058
|
+
"src/native/js-bridge/types.ts"() {
|
|
1059
|
+
"use strict";
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
// src/native/js-bridge/index.ts
|
|
1064
|
+
var init_js_bridge2 = __esm({
|
|
1065
|
+
"src/native/js-bridge/index.ts"() {
|
|
1066
|
+
"use strict";
|
|
1067
|
+
init_js_bridge();
|
|
1068
|
+
init_types();
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
// src/native/js-core/jolibox-js-core.ts
|
|
1073
|
+
var joliboxJSCore, RuntimeLoader, env;
|
|
1074
|
+
var init_jolibox_js_core = __esm({
|
|
1075
|
+
"src/native/js-core/jolibox-js-core.ts"() {
|
|
1076
|
+
"use strict";
|
|
1077
|
+
init_index_es();
|
|
1078
|
+
init_report();
|
|
1079
|
+
RuntimeLoader = {
|
|
1080
|
+
trigger() {
|
|
1081
|
+
},
|
|
1082
|
+
exit() {
|
|
1083
|
+
return false;
|
|
1084
|
+
},
|
|
1085
|
+
onReady(fn) {
|
|
1086
|
+
RuntimeLoader.trigger = fn;
|
|
1087
|
+
},
|
|
1088
|
+
doExit(fn) {
|
|
1089
|
+
RuntimeLoader.exit = fn;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
env = () => {
|
|
1093
|
+
const res = window.prompt(
|
|
1094
|
+
"invoke",
|
|
1095
|
+
JSON.stringify({
|
|
1096
|
+
event: "envSync",
|
|
1097
|
+
paramsString: JSON.stringify({})
|
|
1098
|
+
})
|
|
1099
|
+
);
|
|
1100
|
+
if (!res) {
|
|
1101
|
+
reportError(new J(`native env failed`));
|
|
1102
|
+
} else {
|
|
1103
|
+
const { data } = JSON.parse(res);
|
|
1104
|
+
return data ?? void 0;
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
if (window.webkit) {
|
|
1108
|
+
const _joliboxJSCore = window.webkit.messageHandlers;
|
|
1109
|
+
const onDocumentReady = (path = "") => {
|
|
1110
|
+
RuntimeLoader.trigger();
|
|
1111
|
+
_joliboxJSCore.onDocumentReady.postMessage({ path });
|
|
1112
|
+
};
|
|
1113
|
+
const doExit = (uuid) => {
|
|
1114
|
+
const shouldInterrupt = RuntimeLoader.exit();
|
|
1115
|
+
_joliboxJSCore.doExit.postMessage({ uuid, shouldInterrupt });
|
|
1116
|
+
};
|
|
1117
|
+
joliboxJSCore = {
|
|
1118
|
+
onDocumentReady,
|
|
1119
|
+
doExit,
|
|
1120
|
+
invoke(method, params, callbackId) {
|
|
1121
|
+
_joliboxJSCore.invoke.postMessage({
|
|
1122
|
+
event: method,
|
|
1123
|
+
paramsString: params,
|
|
1124
|
+
callbackId
|
|
1125
|
+
});
|
|
1126
|
+
},
|
|
1127
|
+
// publish(event, params, webviewIds) {
|
|
1128
|
+
// const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
1129
|
+
// _joliboxJSCore.publish.postMessage({
|
|
1130
|
+
// event,
|
|
1131
|
+
// paramsString: JSON.stringify(data),
|
|
1132
|
+
// webviewIds: JSON.stringify(webviewIds)
|
|
1133
|
+
// });
|
|
1134
|
+
// },
|
|
1135
|
+
call(method, params, callbackId) {
|
|
1136
|
+
const res = window.prompt(
|
|
1137
|
+
"invoke",
|
|
1138
|
+
JSON.stringify({
|
|
1139
|
+
event: method,
|
|
1140
|
+
paramsString: JSON.stringify(params),
|
|
1141
|
+
callbackId
|
|
1142
|
+
})
|
|
1143
|
+
);
|
|
1144
|
+
if (res) {
|
|
1145
|
+
return JSON.parse(res);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
const devCore = { onDocumentReady, env };
|
|
1150
|
+
globalThis.joliboxJSCore = {
|
|
1151
|
+
...devCore
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
if (window.JoliAndroidSDKBridge) {
|
|
1155
|
+
const _joliboxJSCore = window.JoliAndroidSDKBridge;
|
|
1156
|
+
const onDocumentReady = (path = "") => {
|
|
1157
|
+
RuntimeLoader.trigger();
|
|
1158
|
+
_joliboxJSCore.onDocumentReady(JSON.stringify({ path }));
|
|
1159
|
+
};
|
|
1160
|
+
const doExit = (uuid) => {
|
|
1161
|
+
const shouldInterrupt = RuntimeLoader.exit();
|
|
1162
|
+
_joliboxJSCore.doExit(JSON.stringify({ uuid, shouldInterrupt }));
|
|
1163
|
+
};
|
|
1164
|
+
joliboxJSCore = {
|
|
1165
|
+
onDocumentReady,
|
|
1166
|
+
invoke(method, params, callbackId) {
|
|
1167
|
+
_joliboxJSCore.invoke(
|
|
1168
|
+
JSON.stringify({
|
|
1169
|
+
event: method,
|
|
1170
|
+
paramsString: params,
|
|
1171
|
+
callbackId
|
|
1172
|
+
})
|
|
1173
|
+
);
|
|
1174
|
+
},
|
|
1175
|
+
doExit,
|
|
1176
|
+
// publish(event, params, webviewIds) {
|
|
1177
|
+
// const data = normalizeParams(params as Record<string, unknown>, 'joliboxJSCore');
|
|
1178
|
+
// _joliboxJSCore.publish({
|
|
1179
|
+
// event,
|
|
1180
|
+
// paramsString: JSON.stringify(data),
|
|
1181
|
+
// webviewIds: JSON.stringify(webviewIds)
|
|
1182
|
+
// });
|
|
1183
|
+
// },
|
|
1184
|
+
call(method, params, callbackId) {
|
|
1185
|
+
const res = window.prompt(
|
|
1186
|
+
"invoke",
|
|
1187
|
+
JSON.stringify({
|
|
1188
|
+
event: method,
|
|
1189
|
+
paramsString: JSON.stringify(params),
|
|
1190
|
+
callbackId
|
|
1191
|
+
})
|
|
1192
|
+
);
|
|
1193
|
+
if (res) {
|
|
1194
|
+
return JSON.parse(res);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
const devCore = { onDocumentReady, env };
|
|
1199
|
+
globalThis.joliboxJSCore = {
|
|
1200
|
+
...devCore
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
// src/native/js-core/utils.ts
|
|
1207
|
+
function normalizeParams(params, type) {
|
|
1208
|
+
return {
|
|
1209
|
+
params,
|
|
1210
|
+
__extra: {
|
|
1211
|
+
startTime: Date.now(),
|
|
1212
|
+
type
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
var init_utils2 = __esm({
|
|
1217
|
+
"src/native/js-core/utils.ts"() {
|
|
1218
|
+
"use strict";
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
// src/native/js-core/message-port.ts
|
|
1223
|
+
function initMessagePort() {
|
|
1224
|
+
globalThis.onmessage = function(msg) {
|
|
1225
|
+
if (msg.data !== "msg:setup") {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
[messagePort] = msg.ports;
|
|
1229
|
+
messagePort.onmessage = function(message) {
|
|
1230
|
+
const data = JSON.parse(message.data);
|
|
1231
|
+
if (data[0] === "publish") {
|
|
1232
|
+
globalThis.ttJSBridge.subscribeHandler(data[1], data[2]);
|
|
1233
|
+
} else if (data[0] === "invoke") {
|
|
1234
|
+
globalThis.ttJSBridge.invokeHandler(data[1], data[2]);
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
messagePort.publish = function(event, params) {
|
|
1238
|
+
const data = normalizeParams(params, "messagePort");
|
|
1239
|
+
messagePort.postMessage(JSON.stringify(["publish", event, JSON.stringify(data)]));
|
|
1240
|
+
};
|
|
1241
|
+
messagePort.postMessage("msg:setup:ok");
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
var messagePort;
|
|
1245
|
+
var init_message_port = __esm({
|
|
1246
|
+
"src/native/js-core/message-port.ts"() {
|
|
1247
|
+
"use strict";
|
|
1248
|
+
init_utils2();
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
// src/native/js-core/index.ts
|
|
1253
|
+
var init_js_core = __esm({
|
|
1254
|
+
"src/native/js-core/index.ts"() {
|
|
1255
|
+
"use strict";
|
|
1256
|
+
init_jolibox_js_core();
|
|
1257
|
+
init_message_port();
|
|
1258
|
+
init_utils2();
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
// src/native/bootstrap/bridge.ts
|
|
1263
|
+
var jsCore, core, bridge, invokeHandler, applyNative, invokeNative, onNative, offNative, subscribeHandler;
|
|
1264
|
+
var init_bridge = __esm({
|
|
1265
|
+
"src/native/bootstrap/bridge.ts"() {
|
|
1266
|
+
"use strict";
|
|
1267
|
+
init_js_bridge2();
|
|
1268
|
+
init_js_core();
|
|
1269
|
+
init_errors();
|
|
1270
|
+
init_index_es();
|
|
1271
|
+
init_js_core();
|
|
1272
|
+
jsCore = joliboxJSCore;
|
|
1273
|
+
if (!jsCore) {
|
|
1274
|
+
throw new B("No joliboxJScore is found, native bridge not found.");
|
|
1275
|
+
}
|
|
1276
|
+
initMessagePort();
|
|
1277
|
+
core = {
|
|
1278
|
+
...jsCore
|
|
1279
|
+
// publish(event: string, params: Record<string, unknown>, webviewIds: number[]) {
|
|
1280
|
+
// if (messagePort) {
|
|
1281
|
+
// messagePort.publish(event, params);
|
|
1282
|
+
// return;
|
|
1283
|
+
// }
|
|
1284
|
+
// jsCore.publish(event, params, webviewIds);
|
|
1285
|
+
// }
|
|
1286
|
+
};
|
|
1287
|
+
bridge = createBridge(core);
|
|
1288
|
+
({ invokeHandler } = bridge);
|
|
1289
|
+
({ applyNative, invokeNative, onNative, offNative, subscribeHandler } = bridge);
|
|
1290
|
+
globalThis.joliboxJSBridge = {
|
|
1291
|
+
callHandler: invokeHandler,
|
|
1292
|
+
invokeHandler,
|
|
1293
|
+
subscribeHandler
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
// src/common/context/url-parse.ts
|
|
1299
|
+
var base64UrlDecode, parseUrlQuery;
|
|
1300
|
+
var init_url_parse = __esm({
|
|
1301
|
+
"src/common/context/url-parse.ts"() {
|
|
1302
|
+
"use strict";
|
|
1303
|
+
init_index_es();
|
|
1304
|
+
init_report();
|
|
1305
|
+
base64UrlDecode = (input) => {
|
|
1306
|
+
const base64 = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
1307
|
+
const padding = base64.length % 4 === 0 ? "" : "=".repeat(4 - base64.length % 4);
|
|
1308
|
+
const jsonStr = atob(base64 + padding);
|
|
1309
|
+
try {
|
|
1310
|
+
return JSON.parse(jsonStr);
|
|
1311
|
+
} catch (e) {
|
|
1312
|
+
return {};
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
parseUrlQuery = (url) => {
|
|
1316
|
+
try {
|
|
1317
|
+
const urlObj = new URL(url);
|
|
1318
|
+
const params = urlObj.searchParams;
|
|
1319
|
+
const joli_source = params.get("joliSource")?.split(".");
|
|
1320
|
+
if (joli_source?.length) {
|
|
1321
|
+
const [headerJsonStr, payloadJsonStr, signatureJsonStr] = joli_source;
|
|
1322
|
+
return {
|
|
1323
|
+
headerJson: base64UrlDecode(headerJsonStr),
|
|
1324
|
+
payloadJson: base64UrlDecode(payloadJsonStr),
|
|
1325
|
+
signature: base64UrlDecode(signatureJsonStr)
|
|
1326
|
+
};
|
|
1327
|
+
} else {
|
|
1328
|
+
throw `joli_source is missing`;
|
|
1329
|
+
}
|
|
1330
|
+
} catch (e) {
|
|
1331
|
+
reportError(new H(`${url} not a valid schema: ${e}`));
|
|
1332
|
+
return {
|
|
1333
|
+
headerJson: {},
|
|
1334
|
+
payloadJson: {},
|
|
1335
|
+
signature: {}
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
// src/common/http/uuid.ts
|
|
1343
|
+
var uuidv4;
|
|
1344
|
+
var init_uuid = __esm({
|
|
1345
|
+
"src/common/http/uuid.ts"() {
|
|
1346
|
+
"use strict";
|
|
1347
|
+
uuidv4 = () => {
|
|
1348
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1349
|
+
const r = Math.random() * 16 | 0;
|
|
1350
|
+
const v2 = c === "x" ? r : r & 3 | 8;
|
|
1351
|
+
return v2.toString(16);
|
|
1352
|
+
});
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
|
|
1357
|
+
// src/common/http/xua.ts
|
|
1358
|
+
var platform, getPlatform, jssdkVersion, getAppVersion, DEVICE_ID, ADVERTISING_ID, getStorage, getDeviceId, getAdvertisingId, firstCharUpperCase, getUtmSource, xUserAgent;
|
|
1359
|
+
var init_xua = __esm({
|
|
1360
|
+
"src/common/http/xua.ts"() {
|
|
1361
|
+
"use strict";
|
|
1362
|
+
init_uuid();
|
|
1363
|
+
platform = {
|
|
1364
|
+
isiOS: navigator.userAgent.includes("iPhone") || navigator.userAgent.includes("iPod") || navigator.userAgent.includes("iPad") || navigator.userAgent.includes("iPhone OS"),
|
|
1365
|
+
iosVersion: () => {
|
|
1366
|
+
const v2 = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
|
|
1367
|
+
return [parseInt(v2[1], 10), parseInt(v2[2], 10), parseInt(v2[3] || "0", 10)];
|
|
1368
|
+
},
|
|
1369
|
+
isAndroid: navigator.userAgent.includes("Android"),
|
|
1370
|
+
isMac: navigator.userAgent.includes("Mac"),
|
|
1371
|
+
isFacebook: navigator.userAgent.includes("FB_IAB"),
|
|
1372
|
+
isPC: !navigator.userAgent.includes("iPhone") && !navigator.userAgent.includes("Android")
|
|
1373
|
+
};
|
|
1374
|
+
getPlatform = () => {
|
|
1375
|
+
if (platform.isiOS) {
|
|
1376
|
+
return "iOS";
|
|
1377
|
+
} else if (platform.isAndroid) {
|
|
1378
|
+
return "Android";
|
|
1379
|
+
} else if (platform.isMac) {
|
|
1380
|
+
return "Mac";
|
|
1381
|
+
} else if (platform.isFacebook) {
|
|
1382
|
+
return "Facebook";
|
|
1383
|
+
} else {
|
|
1384
|
+
return "PC";
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
jssdkVersion = "1.1.4-beta.4";
|
|
1388
|
+
getAppVersion = () => {
|
|
1389
|
+
return jssdkVersion;
|
|
1390
|
+
};
|
|
1391
|
+
DEVICE_ID = "device_id";
|
|
1392
|
+
ADVERTISING_ID = "advertising_id";
|
|
1393
|
+
getStorage = (cookieKey) => {
|
|
1394
|
+
if (!localStorage.getItem(cookieKey)) {
|
|
1395
|
+
localStorage.setItem(cookieKey, uuidv4());
|
|
1396
|
+
}
|
|
1397
|
+
return localStorage.getItem(cookieKey);
|
|
1398
|
+
};
|
|
1399
|
+
getDeviceId = () => {
|
|
1400
|
+
return getStorage(DEVICE_ID);
|
|
1401
|
+
};
|
|
1402
|
+
getAdvertisingId = () => {
|
|
1403
|
+
return getStorage(ADVERTISING_ID);
|
|
1404
|
+
};
|
|
1405
|
+
firstCharUpperCase = (chars) => chars.charAt(0).toUpperCase() + chars.slice(1);
|
|
1406
|
+
getUtmSource = () => {
|
|
1407
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
1408
|
+
return firstCharUpperCase(urlParams.get("utm_source") ?? "") || "JoliboxSDK";
|
|
1409
|
+
};
|
|
1410
|
+
xUserAgent = () => {
|
|
1411
|
+
const applicationName = "JoliboxWebSDK";
|
|
1412
|
+
const thePlatform = getPlatform();
|
|
1413
|
+
const locale = navigator.language;
|
|
1414
|
+
const deviceId = getDeviceId();
|
|
1415
|
+
const adid = getAdvertisingId();
|
|
1416
|
+
const appVersion = getAppVersion();
|
|
1417
|
+
const deviceModel = "UnknownModel";
|
|
1418
|
+
const systemVersion = "UnknownSystemVersion";
|
|
1419
|
+
return `${applicationName} (${getUtmSource()}${thePlatform}; ${deviceModel}; ${systemVersion}; ${locale}) uuid/${deviceId} adid/${adid} version/${appVersion || ""}`;
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
// src/common/context/index.ts
|
|
1425
|
+
var defaultEnv, nativeEnv, env2, wrapContext, context;
|
|
1426
|
+
var init_context = __esm({
|
|
1427
|
+
"src/common/context/index.ts"() {
|
|
1428
|
+
"use strict";
|
|
1429
|
+
init_index_es();
|
|
1430
|
+
init_url_parse();
|
|
1431
|
+
init_xua();
|
|
1432
|
+
defaultEnv = {
|
|
1433
|
+
deviceInfo: {
|
|
1434
|
+
brand: "",
|
|
1435
|
+
model: "",
|
|
1436
|
+
did: getDeviceId(),
|
|
1437
|
+
pixelRatio: window.devicePixelRatio || 1,
|
|
1438
|
+
platform: "h5",
|
|
1439
|
+
system: "",
|
|
1440
|
+
lang: "zh"
|
|
1441
|
+
},
|
|
1442
|
+
hostInfo: {
|
|
1443
|
+
appName: "",
|
|
1444
|
+
version: getAppVersion(),
|
|
1445
|
+
aid: "",
|
|
1446
|
+
channel: ""
|
|
1447
|
+
},
|
|
1448
|
+
sdkInfo: {
|
|
1449
|
+
nativeSDKVersion: "",
|
|
1450
|
+
jssdkVersion: getAppVersion()
|
|
1451
|
+
},
|
|
1452
|
+
schema: "",
|
|
1453
|
+
platform: "h5"
|
|
1454
|
+
};
|
|
1455
|
+
nativeEnv = globalThis.joliboxJSCore?.env;
|
|
1456
|
+
env2 = Object.assign({}, nativeEnv?.() ?? defaultEnv);
|
|
1457
|
+
wrapContext = () => {
|
|
1458
|
+
const { payloadJson, headerJson } = parseUrlQuery(env2.schema);
|
|
1459
|
+
const defaultSessionId = `${env2.deviceInfo.did}-${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
1460
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
1461
|
+
const defaultGameID = urlParams.get("appId") ?? urlParams.get("gameId") ?? "";
|
|
1462
|
+
const sessionId = payloadJson.sessionId ?? urlParams.get("sessionId") ?? defaultSessionId;
|
|
1463
|
+
const testAdsMode = !!(payloadJson.testAdsMode ?? urlParams.get("testAdsMode") === "true");
|
|
1464
|
+
const joliboxEnv = payloadJson.joliboxEnv ?? urlParams.get("joliboxEnv") ?? "production";
|
|
1465
|
+
const testMode = joliboxEnv === "staging";
|
|
1466
|
+
return {
|
|
1467
|
+
get testMode() {
|
|
1468
|
+
return testMode;
|
|
1469
|
+
},
|
|
1470
|
+
get testAdsMode() {
|
|
1471
|
+
return testAdsMode;
|
|
1472
|
+
},
|
|
1473
|
+
get joliboxEnv() {
|
|
1474
|
+
return joliboxEnv;
|
|
1475
|
+
},
|
|
1476
|
+
get game_id() {
|
|
1477
|
+
return defaultGameID ?? payloadJson["id"];
|
|
1478
|
+
},
|
|
1479
|
+
get game_version() {
|
|
1480
|
+
return headerJson.ver ?? "";
|
|
1481
|
+
},
|
|
1482
|
+
get platform() {
|
|
1483
|
+
return env2.platform;
|
|
1484
|
+
},
|
|
1485
|
+
get deviceInfo() {
|
|
1486
|
+
return env2.deviceInfo;
|
|
1487
|
+
},
|
|
1488
|
+
get sdkInfo() {
|
|
1489
|
+
return env2.sdkInfo;
|
|
1490
|
+
},
|
|
1491
|
+
get hostInfo() {
|
|
1492
|
+
return env2.hostInfo;
|
|
1493
|
+
},
|
|
1494
|
+
get hostUserInfo() {
|
|
1495
|
+
return env2.hostUserInfo;
|
|
1496
|
+
},
|
|
1497
|
+
get session_id() {
|
|
1498
|
+
return env2.clientSessionId ?? sessionId ?? defaultSessionId;
|
|
1499
|
+
},
|
|
1500
|
+
onEnvConfigChanged: (newConfig) => {
|
|
1501
|
+
ke(env2, newConfig, Le);
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
};
|
|
1505
|
+
context = wrapContext();
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// src/common/report/errors/report/listeners.ts
|
|
1510
|
+
var reportFlag, hasIn, isBaseError, toCamelCase, innerErrorReport, isUserError;
|
|
1511
|
+
var init_listeners = __esm({
|
|
1512
|
+
"src/common/report/errors/report/listeners.ts"() {
|
|
1513
|
+
"use strict";
|
|
1514
|
+
init_index_es();
|
|
1515
|
+
init_report();
|
|
1516
|
+
init_context();
|
|
1517
|
+
init_index_es();
|
|
1518
|
+
reportFlag = false;
|
|
1519
|
+
hasIn = (object, path) => {
|
|
1520
|
+
if (object == null) return false;
|
|
1521
|
+
return path in object;
|
|
1522
|
+
};
|
|
1523
|
+
isBaseError = (error) => {
|
|
1524
|
+
return hasIn(error, "kind");
|
|
1525
|
+
};
|
|
1526
|
+
toCamelCase = (snakeStr) => {
|
|
1527
|
+
const words = snakeStr.toLowerCase().split("_");
|
|
1528
|
+
return words[0] + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
1529
|
+
};
|
|
1530
|
+
innerErrorReport = (error, options = {}, isFromUser) => {
|
|
1531
|
+
const priority = error.priority ?? "P1";
|
|
1532
|
+
const common = {
|
|
1533
|
+
user_id: context.hostUserInfo?.uid ?? "",
|
|
1534
|
+
device_id: context.deviceInfo.did ?? "",
|
|
1535
|
+
timestamp: Date.now(),
|
|
1536
|
+
tag: toCamelCase(error.name)
|
|
1537
|
+
};
|
|
1538
|
+
const reports = { ...common, env: options.environment, isFromUser };
|
|
1539
|
+
if (isFromUser) {
|
|
1540
|
+
errorReportEmitter.emit("GLOBAL_USER_ERROR", error, reports);
|
|
1541
|
+
} else {
|
|
1542
|
+
errorReportEmitter.emit("GLOBAL_ERROR", error, reports);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
isUserError = (error) => {
|
|
1546
|
+
return hasIn(error, "kind") && error["kind"] === "USER_ERROR";
|
|
1547
|
+
};
|
|
1548
|
+
errorReportCollector.on("ERROR_REPORT", ({ error, options }) => {
|
|
1549
|
+
if (reportFlag) return;
|
|
1550
|
+
reportFlag = true;
|
|
1551
|
+
const raw = isBaseError(error) && error.raw ? error.raw : error;
|
|
1552
|
+
try {
|
|
1553
|
+
const isFromUser = isUserError(error);
|
|
1554
|
+
innerErrorReport(error, options, isFromUser);
|
|
1555
|
+
} catch (err) {
|
|
1556
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1557
|
+
const reportError2 = new Y(`${message}, origin error: ${raw.message}`);
|
|
1558
|
+
q.error(reportError2);
|
|
1559
|
+
innerErrorReport(
|
|
1560
|
+
new Y(reportError2.message),
|
|
1561
|
+
{
|
|
1562
|
+
environment: options.environment
|
|
1563
|
+
},
|
|
1564
|
+
false
|
|
1565
|
+
);
|
|
1566
|
+
} finally {
|
|
1567
|
+
reportFlag = false;
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
// src/native/report/errors/index.ts
|
|
1574
|
+
var init_errors2 = __esm({
|
|
1575
|
+
"src/native/report/errors/index.ts"() {
|
|
1576
|
+
"use strict";
|
|
1577
|
+
init_listeners();
|
|
1578
|
+
init_errors();
|
|
1579
|
+
init_index_es();
|
|
1580
|
+
init_bridge();
|
|
1581
|
+
errorReportEmitter.on("GLOBAL_ERROR", (error, errorData) => {
|
|
1582
|
+
const extra = {
|
|
1583
|
+
message: error.message,
|
|
1584
|
+
stack: error.stack ?? "",
|
|
1585
|
+
errorType: error.name,
|
|
1586
|
+
source: 0
|
|
1587
|
+
};
|
|
1588
|
+
invokeNative("trackAsync", {
|
|
1589
|
+
event: "reportJsError",
|
|
1590
|
+
data: extra
|
|
1591
|
+
});
|
|
1592
|
+
});
|
|
1593
|
+
errorReportEmitter.on("GLOBAL_USER_ERROR", (error, errorData) => {
|
|
1594
|
+
q.log("UserError", error, errorData);
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
// src/common/report/types.ts
|
|
1600
|
+
var init_types2 = __esm({
|
|
1601
|
+
"src/common/report/types.ts"() {
|
|
1602
|
+
"use strict";
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// src/common/report/track.ts
|
|
1607
|
+
function createTrack(reportHandler, common) {
|
|
1608
|
+
const track2 = (tag, info, webviewId) => {
|
|
1609
|
+
const data = {
|
|
1610
|
+
tag,
|
|
1611
|
+
...common,
|
|
1612
|
+
extra: {
|
|
1613
|
+
...info
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
if (tag == "globalJsError") {
|
|
1617
|
+
reportError(new $(JSON.stringify(data), "P0"));
|
|
1618
|
+
} else {
|
|
1619
|
+
reportHandler("systemLog", data, webviewId);
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
track2.debounce = Ue(track2, 500, { leading: true });
|
|
1623
|
+
return track2;
|
|
1624
|
+
}
|
|
1625
|
+
function createTrackPerformance(track2) {
|
|
1626
|
+
const trackPerformance2 = (type, duration, data) => {
|
|
1627
|
+
const length = (data && JSON.stringify(data)) ?? 0;
|
|
1628
|
+
const info = {
|
|
1629
|
+
speed_value_type: type,
|
|
1630
|
+
total_duration: duration
|
|
1631
|
+
};
|
|
1632
|
+
if (length) {
|
|
1633
|
+
Object.assign(info, { extra: length });
|
|
1634
|
+
}
|
|
1635
|
+
track2("joliboxSpeedAnalysis", info);
|
|
1636
|
+
};
|
|
1637
|
+
trackPerformance2.debounce = Ue(trackPerformance2, 500, {
|
|
1638
|
+
leading: true
|
|
1639
|
+
});
|
|
1640
|
+
return trackPerformance2;
|
|
1641
|
+
}
|
|
1642
|
+
var init_track = __esm({
|
|
1643
|
+
"src/common/report/track.ts"() {
|
|
1644
|
+
"use strict";
|
|
1645
|
+
init_index_es();
|
|
1646
|
+
init_index_es();
|
|
1647
|
+
init_report();
|
|
1648
|
+
}
|
|
1649
|
+
});
|
|
1650
|
+
|
|
1651
|
+
// src/common/report/create-trace.ts
|
|
1652
|
+
function createTracks(reportHandler, common) {
|
|
1653
|
+
const track2 = createTrack(reportHandler, common);
|
|
1654
|
+
const trackPerformance2 = createTrackPerformance(track2);
|
|
1655
|
+
return {
|
|
1656
|
+
track: track2,
|
|
1657
|
+
trackPerformance: trackPerformance2
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
var init_create_trace = __esm({
|
|
1661
|
+
"src/common/report/create-trace.ts"() {
|
|
1662
|
+
"use strict";
|
|
1663
|
+
init_track();
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
// src/common/report/base-tracker.ts
|
|
1668
|
+
var init_base_tracker = __esm({
|
|
1669
|
+
"src/common/report/base-tracker.ts"() {
|
|
1670
|
+
"use strict";
|
|
1671
|
+
init_context();
|
|
1672
|
+
init_index_es();
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
|
|
1676
|
+
// src/common/report/index.ts
|
|
1677
|
+
var init_report3 = __esm({
|
|
1678
|
+
"src/common/report/index.ts"() {
|
|
1679
|
+
"use strict";
|
|
1680
|
+
init_create_trace();
|
|
1681
|
+
init_types2();
|
|
1682
|
+
init_base_tracker();
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
|
|
1686
|
+
// src/common/report/task-track/index.ts
|
|
1687
|
+
var TaskTracker;
|
|
1688
|
+
var init_task_track = __esm({
|
|
1689
|
+
"src/common/report/task-track/index.ts"() {
|
|
1690
|
+
"use strict";
|
|
1691
|
+
TaskTracker = class {
|
|
1692
|
+
constructor(eventEmitter, interval) {
|
|
1693
|
+
this.lastReportTime = 0;
|
|
1694
|
+
this.visible = true;
|
|
1695
|
+
this.timer = this.createRAFTimer((duration) => {
|
|
1696
|
+
this.reporter({
|
|
1697
|
+
event: "PLAY_GAME",
|
|
1698
|
+
params: {
|
|
1699
|
+
duration: duration / 1e3
|
|
1700
|
+
// second
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
});
|
|
1704
|
+
this.interval = interval ?? 10 * 1e3;
|
|
1705
|
+
eventEmitter.on("visible", (visible) => {
|
|
1706
|
+
this.visible = visible;
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
start(duration) {
|
|
1710
|
+
this.reporter({
|
|
1711
|
+
event: "OPEN_GAME",
|
|
1712
|
+
params: {
|
|
1713
|
+
timestamp: Date.now(),
|
|
1714
|
+
duration: duration ?? 0 / 1e3
|
|
1715
|
+
// second
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
this.timer.start();
|
|
1719
|
+
}
|
|
1720
|
+
close(duration) {
|
|
1721
|
+
this.reporter({
|
|
1722
|
+
event: "CLOSE_GAME",
|
|
1723
|
+
params: {
|
|
1724
|
+
timestamp: Date.now(),
|
|
1725
|
+
duration: duration / 1e3
|
|
1726
|
+
// second
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
this.timer.stop();
|
|
1730
|
+
}
|
|
1731
|
+
createRAFTimer(callback) {
|
|
1732
|
+
let lastTime = performance.now();
|
|
1733
|
+
let rafId;
|
|
1734
|
+
let isRunning = false;
|
|
1735
|
+
let totalTime = 0;
|
|
1736
|
+
const tick = (currentTime) => {
|
|
1737
|
+
if (!isRunning) return;
|
|
1738
|
+
const deltaTime = currentTime - lastTime;
|
|
1739
|
+
if (deltaTime >= this.interval) {
|
|
1740
|
+
if (this.visible) {
|
|
1741
|
+
totalTime += deltaTime;
|
|
1742
|
+
callback(totalTime);
|
|
1743
|
+
}
|
|
1744
|
+
lastTime = currentTime;
|
|
1745
|
+
}
|
|
1746
|
+
rafId = requestAnimationFrame(tick);
|
|
1747
|
+
};
|
|
1748
|
+
return {
|
|
1749
|
+
start() {
|
|
1750
|
+
if (!isRunning) {
|
|
1751
|
+
isRunning = true;
|
|
1752
|
+
lastTime = performance.now();
|
|
1753
|
+
rafId = requestAnimationFrame(tick);
|
|
1754
|
+
}
|
|
1755
|
+
},
|
|
1756
|
+
stop() {
|
|
1757
|
+
isRunning = false;
|
|
1758
|
+
if (rafId) {
|
|
1759
|
+
cancelAnimationFrame(rafId);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
|
|
1768
|
+
// src/native/network/types.ts
|
|
1769
|
+
var init_types3 = __esm({
|
|
1770
|
+
"src/native/network/types.ts"() {
|
|
1771
|
+
"use strict";
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1775
|
+
// src/native/network/report.ts
|
|
1776
|
+
function reportNetworkAPI(method, url, options) {
|
|
1777
|
+
const { response, startTime, endTime, requestFrom } = options;
|
|
1778
|
+
const { errMsg = "", profile = {} } = response;
|
|
1779
|
+
const duration = endTime - startTime;
|
|
1780
|
+
const trackData = {
|
|
1781
|
+
duration,
|
|
1782
|
+
request_type: method,
|
|
1783
|
+
url: url.split("?")[0],
|
|
1784
|
+
result: options.state,
|
|
1785
|
+
error_msg: options.state === "fail" ? errMsg : "",
|
|
1786
|
+
socket_reused: profile.socketReused ? 1 : 0,
|
|
1787
|
+
request_from: requestFrom
|
|
1788
|
+
};
|
|
1789
|
+
if (requestFrom === "public" /* PUBLIC */ && requestNumber < requestNumberLimit || requestFrom === "inner" /* INNER */) {
|
|
1790
|
+
trackData.joli_request_number = requestNumber++;
|
|
1791
|
+
setTimeout(() => {
|
|
1792
|
+
track("joliboxNetRequestResult", trackData);
|
|
1793
|
+
}, 500);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
var requestNumber, requestNumberLimit;
|
|
1797
|
+
var init_report4 = __esm({
|
|
1798
|
+
"src/native/network/report.ts"() {
|
|
1799
|
+
"use strict";
|
|
1800
|
+
init_types3();
|
|
1801
|
+
init_report5();
|
|
1802
|
+
requestNumber = 0;
|
|
1803
|
+
requestNumberLimit = 10;
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
// src/native/network/create-fetch.ts
|
|
1808
|
+
function createFetch(createMethod, operateMethod, options) {
|
|
1809
|
+
const promiseMap = /* @__PURE__ */ new Map();
|
|
1810
|
+
const baseUrl = options?.baseUrl ?? `https://api.jolibox.com`;
|
|
1811
|
+
const type = options?.type ?? "public";
|
|
1812
|
+
const defaultHeaders = options?.defaultHeaders ?? {};
|
|
1813
|
+
onNative("onRequestTaskStateChange", (res) => {
|
|
1814
|
+
if (typeof res.requestTaskId !== "string") return;
|
|
1815
|
+
const task = promiseMap.get(res.requestTaskId);
|
|
1816
|
+
if (!task) return;
|
|
1817
|
+
if (res.state === "success") {
|
|
1818
|
+
const { requestTaskId, state, ...rest } = res;
|
|
1819
|
+
task.resolve(rest);
|
|
1820
|
+
promiseMap.delete(requestTaskId);
|
|
1821
|
+
} else if (res.state === "fail") {
|
|
1822
|
+
const { requestTaskId, state, ...rest } = res;
|
|
1823
|
+
task.reject(rest);
|
|
1824
|
+
promiseMap.delete(requestTaskId);
|
|
1825
|
+
} else {
|
|
1826
|
+
q.warn(`onRequestTaskStateChange unknown event`, res);
|
|
1827
|
+
}
|
|
1828
|
+
});
|
|
1829
|
+
En.on("onLoginComplete", ({ isLogin, token }) => {
|
|
1830
|
+
if (isLogin && token) {
|
|
1831
|
+
defaultHeaders["X-JOLI-TOKEN"] = token;
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
const fetch = async (originUrl, options2 = {}) => {
|
|
1835
|
+
const startTime = Date.now();
|
|
1836
|
+
const url = processUrl(originUrl, { ...options2, baseUrl });
|
|
1837
|
+
const {
|
|
1838
|
+
method = "GET",
|
|
1839
|
+
responseType = "text",
|
|
1840
|
+
dataType = "json",
|
|
1841
|
+
timeout,
|
|
1842
|
+
enableCache = false,
|
|
1843
|
+
appendHostCookie = true
|
|
1844
|
+
} = options2;
|
|
1845
|
+
const header = Object.assign({ "content-type": "application/json" }, defaultHeaders, options2.header);
|
|
1846
|
+
const params = {
|
|
1847
|
+
url,
|
|
1848
|
+
method,
|
|
1849
|
+
header,
|
|
1850
|
+
enableCache,
|
|
1851
|
+
responseType,
|
|
1852
|
+
appendHostCookie
|
|
1853
|
+
};
|
|
1854
|
+
if (method == "POST" || method == "PUT") {
|
|
1855
|
+
const data = normalizeData(options2.data, header["content-type"]);
|
|
1856
|
+
params["data"] = data;
|
|
1857
|
+
}
|
|
1858
|
+
if (timeout) {
|
|
1859
|
+
Object.assign(params, { timeout });
|
|
1860
|
+
}
|
|
1861
|
+
const {
|
|
1862
|
+
data: { requestTaskId }
|
|
1863
|
+
} = invokeNative(createMethod, params);
|
|
1864
|
+
if (typeof requestTaskId !== "string") {
|
|
1865
|
+
throw createAPIError({
|
|
1866
|
+
code: -1,
|
|
1867
|
+
msg: "requestTaskId is not a string"
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
const report = (state, response) => {
|
|
1871
|
+
reportNetworkAPI("request", url, {
|
|
1872
|
+
state,
|
|
1873
|
+
startTime,
|
|
1874
|
+
endTime: Date.now(),
|
|
1875
|
+
params,
|
|
1876
|
+
response,
|
|
1877
|
+
requestId: requestTaskId,
|
|
1878
|
+
requestFrom: type == "public" ? "public" /* PUBLIC */ : "inner" /* INNER */
|
|
1879
|
+
});
|
|
1880
|
+
};
|
|
1881
|
+
const { resolve, reject, promise } = new L();
|
|
1882
|
+
promiseMap.set(requestTaskId, { resolve, reject });
|
|
1883
|
+
try {
|
|
1884
|
+
const res = await promise;
|
|
1885
|
+
report("success", res);
|
|
1886
|
+
let { data } = res;
|
|
1887
|
+
if (dataType === "json" && typeof data === "string") {
|
|
1888
|
+
data = parseJSON(data);
|
|
1889
|
+
}
|
|
1890
|
+
return {
|
|
1891
|
+
url,
|
|
1892
|
+
timeout,
|
|
1893
|
+
method,
|
|
1894
|
+
response: { ...res, data }
|
|
1895
|
+
};
|
|
1896
|
+
} catch (err) {
|
|
1897
|
+
const error = err;
|
|
1898
|
+
if (ie(error)) {
|
|
1899
|
+
const { errMsg, prefetchDetail, isPrefetch, errNo } = error;
|
|
1900
|
+
if (b(errMsg)) {
|
|
1901
|
+
report("fail", {
|
|
1902
|
+
errMsg,
|
|
1903
|
+
isPrefetch,
|
|
1904
|
+
prefetchDetail
|
|
1905
|
+
});
|
|
1906
|
+
reportError(createAPIError({ code: -1, msg: errMsg }, { errNo, errMsg }));
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
throw err;
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
return fetch;
|
|
1913
|
+
}
|
|
1914
|
+
function parseJSON(data) {
|
|
1915
|
+
try {
|
|
1916
|
+
return JSON.parse(data.trim());
|
|
1917
|
+
} catch {
|
|
1918
|
+
return data;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
function normalizeData(data, contentType = "application/json") {
|
|
1922
|
+
const type = contentType.toLowerCase();
|
|
1923
|
+
if (data === void 0) {
|
|
1924
|
+
return "";
|
|
1925
|
+
}
|
|
1926
|
+
if (typeof data === "string" || data instanceof ArrayBuffer) {
|
|
1927
|
+
return data;
|
|
1928
|
+
}
|
|
1929
|
+
if (type.includes("application/x-www-form-urlencoded")) {
|
|
1930
|
+
return JSON.stringify(data);
|
|
1931
|
+
}
|
|
1932
|
+
if (type.includes("application/json")) {
|
|
1933
|
+
return JSON.stringify(data);
|
|
1934
|
+
}
|
|
1935
|
+
if (typeof data === "object") {
|
|
1936
|
+
return JSON.stringify(data);
|
|
1937
|
+
}
|
|
1938
|
+
return String(data);
|
|
1939
|
+
}
|
|
1940
|
+
var processUrl;
|
|
1941
|
+
var init_create_fetch = __esm({
|
|
1942
|
+
"src/native/network/create-fetch.ts"() {
|
|
1943
|
+
"use strict";
|
|
1944
|
+
init_index_es();
|
|
1945
|
+
init_report4();
|
|
1946
|
+
init_types3();
|
|
1947
|
+
init_bridge();
|
|
1948
|
+
init_report();
|
|
1949
|
+
init_errors();
|
|
1950
|
+
processUrl = (url, options) => {
|
|
1951
|
+
if (/^https?:\/\//.test(url)) {
|
|
1952
|
+
return url;
|
|
1953
|
+
}
|
|
1954
|
+
const query = options?.query;
|
|
1955
|
+
const searchParams = new URLSearchParams(query);
|
|
1956
|
+
const search = searchParams.toString();
|
|
1957
|
+
return options?.baseUrl ? `${options.baseUrl}${url}${search ? `?${search}` : ""}` : `${url}${search ? `?${search}` : ""}`;
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
|
|
1962
|
+
// src/native/network/index.ts
|
|
1963
|
+
var innerFetch;
|
|
1964
|
+
var init_network = __esm({
|
|
1965
|
+
"src/native/network/index.ts"() {
|
|
1966
|
+
"use strict";
|
|
1967
|
+
init_xua();
|
|
1968
|
+
init_create_fetch();
|
|
1969
|
+
init_context();
|
|
1970
|
+
innerFetch = createFetch("createRequestTaskSync", "operateRequestTaskSync", {
|
|
1971
|
+
type: "inner",
|
|
1972
|
+
baseUrl: context.testMode ? "https://stg-api.jolibox.com" : "https://api.jolibox.com",
|
|
1973
|
+
defaultHeaders: {
|
|
1974
|
+
"x-user-agent": xUserAgent(),
|
|
1975
|
+
"X-JOLI-TOKEN": context.hostUserInfo?.token ?? ""
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
// src/native/report/task-tracker.ts
|
|
1982
|
+
var NativeTaskTracker;
|
|
1983
|
+
var init_task_tracker = __esm({
|
|
1984
|
+
"src/native/report/task-tracker.ts"() {
|
|
1985
|
+
"use strict";
|
|
1986
|
+
init_context();
|
|
1987
|
+
init_task_track();
|
|
1988
|
+
init_network();
|
|
1989
|
+
init_bridge();
|
|
1990
|
+
NativeTaskTracker = class extends TaskTracker {
|
|
1991
|
+
constructor(eventEmitter, interval) {
|
|
1992
|
+
super(eventEmitter, interval);
|
|
1993
|
+
this.gameId = context.game_id;
|
|
1994
|
+
this.sessionId = context.session_id;
|
|
1995
|
+
}
|
|
1996
|
+
async reporter(point) {
|
|
1997
|
+
const { event, params } = point;
|
|
1998
|
+
const reportTasks = [];
|
|
1999
|
+
reportTasks.push(
|
|
2000
|
+
innerFetch(`/api/base/app-event`, {
|
|
2001
|
+
method: "POST",
|
|
2002
|
+
data: {
|
|
2003
|
+
eventType: event,
|
|
2004
|
+
gameInfo: {
|
|
2005
|
+
gameId: this.gameId,
|
|
2006
|
+
sessionId: this.sessionId,
|
|
2007
|
+
...params
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
})
|
|
2011
|
+
);
|
|
2012
|
+
await Promise.all(reportTasks);
|
|
2013
|
+
}
|
|
2014
|
+
async reportToNative(point) {
|
|
2015
|
+
const { event, params } = point;
|
|
2016
|
+
await applyNative("userTrackAsync", {
|
|
2017
|
+
event,
|
|
2018
|
+
params: {
|
|
2019
|
+
...params
|
|
2020
|
+
},
|
|
2021
|
+
gameId: this.gameId
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
});
|
|
2027
|
+
|
|
2028
|
+
// src/native/report/index.ts
|
|
2029
|
+
var reportNative, track, trackPerformance, commands, nativeTaskEmitter, taskTracker;
|
|
2030
|
+
var init_report5 = __esm({
|
|
2031
|
+
"src/native/report/index.ts"() {
|
|
2032
|
+
"use strict";
|
|
2033
|
+
init_errors2();
|
|
2034
|
+
init_index_es();
|
|
2035
|
+
init_types2();
|
|
2036
|
+
init_report3();
|
|
2037
|
+
init_context();
|
|
2038
|
+
init_task_tracker();
|
|
2039
|
+
init_bridge();
|
|
2040
|
+
reportNative = (event, data, webviewId) => {
|
|
2041
|
+
const _data = data;
|
|
2042
|
+
const originExtra = ie(_data.extra) ? _data.extra : b(_data.extra) ? JSON.parse(_data.extra) : {};
|
|
2043
|
+
const extra = {
|
|
2044
|
+
...originExtra,
|
|
2045
|
+
source_id: _data.source_id ?? "",
|
|
2046
|
+
source_version: _data.source_version ?? ""
|
|
2047
|
+
};
|
|
2048
|
+
invokeNative("trackAsync", {
|
|
2049
|
+
event,
|
|
2050
|
+
data: extra,
|
|
2051
|
+
webviewId
|
|
2052
|
+
});
|
|
2053
|
+
};
|
|
2054
|
+
({ track, trackPerformance } = createTracks(reportNative, {
|
|
2055
|
+
type: "app-sdk" /* AppSDK */,
|
|
2056
|
+
platform: "native",
|
|
2057
|
+
jssdk_version: context.sdkInfo?.jssdkVersion ?? "1.0.0",
|
|
2058
|
+
source_id: context.game_id,
|
|
2059
|
+
source_version: context.game_version
|
|
2060
|
+
}));
|
|
2061
|
+
commands = Vn();
|
|
2062
|
+
commands.registerCommand("ReportSDK.traceSystemTimeline", ({ event, duration }) => {
|
|
2063
|
+
trackPerformance(event, duration);
|
|
2064
|
+
});
|
|
2065
|
+
commands.registerCommand("ReportSDK.traceSystem", ({ event, info }) => {
|
|
2066
|
+
track(event, info);
|
|
2067
|
+
});
|
|
2068
|
+
nativeTaskEmitter = new _();
|
|
2069
|
+
taskTracker = new NativeTaskTracker(nativeTaskEmitter);
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
|
|
2073
|
+
// src/common/can-i-use.ts
|
|
2074
|
+
function registerCanIUseFactory(platform2) {
|
|
2075
|
+
let configMap = Be.config[platform2];
|
|
2076
|
+
if (!configMap) {
|
|
2077
|
+
configMap = {};
|
|
2078
|
+
Be.config[platform2] = configMap;
|
|
2079
|
+
}
|
|
2080
|
+
return (name, config2) => {
|
|
2081
|
+
if (configMap[name]) {
|
|
2082
|
+
q.warn(`[can i use] ${name} already registered`);
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
configMap[name] = {
|
|
2086
|
+
...config2
|
|
2087
|
+
};
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
var init_can_i_use = __esm({
|
|
2091
|
+
"src/common/can-i-use.ts"() {
|
|
2092
|
+
"use strict";
|
|
2093
|
+
init_index_es();
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
2096
|
+
|
|
2097
|
+
// src/common/api-factory/validator/validate.ts
|
|
2098
|
+
function setCollect(flag) {
|
|
2099
|
+
collectError = flag;
|
|
2100
|
+
}
|
|
2101
|
+
function deepClone(obj) {
|
|
2102
|
+
if (obj === null || typeof obj !== "object") {
|
|
2103
|
+
return obj;
|
|
2104
|
+
}
|
|
2105
|
+
if (Array.isArray(obj)) {
|
|
2106
|
+
return obj.map((item) => deepClone(item));
|
|
2107
|
+
}
|
|
2108
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
2109
|
+
acc[key] = deepClone(obj[key]);
|
|
2110
|
+
return acc;
|
|
2111
|
+
}, {});
|
|
2112
|
+
}
|
|
2113
|
+
function isNumber(x2) {
|
|
2114
|
+
return typeof x2 === "number";
|
|
2115
|
+
}
|
|
2116
|
+
function echo(x2) {
|
|
2117
|
+
const s = getType2(x2);
|
|
2118
|
+
switch (s) {
|
|
2119
|
+
case "string":
|
|
2120
|
+
return `"${x2}"`;
|
|
2121
|
+
case "number":
|
|
2122
|
+
case "boolean":
|
|
2123
|
+
case "null":
|
|
2124
|
+
case "undefined":
|
|
2125
|
+
return String(x2);
|
|
2126
|
+
default:
|
|
2127
|
+
return `a(n) ${s}`;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
function getType2(x2) {
|
|
2131
|
+
if (typeof x2 === "function") return "function";
|
|
2132
|
+
const type = Object.prototype.toString.call(x2).slice(8).slice(0, -1);
|
|
2133
|
+
return type.toLowerCase();
|
|
2134
|
+
}
|
|
2135
|
+
var collectError, Validator, $number, $boolean, $string, $symbol, $any, $undefined, $null, $function, $enum, $array, $record, $object, $literal, $or, $tuple, $arraybuffer, $typedarray;
|
|
2136
|
+
var init_validate = __esm({
|
|
2137
|
+
"src/common/api-factory/validator/validate.ts"() {
|
|
2138
|
+
"use strict";
|
|
2139
|
+
collectError = false;
|
|
2140
|
+
Validator = class {
|
|
2141
|
+
constructor() {
|
|
2142
|
+
this.errors = [];
|
|
2143
|
+
this.hasFallback = false;
|
|
2144
|
+
this.hasDefault = false;
|
|
2145
|
+
this._optional = false;
|
|
2146
|
+
}
|
|
2147
|
+
fail(options) {
|
|
2148
|
+
if (collectError) {
|
|
2149
|
+
if (typeof options === "string") {
|
|
2150
|
+
this.errors.push(options);
|
|
2151
|
+
} else {
|
|
2152
|
+
let message = `${this.path} should be ${options.expect}`;
|
|
2153
|
+
if (this._optional && options.expect !== "undefined") {
|
|
2154
|
+
message += " or undefined, ";
|
|
2155
|
+
} else {
|
|
2156
|
+
message += ", ";
|
|
2157
|
+
}
|
|
2158
|
+
message += `but got ${echo(options.actual)}`;
|
|
2159
|
+
this.errors.push(message);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
return false;
|
|
2163
|
+
}
|
|
2164
|
+
fallback(v2) {
|
|
2165
|
+
this.hasFallback = true;
|
|
2166
|
+
this._fallback = v2;
|
|
2167
|
+
return this;
|
|
2168
|
+
}
|
|
2169
|
+
get fallbackValue() {
|
|
2170
|
+
return deepClone(this._fallback);
|
|
2171
|
+
}
|
|
2172
|
+
default(v2) {
|
|
2173
|
+
this.hasDefault = true;
|
|
2174
|
+
this._default = v2;
|
|
2175
|
+
return this;
|
|
2176
|
+
}
|
|
2177
|
+
get defaultValue() {
|
|
2178
|
+
if (typeof this._default === "function") {
|
|
2179
|
+
return this._default;
|
|
2180
|
+
}
|
|
2181
|
+
return deepClone(this._default);
|
|
2182
|
+
}
|
|
2183
|
+
optional() {
|
|
2184
|
+
this._optional = true;
|
|
2185
|
+
return this;
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
$number = class extends Validator {
|
|
2189
|
+
validate(x2) {
|
|
2190
|
+
if (this._optional && x2 === void 0) return true;
|
|
2191
|
+
if (!isNumber(x2)) {
|
|
2192
|
+
return this.fail({ expect: "number", actual: x2 });
|
|
2193
|
+
}
|
|
2194
|
+
if (isNumber(this._min) && x2 < this._min) {
|
|
2195
|
+
return this.fail(`the value of ${this.path} should be greater than or equal to ${this._min}`);
|
|
2196
|
+
}
|
|
2197
|
+
if (isNumber(this._max) && x2 > this._max) {
|
|
2198
|
+
return this.fail(`the value of ${this.path} should be less than or equal to ${this._max}`);
|
|
2199
|
+
}
|
|
2200
|
+
if (isNumber(this._greater) && x2 <= this._greater) {
|
|
2201
|
+
return this.fail(`the value of ${this.path} should be greater than ${this._greater}`);
|
|
2202
|
+
}
|
|
2203
|
+
if (this._isInt && x2 !== Math.floor(x2)) {
|
|
2204
|
+
return this.fail(`the value of ${this.path} should be integer but got ${x2}`);
|
|
2205
|
+
}
|
|
2206
|
+
return true;
|
|
2207
|
+
}
|
|
2208
|
+
min(v2) {
|
|
2209
|
+
this._min = v2;
|
|
2210
|
+
return this;
|
|
2211
|
+
}
|
|
2212
|
+
max(v2) {
|
|
2213
|
+
this._max = v2;
|
|
2214
|
+
return this;
|
|
2215
|
+
}
|
|
2216
|
+
isInt(v2) {
|
|
2217
|
+
this._isInt = v2;
|
|
2218
|
+
return this;
|
|
2219
|
+
}
|
|
2220
|
+
greater(v2) {
|
|
2221
|
+
this._greater = v2;
|
|
2222
|
+
return this;
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
$boolean = class extends Validator {
|
|
2226
|
+
validate(x2) {
|
|
2227
|
+
if (this._optional && x2 === void 0) return true;
|
|
2228
|
+
if (typeof x2 !== "boolean") {
|
|
2229
|
+
return this.fail({ expect: "boolean", actual: x2 });
|
|
2230
|
+
}
|
|
2231
|
+
return true;
|
|
2232
|
+
}
|
|
2233
|
+
};
|
|
2234
|
+
$string = class extends Validator {
|
|
2235
|
+
validate(x2) {
|
|
2236
|
+
if (this._optional && x2 === void 0) return true;
|
|
2237
|
+
if (typeof x2 !== "string") {
|
|
2238
|
+
return this.fail({ expect: "string", actual: x2 });
|
|
2239
|
+
}
|
|
2240
|
+
if (isNumber(this._maxLength) && x2.length > this._maxLength) {
|
|
2241
|
+
return this.fail(`the length of ${this.path} should be less than or equal to ${this._maxLength}`);
|
|
2242
|
+
}
|
|
2243
|
+
if (isNumber(this._minLength) && x2.length < this._minLength) {
|
|
2244
|
+
return this.fail(`the length of ${this.path} should be greater than or equal to ${this._minLength}`);
|
|
2245
|
+
}
|
|
2246
|
+
if (typeof this._pattern === "string") {
|
|
2247
|
+
const reg = new RegExp(this._pattern);
|
|
2248
|
+
if (!reg.test(x2)) {
|
|
2249
|
+
return this.fail(`${this.path} should match pattern "${this._pattern}"`);
|
|
2250
|
+
}
|
|
2251
|
+
} else if (this._pattern) {
|
|
2252
|
+
if (!this._pattern.test(x2)) {
|
|
2253
|
+
return this.fail(`${this.path} should match pattern "${this._pattern.toString()}"`);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
return true;
|
|
2257
|
+
}
|
|
2258
|
+
minLength(len) {
|
|
2259
|
+
this._minLength = len;
|
|
2260
|
+
return this;
|
|
2261
|
+
}
|
|
2262
|
+
maxLength(len) {
|
|
2263
|
+
this._maxLength = len;
|
|
2264
|
+
return this;
|
|
2265
|
+
}
|
|
2266
|
+
pattern(patten) {
|
|
2267
|
+
this._pattern = patten;
|
|
2268
|
+
return this;
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
$symbol = class extends Validator {
|
|
2272
|
+
validate(x2) {
|
|
2273
|
+
if (this._optional && x2 === void 0) return true;
|
|
2274
|
+
if (typeof x2 !== "symbol") {
|
|
2275
|
+
return this.fail({ expect: "symbol", actual: x2 });
|
|
2276
|
+
}
|
|
2277
|
+
return true;
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
$any = class extends Validator {
|
|
2281
|
+
// eslint-disable-next-line class-methods-use-this
|
|
2282
|
+
validate(x2) {
|
|
2283
|
+
return true;
|
|
2284
|
+
}
|
|
2285
|
+
};
|
|
2286
|
+
$undefined = class extends Validator {
|
|
2287
|
+
validate(x2) {
|
|
2288
|
+
if (x2 !== void 0) {
|
|
2289
|
+
return this.fail({ expect: "undefined", actual: x2 });
|
|
2290
|
+
}
|
|
2291
|
+
return true;
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
$null = class extends Validator {
|
|
2295
|
+
validate(x2) {
|
|
2296
|
+
if (this._optional && x2 === void 0) return true;
|
|
2297
|
+
if (x2 !== null) {
|
|
2298
|
+
return this.fail({ expect: "null", actual: x2 });
|
|
2299
|
+
}
|
|
2300
|
+
return true;
|
|
2301
|
+
}
|
|
2302
|
+
};
|
|
2303
|
+
$function = class extends Validator {
|
|
2304
|
+
validate(x2) {
|
|
2305
|
+
if (this._optional && x2 === void 0) return true;
|
|
2306
|
+
if (typeof x2 !== "function") {
|
|
2307
|
+
return this.fail({ expect: "function", actual: x2 });
|
|
2308
|
+
}
|
|
2309
|
+
return true;
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
$enum = class extends Validator {
|
|
2313
|
+
constructor(..._items) {
|
|
2314
|
+
super();
|
|
2315
|
+
this._items = _items;
|
|
2316
|
+
}
|
|
2317
|
+
validate(x2) {
|
|
2318
|
+
if (this._optional && x2 === void 0) return true;
|
|
2319
|
+
if (!this._items.includes(x2)) {
|
|
2320
|
+
const enums = this._items.map((i) => JSON.stringify(i)).join(", ");
|
|
2321
|
+
return this.fail(`expect ${this.path} to be one of ${enums}, but got ${echo(x2)}`);
|
|
2322
|
+
}
|
|
2323
|
+
return true;
|
|
2324
|
+
}
|
|
2325
|
+
};
|
|
2326
|
+
$array = class extends Validator {
|
|
2327
|
+
constructor(_item) {
|
|
2328
|
+
super();
|
|
2329
|
+
this._item = _item;
|
|
2330
|
+
}
|
|
2331
|
+
validate(x2) {
|
|
2332
|
+
if (this._optional && x2 === void 0) return true;
|
|
2333
|
+
if (!Array.isArray(x2)) {
|
|
2334
|
+
return this.fail({ expect: "array", actual: x2 });
|
|
2335
|
+
}
|
|
2336
|
+
if (isNumber(this._minItems) && x2.length < this._minItems) {
|
|
2337
|
+
return this.fail(`the length of ${this.path} should be greater than or equal to ${this._minItems}`);
|
|
2338
|
+
}
|
|
2339
|
+
if (isNumber(this._maxItems) && x2.length > this._maxItems) {
|
|
2340
|
+
return this.fail(`the length of ${this.path} should be less than or equal to ${this._maxItems}`);
|
|
2341
|
+
}
|
|
2342
|
+
if (isNumber(this._length) && x2.length !== this._length) {
|
|
2343
|
+
return this.fail(`the length of ${this.path} should be equal to ${this._length}`);
|
|
2344
|
+
}
|
|
2345
|
+
const validator = this._item;
|
|
2346
|
+
if (!validator) return true;
|
|
2347
|
+
let result = true;
|
|
2348
|
+
x2.forEach((item, index) => {
|
|
2349
|
+
validator.path = `${this.path}[${index}]`;
|
|
2350
|
+
validator.errors = this.errors;
|
|
2351
|
+
if (item === void 0 && validator.hasDefault) {
|
|
2352
|
+
x2[index] = validator.defaultValue;
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
if (!validator.validate(item)) {
|
|
2356
|
+
if (validator.hasFallback) {
|
|
2357
|
+
x2[index] = validator.fallbackValue;
|
|
2358
|
+
} else {
|
|
2359
|
+
result = false;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
});
|
|
2363
|
+
if (this._uniqueItems) {
|
|
2364
|
+
const map = /* @__PURE__ */ new Map();
|
|
2365
|
+
for (let i in x2) {
|
|
2366
|
+
if (map.has(x2[i])) {
|
|
2367
|
+
result = this.fail(
|
|
2368
|
+
`${this.path} should NOT have duplicate items (${this.path}[${map.get(x2[i])}] and ${this.path}[${i}] are identical)`
|
|
2369
|
+
);
|
|
2370
|
+
} else {
|
|
2371
|
+
map.set(x2[i], i);
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
return result;
|
|
2376
|
+
}
|
|
2377
|
+
minItems(len) {
|
|
2378
|
+
this._minItems = len;
|
|
2379
|
+
return this;
|
|
2380
|
+
}
|
|
2381
|
+
maxItems(len) {
|
|
2382
|
+
this._maxItems = len;
|
|
2383
|
+
return this;
|
|
2384
|
+
}
|
|
2385
|
+
uniqueItems() {
|
|
2386
|
+
this._uniqueItems = true;
|
|
2387
|
+
return this;
|
|
2388
|
+
}
|
|
2389
|
+
length(len) {
|
|
2390
|
+
this._length = len;
|
|
2391
|
+
return this;
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
$record = class extends Validator {
|
|
2395
|
+
constructor(_value) {
|
|
2396
|
+
super();
|
|
2397
|
+
this._value = _value;
|
|
2398
|
+
}
|
|
2399
|
+
validate(x2) {
|
|
2400
|
+
if (this._optional && x2 === void 0) return true;
|
|
2401
|
+
const type = getType2(x2);
|
|
2402
|
+
if (type !== "object") {
|
|
2403
|
+
return this.fail({ expect: "object", actual: x2 });
|
|
2404
|
+
}
|
|
2405
|
+
const values = x2;
|
|
2406
|
+
const validator = this._value;
|
|
2407
|
+
validator.errors = this.errors;
|
|
2408
|
+
let result = true;
|
|
2409
|
+
for (const k2 in values) {
|
|
2410
|
+
const value = values[k2];
|
|
2411
|
+
if (/^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/.test(k2)) {
|
|
2412
|
+
validator.path = `${this.path}.${k2}`;
|
|
2413
|
+
} else {
|
|
2414
|
+
validator.path = `${this.path}["${k2}"]`;
|
|
2415
|
+
}
|
|
2416
|
+
if (value === void 0 && validator._optional) {
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
if (value === void 0 && validator.hasDefault) {
|
|
2420
|
+
values[k2] = validator.defaultValue;
|
|
2421
|
+
continue;
|
|
2422
|
+
}
|
|
2423
|
+
if (!validator.validate(value)) {
|
|
2424
|
+
if (validator.hasFallback) {
|
|
2425
|
+
values[k2] = validator.fallbackValue;
|
|
2426
|
+
} else {
|
|
2427
|
+
result = false;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return result;
|
|
2432
|
+
}
|
|
2433
|
+
};
|
|
2434
|
+
$object = class extends Validator {
|
|
2435
|
+
constructor(_object = {}) {
|
|
2436
|
+
super();
|
|
2437
|
+
this._object = _object;
|
|
2438
|
+
}
|
|
2439
|
+
validate(x2) {
|
|
2440
|
+
if (this._optional && x2 === void 0) return true;
|
|
2441
|
+
if (getType2(x2) !== "object") {
|
|
2442
|
+
return this.fail({ expect: "object", actual: x2 });
|
|
2443
|
+
}
|
|
2444
|
+
const values = x2;
|
|
2445
|
+
let result = true;
|
|
2446
|
+
for (const k2 in this._object) {
|
|
2447
|
+
const value = values[k2];
|
|
2448
|
+
const validator = this._object[k2];
|
|
2449
|
+
validator.errors = this.errors;
|
|
2450
|
+
if (/^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/.test(k2)) {
|
|
2451
|
+
validator.path = `${this.path}.${k2}`;
|
|
2452
|
+
} else {
|
|
2453
|
+
validator.path = `${this.path}["${k2}"]`;
|
|
2454
|
+
}
|
|
2455
|
+
if (validator._optional && value === void 0) {
|
|
2456
|
+
continue;
|
|
2457
|
+
}
|
|
2458
|
+
if (value === void 0 && validator.hasDefault) {
|
|
2459
|
+
values[k2] = validator.defaultValue;
|
|
2460
|
+
continue;
|
|
2461
|
+
}
|
|
2462
|
+
if (!validator.validate(value)) {
|
|
2463
|
+
if (validator.hasFallback) {
|
|
2464
|
+
values[k2] = validator.fallbackValue;
|
|
2465
|
+
} else {
|
|
2466
|
+
result = false;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
return result;
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
$literal = class extends Validator {
|
|
2474
|
+
constructor(value) {
|
|
2475
|
+
super();
|
|
2476
|
+
this.value = value;
|
|
2477
|
+
}
|
|
2478
|
+
validate(x2) {
|
|
2479
|
+
if (x2 === void 0 && this._optional) return true;
|
|
2480
|
+
if (x2 !== this.value) {
|
|
2481
|
+
return this.fail({ expect: echo(this.value), actual: x2 });
|
|
2482
|
+
}
|
|
2483
|
+
return true;
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
$or = class extends Validator {
|
|
2487
|
+
constructor(..._items) {
|
|
2488
|
+
super();
|
|
2489
|
+
this._items = _items;
|
|
2490
|
+
}
|
|
2491
|
+
validate(x2) {
|
|
2492
|
+
if (x2 === void 0 && this._optional) return true;
|
|
2493
|
+
const orErrors = [];
|
|
2494
|
+
let result = false;
|
|
2495
|
+
const itemLength = this._items.length;
|
|
2496
|
+
for (let i = 0; i < itemLength; i++) {
|
|
2497
|
+
const validator = this._items[i];
|
|
2498
|
+
validator.errors = [];
|
|
2499
|
+
validator.path = this.path;
|
|
2500
|
+
if (!validator.validate(x2)) {
|
|
2501
|
+
orErrors.push(validator.errors.join("; "));
|
|
2502
|
+
} else if (!result) {
|
|
2503
|
+
result = true;
|
|
2504
|
+
break;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
if (!result) {
|
|
2508
|
+
const grouped = orErrors.join("\nor ");
|
|
2509
|
+
this.errors.push(grouped);
|
|
2510
|
+
}
|
|
2511
|
+
return result;
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
$tuple = class extends Validator {
|
|
2515
|
+
constructor(..._items) {
|
|
2516
|
+
super();
|
|
2517
|
+
this._items = _items;
|
|
2518
|
+
let optionalCount = 0;
|
|
2519
|
+
let i = _items.length - 1;
|
|
2520
|
+
for (; i >= 0; i--) {
|
|
2521
|
+
const validator = _items[i];
|
|
2522
|
+
if (validator._optional || validator.hasDefault) {
|
|
2523
|
+
optionalCount += 1;
|
|
2524
|
+
} else {
|
|
2525
|
+
break;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
this._minItems = _items.length - optionalCount;
|
|
2529
|
+
}
|
|
2530
|
+
validate(x2) {
|
|
2531
|
+
if (x2 === void 0 && this._optional) return true;
|
|
2532
|
+
if (!Array.isArray(x2)) {
|
|
2533
|
+
return this.fail({ expect: "array", actual: x2 });
|
|
2534
|
+
}
|
|
2535
|
+
if (x2.length < this._minItems) {
|
|
2536
|
+
return this.fail(`the length of ${this.path} should be greater than or equal to ${this._minItems}`);
|
|
2537
|
+
}
|
|
2538
|
+
let result = true;
|
|
2539
|
+
this._items.forEach((validator, index) => {
|
|
2540
|
+
validator.path = `${this.path}[${index}]`;
|
|
2541
|
+
validator.errors = this.errors;
|
|
2542
|
+
const item = x2[index];
|
|
2543
|
+
if (item === void 0 && validator.hasDefault) {
|
|
2544
|
+
x2[index] = validator.defaultValue;
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
if (!validator.validate(x2[index])) {
|
|
2548
|
+
if (validator.hasFallback) {
|
|
2549
|
+
x2[index] = validator._fallback;
|
|
2550
|
+
} else {
|
|
2551
|
+
result = false;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
});
|
|
2555
|
+
return result;
|
|
2556
|
+
}
|
|
2557
|
+
};
|
|
2558
|
+
$arraybuffer = class extends Validator {
|
|
2559
|
+
validate(x2) {
|
|
2560
|
+
if (x2 === void 0 && this._optional) return true;
|
|
2561
|
+
if (x2 instanceof ArrayBuffer) {
|
|
2562
|
+
return true;
|
|
2563
|
+
}
|
|
2564
|
+
return this.fail({ expect: "arraybuffer", actual: x2 });
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
$typedarray = class extends Validator {
|
|
2568
|
+
constructor(ctor) {
|
|
2569
|
+
super();
|
|
2570
|
+
this._ctor = ctor;
|
|
2571
|
+
}
|
|
2572
|
+
validate(x2) {
|
|
2573
|
+
if (x2 === void 0 && this._optional) return true;
|
|
2574
|
+
if (x2 instanceof this._ctor) {
|
|
2575
|
+
return true;
|
|
2576
|
+
}
|
|
2577
|
+
return this.fail({ expect: `typedarray of ${this._ctor.name}`, actual: x2 });
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
|
|
2583
|
+
// src/common/api-factory/validator/index.ts
|
|
2584
|
+
function typeAsserts(validator, x2, path = "param") {
|
|
2585
|
+
validator.errors = [];
|
|
2586
|
+
validator.path = path;
|
|
2587
|
+
setCollect(true);
|
|
2588
|
+
if (!validator.validate(x2)) {
|
|
2589
|
+
const messages = validator.errors.join("\n");
|
|
2590
|
+
validator.errors.length = 0;
|
|
2591
|
+
setCollect(false);
|
|
2592
|
+
throw new TypeError(messages);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
var t;
|
|
2596
|
+
var init_validator = __esm({
|
|
2597
|
+
"src/common/api-factory/validator/index.ts"() {
|
|
2598
|
+
"use strict";
|
|
2599
|
+
init_validate();
|
|
2600
|
+
init_validate();
|
|
2601
|
+
t = {
|
|
2602
|
+
object(schemas) {
|
|
2603
|
+
return new $object(schemas);
|
|
2604
|
+
},
|
|
2605
|
+
array(schema) {
|
|
2606
|
+
return new $array(schema);
|
|
2607
|
+
},
|
|
2608
|
+
tuple(...schemas) {
|
|
2609
|
+
return new $tuple(...schemas);
|
|
2610
|
+
},
|
|
2611
|
+
literal(v2) {
|
|
2612
|
+
return new $literal(v2);
|
|
2613
|
+
},
|
|
2614
|
+
or(...schemas) {
|
|
2615
|
+
return new $or(...schemas);
|
|
2616
|
+
},
|
|
2617
|
+
symbol() {
|
|
2618
|
+
return new $symbol();
|
|
2619
|
+
},
|
|
2620
|
+
record(schema) {
|
|
2621
|
+
return new $record(schema);
|
|
2622
|
+
},
|
|
2623
|
+
function() {
|
|
2624
|
+
return new $function();
|
|
2625
|
+
},
|
|
2626
|
+
boolean() {
|
|
2627
|
+
return new $boolean();
|
|
2628
|
+
},
|
|
2629
|
+
string() {
|
|
2630
|
+
return new $string();
|
|
2631
|
+
},
|
|
2632
|
+
number() {
|
|
2633
|
+
return new $number();
|
|
2634
|
+
},
|
|
2635
|
+
undefined() {
|
|
2636
|
+
return new $undefined();
|
|
2637
|
+
},
|
|
2638
|
+
null() {
|
|
2639
|
+
return new $null();
|
|
2640
|
+
},
|
|
2641
|
+
unknown() {
|
|
2642
|
+
return new $any();
|
|
2643
|
+
},
|
|
2644
|
+
any() {
|
|
2645
|
+
return new $any();
|
|
2646
|
+
},
|
|
2647
|
+
as() {
|
|
2648
|
+
return new $any();
|
|
2649
|
+
},
|
|
2650
|
+
arraybuffer() {
|
|
2651
|
+
return new $arraybuffer();
|
|
2652
|
+
},
|
|
2653
|
+
enum(...values) {
|
|
2654
|
+
return new $enum(...values);
|
|
2655
|
+
},
|
|
2656
|
+
typedarray(ctor) {
|
|
2657
|
+
return new $typedarray(ctor);
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
});
|
|
2662
|
+
|
|
2663
|
+
// src/common/api-factory/index.ts
|
|
2664
|
+
var traceId, createAPIFactory;
|
|
2665
|
+
var init_api_factory = __esm({
|
|
2666
|
+
"src/common/api-factory/index.ts"() {
|
|
2667
|
+
"use strict";
|
|
2668
|
+
init_index_es();
|
|
2669
|
+
init_report();
|
|
2670
|
+
init_validator();
|
|
2671
|
+
init_errors();
|
|
2672
|
+
traceId = 1;
|
|
2673
|
+
createAPIFactory = (track2) => {
|
|
2674
|
+
function createSyncAPI2(method, config2) {
|
|
2675
|
+
return (...inputs) => {
|
|
2676
|
+
const startTime = Date.now();
|
|
2677
|
+
const reportExtra = { method, trace_id: traceId };
|
|
2678
|
+
traceId += 1;
|
|
2679
|
+
let status = "SUCCESS";
|
|
2680
|
+
let errMsg = `${method}:ok`;
|
|
2681
|
+
let errNo = 0;
|
|
2682
|
+
try {
|
|
2683
|
+
if (config2.paramsSchema) {
|
|
2684
|
+
try {
|
|
2685
|
+
typeAsserts(config2.paramsSchema, inputs, "params");
|
|
2686
|
+
} catch (err) {
|
|
2687
|
+
const error = err;
|
|
2688
|
+
throw createUserAPIError(`${method}:fail ${error.message}`);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
const res = config2.implement(...inputs);
|
|
2692
|
+
let data = res;
|
|
2693
|
+
let message = `${method}:ok`;
|
|
2694
|
+
if (res && "code" in res) {
|
|
2695
|
+
const {
|
|
2696
|
+
code,
|
|
2697
|
+
data: originData,
|
|
2698
|
+
message: originMessage
|
|
2699
|
+
} = res;
|
|
2700
|
+
status = code;
|
|
2701
|
+
data = originData;
|
|
2702
|
+
message = originMessage;
|
|
2703
|
+
}
|
|
2704
|
+
return {
|
|
2705
|
+
code: status,
|
|
2706
|
+
message,
|
|
2707
|
+
data
|
|
2708
|
+
};
|
|
2709
|
+
} catch (error) {
|
|
2710
|
+
const _error = error;
|
|
2711
|
+
errNo = _error.code ?? _error.errNo ?? 2e3;
|
|
2712
|
+
status = "FAILURE";
|
|
2713
|
+
const msg = _error.message ?? _error.errMsg ?? `${error}`;
|
|
2714
|
+
errMsg = `${method}:${status} ${msg.replace(/^\S+:(fail|cancel)\s?/, "")}`;
|
|
2715
|
+
reportError(new Q(errMsg, errNo));
|
|
2716
|
+
return {
|
|
2717
|
+
code: status,
|
|
2718
|
+
message: errMsg
|
|
2719
|
+
};
|
|
2720
|
+
} finally {
|
|
2721
|
+
const duration = Date.now() - startTime;
|
|
2722
|
+
track2("apiInvoked", { ...reportExtra, duration, status });
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function createAPI2(method, config2) {
|
|
2727
|
+
return async (..._inputs) => {
|
|
2728
|
+
const inputs = Ce(_inputs) ? _inputs : [_inputs];
|
|
2729
|
+
const startTime = Date.now();
|
|
2730
|
+
const reportExtra = { method, trace_id: traceId };
|
|
2731
|
+
traceId += 1;
|
|
2732
|
+
let message = `${method}:ok`;
|
|
2733
|
+
let status = "SUCCESS";
|
|
2734
|
+
const res = {
|
|
2735
|
+
code: status,
|
|
2736
|
+
message
|
|
2737
|
+
};
|
|
2738
|
+
try {
|
|
2739
|
+
if (config2.paramsSchema) {
|
|
2740
|
+
try {
|
|
2741
|
+
typeAsserts(config2.paramsSchema, inputs, "params");
|
|
2742
|
+
} catch (error) {
|
|
2743
|
+
throw createUserAPIError(error.message);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
const data = await config2.implement(...inputs);
|
|
2747
|
+
let ret = data;
|
|
2748
|
+
if (ret && "code" in ret) {
|
|
2749
|
+
const {
|
|
2750
|
+
code,
|
|
2751
|
+
data: originData,
|
|
2752
|
+
message: originMessage
|
|
2753
|
+
} = ret;
|
|
2754
|
+
status = code;
|
|
2755
|
+
message = originMessage;
|
|
2756
|
+
ret = originData;
|
|
2757
|
+
}
|
|
2758
|
+
Object.assign(res, {
|
|
2759
|
+
code: status,
|
|
2760
|
+
message,
|
|
2761
|
+
data: ret
|
|
2762
|
+
});
|
|
2763
|
+
return res;
|
|
2764
|
+
} catch (error) {
|
|
2765
|
+
const _error = error;
|
|
2766
|
+
const errNo = _error.code ?? _error.errNo ?? 2e3;
|
|
2767
|
+
status = "FAILURE";
|
|
2768
|
+
const msg = _error.message ?? _error.errMsg ?? `${error}`;
|
|
2769
|
+
const errMsg = `${method}:${status} ${msg.replace(/^\S+:(fail|cancel)\s?/, "")}`;
|
|
2770
|
+
Object.assign(res, {
|
|
2771
|
+
code: status,
|
|
2772
|
+
message: errMsg
|
|
2773
|
+
});
|
|
2774
|
+
reportError(new Q(errMsg, errNo));
|
|
2775
|
+
return res;
|
|
2776
|
+
} finally {
|
|
2777
|
+
const duration = Date.now() - startTime;
|
|
2778
|
+
track2("apiInvoked", { ...reportExtra, duration, status });
|
|
2779
|
+
}
|
|
2780
|
+
};
|
|
2781
|
+
}
|
|
2782
|
+
return { createAPI: createAPI2, createSyncAPI: createSyncAPI2 };
|
|
2783
|
+
};
|
|
2784
|
+
}
|
|
2785
|
+
});
|
|
2786
|
+
|
|
2787
|
+
// src/native/api/base.ts
|
|
2788
|
+
var createAPI, createSyncAPI, registerCanIUse;
|
|
2789
|
+
var init_base = __esm({
|
|
2790
|
+
"src/native/api/base.ts"() {
|
|
2791
|
+
"use strict";
|
|
2792
|
+
init_can_i_use();
|
|
2793
|
+
init_report5();
|
|
2794
|
+
init_api_factory();
|
|
2795
|
+
init_validator();
|
|
2796
|
+
({ createAPI, createSyncAPI } = createAPIFactory(track));
|
|
2797
|
+
registerCanIUse = registerCanIUseFactory("native");
|
|
2798
|
+
}
|
|
2799
|
+
});
|
|
2800
|
+
|
|
2801
|
+
// src/native/api/lifecycle.ts
|
|
2802
|
+
var require_lifecycle = __commonJS({
|
|
2803
|
+
"src/native/api/lifecycle.ts"(exports) {
|
|
2804
|
+
"use strict";
|
|
2805
|
+
init_index_es();
|
|
2806
|
+
init_base();
|
|
2807
|
+
init_report();
|
|
2808
|
+
init_bridge();
|
|
2809
|
+
init_report5();
|
|
2810
|
+
var EXIT_GAME = "exitGame";
|
|
2811
|
+
var ON_READY = "onReady";
|
|
2812
|
+
var ON_GAME_SHOW = "onGameShow";
|
|
2813
|
+
var ON_GAME_HIDE = "onGameHide";
|
|
2814
|
+
var commands8 = Vn();
|
|
2815
|
+
var safeCallbackWrapper2 = He(reportError);
|
|
2816
|
+
var exitGame = createAPI(EXIT_GAME, {
|
|
2817
|
+
paramsSchema: t.tuple(t.function()),
|
|
2818
|
+
implement: async (onBeforeExit) => {
|
|
2819
|
+
const safeCallback = safeCallbackWrapper2(onBeforeExit);
|
|
2820
|
+
safeCallback.call(exports);
|
|
2821
|
+
await applyNative("exitAppAsync");
|
|
2822
|
+
}
|
|
2823
|
+
});
|
|
2824
|
+
var onGameShow = createSyncAPI(ON_GAME_SHOW, {
|
|
2825
|
+
paramsSchema: t.tuple(t.function()),
|
|
2826
|
+
implement(callback) {
|
|
2827
|
+
const safeCallback = safeCallbackWrapper2(callback);
|
|
2828
|
+
onNative("onJoliboxEnterForeground", () => {
|
|
2829
|
+
safeCallback.call(this);
|
|
2830
|
+
nativeTaskEmitter.emit("visible", true);
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
var onGameHide = createSyncAPI(ON_GAME_HIDE, {
|
|
2835
|
+
paramsSchema: t.tuple(t.function()),
|
|
2836
|
+
implement(callback) {
|
|
2837
|
+
const safeCallback = safeCallbackWrapper2(callback);
|
|
2838
|
+
onNative("onJoliboxEnterBackground", () => {
|
|
2839
|
+
safeCallback.call(this);
|
|
2840
|
+
nativeTaskEmitter.emit("visible", false);
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
});
|
|
2844
|
+
var onReadyHandler = createSyncAPI(ON_READY, {
|
|
2845
|
+
paramsSchema: t.tuple(t.function()),
|
|
2846
|
+
implement(callback) {
|
|
2847
|
+
const safeCallback = safeCallbackWrapper2(callback);
|
|
2848
|
+
En.on("LifecycleEvent.onReady", (info) => {
|
|
2849
|
+
safeCallback(info);
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
commands8.registerCommand("LifecycleSDK.exit", exitGame);
|
|
2854
|
+
commands8.registerCommand("LifecycleSDK.onReady", onReadyHandler);
|
|
2855
|
+
commands8.registerCommand("LifecycleSDK.onJoliboxShow", onGameShow);
|
|
2856
|
+
commands8.registerCommand("LifecycleSDK.onJoliboxHide", onGameHide);
|
|
2857
|
+
registerCanIUse("lifeCycle.exit", {
|
|
2858
|
+
version: "1.0.0"
|
|
2859
|
+
// mock
|
|
2860
|
+
});
|
|
2861
|
+
registerCanIUse("lifeCycle.onReady", {
|
|
2862
|
+
version: "1.0.0"
|
|
2863
|
+
// mock
|
|
2864
|
+
});
|
|
2865
|
+
registerCanIUse("lifeCycle.onGameShow", {
|
|
2866
|
+
version: "1.0.0"
|
|
2867
|
+
// mock
|
|
2868
|
+
});
|
|
2869
|
+
registerCanIUse("lifeCycle.onGameHide", {
|
|
2870
|
+
version: "1.0.0"
|
|
2871
|
+
// mock
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2875
|
+
|
|
2876
|
+
// src/native/bootstrap/index.ts
|
|
2877
|
+
init_bridge();
|
|
2878
|
+
init_js_core();
|
|
2879
|
+
init_context();
|
|
2880
|
+
init_index_es();
|
|
2881
|
+
init_report5();
|
|
2882
|
+
RuntimeLoader.onReady(() => {
|
|
2883
|
+
});
|
|
2884
|
+
RuntimeLoader.doExit(() => {
|
|
2885
|
+
track("onBeforeExit", {
|
|
2886
|
+
timestamp: Date.now()
|
|
2887
|
+
});
|
|
2888
|
+
return false;
|
|
2889
|
+
});
|
|
2890
|
+
function addWebviewReadyListener() {
|
|
2891
|
+
En.on("onDocumentReady", () => {
|
|
2892
|
+
joliboxJSCore?.onDocumentReady(window.location.href);
|
|
2893
|
+
track("onDocumentReady", {
|
|
2894
|
+
start_timestamp,
|
|
2895
|
+
timestamp: Date.now()
|
|
2896
|
+
});
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
function addGameServiceReadyListener() {
|
|
2900
|
+
onNative("onJoliboxServiceReady", ({ runtimeInfo, loadDuration }) => {
|
|
2901
|
+
runtimeInfo && context.onEnvConfigChanged({ hostUserInfo: runtimeInfo });
|
|
2902
|
+
En.emit("LifecycleEvent.onReady", {
|
|
2903
|
+
...context.hostUserInfo ? context.hostUserInfo : { isLogin: false }
|
|
2904
|
+
});
|
|
2905
|
+
track("joliboxServiceReady", {
|
|
2906
|
+
start_timestamp,
|
|
2907
|
+
timestamp: Date.now()
|
|
2908
|
+
});
|
|
2909
|
+
taskTracker.start(loadDuration);
|
|
2910
|
+
});
|
|
2911
|
+
onNative("onBeforeExit", ({ uuid }) => {
|
|
2912
|
+
joliboxJSCore?.doExit(uuid);
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
var start_timestamp;
|
|
2916
|
+
function config() {
|
|
2917
|
+
start_timestamp = Date.now();
|
|
2918
|
+
addGameServiceReadyListener();
|
|
2919
|
+
addWebviewReadyListener();
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
// src/native/api/get-system-info.ts
|
|
2923
|
+
init_index_es();
|
|
2924
|
+
init_base();
|
|
2925
|
+
init_bridge();
|
|
2926
|
+
var commands2 = Vn();
|
|
2927
|
+
var API_ENV = "env";
|
|
2928
|
+
var API_GET_SYSTEM_SYNC = "getSystemInfoSync";
|
|
2929
|
+
var getSystemInfoSync = createSyncAPI(API_GET_SYSTEM_SYNC, {
|
|
2930
|
+
implement: () => {
|
|
2931
|
+
const res = invokeNative("envSync");
|
|
2932
|
+
const { data } = res;
|
|
2933
|
+
return {
|
|
2934
|
+
system: data.deviceInfo.system,
|
|
2935
|
+
platform: data.platform,
|
|
2936
|
+
version: data.sdkInfo.jssdkVersion,
|
|
2937
|
+
pixelRatio: data.deviceInfo.pixelRatio,
|
|
2938
|
+
language: data.deviceInfo.lang
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
var getEnv = createSyncAPI(API_ENV, {
|
|
2943
|
+
implement: () => {
|
|
2944
|
+
const res = invokeNative("envSync");
|
|
2945
|
+
return res?.data ?? void 0;
|
|
2946
|
+
}
|
|
2947
|
+
});
|
|
2948
|
+
commands2.registerCommand("API.getSystemInfoSync", getSystemInfoSync);
|
|
2949
|
+
commands2.registerCommand("API.env", getEnv);
|
|
2950
|
+
registerCanIUse("env", {
|
|
2951
|
+
version: "1.0.0"
|
|
2952
|
+
});
|
|
2953
|
+
registerCanIUse("getSystemInfoSync", {
|
|
2954
|
+
version: "1.0.0"
|
|
2955
|
+
});
|
|
2956
|
+
|
|
2957
|
+
// src/native/api/index.ts
|
|
2958
|
+
var import_lifecycle = __toESM(require_lifecycle());
|
|
2959
|
+
|
|
2960
|
+
// src/native/api/request.ts
|
|
2961
|
+
init_errors();
|
|
2962
|
+
init_create_fetch();
|
|
2963
|
+
init_base();
|
|
2964
|
+
|
|
2965
|
+
// src/native/network/utils.ts
|
|
2966
|
+
init_index_es();
|
|
2967
|
+
function normalizeHeader(header) {
|
|
2968
|
+
const normalized = {};
|
|
2969
|
+
if (!ie(header)) {
|
|
2970
|
+
return normalized;
|
|
2971
|
+
}
|
|
2972
|
+
for (const [_key, value] of Object.entries(header)) {
|
|
2973
|
+
const key = _key.toLocaleLowerCase();
|
|
2974
|
+
if (!value) {
|
|
2975
|
+
normalized[key] = "";
|
|
2976
|
+
} else if (typeof value === "object") {
|
|
2977
|
+
normalized[key] = Object.prototype.toString.call(value);
|
|
2978
|
+
} else {
|
|
2979
|
+
normalized[key] = String(value);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
return normalized;
|
|
2983
|
+
}
|
|
2984
|
+
function normalizeMethod(method = "GET") {
|
|
2985
|
+
if (method === "") {
|
|
2986
|
+
return "POST";
|
|
2987
|
+
}
|
|
2988
|
+
const _method = method.toUpperCase();
|
|
2989
|
+
if (["GET", "OPTIONS", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT", "PATCH"].includes(_method)) {
|
|
2990
|
+
return _method;
|
|
2991
|
+
}
|
|
2992
|
+
return "GET";
|
|
2993
|
+
}
|
|
2994
|
+
function normalizeTimeout(time, unlimited = false) {
|
|
2995
|
+
if (!time) return void 0;
|
|
2996
|
+
if (unlimited || time > 0 && time <= 6e4) return Math.ceil(time);
|
|
2997
|
+
return 6e4;
|
|
2998
|
+
}
|
|
2999
|
+
function dirtyURL(url, method, data) {
|
|
3000
|
+
if (["POST", "PUT", "PATCH"].includes(method)) return url;
|
|
3001
|
+
if (!ie(data)) return url;
|
|
3002
|
+
const [_url, search = ""] = url.split("?");
|
|
3003
|
+
const query = JSON.stringify({
|
|
3004
|
+
...JSON.parse(search),
|
|
3005
|
+
...data
|
|
3006
|
+
});
|
|
3007
|
+
return `${_url}?${query}`;
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
// src/native/api/request.ts
|
|
3011
|
+
init_index_es();
|
|
3012
|
+
init_report();
|
|
3013
|
+
var LIMIT = 15;
|
|
3014
|
+
var publicFetch = createFetch("createRequestTaskSync", "operateRequestTaskSync", {
|
|
3015
|
+
type: "public"
|
|
3016
|
+
});
|
|
3017
|
+
var activeCount = 0;
|
|
3018
|
+
var deferQueue = [];
|
|
3019
|
+
var safeCallbackWrapper = He(reportError);
|
|
3020
|
+
var remove = (array, predicate) => {
|
|
3021
|
+
const removedElements = array.filter(predicate);
|
|
3022
|
+
const remainingElements = array.filter((item) => !predicate(item));
|
|
3023
|
+
array.length = 0;
|
|
3024
|
+
array.push(...remainingElements);
|
|
3025
|
+
return removedElements;
|
|
3026
|
+
};
|
|
3027
|
+
var request = (_params) => {
|
|
3028
|
+
const deferred = new L();
|
|
3029
|
+
let teardown = () => {
|
|
3030
|
+
};
|
|
3031
|
+
const _request = createAPI("request", {
|
|
3032
|
+
paramsSchema: t.tuple(
|
|
3033
|
+
t.object({
|
|
3034
|
+
url: t.string(),
|
|
3035
|
+
method: t.string(),
|
|
3036
|
+
header: t.object(),
|
|
3037
|
+
data: t.object().optional(),
|
|
3038
|
+
query: t.object().optional(),
|
|
3039
|
+
dataType: t.string().default("json"),
|
|
3040
|
+
responseType: t.string().default("text"),
|
|
3041
|
+
enableCache: t.boolean().default(false),
|
|
3042
|
+
appendHostCookie: t.boolean().default(true),
|
|
3043
|
+
timeout: t.number().default(3e4),
|
|
3044
|
+
success: t.function(),
|
|
3045
|
+
fail: t.function()
|
|
3046
|
+
})
|
|
3047
|
+
),
|
|
3048
|
+
implement(params) {
|
|
3049
|
+
const action = async () => {
|
|
3050
|
+
const failCallback = safeCallbackWrapper(params.fail);
|
|
3051
|
+
try {
|
|
3052
|
+
activeCount += 1;
|
|
3053
|
+
if (deferred.state !== "pending") {
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
const { data, dataType, responseType, enableCache, appendHostCookie } = params;
|
|
3057
|
+
const header = normalizeHeader(params.header);
|
|
3058
|
+
const method = normalizeMethod(params.method);
|
|
3059
|
+
const timeout = normalizeTimeout(params.timeout);
|
|
3060
|
+
const url = dirtyURL(params.url, method, data);
|
|
3061
|
+
const successCallback = safeCallbackWrapper(params.success);
|
|
3062
|
+
const _params2 = Object.assign({}, params, {
|
|
3063
|
+
method,
|
|
3064
|
+
header,
|
|
3065
|
+
data: method === "GET" || method === "HEAD" ? void 0 : data,
|
|
3066
|
+
// GET HEAD 请求不需要 data 参数
|
|
3067
|
+
enableCache,
|
|
3068
|
+
query: params.query ?? {},
|
|
3069
|
+
dataType,
|
|
3070
|
+
responseType,
|
|
3071
|
+
appendHostCookie
|
|
3072
|
+
});
|
|
3073
|
+
if (timeout) _params2["timeout"] = timeout;
|
|
3074
|
+
const task = publicFetch(url, _params2);
|
|
3075
|
+
{
|
|
3076
|
+
const { response } = await task;
|
|
3077
|
+
const { code, data: data2, message } = response;
|
|
3078
|
+
deferred.resolve({
|
|
3079
|
+
code: code ?? "SUCCESS",
|
|
3080
|
+
data: data2,
|
|
3081
|
+
message: message ?? "request:ok"
|
|
3082
|
+
});
|
|
3083
|
+
successCallback({
|
|
3084
|
+
code: "SUCCESS",
|
|
3085
|
+
message: "request:ok",
|
|
3086
|
+
data: data2
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
} catch (err) {
|
|
3090
|
+
deferred.reject(err);
|
|
3091
|
+
failCallback({
|
|
3092
|
+
code: "FAILURE",
|
|
3093
|
+
message: "httpRequst: failed"
|
|
3094
|
+
});
|
|
3095
|
+
} finally {
|
|
3096
|
+
activeCount -= 1;
|
|
3097
|
+
deferQueue.shift()?.();
|
|
3098
|
+
}
|
|
3099
|
+
};
|
|
3100
|
+
if (activeCount >= LIMIT) {
|
|
3101
|
+
teardown = () => {
|
|
3102
|
+
remove(deferQueue, (i) => i === action);
|
|
3103
|
+
};
|
|
3104
|
+
deferQueue.push(action);
|
|
3105
|
+
} else {
|
|
3106
|
+
void action();
|
|
3107
|
+
}
|
|
3108
|
+
return deferred.promise;
|
|
3109
|
+
}
|
|
3110
|
+
});
|
|
3111
|
+
_request(_params);
|
|
3112
|
+
return {
|
|
3113
|
+
/**
|
|
3114
|
+
* 1. requesting...
|
|
3115
|
+
* 2. not in deferred
|
|
3116
|
+
*/
|
|
3117
|
+
abort() {
|
|
3118
|
+
deferred.reject(createAPIError({ code: -1, msg: "request:fail abort" }));
|
|
3119
|
+
teardown();
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
};
|
|
3123
|
+
var commands3 = Vn();
|
|
3124
|
+
commands3.registerCommand("HttpSDK.request", request);
|
|
3125
|
+
registerCanIUse("request", {
|
|
3126
|
+
version: "1.0.0"
|
|
3127
|
+
});
|
|
3128
|
+
|
|
3129
|
+
// src/native/api/storage.ts
|
|
3130
|
+
init_base();
|
|
3131
|
+
init_bridge();
|
|
3132
|
+
init_index_es();
|
|
3133
|
+
init_network();
|
|
3134
|
+
init_context();
|
|
3135
|
+
var commands4 = Vn();
|
|
3136
|
+
var getStorage2 = createAPI("getLocalStorage", {
|
|
3137
|
+
paramsSchema: t.tuple(t.string()),
|
|
3138
|
+
async implement(key) {
|
|
3139
|
+
const { response } = await innerFetch(`/api/games/user-storage/${context.game_id}`, {
|
|
3140
|
+
method: "GET",
|
|
3141
|
+
responseType: "json",
|
|
3142
|
+
appendHostCookie: true,
|
|
3143
|
+
query: {
|
|
3144
|
+
key
|
|
3145
|
+
}
|
|
3146
|
+
});
|
|
3147
|
+
const {
|
|
3148
|
+
data: { code, message, data: originData }
|
|
3149
|
+
} = await response;
|
|
3150
|
+
if (code === "SUCCESS") {
|
|
3151
|
+
return {
|
|
3152
|
+
code,
|
|
3153
|
+
message,
|
|
3154
|
+
data: originData?.value
|
|
3155
|
+
};
|
|
3156
|
+
}
|
|
3157
|
+
try {
|
|
3158
|
+
const {
|
|
3159
|
+
data: { data, dataType }
|
|
3160
|
+
} = await applyNative("getLocalStorageAsync", { key });
|
|
3161
|
+
const parsedData = parse(data, dataType);
|
|
3162
|
+
return {
|
|
3163
|
+
code,
|
|
3164
|
+
message: `${message}. fallback to native`,
|
|
3165
|
+
data: parsedData
|
|
3166
|
+
};
|
|
3167
|
+
} catch (error) {
|
|
3168
|
+
return {
|
|
3169
|
+
code: "INTERNAL_ERROR",
|
|
3170
|
+
message: "[Jolibox SDK] get local storage failed",
|
|
3171
|
+
data: null
|
|
3172
|
+
};
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
});
|
|
3176
|
+
commands4.registerCommand("StorageSDK.getItem", getStorage2);
|
|
3177
|
+
registerCanIUse("storage.getItem", {
|
|
3178
|
+
version: "1.0.0",
|
|
3179
|
+
properties: {
|
|
3180
|
+
key: "1.0.0",
|
|
3181
|
+
value: "1.0.0"
|
|
3182
|
+
}
|
|
3183
|
+
});
|
|
3184
|
+
var setStorage = createAPI("setStorage", {
|
|
3185
|
+
paramsSchema: t.tuple(t.string(), t.or(t.string(), t.boolean(), t.number())),
|
|
3186
|
+
async implement(key, value) {
|
|
3187
|
+
const gameId = context.game_id;
|
|
3188
|
+
const valueToStore = typeof value == "string" ? value : String(value);
|
|
3189
|
+
const { response } = await innerFetch(`/api/games/user-storage/${gameId}`, {
|
|
3190
|
+
method: "POST",
|
|
3191
|
+
responseType: "json",
|
|
3192
|
+
appendHostCookie: true,
|
|
3193
|
+
data: {
|
|
3194
|
+
key,
|
|
3195
|
+
value: valueToStore
|
|
3196
|
+
}
|
|
3197
|
+
});
|
|
3198
|
+
const {
|
|
3199
|
+
data: { code, message }
|
|
3200
|
+
} = response;
|
|
3201
|
+
const dataType = getType3(value);
|
|
3202
|
+
const data = stringify(value, dataType);
|
|
3203
|
+
await applyNative("setLocalStorageAsync", {
|
|
3204
|
+
key,
|
|
3205
|
+
data,
|
|
3206
|
+
dataType
|
|
3207
|
+
});
|
|
3208
|
+
if (code == "SUCCESS") {
|
|
3209
|
+
return {
|
|
3210
|
+
code,
|
|
3211
|
+
message
|
|
3212
|
+
};
|
|
3213
|
+
} else {
|
|
3214
|
+
return {
|
|
3215
|
+
code,
|
|
3216
|
+
message: `${message}. fallback to native`
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
});
|
|
3221
|
+
commands4.registerCommand("StorageSDK.setItem", setStorage);
|
|
3222
|
+
registerCanIUse("storage.setItem", {
|
|
3223
|
+
version: "1.0.0",
|
|
3224
|
+
properties: {
|
|
3225
|
+
key: "1.0.0",
|
|
3226
|
+
value: "1.0.0"
|
|
3227
|
+
}
|
|
3228
|
+
});
|
|
3229
|
+
var removeStorage = createAPI("removeStorage", {
|
|
3230
|
+
paramsSchema: t.tuple(t.string()),
|
|
3231
|
+
async implement(key) {
|
|
3232
|
+
const gameId = context.game_id;
|
|
3233
|
+
const { response } = await innerFetch(`/api/games/user-storage/${gameId}/remove`, {
|
|
3234
|
+
method: "POST",
|
|
3235
|
+
responseType: "json",
|
|
3236
|
+
appendHostCookie: true,
|
|
3237
|
+
data: {
|
|
3238
|
+
key
|
|
3239
|
+
}
|
|
3240
|
+
});
|
|
3241
|
+
const {
|
|
3242
|
+
data: { code, message }
|
|
3243
|
+
} = response;
|
|
3244
|
+
await applyNative("removeLocalStorageAsync", { key });
|
|
3245
|
+
if (code === "SUCCESS") {
|
|
3246
|
+
return {
|
|
3247
|
+
code,
|
|
3248
|
+
message
|
|
3249
|
+
};
|
|
3250
|
+
} else {
|
|
3251
|
+
return {
|
|
3252
|
+
code,
|
|
3253
|
+
message: "[Jolibox SDK] remove item succ"
|
|
3254
|
+
};
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
});
|
|
3258
|
+
commands4.registerCommand("StorageSDK.removeItem", removeStorage);
|
|
3259
|
+
registerCanIUse("storage.removeItem", {
|
|
3260
|
+
version: "1.0.0",
|
|
3261
|
+
properties: {
|
|
3262
|
+
key: "1.0.0"
|
|
3263
|
+
}
|
|
3264
|
+
});
|
|
3265
|
+
var clearStorage = createAPI("clearStorage", {
|
|
3266
|
+
async implement() {
|
|
3267
|
+
const gameId = context.game_id;
|
|
3268
|
+
const { response } = await innerFetch(`/api/games/user-storage/${gameId}/clear`, {
|
|
3269
|
+
method: "POST",
|
|
3270
|
+
appendHostCookie: true
|
|
3271
|
+
});
|
|
3272
|
+
applyNative("clearLocalStorageAsync");
|
|
3273
|
+
const {
|
|
3274
|
+
data: { code, message }
|
|
3275
|
+
} = response;
|
|
3276
|
+
if (code === "SUCCESS") {
|
|
3277
|
+
return {
|
|
3278
|
+
code,
|
|
3279
|
+
message
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
return {
|
|
3283
|
+
code,
|
|
3284
|
+
message: `${message}.fallback to native`
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3288
|
+
commands4.registerCommand("StorageSDK.clear", clearStorage);
|
|
3289
|
+
registerCanIUse("storage.clear", {
|
|
3290
|
+
version: "1.0.0"
|
|
3291
|
+
});
|
|
3292
|
+
var getStorageInfo = createAPI("getStorageInfo", {
|
|
3293
|
+
async implement() {
|
|
3294
|
+
const { data } = await applyNative("getStorageInfoAsync");
|
|
3295
|
+
return data;
|
|
3296
|
+
}
|
|
3297
|
+
});
|
|
3298
|
+
registerCanIUse("getStorageInfo", {
|
|
3299
|
+
version: "1.0.0",
|
|
3300
|
+
success: {
|
|
3301
|
+
keys: "1.0.0",
|
|
3302
|
+
// string[] 本地数据缓存中的所有键名列表,如本地数据则返回空数组
|
|
3303
|
+
currentSize: "1.0.0",
|
|
3304
|
+
// number 当前占用的空间大小,以 KB 为单位
|
|
3305
|
+
limitSize: "1.0.0"
|
|
3306
|
+
// number 存储空间上限,以 KB 为单位,一般来说会返回 10240
|
|
3307
|
+
}
|
|
3308
|
+
});
|
|
3309
|
+
var getStorageInfoSync = createSyncAPI("getStorageInfoSync", {
|
|
3310
|
+
implement() {
|
|
3311
|
+
return invokeNative("getStorageInfoSync");
|
|
3312
|
+
}
|
|
3313
|
+
});
|
|
3314
|
+
var DATA_TYPE = [
|
|
3315
|
+
"string",
|
|
3316
|
+
"number",
|
|
3317
|
+
"boolean",
|
|
3318
|
+
"object",
|
|
3319
|
+
""
|
|
3320
|
+
// 表示不支持的类型
|
|
3321
|
+
];
|
|
3322
|
+
function getType3(data) {
|
|
3323
|
+
const type = Object.prototype.toString.call(data).split(" ")[1].split("]")[0].toLocaleLowerCase();
|
|
3324
|
+
if (DATA_TYPE.includes(type)) {
|
|
3325
|
+
return type;
|
|
3326
|
+
}
|
|
3327
|
+
return "";
|
|
3328
|
+
}
|
|
3329
|
+
function parse(str, type) {
|
|
3330
|
+
try {
|
|
3331
|
+
switch (type) {
|
|
3332
|
+
case "string":
|
|
3333
|
+
return str;
|
|
3334
|
+
case "object":
|
|
3335
|
+
return JSON.parse(str);
|
|
3336
|
+
case "number":
|
|
3337
|
+
return parseFloat(str);
|
|
3338
|
+
case "boolean":
|
|
3339
|
+
return str === "true";
|
|
3340
|
+
default:
|
|
3341
|
+
return "";
|
|
3342
|
+
}
|
|
3343
|
+
} catch {
|
|
3344
|
+
return "";
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
function stringify(data, type) {
|
|
3348
|
+
try {
|
|
3349
|
+
switch (type) {
|
|
3350
|
+
case "string":
|
|
3351
|
+
case "number":
|
|
3352
|
+
case "boolean":
|
|
3353
|
+
return `${data}`;
|
|
3354
|
+
case "object":
|
|
3355
|
+
return JSON.stringify(data);
|
|
3356
|
+
default:
|
|
3357
|
+
return "";
|
|
3358
|
+
}
|
|
3359
|
+
} catch {
|
|
3360
|
+
return "";
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
// src/native/api/keyboard.ts
|
|
3365
|
+
init_index_es();
|
|
3366
|
+
init_bridge();
|
|
3367
|
+
init_base();
|
|
3368
|
+
var showKeyboard = createAPI("showKeyboard", {
|
|
3369
|
+
paramsSchema: t.tuple(
|
|
3370
|
+
t.object({
|
|
3371
|
+
defaultValue: t.string().default(""),
|
|
3372
|
+
multiple: t.boolean().default(false),
|
|
3373
|
+
maxLength: t.unknown().optional().default(1e5)
|
|
3374
|
+
})
|
|
3375
|
+
),
|
|
3376
|
+
async implement(params) {
|
|
3377
|
+
const maxLength = Math.floor(Number(params.maxLength) ?? 1e5);
|
|
3378
|
+
let { defaultValue } = params;
|
|
3379
|
+
if (defaultValue && maxLength) {
|
|
3380
|
+
defaultValue = defaultValue.slice(0, maxLength);
|
|
3381
|
+
}
|
|
3382
|
+
applyNative("showKeyboardSync", { ...params, defaultValue, maxLength });
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
registerCanIUse("keyboard.showKeyboard", {
|
|
3386
|
+
version: "1.0.0",
|
|
3387
|
+
properties: {
|
|
3388
|
+
params: {
|
|
3389
|
+
defaultValue: "1.0.0",
|
|
3390
|
+
multiple: "1.0.0",
|
|
3391
|
+
confirmHold: "1.0.0",
|
|
3392
|
+
confirmType: "1.0.0",
|
|
3393
|
+
maxLength: "1.0.0"
|
|
3394
|
+
}
|
|
3395
|
+
},
|
|
3396
|
+
success: {
|
|
3397
|
+
errMsg: "1.0.0"
|
|
3398
|
+
}
|
|
3399
|
+
});
|
|
3400
|
+
var updateKeyboard = createAPI("updateKeyboard", {
|
|
3401
|
+
paramsSchema: t.tuple(
|
|
3402
|
+
t.object({
|
|
3403
|
+
value: t.string()
|
|
3404
|
+
})
|
|
3405
|
+
),
|
|
3406
|
+
async implement(params) {
|
|
3407
|
+
applyNative("updateKeyboardSync", params);
|
|
3408
|
+
}
|
|
3409
|
+
});
|
|
3410
|
+
registerCanIUse("keyboard.updateKeyboard", {
|
|
3411
|
+
version: "1.0.0",
|
|
3412
|
+
properties: {
|
|
3413
|
+
params: {
|
|
3414
|
+
value: "1.0.0"
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
});
|
|
3418
|
+
var hideKeyboard = createAPI("hideKeyboard", {
|
|
3419
|
+
async implement() {
|
|
3420
|
+
applyNative("hideKeyboardSync");
|
|
3421
|
+
}
|
|
3422
|
+
});
|
|
3423
|
+
registerCanIUse("keyboard.hideKeyboard", {
|
|
3424
|
+
version: "1.0.0"
|
|
3425
|
+
});
|
|
3426
|
+
var commands5 = Vn();
|
|
3427
|
+
commands5.registerCommand("KeyboardSDK.showKeyboard", showKeyboard);
|
|
3428
|
+
commands5.registerCommand("KeyboardSDK.updateKeyboard", updateKeyboard);
|
|
3429
|
+
commands5.registerCommand("KeyboardSDK.hideKeyboard", hideKeyboard);
|
|
3430
|
+
|
|
3431
|
+
// src/native/api/task.ts
|
|
3432
|
+
init_index_es();
|
|
3433
|
+
init_base();
|
|
3434
|
+
init_report5();
|
|
3435
|
+
var commands6 = Vn();
|
|
3436
|
+
var onLevelFinished = createAPI("levelFinished", {
|
|
3437
|
+
paramsSchema: t.tuple(
|
|
3438
|
+
t.string(),
|
|
3439
|
+
t.object({
|
|
3440
|
+
result: t.boolean(),
|
|
3441
|
+
duration: t.number()
|
|
3442
|
+
})
|
|
3443
|
+
),
|
|
3444
|
+
implement: async (levelId, parmas) => {
|
|
3445
|
+
const { result, duration } = parmas;
|
|
3446
|
+
const tasks = [];
|
|
3447
|
+
tasks.push(
|
|
3448
|
+
taskTracker.reportToNative({
|
|
3449
|
+
event: "LEVEL_FINISHED",
|
|
3450
|
+
params: {
|
|
3451
|
+
levelId,
|
|
3452
|
+
result,
|
|
3453
|
+
duration
|
|
3454
|
+
}
|
|
3455
|
+
})
|
|
3456
|
+
);
|
|
3457
|
+
tasks.push(
|
|
3458
|
+
taskTracker.reporter({
|
|
3459
|
+
event: "COMPLETE_QUEST"
|
|
3460
|
+
})
|
|
3461
|
+
);
|
|
3462
|
+
await Promise.all(tasks);
|
|
3463
|
+
}
|
|
3464
|
+
});
|
|
3465
|
+
var onTaskFinished = createAPI("taskFinished", {
|
|
3466
|
+
paramsSchema: t.tuple(
|
|
3467
|
+
t.string(),
|
|
3468
|
+
t.object({
|
|
3469
|
+
duration: t.number()
|
|
3470
|
+
})
|
|
3471
|
+
),
|
|
3472
|
+
implement: async (taskId, params) => {
|
|
3473
|
+
const { duration } = params;
|
|
3474
|
+
return await taskTracker.reportToNative({
|
|
3475
|
+
event: "TASK_FINISHED",
|
|
3476
|
+
params: {
|
|
3477
|
+
duration,
|
|
3478
|
+
taskId
|
|
3479
|
+
}
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
});
|
|
3483
|
+
var onLevelUpgrade = createAPI("levelUpgrade", {
|
|
3484
|
+
paramsSchema: t.tuple(t.string(), t.string()),
|
|
3485
|
+
implement: async (levelId, name) => {
|
|
3486
|
+
const tasks = [];
|
|
3487
|
+
tasks.push(
|
|
3488
|
+
taskTracker.reporter({
|
|
3489
|
+
event: "COMPLETE_QUEST"
|
|
3490
|
+
})
|
|
3491
|
+
);
|
|
3492
|
+
tasks.push(
|
|
3493
|
+
taskTracker.reportToNative({
|
|
3494
|
+
event: "LEVEL_UPGRADE",
|
|
3495
|
+
params: {
|
|
3496
|
+
name,
|
|
3497
|
+
levelId
|
|
3498
|
+
}
|
|
3499
|
+
})
|
|
3500
|
+
);
|
|
3501
|
+
await Promise.all(tasks);
|
|
3502
|
+
}
|
|
3503
|
+
});
|
|
3504
|
+
var onHistoryUserLevel = createAPI("onHistoryUserLevel", {
|
|
3505
|
+
paramsSchema: t.tuple(t.number()),
|
|
3506
|
+
implement: async (level) => {
|
|
3507
|
+
return await taskTracker.reportToNative({
|
|
3508
|
+
event: "HISTORY_USER_LEVEL",
|
|
3509
|
+
params: {
|
|
3510
|
+
level
|
|
3511
|
+
}
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
});
|
|
3515
|
+
var onHistoryUserScore = createAPI("onHistoryUserScore", {
|
|
3516
|
+
paramsSchema: t.tuple(t.number()),
|
|
3517
|
+
implement: async (score) => {
|
|
3518
|
+
return await taskTracker.reportToNative({
|
|
3519
|
+
event: "HISTORY_USER_SCORE",
|
|
3520
|
+
params: {
|
|
3521
|
+
score
|
|
3522
|
+
}
|
|
3523
|
+
});
|
|
3524
|
+
}
|
|
3525
|
+
});
|
|
3526
|
+
var onTaskEvent = createAPI("taskEvent", {
|
|
3527
|
+
paramsSchema: t.tuple(
|
|
3528
|
+
t.string(),
|
|
3529
|
+
t.object({
|
|
3530
|
+
tools: t.array(
|
|
3531
|
+
t.object({
|
|
3532
|
+
id: t.string(),
|
|
3533
|
+
name: t.string(),
|
|
3534
|
+
count: t.number(),
|
|
3535
|
+
description: t.string().optional(),
|
|
3536
|
+
price: t.object({
|
|
3537
|
+
amount: t.number(),
|
|
3538
|
+
unit: t.string()
|
|
3539
|
+
}).optional()
|
|
3540
|
+
})
|
|
3541
|
+
).optional(),
|
|
3542
|
+
awards: t.array(
|
|
3543
|
+
t.object({
|
|
3544
|
+
id: t.string(),
|
|
3545
|
+
name: t.string()
|
|
3546
|
+
})
|
|
3547
|
+
).optional()
|
|
3548
|
+
})
|
|
3549
|
+
),
|
|
3550
|
+
implement: async (taskId, params) => {
|
|
3551
|
+
const tasks = [];
|
|
3552
|
+
tasks.push(
|
|
3553
|
+
taskTracker.reportToNative({
|
|
3554
|
+
event: "TASK_EVENT",
|
|
3555
|
+
params: {
|
|
3556
|
+
taskId,
|
|
3557
|
+
...params
|
|
3558
|
+
}
|
|
3559
|
+
})
|
|
3560
|
+
);
|
|
3561
|
+
if (params.tools?.length ?? 0 > 0) {
|
|
3562
|
+
tasks.push(
|
|
3563
|
+
taskTracker.reporter({
|
|
3564
|
+
event: "USE_GAME_ITEM"
|
|
3565
|
+
})
|
|
3566
|
+
);
|
|
3567
|
+
}
|
|
3568
|
+
await Promise.all(tasks);
|
|
3569
|
+
}
|
|
3570
|
+
});
|
|
3571
|
+
var onTaskPayment = createAPI("taskPayment", {
|
|
3572
|
+
paramsSchema: t.tuple(
|
|
3573
|
+
t.string(),
|
|
3574
|
+
t.object({
|
|
3575
|
+
id: t.string(),
|
|
3576
|
+
amount: t.number(),
|
|
3577
|
+
unit: t.string()
|
|
3578
|
+
})
|
|
3579
|
+
),
|
|
3580
|
+
implement: async (taskId, params) => {
|
|
3581
|
+
const tasks = [];
|
|
3582
|
+
tasks.push(
|
|
3583
|
+
taskTracker.reportToNative({
|
|
3584
|
+
event: "TASK_PAYMENT",
|
|
3585
|
+
params: {
|
|
3586
|
+
taskId,
|
|
3587
|
+
params
|
|
3588
|
+
}
|
|
3589
|
+
})
|
|
3590
|
+
);
|
|
3591
|
+
tasks.push(
|
|
3592
|
+
taskTracker.reporter({
|
|
3593
|
+
event: "IN_GAME_PURCHASES"
|
|
3594
|
+
})
|
|
3595
|
+
);
|
|
3596
|
+
await Promise.all(tasks);
|
|
3597
|
+
}
|
|
3598
|
+
});
|
|
3599
|
+
commands6.registerCommand("TaskTrackerSDK.levelFinished", onLevelFinished);
|
|
3600
|
+
commands6.registerCommand("TaskTrackerSDK.taskFinished", onTaskFinished);
|
|
3601
|
+
commands6.registerCommand("TaskTrackerSDK.levelUpgrade", onLevelUpgrade);
|
|
3602
|
+
commands6.registerCommand("TaskTrackerSDK.historyUserLevel", onHistoryUserLevel);
|
|
3603
|
+
commands6.registerCommand("TaskTrackerSDK.historyUserScore", onHistoryUserScore);
|
|
3604
|
+
commands6.registerCommand("TaskTrackerSDK.taskEvent", onTaskEvent);
|
|
3605
|
+
commands6.registerCommand("TaskTrackerSDK.taskPayment", onTaskPayment);
|
|
3606
|
+
registerCanIUse("TaskTrackerSDK.onLevelFinished", {
|
|
3607
|
+
version: "1.0.0",
|
|
3608
|
+
properties: {
|
|
3609
|
+
levelId: "1.0.0",
|
|
3610
|
+
params: {
|
|
3611
|
+
result: "1.0.0",
|
|
3612
|
+
duration: "1.0.0"
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
});
|
|
3616
|
+
registerCanIUse("TaskTrackerSDK.onTaskFinished", {
|
|
3617
|
+
version: "1.0.0",
|
|
3618
|
+
properties: {
|
|
3619
|
+
taskId: "1.0.0",
|
|
3620
|
+
duration: "1.0.0"
|
|
3621
|
+
}
|
|
3622
|
+
});
|
|
3623
|
+
registerCanIUse("TaskTrackerSDK.onLevelUpgrade", {
|
|
3624
|
+
version: "1.0.0",
|
|
3625
|
+
properties: {
|
|
3626
|
+
levelId: "1.0.0",
|
|
3627
|
+
name: "1.0.0"
|
|
3628
|
+
}
|
|
3629
|
+
});
|
|
3630
|
+
registerCanIUse("TaskTrackerSDK.onHistoryUserLevel", {
|
|
3631
|
+
version: "1.0.0",
|
|
3632
|
+
properties: {
|
|
3633
|
+
level: "1.0.0"
|
|
3634
|
+
}
|
|
3635
|
+
});
|
|
3636
|
+
registerCanIUse("TaskTrackerSDK.onHistoryUserScore", {
|
|
3637
|
+
version: "1.0.0",
|
|
3638
|
+
properties: {
|
|
3639
|
+
score: "1.0.0"
|
|
3640
|
+
}
|
|
3641
|
+
});
|
|
3642
|
+
registerCanIUse("TaskTrackerSDK.onTaskEvent", {
|
|
3643
|
+
version: "1.0.0",
|
|
3644
|
+
properties: {
|
|
3645
|
+
taskId: "1.0.0",
|
|
3646
|
+
params: {
|
|
3647
|
+
tools: {
|
|
3648
|
+
id: "1.0.0",
|
|
3649
|
+
name: "1.0.0",
|
|
3650
|
+
count: "1.0.0",
|
|
3651
|
+
description: "1.0.0",
|
|
3652
|
+
price: {
|
|
3653
|
+
amount: "1.0.0",
|
|
3654
|
+
unit: "1.0.0"
|
|
3655
|
+
}
|
|
3656
|
+
},
|
|
3657
|
+
awards: {
|
|
3658
|
+
id: "1.0.0",
|
|
3659
|
+
name: "1.0.0"
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
registerCanIUse("TaskTrackerSDK.onTaskPayment", {
|
|
3665
|
+
version: "1.0.0",
|
|
3666
|
+
properties: {
|
|
3667
|
+
taskId: "1.0.0",
|
|
3668
|
+
params: {
|
|
3669
|
+
amount: "1.0.0",
|
|
3670
|
+
unit: "1.0.0"
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
});
|
|
3674
|
+
|
|
3675
|
+
// src/native/api/login.ts
|
|
3676
|
+
init_context();
|
|
3677
|
+
init_bridge();
|
|
3678
|
+
init_base();
|
|
3679
|
+
init_index_es();
|
|
3680
|
+
init_errors();
|
|
3681
|
+
registerCanIUse("login", {
|
|
3682
|
+
version: "1.0.0",
|
|
3683
|
+
properties: {
|
|
3684
|
+
force: "1.0.0"
|
|
3685
|
+
},
|
|
3686
|
+
success: {
|
|
3687
|
+
errMsg: "1.0.0",
|
|
3688
|
+
code: "1.0.0",
|
|
3689
|
+
token: "1.0.0",
|
|
3690
|
+
isLogin: "1.0.0"
|
|
3691
|
+
}
|
|
3692
|
+
});
|
|
3693
|
+
registerCanIUse("checkSession", {
|
|
3694
|
+
version: "1.0.0",
|
|
3695
|
+
success: {
|
|
3696
|
+
errMsg: "1.0.0"
|
|
3697
|
+
}
|
|
3698
|
+
});
|
|
3699
|
+
var login = createAPI("login", {
|
|
3700
|
+
async implement() {
|
|
3701
|
+
const isLogin = await applyNative("checkLoginAsync");
|
|
3702
|
+
if (isLogin) {
|
|
3703
|
+
return { isLogin: true, token: context.hostUserInfo?.token };
|
|
3704
|
+
}
|
|
3705
|
+
onNative("onLoginStateChange", ({ isLogin: isLogin2, token, uuid }) => {
|
|
3706
|
+
if (uuid == loginUUID) {
|
|
3707
|
+
resolve({ isLogin: isLogin2, token });
|
|
3708
|
+
}
|
|
3709
|
+
});
|
|
3710
|
+
const res = invokeNative("loginSync");
|
|
3711
|
+
const {
|
|
3712
|
+
data: { uuid: loginUUID }
|
|
3713
|
+
} = res;
|
|
3714
|
+
if (!loginUUID) {
|
|
3715
|
+
throw createAPIError({
|
|
3716
|
+
code: -1,
|
|
3717
|
+
msg: "login failed"
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
const { promise, resolve } = new L();
|
|
3721
|
+
const loginRes = await promise;
|
|
3722
|
+
context.onEnvConfigChanged({ hostUserInfo: loginRes });
|
|
3723
|
+
En.emit("onLoginComplete", loginRes);
|
|
3724
|
+
return loginRes;
|
|
3725
|
+
}
|
|
3726
|
+
});
|
|
3727
|
+
var checkSession = createAPI("checkSession", {
|
|
3728
|
+
async implement() {
|
|
3729
|
+
const {
|
|
3730
|
+
data: { isLogin }
|
|
3731
|
+
} = await applyNative("checkLoginAsync");
|
|
3732
|
+
return {
|
|
3733
|
+
isLogin
|
|
3734
|
+
};
|
|
3735
|
+
}
|
|
3736
|
+
});
|
|
3737
|
+
var commands7 = Vn();
|
|
3738
|
+
commands7.registerCommand("API.login", login);
|
|
3739
|
+
commands7.registerCommand("API.checkSession", checkSession);
|
|
3740
|
+
|
|
3741
|
+
// src/index.native.ts
|
|
3742
|
+
init_report5();
|
|
3743
|
+
config();
|