@yysports/tools 2.0.1 → 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 -20
- package/dist/Track/index.js +40 -164
- 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 -20
- package/lib/Track/index.js +39 -91
- 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 -14
- package/dist/Track/core/constants.js +0 -25
- package/dist/Track/core/envelope.d.ts +0 -9
- package/dist/Track/core/envelope.js +0 -54
- package/dist/Track/core/instance.d.ts +0 -108
- package/dist/Track/core/instance.js +0 -365
- 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 -151
- 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 -14
- package/lib/Track/core/constants.js +0 -56
- package/lib/Track/core/envelope.d.ts +0 -9
- package/lib/Track/core/envelope.js +0 -61
- package/lib/Track/core/instance.d.ts +0 -108
- package/lib/Track/core/instance.js +0 -257
- 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 -115
package/lib/Track/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,108 +16,54 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
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
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/Track/index.ts
|
|
20
30
|
var Track_exports = {};
|
|
21
31
|
__export(Track_exports, {
|
|
22
|
-
default: () =>
|
|
32
|
+
default: () => Track
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(Track_exports);
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this._profile = profile;
|
|
37
|
-
return profile;
|
|
38
|
-
})();
|
|
39
|
-
}
|
|
40
|
-
return this._initPromise;
|
|
35
|
+
var import_Beacon = __toESM(require("./Beacon"));
|
|
36
|
+
var import_Config = __toESM(require("./Config"));
|
|
37
|
+
var import_Listener = __toESM(require("./Listener"));
|
|
38
|
+
var import_Log = __toESM(require("./Log"));
|
|
39
|
+
var import_Replay = __toESM(require("./Replay"));
|
|
40
|
+
var import_System = __toESM(require("./System"));
|
|
41
|
+
var import_User = __toESM(require("./User"));
|
|
42
|
+
var Track = class {
|
|
43
|
+
static init(cfg) {
|
|
44
|
+
import_Config.default.validate(cfg);
|
|
45
|
+
this.run();
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!this._instance)
|
|
45
|
-
throw new Error("Track 未初始化,请先调用 Track.init(config)");
|
|
46
|
-
return this._instance;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 发送事件日志(通用事件)
|
|
50
|
-
* - 若未初始化:自动排队等待 init 完成后回放
|
|
51
|
-
*/
|
|
52
|
-
static eventLog(...args) {
|
|
53
|
-
this.ensure().eventLog(...args);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 发送访问/页面曝光日志
|
|
57
|
-
* - 用于记录页面 / 场景进入等行为
|
|
58
|
-
*/
|
|
59
|
-
static visitLog(...args) {
|
|
60
|
-
this.ensure().visitLog(...args);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 发送错误日志
|
|
64
|
-
* - 适用于运行时异常、资源加载失败、接口异常包装等
|
|
65
|
-
*/
|
|
66
|
-
static async errorLog(...args) {
|
|
67
|
-
return this.ensure().errorLog(...args);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 发送接口调用相关日志
|
|
71
|
-
* - 记录接口耗时 / 结果状态
|
|
72
|
-
*/
|
|
73
|
-
static apiLog(...args) {
|
|
74
|
-
this.ensure().apiLog(...args);
|
|
47
|
+
static setUserProfile(profile) {
|
|
48
|
+
import_User.default.setUserProfile(profile);
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/
|
|
79
|
-
static flush() {
|
|
80
|
-
this.ensure().flush();
|
|
50
|
+
static get config() {
|
|
51
|
+
return import_Config.default.data;
|
|
81
52
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* - 停止上报 / 释放资源
|
|
85
|
-
* - 再次使用需重新 init
|
|
86
|
-
*/
|
|
87
|
-
static destroy() {
|
|
88
|
-
if (!this._instance)
|
|
89
|
-
return;
|
|
90
|
-
this._instance.destroy();
|
|
91
|
-
this._instance = null;
|
|
92
|
-
this._initPromise = null;
|
|
93
|
-
this._profile = null;
|
|
53
|
+
static get userProfile() {
|
|
54
|
+
return import_User.default.profile;
|
|
94
55
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
* - 若在 init 前调用:会延迟到实例 ready 后再真正执行
|
|
98
|
-
*/
|
|
99
|
-
static setUserProfile(profile) {
|
|
100
|
-
this.ensure().setUserProfile(profile);
|
|
56
|
+
static get systemProfile() {
|
|
57
|
+
return import_System.default.profile;
|
|
101
58
|
}
|
|
102
|
-
|
|
103
|
-
static
|
|
104
|
-
|
|
59
|
+
// 需要初始化执行的组件都需在这里初始化调用
|
|
60
|
+
static run() {
|
|
61
|
+
import_Listener.default.run();
|
|
62
|
+
import_Replay.default.run();
|
|
63
|
+
import_Beacon.default.updateVersion();
|
|
105
64
|
}
|
|
106
65
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
init: TrackFacade.init.bind(TrackFacade),
|
|
112
|
-
eventLog: TrackFacade.eventLog.bind(TrackFacade),
|
|
113
|
-
visitLog: TrackFacade.visitLog.bind(TrackFacade),
|
|
114
|
-
errorLog: TrackFacade.errorLog.bind(TrackFacade),
|
|
115
|
-
apiLog: TrackFacade.apiLog.bind(TrackFacade),
|
|
116
|
-
flush: TrackFacade.flush.bind(TrackFacade),
|
|
117
|
-
destroy: TrackFacade.destroy.bind(TrackFacade),
|
|
118
|
-
setUserProfile: TrackFacade.setUserProfile.bind(TrackFacade),
|
|
119
|
-
getConfig: TrackFacade.getConfig.bind(TrackFacade)
|
|
120
|
-
};
|
|
121
|
-
var Track_default = Track;
|
|
66
|
+
Track.visitLog = import_Log.default.visitLog.bind(import_Log.default);
|
|
67
|
+
Track.eventLog = import_Log.default.eventLog.bind(import_Log.default);
|
|
68
|
+
Track.errorLog = import_Log.default.errorLog.bind(import_Log.default);
|
|
69
|
+
Track.apiLog = import_Log.default.apiLog.bind(import_Log.default);
|
package/lib/Utils/auth.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AuthCenterUserProfile } from '../interfaces/track.interface';
|
|
2
|
+
/**
|
|
3
|
+
* 获取当前用户在权限中心的信息,并格式化前端路由所需的数据格式
|
|
4
|
+
* @param fetchUserInfo
|
|
5
|
+
* @param fetchMenuBuild
|
|
6
|
+
* @param fetchZoneScope
|
|
7
|
+
* @returns {Promise<AuthCenterUserProfile>}
|
|
8
|
+
*/
|
|
9
|
+
export declare const fetchCurrentUserFromAuthCenter: (fetchUserInfo: () => Promise<any>, fetchMenuBuild: () => Promise<any>, fetchZoneScope?: () => Promise<any>) => Promise<AuthCenterUserProfile>;
|
package/lib/Utils/auth.js
CHANGED
|
@@ -19,27 +19,62 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/Utils/auth.ts
|
|
20
20
|
var auth_exports = {};
|
|
21
21
|
__export(auth_exports, {
|
|
22
|
-
|
|
22
|
+
fetchCurrentUserFromAuthCenter: () => fetchCurrentUserFromAuthCenter
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(auth_exports);
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
var fetchCurrentUserFromAuthCenter = async (fetchUserInfo, fetchMenuBuild, fetchZoneScope) => {
|
|
26
|
+
const [userInfo, menuBuild, zoneScope] = await Promise.all([
|
|
27
|
+
fetchUserInfo == null ? void 0 : fetchUserInfo(),
|
|
28
|
+
fetchMenuBuild == null ? void 0 : fetchMenuBuild(),
|
|
29
|
+
fetchZoneScope == null ? void 0 : fetchZoneScope()
|
|
30
|
+
]);
|
|
31
|
+
const currentUser = {};
|
|
32
|
+
if (userInfo) {
|
|
33
|
+
const { user = {}, roles = [] } = userInfo;
|
|
34
|
+
const { roles: dataScopeRoles = [] } = user;
|
|
35
|
+
const isAdmin = roles.includes("admin");
|
|
36
|
+
Object.assign(currentUser, {
|
|
37
|
+
...user,
|
|
38
|
+
dataScopeRoles,
|
|
39
|
+
// 用户拥有的数据权限角色
|
|
40
|
+
roles,
|
|
41
|
+
// 用户拥有的页面、功能权限列表
|
|
42
|
+
isAdmin
|
|
43
|
+
// 是否为管理员
|
|
37
44
|
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
}
|
|
46
|
+
if (zoneScope) {
|
|
47
|
+
Object.assign(currentUser, {
|
|
48
|
+
dataScopeZonePermissions: zoneScope
|
|
49
|
+
// 用户拥有的数据权限区域列表
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(menuBuild)) {
|
|
53
|
+
const accessPage = [];
|
|
54
|
+
const authLogMap = {};
|
|
55
|
+
const traverseMenu = (menus) => {
|
|
56
|
+
menus.forEach(({ permission, logAction, children }) => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (permission && (currentUser.isAdmin || ((_a = currentUser.roles) == null ? void 0 : _a.includes(permission)))) {
|
|
59
|
+
accessPage.push(permission);
|
|
60
|
+
if (logAction) {
|
|
61
|
+
authLogMap[permission] = logAction;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
65
|
+
traverseMenu(children);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
traverseMenu(menuBuild);
|
|
70
|
+
Object.assign(currentUser, {
|
|
71
|
+
accessPage,
|
|
72
|
+
authLogMap
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return currentUser;
|
|
41
76
|
};
|
|
42
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
78
|
0 && (module.exports = {
|
|
44
|
-
|
|
79
|
+
fetchCurrentUserFromAuthCenter
|
|
45
80
|
});
|
package/lib/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/lib/Utils/route.js
CHANGED
|
@@ -19,59 +19,44 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/Utils/route.ts
|
|
20
20
|
var route_exports = {};
|
|
21
21
|
__export(route_exports, {
|
|
22
|
-
|
|
22
|
+
getModuleNameByUmi: () => getModuleNameByUmi
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(route_exports);
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (redirect) {
|
|
44
|
-
Object.assign(savedRoute, { isRedirect: true });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
|
|
48
|
-
const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
|
|
49
|
-
if (name) {
|
|
50
|
-
nameArr.push(name);
|
|
51
|
-
if (menuNameMap) {
|
|
52
|
-
const menuKey = ["menu", ...nameArr].join(".");
|
|
53
|
-
moduleArr.push(menuNameMap[menuKey]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (access) {
|
|
57
|
-
Object.assign(savedRoute, {
|
|
58
|
-
access: [...savedRoute.access || [], access]
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const routeInfo = {
|
|
62
|
-
name: nameArr,
|
|
63
|
-
module: moduleArr
|
|
64
|
-
};
|
|
65
|
-
Object.assign(savedRoute, routeInfo);
|
|
66
|
-
if (routes2) {
|
|
67
|
-
ergodicLocalMenu(routes2, routeInfo);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
25
|
+
var getModuleNameByUmi = (onRouteChangeArgs, menuNameMap) => {
|
|
26
|
+
const { location, routes } = onRouteChangeArgs;
|
|
27
|
+
const { pathname } = location;
|
|
28
|
+
const currentRouteKey = Object.keys(routes).find(
|
|
29
|
+
(v) => routes[v].path === pathname
|
|
30
|
+
);
|
|
31
|
+
if (!currentRouteKey || routes[currentRouteKey].redirect) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const menuHierarchyKeys = ["menu"];
|
|
35
|
+
const buildMenuHierarchy = (routeId) => {
|
|
36
|
+
const route = routes[routeId];
|
|
37
|
+
if (route == null ? void 0 : route.name) {
|
|
38
|
+
menuHierarchyKeys.splice(1, 0, route.name);
|
|
39
|
+
}
|
|
40
|
+
if (route == null ? void 0 : route.parentId) {
|
|
41
|
+
buildMenuHierarchy(route.parentId);
|
|
42
|
+
}
|
|
70
43
|
};
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
buildMenuHierarchy(currentRouteKey);
|
|
45
|
+
if (menuHierarchyKeys.length === 1) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const menuDisplayNames = [];
|
|
49
|
+
for (let i = 1; i < menuHierarchyKeys.length; i++) {
|
|
50
|
+
const menuKey = menuHierarchyKeys.slice(0, i + 1).join(".");
|
|
51
|
+
const displayName = menuNameMap[menuKey];
|
|
52
|
+
menuDisplayNames.push(displayName);
|
|
53
|
+
}
|
|
54
|
+
if (menuDisplayNames.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return menuDisplayNames.join("-");
|
|
73
58
|
};
|
|
74
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
60
|
0 && (module.exports = {
|
|
76
|
-
|
|
61
|
+
getModuleNameByUmi
|
|
77
62
|
});
|
package/lib/Utils/url.js
CHANGED
|
@@ -34,9 +34,9 @@ var getUrlParams = (str) => {
|
|
|
34
34
|
}
|
|
35
35
|
const searchParams = new URLSearchParams(paramsStr);
|
|
36
36
|
const params = {};
|
|
37
|
-
|
|
38
|
-
params[
|
|
39
|
-
}
|
|
37
|
+
searchParams.forEach((value, key) => {
|
|
38
|
+
params[key] = value;
|
|
39
|
+
});
|
|
40
40
|
return params;
|
|
41
41
|
};
|
|
42
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -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
|
-
domain: string;
|
|
35
|
-
enableReplay?: boolean;
|
|
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
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yysports/tools",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "常用工具函数库",
|
|
5
5
|
"homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"docs:build": "dumi build",
|
|
31
31
|
"doctor": "father doctor",
|
|
32
32
|
"lint": "npm run lint:es && npm run lint:css",
|
|
33
|
-
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
|
|
33
|
+
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\" --allow-empty-input",
|
|
34
34
|
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
35
35
|
"prepare": "husky install && dumi setup",
|
|
36
36
|
"prepublishOnly": "father doctor && npm run build",
|
|
@@ -60,30 +60,30 @@
|
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@babel/runtime": "^7.28.
|
|
63
|
+
"@babel/runtime": "^7.28.4",
|
|
64
64
|
"@rrweb/record": "2.0.0-alpha.18",
|
|
65
65
|
"@rrweb/rrweb-plugin-console-record": "2.0.0-alpha.18",
|
|
66
66
|
"image-conversion": "^2.1.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@ant-design/pro-components": "^2.8.10",
|
|
70
|
-
"@commitlint/cli": "^
|
|
71
|
-
"@commitlint/config-conventional": "^
|
|
72
|
-
"@types/react": "^18.3.
|
|
70
|
+
"@commitlint/cli": "^20.1.0",
|
|
71
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
72
|
+
"@types/react": "^18.3.26",
|
|
73
73
|
"@types/react-dom": "^18.3.7",
|
|
74
|
-
"@umijs/lint": "^4.
|
|
75
|
-
"antd": "^5.
|
|
74
|
+
"@umijs/lint": "^4.5.3",
|
|
75
|
+
"antd": "^5.28.1",
|
|
76
76
|
"dumi": "^2.4.21",
|
|
77
|
-
"eslint": "^
|
|
78
|
-
"father": "^4.6.
|
|
77
|
+
"eslint": "^8.57.1",
|
|
78
|
+
"father": "^4.6.7",
|
|
79
79
|
"husky": "^9.1.7",
|
|
80
|
-
"lint-staged": "^16.
|
|
80
|
+
"lint-staged": "^16.2.6",
|
|
81
81
|
"prettier": "^3.6.2",
|
|
82
|
-
"prettier-plugin-organize-imports": "^4.
|
|
82
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
83
83
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
84
84
|
"react": "^18.3.1",
|
|
85
85
|
"react-dom": "^18.3.1",
|
|
86
|
-
"stylelint": "^16.
|
|
86
|
+
"stylelint": "^16.25.0"
|
|
87
87
|
},
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AuthCenterUserProfile, RouteMapValueType, TrackConfig } from '../../interfaces/track.interface';
|
|
2
|
-
export interface AuthInitResult {
|
|
3
|
-
authCenterUserProfile: AuthCenterUserProfile;
|
|
4
|
-
routesMap: Map<string, RouteMapValueType>;
|
|
5
|
-
authMap: Map<string, string>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* 初始化权限 / 菜单 / 路由配置信息
|
|
9
|
-
* 1. 并行请求:用户权限(getAuth) / 菜单(menuBuild) / 数据域权限(getDataScopeZonePermissions)
|
|
10
|
-
* 2. 生成 routesMap 以及可访问页面 accessPage
|
|
11
|
-
* 3. 生成 authMap(按钮/操作编码 -> 中文描述)
|
|
12
|
-
* 4. 组织返回 AuthCenterUserProfile
|
|
13
|
-
* @param config TrackConfig
|
|
14
|
-
* @returns {AuthInitResult}
|
|
15
|
-
*/
|
|
16
|
-
export declare function initAuthCenterData(config: TrackConfig): Promise<AuthInitResult>;
|
package/dist/Track/core/auth.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
-
var _excluded = ["roles"];
|
|
8
|
-
/**
|
|
9
|
-
* 权限中心 / 菜单 / 数据权限初始化逻辑
|
|
10
|
-
*/
|
|
11
|
-
import { getAuthMapByAuthCenter, getRoutesMap } from "../../Utils";
|
|
12
|
-
/**
|
|
13
|
-
* 初始化权限 / 菜单 / 路由配置信息
|
|
14
|
-
* 1. 并行请求:用户权限(getAuth) / 菜单(menuBuild) / 数据域权限(getDataScopeZonePermissions)
|
|
15
|
-
* 2. 生成 routesMap 以及可访问页面 accessPage
|
|
16
|
-
* 3. 生成 authMap(按钮/操作编码 -> 中文描述)
|
|
17
|
-
* 4. 组织返回 AuthCenterUserProfile
|
|
18
|
-
* @param config TrackConfig
|
|
19
|
-
* @returns {AuthInitResult}
|
|
20
|
-
*/
|
|
21
|
-
export function initAuthCenterData(_x) {
|
|
22
|
-
return _initAuthCenterData.apply(this, arguments);
|
|
23
|
-
}
|
|
24
|
-
function _initAuthCenterData() {
|
|
25
|
-
_initAuthCenterData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
|
|
26
|
-
var getAuth, menuBuild, getDataScopeZonePermissions, menuNameMap, routes, tasks, _yield$Promise$all, _yield$Promise$all2, _yield$Promise$all2$, authInfo, _yield$Promise$all2$2, menuData, dataScopeZonePermissions, _ref, _ref$user, user, _ref$roles, roles, _ref2, dataScopeRoles, restUser, isAdmin, accessPage, routesMap, authMap, profile;
|
|
27
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
|
-
while (1) switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
getAuth = config.getAuth, menuBuild = config.menuBuild, getDataScopeZonePermissions = config.getDataScopeZonePermissions, menuNameMap = config.menuNameMap, routes = config.routes; // 并行触发三个可选任务(若未提供则使用 resolved Promise)
|
|
31
|
-
tasks = [getAuth === null || getAuth === void 0 ? void 0 : getAuth(), menuBuild === null || menuBuild === void 0 ? void 0 : menuBuild(), getDataScopeZonePermissions === null || getDataScopeZonePermissions === void 0 ? void 0 : getDataScopeZonePermissions()];
|
|
32
|
-
_context.next = 4;
|
|
33
|
-
return Promise.all(tasks.map(function (t) {
|
|
34
|
-
return t !== null && t !== void 0 ? t : Promise.resolve();
|
|
35
|
-
}));
|
|
36
|
-
case 4:
|
|
37
|
-
_yield$Promise$all = _context.sent;
|
|
38
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
|
|
39
|
-
_yield$Promise$all2$ = _yield$Promise$all2[0];
|
|
40
|
-
authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
|
|
41
|
-
_yield$Promise$all2$2 = _yield$Promise$all2[1];
|
|
42
|
-
menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
|
|
43
|
-
dataScopeZonePermissions = _yield$Promise$all2[2];
|
|
44
|
-
_ref = authInfo || {}, _ref$user = _ref.user, user = _ref$user === void 0 ? {} : _ref$user, _ref$roles = _ref.roles, roles = _ref$roles === void 0 ? [] : _ref$roles;
|
|
45
|
-
_ref2 = user, dataScopeRoles = _ref2.roles, restUser = _objectWithoutProperties(_ref2, _excluded);
|
|
46
|
-
isAdmin = roles.includes('admin');
|
|
47
|
-
accessPage = [];
|
|
48
|
-
routesMap = new Map();
|
|
49
|
-
if (routes) {
|
|
50
|
-
routesMap = getRoutesMap(routes, menuNameMap);
|
|
51
|
-
routesMap.forEach(function (_ref3) {
|
|
52
|
-
var access = _ref3.access;
|
|
53
|
-
if (!access.length) return;
|
|
54
|
-
if (isAdmin) accessPage.push.apply(accessPage, _toConsumableArray(access));else access.forEach(function (k) {
|
|
55
|
-
return roles.includes(k) && accessPage.push(k);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
authMap = getAuthMapByAuthCenter(menuData);
|
|
60
|
-
profile = _objectSpread(_objectSpread({}, restUser), {}, {
|
|
61
|
-
dataScopeRoles: dataScopeRoles,
|
|
62
|
-
roles: roles,
|
|
63
|
-
accessPage: accessPage,
|
|
64
|
-
isAdmin: isAdmin
|
|
65
|
-
});
|
|
66
|
-
if (dataScopeZonePermissions)
|
|
67
|
-
// 合并数据域区权限结构
|
|
68
|
-
Object.assign(profile, {
|
|
69
|
-
dataScopeZonePermissions: dataScopeZonePermissions
|
|
70
|
-
});
|
|
71
|
-
return _context.abrupt("return", {
|
|
72
|
-
authCenterUserProfile: profile,
|
|
73
|
-
routesMap: routesMap,
|
|
74
|
-
authMap: authMap
|
|
75
|
-
});
|
|
76
|
-
case 21:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee);
|
|
81
|
-
}));
|
|
82
|
-
return _initAuthCenterData.apply(this, arguments);
|
|
83
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Track 常量定义
|
|
3
|
-
* 集中维护埋点内部所需的可配置默认值、端点等信息。
|
|
4
|
-
*/
|
|
5
|
-
export declare const DEFAULT_FLUSH_THRESHOLD = 5;
|
|
6
|
-
export declare const DEFAULT_MAX_WAIT_MS = 5000;
|
|
7
|
-
export declare const TRACK_ENDPOINT = "/pousheng-guard/api/track";
|
|
8
|
-
export declare const APP_VERSION_ENDPOINT = "/pousheng-guard/api/apps/version/update";
|
|
9
|
-
export declare const ERROR_TRACK_ENDPOINT = "/pousheng-guard/api/track/error";
|
|
10
|
-
export declare const ERROR_REPLAY_ENDPOINT = "/pousheng-guard/api/track/error-replay/";
|
|
11
|
-
export declare const DEFAULT_REPLAY_CHECKOUT_NMS: number;
|
|
12
|
-
export declare const DEFAULT_REPLAY_MAX_EVENTS = 1000;
|
|
13
|
-
export declare const DEFAULT_REPLAY_MAX_BYTES: number;
|
|
14
|
-
export declare const DEFAULT_ERROR_THROTTLE_MS = 3000;
|