@fz-firefly/experience 0.6.1 → 0.7.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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @fz-firefly/experience
2
+
3
+ 萤火虫 SDK 的可选体验增强:白屏检测、会话回放、用户连线。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @fz-firefly/experience
9
+ ```
10
+
11
+ `rrweb` 和 `modern-screenshot` 已作为本包依赖自动安装;它们只在开启回放 / 截图时动态加载,不进入主包。
12
+
13
+ ## 初始化
14
+
15
+ 先初始化核心 SDK,再显式安装体验增强:
16
+
17
+ ```ts
18
+ import { initFirefly } from '@fz-firefly/vue'
19
+ import { installExperience } from '@fz-firefly/experience'
20
+
21
+ const firefly = initFirefly({
22
+ dsn: '...',
23
+ endpoint: '...',
24
+ environment: 'production',
25
+ })
26
+
27
+ const disposeExperience = installExperience(firefly.client, {
28
+ whiteScreen: { screenshot: true },
29
+ // 生产推荐 on-error:报错时上传最近一段录屏。
30
+ replay: { mode: 'on-error' },
31
+ // 用户连线:远程 console / storage / 录屏开关。
32
+ remote: true,
33
+ })
34
+
35
+ // 需要卸载时:
36
+ // disposeExperience()
37
+ ```
38
+
39
+ ## 说明
40
+
41
+ - 不调用 `installExperience` 时,不会加载任何体验增强代码。
42
+ - 只有配置开启的能力会动态加载对应模块。
43
+ - uni-app / Taro 的小程序环境没有 DOM,白屏、回放、用户连线仅适用于 Web / H5。
package/dist/index.cjs CHANGED
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let _fz_firefly_core = require("@fz-firefly/core");
3
2
  // src/options.ts
4
3
  function finite(value, fallback, min, max) {
5
4
  const number = Number(value);
@@ -75,22 +74,24 @@ function normalizeExperienceOptions(value) {
75
74
  remote: normalizeRemote(value.remote)
76
75
  };
77
76
  }
78
- // src/index.ts
77
+ // src/install.ts
79
78
  /**
80
- * 自动注册体验增强能力。
79
+ * 安装可选体验增强。
80
+ *
81
+ * 与核心 SDK 解耦:先 initFirefly 创建 client,再按需安装体验能力。
82
+ * 只有开启的能力会被动态加载,主入口不会静态引入 rrweb / modern-screenshot。
81
83
  *
82
- * 业务只需要:
83
84
  * ```ts
