@scalebun/react-native 1.1.0 → 1.2.1

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 (380) hide show
  1. package/dist/scalebun.full.js +33218 -0
  2. package/dist/scalebun.full.js.map +1 -0
  3. package/dist/scalebun.slim.js +30016 -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/performance/PerformanceFeature.js +121 -23
  78. package/lib/commonjs/features/performance/PerformanceFeature.js.map +1 -1
  79. package/lib/commonjs/features/replay/core/logger/logger.js +0 -4
  80. package/lib/commonjs/features/replay/core/logger/logger.js.map +1 -1
  81. package/lib/commonjs/features/replay/integrations/network/networkAdapter.js +1 -54
  82. package/lib/commonjs/features/replay/integrations/network/networkAdapter.js.map +1 -1
  83. package/lib/commonjs/features/replay/integrations/react-navigation/navigationIntegration.js +1 -1
  84. package/lib/commonjs/features/replay/integrations/react-navigation/navigationIntegration.js.map +1 -1
  85. package/lib/commonjs/features/replay/integrations/touch/ReplayRoot.js +1 -1
  86. package/lib/commonjs/features/replay/integrations/touch/ReplayRoot.js.map +1 -1
  87. package/lib/commonjs/features/replay/pipeline/batching/batchManager.js +1 -1
  88. package/lib/commonjs/features/replay/pipeline/batching/batchManager.js.map +1 -1
  89. package/lib/commonjs/features/replay/pipeline/retry/retryPolicy.js +1 -1
  90. package/lib/commonjs/features/replay/pipeline/retry/retryPolicy.js.map +1 -1
  91. package/lib/commonjs/features/replay/public/api.js +7 -7
  92. package/lib/commonjs/features/replay/public/api.js.map +1 -1
  93. package/lib/commonjs/features/replay/replay/session/sessionOrchestrator.js +9 -9
  94. package/lib/commonjs/features/replay/replay/session/sessionOrchestrator.js.map +1 -1
  95. package/lib/commonjs/features/session/BackendSessionAdapter.js +41 -41
  96. package/lib/commonjs/features/session/BackendSessionAdapter.js.map +1 -1
  97. package/lib/commonjs/features/session/DesktopSessionTransport.js +5 -2
  98. package/lib/commonjs/features/session/DesktopSessionTransport.js.map +1 -1
  99. package/lib/commonjs/features/session/JourneyEventPipeline.js +1 -1
  100. package/lib/commonjs/features/session/JourneyEventPipeline.js.map +1 -1
  101. package/lib/commonjs/features/session/ReplayCaptureManager.js +14 -14
  102. package/lib/commonjs/features/session/ReplayCaptureManager.js.map +1 -1
  103. package/lib/commonjs/features/session/SessionManager.js +9 -9
  104. package/lib/commonjs/features/session/SessionManager.js.map +1 -1
  105. package/lib/commonjs/features/session/SyncDecisionEngine.js +1 -1
  106. package/lib/commonjs/features/session/SyncDecisionEngine.js.map +1 -1
  107. package/lib/commonjs/features/skan/skanBridge.js +6 -15
  108. package/lib/commonjs/features/skan/skanBridge.js.map +1 -1
  109. package/lib/commonjs/features/skan/skanConversionManager.js +5 -5
  110. package/lib/commonjs/features/skan/skanConversionManager.js.map +1 -1
  111. package/lib/commonjs/integrations/fetch/fetchInterceptor.js +1 -1
  112. package/lib/commonjs/integrations/fetch/fetchInterceptor.js.map +1 -1
  113. package/lib/commonjs/integrations/xhr/xhrInterceptor.js +1 -1
  114. package/lib/commonjs/integrations/xhr/xhrInterceptor.js.map +1 -1
  115. package/lib/commonjs/metro/composeSourceMap.js +105 -0
  116. package/lib/commonjs/metro/composeSourceMap.js.map +1 -0
  117. package/lib/commonjs/metro/featureModules.js +131 -0
  118. package/lib/commonjs/metro/featureModules.js.map +1 -0
  119. package/lib/commonjs/metro/index.js +123 -2
  120. package/lib/commonjs/metro/index.js.map +1 -1
  121. package/lib/commonjs/metro/serializerCompose.js +129 -0
  122. package/lib/commonjs/metro/serializerCompose.js.map +1 -0
  123. package/lib/commonjs/pipeline/dispatcher/dispatcher.js +1 -1
  124. package/lib/commonjs/pipeline/dispatcher/dispatcher.js.map +1 -1
  125. package/lib/commonjs/pipeline/queue/flushQueue.js +2 -2
  126. package/lib/commonjs/pipeline/queue/flushQueue.js.map +1 -1
  127. package/lib/commonjs/pipeline/queue/persistentQueue.js +6 -37
  128. package/lib/commonjs/pipeline/queue/persistentQueue.js.map +1 -1
  129. package/lib/commonjs/pipeline/scheduler/flushScheduler.js +1 -1
  130. package/lib/commonjs/pipeline/scheduler/flushScheduler.js.map +1 -1
  131. package/lib/commonjs/public/ScaleBunFacade.js +15 -15
  132. package/lib/commonjs/public/ScaleBunFacade.js.map +1 -1
  133. package/lib/commonjs/push/PushManager.js +3 -3
  134. package/lib/commonjs/push/PushManager.js.map +1 -1
  135. package/lib/commonjs/push/adapters/NativeBridgeAdapter.js +1 -1
  136. package/lib/commonjs/push/adapters/NativeBridgeAdapter.js.map +1 -1
  137. package/lib/commonjs/push/native/nativeNotifications.js +7 -18
  138. package/lib/commonjs/push/native/nativeNotifications.js.map +1 -1
  139. package/lib/commonjs/storage/StorageBackend.js +1 -1
  140. package/lib/commonjs/storage/StorageBackend.js.map +1 -1
  141. package/lib/module/bootstrap/FeatureRegistry.js +4 -4
  142. package/lib/module/bootstrap/FeatureRegistry.js.map +1 -1
  143. package/lib/module/bootstrap/SDKBootstrapper.js +8 -8
  144. package/lib/module/bootstrap/SDKBootstrapper.js.map +1 -1
  145. package/lib/module/core/config/schema.js +411 -231
  146. package/lib/module/core/config/schema.js.map +1 -1
  147. package/lib/module/core/constants/protocol.js +25 -0
  148. package/lib/module/core/constants/protocol.js.map +1 -0
  149. package/lib/module/core/constants/timings.js +3 -1
  150. package/lib/module/core/constants/timings.js.map +1 -1
  151. package/lib/module/core/lifecycle/appLifecycle.js +1 -1
  152. package/lib/module/core/lifecycle/appLifecycle.js.map +1 -1
  153. package/lib/module/debug/bootstrap.js +30 -9
  154. package/lib/module/debug/bootstrap.js.map +1 -1
  155. package/lib/module/debug/exportBridge.js +5 -3
  156. package/lib/module/debug/exportBridge.js.map +1 -1
  157. package/lib/module/debug/hostResolver.js +2 -2
  158. package/lib/module/debug/hostResolver.js.map +1 -1
  159. package/lib/module/debug/perfWiring.js +4 -4
  160. package/lib/module/debug/perfWiring.js.map +1 -1
  161. package/lib/module/debug/replayWiring.js +5 -5
  162. package/lib/module/debug/replayWiring.js.map +1 -1
  163. package/lib/module/debug/screenTracking.js +2 -2
  164. package/lib/module/debug/screenTracking.js.map +1 -1
  165. package/lib/module/debug/sessionWiring.js +2 -2
  166. package/lib/module/debug/sessionWiring.js.map +1 -1
  167. package/lib/module/features/crash/NativeCrashFeature.js +1 -1
  168. package/lib/module/features/crash/NativeCrashFeature.js.map +1 -1
  169. package/lib/module/features/crash/globalHandler.js +3 -3
  170. package/lib/module/features/crash/globalHandler.js.map +1 -1
  171. package/lib/module/features/crash/nativeCrashBridge.js +7 -7
  172. package/lib/module/features/crash/nativeCrashBridge.js.map +1 -1
  173. package/lib/module/features/crash/rejectionHandler.js +2 -2
  174. package/lib/module/features/crash/rejectionHandler.js.map +1 -1
  175. package/lib/module/features/engage/EngageArchetypeRenderers.js +0 -8
  176. package/lib/module/features/engage/EngageArchetypeRenderers.js.map +1 -1
  177. package/lib/module/features/engage/EngageInAppView.js +1 -1
  178. package/lib/module/features/engage/EngageInAppView.js.map +1 -1
  179. package/lib/module/features/engage/EngagePromptProvider.js +17 -17
  180. package/lib/module/features/engage/EngagePromptProvider.js.map +1 -1
  181. package/lib/module/features/engage/EngageTransport.js +5 -5
  182. package/lib/module/features/engage/EngageTransport.js.map +1 -1
  183. package/lib/module/features/engage/engagePushTokenBridge.js +4 -4
  184. package/lib/module/features/engage/engagePushTokenBridge.js.map +1 -1
  185. package/lib/module/features/engage/engageShakeBridge.js +2 -2
  186. package/lib/module/features/engage/engageShakeBridge.js.map +1 -1
  187. package/lib/module/features/engage/engageSignals.js +1 -1
  188. package/lib/module/features/engage/engageSignals.js.map +1 -1
  189. package/lib/module/features/engage/engageStoreReviewBridge.js +2 -2
  190. package/lib/module/features/engage/engageStoreReviewBridge.js.map +1 -1
  191. package/lib/module/features/engage/engageTestSeenStore.js +1 -1
  192. package/lib/module/features/engage/engageTestSeenStore.js.map +1 -1
  193. package/lib/module/features/engage/engageThrottle.js +4 -4
  194. package/lib/module/features/engage/engageThrottle.js.map +1 -1
  195. package/lib/module/features/engage/engageTriggerEngine.js +4 -4
  196. package/lib/module/features/engage/engageTriggerEngine.js.map +1 -1
  197. package/lib/module/features/engage/engageWindowInsets.js +1 -1
  198. package/lib/module/features/engage/engageWindowInsets.js.map +1 -1
  199. package/lib/module/features/install-referrer/installReferrer.js +3 -3
  200. package/lib/module/features/install-referrer/installReferrer.js.map +1 -1
  201. package/lib/module/features/journey/calibrationContext.js +0 -8
  202. package/lib/module/features/journey/calibrationContext.js.map +1 -1
  203. package/lib/module/features/journey/journeyManager.js +3 -1
  204. package/lib/module/features/journey/journeyManager.js.map +1 -1
  205. package/lib/module/features/navigation/AutoScreenDetector.js +4 -4
  206. package/lib/module/features/navigation/AutoScreenDetector.js.map +1 -1
  207. package/lib/module/features/ota/OtaOrchestrator.js +18 -18
  208. package/lib/module/features/ota/OtaOrchestrator.js.map +1 -1
  209. package/lib/module/features/ota/geoCountry.js +2 -2
  210. package/lib/module/features/ota/geoCountry.js.map +1 -1
  211. package/lib/module/features/ota/retry.js +2 -2
  212. package/lib/module/features/ota/retry.js.map +1 -1
  213. package/lib/module/features/performance/PerformanceFeature.js +122 -23
  214. package/lib/module/features/performance/PerformanceFeature.js.map +1 -1
  215. package/lib/module/features/replay/core/logger/logger.js +0 -3
  216. package/lib/module/features/replay/core/logger/logger.js.map +1 -1
  217. package/lib/module/features/replay/integrations/network/networkAdapter.js +1 -52
  218. package/lib/module/features/replay/integrations/network/networkAdapter.js.map +1 -1
  219. package/lib/module/features/replay/integrations/react-navigation/navigationIntegration.js +1 -1
  220. package/lib/module/features/replay/integrations/react-navigation/navigationIntegration.js.map +1 -1
  221. package/lib/module/features/replay/integrations/touch/ReplayRoot.js +1 -1
  222. package/lib/module/features/replay/integrations/touch/ReplayRoot.js.map +1 -1
  223. package/lib/module/features/replay/pipeline/batching/batchManager.js +1 -1
  224. package/lib/module/features/replay/pipeline/batching/batchManager.js.map +1 -1
  225. package/lib/module/features/replay/pipeline/retry/retryPolicy.js +1 -1
  226. package/lib/module/features/replay/pipeline/retry/retryPolicy.js.map +1 -1
  227. package/lib/module/features/replay/public/api.js +7 -7
  228. package/lib/module/features/replay/public/api.js.map +1 -1
  229. package/lib/module/features/replay/replay/session/sessionOrchestrator.js +9 -9
  230. package/lib/module/features/replay/replay/session/sessionOrchestrator.js.map +1 -1
  231. package/lib/module/features/session/BackendSessionAdapter.js +41 -41
  232. package/lib/module/features/session/BackendSessionAdapter.js.map +1 -1
  233. package/lib/module/features/session/DesktopSessionTransport.js +4 -2
  234. package/lib/module/features/session/DesktopSessionTransport.js.map +1 -1
  235. package/lib/module/features/session/JourneyEventPipeline.js +1 -1
  236. package/lib/module/features/session/JourneyEventPipeline.js.map +1 -1
  237. package/lib/module/features/session/ReplayCaptureManager.js +14 -14
  238. package/lib/module/features/session/ReplayCaptureManager.js.map +1 -1
  239. package/lib/module/features/session/SessionManager.js +9 -9
  240. package/lib/module/features/session/SessionManager.js.map +1 -1
  241. package/lib/module/features/session/SyncDecisionEngine.js +1 -1
  242. package/lib/module/features/session/SyncDecisionEngine.js.map +1 -1
  243. package/lib/module/features/skan/skanBridge.js +6 -14
  244. package/lib/module/features/skan/skanBridge.js.map +1 -1
  245. package/lib/module/features/skan/skanConversionManager.js +5 -5
  246. package/lib/module/features/skan/skanConversionManager.js.map +1 -1
  247. package/lib/module/integrations/fetch/fetchInterceptor.js +1 -1
  248. package/lib/module/integrations/fetch/fetchInterceptor.js.map +1 -1
  249. package/lib/module/integrations/xhr/xhrInterceptor.js +1 -1
  250. package/lib/module/integrations/xhr/xhrInterceptor.js.map +1 -1
  251. package/lib/module/metro/composeSourceMap.js +97 -0
  252. package/lib/module/metro/composeSourceMap.js.map +1 -0
  253. package/lib/module/metro/featureModules.js +123 -0
  254. package/lib/module/metro/featureModules.js.map +1 -0
  255. package/lib/module/metro/index.js +122 -2
  256. package/lib/module/metro/index.js.map +1 -1
  257. package/lib/module/metro/serializerCompose.js +120 -0
  258. package/lib/module/metro/serializerCompose.js.map +1 -0
  259. package/lib/module/pipeline/dispatcher/dispatcher.js +1 -1
  260. package/lib/module/pipeline/dispatcher/dispatcher.js.map +1 -1
  261. package/lib/module/pipeline/queue/flushQueue.js +2 -2
  262. package/lib/module/pipeline/queue/flushQueue.js.map +1 -1
  263. package/lib/module/pipeline/queue/persistentQueue.js +6 -36
  264. package/lib/module/pipeline/queue/persistentQueue.js.map +1 -1
  265. package/lib/module/pipeline/scheduler/flushScheduler.js +1 -1
  266. package/lib/module/pipeline/scheduler/flushScheduler.js.map +1 -1
  267. package/lib/module/public/ScaleBunFacade.js +15 -15
  268. package/lib/module/public/ScaleBunFacade.js.map +1 -1
  269. package/lib/module/push/PushManager.js +3 -3
  270. package/lib/module/push/PushManager.js.map +1 -1
  271. package/lib/module/push/adapters/NativeBridgeAdapter.js +1 -1
  272. package/lib/module/push/adapters/NativeBridgeAdapter.js.map +1 -1
  273. package/lib/module/push/native/nativeNotifications.js +7 -17
  274. package/lib/module/push/native/nativeNotifications.js.map +1 -1
  275. package/lib/module/storage/StorageBackend.js +1 -1
  276. package/lib/module/storage/StorageBackend.js.map +1 -1
  277. package/lib/typescript/core/config/schema.d.ts +61 -40
  278. package/lib/typescript/core/config/schema.d.ts.map +1 -1
  279. package/lib/typescript/core/constants/protocol.d.ts +23 -0
  280. package/lib/typescript/core/constants/protocol.d.ts.map +1 -0
  281. package/lib/typescript/core/constants/timings.d.ts +1 -1
  282. package/lib/typescript/core/constants/timings.d.ts.map +1 -1
  283. package/lib/typescript/debug/bootstrap.d.ts +0 -1
  284. package/lib/typescript/debug/bootstrap.d.ts.map +1 -1
  285. package/lib/typescript/debug/exportBridge.d.ts.map +1 -1
  286. package/lib/typescript/features/engage/EngageArchetypeRenderers.d.ts +0 -2
  287. package/lib/typescript/features/engage/EngageArchetypeRenderers.d.ts.map +1 -1
  288. package/lib/typescript/features/journey/calibrationContext.d.ts +0 -1
  289. package/lib/typescript/features/journey/calibrationContext.d.ts.map +1 -1
  290. package/lib/typescript/features/journey/journeyManager.d.ts.map +1 -1
  291. package/lib/typescript/features/performance/PerformanceFeature.d.ts +31 -0
  292. package/lib/typescript/features/performance/PerformanceFeature.d.ts.map +1 -1
  293. package/lib/typescript/features/replay/core/logger/logger.d.ts +0 -1
  294. package/lib/typescript/features/replay/core/logger/logger.d.ts.map +1 -1
  295. package/lib/typescript/features/replay/integrations/network/networkAdapter.d.ts +0 -10
  296. package/lib/typescript/features/replay/integrations/network/networkAdapter.d.ts.map +1 -1
  297. package/lib/typescript/features/session/DesktopSessionTransport.d.ts.map +1 -1
  298. package/lib/typescript/features/skan/skanBridge.d.ts +0 -2
  299. package/lib/typescript/features/skan/skanBridge.d.ts.map +1 -1
  300. package/lib/typescript/metro/composeSourceMap.d.ts +26 -0
  301. package/lib/typescript/metro/composeSourceMap.d.ts.map +1 -0
  302. package/lib/typescript/metro/featureModules.d.ts +49 -0
  303. package/lib/typescript/metro/featureModules.d.ts.map +1 -0
  304. package/lib/typescript/metro/index.d.ts +22 -0
  305. package/lib/typescript/metro/index.d.ts.map +1 -1
  306. package/lib/typescript/metro/serializerCompose.d.ts +46 -0
  307. package/lib/typescript/metro/serializerCompose.d.ts.map +1 -0
  308. package/lib/typescript/pipeline/queue/persistentQueue.d.ts +0 -10
  309. package/lib/typescript/pipeline/queue/persistentQueue.d.ts.map +1 -1
  310. package/lib/typescript/push/native/nativeNotifications.d.ts +0 -6
  311. package/lib/typescript/push/native/nativeNotifications.d.ts.map +1 -1
  312. package/package.json +15 -11
  313. package/src/bootstrap/FeatureRegistry.ts +4 -4
  314. package/src/bootstrap/SDKBootstrapper.ts +8 -8
  315. package/src/core/config/schema.ts +353 -235
  316. package/src/core/constants/protocol.ts +24 -0
  317. package/src/core/constants/timings.ts +3 -1
  318. package/src/core/lifecycle/appLifecycle.ts +1 -1
  319. package/src/debug/bootstrap.ts +40 -7
  320. package/src/debug/exportBridge.ts +5 -3
  321. package/src/debug/hostResolver.ts +2 -2
  322. package/src/debug/perfWiring.ts +4 -4
  323. package/src/debug/replayWiring.ts +5 -5
  324. package/src/debug/screenTracking.ts +2 -2
  325. package/src/debug/sessionWiring.ts +2 -2
  326. package/src/features/crash/NativeCrashFeature.ts +1 -1
  327. package/src/features/crash/globalHandler.ts +3 -3
  328. package/src/features/crash/nativeCrashBridge.ts +7 -7
  329. package/src/features/crash/rejectionHandler.ts +2 -2
  330. package/src/features/engage/EngageArchetypeRenderers.tsx +0 -11
  331. package/src/features/engage/EngageInAppView.tsx +1 -1
  332. package/src/features/engage/EngagePromptProvider.tsx +17 -17
  333. package/src/features/engage/EngageTransport.ts +5 -5
  334. package/src/features/engage/engagePushTokenBridge.ts +4 -4
  335. package/src/features/engage/engageShakeBridge.ts +2 -2
  336. package/src/features/engage/engageSignals.ts +1 -1
  337. package/src/features/engage/engageStoreReviewBridge.ts +2 -2
  338. package/src/features/engage/engageTestSeenStore.ts +1 -1
  339. package/src/features/engage/engageThrottle.ts +4 -4
  340. package/src/features/engage/engageTriggerEngine.ts +4 -4
  341. package/src/features/engage/engageWindowInsets.ts +1 -1
  342. package/src/features/install-referrer/installReferrer.ts +3 -3
  343. package/src/features/journey/calibrationContext.ts +0 -9
  344. package/src/features/journey/journeyManager.ts +3 -1
  345. package/src/features/navigation/AutoScreenDetector.ts +4 -4
  346. package/src/features/ota/OtaOrchestrator.ts +18 -18
  347. package/src/features/ota/geoCountry.ts +2 -2
  348. package/src/features/ota/retry.ts +2 -2
  349. package/src/features/performance/PerformanceFeature.ts +130 -20
  350. package/src/features/replay/core/logger/logger.ts +0 -4
  351. package/src/features/replay/integrations/network/networkAdapter.ts +1 -56
  352. package/src/features/replay/integrations/react-navigation/navigationIntegration.ts +1 -1
  353. package/src/features/replay/integrations/touch/ReplayRoot.tsx +1 -1
  354. package/src/features/replay/pipeline/batching/batchManager.ts +1 -1
  355. package/src/features/replay/pipeline/retry/retryPolicy.ts +1 -1
  356. package/src/features/replay/public/api.ts +7 -7
  357. package/src/features/replay/replay/session/sessionOrchestrator.ts +9 -9
  358. package/src/features/session/BackendSessionAdapter.ts +41 -41
  359. package/src/features/session/DesktopSessionTransport.ts +4 -2
  360. package/src/features/session/JourneyEventPipeline.ts +1 -1
  361. package/src/features/session/ReplayCaptureManager.ts +14 -14
  362. package/src/features/session/SessionManager.ts +9 -9
  363. package/src/features/session/SyncDecisionEngine.ts +1 -1
  364. package/src/features/skan/skanBridge.ts +6 -14
  365. package/src/features/skan/skanConversionManager.ts +5 -5
  366. package/src/integrations/fetch/fetchInterceptor.ts +1 -1
  367. package/src/integrations/xhr/xhrInterceptor.ts +1 -1
  368. package/src/metro/composeSourceMap.ts +104 -0
  369. package/src/metro/featureModules.ts +143 -0
  370. package/src/metro/index.ts +173 -1
  371. package/src/metro/serializerCompose.ts +157 -0
  372. package/src/pipeline/dispatcher/dispatcher.ts +1 -1
  373. package/src/pipeline/queue/flushQueue.ts +2 -2
  374. package/src/pipeline/queue/persistentQueue.ts +6 -35
  375. package/src/pipeline/scheduler/flushScheduler.ts +1 -1
  376. package/src/public/ScaleBunFacade.ts +15 -15
  377. package/src/push/PushManager.ts +3 -3
  378. package/src/push/adapters/NativeBridgeAdapter.ts +1 -1
  379. package/src/push/native/nativeNotifications.ts +7 -16
  380. package/src/storage/StorageBackend.ts +1 -1
