@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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TrackQueue - 轻量埋点队列实现
|
|
3
|
-
* 提供 push / size / drain 三个最小操作,避免引入额外依赖。
|
|
4
|
-
*/
|
|
5
|
-
export declare class TrackQueue<T> {
|
|
6
|
-
private items;
|
|
7
|
-
/** 入队一个元素 */
|
|
8
|
-
push(item: T): void;
|
|
9
|
-
/** 当前元素数量 */
|
|
10
|
-
size(): number;
|
|
11
|
-
/** 取出并清空所有元素(返回快照) */
|
|
12
|
-
drain(): T[];
|
|
13
|
-
}
|
package/dist/Track/core/queue.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
/**
|
|
5
|
-
* TrackQueue - 轻量埋点队列实现
|
|
6
|
-
* 提供 push / size / drain 三个最小操作,避免引入额外依赖。
|
|
7
|
-
*/
|
|
8
|
-
export var TrackQueue = /*#__PURE__*/function () {
|
|
9
|
-
function TrackQueue() {
|
|
10
|
-
_classCallCheck(this, TrackQueue);
|
|
11
|
-
_defineProperty(this, "items", []);
|
|
12
|
-
}
|
|
13
|
-
_createClass(TrackQueue, [{
|
|
14
|
-
key: "push",
|
|
15
|
-
value: /** 入队一个元素 */
|
|
16
|
-
function push(item) {
|
|
17
|
-
this.items.push(item);
|
|
18
|
-
}
|
|
19
|
-
/** 当前元素数量 */
|
|
20
|
-
}, {
|
|
21
|
-
key: "size",
|
|
22
|
-
value: function size() {
|
|
23
|
-
return this.items.length;
|
|
24
|
-
}
|
|
25
|
-
/** 取出并清空所有元素(返回快照) */
|
|
26
|
-
}, {
|
|
27
|
-
key: "drain",
|
|
28
|
-
value: function drain() {
|
|
29
|
-
if (!this.items.length) return [];
|
|
30
|
-
var copy = this.items.slice();
|
|
31
|
-
this.items.length = 0;
|
|
32
|
-
return copy;
|
|
33
|
-
}
|
|
34
|
-
}]);
|
|
35
|
-
return TrackQueue;
|
|
36
|
-
}();
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ErrorProfile, TrackConfig } from '../../interfaces/track.interface';
|
|
2
|
-
export declare class ReplayManager {
|
|
3
|
-
private config;
|
|
4
|
-
private stopRecord?;
|
|
5
|
-
private segments;
|
|
6
|
-
constructor(config: TrackConfig);
|
|
7
|
-
start(): void;
|
|
8
|
-
stop(): void;
|
|
9
|
-
/**
|
|
10
|
-
* 构建随错包携带的回放事件,受条数与字节限制
|
|
11
|
-
*/
|
|
12
|
-
buildAttachment(): any[] | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* 在回放流中注入一条“错误”标记事件,便于后续定位
|
|
15
|
-
*/
|
|
16
|
-
markError(error: ErrorProfile): void;
|
|
17
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
-
/**
|
|
6
|
-
* ReplayManager - 封装 rrweb 录制 & 最近片段管理
|
|
7
|
-
*/
|
|
8
|
-
import { record as rrwebRecord } from '@rrweb/record';
|
|
9
|
-
import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
|
|
10
|
-
import { DEFAULT_REPLAY_CHECKOUT_NMS, DEFAULT_REPLAY_MAX_BYTES, DEFAULT_REPLAY_MAX_EVENTS } from "./constants";
|
|
11
|
-
export var ReplayManager = /*#__PURE__*/function () {
|
|
12
|
-
// 仅保留最近两段
|
|
13
|
-
|
|
14
|
-
function ReplayManager(config) {
|
|
15
|
-
_classCallCheck(this, ReplayManager);
|
|
16
|
-
_defineProperty(this, "config", void 0);
|
|
17
|
-
_defineProperty(this, "stopRecord", void 0);
|
|
18
|
-
_defineProperty(this, "segments", [[]]);
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
_createClass(ReplayManager, [{
|
|
22
|
-
key: "start",
|
|
23
|
-
value: function start() {
|
|
24
|
-
var _this = this;
|
|
25
|
-
if (!this.config.enableReplay) return;
|
|
26
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
27
|
-
try {
|
|
28
|
-
var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
|
|
29
|
-
var rrwebOptions = {
|
|
30
|
-
checkoutEveryNms: DEFAULT_REPLAY_CHECKOUT_NMS
|
|
31
|
-
};
|
|
32
|
-
this.stopRecord = rrwebRecord(_objectSpread({
|
|
33
|
-
emit: function emit(event, isCheckout) {
|
|
34
|
-
if (isCheckout) _this.segments.push([]);
|
|
35
|
-
var last = _this.segments[_this.segments.length - 1];
|
|
36
|
-
last.push(event);
|
|
37
|
-
if (_this.segments.length > 2) _this.segments.shift();
|
|
38
|
-
if (last.length > maxEvents) last.splice(0, last.length - maxEvents);
|
|
39
|
-
},
|
|
40
|
-
plugins: [getRecordConsolePlugin()]
|
|
41
|
-
}, rrwebOptions));
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.warn('[track:debug] replay start failed', err);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "stop",
|
|
48
|
-
value: function stop() {
|
|
49
|
-
try {
|
|
50
|
-
this.stopRecord && this.stopRecord();
|
|
51
|
-
this.stopRecord = undefined;
|
|
52
|
-
} catch (_unused) {
|
|
53
|
-
/* ignore */
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 构建随错包携带的回放事件,受条数与字节限制
|
|
59
|
-
*/
|
|
60
|
-
}, {
|
|
61
|
-
key: "buildAttachment",
|
|
62
|
-
value: function buildAttachment() {
|
|
63
|
-
if (!this.config.enableReplay) return undefined;
|
|
64
|
-
if (!this.segments.length) return undefined;
|
|
65
|
-
var joined = (this.segments[this.segments.length - 2] || []).concat(this.segments[this.segments.length - 1] || []);
|
|
66
|
-
if (!joined.length) return undefined;
|
|
67
|
-
var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
|
|
68
|
-
var sliced = joined.slice(-maxEvents);
|
|
69
|
-
var maxBytes = DEFAULT_REPLAY_MAX_BYTES;
|
|
70
|
-
var json = JSON.stringify(sliced);
|
|
71
|
-
if (json.length > maxBytes) {
|
|
72
|
-
var step = Math.max(50, Math.floor(sliced.length * 0.1));
|
|
73
|
-
while (json.length > maxBytes && sliced.length > step) {
|
|
74
|
-
sliced = sliced.slice(step);
|
|
75
|
-
json = JSON.stringify(sliced);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return sliced;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 在回放流中注入一条“错误”标记事件,便于后续定位
|
|
83
|
-
*/
|
|
84
|
-
}, {
|
|
85
|
-
key: "markError",
|
|
86
|
-
value: function markError(error) {
|
|
87
|
-
if (!this.config.enableReplay) return;
|
|
88
|
-
try {
|
|
89
|
-
var _location, _navigator;
|
|
90
|
-
var event = {
|
|
91
|
-
// rrweb 自定义事件类型:5(EventType.Custom)。避免直接依赖枚举,使用字面量。
|
|
92
|
-
type: 5,
|
|
93
|
-
timestamp: Date.now(),
|
|
94
|
-
data: {
|
|
95
|
-
tag: 'error',
|
|
96
|
-
payload: {
|
|
97
|
-
message: error.message,
|
|
98
|
-
fileName: error.fileName,
|
|
99
|
-
href: typeof location !== 'undefined' && (_location = location) !== null && _location !== void 0 && _location.href ? location.href : '',
|
|
100
|
-
userAgent: typeof navigator !== 'undefined' && (_navigator = navigator) !== null && _navigator !== void 0 && _navigator.userAgent ? navigator.userAgent : ''
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
if (!this.segments.length) this.segments.push([]);
|
|
105
|
-
var last = this.segments[this.segments.length - 1];
|
|
106
|
-
last.push(event);
|
|
107
|
-
|
|
108
|
-
// 与 start() 中保持一致的长度限制
|
|
109
|
-
var maxEvents = DEFAULT_REPLAY_MAX_EVENTS;
|
|
110
|
-
if (last.length > maxEvents) last.splice(0, last.length - maxEvents);
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.warn('[track:debug] markError failed', e);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}]);
|
|
116
|
-
return ReplayManager;
|
|
117
|
-
}();
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路由辅助:基于 base 前缀规范化路径,并从 routesMap 提取模块层级
|
|
3
|
-
*/
|
|
4
|
-
import { RouteMapValueType, TrackConfig } from '../../interfaces/track.interface';
|
|
5
|
-
export declare function getFormattedPath(config: TrackConfig): string;
|
|
6
|
-
export declare function getPageModules(config: TrackConfig, routesMap: Map<string, RouteMapValueType>): string[];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路由辅助:基于 base 前缀规范化路径,并从 routesMap 提取模块层级
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export function getFormattedPath(config) {
|
|
6
|
-
var _config$base = config.base,
|
|
7
|
-
base = _config$base === void 0 ? '/' : _config$base;
|
|
8
|
-
var pathname = typeof location !== 'undefined' ? location.pathname : '';
|
|
9
|
-
// 确保只剥离一次 base 前缀
|
|
10
|
-
return pathname.replace(base, '/');
|
|
11
|
-
}
|
|
12
|
-
export function getPageModules(config, routesMap) {
|
|
13
|
-
var ri = routesMap.get(getFormattedPath(config));
|
|
14
|
-
return (ri === null || ri === void 0 ? void 0 : ri.module) || [];
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 系统/运行环境信息采集:IMEI 生成 + 视口 + 当前 URL 等。
|
|
3
|
-
*/
|
|
4
|
-
import { SystemProfile } from '../../interfaces/track.interface';
|
|
5
|
-
/**
|
|
6
|
-
* 确保存在一个持久化 IMEI(匿名设备标识)
|
|
7
|
-
* - 优先 localStorage
|
|
8
|
-
* - 不可用时降级随机字符串
|
|
9
|
-
*/
|
|
10
|
-
export declare function ensureIMEI(): string;
|
|
11
|
-
/**
|
|
12
|
-
* 收集系统(会话)级别指标:窗口尺寸 / URL / 时间戳 / IMEI
|
|
13
|
-
*/
|
|
14
|
-
export declare function getSystemProfile(): SystemProfile;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 系统/运行环境信息采集:IMEI 生成 + 视口 + 当前 URL 等。
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { generateRandomString } from "../../Utils";
|
|
6
|
-
var IMEI_KEY = '__IMEI__';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 确保存在一个持久化 IMEI(匿名设备标识)
|
|
10
|
-
* - 优先 localStorage
|
|
11
|
-
* - 不可用时降级随机字符串
|
|
12
|
-
*/
|
|
13
|
-
export function ensureIMEI() {
|
|
14
|
-
try {
|
|
15
|
-
var val = localStorage.getItem(IMEI_KEY);
|
|
16
|
-
if (val) return val;
|
|
17
|
-
var imei = generateRandomString(16);
|
|
18
|
-
localStorage.setItem(IMEI_KEY, imei);
|
|
19
|
-
return imei;
|
|
20
|
-
} catch (_unused) {
|
|
21
|
-
return generateRandomString(16);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 收集系统(会话)级别指标:窗口尺寸 / URL / 时间戳 / IMEI
|
|
27
|
-
*/
|
|
28
|
-
export function getSystemProfile() {
|
|
29
|
-
return {
|
|
30
|
-
innerHeight: typeof window !== 'undefined' ? window.innerHeight : 0,
|
|
31
|
-
innerWidth: typeof window !== 'undefined' ? window.innerWidth : 0,
|
|
32
|
-
href: typeof location !== 'undefined' ? location.href : '',
|
|
33
|
-
systemTime: new Date(),
|
|
34
|
-
IMEI: ensureIMEI()
|
|
35
|
-
};
|
|
36
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { TrackConfig } from '../../interfaces/track.interface';
|
|
2
|
-
/**
|
|
3
|
-
* sendBeacon 包装:
|
|
4
|
-
* - 统一 JSON 序列化
|
|
5
|
-
* - debug 输出
|
|
6
|
-
* - 失败仅打印(不抛错,避免影响业务)
|
|
7
|
-
*/
|
|
8
|
-
export declare function beaconSend(url: string, payload: object | any[]): void;
|
|
9
|
-
/**
|
|
10
|
-
* 上报当前应用版本:避免重复上报,通过 localStorage 绑定 appId 做缓存
|
|
11
|
-
*/
|
|
12
|
-
export declare function reportAppVersion(config: TrackConfig): void;
|
|
13
|
-
/** 批量上报日志事件数组 */
|
|
14
|
-
export declare function reportBatch(config: TrackConfig, batch: any[]): void;
|
|
15
|
-
/** 上报单条 API 日志(独立通道) */
|
|
16
|
-
export declare function reportApiLog(config: TrackConfig, apiLog: any, envelope: any): void;
|
|
17
|
-
/** 上报单条错误日志到专用端点 */
|
|
18
|
-
export declare function reportError(config: TrackConfig, envelope: any, replayPayload?: any): Promise<void>;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
-
/**
|
|
5
|
-
* 传输层:统一封装 sendBeacon 调用与批量 / 版本上报逻辑。
|
|
6
|
-
*/
|
|
7
|
-
import { version } from "../../../package.json";
|
|
8
|
-
import { APP_VERSION_ENDPOINT, ERROR_REPLAY_ENDPOINT, ERROR_TRACK_ENDPOINT, TRACK_ENDPOINT } from "./constants";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 包装fetch,方便async/await调用
|
|
12
|
-
* @param url
|
|
13
|
-
* @param options
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
function fetchWrapper(_x, _x2) {
|
|
17
|
-
return _fetchWrapper.apply(this, arguments);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* sendBeacon 包装:
|
|
21
|
-
* - 统一 JSON 序列化
|
|
22
|
-
* - debug 输出
|
|
23
|
-
* - 失败仅打印(不抛错,避免影响业务)
|
|
24
|
-
*/
|
|
25
|
-
function _fetchWrapper() {
|
|
26
|
-
_fetchWrapper = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, options) {
|
|
27
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
|
-
while (1) switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
31
|
-
fetch(url, options).then(function (response) {
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
throw new Error("Network response was not ok: ".concat(response.statusText));
|
|
34
|
-
}
|
|
35
|
-
return response.json();
|
|
36
|
-
}).then(function (data) {
|
|
37
|
-
return resolve(data);
|
|
38
|
-
}).catch(function (error) {
|
|
39
|
-
return reject(error);
|
|
40
|
-
});
|
|
41
|
-
}));
|
|
42
|
-
case 1:
|
|
43
|
-
case "end":
|
|
44
|
-
return _context.stop();
|
|
45
|
-
}
|
|
46
|
-
}, _callee);
|
|
47
|
-
}));
|
|
48
|
-
return _fetchWrapper.apply(this, arguments);
|
|
49
|
-
}
|
|
50
|
-
export function beaconSend(url, payload) {
|
|
51
|
-
try {
|
|
52
|
-
// 只允许对象或数组
|
|
53
|
-
if (!Array.isArray(payload) && (_typeof(payload) !== 'object' || payload === null)) {
|
|
54
|
-
throw new Error('Payload must be an object or array');
|
|
55
|
-
}
|
|
56
|
-
var body = new Blob([JSON.stringify(payload)], {
|
|
57
|
-
type: 'application/json'
|
|
58
|
-
});
|
|
59
|
-
navigator.sendBeacon(url, body);
|
|
60
|
-
} catch (err) {
|
|
61
|
-
console.warn('[track:debug] beacon failed', err, url, payload);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 上报当前应用版本:避免重复上报,通过 localStorage 绑定 appId 做缓存
|
|
67
|
-
*/
|
|
68
|
-
export function reportAppVersion(config) {
|
|
69
|
-
var appId = config.appId,
|
|
70
|
-
domain = config.domain;
|
|
71
|
-
var storageKey = "__Track__".concat(appId);
|
|
72
|
-
try {
|
|
73
|
-
var cached = localStorage.getItem(storageKey);
|
|
74
|
-
if (cached) {
|
|
75
|
-
try {
|
|
76
|
-
var _ref = JSON.parse(cached),
|
|
77
|
-
v = _ref.v;
|
|
78
|
-
if (v === version) {
|
|
79
|
-
console.debug('[track:debug] skip version report (same)', version);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
} catch (_unused) {
|
|
83
|
-
/* ignore parse error */
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
localStorage.setItem(storageKey, JSON.stringify({
|
|
87
|
-
v: version,
|
|
88
|
-
t: new Date().toLocaleString()
|
|
89
|
-
}));
|
|
90
|
-
} catch (_unused2) {
|
|
91
|
-
/* storage not available */
|
|
92
|
-
}
|
|
93
|
-
beaconSend("".concat(domain).concat(APP_VERSION_ENDPOINT), {
|
|
94
|
-
appId: appId,
|
|
95
|
-
version: version
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** 批量上报日志事件数组 */
|
|
100
|
-
export function reportBatch(config, batch) {
|
|
101
|
-
if (!batch.length) return;
|
|
102
|
-
var domain = config.domain;
|
|
103
|
-
beaconSend("".concat(domain).concat(TRACK_ENDPOINT), batch);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** 上报单条 API 日志(独立通道) */
|
|
107
|
-
export function reportApiLog(config, apiLog, envelope) {
|
|
108
|
-
var domain = config.domain;
|
|
109
|
-
beaconSend("".concat(domain).concat(TRACK_ENDPOINT), [envelope]);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** 上报单条错误日志到专用端点 */
|
|
113
|
-
export function reportError(_x3, _x4, _x5) {
|
|
114
|
-
return _reportError.apply(this, arguments);
|
|
115
|
-
}
|
|
116
|
-
function _reportError() {
|
|
117
|
-
_reportError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config, envelope, replayPayload) {
|
|
118
|
-
var domain, _yield$fetchWrapper, id;
|
|
119
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
120
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
121
|
-
case 0:
|
|
122
|
-
domain = config.domain;
|
|
123
|
-
_context2.next = 3;
|
|
124
|
-
return fetchWrapper("".concat(domain).concat(ERROR_TRACK_ENDPOINT), {
|
|
125
|
-
method: 'POST',
|
|
126
|
-
headers: {
|
|
127
|
-
'Content-Type': 'application/json'
|
|
128
|
-
},
|
|
129
|
-
body: JSON.stringify(envelope)
|
|
130
|
-
});
|
|
131
|
-
case 3:
|
|
132
|
-
_yield$fetchWrapper = _context2.sent;
|
|
133
|
-
id = _yield$fetchWrapper.data;
|
|
134
|
-
if (id && replayPayload) {
|
|
135
|
-
// 将replayPayload以文本方式上传,不经过序列化
|
|
136
|
-
fetchWrapper("".concat(domain).concat(ERROR_REPLAY_ENDPOINT).concat(id), {
|
|
137
|
-
method: 'POST',
|
|
138
|
-
headers: {
|
|
139
|
-
'Content-Type': 'text/plain'
|
|
140
|
-
},
|
|
141
|
-
body: JSON.stringify(replayPayload)
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
case 6:
|
|
145
|
-
case "end":
|
|
146
|
-
return _context2.stop();
|
|
147
|
-
}
|
|
148
|
-
}, _callee2);
|
|
149
|
-
}));
|
|
150
|
-
return _reportError.apply(this, arguments);
|
|
151
|
-
}
|
package/lib/Track/core/auth.d.ts
DELETED
|
@@ -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/lib/Track/core/auth.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -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;
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
});
|