@yysports/tools 2.0.2 → 2.2.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.
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 +2 -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 +2 -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
@@ -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,58 @@
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
+ import { version } from "../../package.json";
5
+ import Config from "./Config";
6
+ var Beacon = /*#__PURE__*/function () {
7
+ function Beacon() {
8
+ _classCallCheck(this, Beacon);
9
+ }
10
+ _createClass(Beacon, null, [{
11
+ key: "push",
12
+ value:
13
+ // 加入Beacon消息队列,检测超过5条记录时自动发送
14
+ function push(data) {
15
+ this._queue.push(data);
16
+ if (this._queue.length >= 5) {
17
+ this.send();
18
+ }
19
+ }
20
+
21
+ // 发送Beacon消息
22
+ }, {
23
+ key: "send",
24
+ value: function send(data) {
25
+ var _navigator;
26
+ var api = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/pousheng-guard/api/track';
27
+ var sendData = data ? data : this._queue.splice(0, 5);
28
+ // 判断 sendData 是否为空
29
+ if (!sendData || Array.isArray(sendData) && sendData.length === 0) {
30
+ return;
31
+ }
32
+ var blob = new Blob([JSON.stringify(sendData)], {
33
+ type: 'application/json'
34
+ });
35
+ (_navigator = navigator) === null || _navigator === void 0 || _navigator.sendBeacon("".concat(Config.data.domain).concat(api), blob);
36
+ }
37
+
38
+ // 更新Track版本号
39
+ }, {
40
+ key: "updateVersion",
41
+ value: function updateVersion() {
42
+ // 获取缓存中的版本信息
43
+ var storageKey = "__TrackVersion__";
44
+ var cachedVersion = localStorage.getItem(storageKey);
45
+ if (cachedVersion !== version) {
46
+ this.send({
47
+ appId: Config.data.appId,
48
+ version: version
49
+ }, '/pousheng-guard/api/apps/version/update');
50
+ localStorage.setItem(storageKey, version);
51
+ }
52
+ }
53
+ }]);
54
+ return Beacon;
55
+ }();
56
+ // 消息队列
57
+ _defineProperty(Beacon, "_queue", []);
58
+ export { Beacon as default };
@@ -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
+ }
@@ -0,0 +1,34 @@
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
+ var Config = /*#__PURE__*/function () {
5
+ function Config() {
6
+ _classCallCheck(this, Config);
7
+ }
8
+ _createClass(Config, null, [{
9
+ key: "validate",
10
+ value: function validate(config) {
11
+ var _config$appId, _config$domain;
12
+ if (!((_config$appId = config.appId) !== null && _config$appId !== void 0 && _config$appId.trim())) {
13
+ throw new Error('Config: appId is required');
14
+ }
15
+ if (!((_config$domain = config.domain) !== null && _config$domain !== void 0 && _config$domain.trim())) {
16
+ throw new Error('Config: domain is required');
17
+ }
18
+ Object.assign(this._data, config);
19
+ }
20
+ }, {
21
+ key: "data",
22
+ get: function get() {
23
+ return this._data;
24
+ }
25
+ }]);
26
+ return Config;
27
+ }();
28
+ _defineProperty(Config, "_data", {
29
+ appId: '',
30
+ domain: '',
31
+ autoReportError: true,
32
+ enableReplay: true
33
+ });
34
+ export { Config as default };
@@ -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,46 @@
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
+ import Beacon from "./Beacon";
5
+ import Config from "./Config";
6
+ import Log from "./Log";
7
+ var Listener = /*#__PURE__*/function () {
8
+ function Listener() {
9
+ _classCallCheck(this, Listener);
10
+ }
11
+ _createClass(Listener, null, [{
12
+ key: "run",
13
+ value: function run() {
14
+ var _this = this;
15
+ if (this._loaded || !Config.data.autoReportError) {
16
+ return;
17
+ }
18
+
19
+ // 监听全局未捕获的错误,同时进行防抖处理,高频报错时只上报最后一条
20
+ window.addEventListener('error', function (event) {
21
+ if (_this._reporter) {
22
+ clearTimeout(_this._reporter);
23
+ }
24
+ _this._reporter = setTimeout(function () {
25
+ // 立即触发上报当前剩余的 Beacon 数据
26
+ Beacon.send();
27
+ Log.errorLog(event.message);
28
+ _this._reporter = null;
29
+ }, 1000);
30
+ });
31
+
32
+ // 监听页面可见性变化
33
+ document.addEventListener('visibilitychange', function () {
34
+ var _document;
35
+ if (((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'hidden') {
36
+ Beacon.send();
37
+ }
38
+ });
39
+ this._loaded = true;
40
+ }
41
+ }]);
42
+ return Listener;
43
+ }();
44
+ _defineProperty(Listener, "_loaded", false);
45
+ _defineProperty(Listener, "_reporter", null);
46
+ export { Listener as default };
@@ -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
+ }
@@ -0,0 +1,100 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
6
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+ import Beacon from "./Beacon";
8
+ import Config from "./Config";
9
+ import Replay from "./Replay";
10
+ import System from "./System";
11
+ import User from "./User";
12
+ var Log = /*#__PURE__*/function () {
13
+ function Log() {
14
+ _classCallCheck(this, Log);
15
+ }
16
+ _createClass(Log, null, [{
17
+ key: "_commonProps",
18
+ value:
19
+ // 上报日志的公共属性
20
+ function _commonProps() {
21
+ return _objectSpread(_objectSpread(_objectSpread({}, User.profile), System.profile), {}, {
22
+ appId: Config.data.appId,
23
+ module: this._module
24
+ });
25
+ }
26
+ }, {
27
+ key: "visitLog",
28
+ value: function visitLog(module) {
29
+ this._module = module;
30
+ var lastModule = this._module.split('-').pop();
31
+ Beacon.push(_objectSpread(_objectSpread({}, this._commonProps()), {}, {
32
+ type: 'visit',
33
+ content: "\u8BBF\u95EE\u9875\u9762\uFF1A".concat(lastModule)
34
+ }));
35
+ }
36
+ }, {
37
+ key: "eventLog",
38
+ value: function eventLog(content) {
39
+ Beacon.push(_objectSpread(_objectSpread({}, this._commonProps()), {}, {
40
+ type: 'event',
41
+ content: content
42
+ }));
43
+ }
44
+ }, {
45
+ key: "errorLog",
46
+ value: function () {
47
+ var _errorLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(message) {
48
+ var res, _yield$res$json, id;
49
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
50
+ while (1) switch (_context.prev = _context.next) {
51
+ case 0:
52
+ _context.next = 2;
53
+ return fetch("".concat(Config.data.domain, "/pousheng-guard/api/track/error"), {
54
+ method: 'POST',
55
+ headers: {
56
+ 'Content-Type': 'application/json'
57
+ },
58
+ body: JSON.stringify(_objectSpread(_objectSpread({}, this._commonProps()), {}, {
59
+ type: 'error',
60
+ log: JSON.stringify({
61
+ message: message
62
+ })
63
+ }))
64
+ });
65
+ case 2:
66
+ res = _context.sent;
67
+ _context.next = 5;
68
+ return res.json();
69
+ case 5:
70
+ _yield$res$json = _context.sent;
71
+ id = _yield$res$json.data;
72
+ if (Config.data.autoReportError) {
73
+ // 上报回放片段
74
+ Replay.reportSnapshot(id);
75
+ }
76
+ case 8:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }, _callee, this);
81
+ }));
82
+ function errorLog(_x) {
83
+ return _errorLog.apply(this, arguments);
84
+ }
85
+ return errorLog;
86
+ }()
87
+ }, {
88
+ key: "apiLog",
89
+ value: function apiLog(log) {
90
+ Beacon.push(_objectSpread(_objectSpread({}, this._commonProps()), {}, {
91
+ type: 'api',
92
+ log: log
93
+ }));
94
+ }
95
+ }]);
96
+ return Log;
97
+ }();
98
+ // 当前模块
99
+ _defineProperty(Log, "_module", '');
100
+ export { Log as default };
@@ -0,0 +1,6 @@
1
+ export default class Replay {
2
+ private static _events;
3
+ private static _stop;
4
+ static run(): void;
5
+ static reportSnapshot(errorId: string): Promise<void>;
6
+ }
@@ -0,0 +1,77 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
+ import { record } from '@rrweb/record';
7
+ import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
8
+ import Config from "./Config";
9
+ var Replay = /*#__PURE__*/function () {
10
+ function Replay() {
11
+ _classCallCheck(this, Replay);
12
+ }
13
+ _createClass(Replay, null, [{
14
+ key: "run",
15
+ value: function run() {
16
+ var _this = this;
17
+ if (this._stop || !Config.data.enableReplay) {
18
+ return;
19
+ }
20
+ try {
21
+ this._stop = record({
22
+ emit: function emit(e) {
23
+ _this._events.push(e);
24
+ // 截断到最大长度
25
+ var over = _this._events.length - 1000;
26
+ if (over > 0) _this._events.splice(0, over);
27
+ },
28
+ plugins: [getRecordConsolePlugin({
29
+ level: ['log', 'info', 'warn', 'error', 'debug']
30
+ })]
31
+ });
32
+ } catch (err) {
33
+ this._stop = undefined;
34
+ }
35
+ }
36
+
37
+ // 快照
38
+ }, {
39
+ key: "reportSnapshot",
40
+ value: function () {
41
+ var _reportSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(errorId) {
42
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ if (this._stop) {
46
+ _context.next = 2;
47
+ break;
48
+ }
49
+ return _context.abrupt("return");
50
+ case 2:
51
+ _context.next = 4;
52
+ return fetch("".concat(Config.data.domain, "/pousheng-guard/api/track/error-replay/").concat(errorId), {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'text/plain'
56
+ },
57
+ body: JSON.stringify(this._events)
58
+ });
59
+ case 4:
60
+ this._events = [];
61
+ case 5:
62
+ case "end":
63
+ return _context.stop();
64
+ }
65
+ }, _callee, this);
66
+ }));
67
+ function reportSnapshot(_x) {
68
+ return _reportSnapshot.apply(this, arguments);
69
+ }
70
+ return reportSnapshot;
71
+ }()
72
+ }]);
73
+ return Replay;
74
+ }();
75
+ _defineProperty(Replay, "_events", []);
76
+ _defineProperty(Replay, "_stop", void 0);
77
+ export { Replay as default };
@@ -0,0 +1,5 @@
1
+ import { SystemProfile } from '../interfaces/track.interface';
2
+ export default class System {
3
+ private static IMEI;
4
+ static get profile(): SystemProfile;
5
+ }
@@ -0,0 +1,24 @@
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
+ import { generateRandomString } from "../Utils";
5
+ var System = /*#__PURE__*/function () {
6
+ function System() {
7
+ _classCallCheck(this, System);
8
+ }
9
+ _createClass(System, null, [{
10
+ key: "profile",
11
+ get: function get() {
12
+ return {
13
+ IMEI: this.IMEI,
14
+ innerHeight: typeof window !== 'undefined' ? window.innerHeight : 0,
15
+ innerWidth: typeof window !== 'undefined' ? window.innerWidth : 0,
16
+ href: typeof location !== 'undefined' ? location.href : '',
17
+ systemTime: new Date()
18
+ };
19
+ }
20
+ }]);
21
+ return System;
22
+ }();
23
+ _defineProperty(System, "IMEI", generateRandomString(6));
24
+ export { System as default };
@@ -0,0 +1,6 @@
1
+ import { UserProfile } from '../interfaces/track.interface';
2
+ export default class User {
3
+ private static _profile;
4
+ static setUserProfile(profile: UserProfile): void;
5
+ static get profile(): UserProfile | null;
6
+ }
@@ -0,0 +1,29 @@
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
+ var User = /*#__PURE__*/function () {
5
+ function User() {
6
+ _classCallCheck(this, User);
7
+ }
8
+ _createClass(User, null, [{
9
+ key: "setUserProfile",
10
+ value: function setUserProfile(profile) {
11
+ var _profile$userId, _profile$userName;
12
+ if (!((_profile$userId = profile.userId) !== null && _profile$userId !== void 0 && _profile$userId.trim())) {
13
+ throw new Error('UserProfile: userId is required');
14
+ }
15
+ if (!((_profile$userName = profile.userName) !== null && _profile$userName !== void 0 && _profile$userName.trim())) {
16
+ throw new Error('UserProfile: userName is required');
17
+ }
18
+ this._profile = profile;
19
+ }
20
+ }, {
21
+ key: "profile",
22
+ get: function get() {
23
+ return this._profile;
24
+ }
25
+ }]);
26
+ return User;
27
+ }();
28
+ _defineProperty(User, "_profile", null);
29
+ export { User as default };
@@ -1,17 +1,15 @@
1
- /**
2
- * 提供统一 Track.init(config) 及若干日志方法,未初始化即抛错
3
- */
4
- import { AuthCenterUserProfile, TrackConfig } from '../interfaces/track.interface';
5
- import { TrackerInstance } from './core';
6
- export type { TrackerInstance };
7
- type TrackAPI = {
8
- init: (config: TrackConfig) => Promise<AuthCenterUserProfile>;
9
- eventLog: TrackerInstance['eventLog'];
10
- visitLog: TrackerInstance['visitLog'];
11
- setUserProfile: (profile: Parameters<TrackerInstance['setUserProfile']>[0]) => void;
12
- config: TrackConfig;
13
- };
14
- declare const Track: TrackAPI & {
15
- getInstance?: (() => TrackerInstance) | undefined;
16
- };
17
- export default Track;
1
+ import { UserProfile } from '../interfaces/track.interface';
2
+ import { IConfig } from './Config';
3
+ import Log from './Log';
4
+ export default class Track {
5
+ static init(cfg: IConfig): void;
6
+ static setUserProfile(profile: UserProfile): void;
7
+ static get config(): IConfig;
8
+ static get userProfile(): UserProfile | null;
9
+ static get systemProfile(): import("../interfaces/track.interface").SystemProfile;
10
+ static run(): void;
11
+ static visitLog: typeof Log.visitLog;
12
+ static eventLog: typeof Log.eventLog;
13
+ static errorLog: typeof Log.errorLog;
14
+ static apiLog: typeof Log.apiLog;
15
+ }
@@ -1,68 +1,57 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- /**
4
- * 提供统一 Track.init(config) 及若干日志方法,未初始化即抛错
5
- */
6
-
7
- import { TrackerInstance } from "./core";
8
- // 模块级单例,简洁实现
9
- var _instance = null;
10
- var _profile = null;
11
- function init(_x) {
12
- return _init.apply(this, arguments);
13
- }
14
- function _init() {
15
- _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
16
- var ins, profile;
17
- return _regeneratorRuntime().wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
19
- case 0:
20
- if (!_instance) {
21
- _context.next = 2;
22
- break;
23
- }
24
- return _context.abrupt("return", Promise.resolve(_profile));
25
- case 2:
26
- ins = new TrackerInstance(config);
27
- _context.next = 5;
28
- return ins.init();
29
- case 5:
30
- profile = _context.sent;
31
- _instance = ins;
32
- _profile = profile;
33
- return _context.abrupt("return", profile);
34
- case 9:
35
- case "end":
36
- return _context.stop();
37
- }
38
- }, _callee);
39
- }));
40
- return _init.apply(this, arguments);
41
- }
42
- function ensure() {
43
- if (!_instance) throw new Error('Track 未初始化,请先调用 Track.init(config)');
44
- return _instance;
45
- }
46
-
47
- // 更安全的导出:显式 API 形状 + 绑定 this
48
-
49
- // 懒代理:除 init 外,所有方法直接代理到内部单例实例(调用时会 ensure)
50
- var Track = new Proxy({}, {
51
- get: function get(_, prop) {
52
- if (prop === 'init') return init;
53
- if (prop === 'config') return ensure().getConfig();
54
- // 返回一个函数,调用时转发到实例对应方法
55
- return function () {
56
- var inst = ensure();
57
- var fn = inst[prop];
58
- if (typeof fn !== 'function') {
59
- throw new Error("Track: no method named \"".concat(String(prop), "\" on instance"));
60
- }
61
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
62
- args[_key] = arguments[_key];
63
- }
64
- return fn.apply(inst, args);
65
- };
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
+ import Beacon from "./Beacon";
5
+ import Config from "./Config";
6
+ import Listener from "./Listener";
7
+ import Log from "./Log";
8
+ import Replay from "./Replay";
9
+ import System from "./System";
10
+ import User from "./User";
11
+ var Track = /*#__PURE__*/function () {
12
+ function Track() {
13
+ _classCallCheck(this, Track);
66
14
  }
67
- });
68
- export default Track;
15
+ _createClass(Track, null, [{
16
+ key: "init",
17
+ value: function init(cfg) {
18
+ Config.validate(cfg);
19
+ this.run();
20
+ }
21
+ }, {
22
+ key: "setUserProfile",
23
+ value: function setUserProfile(profile) {
24
+ User.setUserProfile(profile);
25
+ }
26
+ }, {
27
+ key: "config",
28
+ get: function get() {
29
+ return Config.data;
30
+ }
31
+ }, {
32
+ key: "userProfile",
33
+ get: function get() {
34
+ return User.profile;
35
+ }
36
+ }, {
37
+ key: "systemProfile",
38
+ get: function get() {
39
+ return System.profile;
40
+ }
41
+
42
+ // 需要初始化执行的组件都需在这里初始化调用
43
+ }, {
44
+ key: "run",
45
+ value: function run() {
46
+ Listener.run();
47
+ Replay.run();
48
+ Beacon.updateVersion();
49
+ }
50
+ }]);
51
+ return Track;
52
+ }();
53
+ _defineProperty(Track, "visitLog", Log.visitLog.bind(Log));
54
+ _defineProperty(Track, "eventLog", Log.eventLog.bind(Log));
55
+ _defineProperty(Track, "errorLog", Log.errorLog.bind(Log));
56
+ _defineProperty(Track, "apiLog", Log.apiLog.bind(Log));
57
+ export { Track as default };
@@ -1,2 +1,9 @@
1
- import { AuthDataType } from '../interfaces/track.interface';
2
- export declare const getAuthMapByAuthCenter: (authData: AuthDataType[]) => Map<string, string>;
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>;