@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,344 @@
1
+ #import "BGSRNConsoleCapture.h"
2
+
3
+ #import <Bugsee/Bugsee.h>
4
+ #import <React/RCTLog.h>
5
+
6
+ #if __has_include(<BugseeRNSupport/BGSRNWrapperChannelHolder.h>)
7
+ #import <BugseeRNSupport/BGSRNWrapperChannelHolder.h>
8
+ #else
9
+ #import "BGSRNWrapperChannelHolder.h"
10
+ #endif
11
+
12
+ static NSString *const BGSRNConsoleCaptureKey = @"bugsee.rn.consoleCapture";
13
+
14
+ /**
15
+ * RCTLog's levels are not Bugsee's. trace → Debug (4), info → Info (3),
16
+ * warn → Warning (2), error and fatal → Error (1). The JS patch's own
17
+ * table (error 1, warn 2, log/info 3, debug 4) is unchanged; this is only
18
+ * the native stream.
19
+ */
20
+ static NSInteger BGSRNWireLevelForRCTLogLevel(RCTLogLevel level) {
21
+ switch (level) {
22
+ case RCTLogLevelTrace:
23
+ return 4;
24
+ case RCTLogLevelInfo:
25
+ return 3;
26
+ case RCTLogLevelWarning:
27
+ return 2;
28
+ case RCTLogLevelError:
29
+ case RCTLogLevelFatal:
30
+ return 1;
31
+ default:
32
+ return 3;
33
+ }
34
+ }
35
+
36
+ /// Explicit false turns console capture off. Absent means on, the SDK default.
37
+ static BOOL BGSRNConsoleCaptureEnabled(void) {
38
+ NSDictionary *options = [Bugsee getLaunchOptions];
39
+ id value = options[@"com.bugsee.option.capture.logs"];
40
+ if (![value isKindOfClass:[NSNumber class]]) {
41
+ return YES;
42
+ }
43
+ return [value boolValue];
44
+ }
45
+
46
+ static const NSTimeInterval BGSRNEchoWindowSeconds = 2.0;
47
+ static const NSUInteger BGSRNEchoNoteCap = 32;
48
+
49
+ /// Stdout and stderr. The console echo of `console.log` arrives on one of
50
+ /// these. A Custom line, including `Bugsee.log` and a native RCTLog forwarded
51
+ /// by this hook, does not.
52
+ static const NSInteger BGSRNLogSourceStdOut = 1;
53
+ static const NSInteger BGSRNLogSourceStdErr = 2;
54
+
55
+ /// Set only around the wrapper channel's own logMessage. The filter runs on
56
+ /// that same thread, so this call is the channel line. Keeping it ends the
57
+ /// equal-text claim. It does not consume the one-shot stdio echo.
58
+ static __thread int BGSRNChannelDepth;
59
+
60
+ @interface BGSRNEchoNote : NSObject
61
+ @property (nonatomic, copy) NSString *text;
62
+ @property (nonatomic, assign) NSTimeInterval expires;
63
+ /// Equal-text claim. Cleared when the channel line is kept. Not a drop of a
64
+ /// later Custom line.
65
+ @property (nonatomic, assign) BOOL exact;
66
+ /// One stderr stamp of `text`. Independent of `exact`.
67
+ @property (nonatomic, assign) BOOL stamp;
68
+ /// One raw stdout or stderr line of `text`. Independent of `exact`.
69
+ @property (nonatomic, assign) BOOL stdio;
70
+ @end
71
+
72
+ @implementation BGSRNEchoNote
73
+ @end
74
+
75
+ static NSMutableArray<BGSRNEchoNote *> *BGSRNEchoNotes;
76
+
77
+ static id BGSRNEchoLock(void) {
78
+ static id lock;
79
+ static dispatch_once_t onceToken;
80
+ dispatch_once(&onceToken, ^{
81
+ lock = [NSObject new];
82
+ BGSRNEchoNotes = [NSMutableArray array];
83
+ });
84
+ return lock;
85
+ }
86
+
87
+ static BOOL BGSRNIsConsoleStamp(NSString *line, NSString *message) {
88
+ if (message.length == 0 || line.length == 0) {
89
+ return NO;
90
+ }
91
+ NSString *tail = [NSString stringWithFormat:@"] %@", message];
92
+ if (![line hasSuffix:tail] || line.length <= tail.length) {
93
+ return NO;
94
+ }
95
+ NSString *head = [line substringToIndex:line.length - tail.length];
96
+ NSRange bracket = [head rangeOfString:@"["];
97
+ if (bracket.location == NSNotFound || bracket.location == 0) {
98
+ return NO;
99
+ }
100
+ NSString *when = [head substringToIndex:bracket.location];
101
+ NSString *pid = [head substringFromIndex:NSMaxRange(bracket)];
102
+ static NSRegularExpression *whenPattern;
103
+ static NSRegularExpression *pidPattern;
104
+ static dispatch_once_t onceToken;
105
+ dispatch_once(&onceToken, ^{
106
+ whenPattern = [NSRegularExpression
107
+ regularExpressionWithPattern:@"^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d+ [^\\s\\[]+$"
108
+ options:0
109
+ error:nil];
110
+ pidPattern = [NSRegularExpression regularExpressionWithPattern:@"^\\d+:\\d+$"
111
+ options:0
112
+ error:nil];
113
+ });
114
+ if (whenPattern == nil || pidPattern == nil) {
115
+ return NO;
116
+ }
117
+ NSRange whenRange = NSMakeRange(0, when.length);
118
+ NSRange pidRange = NSMakeRange(0, pid.length);
119
+ NSTextCheckingResult *whenMatch = [whenPattern firstMatchInString:when options:0 range:whenRange];
120
+ NSTextCheckingResult *pidMatch = [pidPattern firstMatchInString:pid options:0 range:pidRange];
121
+ return whenMatch != nil && whenMatch.range.length == when.length && pidMatch != nil &&
122
+ pidMatch.range.length == pid.length;
123
+ }
124
+
125
+ static void BGSRNPruneEchoNotes(NSTimeInterval now) {
126
+ for (NSInteger index = (NSInteger)BGSRNEchoNotes.count - 1; index >= 0; index--) {
127
+ BGSRNEchoNote *note = BGSRNEchoNotes[(NSUInteger)index];
128
+ if (note.expires <= now || (!note.exact && !note.stamp && !note.stdio)) {
129
+ [BGSRNEchoNotes removeObjectAtIndex:(NSUInteger)index];
130
+ }
131
+ }
132
+ }
133
+
134
+ void BGSRNNoteConsoleEcho(NSString *message) {
135
+ if (message == nil) {
136
+ return;
137
+ }
138
+ @synchronized(BGSRNEchoLock()) {
139
+ BGSRNPruneEchoNotes([NSDate date].timeIntervalSince1970);
140
+ BGSRNEchoNote *note = [BGSRNEchoNote new];
141
+ note.text = message;
142
+ note.expires = [NSDate date].timeIntervalSince1970 + BGSRNEchoWindowSeconds;
143
+ note.exact = YES;
144
+ note.stamp = YES;
145
+ note.stdio = YES;
146
+ [BGSRNEchoNotes addObject:note];
147
+ while (BGSRNEchoNotes.count > BGSRNEchoNoteCap) {
148
+ [BGSRNEchoNotes removeObjectAtIndex:0];
149
+ }
150
+ }
151
+ }
152
+
153
+ void BGSRNBeginChannelLine(NSString *message) {
154
+ if (message == nil) {
155
+ return;
156
+ }
157
+ BGSRNChannelDepth++;
158
+ }
159
+
160
+ void BGSRNEndChannelLine(NSString *message) {
161
+ if (message == nil || BGSRNChannelDepth <= 0) {
162
+ return;
163
+ }
164
+ BGSRNChannelDepth--;
165
+ }
166
+
167
+ static BOOL BGSRNNoteIsSpent(BGSRNEchoNote *note) {
168
+ return !note.exact && !note.stamp && !note.stdio;
169
+ }
170
+
171
+ static BOOL BGSRNIsStdioSource(NSInteger source) {
172
+ return source == BGSRNLogSourceStdOut || source == BGSRNLogSourceStdErr;
173
+ }
174
+
175
+ BOOL BGSRNDropConsoleEcho(NSString *line, NSInteger source) {
176
+ if (line.length == 0) {
177
+ return NO;
178
+ }
179
+ @synchronized(BGSRNEchoLock()) {
180
+ BGSRNPruneEchoNotes([NSDate date].timeIntervalSince1970);
181
+ for (NSInteger index = 0; index < (NSInteger)BGSRNEchoNotes.count; index++) {
182
+ BGSRNEchoNote *note = BGSRNEchoNotes[(NSUInteger)index];
183
+ if (note.stamp && BGSRNIsConsoleStamp(line, note.text)) {
184
+ note.stamp = NO;
185
+ if (BGSRNNoteIsSpent(note)) {
186
+ [BGSRNEchoNotes removeObjectAtIndex:(NSUInteger)index];
187
+ }
188
+ return YES;
189
+ }
190
+ }
191
+ for (NSInteger index = 0; index < (NSInteger)BGSRNEchoNotes.count; index++) {
192
+ BGSRNEchoNote *note = BGSRNEchoNotes[(NSUInteger)index];
193
+ if (![note.text isEqualToString:line]) {
194
+ continue;
195
+ }
196
+ // The channel line. Keeping it ends the equal-text claim. A later
197
+ // Custom line of the same text is not the echo. A stdio line is the
198
+ // echo even when it is filtered on this thread.
199
+ if (BGSRNChannelDepth > 0 && note.exact && !BGSRNIsStdioSource(source)) {
200
+ note.exact = NO;
201
+ if (BGSRNNoteIsSpent(note)) {
202
+ [BGSRNEchoNotes removeObjectAtIndex:(NSUInteger)index];
203
+ }
204
+ return NO;
205
+ }
206
+ if (note.stdio && BGSRNIsStdioSource(source)) {
207
+ note.stdio = NO;
208
+ if (BGSRNNoteIsSpent(note)) {
209
+ [BGSRNEchoNotes removeObjectAtIndex:(NSUInteger)index];
210
+ }
211
+ return YES;
212
+ }
213
+ }
214
+ return NO;
215
+ }
216
+ }
217
+
218
+ /// Native warnings React Native re-logs from JS. In a Debug build
219
+ /// `_RCTLogNativeInternal` also calls `RCTLog.logIfNoNativeHook`, and
220
+ /// LogBox's warning handler passes a `warn` to the `console.warn` it saved
221
+ /// before any patch. That reaches RCTLog a second time, as
222
+ /// `RCTLogSourceJavaScript`, with the same text. This hook does not record
223
+ /// it, but whatever the log function chain writes for it (an app's stderr
224
+ /// mirror, an NSLog) is a second echo of the line already recorded. Each
225
+ /// entry arms one more echo drop when that delivery arrives. Under the echo
226
+ /// lock.
227
+ static NSMutableArray<BGSRNEchoNote *> *BGSRNRelogNotes;
228
+
229
+ static void BGSRNExpectJsRelog(NSString *message) {
230
+ @synchronized(BGSRNEchoLock()) {
231
+ const NSTimeInterval now = [NSDate date].timeIntervalSince1970;
232
+ if (BGSRNRelogNotes == nil) {
233
+ BGSRNRelogNotes = [NSMutableArray array];
234
+ }
235
+ BGSRNEchoNote *note = [BGSRNEchoNote new];
236
+ note.text = message;
237
+ note.expires = now + BGSRNEchoWindowSeconds;
238
+ [BGSRNRelogNotes addObject:note];
239
+ while (BGSRNRelogNotes.count > BGSRNEchoNoteCap) {
240
+ [BGSRNRelogNotes removeObjectAtIndex:0];
241
+ }
242
+ }
243
+ }
244
+
245
+ /// YES once per expected relog of `message`, within the echo window.
246
+ static BOOL BGSRNClaimJsRelog(NSString *message) {
247
+ @synchronized(BGSRNEchoLock()) {
248
+ const NSTimeInterval now = [NSDate date].timeIntervalSince1970;
249
+ for (NSInteger index = (NSInteger)BGSRNRelogNotes.count - 1; index >= 0; index--) {
250
+ if (BGSRNRelogNotes[(NSUInteger)index].expires <= now) {
251
+ [BGSRNRelogNotes removeObjectAtIndex:(NSUInteger)index];
252
+ }
253
+ }
254
+ for (NSUInteger index = 0; index < BGSRNRelogNotes.count; index++) {
255
+ if ([BGSRNRelogNotes[index].text isEqualToString:message]) {
256
+ [BGSRNRelogNotes removeObjectAtIndex:index];
257
+ return YES;
258
+ }
259
+ }
260
+ return NO;
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Runs before the rest of the log function chain, so every echo drop is
266
+ * armed before anything in that chain can write the line where the SDK
267
+ * captures it. Returns YES when this line is to be recorded on the channel
268
+ * after the chain has run.
269
+ *
270
+ * JavaScript source is the console echo. The JS patch forwards that call in
271
+ * dev and in release; recording it here would run the filter twice. Release
272
+ * builds often never produce this source for console.*, and dropping the
273
+ * patch instead of this echo would drop those logs. A JavaScript delivery
274
+ * that is the relog of a native warning arms one more echo drop.
275
+ *
276
+ * A native line is recorded here, once, and its echo drop is armed the way
277
+ * the JS patch arms one for a console call: a stderr stamp and one raw
278
+ * stdout or stderr line of that text.
279
+ */
280
+ static BOOL BGSRNBeginRCTLog(RCTLogLevel level, RCTLogSource source, NSString *message) {
281
+ if (message.length == 0) {
282
+ return NO;
283
+ }
284
+ if (source == RCTLogSourceJavaScript) {
285
+ if (BGSRNClaimJsRelog(message)) {
286
+ BGSRNNoteConsoleEcho(message);
287
+ }
288
+ return NO;
289
+ }
290
+ if (NSThread.currentThread.threadDictionary[BGSRNConsoleCaptureKey] != nil) {
291
+ return NO;
292
+ }
293
+ if (!BGSRNConsoleCaptureEnabled()) {
294
+ return NO;
295
+ }
296
+ BGSRNNoteConsoleEcho(message);
297
+ #if RCT_DEBUG
298
+ if (level == RCTLogLevelWarning) {
299
+ BGSRNExpectJsRelog(message);
300
+ }
301
+ #endif
302
+ return YES;
303
+ }
304
+
305
+ /// Records a native line on the channel, as Custom. The filter runs inside
306
+ /// this call on this thread: that is the channel line, which is kept.
307
+ static void BGSRNForwardRCTLog(RCTLogLevel level, NSString *message) {
308
+ NSMutableDictionary *locals = NSThread.currentThread.threadDictionary;
309
+ locals[BGSRNConsoleCaptureKey] = @YES;
310
+ BGSRNBeginChannelLine(message);
311
+ @try {
312
+ [BGSRNWrapperChannelHolder.shared logMessage:message
313
+ level:BGSRNWireLevelForRCTLogLevel(level)];
314
+ } @finally {
315
+ BGSRNEndChannelLine(message);
316
+ [locals removeObjectForKey:BGSRNConsoleCaptureKey];
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Wraps the current log function rather than appending to it
322
+ * (`RCTAddLogFunction` runs the existing function first): the echo drop of a
323
+ * line must be armed before the existing function writes that line to
324
+ * stderr, or the SDK could capture and filter the echo first.
325
+ */
326
+ void BGSRNInstallConsoleCapture(void) {
327
+ static dispatch_once_t onceToken;
328
+ dispatch_once(&onceToken, ^{
329
+ RCTLogFunction existing = RCTGetLogFunction();
330
+ RCTSetLogFunction(^(RCTLogLevel level,
331
+ RCTLogSource source,
332
+ NSString *fileName,
333
+ NSNumber *lineNumber,
334
+ NSString *message) {
335
+ const BOOL forward = BGSRNBeginRCTLog(level, source, message);
336
+ if (existing != nil) {
337
+ existing(level, source, fileName, lineNumber, message);
338
+ }
339
+ if (forward) {
340
+ BGSRNForwardRCTLog(level, message);
341
+ }
342
+ });
343
+ });
344
+ }
@@ -0,0 +1,25 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <React/RCTInvalidating.h>
3
+ #import <RNBugseeSpec/RNBugseeSpec.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ /// The iOS half of the `Bugsee` TurboModule.
8
+ ///
9
+ /// Every SDK entry point is reached on the main thread. `launchWithToken:`
10
+ /// called from the TurboModule's own queue logs "Incorrect bugsee launch,
11
+ /// please make sure that you run bugsee in main thread!" and does not start
12
+ /// correctly — reproduced on device, not inferred.
13
+ ///
14
+ /// Translation between the JS wire shape and the SDK's types lives in
15
+ /// BugseeRNSupport, which is unit-tested without React Native.
16
+ /// Inherits NativeBugseeSpecBase rather than NSObject because the spec
17
+ /// declares an EventEmitter: codegen puts `emitOnLifecycleEvent:` on that base
18
+ /// class, not on the protocol, so an NSObject subclass conforms to
19
+ /// NativeBugseeSpec and still cannot emit. The compiler says
20
+ /// "no visible @interface ... declares the selector", which points at the call
21
+ /// site rather than at the superclass that is actually wrong.
22
+ @interface BugseeModule : NativeBugseeSpecBase <NativeBugseeSpec, RCTInvalidating>
23
+ @end
24
+
25
+ NS_ASSUME_NONNULL_END