@scalebun/react-native 1.1.0 → 1.2.0

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 (373) hide show
  1. package/dist/scalebun.full.js +33132 -0
  2. package/dist/scalebun.full.js.map +1 -0
  3. package/dist/scalebun.slim.js +29930 -0
  4. package/dist/scalebun.slim.js.map +1 -0
  5. package/lib/commonjs/bootstrap/FeatureRegistry.js +4 -4
  6. package/lib/commonjs/bootstrap/FeatureRegistry.js.map +1 -1
  7. package/lib/commonjs/bootstrap/SDKBootstrapper.js +8 -8
  8. package/lib/commonjs/bootstrap/SDKBootstrapper.js.map +1 -1
  9. package/lib/commonjs/core/config/schema.js +412 -232
  10. package/lib/commonjs/core/config/schema.js.map +1 -1
  11. package/lib/commonjs/core/constants/protocol.js +31 -0
  12. package/lib/commonjs/core/constants/protocol.js.map +1 -0
  13. package/lib/commonjs/core/constants/timings.js +4 -1
  14. package/lib/commonjs/core/constants/timings.js.map +1 -1
  15. package/lib/commonjs/core/lifecycle/appLifecycle.js +1 -1
  16. package/lib/commonjs/core/lifecycle/appLifecycle.js.map +1 -1
  17. package/lib/commonjs/debug/bootstrap.js +30 -10
  18. package/lib/commonjs/debug/bootstrap.js.map +1 -1
  19. package/lib/commonjs/debug/exportBridge.js +5 -3
  20. package/lib/commonjs/debug/exportBridge.js.map +1 -1
  21. package/lib/commonjs/debug/hostResolver.js +2 -2
  22. package/lib/commonjs/debug/hostResolver.js.map +1 -1
  23. package/lib/commonjs/debug/perfWiring.js +4 -4
  24. package/lib/commonjs/debug/perfWiring.js.map +1 -1
  25. package/lib/commonjs/debug/replayWiring.js +5 -5
  26. package/lib/commonjs/debug/replayWiring.js.map +1 -1
  27. package/lib/commonjs/debug/screenTracking.js +2 -2
  28. package/lib/commonjs/debug/screenTracking.js.map +1 -1
  29. package/lib/commonjs/debug/sessionWiring.js +2 -2
  30. package/lib/commonjs/debug/sessionWiring.js.map +1 -1
  31. package/lib/commonjs/features/crash/NativeCrashFeature.js +1 -1
  32. package/lib/commonjs/features/crash/NativeCrashFeature.js.map +1 -1
  33. package/lib/commonjs/features/crash/globalHandler.js +3 -3
  34. package/lib/commonjs/features/crash/globalHandler.js.map +1 -1
  35. package/lib/commonjs/features/crash/nativeCrashBridge.js +7 -7
  36. package/lib/commonjs/features/crash/nativeCrashBridge.js.map +1 -1
  37. package/lib/commonjs/features/crash/rejectionHandler.js +2 -2
  38. package/lib/commonjs/features/crash/rejectionHandler.js.map +1 -1
  39. package/lib/commonjs/features/engage/EngageArchetypeRenderers.js +0 -9
  40. package/lib/commonjs/features/engage/EngageArchetypeRenderers.js.map +1 -1
  41. package/lib/commonjs/features/engage/EngageInAppView.js +1 -1
  42. package/lib/commonjs/features/engage/EngageInAppView.js.map +1 -1
  43. package/lib/commonjs/features/engage/EngagePromptProvider.js +17 -17
  44. package/lib/commonjs/features/engage/EngagePromptProvider.js.map +1 -1
  45. package/lib/commonjs/features/engage/EngageTransport.js +5 -5
  46. package/lib/commonjs/features/engage/EngageTransport.js.map +1 -1
  47. package/lib/commonjs/features/engage/engagePushTokenBridge.js +4 -4
  48. package/lib/commonjs/features/engage/engagePushTokenBridge.js.map +1 -1
  49. package/lib/commonjs/features/engage/engageShakeBridge.js +2 -2
  50. package/lib/commonjs/features/engage/engageShakeBridge.js.map +1 -1
  51. package/lib/commonjs/features/engage/engageSignals.js +1 -1
  52. package/lib/commonjs/features/engage/engageSignals.js.map +1 -1
  53. package/lib/commonjs/features/engage/engageStoreReviewBridge.js +2 -2
  54. package/lib/commonjs/features/engage/engageStoreReviewBridge.js.map +1 -1
  55. package/lib/commonjs/features/engage/engageTestSeenStore.js +1 -1
  56. package/lib/commonjs/features/engage/engageTestSeenStore.js.map +1 -1
  57. package/lib/commonjs/features/engage/engageThrottle.js +4 -4
  58. package/lib/commonjs/features/engage/engageThrottle.js.map +1 -1
  59. package/lib/commonjs/features/engage/engageTriggerEngine.js +4 -4
  60. package/lib/commonjs/features/engage/engageTriggerEngine.js.map +1 -1
  61. package/lib/commonjs/features/engage/engageWindowInsets.js +1 -1
  62. package/lib/commonjs/features/engage/engageWindowInsets.js.map +1 -1
  63. package/lib/commonjs/features/install-referrer/installReferrer.js +3 -3
  64. package/lib/commonjs/features/install-referrer/installReferrer.js.map +1 -1
  65. package/lib/commonjs/features/journey/calibrationContext.js +0 -9
  66. package/lib/commonjs/features/journey/calibrationContext.js.map +1 -1
  67. package/lib/commonjs/features/journey/journeyManager.js +4 -1
  68. package/lib/commonjs/features/journey/journeyManager.js.map +1 -1
  69. package/lib/commonjs/features/navigation/AutoScreenDetector.js +4 -4
  70. package/lib/commonjs/features/navigation/AutoScreenDetector.js.map +1 -1
  71. package/lib/commonjs/features/ota/OtaOrchestrator.js +18 -18
  72. package/lib/commonjs/features/ota/OtaOrchestrator.js.map +1 -1
  73. package/lib/commonjs/features/ota/geoCountry.js +2 -2
  74. package/lib/commonjs/features/ota/geoCountry.js.map +1 -1
  75. package/lib/commonjs/features/ota/retry.js +2 -2
  76. package/lib/commonjs/features/ota/retry.js.map +1 -1
  77. package/lib/commonjs/features/replay/core/logger/logger.js +0 -4
  78. package/lib/commonjs/features/replay/core/logger/logger.js.map +1 -1
  79. package/lib/commonjs/features/replay/integrations/network/networkAdapter.js +1 -54
  80. package/lib/commonjs/features/replay/integrations/network/networkAdapter.js.map +1 -1
  81. package/lib/commonjs/features/replay/integrations/react-navigation/navigationIntegration.js +1 -1
  82. package/lib/commonjs/features/replay/integrations/react-navigation/navigationIntegration.js.map +1 -1
  83. package/lib/commonjs/features/replay/integrations/touch/ReplayRoot.js +1 -1
  84. package/lib/commonjs/features/replay/integrations/touch/ReplayRoot.js.map +1 -1
  85. package/lib/commonjs/features/replay/pipeline/batching/batchManager.js +1 -1
  86. package/lib/commonjs/features/replay/pipeline/batching/batchManager.js.map +1 -1
  87. package/lib/commonjs/features/replay/pipeline/retry/retryPolicy.js +1 -1
  88. package/lib/commonjs/features/replay/pipeline/retry/retryPolicy.js.map +1 -1
  89. package/lib/commonjs/features/replay/public/api.js +7 -7
  90. package/lib/commonjs/features/replay/public/api.js.map +1 -1
  91. package/lib/commonjs/features/replay/replay/session/sessionOrchestrator.js +9 -9
  92. package/lib/commonjs/features/replay/replay/session/sessionOrchestrator.js.map +1 -1
  93. package/lib/commonjs/features/session/BackendSessionAdapter.js +41 -41
  94. package/lib/commonjs/features/session/BackendSessionAdapter.js.map +1 -1
  95. package/lib/commonjs/features/session/DesktopSessionTransport.js +5 -2
  96. package/lib/commonjs/features/session/DesktopSessionTransport.js.map +1 -1
  97. package/lib/commonjs/features/session/JourneyEventPipeline.js +1 -1
  98. package/lib/commonjs/features/session/JourneyEventPipeline.js.map +1 -1
  99. package/lib/commonjs/features/session/ReplayCaptureManager.js +14 -14
  100. package/lib/commonjs/features/session/ReplayCaptureManager.js.map +1 -1
  101. package/lib/commonjs/features/session/SessionManager.js +9 -9
  102. package/lib/commonjs/features/session/SessionManager.js.map +1 -1
  103. package/lib/commonjs/features/session/SyncDecisionEngine.js +1 -1
  104. package/lib/commonjs/features/session/SyncDecisionEngine.js.map +1 -1
  105. package/lib/commonjs/features/skan/skanBridge.js +6 -15
  106. package/lib/commonjs/features/skan/skanBridge.js.map +1 -1
  107. package/lib/commonjs/features/skan/skanConversionManager.js +5 -5
  108. package/lib/commonjs/features/skan/skanConversionManager.js.map +1 -1
  109. package/lib/commonjs/integrations/fetch/fetchInterceptor.js +1 -1
  110. package/lib/commonjs/integrations/fetch/fetchInterceptor.js.map +1 -1
  111. package/lib/commonjs/integrations/xhr/xhrInterceptor.js +1 -1
  112. package/lib/commonjs/integrations/xhr/xhrInterceptor.js.map +1 -1
  113. package/lib/commonjs/metro/composeSourceMap.js +105 -0
  114. package/lib/commonjs/metro/composeSourceMap.js.map +1 -0
  115. package/lib/commonjs/metro/featureModules.js +131 -0
  116. package/lib/commonjs/metro/featureModules.js.map +1 -0
  117. package/lib/commonjs/metro/index.js +123 -2
  118. package/lib/commonjs/metro/index.js.map +1 -1
  119. package/lib/commonjs/metro/serializerCompose.js +129 -0
  120. package/lib/commonjs/metro/serializerCompose.js.map +1 -0
  121. package/lib/commonjs/pipeline/dispatcher/dispatcher.js +1 -1
  122. package/lib/commonjs/pipeline/dispatcher/dispatcher.js.map +1 -1
  123. package/lib/commonjs/pipeline/queue/flushQueue.js +2 -2
  124. package/lib/commonjs/pipeline/queue/flushQueue.js.map +1 -1
  125. package/lib/commonjs/pipeline/queue/persistentQueue.js +6 -37
  126. package/lib/commonjs/pipeline/queue/persistentQueue.js.map +1 -1
  127. package/lib/commonjs/pipeline/scheduler/flushScheduler.js +1 -1
  128. package/lib/commonjs/pipeline/scheduler/flushScheduler.js.map +1 -1
  129. package/lib/commonjs/public/ScaleBunFacade.js +15 -15
  130. package/lib/commonjs/public/ScaleBunFacade.js.map +1 -1
  131. package/lib/commonjs/push/PushManager.js +3 -3
  132. package/lib/commonjs/push/PushManager.js.map +1 -1
  133. package/lib/commonjs/push/adapters/NativeBridgeAdapter.js +1 -1
  134. package/lib/commonjs/push/adapters/NativeBridgeAdapter.js.map +1 -1
  135. package/lib/commonjs/push/native/nativeNotifications.js +7 -18
  136. package/lib/commonjs/push/native/nativeNotifications.js.map +1 -1
  137. package/lib/commonjs/storage/StorageBackend.js +1 -1
  138. package/lib/commonjs/storage/StorageBackend.js.map +1 -1
  139. package/lib/module/bootstrap/FeatureRegistry.js +4 -4
  140. package/lib/module/bootstrap/FeatureRegistry.js.map +1 -1
  141. package/lib/module/bootstrap/SDKBootstrapper.js +8 -8
  142. package/lib/module/bootstrap/SDKBootstrapper.js.map +1 -1
  143. package/lib/module/core/config/schema.js +411 -231
  144. package/lib/module/core/config/schema.js.map +1 -1
  145. package/lib/module/core/constants/protocol.js +25 -0
  146. package/lib/module/core/constants/protocol.js.map +1 -0
  147. package/lib/module/core/constants/timings.js +3 -1
  148. package/lib/module/core/constants/timings.js.map +1 -1
  149. package/lib/module/core/lifecycle/appLifecycle.js +1 -1
  150. package/lib/module/core/lifecycle/appLifecycle.js.map +1 -1
  151. package/lib/module/debug/bootstrap.js +30 -9
  152. package/lib/module/debug/bootstrap.js.map +1 -1
  153. package/lib/module/debug/exportBridge.js +5 -3
  154. package/lib/module/debug/exportBridge.js.map +1 -1
  155. package/lib/module/debug/hostResolver.js +2 -2
  156. package/lib/module/debug/hostResolver.js.map +1 -1
  157. package/lib/module/debug/perfWiring.js +4 -4
  158. package/lib/module/debug/perfWiring.js.map +1 -1
  159. package/lib/module/debug/replayWiring.js +5 -5
  160. package/lib/module/debug/replayWiring.js.map +1 -1
  161. package/lib/module/debug/screenTracking.js +2 -2
  162. package/lib/module/debug/screenTracking.js.map +1 -1
  163. package/lib/module/debug/sessionWiring.js +2 -2
  164. package/lib/module/debug/sessionWiring.js.map +1 -1
  165. package/lib/module/features/crash/NativeCrashFeature.js +1 -1
  166. package/lib/module/features/crash/NativeCrashFeature.js.map +1 -1
  167. package/lib/module/features/crash/globalHandler.js +3 -3
  168. package/lib/module/features/crash/globalHandler.js.map +1 -1
  169. package/lib/module/features/crash/nativeCrashBridge.js +7 -7
  170. package/lib/module/features/crash/nativeCrashBridge.js.map +1 -1
  171. package/lib/module/features/crash/rejectionHandler.js +2 -2
  172. package/lib/module/features/crash/rejectionHandler.js.map +1 -1
  173. package/lib/module/features/engage/EngageArchetypeRenderers.js +0 -8
  174. package/lib/module/features/engage/EngageArchetypeRenderers.js.map +1 -1
  175. package/lib/module/features/engage/EngageInAppView.js +1 -1
  176. package/lib/module/features/engage/EngageInAppView.js.map +1 -1
  177. package/lib/module/features/engage/EngagePromptProvider.js +17 -17
  178. package/lib/module/features/engage/EngagePromptProvider.js.map +1 -1
  179. package/lib/module/features/engage/EngageTransport.js +5 -5
  180. package/lib/module/features/engage/EngageTransport.js.map +1 -1
  181. package/lib/module/features/engage/engagePushTokenBridge.js +4 -4
  182. package/lib/module/features/engage/engagePushTokenBridge.js.map +1 -1
  183. package/lib/module/features/engage/engageShakeBridge.js +2 -2
  184. package/lib/module/features/engage/engageShakeBridge.js.map +1 -1
  185. package/lib/module/features/engage/engageSignals.js +1 -1
  186. package/lib/module/features/engage/engageSignals.js.map +1 -1
  187. package/lib/module/features/engage/engageStoreReviewBridge.js +2 -2
  188. package/lib/module/features/engage/engageStoreReviewBridge.js.map +1 -1
  189. package/lib/module/features/engage/engageTestSeenStore.js +1 -1
  190. package/lib/module/features/engage/engageTestSeenStore.js.map +1 -1
  191. package/lib/module/features/engage/engageThrottle.js +4 -4
  192. package/lib/module/features/engage/engageThrottle.js.map +1 -1
  193. package/lib/module/features/engage/engageTriggerEngine.js +4 -4
  194. package/lib/module/features/engage/engageTriggerEngine.js.map +1 -1
  195. package/lib/module/features/engage/engageWindowInsets.js +1 -1
  196. package/lib/module/features/engage/engageWindowInsets.js.map +1 -1
  197. package/lib/module/features/install-referrer/installReferrer.js +3 -3
  198. package/lib/module/features/install-referrer/installReferrer.js.map +1 -1
  199. package/lib/module/features/journey/calibrationContext.js +0 -8
  200. package/lib/module/features/journey/calibrationContext.js.map +1 -1
  201. package/lib/module/features/journey/journeyManager.js +3 -1
  202. package/lib/module/features/journey/journeyManager.js.map +1 -1
  203. package/lib/module/features/navigation/AutoScreenDetector.js +4 -4
  204. package/lib/module/features/navigation/AutoScreenDetector.js.map +1 -1
  205. package/lib/module/features/ota/OtaOrchestrator.js +18 -18
  206. package/lib/module/features/ota/OtaOrchestrator.js.map +1 -1
  207. package/lib/module/features/ota/geoCountry.js +2 -2
  208. package/lib/module/features/ota/geoCountry.js.map +1 -1
  209. package/lib/module/features/ota/retry.js +2 -2
  210. package/lib/module/features/ota/retry.js.map +1 -1
  211. package/lib/module/features/replay/core/logger/logger.js +0 -3
  212. package/lib/module/features/replay/core/logger/logger.js.map +1 -1
  213. package/lib/module/features/replay/integrations/network/networkAdapter.js +1 -52
  214. package/lib/module/features/replay/integrations/network/networkAdapter.js.map +1 -1
  215. package/lib/module/features/replay/integrations/react-navigation/navigationIntegration.js +1 -1
  216. package/lib/module/features/replay/integrations/react-navigation/navigationIntegration.js.map +1 -1
  217. package/lib/module/features/replay/integrations/touch/ReplayRoot.js +1 -1
  218. package/lib/module/features/replay/integrations/touch/ReplayRoot.js.map +1 -1
  219. package/lib/module/features/replay/pipeline/batching/batchManager.js +1 -1
  220. package/lib/module/features/replay/pipeline/batching/batchManager.js.map +1 -1
  221. package/lib/module/features/replay/pipeline/retry/retryPolicy.js +1 -1
  222. package/lib/module/features/replay/pipeline/retry/retryPolicy.js.map +1 -1
  223. package/lib/module/features/replay/public/api.js +7 -7
  224. package/lib/module/features/replay/public/api.js.map +1 -1
  225. package/lib/module/features/replay/replay/session/sessionOrchestrator.js +9 -9
  226. package/lib/module/features/replay/replay/session/sessionOrchestrator.js.map +1 -1
  227. package/lib/module/features/session/BackendSessionAdapter.js +41 -41
  228. package/lib/module/features/session/BackendSessionAdapter.js.map +1 -1
  229. package/lib/module/features/session/DesktopSessionTransport.js +4 -2
  230. package/lib/module/features/session/DesktopSessionTransport.js.map +1 -1
  231. package/lib/module/features/session/JourneyEventPipeline.js +1 -1
  232. package/lib/module/features/session/JourneyEventPipeline.js.map +1 -1
  233. package/lib/module/features/session/ReplayCaptureManager.js +14 -14
  234. package/lib/module/features/session/ReplayCaptureManager.js.map +1 -1
  235. package/lib/module/features/session/SessionManager.js +9 -9
  236. package/lib/module/features/session/SessionManager.js.map +1 -1
  237. package/lib/module/features/session/SyncDecisionEngine.js +1 -1
  238. package/lib/module/features/session/SyncDecisionEngine.js.map +1 -1
  239. package/lib/module/features/skan/skanBridge.js +6 -14
  240. package/lib/module/features/skan/skanBridge.js.map +1 -1
  241. package/lib/module/features/skan/skanConversionManager.js +5 -5
  242. package/lib/module/features/skan/skanConversionManager.js.map +1 -1
  243. package/lib/module/integrations/fetch/fetchInterceptor.js +1 -1
  244. package/lib/module/integrations/fetch/fetchInterceptor.js.map +1 -1
  245. package/lib/module/integrations/xhr/xhrInterceptor.js +1 -1
  246. package/lib/module/integrations/xhr/xhrInterceptor.js.map +1 -1
  247. package/lib/module/metro/composeSourceMap.js +97 -0
  248. package/lib/module/metro/composeSourceMap.js.map +1 -0
  249. package/lib/module/metro/featureModules.js +123 -0
  250. package/lib/module/metro/featureModules.js.map +1 -0
  251. package/lib/module/metro/index.js +122 -2
  252. package/lib/module/metro/index.js.map +1 -1
  253. package/lib/module/metro/serializerCompose.js +120 -0
  254. package/lib/module/metro/serializerCompose.js.map +1 -0
  255. package/lib/module/pipeline/dispatcher/dispatcher.js +1 -1
  256. package/lib/module/pipeline/dispatcher/dispatcher.js.map +1 -1
  257. package/lib/module/pipeline/queue/flushQueue.js +2 -2
  258. package/lib/module/pipeline/queue/flushQueue.js.map +1 -1
  259. package/lib/module/pipeline/queue/persistentQueue.js +6 -36
  260. package/lib/module/pipeline/queue/persistentQueue.js.map +1 -1
  261. package/lib/module/pipeline/scheduler/flushScheduler.js +1 -1
  262. package/lib/module/pipeline/scheduler/flushScheduler.js.map +1 -1
  263. package/lib/module/public/ScaleBunFacade.js +15 -15
  264. package/lib/module/public/ScaleBunFacade.js.map +1 -1
  265. package/lib/module/push/PushManager.js +3 -3
  266. package/lib/module/push/PushManager.js.map +1 -1
  267. package/lib/module/push/adapters/NativeBridgeAdapter.js +1 -1
  268. package/lib/module/push/adapters/NativeBridgeAdapter.js.map +1 -1
  269. package/lib/module/push/native/nativeNotifications.js +7 -17
  270. package/lib/module/push/native/nativeNotifications.js.map +1 -1
  271. package/lib/module/storage/StorageBackend.js +1 -1
  272. package/lib/module/storage/StorageBackend.js.map +1 -1
  273. package/lib/typescript/core/config/schema.d.ts +61 -40
  274. package/lib/typescript/core/config/schema.d.ts.map +1 -1
  275. package/lib/typescript/core/constants/protocol.d.ts +23 -0
  276. package/lib/typescript/core/constants/protocol.d.ts.map +1 -0
  277. package/lib/typescript/core/constants/timings.d.ts +1 -1
  278. package/lib/typescript/core/constants/timings.d.ts.map +1 -1
  279. package/lib/typescript/debug/bootstrap.d.ts +0 -1
  280. package/lib/typescript/debug/bootstrap.d.ts.map +1 -1
  281. package/lib/typescript/debug/exportBridge.d.ts.map +1 -1
  282. package/lib/typescript/features/engage/EngageArchetypeRenderers.d.ts +0 -2
  283. package/lib/typescript/features/engage/EngageArchetypeRenderers.d.ts.map +1 -1
  284. package/lib/typescript/features/journey/calibrationContext.d.ts +0 -1
  285. package/lib/typescript/features/journey/calibrationContext.d.ts.map +1 -1
  286. package/lib/typescript/features/journey/journeyManager.d.ts.map +1 -1
  287. package/lib/typescript/features/replay/core/logger/logger.d.ts +0 -1
  288. package/lib/typescript/features/replay/core/logger/logger.d.ts.map +1 -1
  289. package/lib/typescript/features/replay/integrations/network/networkAdapter.d.ts +0 -10
  290. package/lib/typescript/features/replay/integrations/network/networkAdapter.d.ts.map +1 -1
  291. package/lib/typescript/features/session/DesktopSessionTransport.d.ts.map +1 -1
  292. package/lib/typescript/features/skan/skanBridge.d.ts +0 -2
  293. package/lib/typescript/features/skan/skanBridge.d.ts.map +1 -1
  294. package/lib/typescript/metro/composeSourceMap.d.ts +26 -0
  295. package/lib/typescript/metro/composeSourceMap.d.ts.map +1 -0
  296. package/lib/typescript/metro/featureModules.d.ts +49 -0
  297. package/lib/typescript/metro/featureModules.d.ts.map +1 -0
  298. package/lib/typescript/metro/index.d.ts +22 -0
  299. package/lib/typescript/metro/index.d.ts.map +1 -1
  300. package/lib/typescript/metro/serializerCompose.d.ts +46 -0
  301. package/lib/typescript/metro/serializerCompose.d.ts.map +1 -0
  302. package/lib/typescript/pipeline/queue/persistentQueue.d.ts +0 -10
  303. package/lib/typescript/pipeline/queue/persistentQueue.d.ts.map +1 -1
  304. package/lib/typescript/push/native/nativeNotifications.d.ts +0 -6
  305. package/lib/typescript/push/native/nativeNotifications.d.ts.map +1 -1
  306. package/package.json +15 -11
  307. package/src/bootstrap/FeatureRegistry.ts +4 -4
  308. package/src/bootstrap/SDKBootstrapper.ts +8 -8
  309. package/src/core/config/schema.ts +353 -235
  310. package/src/core/constants/protocol.ts +24 -0
  311. package/src/core/constants/timings.ts +3 -1
  312. package/src/core/lifecycle/appLifecycle.ts +1 -1
  313. package/src/debug/bootstrap.ts +40 -7
  314. package/src/debug/exportBridge.ts +5 -3
  315. package/src/debug/hostResolver.ts +2 -2
  316. package/src/debug/perfWiring.ts +4 -4
  317. package/src/debug/replayWiring.ts +5 -5
  318. package/src/debug/screenTracking.ts +2 -2
  319. package/src/debug/sessionWiring.ts +2 -2
  320. package/src/features/crash/NativeCrashFeature.ts +1 -1
  321. package/src/features/crash/globalHandler.ts +3 -3
  322. package/src/features/crash/nativeCrashBridge.ts +7 -7
  323. package/src/features/crash/rejectionHandler.ts +2 -2
  324. package/src/features/engage/EngageArchetypeRenderers.tsx +0 -11
  325. package/src/features/engage/EngageInAppView.tsx +1 -1
  326. package/src/features/engage/EngagePromptProvider.tsx +17 -17
  327. package/src/features/engage/EngageTransport.ts +5 -5
  328. package/src/features/engage/engagePushTokenBridge.ts +4 -4
  329. package/src/features/engage/engageShakeBridge.ts +2 -2
  330. package/src/features/engage/engageSignals.ts +1 -1
  331. package/src/features/engage/engageStoreReviewBridge.ts +2 -2
  332. package/src/features/engage/engageTestSeenStore.ts +1 -1
  333. package/src/features/engage/engageThrottle.ts +4 -4
  334. package/src/features/engage/engageTriggerEngine.ts +4 -4
  335. package/src/features/engage/engageWindowInsets.ts +1 -1
  336. package/src/features/install-referrer/installReferrer.ts +3 -3
  337. package/src/features/journey/calibrationContext.ts +0 -9
  338. package/src/features/journey/journeyManager.ts +3 -1
  339. package/src/features/navigation/AutoScreenDetector.ts +4 -4
  340. package/src/features/ota/OtaOrchestrator.ts +18 -18
  341. package/src/features/ota/geoCountry.ts +2 -2
  342. package/src/features/ota/retry.ts +2 -2
  343. package/src/features/replay/core/logger/logger.ts +0 -4
  344. package/src/features/replay/integrations/network/networkAdapter.ts +1 -56
  345. package/src/features/replay/integrations/react-navigation/navigationIntegration.ts +1 -1
  346. package/src/features/replay/integrations/touch/ReplayRoot.tsx +1 -1
  347. package/src/features/replay/pipeline/batching/batchManager.ts +1 -1
  348. package/src/features/replay/pipeline/retry/retryPolicy.ts +1 -1
  349. package/src/features/replay/public/api.ts +7 -7
  350. package/src/features/replay/replay/session/sessionOrchestrator.ts +9 -9
  351. package/src/features/session/BackendSessionAdapter.ts +41 -41
  352. package/src/features/session/DesktopSessionTransport.ts +4 -2
  353. package/src/features/session/JourneyEventPipeline.ts +1 -1
  354. package/src/features/session/ReplayCaptureManager.ts +14 -14
  355. package/src/features/session/SessionManager.ts +9 -9
  356. package/src/features/session/SyncDecisionEngine.ts +1 -1
  357. package/src/features/skan/skanBridge.ts +6 -14
  358. package/src/features/skan/skanConversionManager.ts +5 -5
  359. package/src/integrations/fetch/fetchInterceptor.ts +1 -1
  360. package/src/integrations/xhr/xhrInterceptor.ts +1 -1
  361. package/src/metro/composeSourceMap.ts +104 -0
  362. package/src/metro/featureModules.ts +143 -0
  363. package/src/metro/index.ts +173 -1
  364. package/src/metro/serializerCompose.ts +157 -0
  365. package/src/pipeline/dispatcher/dispatcher.ts +1 -1
  366. package/src/pipeline/queue/flushQueue.ts +2 -2
  367. package/src/pipeline/queue/persistentQueue.ts +6 -35
  368. package/src/pipeline/scheduler/flushScheduler.ts +1 -1
  369. package/src/public/ScaleBunFacade.ts +15 -15
  370. package/src/push/PushManager.ts +3 -3
  371. package/src/push/adapters/NativeBridgeAdapter.ts +1 -1
  372. package/src/push/native/nativeNotifications.ts +7 -16
  373. package/src/storage/StorageBackend.ts +1 -1
