@yysports/tools 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Track/core/auth.d.ts +16 -0
- package/dist/Track/core/auth.js +83 -0
- package/dist/Track/core/constants.d.ts +14 -0
- package/dist/Track/core/constants.js +25 -0
- package/dist/Track/core/envelope.d.ts +9 -0
- package/dist/Track/core/envelope.js +54 -0
- package/dist/Track/core/instance.d.ts +108 -0
- package/dist/Track/core/instance.js +365 -0
- package/dist/Track/core/lifecycle.d.ts +18 -0
- package/dist/Track/core/lifecycle.js +59 -0
- package/dist/Track/core/profile.d.ts +5 -0
- package/dist/Track/core/profile.js +30 -0
- package/dist/Track/core/queue.d.ts +13 -0
- package/dist/Track/core/queue.js +36 -0
- package/dist/Track/core/replay.d.ts +17 -0
- package/dist/Track/core/replay.js +117 -0
- package/dist/Track/core/router.d.ts +6 -0
- package/dist/Track/core/router.js +15 -0
- package/dist/Track/core/system.d.ts +14 -0
- package/dist/Track/core/system.js +36 -0
- package/dist/Track/core/transport.d.ts +18 -0
- package/dist/Track/core/transport.js +151 -0
- package/dist/Track/index.d.ts +19 -28
- package/dist/Track/index.js +144 -396
- package/dist/Utils/common.js +5 -6
- package/dist/Utils/route.js +1 -6
- package/dist/Utils/url.js +1 -3
- package/dist/Utils/wx.js +2 -7
- package/dist/interfaces/track.interface.d.ts +14 -4
- package/lib/Track/core/auth.d.ts +16 -0
- package/lib/Track/core/auth.js +67 -0
- package/lib/Track/core/constants.d.ts +14 -0
- package/lib/Track/core/constants.js +56 -0
- package/lib/Track/core/envelope.d.ts +9 -0
- package/lib/Track/core/envelope.js +61 -0
- package/lib/Track/core/instance.d.ts +108 -0
- package/lib/Track/core/instance.js +257 -0
- package/lib/Track/core/lifecycle.d.ts +18 -0
- package/lib/Track/core/lifecycle.js +74 -0
- package/lib/Track/core/profile.d.ts +5 -0
- package/lib/Track/core/profile.js +47 -0
- package/lib/Track/core/queue.d.ts +13 -0
- package/lib/Track/core/queue.js +49 -0
- package/lib/Track/core/replay.d.ts +17 -0
- package/lib/Track/core/replay.js +131 -0
- package/lib/Track/core/router.d.ts +6 -0
- package/lib/Track/core/router.js +39 -0
- package/lib/Track/core/system.d.ts +14 -0
- package/lib/Track/core/system.js +53 -0
- package/lib/Track/core/transport.d.ts +18 -0
- package/lib/Track/core/transport.js +115 -0
- package/lib/Track/index.d.ts +19 -28
- package/lib/Track/index.js +93 -317
- package/lib/Utils/common.js +4 -6
- package/lib/interfaces/track.interface.d.ts +14 -4
- package/package.json +11 -10
|
@@ -0,0 +1,74 @@
|
|
|
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/lifecycle.ts
|
|
20
|
+
var lifecycle_exports = {};
|
|
21
|
+
__export(lifecycle_exports, {
|
|
22
|
+
LifecycleManager: () => LifecycleManager
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(lifecycle_exports);
|
|
25
|
+
var LifecycleManager = class {
|
|
26
|
+
constructor(opts) {
|
|
27
|
+
this.onVisibilityChange = () => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
try {
|
|
30
|
+
if (typeof document === "undefined")
|
|
31
|
+
return;
|
|
32
|
+
if (document.visibilityState === "hidden")
|
|
33
|
+
(_b = (_a = this.opts).onHidden) == null ? void 0 : _b.call(_a);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.onWindowError = (e) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const err = {
|
|
40
|
+
message: e.message,
|
|
41
|
+
fileName: e.filename
|
|
42
|
+
};
|
|
43
|
+
(_b = (_a = this.opts).onError) == null ? void 0 : _b.call(_a, err);
|
|
44
|
+
};
|
|
45
|
+
this.onUnhandledRejection = (e) => {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
const reason = e.reason;
|
|
48
|
+
const message = reason && (reason.message || ((_a = reason.toString) == null ? void 0 : _a.call(reason))) || "unhandledrejection";
|
|
49
|
+
(_c = (_b = this.opts).onError) == null ? void 0 : _c.call(_b, { message, fileName: "unhandledrejection" });
|
|
50
|
+
};
|
|
51
|
+
this.opts = opts;
|
|
52
|
+
}
|
|
53
|
+
mount() {
|
|
54
|
+
if (typeof addEventListener === "undefined")
|
|
55
|
+
return;
|
|
56
|
+
addEventListener("visibilitychange", this.onVisibilityChange);
|
|
57
|
+
addEventListener("error", this.onWindowError);
|
|
58
|
+
addEventListener("unhandledrejection", this.onUnhandledRejection);
|
|
59
|
+
}
|
|
60
|
+
unmount() {
|
|
61
|
+
if (typeof removeEventListener === "undefined")
|
|
62
|
+
return;
|
|
63
|
+
removeEventListener("visibilitychange", this.onVisibilityChange);
|
|
64
|
+
removeEventListener("error", this.onWindowError);
|
|
65
|
+
removeEventListener(
|
|
66
|
+
"unhandledrejection",
|
|
67
|
+
this.onUnhandledRejection
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
LifecycleManager
|
|
74
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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/profile.ts
|
|
20
|
+
var profile_exports = {};
|
|
21
|
+
__export(profile_exports, {
|
|
22
|
+
mergeUserProfile: () => mergeUserProfile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(profile_exports);
|
|
25
|
+
function mergeUserProfile(authCenter, external) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
if (!(authCenter == null ? void 0 : authCenter.userName)) {
|
|
28
|
+
return {
|
|
29
|
+
userId: "",
|
|
30
|
+
userName: "",
|
|
31
|
+
...external || {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const base = {
|
|
35
|
+
userId: authCenter.userName,
|
|
36
|
+
userName: authCenter.nickName,
|
|
37
|
+
orgCode: authCenter.orgCode,
|
|
38
|
+
orgTitle: authCenter.orgTitle,
|
|
39
|
+
dataScopeRoles: (_a = authCenter.dataScopeRoles) == null ? void 0 : _a.map((r) => r.name).join(","),
|
|
40
|
+
dataScopeZonePermissions: (_c = (_b = authCenter.dataScopeZonePermissions) == null ? void 0 : _b.list) == null ? void 0 : _c.map((g) => g.list.map((z) => z.zoneId).join(",")).join(",")
|
|
41
|
+
};
|
|
42
|
+
return { ...base, ...external || {} };
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
mergeUserProfile
|
|
47
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrackQueue - 轻量埋点队列实现
|
|
3
|
+
* 提供 push / size / drain 三个最小操作,避免引入额外依赖。
|
|
4
|
+
*/
|
|
5
|
+
export declare class TrackQueue<T> {
|
|
6
|
+
private items;
|
|
7
|
+
/** 入队一个元素 */
|
|
8
|
+
push(item: T): void;
|
|
9
|
+
/** 当前元素数量 */
|
|
10
|
+
size(): number;
|
|
11
|
+
/** 取出并清空所有元素(返回快照) */
|
|
12
|
+
drain(): T[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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/queue.ts
|
|
20
|
+
var queue_exports = {};
|
|
21
|
+
__export(queue_exports, {
|
|
22
|
+
TrackQueue: () => TrackQueue
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(queue_exports);
|
|
25
|
+
var TrackQueue = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.items = [];
|
|
28
|
+
}
|
|
29
|
+
/** 入队一个元素 */
|
|
30
|
+
push(item) {
|
|
31
|
+
this.items.push(item);
|
|
32
|
+
}
|
|
33
|
+
/** 当前元素数量 */
|
|
34
|
+
size() {
|
|
35
|
+
return this.items.length;
|
|
36
|
+
}
|
|
37
|
+
/** 取出并清空所有元素(返回快照) */
|
|
38
|
+
drain() {
|
|
39
|
+
if (!this.items.length)
|
|
40
|
+
return [];
|
|
41
|
+
const copy = this.items.slice();
|
|
42
|
+
this.items.length = 0;
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
TrackQueue
|
|
49
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ErrorProfile, TrackConfig } from '../../interfaces/track.interface';
|
|
2
|
+
export declare class ReplayManager {
|
|
3
|
+
private config;
|
|
4
|
+
private stopRecord?;
|
|
5
|
+
private segments;
|
|
6
|
+
constructor(config: TrackConfig);
|
|
7
|
+
start(): void;
|
|
8
|
+
stop(): void;
|
|
9
|
+
/**
|
|
10
|
+
* 构建随错包携带的回放事件,受条数与字节限制
|
|
11
|
+
*/
|
|
12
|
+
buildAttachment(): any[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* 在回放流中注入一条“错误”标记事件,便于后续定位
|
|
15
|
+
*/
|
|
16
|
+
markError(error: ErrorProfile): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
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/replay.ts
|
|
20
|
+
var replay_exports = {};
|
|
21
|
+
__export(replay_exports, {
|
|
22
|
+
ReplayManager: () => ReplayManager
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(replay_exports);
|
|
25
|
+
var import_record = require("@rrweb/record");
|
|
26
|
+
var import_rrweb_plugin_console_record = require("@rrweb/rrweb-plugin-console-record");
|
|
27
|
+
var import_constants = require("./constants");
|
|
28
|
+
var ReplayManager = class {
|
|
29
|
+
// 仅保留最近两段
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.segments = [[]];
|
|
32
|
+
this.config = config;
|
|
33
|
+
}
|
|
34
|
+
start() {
|
|
35
|
+
if (!this.config.enableReplay)
|
|
36
|
+
return;
|
|
37
|
+
if (typeof window === "undefined" || typeof document === "undefined")
|
|
38
|
+
return;
|
|
39
|
+
try {
|
|
40
|
+
const maxEvents = import_constants.DEFAULT_REPLAY_MAX_EVENTS;
|
|
41
|
+
const rrwebOptions = {
|
|
42
|
+
checkoutEveryNms: import_constants.DEFAULT_REPLAY_CHECKOUT_NMS
|
|
43
|
+
};
|
|
44
|
+
this.stopRecord = (0, import_record.record)({
|
|
45
|
+
emit: (event, isCheckout) => {
|
|
46
|
+
if (isCheckout)
|
|
47
|
+
this.segments.push([]);
|
|
48
|
+
const last = this.segments[this.segments.length - 1];
|
|
49
|
+
last.push(event);
|
|
50
|
+
if (this.segments.length > 2)
|
|
51
|
+
this.segments.shift();
|
|
52
|
+
if (last.length > maxEvents)
|
|
53
|
+
last.splice(0, last.length - maxEvents);
|
|
54
|
+
},
|
|
55
|
+
plugins: [(0, import_rrweb_plugin_console_record.getRecordConsolePlugin)()],
|
|
56
|
+
...rrwebOptions
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.warn("[track:debug] replay start failed", err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
stop() {
|
|
63
|
+
try {
|
|
64
|
+
this.stopRecord && this.stopRecord();
|
|
65
|
+
this.stopRecord = void 0;
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 构建随错包携带的回放事件,受条数与字节限制
|
|
71
|
+
*/
|
|
72
|
+
buildAttachment() {
|
|
73
|
+
if (!this.config.enableReplay)
|
|
74
|
+
return void 0;
|
|
75
|
+
if (!this.segments.length)
|
|
76
|
+
return void 0;
|
|
77
|
+
const joined = (this.segments[this.segments.length - 2] || []).concat(
|
|
78
|
+
this.segments[this.segments.length - 1] || []
|
|
79
|
+
);
|
|
80
|
+
if (!joined.length)
|
|
81
|
+
return void 0;
|
|
82
|
+
const maxEvents = import_constants.DEFAULT_REPLAY_MAX_EVENTS;
|
|
83
|
+
let sliced = joined.slice(-maxEvents);
|
|
84
|
+
const maxBytes = import_constants.DEFAULT_REPLAY_MAX_BYTES;
|
|
85
|
+
let json = JSON.stringify(sliced);
|
|
86
|
+
if (json.length > maxBytes) {
|
|
87
|
+
const step = Math.max(50, Math.floor(sliced.length * 0.1));
|
|
88
|
+
while (json.length > maxBytes && sliced.length > step) {
|
|
89
|
+
sliced = sliced.slice(step);
|
|
90
|
+
json = JSON.stringify(sliced);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return sliced;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 在回放流中注入一条“错误”标记事件,便于后续定位
|
|
97
|
+
*/
|
|
98
|
+
markError(error) {
|
|
99
|
+
if (!this.config.enableReplay)
|
|
100
|
+
return;
|
|
101
|
+
try {
|
|
102
|
+
const event = {
|
|
103
|
+
// rrweb 自定义事件类型:5(EventType.Custom)。避免直接依赖枚举,使用字面量。
|
|
104
|
+
type: 5,
|
|
105
|
+
timestamp: Date.now(),
|
|
106
|
+
data: {
|
|
107
|
+
tag: "error",
|
|
108
|
+
payload: {
|
|
109
|
+
message: error.message,
|
|
110
|
+
fileName: error.fileName,
|
|
111
|
+
href: typeof location !== "undefined" && (location == null ? void 0 : location.href) ? location.href : "",
|
|
112
|
+
userAgent: typeof navigator !== "undefined" && (navigator == null ? void 0 : navigator.userAgent) ? navigator.userAgent : ""
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (!this.segments.length)
|
|
117
|
+
this.segments.push([]);
|
|
118
|
+
const last = this.segments[this.segments.length - 1];
|
|
119
|
+
last.push(event);
|
|
120
|
+
const maxEvents = import_constants.DEFAULT_REPLAY_MAX_EVENTS;
|
|
121
|
+
if (last.length > maxEvents)
|
|
122
|
+
last.splice(0, last.length - maxEvents);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.warn("[track:debug] markError failed", e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
ReplayManager
|
|
131
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由辅助:基于 base 前缀规范化路径,并从 routesMap 提取模块层级
|
|
3
|
+
*/
|
|
4
|
+
import { RouteMapValueType, TrackConfig } from '../../interfaces/track.interface';
|
|
5
|
+
export declare function getFormattedPath(config: TrackConfig): string;
|
|
6
|
+
export declare function getPageModules(config: TrackConfig, routesMap: Map<string, RouteMapValueType>): string[];
|
|
@@ -0,0 +1,39 @@
|
|
|
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/router.ts
|
|
20
|
+
var router_exports = {};
|
|
21
|
+
__export(router_exports, {
|
|
22
|
+
getFormattedPath: () => getFormattedPath,
|
|
23
|
+
getPageModules: () => getPageModules
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(router_exports);
|
|
26
|
+
function getFormattedPath(config) {
|
|
27
|
+
const { base = "/" } = config;
|
|
28
|
+
const pathname = typeof location !== "undefined" ? location.pathname : "";
|
|
29
|
+
return pathname.replace(base, "/");
|
|
30
|
+
}
|
|
31
|
+
function getPageModules(config, routesMap) {
|
|
32
|
+
const ri = routesMap.get(getFormattedPath(config));
|
|
33
|
+
return (ri == null ? void 0 : ri.module) || [];
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
getFormattedPath,
|
|
38
|
+
getPageModules
|
|
39
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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>;
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
});
|
package/lib/Track/index.d.ts
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
log: ErrorProfile | CustomizeProfile;
|
|
21
|
-
}): void;
|
|
22
|
-
static getFormatBasePath(): string;
|
|
23
|
-
static getPageModuleName(): string[];
|
|
24
|
-
static errorLog(errorLog: ErrorProfile): void;
|
|
25
|
-
static eventLog(eventLog: CustomizeProfile | string): void;
|
|
26
|
-
static visitLog(visitLog?: CustomizeProfile): void;
|
|
27
|
-
static apiLog(apiLog: any): void;
|
|
28
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 简化版埋点入口(单实例)
|
|
3
|
+
* 提供统一 Track.init(config) 及若干日志方法,未初始化即抛错
|
|
4
|
+
*/
|
|
5
|
+
import { AuthCenterUserProfile, TrackConfig } from '../interfaces/track.interface';
|
|
6
|
+
import { TrackerInstance } from './core/instance';
|
|
7
|
+
export type { TrackerInstance };
|
|
8
|
+
type TrackAPI = {
|
|
9
|
+
init: (config: TrackConfig) => Promise<AuthCenterUserProfile>;
|
|
10
|
+
eventLog: TrackerInstance['eventLog'];
|
|
11
|
+
visitLog: TrackerInstance['visitLog'];
|
|
12
|
+
errorLog: (...args: Parameters<TrackerInstance['errorLog']>) => Promise<void>;
|
|
13
|
+
apiLog: TrackerInstance['apiLog'];
|
|
14
|
+
flush: () => void;
|
|
15
|
+
destroy: () => void;
|
|
16
|
+
setUserProfile: (profile: Parameters<TrackerInstance['setUserProfile']>[0]) => void;
|
|
17
|
+
getConfig: () => TrackConfig;
|
|
18
|
+
};
|
|
19
|
+
declare const Track: TrackAPI;
|
|
29
20
|
export default Track;
|