@yysports/tools 3.2.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.
- package/README.md +1 -3
- package/dist/Track/Beacon.d.ts +0 -18
- package/dist/Track/Beacon.js +3 -31
- package/dist/Track/Config.d.ts +0 -15
- package/dist/Track/Config.js +1 -11
- package/dist/Track/Device.d.ts +7 -0
- package/dist/Track/Device.js +55 -0
- package/dist/Track/Listener.d.ts +0 -11
- package/dist/Track/Listener.js +1 -26
- package/dist/Track/Log.d.ts +0 -23
- package/dist/Track/Log.js +18 -60
- package/dist/Track/System.d.ts +0 -1
- package/dist/Track/System.js +2 -3
- package/dist/Track/User.js +1 -1
- package/dist/Track/envelope.d.ts +0 -18
- package/dist/Track/envelope.js +6 -27
- package/dist/Track/index.js +3 -16
- package/dist/Utils/auth.d.ts +0 -7
- package/dist/Utils/auth.js +6 -17
- package/dist/Utils/common.d.ts +0 -16
- package/dist/Utils/common.js +0 -20
- package/dist/Utils/file.d.ts +0 -10
- package/dist/Utils/file.js +0 -14
- package/dist/Utils/route.d.ts +0 -6
- package/dist/Utils/route.js +0 -19
- package/dist/interfaces/protocol.d.ts +5 -54
- package/dist/interfaces/protocol.js +1 -56
- package/dist/interfaces/track.interface.js +1 -9
- package/lib/Track/Beacon.d.ts +0 -18
- package/lib/Track/Beacon.js +36 -79
- package/lib/Track/Config.d.ts +0 -15
- package/lib/Track/Config.js +20 -51
- package/lib/Track/Device.d.ts +7 -0
- package/lib/Track/Device.js +48 -0
- package/lib/Track/Listener.d.ts +0 -11
- package/lib/Track/Listener.js +31 -73
- package/lib/Track/Log.d.ts +0 -23
- package/lib/Track/Log.js +50 -114
- package/lib/Track/System.d.ts +0 -1
- package/lib/Track/System.js +13 -31
- package/lib/Track/User.js +12 -30
- package/lib/Track/envelope.d.ts +0 -18
- package/lib/Track/envelope.js +38 -78
- package/lib/Track/index.js +31 -63
- package/lib/Utils/auth.d.ts +0 -7
- package/lib/Utils/auth.js +24 -53
- package/lib/Utils/common.d.ts +0 -16
- package/lib/Utils/common.js +15 -40
- package/lib/Utils/file.d.ts +0 -10
- package/lib/Utils/file.js +21 -42
- package/lib/Utils/index.js +69 -31
- package/lib/Utils/route.d.ts +0 -6
- package/lib/Utils/route.js +25 -43
- package/lib/Utils/url.js +8 -29
- package/lib/Utils/wx.js +18 -35
- package/lib/index.js +41 -43
- package/lib/interfaces/protocol.d.ts +5 -54
- package/lib/interfaces/protocol.js +14 -56
- package/lib/interfaces/track.interface.js +15 -28
- package/package.json +7 -10
- package/dist/Track/Replay.d.ts +0 -93
- package/dist/Track/Replay.js +0 -447
- package/lib/Track/Replay.d.ts +0 -93
- package/lib/Track/Replay.js +0 -330
package/README.md
CHANGED
package/dist/Track/Beacon.d.ts
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
import { type TrackV3Event } from '../interfaces/protocol';
|
|
2
|
-
/**
|
|
3
|
-
* 批量日志队列(通道 1)。
|
|
4
|
-
*
|
|
5
|
-
* 发送语义是**尽力而为**:`sendBeacon` / `fetch` 都无法感知服务端 4xx/413,因此不做队列
|
|
6
|
-
* 驻留与重试,入队失败即丢弃该批,被拒的丢数由服务端侧计数告警补偿。
|
|
7
|
-
* 无 sendBeacon 环境(部分 WebView / 老浏览器)降级用 fetch(keepalive) 发送。
|
|
8
|
-
*/
|
|
9
2
|
export default class Beacon {
|
|
10
3
|
private static _queue;
|
|
11
4
|
private static _timer;
|
|
12
|
-
/**
|
|
13
|
-
* 启动定时 flush 与卸载兜底(Track.init 时调用,重复调用无副作用)。
|
|
14
|
-
*
|
|
15
|
-
* 兜底 flush 放在这里、不放 `Listener`:那会让「是否采集错误」与「通道能否送达」耦合,
|
|
16
|
-
* 关掉 `autoReportError` 会连带丢掉所有不满一批的数据。
|
|
17
|
-
*
|
|
18
|
-
* `flushInterval` 只在首次创建定时器时读取,热更新重建留待 3.2.0(P1-6)。
|
|
19
|
-
*/
|
|
20
5
|
static start(): void;
|
|
21
|
-
/** 入队,达到协议上限立即 flush */
|
|
22
6
|
static push(event: TrackV3Event): void;
|
|
23
|
-
/** 按批发送并出队;发送失败同样出队(尽力而为,不驻留重试) */
|
|
24
7
|
static flush(): void;
|
|
25
8
|
private static sendBatch;
|
|
26
9
|
private static trySendBeacon;
|
|
27
|
-
/** fetch keepalive:无 sendBeacon 环境的主要通道,已发出即视为送达(不等响应、不阻塞队列) */
|
|
28
10
|
private static trySendKeepalive;
|
|
29
11
|
}
|
package/dist/Track/Beacon.js
CHANGED
|
@@ -5,37 +5,19 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
5
5
|
import { TRACK_CONTENT_TYPE, TRACK_LIMITS } from "../interfaces/protocol";
|
|
6
6
|
import Config from "./Config";
|
|
7
7
|
import { buildEnvelopeBase, trackUrl } from "./envelope";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 批量日志队列(通道 1)。
|
|
11
|
-
*
|
|
12
|
-
* 发送语义是**尽力而为**:`sendBeacon` / `fetch` 都无法感知服务端 4xx/413,因此不做队列
|
|
13
|
-
* 驻留与重试,入队失败即丢弃该批,被拒的丢数由服务端侧计数告警补偿。
|
|
14
|
-
* 无 sendBeacon 环境(部分 WebView / 老浏览器)降级用 fetch(keepalive) 发送。
|
|
15
|
-
*/
|
|
16
|
-
var Beacon = /*#__PURE__*/function () {
|
|
8
|
+
var Beacon = function () {
|
|
17
9
|
function Beacon() {
|
|
18
10
|
_classCallCheck(this, Beacon);
|
|
19
11
|
}
|
|
20
12
|
_createClass(Beacon, null, [{
|
|
21
13
|
key: "start",
|
|
22
|
-
value:
|
|
23
|
-
/**
|
|
24
|
-
* 启动定时 flush 与卸载兜底(Track.init 时调用,重复调用无副作用)。
|
|
25
|
-
*
|
|
26
|
-
* 兜底 flush 放在这里、不放 `Listener`:那会让「是否采集错误」与「通道能否送达」耦合,
|
|
27
|
-
* 关掉 `autoReportError` 会连带丢掉所有不满一批的数据。
|
|
28
|
-
*
|
|
29
|
-
* `flushInterval` 只在首次创建定时器时读取,热更新重建留待 3.2.0(P1-6)。
|
|
30
|
-
*/
|
|
31
|
-
function start() {
|
|
14
|
+
value: function start() {
|
|
32
15
|
var _this = this,
|
|
33
16
|
_Config$data$flushInt;
|
|
34
17
|
if (this._timer) return;
|
|
35
18
|
this._timer = setInterval(function () {
|
|
36
19
|
return _this.flush();
|
|
37
20
|
}, (_Config$data$flushInt = Config.data.flushInterval) !== null && _Config$data$flushInt !== void 0 ? _Config$data$flushInt : 10000);
|
|
38
|
-
// Node / Worker 等无 DOM 环境无法监听生命周期,只跑定时 flush
|
|
39
21
|
if (typeof document === 'undefined' || typeof window === 'undefined') {
|
|
40
22
|
return;
|
|
41
23
|
}
|
|
@@ -48,12 +30,9 @@ var Beacon = /*#__PURE__*/function () {
|
|
|
48
30
|
_this.flush();
|
|
49
31
|
});
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
/** 入队,达到协议上限立即 flush */
|
|
53
33
|
}, {
|
|
54
34
|
key: "push",
|
|
55
35
|
value: function push(event) {
|
|
56
|
-
// 未 init(appId 为空)时报出的数据无归属、必被服务端 403/400 拒,直接丢弃并提示调用方
|
|
57
36
|
if (!Config.data.appId) {
|
|
58
37
|
console.warn('[Track] 尚未调用 Track.init(appId 为空),该条上报已丢弃');
|
|
59
38
|
return;
|
|
@@ -63,8 +42,6 @@ var Beacon = /*#__PURE__*/function () {
|
|
|
63
42
|
this.flush();
|
|
64
43
|
}
|
|
65
44
|
}
|
|
66
|
-
|
|
67
|
-
/** 按批发送并出队;发送失败同样出队(尽力而为,不驻留重试) */
|
|
68
45
|
}, {
|
|
69
46
|
key: "flush",
|
|
70
47
|
value: function flush() {
|
|
@@ -80,7 +57,6 @@ var Beacon = /*#__PURE__*/function () {
|
|
|
80
57
|
}, {
|
|
81
58
|
key: "sendBatch",
|
|
82
59
|
value: function sendBatch(payload) {
|
|
83
|
-
// 优先 sendBeacon(页面卸载场景仍可送达);不可用或入队失败时降级 fetch(keepalive)
|
|
84
60
|
if (!this.trySendBeacon(payload)) {
|
|
85
61
|
this.trySendKeepalive(payload);
|
|
86
62
|
}
|
|
@@ -97,8 +73,6 @@ var Beacon = /*#__PURE__*/function () {
|
|
|
97
73
|
return false;
|
|
98
74
|
}
|
|
99
75
|
}
|
|
100
|
-
|
|
101
|
-
/** fetch keepalive:无 sendBeacon 环境的主要通道,已发出即视为送达(不等响应、不阻塞队列) */
|
|
102
76
|
}, {
|
|
103
77
|
key: "trySendKeepalive",
|
|
104
78
|
value: function trySendKeepalive(payload) {
|
|
@@ -114,9 +88,7 @@ var Beacon = /*#__PURE__*/function () {
|
|
|
114
88
|
}).catch(function () {
|
|
115
89
|
return undefined;
|
|
116
90
|
});
|
|
117
|
-
} catch (error) {
|
|
118
|
-
// 同步抛错(如 URL 非法)时同样丢弃该批:尽力而为,不重试
|
|
119
|
-
}
|
|
91
|
+
} catch (error) {}
|
|
120
92
|
}
|
|
121
93
|
}]);
|
|
122
94
|
return Beacon;
|
package/dist/Track/Config.d.ts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
export interface IConfig {
|
|
2
2
|
appId: string;
|
|
3
3
|
domain: string;
|
|
4
|
-
/**
|
|
5
|
-
* 调用方应用自身的版本号(可选)。
|
|
6
|
-
* 探针取不到宿主程序版本(`sdkVersion` 是探针自己的版本),只能由接入方显式传入;
|
|
7
|
-
* 不传时服务端 `guard_track.app_version` 落 NULL,不影响上报。
|
|
8
|
-
*/
|
|
9
4
|
appVersion?: string;
|
|
10
5
|
autoReportError?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* 是否启用回放录制(默认 true)。
|
|
13
|
-
* 回放体积 / 去重 / 掩码策略全部由 SDK 内部固定:这些参数只会「配错就崩」
|
|
14
|
-
* (配大必然 413、配小频繁放弃),接入方只表达「要不要录」。
|
|
15
|
-
*/
|
|
16
|
-
enableReplay?: boolean;
|
|
17
6
|
flushInterval?: number;
|
|
18
7
|
}
|
|
19
8
|
export default class Config {
|
|
20
9
|
private static _data;
|
|
21
10
|
static validate(config: IConfig): void;
|
|
22
|
-
/**
|
|
23
|
-
* `0` / 非数字 / `null` 回落默认值,其余小于下限的收敛到下限。
|
|
24
|
-
* `0` 按非法处理而非下限:`Number(null)` 也是 0,混在一起会让下限失去意义。
|
|
25
|
-
*/
|
|
26
11
|
private static normalize;
|
|
27
12
|
static get data(): IConfig;
|
|
28
13
|
}
|
package/dist/Track/Config.js
CHANGED
|
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
-
var Config =
|
|
5
|
+
var Config = function () {
|
|
6
6
|
function Config() {
|
|
7
7
|
_classCallCheck(this, Config);
|
|
8
8
|
}
|
|
@@ -16,23 +16,14 @@ var Config = /*#__PURE__*/function () {
|
|
|
16
16
|
if (!((_config$domain = config.domain) !== null && _config$domain !== void 0 && _config$domain.trim())) {
|
|
17
17
|
throw new Error('Config: domain is required');
|
|
18
18
|
}
|
|
19
|
-
// 过滤显式 undefined 的键:`Object.assign` 会把 undefined 写进配置、清空已有值
|
|
20
|
-
// (如重复 init 时 `appVersion: undefined` 会抹掉先前设置的版本号)
|
|
21
19
|
var defined = Object.fromEntries(Object.entries(config).filter(function (_ref) {
|
|
22
20
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
23
21
|
value = _ref2[1];
|
|
24
22
|
return value !== undefined;
|
|
25
23
|
}));
|
|
26
24
|
Object.assign(this._data, defined);
|
|
27
|
-
|
|
28
|
-
// 数值项归一化:setInterval(0) 会空转占满主线程
|
|
29
25
|
this._data.flushInterval = Config.normalize(this._data.flushInterval, 10000, 1000);
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* `0` / 非数字 / `null` 回落默认值,其余小于下限的收敛到下限。
|
|
34
|
-
* `0` 按非法处理而非下限:`Number(null)` 也是 0,混在一起会让下限失去意义。
|
|
35
|
-
*/
|
|
36
27
|
}, {
|
|
37
28
|
key: "normalize",
|
|
38
29
|
value: function normalize(value, fallback, min) {
|
|
@@ -52,7 +43,6 @@ _defineProperty(Config, "_data", {
|
|
|
52
43
|
appId: '',
|
|
53
44
|
domain: '',
|
|
54
45
|
autoReportError: true,
|
|
55
|
-
enableReplay: true,
|
|
56
46
|
flushInterval: 10000
|
|
57
47
|
});
|
|
58
48
|
export { Config as default };
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
function getUserAgentData() {
|
|
6
|
+
if (typeof navigator === 'undefined') return undefined;
|
|
7
|
+
var uaData = navigator.userAgentData;
|
|
8
|
+
if (!uaData || typeof uaData.getHighEntropyValues !== 'function') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return uaData;
|
|
12
|
+
}
|
|
13
|
+
function toValue(value) {
|
|
14
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
function pickDevice(values) {
|
|
17
|
+
var model = toValue(values === null || values === void 0 ? void 0 : values.model);
|
|
18
|
+
var platformVersion = toValue(values === null || values === void 0 ? void 0 : values.platformVersion);
|
|
19
|
+
return _objectSpread(_objectSpread({}, model ? {
|
|
20
|
+
model: model
|
|
21
|
+
} : {}), platformVersion ? {
|
|
22
|
+
platformVersion: platformVersion
|
|
23
|
+
} : {});
|
|
24
|
+
}
|
|
25
|
+
var Device = function () {
|
|
26
|
+
function Device() {
|
|
27
|
+
_classCallCheck(this, Device);
|
|
28
|
+
}
|
|
29
|
+
_createClass(Device, null, [{
|
|
30
|
+
key: "init",
|
|
31
|
+
value: function init() {
|
|
32
|
+
var _this = this;
|
|
33
|
+
if (this._requested) return;
|
|
34
|
+
this._requested = true;
|
|
35
|
+
var uaData = getUserAgentData();
|
|
36
|
+
if (!uaData) return;
|
|
37
|
+
try {
|
|
38
|
+
void uaData.getHighEntropyValues(['model', 'platformVersion']).then(function (values) {
|
|
39
|
+
_this._device = pickDevice(values);
|
|
40
|
+
}).catch(function () {
|
|
41
|
+
return undefined;
|
|
42
|
+
});
|
|
43
|
+
} catch (_unused) {}
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "data",
|
|
47
|
+
get: function get() {
|
|
48
|
+
return this._device;
|
|
49
|
+
}
|
|
50
|
+
}]);
|
|
51
|
+
return Device;
|
|
52
|
+
}();
|
|
53
|
+
_defineProperty(Device, "_device", {});
|
|
54
|
+
_defineProperty(Device, "_requested", false);
|
|
55
|
+
export { Device as default };
|
package/dist/Track/Listener.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
export default class Listener {
|
|
2
2
|
private static _loaded;
|
|
3
3
|
private static _reporter;
|
|
4
|
-
/**
|
|
5
|
-
* 具名 handler:`removeEventListener` 必须拿到与注册时相同的函数引用,
|
|
6
|
-
* 匿名函数会让 `stop()` 失效(`autoReportError` 从 true 改 false 后仍在采集)。
|
|
7
|
-
*/
|
|
8
4
|
private static readonly _onError;
|
|
9
5
|
static run(): void;
|
|
10
|
-
/**
|
|
11
|
-
* 停止自动上报,供 `init({ autoReportError: false })` 热关闭。
|
|
12
|
-
*
|
|
13
|
-
* 必须复位 `_loaded`:否则再次 `init({ autoReportError: true })` 时 `run()`
|
|
14
|
-
* 直接命中幂等判断返回,监听再也装不回来。挂起的防抖定时器同样要清掉,
|
|
15
|
-
* 否则关闭后仍会补报一条。
|
|
16
|
-
*/
|
|
17
6
|
static stop(): void;
|
|
18
7
|
}
|
package/dist/Track/Listener.js
CHANGED
|
@@ -5,14 +5,6 @@ var _class;
|
|
|
5
5
|
import Beacon from "./Beacon";
|
|
6
6
|
import Config from "./Config";
|
|
7
7
|
import Log from "./Log";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 归一化错误描述。
|
|
11
|
-
*
|
|
12
|
-
* 资源加载错误的 `event.message` 常为空串或缺省,而服务端 `message` 为必填(空值整条 400)。
|
|
13
|
-
* 这类错误能拿到失败资源的地址,用它兜底生成可读 message,避免错误整条丢失;
|
|
14
|
-
* 两者都取不到时返回空串,由 `Log.errorLog` 统一丢弃并告警。
|
|
15
|
-
*/
|
|
16
8
|
function resolveErrorMessage(event) {
|
|
17
9
|
var _event$message, _target$src;
|
|
18
10
|
var message = (_event$message = event.message) === null || _event$message === void 0 ? void 0 : _event$message.trim();
|
|
@@ -21,7 +13,7 @@ function resolveErrorMessage(event) {
|
|
|
21
13
|
var failedUrl = (_target$src = target === null || target === void 0 ? void 0 : target.src) !== null && _target$src !== void 0 ? _target$src : target === null || target === void 0 ? void 0 : target.href;
|
|
22
14
|
return failedUrl ? "\u8D44\u6E90\u52A0\u8F7D\u5931\u8D25\uFF1A".concat(failedUrl) : '';
|
|
23
15
|
}
|
|
24
|
-
var Listener =
|
|
16
|
+
var Listener = function () {
|
|
25
17
|
function Listener() {
|
|
26
18
|
_classCallCheck(this, Listener);
|
|
27
19
|
}
|
|
@@ -31,21 +23,9 @@ var Listener = /*#__PURE__*/function () {
|
|
|
31
23
|
if (this._loaded || !Config.data.autoReportError) {
|
|
32
24
|
return;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
// 监听全局未捕获的错误,同时进行防抖处理,高频报错时只上报最后一条。
|
|
36
|
-
// capture: true 必须保留——资源加载错误(img / script / link)不冒泡,
|
|
37
|
-
// 只有捕获阶段才能在 window 上监听到,否则这类错误完全采集不到
|
|
38
26
|
window.addEventListener('error', this._onError, true);
|
|
39
27
|
this._loaded = true;
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 停止自动上报,供 `init({ autoReportError: false })` 热关闭。
|
|
44
|
-
*
|
|
45
|
-
* 必须复位 `_loaded`:否则再次 `init({ autoReportError: true })` 时 `run()`
|
|
46
|
-
* 直接命中幂等判断返回,监听再也装不回来。挂起的防抖定时器同样要清掉,
|
|
47
|
-
* 否则关闭后仍会补报一条。
|
|
48
|
-
*/
|
|
49
29
|
}, {
|
|
50
30
|
key: "stop",
|
|
51
31
|
value: function stop() {
|
|
@@ -63,17 +43,12 @@ var Listener = /*#__PURE__*/function () {
|
|
|
63
43
|
_class = Listener;
|
|
64
44
|
_defineProperty(Listener, "_loaded", false);
|
|
65
45
|
_defineProperty(Listener, "_reporter", null);
|
|
66
|
-
/**
|
|
67
|
-
* 具名 handler:`removeEventListener` 必须拿到与注册时相同的函数引用,
|
|
68
|
-
* 匿名函数会让 `stop()` 失效(`autoReportError` 从 true 改 false 后仍在采集)。
|
|
69
|
-
*/
|
|
70
46
|
_defineProperty(Listener, "_onError", function (event) {
|
|
71
47
|
if (_class._reporter) {
|
|
72
48
|
clearTimeout(_class._reporter);
|
|
73
49
|
}
|
|
74
50
|
_class._reporter = setTimeout(function () {
|
|
75
51
|
var _event$error;
|
|
76
|
-
// 立即触发上报当前剩余的 Beacon 数据
|
|
77
52
|
Beacon.flush();
|
|
78
53
|
Log.errorLog(resolveErrorMessage(event), (_event$error = event.error) === null || _event$error === void 0 ? void 0 : _event$error.stack);
|
|
79
54
|
_class._reporter = null;
|
package/dist/Track/Log.d.ts
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 日志上报入口。
|
|
3
|
-
*
|
|
4
|
-
* 配置语义:`autoReportError` 只控制是否自动监听 window.onerror(见 Listener);
|
|
5
|
-
* 回放是否随错误一起上报只看 `enableReplay`(见 Replay.run)。
|
|
6
|
-
*/
|
|
7
1
|
export default class Log {
|
|
8
2
|
private static _module;
|
|
9
3
|
static get module(): string;
|
|
10
|
-
/**
|
|
11
|
-
* 条级业务内容超列宽时丢弃该条。
|
|
12
|
-
*
|
|
13
|
-
* `content` 是接入方传入的业务内容:截断会改变语义、把「数据丢失」伪装成「数据完整」,
|
|
14
|
-
* 故选择丢弃 + `console.warn`——联调期即可暴露,且不会让同批其他条一起被 400 拒掉。
|
|
15
|
-
*/
|
|
16
4
|
private static isContentOverlong;
|
|
17
|
-
/**
|
|
18
|
-
* 页面上报。
|
|
19
|
-
*
|
|
20
|
-
* `module` 为空属调用误用(如路由工具返回 `undefined`):`_module` 会被后续事件复用,
|
|
21
|
-
* 记成空串会让之后所有事件的归属一起变空,故丢弃并告警,与 `errorLog` 处理一致。
|
|
22
|
-
*/
|
|
23
5
|
static visitLog(module?: string): void;
|
|
24
6
|
static eventLog(content: string): void;
|
|
25
7
|
static apiLog(log: string): void;
|
|
26
|
-
/**
|
|
27
|
-
* 错误 + 回放一次请求内嵌上报(通道 2)。
|
|
28
|
-
* fetch 失败或页面卸载导致未送达时,用 sendBeacon 补发不含回放的纯错误:
|
|
29
|
-
* 卸载场景 fetch 不可靠,至少保住错误本体,回放可接受丢失。
|
|
30
|
-
*/
|
|
31
8
|
static errorLog(message: string, stack?: string): Promise<void>;
|
|
32
9
|
}
|
package/dist/Track/Log.js
CHANGED
|
@@ -8,32 +8,15 @@ import { TRACK_CONTENT_TYPE, TRACK_LIMITS } from "../interfaces/protocol";
|
|
|
8
8
|
import Beacon from "./Beacon";
|
|
9
9
|
import Config from "./Config";
|
|
10
10
|
import { buildEnvelopeBase, buildEventBase, trackUrl, truncate } from "./envelope";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 日志上报入口。
|
|
15
|
-
*
|
|
16
|
-
* 配置语义:`autoReportError` 只控制是否自动监听 window.onerror(见 Listener);
|
|
17
|
-
* 回放是否随错误一起上报只看 `enableReplay`(见 Replay.run)。
|
|
18
|
-
*/
|
|
19
|
-
var Log = /*#__PURE__*/function () {
|
|
11
|
+
var Log = function () {
|
|
20
12
|
function Log() {
|
|
21
13
|
_classCallCheck(this, Log);
|
|
22
14
|
}
|
|
23
15
|
_createClass(Log, null, [{
|
|
24
16
|
key: "module",
|
|
25
|
-
get:
|
|
26
|
-
// 获取当前模块名称
|
|
27
|
-
function get() {
|
|
17
|
+
get: function get() {
|
|
28
18
|
return this._module;
|
|
29
19
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 条级业务内容超列宽时丢弃该条。
|
|
33
|
-
*
|
|
34
|
-
* `content` 是接入方传入的业务内容:截断会改变语义、把「数据丢失」伪装成「数据完整」,
|
|
35
|
-
* 故选择丢弃 + `console.warn`——联调期即可暴露,且不会让同批其他条一起被 400 拒掉。
|
|
36
|
-
*/
|
|
37
20
|
}, {
|
|
38
21
|
key: "isContentOverlong",
|
|
39
22
|
value: function isContentOverlong(content) {
|
|
@@ -43,13 +26,6 @@ var Log = /*#__PURE__*/function () {
|
|
|
43
26
|
console.warn("[Track] content \u957F\u5EA6 ".concat(content.length, " \u8D85\u8FC7\u4E0A\u9650 ").concat(TRACK_LIMITS.content, "\uFF08\u670D\u52A1\u7AEF\u4F1A\u6574\u6279 400\uFF09\uFF0C\u5DF2\u4E22\u5F03\u8BE5\u6761\u65E5\u5FD7"));
|
|
44
27
|
return true;
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 页面上报。
|
|
49
|
-
*
|
|
50
|
-
* `module` 为空属调用误用(如路由工具返回 `undefined`):`_module` 会被后续事件复用,
|
|
51
|
-
* 记成空串会让之后所有事件的归属一起变空,故丢弃并告警,与 `errorLog` 处理一致。
|
|
52
|
-
*/
|
|
53
29
|
}, {
|
|
54
30
|
key: "visitLog",
|
|
55
31
|
value: function visitLog(module) {
|
|
@@ -59,19 +35,16 @@ var Log = /*#__PURE__*/function () {
|
|
|
59
35
|
return;
|
|
60
36
|
}
|
|
61
37
|
this._module = truncate(module, TRACK_LIMITS.module);
|
|
62
|
-
// 末段取自原始 module:`_module` 已按 255 截断,从它切会把末段从中间切断
|
|
63
38
|
var lastModule = (_module$split$pop = module.split('-').pop()) !== null && _module$split$pop !== void 0 ? _module$split$pop : '';
|
|
64
39
|
Beacon.push(_objectSpread(_objectSpread({}, buildEventBase()), {}, {
|
|
65
40
|
type: 'visit',
|
|
66
41
|
module: this._module,
|
|
67
|
-
// content 列宽 255 且自带 5 字前缀,必须整体截断,否则超限会让同批其他日志一并 400
|
|
68
42
|
content: truncate("\u8BBF\u95EE\u9875\u9762\uFF1A".concat(lastModule), TRACK_LIMITS.content)
|
|
69
43
|
}));
|
|
70
44
|
}
|
|
71
45
|
}, {
|
|
72
46
|
key: "eventLog",
|
|
73
47
|
value: function eventLog(content) {
|
|
74
|
-
// 非字符串会被原样入队,服务端校验失败会连坐同批;与超长处理一致,丢弃并告警
|
|
75
48
|
if (typeof content !== 'string') {
|
|
76
49
|
console.warn('[Track] eventLog 的 content 不是字符串(服务端会整批 400),已丢弃该条日志');
|
|
77
50
|
return;
|
|
@@ -92,17 +65,11 @@ var Log = /*#__PURE__*/function () {
|
|
|
92
65
|
log: log
|
|
93
66
|
}));
|
|
94
67
|
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 错误 + 回放一次请求内嵌上报(通道 2)。
|
|
98
|
-
* fetch 失败或页面卸载导致未送达时,用 sendBeacon 补发不含回放的纯错误:
|
|
99
|
-
* 卸载场景 fetch 不可靠,至少保住错误本体,回放可接受丢失。
|
|
100
|
-
*/
|
|
101
68
|
}, {
|
|
102
69
|
key: "errorLog",
|
|
103
70
|
value: (function () {
|
|
104
|
-
var _errorLog = _asyncToGenerator(
|
|
105
|
-
var
|
|
71
|
+
var _errorLog = _asyncToGenerator(_regeneratorRuntime().mark(function _callee(message, stack) {
|
|
72
|
+
var payload, res, _navigator, _navigator$sendBeacon;
|
|
106
73
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
107
74
|
while (1) switch (_context.prev = _context.next) {
|
|
108
75
|
case 0:
|
|
@@ -120,19 +87,15 @@ var Log = /*#__PURE__*/function () {
|
|
|
120
87
|
console.warn('[Track] errorLog 的 message 为空(服务端会整条 400),已丢弃该条错误上报');
|
|
121
88
|
return _context.abrupt("return");
|
|
122
89
|
case 6:
|
|
123
|
-
|
|
124
|
-
pureError = _objectSpread(_objectSpread({}, buildEnvelopeBase()), {}, {
|
|
90
|
+
payload = _objectSpread(_objectSpread({}, buildEnvelopeBase()), {}, {
|
|
125
91
|
error: _objectSpread(_objectSpread({}, buildEventBase()), {}, {
|
|
126
92
|
message: message,
|
|
127
93
|
stack: stack,
|
|
128
94
|
module: this._module
|
|
129
95
|
})
|
|
130
96
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}) : pureError;
|
|
134
|
-
_context.prev = 9;
|
|
135
|
-
_context.next = 12;
|
|
97
|
+
_context.prev = 7;
|
|
98
|
+
_context.next = 10;
|
|
136
99
|
return fetch(trackUrl('/error'), {
|
|
137
100
|
method: 'POST',
|
|
138
101
|
headers: {
|
|
@@ -140,33 +103,29 @@ var Log = /*#__PURE__*/function () {
|
|
|
140
103
|
},
|
|
141
104
|
body: JSON.stringify(payload)
|
|
142
105
|
});
|
|
143
|
-
case
|
|
106
|
+
case 10:
|
|
144
107
|
res = _context.sent;
|
|
145
108
|
if (res.ok) {
|
|
146
|
-
_context.next =
|
|
109
|
+
_context.next = 13;
|
|
147
110
|
break;
|
|
148
111
|
}
|
|
149
112
|
throw new Error("HTTP ".concat(res.status));
|
|
150
|
-
case
|
|
151
|
-
|
|
152
|
-
Replay.commitSnapshot(replay);
|
|
153
|
-
_context.next = 21;
|
|
113
|
+
case 13:
|
|
114
|
+
_context.next = 18;
|
|
154
115
|
break;
|
|
155
|
-
case
|
|
156
|
-
_context.prev =
|
|
157
|
-
_context.t0 = _context["catch"](
|
|
116
|
+
case 15:
|
|
117
|
+
_context.prev = 15;
|
|
118
|
+
_context.t0 = _context["catch"](7);
|
|
158
119
|
try {
|
|
159
|
-
(_navigator = navigator) === null || _navigator === void 0 || (_navigator$sendBeacon = _navigator.sendBeacon) === null || _navigator$sendBeacon === void 0 || _navigator$sendBeacon.call(_navigator, trackUrl('/error'), new Blob([JSON.stringify(
|
|
120
|
+
(_navigator = navigator) === null || _navigator === void 0 || (_navigator$sendBeacon = _navigator.sendBeacon) === null || _navigator$sendBeacon === void 0 || _navigator$sendBeacon.call(_navigator, trackUrl('/error'), new Blob([JSON.stringify(payload)], {
|
|
160
121
|
type: TRACK_CONTENT_TYPE
|
|
161
122
|
}));
|
|
162
|
-
} catch (beaconError) {
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
case 21:
|
|
123
|
+
} catch (beaconError) {}
|
|
124
|
+
case 18:
|
|
166
125
|
case "end":
|
|
167
126
|
return _context.stop();
|
|
168
127
|
}
|
|
169
|
-
}, _callee, this, [[
|
|
128
|
+
}, _callee, this, [[7, 15]]);
|
|
170
129
|
}));
|
|
171
130
|
function errorLog(_x, _x2) {
|
|
172
131
|
return _errorLog.apply(this, arguments);
|
|
@@ -176,6 +135,5 @@ var Log = /*#__PURE__*/function () {
|
|
|
176
135
|
}]);
|
|
177
136
|
return Log;
|
|
178
137
|
}();
|
|
179
|
-
// 当前模块
|
|
180
138
|
_defineProperty(Log, "_module", '');
|
|
181
139
|
export { Log as default };
|
package/dist/Track/System.d.ts
CHANGED
package/dist/Track/System.js
CHANGED
|
@@ -2,14 +2,13 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import { generateRandomString } from "../Utils";
|
|
5
|
-
var System =
|
|
5
|
+
var System = function () {
|
|
6
6
|
function System() {
|
|
7
7
|
_classCallCheck(this, System);
|
|
8
8
|
}
|
|
9
9
|
_createClass(System, null, [{
|
|
10
10
|
key: "imei",
|
|
11
|
-
get:
|
|
12
|
-
function get() {
|
|
11
|
+
get: function get() {
|
|
13
12
|
return this._imei;
|
|
14
13
|
}
|
|
15
14
|
}, {
|
package/dist/Track/User.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
var User =
|
|
4
|
+
var User = function () {
|
|
5
5
|
function User() {
|
|
6
6
|
_classCallCheck(this, User);
|
|
7
7
|
}
|
package/dist/Track/envelope.d.ts
CHANGED
|
@@ -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;
|