@@ -0,0 +1,104 @@
1
+ /**
2
+ * ScaleBun SDK — source-map composition for the pre-bundled artifact.
3
+ *
4
+ * The SDK ships as one scope-hoisted file (dist/scalebun.*.js). Metro's map therefore resolves
5
+ * every SDK frame to that single generated file, and Metro cannot chain the artifact's own map
6
+ * (no inputSourceMap support anywhere in metro-transform-worker). Left like that, a production
7
+ * crash inside the SDK symbolicates to one opaque file:line — for a crash-reporting SDK that is
8
+ * self-sabotage.
9
+ *
10
+ * This module performs the missing chain step: every mapping in the app's final map that lands in
11
+ * a ScaleBun artifact is re-resolved through the artifact's stage-2 map (which itself chains via
12
+ * bob's per-file maps back to the original TypeScript). It runs inside `withScaleBun`'s
13
+ * serializer wrapper, so the .map Metro writes to disk is already correct — for ScaleBun's own
14
+ * backend and for any third-party tool the host uploads maps to, with zero consumer action.
15
+ *
16
+ * Node-only (metro.config.js context). Never part of the app bundle.
17
+ */
18
+ import * as fs from 'fs';
19
+ import * as path from 'path';
20
+
21
+ import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping';
22
+ import { decode, encode } from '@jridgewell/sourcemap-codec';
23
+
24
+ export interface ArtifactMapping {
25
+ /** Absolute path of the pre-bundled artifact as Metro resolved it. */
26
+ artifactPath: string;
27
+ /** Absolute path of the artifact's stage-2 source map. */
28
+ mapPath: string;
29
+ }
30
+
31
+ interface MutableSourceMap {
32
+ version: number;
33
+ sources: (string | null)[];
34
+ sourcesContent?: (string | null)[];
35
+ names: string[];
36
+ mappings: string;
37
+ [key: string]: unknown;
38
+ }
39
+
40
+ const normalize = (p: string): string => p.replace(/\\/g, '/');
41
+
42
+ /**
43
+ * Rewrite `metroMap` so mappings pointing into any of `artifacts` resolve through that artifact's
44
+ * stage-2 map. Returns the number of rewritten segments (0 = nothing matched, map returned as-is).
45
+ *
46
+ * The input object is mutated and returned — serialization happens exactly once, in the caller.
47
+ */
48
+ export function composeSourceMap(
49
+ metroMap: MutableSourceMap,
50
+ artifacts: readonly ArtifactMapping[],
51
+ ): { map: MutableSourceMap; rewritten: number } {
52
+ // Index of each artifact in the outer map's source list, if present at all.
53
+ const byIndex = new Map<number, { trace: TraceMap; mapDir: string }>();
54
+ for (const { artifactPath, mapPath } of artifacts) {
55
+ const wanted = normalize(artifactPath);
56
+ const idx = metroMap.sources.findIndex(s => s != null && normalize(s) === wanted);
57
+ if (idx < 0) continue;
58
+ const trace = new TraceMap(JSON.parse(fs.readFileSync(mapPath, 'utf8')));
59
+ byIndex.set(idx, { trace, mapDir: path.dirname(mapPath) });
60
+ }
61
+ if (byIndex.size === 0) return { map: metroMap, rewritten: 0 };
62
+
63
+ const sourcesContent = (metroMap.sourcesContent ??= []);
64
+ while (sourcesContent.length < metroMap.sources.length) sourcesContent.push(null);
65
+
66
+ /** stage-2 source (resolved against its map's directory) → index in the outer source list. */
67
+ const appended = new Map<string, number>();
68
+ const indexFor = (mapDir: string, source: string, content: string | null): number => {
69
+ // build-dist rewrites stage-2 sources to package-relative "src/…", and the maps live in
70
+ // <packageRoot>/dist — so resolve against the map directory's PARENT to yield
71
+ // "<packageRoot>/src/…" like every other absolute path in the outer map.
72
+ const abs = normalize(path.resolve(path.dirname(mapDir), source));
73
+ const hit = appended.get(abs);
74
+ if (hit !== undefined) return hit;
75
+ metroMap.sources.push(abs);
76
+ sourcesContent.push(content);
77
+ const idx = metroMap.sources.length - 1;
78
+ appended.set(abs, idx);
79
+ return idx;
80
+ };
81
+
82
+ const decoded = decode(metroMap.mappings);
83
+ let rewritten = 0;
84
+ for (const line of decoded) {
85
+ for (const seg of line) {
86
+ if (seg.length < 4) continue;
87
+ const hit = byIndex.get(seg[1]!);
88
+ if (!hit) continue;
89
+ const pos = originalPositionFor(hit.trace, { line: seg[2]! + 1, column: seg[3]! });
90
+ if (pos.source == null || pos.line == null) continue;
91
+ const srcIdx = hit.trace.resolvedSources.indexOf(pos.source);
92
+ const content = srcIdx >= 0 ? (hit.trace.sourcesContent?.[srcIdx] ?? null) : null;
93
+ seg[1] = indexFor(hit.mapDir, pos.source, content);
94
+ seg[2] = pos.line - 1;
95
+ seg[3] = pos.column;
96
+ // Drop the name index: it refers to the outer map's name table, which is meaningless
97
+ // for a position that now lives in the stage-2 map's coordinate space.
98
+ if (seg.length === 5) (seg as unknown as number[]).length = 4;
99
+ rewritten++;
100
+ }
101
+ }
102
+ metroMap.mappings = encode(decoded);
103
+ return { map: metroMap, rewritten };
104
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * ScaleBun SDK — Build-time excludable feature registry.
3
+ *
4
+ * Metro has NO tree shaking: every module reachable from the entry point is bundled regardless of
5
+ * whether it is ever imported by name or ever executed. Measured on this SDK, importing a single
6
+ * tiny function instead of the whole facade changed the bundle by 115 bytes. So the only way a
7
+ * consumer can stop paying for a subsystem they do not use is to make it unreachable at RESOLUTION
8
+ * time, which is what `withScaleBun`'s `features` option does.
9
+ *
10
+ * Each entry lists module paths RELATIVE TO THE PACKAGE ROOT, without extension and without the
11
+ * `lib/module` / `lib/commonjs` / `src` prefix, so one list covers every build output.
12
+ *
13
+ * IMPORTANT: a module belongs here only if it is genuinely unreachable when the feature is off.
14
+ * `debug/` is the cautionary case — it also contains PRODUCTION code:
15
+ * - `debug/redaction` → redactBody / redactNetworkEvent, used by SessionManager,
16
+ * persistentQueue and both network interceptors. Removing it would
17
+ * silently disable payload redaction. It is NOT listed here.
18
+ * - `debug/protocol` → PROTOCOL_VERSION, imported as a VALUE by journeyManager and
19
+ * DesktopSessionTransport. NOT listed here.
20
+ * - `debug/screenTracking` → getTrackedScreen, used by NetworkFeature. NOT listed here.
21
+ * - `debug/bootstrap` → re-exported from the package entry point. NOT listed here; it is
22
+ * instead guarded at runtime (see enableDebug).
23
+ */
24
+
25
+ /**
26
+ * The desktop-debugger tooling: a WebSocket bridge to the ScaleBun desktop app, the command
27
+ * registry it drives, the event stream it consumes, and the profiler that only it initialises.
28
+ *
29
+ * `debug/transport` is included because every importer outside `debug/bootstrap` uses
30
+ * `import type`, which is erased at compile time — bootstrap is its only value consumer, and
31
+ * bootstrap degrades gracefully when the tooling is absent.
32
+ *
33
+ * `features/profiler/` is included because nothing outside `debug/` references ProfilerFeature.
34
+ */
35
+ const DEV_TOOLS_MODULES = [
36
+ // Reached only from inside enableDebug(), which returns early when the tooling is absent, or
37
+ // through accessors that read a module-level variable left at null (`_getStream`,
38
+ // `_getCommands`, `_getTransport`) or optional-chain it (`_setFlushFn`, `addBreadcrumb`,
39
+ // `ping`, `_perf?.stop()`). None of them call into these modules directly.
40
+ 'debug/commands',
41
+ 'debug/stream',
42
+ 'debug/transport',
43
+ 'debug/perf',
44
+ 'debug/hostResolver',
45
+ 'debug/perfWiring',
46
+ 'debug/sessionWiring',
47
+
48
+ // Profiler is unreachable once perfWiring is gone — nothing outside debug/ imports it.
49
+ 'features/profiler/ProfilerFeature',
50
+ 'features/profiler/ProfilerTransport',
51
+ 'features/profiler/index',
52
+ 'features/profiler/config',
53
+ 'features/profiler/contracts',
54
+ 'features/profiler/models',
55
+
56
+ // DELIBERATELY ABSENT, each verified by reading its callers:
57
+ // debug/replayWiring — `_getReplaySdk()` / `_isReplaySdkInitialized()` call into it
58
+ // unconditionally, outside any enable/disable guard.
59
+ // debug/exportBridge — `requestExport()` / `_handleExportResult()` likewise.
60
+ // debug/configBuilder — ScaleBunFacade calls applyFeatureGatesToDebugConfig() BEFORE
61
+ // bootstrap's guard can run.
62
+ // debug/metrics — `ScaleBun.debug.sendMetric()` is public API and is NOT wrapped in
63
+ // noThrow, so a stub would throw straight into caller code.
64
+ ] as const;
65
+
66
+ /**
67
+ * Feature name → the modules that become unreachable when it is disabled.
68
+ *
69
+ * Keep this narrow and evidence-backed. Every addition must be justified by checking who actually
70
+ * imports the module, distinguishing `import type` (erased) from a value import (not erased).
71
+ */
72
+ export const SCALEBUN_FEATURE_MODULES: Readonly<Record<string, readonly string[]>> = {
73
+ /**
74
+ * Desktop-debugger tooling. Disabling it means `ScaleBun.init({ debugConnection })` no longer
75
+ * connects in that build; the SDK logs one clear warning and continues. All analytics, session,
76
+ * replay, crash, network and redaction behaviour is unaffected.
77
+ *
78
+ * Measured saving: 52,138 bytes of minified JavaScript in a production Android bundle.
79
+ */
80
+ devTools: DEV_TOOLS_MODULES,
81
+ };
82
+
83
+ export type ScaleBunFeatureName = keyof typeof SCALEBUN_FEATURE_MODULES;
84
+
85
+ /**
86
+ * Per-feature default when the host's config does not mention it.
87
+ *
88
+ * `devTools` defaults to OFF: the desktop debugger it talks to is a future product — no
89
+ * counterpart exists yet anywhere, so today the tooling can only ever dial a socket nobody is
90
+ * listening on, retry, and give up. Shipping 53 KB of that in every app by default was pure waste.
91
+ * When the desktop app ships, hosts opt in with `features: { devTools: true }` (and the default
92
+ * here may flip back).
93
+ */
94
+ const FEATURE_DEFAULTS: Readonly<Record<ScaleBunFeatureName, boolean>> = {
95
+ devTools: false,
96
+ };
97
+
98
+ /**
99
+ * Build the set of module suffixes to exclude for a given feature configuration.
100
+ *
101
+ * Every known feature is resolved: an explicit `true`/`false` in `features` wins, otherwise the
102
+ * feature's default applies. Unknown names throw — a typo here would silently ship (or silently
103
+ * keep) code the caller believed they had configured, so it is an error rather than a warning.
104
+ */
105
+ export function resolveExcludedModules(
106
+ features: Readonly<Record<string, boolean | undefined>> | undefined,
107
+ ): ReadonlySet<string> {
108
+ for (const name of Object.keys(features ?? {})) {
109
+ if (!SCALEBUN_FEATURE_MODULES[name]) {
110
+ throw new Error(
111
+ `[scalebun/metro] Unknown feature "${name}". Known features: ` +
112
+ `${Object.keys(SCALEBUN_FEATURE_MODULES).join(', ')}.`,
113
+ );
114
+ }
115
+ }
116
+
117
+ const excluded = new Set<string>();
118
+ for (const [name, modules] of Object.entries(SCALEBUN_FEATURE_MODULES)) {
119
+ const enabled = features?.[name] ?? FEATURE_DEFAULTS[name as ScaleBunFeatureName] ?? true;
120
+ if (enabled) continue;
121
+ for (const m of modules) excluded.add(m);
122
+ }
123
+ return excluded;
124
+ }
125
+
126
+ /**
127
+ * Does `filePath` correspond to one of the excluded module paths?
128
+ *
129
+ * Matches against the tail of the path so a single registry entry covers `lib/module/…​.js`,
130
+ * `lib/commonjs/…​.js` and `src/…​.ts`. Callers MUST have already confirmed the file lives inside
131
+ * the ScaleBun package — matching on the tail alone would also match a host application's own
132
+ * `debug/commands.js`, which must never be stubbed.
133
+ */
134
+ export function isExcludedModule(filePath: string, excluded: ReadonlySet<string>): boolean {
135
+ if (excluded.size === 0) return false;
136
+ const normalized = filePath.replace(/\\/g, '/');
137
+ // Drop the extension so 'debug/commands' matches commands.js, commands.ts and commands.tsx.
138
+ const withoutExt = normalized.replace(/\.[cm]?[jt]sx?$/, '');
139
+ for (const suffix of excluded) {
140
+ if (withoutExt.endsWith('/' + suffix)) return true;
141
+ }
142
+ return false;
143
+ }
@@ -25,7 +25,17 @@
25
25
  * otherwise the original resolution error is rethrown.
26
26
  */
27
27
 
28
+ import * as nodePath from 'path';
29
+ import * as nodeFs from 'fs';
30
+
28
31
  import { SCALEBUN_OPTIONAL_MODULES } from './optionalModules';
32
+ import { isExcludedModule, resolveExcludedModules } from './featureModules';
33
+ import {
34
+ createComposingSerializer,
35
+ discoverArtifacts,
36
+ resolveMetroInternals,
37
+ type MetroSerializer,
38
+ } from './serializerCompose';
29
39
 
30
40
  // Minimal structural types for the slice of Metro's resolver API we touch. We
31
41
  // avoid a hard dependency on `metro`/`metro-resolver` types so the helper builds
@@ -74,6 +84,29 @@ export interface WithScaleBunOptions {
74
84
  * installing — never to silence unrelated missing modules.
75
85
  */
76
86
  optionalModules?: readonly string[];
87
+
88
+ /**
89
+ * Per-subsystem bundling switches. Metro performs no tree shaking, so a subsystem you never
90
+ * call is still bundled in full; resolution-time exclusion is the only mechanism that removes
91
+ * it. See ./featureModules for the module list behind each name and, importantly, for what
92
+ * deliberately stays (redaction, protocol constants and screen tracking live under `debug/`
93
+ * but are production code).
94
+ *
95
+ * | feature | contents | default | measured cost |
96
+ * |------------|---------------------------------------|---------|---------------|
97
+ * | `devTools` | desktop-debugger bridge + profiler | OFF | ~53 KB |
98
+ *
99
+ * `devTools` is OFF by default because the ScaleBun desktop debugger is a future product —
100
+ * no counterpart exists yet, so the tooling can only dial a socket nobody is listening on.
101
+ * When the desktop app ships, opt in with:
102
+ *
103
+ * withScaleBun(config, { features: { devTools: true } })
104
+ *
105
+ * In a devTools-excluded bundle, `ScaleBun.init({ debugConnection })` logs one clear warning
106
+ * and continues; every production feature (analytics, sessions, replay, crash, network
107
+ * capture, redaction, Engage, OTA, push) is unaffected — verified by differential test.
108
+ */
109
+ features?: Readonly<Record<string, boolean | undefined>>;
77
110
  }
78
111
 
79
112
  /**
@@ -95,6 +128,56 @@ function resolveStubPath(): string {
95
128
  }
96
129
  }
97
130
 
131
+ /**
132
+ * Absolute path to this package's root, found by walking up from this file until a package.json
133
+ * naming this package appears.
134
+ *
135
+ * Computed by search rather than a fixed number of `..` segments because this module is emitted to
136
+ * different depths (`lib/commonjs/metro/` when published, `src/metro/` under ts-jest), and a
137
+ * hard-coded depth would silently resolve to the wrong directory in one of them.
138
+ *
139
+ * Returns null if the root cannot be identified, in which case feature exclusion is skipped
140
+ * entirely — stubbing on a tail match alone could hit a host application's own files.
141
+ */
142
+ function findPackageRoot(): string | null {
143
+ let dir = __dirname;
144
+ for (let i = 0; i < 10; i++) {
145
+ try {
146
+ const manifest = nodePath.join(dir, 'package.json');
147
+ if (nodeFs.existsSync(manifest)) {
148
+ const name = JSON.parse(nodeFs.readFileSync(manifest, 'utf8'))?.name;
149
+ if (name === '@scalebun/react-native') return nodeFs.realpathSync(dir);
150
+ }
151
+ } catch {
152
+ // Unreadable/malformed manifest — keep walking rather than failing the whole build.
153
+ }
154
+ const parent = nodePath.dirname(dir);
155
+ if (parent === dir) break;
156
+ dir = parent;
157
+ }
158
+ return null;
159
+ }
160
+
161
+ /**
162
+ * Is `filePath` inside this package?
163
+ *
164
+ * Both sides are realpath'd because pnpm and npm workspaces symlink the package into
165
+ * `node_modules`, so Metro can hand back a path through the symlink while the package root was
166
+ * discovered through the store — a plain prefix comparison would then miss and quietly disable
167
+ * exclusion. Falls back to the raw path when realpath fails (file may not exist yet).
168
+ */
169
+ function isInsidePackage(filePath: string, packageRoot: string): boolean {
170
+ let real = filePath;
171
+ try {
172
+ real = nodeFs.realpathSync(filePath);
173
+ } catch {
174
+ // Keep the original path; the relative check below still gives a correct answer for
175
+ // anything that genuinely lives under the package root.
176
+ }
177
+ const rel = nodePath.relative(packageRoot, real);
178
+ return rel !== '' && !rel.startsWith('..') && !nodePath.isAbsolute(rel);
179
+ }
180
+
98
181
  /**
99
182
  * Wrap a Metro configuration so the SDK's optional integration packages resolve
100
183
  * to an empty stub when they are not installed.
@@ -120,6 +203,36 @@ export function withScaleBun<T extends MetroConfigLike>(
120
203
  ...(options.optionalModules ?? []),
121
204
  ]);
122
205
 
206
+ // Throws on an unknown feature name, at config load, rather than silently shipping code the
207
+ // caller believed they had excluded.
208
+ const excludedModules = resolveExcludedModules(options.features);
209
+ const packageRoot = findPackageRoot();
210
+
211
+ if (excludedModules.size > 0 && packageRoot == null) {
212
+ throw new Error(
213
+ '[scalebun/metro] features were requested but the @scalebun/react-native package root ' +
214
+ 'could not be located from ' +
215
+ __dirname +
216
+ '. Refusing to exclude modules by path suffix alone, because that could stub files ' +
217
+ "belonging to your own app. Reinstall the package, or drop the `features` option.",
218
+ );
219
+ }
220
+
221
+ // The pre-bundled artifacts. Package exports resolve "@scalebun/react-native" to the slim one;
222
+ // `features: { devTools: true }` redirects to the full one below. When the package was built
223
+ // without dist/ (working from raw source), both lists are empty and every dist-dependent
224
+ // behaviour degrades to the per-file lib/ path.
225
+ const artifacts = packageRoot ? discoverArtifacts(packageRoot) : [];
226
+ const fullArtifact = artifacts.find(a => a.artifactPath.endsWith('scalebun.full.js'));
227
+ const wantsDevTools = options.features?.devTools === true;
228
+
229
+ if (wantsDevTools && artifacts.length > 0 && !fullArtifact) {
230
+ throw new Error(
231
+ '[scalebun/metro] features.devTools is true but dist/scalebun.full.js is missing from ' +
232
+ 'the installed package. Reinstall @scalebun/react-native.',
233
+ );
234
+ }
235
+
123
236
  // Preserve a host-provided resolver so aliases, monorepo/PnP, SVG, NativeWind,
124
237
  // Storybook, Expo, etc. keep working. We call it first and only add a fallback.
125
238
  const hostResolveRequest = config.resolver?.resolveRequest;
@@ -137,8 +250,16 @@ export function withScaleBun<T extends MetroConfigLike>(
137
250
  );
138
251
  }
139
252
 
253
+ // devTools opt-in: the package's exports point at the slim artifact, so the full one is
254
+ // reachable only through this redirect. Matching the bare specifier is safe here — it is
255
+ // the package's own name, which nothing else can legitimately claim.
256
+ if (wantsDevTools && fullArtifact && moduleName === '@scalebun/react-native') {
257
+ return { type: 'sourceFile', filePath: fullArtifact.artifactPath };
258
+ }
259
+
260
+ let resolution: MetroResolution;
140
261
  try {
141
- return baseResolve(context, moduleName, platform);
262
+ resolution = baseResolve(context, moduleName, platform);
142
263
  } catch (error) {
143
264
  if (optionalModules.has(moduleName)) {
144
265
  // Known ScaleBun optional integration, not installed → empty stub.
@@ -147,14 +268,65 @@ export function withScaleBun<T extends MetroConfigLike>(
147
268
  // Unrelated module: preserve Metro's original failure exactly.
148
269
  throw error;
149
270
  }
271
+
272
+ // Feature exclusion is decided on the RESOLVED path, never on the request string: one
273
+ // module is reached through many different relative specifiers, and only a resolved path
274
+ // can be confirmed to live inside this package. That containment check is the safety
275
+ // property — a tail match alone would also stub a host app's own `debug/commands.js`.
276
+ if (
277
+ packageRoot != null &&
278
+ resolution != null &&
279
+ resolution.type === 'sourceFile' &&
280
+ typeof resolution.filePath === 'string' &&
281
+ isInsidePackage(resolution.filePath, packageRoot) &&
282
+ isExcludedModule(resolution.filePath, excludedModules)
283
+ ) {
284
+ return { type: 'sourceFile', filePath: stubPath };
285
+ }
286
+
287
+ return resolution;
150
288
  };
151
289
 
290
+ // ── Source-map composition (symbolication correct by default) ───────────────────────────
291
+ // The pre-bundled artifact collapses SDK frames to one generated file in Metro's map, and
292
+ // Metro cannot chain input maps. Wrapping the serializer here means the .map every consumer
293
+ // build writes already resolves SDK frames to original TypeScript — wherever it is uploaded.
294
+ let serializerConfig = (config as { serializer?: { customSerializer?: unknown } }).serializer;
295
+ if (artifacts.length > 0) {
296
+ // Anchor metro resolution at the app: its projectRoot when the config carries one, else
297
+ // the bundling process's cwd (react-native CLI runs from the app root).
298
+ const projectRoot = (config as { projectRoot?: unknown }).projectRoot;
299
+ const internals = resolveMetroInternals([
300
+ ...(typeof projectRoot === 'string' ? [projectRoot] : []),
301
+ process.cwd(),
302
+ ]);
303
+ if (internals == null) {
304
+ // eslint-disable-next-line no-console
305
+ console.warn(
306
+ '[scalebun/metro] Could not load Metro serialization internals from this Metro ' +
307
+ "version, so ScaleBun's source-map composition is disabled. Builds work, but " +
308
+ 'SDK stack frames will symbolicate to the bundled artifact instead of original ' +
309
+ 'sources. Please report your Metro version to ScaleBun.',
310
+ );
311
+ } else {
312
+ serializerConfig = {
313
+ ...serializerConfig,
314
+ customSerializer: createComposingSerializer(
315
+ artifacts,
316
+ internals,
317
+ serializerConfig?.customSerializer as MetroSerializer | undefined,
318
+ ),
319
+ };
320
+ }
321
+ }
322
+
152
323
  return {
153
324
  ...config,
154
325
  resolver: {
155
326
  ...config.resolver,
156
327
  resolveRequest,
157
328
  },
329
+ ...(serializerConfig !== undefined ? { serializer: serializerConfig } : {}),
158
330
  };
159
331
  }
160
332
 
@@ -0,0 +1,157 @@
1
+ /**
2
+ * ScaleBun SDK — Metro serializer wrapper that emits a COMPOSED source map.
3
+ *
4
+ * Attached by `withScaleBun`. Reproduces Metro's default serialization (the exact calls
5
+ * Server.js makes when no custom serializer is configured), then rewrites every mapping that
6
+ * lands in a ScaleBun pre-bundled artifact through that artifact's stage-2 map, so the .map the
7
+ * build writes resolves SDK frames to original TypeScript — by default, for every consumer.
8
+ *
9
+ * Cooperation with a host-configured serializer: the host runs first and its code output is
10
+ * respected verbatim. If it returned its own map, that map is composed; if it returned only a
11
+ * string, the map is built from the graph exactly as Metro itself would have, then composed —
12
+ * either way the host loses nothing and gains correct SDK frames.
13
+ *
14
+ * Metro's serialization internals are reached through the "./private/*" exports alias
15
+ * (Metro >= 0.80.6) with a fallback to the bare "./src/*" paths older versions expose. If
16
+ * neither resolves, the wrapper is NOT attached and one warning explains what degrades —
17
+ * bundling must never fail because symbolication couldn't be improved.
18
+ */
19
+ import * as fs from 'fs';
20
+ import * as path from 'path';
21
+
22
+ import { composeSourceMap, type ArtifactMapping } from './composeSourceMap';
23
+
24
+ // ─── Minimal structural types for the slice of Metro's serializer API we touch ─────────────────
25
+
26
+ type MetroModule = { path: string };
27
+
28
+ export interface MetroSerializerOptions {
29
+ createModuleId: (filePath: string) => number;
30
+ excludeSource?: boolean;
31
+ processModuleFilter?: (module: MetroModule) => boolean;
32
+ shouldAddToIgnoreList?: (module: MetroModule) => boolean;
33
+ getSourceUrl?: (module: MetroModule) => string;
34
+ [key: string]: unknown;
35
+ }
36
+
37
+ export type MetroSerializerResult = string | { code: string; map: string };
38
+
39
+ export type MetroSerializer = (
40
+ entryPoint: string,
41
+ preModules: readonly MetroModule[],
42
+ graph: { dependencies: Map<string, MetroModule> },
43
+ options: MetroSerializerOptions,
44
+ ) => MetroSerializerResult | Promise<MetroSerializerResult>;
45
+
46
+ interface MetroInternals {
47
+ baseJSBundle: (
48
+ entryPoint: string,
49
+ preModules: readonly MetroModule[],
50
+ graph: { dependencies: Map<string, MetroModule> },
51
+ options: MetroSerializerOptions,
52
+ ) => unknown;
53
+ bundleToString: (bundle: unknown) => { code: string };
54
+ sourceMapObject: (modules: readonly MetroModule[], options: object) => object;
55
+ }
56
+
57
+ /**
58
+ * Resolve Metro's serialization helpers from the HOST's Metro install. Returns null when they
59
+ * cannot be found (exotic Metro version/layout) — callers must degrade gracefully.
60
+ *
61
+ * Resolution is anchored at the APP (project root / cwd), never at this package's own location:
62
+ * `metro` is not a dependency of the SDK, so under pnpm's strict layout a bare require from here
63
+ * finds nothing — and even where it would resolve, the app's Metro is the one whose serializer
64
+ * contract must be matched, not whichever copy happens to sit near the SDK.
65
+ */
66
+ export function resolveMetroInternals(searchPaths: readonly string[]): MetroInternals | null {
67
+ const paths = [...searchPaths.filter(Boolean)];
68
+ const req = (spec: string): unknown => require(require.resolve(spec, { paths }));
69
+ for (const prefix of ['metro/private', 'metro/src']) {
70
+ try {
71
+ const base = req(`${prefix}/DeltaBundler/Serializers/baseJSBundle`) as {
72
+ default?: unknown;
73
+ };
74
+ const bts = req(`${prefix}/lib/bundleToString`) as { default?: unknown };
75
+ const smo = req(`${prefix}/DeltaBundler/Serializers/sourceMapObject`) as {
76
+ sourceMapObject?: unknown;
77
+ default?: unknown;
78
+ };
79
+ const baseJSBundle = base.default ?? base;
80
+ const bundleToString = bts.default ?? bts;
81
+ const sourceMapObject = smo.sourceMapObject ?? smo.default ?? smo;
82
+ if (
83
+ typeof baseJSBundle === 'function' &&
84
+ typeof bundleToString === 'function' &&
85
+ typeof sourceMapObject === 'function'
86
+ ) {
87
+ return { baseJSBundle, bundleToString, sourceMapObject } as MetroInternals;
88
+ }
89
+ } catch {
90
+ // try the next prefix
91
+ }
92
+ }
93
+ return null;
94
+ }
95
+
96
+ /** The artifacts a package root can contain, with existence checked once at config time. */
97
+ export function discoverArtifacts(packageRoot: string): ArtifactMapping[] {
98
+ const out: ArtifactMapping[] = [];
99
+ for (const name of ['scalebun.slim.js', 'scalebun.full.js']) {
100
+ const artifactPath = path.join(packageRoot, 'dist', name);
101
+ const mapPath = artifactPath + '.map';
102
+ if (fs.existsSync(artifactPath) && fs.existsSync(mapPath)) {
103
+ out.push({ artifactPath, mapPath });
104
+ }
105
+ }
106
+ return out;
107
+ }
108
+
109
+ /**
110
+ * Build the composing serializer. `hostSerializer` is the app's own customSerializer, if any.
111
+ */
112
+ export function createComposingSerializer(
113
+ artifacts: readonly ArtifactMapping[],
114
+ internals: MetroInternals,
115
+ hostSerializer: MetroSerializer | undefined,
116
+ ): MetroSerializer {
117
+ return async (entryPoint, preModules, graph, options) => {
118
+ let code: string;
119
+ let mapObj: object | null = null;
120
+
121
+ if (hostSerializer) {
122
+ const hostResult = await hostSerializer(entryPoint, preModules, graph, options);
123
+ if (typeof hostResult === 'string') {
124
+ code = hostResult;
125
+ } else {
126
+ code = hostResult.code;
127
+ try {
128
+ mapObj = JSON.parse(hostResult.map);
129
+ } catch {
130
+ // Host emitted an unparsable map; fall through and rebuild from the graph so
131
+ // the build still succeeds with a correct map rather than failing here.
132
+ mapObj = null;
133
+ }
134
+ }
135
+ } else {
136
+ code = internals.bundleToString(
137
+ internals.baseJSBundle(entryPoint, preModules, graph, options),
138
+ ).code;
139
+ }
140
+
141
+ if (mapObj == null) {
142
+ // Metro's own fallback, replicated: modules sorted by module id, same options.
143
+ const modules = [...graph.dependencies.values()].sort(
144
+ (a, b) => options.createModuleId(a.path) - options.createModuleId(b.path),
145
+ );
146
+ mapObj = internals.sourceMapObject([...preModules, ...modules], {
147
+ excludeSource: options.excludeSource,
148
+ processModuleFilter: options.processModuleFilter,
149
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
150
+ getSourceUrl: options.getSourceUrl,
151
+ });
152
+ }
153
+
154
+ const { map } = composeSourceMap(mapObj as never, artifacts);
155
+ return { code, map: JSON.stringify(map) };
156
+ };
157
+ }
@@ -11,7 +11,7 @@ export class Dispatcher {
11
11
 
12
12
  try {
13
13
  await this.transport(batch);
14
- logger.info(`Successfully dispatched batch of ${batch.length} events`);
14
+ __DEV__ && logger.info(`Successfully dispatched batch of ${batch.length} events`);
15
15
  } catch (err) {
16
16
  logger.error('Failed to dispatch batch, returning to queue', err);
17
17
  // Re-queue items on failure
@@ -34,7 +34,7 @@ export async function flushQueue(
34
34
  headers?: Record<string, string>,
35
35
  ): Promise<FlushResult> {
36
36
  if (inFlight.has(queue)) {
37
- logger.debug('[Flush] Skipped — a flush is already in progress');
37
+ __DEV__ && logger.debug('[Flush] Skipped — a flush is already in progress');
38
38
  return { status: 'skipped', batchSize: 0 };
39
39
  }
40
40
 
@@ -77,7 +77,7 @@ export async function flushQueue(
77
77
  }
78
78
 
79
79
  failureStreak.delete(queue);
80
- logger.info(`Successfully flushed ${batch.length} events`);
80
+ __DEV__ && logger.info(`Successfully flushed ${batch.length} events`);
81
81
  return { status: 'flushed', batchSize: batch.length };
82
82
  } catch (err) {
83
83
  if (isRecoverableFlushError(err)) {