@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.
Files changed (46) hide show
  1. package/docs/assets/audit-auto-stop-config-2026-10-21.jpg +0 -0
  2. package/docs/assets/audit-balanced-panel-2026-10-16.jpg +0 -0
  3. package/docs/assets/audit-lcp-input-2026-10-20.jpg +0 -0
  4. package/docs/assets/audit-paint-game3d-2026-10-16.jpg +0 -0
  5. package/docs/assets/audit-paint-webgl-2026-10-16.jpg +0 -0
  6. package/docs/assets/audit-paint-webgl-apm-excerpt-2026-10-16.json +397 -0
  7. package/docs/assets/audit-poetry-2026-10-16.jpg +0 -0
  8. package/docs/assets/audit-remaining-results-2026-10-16.json +2749 -0
  9. package/docs/assets/miniapp-audit-risk-review-2026-10-13.png +0 -0
  10. package/docs/assets/miniapp-audit-runtime-hung-2026-10-13.png +0 -0
  11. package/docs/audit-data-collection.codex.md +105 -0
  12. package/docs/audit-local-validation.codex.md +165 -0
  13. package/docs/audit-score-design.codex.md +222 -0
  14. package/docs/audit-score-design.md +832 -0
  15. package/docs/audit-score-tech-plan.md +450 -0
  16. package/docs/audit-tech-design.codex.md +485 -0
  17. package/docs/electron-review.md +223 -12
  18. package/docs/quality-evaluation-redoc.xml +163 -0
  19. package/docs/tracker.md +3 -2
  20. package/lib/client-BjYHK9LR.mjs +1220 -0
  21. package/lib/{index-D5AYVv8s.mjs → index-CqClPZVv.mjs} +230 -184
  22. package/lib/index.js +2204 -1999
  23. package/lib/remote-client.js +2 -2
  24. package/lib/types/host/shadow-host.d.ts +10 -0
  25. package/lib/types/injection/registry.d.ts +5 -0
  26. package/lib/types/remote/audit-controller.d.ts +61 -0
  27. package/lib/types/remote/audit-leave-monitor.d.ts +12 -0
  28. package/lib/types/remote/audit-package-sources.d.ts +9 -0
  29. package/lib/types/remote/audit-telemetry.d.ts +36 -0
  30. package/lib/types/remote/audit-watchdog.d.ts +14 -0
  31. package/lib/types/remote/client.d.ts +25 -1
  32. package/lib/types/remote/load-timing.d.ts +5 -0
  33. package/lib/types/remote/protocol.d.ts +162 -1
  34. package/lib/types/remote/runtime.d.ts +2 -0
  35. package/lib/types/remote-client.d.ts +2 -2
  36. package/lib/types/runtime/jsapi-modules/interaction.d.ts +1 -1
  37. package/lib/types/runtime/jsapi-modules/local-media.d.ts +4 -0
  38. package/lib/types/runtime/jsapi-modules/media.d.ts +1 -1
  39. package/lib/types/runtime/jsapi-modules/note-publish-media.d.ts +9 -0
  40. package/lib/types/sw/service-worker-host.d.ts +15 -0
  41. package/lib/types/tracker/constants.d.ts +1 -1
  42. package/lib/types/tracker/default-tracker.d.ts +9 -1
  43. package/lib/types/types/options.d.ts +24 -0
  44. package/lib/workbench.js +1 -1
  45. package/package.json +1 -1
  46. package/lib/client-_vNHVHSm.mjs +0 -775
