@yysports/tools 3.3.0 → 3.4.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 (64) hide show
  1. package/README.md +1 -3
  2. package/dist/Track/Beacon.d.ts +0 -18
  3. package/dist/Track/Beacon.js +3 -31
  4. package/dist/Track/Config.d.ts +0 -15
  5. package/dist/Track/Config.js +1 -11
  6. package/dist/Track/Device.d.ts +0 -8
  7. package/dist/Track/Device.js +4 -38
  8. package/dist/Track/Listener.d.ts +0 -11
  9. package/dist/Track/Listener.js +1 -26
  10. package/dist/Track/Log.d.ts +0 -23
  11. package/dist/Track/Log.js +18 -60
  12. package/dist/Track/System.d.ts +0 -1
  13. package/dist/Track/System.js +2 -3
  14. package/dist/Track/User.js +1 -1
  15. package/dist/Track/envelope.d.ts +0 -18
  16. package/dist/Track/envelope.js +0 -26
  17. package/dist/Track/index.js +1 -17
  18. package/dist/Utils/auth.d.ts +0 -7
  19. package/dist/Utils/auth.js +6 -17
  20. package/dist/Utils/common.d.ts +0 -16
  21. package/dist/Utils/common.js +0 -20
  22. package/dist/Utils/file.d.ts +0 -10
  23. package/dist/Utils/file.js +0 -14
  24. package/dist/Utils/route.d.ts +0 -6
  25. package/dist/Utils/route.js +0 -19
  26. package/dist/interfaces/protocol.d.ts +0 -67
  27. package/dist/interfaces/protocol.js +1 -64
  28. package/dist/interfaces/track.interface.js +1 -9
  29. package/lib/Track/Beacon.d.ts +0 -18
  30. package/lib/Track/Beacon.js +36 -79
  31. package/lib/Track/Config.d.ts +0 -15
  32. package/lib/Track/Config.js +20 -51
  33. package/lib/Track/Device.d.ts +0 -8
  34. package/lib/Track/Device.js +26 -51
  35. package/lib/Track/Listener.d.ts +0 -11
  36. package/lib/Track/Listener.js +31 -73
  37. package/lib/Track/Log.d.ts +0 -23
  38. package/lib/Track/Log.js +50 -114
  39. package/lib/Track/System.d.ts +0 -1
  40. package/lib/Track/System.js +13 -31
  41. package/lib/Track/User.js +12 -30
  42. package/lib/Track/envelope.d.ts +0 -18
  43. package/lib/Track/envelope.js +38 -82
  44. package/lib/Track/index.js +31 -65
  45. package/lib/Utils/auth.d.ts +0 -7
  46. package/lib/Utils/auth.js +24 -53
  47. package/lib/Utils/common.d.ts +0 -16
  48. package/lib/Utils/common.js +15 -40
  49. package/lib/Utils/file.d.ts +0 -10
  50. package/lib/Utils/file.js +21 -42
  51. package/lib/Utils/index.js +69 -31
  52. package/lib/Utils/route.d.ts +0 -6
  53. package/lib/Utils/route.js +25 -43
  54. package/lib/Utils/url.js +8 -29
  55. package/lib/Utils/wx.js +18 -35
  56. package/lib/index.js +41 -43
  57. package/lib/interfaces/protocol.d.ts +0 -67
  58. package/lib/interfaces/protocol.js +14 -56
  59. package/lib/interfaces/track.interface.js +15 -28
  60. package/package.json +3 -6
  61. package/dist/Track/Replay.d.ts +0 -93
  62. package/dist/Track/Replay.js +0 -447
  63. package/lib/Track/Replay.d.ts +0 -93
  64. package/lib/Track/Replay.js +0 -330
package/lib/Track/Log.js CHANGED
@@ -1,159 +1,95 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
28
2
 
29
- // src/Track/Log.ts
30
- var Log_exports = {};
31
- __export(Log_exports, {
32
- default: () => Log
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
33
6
  });
