@yysports/tools 2.0.2 → 2.2.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.
Files changed (92) 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 -17
  16. package/dist/Track/index.js +56 -67
  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 +2 -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 -17
  39. package/lib/Track/index.js +45 -39
  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 +2 -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 -17
  50. package/dist/Track/core/constants.js +0 -34
  51. package/dist/Track/core/envelope.d.ts +0 -9
  52. package/dist/Track/core/envelope.js +0 -54
  53. package/dist/Track/core/index.d.ts +0 -22
  54. package/dist/Track/core/index.js +0 -23
  55. package/dist/Track/core/instance.d.ts +0 -108
  56. package/dist/Track/core/instance.js +0 -375
  57. package/dist/Track/core/lifecycle.d.ts +0 -18
  58. package/dist/Track/core/lifecycle.js +0 -59
  59. package/dist/Track/core/profile.d.ts +0 -5
  60. package/dist/Track/core/profile.js +0 -30
  61. package/dist/Track/core/queue.d.ts +0 -13
  62. package/dist/Track/core/queue.js +0 -36
  63. package/dist/Track/core/replay.d.ts +0 -17
  64. package/dist/Track/core/replay.js +0 -117
  65. package/dist/Track/core/router.d.ts +0 -6
  66. package/dist/Track/core/router.js +0 -15
  67. package/dist/Track/core/system.d.ts +0 -14
  68. package/dist/Track/core/system.js +0 -36
  69. package/dist/Track/core/transport.d.ts +0 -18
  70. package/dist/Track/core/transport.js +0 -165
  71. package/lib/Track/core/auth.d.ts +0 -16
  72. package/lib/Track/core/auth.js +0 -67
  73. package/lib/Track/core/constants.d.ts +0 -17
  74. package/lib/Track/core/constants.js +0 -65
  75. package/lib/Track/core/envelope.d.ts +0 -9
  76. package/lib/Track/core/envelope.js +0 -61
  77. package/lib/Track/core/index.d.ts +0 -22
  78. package/lib/Track/core/index.js +0 -51
  79. package/lib/Track/core/instance.d.ts +0 -108
  80. package/lib/Track/core/instance.js +0 -266
  81. package/lib/Track/core/lifecycle.d.ts +0 -18
  82. package/lib/Track/core/lifecycle.js +0 -74
  83. package/lib/Track/core/profile.d.ts +0 -5
  84. package/lib/Track/core/profile.js +0 -47
  85. package/lib/Track/core/queue.d.ts +0 -13
  86. package/lib/Track/core/replay.d.ts +0 -17
  87. package/lib/Track/core/replay.js +0 -131
  88. package/lib/Track/core/router.d.ts +0 -6
  89. package/lib/Track/core/system.d.ts +0 -14
  90. package/lib/Track/core/system.js +0 -53
  91. package/lib/Track/core/transport.d.ts +0 -18
  92. package/lib/Track/core/transport.js +0 -128
