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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,342 @@
1
+ /**
2
+ * What drives each native `Animated.Value`, as far as JS can know it.
3
+ *
4
+ * Natively, a value moves by an animation (which JS starts, and which hands
5
+ * JS its end value) or by a native event attached to it (a scroll, a
6
+ * gesture), whose values JS never sees. React Native attaches native events
7
+ * two ways: an `Animated` component attaches the `Animated.event`s in its
8
+ * props through `AnimatedEvent.__attach`, and `Animated.attachNativeEvent`
9
+ * attaches a mapping directly (React Native's own ScrollView does, for its
10
+ * sticky headers). Both are followed here, from when the package is first
11
+ * imported (`followEvents.ts`, imported for its effect by the package entry),
12
+ * and so is every value being made native (`AnimatedValue.__makeNative`).
13
+ *
14
+ * A native value is then one of:
15
+ * - driven by events: some are attached to it now (`eventsOn`), and it is
16
+ * wherever they take it;
17
+ * - known: made native while followed (or seen animating) and no event is
18
+ * attached now: only animations move it, and JS has where they leave it;
19
+ * - unknown: neither (made native before the package was imported, or its
20
+ * last event detached), or nothing can be followed (React Native moved
21
+ * these internals, or an attachment could not be read): anything may
22
+ * drive it.
23
+ *
24
+ * Patching is global and done once: each object patched carries this state
25
+ * under a symbol (not enumerable), so a second copy of this module (Fast
26
+ * Refresh, two copies of the package) shares it rather than wrapping again.
27
+ * An app that never renders a `<BugseeSecure>` pays a few map updates per
28
+ * attach and detach, and nothing else.
29
+ */
30
+
31
+ /** A native event attached to a value: the view, the event's name, where in the event the value is. */
32
+ export interface Attachment {
33
+ readonly view: unknown;
34
+ readonly event: unknown;
35
+ /** From the event's first argument: `['nativeEvent', 'contentOffset', 'y']`. */
36
+ readonly path: readonly string[];
37
+ }
38
+
39
+ /** An attachment with the value it drives. */
40
+ type Attached = Attachment & { readonly value: object };
41
+
42
+ interface DriverState {
43
+ /** The events attached to each value now (one entry per attachment). */
44
+ readonly attached: WeakMap<object, Attached[]>;
45
+ /** Per `AnimatedEvent`, the attachments of each `__attach` still in place, oldest first. */
46
+ readonly events: WeakMap<object, Attached[][]>;
47
+ /** Values made native while followed, or seen animating, with no event since: only animations move them. */
48
+ readonly known: WeakSet<object>;
49
+ /** Called the moment JS moves a value, or makes it native, by value. */
50
+ readonly onMove: WeakMap<object, Set<() => void>>;
51
+ /** An attachment could not be read: which values it drives is not known. */
52
+ lost: boolean;
53
+ }
54
+
55
+ /** Where the state is kept on every object patched, and on every function that wraps one. */
56
+ // Stryker disable next-line StringLiteral -- any key nothing else uses
57
+ const KEY = Symbol.for('@bugsee/react-native/secure-drivers');
58
+
59
+ /** The state, while everything is followed; `null`: nothing can be trusted. */
60
+ let drivers: DriverState | null = null;
61
+
62
+ /** How deep in an event's mapping its values are looked for (`{ nativeEvent: { contentOffset: { y } } }`). */
63
+ const MAPPING_DEPTH = 8;
64
+
65
+ /** Anything with React Native's `Animated` node interface. */
66
+ export function isNode(value: unknown): value is { __getValue: () => unknown; [field: string]: unknown } {
67
+ return typeof (value as { __getValue?: unknown } | null | undefined)?.__getValue === 'function';
68
+ }
69
+
70
+ /**
71
+ * The `Animated.Value`s in an event's mapping, with where each is (an
72
+ * `Animated.ValueXY`'s two at `x` and `y`), as React Native maps them.
73
+ */
74
+ function attachmentsIn(mapping: unknown, view: unknown, event: unknown): Attached[] {
75
+ const found: Attached[] = [];
76
+ const visit = (at: unknown, path: string[]): void => {
77
+ if (at === null || typeof at !== 'object' || path.length > MAPPING_DEPTH) {
78
+ return;
79
+ }
80
+ if (isNode(at)) {
81
+ if ('_value' in at) {
82
+ found.push({ value: at, view, event, path });
83
+ } else {
84
+ visit(at.x, [...path, 'x']);
85
+ visit(at.y, [...path, 'y']);
86
+ }
87
+ return;
88
+ }
89
+ for (const [key, inner] of Object.entries(at)) {
90
+ visit(inner, [...path, key]);
91
+ }
92
+ };
93
+ visit(mapping, []);
94
+ return found;
95
+ }
96
+
97
+ function add(state: DriverState, attachments: readonly Attached[]): void {
98
+ for (const attachment of attachments) {
99
+ state.attached.set(attachment.value, [...(state.attached.get(attachment.value) ?? []), attachment]);
100
+ state.known.delete(attachment.value);
101
+ }
102
+ // Counted only now: a view woken as React Native made the value native (inside the attach) took it as still.
103
+ for (const attachment of attachments) {
104
+ moved(state, attachment.value);
105
+ }
106
+ }
107
+
108
+ function remove(state: DriverState, attachments: readonly Attached[]): void {
109
+ for (const attachment of attachments) {
110
+ // Each attachment is removed once, after it was added.
111
+ const left = (state.attached.get(attachment.value) as Attached[]).filter((each) => each !== attachment);
112
+ state.attached.set(attachment.value, left);
113
+ if (left.length === 0) {
114
+ // Where the last event left it, JS may not know (whatever JS set while it was attached): it stays unknown
115
+ // until JS next animates or sets it.
116
+ state.known.delete(attachment.value);
117
+ }
118
+ }
119
+ }
120
+
121
+ /** Reads an attachment's values; one that cannot be read loses track of every value. */
122
+ function read(state: DriverState, mapping: () => unknown, view: unknown, event: unknown): Attached[] {
123
+ try {
124
+ return attachmentsIn(mapping(), view, event);
125
+ } catch {
126
+ state.lost = true;
127
+ return [];
128
+ }
129
+ }
130
+
131
+ type Method = (this: unknown, ...args: unknown[]) => unknown;
132
+
133
+ function mark<T extends object>(target: T, state: DriverState): T {
134
+ // Not enumerable (the default): spreading the object copies no state.
135
+ Object.defineProperty(target, KEY, { value: state });
136
+ return target;
137
+ }
138
+
139
+ function stateOn(target: object | undefined): DriverState | undefined {
140
+ return (target as { [KEY]?: DriverState } | undefined)?.[KEY];
141
+ }
142
+
143
+ function wrapEvents(prototype: Record<string, unknown>, state: DriverState): void {
144
+ const attach = prototype.__attach as Method;
145
+ const detach = prototype.__detach as Method;
146
+ prototype.__attach = mark(function (this: { _argMapping?: unknown }, ...args: unknown[]) {
147
+ const result = attach.apply(this, args);
148
+ const attachments = read(state, () => (this._argMapping as unknown[] | undefined)?.[0], args[0], args[1]);
149
+ add(state, attachments);
150
+ state.events.set(this, [...(state.events.get(this) ?? []), attachments]);
151
+ return result;
152
+ }, state);
153
+ prototype.__detach = mark(function (this: object, ...args: unknown[]) {
154
+ // Detached with nothing attached: nothing to count. (A string in either list counts no object.)
155
+ // Stryker disable next-line ArrayDeclaration
156
+ const [attachments = [], ...rest] = state.events.get(this) ?? [];
157
+ state.events.set(this, rest);
158
+ remove(state, attachments);
159
+ return detach.apply(this, args);
160
+ }, state);
161
+ mark(prototype, state);
162
+ }
163
+
164
+ function wrapAttach(target: Record<string, unknown>, state: DriverState): void {
165
+ const attachNativeEvent = target.attachNativeEvent as Method;
166
+ target.attachNativeEvent = mark(function (this: unknown, ...args: unknown[]) {
167
+ const handle = attachNativeEvent.apply(this, args) as { detach?: unknown } | null | undefined;
168
+ const attachments = read(state, () => (args[2] as unknown[] | null | undefined)?.[0], args[0], args[1]);
169
+ add(state, attachments);
170
+ // A handle that cannot be wrapped keeps them counted for good: covered, never trusted.
171
+ try {
172
+ const detach = (handle as { detach: Method }).detach;
173
+ (handle as { detach: Method }).detach = function (this: unknown, ...rest: unknown[]) {
174
+ // Detached again: its attachments are gone already, and removing them again removes nothing.
175
+ remove(state, attachments);
176
+ return detach.apply(this, rest);
177
+ };
178
+ } catch {
179
+ // Kept counted.
180
+ }
181
+ return handle;
182
+ }, state);
183
+ mark(target, state);
184
+ }
185
+
186
+ /** Wakes what watches `value`, at once: before React Native hands the change to the UI thread. */
187
+ function moved(state: DriverState, value: object): void {
188
+ const wakes = state.onMove.get(value);
189
+ if (wakes === undefined) {
190
+ return;
191
+ }
192
+ // A snapshot: a watcher may stop watching, or watch again, as it is woken.
193
+ for (const wake of [...wakes]) {
194
+ try {
195
+ wake();
196
+ } catch {
197
+ // A watcher's failure is its own; React Native's animation goes on.
198
+ }
199
+ }
200
+ }
201
+
202
+ /**
203
+ * The `AnimatedValue` methods by which JS moves a value natively: starting an
204
+ * animation, setting or resetting it, changing its offset. Each is followed
205
+ * where React Native has it.
206
+ */
207
+ const MOVES = ['animate', 'setValue', 'resetAnimation', 'setOffset', 'flattenOffset', 'extractOffset'];
208
+
209
+ function wrapNative(prototype: Record<string, unknown>, state: DriverState): void {
210
+ const makeNative = prototype.__makeNative as Method;
211
+ prototype.__makeNative = mark(function (this: { __isNative?: unknown }, ...args: unknown[]) {
212
+ const becoming = this.__isNative !== true;
213
+ const result = makeNative.apply(this, args);
214
+ if (becoming) {
215
+ state.known.add(this);
216
+ moved(state, this);
217
+ }
218
+ return result;
219
+ }, state);
220
+ for (const name of MOVES.filter((each) => typeof prototype[each] === 'function')) {
221
+ const move = prototype[name] as Method;
222
+ prototype[name] = mark(function (this: object, ...args: unknown[]) {
223
+ const result = move.apply(this, args);
224
+ // Set from JS: where it is now, JS has. (An event attached to it still moves it, and is told first.)
225
+ state.known.add(this);
226
+ moved(state, this);
227
+ return result;
228
+ }, state);
229
+ }
230
+ mark(prototype, state);
231
+ }
232
+
233
+ /** What React Native has to follow; each from its own module. */
234
+ export interface DriverSources {
235
+ /** The `AnimatedEvent` class. */
236
+ readonly eventClass: unknown;
237
+ /** `AnimatedImplementation`: what ScrollView calls `attachNativeEvent` on. */
238
+ readonly implementation: unknown;
239
+ /** The public `Animated` object (a copy of `AnimatedImplementation`'s fields), where it can be loaded. */
240
+ readonly exported?: unknown;
241
+ /** The `AnimatedValue` class. */
242
+ readonly valueClass: unknown;
243
+ }
244
+
245
+ function prototypeOf(type: unknown): unknown {
246
+ return (type as { prototype?: unknown } | null | undefined)?.prototype;
247
+ }
248
+
249
+ function withMethods(target: unknown, ...names: string[]): Record<string, unknown> | undefined {
250
+ const record = target as Record<string, unknown> | null | undefined;
251
+ return record != null && names.every((name) => typeof record[name] === 'function') ? record : undefined;
252
+ }
253
+
254
+ /**
255
+ * Follows what drives native values from now on, through `sources`; once
256
+ * per object, sharing the state any earlier copy of this module set up.
257
+ * Anything missing follows nothing: no still native value is trusted.
258
+ * Returns whether everything is followed.
259
+ */
260
+ export function followDrivers(sources: DriverSources): boolean {
261
+ const events = withMethods(prototypeOf(sources.eventClass), '__attach', '__detach');
262
+ const values = withMethods(prototypeOf(sources.valueClass), '__makeNative');
263
+ const implementation = withMethods(sources.implementation, 'attachNativeEvent');
264
+ if (events === undefined || values === undefined || implementation === undefined) {
265
+ drivers = null;
266
+ return false;
267
+ }
268
+ const exported = withMethods(sources.exported, 'attachNativeEvent');
269
+ const state = [events, values, implementation, exported].map(stateOn).find((found) => found !== undefined) ?? {
270
+ attached: new WeakMap(),
271
+ events: new WeakMap(),
272
+ known: new WeakSet(),
273
+ onMove: new WeakMap(),
274
+ lost: false,
275
+ };
276
+ if (stateOn(events) === undefined) {
277
+ wrapEvents(events, state);
278
+ }
279
+ if (stateOn(values) === undefined) {
280
+ wrapNative(values, state);
281
+ }
282
+ for (const target of [implementation, exported]) {
283
+ // Once per object: a function set over the wrapper since (an app's own, calling ours) is not wrapped again.
284
+ // The public object may hold the wrapper already, spread from `AnimatedImplementation` once it was wrapped.
285
+ const unwrapped = target !== undefined && stateOn(target.attachNativeEvent as object) === undefined;
286
+ if (unwrapped && stateOn(target) === undefined) {
287
+ wrapAttach(target, state);
288
+ }
289
+ }
290
+ drivers = state;
291
+ return true;
292
+ }
293
+
294
+ /** Stops following (nothing is trusted from then on); for tests. */
295
+ export function forgetDrivers(): void {
296
+ drivers = null;
297
+ }
298
+
299
+ /**
300
+ * The native events attached to `node` now (none: an empty list), or
301
+ * `undefined` when that cannot be known.
302
+ */
303
+ export function eventsOn(node: object): readonly Attachment[] | undefined {
304
+ if (drivers === null || drivers.lost) {
305
+ return undefined;
306
+ }
307
+ return drivers.attached.get(node) ?? [];
308
+ }
309
+
310
+ /** Whether only animations have moved `node` since it was made native, as far as followed. */
311
+ export function knownDriven(node: object): boolean {
312
+ return drivers?.known.has(node) === true;
313
+ }
314
+
315
+ /** `node` is seen animating: from now on, only animations move it until an event is attached. */
316
+ export function noteAnimating(node: object): void {
317
+ drivers?.known.add(node);
318
+ }
319
+
320
+ /**
321
+ * Calls `wake` the moment JS moves `node` (starts an animation on it, sets,
322
+ * resets or offsets it) or makes it native (its first animation or event
323
+ * with the native driver, which commits nothing), synchronously, until the
324
+ * returned function is called; `undefined` when that is not followed.
325
+ */
326
+ export function whenMoved(node: object, wake: () => void): (() => void) | undefined {
327
+ const state = drivers;
328
+ if (state === null) {
329
+ return undefined;
330
+ }
331
+ let wakes = state.onMove.get(node);
332
+ if (wakes === undefined) {
333
+ wakes = new Set();
334
+ state.onMove.set(node, wakes);
335
+ }
336
+ const subscription = (): void => wake();
337
+ wakes.add(subscription);
338
+ const from = wakes;
339
+ return () => {
340
+ from.delete(subscription);
341
+ };
342
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Starts following what drives native `Animated` values (`drivers.ts`) as
3
+ * soon as it is evaluated. The package entry imports it for its effect alone,
4
+ * which Metro's `inlineRequires` leaves eager from the entry's first
5
+ * evaluation: with `inlineRequires`, that is the app's first use of
6
+ * `@bugsee/react-native` (import it, or call `Bugsee.launch`, at the top of
7
+ * `index.js` to follow from the start). An event attached by a screen that
8
+ * mounts before then is not seen; the value it drives was made native
9
+ * unfollowed, so it is not trusted until JS next animates or sets it.
10
+ *
11
+ * React Native's own modules, where an app has them; anywhere they cannot be
12
+ * loaded (a test environment, or React Native moved them), nothing is
13
+ * followed, and no still native value is trusted.
14
+ *
15
+ * Each `require` has a literal path (Metro bundles nothing else) and sits
16
+ * directly in a `try` block: Metro then takes it as an optional dependency
17
+ * (`allowOptionalDependencies`, on by default in React Native's and Expo's
18
+ * Metro configs), so a file a future React Native moved builds into the
19
+ * bundle as a `require` that throws at startup, caught here, rather than
20
+ * failing the build. An app that turns optional dependencies off would fail
21
+ * its build instead; `scripts/check-rn-compat.sh` guards the four paths on
22
+ * every supported React Native first.
23
+ */
24
+ /* eslint-disable @typescript-eslint/no-require-imports -- React Native's internals, where they are */
25
+ import { followDrivers } from './drivers';
26
+
27
+ type Module = Record<string, unknown>;
28
+
29
+ // An empty catch leaves that source missing, which follows nothing.
30
+ // Stryker disable all
31
+ let eventClass: unknown;
32
+ try {
33
+ eventClass = (require('react-native/Libraries/Animated/AnimatedEvent') as Module).AnimatedEvent;
34
+ } catch {
35
+ // Not there: nothing followed.
36
+ }
37
+ let implementation: unknown;
38
+ try {
39
+ implementation = (require('react-native/Libraries/Animated/AnimatedImplementation') as Module).default;
40
+ } catch {
41
+ // As above.
42
+ }
43
+ let exported: unknown;
44
+ try {
45
+ exported = (require('react-native/Libraries/Animated/Animated') as Module).default;
46
+ } catch {
47
+ // As above.
48
+ }
49
+ let valueClass: unknown;
50
+ try {
51
+ valueClass = (require('react-native/Libraries/Animated/nodes/AnimatedValue') as Module).default;
52
+ } catch {
53
+ // As above.
54
+ }
55
+
56
+ followDrivers({ eventClass, implementation, exported, valueClass });
57
+ // Stryker restore all
@@ -0,0 +1,99 @@
1
+ import type { WindowRect } from '../viewtree/fiber';
2
+
3
+ /**
4
+ * How long a `<BugseeSecure>` keeps covering what it covered before it shrank,
5
+ * moved or was hidden.
6
+ *
7
+ * `measureInWindow` and committed props describe the shadow tree; native
8
+ * draws it a frame or more later, and a LayoutAnimation (`configureNext`, as
9
+ * KeyboardAvoidingView uses, about 250 ms) only reaches its end state at the
10
+ * end of the animation. Coverage taken away on shadow-tree evidence alone
11
+ * could uncover a field native still draws where it was. So coverage is
12
+ * added at once and removed late: what a view covered stays published for
13
+ * this long after it stopped covering it, and a hidden view withdraws only
14
+ * once it has been hidden this long without a break.
15
+ *
16
+ * What is held is what the view covered, not the path between: a native
17
+ * animation that carries the view further than its own size in one step
18
+ * draws positions neither the old nor the new rectangle covers. Main, which
19
+ * publishes only where the view is now, covers them no better.
20
+ */
21
+ export const SECURE_SHRINK_HOLD_MS = 500;
22
+
23
+ /** The width of one hold window: what leaves within one is held as one box. */
24
+ const WINDOW_MS = 100;
25
+
26
+ interface Held {
27
+ /** The window this box collects what left during. */
28
+ readonly window: number;
29
+ left: number;
30
+ top: number;
31
+ right: number;
32
+ bottom: number;
33
+ }
34
+
35
+ /**
36
+ * One instance's coverage over time: the rectangle it covers now, and, per
37
+ * {@link WINDOW_MS} window of the last {@link SECURE_SHRINK_HOLD_MS}, the
38
+ * bounding box of what it stopped covering then. At most a handful of
39
+ * boxes, however much the view moves.
40
+ */
41
+ export class CoverageHold {
42
+ private current: WindowRect | null = null;
43
+ private held: Held[] = [];
44
+
45
+ /**
46
+ * Sets what the view covers now (`null`: nothing, hidden or cut away) and
47
+ * returns everything to publish: the current rectangle and every held box.
48
+ */
49
+ update(visible: WindowRect | null, now: number): WindowRect[] {
50
+ const previous = this.current;
51
+ if (previous !== null && !sameRect(previous, visible)) {
52
+ this.hold(previous, now);
53
+ }
54
+ this.current = visible;
55
+ return this.publishable(now);
56
+ }
57
+
58
+ /** What to publish now, after dropping what has been held long enough. */
59
+ publishable(now: number): WindowRect[] {
60
+ this.held = this.held.filter((box) => (box.window + 1) * WINDOW_MS + SECURE_SHRINK_HOLD_MS > now);
61
+ const out = this.held.map(({ left, top, right, bottom }) => ({
62
+ x: left,
63
+ y: top,
64
+ width: right - left,
65
+ height: bottom - top,
66
+ }));
67
+ return this.current === null ? out : [this.current, ...out];
68
+ }
69
+
70
+ /** Whether anything is still held: what is published will change on its own. */
71
+ holding(): boolean {
72
+ return this.held.length > 0;
73
+ }
74
+
75
+ /** Forgets everything, as unmounting or disabling does. */
76
+ clear(): void {
77
+ this.current = null;
78
+ this.held = [];
79
+ }
80
+
81
+ private hold(rect: WindowRect, now: number): void {
82
+ const window = Math.floor(now / WINDOW_MS);
83
+ const last = this.held[this.held.length - 1];
84
+ const right = rect.x + rect.width;
85
+ const bottom = rect.y + rect.height;
86
+ if (last !== undefined && last.window === window) {
87
+ last.left = Math.min(last.left, rect.x);
88
+ last.top = Math.min(last.top, rect.y);
89
+ last.right = Math.max(last.right, right);
90
+ last.bottom = Math.max(last.bottom, bottom);
91
+ return;
92
+ }
93
+ this.held.push({ window, left: rect.x, top: rect.y, right, bottom });
94
+ }
95
+ }
96
+
97
+ function sameRect(a: WindowRect, b: WindowRect | null): boolean {
98
+ return b !== null && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
99
+ }