34
- module.exports = __toCommonJS(Log_exports);
35
- var import_protocol = require("../interfaces/protocol");
36
- var import_Beacon = __toESM(require("./Beacon"));
37
- var import_Config = __toESM(require("./Config"));
38
- var import_envelope = require("./envelope");
39
- var import_Replay = __toESM(require("./Replay"));
40
- var Log = class {
41
- // 获取当前模块名称
7
+ exports.default = void 0;
8
+ var _protocol = require("../interfaces/protocol");
9
+ var _Beacon = _interopRequireDefault(require("./Beacon"));
10
+ var _Config = _interopRequireDefault(require("./Config"));
11
+ var _envelope = require("./envelope");
12
+ class Log {
13
+ static _module = '';
42
14
  static get module() {
43
15
  return this._module;
44
16
  }
45
- /**
46
- * 条级业务内容超列宽时丢弃该条。
47
- *
48
- * `content` 是接入方传入的业务内容:截断会改变语义、把「数据丢失」伪装成「数据完整」,
49
- * 故选择丢弃 + `console.warn`——联调期即可暴露,且不会让同批其他条一起被 400 拒掉。
50
- */
51
17
  static isContentOverlong(content) {
52
- if (typeof content !== "string" || content.length <= import_protocol.TRACK_LIMITS.content) {
18
+ if (typeof content !== 'string' || content.length <= _protocol.TRACK_LIMITS.content) {
53
19
  return false;
54
20
  }
55
- console.warn(
56
- `[Track] content 长度 ${content.length} 超过上限 ${import_protocol.TRACK_LIMITS.content}(服务端会整批 400),已丢弃该条日志`
57
- );
21
+ console.warn(`[Track] content 长度 ${content.length} 超过上限 ${_protocol.TRACK_LIMITS.content}(服务端会整批 400),已丢弃该条日志`);
58
22
  return true;
59
23
  }
60
- /**
61
- * 页面上报。
62
- *
63
- * `module` 为空属调用误用(如路由工具返回 `undefined`):`_module` 会被后续事件复用,
64
- * 记成空串会让之后所有事件的归属一起变空,故丢弃并告警,与 `errorLog` 处理一致。
65
- */
66
- static visitLog(module2) {
67
- if (typeof module2 !== "string" || !module2) {
68
- console.warn(
69
- "[Track] visitLog 的 module 为空(服务端 module 为可选项,空值会让后续事件失去归属),已丢弃该条"
70
- );
24
+ static visitLog(module) {
25
+ if (typeof module !== 'string' || !module) {
26
+ console.warn('[Track] visitLog 的 module 为空(服务端 module 为可选项,空值会让后续事件失去归属),已丢弃该条');
71
27
  return;
72
28
  }
73
- this._module = (0, import_envelope.truncate)(module2, import_protocol.TRACK_LIMITS.module);
74
- const lastModule = module2.split("-").pop() ?? "";
75
- import_Beacon.default.push({
76
- ...(0, import_envelope.buildEventBase)(),
77
- type: "visit",
29
+ this._module = (0, _envelope.truncate)(module, _protocol.TRACK_LIMITS.module);
30
+ const lastModule = module.split('-').pop() ?? '';
31
+ _Beacon.default.push({
32
+ ...(0, _envelope.buildEventBase)(),
33
+ type: 'visit',
78
34
  module: this._module,
79
- // content 列宽 255 且自带 5 字前缀,必须整体截断,否则超限会让同批其他日志一并 400
80
- content: (0, import_envelope.truncate)(`访问页面:${lastModule}`, import_protocol.TRACK_LIMITS.content)
35
+ content: (0, _envelope.truncate)(`访问页面:${lastModule}`, _protocol.TRACK_LIMITS.content)
81
36
  });
82
37
  }
83
38
  static eventLog(content) {
84
- if (typeof content !== "string") {
85
- console.warn(
86
- "[Track] eventLog 的 content 不是字符串(服务端会整批 400),已丢弃该条日志"
87
- );
39
+ if (typeof content !== 'string') {
40
+ console.warn('[Track] eventLog 的 content 不是字符串(服务端会整批 400),已丢弃该条日志');
88
41
  return;
89
42
  }
90
- if (this.isContentOverlong(content))
91
- return;
92
- import_Beacon.default.push({
93
- ...(0, import_envelope.buildEventBase)(),
94
- type: "event",
43
+ if (this.isContentOverlong(content)) return;
44
+ _Beacon.default.push({
45
+ ...(0, _envelope.buildEventBase)(),
46
+ type: 'event',
95
47
  module: this._module,
96
48
  content
97
49
  });
98
50
  }
99
51
  static apiLog(log) {
100
- import_Beacon.default.push({
101
- ...(0, import_envelope.buildEventBase)(),
102
- type: "api",
52
+ _Beacon.default.push({
53
+ ...(0, _envelope.buildEventBase)(),
54
+ type: 'api',
103
55
  module: this._module,
104
56
  log
105
57
  });
106
58
  }
107
- /**
108
- * 错误 + 回放一次请求内嵌上报(通道 2)。
109
- * fetch 失败或页面卸载导致未送达时,用 sendBeacon 补发不含回放的纯错误:
110
- * 卸载场景 fetch 不可靠,至少保住错误本体,回放可接受丢失。
111
- */
112
59
  static async errorLog(message, stack) {
113
- var _a;
114
- if (!import_Config.default.data.appId) {
115
- console.warn(
116
- "[Track] 尚未调用 Track.init(appId 为空),该条错误上报已丢弃"
117
- );
60
+ if (!_Config.default.data.appId) {
61
+ console.warn('[Track] 尚未调用 Track.init(appId 为空),该条错误上报已丢弃');
118
62
  return;
119
63
  }
120
- if (typeof message !== "string" || !message.trim()) {
121
- console.warn(
122
- "[Track] errorLog 的 message 为空(服务端会整条 400),已丢弃该条错误上报"
123
- );
64
+ if (typeof message !== 'string' || !message.trim()) {
65
+ console.warn('[Track] errorLog 的 message 为空(服务端会整条 400),已丢弃该条错误上报');
124
66
  return;
125
67
  }
126
- const replay = import_Replay.default.snapshot();
127
- const pureError = {
128
- ...(0, import_envelope.buildEnvelopeBase)(),
68
+ const payload = {
69
+ ...(0, _envelope.buildEnvelopeBase)(),
129
70
  error: {
130
- ...(0, import_envelope.buildEventBase)(),
71
+ ...(0, _envelope.buildEventBase)(),
131
72
  message,
132
73
  stack,
133
74
  module: this._module
134
75
  }
135
76
  };
136
- const payload = replay.length ? { ...pureError, replay } : pureError;
137
77
  try {
138
- const res = await fetch((0, import_envelope.trackUrl)("/error"), {
139
- method: "POST",
140
- headers: { "Content-Type": import_protocol.TRACK_CONTENT_TYPE },
78
+ const res = await fetch((0, _envelope.trackUrl)('/error'), {
79
+ method: 'POST',
80
+ headers: {
81
+ 'Content-Type': _protocol.TRACK_CONTENT_TYPE
82
+ },
141
83
  body: JSON.stringify(payload)
142
84
  });
143
- if (!res.ok)
144
- throw new Error(`HTTP ${res.status}`);
145
- import_Replay.default.commitSnapshot(replay);
85
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
146
86
  } catch (error) {
147
87
  try {
148
- (_a = navigator == null ? void 0 : navigator.sendBeacon) == null ? void 0 : _a.call(
149
- navigator,
150
- (0, import_envelope.trackUrl)("/error"),
151
- new Blob([JSON.stringify(pureError)], { type: import_protocol.TRACK_CONTENT_TYPE })
152
- );
153
- } catch (beaconError) {
154
- }
88
+ navigator?.sendBeacon?.((0, _envelope.trackUrl)('/error'), new Blob([JSON.stringify(payload)], {
89
+ type: _protocol.TRACK_CONTENT_TYPE
90
+ }));
91
+ } catch (beaconError) {}
155
92
  }
156
93
  }
157
- };
158
- // 当前模块
159
- Log._module = "";
94
+ }
95
+ exports.default = Log;
@@ -1,7 +1,6 @@
1
1
  import { SystemProfile } from '../interfaces/track.interface';
2
2
  export default class System {
3
3
  private static readonly _imei;
4
- /** 会话串,作为信封必填的 imei 上报(生成逻辑不变) */
5
4
  static get imei(): string;
6
5
  static get profile(): SystemProfile;
7
6
  }
@@ -1,41 +1,23 @@
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);
1
+ "use strict";
18
2
 
19
- // src/Track/System.ts
20
- var System_exports = {};
21
- __export(System_exports, {
22
- default: () => System
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
23
5
  });
24
- module.exports = __toCommonJS(System_exports);
25
- var import_Utils = require("../Utils");
26
- var System = class {
27
- /** 会话串,作为信封必填的 imei 上报(生成逻辑不变) */
6
+ exports.default = void 0;
7
+ var _Utils = require("../Utils");
8
+ class System {
9
+ static _imei = (0, _Utils.generateRandomString)(6);
28
10
  static get imei() {
29
11
  return this._imei;
30
12
  }
31
13
  static get profile() {
32
14
  return {
33
15
  imei: this._imei,
34
- innerHeight: typeof window !== "undefined" ? window.innerHeight : 0,
35
- innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
36
- href: typeof location !== "undefined" ? location.href : "",
37
- systemTime: /* @__PURE__ */ new Date()
16
+ innerHeight: typeof window !== 'undefined' ? window.innerHeight : 0,
17
+ innerWidth: typeof window !== 'undefined' ? window.innerWidth : 0,
18
+ href: typeof location !== 'undefined' ? location.href : '',
19
+ systemTime: new Date()
38
20
  };
39
21
  }
40
- };
41
- System._imei = (0, import_Utils.generateRandomString)(6);
22
+ }
23
+ exports.default = System;
package/lib/Track/User.js CHANGED
@@ -1,40 +1,22 @@
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);
1
+ "use strict";
18
2
 
19
- // src/Track/User.ts
20
- var User_exports = {};
21
- __export(User_exports, {
22
- default: () => User
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
23
5
  });
24
- module.exports = __toCommonJS(User_exports);
25
- var User = class {
6
+ exports.default = void 0;
7
+ class User {
8
+ static _profile = null;
26
9
  static setUserProfile(profile) {
27
- var _a, _b;
28
- if (!((_a = profile.userId) == null ? void 0 : _a.trim())) {
29
- throw new Error("UserProfile: userId is required");
10
+ if (!profile.userId?.trim()) {
11
+ throw new Error('UserProfile: userId is required');
30
12
  }
31
- if (!((_b = profile.userName) == null ? void 0 : _b.trim())) {
32
- throw new Error("UserProfile: userName is required");
13
+ if (!profile.userName?.trim()) {
14
+ throw new Error('UserProfile: userName is required');
33
15
  }
34
16
  this._profile = profile;
35
17
  }
36
18
  static get profile() {
37
19
  return this._profile;
38
20
  }
39
- };
40
- User._profile = null;
21
+ }
22
+ exports.default = User;
@@ -1,24 +1,6 @@
1
1
  import { type TrackV3Envelope, type TrackV3Event } from '../interfaces/protocol';
2
- /**
3
- * 按列宽截断。
4
- *
5
- * 只用于「接入方拿不到也改不了」的字段:请求级信封字段(`imei` / `sdkVersion` /
6
- * `appVersion` / `user.*`)、逐条自动采集的 `href`、以及会话级缓存的 `module`。
7
- * 这些值一旦超列宽,服务端会因 `@MaxLength` 直接 400(整批 / 整请求被拒),
8
- * 丢弃等于让该应用或该页面的上报整体消失;截断至少保住定位信息。
9
- *
10
- * 反之,接入方自己传的业务内容(`content`)超限时**丢弃该条**而不是截断,
11
- * 见 `Log.isContentOverlong`——截断会把「数据丢失」伪装成「数据完整」。
12
- */
13
2
  export declare function truncate(value: string, limit: number): string;
14
3
  export declare function truncate(value: string | undefined, limit: number): string | undefined;
15
- /** 请求级公共段(信封):字段与实体属性同名(camelCase),每次请求仅一份 */
16
4
  export declare function buildEnvelopeBase(): TrackV3Envelope;
17
- /** 条级事件公共字段:href / 视口 / 毫秒时间戳在批量窗口内会变,逐条携带 */
18
5
  export declare function buildEventBase(): Pick<TrackV3Event, 'systemTime' | 'href' | 'innerWidth' | 'innerHeight'>;
19
- /**
20
- * V3 上报地址:鉴权**仅 appId**,走 URL query(sendBeacon 无法自定义 header)。
21
- * 刻意不实现 `ts` / `nonce` / `sign`:探针运行在公开前端页面,密钥无法保密,签名不构成防线;
22
- * 准入由服务端 TrackAuthGuard(appId 在册 + 停收开关 + 限流)负责。
23
- */
24
6
  export declare function trackUrl(path: '/batch' | '/error'): string;
@@ -1,100 +1,56 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
28
2
 
29
- // src/Track/envelope.ts
30
- var envelope_exports = {};
31
- __export(envelope_exports, {
32
- buildEnvelopeBase: () => buildEnvelopeBase,
33
- buildEventBase: () => buildEventBase,
34
- trackUrl: () => trackUrl,
35
- truncate: () => truncate
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
36
6
  });
37
- module.exports = __toCommonJS(envelope_exports);
38
- var import_package = __toESM(require("../../package.json"));
39
- var import_protocol = require("../interfaces/protocol");
40
- var import_Config = __toESM(require("./Config"));
41
- var import_Device = __toESM(require("./Device"));
42
- var import_System = __toESM(require("./System"));
43
- var import_User = __toESM(require("./User"));
7
+ exports.buildEnvelopeBase = buildEnvelopeBase;
8
+ exports.buildEventBase = buildEventBase;
9
+ exports.trackUrl = trackUrl;
10
+ exports.truncate = truncate;
11
+ var _package = _interopRequireDefault(require("../../package.json"));
12
+ var _protocol = require("../interfaces/protocol");
13
+ var _Config = _interopRequireDefault(require("./Config"));
14
+ var _Device = _interopRequireDefault(require("./Device"));
15
+ var _System = _interopRequireDefault(require("./System"));
16
+ var _User = _interopRequireDefault(require("./User"));
44
17
  function truncate(value, limit) {
45
- if (value === null || value === void 0)
46
- return void 0;
18
+ if (value === null || value === undefined) return undefined;
47
19
  return value.length > limit ? value.slice(0, limit) : value;
48
20
  }
49
21
  function buildEnvelopeBase() {
50
- const profile = import_User.default.profile;
51
- const device = import_Device.default.data;
22
+ const profile = _User.default.profile;
23
+ const device = _Device.default.data;
52
24
  return {
53
- appId: import_Config.default.data.appId,
54
- sdkVersion: truncate(import_package.default.version, import_protocol.TRACK_LIMITS.sdkVersion),
55
- // 调用方应用版本:未配置时为 undefined,JSON.stringify 会丢弃该键(服务端落 NULL)
56
- appVersion: truncate(import_Config.default.data.appVersion, import_protocol.TRACK_LIMITS.appVersion),
57
- imei: truncate(import_System.default.imei, import_protocol.TRACK_LIMITS.imei),
58
- // 只输出有值的段:空对象是纯噪音,服务端也按「无该段」处理
59
- ...Object.keys(device).length ? { device } : {},
60
- ...profile ? {
25
+ appId: _Config.default.data.appId,
26
+ sdkVersion: truncate(_package.default.version, _protocol.TRACK_LIMITS.sdkVersion),
27
+ appVersion: truncate(_Config.default.data.appVersion, _protocol.TRACK_LIMITS.appVersion),
28
+ imei: truncate(_System.default.imei, _protocol.TRACK_LIMITS.imei),
29
+ ...(Object.keys(device).length ? {
30
+ device
31
+ } : {}),
32
+ ...(profile ? {
61
33
  user: {
62
- userId: truncate(profile.userId, import_protocol.TRACK_LIMITS.userField),
63
- userName: truncate(profile.userName, import_protocol.TRACK_LIMITS.userField),
64
- orgCode: truncate(profile.orgCode, import_protocol.TRACK_LIMITS.userField),
65
- orgTitle: truncate(profile.orgTitle, import_protocol.TRACK_LIMITS.userField),
66
- dataScopeZonePermissions: truncate(
67
- profile.dataScopeZonePermissions,
68
- import_protocol.TRACK_LIMITS.userField
69
- ),
70
- dataScopeRoles: truncate(
71
- profile.dataScopeRoles,
72
- import_protocol.TRACK_LIMITS.userField
73
- )
34
+ userId: truncate(profile.userId, _protocol.TRACK_LIMITS.userField),
35
+ userName: truncate(profile.userName, _protocol.TRACK_LIMITS.userField),
36
+ orgCode: truncate(profile.orgCode, _protocol.TRACK_LIMITS.userField),
37
+ orgTitle: truncate(profile.orgTitle, _protocol.TRACK_LIMITS.userField),
38
+ dataScopeZonePermissions: truncate(profile.dataScopeZonePermissions, _protocol.TRACK_LIMITS.userField),
39
+ dataScopeRoles: truncate(profile.dataScopeRoles, _protocol.TRACK_LIMITS.userField)
74
40
  }
75
- } : {}
41
+ } : {})
76
42
  };
77
43
  }
78
44
  function buildEventBase() {
79
45
  return {
80
46
  systemTime: Date.now(),
81
- href: truncate(
82
- typeof location !== "undefined" ? location.href : "",
83
- import_protocol.TRACK_LIMITS.href
84
- ),
85
- innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
86
- innerHeight: typeof window !== "undefined" ? window.innerHeight : 0
47
+ href: truncate(typeof location !== 'undefined' ? location.href : '', _protocol.TRACK_LIMITS.href),
48
+ innerWidth: typeof window !== 'undefined' ? window.innerWidth : 0,
49
+ innerHeight: typeof window !== 'undefined' ? window.innerHeight : 0
87
50
  };
88
51
  }
89
52
  function trackUrl(path) {
90
- const appId = encodeURIComponent(import_Config.default.data.appId);
91
- const domain = import_Config.default.data.domain.replace(/\/+$/, "");
53
+ const appId = encodeURIComponent(_Config.default.data.appId);
54
+ const domain = _Config.default.data.domain.replace(/\/+$/, '');
92
55
  return `${domain}/pousheng-guard/api/track/v3${path}?appId=${appId}`;
93
- }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- buildEnvelopeBase,
97
- buildEventBase,
98
- trackUrl,
99
- truncate
100
- });
56
+ }
@@ -1,83 +1,49 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
28
2
 
29
- // src/Track/index.ts
30
- var Track_exports = {};
31
- __export(Track_exports, {
32
- default: () => Track
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
33
6
  });
34
- module.exports = __toCommonJS(Track_exports);
35
- var import_Beacon = __toESM(require("./Beacon"));
36
- var import_Config = __toESM(require("./Config"));
37
- var import_Device = __toESM(require("./Device"));
38
- var import_Listener = __toESM(require("./Listener"));
39
- var import_Log = __toESM(require("./Log"));
40
- var import_Replay = __toESM(require("./Replay"));
41
- var import_System = __toESM(require("./System"));
42
- var import_User = __toESM(require("./User"));
43
- var Track = class {
7
+ exports.default = void 0;
8
+ var _Beacon = _interopRequireDefault(require("./Beacon"));
9
+ var _Config = _interopRequireDefault(require("./Config"));
10
+ var _Device = _interopRequireDefault(require("./Device"));
11
+ var _Listener = _interopRequireDefault(require("./Listener"));
12
+ var _Log = _interopRequireDefault(require("./Log"));
13
+ var _System = _interopRequireDefault(require("./System"));
14
+ var _User = _interopRequireDefault(require("./User"));
15
+ class Track {
44
16
  static init(cfg) {
45
- import_Config.default.validate(cfg);
17
+ _Config.default.validate(cfg);
46
18
  this.run();
47
19
  }
48
20
  static setUserProfile(profile) {
49
- import_User.default.setUserProfile(profile);
21
+ _User.default.setUserProfile(profile);
50
22
  }
51
23
  static get config() {
52
- return import_Config.default.data;
24
+ return _Config.default.data;
53
25
  }
54
26
  static get userProfile() {
55
- return import_User.default.profile;
27
+ return _User.default.profile;
56
28
  }
57
29
  static get systemProfile() {
58
- return import_System.default.profile;
30
+ return _System.default.profile;
59
31
  }
60
- // 需要初始化执行的组件都需在这里初始化调用
61
32
  static run() {
62
- import_Device.default.init();
63
- if (import_Config.default.data.autoReportError) {
64
- import_Listener.default.run();
65
- } else {
66
- import_Listener.default.stop();
67
- }
68
- if (import_Config.default.data.enableReplay) {
69
- void import_Replay.default.run();
33
+ _Device.default.init();
34
+ if (_Config.default.data.autoReportError) {
35
+ _Listener.default.run();
70
36
  } else {
71
- import_Replay.default.stop();
37
+ _Listener.default.stop();
72
38
  }
73
- import_Beacon.default.start();
39
+ _Beacon.default.start();
74
40
  }
75
- // 获取当前页面模块名称
76
41
  static get module() {
77
- return import_Log.default.module;
78
- }
79
- };
80
- Track.visitLog = import_Log.default.visitLog.bind(import_Log.default);
81
- Track.eventLog = import_Log.default.eventLog.bind(import_Log.default);
82
- Track.errorLog = import_Log.default.errorLog.bind(import_Log.default);
83
- Track.apiLog = import_Log.default.apiLog.bind(import_Log.default);
42
+ return _Log.default.module;
43
+ }
44
+ static visitLog = _Log.default.visitLog.bind(_Log.default);
45
+ static eventLog = _Log.default.eventLog.bind(_Log.default);
46
+ static errorLog = _Log.default.errorLog.bind(_Log.default);
47
+ static apiLog = _Log.default.apiLog.bind(_Log.default);
48
+ }
49
+ exports.default = Track;
@@ -1,9 +1,2 @@
1
1
  import { AuthCenterUserProfile } from '../interfaces/track.interface';
2
- /**
3
- * 获取当前用户在权限中心的信息,并格式化前端路由所需的数据格式
4
- * @param fetchUserInfo
5
- * @param fetchMenuBuild
6
- * @param fetchZoneScope
7
- * @returns {Promise<AuthCenterUserProfile>}
8
- */
9
2
  export declare const fetchCurrentUserFromAuthCenter: (fetchUserInfo: () => Promise<any>, fetchMenuBuild: () => Promise<any>, fetchZoneScope?: () => Promise<any>) => Promise<AuthCenterUserProfile>;