@@ -1,375 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/esm/createClass";
6
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
- /**
8
- * TrackerInstance - 多实例核心组合:权限初始化 + 队列 + 采样 + 生命周期
9
- */
10
-
11
- import { initAuthCenterData } from "./auth";
12
- import { DEFAULT_ERROR_THROTTLE_MS, DEFAULT_FLUSH_THRESHOLD, DEFAULT_MAX_WAIT_MS } from "./constants";
13
- import { buildEnvelope } from "./envelope";
14
- import { LifecycleManager } from "./lifecycle";
15
- import { mergeUserProfile as _mergeUserProfile } from "./profile";
16
- import { TrackQueue } from "./queue";
17
- import { ReplayManager } from "./replay";
18
- import { getFormattedPath, getPageModules as _getPageModules } from "./router";
19
- import { reportApiLog, reportAppVersion, reportBatch, reportError } from "./transport";
20
- export var TrackerInstance = /*#__PURE__*/function () {
21
- /**
22
- * 构造函数:合并配置 + 参数校验
23
- */
24
- function TrackerInstance(cfg) {
25
- _classCallCheck(this, TrackerInstance);
26
- _defineProperty(this, "config", void 0);
27
- _defineProperty(this, "userProfile", {
28
- userId: '',
29
- userName: ''
30
- });
31
- _defineProperty(this, "authCenterUserProfile", {});
32
- _defineProperty(this, "routesMap", new Map());
33
- _defineProperty(this, "authMap", new Map());
34
- _defineProperty(this, "queue", new TrackQueue());
35
- _defineProperty(this, "internal", {
36
- initialized: false,
37
- destroyed: false
38
- });
39
- // 录制管理器
40
- _defineProperty(this, "replay", void 0);
41
- // 生命周期与错误监听
42
- _defineProperty(this, "lifecycle", void 0);
43
- this.config = _objectSpread({
44
- // 回放默认开启
45
- enableReplay: true
46
- }, cfg);
47
- this.validate();
48
- }
49
-
50
- /**
51
- * 初始化:
52
- * 1. 拉取权限/菜单/数据域信息
53
- * 2. 合并用户画像(优先 AuthCenter,再叠加外部传入)
54
- * 3. 挂载生命周期监听(visibilitychange / error)
55
- * 4. 上报版本信息 & 启动定时 flush
56
- */
57
- _createClass(TrackerInstance, [{
58
- key: "init",
59
- value: (function () {
60
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
61
- var _yield$initAuthCenter, authCenterUserProfile, authMap, routesMap;
62
- return _regeneratorRuntime().wrap(function _callee$(_context) {
63
- while (1) switch (_context.prev = _context.next) {
64
- case 0:
65
- if (!this.internal.initialized) {
66
- _context.next = 2;
67
- break;
68
- }
69
- return _context.abrupt("return", this.authCenterUserProfile);
70
- case 2:
71
- _context.next = 4;
72
- return initAuthCenterData(this.config);
73
- case 4:
74
- _yield$initAuthCenter = _context.sent;
75
- authCenterUserProfile = _yield$initAuthCenter.authCenterUserProfile;
76
- authMap = _yield$initAuthCenter.authMap;
77
- routesMap = _yield$initAuthCenter.routesMap;
78
- this.authCenterUserProfile = authCenterUserProfile;
79
- this.authMap = authMap;
80
- this.routesMap = routesMap;
81
- this.mergeUserProfile();
82
- this.mountLifecycle();
83
- this.maybeStartReplay();
84
- reportAppVersion(this.config);
85
- this.internal.initialized = true;
86
- this.scheduleFlushTimer();
87
- return _context.abrupt("return", this.authCenterUserProfile);
88
- case 18:
89
- case "end":
90
- return _context.stop();
91
- }
92
- }, _callee, this);
93
- }));
94
- function init() {
95
- return _init.apply(this, arguments);
96
- }
97
- return init;
98
- }()
99
- /**
100
- * Flush:
101
- * - 取出队列中全部事件
102
- */
103
- )
104
- }, {
105
- key: "flush",
106
- value: function flush() {
107
- if (!this.queue.size()) return;
108
- var batch = this.queue.drain();
109
- reportBatch(this.config, batch);
110
- }
111
-
112
- /**
113
- * 销毁:清理定时器 & 事件监听,并 flush 剩余数据
114
- */
115
- }, {
116
- key: "destroy",
117
- value: function destroy() {
118
- var _this$lifecycle;
119
- if (this.internal.destroyed) return;
120
- this.flush();
121
- (_this$lifecycle = this.lifecycle) === null || _this$lifecycle === void 0 || _this$lifecycle.unmount();
122
- this.stopReplay();
123
- clearInterval(this.internal.flushTimer);
124
- this.internal.destroyed = true;
125
- }
126
-
127
- /**
128
- * 事件日志:
129
- * - 支持传入字符串(自动映射为 authMap 描述)或对象
130
- * - 自动补全 module(基于当前路由)
131
- */
132
- }, {
133
- key: "eventLog",
134
- value: function eventLog(_eventLog) {
135
- if (!this.internal.initialized) return;
136
- var data = {
137
- module: '',
138
- content: ''
139
- };
140
- if (typeof _eventLog === 'string') {
141
- var action = this.authMap.get(_eventLog);
142
- data.content = action ? '触发: ' + action : _eventLog;
143
- } else Object.assign(data, _eventLog);
144
-
145
- // 统一的模块补齐与校验
146
- var modules = this.getFilteredModules();
147
- if (!this.fillModuleIfMissing(data, modules)) return;
148
- this.enqueue('event', data);
149
- }
150
-
151
- /**
152
- * 访问日志:
153
- * - 默认按当前路由模块组装文案
154
- * - 若路由标记 isRedirect 则跳过(避免中转页统计)
155
- */
156
- }, {
157
- key: "visitLog",
158
- value: function visitLog(_visitLog) {
159
- if (!this.internal.initialized) return;
160
- var routeInfo = this.routesMap.get(this.getFormatPath());
161
- if (routeInfo !== null && routeInfo !== void 0 && routeInfo.isRedirect) return;
162
- var mods = this.getFilteredModules();
163
- if (!_visitLog) {
164
- if (!mods.length) return;
165
- _visitLog = {
166
- module: mods.join('-'),
167
- content: "\u8BBF\u95EE\u9875\u9762: ".concat(mods[mods.length - 1])
168
- };
169
- }
170
- // 统一的模块补齐与校验
171
- if (!this.fillModuleIfMissing(_visitLog, mods)) return;
172
- this.enqueue('visit', _visitLog);
173
- }
174
-
175
- /**
176
- * 错误日志:force = true 不受采样率影响
177
- */
178
- }, {
179
- key: "errorLog",
180
- value: (function () {
181
- var _errorLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
182
- var _this$replay;
183
- var throttle, now, replayPayload, env;
184
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
185
- while (1) switch (_context2.prev = _context2.next) {
186
- case 0:
187
- if (this.internal.initialized) {
188
- _context2.next = 2;
189
- break;
190
- }
191
- return _context2.abrupt("return");
192
- case 2:
193
- // 简单节流:同一窗口只发送首条
194
- throttle = DEFAULT_ERROR_THROTTLE_MS;
195
- now = Date.now();
196
- if (!(this.internal.lastErrorSentAt && now - this.internal.lastErrorSentAt < throttle)) {
197
- _context2.next = 6;
198
- break;
199
- }
200
- return _context2.abrupt("return");
201
- case 6:
202
- // 先把报错信息写入回放流,便于回放中定位
203
- (_this$replay = this.replay) === null || _this$replay === void 0 || _this$replay.markError(error);
204
-
205
- // 构建回放附件(包含刚刚注入的错误标记)
206
- replayPayload = this.buildReplayAttachment();
207
- env = buildEnvelope(this.config, this.userProfile, 'error', error);
208
- reportError(this.config, env, replayPayload);
209
-
210
- // 上报完成后再更新节流时间戳
211
- this.internal.lastErrorSentAt = now;
212
- case 11:
213
- case "end":
214
- return _context2.stop();
215
- }
216
- }, _callee2, this);
217
- }));
218
- function errorLog(_x) {
219
- return _errorLog.apply(this, arguments);
220
- }
221
- return errorLog;
222
- }()
223
- /**
224
- * API 日志:直接即时上报(不进入公共队列)
225
- */
226
- )
227
- }, {
228
- key: "apiLog",
229
- value: function apiLog(_apiLog) {
230
- if (!this.internal.initialized) return;
231
- var env = buildEnvelope(this.config, this.userProfile, 'api', _apiLog);
232
- reportApiLog(this.config, _apiLog, env);
233
- }
234
-
235
- /**
236
- * 动态更新用户画像(不会重置已有字段)
237
- */
238
- }, {
239
- key: "setUserProfile",
240
- value: function setUserProfile(patch) {
241
- Object.assign(this.userProfile, patch);
242
- }
243
-
244
- /** 获取当前实例配置副本(避免外部直接修改内部对象) */
245
- }, {
246
- key: "getConfig",
247
- value: function getConfig() {
248
- return _objectSpread({}, this.config);
249
- }
250
-
251
- /** 配置校验:缺少关键字段直接抛错 */
252
- }, {
253
- key: "validate",
254
- value: function validate() {
255
- if (!this.config.env) throw new Error('缺少 env');
256
- if (!this.config.appId) throw new Error('缺少 appId');
257
- }
258
-
259
- /**
260
- * 合并用户画像:
261
- * - 若权限中心未返回 userName,则只使用外部提供
262
- * - 否则使用 AuthCenter 信息并叠加外部 patch
263
- */
264
- }, {
265
- key: "mergeUserProfile",
266
- value: function mergeUserProfile() {
267
- this.userProfile = _mergeUserProfile(this.authCenterUserProfile, this.config.userProfile);
268
- }
269
-
270
- /**
271
- * 入队封装:
272
- * - 全量采样
273
- * - 生成 envelope
274
- * - 触发阈值自动 flush
275
- */
276
- }, {
277
- key: "enqueue",
278
- value: function enqueue(type, log, opts) {
279
- var env = buildEnvelope(this.config, this.userProfile, type, log);
280
- this.queue.push(env);
281
- if (this.queue.size() >= DEFAULT_FLUSH_THRESHOLD) this.flush();
282
- }
283
-
284
- /** 获取当前路径(剥离 base 前缀) */
285
- }, {
286
- key: "getFormatPath",
287
- value: function getFormatPath() {
288
- return getFormattedPath(this.config);
289
- }
290
-
291
- /** 获取当前页面的模块层级(由 routesMap 提供) */
292
- }, {
293
- key: "getPageModules",
294
- value: function getPageModules() {
295
- return _getPageModules(this.config, this.routesMap);
296
- }
297
-
298
- /** 挂载浏览器事件监听 */
299
- }, {
300
- key: "mountLifecycle",
301
- value: function mountLifecycle() {
302
- var _this = this;
303
- this.lifecycle = new LifecycleManager({
304
- onHidden: function onHidden() {
305
- return _this.flush();
306
- },
307
- onError: function onError(err) {
308
- return _this.errorLog(err);
309
- }
310
- });
311
- this.lifecycle.mount();
312
- }
313
-
314
- // history 监听功能已移除
315
-
316
- /** 启动/重置周期性 flush 计时器 */
317
- }, {
318
- key: "scheduleFlushTimer",
319
- value: function scheduleFlushTimer() {
320
- var _this2 = this;
321
- this.internal.flushTimer && clearInterval(this.internal.flushTimer);
322
- this.internal.flushTimer = setInterval(function () {
323
- return _this2.flush();
324
- }, DEFAULT_MAX_WAIT_MS);
325
- }
326
-
327
- /** 校验 module 是否有效(非空且非纯空白) */
328
- }, {
329
- key: "isValidModule",
330
- value: function isValidModule(mod) {
331
- return !!(mod && mod.trim());
332
- }
333
-
334
- /** 获取过滤后的模块层级(去除空项和空白) */
335
- }, {
336
- key: "getFilteredModules",
337
- value: function getFilteredModules() {
338
- return (this.getPageModules() || []).filter(function (m) {
339
- return m && m.trim();
340
- });
341
- }
342
-
343
- /** 若日志缺少 module,则尝试用路由模块补齐;返回是否有效 */
344
- }, {
345
- key: "fillModuleIfMissing",
346
- value: function fillModuleIfMissing(profile, modules) {
347
- if (!profile.module && modules.length) {
348
- profile.module = modules.join('-');
349
- }
350
- return this.isValidModule(profile.module);
351
- }
352
-
353
- /* ================= rrweb 录制相关 ================= */
354
- }, {
355
- key: "maybeStartReplay",
356
- value: function maybeStartReplay() {
357
- if (!this.config.enableReplay) return;
358
- this.replay = new ReplayManager(this.config);
359
- this.replay.start();
360
- }
361
- }, {
362
- key: "stopReplay",
363
- value: function stopReplay() {
364
- var _this$replay2;
365
- (_this$replay2 = this.replay) === null || _this$replay2 === void 0 || _this$replay2.stop();
366
- }
367
- }, {
368
- key: "buildReplayAttachment",
369
- value: function buildReplayAttachment() {
370
- var _this$replay3;
371
- return (_this$replay3 = this.replay) === null || _this$replay3 === void 0 ? void 0 : _this$replay3.buildAttachment();
372
- }
373
- }]);
374
- return TrackerInstance;
375
- }();
@@ -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,59 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- /**
5
- * LifecycleManager - 浏览器生命周期与错误监听的封装
6
- */
7
-
8
- export var LifecycleManager = /*#__PURE__*/function () {
9
- function LifecycleManager(opts) {
10
- var _this = this;
11
- _classCallCheck(this, LifecycleManager);
12
- _defineProperty(this, "opts", void 0);
13
- _defineProperty(this, "onVisibilityChange", function () {
14
- try {
15
- var _this$opts$onHidden, _this$opts;
16
- if (typeof document === 'undefined') return;
17
- if (document.visibilityState === 'hidden') (_this$opts$onHidden = (_this$opts = _this.opts).onHidden) === null || _this$opts$onHidden === void 0 || _this$opts$onHidden.call(_this$opts);
18
- } catch (_unused) {
19
- /* ignore */
20
- }
21
- });
22
- _defineProperty(this, "onWindowError", function (e) {
23
- var _this$opts$onError, _this$opts2;
24
- var err = {
25
- message: e.message,
26
- fileName: e.filename
27
- };
28
- (_this$opts$onError = (_this$opts2 = _this.opts).onError) === null || _this$opts$onError === void 0 || _this$opts$onError.call(_this$opts2, err);
29
- });
30
- _defineProperty(this, "onUnhandledRejection", function (e) {
31
- var _reason$toString, _this$opts$onError2, _this$opts3;
32
- var reason = e.reason;
33
- var message = reason && (reason.message || ((_reason$toString = reason.toString) === null || _reason$toString === void 0 ? void 0 : _reason$toString.call(reason))) || 'unhandledrejection';
34
- (_this$opts$onError2 = (_this$opts3 = _this.opts).onError) === null || _this$opts$onError2 === void 0 || _this$opts$onError2.call(_this$opts3, {
35
- message: message,
36
- fileName: 'unhandledrejection'
37
- });
38
- });
39
- this.opts = opts;
40
- }
41
- _createClass(LifecycleManager, [{
42
- key: "mount",
43
- value: function mount() {
44
- if (typeof addEventListener === 'undefined') return;
45
- addEventListener('visibilitychange', this.onVisibilityChange);
46
- addEventListener('error', this.onWindowError);
47
- addEventListener('unhandledrejection', this.onUnhandledRejection);
48
- }
49
- }, {
50
- key: "unmount",
51
- value: function unmount() {
52
- if (typeof removeEventListener === 'undefined') return;
53
- removeEventListener('visibilitychange', this.onVisibilityChange);
54
- removeEventListener('error', this.onWindowError);
55
- removeEventListener('unhandledrejection', this.onUnhandledRejection);
56
- }
57
- }]);
58
- return LifecycleManager;
59
- }();
@@ -1,5 +0,0 @@
1
- /**
2
- * 用户画像合并:优先使用权限中心信息,并叠加外部传入的 patch
3
- */
4
- import { AuthCenterUserProfile, UserProfile } from '../../interfaces/track.interface';
5
- export declare function mergeUserProfile(authCenter: AuthCenterUserProfile, external?: Partial<UserProfile>): UserProfile;
@@ -1,30 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- /**
3
- * 用户画像合并:优先使用权限中心信息,并叠加外部传入的 patch
4
- */
5
-
6
- export function mergeUserProfile(authCenter, external) {
7
- var _authCenter$dataScope, _authCenter$dataScope2;
8
- // 权限中心未返回 userName,则仅使用外部提供(保持与原逻辑一致)
9
- if (!(authCenter !== null && authCenter !== void 0 && authCenter.userName)) {
10
- return _objectSpread({
11
- userId: '',
12
- userName: ''
13
- }, external || {});
14
- }
15
- var base = {
16
- userId: authCenter.userName,
17
- userName: authCenter.nickName,
18
- orgCode: authCenter.orgCode,
19
- orgTitle: authCenter.orgTitle,
20
- dataScopeRoles: (_authCenter$dataScope = authCenter.dataScopeRoles) === null || _authCenter$dataScope === void 0 ? void 0 : _authCenter$dataScope.map(function (r) {
21
- return r.name;
22
- }).join(','),
23
- dataScopeZonePermissions: (_authCenter$dataScope2 = authCenter.dataScopeZonePermissions) === null || _authCenter$dataScope2 === void 0 || (_authCenter$dataScope2 = _authCenter$dataScope2.list) === null || _authCenter$dataScope2 === void 0 ? void 0 : _authCenter$dataScope2.map(function (g) {
24
- return g.list.map(function (z) {
25
- return z.zoneId;
26
- }).join(',');
27
- }).join(',')
28
- };
29
- return _objectSpread(_objectSpread({}, base), external || {});
30
- }
@@ -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,36 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- /**
5
- * TrackQueue - 轻量埋点队列实现
6
- * 提供 push / size / drain 三个最小操作,避免引入额外依赖。
7
- */
8
- export var TrackQueue = /*#__PURE__*/function () {
9
- function TrackQueue() {
10
- _classCallCheck(this, TrackQueue);
11
- _defineProperty(this, "items", []);
12
- }
13
- _createClass(TrackQueue, [{
14
- key: "push",
15
- value: /** 入队一个元素 */
16
- function push(item) {
17
- this.items.push(item);
18
- }
19
- /** 当前元素数量 */
20
- }, {
21
- key: "size",
22
- value: function size() {
23
- return this.items.length;
24
- }
25
- /** 取出并清空所有元素(返回快照) */
26
- }, {
27
- key: "drain",
28
- value: function drain() {
29
- if (!this.items.length) return [];
30
- var copy = this.items.slice();
31
- this.items.length = 0;
32
- return copy;
33
- }
34
- }]);
35
- return TrackQueue;
36
- }();
@@ -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
- }
@@ -1,117 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- /**
6
- * ReplayManager - 封装 rrweb 录制 & 最近片段管理
7
- */
8
- import { record as rrwebRecord } from '@rrweb/record';
9
- import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
10
- import { DEFAULT_REPLAY_CHECKOUT_NMS, DEFAULT_REPLAY_MAX_BYTES, DEFAULT_REPLAY_MAX_EVENTS } from "./constants";
11
- export var ReplayManager = /*#__PURE__*/function () {
12
- // 仅保留最近两段
13
-
14
- function ReplayManager(config) {
15
- _classCallCheck(this, ReplayManager);
16
- _defineProperty(this, "config", void 0);
17
- _defineProperty(this, "stopRecord", void 0);
18
- _defineProperty(this, "segments", [[]]);
19
- this.config = config;
20
- }
21
- _createClass(ReplayManager, [{
22
- key: "start",
23
- value: function start() {
24
- var _this = this;
25
- if (!this.config.enableReplay) return;
26
- if (typeof window === 'undefined' || typeof document === 'undefined') return;
27
- try {
28
- var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
29
- var rrwebOptions = {
30
- checkoutEveryNms: DEFAULT_REPLAY_CHECKOUT_NMS
31
- };
32
- this.stopRecord = rrwebRecord(_objectSpread({
33
- emit: function emit(event, isCheckout) {
34
- if (isCheckout) _this.segments.push([]);
35
- var last = _this.segments[_this.segments.length - 1];
36
- last.push(event);
37
- if (_this.segments.length > 2) _this.segments.shift();
38
- if (last.length > maxEvents) last.splice(0, last.length - maxEvents);
39
- },
40
- plugins: [getRecordConsolePlugin()]
41
- }, rrwebOptions));
42
- } catch (err) {
43
- console.warn('[track:debug] replay start failed', err);
44
- }
45
- }
46
- }, {
47
- key: "stop",
48
- value: function stop() {
49
- try {
50
- this.stopRecord && this.stopRecord();
51
- this.stopRecord = undefined;
52
- } catch (_unused) {
53
- /* ignore */
54
- }
55
- }
56
-
57
- /**
58
- * 构建随错包携带的回放事件,受条数与字节限制
59
- */
60
- }, {
61
- key: "buildAttachment",
62
- value: function buildAttachment() {
63
- if (!this.config.enableReplay) return undefined;
64
- if (!this.segments.length) return undefined;
65
- var joined = (this.segments[this.segments.length - 2] || []).concat(this.segments[this.segments.length - 1] || []);
66
- if (!joined.length) return undefined;
67
- var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
68
- var sliced = joined.slice(-maxEvents);
69
- var maxBytes = DEFAULT_REPLAY_MAX_BYTES;
70
- var json = JSON.stringify(sliced);
71
- if (json.length > maxBytes) {
72
- var step = Math.max(50, Math.floor(sliced.length * 0.1));
73
- while (json.length > maxBytes && sliced.length > step) {
74
- sliced = sliced.slice(step);
75
- json = JSON.stringify(sliced);
76
- }
77
- }
78
- return sliced;
79
- }
80
-
81
- /**
82
- * 在回放流中注入一条“错误”标记事件,便于后续定位
83
- */
84
- }, {
85
- key: "markError",
86
- value: function markError(error) {
87
- if (!this.config.enableReplay) return;
88
- try {
89
- var _location, _navigator;
90
- var event = {
91
- // rrweb 自定义事件类型:5(EventType.Custom)。避免直接依赖枚举,使用字面量。
92
- type: 5,
93
- timestamp: Date.now(),
94
- data: {
95
- tag: 'error',
96
- payload: {
97
- message: error.message,
98
- fileName: error.fileName,
99
- href: typeof location !== 'undefined' && (_location = location) !== null && _location !== void 0 && _location.href ? location.href : '',
100
- userAgent: typeof navigator !== 'undefined' && (_navigator = navigator) !== null && _navigator !== void 0 && _navigator.userAgent ? navigator.userAgent : ''
101
- }
102
- }
103
- };
104
- if (!this.segments.length) this.segments.push([]);
105
- var last = this.segments[this.segments.length - 1];
106
- last.push(event);
107
-
108
- // 与 start() 中保持一致的长度限制
109
- var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
110
- if (last.length > maxEvents) last.splice(0, last.length - maxEvents);
111
- } catch (e) {
112
- console.warn('[track:debug] markError failed', e);
113
- }
114
- }
115
- }]);
116
- return ReplayManager;
117
- }();
@@ -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[];