@yysports/tools 2.0.1 → 2.2.0

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 (88) hide show
  1. package/dist/Track/Beacon.d.ts +6 -0
  2. package/dist/Track/Beacon.js +58 -0
  3. package/dist/Track/Config.d.ts +11 -0
  4. package/dist/Track/Config.js +34 -0
  5. package/dist/Track/Listener.d.ts +5 -0
  6. package/dist/Track/Listener.js +46 -0
  7. package/dist/Track/Log.d.ts +8 -0
  8. package/dist/Track/Log.js +100 -0
  9. package/dist/Track/Replay.d.ts +6 -0
  10. package/dist/Track/Replay.js +77 -0
  11. package/dist/Track/System.d.ts +5 -0
  12. package/dist/Track/System.js +24 -0
  13. package/dist/Track/User.d.ts +6 -0
  14. package/dist/Track/User.js +29 -0
  15. package/dist/Track/index.d.ts +15 -20
  16. package/dist/Track/index.js +40 -164
  17. package/dist/Utils/auth.d.ts +9 -2
  18. package/dist/Utils/auth.js +80 -20
  19. package/dist/Utils/route.d.ts +11 -3
  20. package/dist/Utils/route.js +49 -56
  21. package/dist/Utils/url.js +3 -13
  22. package/dist/interfaces/track.interface.d.ts +1 -80
  23. package/dist/interfaces/track.interface.js +1 -5
  24. package/lib/Track/Beacon.d.ts +6 -0
  25. package/lib/Track/Beacon.js +73 -0
  26. package/lib/Track/Config.d.ts +11 -0
  27. package/lib/Track/{core/queue.js → Config.js} +23 -27
  28. package/lib/Track/Listener.d.ts +5 -0
  29. package/lib/Track/Listener.js +62 -0
  30. package/lib/Track/Log.d.ts +8 -0
  31. package/lib/Track/Log.js +95 -0
  32. package/lib/Track/Replay.d.ts +6 -0
  33. package/lib/Track/Replay.js +79 -0
  34. package/lib/Track/System.d.ts +5 -0
  35. package/lib/Track/{core/router.js → System.js} +18 -20
  36. package/lib/Track/User.d.ts +6 -0
  37. package/lib/Track/User.js +40 -0
  38. package/lib/Track/index.d.ts +15 -20
  39. package/lib/Track/index.js +39 -91
  40. package/lib/Utils/auth.d.ts +9 -2
  41. package/lib/Utils/auth.js +52 -17
  42. package/lib/Utils/route.d.ts +11 -3
  43. package/lib/Utils/route.js +34 -49
  44. package/lib/Utils/url.js +3 -3
  45. package/lib/interfaces/track.interface.d.ts +1 -80
  46. package/package.json +13 -13
  47. package/dist/Track/core/auth.d.ts +0 -16
  48. package/dist/Track/core/auth.js +0 -83
  49. package/dist/Track/core/constants.d.ts +0 -14
  50. package/dist/Track/core/constants.js +0 -25
  51. package/dist/Track/core/envelope.d.ts +0 -9
  52. package/dist/Track/core/envelope.js +0 -54
  53. package/dist/Track/core/instance.d.ts +0 -108
  54. package/dist/Track/core/instance.js +0 -365
  55. package/dist/Track/core/lifecycle.d.ts +0 -18
  56. package/dist/Track/core/lifecycle.js +0 -59
  57. package/dist/Track/core/profile.d.ts +0 -5
  58. package/dist/Track/core/profile.js +0 -30
  59. package/dist/Track/core/queue.d.ts +0 -13
  60. package/dist/Track/core/queue.js +0 -36
  61. package/dist/Track/core/replay.d.ts +0 -17
  62. package/dist/Track/core/replay.js +0 -117
  63. package/dist/Track/core/router.d.ts +0 -6
  64. package/dist/Track/core/router.js +0 -15
  65. package/dist/Track/core/system.d.ts +0 -14
  66. package/dist/Track/core/system.js +0 -36
  67. package/dist/Track/core/transport.d.ts +0 -18
  68. package/dist/Track/core/transport.js +0 -151
  69. package/lib/Track/core/auth.d.ts +0 -16
  70. package/lib/Track/core/auth.js +0 -67
  71. package/lib/Track/core/constants.d.ts +0 -14
  72. package/lib/Track/core/constants.js +0 -56
  73. package/lib/Track/core/envelope.d.ts +0 -9
  74. package/lib/Track/core/envelope.js +0 -61
  75. package/lib/Track/core/instance.d.ts +0 -108
  76. package/lib/Track/core/instance.js +0 -257
  77. package/lib/Track/core/lifecycle.d.ts +0 -18
  78. package/lib/Track/core/lifecycle.js +0 -74
  79. package/lib/Track/core/profile.d.ts +0 -5
  80. package/lib/Track/core/profile.js +0 -47
  81. package/lib/Track/core/queue.d.ts +0 -13
  82. package/lib/Track/core/replay.d.ts +0 -17
  83. package/lib/Track/core/replay.js +0 -131
  84. package/lib/Track/core/router.d.ts +0 -6
  85. package/lib/Track/core/system.d.ts +0 -14
  86. package/lib/Track/core/system.js +0 -53
  87. package/lib/Track/core/transport.d.ts +0 -18
  88. package/lib/Track/core/transport.js +0 -115
