@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,39 @@
1
+ /**
2
+ * The two stable codes an attribute or identity operation can fail with.
3
+ *
4
+ * Stable, and worth stating: an app matches on `.code`, so these strings are
5
+ * part of the public contract, not an implementation detail free to change
6
+ * between releases like an error message is.
7
+ */
8
+ export const AttributeErrorCode = {
9
+ /** JS-side validation rejected the name or value before it crossed the bridge. */
10
+ BadArgument: 'E_ATTRIBUTE_BAD_ARGUMENT',
11
+ /**
12
+ * Native did not keep the value: it was over a size limit (iOS's archived-
13
+ * size limit; the value crossed, but a native read-back afterwards found
14
+ * something else), or dropped for any other reason.
15
+ */
16
+ Rejected: 'E_ATTRIBUTE_REJECTED',
17
+ } as const;
18
+
19
+ export type AttributeErrorCode =
20
+ (typeof AttributeErrorCode)[keyof typeof AttributeErrorCode];
21
+
22
+ /**
23
+ * What every attribute or identity rejection is an instance of, whether it
24
+ * was raised locally (JS validation) or translated from a native rejection
25
+ * that carried one of the codes above.
26
+ */
27
+ export class BugseeAttributeError extends Error {
28
+ readonly code: AttributeErrorCode;
29
+
30
+ constructor(code: AttributeErrorCode, message: string) {
31
+ super(message);
32
+ this.name = 'BugseeAttributeError';
33
+ this.code = code;
34
+ // Restores `instanceof` across the ES5 transpile some consumers still
35
+ // build with -- without it, `Error` subclasses lose their prototype chain
36
+ // and `error instanceof BugseeAttributeError` reads false for a real one.
37
+ Object.setPrototypeOf(this, BugseeAttributeError.prototype);
38
+ }
39
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * The value domain `Bugsee.setAttribute` accepts, and the domain a read can
3
+ * come back as.
4
+ *
5
+ * The domain is the intersection of both native SDKs (design doc Phase 5,
6
+ * "Planner decisions"): `string | number | boolean`. Android also takes
7
+ * `Set<String>`; iOS takes any property-list object. Neither is common to
8
+ * both, so neither is accepted going in -- but a `Set<String>` can come back
9
+ * OUT on Android, as a `string[]`, since `getAllAttributes`/`getAttribute`
10
+ * must still be able to report a value an app (or an older wrapper) set that
11
+ * way.
12
+ */
13
+ import {
14
+ BUNDLE_NUMBER_LIMIT_DECIMAL,
15
+ isWithinBundleNumberLimit,
16
+ } from '../data/validate';
17
+ import { AttributeErrorCode, BugseeAttributeError } from './errors';
18
+
19
+ /** One value `setAttribute` accepts. */
20
+ export type AttributeValue = string | number | boolean;
21
+
22
+ /**
23
+ * One value a read can report. `string[]` only ever comes back for a
24
+ * `Set<String>` Android native code set directly -- `setAttribute` cannot
25
+ * produce one.
26
+ */
27
+ export type AttributeReadValue = string | number | boolean | string[];
28
+
29
+ /** Android's per-value string limit, inclusive, counted in UTF-16 units. */
30
+ export const ATTRIBUTE_STRING_MAX_LENGTH = 1024;
31
+
32
+ function badArgument(message: string): never {
33
+ throw new BugseeAttributeError(AttributeErrorCode.BadArgument, message);
34
+ }
35
+
36
+ /** A short, human-legible name for a rejected value's type. */
37
+ function describeType(value: unknown): string {
38
+ if (value === null) return 'null';
39
+ if (value === undefined) return 'undefined';
40
+ if (Array.isArray(value)) return 'array';
41
+ if (typeof value === 'bigint') return 'bigint';
42
+ if (typeof value === 'object') {
43
+ return (value as object).constructor?.name ?? 'object';
44
+ }
45
+ return typeof value;
46
+ }
47
+
48
+ /** Validates an attribute name: a non-empty string. Throws `BugseeAttributeError`. */
49
+ export function validateAttributeName(name: unknown): string {
50
+ if (typeof name !== 'string' || name.length === 0) {
51
+ badArgument(
52
+ `attribute name must be a non-empty string, got ${describeType(name)}`,
53
+ );
54
+ }
55
+ return name as string;
56
+ }
57
+
58
+ /**
59
+ * Validates an attribute value against the accepted domain. Throws
60
+ * `BugseeAttributeError` code `BadArgument` for anything outside it,
61
+ * including a number failing {@link isWithinBundleNumberLimit} (which also covers
62
+ * `NaN`/`Infinity`/`-Infinity`, all non-finite) or a string over
63
+ * {@link ATTRIBUTE_STRING_MAX_LENGTH} UTF-16 units -- `.length` counts UTF-16
64
+ * units natively, so no surrogate-aware counting is needed here.
65
+ */
66
+ export function validateAttributeValue(value: unknown): AttributeValue {
67
+ if (typeof value === 'string') {
68
+ if (value.length > ATTRIBUTE_STRING_MAX_LENGTH) {
69
+ badArgument(`attribute value must be at most ${ATTRIBUTE_STRING_MAX_LENGTH} UTF-16 units`);
70
+ }
71
+ return value;
72
+ }
73
+ if (typeof value === 'boolean') {
74
+ return value;
75
+ }
76
+ if (typeof value === 'number') {
77
+ if (!isWithinBundleNumberLimit(value)) {
78
+ // Never echo the rejected value -- see
79
+ // {@link BUNDLE_NUMBER_LIMIT_DECIMAL} for why even the bound itself
80
+ // must not be printed via `Number`'s own string conversion.
81
+ badArgument(
82
+ `attribute value must be a finite number smaller than ` +
83
+ `2^63 (${BUNDLE_NUMBER_LIMIT_DECIMAL}) in magnitude`,
84
+ );
85
+ }
86
+ return value;
87
+ }
88
+ badArgument(
89
+ `attribute value must be a string, a number or a boolean, got ${describeType(value)}`,
90
+ );
91
+ }
92
+
93
+ /**
94
+ * `raw` (whatever `getAttribute`'s native `{ value }` member held, or
95
+ * `undefined` for a native `{}`) as an {@link AttributeReadValue}, or
96
+ * `undefined` for anything that is not one -- including a native `{}`, since
97
+ * its absent `value` member is already `undefined` by the time it gets here.
98
+ */
99
+ export function normalizeAttributeReadValue(raw: unknown): AttributeReadValue | undefined {
100
+ if (typeof raw === 'string' || typeof raw === 'number' || typeof raw === 'boolean') {
101
+ return raw;
102
+ }
103
+ if (Array.isArray(raw) && raw.every((item) => typeof item === 'string')) {
104
+ return [...(raw as string[])];
105
+ }
106
+ return undefined;
107
+ }
108
+
109
+ /**
110
+ * `raw` (native `getAllAttributes`'s map, or `{}` for none) as a plain
111
+ * record of {@link AttributeReadValue}s. A member whose value does not
112
+ * normalize is dropped rather than surfaced as something it is not.
113
+ *
114
+ * Built on `Object.create(null)`: an attribute literally named `__proto__`
115
+ * (a legal name on both SDKs) must be kept as an ordinary own key rather
116
+ * than silently vanishing into a plain `{}`'s prototype setter.
117
+ */
118
+ export function normalizeAttributesMap(raw: unknown): Record<string, AttributeReadValue> {
119
+ const result: Record<string, AttributeReadValue> = Object.create(null);
120
+ if (typeof raw !== 'object' || raw === null) {
121
+ return result;
122
+ }
123
+ for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {
124
+ const normalized = normalizeAttributeReadValue(value);
125
+ if (normalized !== undefined) {
126
+ result[key] = normalized;
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+
132
+ /**
133
+ * `raw` (whatever `getUserIdentifier`'s native `{ value }` member held, or
134
+ * `undefined` for a native `{}`) as the identifier, or `undefined` for
135
+ * anything else -- including an empty string, which both SDKs treat as "no
136
+ * identifier" (the ruling: an empty identifier clears, and a read reports it
137
+ * as absent on both platforms).
138
+ */
139
+ export function normalizeIdentifier(raw: unknown): string | undefined {
140
+ return typeof raw === 'string' && raw.length > 0 ? raw : undefined;
141
+ }
142
+
143
+ /** Validates a `setUserIdentifier` argument: a string. Throws `TypeError`, synchronously. */
144
+ export function assertIdentifierString(value: unknown): asserts value is string {
145
+ if (typeof value !== 'string') {
146
+ throw new TypeError(
147
+ `Bugsee.setUserIdentifier requires a string, got ${describeType(value)}`,
148
+ );
149
+ }
150
+ }
@@ -0,0 +1,58 @@
1
+ import NativeBugsee from '../NativeBugsee';
2
+ import { encodeBridgeObject } from '../bridge/json';
3
+ import { copyBreadcrumbData } from './data';
4
+ import { releaseBreadcrumbFilterForAdd, retainBreadcrumbFilterForAdd } from './filter';
5
+ import { isBreadcrumbLevel } from './types';
6
+ import type { Breadcrumb } from './types';
7
+
8
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
9
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
10
+ return false;
11
+ }
12
+ const proto: unknown = Object.getPrototypeOf(value);
13
+ return proto === Object.prototype || proto === null;
14
+ }
15
+
16
+ function requireString(name: string, value: unknown): string {
17
+ if (typeof value !== 'string') {
18
+ const kind = value === null ? 'null' : typeof value;
19
+ throw new TypeError(`Bugsee.addBreadcrumb ${name} must be a string, got ${kind}`);
20
+ }
21
+ return value;
22
+ }
23
+
24
+ /**
25
+ * Records `crumb` through the native exchange factory, which stamps the time.
26
+ * `timestamp` on `crumb` is ignored. `data` omitted or `null` sends no data.
27
+ */
28
+ export function addBreadcrumb(crumb: Breadcrumb): void {
29
+ if (!isPlainObject(crumb)) {
30
+ const kind = crumb === null ? 'null' : Array.isArray(crumb) ? 'array' : typeof crumb;
31
+ throw new TypeError(`Bugsee.addBreadcrumb requires a crumb object, got ${kind}`);
32
+ }
33
+ const category = requireString('category', crumb.category);
34
+ const message = requireString('message', crumb.message);
35
+ const type = requireString('type', crumb.type);
36
+ if (!isBreadcrumbLevel(crumb.level)) {
37
+ // The type only: a level name the app made up is still the app's text.
38
+ const kind = typeof crumb.level;
39
+ throw new TypeError(
40
+ `Bugsee.addBreadcrumb level must be one of debug, info, warning, error, fatal, got ${kind}`,
41
+ );
42
+ }
43
+ const level = crumb.level;
44
+ let dataJson: string | null = null;
45
+ if (crumb.data != null) {
46
+ dataJson = encodeBridgeObject(copyBreadcrumbData(crumb.data));
47
+ }
48
+ const addId = retainBreadcrumbFilterForAdd();
49
+ let emitted = false;
50
+ try {
51
+ emitted =
52
+ NativeBugsee.addBreadcrumb(category, level, message, type, dataJson, addId) === true;
53
+ } finally {
54
+ if (addId !== null && !emitted) {
55
+ releaseBreadcrumbFilterForAdd(addId);
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,33 @@
1
+ import { copyEventParams } from '../data/validate';
2
+ import type { EventParams } from '../data/validate';
3
+
4
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
5
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
6
+ return false;
7
+ }
8
+ const proto: unknown = Object.getPrototypeOf(value);
9
+ return proto === Object.prototype || proto === null;
10
+ }
11
+
12
+ /**
13
+ * A copy of breadcrumb `data` in the same value domain as event params.
14
+ *
15
+ * `copyEventParams` names its path `params`. The messages are retargeted so
16
+ * a rejection from `addBreadcrumb` names `data`.
17
+ */
18
+ export function copyBreadcrumbData(data: unknown): Record<string, unknown> {
19
+ if (!isPlainObject(data)) {
20
+ const kind = data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data;
21
+ throw new TypeError(
22
+ `Bugsee.addBreadcrumb data must be a plain object, got ${kind}`,
23
+ );
24
+ }
25
+ try {
26
+ return copyEventParams(data as EventParams);
27
+ } catch (error) {
28
+ if (error instanceof Error) {
29
+ error.message = error.message.replaceAll('params', 'data');
30
+ }
31
+ throw error;
32
+ }
33
+ }
@@ -0,0 +1,215 @@
1
+ import NativeBugsee from '../NativeBugsee';
2
+ import { encodeBridgeObject } from '../bridge/json';
3
+ import { copyBreadcrumbData } from './data';
4
+ import { isBreadcrumbLevel } from './types';
5
+ import type { BreadcrumbFilter, BreadcrumbSnapshot } from './types';
6
+
7
+ const WRITABLE_STRINGS = ['category', 'message', 'type'] as const;
8
+
9
+ let current: BreadcrumbFilter | undefined;
10
+ let subscribed = false;
11
+
12
+ /**
13
+ * One `addBreadcrumb` submitted while `current` was set. iOS records on the
14
+ * main queue, so a later `setBreadcrumbFilter` on that turn runs before the
15
+ * record asks JS. The callback installed at the add still answers that crumb.
16
+ * The id is not the crumb's message: two adds with the same message, and an
17
+ * SDK crumb that happens to repeat it, must not take each other's callback.
18
+ * An add native did not ask about is removed, so it cannot be claimed later.
19
+ */
20
+ let nextAddId = 0;
21
+ const owed: Array<{ id: string; callback: BreadcrumbFilter }> = [];
22
+
23
+ /**
24
+ * Called from `addBreadcrumb` after validation, before the native call.
25
+ * Returns the id native echoes on that add's filter request, or `null` when
26
+ * nothing is installed and there is nothing to retain.
27
+ */
28
+ export function retainBreadcrumbFilterForAdd(): string | null {
29
+ if (current === undefined) {
30
+ return null;
31
+ }
32
+ nextAddId += 1;
33
+ const id = String(nextAddId);
34
+ owed.push({ id, callback: current });
35
+ return id;
36
+ }
37
+
38
+ /** Drops an id native reported it will not ask about. */
39
+ export function releaseBreadcrumbFilterForAdd(id: string): void {
40
+ const index = owed.findIndex((item) => item.id === id);
41
+ if (index >= 0) {
42
+ owed.splice(index, 1);
43
+ }
44
+ }
45
+
46
+ function claimBreadcrumbFilter(id: string | undefined): BreadcrumbFilter | undefined {
47
+ if (id === undefined || id.length === 0) {
48
+ return undefined;
49
+ }
50
+ const index = owed.findIndex((item) => item.id === id);
51
+ if (index < 0) {
52
+ return undefined;
53
+ }
54
+ const [item] = owed.splice(index, 1);
55
+ return item?.callback;
56
+ }
57
+
58
+ /**
59
+ * Registers `callback` as the only breadcrumb filter. A later call replaces
60
+ * it. `undefined` or `null` clears it, which tells native to uninstall the
61
+ * filter so crumbs are recorded without one.
62
+ *
63
+ * The JS listener is subscribed before the native filter is installed, so a
64
+ * crumb filtered on the installing turn still has a listener. The subscription
65
+ * stays: clearing the callback stops native from asking, and a later callback
66
+ * must still be able to answer.
67
+ */
68
+ export function setBreadcrumbFilter(callback?: BreadcrumbFilter | null): void {
69
+ if (callback != null && typeof callback !== 'function') {
70
+ throw new TypeError(
71
+ `Bugsee.setBreadcrumbFilter requires a function, got ${typeof callback}`,
72
+ );
73
+ }
74
+ current = callback ?? undefined;
75
+ if (current !== undefined && !subscribed) {
76
+ subscribed = true;
77
+ NativeBugsee.onBreadcrumbFilterRequest(onBreadcrumbFilterRequest);
78
+ }
79
+ NativeBugsee.setBreadcrumbFilterEnabled(current !== undefined);
80
+ }
81
+
82
+ /**
83
+ * Answers one native filter request.
84
+ *
85
+ * The callback is read here, at dispatch, so a `setBreadcrumbFilter` made
86
+ * while this request is in flight changes the next crumb, not this one.
87
+ * A request that carries the id from `addBreadcrumb` is answered by the
88
+ * callback that was installed for that add, including when this turn then
89
+ * cleared the filter or replaced it with another function. A request with
90
+ * no id is an SDK crumb: it uses whatever is installed now and does not
91
+ * take an owed callback. The callback itself runs on a later turn.
92
+ *
93
+ * A throw, a rejection, a result that is not an object, or a keep that drops
94
+ * a writable key the snapshot sent (`category`, `level`, `message`, `type`,
95
+ * and `data` when it was present) drops the crumb. A callback that never
96
+ * settles does not reply at all. Neither path replies with the original crumb.
97
+ * `timestamp` is not a writable key, and a key the snapshot omitted stays
98
+ * omitted. `data: null` when the snapshot sent `data` clears it.
99
+ */
100
+ function onBreadcrumbFilterRequest(event: {
101
+ requestId: string;
102
+ crumbJson: string;
103
+ addId?: string;
104
+ }): void {
105
+ const { requestId } = event;
106
+ // Claim before parsing. A release for an add that never asked has an id
107
+ // and a crumb JSON that is not a snapshot; the slot has to go, and the
108
+ // callback must not run.
109
+ const reserved = claimBreadcrumbFilter(event.addId);
110
+ const snapshot = snapshotFromJson(event.crumbJson);
111
+ if (snapshot === null) {
112
+ reply(requestId, null);
113
+ return;
114
+ }
115
+ const callback = reserved ?? current;
116
+ if (callback === undefined) {
117
+ reply(requestId, null);
118
+ return;
119
+ }
120
+
121
+ Promise.resolve()
122
+ .then(() => callback(snapshot))
123
+ .then((result) => {
124
+ reply(requestId, keptJson(snapshot, result));
125
+ })
126
+ .catch(() => {
127
+ reply(requestId, null);
128
+ });
129
+ }
130
+
131
+ function snapshotFromJson(json: string): BreadcrumbSnapshot | null {
132
+ let parsed: unknown;
133
+ try {
134
+ parsed = JSON.parse(json);
135
+ } catch {
136
+ return null;
137
+ }
138
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
139
+ return null;
140
+ }
141
+ const source = parsed as Record<string, unknown>;
142
+ const snapshot: BreadcrumbSnapshot = Object.create(null);
143
+ for (const key of WRITABLE_STRINGS) {
144
+ if (!Object.hasOwn(source, key)) {
145
+ continue;
146
+ }
147
+ const value = source[key];
148
+ if (typeof value !== 'string') {
149
+ return null;
150
+ }
151
+ snapshot[key] = value;
152
+ }
153
+ if (Object.hasOwn(source, 'level')) {
154
+ if (!isBreadcrumbLevel(source.level)) {
155
+ return null;
156
+ }
157
+ snapshot.level = source.level;
158
+ }
159
+ if (Object.hasOwn(source, 'data')) {
160
+ snapshot.data = source.data;
161
+ }
162
+ if (Object.hasOwn(source, 'timestamp') && typeof source.timestamp === 'number') {
163
+ snapshot.timestamp = source.timestamp;
164
+ }
165
+ return snapshot;
166
+ }
167
+
168
+ /**
169
+ * The JSON to send back, or `null` to drop.
170
+ *
171
+ * Every writable key the snapshot has must be an own key of `result`, and
172
+ * not `undefined`. String keys must be strings. `level` must still be a
173
+ * level name, and that name is what is sent. `data: null` is kept as `null`.
174
+ * `timestamp` is not copied. A key the snapshot does not have is not added.
175
+ */
176
+ function keptJson(snapshot: BreadcrumbSnapshot, result: unknown): string | null {
177
+ if (result === null || result === undefined || typeof result !== 'object') {
178
+ return null;
179
+ }
180
+ const record = result as Record<string, unknown>;
181
+ const out: Record<string, unknown> = Object.create(null);
182
+ for (const key of WRITABLE_STRINGS) {
183
+ if (!Object.hasOwn(snapshot, key)) {
184
+ continue;
185
+ }
186
+ if (!Object.hasOwn(record, key) || typeof record[key] !== 'string') {
187
+ return null;
188
+ }
189
+ out[key] = record[key];
190
+ }
191
+ if (Object.hasOwn(snapshot, 'level')) {
192
+ if (!Object.hasOwn(record, 'level')) {
193
+ return null;
194
+ }
195
+ if (!isBreadcrumbLevel(record.level)) {
196
+ return null;
197
+ }
198
+ out.level = record.level;
199
+ }
200
+ if (Object.hasOwn(snapshot, 'data')) {
201
+ if (!Object.hasOwn(record, 'data') || record.data === undefined) {
202
+ return null;
203
+ }
204
+ out.data = record.data === null ? null : copyBreadcrumbData(record.data);
205
+ }
206
+ return encodeBridgeObject(out);
207
+ }
208
+
209
+ function reply(requestId: string, crumbJson: string | null): void {
210
+ try {
211
+ NativeBugsee.replyBreadcrumbFilter(requestId, crumbJson);
212
+ } catch {
213
+ // The bridge is gone. An unanswered request is not recorded.
214
+ }
215
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The level names the bridge sends. Each native side maps a name to its own
3
+ * integer when it writes the crumb. Those integers are not the same:
4
+ *
5
+ * Android `Breadcrumb.Level.getValue()` is debug 1, info 2, warning 3,
6
+ * error 4, fatal 5 (not the enum ordinal).
7
+ *
8
+ * iOS `BGSBreadcrumb.level` is `BugseeLogLevel`: error 1, warning 2, info 3,
9
+ * debug 4. There is no fatal on that ladder, so iOS stores `fatal` as 1,
10
+ * which the bundle records as `error`. Verbose (5) is not a JS name; a
11
+ * stored verbose reads back as `debug`.
12
+ *
13
+ * The filter snapshot's `level` is this name, on both platforms. A keep
14
+ * echoes the name. Sending Android's integer to iOS records `info` as
15
+ * `warning`.
16
+ */
17
+ export const BREADCRUMB_LEVELS = ['debug', 'info', 'warning', 'error', 'fatal'] as const;
18
+
19
+ export type BreadcrumbLevel = (typeof BREADCRUMB_LEVELS)[number];
20
+
21
+ /** Whether `level` is one of the JS names. A number is not. */
22
+ export function isBreadcrumbLevel(level: unknown): level is BreadcrumbLevel {
23
+ return typeof level === 'string' && (BREADCRUMB_LEVELS as readonly string[]).includes(level);
24
+ }
25
+
26
+ /**
27
+ * What `addBreadcrumb` records. The factory stamps the time, so `timestamp`
28
+ * is not a field the caller supplies.
29
+ */
30
+ export interface Breadcrumb {
31
+ category: string;
32
+ level: BreadcrumbLevel;
33
+ message: string;
34
+ type: string;
35
+ data?: Record<string, unknown> | null;
36
+ }
37
+
38
+ /**
39
+ * What the filter callback sees. A key the native crumb did not have is
40
+ * absent. `timestamp` may be present and is not writable: a keep does not
41
+ * have to send it back. `data` is present only when the crumb had data,
42
+ * including when that value is `null` only on the way back, to clear it.
43
+ */
44
+ export interface BreadcrumbSnapshot {
45
+ category?: string;
46
+ level?: BreadcrumbLevel;
47
+ message?: string;
48
+ type?: string;
49
+ data?: unknown;
50
+ timestamp?: number;
51
+ }
52
+
53
+ /**
54
+ * One crumb in, the crumb to keep out.
55
+ *
56
+ * Returning the crumb, or another object, keeps it. `null` and `undefined`
57
+ * drop it. A promise is waited on. This function does not add a timeout of
58
+ * its own: an unanswered filter is not recorded, and a timeout here that then
59
+ * passed the original crumb would leak exactly what the filter exists to
60
+ * remove.
61
+ */
62
+ export type BreadcrumbFilter = (
63
+ crumb: BreadcrumbSnapshot,
64
+ ) => object | null | undefined | Promise<object | null | undefined>;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The one transport for an object payload that may carry `null` members:
3
+ * JSON text, parsed natively (Android `BridgeJson`, iOS `BGSRNJSONObject`).
4
+ *
5
+ * Not `UnsafeObject`. React Native's iOS TurboModule conversion of an object
6
+ * argument (`convertJSIObjectToNSDictionary` in `RCTTurboModule.mm`) skips
7
+ * every member whose converted value is `nil`, and a JS `null` converts to
8
+ * `nil` unless the app turns on
9
+ * `enableModuleArgumentNSNullConversionIOS` -- off by default, and not a flag
10
+ * a library can depend on across its 0.81 floor. So `{ summary: null }`
11
+ * reached iOS as `{}`: "clear this" arrived as "leave it alone", while
12
+ * Android's `ReadableMap` kept the null. As text, a null is just `null` on
13
+ * both.
14
+ *
15
+ * Every object payload with nullable members uses this: event params, the
16
+ * report patch, and Phase 5's attribute maps.
17
+ */
18
+
19
+ const REPLACEMENT_CHARACTER = '\uFFFD';
20
+
21
+ function isHighSurrogate(code: number): boolean {
22
+ return code >= 0xd800 && code <= 0xdbff;
23
+ }
24
+
25
+ function isLowSurrogate(code: number): boolean {
26
+ return code >= 0xdc00 && code <= 0xdfff;
27
+ }
28
+
29
+ /**
30
+ * `text` with every lone UTF-16 surrogate replaced by U+FFFD, and every valid
31
+ * pair kept -- `String.prototype.toWellFormed`, for an engine without it.
32
+ * Exported for its tests, which run on an engine that has it.
33
+ */
34
+ export function replaceLoneSurrogates(text: string): string {
35
+ let result = '';
36
+ for (let i = 0; i < text.length; i += 1) {
37
+ const code = text.charCodeAt(i);
38
+ if (isHighSurrogate(code) && isLowSurrogate(text.charCodeAt(i + 1))) {
39
+ result += text.slice(i, i + 2);
40
+ i += 1;
41
+ } else if (isHighSurrogate(code) || isLowSurrogate(code)) {
42
+ result += REPLACEMENT_CHARACTER;
43
+ } else {
44
+ result += text[i];
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+
50
+ /** ES2024's `toWellFormed` when the engine has it (Hermes may not), else the fallback. */
51
+ function wellFormed(text: string): string {
52
+ const native = (text as { toWellFormed?: () => string }).toWellFormed;
53
+ return typeof native === 'function' ? native.call(text) : replaceLoneSurrogates(text);
54
+ }
55
+
56
+ /**
57
+ * A copy of `value` whose every string, key or value, is well-formed.
58
+ *
59
+ * Why: `JSON.stringify` writes a lone surrogate as the escape `\ud83d`, and
60
+ * iOS's `NSJSONSerialization` rejects the WHOLE text for it, so a summary cut
61
+ * mid-emoji (`text.slice(0, 100)`) would reject on iOS and resolve on
62
+ * Android, and such an event would be dropped on iOS alone. Before this
63
+ * transport, React Native's own string conversion turned a lone surrogate
64
+ * into U+FFFD on both; this keeps that. Two keys that differ only in a lone
65
+ * surrogate become the same key, and the later one wins.
66
+ *
67
+ * Built on a prototype-less object, so a "__proto__" key stays an ordinary
68
+ * key rather than hitting `Object.prototype`'s setter.
69
+ */
70
+ function wellFormedCopy(value: unknown): unknown {
71
+ if (typeof value === 'string') {
72
+ return wellFormed(value);
73
+ }
74
+ if (Array.isArray(value)) {
75
+ return value.map(wellFormedCopy);
76
+ }
77
+ if (typeof value === 'object' && value !== null) {
78
+ const source = value as Record<string, unknown>;
79
+ const copy: Record<string, unknown> = Object.create(null);
80
+ for (const key of Object.keys(source)) {
81
+ copy[wellFormed(key)] = wellFormedCopy(source[key]);
82
+ }
83
+ return copy;
84
+ }
85
+ return value;
86
+ }
87
+
88
+ /**
89
+ * `value` as JSON text for the bridge, every string in it well-formed
90
+ * (lone surrogates replaced by U+FFFD; see `wellFormedCopy`).
91
+ *
92
+ * `value` must already be validated and plain -- finite numbers only, no
93
+ * `undefined` array elements, no cycles -- as `copyEventParams` and
94
+ * `validateReportPatch` guarantee. This does no validation of its own:
95
+ * `JSON.stringify` would silently turn `NaN` into `null` and drop an
96
+ * `undefined` member, and those are the validators' to reject, not this
97
+ * function's to paper over.
98
+ */
99
+ export function encodeBridgeObject(value: Readonly<Record<string, unknown>>): string {
100
+ return JSON.stringify(wellFormedCopy(value));
101
+ }
102
+
103
+ /**
104
+ * One JSON value for the bridge, strings well-formed the same way as
105
+ * {@link encodeBridgeObject}. A lone surrogate becomes U+FFFD before
106
+ * `JSON.stringify`, so iOS `NSJSONSerialization` does not reject the text.
107
+ */
108
+ export function encodeBridgeJson(value: unknown): string {
109
+ return JSON.stringify(wellFormedCopy(value));
110
+ }