@yysports/tools 2.0.2 → 2.2.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/dist/Track/Beacon.d.ts +6 -0
- package/dist/Track/Beacon.js +58 -0
- package/dist/Track/Config.d.ts +11 -0
- package/dist/Track/Config.js +34 -0
- package/dist/Track/Listener.d.ts +5 -0
- package/dist/Track/Listener.js +46 -0
- package/dist/Track/Log.d.ts +8 -0
- package/dist/Track/Log.js +100 -0
- package/dist/Track/Replay.d.ts +6 -0
- package/dist/Track/Replay.js +77 -0
- package/dist/Track/System.d.ts +5 -0
- package/dist/Track/System.js +24 -0
- package/dist/Track/User.d.ts +6 -0
- package/dist/Track/User.js +29 -0
- package/dist/Track/index.d.ts +15 -17
- package/dist/Track/index.js +56 -67
- package/dist/Utils/auth.d.ts +9 -2
- package/dist/Utils/auth.js +80 -20
- package/dist/Utils/route.d.ts +11 -3
- package/dist/Utils/route.js +49 -56
- package/dist/Utils/url.js +3 -13
- package/dist/interfaces/track.interface.d.ts +1 -80
- package/dist/interfaces/track.interface.js +1 -5
- package/lib/Track/Beacon.d.ts +6 -0
- package/lib/Track/Beacon.js +73 -0
- package/lib/Track/Config.d.ts +11 -0
- package/lib/Track/{core/queue.js → Config.js} +23 -27
- package/lib/Track/Listener.d.ts +5 -0
- package/lib/Track/Listener.js +62 -0
- package/lib/Track/Log.d.ts +8 -0
- package/lib/Track/Log.js +95 -0
- package/lib/Track/Replay.d.ts +6 -0
- package/lib/Track/Replay.js +79 -0
- package/lib/Track/System.d.ts +5 -0
- package/lib/Track/{core/router.js → System.js} +18 -20
- package/lib/Track/User.d.ts +6 -0
- package/lib/Track/User.js +40 -0
- package/lib/Track/index.d.ts +15 -17
- package/lib/Track/index.js +45 -39
- package/lib/Utils/auth.d.ts +9 -2
- package/lib/Utils/auth.js +52 -17
- package/lib/Utils/route.d.ts +11 -3
- package/lib/Utils/route.js +34 -49
- package/lib/Utils/url.js +3 -3
- package/lib/interfaces/track.interface.d.ts +1 -80
- package/package.json +13 -13
- package/dist/Track/core/auth.d.ts +0 -16
- package/dist/Track/core/auth.js +0 -83
- package/dist/Track/core/constants.d.ts +0 -17
- package/dist/Track/core/constants.js +0 -34
- package/dist/Track/core/envelope.d.ts +0 -9
- package/dist/Track/core/envelope.js +0 -54
- package/dist/Track/core/index.d.ts +0 -22
- package/dist/Track/core/index.js +0 -23
- package/dist/Track/core/instance.d.ts +0 -108
- package/dist/Track/core/instance.js +0 -375
- package/dist/Track/core/lifecycle.d.ts +0 -18
- package/dist/Track/core/lifecycle.js +0 -59
- package/dist/Track/core/profile.d.ts +0 -5
- package/dist/Track/core/profile.js +0 -30
- package/dist/Track/core/queue.d.ts +0 -13
- package/dist/Track/core/queue.js +0 -36
- package/dist/Track/core/replay.d.ts +0 -17
- package/dist/Track/core/replay.js +0 -117
- package/dist/Track/core/router.d.ts +0 -6
- package/dist/Track/core/router.js +0 -15
- package/dist/Track/core/system.d.ts +0 -14
- package/dist/Track/core/system.js +0 -36
- package/dist/Track/core/transport.d.ts +0 -18
- package/dist/Track/core/transport.js +0 -165
- package/lib/Track/core/auth.d.ts +0 -16
- package/lib/Track/core/auth.js +0 -67
- package/lib/Track/core/constants.d.ts +0 -17
- package/lib/Track/core/constants.js +0 -65
- package/lib/Track/core/envelope.d.ts +0 -9
- package/lib/Track/core/envelope.js +0 -61
- package/lib/Track/core/index.d.ts +0 -22
- package/lib/Track/core/index.js +0 -51
- package/lib/Track/core/instance.d.ts +0 -108
- package/lib/Track/core/instance.js +0 -266
- package/lib/Track/core/lifecycle.d.ts +0 -18
- package/lib/Track/core/lifecycle.js +0 -74
- package/lib/Track/core/profile.d.ts +0 -5
- package/lib/Track/core/profile.js +0 -47
- package/lib/Track/core/queue.d.ts +0 -13
- package/lib/Track/core/replay.d.ts +0 -17
- package/lib/Track/core/replay.js +0 -131
- package/lib/Track/core/router.d.ts +0 -6
- package/lib/Track/core/system.d.ts +0 -14
- package/lib/Track/core/system.js +0 -53
- package/lib/Track/core/transport.d.ts +0 -18
- package/lib/Track/core/transport.js +0 -128
package/dist/Utils/auth.js
CHANGED
|
@@ -1,22 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
/**
|
|
6
|
+
* 获取当前用户在权限中心的信息,并格式化前端路由所需的数据格式
|
|
7
|
+
* @param fetchUserInfo
|
|
8
|
+
* @param fetchMenuBuild
|
|
9
|
+
* @param fetchZoneScope
|
|
10
|
+
* @returns {Promise<AuthCenterUserProfile>}
|
|
11
|
+
*/
|
|
12
|
+
export var fetchCurrentUserFromAuthCenter = /*#__PURE__*/function () {
|
|
13
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fetchUserInfo, fetchMenuBuild, fetchZoneScope) {
|
|
14
|
+
var _yield$Promise$all, _yield$Promise$all2, userInfo, menuBuild, zoneScope, currentUser, _userInfo$user, user, _userInfo$roles, roles, _user$roles, dataScopeRoles, isAdmin, accessPage, authLogMap, traverseMenu;
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
_context.next = 2;
|
|
19
|
+
return Promise.all([fetchUserInfo === null || fetchUserInfo === void 0 ? void 0 : fetchUserInfo(), fetchMenuBuild === null || fetchMenuBuild === void 0 ? void 0 : fetchMenuBuild(), fetchZoneScope === null || fetchZoneScope === void 0 ? void 0 : fetchZoneScope()]);
|
|
20
|
+
case 2:
|
|
21
|
+
_yield$Promise$all = _context.sent;
|
|
22
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
|
|
23
|
+
userInfo = _yield$Promise$all2[0];
|
|
24
|
+
menuBuild = _yield$Promise$all2[1];
|
|
25
|
+
zoneScope = _yield$Promise$all2[2];
|
|
26
|
+
currentUser = {};
|
|
27
|
+
if (userInfo) {
|
|
28
|
+
_userInfo$user = userInfo.user, user = _userInfo$user === void 0 ? {} : _userInfo$user, _userInfo$roles = userInfo.roles, roles = _userInfo$roles === void 0 ? [] : _userInfo$roles;
|
|
29
|
+
_user$roles = user.roles, dataScopeRoles = _user$roles === void 0 ? [] : _user$roles;
|
|
30
|
+
isAdmin = roles.includes('admin');
|
|
31
|
+
Object.assign(currentUser, _objectSpread(_objectSpread({}, user), {}, {
|
|
32
|
+
dataScopeRoles: dataScopeRoles,
|
|
33
|
+
// 用户拥有的数据权限角色
|
|
34
|
+
roles: roles,
|
|
35
|
+
// 用户拥有的页面、功能权限列表
|
|
36
|
+
isAdmin: isAdmin // 是否为管理员
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
if (zoneScope) {
|
|
40
|
+
Object.assign(currentUser, {
|
|
41
|
+
dataScopeZonePermissions: zoneScope // 用户拥有的数据权限区域列表
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(menuBuild)) {
|
|
45
|
+
// 有权限的页面列表
|
|
46
|
+
accessPage = []; // 权限按钮映射表
|
|
47
|
+
authLogMap = {}; // 递归遍历菜单数据,提取权限页面和权限按钮
|
|
48
|
+
traverseMenu = function traverseMenu(menus) {
|
|
49
|
+
menus.forEach(function (_ref2) {
|
|
50
|
+
var _currentUser$roles;
|
|
51
|
+
var permission = _ref2.permission,
|
|
52
|
+
logAction = _ref2.logAction,
|
|
53
|
+
children = _ref2.children;
|
|
54
|
+
if (permission && (currentUser.isAdmin || (_currentUser$roles = currentUser.roles) !== null && _currentUser$roles !== void 0 && _currentUser$roles.includes(permission))) {
|
|
55
|
+
accessPage.push(permission);
|
|
56
|
+
if (logAction) {
|
|
57
|
+
authLogMap[permission] = logAction;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// 递归处理子菜单
|
|
61
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
62
|
+
traverseMenu(children);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
traverseMenu(menuBuild);
|
|
67
|
+
Object.assign(currentUser, {
|
|
68
|
+
accessPage: accessPage,
|
|
69
|
+
authLogMap: authLogMap
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return _context.abrupt("return", currentUser);
|
|
73
|
+
case 12:
|
|
74
|
+
case "end":
|
|
75
|
+
return _context.stop();
|
|
14
76
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
77
|
+
}, _callee);
|
|
78
|
+
}));
|
|
79
|
+
return function fetchCurrentUserFromAuthCenter(_x, _x2, _x3) {
|
|
80
|
+
return _ref.apply(this, arguments);
|
|
19
81
|
};
|
|
20
|
-
|
|
21
|
-
return authMap;
|
|
22
|
-
};
|
|
82
|
+
}();
|
package/dist/Utils/route.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 适用于 Umi 框架的路由模块名称获取
|
|
3
|
+
* @param onRouteChangeArgs onRouteChange的参数
|
|
4
|
+
* @param menuNameMap 国际化菜单名称映射表
|
|
5
|
+
* @returns {undefined | string} 模块名称,格式如 "菜单1-子菜单A-子菜单a1",如果无法获取则返回 undefined
|
|
6
|
+
*/
|
|
7
|
+
export declare const getModuleNameByUmi: (onRouteChangeArgs: {
|
|
8
|
+
location: any;
|
|
9
|
+
routes: any;
|
|
10
|
+
}, menuNameMap?: {
|
|
3
11
|
[key: string]: string;
|
|
4
|
-
} | undefined) =>
|
|
12
|
+
} | undefined) => string | undefined;
|
package/dist/Utils/route.js
CHANGED
|
@@ -1,58 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
|
|
33
|
-
var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
|
|
34
|
-
if (name) {
|
|
35
|
-
nameArr.push(name);
|
|
36
|
-
if (menuNameMap) {
|
|
37
|
-
var menuKey = ['menu'].concat(_toConsumableArray(nameArr)).join('.');
|
|
38
|
-
moduleArr.push(menuNameMap[menuKey]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (access) {
|
|
42
|
-
Object.assign(savedRoute, {
|
|
43
|
-
access: [].concat(_toConsumableArray(savedRoute.access || []), [access])
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
var routeInfo = {
|
|
47
|
-
name: nameArr,
|
|
48
|
-
module: moduleArr
|
|
49
|
-
};
|
|
50
|
-
Object.assign(savedRoute, routeInfo);
|
|
51
|
-
if (routes) {
|
|
52
|
-
ergodicLocalMenu(routes, routeInfo);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* 适用于 Umi 框架的路由模块名称获取
|
|
3
|
+
* @param onRouteChangeArgs onRouteChange的参数
|
|
4
|
+
* @param menuNameMap 国际化菜单名称映射表
|
|
5
|
+
* @returns {undefined | string} 模块名称,格式如 "菜单1-子菜单A-子菜单a1",如果无法获取则返回 undefined
|
|
6
|
+
*/
|
|
7
|
+
export var getModuleNameByUmi = function getModuleNameByUmi(onRouteChangeArgs, menuNameMap) {
|
|
8
|
+
var location = onRouteChangeArgs.location,
|
|
9
|
+
routes = onRouteChangeArgs.routes;
|
|
10
|
+
var pathname = location.pathname;
|
|
11
|
+
var currentRouteKey = Object.keys(routes).find(function (v) {
|
|
12
|
+
return routes[v].path === pathname;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// 如果路由不存在或是重定向路由,直接返回
|
|
16
|
+
if (!currentRouteKey || routes[currentRouteKey].redirect) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 构建菜单层级路径(从根节点到当前节点)
|
|
21
|
+
var menuHierarchyKeys = ['menu'];
|
|
22
|
+
var buildMenuHierarchy = function buildMenuHierarchy(routeId) {
|
|
23
|
+
var route = routes[routeId];
|
|
24
|
+
if (route !== null && route !== void 0 && route.name) {
|
|
25
|
+
// 将当前菜单名插入到数组开头(menu之后)
|
|
26
|
+
menuHierarchyKeys.splice(1, 0, route.name);
|
|
27
|
+
}
|
|
28
|
+
// 递归处理父级菜单
|
|
29
|
+
if (route !== null && route !== void 0 && route.parentId) {
|
|
30
|
+
buildMenuHierarchy(route.parentId);
|
|
31
|
+
}
|
|
55
32
|
};
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
buildMenuHierarchy(currentRouteKey);
|
|
34
|
+
|
|
35
|
+
// 如果只有根节点,说明没有有效的菜单层级
|
|
36
|
+
if (menuHierarchyKeys.length === 1) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 构建完整的菜单显示名称数组
|
|
41
|
+
var menuDisplayNames = [];
|
|
42
|
+
for (var i = 1; i < menuHierarchyKeys.length; i++) {
|
|
43
|
+
var menuKey = menuHierarchyKeys.slice(0, i + 1).join('.');
|
|
44
|
+
var displayName = menuNameMap[menuKey];
|
|
45
|
+
menuDisplayNames.push(displayName);
|
|
46
|
+
}
|
|
47
|
+
if (menuDisplayNames.length === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return menuDisplayNames.join('-');
|
|
58
51
|
};
|
package/dist/Utils/url.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
1
|
export var getUrlParams = function getUrlParams(str) {
|
|
3
2
|
var paramsStr = location.search;
|
|
4
3
|
if (typeof str === 'string') {
|
|
@@ -11,17 +10,8 @@ export var getUrlParams = function getUrlParams(str) {
|
|
|
11
10
|
}
|
|
12
11
|
var searchParams = new URLSearchParams(paramsStr);
|
|
13
12
|
var params = {};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
18
|
-
var v = _step.value;
|
|
19
|
-
params[v[0]] = v[1];
|
|
20
|
-
}
|
|
21
|
-
} catch (err) {
|
|
22
|
-
_iterator.e(err);
|
|
23
|
-
} finally {
|
|
24
|
-
_iterator.f();
|
|
25
|
-
}
|
|
13
|
+
searchParams.forEach(function (value, key) {
|
|
14
|
+
params[key] = value;
|
|
15
|
+
});
|
|
26
16
|
return params;
|
|
27
17
|
};
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
export type LocalRouteItemType = {
|
|
2
|
-
access?: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
parentPath?: string;
|
|
5
|
-
path?: string;
|
|
6
|
-
routes?: LocalRouteItemType[];
|
|
7
|
-
};
|
|
8
|
-
export type AuthMenuItemType = {
|
|
9
|
-
logAction: any;
|
|
10
|
-
name: string;
|
|
11
|
-
meta?: {
|
|
12
|
-
title: string;
|
|
13
|
-
};
|
|
14
|
-
permission?: string;
|
|
15
|
-
children?: AuthMenuItemType[];
|
|
16
|
-
path?: string;
|
|
17
|
-
builtIn?: boolean;
|
|
18
|
-
};
|
|
19
|
-
export type MenuNameMapType = {
|
|
20
|
-
[key: string]: string;
|
|
21
|
-
};
|
|
22
|
-
export interface TrackConfig {
|
|
23
|
-
appId: string;
|
|
24
|
-
userProfile?: UserProfile;
|
|
25
|
-
base?: string;
|
|
26
|
-
getAuth?: () => Promise<any>;
|
|
27
|
-
menuBuild?: () => Promise<AuthMenuItemType[]>;
|
|
28
|
-
menuNameMap?: MenuNameMapType;
|
|
29
|
-
routes?: RouteType[];
|
|
30
|
-
getDataScopeZonePermissions?: () => Promise<{
|
|
31
|
-
zoneId: number;
|
|
32
|
-
zoneName: string;
|
|
33
|
-
}[]>;
|
|
34
|
-
enableReplay?: boolean;
|
|
35
|
-
env: 'dev' | 'test' | 'prod';
|
|
36
|
-
}
|
|
37
1
|
export declare enum TrackTypeEnum {
|
|
38
2
|
error = "\u9519\u8BEF\u4FE1\u606F",
|
|
39
3
|
visit = "\u9875\u9762\u8BBF\u95EE",
|
|
@@ -56,7 +20,7 @@ export interface AuthCenterUserProfile {
|
|
|
56
20
|
department?: string;
|
|
57
21
|
email?: string;
|
|
58
22
|
gender?: string;
|
|
59
|
-
phone
|
|
23
|
+
phone: string;
|
|
60
24
|
roles?: string[];
|
|
61
25
|
accessPage?: string[];
|
|
62
26
|
orgCode: string;
|
|
@@ -83,46 +47,3 @@ export interface SystemProfile {
|
|
|
83
47
|
href: string;
|
|
84
48
|
systemTime: Date;
|
|
85
49
|
}
|
|
86
|
-
export interface CustomizeProfile {
|
|
87
|
-
content: string;
|
|
88
|
-
module: string;
|
|
89
|
-
}
|
|
90
|
-
export interface ErrorProfile {
|
|
91
|
-
fileName: string;
|
|
92
|
-
message: string;
|
|
93
|
-
}
|
|
94
|
-
export type RouteType = {
|
|
95
|
-
path?: string;
|
|
96
|
-
redirect?: string;
|
|
97
|
-
name?: string;
|
|
98
|
-
access?: string;
|
|
99
|
-
routes?: RouteType[];
|
|
100
|
-
[key: string]: any;
|
|
101
|
-
};
|
|
102
|
-
export type RouteMapValueType = {
|
|
103
|
-
access: string[];
|
|
104
|
-
name: string[];
|
|
105
|
-
module: string[];
|
|
106
|
-
isRedirect: boolean;
|
|
107
|
-
};
|
|
108
|
-
export type AuthDataType = {
|
|
109
|
-
children: AuthDataType[];
|
|
110
|
-
name?: string;
|
|
111
|
-
logAction?: string;
|
|
112
|
-
permission?: string;
|
|
113
|
-
meta?: {
|
|
114
|
-
title: string;
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
export interface TrackEventEnvelope extends SystemProfile, UserProfile, CustomizeProfile {
|
|
118
|
-
appId: string;
|
|
119
|
-
type: TrackType;
|
|
120
|
-
/**
|
|
121
|
-
* V2.0.0 版本后为非必填字段,如需传入请使用JSON.stringify格式化为字符串
|
|
122
|
-
*/
|
|
123
|
-
log?: string;
|
|
124
|
-
/**
|
|
125
|
-
* V2.0.0 版本后为非必填字段,错误类型时携带回放片段
|
|
126
|
-
*/
|
|
127
|
-
replay?: string;
|
|
128
|
-
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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);
|
|
28
|
+
|
|
29
|
+
// src/Track/Beacon.ts
|
|
30
|
+
var Beacon_exports = {};
|
|
31
|
+
__export(Beacon_exports, {
|
|
32
|
+
default: () => Beacon
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Beacon_exports);
|
|
35
|
+
var import_package = require("../../package.json");
|
|
36
|
+
var import_Config = __toESM(require("./Config"));
|
|
37
|
+
var Beacon = class {
|
|
38
|
+
// 加入Beacon消息队列,检测超过5条记录时自动发送
|
|
39
|
+
static push(data) {
|
|
40
|
+
this._queue.push(data);
|
|
41
|
+
if (this._queue.length >= 5) {
|
|
42
|
+
this.send();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 发送Beacon消息
|
|
46
|
+
static send(data, api = "/pousheng-guard/api/track") {
|
|
47
|
+
const sendData = data ? data : this._queue.splice(0, 5);
|
|
48
|
+
if (!sendData || Array.isArray(sendData) && sendData.length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const blob = new Blob([JSON.stringify(sendData)], {
|
|
52
|
+
type: "application/json"
|
|
53
|
+
});
|
|
54
|
+
navigator == null ? void 0 : navigator.sendBeacon(`${import_Config.default.data.domain}${api}`, blob);
|
|
55
|
+
}
|
|
56
|
+
// 更新Track版本号
|
|
57
|
+
static updateVersion() {
|
|
58
|
+
const storageKey = `__TrackVersion__`;
|
|
59
|
+
const cachedVersion = localStorage.getItem(storageKey);
|
|
60
|
+
if (cachedVersion !== import_package.version) {
|
|
61
|
+
this.send(
|
|
62
|
+
{
|
|
63
|
+
appId: import_Config.default.data.appId,
|
|
64
|
+
version: import_package.version
|
|
65
|
+
},
|
|
66
|
+
"/pousheng-guard/api/apps/version/update"
|
|
67
|
+
);
|
|
68
|
+
localStorage.setItem(storageKey, import_package.version);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// 消息队列
|
|
73
|
+
Beacon._queue = [];
|
|
@@ -16,34 +16,30 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/Track/
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/Track/Config.ts
|
|
20
|
+
var Config_exports = {};
|
|
21
|
+
__export(Config_exports, {
|
|
22
|
+
default: () => Config
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
module.exports = __toCommonJS(Config_exports);
|
|
25
|
+
var Config = class {
|
|
26
|
+
static validate(config) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (!((_a = config.appId) == null ? void 0 : _a.trim())) {
|
|
29
|
+
throw new Error("Config: appId is required");
|
|
30
|
+
}
|
|
31
|
+
if (!((_b = config.domain) == null ? void 0 : _b.trim())) {
|
|
32
|
+
throw new Error("Config: domain is required");
|
|
33
|
+
}
|
|
34
|
+
Object.assign(this._data, config);
|
|
28
35
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.items.push(item);
|
|
32
|
-
}
|
|
33
|
-
/** 当前元素数量 */
|
|
34
|
-
size() {
|
|
35
|
-
return this.items.length;
|
|
36
|
-
}
|
|
37
|
-
/** 取出并清空所有元素(返回快照) */
|
|
38
|
-
drain() {
|
|
39
|
-
if (!this.items.length)
|
|
40
|
-
return [];
|
|
41
|
-
const copy = this.items.slice();
|
|
42
|
-
this.items.length = 0;
|
|
43
|
-
return copy;
|
|
36
|
+
static get data() {
|
|
37
|
+
return this._data;
|
|
44
38
|
}
|
|
45
39
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
Config._data = {
|
|
41
|
+
appId: "",
|
|
42
|
+
domain: "",
|
|
43
|
+
autoReportError: true,
|
|
44
|
+
enableReplay: true
|
|
45
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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);
|
|
28
|
+
|
|
29
|
+
// src/Track/Listener.ts
|
|
30
|
+
var Listener_exports = {};
|
|
31
|
+
__export(Listener_exports, {
|
|
32
|
+
default: () => Listener
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Listener_exports);
|
|
35
|
+
var import_Beacon = __toESM(require("./Beacon"));
|
|
36
|
+
var import_Config = __toESM(require("./Config"));
|
|
37
|
+
var import_Log = __toESM(require("./Log"));
|
|
38
|
+
var Listener = class {
|
|
39
|
+
static run() {
|
|
40
|
+
if (this._loaded || !import_Config.default.data.autoReportError) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
window.addEventListener("error", (event) => {
|
|
44
|
+
if (this._reporter) {
|
|
45
|
+
clearTimeout(this._reporter);
|
|
46
|
+
}
|
|
47
|
+
this._reporter = setTimeout(() => {
|
|
48
|
+
import_Beacon.default.send();
|
|
49
|
+
import_Log.default.errorLog(event.message);
|
|
50
|
+
this._reporter = null;
|
|
51
|
+
}, 1e3);
|
|
52
|
+
});
|
|
53
|
+
document.addEventListener("visibilitychange", () => {
|
|
54
|
+
if ((document == null ? void 0 : document.visibilityState) === "hidden") {
|
|
55
|
+
import_Beacon.default.send();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
this._loaded = true;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
Listener._loaded = false;
|
|
62
|
+
Listener._reporter = null;
|