@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.
- 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 -17
- package/dist/Track/index.js +56 -67
- 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 +2 -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 -17
- package/lib/Track/index.js +45 -39
- 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 +2 -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 -17
- package/dist/Track/core/constants.js +0 -34
- package/dist/Track/core/envelope.d.ts +0 -9
- package/dist/Track/core/envelope.js +0 -54
- package/dist/Track/core/index.d.ts +0 -22
- package/dist/Track/core/index.js +0 -23
- package/dist/Track/core/instance.d.ts +0 -108
- package/dist/Track/core/instance.js +0 -375
- 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 -165
- 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 -17
- package/lib/Track/core/constants.js +0 -65
- package/lib/Track/core/envelope.d.ts +0 -9
- package/lib/Track/core/envelope.js +0 -61
- package/lib/Track/core/index.d.ts +0 -22
- package/lib/Track/core/index.js +0 -51
- package/lib/Track/core/instance.d.ts +0 -108
- package/lib/Track/core/instance.js +0 -266
- 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 -128
package/lib/Track/Log.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
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/Log.ts
|
|
30
|
+
var Log_exports = {};
|
|
31
|
+
__export(Log_exports, {
|
|
32
|
+
default: () => Log
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Log_exports);
|
|
35
|
+
var import_Beacon = __toESM(require("./Beacon"));
|
|
36
|
+
var import_Config = __toESM(require("./Config"));
|
|
37
|
+
var import_Replay = __toESM(require("./Replay"));
|
|
38
|
+
var import_System = __toESM(require("./System"));
|
|
39
|
+
var import_User = __toESM(require("./User"));
|
|
40
|
+
var Log = class {
|
|
41
|
+
// 上报日志的公共属性
|
|
42
|
+
static _commonProps() {
|
|
43
|
+
return {
|
|
44
|
+
...import_User.default.profile,
|
|
45
|
+
...import_System.default.profile,
|
|
46
|
+
appId: import_Config.default.data.appId,
|
|
47
|
+
module: this._module
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
static visitLog(module2) {
|
|
51
|
+
this._module = module2;
|
|
52
|
+
const lastModule = this._module.split("-").pop();
|
|
53
|
+
import_Beacon.default.push({
|
|
54
|
+
...this._commonProps(),
|
|
55
|
+
type: "visit",
|
|
56
|
+
content: `访问页面:${lastModule}`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
static eventLog(content) {
|
|
60
|
+
import_Beacon.default.push({
|
|
61
|
+
...this._commonProps(),
|
|
62
|
+
type: "event",
|
|
63
|
+
content
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static async errorLog(message) {
|
|
67
|
+
const res = await fetch(
|
|
68
|
+
`${import_Config.default.data.domain}/pousheng-guard/api/track/error`,
|
|
69
|
+
{
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/json"
|
|
73
|
+
},
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
...this._commonProps(),
|
|
76
|
+
type: "error",
|
|
77
|
+
log: JSON.stringify({ message })
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
const { data: id } = await res.json();
|
|
82
|
+
if (import_Config.default.data.autoReportError) {
|
|
83
|
+
import_Replay.default.reportSnapshot(id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
static apiLog(log) {
|
|
87
|
+
import_Beacon.default.push({
|
|
88
|
+
...this._commonProps(),
|
|
89
|
+
type: "api",
|
|
90
|
+
log
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// 当前模块
|
|
95
|
+
Log._module = "";
|
|
@@ -0,0 +1,79 @@
|
|
|
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/Replay.ts
|
|
30
|
+
var Replay_exports = {};
|
|
31
|
+
__export(Replay_exports, {
|
|
32
|
+
default: () => Replay
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Replay_exports);
|
|
35
|
+
var import_record = require("@rrweb/record");
|
|
36
|
+
var import_rrweb_plugin_console_record = require("@rrweb/rrweb-plugin-console-record");
|
|
37
|
+
var import_Config = __toESM(require("./Config"));
|
|
38
|
+
var Replay = class {
|
|
39
|
+
static run() {
|
|
40
|
+
if (this._stop || !import_Config.default.data.enableReplay) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
this._stop = (0, import_record.record)({
|
|
45
|
+
emit: (e) => {
|
|
46
|
+
this._events.push(e);
|
|
47
|
+
const over = this._events.length - 1e3;
|
|
48
|
+
if (over > 0)
|
|
49
|
+
this._events.splice(0, over);
|
|
50
|
+
},
|
|
51
|
+
plugins: [
|
|
52
|
+
(0, import_rrweb_plugin_console_record.getRecordConsolePlugin)({
|
|
53
|
+
level: ["log", "info", "warn", "error", "debug"]
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
} catch (err) {
|
|
58
|
+
this._stop = void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 快照
|
|
62
|
+
static async reportSnapshot(errorId) {
|
|
63
|
+
if (!this._stop) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await fetch(
|
|
67
|
+
`${import_Config.default.data.domain}/pousheng-guard/api/track/error-replay/${errorId}`,
|
|
68
|
+
{
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": "text/plain"
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(this._events)
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
this._events = [];
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
Replay._events = [];
|
|
@@ -16,24 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/Track/
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
23
|
-
getPageModules: () => getPageModules
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(router_exports);
|
|
26
|
-
function getFormattedPath(config) {
|
|
27
|
-
const { base = "/" } = config;
|
|
28
|
-
const pathname = typeof location !== "undefined" ? location.pathname : "";
|
|
29
|
-
return pathname.replace(base, "/");
|
|
30
|
-
}
|
|
31
|
-
function getPageModules(config, routesMap) {
|
|
32
|
-
const ri = routesMap.get(getFormattedPath(config));
|
|
33
|
-
return (ri == null ? void 0 : ri.module) || [];
|
|
34
|
-
}
|
|
35
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
-
0 && (module.exports = {
|
|
37
|
-
getFormattedPath,
|
|
38
|
-
getPageModules
|
|
19
|
+
// src/Track/System.ts
|
|
20
|
+
var System_exports = {};
|
|
21
|
+
__export(System_exports, {
|
|
22
|
+
default: () => System
|
|
39
23
|
});
|
|
24
|
+
module.exports = __toCommonJS(System_exports);
|
|
25
|
+
var import_Utils = require("../Utils");
|
|
26
|
+
var System = class {
|
|
27
|
+
static get profile() {
|
|
28
|
+
return {
|
|
29
|
+
IMEI: this.IMEI,
|
|
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: /* @__PURE__ */ new Date()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
System.IMEI = (0, import_Utils.generateRandomString)(6);
|
|
@@ -0,0 +1,40 @@
|
|
|
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/User.ts
|
|
20
|
+
var User_exports = {};
|
|
21
|
+
__export(User_exports, {
|
|
22
|
+
default: () => User
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(User_exports);
|
|
25
|
+
var User = class {
|
|
26
|
+
static setUserProfile(profile) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (!((_a = profile.userId) == null ? void 0 : _a.trim())) {
|
|
29
|
+
throw new Error("UserProfile: userId is required");
|
|
30
|
+
}
|
|
31
|
+
if (!((_b = profile.userName) == null ? void 0 : _b.trim())) {
|
|
32
|
+
throw new Error("UserProfile: userName is required");
|
|
33
|
+
}
|
|
34
|
+
this._profile = profile;
|
|
35
|
+
}
|
|
36
|
+
static get profile() {
|
|
37
|
+
return this._profile;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
User._profile = null;
|
package/lib/Track/index.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
package/lib/Track/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,50 +16,54 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/Track/index.ts
|
|
20
30
|
var Track_exports = {};
|
|
21
31
|
__export(Track_exports, {
|
|
22
|
-
default: () =>
|
|
32
|
+
default: () => Track
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(Track_exports);
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
function ensure() {
|
|
38
|
-
if (!_instance)
|
|
39
|
-
throw new Error("Track 未初始化,请先调用 Track.init(config)");
|
|
40
|
-
return _instance;
|
|
41
|
-
}
|
|
42
|
-
var Track = new Proxy(
|
|
43
|
-
{},
|
|
44
|
-
{
|
|
45
|
-
get(_, prop) {
|
|
46
|
-
if (prop === "init")
|
|
47
|
-
return init;
|
|
48
|
-
if (prop === "config")
|
|
49
|
-
return ensure().getConfig();
|
|
50
|
-
return (...args) => {
|
|
51
|
-
const inst = ensure();
|
|
52
|
-
const fn = inst[prop];
|
|
53
|
-
if (typeof fn !== "function") {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Track: no method named "${String(prop)}" on instance`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return fn.apply(inst, args);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
35
|
+
var import_Beacon = __toESM(require("./Beacon"));
|
|
36
|
+
var import_Config = __toESM(require("./Config"));
|
|
37
|
+
var import_Listener = __toESM(require("./Listener"));
|
|
38
|
+
var import_Log = __toESM(require("./Log"));
|
|
39
|
+
var import_Replay = __toESM(require("./Replay"));
|
|
40
|
+
var import_System = __toESM(require("./System"));
|
|
41
|
+
var import_User = __toESM(require("./User"));
|
|
42
|
+
var Track = class {
|
|
43
|
+
static init(cfg) {
|
|
44
|
+
import_Config.default.validate(cfg);
|
|
45
|
+
this.run();
|
|
61
46
|
}
|
|
62
|
-
)
|
|
63
|
-
|
|
47
|
+
static setUserProfile(profile) {
|
|
48
|
+
import_User.default.setUserProfile(profile);
|
|
49
|
+
}
|
|
50
|
+
static get config() {
|
|
51
|
+
return import_Config.default.data;
|
|
52
|
+
}
|
|
53
|
+
static get userProfile() {
|
|
54
|
+
return import_User.default.profile;
|
|
55
|
+
}
|
|
56
|
+
static get systemProfile() {
|
|
57
|
+
return import_System.default.profile;
|
|
58
|
+
}
|
|
59
|
+
// 需要初始化执行的组件都需在这里初始化调用
|
|
60
|
+
static run() {
|
|
61
|
+
import_Listener.default.run();
|
|
62
|
+
import_Replay.default.run();
|
|
63
|
+
import_Beacon.default.updateVersion();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
Track.visitLog = import_Log.default.visitLog.bind(import_Log.default);
|
|
67
|
+
Track.eventLog = import_Log.default.eventLog.bind(import_Log.default);
|
|
68
|
+
Track.errorLog = import_Log.default.errorLog.bind(import_Log.default);
|
|
69
|
+
Track.apiLog = import_Log.default.apiLog.bind(import_Log.default);
|
package/lib/Utils/auth.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AuthCenterUserProfile } from '../interfaces/track.interface';
|
|
2
|
+
/**
|
|
3
|
+
* 获取当前用户在权限中心的信息,并格式化前端路由所需的数据格式
|
|
4
|
+
* @param fetchUserInfo
|
|
5
|
+
* @param fetchMenuBuild
|
|
6
|
+
* @param fetchZoneScope
|
|
7
|
+
* @returns {Promise<AuthCenterUserProfile>}
|
|
8
|
+
*/
|
|
9
|
+
export declare const fetchCurrentUserFromAuthCenter: (fetchUserInfo: () => Promise<any>, fetchMenuBuild: () => Promise<any>, fetchZoneScope?: () => Promise<any>) => Promise<AuthCenterUserProfile>;
|
package/lib/Utils/auth.js
CHANGED
|
@@ -19,27 +19,62 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/Utils/auth.ts
|
|
20
20
|
var auth_exports = {};
|
|
21
21
|
__export(auth_exports, {
|
|
22
|
-
|
|
22
|
+
fetchCurrentUserFromAuthCenter: () => fetchCurrentUserFromAuthCenter
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(auth_exports);
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
var fetchCurrentUserFromAuthCenter = async (fetchUserInfo, fetchMenuBuild, fetchZoneScope) => {
|
|
26
|
+
const [userInfo, menuBuild, zoneScope] = await Promise.all([
|
|
27
|
+
fetchUserInfo == null ? void 0 : fetchUserInfo(),
|
|
28
|
+
fetchMenuBuild == null ? void 0 : fetchMenuBuild(),
|
|
29
|
+
fetchZoneScope == null ? void 0 : fetchZoneScope()
|
|
30
|
+
]);
|
|
31
|
+
const currentUser = {};
|
|
32
|
+
if (userInfo) {
|
|
33
|
+
const { user = {}, roles = [] } = userInfo;
|
|
34
|
+
const { roles: dataScopeRoles = [] } = user;
|
|
35
|
+
const isAdmin = roles.includes("admin");
|
|
36
|
+
Object.assign(currentUser, {
|
|
37
|
+
...user,
|
|
38
|
+
dataScopeRoles,
|
|
39
|
+
// 用户拥有的数据权限角色
|
|
40
|
+
roles,
|
|
41
|
+
// 用户拥有的页面、功能权限列表
|
|
42
|
+
isAdmin
|
|
43
|
+
// 是否为管理员
|
|
37
44
|
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
}
|
|
46
|
+
if (zoneScope) {
|
|
47
|
+
Object.assign(currentUser, {
|
|
48
|
+
dataScopeZonePermissions: zoneScope
|
|
49
|
+
// 用户拥有的数据权限区域列表
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(menuBuild)) {
|
|
53
|
+
const accessPage = [];
|
|
54
|
+
const authLogMap = {};
|
|
55
|
+
const traverseMenu = (menus) => {
|
|
56
|
+
menus.forEach(({ permission, logAction, children }) => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (permission && (currentUser.isAdmin || ((_a = currentUser.roles) == null ? void 0 : _a.includes(permission)))) {
|
|
59
|
+
accessPage.push(permission);
|
|
60
|
+
if (logAction) {
|
|
61
|
+
authLogMap[permission] = logAction;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
65
|
+
traverseMenu(children);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
traverseMenu(menuBuild);
|
|
70
|
+
Object.assign(currentUser, {
|
|
71
|
+
accessPage,
|
|
72
|
+
authLogMap
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return currentUser;
|
|
41
76
|
};
|
|
42
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
78
|
0 && (module.exports = {
|
|
44
|
-
|
|
79
|
+
fetchCurrentUserFromAuthCenter
|
|
45
80
|
});
|
package/lib/Utils/route.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 适用于 Umi 框架的路由模块名称获取
|
|
3
|
+
* @param onRouteChangeArgs onRouteChange的参数
|
|
4
|
+
* @param menuNameMap 国际化菜单名称映射表
|
|
5
|
+
* @returns {undefined | string} 模块名称,格式如 "菜单1-子菜单A-子菜单a1",如果无法获取则返回 undefined
|
|
6
|
+
*/
|
|
7
|
+
export declare const getModuleNameByUmi: (onRouteChangeArgs: {
|
|
8
|
+
location: any;
|
|
9
|
+
routes: any;
|
|
10
|
+
}, menuNameMap?: {
|
|
3
11
|
[key: string]: string;
|
|
4
|
-
} | undefined) =>
|
|
12
|
+
} | undefined) => string | undefined;
|
package/lib/Utils/route.js
CHANGED
|
@@ -19,59 +19,44 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/Utils/route.ts
|
|
20
20
|
var route_exports = {};
|
|
21
21
|
__export(route_exports, {
|
|
22
|
-
|
|
22
|
+
getModuleNameByUmi: () => getModuleNameByUmi
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(route_exports);
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (redirect) {
|
|
44
|
-
Object.assign(savedRoute, { isRedirect: true });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
|
|
48
|
-
const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
|
|
49
|
-
if (name) {
|
|
50
|
-
nameArr.push(name);
|
|
51
|
-
if (menuNameMap) {
|
|
52
|
-
const menuKey = ["menu", ...nameArr].join(".");
|
|
53
|
-
moduleArr.push(menuNameMap[menuKey]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (access) {
|
|
57
|
-
Object.assign(savedRoute, {
|
|
58
|
-
access: [...savedRoute.access || [], access]
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const routeInfo = {
|
|
62
|
-
name: nameArr,
|
|
63
|
-
module: moduleArr
|
|
64
|
-
};
|
|
65
|
-
Object.assign(savedRoute, routeInfo);
|
|
66
|
-
if (routes2) {
|
|
67
|
-
ergodicLocalMenu(routes2, routeInfo);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
25
|
+
var getModuleNameByUmi = (onRouteChangeArgs, menuNameMap) => {
|
|
26
|
+
const { location, routes } = onRouteChangeArgs;
|
|
27
|
+
const { pathname } = location;
|
|
28
|
+
const currentRouteKey = Object.keys(routes).find(
|
|
29
|
+
(v) => routes[v].path === pathname
|
|
30
|
+
);
|
|
31
|
+
if (!currentRouteKey || routes[currentRouteKey].redirect) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const menuHierarchyKeys = ["menu"];
|
|
35
|
+
const buildMenuHierarchy = (routeId) => {
|
|
36
|
+
const route = routes[routeId];
|
|
37
|
+
if (route == null ? void 0 : route.name) {
|
|
38
|
+
menuHierarchyKeys.splice(1, 0, route.name);
|
|
39
|
+
}
|
|
40
|
+
if (route == null ? void 0 : route.parentId) {
|
|
41
|
+
buildMenuHierarchy(route.parentId);
|
|
42
|
+
}
|
|
70
43
|
};
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
buildMenuHierarchy(currentRouteKey);
|
|
45
|
+
if (menuHierarchyKeys.length === 1) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const menuDisplayNames = [];
|
|
49
|
+
for (let i = 1; i < menuHierarchyKeys.length; i++) {
|
|
50
|
+
const menuKey = menuHierarchyKeys.slice(0, i + 1).join(".");
|
|
51
|
+
const displayName = menuNameMap[menuKey];
|
|
52
|
+
menuDisplayNames.push(displayName);
|
|
53
|
+
}
|
|
54
|
+
if (menuDisplayNames.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return menuDisplayNames.join("-");
|
|
73
58
|
};
|
|
74
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
60
|
0 && (module.exports = {
|
|
76
|
-
|
|
61
|
+
getModuleNameByUmi
|
|
77
62
|
});
|
package/lib/Utils/url.js
CHANGED
|
@@ -34,9 +34,9 @@ var getUrlParams = (str) => {
|
|
|
34
34
|
}
|
|
35
35
|
const searchParams = new URLSearchParams(paramsStr);
|
|
36
36
|
const params = {};
|
|
37
|
-
|
|
38
|
-
params[
|
|
39
|
-
}
|
|
37
|
+
searchParams.forEach((value, key) => {
|
|
38
|
+
params[key] = value;
|
|
39
|
+
});
|
|
40
40
|
return params;
|
|
41
41
|
};
|
|
42
42
|
// Annotate the CommonJS export names for ESM import in node:
|