@aochuang/client-sdk 1.0.382 → 1.0.401

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 (177) hide show
  1. package/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +4 -40
  2. package/components/chat-editor/chat-editor.vue +5 -75
  3. package/components/index.js +6 -1
  4. package/components/session-select/session-select-item.vue +8 -9
  5. package/components/wechat-chat-control/location/location.vue +3 -3
  6. package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
  7. package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
  8. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  9. package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
  10. package/components/wework-chat-control/file-url/file-url.vue +34 -16
  11. package/components/wework-chat-control/image/image.vue +137 -2
  12. package/components/wework-chat-control/index.js +15 -7
  13. package/components/wework-chat-control/location/location.vue +3 -3
  14. package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
  15. package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
  16. package/components/wework-chat-control/merge-message/util.js +59 -0
  17. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  18. package/components/wework-chat-control/metting/meeting-video.svg +4 -0
  19. package/components/wework-chat-control/metting/metting.vue +181 -0
  20. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
  21. package/components/wework-chat-control/text/text-default.vue +99 -0
  22. package/components/wework-chat-control/text/text-quote.vue +138 -0
  23. package/components/wework-chat-control/text/text.vue +27 -143
  24. package/components/wework-chat-control/url/url-channel-live.vue +53 -0
  25. package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
  26. package/components/wework-chat-control/url/url.vue +26 -2
  27. package/components/wework-chat-control/util.js +30 -17
  28. package/components/wework-chat-control/video/video.vue +11 -3
  29. package/components/wework-chat-control/voice/voice.vue +14 -3
  30. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  31. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  32. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  33. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +120 -0
  34. package/components/wework-chat-panel/chat-panel-item.vue +70 -39
  35. package/components/wework-chat-panel/chat-panel.vue +96 -13
  36. package/package.json +10 -3
  37. package/services/client-chat/client-chat-wechat/client-chat-account.js +37 -7
  38. package/services/client-chat/client-chat-wechat/client-chat-message.js +175 -18
  39. package/services/client-chat/client-chat-wechat/client-chat-session.js +83 -10
  40. package/services/client-chat/client-chat-wechat/client-chat-socket.js +80 -22
  41. package/services/client-chat/client-chat-wechat/client-chat.js +59 -11
  42. package/services/client-chat/client-chat-wework/client-chat-account.js +93 -1
  43. package/services/client-chat/client-chat-wework/client-chat-concats.js +104 -18
  44. package/services/client-chat/client-chat-wework/client-chat-message.js +268 -11
  45. package/services/client-chat/client-chat-wework/client-chat-session.js +271 -191
  46. package/services/client-chat/client-chat-wework/client-chat-socket.js +18 -2
  47. package/services/client-chat/client-chat-wework/client-chat.js +470 -85
  48. package/services/client-chat/client-chat-wework/docs/README.md +308 -0
  49. package/services/client-chat/client-chat-wework/utils.js +5 -5
  50. package/services/socket/socket.js +56 -7
  51. package/utils/log/constants.js +13 -0
  52. package/utils/log/export.js +88 -0
  53. package/utils/log/findings.md +141 -0
  54. package/utils/log/index.js +331 -0
  55. package/utils/log/indexed-db.js +228 -0
  56. package/utils/log/progress.md +267 -0
  57. package/utils/log/serialize.js +146 -0
  58. package/utils/log/task_plan.md +149 -0
  59. package/utils/log//345/210/206/346/236/220/344/270/216/344/274/230/345/214/226/346/226/271/346/241/210.md +303 -0
  60. package/utils/log//346/212/200/346/234/257/346/226/271/346/241/210/346/226/207/346/241/243.md +201 -0
  61. package/utils/log//346/236/266/346/236/204/346/226/207/346/241/243.md +169 -0
  62. package/utils/log//351/234/200/346/261/202/346/226/207/346/241/243.md +124 -0
  63. package/utils/log.js +2 -626
  64. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  65. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  66. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  67. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  68. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  69. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  70. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  71. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  72. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  73. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  74. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  75. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  76. package/uni-common/account-portray/account-portray.vue +0 -51
  77. package/uni-common/account-select/account-select-item.vue +0 -172
  78. package/uni-common/account-select/account-select.vue +0 -252
  79. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  80. package/uni-common/friend-avatar/default.svg +0 -1
  81. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  82. package/uni-common/friend-avatar/index.js +0 -3
  83. package/uni-common/friend-loader/friend-loader.vue +0 -53
  84. package/uni-common/friend-portray/friend-portray.vue +0 -56
  85. package/uni-common/group-avatar/default.svg +0 -1
  86. package/uni-common/group-avatar/group-avatar.vue +0 -18
  87. package/uni-common/group-avatar/index.js +0 -3
  88. package/uni-common/room-avatar/default.svg +0 -6
  89. package/uni-common/room-avatar/index.js +0 -3
  90. package/uni-common/room-avatar/room-avatar.vue +0 -27
  91. package/uni-common/room-loader/room-loader.vue +0 -53
  92. package/uni-common/room-portray/room-portray.vue +0 -56
  93. package/uni-components/chat-control/calling/calling.vue +0 -91
  94. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  95. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  96. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  97. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  98. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  99. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  100. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  101. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  102. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  103. package/uni-components/chat-control/chat-control.vue +0 -218
  104. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  105. package/uni-components/chat-control/const.js +0 -28
  106. package/uni-components/chat-control/expression/expression.vue +0 -41
  107. package/uni-components/chat-control/image/image.vue +0 -68
  108. package/uni-components/chat-control/index.js +0 -89
  109. package/uni-components/chat-control/location/location.vue +0 -110
  110. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  111. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  112. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  113. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  114. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  115. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  116. package/uni-components/chat-control/system/system.vue +0 -69
  117. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  118. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  119. package/uni-components/chat-control/text/text.vue +0 -67
  120. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  121. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  122. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  123. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  124. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  125. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  126. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  127. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  128. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  129. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  130. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  131. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  132. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  133. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  134. package/uni-components/chat-control/url/icons/index.js +0 -24
  135. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  136. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  137. package/uni-components/chat-control/url/url.vue +0 -306
  138. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  139. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  140. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  141. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  142. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  143. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  144. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  145. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  146. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  147. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  148. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  149. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  150. package/uni-components/chat-control/utils.js +0 -12
  151. package/uni-components/chat-control/video/video.vue +0 -156
  152. package/uni-components/chat-control/voice/voice.vue +0 -166
  153. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  154. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  155. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  156. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  157. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  158. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  159. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  160. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  161. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  162. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  163. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  164. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  165. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  166. package/uni-components/chat-editor/chat-editor.vue +0 -257
  167. package/uni-components/chat-editor/index.js +0 -10
  168. package/uni-components/chat-editor/util.js +0 -65
  169. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  170. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  171. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  172. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  173. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  174. package/uni-components/chat-panel/chat-panel.vue +0 -227
  175. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  176. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  177. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -0,0 +1,141 @@