@@ -1,14 +0,0 @@
1
- /**
2
- * 系统/运行环境信息采集:IMEI 生成 + 视口 + 当前 URL 等。
3
- */
4
- import { SystemProfile } from '../../interfaces/track.interface';
5
- /**
6
- * 确保存在一个持久化 IMEI(匿名设备标识)
7
- * - 优先 localStorage
8
- * - 不可用时降级随机字符串
9
- */
10
- export declare function ensureIMEI(): string;
11
- /**
12
- * 收集系统(会话)级别指标:窗口尺寸 / URL / 时间戳 / IMEI
13
- */
14
- export declare function getSystemProfile(): SystemProfile;
@@ -1,53 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/Track/core/system.ts
20
- var system_exports = {};
21
- __export(system_exports, {
22
- ensureIMEI: () => ensureIMEI,
23
- getSystemProfile: () => getSystemProfile
24
- });
25
- module.exports = __toCommonJS(system_exports);
26
- var import_Utils = require("../../Utils");
27
- var IMEI_KEY = "__IMEI__";
28
- function ensureIMEI() {
29
- try {
30
- const val = localStorage.getItem(IMEI_KEY);
31
- if (val)
32
- return val;
33
- const imei = (0, import_Utils.generateRandomString)(16);
34
- localStorage.setItem(IMEI_KEY, imei);
35
- return imei;
36
- } catch {
37
- return (0, import_Utils.generateRandomString)(16);
38
- }
39
- }
40
- function getSystemProfile() {
41
- return {
42
- innerHeight: typeof window !== "undefined" ? window.innerHeight : 0,
43
- innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
44
- href: typeof location !== "undefined" ? location.href : "",
45
- systemTime: /* @__PURE__ */ new Date(),
46
- IMEI: ensureIMEI()
47
- };
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- ensureIMEI,
52
- getSystemProfile
53
- });
@@ -1,18 +0,0 @@
1
- import { TrackConfig } from '../../interfaces/track.interface';
2
- /**
3
- * sendBeacon 包装:
4
- * - 统一 JSON 序列化
5
- * - debug 输出
6
- * - 失败仅打印(不抛错,避免影响业务)
7
- */
8
- export declare function beaconSend(url: string, payload: object | any[]): void;
9
- /**
10
- * 上报当前应用版本:避免重复上报,通过 localStorage 绑定 appId 做缓存
11
- */
12
- export declare function reportAppVersion(config: TrackConfig): void;
13
- /** 批量上报日志事件数组 */
14
- export declare function reportBatch(config: TrackConfig, batch: any[]): void;
15
- /** 上报单条 API 日志(独立通道) */
16
- export declare function reportApiLog(config: TrackConfig, apiLog: any, envelope: any): void;
17
- /** 上报单条错误日志到专用端点 */
18
- export declare function reportError(config: TrackConfig, envelope: any, replayPayload?: any): Promise<void>;
@@ -1,115 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/Track/core/transport.ts
20
- var transport_exports = {};
21
- __export(transport_exports, {
22
- beaconSend: () => beaconSend,
23
- reportApiLog: () => reportApiLog,
24
- reportAppVersion: () => reportAppVersion,
25
- reportBatch: () => reportBatch,
26
- reportError: () => reportError
27
- });
28
- module.exports = __toCommonJS(transport_exports);
29
- var import_package = require("../../../package.json");
30
- var import_constants = require("./constants");
31
- async function fetchWrapper(url, options) {
32
- return new Promise((resolve, reject) => {
33
- fetch(url, options).then((response) => {
34
- if (!response.ok) {
35
- throw new Error(
36
- `Network response was not ok: ${response.statusText}`
37
- );
38
- }
39
- return response.json();
40
- }).then((data) => resolve(data)).catch((error) => reject(error));
41
- });
42
- }
43
- function beaconSend(url, payload) {
44
- try {
45
- if (!Array.isArray(payload) && (typeof payload !== "object" || payload === null)) {
46
- throw new Error("Payload must be an object or array");
47
- }
48
- const body = new Blob([JSON.stringify(payload)], {
49
- type: "application/json"
50
- });
51
- navigator.sendBeacon(url, body);
52
- } catch (err) {
53
- console.warn("[track:debug] beacon failed", err, url, payload);
54
- }
55
- }
56
- function reportAppVersion(config) {
57
- const { appId, domain } = config;
58
- const storageKey = `__Track__${appId}`;
59
- try {
60
- const cached = localStorage.getItem(storageKey);
61
- if (cached) {
62
- try {
63
- const { v } = JSON.parse(cached);
64
- if (v === import_package.version) {
65
- console.debug("[track:debug] skip version report (same)", import_package.version);
66
- return;
67
- }
68
- } catch {
69
- }
70
- }
71
- localStorage.setItem(
72
- storageKey,
73
- JSON.stringify({ v: import_package.version, t: (/* @__PURE__ */ new Date()).toLocaleString() })
74
- );
75
- } catch {
76
- }
77
- beaconSend(`${domain}${import_constants.APP_VERSION_ENDPOINT}`, { appId, version: import_package.version });
78
- }
79
- function reportBatch(config, batch) {
80
- if (!batch.length)
81
- return;
82
- const { domain } = config;
83
- beaconSend(`${domain}${import_constants.TRACK_ENDPOINT}`, batch);
84
- }
85
- function reportApiLog(config, apiLog, envelope) {
86
- const { domain } = config;
87
- beaconSend(`${domain}${import_constants.TRACK_ENDPOINT}`, [envelope]);
88
- }
89
- async function reportError(config, envelope, replayPayload) {
90
- const { domain } = config;
91
- const { data: id } = await fetchWrapper(`${domain}${import_constants.ERROR_TRACK_ENDPOINT}`, {
92
- method: "POST",
93
- headers: {
94
- "Content-Type": "application/json"
95
- },
96
- body: JSON.stringify(envelope)
97
- });
98
- if (id && replayPayload) {
99
- fetchWrapper(`${domain}${import_constants.ERROR_REPLAY_ENDPOINT}${id}`, {
100
- method: "POST",
101
- headers: {
102
- "Content-Type": "text/plain"
103
- },
104
- body: JSON.stringify(replayPayload)
105
- });
106
- }
107
- }
108
- // Annotate the CommonJS export names for ESM import in node:
109
- 0 && (module.exports = {
110
- beaconSend,
111
- reportApiLog,
112
- reportAppVersion,
113
- reportBatch,
114
- reportError
115
- });