84
- * import '@fz-firefly/experience'
85
- * initFirefly({ ..., experience: { whiteScreen: true } })
85
+ * const firefly = initFirefly({ ... })
86
+ * const disposeExperience = installExperience(firefly.client, {
87
+ * replay: { mode: 'on-error' },
88
+ * remote: true,
89
+ * })
86
90
  * ```
87
- *
88
- * 这里不静态引入 white-screen / replay / remote,只有对应能力开启时才
89
- * 动态加载,保证主包和首屏体积不变。
90
91
  */
91
- (0, _fz_firefly_core.registerIntegration)("experience", (client, options) => {
92
- const config = normalizeExperienceOptions(options.experience);
93
- if (typeof window === "undefined") return;
92
+ function installExperience(client, options) {
93
+ if (typeof window === "undefined") return () => {};
94
+ const config = normalizeExperienceOptions(options);
94
95
  let disposed = false;
95
96
  const disposers = [];
96
97
  function track(dispose) {
@@ -103,18 +104,19 @@ function normalizeExperienceOptions(value) {
103
104
  const { whiteScreen, replay, remote } = config;
104
105
  if (whiteScreen) Promise.resolve().then(() => require("./white-screen.cjs")).then(({ installWhiteScreen }) => {
105
106
  track(installWhiteScreen(client, whiteScreen));
106
- });
107
+ }).catch(() => {});
107
108
  if (replay) Promise.resolve().then(() => require("./replay.cjs")).then(({ installReplay }) => {
108
109
  track(installReplay(client, replay));
109
- });
110
+ }).catch(() => {});
110
111
  if (remote) Promise.resolve().then(() => require("./remote.cjs")).then(({ installRemote }) => {
111
112
  track(installRemote(client, remote));
112
- });
113
+ }).catch(() => {});
113
114
  return () => {
114
115
  disposed = true;
115
- for (const dispose of disposers) dispose();
116
+ for (const dispose of disposers.splice(0)) dispose();
116
117
  };
117
- });
118
+ }
119
+ exports.installExperience = installExperience;
118
120
  exports.normalizeExperienceOptions = normalizeExperienceOptions;
119
121
 
120
122
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,15 +1,19 @@
1
1
  import { c as normalizeExperienceOptions, n as RemoteOptions, r as ReplayOptions, s as WhiteScreenOptions, t as ExperienceOptions } from "./options-C2iLgUnA.cjs";
2
+ import { FireflyClient } from "@fz-firefly/core";
2
3
  /**
3
- * 给 core 的初始化参数补上 experience 字段。
4
+ * 安装可选体验增强。
4
5
  *
5
- * 只有 import '@fz-firefly/experience' 后才会加载这份声明;
6
- * 没引入包却写 experience 时,TypeScript 会直接报错,避免运行时静默失效。
6
+ * 与核心 SDK 解耦:先 initFirefly 创建 client,再按需安装体验能力。
7
+ * 只有开启的能力会被动态加载,主入口不会静态引入 rrweb / modern-screenshot。
8
+ *
9
+ * ```ts
10
+ * const firefly = initFirefly({ ... })
11
+ * const disposeExperience = installExperience(firefly.client, {
12
+ * replay: { mode: 'on-error' },
13
+ * remote: true,
14
+ * })
15
+ * ```
7
16
  */
8
- declare module '@fz-firefly/core' {
9
- interface FireflyOptions {
10
- /** 体验增强能力:白屏检测、会话回放、用户连线。 */
11
- experience?: ExperienceOptions;
12
- }
13
- }
17
+ export declare function installExperience(client: FireflyClient, options?: ExperienceOptions): () => void;
14
18
  export { type ExperienceOptions, type RemoteOptions, type ReplayOptions, type WhiteScreenOptions, normalizeExperienceOptions };
15
19
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,15 +1,19 @@
1
1
  import { c as normalizeExperienceOptions, n as RemoteOptions, r as ReplayOptions, s as WhiteScreenOptions, t as ExperienceOptions } from "./options-C2iLgUnA.js";
2
+ import { FireflyClient } from "@fz-firefly/core";
2
3
  /**
3
- * 给 core 的初始化参数补上 experience 字段。
4
+ * 安装可选体验增强。
4
5
  *
5
- * 只有 import '@fz-firefly/experience' 后才会加载这份声明;
6
- * 没引入包却写 experience 时,TypeScript 会直接报错,避免运行时静默失效。
6
+ * 与核心 SDK 解耦:先 initFirefly 创建 client,再按需安装体验能力。
7
+ * 只有开启的能力会被动态加载,主入口不会静态引入 rrweb / modern-screenshot。
8
+ *
9
+ * ```ts
10
+ * const firefly = initFirefly({ ... })
11
+ * const disposeExperience = installExperience(firefly.client, {
12
+ * replay: { mode: 'on-error' },
13
+ * remote: true,
14
+ * })
15
+ * ```
7
16
  */
8
- declare module '@fz-firefly/core' {
9
- interface FireflyOptions {
10
- /** 体验增强能力:白屏检测、会话回放、用户连线。 */
11
- experience?: ExperienceOptions;
12
- }
13
- }
17
+ export declare function installExperience(client: FireflyClient, options?: ExperienceOptions): () => void;
14
18
  export { type ExperienceOptions, type RemoteOptions, type ReplayOptions, type WhiteScreenOptions, normalizeExperienceOptions };
15
19
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import { registerIntegration } from "@fz-firefly/core";
2
1
  // src/options.ts
3
2
  function finite(value, fallback, min, max) {
4
3
  const number = Number(value);
@@ -74,22 +73,24 @@ function normalizeExperienceOptions(value) {
74
73
  remote: normalizeRemote(value.remote)
75
74
  };
76
75
  }
77
- // src/index.ts
76
+ // src/install.ts
78
77
  /**
79
- * 自动注册体验增强能力。
78
+ * 安装可选体验增强。
79
+ *
80
+ * 与核心 SDK 解耦:先 initFirefly 创建 client,再按需安装体验能力。
81
+ * 只有开启的能力会被动态加载,主入口不会静态引入 rrweb / modern-screenshot。
80
82
  *
81
- * 业务只需要:
82
83
  * ```ts