@@ -205,7 +205,7 @@ export class SessionManager {
205
205
  */
206
206
  setBackendTransport(transport: BackendSessionAdapter): void {
207
207
  this._backendTransport = transport;
208
- logger.info('[SessionManager] Backend transport attached (replay → backend upload enabled)');
208
+ __DEV__ && logger.info('[SessionManager] Backend transport attached (replay → backend upload enabled)');
209
209
  }
210
210
 
211
211
  /** Expose the backend transport so features can queue network/errors/performance. */
@@ -235,7 +235,7 @@ export class SessionManager {
235
235
  */
236
236
  setDesktopTransport(debugTransport: DebugTransport): void {
237
237
  this.desktopTransport = new DesktopSessionTransport(debugTransport);
238
- logger.info('[SessionManager] Desktop transport attached');
238
+ __DEV__ && logger.info('[SessionManager] Desktop transport attached');
239
239
  }
240
240
 
241
241
  // ─── Session Lifecycle ──────────────────────────────────────────────
@@ -278,7 +278,7 @@ export class SessionManager {
278
278
  // Hot-swap into active capture manager if session is running
279
279
  if (this.active && this.captureManager) {
280
280
  (this.captureManager as any).nativeCapture = captureFn;
281
- logger.info('[SessionManager] Capture function updated (hot-swap)');
281
+ __DEV__ && logger.info('[SessionManager] Capture function updated (hot-swap)');
282
282
  }
283
283
  }
284
284
 
@@ -288,7 +288,7 @@ export class SessionManager {
288
288
  startSession(metadata?: Partial<SessionMetadata>): void {
289
289
  try {
290
290
  if (this.active) {
291
- logger.debug('[SessionManager] Session already active, skipping start');
291
+ __DEV__ && logger.debug('[SessionManager] Session already active, skipping start');
292
292
  return;
293
293
  }
294
294
 
@@ -461,12 +461,12 @@ export class SessionManager {
461
461
  // Set timeout
462
462
  if (this.config.maxDurationMs > 0) {
463
463
  this.timeoutTimer = setTimeout(() => {
464
- logger.debug('[SessionManager] Session timeout reached');
464
+ __DEV__ && logger.debug('[SessionManager] Session timeout reached');
465
465
  this.endSession('timeout');
466
466
  }, this.config.maxDurationMs);
467
467
  }
468
468
 
469
- logger.info(`[SessionManager] Session started: ${sessionId}`);
469
+ __DEV__ && logger.info(`[SessionManager] Session started: ${sessionId}`);
470
470
 
471
471
  // ── Replay initial screen ──────────────────────────────────────
472
472
  // If the user was already on a screen before pressing Record
@@ -566,7 +566,7 @@ export class SessionManager {
566
566
  this.captureManager.clear();
567
567
  // (this.active already set to false above)
568
568
 
569
- logger.info(
569
+ __DEV__ && logger.info(
570
570
  `[SessionManager] Session ended: ${this.session.sessionId} ` +
571
571
  `(${reason}, sync=${decision.shouldSync}, priority=${decision.priority})`,
572
572
  );
@@ -805,7 +805,7 @@ export class SessionManager {
805
805
 
806
806
  const alreadyNormalized = this._normalizeInteractionPayload(p);
807
807
 
808
- logger.debug(
808
+ __DEV__ && logger.debug(
809
809
  `[TapAccuracy] sink platform=${p.platform ?? '?'} space=${p.coordinateSpace ?? '?'} ` +
810
810
  `source=${alreadyNormalized ? (p.confidence === 'high' ? 'native-high' : 'js-precomputed') : 'js-estimated'} ` +
811
811
  `norm=(${p.normalizedX},${p.normalizedY}) base=(${p.viewportWidth}x${p.viewportHeight})`,
@@ -963,7 +963,7 @@ export class SessionManager {
963
963
 
964
964
  this.crashAnchors.push(anchor);
965
965
 
966
- logger.debug(
966
+ __DEV__ && logger.debug(
967
967
  `[SessionManager] Crash anchored: ${crashEventId}, ` +
968
968
  `protected ${anchor.nearbyEventIds.length} events, ` +
969
969
  `${anchor.nearbyFrameIds.length} frames`,
@@ -71,7 +71,7 @@ export class SyncDecisionEngine {
71
71
 
72
72
  const decision = this._policy(enrichedCandidate);
73
73
 
74
- logger.debug(
74
+ __DEV__ && logger.debug(
75
75
  `[SyncDecisionEngine] Session ${candidate.sessionId}: ` +
76
76
  `shouldSync=${decision.shouldSync}, priority=${decision.priority}, ` +
77
77
  `reason="${decision.reason}"`,
@@ -35,27 +35,19 @@ export async function updateSkanConversionValue(
35
35
  try {
36
36
  const mod = getSkanModule();
37
37
  if (!mod?.updateConversionValue) {
38
- logger.debug('[SKAN] Native module unavailable — conversion value not sent');
38
+ __DEV__ && logger.debug('[SKAN] Native module unavailable — conversion value not sent');
39
39
  return false;
40
40
  }
41
41
  const fine = Math.max(0, Math.min(63, Math.round(value)));
42
42
  await mod.updateConversionValue(fine, coarseValue ?? null, !!lockWindow);
43
- logger.debug(`[SKAN] updateConversionValue(${fine}, ${coarseValue ?? '-'}, lock=${lockWindow})`);
43
+ __DEV__ && logger.debug(`[SKAN] updateConversionValue(${fine}, ${coarseValue ?? '-'}, lock=${lockWindow})`);
44
44
  return true;
45
45
  } catch (err) {
46
- logger.debug(`[SKAN] updateConversionValue failed: ${(err as Error)?.message}`);
46
+ __DEV__ && logger.debug(`[SKAN] updateConversionValue failed: ${(err as Error)?.message}`);
47
47
  return false;
48
48
  }
49
49
  }
50
50
 
51
- /** Register the app's SKAdNetwork attribution at first launch (iOS 11.3+). No-op elsewhere. */
52
- export async function registerSkanAttribution(): Promise<void> {
53
- try {
54
- const mod = getSkanModule();
55
- if (!mod?.registerAppForAttribution) return;
56
- await mod.registerAppForAttribution();
57
- logger.debug('[SKAN] registered app for attribution');
58
- } catch {
59
- // No-throw.
60
- }
61
- }
51
+ // (registerSkanAttribution was removed: nothing in the SDK or any consumer ever called it, so SKAN
52
+ // attribution registration never actually happened. If the feature is wanted, wire it from the
53
+ // facade's init path rather than restoring an orphaned export — see git history for the body.)
@@ -106,7 +106,7 @@ export class SkanConversionManager {
106
106
  headers: { 'x-scalebun-client-key': this.clientKey },
107
107
  });
108
108
  if (!res.ok) {
109
- logger.debug(`[SKAN] schema fetch HTTP ${res.status}`);
109
+ __DEV__ && logger.debug(`[SKAN] schema fetch HTTP ${res.status}`);
110
110
  return;
111
111
  }
112
112
  const json: any = await res.json();
@@ -118,12 +118,12 @@ export class SkanConversionManager {
118
118
  } catch {
119
119
  /* no-throw */
120
120
  }
121
- logger.debug(
121
+ __DEV__ && logger.debug(
122
122
  `[SKAN] schema loaded (enabled=${this.enabled}, ${this.schema.length} rules)`,
123
123
  );
124
124
  }
125
125
  } catch (err) {
126
- logger.debug(`[SKAN] schema fetch failed: ${(err as Error)?.message}`);
126
+ __DEV__ && logger.debug(`[SKAN] schema fetch failed: ${(err as Error)?.message}`);
127
127
  }
128
128
  }
129
129
 
@@ -142,12 +142,12 @@ export class SkanConversionManager {
142
142
  this.persist();
143
143
 
144
144
  void this.applyCv(rule.value, rule.coarse, rule.lockWindow ?? false);
145
- logger.debug(
145
+ __DEV__ && logger.debug(
146
146
  `[SKAN] event '${eventName}' → CV ${rule.value}` +
147
147
  `${rule.coarse ? `/${rule.coarse}` : ''}${rule.lockWindow ? ' (locked)' : ''}`,
148
148
  );
149
149
  } catch (err) {
150
- logger.debug(`[SKAN] onEvent('${eventName}') failed: ${(err as Error)?.message}`);
150
+ __DEV__ && logger.debug(`[SKAN] onEvent('${eventName}') failed: ${(err as Error)?.message}`);
151
151
  }
152
152
  }
153
153
 
@@ -177,6 +177,6 @@ export function installFetchInterceptor(
177
177
  }
178
178
  };
179
179
 
180
- logger.debug('Fetch Interceptor installed');
180
+ __DEV__ && logger.debug('Fetch Interceptor installed');
181
181
  });
182
182
  }
@@ -226,6 +226,6 @@ export function installXHRInterceptor(
226
226
  return originalSend.apply(this, arguments as any);
227
227
  };
228
228
 
229
- logger.debug('XHR Interceptor installed');
229
+ __DEV__ && logger.debug('XHR Interceptor installed');
230
230
  });
231
231
  }
@@ -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