1
+ # 发现与决策
2
+
3
+ ## 需求
4
+ - 新增消息/会话日志必须避免重复保存同一消息对象,统一通过 messageId/msgSvrId/sessionId/账号 ID 关联;可由已有字段或事件顺序计算的值不冗余存储。
5
+ - 每次页面刷新需要记录可排障的运行环境和当前登录账号;环境与身份作为启动上下文低频记录,不注入每条业务日志。
6
+ - 对象中没有值的字段不应导出为 `"[undefined]"`;应直接省略,降低噪声和体积。
7
+ - 已经记录为 `request_failed` 的请求异常不得再进入独立错误日志,避免刷新时重复。
8
+ - 日志持久化只考虑 IndexedDB,不保留 localStorage 兼容或应急方案。
9
+ - `logger.addLog()` 必须内部处理同步异常,异步写入错误也不得传播到业务调用方。
10
+ - Request 请求参数、成功响应和失败响应都需要递归裁剪;字符串保留前 100 字符,后缀记录省略字符数。
11
+ - File、Blob、二进制只记录类型占位符,不读取实际内容。
12
+ - 后端 `traceid` 必须独立保留。
13
+ - 下载全部日志,并按天拆分文件;不提供日期筛选。
14
+ - 日志高峰不能频繁读写 IndexedDB,允许异常退出时丢失少量尚未提交的日志。
15
+ - 页面脚本异常需要进入诊断日志,覆盖全局 JavaScript 异常、未处理 Promise 拒绝和 Vue 运行期异常。
16
+ - 下载时错误日志必须按天输出到独立文件,且不得重复包含在操作日志中。
17
+
18
+ ## 研究发现
19
+ - `normalizeForJson()` 和 `cropRequestValue()` 当前都会将 undefined 主动转换成字符串 `"[undefined]"`;SDK `addLog()` 还默认注入 `refererId: undefined`,共同造成无意义字段。
20
+ - Axios 失败记录后直接 `Promise.reject(error)`,错误对象没有去重标记,因此未处理拒绝还会被 `runtime_error` 捕获。
21
+ - 网络错误没有 response 时,`throwError()` 仍直接读取 `response.config`,会制造额外 TypeError。
22
+ - SDK 当前日志实现位于单文件 `utils/log.js`,IndexedDB 版本为 v2,容量上限为 50MB。
23
+ - 当前 `addLog()` 会同步 JSON 编码,并在临时队列超过 5 条时触发发布,密集消息下事务可能过于频繁。
24
+ - 当前 IndexedDB 写入会对每条记录先 `get` 再 `put`,并在每批写入后打开清理游标。
25
+ - JavaMain-combine 存在新旧两套开发日志下载实现,需要统一入口。
26
+ - 现有相关分析文档位于本目录,应在此基础上拆分需求、架构和方案文档。
27
+ - SDK 内部 `client-chat-message.js` 为避免日志影响业务,当前在调用点包裹了 `try/catch`;这类保护应统一下沉至 `Log.addLog()`。
28
+ - 当前 Web 日志写入每条记录都会执行 `store.get(recordId)` 后再 `store.put(record)`,运行期生成的 ID 已可保证唯一,这个读操作可以从常规写入链路移除。
29
+ - 当前每次写入都会打开最旧记录游标,即使未超过容量也会产生游标请求;应仅在统计大小超过上限时清理。
30
+ - `@aochuang/client-sdk/utils/log.js` 是 JavaMain-combine 的显式公共入口,目录化后必须保留该文件作为默认导出转发层。
31
+ - JavaMain-combine 的共享 logger 已使用 `client_chat` 数据库;Request 日志应复用该实例,避免同页创建多个针对同一 IndexedDB 的独立写队列。
32
+ - 当前 Axios 层包含 429 自动重试和登录验证码重试,诊断元数据需要挂在 config 上并在重试时延续 requestId、递增 attempt。
33
+ - 当前主下载入口对 `exportLogData()`、网络日志及业务快照统一执行 `JSON.stringify(data, null, 4)`;改造后操作日志直接消费 `exportLogFiles()` Blob,其他对象仅做紧凑 JSON 序列化。
34
+ - 旧 Vue 下载面板直接调用 `$clientChat.socket.exportLogData()`,应改为复用公共下载收集逻辑,避免两套命名和编码行为继续分叉。
35
+ - SDK 对外实际使用的日志方法集中在 `onBeforeAdd`、`addLog`、`checkAndSync`、`publishLogData`、`loadLogData`、`exportLogData` 和 `clearLogData`;目录化实现需保持这些方法签名。
36
+ - 前端 `visibilitychange` 当前调用的是 `syncDiagnosticLog()`,可将该函数调整为触发 `publishLogData()`,让隐藏页面尽快提交当前内存批次。
37
+ - 网络检测日志是带 `timestamp` 的数组,下载时可在内存中按 `timestamp` 前 10 位分组;其现有采集存储不属于 SDK logger 的 localStorage 降级链路,本次不改动网络检测器本身。
38
+ - 聊天入口仍保留了用于旧 localStorage 迁移的 `Log.checkAndSync([...])` 启动调用;IndexedDB-only 方案下应移除该导入和迁移调用。
39
+ - 现有消息日志只有 Socket 收包和事件抑制,缺少内存落入、重复拒绝和事件成功派发节点;已补为统一 `diagnostic:*` 事件并限制正文预览。
40
+ - 现有会话轮询虽有开始/成功/失败数据,但使用中文标题和旧 group,且已读请求无结果日志;统一事件名后可用 messageId/sessionId/账号 ID 串起未读变化。
41
+
42
+ ## 技术决策
43
+ | 决策 | 理由 |
44
+ |------|------|
45
+ | 日志模块目录化并保留 `utils/log.js` 转发入口 | 避免破坏已有大量 import 路径 |
46
+ | 使用内存队列加单事务批量写入 | 降低消息密集时的 IndexedDB 事务数量 |
47
+ | 日志 API 全部故障隔离 | 日志故障不能改变业务控制流 |
48
+ | 保持 v2 并兼容新旧记录结构 | 无需日期索引,减少升级风险 |
49
+ | 常规批次 300ms 或 50 条触发,单事务最多 500 条 | 将异常退出损失约束在一个小批次,同时避免逐条事务 |
50
+ | 运行期记录使用页面实例 ID 组成唯一 recordId | 可以省去常规写入的逐条查重读取 |
51
+ | 对象 undefined 省略、数组 undefined 转 null | 减少无意义字段,同时保持数组索引语义与原生 JSON 一致 |
52
+ | 请求异常在进入 Request 日志时增加不可枚举标记 | 让全局 Promise 异常监听在采集入口去重,且不把内部标记导出到日志 |
53
+ | 页面环境只进入 `page_boot`,登录身份进入既有 `user_init_result` | 每次刷新完整记录上下文,同时不扩散到每条业务日志或新增重复身份事件 |
54
+ | 消息高频链路以 `messageId + msgSvrId + sessionId` 关联 | `sessionId` 直接连接消息与会话阶段,可删除重复的账号、目标、类型、时间和完整消息对象 |
55
+ | 正常账号未读刷新不增加 requested/applied | 成功已有 `account_unread_changed` 可证明结果,只对失败补一条诊断,控制日志量 |
56
+ | Socket 新消息保留唯一完整快照 | 用户需要用原始 `friendMessage/chatroomMessage` 排查字段问题;下游仍只记 ID,避免跨阶段重复完整对象 |
57
+
58
+ ## 遇到的问题
59
+ | 问题 | 解决方案 |
60
+ |------|---------|
61
+ | 浏览器强杀时无法同时保证零丢失和零性能成本 | 缩短批量提交窗口,页面隐藏时立即请求 flush;明确允许丢失最后一个未提交批次 |
62
+ | BrowserSkill 截图后页面语义引用失效 | 重新 observe 获取当前引用,不重试已经失效的引用 |
63
+ | 登录后“稍后提醒”点击未关闭更新弹窗 | 不重复相同按钮,改用弹窗关闭按钮并重新观察状态 |
64
+ | 更新弹窗在二次观察前异步消失,关闭按钮已无可见几何 | 以重新观察到的主界面为准,不再操作已消失弹窗 |
65
+ | BrowserSkill `request-help` 运行时会话被独占,无法并行截图提示层 | 保留人工确认结果,提示完成后截取业务状态;不重试并行截图 |
66
+ | 最终显式停止 BrowserSkill 时会话已自动注销 | 状态检查确认 `sessions=[]`、浏览器 `session_count=0`,无需再次停止 |
67
+ | SDK 仓库自身没有可直接使用的 `@babel/core` | 不新增 SDK 依赖;复用 JavaMain-combine 已安装的 Babel 环境加载 SDK 序列化模块,并以定向测试覆盖 |
68
+ | 阶段 10 使用系统 `unzip -l` 时中文文件名显示为问号,`shasum` 提示 locale fallback | 不依赖终端显示解析文件名,改用项目已安装的 JSZip 直接读取 ZIP;哈希和字节数仍有效 |
69
+ | 阶段 10 首次更新规划文件时补丁上下文顺序不匹配 | 重新定位准确标题与行内容后分块更新,未改动业务代码 |
70
+ | 阶段 11 初次检索误用 `src/store` 且 shell `.env*` 无匹配 | 使用 `src/entries/chat/store` 与显式文件列表继续,不重复失败命令 |
71
+
72
+ ## 资源
73
+ - `utils/log.js`
74
+ - `services/client-chat/client-chat-wechat/`
75
+ - JavaMain-combine `src/libs/request.js`
76
+ - JavaMain-combine `src/entries/chat/common/develop-log/`
77
+
78
+ ## 视觉/浏览器发现
79
+ - 阶段 13 已通过页面真实 SDK API 清空 `log_client_chat`:清理前 889 条/1185992 bytes;二次清理并导航后所有记录均为本轮新数据,登录态和业务数据库未清理。
80
+ - 阶段 13 真实消息 order 207~213:会话/账号未读均 13->14,Socket 完整 chatroomMessage 仅在 message_received 出现一次,缓存 success/24ms;UI 两处徽标均为 14。
81
+ - 阶段 13 真实刷新 pageInstanceId `1794035487094_33kh08`:page_boot reload、user_init_result success、page_ready rendered 可以完整关联。
82
+ - 阶段 13 下载 ZIP 为 589929 bytes,SHA-256 `03d6f894160442bf12810f019910ebacfb7855a6058e5d06c3a193a4dbf8c107`;操作/网络日志分别 407/48 条,本轮无脚本异常所以没有空错误日志文件。
83
+ - BrowserSkill 会话 `pkke` 已显式停止;最终 daemon 状态 `sessions=[]`,无残留自动化 session。停止后 Chrome 扩展连接也从 daemon 列表退出,不影响已保存证据。
84
+ - 阶段 10 ZIP 解析:操作日志 406 条/649880 bytes、错误日志 94 条/57255 bytes、网络日志 18 条/3443 bytes,另含微号数据 109 条和已加载会话 49 条;所有文件合计 `"[undefined]"` 0。请求探针在操作日志命中 2 个事件、错误日志 0;普通异常探针在操作日志 0、错误日志所属记录 1(文本命中 2 次来自 message/stack);操作/错误分类错误均为 0。
85
+ - 视觉复核确认 `06-undefined-request-dedupe-download-menu.png` 仅显示“下载日志”按钮,无聊天正文。新 ZIP 大小 `805326` bytes,SHA-256 `13de562d264a68f018d8d04f9f1389c81fc95c356955fcad0405fe7af3218230`,包含 8 个条目;系统 `unzip -l` 因终端编码未正确显示中文名,后续改用 JSZip 读取原始文件名。
86
+ - 已保存真实“下载日志”按钮裁剪截图 `06-undefined-request-dedupe-download-menu.png`(130x36,1681 bytes),并从该按钮下载 `开发日志-undefined请求异常去重UI回归-2026-11-07.zip`。
87
+ - 真实页面右上角用户菜单已通过悬停打开,语义树确认“去管理端 / 下载日志 / 退出登录”均可见,下载入口 ref 为 `@e553`;下一步从该入口下载而不是直接调用导出函数。
88
+ - 普通异常真实验证:从 order `484` 基线后触发未处理 Promise rejection `e2e-runtime-error-1794031956191`,order `487` 生成独立 runtime_error,source=`unhandled_rejection`、errorId=`dd32cb43`;同期 request_failed `0`、`"[undefined]"` `0`,证明非请求脚本异常仍保留。
89
+ - 请求失败真实验证:在 order `478~483` 的 6 条新增记录中,探针请求 `e2e-request-failure-1794031915232` 生成 request_started(order 481) 和 request_failed(order 482),二者 requestId 同为 `1794031915232_22`,失败结果为 `network_error`/`Network Error`;同期 runtime_error `0`、`"[undefined]"` `0`。这同时证明请求异常去重和无 response 网络错误保护生效。
90
+ - 已通过临时测试模块从 Webpack 已加载缓存定位到 `./src/libs/request.js` 的默认 Axios service,不读取 token/cookie;请求失败测试基线为 `2026-11-07T06:11:32.566Z`、`nextOrder=477`、`totalBytes=694515`。
91
+ - 页面使用 Webpack 4 风格 `window.webpackJsonp` runtime,可在当前测试页临时注入无业务副作用的测试模块来取得 `__webpack_require__`,从已加载模块缓存中定位 Axios service;该方式不需要暴露或修改应用源码,也不读取认证信息。
92
+ - 刷新产生的 30 条非 Request runtime_error 均为不同账号的 `未找到<账号ID>未读数据`,每条 errorId 不同,因此现有 5 秒指纹去重不会合并;这是账号未读初始化中的独立 Promise 异常噪声,不是 Axios/request_failed 重复。页面未暴露全局 Axios/request 实例。
93
+ - 阶段 10 真实刷新后新增 order `323~463` 共 `141` 条:Request started/completed 为 `16/16`、failed `0`,payload 含字面量 `"[undefined]"` 的记录为 `0`。新增 `runtime_error` 30 条,来源均为 `unhandled_rejection`;因同期没有 request_failed,这批不是 Request 重复错误,需要继续识别其脱敏消息。
94
+ - 阶段 10 刷新前基线:`2026-11-07T06:08:39.586Z`,IndexedDB `log_client_chat` v2,`count=322`、`nextOrder=322`、`totalBytes=465324`;随后通过 BrowserSkill 真实导航同一 URL 触发页面刷新和 Axios 初始化请求。
95
+ - 阶段 10 IndexedDB 采样将只读 `log_client_chat` 的 `logs` 与 `meta` store;以 `meta.stats.nextOrder` 固定基线,再只分析更大 order 的新增记录,避免历史 `"[undefined]"` 干扰结论。
96
+ - 关闭更新弹窗后,客服主界面正常加载,页面标题为“新消息99+条”,账号列表、最近聊天和快捷语区域可操作;本轮不截图包含聊天正文的完整页面。
97
+ - 测试人员在 BrowserSkill 人工协助中填入凭据后,自动化点击登录;真实页面已进入登录后状态并显示“系统已更新”弹窗,确认认证成功。自动化未提取或保存密码。
98
+ - 阶段 10 BrowserSkill 会话 `pkke` 已导航至客服端;Agent Window 显示登录页且账号、密码为空,需要测试人员通过安全人工协助完成登录,自动化不读取凭据。
99
+ - 阶段 10 回归开始时,`http://localhost:8081/user/chat/index.html` 返回 HTTP 200;BrowserSkill daemon/扩展均为 0.3.2、协议 1.3,Chrome 156 已连接且无残留 session。
100
+ - JavaMain-combine 的 `node_modules/@aochuang/client-sdk` 当前符号链接到本地 `/Volumes/Sites/AoChuang/fangzhou/client-sdk`,页面可直接验证本轮 SDK 序列化修改。
101
+ - 最终 UI 自动化会话 `cvag` 于 2026-11-07 启动,访问 `http://localhost:8081/user/chat/index.html` 后保持登录态,并真实显示“系统已更新”弹窗,可用于证明页面启动/刷新检测场景。
102
+ - 关闭更新提示后页面显示登录表单,浏览器已有预填信息;自动化仅触发登录按钮,未读取、导出或记录密码。
103
+ - 登录请求完成后客服主界面已加载,更新弹窗在登录后再次出现,确认其来源是版本检查而不是登录失败。
104
+ - 主界面标题真实显示“新消息99+条”,账号和会话列表存在未读徽标;最终报告截图将聚焦未读区域,减少聊天正文暴露。
105
+ - 最终真实消息基线采集于 `2026-11-07 13:26:04`(Asia/Shanghai):IndexedDB `log_client_chat` v2,记录数 `2455`,`stats.nextOrder=2455`,`stats.totalBytes=3448993`,页面标题“新消息99+条”。
106
+ - BrowserSkill 已在页面内提示测试人员发送真实消息,测试人员通过提示层确认“发了”;后续差量仅分析 `order > 2455`,不提取消息正文。
107
+ - `2026-11-07 13:26:45~13:26:46` 实际到达 3 条同会话文本消息。消息 ID 分别为 `ff062b64629ee0ac88243927b46144dc468984a3`、`ea4ff548e8bb7215c6a5c4c77c541d4a3f50bcde`、`f333777d174a689552f8479a7076366900651949`;会话 ID 为 `f5a2b25f037c7b28f0e92bc1e17a057216a8203a`,账号 ID 为 `656a9e164516dba13e19bb629140789a757d0688`。
108
+ - 三条消息都形成 `message_stored -> session_unread_changed -> session_resolved -> message_event_emitted -> message_received -> account_unread_changed -> message_cache_result` 链路;会话和账号未读均从 `0` 连续增加到 `3`,缓存均成功,耗时 `16/21/26ms`。
109
+ - 真实消息后采样:日志记录数 `2488`,`nextOrder=2488`,`totalBytes=3469449`。全程未读取或保存消息正文。
110
+ - 页面观察与日志一致:对应账号未读徽标为 `3`,最近聊天中对应会话未读徽标为 `3`,会话时间显示 `13:26`。
111
+ - 主入口“下载日志”会直接调用 `downloadDevelopLogs(ClientChat)` 全量下载,不显示类型选择面板;这符合用户要求的“下载所有”。右上角弹层已实际打开,三个菜单项可见。
112
+ - 已将真实下载菜单截图裁剪到右上角区域,避免将聊天正文写入报告;截图中“下载日志”入口清晰可见。
113
+ - 视觉复核发现首张截图实际捕获的是更新弹窗异步消失后的登录页,而不是更新弹窗;最终报告将按真实内容标注,并使用 IndexedDB 启动事件证明刷新/首次加载,避免误报。
114
+ - 最终真实下载浏览器建议文件名 `开发日志2026-11-07 13_32_10.zip`;归档副本 `开发日志-最终UI验证-2026-11-07.zip` 为 `3617469` bytes,SHA-256 `0ba99fcd15c47c2f473c0b04187f4571d02f19b388b1b5adf6060460182a8710`。
115
+ - 最终 ZIP 内:操作日志 `2296` 条/`3341857` bytes,错误日志 `218` 条/`151948` bytes,网络日志 `150` 条/`28927` bytes,微号数据 `109` 条/`68644` bytes,已加载会话 `49` 条/`24523` bytes;全部为可解析的紧凑 JSON。
116
+ - 分类校验:操作日志 runtime error `0`,错误日志非 runtime error `0`,跨分类重复 errorId `0`。三条真实 messageId 均能在操作日志中找到 stored/emitted/received/cache_result 四个消息级事件。
117
+ - 最终操作日志包含 `15` 条 `page_boot`,其中 `9` 条明确为 `navigationType=reload/isReload=true`;最近一次刷新为 `13:06:05`。本轮 `13:23:15` 和 `13:24:22` 的导航也均形成 page_boot/page_show/page_ready 记录。
118
+ - 请求日志共 `797` 条:started `399`、completed `383`、failed `15`;`398` 个终态事件带 traceid,全部 `383` 条成功响应包含裁剪 response。检测到 `2426` 个带 `...+N` 后缀的截断字符串,最大长度 `110`(100 字符正文加省略数量后缀)。
119
+ - BrowserSkill 已在 Chrome 156 中完成真实页面登录、刷新、会话打开和日志下载操作。
120
+
121
+ ## 生产发布前审查发现
122
+ - **发布阻断:** JavaMain-combine 的 `package.json/package-lock.json` 仍锁定 `@aochuang/client-sdk 1.0.382`,当前 `node_modules` 实际是指向本地 SDK 工作区的符号链接(工作区版本 `1.0.381-dev-2`)。前端新下载逻辑依赖本地未发布的 `Log.exportLogFiles()`;生产重新安装 1.0.382 后该 API 和本次消息/会话日志不保证存在,必须先发布 SDK 新版本并更新前端依赖与锁文件后再构建验证。
123
+ - 已从 npm registry 实际下载 1.0.382 核对:它仍是旧单文件 `utils/log.js`,没有 `exportLogFiles()`,Socket 也没有对应转发方法或新的 message_received 诊断。因此当前前端用正式 1.0.382 时下载入口必然在运行时失败。
124
+ - **发布阻断:** SDK 没有 `.npmignore` 或 `package.json#files` 白名单;`npm pack --dry-run` 确认 `utils/log/task_plan.md`、`progress.md`、`findings.md` 和需求/架构/方案文档都会进入 public npm 包。内部进度文档包含测试账号、真实诊断 ID、本地 URL 和 ZIP 哈希,必须在发布清单中排除,但可继续留在仓库。
125
+ - `ClientChatMessage.addMessage()` 的“先 onAddMessageSuccess、再 add-message”顺序和同步 try/catch 在当前分支 HEAD 已存在,不是本次日志改造引入;本次新增的是返回 Promise 的 rejection 记录,不改变成功路径和 add-message 派发。
126
+ - `ClientChatSession.reload()` 为内部 `ps1.then(success)` 补空 rejection handler,只消除重复的 unhandled rejection;外层 `Promise.all([ps1])` 仍保持原有 reject 行为和 loading 复位逻辑。
127
+ - SDK 日志入口保持 `utils/log.js` 默认导出兼容,IndexedDB 版本仍为 v2;新实现同时兼容旧 v2 的 `{log}` 记录和新 `{payload}` 记录。
128
+ - 所有高频 SDK 诊断调用最终进入 `Log.addLog()` 的同步 try/catch;IndexedDB 写入在 Promise 队列中执行,失败会回队列并指数退避,不向消息/会话调用栈抛出。
129
+ - 需要继续确认:公共 Log 在非浏览器/uni 环境由旧 localStorage 行为改为无持久化是否影响本次生产目标之外的 SDK 消费方;Request/Socket 同步裁剪的最坏主线程成本;未跟踪文件是否全部进入发布提交。
130
+ - 性能抽测:64KB 预算的大响应 `cropRequestValue` 2000 次平均 0.0471ms/次;含 10000 字符正文的完整消息 `safeStringify` 5000 次平均 0.0248ms/次。Node 22 数据不能代表全部低配浏览器,但结合真实 UI 回归,没有看到正常消息密度下的主线程风险。
131
+ - **建议发布前修复:** `client-chat-socket.js` 在调用业务 `onCmdNewMessage` 之前先执行 `getSocketMessageLogData()`,该快照函数没有 try/catch。故障注入一个带抛错 getter 的消息对象时实测抛出 `Error: snapshot failed`,会阻止业务回调执行。WebSocket JSON 正常为普通对象,实际概率低,但这不满足“日志任何失败都不影响消息处理”的强约束;应让业务回调先执行,并将快照构造/写日志整体放入独立 try/catch。
132
+ - 正式 Node 14 production build 成功(31 个既有 CSS 顺序/体积 warning,无编译错误);该构建使用本地 SDK 符号链接,只证明源码可编译,不能替代新版 SDK tarball 安装验证。
133
+ - Node 22 执行 `diagnostic-log.test.js + security-regression.test.js` 共 28 项全部通过。
134
+ - 前端声明 SDK 1.0.382,但测试开始时 `node_modules` 实际为 1.0.381;临时链接本地 SDK 后新增会话和未读诊断事件才生效。
135
+ - `/api/friendMessage/searchFriendMessage` 成功响应真实返回 traceid,Request 日志已独立保留。
136
+ - 下载 ZIP 为 938470 bytes,操作日志是包含 466 个对象的 JSON 数组,并按 `2026-11-07` 独立文件输出。
137
+ - 纯网络错误时 `request.js` 会因读取不存在的 `response.config` 再次抛出 TypeError;日志已成功记录该 network_error,但业务错误处理需要另行修复。
138
+ - 真实新消息尚未在自动化窗口期间到达,需要测试人员发送消息补齐完整链路证据。
139
+ - 真实消息发送前基线已于 `2026-11-07 12:27:29` 固定:IndexedDB 共 `670` 条记录,`nextOrder=670`,`totalBytes=1114028`;后续以新增记录和消息公共标识做差量关联。
140
+ - 真实页面已捕获未处理 Promise 拒绝,并在一分钟异常上限后产生 `runtime_error_suppressed`,实际 `suppressedCount=21`;页面保持可操作。
141
+ - 新下载 ZIP 包含 184 条独立错误日志和 1958 条操作日志;操作日志中的 runtime error、错误日志中的普通操作及交叉重复 errorId 均为 0。
@@ -0,0 +1,331 @@
1
+ import { formatDate } from '../date'
2
+ import {
3
+ DEFAULT_INDEXED_DB_MAX_SIZE,
4
+ DEFAULT_FLUSH_INTERVAL,
5
+ DEFAULT_FLUSH_THRESHOLD,
6
+ DEFAULT_FLUSH_BATCH_SIZE,
7
+ DEFAULT_MAX_PENDING_COUNT,
8
+ DEFAULT_MAX_PENDING_BYTES
9
+ } from './constants'
10
+ import { safeStringify, getByteSize } from './serialize'
11
+ import IndexedDbLogStorage from './indexed-db'
12
+ import { createExportFiles, recordPayload } from './export'
13
+
14
+ let instanceSequence = 0
15
+
16
+ function createPageInstanceId () {
17
+ instanceSequence++
18
+ return `${Date.now()}_${instanceSequence}_${Math.random().toString(36).slice(2, 10)}`
19
+ }
20
+
21
+ function getDay (date) {
22
+ return formatDate(date, 'YYYY-mm-dd') || 'unknown-date'
23
+ }
24
+
25
+ export default class Log {
26
+ static checkAndSync (storageKeys) {
27
+ return Promise.resolve([].concat(storageKeys || []).filter(Boolean).map(storageKey => ({
28
+ storageKey,
29
+ synced: false,
30
+ migratedCount: 0,
31
+ duplicateCount: 0,
32
+ removedCount: 0
33
+ })))
34
+ }
35
+
36
+ constructor (options) {
37
+ options = Object.assign({
38
+ name: null,
39
+ console: false,
40
+ indexedDbMaxSize: DEFAULT_INDEXED_DB_MAX_SIZE,
41
+ flushInterval: DEFAULT_FLUSH_INTERVAL,
42
+ flushThreshold: DEFAULT_FLUSH_THRESHOLD,
43
+ flushBatchSize: DEFAULT_FLUSH_BATCH_SIZE,
44
+ maxPendingCount: DEFAULT_MAX_PENDING_COUNT,
45
+ maxPendingBytes: DEFAULT_MAX_PENDING_BYTES
46
+ }, options)
47
+ if (!options.name) {
48
+ throw new Error('必须指定日志的name名称')
49
+ }
50
+ this.prefix = 'log'
51
+ this.name = options.name
52
+ this.options = options
53
+ this.maxSize = options.maxSize
54
+ this.validTime = options.validTime
55
+ this.beforeAddCallback = null
56
+ this.tempStore = []
57
+ this._pendingBytes = 0
58
+ this._droppedCount = 0
59
+ this._internalFailureCount = 0
60
+ this._sequence = 0
61
+ this._pageInstanceId = createPageInstanceId()
62
+ this._customStorageKey = null
63
+ this._publishTimer = null
64
+ this._retryCount = 0
65
+ this._writePromise = Promise.resolve()
66
+ this._storage = new IndexedDbLogStorage({
67
+ name: this.indexedDbName,
68
+ storageKey: this.storageKey,
69
+ maxBytes: options.indexedDbMaxSize
70
+ })
71
+ this._bindLifecycleFlush()
72
+ }
73
+
74
+ get storageKey () {
75
+ return this._customStorageKey || `${this.prefix}_${this.name}`
76
+ }
77
+
78
+ get indexedDbName () {
79
+ return this.storageKey
80
+ }
81
+
82
+ get useIndexedDb () {
83
+ return this._storage ? this._storage.supported : (
84
+ typeof window !== 'undefined' && !!window.indexedDB
85
+ )
86
+ }
87
+
88
+ onBeforeAdd (callback) {
89
+ this.beforeAddCallback = callback
90
+ }
91
+
92
+ _recordInternalFailure () {
93
+ this._internalFailureCount++
94
+ }
95
+
96
+ _bindLifecycleFlush () {
97
+ if (typeof document !== 'undefined' && document.addEventListener) {
98
+ document.addEventListener('visibilitychange', () => {
99
+ if (document.visibilityState === 'hidden') {
100
+ this._backgroundFlush()
101
+ }
102
+ })
103
+ }
104
+ if (typeof window !== 'undefined' && window.addEventListener) {
105
+ window.addEventListener('pagehide', () => this._backgroundFlush())
106
+ }
107
+ }
108
+
109
+ _enqueueWrite (callback) {
110
+ const task = this._writePromise.then(callback, callback)
111
+ this._writePromise = task.catch(() => {})
112
+ return task
113
+ }
114
+
115
+ _clearPublishTimer () {
116
+ if (this._publishTimer) {
117
+ clearTimeout(this._publishTimer)
118
+ this._publishTimer = null
119
+ }
120
+ }
121
+
122
+ _schedulePublish (delay = this.options.flushInterval) {
123
+ if (this._publishTimer) {
124
+ return
125
+ }
126
+ this._publishTimer = setTimeout(() => {
127
+ this._publishTimer = null
128
+ this._backgroundFlush()
129
+ }, delay)
130
+ }
131
+
132
+ _backgroundFlush () {
133
+ this.publishLogData().catch(() => {})
134
+ }
135
+
136
+ _createRecord (data) {
137
+ let payload = safeStringify(data)
138
+ if (!payload) {
139
+ return null
140
+ }
141
+ data.size = getByteSize(payload)
142
+ payload = safeStringify(data)
143
+ if (!payload) {
144
+ return null
145
+ }
146
+ const byteSize = getByteSize(payload)
147
+ return {
148
+ recordId: `${this._pageInstanceId}:${this._sequence}`,
149
+ order: 0,
150
+ byteSize,
151
+ day: getDay(new Date(data.timestamp)),
152
+ group: data.group,
153
+ payload
154
+ }
155
+ }
156
+
157
+ _enqueueRecord (record) {
158
+ this.tempStore.push(record)
159
+ this._pendingBytes += record.byteSize
160
+ while (
161
+ this.tempStore.length > this.options.maxPendingCount ||
162
+ this._pendingBytes > this.options.maxPendingBytes
163
+ ) {
164
+ const removed = this.tempStore.shift()
165
+ this._pendingBytes = Math.max(0, this._pendingBytes - (removed.byteSize || 0))
166
+ this._droppedCount++
167
+ }
168
+ }
169
+
170
+ addLog (input) {
171
+ try {
172
+ this._sequence++
173
+ const now = new Date()
174
+ const data = Object.assign({
175
+ group: this.defautGroup,
176
+ refererId: undefined,
177
+ content: null
178
+ }, input, {
179
+ id: `${this._pageInstanceId}:${this._sequence}`,
180
+ createTime: formatDate(now),
181
+ timestamp: now.getTime()
182
+ })
183
+ if (this.beforeAddCallback && this.beforeAddCallback({ data }) === false) {
184
+ return
185
+ }
186
+ const record = this._createRecord(data)
187
+ if (!record) {
188
+ this._recordInternalFailure()
189
+ return
190
+ }
191
+ if (this.useIndexedDb) {
192
+ this._enqueueRecord(record)
193
+ if (this.tempStore.length >= this.options.flushThreshold) {
194
+ this._clearPublishTimer()
195
+ this._backgroundFlush()
196
+ } else {
197
+ this._schedulePublish()
198
+ }
199
+ }
200
+ if (this.options.console && typeof console !== 'undefined' && console.log) {
201
+ console.log(`【${this.name || 'operateLog'}】${record.payload}`)
202
+ }
203
+ return data
204
+ } catch (error) {
205
+ this._recordInternalFailure()
206
+ return
207
+ }
208
+ }
209
+
210
+ checkAndSync () {
211
+ return Promise.resolve({
212
+ synced: false,
213
+ migratedCount: 0,
214
+ duplicateCount: 0,
215
+ removedCount: 0
216
+ })
217
+ }
218
+
219
+ publishLogData () {
220
+ this._clearPublishTimer()
221
+ if (!this.useIndexedDb || !this.tempStore.length) {
222
+ if (!this.useIndexedDb) {
223
+ this.tempStore = []
224
+ this._pendingBytes = 0
225
+ }
226
+ return Promise.resolve({ writtenCount: 0, removedCount: 0 })
227
+ }
228
+ const records = this.tempStore.splice(0, this.tempStore.length)
229
+ const recordsBytes = records.reduce((sum, record) => sum + (record.byteSize || 0), 0)
230
+ this._pendingBytes = Math.max(0, this._pendingBytes - recordsBytes)
231
+ let committedCount = 0
232
+ return this._enqueueWrite(() => {
233
+ let offset = 0
234
+ let result = { writtenCount: 0, removedCount: 0 }
235
+ const writeNext = () => {
236
+ if (offset >= records.length) {
237
+ return result
238
+ }
239
+ const batch = records.slice(offset, offset + this.options.flushBatchSize)
240
+ offset += batch.length
241
+ return this._storage.write(batch).then(batchResult => {
242
+ committedCount += batch.length
243
+ result.writtenCount += batchResult.writtenCount
244
+ result.removedCount += batchResult.removedCount
245
+ return writeNext()
246
+ })
247
+ }
248
+ return writeNext()
249
+ }).then(result => {
250
+ this._retryCount = 0
251
+ if (this._droppedCount) {
252
+ const droppedCount = this._droppedCount
253
+ this._droppedCount = 0
254
+ this.addLog({
255
+ group: 'diagnostic:logger_dropped',
256
+ content: {
257
+ event: 'logger_dropped',
258
+ droppedCount
259
+ }
260
+ })
261
+ }
262
+ return result
263
+ }).catch(error => {
264
+ this._retryCount++
265
+ records.slice(committedCount).reverse().forEach(record => {
266
+ this.tempStore.unshift(record)
267
+ this._pendingBytes += record.byteSize || 0
268
+ })
269
+ while (
270
+ this.tempStore.length > this.options.maxPendingCount ||
271
+ this._pendingBytes > this.options.maxPendingBytes
272
+ ) {
273
+ const removed = this.tempStore.shift()
274
+ this._pendingBytes = Math.max(0, this._pendingBytes - (removed.byteSize || 0))
275
+ this._droppedCount++
276
+ }
277
+ this._schedulePublish(Math.min(30000, 500 * Math.pow(2, Math.min(this._retryCount, 6))))
278
+ throw error
279
+ })
280
+ }
281
+
282
+ loadLogData () {
283
+ if (!this.useIndexedDb) {
284
+ return Promise.resolve({ size: 0, data: [] })
285
+ }
286
+ return this._writePromise.then(() => this._storage.readRecords('prev')).then(records => {
287
+ let size = 0
288
+ const data = records.map(record => {
289
+ size += record.byteSize || 0
290
+ if (record.log !== undefined) {
291
+ return record.log
292
+ }
293
+ try {
294
+ return JSON.parse(recordPayload(record))
295
+ } catch (error) {
296
+ return null
297
+ }
298
+ }).filter(item => item !== null)
299
+ return { size, data }
300
+ }).catch(() => ({ size: 0, data: [] }))
301
+ }
302
+
303
+ exportLogData () {
304
+ return this.publishLogData().then(() => this.loadLogData())
305
+ }
306
+
307
+ exportLogFiles (options) {
308
+ if (!this.useIndexedDb) {
309
+ return Promise.resolve([])
310
+ }
311
+ return this.publishLogData()
312
+ .then(() => this._storage.readRecords('next'))
313
+ .then(records => createExportFiles(records, options))
314
+ }
315
+
316
+ clearLogData () {
317
+ this._clearPublishTimer()
318
+ this.tempStore = []
319
+ this._pendingBytes = 0
320
+ if (!this.useIndexedDb) {
321
+ return Promise.resolve()
322
+ }
323
+ return this._enqueueWrite(() => this._storage.clear())
324
+ }
325
+
326
+ _closeIndexedDb () {
327
+ return this._storage.close()
328
+ }
329
+ }
330
+
331
+ export { safeStringify, createExportFiles }