@skillbuilder/miniapp-simulator 0.2.2 → 0.2.7
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/docs/assets/audit-auto-stop-config-2026-10-21.jpg +0 -0
- package/docs/assets/audit-balanced-panel-2026-10-16.jpg +0 -0
- package/docs/assets/audit-lcp-input-2026-10-20.jpg +0 -0
- package/docs/assets/audit-paint-game3d-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-apm-excerpt-2026-10-16.json +397 -0
- package/docs/assets/audit-poetry-2026-10-16.jpg +0 -0
- package/docs/assets/audit-remaining-results-2026-10-16.json +2749 -0
- package/docs/assets/miniapp-audit-risk-review-2026-10-13.png +0 -0
- package/docs/assets/miniapp-audit-runtime-hung-2026-10-13.png +0 -0
- package/docs/audit-data-collection.codex.md +105 -0
- package/docs/audit-local-validation.codex.md +165 -0
- package/docs/audit-score-design.codex.md +222 -0
- package/docs/audit-score-design.md +832 -0
- package/docs/audit-score-tech-plan.md +450 -0
- package/docs/audit-tech-design.codex.md +485 -0
- package/docs/electron-review.md +223 -12
- package/docs/quality-evaluation-redoc.xml +163 -0
- package/docs/tracker.md +3 -2
- package/lib/client-BjYHK9LR.mjs +1220 -0
- package/lib/{index-D5AYVv8s.mjs → index-CqClPZVv.mjs} +230 -184
- package/lib/index.js +2204 -1999
- package/lib/remote-client.js +2 -2
- package/lib/types/host/shadow-host.d.ts +10 -0
- package/lib/types/injection/registry.d.ts +5 -0
- package/lib/types/remote/audit-controller.d.ts +61 -0
- package/lib/types/remote/audit-leave-monitor.d.ts +12 -0
- package/lib/types/remote/audit-package-sources.d.ts +9 -0
- package/lib/types/remote/audit-telemetry.d.ts +36 -0
- package/lib/types/remote/audit-watchdog.d.ts +14 -0
- package/lib/types/remote/client.d.ts +25 -1
- package/lib/types/remote/load-timing.d.ts +5 -0
- package/lib/types/remote/protocol.d.ts +162 -1
- package/lib/types/remote/runtime.d.ts +2 -0
- package/lib/types/remote-client.d.ts +2 -2
- package/lib/types/runtime/jsapi-modules/interaction.d.ts +1 -1
- package/lib/types/runtime/jsapi-modules/local-media.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/media.d.ts +1 -1
- package/lib/types/runtime/jsapi-modules/note-publish-media.d.ts +9 -0
- package/lib/types/sw/service-worker-host.d.ts +15 -0
- package/lib/types/tracker/constants.d.ts +1 -1
- package/lib/types/tracker/default-tracker.d.ts +9 -1
- package/lib/types/types/options.d.ts +24 -0
- package/lib/workbench.js +1 -1
- package/package.json +1 -1
- package/lib/client-_vNHVHSm.mjs +0 -775
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const T = "0.2.7", v = /* @__PURE__ */ new Set();
|
|
2
|
+
function Z(e, n) {
|
|
3
3
|
const t = () => {
|
|
4
|
-
let
|
|
5
|
-
for (let
|
|
6
|
-
const a = getComputedStyle(
|
|
7
|
-
|
|
8
|
-
const c =
|
|
9
|
-
|
|
4
|
+
let r = !document.hidden && e.isConnected;
|
|
5
|
+
for (let s = e; r && s; ) {
|
|
6
|
+
const a = getComputedStyle(s);
|
|
7
|
+
r = a.display !== "none" && a.visibility !== "hidden" && a.visibility !== "collapse";
|
|
8
|
+
const c = s.getRootNode();
|
|
9
|
+
s = s.parentElement ?? (c instanceof ShadowRoot ? c.host : null);
|
|
10
10
|
}
|
|
11
|
-
n(
|
|
12
|
-
},
|
|
13
|
-
for (let
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
11
|
+
n(r);
|
|
12
|
+
}, o = new MutationObserver(t);
|
|
13
|
+
for (let r = e; r; ) {
|
|
14
|
+
o.observe(r, { attributes: !0, attributeFilter: ["style", "class", "hidden"] });
|
|
15
|
+
const s = r.getRootNode();
|
|
16
|
+
r = r.parentElement ?? (s instanceof ShadowRoot ? s.host : null);
|
|
17
17
|
}
|
|
18
18
|
return document.addEventListener("visibilitychange", t), window.addEventListener("resize", t), window.addEventListener("pageshow", t), t(), () => {
|
|
19
|
-
|
|
19
|
+
o.disconnect(), document.removeEventListener("visibilitychange", t), window.removeEventListener("resize", t), window.removeEventListener("pageshow", t);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
let t = "",
|
|
24
|
-
const
|
|
22
|
+
function J(e, n) {
|
|
23
|
+
let t = "", o = 0;
|
|
24
|
+
const r = () => {
|
|
25
25
|
if (document.hidden || !e.isConnected) return !1;
|
|
26
|
-
for (let
|
|
27
|
-
const u = getComputedStyle(
|
|
26
|
+
for (let i = e; i; ) {
|
|
27
|
+
const u = getComputedStyle(i);
|
|
28
28
|
if (u.display === "none" || u.visibility === "hidden" || u.visibility === "collapse")
|
|
29
29
|
return !1;
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const l = i.getRootNode();
|
|
31
|
+
i = i.parentElement ?? (l instanceof ShadowRoot ? l.host : null);
|
|
32
32
|
}
|
|
33
33
|
return !0;
|
|
34
|
-
},
|
|
34
|
+
}, s = () => {
|
|
35
35
|
if (t)
|
|
36
36
|
try {
|
|
37
|
-
const
|
|
37
|
+
const i = new URL(n(), location.href).origin;
|
|
38
38
|
e.contentWindow?.postMessage(
|
|
39
39
|
{
|
|
40
40
|
type: "mini-app:worker-state",
|
|
41
41
|
sessionId: t,
|
|
42
|
-
sequence: ++
|
|
43
|
-
state:
|
|
42
|
+
sequence: ++o,
|
|
43
|
+
state: r() ? "visible" : "hidden"
|
|
44
44
|
},
|
|
45
|
-
|
|
45
|
+
i
|
|
46
46
|
);
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
|
-
}, a = (
|
|
50
|
-
if (!(!
|
|
49
|
+
}, a = (i) => {
|
|
50
|
+
if (!(!i.isTrusted || i.source !== e.contentWindow || i.data?.type !== "mini-app:worker-ready" || typeof i.data.sessionId != "string")) {
|
|
51
51
|
try {
|
|
52
|
-
if (
|
|
52
|
+
if (i.origin !== new URL(n(), location.href).origin || e.contentWindow?.__MINITOOL_WORKER_CONTEXT__?.sessionId !== i.data.sessionId)
|
|
53
53
|
return;
|
|
54
54
|
} catch {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
t =
|
|
57
|
+
t = i.data.sessionId, s();
|
|
58
58
|
}
|
|
59
|
-
}, c = new MutationObserver(
|
|
60
|
-
for (let
|
|
61
|
-
c.observe(
|
|
62
|
-
const u =
|
|
63
|
-
|
|
59
|
+
}, c = new MutationObserver(s);
|
|
60
|
+
for (let i = e; i; ) {
|
|
61
|
+
c.observe(i, { attributes: !0, attributeFilter: ["style", "class", "hidden"] });
|
|
62
|
+
const u = i.getRootNode();
|
|
63
|
+
i = i.parentElement ?? (u instanceof ShadowRoot ? u.host : null);
|
|
64
64
|
}
|
|
65
|
-
return window.addEventListener("message", a), window.addEventListener("resize",
|
|
66
|
-
|
|
65
|
+
return window.addEventListener("message", a), window.addEventListener("resize", s), window.addEventListener("pageshow", s), document.addEventListener("visibilitychange", s), v.add(s), () => {
|
|
66
|
+
v.delete(s), c.disconnect(), window.removeEventListener("message", a), window.removeEventListener("resize", s), window.removeEventListener("pageshow", s), document.removeEventListener("visibilitychange", s);
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
var
|
|
70
|
-
function
|
|
69
|
+
var f = /* @__PURE__ */ ((e) => (e[e.INVALID_PARAM = 10001] = "INVALID_PARAM", e[e.API_UNAVAILABLE = 10002] = "API_UNAVAILABLE", e[e.URL_SCHEME_NOT_ALLOWED = 10003] = "URL_SCHEME_NOT_ALLOWED", e[e.REQUEST_TIMEOUT = 10101] = "REQUEST_TIMEOUT", e[e.REQUEST_ABORTED = 10102] = "REQUEST_ABORTED", e[e.REQUEST_FAILED = 15201] = "REQUEST_FAILED", e[e.STORAGE_IO_ERROR = 50101] = "STORAGE_IO_ERROR", e[e.STORAGE_QUOTA_EXCEEDED = 50201] = "STORAGE_QUOTA_EXCEEDED", e[e.FILE_NOT_FOUND = 50202] = "FILE_NOT_FOUND", e[e.PATH_INVALID = 50203] = "PATH_INVALID", e[e.FILE_ALREADY_EXISTS = 50204] = "FILE_ALREADY_EXISTS", e[e.NOT_A_FILE = 50205] = "NOT_A_FILE", e[e.NOT_A_DIRECTORY = 50206] = "NOT_A_DIRECTORY", e))(f || {});
|
|
70
|
+
function m(e, n) {
|
|
71
71
|
return Object.assign(new Error(n), { code: e });
|
|
72
72
|
}
|
|
73
|
-
class
|
|
73
|
+
class I {
|
|
74
74
|
constructor() {
|
|
75
75
|
this.buffer = "";
|
|
76
76
|
}
|
|
@@ -84,30 +84,30 @@ class k {
|
|
|
84
84
|
}
|
|
85
85
|
drain(n) {
|
|
86
86
|
const t = [];
|
|
87
|
-
let
|
|
88
|
-
for (;
|
|
89
|
-
const a = this.buffer[
|
|
87
|
+
let o = 0, r = 0, s = 0;
|
|
88
|
+
for (; s < this.buffer.length; ) {
|
|
89
|
+
const a = this.buffer[s];
|
|
90
90
|
if (a !== "\r" && a !== `
|
|
91
91
|
`) {
|
|
92
|
-
|
|
92
|
+
s += 1;
|
|
93
93
|
continue;
|
|
94
94
|
}
|
|
95
|
-
let c =
|
|
95
|
+
let c = s + 1;
|
|
96
96
|
if (a === "\r") {
|
|
97
97
|
if (c === this.buffer.length && !n) break;
|
|
98
98
|
this.buffer[c] === `
|
|
99
99
|
` && (c += 1);
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
s === r && (t.push(this.buffer.slice(o, c)), o = c), r = c, s = c;
|
|
102
102
|
}
|
|
103
|
-
return
|
|
103
|
+
return o > 0 && (this.buffer = this.buffer.slice(o)), t;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function ee() {
|
|
107
107
|
let e = "";
|
|
108
108
|
const n = (t) => {
|
|
109
|
-
const
|
|
110
|
-
let
|
|
109
|
+
const o = [];
|
|
110
|
+
let r = 0, s = 0, a = 0;
|
|
111
111
|
for (; a < e.length; ) {
|
|
112
112
|
const c = e[a];
|
|
113
113
|
if (c !== "\r" && c !== `
|
|
@@ -115,15 +115,15 @@ function X() {
|
|
|
115
115
|
a += 1;
|
|
116
116
|
continue;
|
|
117
117
|
}
|
|
118
|
-
let
|
|
118
|
+
let i = a + 1;
|
|
119
119
|
if (c === "\r") {
|
|
120
|
-
if (
|
|
121
|
-
e[
|
|
122
|
-
` && (
|
|
120
|
+
if (i === e.length && !t) break;
|
|
121
|
+
e[i] === `
|
|
122
|
+
` && (i += 1);
|
|
123
123
|
}
|
|
124
|
-
a ===
|
|
124
|
+
a === s && (o.push(e.slice(r, i)), r = i), s = i, a = i;
|
|
125
125
|
}
|
|
126
|
-
return
|
|
126
|
+
return r > 0 && (e = e.slice(r)), o;
|
|
127
127
|
};
|
|
128
128
|
return {
|
|
129
129
|
push(t) {
|
|
@@ -135,116 +135,116 @@ function X() {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function S(e) {
|
|
139
139
|
return e?.toLowerCase().includes("text/event-stream") ?? !1;
|
|
140
140
|
}
|
|
141
|
-
const
|
|
142
|
-
async function
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
const
|
|
141
|
+
const R = /* @__PURE__ */ new WeakMap();
|
|
142
|
+
async function te(e, n, t) {
|
|
143
|
+
N(n.data);
|
|
144
|
+
const o = R.get(e);
|
|
145
|
+
if (o) return o(n, t);
|
|
146
|
+
const r = await e(L(n, t.signal));
|
|
147
147
|
if (t.signal.aborted)
|
|
148
|
-
throw f
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
return t.onHeaders({ taskId: n.taskId, statusCode:
|
|
148
|
+
throw m(f.REQUEST_ABORTED, "request aborted");
|
|
149
|
+
U(r);
|
|
150
|
+
const s = A(r.header);
|
|
151
|
+
return t.onHeaders({ taskId: n.taskId, statusCode: r.statusCode, header: s }), n.enableChunked && S(s["content-type"]) && (typeof r.data == "string" || C(r.data)) ? (await P(r.data, n.taskId, t), { taskId: n.taskId, statusCode: r.statusCode, data: "", header: s }) : {
|
|
152
152
|
taskId: n.taskId,
|
|
153
|
-
statusCode:
|
|
154
|
-
data: await B(
|
|
155
|
-
header:
|
|
153
|
+
statusCode: r.statusCode,
|
|
154
|
+
data: await B(r.data, n),
|
|
155
|
+
header: s
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
|
-
function
|
|
159
|
-
const t = e.data,
|
|
160
|
-
return
|
|
161
|
-
url:
|
|
158
|
+
function L(e, n) {
|
|
159
|
+
const t = e.data, o = { ...e.header }, r = e.method.toUpperCase();
|
|
160
|
+
return r === "GET" || r === "HEAD" ? {
|
|
161
|
+
url: O(e.url, k(t)),
|
|
162
162
|
method: e.method,
|
|
163
|
-
header:
|
|
163
|
+
header: o,
|
|
164
164
|
responseType: e.responseType,
|
|
165
165
|
enableChunked: e.enableChunked,
|
|
166
166
|
signal: n
|
|
167
167
|
} : {
|
|
168
168
|
url: e.url,
|
|
169
169
|
method: e.method,
|
|
170
|
-
header:
|
|
171
|
-
data:
|
|
170
|
+
header: o,
|
|
171
|
+
data: D(t, o),
|
|
172
172
|
responseType: e.responseType,
|
|
173
173
|
enableChunked: e.enableChunked,
|
|
174
174
|
signal: n
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function O(e, n) {
|
|
178
178
|
if (!n) return e;
|
|
179
|
-
const t = e.indexOf("#"),
|
|
180
|
-
return `${
|
|
179
|
+
const t = e.indexOf("#"), o = t >= 0 ? e.slice(t) : "", r = t >= 0 ? e.slice(0, t) : e;
|
|
180
|
+
return `${r}${r.includes("?") ? "&" : "?"}${n}${o}`;
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function k(e) {
|
|
183
183
|
return e == null ? "" : typeof e == "string" ? e : typeof e != "object" || Array.isArray(e) ? String(e) : Object.entries(e).map(([n, t]) => `${encodeURIComponent(n)}=${encodeURIComponent(String(t))}`).join("&");
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function D(e, n) {
|
|
186
186
|
if (e == null || typeof e == "string") return e;
|
|
187
|
-
let t =
|
|
188
|
-
return t || (t = "application/json", n["content-type"] = t), t.toLowerCase().includes("application/json") ? JSON.stringify(e) : t.toLowerCase().includes("application/x-www-form-urlencoded") ?
|
|
187
|
+
let t = x(n, "content-type");
|
|
188
|
+
return t || (t = "application/json", n["content-type"] = t), t.toLowerCase().includes("application/json") ? JSON.stringify(e) : t.toLowerCase().includes("application/x-www-form-urlencoded") ? k(e) : String(e);
|
|
189
189
|
}
|
|
190
|
-
function
|
|
191
|
-
const t = Object.keys(e).find((
|
|
190
|
+
function x(e, n) {
|
|
191
|
+
const t = Object.keys(e).find((o) => o.toLowerCase() === n);
|
|
192
192
|
return t ? String(e[t]) : void 0;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function N(e) {
|
|
195
195
|
if (!(!(e instanceof ArrayBuffer) && !ArrayBuffer.isView(e)))
|
|
196
|
-
throw
|
|
197
|
-
|
|
196
|
+
throw m(
|
|
197
|
+
f.INVALID_PARAM,
|
|
198
198
|
"request data does not support ArrayBuffer"
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function U(e) {
|
|
202
202
|
if (!e || typeof e != "object" || typeof e.statusCode != "number")
|
|
203
|
-
throw
|
|
204
|
-
|
|
203
|
+
throw m(
|
|
204
|
+
f.REQUEST_FAILED,
|
|
205
205
|
"host request adapter returned an invalid response"
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function C(e) {
|
|
209
209
|
return !!(e && typeof e == "object" && "getReader" in e);
|
|
210
210
|
}
|
|
211
|
-
async function
|
|
212
|
-
const
|
|
213
|
-
for (const u of
|
|
211
|
+
async function P(e, n, t) {
|
|
212
|
+
const o = new I(), r = (i) => {
|
|
213
|
+
for (const u of o.push(i)) t.onChunk({ taskId: n, chunk: u });
|
|
214
214
|
};
|
|
215
215
|
if (typeof e == "string") {
|
|
216
|
-
|
|
217
|
-
for (const
|
|
216
|
+
r(e);
|
|
217
|
+
for (const i of o.finish()) t.onChunk({ taskId: n, chunk: i });
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
|
-
const
|
|
220
|
+
const s = e.getReader(), a = new TextDecoder(), c = () => void s.cancel().catch(() => {
|
|
221
221
|
});
|
|
222
222
|
t.signal.addEventListener("abort", c, { once: !0 });
|
|
223
223
|
try {
|
|
224
224
|
for (; ; ) {
|
|
225
225
|
if (t.signal.aborted) return;
|
|
226
|
-
const u = await
|
|
226
|
+
const u = await s.read();
|
|
227
227
|
if (u.done) break;
|
|
228
|
-
const
|
|
229
|
-
|
|
228
|
+
const l = typeof u.value == "string" ? u.value : a.decode(u.value, { stream: !0 });
|
|
229
|
+
l && r(l);
|
|
230
230
|
}
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
for (const u of
|
|
231
|
+
const i = a.decode();
|
|
232
|
+
i && r(i);
|
|
233
|
+
for (const u of o.finish()) t.onChunk({ taskId: n, chunk: u });
|
|
234
234
|
} finally {
|
|
235
|
-
t.signal.removeEventListener("abort", c),
|
|
235
|
+
t.signal.removeEventListener("abort", c), s.releaseLock();
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
function
|
|
238
|
+
function A(e) {
|
|
239
239
|
const n = {};
|
|
240
|
-
for (const [t,
|
|
241
|
-
t.toLowerCase() !== "set-cookie" && (n[t.toLowerCase()] = String(
|
|
240
|
+
for (const [t, o] of Object.entries(e ?? {}))
|
|
241
|
+
t.toLowerCase() !== "set-cookie" && (n[t.toLowerCase()] = String(o));
|
|
242
242
|
return n;
|
|
243
243
|
}
|
|
244
244
|
async function B(e, n) {
|
|
245
245
|
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e))
|
|
246
|
-
throw
|
|
247
|
-
|
|
246
|
+
throw m(
|
|
247
|
+
f.REQUEST_FAILED,
|
|
248
248
|
"request response does not support ArrayBuffer"
|
|
249
249
|
);
|
|
250
250
|
if (n.dataType === "json" && typeof e == "string")
|
|
@@ -255,7 +255,7 @@ async function B(e, n) {
|
|
|
255
255
|
}
|
|
256
256
|
return e;
|
|
257
257
|
}
|
|
258
|
-
const
|
|
258
|
+
const F = "miniapp_simulator_event", q = "skillbuilder-miniapp", j = {
|
|
259
259
|
cn: {
|
|
260
260
|
production: "https://apm-fe.xiaohongshu.com/api/data",
|
|
261
261
|
development: "https://apm-fe-test.xiaohongshu.com/api/data"
|
|
@@ -264,11 +264,19 @@ const P = "miniapp_simulator_event", A = "skillbuilder-miniapp", C = {
|
|
|
264
264
|
production: "https://apm-fe.rnote.com/api/data",
|
|
265
265
|
development: "https://apm-fe.rnote.com/api/data"
|
|
266
266
|
}
|
|
267
|
-
},
|
|
268
|
-
function
|
|
267
|
+
}, b = 10, H = 1e4;
|
|
268
|
+
function w() {
|
|
269
269
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`;
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function V(e) {
|
|
272
|
+
return Object.fromEntries(
|
|
273
|
+
Object.entries(e).map(([n, t]) => [
|
|
274
|
+
n,
|
|
275
|
+
typeof t == "boolean" ? Number(t) : t
|
|
276
|
+
])
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
function Q(e, n) {
|
|
272
280
|
const t = typeof window < "u";
|
|
273
281
|
return {
|
|
274
282
|
clientTime: Date.now(),
|
|
@@ -288,125 +296,163 @@ function q(e, n) {
|
|
|
288
296
|
context_matchedPath: t ? window.location.pathname : "",
|
|
289
297
|
context_route: t ? window.location.href : "",
|
|
290
298
|
context_userAgent: typeof navigator < "u" ? navigator.userAgent : "",
|
|
291
|
-
context_artifactName:
|
|
292
|
-
context_artifactVersion:
|
|
299
|
+
context_artifactName: q,
|
|
300
|
+
context_artifactVersion: T,
|
|
293
301
|
context_deviceLevel: "unknown",
|
|
294
302
|
context_feSdkVersion: "1.3.13",
|
|
295
303
|
context_userId: n.userId,
|
|
296
|
-
measurement_name:
|
|
304
|
+
measurement_name: F,
|
|
297
305
|
measurement_data: {
|
|
298
306
|
event_name: e.name,
|
|
299
307
|
timestamp: e.timestamp,
|
|
300
|
-
...e.payload
|
|
308
|
+
...V(e.payload)
|
|
301
309
|
}
|
|
302
310
|
};
|
|
303
311
|
}
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
const y = [250, 1e3], M = 5e3;
|
|
313
|
+
let E = Promise.resolve();
|
|
314
|
+
function W(e, n) {
|
|
315
|
+
const t = async () => {
|
|
316
|
+
let o;
|
|
306
317
|
try {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
},
|
|
314
|
-
body: JSON.stringify(n)
|
|
315
|
-
};
|
|
316
|
-
typeof navigator < "u" && "sendBeacon" in navigator && (t.keepalive = !0), Promise.resolve(fetch(e, t)).catch(() => {
|
|
317
|
-
});
|
|
318
|
+
o = await z(e.endpoint, n);
|
|
319
|
+
} catch {
|
|
320
|
+
o = { ok: !1, attempts: 0, eventCount: n.length };
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
e.onDelivery?.(o);
|
|
318
324
|
} catch {
|
|
319
325
|
}
|
|
326
|
+
};
|
|
327
|
+
E = E.then(t, t);
|
|
320
328
|
}
|
|
321
|
-
function
|
|
329
|
+
async function z(e, n) {
|
|
330
|
+
const t = n.length;
|
|
331
|
+
if (typeof fetch != "function" || t === 0)
|
|
332
|
+
return { ok: !1, attempts: 0, eventCount: t };
|
|
333
|
+
const o = {
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers: {
|
|
336
|
+
"content-type": "application/json",
|
|
337
|
+
"Biz-Type": "apm_fe",
|
|
338
|
+
Batch: "true"
|
|
339
|
+
},
|
|
340
|
+
body: JSON.stringify(n),
|
|
341
|
+
keepalive: !0
|
|
342
|
+
};
|
|
343
|
+
let r;
|
|
344
|
+
for (let s = 0; s <= y.length; s += 1) {
|
|
345
|
+
const a = new AbortController(), c = setTimeout(() => a.abort(), M);
|
|
346
|
+
try {
|
|
347
|
+
const u = await fetch(e, { ...o, signal: a.signal });
|
|
348
|
+
if (r = u.status, u.ok)
|
|
349
|
+
return { ok: !0, status: u.status, attempts: s + 1, eventCount: t };
|
|
350
|
+
if (u.status >= 400 && u.status < 500)
|
|
351
|
+
return { ok: !1, status: u.status, attempts: s + 1, eventCount: t };
|
|
352
|
+
} catch {
|
|
353
|
+
} finally {
|
|
354
|
+
clearTimeout(c);
|
|
355
|
+
}
|
|
356
|
+
const i = y[s];
|
|
357
|
+
if (i === void 0)
|
|
358
|
+
return { ok: !1, status: r, attempts: s + 1, eventCount: t };
|
|
359
|
+
await new Promise((u) => setTimeout(u, i));
|
|
360
|
+
}
|
|
361
|
+
return { ok: !1, status: r, attempts: y.length + 1, eventCount: t };
|
|
362
|
+
}
|
|
363
|
+
function $(e) {
|
|
322
364
|
if (typeof console > "u") return;
|
|
323
365
|
const n = e.measurement_name ?? "apm";
|
|
324
366
|
console.groupCollapsed(`[apm] ${n}`), console.log(e), console.groupEnd();
|
|
325
367
|
}
|
|
326
|
-
function
|
|
327
|
-
const n = e.debug === !0, t =
|
|
328
|
-
let
|
|
368
|
+
function G(e) {
|
|
369
|
+
const n = e.debug === !0, t = w(), o = w();
|
|
370
|
+
let r = 0, s = [], a = null, c = 0, i = !1;
|
|
329
371
|
const u = () => {
|
|
330
|
-
if (
|
|
331
|
-
const h =
|
|
332
|
-
|
|
333
|
-
|
|
372
|
+
if (i = !1, a !== null && (clearTimeout(a), a = null), s.length === 0) return;
|
|
373
|
+
const h = s;
|
|
374
|
+
s = [];
|
|
375
|
+
for (let d = 0; d < h.length; d += b) {
|
|
376
|
+
const _ = h.slice(d, d + b);
|
|
377
|
+
W(e, _);
|
|
378
|
+
}
|
|
379
|
+
}, l = () => {
|
|
334
380
|
if (a !== null && (clearTimeout(a), a = null), c > 0) {
|
|
335
|
-
|
|
381
|
+
i = !0;
|
|
336
382
|
return;
|
|
337
383
|
}
|
|
338
384
|
u();
|
|
339
|
-
},
|
|
340
|
-
a === null && (a = setTimeout(
|
|
385
|
+
}, p = () => {
|
|
386
|
+
a === null && (a = setTimeout(l, H));
|
|
341
387
|
};
|
|
342
388
|
return {
|
|
343
389
|
sendCustomPoint(h) {
|
|
344
|
-
const
|
|
345
|
-
c += 1, Promise.resolve().then(() => e.resolveUserId()).catch(() => "").then((
|
|
390
|
+
const d = r++;
|
|
391
|
+
c += 1, Promise.resolve().then(() => e.resolveUserId()).catch(() => "").then((_) => {
|
|
346
392
|
try {
|
|
347
|
-
const
|
|
393
|
+
const g = Q(h, {
|
|
348
394
|
sessionId: t,
|
|
349
|
-
pageSessionId:
|
|
350
|
-
seqId:
|
|
351
|
-
userId:
|
|
395
|
+
pageSessionId: o,
|
|
396
|
+
seqId: d,
|
|
397
|
+
userId: _,
|
|
352
398
|
region: e.region
|
|
353
399
|
});
|
|
354
400
|
if (n) {
|
|
355
|
-
|
|
401
|
+
$(g);
|
|
356
402
|
return;
|
|
357
403
|
}
|
|
358
|
-
|
|
404
|
+
s.push(g), s.length >= b ? setTimeout(() => l()) : p();
|
|
359
405
|
} catch {
|
|
360
406
|
}
|
|
361
407
|
}).finally(() => {
|
|
362
|
-
c -= 1, c === 0 &&
|
|
408
|
+
c -= 1, c === 0 && i && u();
|
|
363
409
|
});
|
|
364
410
|
},
|
|
365
|
-
flush:
|
|
411
|
+
flush: l
|
|
366
412
|
};
|
|
367
413
|
}
|
|
368
|
-
function
|
|
414
|
+
function X(e) {
|
|
369
415
|
const n = e.region ?? "cn";
|
|
370
416
|
if (e.endpoint) return e.endpoint;
|
|
371
|
-
const t =
|
|
372
|
-
return
|
|
417
|
+
const t = Y();
|
|
418
|
+
return j[n][t];
|
|
373
419
|
}
|
|
374
|
-
function
|
|
420
|
+
function Y() {
|
|
375
421
|
if (typeof window > "u") return "production";
|
|
376
422
|
const e = window.location.hostname.toLowerCase();
|
|
377
423
|
return e === "localhost" || e === "127.0.0.1" || e === "0.0.0.0" || e.includes(".sit.") || // hostname.includes(".beta.") ||
|
|
378
424
|
e.startsWith("local.") ? "development" : "production";
|
|
379
425
|
}
|
|
380
|
-
function
|
|
426
|
+
function K(e, n) {
|
|
381
427
|
if (e === !1) return null;
|
|
382
428
|
try {
|
|
383
|
-
const t = e.region ?? "cn",
|
|
384
|
-
endpoint:
|
|
429
|
+
const t = e.region ?? "cn", o = G({
|
|
430
|
+
endpoint: X(e),
|
|
385
431
|
region: t,
|
|
386
432
|
resolveUserId: n ?? (() => Promise.resolve("")),
|
|
387
433
|
debug: e.debug
|
|
388
434
|
});
|
|
389
|
-
return { send: (
|
|
435
|
+
return { send: (r) => o.sendCustomPoint(r), flush: () => o.flush() };
|
|
390
436
|
} catch {
|
|
391
437
|
return null;
|
|
392
438
|
}
|
|
393
439
|
}
|
|
394
|
-
class
|
|
395
|
-
constructor(n, t,
|
|
396
|
-
this.resolveContext =
|
|
440
|
+
class ne {
|
|
441
|
+
constructor(n, t, o, r) {
|
|
442
|
+
this.resolveContext = r, this.unsubscribers = [], this.common = {
|
|
397
443
|
business_line: "",
|
|
398
444
|
sdk_version: "",
|
|
399
445
|
content_mode: "",
|
|
400
446
|
renderer: ""
|
|
401
447
|
};
|
|
402
|
-
const
|
|
403
|
-
if (!
|
|
448
|
+
const s = K(n, o);
|
|
449
|
+
if (!s) {
|
|
404
450
|
this.send = () => {
|
|
405
451
|
}, this.flush = () => {
|
|
406
452
|
};
|
|
407
453
|
return;
|
|
408
454
|
}
|
|
409
|
-
this.send =
|
|
455
|
+
this.send = s.send, this.flush = s.flush, this.common = {
|
|
410
456
|
...this.common,
|
|
411
457
|
...n === !1 ? {} : n.context,
|
|
412
458
|
business_line: n === !1 ? "" : n.business_line ?? "unknown"
|
|
@@ -535,14 +581,14 @@ class K {
|
|
|
535
581
|
/** 发送打点:自动合入公共字段 */
|
|
536
582
|
track(n, t) {
|
|
537
583
|
try {
|
|
538
|
-
let
|
|
584
|
+
let o = {};
|
|
539
585
|
try {
|
|
540
|
-
|
|
586
|
+
o = this.resolveContext?.() ?? {};
|
|
541
587
|
} catch {
|
|
542
588
|
}
|
|
543
589
|
this.send({
|
|
544
590
|
name: n,
|
|
545
|
-
payload: { ...this.common, ...t, ...
|
|
591
|
+
payload: { ...this.common, ...t, ...o },
|
|
546
592
|
timestamp: Date.now()
|
|
547
593
|
});
|
|
548
594
|
} catch {
|
|
@@ -555,20 +601,20 @@ class K {
|
|
|
555
601
|
this.unsubscribers.length = 0;
|
|
556
602
|
}
|
|
557
603
|
}
|
|
558
|
-
function
|
|
604
|
+
function se(e) {
|
|
559
605
|
return !(e === void 0 || e === !1);
|
|
560
606
|
}
|
|
561
607
|
export {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
608
|
+
f as M,
|
|
609
|
+
J as a,
|
|
610
|
+
m as b,
|
|
611
|
+
G as c,
|
|
612
|
+
ee as d,
|
|
613
|
+
te as e,
|
|
614
|
+
se as f,
|
|
615
|
+
ne as g,
|
|
616
|
+
S as i,
|
|
617
|
+
Z as o,
|
|
618
|
+
X as r,
|
|
619
|
+
T as v
|
|
574
620
|
};
|