@yysports/tools 3.0.1 → 3.0.3

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.
@@ -1,6 +1,12 @@
1
1
  export interface IConfig {
2
2
  appId: string;
3
3
  domain: string;
4
+ /**
5
+ * 调用方应用自身的版本号(可选)。
6
+ * 探针取不到宿主程序版本(`sdkVersion` 是探针自己的版本),只能由接入方显式传入;
7
+ * 不传时服务端 `guard_track.app_version` 落 NULL,不影响上报。
8
+ */
9
+ appVersion?: string;
4
10
  autoReportError?: boolean;
5
11
  enableReplay?: boolean;
6
12
  batchSize?: number;
@@ -2,8 +2,17 @@ type RRWebEvent = any;
2
2
  export default class Replay {
3
3
  private static _events;
4
4
  private static _stop;
5
+ private static _loading;
5
6
  private static _bytes;
6
- static run(): void;
7
+ /**
8
+ * 启动录制。
9
+ *
10
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
11
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
12
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
13
+ * 错误本体的上报不受影响)。
14
+ */
15
+ static run(): Promise<void>;
7
16
  /** 截断到体积上限,保留最近片段 */
8
17
  private static truncate;
9
18
  /** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
@@ -1,10 +1,11 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
6
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
7
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
8
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
- import { record } from '@rrweb/record';
7
- import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
8
9
  import Config from "./Config";
9
10
  var Replay = /*#__PURE__*/function () {
10
11
  function Replay() {
@@ -12,36 +13,77 @@ var Replay = /*#__PURE__*/function () {
12
13
  }
13
14
  _createClass(Replay, null, [{
14
15
  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(_objectSpread(_objectSpread({
22
- emit: function emit(e) {
23
- _this._events.push(e);
24
- _this._bytes += JSON.stringify(e).length;
25
- _this.truncate();
26
- },
27
- // 输入掩码:password 类型强制掩码,防止敏感输入进入回放文件;
28
- // 其余类型可由接入方通过 replayMaskTextClass 扩展
29
- maskInputOptions: {
30
- password: true
16
+ value: (
17
+ /**
18
+ * 启动录制。
19
+ *
20
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
21
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
22
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
23
+ * 错误本体的上报不受影响)。
24
+ */
25
+ function () {
26
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
27
+ var _this = this;
28
+ var _yield$Promise$all, _yield$Promise$all2, startRecord, getRecordConsolePlugin;
29
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
30
+ while (1) switch (_context.prev = _context.next) {
31
+ case 0:
32
+ if (!(this._stop || this._loading || !Config.data.enableReplay)) {
33
+ _context.next = 2;
34
+ break;
35
+ }
36
+ return _context.abrupt("return");
37
+ case 2:
38
+ this._loading = true;
39
+ _context.prev = 3;
40
+ _context.next = 6;
41
+ return Promise.all([import('@rrweb/record'), import('@rrweb/rrweb-plugin-console-record')]);
42
+ case 6:
43
+ _yield$Promise$all = _context.sent;
44
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
45
+ startRecord = _yield$Promise$all2[0].record;
46
+ getRecordConsolePlugin = _yield$Promise$all2[1].getRecordConsolePlugin;
47
+ this._stop = startRecord(_objectSpread(_objectSpread({
48
+ emit: function emit(e) {
49
+ _this._events.push(e);
50
+ _this._bytes += JSON.stringify(e).length;
51
+ _this.truncate();
52
+ },
53
+ // 输入掩码:password 类型强制掩码,防止敏感输入进入回放文件;
54
+ // 其余类型可由接入方通过 replayMaskTextClass 扩展
55
+ maskInputOptions: {
56
+ password: true
57
+ }
58
+ }, Config.data.replayMaskTextClass ? {
59
+ maskTextClass: Config.data.replayMaskTextClass
60
+ } : {}), {}, {
61
+ plugins: [getRecordConsolePlugin({
62
+ level: ['log', 'info', 'warn', 'error', 'debug']
63
+ })]
64
+ }));
65
+ _context.next = 16;
66
+ break;
67
+ case 13:
68
+ _context.prev = 13;
69
+ _context.t0 = _context["catch"](3);
70
+ // 加载或启动失败:静默降级,仅回放不可用
71
+ this._stop = undefined;
72
+ case 16:
73
+ _context.prev = 16;
74
+ this._loading = false;
75
+ return _context.finish(16);
76
+ case 19:
77
+ case "end":
78
+ return _context.stop();
31
79
  }
32
- }, Config.data.replayMaskTextClass ? {
33
- maskTextClass: Config.data.replayMaskTextClass
34
- } : {}), {}, {
35
- plugins: [getRecordConsolePlugin({
36
- level: ['log', 'info', 'warn', 'error', 'debug']
37
- })]
38
- }));
39
- } catch (err) {
40
- this._stop = undefined;
80
+ }, _callee, this, [[3, 13, 16, 19]]);
81
+ }));
82
+ function run() {
83
+ return _run.apply(this, arguments);
41
84
  }
42
- }
43
-
44
- /** 截断到体积上限,保留最近片段 */
85
+ return run;
86
+ }() /** 截断到体积上限,保留最近片段 */)
45
87
  }, {
46
88
  key: "truncate",
47
89
  value: function truncate() {
@@ -81,6 +123,8 @@ var Replay = /*#__PURE__*/function () {
81
123
  }();
82
124
  _defineProperty(Replay, "_events", []);
83
125
  _defineProperty(Replay, "_stop", void 0);
126
+ // rrweb 异步加载中的标记:避免 init 被重复调用时启动两个录制实例
127
+ _defineProperty(Replay, "_loading", false);
84
128
  // 录制阶段的累计体积(近似值),达到 replayMaxBytes 后从最早事件开始截断
85
129
  _defineProperty(Replay, "_bytes", 0);
86
130
  export { Replay as default };
@@ -10,6 +10,8 @@ export function buildEnvelopeBase() {
10
10
  return _objectSpread({
11
11
  appId: Config.data.appId,
12
12
  sdkVersion: packageJson.version,
13
+ // 调用方应用版本:未配置时为 undefined,JSON.stringify 会丢弃该键(服务端落 NULL)
14
+ appVersion: Config.data.appVersion,
13
15
  imei: System.imei
14
16
  }, profile ? {
15
17
  user: {
@@ -44,7 +44,8 @@ var Track = /*#__PURE__*/function () {
44
44
  key: "run",
45
45
  value: function run() {
46
46
  Listener.run();
47
- Replay.run();
47
+ // 回放为异步启动(rrweb 懒加载),不阻塞 init;未开回放时不会加载 rrweb
48
+ void Replay.run();
48
49
  // 版本上报已并入信封 sdkVersion,不再有独立请求
49
50
  Beacon.start();
50
51
  }
@@ -22,6 +22,8 @@ export declare const TRACK_LIMITS: {
22
22
  readonly maxItems: 20;
23
23
  /** 探针版本号,guard_conf.version varchar(20) */
24
24
  readonly sdkVersion: 20;
25
+ /** 应用版本号(调用方应用自身版本,与探针版本无关),guard_track.app_version varchar(20) */
26
+ readonly appVersion: 20;
25
27
  /** 会话串,列默认 varchar(255) */
26
28
  readonly imei: 255;
27
29
  /** 页面 URL,varchar(1000) */
@@ -69,6 +71,12 @@ export interface TrackV3Event {
69
71
  export interface TrackV3Envelope {
70
72
  appId: string;
71
73
  sdkVersion: string;
74
+ /**
75
+ * 调用方应用**自身**的版本号(由接入方在 `init` 的 `appVersion` 传入)。
76
+ * 可选:老版本探针不传,服务端该列落 `NULL`——**不得设为必填**,否则线上旧探针会全部 400。
77
+ * 与 `sdkVersion`(探针自身版本)语义无关,服务端不允许相互顶替。
78
+ */
79
+ appVersion?: string;
72
80
  /** 会话串,前端初始化时生成;与库列名 `imei` 一致 */
73
81
  imei: string;
74
82
  user?: TrackV3User;
@@ -30,6 +30,8 @@ export var TRACK_LIMITS = {
30
30
  maxItems: 20,
31
31
  /** 探针版本号,guard_conf.version varchar(20) */
32
32
  sdkVersion: 20,
33
+ /** 应用版本号(调用方应用自身版本,与探针版本无关),guard_track.app_version varchar(20) */
34
+ appVersion: 20,
33
35
  /** 会话串,列默认 varchar(255) */
34
36
  imei: 255,
35
37
  /** 页面 URL,varchar(1000) */
@@ -1,6 +1,12 @@
1
1
  export interface IConfig {
2
2
  appId: string;
3
3
  domain: string;
4
+ /**
5
+ * 调用方应用自身的版本号(可选)。
6
+ * 探针取不到宿主程序版本(`sdkVersion` 是探针自己的版本),只能由接入方显式传入;
7
+ * 不传时服务端 `guard_track.app_version` 落 NULL,不影响上报。
8
+ */
9
+ appVersion?: string;
4
10
  autoReportError?: boolean;
5
11
  enableReplay?: boolean;
6
12
  batchSize?: number;
@@ -2,8 +2,17 @@ type RRWebEvent = any;
2
2
  export default class Replay {
3
3
  private static _events;
4
4
  private static _stop;
5
+ private static _loading;
5
6
  private static _bytes;
6
- static run(): void;
7
+ /**
8
+ * 启动录制。
9
+ *
10
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
11
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
12
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
13
+ * 错误本体的上报不受影响)。
14
+ */
15
+ static run(): Promise<void>;
7
16
  /** 截断到体积上限,保留最近片段 */
8
17
  private static truncate;
9
18
  /** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
@@ -32,16 +32,27 @@ __export(Replay_exports, {
32
32
  default: () => Replay
33
33
  });
34
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
35
  var import_Config = __toESM(require("./Config"));
38
36
  var Replay = class {
39
- static run() {
40
- if (this._stop || !import_Config.default.data.enableReplay) {
37
+ /**
38
+ * 启动录制。
39
+ *
40
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
41
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
42
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
43
+ * 错误本体的上报不受影响)。
44
+ */
45
+ static async run() {
46
+ if (this._stop || this._loading || !import_Config.default.data.enableReplay) {
41
47
  return;
42
48
  }
49
+ this._loading = true;
43
50
  try {
44
- this._stop = (0, import_record.record)({
51
+ const [{ record: startRecord }, { getRecordConsolePlugin }] = await Promise.all([
52
+ import("@rrweb/record"),
53
+ import("@rrweb/rrweb-plugin-console-record")
54
+ ]);
55
+ this._stop = startRecord({
45
56
  emit: (e) => {
46
57
  this._events.push(e);
47
58
  this._bytes += JSON.stringify(e).length;
@@ -52,13 +63,15 @@ var Replay = class {
52
63
  maskInputOptions: { password: true },
53
64
  ...import_Config.default.data.replayMaskTextClass ? { maskTextClass: import_Config.default.data.replayMaskTextClass } : {},
54
65
  plugins: [
55
- (0, import_rrweb_plugin_console_record.getRecordConsolePlugin)({
66
+ getRecordConsolePlugin({
56
67
  level: ["log", "info", "warn", "error", "debug"]
57
68
  })
58
69
  ]
59
70
  });
60
71
  } catch (err) {
61
72
  this._stop = void 0;
73
+ } finally {
74
+ this._loading = false;
62
75
  }
63
76
  }
64
77
  /** 截断到体积上限,保留最近片段 */
@@ -90,5 +103,7 @@ var Replay = class {
90
103
  }
91
104
  };
92
105
  Replay._events = [];
106
+ // rrweb 异步加载中的标记:避免 init 被重复调用时启动两个录制实例
107
+ Replay._loading = false;
93
108
  // 录制阶段的累计体积(近似值),达到 replayMaxBytes 后从最早事件开始截断
94
109
  Replay._bytes = 0;
@@ -43,6 +43,8 @@ function buildEnvelopeBase() {
43
43
  return {
44
44
  appId: import_Config.default.data.appId,
45
45
  sdkVersion: import_package.default.version,
46
+ // 调用方应用版本:未配置时为 undefined,JSON.stringify 会丢弃该键(服务端落 NULL)
47
+ appVersion: import_Config.default.data.appVersion,
46
48
  imei: import_System.default.imei,
47
49
  ...profile ? {
48
50
  user: {
@@ -59,7 +59,7 @@ var Track = class {
59
59
  // 需要初始化执行的组件都需在这里初始化调用
60
60
  static run() {
61
61
  import_Listener.default.run();
62
- import_Replay.default.run();
62
+ void import_Replay.default.run();
63
63
  import_Beacon.default.start();
64
64
  }
65
65
  // 获取当前页面模块名称
@@ -22,6 +22,8 @@ export declare const TRACK_LIMITS: {
22
22
  readonly maxItems: 20;
23
23
  /** 探针版本号,guard_conf.version varchar(20) */
24
24
  readonly sdkVersion: 20;
25
+ /** 应用版本号(调用方应用自身版本,与探针版本无关),guard_track.app_version varchar(20) */
26
+ readonly appVersion: 20;
25
27
  /** 会话串,列默认 varchar(255) */
26
28
  readonly imei: 255;
27
29
  /** 页面 URL,varchar(1000) */
@@ -69,6 +71,12 @@ export interface TrackV3Event {
69
71
  export interface TrackV3Envelope {
70
72
  appId: string;
71
73
  sdkVersion: string;
74
+ /**
75
+ * 调用方应用**自身**的版本号(由接入方在 `init` 的 `appVersion` 传入)。
76
+ * 可选:老版本探针不传,服务端该列落 `NULL`——**不得设为必填**,否则线上旧探针会全部 400。
77
+ * 与 `sdkVersion`(探针自身版本)语义无关,服务端不允许相互顶替。
78
+ */
79
+ appVersion?: string;
72
80
  /** 会话串,前端初始化时生成;与库列名 `imei` 一致 */
73
81
  imei: string;
74
82
  user?: TrackV3User;
@@ -42,6 +42,8 @@ var TRACK_LIMITS = {
42
42
  maxItems: 20,
43
43
  /** 探针版本号,guard_conf.version varchar(20) */
44
44
  sdkVersion: 20,
45
+ /** 应用版本号(调用方应用自身版本,与探针版本无关),guard_track.app_version varchar(20) */
46
+ appVersion: 20,
45
47
  /** 会话串,列默认 varchar(255) */
46
48
  imei: 255,
47
49
  /** 页面 URL,varchar(1000) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -32,7 +32,7 @@
32
32
  "lint": "npm run lint:es && npm run lint:css",
33
33
  "lint:css": "stylelint \"{src,test}/**/*.{css,less}\" --allow-empty-input",
34
34
  "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
35
- "prepare": "husky install && dumi setup",
35
+ "prepare": "husky && dumi setup",
36
36
  "prepublishOnly": "father doctor && npm run build",
37
37
  "release": "npm run build && npm publish --access public --registry https://registry.npmjs.org",
38
38
  "start": "npm run dev"
@@ -66,19 +66,17 @@
66
66
  "image-conversion": "^2.1.1"
67
67
  },
68
68
  "devDependencies": {
69
- "@ant-design/pro-components": "^2.8.10",
70
69
  "@commitlint/cli": "^20.5.3",
71
70
  "@commitlint/config-conventional": "^20.5.3",
72
71
  "@types/react": "^19.3.0",
73
- "@types/react-dom": "^19.3.0",
74
- "@umijs/lint": "^4.7.19",
75
- "antd": "^6.6.4",
72
+ "@umijs/lint": "^4.7.21",
73
+ "antd": "^6.6.5",
76
74
  "dumi": "^2.4.49",
77
75
  "eslint": "^8.57.1",
78
76
  "father": "^4.6.38",
79
77
  "husky": "^9.1.7",
80
78
  "lint-staged": "^16.4.0",
81
- "prettier": "^3.9.8",
79
+ "prettier": "^3.9.9",
82
80
  "prettier-plugin-organize-imports": "^4.3.0",
83
81
  "prettier-plugin-packagejson": "^2.5.22",
84
82
  "react": "^19.3.0",