@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
@@ -0,0 +1,180 @@
1
+ import NativeBugsee from '../NativeBugsee';
2
+ import { LogLevel } from '../options/enums';
3
+ import { forwardLog } from '../wrapper/channel';
4
+ import {
5
+ claimEcho,
6
+ protectLine,
7
+ readDev,
8
+ shouldForwardJsPatch,
9
+ } from './dedup';
10
+
11
+ /**
12
+ * The launch option that turns console forwarding off. Absent means on,
13
+ * which is the SDK default. Read on every install, including a second one:
14
+ * the functions are wrapped only once, but a later `launch` / `relaunch` /
15
+ * `attach` can still stop or resume forwarding.
16
+ */
17
+ const CAPTURE_LOGS_OPTION = 'com.bugsee.option.capture.logs';
18
+
19
+ const METHODS = ['error', 'warn', 'log', 'info', 'debug'] as const;
20
+ type ConsoleMethod = (typeof METHODS)[number];
21
+
22
+ /**
23
+ * `console.error` → Error (1), `warn` → Warning (2), `log` and `info` →
24
+ * Info (3), `debug` → Debug (4). There is no `console.trace` mapping.
25
+ */
26
+ const LEVEL_BY_METHOD: Record<ConsoleMethod, LogLevel> = {
27
+ error: LogLevel.Error,
28
+ warn: LogLevel.Warning,
29
+ log: LogLevel.Info,
30
+ info: LogLevel.Info,
31
+ debug: LogLevel.Debug,
32
+ };
33
+
34
+ let installed = false;
35
+ let forwardEnabled!: boolean;
36
+ /** Set around the original console call when this patch will also forward. */
37
+ let expectingEcho = false;
38
+
39
+ interface NativeLoggingHost {
40
+ nativeLoggingHook?: (message: string, level: number) => void;
41
+ }
42
+
43
+ interface WrappedHook {
44
+ (message: string, level: number): void;
45
+ bugseeConsoleHook?: boolean;
46
+ }
47
+
48
+ function loggingHost(): NativeLoggingHost {
49
+ return globalThis as NativeLoggingHost;
50
+ }
51
+
52
+ /**
53
+ * Wraps `nativeLoggingHook` once. The original hook still runs, so logcat
54
+ * and the Xcode console keep the line. While this patch is inside a console
55
+ * call it will forward, the hook's message is claimed before the original
56
+ * hook runs. That is before logcat is written, so the claim exists when the
57
+ * echo is filtered, even if the channel line has not been noted yet.
58
+ *
59
+ * `noteConsoleEcho` returns a value, so codegen runs it here on the JS
60
+ * thread, and the native credit exists before the original hook writes
61
+ * the line. A `void` method would be queued, and the SDK's logcat reader
62
+ * could filter the echo first.
63
+ */
64
+ function installNativeHook(): void {
65
+ const host = loggingHost();
66
+ const current = host.nativeLoggingHook;
67
+ if (typeof current !== 'function' || isWrappedHook(current)) {
68
+ return;
69
+ }
70
+ const wrapped: WrappedHook = (message: string, level: number): void => {
71
+ if (expectingEcho) {
72
+ expectingEcho = false;
73
+ claimEcho(message);
74
+ // Synchronous, before the original hook writes logcat or os_log, so
75
+ // the native drop is armed when the echo is captured. Not a second
76
+ // log route. The returned value carries nothing.
77
+ try {
78
+ NativeBugsee.noteConsoleEcho(message);
79
+ } catch {
80
+ // The echo may reach the filter. The claim still drops a stamp.
81
+ }
82
+ }
83
+ current(message, level);
84
+ };
85
+ wrapped.bugseeConsoleHook = true;
86
+ host.nativeLoggingHook = wrapped;
87
+ }
88
+
89
+ function isWrappedHook(
90
+ hook: (message: string, level: number) => void,
91
+ ): hook is WrappedHook {
92
+ return (hook as WrappedHook).bugseeConsoleHook === true;
93
+ }
94
+
95
+ /**
96
+ * One argument, via `String`. That is the success path, including functions.
97
+ * `String` throws for a null-prototype object and for a throwing `toString`
98
+ * / `valueOf`. The fallback is the ordinary tag, which does not copy fields.
99
+ */
100
+ function stringifyArg(arg: unknown): string {
101
+ try {
102
+ return String(arg);
103
+ } catch {
104
+ return Object.prototype.toString.call(arg);
105
+ }
106
+ }
107
+
108
+ /**
109
+ * One console line, the way a console prints several arguments: joined with
110
+ * a space. Objects that `String` can convert stay `[object Object]` — they
111
+ * are not JSON, so a field that holds a secret is not copied into the log.
112
+ */
113
+ function formatConsoleLine(args: readonly unknown[]): string {
114
+ // A loop, not map+join: the intermediate array showed up on this hot path.
115
+ let result = '';
116
+ let first = true;
117
+ for (const arg of args) {
118
+ result += (first ? '' : ' ') + stringifyArg(arg);
119
+ first = false;
120
+ }
121
+ return result;
122
+ }
123
+
124
+ function patch(method: ConsoleMethod): void {
125
+ const level = LEVEL_BY_METHOD[method];
126
+ const original = console[method].bind(console);
127
+ const wrapped = (...args: unknown[]): void => {
128
+ const dev = readDev();
129
+ const owns = forwardEnabled && shouldForwardJsPatch(dev);
130
+ if (!owns) {
131
+ original(...args);
132
+ return;
133
+ }
134
+ // The patch owns the call, so the echo is claimed and the line is
135
+ // protected. That is shouldDropConsoleEcho(dev, true).
136
+ const line = formatConsoleLine(args);
137
+ expectingEcho = true;
138
+ try {
139
+ original(...args);
140
+ } finally {
141
+ expectingEcho = false;
142
+ }
143
+ // The channel can throw. The original call has already run; this wrap
144
+ // must not turn that into an uncaught exception.
145
+ try {
146
+ protectLine(line);
147
+ forwardLog(line, level);
148
+ } catch {
149
+ // Drop the line. The console call itself succeeded.
150
+ }
151
+ };
152
+ console[method] = wrapped as typeof console.log;
153
+ }
154
+
155
+ /**
156
+ * Patches `console.log`, `console.info`, `console.warn`, `console.error`
157
+ * and `console.debug`. Each call still performs the original console call,
158
+ * then forwards one line through `forwardLog` — the only native route for
159
+ * the patch. The app's log filter is not run here. Under `__DEV__` the
160
+ * same call also reaches `RCTLog`; that echo is claimed so the filter
161
+ * runs once. The patch still forwards in release: `RCTLog` does not carry
162
+ * `console.*` there.
163
+ *
164
+ * Idempotent. A second call does not wrap the already-patched functions.
165
+ * It does re-read `com.bugsee.option.capture.logs`: `false` stops
166
+ * forwarding, and an absent option leaves forwarding on.
167
+ *
168
+ * An explicit `Bugsee.log` does not go through this patch.
169
+ */
170
+ export function installConsoleCapture(options: Record<string, unknown> = {}): void {
171
+ forwardEnabled = options[CAPTURE_LOGS_OPTION] !== false;
172
+ installNativeHook();
173
+ if (installed) {
174
+ return;
175
+ }
176
+ installed = true;
177
+ for (const method of METHODS) {
178
+ patch(method);
179
+ }
180
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Which of the two console streams may reach the user's log filter.
3
+ *
4
+ * Under `__DEV__`, one `console.*` call is seen by the JS patch and by
5
+ * React Native's `RCTLog` (`nativeLoggingHook`). Both streams stay live:
6
+ * the patch is how a release build still records console output (React
7
+ * Native does not route `console.*` through `RCTLog` then, and a Hermes
8
+ * release build often strips the call before `RCTLog` could see it), and
9
+ * `RCTLog` is how RN-internal lines that the patch never sees are recorded.
10
+ *
11
+ * The overlap is removed by dropping the echo, not the patch. Dropping the
12
+ * patch because `RCTLog` "will also see it" would drop release logs.
13
+ */
14
+
15
+ /** How long an echo claim can still suppress a second filter pass. */
16
+ export const ECHO_WINDOW_MS = 2_000;
17
+
18
+ const MAX_CLAIMS = 32;
19
+
20
+ interface Claim {
21
+ text: string;
22
+ expires: number;
23
+ }
24
+
25
+ /**
26
+ * Equal text and the stderr stamp are separate claims. Delivering the patch
27
+ * removes the equal-text claim on both platforms: Android already dropped
28
+ * the logcat echo, and iOS does not forward `RCTLogSourceJavaScript`.
29
+ * os_log capture is disabled, so there is no unstamped stderr copy to wait
30
+ * for. The stamp is a different string and is dropped on its own.
31
+ */
32
+ const exactEchoes = new Array<Claim>();
33
+ const stampEchoes = new Array<Claim>();
34
+ const protectedLines = new Array<Claim>();
35
+
36
+ /** `__DEV__` when the runtime defined it, otherwise a release-shaped build. */
37
+ export function readDev(): boolean {
38
+ const devFlag = (globalThis as { __DEV__?: unknown }).__DEV__;
39
+ return typeof devFlag === 'boolean' ? devFlag : false;
40
+ }
41
+
42
+ /**
43
+ * The JS patch forwards in dev and in release. A build that forwarded only
44
+ * in one of them would either double-filter dev or drop release.
45
+ */
46
+ // The build flag is part of the signature. Both values forward.
47
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
+ export function shouldForwardJsPatch(dev: boolean): boolean {
49
+ // Dev and release both forward. The argument stays so a caller cannot
50
+ // select one build and skip the other.
51
+ return true;
52
+ }
53
+
54
+ /**
55
+ * The RCTLog echo of a call the patch is forwarding. Dropped in dev, where
56
+ * that overlap exists, and in release if the echo is still produced: the
57
+ * patch already has the line. An RCTLog line the patch does not own (RN
58
+ * core, a native module) is not an echo and is kept.
59
+ */
60
+ export function shouldDropConsoleEcho(dev: boolean, patchOwnsCall: boolean): boolean {
61
+ // The echo is dropped in dev and in release. Only whether the patch owns
62
+ // the call changes the answer.
63
+ return patchOwnsCall;
64
+ }
65
+
66
+ /**
67
+ * The equal-text claim dies with the patch. No unstamped echo of that line
68
+ * reaches JS: Android drops it in the bridge, and iOS writes only os_log of
69
+ * the raw message while this package skips `RCTLogSourceJavaScript`.
70
+ */
71
+ function retireExact(text: string): void {
72
+ const echoAt = exactEchoes.findIndex((claim) => claim.text === text);
73
+ if (echoAt !== -1) {
74
+ exactEchoes.splice(echoAt, 1);
75
+ }
76
+ }
77
+
78
+ function prune(list: Claim[], now: number): void {
79
+ let index = 0;
80
+ while (index < list.length) {
81
+ const claim = list[index]!;
82
+ if (claim.expires <= now) {
83
+ if (list === protectedLines) {
84
+ retireExact(claim.text);
85
+ }
86
+ list.splice(index, 1);
87
+ } else {
88
+ index += 1;
89
+ }
90
+ }
91
+ }
92
+
93
+ function remember(list: Claim[], text: string, now: number): void {
94
+ list.push({ text, expires: now + ECHO_WINDOW_MS });
95
+ while (list.length > MAX_CLAIMS) {
96
+ list.shift();
97
+ }
98
+ }
99
+
100
+ /** The text `nativeLoggingHook` actually emitted for this console call. */
101
+ export function claimEcho(message: string, now: number = Date.now()): void {
102
+ remember(exactEchoes, message, now);
103
+ remember(stampEchoes, message, now);
104
+ }
105
+
106
+ /** The line the JS patch is about to forward. That copy reaches the filter. */
107
+ export function protectLine(line: string, now: number = Date.now()): void {
108
+ remember(protectedLines, line, now);
109
+ }
110
+
111
+ /**
112
+ * A stderr line the iOS SDK stored as
113
+ * `2026-10-02 18:40:35.273 BareExample[60839:42420530] <message>`.
114
+ * The stamp is a different string from the patch. Dropping it does not
115
+ * retire the equal-text claim; delivering the patch does. os_log capture
116
+ * is disabled, and this package does not wait for an unstamped stderr
117
+ * copy. Android's logcat echo is dropped in the bridge before JS is asked.
118
+ */
119
+ export function isConsoleStampOf(line: string, message: string): boolean {
120
+ const tail = `] ${message}`;
121
+ if (message.length === 0 || !line.endsWith(tail)) {
122
+ return false;
123
+ }
124
+ const head = line.slice(0, line.length - tail.length);
125
+ const splitAt = head.indexOf('[');
126
+ const when = head.slice(0, splitAt);
127
+ const pid = head.slice(splitAt + 1);
128
+ return (
129
+ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [^\s[]+$/.test(when) && /^\d+:\d+$/.test(pid)
130
+ );
131
+ }
132
+
133
+ /**
134
+ * `deliver` runs the user's filter. `drop` answers the native request with
135
+ * null and does not call the user.
136
+ *
137
+ * The equal-text claim dies when the patch is delivered, on Android and
138
+ * on iOS. A later `Bugsee.log`, native line, or second `console.*` of that
139
+ * string is kept. An echo that is actually classified — a stderr stamp, or
140
+ * an equal line that arrives while the claim is still live — is dropped
141
+ * once. os_log capture is disabled. There is no unstamped stderr copy to
142
+ * wait for.
143
+ */
144
+ export function classifyFilterRequest(
145
+ line: string,
146
+ now: number = Date.now(),
147
+ ): 'deliver' | 'drop' {
148
+ prune(protectedLines, now);
149
+ prune(exactEchoes, now);
150
+ prune(stampEchoes, now);
151
+ const stampAt = stampEchoes.findIndex((claim) => isConsoleStampOf(line, claim.text));
152
+ if (stampAt !== -1) {
153
+ stampEchoes.splice(stampAt, 1);
154
+ return 'drop';
155
+ }
156
+ const protectAt = protectedLines.findIndex((claim) => claim.text === line);
157
+ if (protectAt !== -1) {
158
+ protectedLines.splice(protectAt, 1);
159
+ retireExact(line);
160
+ return 'deliver';
161
+ }
162
+ const echoAt = exactEchoes.findIndex((claim) => claim.text === line);
163
+ if (echoAt !== -1) {
164
+ exactEchoes.splice(echoAt, 1);
165
+ return 'drop';
166
+ }
167
+ return 'deliver';
168
+ }
169
+
170
+ /** Tests start from an empty ledger. Production never calls this. */
171
+ export function resetConsoleDedup(): void {
172
+ exactEchoes.length = 0;
173
+ stampEchoes.length = 0;
174
+ protectedLines.length = 0;
175
+ }
@@ -0,0 +1,259 @@
1
+ /**
2
+ * The value domain shared by `Bugsee.event` and `Bugsee.trace`.
3
+ *
4
+ * Both SDKs serialise nested maps, lists, strings, booleans, numbers and null
5
+ * (design doc Phase 4, "Verified facts"), but neither does anything useful
6
+ * with a value outside that set: a `Date` silently becomes whatever its
7
+ * `HashMap`/`NSDictionary` conversion does with an opaque object, a cycle
8
+ * hangs the native JSON writer, and `undefined` has no wire representation at
9
+ * all. So everything here is checked and copied in JS, before crossing,
10
+ * rather than left for native to discover.
11
+ */
12
+
13
+ /** One value inside an event's params, recursively. */
14
+ export type EventParamValue =
15
+ | string
16
+ | number
17
+ | boolean
18
+ | null
19
+ | readonly EventParamValue[]
20
+ | { readonly [key: string]: EventParamValue | undefined };
21
+
22
+ /** An event's params: a plain object of {@link EventParamValue}s. */
23
+ export type EventParams = { readonly [key: string]: EventParamValue | undefined };
24
+
25
+ /** A trace's value: a string, a finite number or a boolean. */
26
+ export type TraceValue = string | number | boolean;
27
+
28
+ /**
29
+ * Nesting past this is almost certainly a cycle or an accident, not a
30
+ * deliberate payload. Rejected with the path that hit it.
31
+ */
32
+ export const EVENT_PARAMS_MAX_DEPTH = 16;
33
+
34
+ /**
35
+ * The one numeric bound for every number that reaches a bundle -- event
36
+ * params, trace values, and (Phase 5) attributes: finite and smaller than
37
+ * `2^63` in magnitude. Exclusive of `2^63` itself: Android's JSON writer
38
+ * sends any integral value at or beyond `Long.MAX_VALUE` through
39
+ * `longValue()`, and every double `>= 2^63` silently becomes
40
+ * `9223372036854775807` there rather than round-tripping, so the bound must
41
+ * reject before that point, not at it. Shared with `src/attributes/validate.ts`.
42
+ */
43
+ export const BUNDLE_NUMBER_LIMIT = 2 ** 63;
44
+
45
+ /**
46
+ * {@link BUNDLE_NUMBER_LIMIT} as the exact decimal integer string, for use in
47
+ * rejection messages. Printing the bound (or a rejected value near it) via
48
+ * `Number`'s own string conversion rounds: `String(BUNDLE_NUMBER_LIMIT)`
49
+ * reads `9223372036854776000`, not the true `9223372036854775808`, and a
50
+ * value like `1e19` prints as `10000000000000000000`. Derived with `BigInt`,
51
+ * which has no such rounding, rather than hard-coded, so it can never drift
52
+ * from {@link BUNDLE_NUMBER_LIMIT}.
53
+ */
54
+ export const BUNDLE_NUMBER_LIMIT_DECIMAL = (2n ** 63n).toString();
55
+
56
+ /**
57
+ * Whether `value` satisfies the domain every bundle number must:
58
+ * `typeof value === 'number'`, finite, and `|value| < BUNDLE_NUMBER_LIMIT`.
59
+ * Takes `unknown`, like `Number.isFinite`'s own signature in this codebase's
60
+ * lib target, so a caller need not narrow first.
61
+ */
62
+ export function isWithinBundleNumberLimit(value: unknown): boolean {
63
+ return (
64
+ typeof value === 'number' &&
65
+ Number.isFinite(value) &&
66
+ Math.abs(value) < BUNDLE_NUMBER_LIMIT
67
+ );
68
+ }
69
+
70
+ /** A short, human-legible name for a rejected value's type. */
71
+ function describeType(value: unknown): string {
72
+ if (value === null) return 'null';
73
+ if (value === undefined) return 'undefined';
74
+ if (Array.isArray(value)) return 'array';
75
+ if (typeof value === 'object') {
76
+ if (value instanceof Date) return 'Date';
77
+ if (value instanceof Map) return 'Map';
78
+ if (value instanceof Set) return 'Set';
79
+ if (ArrayBuffer.isView(value)) {
80
+ return (value as object).constructor?.name ?? 'TypedArray';
81
+ }
82
+ return (value as object).constructor?.name ?? 'object';
83
+ }
84
+ return typeof value;
85
+ }
86
+
87
+ /**
88
+ * A plain object: its prototype is `Object.prototype` or `null`. Excludes
89
+ * arrays (their own branch), `Date`, `Map`, `Set`, typed arrays and class
90
+ * instances, none of which either SDK's JSON writer round-trips faithfully.
91
+ */
92
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
93
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
94
+ return false;
95
+ }
96
+ const proto: unknown = Object.getPrototypeOf(value);
97
+ return proto === Object.prototype || proto === null;
98
+ }
99
+
100
+ /** One rejected value, at `keyPath`, as a `TypeError` naming what it actually was. */
101
+ function rejectValue(keyPath: string, value: unknown): never {
102
+ throw new TypeError(
103
+ `${keyPath} must be a plain object, an array, a string, a finite number, ` +
104
+ `a boolean or null; got ${describeType(value)}`,
105
+ );
106
+ }
107
+
108
+ function copyValue(
109
+ value: unknown,
110
+ keyPath: string,
111
+ depth: number,
112
+ ancestors: Set<object>,
113
+ ): unknown {
114
+ if (value === null) return null;
115
+ const kind = typeof value;
116
+ if (kind === 'string' || kind === 'boolean') return value;
117
+ if (kind === 'number') {
118
+ // Never echo the rejected value: `String`/template-literal conversion of
119
+ // a number this size rounds -- see {@link BUNDLE_NUMBER_LIMIT_DECIMAL}.
120
+ // The path is still named.
121
+ if (!Number.isFinite(value)) {
122
+ throw new RangeError(`${keyPath} must be a finite number`);
123
+ }
124
+ if (!isWithinBundleNumberLimit(value)) {
125
+ throw new RangeError(
126
+ `${keyPath} must be smaller than 2^63 (${BUNDLE_NUMBER_LIMIT_DECIMAL}) in magnitude`,
127
+ );
128
+ }
129
+ return value;
130
+ }
131
+ if (kind === 'object') {
132
+ if (Array.isArray(value)) {
133
+ return copyArray(value, keyPath, depth, ancestors);
134
+ }
135
+ if (isPlainObject(value)) {
136
+ return copyObject(value, keyPath, depth, ancestors);
137
+ }
138
+ }
139
+ return rejectValue(keyPath, value);
140
+ }
141
+
142
+ function copyObject(
143
+ obj: Record<string, unknown>,
144
+ keyPath: string,
145
+ depth: number,
146
+ ancestors: Set<object>,
147
+ ): Record<string, unknown> {
148
+ if (depth > EVENT_PARAMS_MAX_DEPTH) {
149
+ throw new RangeError(
150
+ `${keyPath} nests deeper than the maximum of ${EVENT_PARAMS_MAX_DEPTH}`,
151
+ );
152
+ }
153
+ if (ancestors.has(obj)) {
154
+ throw new TypeError(`${keyPath} is a cycle: it contains itself`);
155
+ }
156
+ ancestors.add(obj);
157
+ try {
158
+ // No prototype, so every key is kept as an own key -- "__proto__"
159
+ // included. On a plain `{}` that assignment hits Object.prototype's
160
+ // setter instead of creating an own property, and the key silently
161
+ // vanishes from the copy (and from the JSON text it is later encoded
162
+ // into) rather than being rejected or kept.
163
+ const result: Record<string, unknown> = Object.create(null);
164
+ for (const key of Object.keys(obj)) {
165
+ const value = obj[key];
166
+ // Omitted, as JSON.stringify does -- not an error. An array element
167
+ // gets no such pass, since an array has no key to drop.
168
+ if (value === undefined) continue;
169
+ result[key] = copyValue(value, `${keyPath}.${key}`, depth + 1, ancestors);
170
+ }
171
+ return result;
172
+ } finally {
173
+ ancestors.delete(obj);
174
+ }
175
+ }
176
+
177
+ function copyArray(
178
+ arr: readonly unknown[],
179
+ keyPath: string,
180
+ depth: number,
181
+ ancestors: Set<object>,
182
+ ): unknown[] {
183
+ if (depth > EVENT_PARAMS_MAX_DEPTH) {
184
+ throw new RangeError(
185
+ `${keyPath} nests deeper than the maximum of ${EVENT_PARAMS_MAX_DEPTH}`,
186
+ );
187
+ }
188
+ if (ancestors.has(arr as object)) {
189
+ throw new TypeError(`${keyPath} is a cycle: it contains itself`);
190
+ }
191
+ ancestors.add(arr as object);
192
+ try {
193
+ const result: unknown[] = [];
194
+ for (let i = 0; i < arr.length; i += 1) {
195
+ const value = arr[i];
196
+ if (value === undefined) {
197
+ throw new TypeError(`${keyPath}[${i}] must not be undefined`);
198
+ }
199
+ result.push(copyValue(value, `${keyPath}[${i}]`, depth + 1, ancestors));
200
+ }
201
+ return result;
202
+ } finally {
203
+ ancestors.delete(arr as object);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Validates `params` against the accepted value domain and returns a fresh
209
+ * plain copy, with `undefined` object members omitted.
210
+ *
211
+ * Throws `TypeError` for a value of the wrong type (naming its path, e.g.
212
+ * `params.a.b[1]`) and `RangeError` for a non-finite number or nesting past
213
+ * {@link EVENT_PARAMS_MAX_DEPTH}. The copy means a caller mutating its
214
+ * original object afterwards cannot change what already crossed.
215
+ */
216
+ export function copyEventParams(params: EventParams): Record<string, unknown> {
217
+ if (!isPlainObject(params)) {
218
+ throw new TypeError(
219
+ `Bugsee.event requires params to be a plain object, got ${describeType(params)}`,
220
+ );
221
+ }
222
+ return copyObject(params, 'params', 1, new Set());
223
+ }
224
+
225
+ /** Validates an event or trace name: a non-empty string. */
226
+ export function assertEventOrTraceName(
227
+ kind: 'event' | 'trace',
228
+ name: unknown,
229
+ ): asserts name is string {
230
+ if (typeof name !== 'string') {
231
+ throw new TypeError(
232
+ `Bugsee.${kind} requires name to be a string, got ${describeType(name)}`,
233
+ );
234
+ }
235
+ if (name.length === 0) {
236
+ throw new RangeError(`Bugsee.${kind} requires a non-empty name`);
237
+ }
238
+ }
239
+
240
+ /** Validates a trace value: a string, a finite number or a boolean. */
241
+ export function assertTraceValue(value: unknown): asserts value is TraceValue {
242
+ const kind = typeof value;
243
+ if (kind === 'string' || kind === 'boolean') return;
244
+ if (kind === 'number') {
245
+ // Never echo the rejected value -- see {@link BUNDLE_NUMBER_LIMIT_DECIMAL}.
246
+ if (!Number.isFinite(value)) {
247
+ throw new RangeError(`Bugsee.trace requires a finite number`);
248
+ }
249
+ if (!isWithinBundleNumberLimit(value)) {
250
+ throw new RangeError(
251
+ `Bugsee.trace requires a number smaller than 2^63 (${BUNDLE_NUMBER_LIMIT_DECIMAL}) in magnitude`,
252
+ );
253
+ }
254
+ return;
255
+ }
256
+ throw new TypeError(
257
+ `Bugsee.trace requires a string, a finite number or a boolean, got ${describeType(value)}`,
258
+ );
259
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * What a package log line may say about something thrown: an `Error`'s class
3
+ * name, or the type of anything else. Never its message or stack -- those are
4
+ * whatever the throwing code put there (an app callback's own text, a value),
5
+ * and the SDK captures console output into the report it uploads.
6
+ *
7
+ * Never throws. It runs inside the catch blocks that keep one failure from
8
+ * reaching the rest (the secure measure loop, the report dispatcher, the
9
+ * view-tree reply), and the thrown value is the app's: a `name` getter can
10
+ * throw, and so can `instanceof` on a Proxy whose `getPrototypeOf` trap
11
+ * throws. The first reads as `'Error'`, the second as the value's type. (The same guard
12
+ * as `exceptions/payload.ts`'s `safeIsError`/`safeGetString`.)
13
+ */
14
+ export function errorName(error: unknown): string {
15
+ if (!isError(error)) {
16
+ return error === null ? 'null' : typeof error;
17
+ }
18
+ try {
19
+ const name: unknown = error.name;
20
+ return typeof name === 'string' && name !== '' ? name : 'Error';
21
+ } catch {
22
+ return 'Error';
23
+ }
24
+ }
25
+
26
+ function isError(value: unknown): value is Error {
27
+ try {
28
+ return value instanceof Error;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }