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

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