@@ -1,76 +1,76 @@
1
- const E = "0.2.2", _ = /* @__PURE__ */ new Set();
2
- function M(e, n) {
1
+ const T = "0.2.7", v = /* @__PURE__ */ new Set();
2
+ function Z(e, n) {
3
3
  const t = () => {
4
- let s = !document.hidden && e.isConnected;
5
- for (let r = e; s && r; ) {
6
- const a = getComputedStyle(r);
7
- s = a.display !== "none" && a.visibility !== "hidden" && a.visibility !== "collapse";
8
- const c = r.getRootNode();
9
- r = r.parentElement ?? (c instanceof ShadowRoot ? c.host : null);
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(s);
12
- }, i = new MutationObserver(t);
13
- for (let s = e; s; ) {
14
- i.observe(s, { attributes: !0, attributeFilter: ["style", "class", "hidden"] });
15
- const r = s.getRootNode();
16
- s = s.parentElement ?? (r instanceof ShadowRoot ? r.host : null);
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
- i.disconnect(), document.removeEventListener("visibilitychange", t), window.removeEventListener("resize", t), window.removeEventListener("pageshow", t);
19
+ o.disconnect(), document.removeEventListener("visibilitychange", t), window.removeEventListener("resize", t), window.removeEventListener("pageshow", t);
20
20
  };
21
21
  }
22
- function G(e, n) {
23
- let t = "", i = 0;
24
- const s = () => {
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 o = e; o; ) {
27
- const u = getComputedStyle(o);
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 d = o.getRootNode();
31
- o = o.parentElement ?? (d instanceof ShadowRoot ? d.host : null);
30
+ const l = i.getRootNode();
31
+ i = i.parentElement ?? (l instanceof ShadowRoot ? l.host : null);
32
32
  }
33
33
  return !0;
34
- }, r = () => {
34
+ }, s = () => {
35
35
  if (t)
36
36
  try {
37
- const o = new URL(n(), location.href).origin;
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: ++i,
43
- state: s() ? "visible" : "hidden"
42
+ sequence: ++o,
43
+ state: r() ? "visible" : "hidden"
44
44
  },
45
- o
45
+ i
46
46
  );
47
47
  } catch {
48
48
  }
49
- }, a = (o) => {
50
- if (!(!o.isTrusted || o.source !== e.contentWindow || o.data?.type !== "mini-app:worker-ready" || typeof o.data.sessionId != "string")) {
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 (o.origin !== new URL(n(), location.href).origin || e.contentWindow?.__MINITOOL_WORKER_CONTEXT__?.sessionId !== o.data.sessionId)
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 = o.data.sessionId, r();
57
+ t = i.data.sessionId, s();
58
58
  }
59
- }, c = new MutationObserver(r);
60
- for (let o = e; o; ) {
61
- c.observe(o, { attributes: !0, attributeFilter: ["style", "class", "hidden"] });
62
- const u = o.getRootNode();
63
- o = o.parentElement ?? (u instanceof ShadowRoot ? u.host : null);
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", r), window.addEventListener("pageshow", r), document.addEventListener("visibilitychange", r), _.add(r), () => {
66
- _.delete(r), c.disconnect(), window.removeEventListener("message", a), window.removeEventListener("resize", r), window.removeEventListener("pageshow", r), document.removeEventListener("visibilitychange", r);
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 l = /* @__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))(l || {});
70
- function f(e, n) {
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 k {
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 i = 0, s = 0, r = 0;
88
- for (; r < this.buffer.length; ) {
89
- const a = this.buffer[r];
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
- r += 1;
92
+ s += 1;
93
93
  continue;
94
94
  }
95
- let c = r + 1;
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
- r === s && (t.push(this.buffer.slice(i, c)), i = c), s = c, r = c;
101
+ s === r && (t.push(this.buffer.slice(o, c)), o = c), r = c, s = c;
102
102
  }
103
- return i > 0 && (this.buffer = this.buffer.slice(i)), t;
103
+ return o > 0 && (this.buffer = this.buffer.slice(o)), t;
104
104
  }
105
105
  }
106
- function X() {
106
+ function ee() {
107
107
  let e = "";
108
108
  const n = (t) => {
109
- const i = [];
110
- let s = 0, r = 0, a = 0;
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 o = a + 1;
118
+ let i = a + 1;
119
119
  if (c === "\r") {
120
- if (o === e.length && !t) break;
121
- e[o] === `
122
- ` && (o += 1);
120
+ if (i === e.length && !t) break;
121
+ e[i] === `
122
+ ` && (i += 1);
123
123
  }
124
- a === r && (i.push(e.slice(s, o)), s = o), r = o, a = o;
124
+ a === s && (o.push(e.slice(r, i)), r = i), s = i, a = i;
125
125
  }
126
- return s > 0 && (e = e.slice(s)), i;
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 p(e) {
138
+ function S(e) {
139
139
  return e?.toLowerCase().includes("text/event-stream") ?? !1;
140
140
  }
141
- const T = /* @__PURE__ */ new WeakMap();
142
- async function Y(e, n, t) {
143
- O(n.data);
144
- const i = T.get(e);
145
- if (i) return i(n, t);
146
- const s = await e(I(n, t.signal));
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(l.REQUEST_ABORTED, "request aborted");
149
- x(s);
150
- const r = U(s.header);
151
- return t.onHeaders({ taskId: n.taskId, statusCode: s.statusCode, header: r }), n.enableChunked && p(r["content-type"]) && (typeof s.data == "string" || D(s.data)) ? (await N(s.data, n.taskId, t), { taskId: n.taskId, statusCode: s.statusCode, data: "", header: r }) : {
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: s.statusCode,
154
- data: await B(s.data, n),
155
- header: r
153
+ statusCode: r.statusCode,
154
+ data: await B(r.data, n),
155
+ header: s
156
156
  };
157
157
  }
158
- function I(e, n) {
159
- const t = e.data, i = { ...e.header }, s = e.method.toUpperCase();
160
- return s === "GET" || s === "HEAD" ? {
161
- url: R(e.url, g(t)),
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: i,
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: i,
171
- data: L(t, i),
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 R(e, n) {
177
+ function O(e, n) {
178
178
  if (!n) return e;
179
- const t = e.indexOf("#"), i = t >= 0 ? e.slice(t) : "", s = t >= 0 ? e.slice(0, t) : e;
180
- return `${s}${s.includes("?") ? "&" : "?"}${n}${i}`;
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 g(e) {
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 L(e, n) {
185
+ function D(e, n) {
186
186
  if (e == null || typeof e == "string") return e;
187
- let t = S(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") ? g(e) : String(e);
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 S(e, n) {
191
- const t = Object.keys(e).find((i) => i.toLowerCase() === n);
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 O(e) {
194
+ function N(e) {
195
195
  if (!(!(e instanceof ArrayBuffer) && !ArrayBuffer.isView(e)))
196
- throw f(
197
- l.INVALID_PARAM,
196
+ throw m(
197
+ f.INVALID_PARAM,
198
198
  "request data does not support ArrayBuffer"
199
199
  );
200
200
  }
201
- function x(e) {
201
+ function U(e) {
202
202
  if (!e || typeof e != "object" || typeof e.statusCode != "number")
203
- throw f(
204
- l.REQUEST_FAILED,
203
+ throw m(
204
+ f.REQUEST_FAILED,
205
205
  "host request adapter returned an invalid response"
206
206
  );
207
207
  }
208
- function D(e) {
208
+ function C(e) {
209
209
  return !!(e && typeof e == "object" && "getReader" in e);
210
210
  }
211
- async function N(e, n, t) {
212
- const i = new k(), s = (o) => {
213
- for (const u of i.push(o)) t.onChunk({ taskId: n, chunk: u });
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
- s(e);
217
- for (const o of i.finish()) t.onChunk({ taskId: n, chunk: o });
216
+ r(e);
217
+ for (const i of o.finish()) t.onChunk({ taskId: n, chunk: i });
218
218
  return;
219
219
  }
220
- const r = e.getReader(), a = new TextDecoder(), c = () => void r.cancel().catch(() => {
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 r.read();
226
+ const u = await s.read();
227
227
  if (u.done) break;
228
- const d = typeof u.value == "string" ? u.value : a.decode(u.value, { stream: !0 });
229
- d && s(d);
228
+ const l = typeof u.value == "string" ? u.value : a.decode(u.value, { stream: !0 });
229
+ l && r(l);
230
230
  }
231
- const o = a.decode();
232
- o && s(o);
233
- for (const u of i.finish()) t.onChunk({ taskId: n, chunk: u });
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), r.releaseLock();
235
+ t.signal.removeEventListener("abort", c), s.releaseLock();
236
236
  }
237
237
  }
238
- function U(e) {
238
+ function A(e) {
239
239
  const n = {};
240
- for (const [t, i] of Object.entries(e ?? {}))
241
- t.toLowerCase() !== "set-cookie" && (n[t.toLowerCase()] = String(i));
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 f(
247
- l.REQUEST_FAILED,
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 P = "miniapp_simulator_event", A = "skillbuilder-miniapp", C = {
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
- }, F = 10, H = 1e4;
268
- function b() {
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 q(e, n) {
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: A,
292
- context_artifactVersion: E,
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: P,
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
- function V(e, n) {
305
- if (!(typeof fetch != "function" || n.length === 0))
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
- const t = {
308
- method: "POST",
309
- headers: {
310
- "content-type": "application/json",
311
- "Biz-Type": "apm_fe",
312
- Batch: "true"
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 j(e) {
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 Q(e) {
327
- const n = e.debug === !0, t = b(), i = b();
328
- let s = 0, r = [], a = null, c = 0, o = !1;
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 (o = !1, a !== null && (clearTimeout(a), a = null), r.length === 0) return;
331
- const h = r;
332
- r = [], V(e.endpoint, h);
333
- }, d = () => {
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
- o = !0;
381
+ i = !0;
336
382
  return;
337
383
  }
338
384
  u();
339
- }, y = () => {
340
- a === null && (a = setTimeout(d, H));
385
+ }, p = () => {
386
+ a === null && (a = setTimeout(l, H));
341
387
  };
342
388
  return {
343
389
  sendCustomPoint(h) {
344
- const v = s++;
345
- c += 1, Promise.resolve().then(() => e.resolveUserId()).catch(() => "").then((w) => {
390
+ const d = r++;
391
+ c += 1, Promise.resolve().then(() => e.resolveUserId()).catch(() => "").then((_) => {
346
392
  try {
347
- const m = q(h, {
393
+ const g = Q(h, {
348
394
  sessionId: t,
349
- pageSessionId: i,
350
- seqId: v,
351
- userId: w,
395
+ pageSessionId: o,
396
+ seqId: d,
397
+ userId: _,
352
398
  region: e.region
353
399
  });
354
400
  if (n) {
355
- j(m);
401
+ $(g);
356
402
  return;
357
403
  }
358
- r.push(m), r.length >= F ? setTimeout(() => d()) : y();
404
+ s.push(g), s.length >= b ? setTimeout(() => l()) : p();
359
405
  } catch {
360
406
  }
361
407
  }).finally(() => {
362
- c -= 1, c === 0 && o && u();
408
+ c -= 1, c === 0 && i && u();
363
409
  });
364
410
  },
365
- flush: d
411
+ flush: l
366
412
  };
367
413
  }
368
- function W(e) {
414
+ function X(e) {
369
415
  const n = e.region ?? "cn";
370
416
  if (e.endpoint) return e.endpoint;
371
- const t = z();
372
- return C[n][t];
417
+ const t = Y();
418
+ return j[n][t];
373
419
  }
374
- function z() {
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 $(e, n) {
426
+ function K(e, n) {
381
427
  if (e === !1) return null;
382
428
  try {
383
- const t = e.region ?? "cn", i = Q({
384
- endpoint: W(e),
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: (s) => i.sendCustomPoint(s), flush: () => i.flush() };
435
+ return { send: (r) => o.sendCustomPoint(r), flush: () => o.flush() };
390
436
  } catch {
391
437
  return null;
392
438
  }
393
439
  }
394
- class K {
395
- constructor(n, t, i, s) {
396
- this.resolveContext = s, this.unsubscribers = [], this.common = {
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 r = $(n, i);
403
- if (!r) {
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 = r.send, this.flush = r.flush, this.common = {
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 i = {};
584
+ let o = {};
539
585
  try {
540
- i = this.resolveContext?.() ?? {};
586
+ o = this.resolveContext?.() ?? {};
541
587
  } catch {
542
588
  }
543
589
  this.send({
544
590
  name: n,
545
- payload: { ...this.common, ...t, ...i },
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 Z(e) {
604
+ function se(e) {
559
605
  return !(e === void 0 || e === !1);
560
606
  }
561
607
  export {
562
- l as M,
563
- G as a,
564
- f as b,
565
- Q as c,
566
- X as d,
567
- Y as e,
568
- Z as f,
569
- K as g,
570
- p as i,
571
- M as o,
572
- W as r,
573
- E as v
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
  };