@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.
Files changed (92) hide show
  1. package/dist/Track/Beacon.d.ts +6 -0
  2. package/dist/Track/Beacon.js +58 -0
  3. package/dist/Track/Config.d.ts +11 -0
  4. package/dist/Track/Config.js +34 -0
  5. package/dist/Track/Listener.d.ts +5 -0
  6. package/dist/Track/Listener.js +46 -0
  7. package/dist/Track/Log.d.ts +8 -0
  8. package/dist/Track/Log.js +100 -0
  9. package/dist/Track/Replay.d.ts +6 -0
  10. package/dist/Track/Replay.js +77 -0
  11. package/dist/Track/System.d.ts +5 -0
  12. package/dist/Track/System.js +24 -0
  13. package/dist/Track/User.d.ts +6 -0
  14. package/dist/Track/User.js +29 -0
  15. package/dist/Track/index.d.ts +15 -17
  16. package/dist/Track/index.js +56 -67
  17. package/dist/Utils/auth.d.ts +9 -2
  18. package/dist/Utils/auth.js +80 -20
  19. package/dist/Utils/route.d.ts +11 -3
  20. package/dist/Utils/route.js +49 -56
  21. package/dist/Utils/url.js +3 -13
  22. package/dist/interfaces/track.interface.d.ts +1 -80
  23. package/dist/interfaces/track.interface.js +1 -5
  24. package/lib/Track/Beacon.d.ts +6 -0
  25. package/lib/Track/Beacon.js +73 -0
  26. package/lib/Track/Config.d.ts +11 -0
  27. package/lib/Track/{core/queue.js → Config.js} +23 -27
  28. package/lib/Track/Listener.d.ts +5 -0
  29. package/lib/Track/Listener.js +62 -0
  30. package/lib/Track/Log.d.ts +8 -0
  31. package/lib/Track/Log.js +95 -0
  32. package/lib/Track/Replay.d.ts +6 -0
  33. package/lib/Track/Replay.js +79 -0
  34. package/lib/Track/System.d.ts +5 -0
  35. package/lib/Track/{core/router.js → System.js} +18 -20
  36. package/lib/Track/User.d.ts +6 -0
  37. package/lib/Track/User.js +40 -0
  38. package/lib/Track/index.d.ts +15 -17
  39. package/lib/Track/index.js +45 -39
  40. package/lib/Utils/auth.d.ts +9 -2
  41. package/lib/Utils/auth.js +52 -17
  42. package/lib/Utils/route.d.ts +11 -3
  43. package/lib/Utils/route.js +34 -49
  44. package/lib/Utils/url.js +3 -3
  45. package/lib/interfaces/track.interface.d.ts +1 -80
  46. package/package.json +13 -13
  47. package/dist/Track/core/auth.d.ts +0 -16
  48. package/dist/Track/core/auth.js +0 -83
  49. package/dist/Track/core/constants.d.ts +0 -17
  50. package/dist/Track/core/constants.js +0 -34
  51. package/dist/Track/core/envelope.d.ts +0 -9
  52. package/dist/Track/core/envelope.js +0 -54
  53. package/dist/Track/core/index.d.ts +0 -22
  54. package/dist/Track/core/index.js +0 -23
  55. package/dist/Track/core/instance.d.ts +0 -108
  56. package/dist/Track/core/instance.js +0 -375
  57. package/dist/Track/core/lifecycle.d.ts +0 -18
  58. package/dist/Track/core/lifecycle.js +0 -59
  59. package/dist/Track/core/profile.d.ts +0 -5
  60. package/dist/Track/core/profile.js +0 -30
  61. package/dist/Track/core/queue.d.ts +0 -13
  62. package/dist/Track/core/queue.js +0 -36
  63. package/dist/Track/core/replay.d.ts +0 -17
  64. package/dist/Track/core/replay.js +0 -117
  65. package/dist/Track/core/router.d.ts +0 -6
  66. package/dist/Track/core/router.js +0 -15
  67. package/dist/Track/core/system.d.ts +0 -14
  68. package/dist/Track/core/system.js +0 -36
  69. package/dist/Track/core/transport.d.ts +0 -18
  70. package/dist/Track/core/transport.js +0 -165
  71. package/lib/Track/core/auth.d.ts +0 -16
  72. package/lib/Track/core/auth.js +0 -67
  73. package/lib/Track/core/constants.d.ts +0 -17
  74. package/lib/Track/core/constants.js +0 -65
  75. package/lib/Track/core/envelope.d.ts +0 -9
  76. package/lib/Track/core/envelope.js +0 -61
  77. package/lib/Track/core/index.d.ts +0 -22
  78. package/lib/Track/core/index.js +0 -51
  79. package/lib/Track/core/instance.d.ts +0 -108
  80. package/lib/Track/core/instance.js +0 -266
  81. package/lib/Track/core/lifecycle.d.ts +0 -18
  82. package/lib/Track/core/lifecycle.js +0 -74
  83. package/lib/Track/core/profile.d.ts +0 -5
  84. package/lib/Track/core/profile.js +0 -47
  85. package/lib/Track/core/queue.d.ts +0 -13
  86. package/lib/Track/core/replay.d.ts +0 -17
  87. package/lib/Track/core/replay.js +0 -131
  88. package/lib/Track/core/router.d.ts +0 -6
  89. package/lib/Track/core/system.d.ts +0 -14
  90. package/lib/Track/core/system.js +0 -53
  91. package/lib/Track/core/transport.d.ts +0 -18
  92. package/lib/Track/core/transport.js +0 -128
