@bugsee/react-native 0.0.0-stage → 7.0.0-beta2

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 (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
package/src/index.ts ADDED
@@ -0,0 +1,962 @@
1
+ import type { ComponentType } from 'react';
2
+ import NativeBugsee from './NativeBugsee';
3
+ import { PACKAGE_VERSION } from './version';
4
+ import { wrap } from './viewtree/anchor';
5
+ import { collectWrapperFacts } from './wrapper/collect';
6
+ import { wrapperIdentity } from './wrapper/identity';
7
+ import { setOwnerRectangles } from './secure/registry';
8
+ // For its effect, eagerly (Metro's inlineRequires defers only what is read): follows native Animated events
9
+ // from here on, so those attached before the first <BugseeSecure> mounts are counted too.
10
+ import './secure/followEvents';
11
+ import type { SecureRectangle } from './secure/rectangles';
12
+ import { Status } from './status';
13
+ import { statusForEvent } from './wrapper/events';
14
+ import type { LifecycleEvent } from './wrapper/events';
15
+ import { setReportHandler as installReportHandler } from './report/dispatcher';
16
+ import { createReport as openCreatedReport } from './report/CreatedReport';
17
+ import type { BugseeCreatedReport, BugseeReportHandler } from './report/types';
18
+ import { log as sendLog } from './logs/log';
19
+ import { installConsoleCapture } from './console/capture';
20
+ import { setLogFilter as installLogFilter } from './logs/filter';
21
+ import type { LogFilter } from './logs/filter';
22
+ import { addBreadcrumb as recordBreadcrumb } from './breadcrumbs/add';
23
+ import { setBreadcrumbFilter as installBreadcrumbFilter } from './breadcrumbs/filter';
24
+ import type { Breadcrumb, BreadcrumbFilter } from './breadcrumbs/types';
25
+ import { setNetworkFilter as installNetworkFilter } from './network/filter';
26
+ import type { NetworkFilter } from './network/filter';
27
+ import { addNetworkEvent as recordNetworkEvent } from './network/add';
28
+ import type { AddedNetworkEvent } from './network/add';
29
+ import { type IssueSeverity, LogLevel } from './options/enums';
30
+ import { BugseeLaunchOptions } from './options/BugseeLaunchOptions';
31
+ import { labelsArgument, severityArgument } from './report/fields';
32
+ import {
33
+ assertEventOrTraceName,
34
+ assertTraceValue,
35
+ copyEventParams,
36
+ } from './data/validate';
37
+ import type { EventParams, TraceValue } from './data/validate';
38
+ import { encodeBridgeObject } from './bridge/json';
39
+ import { AttributeErrorCode, BugseeAttributeError } from './attributes/errors';
40
+ import {
41
+ assertIdentifierString,
42
+ normalizeAttributeReadValue,
43
+ normalizeAttributesMap,
44
+ normalizeIdentifier,
45
+ validateAttributeName,
46
+ validateAttributeValue,
47
+ } from './attributes/validate';
48
+ import type { AttributeReadValue, AttributeValue } from './attributes/validate';
49
+ import { encodeExceptionOptions } from './exceptions/options';
50
+ import type { ExceptionOptions } from './exceptions/options';
51
+ import {
52
+ installExceptionHandlers,
53
+ setExceptionCaptureEnabled,
54
+ } from './exceptions/handlers';
55
+ import {
56
+ markReported,
57
+ reportHandled,
58
+ reportUnhandled,
59
+ } from './exceptions/report';
60
+ import { notify as queueNotification } from './apm/notify';
61
+ import {
62
+ getActiveSpan as readActiveSpan,
63
+ startSpan as openSpan,
64
+ startTransaction as openTransaction,
65
+ } from './apm/span';
66
+ import type { BugseeSpan, BugseeTransaction } from './apm/span';
67
+ import type { SpanAttribute } from './apm/types';
68
+ import { appearance as reportAppearance } from './appearance/report';
69
+ import type { ReportAppearance } from './appearance/report';
70
+
71
+ const DETECT_CRASH_OPTION = 'com.bugsee.option.detect.crash';
72
+
73
+ function applyExceptionCaptureFromOptions(options: LaunchOptions): void {
74
+ setExceptionCaptureEnabled(options[DETECT_CRASH_OPTION] !== false);
75
+ }
76
+
77
+ export { Status } from './status';
78
+
79
+ const KNOWN_STATUSES: ReadonlySet<number> = new Set(Object.values(Status));
80
+
81
+ const KNOWN_ATTRIBUTE_ERROR_CODES: ReadonlySet<string> = new Set(
82
+ Object.values(AttributeErrorCode),
83
+ );
84
+
85
+ /**
86
+ * Translates a native rejection into a `BugseeAttributeError` carrying the
87
+ * same `.code`, so a caller can match on `.code` no matter which side raised
88
+ * it. Anything else -- including a `BugseeAttributeError` already (JS
89
+ * validation raises those directly) -- passes through unchanged.
90
+ */
91
+ function toAttributeError(error: unknown): unknown {
92
+ if (error instanceof BugseeAttributeError) {
93
+ return error;
94
+ }
95
+ const code = (error as { code?: unknown } | null | undefined)?.code;
96
+ if (typeof code === 'string' && KNOWN_ATTRIBUTE_ERROR_CODES.has(code)) {
97
+ const message = (error as { message?: unknown }).message;
98
+ return new BugseeAttributeError(
99
+ code as AttributeErrorCode,
100
+ typeof message === 'string' ? message : code,
101
+ );
102
+ }
103
+ return error;
104
+ }
105
+
106
+ export type LaunchOptions = Record<string, unknown>;
107
+
108
+ /**
109
+ * What `launch` and `relaunch` take: the options object (`createDefaultLaunchOptions()` and its
110
+ * accessors), or the plain `com.bugsee.option.*` map it serialises to. Both are the same payload.
111
+ */
112
+ export type LaunchOptionsInput = BugseeLaunchOptions | LaunchOptions;
113
+
114
+ /** The native payload for either form. An options object is serialised here, once, so callers never have to. */
115
+ function nativeOptionsOf(options: LaunchOptionsInput): LaunchOptions {
116
+ return options instanceof BugseeLaunchOptions
117
+ ? BugseeLaunchOptions.serialize(options)
118
+ : options;
119
+ }
120
+
121
+ class Bugsee {
122
+ /**
123
+ * Starts the SDK. `options` is the options object from `createDefaultLaunchOptions()` as is, or
124
+ * the plain option map; there is no serialise step to call. Resolves to whether the native side
125
+ * actually launched —
126
+ * it can decline (already running, token rejected) without that being an
127
+ * error the caller should throw on.
128
+ *
129
+ * Installs the global JS exception handlers (ErrorUtils and unhandled
130
+ * promise rejections). On Hermes, the last caller of
131
+ * `enablePromiseRejectionTracker` wins — Hermes has no getter — so another
132
+ * SDK that installs a tracker after this call replaces ours.
133
+ *
134
+ * After the native call resolves, patches `console.*` so each line still
135
+ * prints and is then forwarded through the wrapper channel. A rejection
136
+ * does not install the patch. A later call does not wrap the functions
137
+ * again; it does re-read `com.bugsee.option.capture.logs`.
138
+ */
139
+ async launch(token: string, options: LaunchOptionsInput = {}): Promise<boolean> {
140
+ assertUsableToken(token);
141
+ const nativeOptions = nativeOptionsOf(options);
142
+ // Registered before launching, not after: the SDK reads the wrapper while
143
+ // composing a report's environment, and a crash during start-up would
144
+ // otherwise produce a report that does not say what wrapper it came from.
145
+ this.registerWrapper();
146
+ installExceptionHandlers();
147
+ applyExceptionCaptureFromOptions(nativeOptions);
148
+ const launched = await NativeBugsee.launch(token, nativeOptions);
149
+ installConsoleCapture(nativeOptions);
150
+ return launched;
151
+ }
152
+
153
+ /**
154
+ * Tells the SDK what wrapper it is running under.
155
+ *
156
+ * Idempotent and cheap, so `launch` and `relaunch` can both call it; the
157
+ * SDK replaces whatever was registered.
158
+ */
159
+ private registerWrapper(): void {
160
+ NativeBugsee.setWrapperInfo(
161
+ wrapperIdentity(collectWrapperFacts(PACKAGE_VERSION)),
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Restarts an already-launched session with a new set of options.
167
+ *
168
+ * Installs the console patch after the native call resolves, same as
169
+ * {@link launch}. A second install does not wrap again.
170
+ */
171
+ async relaunch(options: LaunchOptionsInput = {}): Promise<boolean> {
172
+ const nativeOptions = nativeOptionsOf(options);
173
+ this.registerWrapper();
174
+ installExceptionHandlers();
175
+ applyExceptionCaptureFromOptions(nativeOptions);
176
+ const relaunched = await NativeBugsee.relaunch(nativeOptions);
177
+ installConsoleCapture(nativeOptions);
178
+ return relaunched;
179
+ }
180
+
181
+ /**
182
+ * Publishes the regions the SDK must not record on `display`, replacing
183
+ * whatever this method published for it before. An empty list clears them.
184
+ *
185
+ * Regions held by a mounted `<BugseeSecure>` are kept apart and published
186
+ * alongside: clearing here never uncovers a component, and a component
187
+ * unmounting never clears these.
188
+ *
189
+ * Synchronous by design. The SDK PULLS these 2-3 times a second from its own
190
+ * thread and never waits on JS, so there is nothing to await; a promise here
191
+ * would only invite a caller to believe a region was redacted before it was.
192
+ *
193
+ * The whole call is rejected if any rectangle is malformed, rather than the
194
+ * bad one being dropped: publishing the rest would leave the caller believing
195
+ * the missing region is redacted when it is not.
196
+ */
197
+ setSecureRectangles(
198
+ rectangles: readonly SecureRectangle[],
199
+ display: number = 0,
200
+ ): void {
201
+ if (!Number.isInteger(display) || display < 0) {
202
+ throw new RangeError(
203
+ 'display must be a non-negative integer; ' +
204
+ 'a fractional index reaches the native cast and silently addresses display 0',
205
+ );
206
+ }
207
+ setOwnerRectangles(`manual:${display}`, display, rectangles);
208
+ }
209
+
210
+ /**
211
+ * Suppresses everything that describes the screen: the video (black
212
+ * frames), the report screenshot (black), touch/gesture recording and the
213
+ * view hierarchy. Logs, network events, custom events and traces keep
214
+ * recording throughout (design doc §4.1).
215
+ *
216
+ * Both platforms honour it before `launch()`: blackout then holds from the
217
+ * first captured frame (Android 7.4.0 applies it at launch,
218
+ * bugsee-android#248). Call it before `launch()` to keep the first seconds
219
+ * of a session redacted.
220
+ *
221
+ * {@link isBlackout} verifies whether it actually took effect.
222
+ */
223
+ startBlackout(): void {
224
+ NativeBugsee.startBlackout();
225
+ }
226
+
227
+ /** Resumes everything {@link startBlackout} suppressed. */
228
+ endBlackout(): void {
229
+ NativeBugsee.endBlackout();
230
+ }
231
+
232
+ /** The current blackout state, as {@link startBlackout} / {@link endBlackout} left it. */
233
+ async isBlackout(): Promise<boolean> {
234
+ return NativeBugsee.isBlackout();
235
+ }
236
+
237
+ /** Captures the view hierarchy immediately, outside a normal snapshot pass. */
238
+ captureViewHierarchy(): void {
239
+ NativeBugsee.captureViewHierarchy();
240
+ }
241
+
242
+ /**
243
+ * Wraps the app's root component so the SDK can capture the on-screen view
244
+ * hierarchy ("vh") -- the anonymised tree of what is on screen that
245
+ * annotates a bug report or a live capture. Without this, the SDK's view-
246
+ * hierarchy request always comes back empty: there is nothing registered
247
+ * for it to walk.
248
+ *
249
+ * Renders `Root` unchanged, alongside an invisible anchor the view-tree
250
+ * walk uses to find the app's fiber tree; neither is ever drawn on top of
251
+ * the app or intercepts a touch. Usage:
252
+ * `AppRegistry.registerComponent(appName, () => Bugsee.wrap(App))`.
253
+ */
254
+ wrap<P extends object>(Root: ComponentType<P>): ComponentType<P> {
255
+ return wrap(Root);
256
+ }
257
+
258
+ /**
259
+ * Subscribes to the SDK's lifecycle events.
260
+ *
261
+ * Events arrive OFF the main thread on both platforms and are delivered to
262
+ * JavaScript as they come; nothing is queued while no subscriber exists, so
263
+ * a subscription made after launch does not replay what it missed. Ask
264
+ * `getStatus()` for the current state rather than reconstructing it.
265
+ *
266
+ * An event this version does not know is delivered unchanged rather than
267
+ * dropped: a newer SDK must be able to reach a subscriber through an older
268
+ * wrapper.
269
+ */
270
+ onLifecycleEvent(
271
+ listener: (event: LifecycleEvent) => void,
272
+ ): { remove: () => void } {
273
+ return NativeBugsee.onLifecycleEvent(listener);
274
+ }
275
+
276
+ /**
277
+ * Subscribes to the SDK's status transitions.
278
+ *
279
+ * Derived from the lifecycle channel, not a second native one: Android has
280
+ * no status listener at all and iOS's belongs to the app's own delegate.
281
+ * Only the four transition events produce a call; everything else is
282
+ * silent, because reporting a status for a non-transition would say the SDK
283
+ * had moved when it had not.
284
+ */
285
+ onStatusChange(
286
+ listener: (status: Status) => void,
287
+ ): { remove: () => void } {
288
+ return NativeBugsee.onLifecycleEvent((event: LifecycleEvent) => {
289
+ const status = statusForEvent(event);
290
+ if (status !== undefined) {
291
+ listener(status);
292
+ }
293
+ });
294
+ }
295
+
296
+ /** Stops the current session. */
297
+ async stop(): Promise<boolean> {
298
+ return NativeBugsee.stop();
299
+ }
300
+
301
+ /**
302
+ * Installs the handler the SDK hands a report to before and/or after it
303
+ * builds one. See `BugseeReportHandler` for the full phase contract.
304
+ *
305
+ * Register before `launch()` to see reports the SDK recovers at launch --
306
+ * a handler installed afterward misses whatever launch already recovered.
307
+ * `null` tells the SDK no phase is wanted; a later call can resume
308
+ * delivery.
309
+ *
310
+ * `onBeforeReportCreated` is at-most-once and may be skipped for a given
311
+ * report; `onAfterReportCreated` is at-least-once and MUST be idempotent
312
+ * (`setLabels`/`setAttribute`, not appending; check `getAttachmentNames()`
313
+ * before adding one).
314
+ *
315
+ * **Attachments.** A handler report takes up to 1000 attachments on both
316
+ * platforms. A file is captured when it is added, and `move` is honoured.
317
+ * `onAfterReportCreated` must check `getAttachmentNames()` before adding.
318
+ *
319
+ * A mutation made after the callback settles, or after
320
+ * its handle's deadline passes -- the SDK's deadline, not one the app
321
+ * negotiates -- does not reach the report.
322
+ *
323
+ * Budgets: 25 s per callback for a live report on both platforms (never
324
+ * raised above that; on Android it follows a lower
325
+ * `report-handler-callback-timeout`). A report recovered at launch gets
326
+ * 2.5 s on iOS (off main, best-effort, edits land only until the bundle is
327
+ * assembled). On Android, a Java uncaught-exception relaunch launched from
328
+ * JS gets the live 25 s on `BugseeReportHandlerThread`. An NDK relaunch,
329
+ * and Android's early bounded recovery, never reach JS. So async I/O in
330
+ * `onAfterReportCreated` can succeed on a Java relaunch and silently miss
331
+ * on iOS recovery or an Android NDK relaunch. Details on
332
+ * `BugseeReportHandler`.
333
+ */
334
+ setReportHandler(handler: BugseeReportHandler | null): void {
335
+ installReportHandler(handler);
336
+ }
337
+
338
+ /**
339
+ * Creates and uploads a bug report immediately, without showing any UI.
340
+ *
341
+ * Does nothing before `launch()`. `showReportDialog` runs
342
+ * `onBeforeReportCreated` before the dialog opens.
343
+ *
344
+ * `summary` and `description` must both be strings (an empty string is
345
+ * fine; only the type is checked). Omitted `severity` crosses as `0`,
346
+ * which is the SDK's default. Omitted `labels` cross as `null`. There is
347
+ * no `includeVideo`: a fifth argument throws `TypeError`.
348
+ */
349
+ upload(
350
+ summary: string,
351
+ description: string,
352
+ severity?: IssueSeverity,
353
+ labels?: readonly string[],
354
+ ): void {
355
+ if (arguments.length > 4) {
356
+ throw new TypeError(
357
+ 'Bugsee.upload takes at most four arguments; 7.x has no includeVideo',
358
+ );
359
+ }
360
+ if (typeof summary !== 'string') {
361
+ throw new TypeError(
362
+ `Bugsee.upload requires summary to be a string, got ${typeof summary}`,
363
+ );
364
+ }
365
+ if (typeof description !== 'string') {
366
+ throw new TypeError(
367
+ `Bugsee.upload requires description to be a string, got ${typeof description}`,
368
+ );
369
+ }
370
+ NativeBugsee.upload(
371
+ summary,
372
+ description,
373
+ severityArgument(severity, 'upload'),
374
+ labelsArgument(labels, 'upload'),
375
+ );
376
+ }
377
+
378
+ /**
379
+ * Shows the bug-report dialog.
380
+ *
381
+ * Does nothing before `launch()`. The dialog runs `onBeforeReportCreated`
382
+ * before it opens.
383
+ *
384
+ * `summary` and `description` are omitted or a string, and cross as `null`
385
+ * when absent. Severity and labels follow `upload`: omitted severity is
386
+ * the SDK default (`0`), omitted labels cross as `null`.
387
+ */
388
+ showReportDialog(
389
+ summary?: string,
390
+ description?: string,
391
+ severity?: IssueSeverity,
392
+ labels?: readonly string[],
393
+ ): void {
394
+ const summaryText = optionalReportText(summary, 'summary');
395
+ const descriptionText = optionalReportText(description, 'description');
396
+ NativeBugsee.showReportDialog(
397
+ summaryText,
398
+ descriptionText,
399
+ severityArgument(severity, 'showReportDialog'),
400
+ labelsArgument(labels, 'showReportDialog'),
401
+ );
402
+ }
403
+
404
+ /**
405
+ * A report to fill and upload. Resolves `null` when the SDK made none
406
+ * (not launched).
407
+ *
408
+ * One outstanding created report at a time. A second `createReport()`
409
+ * before that one is uploaded rejects with `E_REPORT_CREATE_BUSY`. iOS
410
+ * beta3 keeps created-report attributes in file-scope globals, so a second
411
+ * create wipes the first.
412
+ *
413
+ * Android runs `onBeforeReportCreated` inside `createReport` and
414
+ * `onAfterReportCreated` at upload. iOS runs both at upload, after copying
415
+ * the created report's fields, so a handler `setLabels` there replaces the
416
+ * app's labels.
417
+ *
418
+ * iOS created-report attachments: at most 3, each at most 3 MiB. The bridge
419
+ * rejects a further or larger one with `E_REPORT_ATTACHMENT_REJECTED`. iOS
420
+ * ignores `mimeType`. Android's cap is 1000.
421
+ */
422
+ async createReport(): Promise<BugseeCreatedReport | null> {
423
+ return openCreatedReport();
424
+ }
425
+
426
+ /**
427
+ * One line into the Bugsee log: the app's own, through the native
428
+ * `Bugsee.log` (source Bugsee, no tag). Recorded with
429
+ * `com.bugsee.option.capture.logs` false, which turns off only what is
430
+ * captured automatically. The app's log filter ({@link setLogFilter}) runs
431
+ * on it natively, once, only when `requiresFiltering` is `true`; by
432
+ * default it does not, as in the native SDKs. Dropped before launch().
433
+ */
434
+ log(message: string, level: LogLevel = LogLevel.Info, requiresFiltering: boolean = false): void {
435
+ sendLog(message, level, requiresFiltering);
436
+ }
437
+
438
+ /**
439
+ * Registers the only network filter. A later call replaces it. No
440
+ * callback, or `null`, clears it. The callback receives the event the SDK
441
+ * is about to record and returns that event to keep it. Omitting a
442
+ * writable key the callback received drops the event. `url` is always
443
+ * required. `body`, `headers`, `errorDescription`, `errorShortMessage`,
444
+ * `statusText`, `redirectedFromURL`, and `error` are required when that
445
+ * key was present, including when its value was `null`. A `null` value
446
+ * on a key that was present clears that field. A key the snapshot omitted
447
+ * stays omitted: setting that key to `null` leaves it out of the reply.
448
+ * `null` and `undefined` drop the event. The native SDK invokes the
449
+ * filter; JS answers on a later turn, and a callback that throws,
450
+ * rejects, or never settles drops the event.
451
+ *
452
+ * A JS filter replaces the iOS built-in sanitizer. Android runs the
453
+ * default sanitizer before the callback when
454
+ * `com.bugsee.option.capture.network.default-sanitizer` is on.
455
+ */
456
+ setNetworkFilter(callback?: NetworkFilter | null): void {
457
+ installNetworkFilter(callback);
458
+ }
459
+
460
+ /**
461
+ * Records a network event the SDK did not capture: a stack it does not
462
+ * auto-instrument.
463
+ *
464
+ * `url` and `method` must be strings. `stage` names the native stage;
465
+ * `completed` is that stage's name here (the device test records it).
466
+ * Omitted, the stage is `completed`. The bridge stamps the time. The
467
+ * event is built with the SDK exchange factory and handed back with
468
+ * filtering required, so an installed {@link setNetworkFilter} still sees
469
+ * it. This method does not run that filter, and it does not patch
470
+ * `fetch` or XHR.
471
+ *
472
+ * A non-object throws `TypeError`. When the SDK makes no event the call
473
+ * returns and native logs `addNetworkEvent dropped: the SDK made no event`.
474
+ */
475
+ addNetworkEvent(event: AddedNetworkEvent): void {
476
+ recordNetworkEvent(event);
477
+ }
478
+
479
+ /**
480
+ * Registers the log filter. A later call replaces it. Called with no
481
+ * callback, or with `null`, clears it.
482
+ *
483
+ * The callback receives the line and returns the line to keep, or a
484
+ * replacement string. `null` or `undefined` drops the line. The native SDK
485
+ * is what invokes the filter; the callback runs on a later turn, and this
486
+ * method does not wait for it. A callback that throws, rejects, or does
487
+ * not settle before the SDK's own timeout drops the line. It is not passed
488
+ * through.
489
+ */
490
+ setLogFilter(callback?: LogFilter | null): void {
491
+ installLogFilter(callback);
492
+ }
493
+
494
+ /**
495
+ * Records a breadcrumb built by the SDK's exchange factory, which stamps
496
+ * the time. `timestamp` is not a field of `crumb`. `level` is `debug`,
497
+ * `info`, `warning`, `error`, or `fatal`. `data` omitted or `null` leaves
498
+ * the crumb without data.
499
+ *
500
+ * Capture stays off until launch options set `captureBreadcrumbs: true`,
501
+ * on Android and on iOS. While it is off, this records nothing and the
502
+ * filter is not offered a crumb.
503
+ */
504
+ addBreadcrumb(crumb: Breadcrumb): void {
505
+ recordBreadcrumb(crumb);
506
+ }
507
+
508
+ /**
509
+ * Registers the breadcrumb filter. A later call replaces it. Called with
510
+ * no callback, or with `null`, clears it.
511
+ *
512
+ * The callback receives the crumb. Returning the crumb, or another object,
513
+ * keeps it. `null` or `undefined` drops it. A keep must include every
514
+ * writable key the snapshot sent (`category`, `level`, `message`, `type`,
515
+ * and `data` when that key was present). Dropping one, or setting it
516
+ * `undefined`, drops the crumb. A key the snapshot omitted stays omitted.
517
+ * `data: null` clears data. `timestamp` is read-only and is not sent back.
518
+ *
519
+ * The callback runs on a later turn. This method does not wait for it, and
520
+ * it does not add a timeout. A callback that throws, rejects, or never
521
+ * settles drops the crumb. The original is not passed through. A crumb
522
+ * already passed to `addBreadcrumb` is still offered to the callback that
523
+ * was installed for it when this is cleared, or replaced with another
524
+ * function, on that same turn.
525
+ *
526
+ * Capture stays off until launch options set `captureBreadcrumbs: true`,
527
+ * on Android and on iOS. While it is off, `addBreadcrumb` records nothing
528
+ * and the filter is not offered a crumb.
529
+ */
530
+ setBreadcrumbFilter(callback?: BreadcrumbFilter | null): void {
531
+ installBreadcrumbFilter(callback);
532
+ }
533
+
534
+ /**
535
+ * Records a named event, with optional params.
536
+ *
537
+ * `params` must be a plain object or omitted entirely -- `null` throws
538
+ * `TypeError`, a change from 6.x, which accepted `null` there as "no
539
+ * params". Pass no second argument (or `undefined`) instead.
540
+ *
541
+ * `params` is validated against the accepted value domain
542
+ * (`src/data/validate.ts`) and copied before it crosses -- a value outside
543
+ * that domain throws synchronously, in JS, rather than reaching native in
544
+ * some guessed-at shape. It crosses as JSON text (`src/bridge/json.ts`), so
545
+ * a `null` member arrives as `null` on both platforms. Omitting `params`
546
+ * sends `null` natively, not `'{}'`: the bundle's event entry has no
547
+ * `params` key at all when none were given.
548
+ */
549
+ event(name: string, params?: EventParams): void {
550
+ assertEventOrTraceName('event', name);
551
+ if (params === undefined) {
552
+ NativeBugsee.event(name, null);
553
+ return;
554
+ }
555
+ NativeBugsee.event(name, encodeBridgeObject(copyEventParams(params)));
556
+ }
557
+
558
+ /**
559
+ * Records a named trace value.
560
+ *
561
+ * Dispatches on `typeof value` to one of three typed native methods --
562
+ * `traceNumber`, `traceString` or `traceBoolean` -- rather than one
563
+ * untyped call: codegen has no union parameter type, and an untyped path
564
+ * would let a boolean silently arrive as `0`/`1` on the SDK side. `value`
565
+ * is validated first, so nothing outside the domain reaches any of them.
566
+ */
567
+ trace(name: string, value: TraceValue): void {
568
+ assertEventOrTraceName('trace', name);
569
+ assertTraceValue(value);
570
+ if (typeof value === 'number') {
571
+ NativeBugsee.traceNumber(name, value);
572
+ } else if (typeof value === 'string') {
573
+ NativeBugsee.traceString(name, value);
574
+ } else {
575
+ NativeBugsee.traceBoolean(name, value);
576
+ }
577
+ }
578
+
579
+ /**
580
+ * Runs `fn`, translating any rejection into a `BugseeAttributeError`.
581
+ * `fn` validates its own arguments FIRST, synchronously, inside this same
582
+ * async function body -- a synchronous throw there becomes this promise's
583
+ * rejection automatically, so a validation failure never crosses the
584
+ * bridge and never throws synchronously either.
585
+ */
586
+ private async runAttributeOp<T>(fn: () => Promise<T>): Promise<T> {
587
+ try {
588
+ return await fn();
589
+ } catch (error) {
590
+ throw toAttributeError(error);
591
+ }
592
+ }
593
+
594
+ /**
595
+ * Sets an attribute, dispatching on `typeof value` to one of three typed
596
+ * native methods -- exactly as {@link trace} does, and for the same
597
+ * reason: there is no untyped bridge parameter a boolean could not
598
+ * silently become `0`/`1` through.
599
+ *
600
+ * Persists across launches. Android stores a fractional or large number as
601
+ * a 32-bit float, so `setAttribute('k', 0.1)` can read back as
602
+ * `0.10000000149011612` -- the value the report itself carries, not a
603
+ * rounding bug in this wrapper. iOS drops a value whose archived size
604
+ * exceeds about 1.1 KB. In practice a string of up to ~800 ASCII
605
+ * characters is safe on both platforms; Android accepts up to 1024 UTF-16
606
+ * units. A string longer than that can be rejected here with
607
+ * `E_ATTRIBUTE_REJECTED` on iOS while the same value is kept on Android.
608
+ */
609
+ async setAttribute(name: string, value: AttributeValue): Promise<void> {
610
+ return this.runAttributeOp(async () => {
611
+ const validName = validateAttributeName(name);
612
+ const validValue = validateAttributeValue(value);
613
+ if (typeof validValue === 'string') {
614
+ await NativeBugsee.setAttributeString(validName, validValue);
615
+ } else if (typeof validValue === 'number') {
616
+ await NativeBugsee.setAttributeNumber(validName, validValue);
617
+ } else {
618
+ await NativeBugsee.setAttributeBoolean(validName, validValue);
619
+ }
620
+ });
621
+ }
622
+
623
+ /** One attribute's current value, or `undefined` when it is not set. */
624
+ async getAttribute(name: string): Promise<AttributeReadValue | undefined> {
625
+ return this.runAttributeOp(async () => {
626
+ const validName = validateAttributeName(name);
627
+ const raw = (await NativeBugsee.getAttribute(validName)) as { value?: unknown };
628
+ return normalizeAttributeReadValue(raw?.value);
629
+ });
630
+ }
631
+
632
+ /** Every attribute currently set, as the retained report will carry them. */
633
+ async getAllAttributes(): Promise<Record<string, AttributeReadValue>> {
634
+ return this.runAttributeOp(async () => normalizeAttributesMap(await NativeBugsee.getAllAttributes()));
635
+ }
636
+
637
+ /** Removes one attribute. A no-op if it was not set. */
638
+ async clearAttribute(name: string): Promise<void> {
639
+ return this.runAttributeOp(async () => {
640
+ const validName = validateAttributeName(name);
641
+ await NativeBugsee.clearAttribute(validName);
642
+ });
643
+ }
644
+
645
+ /** Removes every attribute. */
646
+ async clearAllAttributes(): Promise<void> {
647
+ return this.runAttributeOp(() => NativeBugsee.clearAllAttributes());
648
+ }
649
+
650
+ /**
651
+ * Sets the user identifier. Synchronous, unlike the attribute methods: no
652
+ * size limit applies to it, so there is nothing a native read-back could
653
+ * usefully reject.
654
+ *
655
+ * `''` clears instead of setting an empty identifier -- both SDKs treat an
656
+ * empty identifier as "no identifier" on read, but only iOS treats SETTING
657
+ * one as a clear; this makes the two consistent.
658
+ */
659
+ setUserIdentifier(identifier: string): void {
660
+ assertIdentifierString(identifier);
661
+ if (identifier.length === 0) {
662
+ NativeBugsee.clearUserIdentifier();
663
+ return;
664
+ }
665
+ NativeBugsee.setUserIdentifier(identifier);
666
+ }
667
+
668
+ /** The current user identifier, or `undefined` when none is set. */
669
+ async getUserIdentifier(): Promise<string | undefined> {
670
+ const raw = (await NativeBugsee.getUserIdentifier()) as { value?: unknown };
671
+ return normalizeIdentifier(raw?.value);
672
+ }
673
+
674
+ /** Clears the user identifier. */
675
+ clearUserIdentifier(): void {
676
+ NativeBugsee.clearUserIdentifier();
677
+ }
678
+
679
+ /**
680
+ * Wires up the JS layer when the native SDK launched itself — on Android,
681
+ * from `com.bugsee.app-token` manifest metadata. Deliberately makes no
682
+ * native launch call; doing so would start a second session.
683
+ *
684
+ * Reads `com.bugsee.option.detect.crash` from the native launch options and
685
+ * applies it before the global handlers are installed (R7). Capture is held
686
+ * off during that read: the default is on, and the read yields, so a render
687
+ * error in the gap would otherwise be reported when the option is false.
688
+ * If the read rejects, capture stays off and the handlers are not installed.
689
+ * The console patch is installed from those same options, after the
690
+ * handlers; a rejected read does not install it either.
691
+ */
692
+ async attach(): Promise<void> {
693
+ setExceptionCaptureEnabled(false);
694
+ const options = await this.getLaunchOptions();
695
+ applyExceptionCaptureFromOptions(options);
696
+ installExceptionHandlers();
697
+ installConsoleCapture(options);
698
+ }
699
+
700
+ /**
701
+ * The SDK's current status. An unrecognised native value reports as
702
+ * `Stopped` rather than being passed through, so a newer native SDK adding
703
+ * a state cannot leak a number no JS caller can interpret.
704
+ */
705
+ async getStatus(): Promise<Status> {
706
+ const raw = await NativeBugsee.getStatus();
707
+ return KNOWN_STATUSES.has(raw) ? (raw as Status) : Status.Stopped;
708
+ }
709
+
710
+ /** The options the SDK reports as being in effect. */
711
+ async getLaunchOptions(): Promise<Record<string, unknown>> {
712
+ return (await NativeBugsee.getLaunchOptions()) as Record<string, unknown>;
713
+ }
714
+
715
+ /**
716
+ * The SDK's own test crash: a Java `RuntimeException` on Android, an
717
+ * `NSException` on iOS. For a real native (signal) crash, see the bare
718
+ * example's native helper package.
719
+ */
720
+ testNativeCrash(): void {
721
+ NativeBugsee.testCrash();
722
+ }
723
+
724
+ /** Throws in JS, to verify the JS exception handler is wired up. */
725
+ testJsCrash(): never {
726
+ throw new Error('Bugsee test JS crash');
727
+ }
728
+
729
+ /**
730
+ * Reports `error` as a handled error. Before launch() the SDKs drop it.
731
+ * Validates `options` first: a bad option throws synchronously and nothing
732
+ * crosses.
733
+ */
734
+ logException(error: unknown, options?: ExceptionOptions): void {
735
+ encodeExceptionOptions(options);
736
+ if (!markReported(error)) {
737
+ return;
738
+ }
739
+ const extras =
740
+ error instanceof Error
741
+ ? undefined
742
+ : { fallbackStack: dropFirstStackFrame(new Error().stack) };
743
+ reportHandled(error, options, extras);
744
+ }
745
+
746
+ /**
747
+ * Reports `error` as a crash; resolves once the SDK has it (at most 1.5 s
748
+ * on iOS, 5 s on Android). iOS surfaces it at the next launch.
749
+ */
750
+ logUnhandledException(error: unknown): Promise<void> {
751
+ if (!markReported(error)) {
752
+ return Promise.resolve();
753
+ }
754
+ const extras =
755
+ error instanceof Error
756
+ ? undefined
757
+ : { fallbackStack: dropFirstStackFrame(new Error().stack) };
758
+ return reportUnhandled(error, extras);
759
+ }
760
+
761
+ /**
762
+ * Queues a notification for the app's messaging integrations. This does
763
+ * not create a bug report: no video, logs or events are attached. Both
764
+ * SDKs persist it and upload it in a batch. `urgent` skip-ahead POSTs
765
+ * this item without draining older ones; omitted, the call is not urgent.
766
+ *
767
+ * Omitted `severity` crosses as `0`, which both SDKs treat as unset.
768
+ * Omitted `fields` cross as null. A call before `launch()` is ignored by
769
+ * the SDK. An empty title is rejected here, because both SDKs would drop
770
+ * it and only log. A sixth argument throws `TypeError`.
771
+ */
772
+ notify(
773
+ title: string,
774
+ body?: string | null,
775
+ severity?: IssueSeverity,
776
+ fields?: Readonly<Record<string, string>> | null,
777
+ urgent?: boolean,
778
+ ): void {
779
+ if (arguments.length > 5) {
780
+ throw new TypeError('Bugsee.notify takes at most five arguments');
781
+ }
782
+ queueNotification(title, body, severity, fields, urgent);
783
+ }
784
+
785
+ /**
786
+ * Starts a performance transaction and returns it. The bridge retains the
787
+ * native object until {@link BugseeSpan.finish} releases it, including any
788
+ * child that finish cancelled.
789
+ *
790
+ * `name` and `operation` are the SDK's two required strings. Omitted
791
+ * `attributes` is the two-argument overload. The transaction becomes the
792
+ * active span on the thread the bridge calls from, so a later
793
+ * {@link startSpan} is its child. Both SDKs return a no-op when
794
+ * performance monitoring is off; `finish` still releases that handle.
795
+ */
796
+ startTransaction(
797
+ name: string,
798
+ operation: string,
799
+ attributes?: Readonly<Record<string, SpanAttribute>>,
800
+ ): BugseeTransaction {
801
+ return openTransaction(name, operation, attributes);
802
+ }
803
+
804
+ /**
805
+ * Starts a span as a child of the active span on the bridge's thread.
806
+ * With no active transaction, or with performance monitoring off, the SDK
807
+ * returns a no-op. `finish` releases the handle either way.
808
+ */
809
+ startSpan(operation: string, description?: string | null): BugseeSpan {
810
+ return openSpan(operation, description);
811
+ }
812
+
813
+ /**
814
+ * The active span on the bridge's thread, or null when there is none.
815
+ * A span this process already holds is the same object.
816
+ */
817
+ getActiveSpan(): BugseeSpan | null {
818
+ return readActiveSpan();
819
+ }
820
+
821
+ /**
822
+ * Report UI colors. One camelCase surface: Android applies
823
+ * `setColor(ReportAppearance.X, int)`, iOS sets the matching property on
824
+ * `BugseeTheme`. Setting a name that exists on only one platform throws on
825
+ * the other. Reading a color this platform does not have returns
826
+ * `undefined`. Reading a color it does have returns what the SDK stored.
827
+ */
828
+ get appearance(): ReportAppearance {
829
+ return reportAppearance;
830
+ }
831
+
832
+ /**
833
+ * Deletes collected data stored on the device.
834
+ *
835
+ * `includingIntermediate` crosses unchanged. Both SDKs delete the rolling
836
+ * capture data whatever it is, and keep finished bundles:
837
+ * - `false`: deletes the capture data, keeps finished bundles.
838
+ * - `true`: also deletes intermediate data (snapshots, exported reports).
839
+ * The SDK must be stopped for the deletion to succeed. While launched, both
840
+ * platforms refuse it and this resolves `false`.
841
+ */
842
+ deleteCollectedDataOnDevice(includingIntermediate: boolean): Promise<boolean> {
843
+ return NativeBugsee.deleteCollectedDataOnDevice(includingIntermediate);
844
+ }
845
+ }
846
+
847
+ /**
848
+ * `stack` with its first frame line removed, so a non-Error logged through the
849
+ * facade has frames that start at the caller rather than at `logException`.
850
+ */
851
+ function dropFirstStackFrame(stack: string | undefined): string | undefined {
852
+ if (typeof stack !== 'string' || stack.length === 0) {
853
+ return stack;
854
+ }
855
+ const lines = stack.split('\n');
856
+ let firstFrame = -1;
857
+ for (let i = 0; i < lines.length; i += 1) {
858
+ const trimmed = lines[i]!.trimStart();
859
+ if (
860
+ trimmed.startsWith('at ') ||
861
+ trimmed.startsWith('@') ||
862
+ /^[^\s@]+@/.test(trimmed)
863
+ ) {
864
+ firstFrame = i;
865
+ break;
866
+ }
867
+ }
868
+ if (firstFrame === -1) {
869
+ return stack;
870
+ }
871
+ lines.splice(firstFrame, 1);
872
+ return lines.join('\n');
873
+ }
874
+
875
+ function optionalReportText(
876
+ value: unknown,
877
+ name: 'summary' | 'description',
878
+ ): string | null {
879
+ if (value === undefined) {
880
+ return null;
881
+ }
882
+ if (typeof value !== 'string') {
883
+ throw new TypeError(
884
+ `Bugsee.showReportDialog requires ${name} to be a string, got ${typeof value}`,
885
+ );
886
+ }
887
+ return value;
888
+ }
889
+
890
+ /**
891
+ * Rejects a blank or non-string token before the bridge, with the code and
892
+ * message the native modules use for the same refusal (`E_TOKEN`), so a
893
+ * caller matching on `.code` sees one answer whichever side raised it.
894
+ */
895
+ function assertUsableToken(token: string): void {
896
+ if (typeof token !== 'string' || token.trim().length === 0) {
897
+ throw Object.assign(new Error('Bugsee.launch requires a non-empty app token'), {
898
+ code: 'E_TOKEN',
899
+ });
900
+ }
901
+ }
902
+
903
+ export { WRAPPER_TYPE } from './wrapper/identity';
904
+ export { PACKAGE_VERSION } from './version';
905
+ export { BugseeLaunchOptions } from './options/BugseeLaunchOptions';
906
+ export { AndroidLaunchOptions } from './options/AndroidLaunchOptions';
907
+ export { IOSLaunchOptions } from './options/IOSLaunchOptions';
908
+ export { createDefaultLaunchOptions } from './options/createDefaultLaunchOptions';
909
+ export { endpointFor } from './options/endpoint';
910
+ export {
911
+ CrashHandlerType,
912
+ FrameRate,
913
+ IssueSeverity,
914
+ LogLevel,
915
+ VideoMode,
916
+ VideoQuality,
917
+ } from './options/enums';
918
+
919
+ export default new Bugsee();
920
+
921
+ export type { SecureRectangle } from './secure/rectangles';
922
+ export { BugseeSecure } from './secure/BugseeSecure';
923
+ export type { BugseeSecureProps } from './secure/BugseeSecure';
924
+
925
+ export type { LifecycleEvent } from './wrapper/events';
926
+
927
+ export { ReportErrorCode, BugseeReportError } from './report/errors';
928
+ export type {
929
+ BugseeCreatedReport,
930
+ BugseeReport,
931
+ BugseeReportHandler,
932
+ BugseeReportSnapshot,
933
+ ReportPatch,
934
+ ReportType,
935
+ } from './report/types';
936
+
937
+ export type { EventParams, EventParamValue, TraceValue } from './data/validate';
938
+
939
+ export { AttributeErrorCode, BugseeAttributeError } from './attributes/errors';
940
+ export type { AttributeReadValue, AttributeValue } from './attributes/validate';
941
+
942
+ export type { LogFilter } from './logs/filter';
943
+ export type { NetworkFilter, NetworkFilterEvent } from './network/filter';
944
+ export type { AddedNetworkEvent } from './network/add';
945
+
946
+ export type {
947
+ Breadcrumb,
948
+ BreadcrumbFilter,
949
+ BreadcrumbLevel,
950
+ BreadcrumbSnapshot,
951
+ } from './breadcrumbs/types';
952
+
953
+ export type { ExceptionOptions } from './exceptions/options';
954
+ export { SpanStatus } from './apm/types';
955
+ export type { SpanAttribute } from './apm/types';
956
+ export type { BugseeSpan, BugseeTransaction } from './apm/span';
957
+ export { SpanErrorCode, BugseeSpanError } from './apm/types';
958
+ export { ErrorBoundary } from './exceptions/ErrorBoundary';
959
+ export type {
960
+ ErrorBoundaryFallbackProps,
961
+ ErrorBoundaryProps,
962
+ } from './exceptions/ErrorBoundary';