@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.
- package/dist/Track/Beacon.d.ts +6 -0
- package/dist/Track/Beacon.js +58 -0
- package/dist/Track/Config.d.ts +11 -0
- package/dist/Track/Config.js +34 -0
- package/dist/Track/Listener.d.ts +5 -0
- package/dist/Track/Listener.js +46 -0
- package/dist/Track/Log.d.ts +8 -0
- package/dist/Track/Log.js +100 -0
- package/dist/Track/Replay.d.ts +6 -0
- package/dist/Track/Replay.js +77 -0
- package/dist/Track/System.d.ts +5 -0
- package/dist/Track/System.js +24 -0
- package/dist/Track/User.d.ts +6 -0
- package/dist/Track/User.js +29 -0
- package/dist/Track/index.d.ts +15 -20
- package/dist/Track/index.js +40 -164
- package/dist/Utils/auth.d.ts +9 -2
- package/dist/Utils/auth.js +80 -20
- package/dist/Utils/route.d.ts +11 -3
- package/dist/Utils/route.js +49 -56
- package/dist/Utils/url.js +3 -13
- package/dist/interfaces/track.interface.d.ts +1 -80
- package/dist/interfaces/track.interface.js +1 -5
- package/lib/Track/Beacon.d.ts +6 -0
- package/lib/Track/Beacon.js +73 -0
- package/lib/Track/Config.d.ts +11 -0
- package/lib/Track/{core/queue.js → Config.js} +23 -27
- package/lib/Track/Listener.d.ts +5 -0
- package/lib/Track/Listener.js +62 -0
- package/lib/Track/Log.d.ts +8 -0
- package/lib/Track/Log.js +95 -0
- package/lib/Track/Replay.d.ts +6 -0
- package/lib/Track/Replay.js +79 -0
- package/lib/Track/System.d.ts +5 -0
- package/lib/Track/{core/router.js → System.js} +18 -20
- package/lib/Track/User.d.ts +6 -0
- package/lib/Track/User.js +40 -0
- package/lib/Track/index.d.ts +15 -20
- package/lib/Track/index.js +39 -91
- package/lib/Utils/auth.d.ts +9 -2
- package/lib/Utils/auth.js +52 -17
- package/lib/Utils/route.d.ts +11 -3
- package/lib/Utils/route.js +34 -49
- package/lib/Utils/url.js +3 -3
- package/lib/interfaces/track.interface.d.ts +1 -80
- package/package.json +13 -13
- package/dist/Track/core/auth.d.ts +0 -16
- package/dist/Track/core/auth.js +0 -83
- package/dist/Track/core/constants.d.ts +0 -14
- package/dist/Track/core/constants.js +0 -25
- package/dist/Track/core/envelope.d.ts +0 -9
- package/dist/Track/core/envelope.js +0 -54
- package/dist/Track/core/instance.d.ts +0 -108
- package/dist/Track/core/instance.js +0 -365
- package/dist/Track/core/lifecycle.d.ts +0 -18
- package/dist/Track/core/lifecycle.js +0 -59
- package/dist/Track/core/profile.d.ts +0 -5
- package/dist/Track/core/profile.js +0 -30
- package/dist/Track/core/queue.d.ts +0 -13
- package/dist/Track/core/queue.js +0 -36
- package/dist/Track/core/replay.d.ts +0 -17
- package/dist/Track/core/replay.js +0 -117
- package/dist/Track/core/router.d.ts +0 -6
- package/dist/Track/core/router.js +0 -15
- package/dist/Track/core/system.d.ts +0 -14
- package/dist/Track/core/system.js +0 -36
- package/dist/Track/core/transport.d.ts +0 -18
- package/dist/Track/core/transport.js +0 -151
- package/lib/Track/core/auth.d.ts +0 -16
- package/lib/Track/core/auth.js +0 -67
- package/lib/Track/core/constants.d.ts +0 -14
- package/lib/Track/core/constants.js +0 -56
- package/lib/Track/core/envelope.d.ts +0 -9
- package/lib/Track/core/envelope.js +0 -61
- package/lib/Track/core/instance.d.ts +0 -108
- package/lib/Track/core/instance.js +0 -257
- package/lib/Track/core/lifecycle.d.ts +0 -18
- package/lib/Track/core/lifecycle.js +0 -74
- package/lib/Track/core/profile.d.ts +0 -5
- package/lib/Track/core/profile.js +0 -47
- package/lib/Track/core/queue.d.ts +0 -13
- package/lib/Track/core/replay.d.ts +0 -17
- package/lib/Track/core/replay.js +0 -131
- package/lib/Track/core/router.d.ts +0 -6
- package/lib/Track/core/system.d.ts +0 -14
- package/lib/Track/core/system.js +0 -53
- package/lib/Track/core/transport.d.ts +0 -18
- package/lib/Track/core/transport.js +0 -115
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TrackerInstance - 多实例核心组合:权限初始化 + 队列 + 采样 + 生命周期
|
|
3
|
-
*/
|
|
4
|
-
import { AuthCenterUserProfile, CustomizeProfile, ErrorProfile, TrackConfig, UserProfile } from '../../interfaces/track.interface';
|
|
5
|
-
export declare class TrackerInstance {
|
|
6
|
-
private config;
|
|
7
|
-
private userProfile;
|
|
8
|
-
private authCenterUserProfile;
|
|
9
|
-
private routesMap;
|
|
10
|
-
private authMap;
|
|
11
|
-
private queue;
|
|
12
|
-
private internal;
|
|
13
|
-
private replay?;
|
|
14
|
-
private lifecycle?;
|
|
15
|
-
/**
|
|
16
|
-
* 构造函数:合并配置 + 参数校验
|
|
17
|
-
*/
|
|
18
|
-
constructor(cfg: TrackConfig);
|
|
19
|
-
/**
|
|
20
|
-
* 初始化:
|
|
21
|
-
* 1. 拉取权限/菜单/数据域信息
|
|
22
|
-
* 2. 合并用户画像(优先 AuthCenter,再叠加外部传入)
|
|
23
|
-
* 3. 挂载生命周期监听(visibilitychange / error)
|
|
24
|
-
* 4. 上报版本信息 & 启动定时 flush
|
|
25
|
-
*/
|
|
26
|
-
init(): Promise<AuthCenterUserProfile>;
|
|
27
|
-
/**
|
|
28
|
-
* Flush:
|
|
29
|
-
* - 取出队列中全部事件
|
|
30
|
-
*/
|
|
31
|
-
flush(): void;
|
|
32
|
-
/**
|
|
33
|
-
* 销毁:清理定时器 & 事件监听,并 flush 剩余数据
|
|
34
|
-
*/
|
|
35
|
-
destroy(): void;
|
|
36
|
-
/**
|
|
37
|
-
* 事件日志:
|
|
38
|
-
* - 支持传入字符串(自动映射为 authMap 描述)或对象
|
|
39
|
-
* - 自动补全 module(基于当前路由)
|
|
40
|
-
*/
|
|
41
|
-
eventLog(eventLog: CustomizeProfile | string): void;
|
|
42
|
-
/**
|
|
43
|
-
* 访问日志:
|
|
44
|
-
* - 默认按当前路由模块组装文案
|
|
45
|
-
* - 若路由标记 isRedirect 则跳过(避免中转页统计)
|
|
46
|
-
*/
|
|
47
|
-
visitLog(visitLog?: CustomizeProfile): void;
|
|
48
|
-
/**
|
|
49
|
-
* 错误日志:force = true 不受采样率影响
|
|
50
|
-
*/
|
|
51
|
-
errorLog(error: ErrorProfile): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* API 日志:直接即时上报(不进入公共队列)
|
|
54
|
-
*/
|
|
55
|
-
apiLog(apiLog: any): void;
|
|
56
|
-
/**
|
|
57
|
-
* 动态更新用户画像(不会重置已有字段)
|
|
58
|
-
*/
|
|
59
|
-
setUserProfile(patch: Partial<UserProfile>): void;
|
|
60
|
-
/** 获取当前实例配置副本(避免外部直接修改内部对象) */
|
|
61
|
-
getConfig(): {
|
|
62
|
-
appId: string;
|
|
63
|
-
userProfile?: UserProfile | undefined;
|
|
64
|
-
base?: string | undefined;
|
|
65
|
-
getAuth?: (() => Promise<any>) | undefined;
|
|
66
|
-
menuBuild?: (() => Promise<import("../../interfaces/track.interface").AuthMenuItemType[]>) | undefined;
|
|
67
|
-
menuNameMap?: import("../../interfaces/track.interface").MenuNameMapType | undefined;
|
|
68
|
-
routes?: import("../../interfaces/track.interface").RouteType[] | undefined;
|
|
69
|
-
getDataScopeZonePermissions?: (() => Promise<{
|
|
70
|
-
zoneId: number;
|
|
71
|
-
zoneName: string;
|
|
72
|
-
}[]>) | undefined;
|
|
73
|
-
domain: string;
|
|
74
|
-
enableReplay?: boolean | undefined;
|
|
75
|
-
};
|
|
76
|
-
/** 配置校验:缺少关键字段直接抛错 */
|
|
77
|
-
private validate;
|
|
78
|
-
/**
|
|
79
|
-
* 合并用户画像:
|
|
80
|
-
* - 若权限中心未返回 userName,则只使用外部提供
|
|
81
|
-
* - 否则使用 AuthCenter 信息并叠加外部 patch
|
|
82
|
-
*/
|
|
83
|
-
private mergeUserProfile;
|
|
84
|
-
/**
|
|
85
|
-
* 入队封装:
|
|
86
|
-
* - 全量采样
|
|
87
|
-
* - 生成 envelope
|
|
88
|
-
* - 触发阈值自动 flush
|
|
89
|
-
*/
|
|
90
|
-
private enqueue;
|
|
91
|
-
/** 获取当前路径(剥离 base 前缀) */
|
|
92
|
-
private getFormatPath;
|
|
93
|
-
/** 获取当前页面的模块层级(由 routesMap 提供) */
|
|
94
|
-
private getPageModules;
|
|
95
|
-
/** 挂载浏览器事件监听 */
|
|
96
|
-
private mountLifecycle;
|
|
97
|
-
/** 启动/重置周期性 flush 计时器 */
|
|
98
|
-
private scheduleFlushTimer;
|
|
99
|
-
/** 校验 module 是否有效(非空且非纯空白) */
|
|
100
|
-
private isValidModule;
|
|
101
|
-
/** 获取过滤后的模块层级(去除空项和空白) */
|
|
102
|
-
private getFilteredModules;
|
|
103
|
-
/** 若日志缺少 module,则尝试用路由模块补齐;返回是否有效 */
|
|
104
|
-
private fillModuleIfMissing;
|
|
105
|
-
private maybeStartReplay;
|
|
106
|
-
private stopReplay;
|
|
107
|
-
private buildReplayAttachment;
|
|
108
|
-
}
|
|
@@ -1,257 +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/instance.ts
|
|
20
|
-
var instance_exports = {};
|
|
21
|
-
__export(instance_exports, {
|
|
22
|
-
TrackerInstance: () => TrackerInstance
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(instance_exports);
|
|
25
|
-
var import_auth = require("./auth");
|
|
26
|
-
var import_constants = require("./constants");
|
|
27
|
-
var import_envelope = require("./envelope");
|
|
28
|
-
var import_lifecycle = require("./lifecycle");
|
|
29
|
-
var import_profile = require("./profile");
|
|
30
|
-
var import_queue = require("./queue");
|
|
31
|
-
var import_replay = require("./replay");
|
|
32
|
-
var import_router = require("./router");
|
|
33
|
-
var import_transport = require("./transport");
|
|
34
|
-
var TrackerInstance = class {
|
|
35
|
-
/**
|
|
36
|
-
* 构造函数:合并配置 + 参数校验
|
|
37
|
-
*/
|
|
38
|
-
constructor(cfg) {
|
|
39
|
-
this.userProfile = { userId: "", userName: "" };
|
|
40
|
-
this.authCenterUserProfile = {};
|
|
41
|
-
this.routesMap = /* @__PURE__ */ new Map();
|
|
42
|
-
this.authMap = /* @__PURE__ */ new Map();
|
|
43
|
-
this.queue = new import_queue.TrackQueue();
|
|
44
|
-
this.internal = { initialized: false, destroyed: false };
|
|
45
|
-
this.config = {
|
|
46
|
-
// 回放默认开启
|
|
47
|
-
enableReplay: true,
|
|
48
|
-
...cfg
|
|
49
|
-
};
|
|
50
|
-
this.validate();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 初始化:
|
|
54
|
-
* 1. 拉取权限/菜单/数据域信息
|
|
55
|
-
* 2. 合并用户画像(优先 AuthCenter,再叠加外部传入)
|
|
56
|
-
* 3. 挂载生命周期监听(visibilitychange / error)
|
|
57
|
-
* 4. 上报版本信息 & 启动定时 flush
|
|
58
|
-
*/
|
|
59
|
-
async init() {
|
|
60
|
-
if (this.internal.initialized)
|
|
61
|
-
return this.authCenterUserProfile;
|
|
62
|
-
const { authCenterUserProfile, authMap, routesMap } = await (0, import_auth.initAuthCenterData)(this.config);
|
|
63
|
-
this.authCenterUserProfile = authCenterUserProfile;
|
|
64
|
-
this.authMap = authMap;
|
|
65
|
-
this.routesMap = routesMap;
|
|
66
|
-
this.mergeUserProfile();
|
|
67
|
-
this.mountLifecycle();
|
|
68
|
-
this.maybeStartReplay();
|
|
69
|
-
(0, import_transport.reportAppVersion)(this.config);
|
|
70
|
-
this.internal.initialized = true;
|
|
71
|
-
this.scheduleFlushTimer();
|
|
72
|
-
return this.authCenterUserProfile;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Flush:
|
|
76
|
-
* - 取出队列中全部事件
|
|
77
|
-
*/
|
|
78
|
-
flush() {
|
|
79
|
-
if (!this.queue.size())
|
|
80
|
-
return;
|
|
81
|
-
const batch = this.queue.drain();
|
|
82
|
-
(0, import_transport.reportBatch)(this.config, batch);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 销毁:清理定时器 & 事件监听,并 flush 剩余数据
|
|
86
|
-
*/
|
|
87
|
-
destroy() {
|
|
88
|
-
var _a;
|
|
89
|
-
if (this.internal.destroyed)
|
|
90
|
-
return;
|
|
91
|
-
this.flush();
|
|
92
|
-
(_a = this.lifecycle) == null ? void 0 : _a.unmount();
|
|
93
|
-
this.stopReplay();
|
|
94
|
-
clearInterval(this.internal.flushTimer);
|
|
95
|
-
this.internal.destroyed = true;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 事件日志:
|
|
99
|
-
* - 支持传入字符串(自动映射为 authMap 描述)或对象
|
|
100
|
-
* - 自动补全 module(基于当前路由)
|
|
101
|
-
*/
|
|
102
|
-
eventLog(eventLog) {
|
|
103
|
-
const data = { module: "", content: "" };
|
|
104
|
-
if (typeof eventLog === "string") {
|
|
105
|
-
const action = this.authMap.get(eventLog);
|
|
106
|
-
data.content = action ? "触发: " + action : eventLog;
|
|
107
|
-
} else
|
|
108
|
-
Object.assign(data, eventLog);
|
|
109
|
-
const modules = this.getFilteredModules();
|
|
110
|
-
if (!this.fillModuleIfMissing(data, modules))
|
|
111
|
-
return;
|
|
112
|
-
this.enqueue("event", data);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 访问日志:
|
|
116
|
-
* - 默认按当前路由模块组装文案
|
|
117
|
-
* - 若路由标记 isRedirect 则跳过(避免中转页统计)
|
|
118
|
-
*/
|
|
119
|
-
visitLog(visitLog) {
|
|
120
|
-
const routeInfo = this.routesMap.get(this.getFormatPath());
|
|
121
|
-
if (routeInfo == null ? void 0 : routeInfo.isRedirect)
|
|
122
|
-
return;
|
|
123
|
-
const mods = this.getFilteredModules();
|
|
124
|
-
if (!visitLog) {
|
|
125
|
-
if (!mods.length)
|
|
126
|
-
return;
|
|
127
|
-
visitLog = {
|
|
128
|
-
module: mods.join("-"),
|
|
129
|
-
content: `访问页面: ${mods[mods.length - 1]}`
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
if (!this.fillModuleIfMissing(visitLog, mods))
|
|
133
|
-
return;
|
|
134
|
-
this.enqueue("visit", visitLog);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 错误日志:force = true 不受采样率影响
|
|
138
|
-
*/
|
|
139
|
-
async errorLog(error) {
|
|
140
|
-
var _a;
|
|
141
|
-
const throttle = import_constants.DEFAULT_ERROR_THROTTLE_MS;
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
if (this.internal.lastErrorSentAt && now - this.internal.lastErrorSentAt < throttle) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
(_a = this.replay) == null ? void 0 : _a.markError(error);
|
|
147
|
-
const replayPayload = this.buildReplayAttachment();
|
|
148
|
-
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, "error", error);
|
|
149
|
-
(0, import_transport.reportError)(this.config, env, replayPayload);
|
|
150
|
-
this.internal.lastErrorSentAt = now;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* API 日志:直接即时上报(不进入公共队列)
|
|
154
|
-
*/
|
|
155
|
-
apiLog(apiLog) {
|
|
156
|
-
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, "api", apiLog);
|
|
157
|
-
(0, import_transport.reportApiLog)(this.config, apiLog, env);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 动态更新用户画像(不会重置已有字段)
|
|
161
|
-
*/
|
|
162
|
-
setUserProfile(patch) {
|
|
163
|
-
Object.assign(this.userProfile, patch);
|
|
164
|
-
}
|
|
165
|
-
/** 获取当前实例配置副本(避免外部直接修改内部对象) */
|
|
166
|
-
getConfig() {
|
|
167
|
-
return { ...this.config };
|
|
168
|
-
}
|
|
169
|
-
/** 配置校验:缺少关键字段直接抛错 */
|
|
170
|
-
validate() {
|
|
171
|
-
if (!this.config.domain)
|
|
172
|
-
throw new Error("缺少 domain");
|
|
173
|
-
if (!this.config.appId)
|
|
174
|
-
throw new Error("缺少 appId");
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 合并用户画像:
|
|
178
|
-
* - 若权限中心未返回 userName,则只使用外部提供
|
|
179
|
-
* - 否则使用 AuthCenter 信息并叠加外部 patch
|
|
180
|
-
*/
|
|
181
|
-
mergeUserProfile() {
|
|
182
|
-
this.userProfile = (0, import_profile.mergeUserProfile)(
|
|
183
|
-
this.authCenterUserProfile,
|
|
184
|
-
this.config.userProfile
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 入队封装:
|
|
189
|
-
* - 全量采样
|
|
190
|
-
* - 生成 envelope
|
|
191
|
-
* - 触发阈值自动 flush
|
|
192
|
-
*/
|
|
193
|
-
enqueue(type, log, opts) {
|
|
194
|
-
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, type, log);
|
|
195
|
-
this.queue.push(env);
|
|
196
|
-
if (this.queue.size() >= import_constants.DEFAULT_FLUSH_THRESHOLD)
|
|
197
|
-
this.flush();
|
|
198
|
-
}
|
|
199
|
-
/** 获取当前路径(剥离 base 前缀) */
|
|
200
|
-
getFormatPath() {
|
|
201
|
-
return (0, import_router.getFormattedPath)(this.config);
|
|
202
|
-
}
|
|
203
|
-
/** 获取当前页面的模块层级(由 routesMap 提供) */
|
|
204
|
-
getPageModules() {
|
|
205
|
-
return (0, import_router.getPageModules)(this.config, this.routesMap);
|
|
206
|
-
}
|
|
207
|
-
/** 挂载浏览器事件监听 */
|
|
208
|
-
mountLifecycle() {
|
|
209
|
-
this.lifecycle = new import_lifecycle.LifecycleManager({
|
|
210
|
-
onHidden: () => this.flush(),
|
|
211
|
-
onError: (err) => this.errorLog(err)
|
|
212
|
-
});
|
|
213
|
-
this.lifecycle.mount();
|
|
214
|
-
}
|
|
215
|
-
/** 启动/重置周期性 flush 计时器 */
|
|
216
|
-
scheduleFlushTimer() {
|
|
217
|
-
this.internal.flushTimer && clearInterval(this.internal.flushTimer);
|
|
218
|
-
this.internal.flushTimer = setInterval(
|
|
219
|
-
() => this.flush(),
|
|
220
|
-
import_constants.DEFAULT_MAX_WAIT_MS
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
/** 校验 module 是否有效(非空且非纯空白) */
|
|
224
|
-
isValidModule(mod) {
|
|
225
|
-
return !!(mod && mod.trim());
|
|
226
|
-
}
|
|
227
|
-
/** 获取过滤后的模块层级(去除空项和空白) */
|
|
228
|
-
getFilteredModules() {
|
|
229
|
-
return (this.getPageModules() || []).filter((m) => m && m.trim());
|
|
230
|
-
}
|
|
231
|
-
/** 若日志缺少 module,则尝试用路由模块补齐;返回是否有效 */
|
|
232
|
-
fillModuleIfMissing(profile, modules) {
|
|
233
|
-
if (!profile.module && modules.length) {
|
|
234
|
-
profile.module = modules.join("-");
|
|
235
|
-
}
|
|
236
|
-
return this.isValidModule(profile.module);
|
|
237
|
-
}
|
|
238
|
-
/* ================= rrweb 录制相关 ================= */
|
|
239
|
-
maybeStartReplay() {
|
|
240
|
-
if (!this.config.enableReplay)
|
|
241
|
-
return;
|
|
242
|
-
this.replay = new import_replay.ReplayManager(this.config);
|
|
243
|
-
this.replay.start();
|
|
244
|
-
}
|
|
245
|
-
stopReplay() {
|
|
246
|
-
var _a;
|
|
247
|
-
(_a = this.replay) == null ? void 0 : _a.stop();
|
|
248
|
-
}
|
|
249
|
-
buildReplayAttachment() {
|
|
250
|
-
var _a;
|
|
251
|
-
return (_a = this.replay) == null ? void 0 : _a.buildAttachment();
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
-
0 && (module.exports = {
|
|
256
|
-
TrackerInstance
|
|
257
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LifecycleManager - 浏览器生命周期与错误监听的封装
|
|
3
|
-
*/
|
|
4
|
-
import { ErrorProfile } from '../../interfaces/track.interface';
|
|
5
|
-
type Options = {
|
|
6
|
-
onHidden?: () => void;
|
|
7
|
-
onError?: (error: ErrorProfile) => void;
|
|
8
|
-
};
|
|
9
|
-
export declare class LifecycleManager {
|
|
10
|
-
private opts;
|
|
11
|
-
constructor(opts: Options);
|
|
12
|
-
private onVisibilityChange;
|
|
13
|
-
private onWindowError;
|
|
14
|
-
private onUnhandledRejection;
|
|
15
|
-
mount(): void;
|
|
16
|
-
unmount(): void;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,74 +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/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
|
-
});
|
|
@@ -1,47 +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/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
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/Track/core/replay.js
DELETED
|
@@ -1,131 +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/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
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
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[];
|