@yysports/tools 1.1.0 → 2.0.1
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/core/auth.d.ts +16 -0
- package/dist/Track/core/auth.js +83 -0
- package/dist/Track/core/constants.d.ts +14 -0
- package/dist/Track/core/constants.js +25 -0
- package/dist/Track/core/envelope.d.ts +9 -0
- package/dist/Track/core/envelope.js +54 -0
- package/dist/Track/core/instance.d.ts +108 -0
- package/dist/Track/core/instance.js +365 -0
- package/dist/Track/core/lifecycle.d.ts +18 -0
- package/dist/Track/core/lifecycle.js +59 -0
- package/dist/Track/core/profile.d.ts +5 -0
- package/dist/Track/core/profile.js +30 -0
- package/dist/Track/core/queue.d.ts +13 -0
- package/dist/Track/core/queue.js +36 -0
- package/dist/Track/core/replay.d.ts +17 -0
- package/dist/Track/core/replay.js +117 -0
- package/dist/Track/core/router.d.ts +6 -0
- package/dist/Track/core/router.js +15 -0
- package/dist/Track/core/system.d.ts +14 -0
- package/dist/Track/core/system.js +36 -0
- package/dist/Track/core/transport.d.ts +18 -0
- package/dist/Track/core/transport.js +151 -0
- package/dist/Track/index.d.ts +19 -28
- package/dist/Track/index.js +144 -396
- package/dist/Utils/common.js +5 -6
- package/dist/Utils/route.js +1 -6
- package/dist/Utils/url.js +1 -3
- package/dist/Utils/wx.js +2 -7
- package/dist/interfaces/track.interface.d.ts +14 -4
- package/lib/Track/core/auth.d.ts +16 -0
- package/lib/Track/core/auth.js +67 -0
- package/lib/Track/core/constants.d.ts +14 -0
- package/lib/Track/core/constants.js +56 -0
- package/lib/Track/core/envelope.d.ts +9 -0
- package/lib/Track/core/envelope.js +61 -0
- package/lib/Track/core/instance.d.ts +108 -0
- package/lib/Track/core/instance.js +257 -0
- package/lib/Track/core/lifecycle.d.ts +18 -0
- package/lib/Track/core/lifecycle.js +74 -0
- package/lib/Track/core/profile.d.ts +5 -0
- package/lib/Track/core/profile.js +47 -0
- package/lib/Track/core/queue.d.ts +13 -0
- package/lib/Track/core/queue.js +49 -0
- package/lib/Track/core/replay.d.ts +17 -0
- package/lib/Track/core/replay.js +131 -0
- package/lib/Track/core/router.d.ts +6 -0
- package/lib/Track/core/router.js +39 -0
- package/lib/Track/core/system.d.ts +14 -0
- package/lib/Track/core/system.js +53 -0
- package/lib/Track/core/transport.d.ts +18 -0
- package/lib/Track/core/transport.js +115 -0
- package/lib/Track/index.d.ts +19 -28
- package/lib/Track/index.js +93 -317
- package/lib/Utils/common.js +4 -6
- package/lib/interfaces/track.interface.d.ts +14 -4
- package/package.json +11 -10
package/dist/Utils/wx.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectDestructuringEmpty from "@babel/runtime/helpers/esm/objectDestructuringEmpty";
|
|
8
3
|
export var isWechat = navigator.userAgent.toLowerCase().includes('micromessenger');
|
|
9
4
|
export var wxSDK = function wxSDK(option) {
|
|
10
5
|
return new Promise(function (resolve, reject) {
|
|
@@ -21,8 +21,6 @@ export type MenuNameMapType = {
|
|
|
21
21
|
};
|
|
22
22
|
export interface TrackConfig {
|
|
23
23
|
appId: string;
|
|
24
|
-
debug?: boolean;
|
|
25
|
-
autoReportError?: boolean;
|
|
26
24
|
userProfile?: UserProfile;
|
|
27
25
|
base?: string;
|
|
28
26
|
getAuth?: () => Promise<any>;
|
|
@@ -34,6 +32,7 @@ export interface TrackConfig {
|
|
|
34
32
|
zoneName: string;
|
|
35
33
|
}[]>;
|
|
36
34
|
domain: string;
|
|
35
|
+
enableReplay?: boolean;
|
|
37
36
|
}
|
|
38
37
|
export declare enum TrackTypeEnum {
|
|
39
38
|
error = "\u9519\u8BEF\u4FE1\u606F",
|
|
@@ -86,8 +85,7 @@ export interface SystemProfile {
|
|
|
86
85
|
}
|
|
87
86
|
export interface CustomizeProfile {
|
|
88
87
|
content: string;
|
|
89
|
-
module
|
|
90
|
-
[key: string]: any;
|
|
88
|
+
module: string;
|
|
91
89
|
}
|
|
92
90
|
export interface ErrorProfile {
|
|
93
91
|
fileName: string;
|
|
@@ -116,3 +114,15 @@ export type AuthDataType = {
|
|
|
116
114
|
title: string;
|
|
117
115
|
};
|
|
118
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,16 @@
|
|
|
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>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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);
|
|
18
|
+
|
|
19
|
+
// src/Track/core/auth.ts
|
|
20
|
+
var auth_exports = {};
|
|
21
|
+
__export(auth_exports, {
|
|
22
|
+
initAuthCenterData: () => initAuthCenterData
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(auth_exports);
|
|
25
|
+
var import_Utils = require("../../Utils");
|
|
26
|
+
async function initAuthCenterData(config) {
|
|
27
|
+
const {
|
|
28
|
+
getAuth,
|
|
29
|
+
menuBuild,
|
|
30
|
+
getDataScopeZonePermissions,
|
|
31
|
+
menuNameMap,
|
|
32
|
+
routes
|
|
33
|
+
} = config;
|
|
34
|
+
const tasks = [getAuth == null ? void 0 : getAuth(), menuBuild == null ? void 0 : menuBuild(), getDataScopeZonePermissions == null ? void 0 : getDataScopeZonePermissions()];
|
|
35
|
+
const [authInfo = {}, menuData = [], dataScopeZonePermissions] = await Promise.all(tasks.map((t) => t ?? Promise.resolve()));
|
|
36
|
+
const { user = {}, roles = [] } = authInfo || {};
|
|
37
|
+
const { roles: dataScopeRoles, ...restUser } = user;
|
|
38
|
+
const isAdmin = roles.includes("admin");
|
|
39
|
+
const accessPage = [];
|
|
40
|
+
let routesMap = /* @__PURE__ */ new Map();
|
|
41
|
+
if (routes) {
|
|
42
|
+
routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
|
|
43
|
+
routesMap.forEach(({ access }) => {
|
|
44
|
+
if (!access.length)
|
|
45
|
+
return;
|
|
46
|
+
if (isAdmin)
|
|
47
|
+
accessPage.push(...access);
|
|
48
|
+
else
|
|
49
|
+
access.forEach((k) => roles.includes(k) && accessPage.push(k));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const authMap = (0, import_Utils.getAuthMapByAuthCenter)(menuData);
|
|
53
|
+
const profile = {
|
|
54
|
+
...restUser,
|
|
55
|
+
dataScopeRoles,
|
|
56
|
+
roles,
|
|
57
|
+
accessPage,
|
|
58
|
+
isAdmin
|
|
59
|
+
};
|
|
60
|
+
if (dataScopeZonePermissions)
|
|
61
|
+
Object.assign(profile, { dataScopeZonePermissions });
|
|
62
|
+
return { authCenterUserProfile: profile, routesMap, authMap };
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
initAuthCenterData
|
|
67
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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);
|
|
18
|
+
|
|
19
|
+
// src/Track/core/constants.ts
|
|
20
|
+
var constants_exports = {};
|
|
21
|
+
__export(constants_exports, {
|
|
22
|
+
APP_VERSION_ENDPOINT: () => APP_VERSION_ENDPOINT,
|
|
23
|
+
DEFAULT_ERROR_THROTTLE_MS: () => DEFAULT_ERROR_THROTTLE_MS,
|
|
24
|
+
DEFAULT_FLUSH_THRESHOLD: () => DEFAULT_FLUSH_THRESHOLD,
|
|
25
|
+
DEFAULT_MAX_WAIT_MS: () => DEFAULT_MAX_WAIT_MS,
|
|
26
|
+
DEFAULT_REPLAY_CHECKOUT_NMS: () => DEFAULT_REPLAY_CHECKOUT_NMS,
|
|
27
|
+
DEFAULT_REPLAY_MAX_BYTES: () => DEFAULT_REPLAY_MAX_BYTES,
|
|
28
|
+
DEFAULT_REPLAY_MAX_EVENTS: () => DEFAULT_REPLAY_MAX_EVENTS,
|
|
29
|
+
ERROR_REPLAY_ENDPOINT: () => ERROR_REPLAY_ENDPOINT,
|
|
30
|
+
ERROR_TRACK_ENDPOINT: () => ERROR_TRACK_ENDPOINT,
|
|
31
|
+
TRACK_ENDPOINT: () => TRACK_ENDPOINT
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(constants_exports);
|
|
34
|
+
var DEFAULT_FLUSH_THRESHOLD = 5;
|
|
35
|
+
var DEFAULT_MAX_WAIT_MS = 5e3;
|
|
36
|
+
var TRACK_ENDPOINT = "/pousheng-guard/api/track";
|
|
37
|
+
var APP_VERSION_ENDPOINT = "/pousheng-guard/api/apps/version/update";
|
|
38
|
+
var ERROR_TRACK_ENDPOINT = "/pousheng-guard/api/track/error";
|
|
39
|
+
var ERROR_REPLAY_ENDPOINT = "/pousheng-guard/api/track/error-replay/";
|
|
40
|
+
var DEFAULT_REPLAY_CHECKOUT_NMS = 5 * 60 * 1e3;
|
|
41
|
+
var DEFAULT_REPLAY_MAX_EVENTS = 1e3;
|
|
42
|
+
var DEFAULT_REPLAY_MAX_BYTES = 1024 * 1024;
|
|
43
|
+
var DEFAULT_ERROR_THROTTLE_MS = 3e3;
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
APP_VERSION_ENDPOINT,
|
|
47
|
+
DEFAULT_ERROR_THROTTLE_MS,
|
|
48
|
+
DEFAULT_FLUSH_THRESHOLD,
|
|
49
|
+
DEFAULT_MAX_WAIT_MS,
|
|
50
|
+
DEFAULT_REPLAY_CHECKOUT_NMS,
|
|
51
|
+
DEFAULT_REPLAY_MAX_BYTES,
|
|
52
|
+
DEFAULT_REPLAY_MAX_EVENTS,
|
|
53
|
+
ERROR_REPLAY_ENDPOINT,
|
|
54
|
+
ERROR_TRACK_ENDPOINT,
|
|
55
|
+
TRACK_ENDPOINT
|
|
56
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件包构建与采样控制
|
|
3
|
+
*/
|
|
4
|
+
import { TrackConfig, TrackEventEnvelope, TrackType, UserProfile } from '../../interfaces/track.interface';
|
|
5
|
+
/**
|
|
6
|
+
* 构建事件信封(统一字段拼装)
|
|
7
|
+
* - systemProfile + user + type + appId + 序列化后的log
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildEnvelope(config: TrackConfig, user: UserProfile, type: TrackType, log: any): TrackEventEnvelope;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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);
|
|
18
|
+
|
|
19
|
+
// src/Track/core/envelope.ts
|
|
20
|
+
var envelope_exports = {};
|
|
21
|
+
__export(envelope_exports, {
|
|
22
|
+
buildEnvelope: () => buildEnvelope
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(envelope_exports);
|
|
25
|
+
var import_system = require("./system");
|
|
26
|
+
function buildEnvelope(config, user, type, log) {
|
|
27
|
+
const trackData = {
|
|
28
|
+
...(0, import_system.getSystemProfile)(),
|
|
29
|
+
...user,
|
|
30
|
+
type,
|
|
31
|
+
appId: config.appId
|
|
32
|
+
};
|
|
33
|
+
if (typeof log === "string") {
|
|
34
|
+
trackData.log = log;
|
|
35
|
+
}
|
|
36
|
+
if (typeof log === "object") {
|
|
37
|
+
let copyLog = {};
|
|
38
|
+
switch (type) {
|
|
39
|
+
case "visit":
|
|
40
|
+
case "event":
|
|
41
|
+
const { module: module2, content, ...rest } = log;
|
|
42
|
+
copyLog = rest;
|
|
43
|
+
Object.assign(trackData, { module: module2, content });
|
|
44
|
+
break;
|
|
45
|
+
case "error":
|
|
46
|
+
Object.assign(trackData, { log: JSON.stringify(log) });
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
copyLog = log;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (Object.keys(copyLog).length > 0) {
|
|
53
|
+
trackData.log = JSON.stringify(copyLog);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return trackData;
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
buildEnvelope
|
|
61
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrackerInstance - 多实例核心组合:权限初始化 + 队列 + 采样 + 生命周期
|
|
3
|
+
*/
|
|
4
|
+
import { AuthCenterUserProfile, CustomizeProfile, ErrorProfile, TrackConfig, UserProfile } from '../../interfaces/track.interface';
|
|
5
|
+
export declare class TrackerInstance {
|
|
6
|
+
private config;
|
|
7
|
+
private userProfile;
|
|
8
|
+
private authCenterUserProfile;
|
|
9
|
+
private routesMap;
|
|
10
|
+
private authMap;
|
|
11
|
+
private queue;
|
|
12
|
+
private internal;
|
|
13
|
+
private replay?;
|
|
14
|
+
private lifecycle?;
|
|
15
|
+
/**
|
|
16
|
+
* 构造函数:合并配置 + 参数校验
|
|
17
|
+
*/
|
|
18
|
+
constructor(cfg: TrackConfig);
|
|
19
|
+
/**
|
|
20
|
+
* 初始化:
|
|
21
|
+
* 1. 拉取权限/菜单/数据域信息
|
|
22
|
+
* 2. 合并用户画像(优先 AuthCenter,再叠加外部传入)
|
|
23
|
+
* 3. 挂载生命周期监听(visibilitychange / error)
|
|
24
|
+
* 4. 上报版本信息 & 启动定时 flush
|
|
25
|
+
*/
|
|
26
|
+
init(): Promise<AuthCenterUserProfile>;
|
|
27
|
+
/**
|
|
28
|
+
* Flush:
|
|
29
|
+
* - 取出队列中全部事件
|
|
30
|
+
*/
|
|
31
|
+
flush(): void;
|
|
32
|
+
/**
|
|
33
|
+
* 销毁:清理定时器 & 事件监听,并 flush 剩余数据
|
|
34
|
+
*/
|
|
35
|
+
destroy(): void;
|
|
36
|
+
/**
|
|
37
|
+
* 事件日志:
|
|
38
|
+
* - 支持传入字符串(自动映射为 authMap 描述)或对象
|
|
39
|
+
* - 自动补全 module(基于当前路由)
|
|
40
|
+
*/
|
|
41
|
+
eventLog(eventLog: CustomizeProfile | string): void;
|
|
42
|
+
/**
|
|
43
|
+
* 访问日志:
|
|
44
|
+
* - 默认按当前路由模块组装文案
|
|
45
|
+
* - 若路由标记 isRedirect 则跳过(避免中转页统计)
|
|
46
|
+
*/
|
|
47
|
+
visitLog(visitLog?: CustomizeProfile): void;
|
|
48
|
+
/**
|
|
49
|
+
* 错误日志:force = true 不受采样率影响
|
|
50
|
+
*/
|
|
51
|
+
errorLog(error: ErrorProfile): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* API 日志:直接即时上报(不进入公共队列)
|
|
54
|
+
*/
|
|
55
|
+
apiLog(apiLog: any): void;
|
|
56
|
+
/**
|
|
57
|
+
* 动态更新用户画像(不会重置已有字段)
|
|
58
|
+
*/
|
|
59
|
+
setUserProfile(patch: Partial<UserProfile>): void;
|
|
60
|
+
/** 获取当前实例配置副本(避免外部直接修改内部对象) */
|
|
61
|
+
getConfig(): {
|
|
62
|
+
appId: string;
|
|
63
|
+
userProfile?: UserProfile | undefined;
|
|
64
|
+
base?: string | undefined;
|
|
65
|
+
getAuth?: (() => Promise<any>) | undefined;
|
|
66
|
+
menuBuild?: (() => Promise<import("../../interfaces/track.interface").AuthMenuItemType[]>) | undefined;
|
|
67
|
+
menuNameMap?: import("../../interfaces/track.interface").MenuNameMapType | undefined;
|
|
68
|
+
routes?: import("../../interfaces/track.interface").RouteType[] | undefined;
|
|
69
|
+
getDataScopeZonePermissions?: (() => Promise<{
|
|
70
|
+
zoneId: number;
|
|
71
|
+
zoneName: string;
|
|
72
|
+
}[]>) | undefined;
|
|
73
|
+
domain: string;
|
|
74
|
+
enableReplay?: boolean | undefined;
|
|
75
|
+
};
|
|
76
|
+
/** 配置校验:缺少关键字段直接抛错 */
|
|
77
|
+
private validate;
|
|
78
|
+
/**
|
|
79
|
+
* 合并用户画像:
|
|
80
|
+
* - 若权限中心未返回 userName,则只使用外部提供
|
|
81
|
+
* - 否则使用 AuthCenter 信息并叠加外部 patch
|
|
82
|
+
*/
|
|
83
|
+
private mergeUserProfile;
|
|
84
|
+
/**
|
|
85
|
+
* 入队封装:
|
|
86
|
+
* - 全量采样
|
|
87
|
+
* - 生成 envelope
|
|
88
|
+
* - 触发阈值自动 flush
|
|
89
|
+
*/
|
|
90
|
+
private enqueue;
|
|
91
|
+
/** 获取当前路径(剥离 base 前缀) */
|
|
92
|
+
private getFormatPath;
|
|
93
|
+
/** 获取当前页面的模块层级(由 routesMap 提供) */
|
|
94
|
+
private getPageModules;
|
|
95
|
+
/** 挂载浏览器事件监听 */
|
|
96
|
+
private mountLifecycle;
|
|
97
|
+
/** 启动/重置周期性 flush 计时器 */
|
|
98
|
+
private scheduleFlushTimer;
|
|
99
|
+
/** 校验 module 是否有效(非空且非纯空白) */
|
|
100
|
+
private isValidModule;
|
|
101
|
+
/** 获取过滤后的模块层级(去除空项和空白) */
|
|
102
|
+
private getFilteredModules;
|
|
103
|
+
/** 若日志缺少 module,则尝试用路由模块补齐;返回是否有效 */
|
|
104
|
+
private fillModuleIfMissing;
|
|
105
|
+
private maybeStartReplay;
|
|
106
|
+
private stopReplay;
|
|
107
|
+
private buildReplayAttachment;
|
|
108
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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);
|
|
18
|
+
|
|
19
|
+
// src/Track/core/instance.ts
|
|
20
|
+
var instance_exports = {};
|
|
21
|
+
__export(instance_exports, {
|
|
22
|
+
TrackerInstance: () => TrackerInstance
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(instance_exports);
|
|
25
|
+
var import_auth = require("./auth");
|
|
26
|
+
var import_constants = require("./constants");
|
|
27
|
+
var import_envelope = require("./envelope");
|
|
28
|
+
var import_lifecycle = require("./lifecycle");
|
|
29
|
+
var import_profile = require("./profile");
|
|
30
|
+
var import_queue = require("./queue");
|
|
31
|
+
var import_replay = require("./replay");
|
|
32
|
+
var import_router = require("./router");
|
|
33
|
+
var import_transport = require("./transport");
|
|
34
|
+
var TrackerInstance = class {
|
|
35
|
+
/**
|
|
36
|
+
* 构造函数:合并配置 + 参数校验
|
|
37
|
+
*/
|
|
38
|
+
constructor(cfg) {
|
|
39
|
+
this.userProfile = { userId: "", userName: "" };
|
|
40
|
+
this.authCenterUserProfile = {};
|
|
41
|
+
this.routesMap = /* @__PURE__ */ new Map();
|
|
42
|
+
this.authMap = /* @__PURE__ */ new Map();
|
|
43
|
+
this.queue = new import_queue.TrackQueue();
|
|
44
|
+
this.internal = { initialized: false, destroyed: false };
|
|
45
|
+
this.config = {
|
|
46
|
+
// 回放默认开启
|
|
47
|
+
enableReplay: true,
|
|
48
|
+
...cfg
|
|
49
|
+
};
|
|
50
|
+
this.validate();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 初始化:
|
|
54
|
+
* 1. 拉取权限/菜单/数据域信息
|
|
55
|
+
* 2. 合并用户画像(优先 AuthCenter,再叠加外部传入)
|
|
56
|
+
* 3. 挂载生命周期监听(visibilitychange / error)
|
|
57
|
+
* 4. 上报版本信息 & 启动定时 flush
|
|
58
|
+
*/
|
|
59
|
+
async init() {
|
|
60
|
+
if (this.internal.initialized)
|
|
61
|
+
return this.authCenterUserProfile;
|
|
62
|
+
const { authCenterUserProfile, authMap, routesMap } = await (0, import_auth.initAuthCenterData)(this.config);
|
|
63
|
+
this.authCenterUserProfile = authCenterUserProfile;
|
|
64
|
+
this.authMap = authMap;
|
|
65
|
+
this.routesMap = routesMap;
|
|
66
|
+
this.mergeUserProfile();
|
|
67
|
+
this.mountLifecycle();
|
|
68
|
+
this.maybeStartReplay();
|
|
69
|
+
(0, import_transport.reportAppVersion)(this.config);
|
|
70
|
+
this.internal.initialized = true;
|
|
71
|
+
this.scheduleFlushTimer();
|
|
72
|
+
return this.authCenterUserProfile;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Flush:
|
|
76
|
+
* - 取出队列中全部事件
|
|
77
|
+
*/
|
|
78
|
+
flush() {
|
|
79
|
+
if (!this.queue.size())
|
|
80
|
+
return;
|
|
81
|
+
const batch = this.queue.drain();
|
|
82
|
+
(0, import_transport.reportBatch)(this.config, batch);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 销毁:清理定时器 & 事件监听,并 flush 剩余数据
|
|
86
|
+
*/
|
|
87
|
+
destroy() {
|
|
88
|
+
var _a;
|
|
89
|
+
if (this.internal.destroyed)
|
|
90
|
+
return;
|
|
91
|
+
this.flush();
|
|
92
|
+
(_a = this.lifecycle) == null ? void 0 : _a.unmount();
|
|
93
|
+
this.stopReplay();
|
|
94
|
+
clearInterval(this.internal.flushTimer);
|
|
95
|
+
this.internal.destroyed = true;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 事件日志:
|
|
99
|
+
* - 支持传入字符串(自动映射为 authMap 描述)或对象
|
|
100
|
+
* - 自动补全 module(基于当前路由)
|
|
101
|
+
*/
|
|
102
|
+
eventLog(eventLog) {
|
|
103
|
+
const data = { module: "", content: "" };
|
|
104
|
+
if (typeof eventLog === "string") {
|
|
105
|
+
const action = this.authMap.get(eventLog);
|
|
106
|
+
data.content = action ? "触发: " + action : eventLog;
|
|
107
|
+
} else
|
|
108
|
+
Object.assign(data, eventLog);
|
|
109
|
+
const modules = this.getFilteredModules();
|
|
110
|
+
if (!this.fillModuleIfMissing(data, modules))
|
|
111
|
+
return;
|
|
112
|
+
this.enqueue("event", data);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 访问日志:
|
|
116
|
+
* - 默认按当前路由模块组装文案
|
|
117
|
+
* - 若路由标记 isRedirect 则跳过(避免中转页统计)
|
|
118
|
+
*/
|
|
119
|
+
visitLog(visitLog) {
|
|
120
|
+
const routeInfo = this.routesMap.get(this.getFormatPath());
|
|
121
|
+
if (routeInfo == null ? void 0 : routeInfo.isRedirect)
|
|
122
|
+
return;
|
|
123
|
+
const mods = this.getFilteredModules();
|
|
124
|
+
if (!visitLog) {
|
|
125
|
+
if (!mods.length)
|
|
126
|
+
return;
|
|
127
|
+
visitLog = {
|
|
128
|
+
module: mods.join("-"),
|
|
129
|
+
content: `访问页面: ${mods[mods.length - 1]}`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (!this.fillModuleIfMissing(visitLog, mods))
|
|
133
|
+
return;
|
|
134
|
+
this.enqueue("visit", visitLog);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 错误日志:force = true 不受采样率影响
|
|
138
|
+
*/
|
|
139
|
+
async errorLog(error) {
|
|
140
|
+
var _a;
|
|
141
|
+
const throttle = import_constants.DEFAULT_ERROR_THROTTLE_MS;
|
|
142
|
+
const now = Date.now();
|
|
143
|
+
if (this.internal.lastErrorSentAt && now - this.internal.lastErrorSentAt < throttle) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
(_a = this.replay) == null ? void 0 : _a.markError(error);
|
|
147
|
+
const replayPayload = this.buildReplayAttachment();
|
|
148
|
+
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, "error", error);
|
|
149
|
+
(0, import_transport.reportError)(this.config, env, replayPayload);
|
|
150
|
+
this.internal.lastErrorSentAt = now;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* API 日志:直接即时上报(不进入公共队列)
|
|
154
|
+
*/
|
|
155
|
+
apiLog(apiLog) {
|
|
156
|
+
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, "api", apiLog);
|
|
157
|
+
(0, import_transport.reportApiLog)(this.config, apiLog, env);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 动态更新用户画像(不会重置已有字段)
|
|
161
|
+
*/
|
|
162
|
+
setUserProfile(patch) {
|
|
163
|
+
Object.assign(this.userProfile, patch);
|
|
164
|
+
}
|
|
165
|
+
/** 获取当前实例配置副本(避免外部直接修改内部对象) */
|
|
166
|
+
getConfig() {
|
|
167
|
+
return { ...this.config };
|
|
168
|
+
}
|
|
169
|
+
/** 配置校验:缺少关键字段直接抛错 */
|
|
170
|
+
validate() {
|
|
171
|
+
if (!this.config.domain)
|
|
172
|
+
throw new Error("缺少 domain");
|
|
173
|
+
if (!this.config.appId)
|
|
174
|
+
throw new Error("缺少 appId");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 合并用户画像:
|
|
178
|
+
* - 若权限中心未返回 userName,则只使用外部提供
|
|
179
|
+
* - 否则使用 AuthCenter 信息并叠加外部 patch
|
|
180
|
+
*/
|
|
181
|
+
mergeUserProfile() {
|
|
182
|
+
this.userProfile = (0, import_profile.mergeUserProfile)(
|
|
183
|
+
this.authCenterUserProfile,
|
|
184
|
+
this.config.userProfile
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 入队封装:
|
|
189
|
+
* - 全量采样
|
|
190
|
+
* - 生成 envelope
|
|
191
|
+
* - 触发阈值自动 flush
|
|
192
|
+
*/
|
|
193
|
+
enqueue(type, log, opts) {
|
|
194
|
+
const env = (0, import_envelope.buildEnvelope)(this.config, this.userProfile, type, log);
|
|
195
|
+
this.queue.push(env);
|
|
196
|
+
if (this.queue.size() >= import_constants.DEFAULT_FLUSH_THRESHOLD)
|
|
197
|
+
this.flush();
|
|
198
|
+
}
|
|
199
|
+
/** 获取当前路径(剥离 base 前缀) */
|
|
200
|
+
getFormatPath() {
|
|
201
|
+
return (0, import_router.getFormattedPath)(this.config);
|
|
202
|
+
}
|
|
203
|
+
/** 获取当前页面的模块层级(由 routesMap 提供) */
|
|
204
|
+
getPageModules() {
|
|
205
|
+
return (0, import_router.getPageModules)(this.config, this.routesMap);
|
|
206
|
+
}
|
|
207
|
+
/** 挂载浏览器事件监听 */
|
|
208
|
+
mountLifecycle() {
|
|
209
|
+
this.lifecycle = new import_lifecycle.LifecycleManager({
|
|
210
|
+
onHidden: () => this.flush(),
|
|
211
|
+
onError: (err) => this.errorLog(err)
|
|
212
|
+
});
|
|
213
|
+
this.lifecycle.mount();
|
|
214
|
+
}
|
|
215
|
+
/** 启动/重置周期性 flush 计时器 */
|
|
216
|
+
scheduleFlushTimer() {
|
|
217
|
+
this.internal.flushTimer && clearInterval(this.internal.flushTimer);
|
|
218
|
+
this.internal.flushTimer = setInterval(
|
|
219
|
+
() => this.flush(),
|
|
220
|
+
import_constants.DEFAULT_MAX_WAIT_MS
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
/** 校验 module 是否有效(非空且非纯空白) */
|
|
224
|
+
isValidModule(mod) {
|
|
225
|
+
return !!(mod && mod.trim());
|
|
226
|
+
}
|
|
227
|
+
/** 获取过滤后的模块层级(去除空项和空白) */
|
|
228
|
+
getFilteredModules() {
|
|
229
|
+
return (this.getPageModules() || []).filter((m) => m && m.trim());
|
|
230
|
+
}
|
|
231
|
+
/** 若日志缺少 module,则尝试用路由模块补齐;返回是否有效 */
|
|
232
|
+
fillModuleIfMissing(profile, modules) {
|
|
233
|
+
if (!profile.module && modules.length) {
|
|
234
|
+
profile.module = modules.join("-");
|
|
235
|
+
}
|
|
236
|
+
return this.isValidModule(profile.module);
|
|
237
|
+
}
|
|
238
|
+
/* ================= rrweb 录制相关 ================= */
|
|
239
|
+
maybeStartReplay() {
|
|
240
|
+
if (!this.config.enableReplay)
|
|
241
|
+
return;
|
|
242
|
+
this.replay = new import_replay.ReplayManager(this.config);
|
|
243
|
+
this.replay.start();
|
|
244
|
+
}
|
|
245
|
+
stopReplay() {
|
|
246
|
+
var _a;
|
|
247
|
+
(_a = this.replay) == null ? void 0 : _a.stop();
|
|
248
|
+
}
|
|
249
|
+
buildReplayAttachment() {
|
|
250
|
+
var _a;
|
|
251
|
+
return (_a = this.replay) == null ? void 0 : _a.buildAttachment();
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
TrackerInstance
|
|
257
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LifecycleManager - 浏览器生命周期与错误监听的封装
|
|
3
|
+
*/
|
|
4
|
+
import { ErrorProfile } from '../../interfaces/track.interface';
|
|
5
|
+
type Options = {
|
|
6
|
+
onHidden?: () => void;
|
|
7
|
+
onError?: (error: ErrorProfile) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare class LifecycleManager {
|
|
10
|
+
private opts;
|
|
11
|
+
constructor(opts: Options);
|
|
12
|
+
private onVisibilityChange;
|
|
13
|
+
private onWindowError;
|
|
14
|
+
private onUnhandledRejection;
|
|
15
|
+
mount(): void;
|
|
16
|
+
unmount(): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|