@@ -1,22 +1,82 @@
1
- // 根据权限中心返回的数据,生成路由映射及权限数据映射
2
- export var getAuthMapByAuthCenter = function getAuthMapByAuthCenter(authData) {
3
- var authMap = new Map();
4
- var ergodicAuthMenu = function ergodicAuthMenu(authCenterData) {
5
- authCenterData.forEach(function (menu) {
6
- var permission = menu.permission,
7
- name = menu.name,
8
- logAction = menu.logAction,
9
- children = menu.children,
10
- meta = menu.meta;
11
- if (permission) {
12
- var authLog = logAction || (meta === null || meta === void 0 ? void 0 : meta.title) || name || '权限校验';
13
- authMap.set(permission, authLog);
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
- if (Array.isArray(children) && children.length > 0) {
16
- ergodicAuthMenu(children);
17
- }
18
- });
77
+ }, _callee);
78
+ }));
79
+ return function fetchCurrentUserFromAuthCenter(_x, _x2, _x3) {
80
+ return _ref.apply(this, arguments);
19
81
  };
20
- ergodicAuthMenu(authData);
21
- return authMap;
22
- };
82
+ }();
@@ -1,4 +1,12 @@
1
- import { RouteMapValueType, RouteType } from '../interfaces/track.interface';
2
- export declare const getRoutesMap: (routes: RouteType[], menuNameMap?: {
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) => Map<string, RouteMapValueType>;
12
+ } | undefined) => string | undefined;
@@ -1,58 +1,51 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- // 根据本地路由配置文件、路由地址名称映射、当前用户权限,生成路由映射关系表
3
- export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
4
- var routesMap = new Map();
5
- var ergodicLocalMenu = function ergodicLocalMenu(rs, parentMenu) {
6
- rs.forEach(function (route) {
7
- var path = route.path,
8
- access = route.access,
9
- name = route.name,
10
- routes = route.routes,
11
- redirect = route.redirect;
12
- if (!path) {
13
- return;
14
- }
15
- // 初始化路由信息
16
- var savedRoute = routesMap.get(path);
17
- if (!savedRoute) {
18
- routesMap.set(path, {
19
- access: [],
20
- name: [],
21
- module: [],
22
- isRedirect: false
23
- });
24
- savedRoute = routesMap.get(path);
25
- }
26
- if (redirect) {
27
- Object.assign(savedRoute, {
28
- isRedirect: true
29
- });
30
- return;
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
- ergodicLocalMenu(routes);
57
- return routesMap;
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
- var _iterator = _createForOfIteratorHelper(searchParams.entries()),
15
- _step;
16
- try {
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?: string;
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
- }
@@ -11,8 +11,4 @@ export var TrackTypeEnum = /*#__PURE__*/function (TrackTypeEnum) {
11
11
 
12
12
  // 权限中心用户信息
13
13
 
14
- // 系统信息
15
-
16
- // 自定义埋点信息
17
-
18
- // 错误信息
14
+ // 系统信息
@@ -0,0 +1,6 @@
1
+ export default class Beacon {
2
+ private static _queue;
3
+ static push(data: any): void;
4
+ static send(data?: object | Array<any>, api?: string): void;
5
+ static updateVersion(): void;
6
+ }
@@ -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 = [];
@@ -0,0 +1,11 @@
1
+ export interface IConfig {
2
+ appId: string;
3
+ domain: string;
4
+ autoReportError?: boolean;
5
+ enableReplay?: boolean;
6
+ }
7
+ export default class Config {
8
+ private static _data;
9
+ static validate(config: IConfig): void;
10
+ static get data(): IConfig;
11
+ }
@@ -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/core/queue.ts
20
- var queue_exports = {};
21
- __export(queue_exports, {
22
- TrackQueue: () => TrackQueue
19
+ // src/Track/Config.ts
20
+ var Config_exports = {};
21
+ __export(Config_exports, {
22
+ default: () => Config
23
23
  });
24
- module.exports = __toCommonJS(queue_exports);
25
- var TrackQueue = class {
26
- constructor() {
27
- this.items = [];
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
- push(item) {
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
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- TrackQueue
49
- });
40
+ Config._data = {
41
+ appId: "",
42
+ domain: "",
43
+ autoReportError: true,
44
+ enableReplay: true
45
+ };
@@ -0,0 +1,5 @@
1
+ export default class Listener {
2
+ private static _loaded;
3
+ private static _reporter;
4
+ static run(): void;
5
+ }
@@ -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;
@@ -0,0 +1,8 @@
1
+ export default class Log {
2
+ private static _module;
3
+ private static _commonProps;
4
+ static visitLog(module: string): void;
5
+ static eventLog(content: string): void;
6
+ static errorLog(message: string): Promise<void>;
7
+ static apiLog(log: string): void;
8
+ }