83
- * import '@fz-firefly/experience'
84
- * initFirefly({ ..., experience: { whiteScreen: true } })
84
+ * const firefly = initFirefly({ ... })
85
+ * const disposeExperience = installExperience(firefly.client, {
86
+ * replay: { mode: 'on-error' },
87
+ * remote: true,
88
+ * })
85
89
  * ```
86
- *
87
- * 这里不静态引入 white-screen / replay / remote,只有对应能力开启时才
88
- * 动态加载,保证主包和首屏体积不变。
89
90
  */
90
- registerIntegration("experience", (client, options) => {
91
- const config = normalizeExperienceOptions(options.experience);
92
- if (typeof window === "undefined") return;
91
+ function installExperience(client, options) {
92
+ if (typeof window === "undefined") return () => {};
93
+ const config = normalizeExperienceOptions(options);
93
94
  let disposed = false;
94
95
  const disposers = [];
95
96
  function track(dispose) {
@@ -102,18 +103,18 @@ registerIntegration("experience", (client, options) => {
102
103
  const { whiteScreen, replay, remote } = config;
103
104
  if (whiteScreen) import("./white-screen.js").then(({ installWhiteScreen }) => {
104
105
  track(installWhiteScreen(client, whiteScreen));
105
- });
106
+ }).catch(() => {});
106
107
  if (replay) import("./replay.js").then(({ installReplay }) => {
107
108
  track(installReplay(client, replay));
108
- });
109
+ }).catch(() => {});
109
110
  if (remote) import("./remote.js").then(({ installRemote }) => {
110
111
  track(installRemote(client, remote));
111
- });
112
+ }).catch(() => {});
112
113
  return () => {
113
114
  disposed = true;
114
- for (const dispose of disposers) dispose();
115
+ for (const dispose of disposers.splice(0)) dispose();
115
116
  };
116
- });
117
- export { normalizeExperienceOptions };
117
+ }
118
+ export { installExperience, normalizeExperienceOptions };
118
119
 
119
120
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fz-firefly/experience",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "萤火虫 SDK 的可选体验增强:白屏检测、会话回放、用户连线。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,36 +33,21 @@
33
33
  "dist",
34
34
  "!dist/**/*.map"
35
35
  ],
36
- "sideEffects": [
37
- "./dist/index.js",
38
- "./dist/index.cjs"
39
- ],
36
+ "sideEffects": false,
40
37
  "publishConfig": {
41
38
  "access": "public"
42
39
  },
43
40
  "dependencies": {
44
- "@fz-firefly/core": "0.6.1"
41
+ "@fz-firefly/core": "0.7.0",
42
+ "modern-screenshot": "^4.7.0",
43
+ "rrweb": "^2.2.2"
45
44
  },
46
45
  "devDependencies": {
47
46
  "jsdom": "^25.0.0",
48
- "modern-screenshot": "^4.7.0",
49
- "rrweb": "^2.2.2",
50
47
  "tsdown": "0.23.2",
51
48
  "typescript": "^5.6.0",
52
49
  "vitest": "^5.0.5"
53
50
  },
54
- "peerDependencies": {
55
- "modern-screenshot": ">=4.0.0",
56
- "rrweb": ">=2.0.0"
57
- },
58
- "peerDependenciesMeta": {
59
- "modern-screenshot": {
60
- "optional": true
61
- },
62
- "rrweb": {
63
- "optional": true
64
- }
65
- },
66
51
  "scripts": {
67
52
  "dev": "tsdown --watch --no-clean",
68
53
  "build": "tsdown",