@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.
- 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 +0 -8
- package/dist/Track/Device.js +4 -38
- 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 +0 -26
- package/dist/Track/index.js +1 -17
- 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 +0 -67
- package/dist/interfaces/protocol.js +1 -64
- 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 +0 -8
- package/lib/Track/Device.js +26 -51
- 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 -82
- package/lib/Track/index.js +31 -65
- 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 +0 -67
- package/lib/interfaces/protocol.js +14 -56
- package/lib/interfaces/track.interface.js +15 -28
- package/package.json +3 -6
- 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/lib/Track/Log.js
CHANGED
|
@@ -1,159 +1,95 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
default: () => Log
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
33
6
|
});
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
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 !==
|
|
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,
|
|
74
|
-
const lastModule =
|
|
75
|
-
|
|
76
|
-
...(0,
|
|
77
|
-
type:
|
|
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
|
-
|
|
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 !==
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
101
|
-
...(0,
|
|
102
|
-
type:
|
|
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
|
-
|
|
114
|
-
|
|
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 !==
|
|
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
|
|
127
|
-
|
|
128
|
-
...(0, import_envelope.buildEnvelopeBase)(),
|
|
68
|
+
const payload = {
|
|
69
|
+
...(0, _envelope.buildEnvelopeBase)(),
|
|
129
70
|
error: {
|
|
130
|
-
...(0,
|
|
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,
|
|
139
|
-
method:
|
|
140
|
-
headers: {
|
|
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
|
-
(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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;
|
package/lib/Track/System.d.ts
CHANGED
package/lib/Track/System.js
CHANGED
|
@@ -1,41 +1,23 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
__export(System_exports, {
|
|
22
|
-
default: () => System
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
23
5
|
});
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
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 !==
|
|
35
|
-
innerWidth: typeof window !==
|
|
36
|
-
href: typeof location !==
|
|
37
|
-
systemTime:
|
|
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
|
-
|
|
22
|
+
}
|
|
23
|
+
exports.default = System;
|
package/lib/Track/User.js
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
__export(User_exports, {
|
|
22
|
-
default: () => User
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
23
5
|
});
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class User {
|
|
8
|
+
static _profile = null;
|
|
26
9
|
static setUserProfile(profile) {
|
|
27
|
-
|
|
28
|
-
|
|
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 (!
|
|
32
|
-
throw new Error(
|
|
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
|
-
|
|
21
|
+
}
|
|
22
|
+
exports.default = User;
|
package/lib/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;
|
package/lib/Track/envelope.js
CHANGED
|
@@ -1,100 +1,56 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
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 ===
|
|
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 =
|
|
51
|
-
const device =
|
|
22
|
+
const profile = _User.default.profile;
|
|
23
|
+
const device = _Device.default.data;
|
|
52
24
|
return {
|
|
53
|
-
appId:
|
|
54
|
-
sdkVersion: truncate(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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,
|
|
63
|
-
userName: truncate(profile.userName,
|
|
64
|
-
orgCode: truncate(profile.orgCode,
|
|
65
|
-
orgTitle: truncate(profile.orgTitle,
|
|
66
|
-
dataScopeZonePermissions: truncate(
|
|
67
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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(
|
|
91
|
-
const domain =
|
|
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
|
+
}
|
package/lib/Track/index.js
CHANGED
|
@@ -1,83 +1,49 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
default: () => Track
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
33
6
|
});
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
|
|
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
|
-
|
|
17
|
+
_Config.default.validate(cfg);
|
|
46
18
|
this.run();
|
|
47
19
|
}
|
|
48
20
|
static setUserProfile(profile) {
|
|
49
|
-
|
|
21
|
+
_User.default.setUserProfile(profile);
|
|
50
22
|
}
|
|
51
23
|
static get config() {
|
|
52
|
-
return
|
|
24
|
+
return _Config.default.data;
|
|
53
25
|
}
|
|
54
26
|
static get userProfile() {
|
|
55
|
-
return
|
|
27
|
+
return _User.default.profile;
|
|
56
28
|
}
|
|
57
29
|
static get systemProfile() {
|
|
58
|
-
return
|
|
30
|
+
return _System.default.profile;
|
|
59
31
|
}
|
|
60
|
-
// 需要初始化执行的组件都需在这里初始化调用
|
|
61
32
|
static run() {
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
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
|
-
|
|
37
|
+
_Listener.default.stop();
|
|
72
38
|
}
|
|
73
|
-
|
|
39
|
+
_Beacon.default.start();
|
|
74
40
|
}
|
|
75
|
-
// 获取当前页面模块名称
|
|
76
41
|
static get module() {
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
package/lib/Utils/auth.d.ts
CHANGED
|
@@ -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>;
|