@yysports/tools 2.2.6 → 3.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.
Files changed (45) hide show
  1. package/README.md +1 -6
  2. package/dist/Track/Beacon.d.ts +22 -3
  3. package/dist/Track/Beacon.js +93 -33
  4. package/dist/Track/Config.d.ts +4 -0
  5. package/dist/Track/Config.js +5 -1
  6. package/dist/Track/Listener.js +8 -4
  7. package/dist/Track/Log.d.ts +12 -2
  8. package/dist/Track/Log.js +71 -48
  9. package/dist/Track/Replay.d.ts +9 -1
  10. package/dist/Track/Replay.js +49 -44
  11. package/dist/Track/System.d.ts +3 -1
  12. package/dist/Track/System.js +8 -2
  13. package/dist/Track/envelope.d.ts +7 -0
  14. package/dist/Track/envelope.js +40 -0
  15. package/dist/Track/index.js +2 -1
  16. package/dist/Utils/route.js +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +2 -1
  19. package/dist/interfaces/protocol.d.ts +94 -0
  20. package/dist/interfaces/protocol.js +65 -0
  21. package/dist/interfaces/track.interface.d.ts +3 -8
  22. package/dist/interfaces/track.interface.js +3 -8
  23. package/lib/Track/Beacon.d.ts +22 -3
  24. package/lib/Track/Beacon.js +70 -28
  25. package/lib/Track/Config.d.ts +4 -0
  26. package/lib/Track/Config.js +5 -1
  27. package/lib/Track/Listener.js +7 -3
  28. package/lib/Track/Log.d.ts +12 -2
  29. package/lib/Track/Log.js +46 -35
  30. package/lib/Track/Replay.d.ts +9 -1
  31. package/lib/Track/Replay.js +32 -20
  32. package/lib/Track/System.d.ts +3 -1
  33. package/lib/Track/System.js +6 -2
  34. package/lib/Track/envelope.d.ts +7 -0
  35. package/lib/Track/envelope.js +76 -0
  36. package/lib/Track/index.js +1 -1
  37. package/lib/Utils/route.js +1 -1
  38. package/lib/index.d.ts +1 -0
  39. package/lib/index.js +3 -1
  40. package/lib/interfaces/protocol.d.ts +94 -0
  41. package/lib/interfaces/protocol.js +66 -0
  42. package/lib/interfaces/track.interface.d.ts +3 -8
  43. package/lib/interfaces/track.interface.js +5 -9
  44. package/package.json +20 -20
  45. package/LICENSE +0 -21
