@yysports/tools 3.0.4 → 3.1.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/README.md +2 -0
- package/dist/Track/Beacon.d.ts +12 -8
- package/dist/Track/Beacon.js +37 -29
- package/dist/Track/Config.d.ts +5 -1
- package/dist/Track/Config.js +25 -3
- package/dist/Track/Listener.d.ts +13 -0
- package/dist/Track/Listener.js +57 -25
- package/dist/Track/Log.d.ts +14 -1
- package/dist/Track/Log.js +55 -17
- package/dist/Track/Replay.d.ts +27 -2
- package/dist/Track/Replay.js +127 -22
- package/dist/Track/envelope.d.ts +19 -2
- package/dist/Track/envelope.js +36 -12
- package/dist/Track/index.js +14 -3
- package/dist/Utils/index.d.ts +2 -2
- package/dist/Utils/index.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/interfaces/protocol.d.ts +1 -1
- package/dist/interfaces/protocol.js +1 -1
- package/dist/interfaces/track.interface.d.ts +1 -1
- package/dist/interfaces/track.interface.js +1 -1
- package/lib/Track/Beacon.d.ts +12 -8
- package/lib/Track/Beacon.js +31 -24
- package/lib/Track/Config.d.ts +5 -1
- package/lib/Track/Config.js +26 -4
- package/lib/Track/Listener.d.ts +13 -0
- package/lib/Track/Listener.js +44 -20
- package/lib/Track/Log.d.ts +14 -1
- package/lib/Track/Log.js +40 -4
- package/lib/Track/Replay.d.ts +27 -2
- package/lib/Track/Replay.js +75 -11
- package/lib/Track/envelope.d.ts +19 -2
- package/lib/Track/envelope.js +31 -13
- package/lib/Track/index.js +10 -2
- package/lib/Utils/index.d.ts +2 -2
- package/lib/Utils/index.js +5 -5
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/interfaces/protocol.d.ts +1 -1
- package/lib/interfaces/protocol.js +1 -1
- package/lib/interfaces/track.interface.d.ts +1 -1
- package/package.json +23 -26
package/lib/Track/Listener.js
CHANGED
|
@@ -35,32 +35,56 @@ module.exports = __toCommonJS(Listener_exports);
|
|
|
35
35
|
var import_Beacon = __toESM(require("./Beacon"));
|
|
36
36
|
var import_Config = __toESM(require("./Config"));
|
|
37
37
|
var import_Log = __toESM(require("./Log"));
|
|
38
|
-
|
|
38
|
+
function resolveErrorMessage(event) {
|
|
39
|
+
var _a;
|
|
40
|
+
const message = (_a = event.message) == null ? void 0 : _a.trim();
|
|
41
|
+
if (message)
|
|
42
|
+
return message;
|
|
43
|
+
const target = event.target;
|
|
44
|
+
const failedUrl = (target == null ? void 0 : target.src) ?? (target == null ? void 0 : target.href);
|
|
45
|
+
return failedUrl ? `资源加载失败:${failedUrl}` : "";
|
|
46
|
+
}
|
|
47
|
+
var _Listener = class {
|
|
39
48
|
static run() {
|
|
40
49
|
if (this._loaded || !import_Config.default.data.autoReportError) {
|
|
41
50
|
return;
|
|
42
51
|
}
|
|
43
|
-
window.addEventListener("error",
|
|
44
|
-
if (this._reporter) {
|
|
45
|
-
clearTimeout(this._reporter);
|
|
46
|
-
}
|
|
47
|
-
this._reporter = setTimeout(() => {
|
|
48
|
-
var _a;
|
|
49
|
-
import_Beacon.default.flush();
|
|
50
|
-
import_Log.default.errorLog(event.message, (_a = event.error) == null ? void 0 : _a.stack);
|
|
51
|
-
this._reporter = null;
|
|
52
|
-
}, 1e3);
|
|
53
|
-
});
|
|
54
|
-
document.addEventListener("visibilitychange", () => {
|
|
55
|
-
if ((document == null ? void 0 : document.visibilityState) === "hidden") {
|
|
56
|
-
import_Beacon.default.flush();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
window.addEventListener("pagehide", () => {
|
|
60
|
-
import_Beacon.default.flush();
|
|
61
|
-
});
|
|
52
|
+
window.addEventListener("error", this._onError, true);
|
|
62
53
|
this._loaded = true;
|
|
63
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* 停止自动上报,供 `init({ autoReportError: false })` 热关闭。
|
|
57
|
+
*
|
|
58
|
+
* 必须复位 `_loaded`:否则再次 `init({ autoReportError: true })` 时 `run()`
|
|
59
|
+
* 直接命中幂等判断返回,监听再也装不回来。挂起的防抖定时器同样要清掉,
|
|
60
|
+
* 否则关闭后仍会补报一条。
|
|
61
|
+
*/
|
|
62
|
+
static stop() {
|
|
63
|
+
if (!this._loaded)
|
|
64
|
+
return;
|
|
65
|
+
window.removeEventListener("error", this._onError, true);
|
|
66
|
+
if (this._reporter) {
|
|
67
|
+
clearTimeout(this._reporter);
|
|
68
|
+
this._reporter = null;
|
|
69
|
+
}
|
|
70
|
+
this._loaded = false;
|
|
71
|
+
}
|
|
64
72
|
};
|
|
73
|
+
var Listener = _Listener;
|
|
65
74
|
Listener._loaded = false;
|
|
66
75
|
Listener._reporter = null;
|
|
76
|
+
/**
|
|
77
|
+
* 具名 handler:`removeEventListener` 必须拿到与注册时相同的函数引用,
|
|
78
|
+
* 匿名函数会让 `stop()` 失效(`autoReportError` 从 true 改 false 后仍在采集)。
|
|
79
|
+
*/
|
|
80
|
+
Listener._onError = (event) => {
|
|
81
|
+
if (_Listener._reporter) {
|
|
82
|
+
clearTimeout(_Listener._reporter);
|
|
83
|
+
}
|
|
84
|
+
_Listener._reporter = setTimeout(() => {
|
|
85
|
+
var _a;
|
|
86
|
+
import_Beacon.default.flush();
|
|
87
|
+
import_Log.default.errorLog(resolveErrorMessage(event), (_a = event.error) == null ? void 0 : _a.stack);
|
|
88
|
+
_Listener._reporter = null;
|
|
89
|
+
}, 1e3);
|
|
90
|
+
};
|
package/lib/Track/Log.d.ts
CHANGED
|
@@ -7,7 +7,20 @@
|
|
|
7
7
|
export default class Log {
|
|
8
8
|
private static _module;
|
|
9
9
|
static get module(): string;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 条级业务内容超列宽时丢弃该条。
|
|
12
|
+
*
|
|
13
|
+
* `content` 是接入方传入的业务内容:截断会改变语义、把「数据丢失」伪装成「数据完整」,
|
|
14
|
+
* 故选择丢弃 + `console.warn`——联调期即可暴露,且不会让同批其他条一起被 400 拒掉。
|
|
15
|
+
*/
|
|
16
|
+
private static isContentOverlong;
|
|
17
|
+
/**
|
|
18
|
+
* 页面上报。
|
|
19
|
+
*
|
|
20
|
+
* `module` 为空属调用误用(如路由工具返回 `undefined`):`_module` 会被后续事件复用,
|
|
21
|
+
* 记成空串会让之后所有事件的归属一起变空,故丢弃并告警,与 `errorLog` 处理一致。
|
|
22
|
+
*/
|
|
23
|
+
static visitLog(module?: string): void;
|
|
11
24
|
static eventLog(content: string): void;
|
|
12
25
|
static apiLog(log: string): void;
|
|
13
26
|
/**
|
package/lib/Track/Log.js
CHANGED
|
@@ -41,17 +41,47 @@ var Log = class {
|
|
|
41
41
|
static get module() {
|
|
42
42
|
return this._module;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* 条级业务内容超列宽时丢弃该条。
|
|
46
|
+
*
|
|
47
|
+
* `content` 是接入方传入的业务内容:截断会改变语义、把「数据丢失」伪装成「数据完整」,
|
|
48
|
+
* 故选择丢弃 + `console.warn`——联调期即可暴露,且不会让同批其他条一起被 400 拒掉。
|
|
49
|
+
*/
|
|
50
|
+
static isContentOverlong(content) {
|
|
51
|
+
if (typeof content !== "string" || content.length <= import_protocol.TRACK_LIMITS.content) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
console.warn(
|
|
55
|
+
`[Track] content 长度 ${content.length} 超过上限 ${import_protocol.TRACK_LIMITS.content}(服务端会整批 400),已丢弃该条日志`
|
|
56
|
+
);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 页面上报。
|
|
61
|
+
*
|
|
62
|
+
* `module` 为空属调用误用(如路由工具返回 `undefined`):`_module` 会被后续事件复用,
|
|
63
|
+
* 记成空串会让之后所有事件的归属一起变空,故丢弃并告警,与 `errorLog` 处理一致。
|
|
64
|
+
*/
|
|
44
65
|
static visitLog(module2) {
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
if (typeof module2 !== "string" || !module2) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[Track] visitLog 的 module 为空(服务端 module 为可选项,空值会让后续事件失去归属),已丢弃该条"
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._module = (0, import_envelope.truncate)(module2, import_protocol.TRACK_LIMITS.module);
|
|
73
|
+
const lastModule = module2.split("-").pop() ?? "";
|
|
47
74
|
import_Beacon.default.push({
|
|
48
75
|
...(0, import_envelope.buildEventBase)(),
|
|
49
76
|
type: "visit",
|
|
50
|
-
module:
|
|
51
|
-
content
|
|
77
|
+
module: this._module,
|
|
78
|
+
// content 列宽 255 且自带 5 字前缀,必须整体截断,否则超限会让同批其他日志一并 400
|
|
79
|
+
content: (0, import_envelope.truncate)(`访问页面:${lastModule}`, import_protocol.TRACK_LIMITS.content)
|
|
52
80
|
});
|
|
53
81
|
}
|
|
54
82
|
static eventLog(content) {
|
|
83
|
+
if (this.isContentOverlong(content))
|
|
84
|
+
return;
|
|
55
85
|
import_Beacon.default.push({
|
|
56
86
|
...(0, import_envelope.buildEventBase)(),
|
|
57
87
|
type: "event",
|
|
@@ -74,6 +104,12 @@ var Log = class {
|
|
|
74
104
|
*/
|
|
75
105
|
static async errorLog(message, stack) {
|
|
76
106
|
var _a;
|
|
107
|
+
if (typeof message !== "string" || !message.trim()) {
|
|
108
|
+
console.warn(
|
|
109
|
+
"[Track] errorLog 的 message 为空(服务端会整条 400),已丢弃该条错误上报"
|
|
110
|
+
);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
77
113
|
const replay = import_Replay.default.snapshot();
|
|
78
114
|
const pureError = {
|
|
79
115
|
...(0, import_envelope.buildEnvelopeBase)(),
|
package/lib/Track/Replay.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ type RRWebEvent = any;
|
|
|
2
2
|
export default class Replay {
|
|
3
3
|
private static _events;
|
|
4
4
|
private static _stop;
|
|
5
|
+
private static _record;
|
|
5
6
|
private static _loading;
|
|
7
|
+
private static _stopRequested;
|
|
6
8
|
private static _bytes;
|
|
7
9
|
/**
|
|
8
10
|
* 启动录制。
|
|
@@ -13,11 +15,34 @@ export default class Replay {
|
|
|
13
15
|
* 错误本体的上报不受影响)。
|
|
14
16
|
*/
|
|
15
17
|
static run(): Promise<void>;
|
|
16
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* 停止录制并清空缓存。
|
|
20
|
+
*
|
|
21
|
+
* `Replay.run` 的幂等只看 `_stop`,`init({ enableReplay: false })` 不会让已启动的录制停下,
|
|
22
|
+
* 因此 `Track.run` 在关闭回放时显式调用本方法。
|
|
23
|
+
*/
|
|
24
|
+
static stop(): void;
|
|
25
|
+
/**
|
|
26
|
+
* 截断到体积上限:整体重开一段,并请求一张新的完整快照。
|
|
27
|
+
*
|
|
28
|
+
* 片段必须自带播放起点(在缓冲区头部),丢掉起点整段就无法播放,而起点之后的事件
|
|
29
|
+
* 全是增量、丢了画面又不完整,所以这里不做「从头丢事件」,直接重开一段。
|
|
30
|
+
*/
|
|
17
31
|
private static truncate;
|
|
32
|
+
/** 缓冲区头部的起点事件(Meta / FullSnapshot);无起点时返回空数组 */
|
|
33
|
+
private static replayStartEvents;
|
|
34
|
+
/** 请求 rrweb 立刻产出一张 FullSnapshot(失败静默,仅影响回放可用性) */
|
|
35
|
+
private static requestFullSnapshot;
|
|
36
|
+
/** 事件数组的近似序列化体积(与 emit 中的累计口径一致) */
|
|
37
|
+
private static bytesOf;
|
|
18
38
|
/** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
|
|
19
39
|
static snapshot(): RRWebEvent[];
|
|
20
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* 上报成功后移除已携带的事件,继续录制——不调用 stop,避免下一个错误重复携带上一段。
|
|
42
|
+
*
|
|
43
|
+
* 起点事件(Meta / FullSnapshot)保留在缓冲区:随本次上报一起移除后,下一段回放
|
|
44
|
+
* 只剩增量事件、播放器无法独立渲染。
|
|
45
|
+
*/
|
|
21
46
|
static commitSnapshot(snapshot: RRWebEvent[]): void;
|
|
22
47
|
}
|
|
23
48
|
export {};
|
package/lib/Track/Replay.js
CHANGED
|
@@ -33,7 +33,10 @@ __export(Replay_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(Replay_exports);
|
|
35
35
|
var import_Config = __toESM(require("./Config"));
|
|
36
|
-
var
|
|
36
|
+
var RRWEB_META = 4;
|
|
37
|
+
var RRWEB_FULL_SNAPSHOT = 2;
|
|
38
|
+
var isReplayStartEvent = (event) => (event == null ? void 0 : event.type) === RRWEB_META || (event == null ? void 0 : event.type) === RRWEB_FULL_SNAPSHOT;
|
|
39
|
+
var _Replay = class {
|
|
37
40
|
/**
|
|
38
41
|
* 启动录制。
|
|
39
42
|
*
|
|
@@ -43,7 +46,11 @@ var Replay = class {
|
|
|
43
46
|
* 错误本体的上报不受影响)。
|
|
44
47
|
*/
|
|
45
48
|
static async run() {
|
|
46
|
-
if (
|
|
49
|
+
if (!import_Config.default.data.enableReplay) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this._stopRequested = false;
|
|
53
|
+
if (this._stop || this._loading) {
|
|
47
54
|
return;
|
|
48
55
|
}
|
|
49
56
|
this._loading = true;
|
|
@@ -52,6 +59,10 @@ var Replay = class {
|
|
|
52
59
|
import("@rrweb/record"),
|
|
53
60
|
import("@rrweb/rrweb-plugin-console-record")
|
|
54
61
|
]);
|
|
62
|
+
if (this._stopRequested || !import_Config.default.data.enableReplay) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this._record = startRecord;
|
|
55
66
|
this._stop = startRecord({
|
|
56
67
|
emit: (e) => {
|
|
57
68
|
this._events.push(e);
|
|
@@ -70,30 +81,79 @@ var Replay = class {
|
|
|
70
81
|
});
|
|
71
82
|
} catch (err) {
|
|
72
83
|
this._stop = void 0;
|
|
84
|
+
this._record = void 0;
|
|
73
85
|
} finally {
|
|
74
86
|
this._loading = false;
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* 停止录制并清空缓存。
|
|
91
|
+
*
|
|
92
|
+
* `Replay.run` 的幂等只看 `_stop`,`init({ enableReplay: false })` 不会让已启动的录制停下,
|
|
93
|
+
* 因此 `Track.run` 在关闭回放时显式调用本方法。
|
|
94
|
+
*/
|
|
95
|
+
static stop() {
|
|
96
|
+
this._stopRequested = true;
|
|
97
|
+
if (this._stop) {
|
|
98
|
+
this._stop();
|
|
99
|
+
}
|
|
100
|
+
this._stop = void 0;
|
|
101
|
+
this._record = void 0;
|
|
102
|
+
this._events = [];
|
|
103
|
+
this._bytes = 0;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 截断到体积上限:整体重开一段,并请求一张新的完整快照。
|
|
107
|
+
*
|
|
108
|
+
* 片段必须自带播放起点(在缓冲区头部),丢掉起点整段就无法播放,而起点之后的事件
|
|
109
|
+
* 全是增量、丢了画面又不完整,所以这里不做「从头丢事件」,直接重开一段。
|
|
110
|
+
*/
|
|
78
111
|
static truncate() {
|
|
79
112
|
const maxBytes = import_Config.default.data.replayMaxBytes ?? 1024 * 1024;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
113
|
+
if (this._bytes <= maxBytes)
|
|
114
|
+
return;
|
|
115
|
+
const startBytes = _Replay.bytesOf(_Replay.replayStartEvents(this._events));
|
|
116
|
+
if (startBytes > maxBytes)
|
|
117
|
+
return;
|
|
118
|
+
this._events = this._events.filter((e) => (e == null ? void 0 : e.type) === RRWEB_META).slice(0, 1);
|
|
119
|
+
this._bytes = _Replay.bytesOf(this._events);
|
|
120
|
+
_Replay.requestFullSnapshot();
|
|
121
|
+
}
|
|
122
|
+
/** 缓冲区头部的起点事件(Meta / FullSnapshot);无起点时返回空数组 */
|
|
123
|
+
static replayStartEvents(events) {
|
|
124
|
+
return events.slice(0, 2).filter(isReplayStartEvent);
|
|
125
|
+
}
|
|
126
|
+
/** 请求 rrweb 立刻产出一张 FullSnapshot(失败静默,仅影响回放可用性) */
|
|
127
|
+
static requestFullSnapshot() {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
try {
|
|
130
|
+
(_b = (_a = _Replay._record) == null ? void 0 : _a.takeFullSnapshot) == null ? void 0 : _b.call(_a, true);
|
|
131
|
+
} catch (err) {
|
|
83
132
|
}
|
|
84
133
|
}
|
|
134
|
+
/** 事件数组的近似序列化体积(与 emit 中的累计口径一致) */
|
|
135
|
+
static bytesOf(events) {
|
|
136
|
+
return events.reduce((sum, e) => sum + JSON.stringify(e).length, 0);
|
|
137
|
+
}
|
|
85
138
|
/** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
|
|
86
139
|
static snapshot() {
|
|
87
140
|
return this._stop ? [...this._events] : [];
|
|
88
141
|
}
|
|
89
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* 上报成功后移除已携带的事件,继续录制——不调用 stop,避免下一个错误重复携带上一段。
|
|
144
|
+
*
|
|
145
|
+
* 起点事件(Meta / FullSnapshot)保留在缓冲区:随本次上报一起移除后,下一段回放
|
|
146
|
+
* 只剩增量事件、播放器无法独立渲染。
|
|
147
|
+
*/
|
|
90
148
|
static commitSnapshot(snapshot) {
|
|
91
149
|
if (!snapshot.length)
|
|
92
150
|
return;
|
|
93
151
|
const sent = new Set(snapshot);
|
|
94
|
-
this._events = this._events.filter((
|
|
95
|
-
if (
|
|
96
|
-
|
|
152
|
+
this._events = this._events.filter((event) => {
|
|
153
|
+
if (isReplayStartEvent(event))
|
|
154
|
+
return true;
|
|
155
|
+
if (sent.has(event)) {
|
|
156
|
+
this._bytes -= JSON.stringify(event).length;
|
|
97
157
|
return false;
|
|
98
158
|
}
|
|
99
159
|
return true;
|
|
@@ -102,8 +162,12 @@ var Replay = class {
|
|
|
102
162
|
this._bytes = 0;
|
|
103
163
|
}
|
|
104
164
|
};
|
|
165
|
+
var Replay = _Replay;
|
|
166
|
+
// 缓冲区:起点事件(Meta / FullSnapshot)始终保留在头部
|
|
105
167
|
Replay._events = [];
|
|
106
168
|
// rrweb 异步加载中的标记:避免 init 被重复调用时启动两个录制实例
|
|
107
169
|
Replay._loading = false;
|
|
108
|
-
//
|
|
170
|
+
// 加载窗口内被 stop 的标记:rrweb 就绪后据此放弃启动
|
|
171
|
+
Replay._stopRequested = false;
|
|
172
|
+
// 录制阶段的累计体积(近似值),达到 replayMaxBytes 后整体重开一段
|
|
109
173
|
Replay._bytes = 0;
|
package/lib/Track/envelope.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
import type
|
|
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
|
+
export declare function truncate(value: string, limit: number): string;
|
|
14
|
+
export declare function truncate(value: string | undefined, limit: number): string | undefined;
|
|
2
15
|
/** 请求级公共段(信封):字段与实体属性同名(camelCase),每次请求仅一份 */
|
|
3
16
|
export declare function buildEnvelopeBase(): TrackV3Envelope;
|
|
4
17
|
/** 条级事件公共字段:href / 视口 / 毫秒时间戳在批量窗口内会变,逐条携带 */
|
|
5
18
|
export declare function buildEventBase(): Pick<TrackV3Event, 'systemTime' | 'href' | 'innerWidth' | 'innerHeight'>;
|
|
6
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* V3 上报地址:鉴权**仅 appId**,走 URL query(sendBeacon 无法自定义 header)。
|
|
21
|
+
* 刻意不实现 `ts` / `nonce` / `sign`:探针运行在公开前端页面,密钥无法保密,签名不构成防线;
|
|
22
|
+
* 准入由服务端 TrackAuthGuard(appId 在册 + 停收开关 + 限流)负责。
|
|
23
|
+
*/
|
|
7
24
|
export declare function trackUrl(path: '/batch' | '/error'): string;
|
package/lib/Track/envelope.js
CHANGED
|
@@ -31,29 +31,42 @@ var envelope_exports = {};
|
|
|
31
31
|
__export(envelope_exports, {
|
|
32
32
|
buildEnvelopeBase: () => buildEnvelopeBase,
|
|
33
33
|
buildEventBase: () => buildEventBase,
|
|
34
|
-
trackUrl: () => trackUrl
|
|
34
|
+
trackUrl: () => trackUrl,
|
|
35
|
+
truncate: () => truncate
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(envelope_exports);
|
|
37
38
|
var import_package = __toESM(require("../../package.json"));
|
|
39
|
+
var import_protocol = require("../interfaces/protocol");
|
|
38
40
|
var import_Config = __toESM(require("./Config"));
|
|
39
41
|
var import_System = __toESM(require("./System"));
|
|
40
42
|
var import_User = __toESM(require("./User"));
|
|
43
|
+
function truncate(value, limit) {
|
|
44
|
+
if (value === null || value === void 0)
|
|
45
|
+
return void 0;
|
|
46
|
+
return value.length > limit ? value.slice(0, limit) : value;
|
|
47
|
+
}
|
|
41
48
|
function buildEnvelopeBase() {
|
|
42
49
|
const profile = import_User.default.profile;
|
|
43
50
|
return {
|
|
44
51
|
appId: import_Config.default.data.appId,
|
|
45
|
-
sdkVersion: import_package.default.version,
|
|
52
|
+
sdkVersion: truncate(import_package.default.version, import_protocol.TRACK_LIMITS.sdkVersion),
|
|
46
53
|
// 调用方应用版本:未配置时为 undefined,JSON.stringify 会丢弃该键(服务端落 NULL)
|
|
47
|
-
appVersion: import_Config.default.data.appVersion,
|
|
48
|
-
imei: import_System.default.imei,
|
|
54
|
+
appVersion: truncate(import_Config.default.data.appVersion, import_protocol.TRACK_LIMITS.appVersion),
|
|
55
|
+
imei: truncate(import_System.default.imei, import_protocol.TRACK_LIMITS.imei),
|
|
49
56
|
...profile ? {
|
|
50
57
|
user: {
|
|
51
|
-
userId: profile.userId,
|
|
52
|
-
userName: profile.userName,
|
|
53
|
-
orgCode: profile.orgCode,
|
|
54
|
-
orgTitle: profile.orgTitle,
|
|
55
|
-
dataScopeZonePermissions:
|
|
56
|
-
|
|
58
|
+
userId: truncate(profile.userId, import_protocol.TRACK_LIMITS.userField),
|
|
59
|
+
userName: truncate(profile.userName, import_protocol.TRACK_LIMITS.userField),
|
|
60
|
+
orgCode: truncate(profile.orgCode, import_protocol.TRACK_LIMITS.userField),
|
|
61
|
+
orgTitle: truncate(profile.orgTitle, import_protocol.TRACK_LIMITS.userField),
|
|
62
|
+
dataScopeZonePermissions: truncate(
|
|
63
|
+
profile.dataScopeZonePermissions,
|
|
64
|
+
import_protocol.TRACK_LIMITS.userField
|
|
65
|
+
),
|
|
66
|
+
dataScopeRoles: truncate(
|
|
67
|
+
profile.dataScopeRoles,
|
|
68
|
+
import_protocol.TRACK_LIMITS.userField
|
|
69
|
+
)
|
|
57
70
|
}
|
|
58
71
|
} : {}
|
|
59
72
|
};
|
|
@@ -61,18 +74,23 @@ function buildEnvelopeBase() {
|
|
|
61
74
|
function buildEventBase() {
|
|
62
75
|
return {
|
|
63
76
|
systemTime: Date.now(),
|
|
64
|
-
href:
|
|
77
|
+
href: truncate(
|
|
78
|
+
typeof location !== "undefined" ? location.href : "",
|
|
79
|
+
import_protocol.TRACK_LIMITS.href
|
|
80
|
+
),
|
|
65
81
|
innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
|
|
66
82
|
innerHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
67
83
|
};
|
|
68
84
|
}
|
|
69
85
|
function trackUrl(path) {
|
|
70
86
|
const appId = encodeURIComponent(import_Config.default.data.appId);
|
|
71
|
-
|
|
87
|
+
const domain = import_Config.default.data.domain.replace(/\/+$/, "");
|
|
88
|
+
return `${domain}/pousheng-guard/api/track/v3${path}?appId=${appId}`;
|
|
72
89
|
}
|
|
73
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
91
|
0 && (module.exports = {
|
|
75
92
|
buildEnvelopeBase,
|
|
76
93
|
buildEventBase,
|
|
77
|
-
trackUrl
|
|
94
|
+
trackUrl,
|
|
95
|
+
truncate
|
|
78
96
|
});
|
package/lib/Track/index.js
CHANGED
|
@@ -58,8 +58,16 @@ var Track = class {
|
|
|
58
58
|
}
|
|
59
59
|
// 需要初始化执行的组件都需在这里初始化调用
|
|
60
60
|
static run() {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (import_Config.default.data.autoReportError) {
|
|
62
|
+
import_Listener.default.run();
|
|
63
|
+
} else {
|
|
64
|
+
import_Listener.default.stop();
|
|
65
|
+
}
|
|
66
|
+
if (import_Config.default.data.enableReplay) {
|
|
67
|
+
void import_Replay.default.run();
|
|
68
|
+
} else {
|
|
69
|
+
import_Replay.default.stop();
|
|
70
|
+
}
|
|
63
71
|
import_Beacon.default.start();
|
|
64
72
|
}
|
|
65
73
|
// 获取当前页面模块名称
|
package/lib/Utils/index.d.ts
CHANGED
package/lib/Utils/index.js
CHANGED
|
@@ -16,18 +16,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
// src/Utils/index.ts
|
|
17
17
|
var Utils_exports = {};
|
|
18
18
|
module.exports = __toCommonJS(Utils_exports);
|
|
19
|
+
__reExport(Utils_exports, require("./auth"), module.exports);
|
|
19
20
|
__reExport(Utils_exports, require("./common"), module.exports);
|
|
20
21
|
__reExport(Utils_exports, require("./file"), module.exports);
|
|
22
|
+
__reExport(Utils_exports, require("./route"), module.exports);
|
|
21
23
|
__reExport(Utils_exports, require("./url"), module.exports);
|
|
22
24
|
__reExport(Utils_exports, require("./wx"), module.exports);
|
|
23
|
-
__reExport(Utils_exports, require("./route"), module.exports);
|
|
24
|
-
__reExport(Utils_exports, require("./auth"), module.exports);
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
|
+
...require("./auth"),
|
|
27
28
|
...require("./common"),
|
|
28
29
|
...require("./file"),
|
|
29
|
-
...require("./url"),
|
|
30
|
-
...require("./wx"),
|
|
31
30
|
...require("./route"),
|
|
32
|
-
...require("./
|
|
31
|
+
...require("./url"),
|
|
32
|
+
...require("./wx")
|
|
33
33
|
});
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -36,12 +36,12 @@ __export(src_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
var import_Track = __toESM(require("./Track"));
|
|
38
38
|
var Utils = __toESM(require("./Utils"));
|
|
39
|
-
__reExport(src_exports, require("./interfaces/track.interface"), module.exports);
|
|
40
39
|
__reExport(src_exports, require("./interfaces/protocol"), module.exports);
|
|
40
|
+
__reExport(src_exports, require("./interfaces/track.interface"), module.exports);
|
|
41
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
42
|
0 && (module.exports = {
|
|
43
43
|
Track,
|
|
44
44
|
Utils,
|
|
45
|
-
...require("./interfaces/
|
|
46
|
-
...require("./interfaces/
|
|
45
|
+
...require("./interfaces/protocol"),
|
|
46
|
+
...require("./interfaces/track.interface")
|
|
47
47
|
});
|
|
@@ -18,7 +18,7 @@ export declare const TrackTypeLabel: Record<TrackType, string>;
|
|
|
18
18
|
* 不做无依据的额外限制——超长字段本身即会写入失败。
|
|
19
19
|
*/
|
|
20
20
|
export declare const TRACK_LIMITS: {
|
|
21
|
-
/** 单次批量 events[] 条数上限(SDK
|
|
21
|
+
/** 单次批量 events[] 条数上限(SDK 切批与服务端 DTO 共用,双方都不可调) */
|
|
22
22
|
readonly maxItems: 20;
|
|
23
23
|
/** 探针版本号,guard_conf.version varchar(20) */
|
|
24
24
|
readonly sdkVersion: 20;
|
|
@@ -38,7 +38,7 @@ var TrackTypeLabel = {
|
|
|
38
38
|
api: "接口触发"
|
|
39
39
|
};
|
|
40
40
|
var TRACK_LIMITS = {
|
|
41
|
-
/** 单次批量 events[] 条数上限(SDK
|
|
41
|
+
/** 单次批量 events[] 条数上限(SDK 切批与服务端 DTO 共用,双方都不可调) */
|
|
42
42
|
maxItems: 20,
|
|
43
43
|
/** 探针版本号,guard_conf.version varchar(20) */
|
|
44
44
|
sdkVersion: 20,
|
package/package.json
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yysports/tools",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "常用工具函数库",
|
|
5
|
-
"homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools/issues"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools.git"
|
|
12
|
-
},
|
|
13
5
|
"license": "UNLICENSED",
|
|
14
6
|
"author": "daiwenyu",
|
|
15
7
|
"main": "lib/index.js",
|
|
@@ -33,9 +25,10 @@
|
|
|
33
25
|
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\" --allow-empty-input",
|
|
34
26
|
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
35
27
|
"prepare": "husky && dumi setup",
|
|
36
|
-
"prepublishOnly": "father doctor && npm run build",
|
|
28
|
+
"prepublishOnly": "father doctor && npm run build && npm test",
|
|
37
29
|
"release": "npm run build && npm publish --access public --registry https://registry.npmjs.org",
|
|
38
|
-
"start": "npm run dev"
|
|
30
|
+
"start": "npm run dev",
|
|
31
|
+
"test": "vitest run"
|
|
39
32
|
},
|
|
40
33
|
"commitlint": {
|
|
41
34
|
"extends": [
|
|
@@ -60,28 +53,32 @@
|
|
|
60
53
|
]
|
|
61
54
|
},
|
|
62
55
|
"dependencies": {
|
|
63
|
-
"@babel/runtime": "^7.29.
|
|
64
|
-
"@rrweb/record": "2.1.
|
|
65
|
-
"@rrweb/rrweb-plugin-console-record": "2.1.
|
|
56
|
+
"@babel/runtime": "^7.29.10",
|
|
57
|
+
"@rrweb/record": "2.1.7",
|
|
58
|
+
"@rrweb/rrweb-plugin-console-record": "2.1.7",
|
|
66
59
|
"image-conversion": "^2.1.1"
|
|
67
60
|
},
|
|
68
61
|
"devDependencies": {
|
|
69
|
-
"@commitlint/cli": "^
|
|
70
|
-
"@commitlint/config-conventional": "^
|
|
62
|
+
"@commitlint/cli": "^21.2.4",
|
|
63
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
71
64
|
"@types/react": "^19.3.0",
|
|
72
|
-
"@umijs/lint": "^4.7.
|
|
73
|
-
"antd": "^6.6.
|
|
74
|
-
"dumi": "^2.4.
|
|
65
|
+
"@umijs/lint": "^4.7.27",
|
|
66
|
+
"antd": "^6.6.7",
|
|
67
|
+
"dumi": "^2.4.53",
|
|
75
68
|
"eslint": "^8.57.1",
|
|
76
|
-
"father": "^4.6.
|
|
69
|
+
"father": "^4.6.41",
|
|
77
70
|
"husky": "^9.1.7",
|
|
78
|
-
"lint-staged": "^
|
|
79
|
-
"prettier": "^3.9.
|
|
71
|
+
"lint-staged": "^17.6.0",
|
|
72
|
+
"prettier": "^3.9.10",
|
|
80
73
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
81
|
-
"prettier-plugin-packagejson": "^
|
|
82
|
-
"react": "^19.3.
|
|
83
|
-
"react-dom": "^19.3.
|
|
84
|
-
"stylelint": "^16.
|
|
74
|
+
"prettier-plugin-packagejson": "^3.0.2",
|
|
75
|
+
"react": "^19.3.1",
|
|
76
|
+
"react-dom": "^19.3.1",
|
|
77
|
+
"stylelint": "^14.16.1",
|
|
78
|
+
"vitest": "^5.0.5"
|
|
79
|
+
},
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=22.22.1"
|
|
85
82
|
},
|
|
86
83
|
"publishConfig": {
|
|
87
84
|
"access": "public"
|