@@ -24,9 +24,13 @@ __export(System_exports, {
24
24
  module.exports = __toCommonJS(System_exports);
25
25
  var import_Utils = require("../Utils");
26
26
  var System = class {
27
+ /** 会话串,作为信封必填的 imei 上报(生成逻辑不变) */
28
+ static get imei() {
29
+ return this._imei;
30
+ }
27
31
  static get profile() {
28
32
  return {
29
- IMEI: this.IMEI,
33
+ imei: this._imei,
30
34
  innerHeight: typeof window !== "undefined" ? window.innerHeight : 0,
31
35
  innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
32
36
  href: typeof location !== "undefined" ? location.href : "",
@@ -34,4 +38,4 @@ var System = class {
34
38
  };
35
39
  }
36
40
  };
37
- System.IMEI = (0, import_Utils.generateRandomString)(6);
41
+ System._imei = (0, import_Utils.generateRandomString)(6);
@@ -0,0 +1,7 @@
1
+ import type { TrackV3Envelope, TrackV3Event } from '../interfaces/protocol';
2
+ /** 请求级公共段(信封):字段与实体属性同名(camelCase),每次请求仅一份 */
3
+ export declare function buildEnvelopeBase(): TrackV3Envelope;
4
+ /** 条级事件公共字段:href / 视口 / 毫秒时间戳在批量窗口内会变,逐条携带 */
5
+ export declare function buildEventBase(): Pick<TrackV3Event, 'systemTime' | 'href' | 'innerWidth' | 'innerHeight'>;
6
+ /** V3 上报地址:鉴权参数位统一走 URL query(sendBeacon 无法自定义 header) */
7
+ export declare function trackUrl(path: '/batch' | '/error'): string;
@@ -0,0 +1,76 @@
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/envelope.ts
30
+ var envelope_exports = {};
31
+ __export(envelope_exports, {
32
+ buildEnvelopeBase: () => buildEnvelopeBase,
33
+ buildEventBase: () => buildEventBase,
34
+ trackUrl: () => trackUrl
35
+ });
36
+ module.exports = __toCommonJS(envelope_exports);
37
+ var import_package = __toESM(require("../../package.json"));
38
+ var import_Config = __toESM(require("./Config"));
39
+ var import_System = __toESM(require("./System"));
40
+ var import_User = __toESM(require("./User"));
41
+ function buildEnvelopeBase() {
42
+ const profile = import_User.default.profile;
43
+ return {
44
+ appId: import_Config.default.data.appId,
45
+ sdkVersion: import_package.default.version,
46
+ imei: import_System.default.imei,
47
+ ...profile ? {
48
+ user: {
49
+ userId: profile.userId,
50
+ userName: profile.userName,
51
+ orgCode: profile.orgCode,
52
+ orgTitle: profile.orgTitle,
53
+ dataScopeZonePermissions: profile.dataScopeZonePermissions,
54
+ dataScopeRoles: profile.dataScopeRoles
55
+ }
56
+ } : {}
57
+ };
58
+ }
59
+ function buildEventBase() {
60
+ return {
61
+ systemTime: Date.now(),
62
+ href: typeof location !== "undefined" ? location.href : "",
63
+ innerWidth: typeof window !== "undefined" ? window.innerWidth : 0,
64
+ innerHeight: typeof window !== "undefined" ? window.innerHeight : 0
65
+ };
66
+ }
67
+ function trackUrl(path) {
68
+ const appId = encodeURIComponent(import_Config.default.data.appId);
69
+ return `${import_Config.default.data.domain}/pousheng-guard/api/track/v3${path}?appId=${appId}`;
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ buildEnvelopeBase,
74
+ buildEventBase,
75
+ trackUrl
76
+ });
@@ -60,7 +60,7 @@ var Track = class {
60
60
  static run() {
61
61
  import_Listener.default.run();
62
62
  import_Replay.default.run();
63
- import_Beacon.default.updateVersion();
63
+ import_Beacon.default.start();
64
64
  }
65
65
  // 获取当前页面模块名称
66
66
  static get module() {
@@ -27,7 +27,7 @@ var getModuleNameByUmi = (onRouteChangeArgs, menuNameMap) => {
27
27
  const { pathname } = location;
28
28
  let routePath = pathname;
29
29
  if (basename !== "/") {
30
- routePath = pathname.replace(basename, "");
30
+ routePath = pathname.replace(basename, "/");
31
31
  }
32
32
  const currentRouteKey = Object.keys(routes).find(
33
33
  (v) => routes[v].path === routePath
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as Track } from './Track';
2
2
  export * as Utils from './Utils';
3
3
  export * from './interfaces/track.interface';
4
+ export * from './interfaces/protocol';
package/lib/index.js CHANGED
@@ -37,9 +37,11 @@ module.exports = __toCommonJS(src_exports);
37
37
  var import_Track = __toESM(require("./Track"));
38
38
  var Utils = __toESM(require("./Utils"));
39
39
  __reExport(src_exports, require("./interfaces/track.interface"), module.exports);
40
+ __reExport(src_exports, require("./interfaces/protocol"), module.exports);
40
41
  // Annotate the CommonJS export names for ESM import in node:
41
42
  0 && (module.exports = {
42
43
  Track,
43
44
  Utils,
44
- ...require("./interfaces/track.interface")
45
+ ...require("./interfaces/track.interface"),
46
+ ...require("./interfaces/protocol")
45
47
  });
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 探针上报协议(V3)的唯一真源:类型与限额常量,供 SDK / 服务端 / 管理端共同复用。
3
+ *
4
+ * 约束:本文件只放无运行时依赖的类型与常量,不得引入 class-validator / typeorm / nest
5
+ * 等框架依赖;服务端的校验装饰器与 ORM 实体各自保留,不在此定义。
6
+ * 协议字段统一 camelCase,与 guard_track 的实体属性同名;库列的 snake_case
7
+ * (如 appId → app_id)由服务端 ORM 命名策略负责,协议层不感知列名。
8
+ */
9
+ /** 上报类型取值(与服务端 guard_track.type 枚举一致) */
10
+ export type TrackType = 'error' | 'visit' | 'event' | 'api';
11
+ /** 类型取值列表(服务端校验 / 管理端筛选用) */
12
+ export declare const TRACK_TYPE_VALUES: readonly TrackType[];
13
+ /** 类型展示标签(管理端表格、下拉用) */
14
+ export declare const TrackTypeLabel: Record<TrackType, string>;
15
+ /**
16
+ * 协议限额:服务端 DTO 校验与两侧截断共用同一份定义。
17
+ * 除 maxItems(协议约定)外,其余取值均对齐 guard_track 的列长,
18
+ * 不做无依据的额外限制——超长字段本身即会写入失败。
19
+ */
20
+ export declare const TRACK_LIMITS: {
21
+ /** 单次批量 events[] 条数上限(SDK batchSize 与服务端 DTO 共用) */
22
+ readonly maxItems: 20;
23
+ /** 探针版本号,guard_conf.version varchar(20) */
24
+ readonly sdkVersion: 20;
25
+ /** 会话串,列默认 varchar(255) */
26
+ readonly imei: 255;
27
+ /** 页面 URL,varchar(1000) */
28
+ readonly href: 1000;
29
+ /** 内容类字段(content / module / user.*),列默认 varchar(255) */
30
+ readonly content: 255;
31
+ readonly module: 255;
32
+ /** 用户画像单个字段长度 */
33
+ readonly userField: 255;
34
+ /** 用户 UA,varchar(1000) */
35
+ readonly userAgent: 1000;
36
+ /** V3 通道整体 body 上限(含内嵌回放),main.ts 直接引用 */
37
+ readonly bodyBytes: number;
38
+ };
39
+ /**
40
+ * 上报请求体 Content-Type:固定 text/plain(body 仍是 JSON 文本)。
41
+ * text/plain 属 CORS safelist,跨域不触发预检——sendBeacon / fetch 在页面卸载时
42
+ * 无需等待 OPTIONS 完成,避免「预检未及时返回」导致的丢数;服务端据此收原始文本再解析 JSON。
43
+ */
44
+ export declare const TRACK_CONTENT_TYPE = "text/plain;charset=UTF-8";
45
+ /** 用户画像(请求级恒定);未登录时整段缺省 */
46
+ export interface TrackV3User {
47
+ userId?: string;
48
+ userName?: string;
49
+ orgCode?: string;
50
+ orgTitle?: string;
51
+ dataScopeZonePermissions?: string;
52
+ dataScopeRoles?: string;
53
+ }
54
+ /** 条级事件:href / 视口在一个批量窗口内会变,逐条携带 */
55
+ export interface TrackV3Event {
56
+ /** 毫秒时间戳 */
57
+ systemTime: number;
58
+ type: Exclude<TrackType, 'error'>;
59
+ href: string;
60
+ innerWidth: number;
61
+ innerHeight: number;
62
+ module?: string;
63
+ /** visit / event 使用 */
64
+ content?: string;
65
+ /** api 使用 */
66
+ log?: string;
67
+ }
68
+ /** 请求级公共段(信封):一个请求只带一份 */
69
+ export interface TrackV3Envelope {
70
+ appId: string;
71
+ sdkVersion: string;
72
+ /** 会话串,前端初始化时生成;与库列名 `imei` 一致 */
73
+ imei: string;
74
+ user?: TrackV3User;
75
+ }
76
+ /** 通道 1:批量日志 */
77
+ export interface TrackV3BatchPayload extends TrackV3Envelope {
78
+ events: TrackV3Event[];
79
+ }
80
+ /** 通道 2 的错误明细 */
81
+ export interface TrackV3ErrorDetail {
82
+ systemTime: number;
83
+ href: string;
84
+ innerWidth: number;
85
+ innerHeight: number;
86
+ message: string;
87
+ stack?: string;
88
+ module?: string;
89
+ }
90
+ /** 通道 2:单条错误,可内嵌 rrweb 回放事件 */
91
+ export interface TrackV3ErrorPayload extends TrackV3Envelope {
92
+ error: TrackV3ErrorDetail;
93
+ replay?: unknown[];
94
+ }
@@ -0,0 +1,66 @@
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/interfaces/protocol.ts
20
+ var protocol_exports = {};
21
+ __export(protocol_exports, {
22
+ TRACK_CONTENT_TYPE: () => TRACK_CONTENT_TYPE,
23
+ TRACK_LIMITS: () => TRACK_LIMITS,
24
+ TRACK_TYPE_VALUES: () => TRACK_TYPE_VALUES,
25
+ TrackTypeLabel: () => TrackTypeLabel
26
+ });
27
+ module.exports = __toCommonJS(protocol_exports);
28
+ var TRACK_TYPE_VALUES = [
29
+ "error",
30
+ "visit",
31
+ "event",
32
+ "api"
33
+ ];
34
+ var TrackTypeLabel = {
35
+ error: "错误信息",
36
+ visit: "页面访问",
37
+ event: "用户触发",
38
+ api: "接口触发"
39
+ };
40
+ var TRACK_LIMITS = {
41
+ /** 单次批量 events[] 条数上限(SDK batchSize 与服务端 DTO 共用) */
42
+ maxItems: 20,
43
+ /** 探针版本号,guard_conf.version varchar(20) */
44
+ sdkVersion: 20,
45
+ /** 会话串,列默认 varchar(255) */
46
+ imei: 255,
47
+ /** 页面 URL,varchar(1000) */
48
+ href: 1e3,
49
+ /** 内容类字段(content / module / user.*),列默认 varchar(255) */
50
+ content: 255,
51
+ module: 255,
52
+ /** 用户画像单个字段长度 */
53
+ userField: 255,
54
+ /** 用户 UA,varchar(1000) */
55
+ userAgent: 1e3,
56
+ /** V3 通道整体 body 上限(含内嵌回放),main.ts 直接引用 */
57
+ bodyBytes: 1024 * 1024
58
+ };
59
+ var TRACK_CONTENT_TYPE = "text/plain;charset=UTF-8";
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ TRACK_CONTENT_TYPE,
63
+ TRACK_LIMITS,
64
+ TRACK_TYPE_VALUES,
65
+ TrackTypeLabel
66
+ });
@@ -1,10 +1,5 @@
1
- export declare enum TrackTypeEnum {
2
- error = "\u9519\u8BEF\u4FE1\u606F",
3
- visit = "\u9875\u9762\u8BBF\u95EE",
4
- event = "\u7528\u6237\u89E6\u53D1",
5
- api = "\u63A5\u53E3\u89E6\u53D1"
6
- }
7
- export type TrackType = keyof typeof TrackTypeEnum;
1
+ export { TrackTypeLabel, TRACK_TYPE_VALUES } from './protocol';
2
+ export type { TrackType } from './protocol';
8
3
  export interface UserProfile {
9
4
  userId: string;
10
5
  userName: string;
@@ -30,7 +25,7 @@ export interface AuthCenterUserProfile {
30
25
  authLogMap?: Record<string, string>;
31
26
  }
32
27
  export interface SystemProfile {
33
- IMEI: string;
28
+ imei: string;
34
29
  innerHeight: number;
35
30
  innerWidth: number;
36
31
  href: string;
@@ -19,17 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/interfaces/track.interface.ts
20
20
  var track_interface_exports = {};
21
21
  __export(track_interface_exports, {
22
- TrackTypeEnum: () => TrackTypeEnum
22
+ TRACK_TYPE_VALUES: () => import_protocol.TRACK_TYPE_VALUES,
23
+ TrackTypeLabel: () => import_protocol.TrackTypeLabel
23
24
  });
24
25
  module.exports = __toCommonJS(track_interface_exports);
25
- var TrackTypeEnum = /* @__PURE__ */ ((TrackTypeEnum2) => {
26
- TrackTypeEnum2["error"] = "错误信息";
27
- TrackTypeEnum2["visit"] = "页面访问";
28
- TrackTypeEnum2["event"] = "用户触发";
29
- TrackTypeEnum2["api"] = "接口触发";
30
- return TrackTypeEnum2;
31
- })(TrackTypeEnum || {});
26
+ var import_protocol = require("./protocol");
32
27
  // Annotate the CommonJS export names for ESM import in node:
33
28
  0 && (module.exports = {
34
- TrackTypeEnum
29
+ TRACK_TYPE_VALUES,
30
+ TrackTypeLabel
35
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "2.2.6",
3
+ "version": "3.0.1",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -10,8 +10,8 @@
10
10
  "type": "git",
11
11
  "url": "git+https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools.git"
12
12
  },
13
- "license": "MIT",
14
- "author": "",
13
+ "license": "UNLICENSED",
14
+ "author": "daiwenyu",
15
15
  "main": "lib/index.js",
16
16
  "module": "dist/index.js",
17
17
  "types": "dist/index.d.ts",
@@ -60,30 +60,30 @@
60
60
  ]
61
61
  },
62
62
  "dependencies": {
63
- "@babel/runtime": "^7.28.4",
64
- "@rrweb/record": "2.0.0-alpha.18",
65
- "@rrweb/rrweb-plugin-console-record": "2.0.0-alpha.18",
63
+ "@babel/runtime": "^7.29.7",
64
+ "@rrweb/record": "2.1.6",
65
+ "@rrweb/rrweb-plugin-console-record": "2.1.6",
66
66
  "image-conversion": "^2.1.1"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@ant-design/pro-components": "^2.8.10",
70
- "@commitlint/cli": "^20.1.0",
71
- "@commitlint/config-conventional": "^20.0.0",
72
- "@types/react": "^19.2.6",
73
- "@types/react-dom": "^19.2.3",
74
- "@umijs/lint": "^4.5.3",
75
- "antd": "^6.0.0",
76
- "dumi": "^2.4.21",
70
+ "@commitlint/cli": "^20.5.3",
71
+ "@commitlint/config-conventional": "^20.5.3",
72
+ "@types/react": "^19.3.0",
73
+ "@types/react-dom": "^19.3.0",
74
+ "@umijs/lint": "^4.7.19",
75
+ "antd": "^6.6.4",
76
+ "dumi": "^2.4.49",
77
77
  "eslint": "^8.57.1",
78
- "father": "^4.6.7",
78
+ "father": "^4.6.38",
79
79
  "husky": "^9.1.7",
80
- "lint-staged": "^16.2.7",
81
- "prettier": "^3.6.2",
80
+ "lint-staged": "^16.4.0",
81
+ "prettier": "^3.9.8",
82
82
  "prettier-plugin-organize-imports": "^4.3.0",
83
- "prettier-plugin-packagejson": "^2.5.19",
84
- "react": "^19.2.0",
85
- "react-dom": "^19.2.0",
86
- "stylelint": "^16.26.0"
83
+ "prettier-plugin-packagejson": "^2.5.22",
84
+ "react": "^19.3.0",
85
+ "react-dom": "^19.3.0",
86
+ "stylelint": "^16.26.1"
87
87
  },
88
88
  "publishConfig": {
89
89
  "access": "public"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.