catalyst-core 0.3.0-beta.5 → 0.3.0-canary.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 (316) hide show
  1. package/changelog.md +80 -0
  2. package/dist/errors/generateDocs.js +100 -0
  3. package/dist/errors/index.js +243 -0
  4. package/dist/errors/registry.js +483 -0
  5. package/dist/errors-index.json +506 -0
  6. package/dist/globals.d.ts +62 -0
  7. package/dist/index.d.ts +5 -0
  8. package/dist/index.jsx +5 -8
  9. package/dist/logger.js +1 -1
  10. package/dist/native/androidProject/app/build.gradle.kts +142 -7
  11. package/dist/native/androidProject/app/src/main/AndroidManifest.xml +4 -0
  12. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +2 -2
  13. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/camera/BarcodeDetector.kt +3 -0
  14. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/camera/CameraSessionManager.kt +3 -0
  15. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +43 -8
  16. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +181 -1
  17. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +156 -236
  18. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileSizeRouterUtilsTest.kt +471 -0
  19. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +222 -226
  20. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FrameworkServerUtilsTest.kt +300 -0
  21. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/IntentUtilsTest.kt +244 -0
  22. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/MetricsMonitorTest.kt +359 -0
  23. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +108 -63
  24. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +329 -385
  25. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/OfflineCacheServiceTest.kt +302 -0
  26. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/PerfEventBufferTest.kt +133 -0
  27. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/UtilsKtTest.kt +152 -0
  28. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +145 -324
  29. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/BarcodeDetectorTest.kt +132 -0
  30. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/HoldControllerTest.kt +155 -0
  31. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/TorchControllerTest.kt +150 -0
  32. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/VideoStreamStateMachineTest.kt +120 -0
  33. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/VideoStreamStateTest.kt +62 -0
  34. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/ViewfinderMapperTest.kt +143 -0
  35. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/ZoomControllerTest.kt +421 -0
  36. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/design/DesignTokensTest.kt +207 -0
  37. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/plugins/PluginBridgeTest.kt +368 -0
  38. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/FridaDetectorTest.kt +193 -0
  39. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/SecurityCheckManagerTest.kt +260 -0
  40. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/SecurityCheckSchedulerTest.kt +166 -0
  41. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/DeviceInfoUtilsTest.kt +167 -0
  42. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/DownloadUtilsTest.kt +197 -0
  43. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/NetworkMonitorTest.kt +271 -0
  44. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/PushNotificationUtilsTest.kt +119 -0
  45. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/SafeAreaUtilsTest.kt +108 -0
  46. package/dist/native/androidProject/build.gradle.kts +1 -0
  47. package/dist/native/androidProject/gradle/libs.versions.toml +26 -0
  48. package/dist/native/androidProject/settings.gradle.kts +11 -8
  49. package/dist/native/androidSetup.js +2 -2
  50. package/dist/native/bridge/WebBridge.d.ts +98 -0
  51. package/dist/native/bridge/WebBridge.js +40 -6
  52. package/dist/native/bridge/constants/NativeInterfaces.d.ts +391 -0
  53. package/dist/native/bridge/errors.d.ts +67 -0
  54. package/dist/native/bridge/errors.js +66 -151
  55. package/dist/native/bridge/hooks/index.d.ts +13 -0
  56. package/dist/native/bridge/hooks/index.js +0 -6
  57. package/dist/native/bridge/hooks/useAI.d.ts +1 -0
  58. package/dist/native/bridge/hooks/useAI.js +3 -1
  59. package/dist/native/bridge/hooks/useCamera.d.ts +86 -0
  60. package/dist/native/bridge/hooks/useCamera.js +35 -6
  61. package/dist/native/bridge/hooks/useDataProtection.d.ts +17 -0
  62. package/dist/native/bridge/hooks/useDeviceInfo.d.ts +34 -0
  63. package/dist/native/bridge/hooks/useDeviceInfo.js +5 -0
  64. package/dist/native/bridge/hooks/useFilePicker.d.ts +53 -0
  65. package/dist/native/bridge/hooks/useFilePicker.js +13 -0
  66. package/dist/native/bridge/hooks/useGoogleSignIn.d.ts +12 -0
  67. package/dist/native/bridge/hooks/useHapticFeedback.d.ts +76 -0
  68. package/dist/native/bridge/hooks/useHapticFeedback.js +6 -1
  69. package/dist/native/bridge/hooks/useIntent.d.ts +33 -0
  70. package/dist/native/bridge/hooks/useIntent.js +2 -0
  71. package/dist/native/bridge/hooks/useNativeTransition.d.ts +53 -0
  72. package/dist/native/bridge/hooks/useNativeTransition.js +12 -5
  73. package/dist/native/bridge/hooks/useNetworkStatus.d.ts +22 -0
  74. package/dist/native/bridge/hooks/useNetworkStatus.js +7 -0
  75. package/dist/native/bridge/hooks/useNotification.d.ts +83 -0
  76. package/dist/native/bridge/hooks/useNotification.js +81 -34
  77. package/dist/native/bridge/hooks/useSafeArea.d.ts +12 -0
  78. package/dist/native/bridge/hooks/useSafeArea.js +8 -0
  79. package/dist/native/bridge/hooks/useVideoStream.d.ts +67 -0
  80. package/dist/native/bridge/hooks/useVideoStream.js +38 -52
  81. package/dist/native/bridge/hooks/utils.d.ts +4 -0
  82. package/dist/native/bridge/hooks.d.ts +1 -0
  83. package/dist/native/bridge/perf/collectors/ApiCollector.d.ts +30 -0
  84. package/dist/native/bridge/perf/collectors/ApiCollector.js +4 -0
  85. package/dist/native/bridge/perf/collectors/CacheCollector.d.ts +43 -0
  86. package/dist/native/bridge/perf/collectors/CacheCollector.js +4 -0
  87. package/dist/native/bridge/perf/collectors/HookCollector.d.ts +37 -0
  88. package/dist/native/bridge/perf/collectors/HookCollector.js +4 -0
  89. package/dist/native/bridge/perf/collectors/InsightsCollector.d.ts +103 -0
  90. package/dist/native/bridge/perf/collectors/InsightsCollector.js +4 -0
  91. package/dist/native/bridge/perf/collectors/InteractionCollector.d.ts +53 -0
  92. package/dist/native/bridge/perf/collectors/InteractionCollector.js +4 -0
  93. package/dist/native/bridge/perf/collectors/KeyboardCollector.d.ts +30 -0
  94. package/dist/native/bridge/perf/collectors/KeyboardCollector.js +4 -0
  95. package/dist/native/bridge/perf/collectors/NavigationCollector.d.ts +37 -0
  96. package/dist/native/bridge/perf/collectors/NavigationCollector.js +4 -0
  97. package/dist/native/bridge/perf/collectors/NetworkTimingCollector.d.ts +30 -0
  98. package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +4 -0
  99. package/dist/native/bridge/perf/collectors/RenderCollector.d.ts +47 -0
  100. package/dist/native/bridge/perf/collectors/RenderCollector.js +8 -0
  101. package/dist/native/bridge/perf/collectors/ScrollCollector.d.ts +29 -0
  102. package/dist/native/bridge/perf/collectors/ScrollCollector.js +4 -0
  103. package/dist/native/bridge/perf/collectors/ThreadCollector.d.ts +31 -0
  104. package/dist/native/bridge/perf/collectors/ThreadCollector.js +4 -0
  105. package/dist/native/bridge/perf/core/constants.d.ts +76 -0
  106. package/dist/native/bridge/perf/core/measure.d.ts +39 -0
  107. package/dist/native/bridge/perf/core/measure.js +4 -0
  108. package/dist/native/bridge/perf/core/session.d.ts +49 -0
  109. package/dist/native/bridge/perf/core/session.js +4 -0
  110. package/dist/native/bridge/perf/core/store.d.ts +37 -0
  111. package/dist/native/bridge/perf/core/store.js +4 -0
  112. package/dist/native/bridge/perf/core/summary.d.ts +60 -0
  113. package/dist/native/bridge/perf/core/traceExport.d.ts +10 -0
  114. package/dist/native/bridge/perf/core/waterfalls.d.ts +2 -0
  115. package/dist/native/bridge/perf/index.d.ts +63 -0
  116. package/dist/native/bridge/perf/index.js +4 -0
  117. package/dist/native/bridge/safeArea.d.ts +11 -0
  118. package/dist/native/bridge/safeArea.js +2 -0
  119. package/dist/native/bridge/useBaseHook.d.ts +137 -0
  120. package/dist/native/bridge/useBaseHook.js +34 -4
  121. package/dist/native/bridge/utils/CameraUtils.d.ts +94 -0
  122. package/dist/native/bridge/utils/CameraUtils.js +4 -0
  123. package/dist/native/bridge/utils/FileObjectConverter.d.ts +36 -0
  124. package/dist/native/bridge/utils/NativeBridge.d.ts +270 -0
  125. package/dist/native/bridge/utils/NativeBridge.js +10 -0
  126. package/dist/native/buildAndroid/index.js +1 -1
  127. package/dist/native/buildAppAndroid.js +9 -0
  128. package/dist/native/buildAppIos.js +16 -1
  129. package/dist/native/buildErrorFormat.js +57 -0
  130. package/dist/native/buildIos/config.js +15 -1
  131. package/dist/native/buildIos/index.js +1 -1
  132. package/dist/native/buildIos/plugins.js +10 -1
  133. package/dist/native/iosnativeWebView/CoreLogic/Package.swift +36 -0
  134. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Camera/VideoStreamState.swift +1 -1
  135. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Camera/VideoStreamStateMachine.swift +6 -4
  136. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/BootTimingUtility.swift +3 -3
  137. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/FrameworkServerUtils.swift +14 -9
  138. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NetworkMonitor.swift +11 -9
  139. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NotificationHandlerProvider.swift +1 -1
  140. package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/URLWhitelistManager.swift +7 -7
  141. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/AnyCodableTests.swift +154 -0
  142. package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/BootTimingUtilityTests.swift +23 -5
  143. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/CatalystConstantsTests.swift +192 -0
  144. package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/ConfigMappingTests.swift +1 -1
  145. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/FrameworkServerUtilsErrorPathTests.swift +106 -0
  146. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/FrameworkServerUtilsLoopbackTests.swift +243 -0
  147. package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/FrameworkServerUtilsTests.swift +1 -1
  148. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/NetworkMonitorTests.swift +119 -0
  149. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/NotificationHandlerProviderTests.swift +59 -0
  150. package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/NotificationHandlerTests.swift +1 -1
  151. package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/URLWhitelistManagerTests.swift +1 -1
  152. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/VideoStreamStateMachineTests.swift +171 -0
  153. package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/VideoStreamStateTests.swift +91 -0
  154. package/dist/native/iosnativeWebView/Package.swift +10 -9
  155. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +7 -2
  156. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +1 -2
  157. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +5 -4
  158. package/dist/native/iosnativeWebView/Sources/Core/Camera/CameraSessionManager.swift +1 -0
  159. package/dist/native/iosnativeWebView/Sources/Core/Camera/HoldController.swift +1 -0
  160. package/dist/native/iosnativeWebView/Sources/Core/Camera/NativeCameraManager.swift +6 -5
  161. package/dist/native/iosnativeWebView/Sources/Core/Camera/ZoomController.swift +1 -0
  162. package/dist/native/iosnativeWebView/Sources/Core/Plugins/PluginBridge.swift +1 -0
  163. package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +31 -30
  164. package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +2 -1
  165. package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +1 -1
  166. package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +22 -19
  167. package/dist/native/iosnativeWebView/Sources/Core/Utils/ImageHandler.swift +40 -39
  168. package/dist/native/iosnativeWebView/Sources/Core/Utils/PerfEventBuffer.swift +1 -0
  169. package/dist/native/iosnativeWebView/Sources/Core/Utils/ResourceURLProtocol.swift +15 -15
  170. package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +4 -3
  171. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +6 -1
  172. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +1 -0
  173. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +2 -1
  174. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +2 -1
  175. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +3 -5
  176. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +20 -13
  177. package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +6 -5
  178. package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +14 -13
  179. package/dist/native/iosnativeWebView/Sources/Core/WebView/TransitionManager.swift +3 -3
  180. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +9 -8
  181. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +7 -6
  182. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +24 -25
  183. package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +6 -1
  184. package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +1 -0
  185. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +4 -0
  186. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +2 -22
  187. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +1 -0
  188. package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +1 -0
  189. package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +2 -1
  190. package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +15 -9
  191. package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +1 -0
  192. package/dist/native/setupEmulatorIos.js +2 -2
  193. package/dist/native/terminalProgress.js +17 -17
  194. package/dist/router/ClientRouter.d.ts +8 -0
  195. package/dist/router/ClientRouter.js +13 -11
  196. package/dist/router/ServerRouter.d.ts +13 -0
  197. package/dist/router/ServerRouter.js +19 -7
  198. package/dist/scripts/build.js +14 -2
  199. package/dist/scripts/loadEnvironmentVariables.js +3 -2
  200. package/dist/scripts/plugins.js +1 -1
  201. package/dist/scripts/preServerInit.js +49 -3
  202. package/dist/scripts/preflight.js +111 -0
  203. package/dist/scripts/scriptUtils.js +46 -1
  204. package/dist/scripts/serve.js +7 -1
  205. package/dist/scripts/start.js +8 -1
  206. package/dist/server/expressServer.d.ts +1 -0
  207. package/dist/server/expressServer.js +247 -271
  208. package/dist/server/manifestCache.d.ts +2 -0
  209. package/dist/server/manifestCache.js +25 -33
  210. package/dist/server/renderer/ChunkExtractor.d.ts +44 -0
  211. package/dist/server/renderer/ChunkExtractor.js +113 -125
  212. package/dist/server/renderer/document/Body.d.ts +21 -0
  213. package/dist/server/renderer/document/Body.jsx +45 -45
  214. package/dist/server/renderer/document/FastRefresh.d.ts +3 -0
  215. package/dist/server/renderer/document/FastRefresh.jsx +7 -13
  216. package/dist/server/renderer/document/Head.d.ts +20 -0
  217. package/dist/server/renderer/document/Head.jsx +32 -32
  218. package/dist/server/renderer/document/index.d.ts +2 -0
  219. package/dist/server/renderer/document/index.jsx +2 -2
  220. package/dist/server/renderer/extract.d.ts +67 -0
  221. package/dist/server/renderer/extract.js +92 -89
  222. package/dist/server/renderer/handler.d.ts +2 -0
  223. package/dist/server/renderer/handler.jsx +401 -404
  224. package/dist/server/renderer/index.d.ts +2 -0
  225. package/dist/server/renderer/index.js +5 -8
  226. package/dist/server/renderer/render.d.ts +35 -0
  227. package/dist/server/renderer/render.js +33 -32
  228. package/dist/server/utils/botDetectionMiddleware.d.ts +1 -0
  229. package/dist/server/utils/botDetectionMiddleware.js +33 -23
  230. package/dist/server/utils/cjsRequire.d.ts +8 -0
  231. package/dist/server/utils/cjsRequire.js +2 -2
  232. package/dist/server/utils/userAgentUtil.d.ts +7 -0
  233. package/dist/server/utils/userAgentUtil.js +68 -71
  234. package/dist/server/utils/validator.d.ts +31 -0
  235. package/dist/server/utils/validator.js +133 -158
  236. package/dist/vite/inject-cache-key-plugin.js +3 -27
  237. package/dist/vite/moduleAliases.js +36 -0
  238. package/dist/vite/node-loader.mjs +2 -29
  239. package/dist/vite/resolveDevServerConfig.js +4 -1
  240. package/dist/vite/vite.config.js +2 -29
  241. package/dist/web-router/components/MetaTag.d.ts +4 -0
  242. package/dist/web-router/components/MetaTag.jsx +26 -28
  243. package/dist/web-router/components/MetaTag.test.jsx +100 -0
  244. package/dist/web-router/components/RouterDataProvider.d.ts +96 -0
  245. package/dist/web-router/components/RouterDataProvider.jsx +260 -259
  246. package/dist/web-router/components/RouterDataProvider.server.test.jsx +98 -0
  247. package/dist/web-router/components/RouterDataProvider.test.jsx +310 -0
  248. package/dist/web-router/components/Split.d.ts +74 -0
  249. package/dist/web-router/components/Split.jsx +147 -156
  250. package/dist/web-router/components/Split.server.test.jsx +52 -0
  251. package/dist/web-router/components/Split.test.jsx +167 -0
  252. package/dist/web-router/components/SplitInview.d.ts +22 -0
  253. package/dist/web-router/components/SplitInview.jsx +78 -89
  254. package/dist/web-router/components/SplitInview.test.jsx +112 -0
  255. package/dist/web-router/components/SsrRequestContext.d.ts +20 -0
  256. package/dist/web-router/components/SsrRequestContext.jsx +17 -7
  257. package/dist/web-router/components/SsrRequestContext.test.jsx +53 -0
  258. package/dist/web-router/context.d.ts +15 -0
  259. package/dist/web-router/context.jsx +5 -5
  260. package/dist/web-router/context.test.jsx +10 -0
  261. package/dist/web-router/utils/metaDataUtils.d.ts +24 -0
  262. package/dist/web-router/utils/metaDataUtils.jsx +86 -86
  263. package/dist/web-router/utils/metaDataUtils.test.jsx +188 -0
  264. package/dist/web-router/vitest.setup.js +12 -0
  265. package/mcp_v2/knowledge-base.json +52 -8
  266. package/mcp_v2/mcp.js +140 -3
  267. package/mcp_v2/package-lock.json +2031 -0
  268. package/mcp_v2/package.json +13 -2
  269. package/mcp_v2/scripts/copyErrorsIndex.cjs +34 -0
  270. package/mcp_v2/test/errors.test.ts +123 -0
  271. package/mcp_v2/test/github.test.ts +177 -0
  272. package/mcp_v2/tools/errors.d.ts +20 -0
  273. package/mcp_v2/tools/errors.js +63 -0
  274. package/mcp_v2/tools/github.d.ts +41 -0
  275. package/mcp_v2/tools/github.js +231 -0
  276. package/mcp_v2/vitest.config.mjs +22 -0
  277. package/package.json +60 -11
  278. package/test/errors/docsDrift.test.ts +113 -0
  279. package/test/errors/index.test.ts +200 -0
  280. package/test/errors/registry.test.ts +108 -0
  281. package/test/scripts/preflight.test.ts +121 -0
  282. package/test/server/ChunkExtractor.test.ts +97 -0
  283. package/test/server/extract.test.ts +128 -0
  284. package/test/server/fixtures/template/server/document.jsx +19 -0
  285. package/test/server/fixtures/template/server/index.js +10 -0
  286. package/test/server/fixtures/template/src/js/containers/App/index.jsx +33 -0
  287. package/test/server/fixtures/template/src/js/routes/index.jsx +72 -0
  288. package/test/server/fixtures/template/src/js/routes/utils.jsx +39 -0
  289. package/test/server/fixtures/template/src/js/store/index.js +19 -0
  290. package/test/server/handler.assets.test.ts +331 -0
  291. package/test/server/handler.test.ts +210 -0
  292. package/test/server/manifestCache.test.ts +71 -0
  293. package/test/server/render.test.ts +90 -0
  294. package/test/server/scriptUtils.test.ts +103 -0
  295. package/test/server/userAgentUtil.test.ts +48 -0
  296. package/test/server/validator.test.ts +228 -0
  297. package/test/vite/resolveDevServerConfig.test.js +4 -1
  298. package/tsconfig.test.json +23 -0
  299. package/vitest.config.ts +93 -0
  300. package/dist/caching.js +0 -1
  301. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +0 -187
  302. package/dist/native/bridge/standardizedHooks.js +0 -611
  303. package/dist/router.js +0 -1
  304. package/dist/scripts/validator.js +0 -149
  305. package/dist/web-router/hooks.jsx +0 -72
  306. package/dist/web-router/types/components/MetaTag.d.ts +0 -2
  307. package/dist/web-router/types/components/RouterDataProvider.d.ts +0 -95
  308. package/dist/web-router/types/context.d.ts +0 -14
  309. package/dist/web-router/types/hooks.d.ts +0 -1
  310. package/dist/web-router/types/index.d.ts +0 -3
  311. package/dist/web-router/types/utils/metaDataUtils.d.ts +0 -40
  312. /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Constants/CatalystConstants.swift +0 -0
  313. /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Constants/ConfigConstants.swift +0 -0
  314. /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Notifications/NotificationModels.swift +0 -0
  315. /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Protocols/NotificationHandlerProtocol.swift +0 -0
  316. /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NullNotificationHandler.swift +0 -0
package/changelog.md CHANGED
@@ -8,6 +8,86 @@
8
8
 
9
9
  # Changelog
10
10
 
11
+ ## [0.4.0] - unreleased
12
+
13
+ This release freezes the public API. The root entry of `catalyst-core` now exports exactly eight names and nothing else: `RouterDataProvider`, `useCurrentRouteData`, `useRouterData`, `MetaTag`, `split`, `hydrationReady`, `Head`, and `Body`. Anything previously reachable through the root entry but not in that list is no longer public. Applications that import a removed name will fail at build time rather than silently resolving to `undefined`.
14
+
15
+ ### React Router is no longer re-exported
16
+
17
+ `catalyst-core` used to re-export the whole of React Router from its root entry, so `Link`, `Outlet`, `RouterProvider`, `useParams`, `useNavigate` and every other router name could be imported from `catalyst-core`. That re-export is gone.
18
+
19
+ React Router is now a peer dependency (`^7.18.2`). Install it in the application:
20
+
21
+ ```bash
22
+ npm install react-router@^7.18.2
23
+ ```
24
+
25
+ Then import router names from `react-router` directly. An import line that mixed both sources splits into two:
26
+
27
+ ```js
28
+ // before
29
+ import { useCurrentRouteData, useParams, Link } from "catalyst-core"
30
+
31
+ // after
32
+ import { useCurrentRouteData } from "catalyst-core"
33
+ import { useParams, Link } from "react-router"
34
+ ```
35
+
36
+ One exception: `client/index.js` imports `RouterProvider` from `react-router/dom`, not from `react-router`. The `react-router/dom` build passes React DOM's `flushSync` into the router, which view transitions and `flushSync` navigations depend on. The `react-router` export renders the same tree but silently skips that.
37
+
38
+ Because the version is now declared by the application, npm will report a peer dependency conflict if the installed React Router major does not satisfy `^7.18.2`. The server also verifies the resolved version at startup and exits with a clear error if React Router is missing or outside the supported range.
39
+
40
+ ### Removed export paths
41
+
42
+ - `catalyst-core/caching` — removed. The caching feature was withdrawn and has no replacement.
43
+ - `catalyst-core/document` — removed. Import `Head` and `Body` from the `catalyst-core` root entry instead.
44
+
45
+ ### No default export from the root entry
46
+
47
+ `split` was previously exported both as a named export and as the default. The default export is gone; use the named one.
48
+
49
+ ```js
50
+ // before
51
+ import split from "catalyst-core"
52
+
53
+ // after
54
+ import { split } from "catalyst-core"
55
+ ```
56
+
57
+ ### Names that are no longer public
58
+
59
+ These were reachable from the root entry and are now internal: `RouterContext`, `serverDataFetcher`, `mergeHeadElements`, `deleteHeadTagsByDataAttribute`, `getMetaData`, and `useNavigateWithTransition`. In addition, `sanitizeFilePickerOptions` is no longer exported from `catalyst-core/hooks`. None of these have a supported replacement. If an application depends on one of them, open an issue describing the use case before upgrading.
60
+
61
+ ### Native hooks: canonical keys
62
+
63
+ The native hooks now agree on one set of key names. Every change in this section is additive: no key that a hook returned before has been removed or repointed, so existing components keep working.
64
+
65
+ Several hooks were missing keys that the rest of the surface already had. `useNotificationPermission` gained `loading`, `data`, `error`, `isNative`, and `isWeb`, and it now reports permission failures as a standard error object instead of only logging them. `useCameraPermission` gained `loading`, `data`, `error`, `execute`, `isNative`, and `isWeb` on the same pattern. `useDeviceInfo` gained `data` alongside its existing `deviceInfo`. `useNativeTransition` gained `loading` alongside `transitioning`. The SSR stub returned by `useAI` reported `isWeb: false`, which was wrong on both counts; it now reports `isWeb: true`.
66
+
67
+ Where a hook had two names for one value, the shorter one is canonical and the older one is a deprecated alias that will be removed at 2.0: `loading` over `isLoading` and `transitioning`, `data` over `deviceInfo` and `permission`, and `execute` over `request`.
68
+
69
+ Hooks fall into three categories, and the category decides whether a hook has `execute`. A hook that wraps a single native operation exposes it as `execute` plus a domain-specific alias — `takePhoto`, `pickFile`, `openFile`, `signIn`, `trigger`, `request`. A hook that wraps several distinct operations has no single action to name, so its named functions are the API and it has no `execute` at all: `useVideoStream`, `useDataProtection`, and `useNativeTransition` work this way. A read-only hook reports ambient device state and has no action functions at all: `useNetworkStatus`, `useDeviceInfo`, and `useSafeArea` return state plus the runtime-context keys. `useNotification` is the one exception. It carries `execute` and `schedule` as aliases of `scheduleLocal` for backward compatibility. Both are frozen, both are discouraged, and neither should be read as the pattern for multi-action hooks. `execute` never takes an operation name as a string argument; it takes the arguments of the operation itself.
70
+
71
+ Hook errors are `CatalystError` values from the framework-wide error registry introduced in this release, carrying a `RUNTIME-NATIVE-*` code, a message, a category, a suggested action, a documentation link, and the originating platform error as `cause`. `useVideoStream` in particular used to report seventeen failures as bare `{ message }` objects with no code at all; those now carry real codes, and a camera denial reports the same code whether it comes from the permission hook or the stream.
72
+
73
+ One consequence for error logging: `CatalystError` extends `Error`, so `message` now lives on the prototype rather than as an own property. Reading `error.message` is unaffected, but `JSON.stringify(error)` no longer includes it. Log `error.message` explicitly, or use the `code` and `docUrl` fields.
74
+
75
+ Two hooks are exempt from the error contract. `useNativeTransition` and `useSafeArea` return no `error` key, because transition failures self-heal into a plain navigation and safe-area insets always resolve to numeric defaults. Two others carry the right key with the wrong type: `error` on `useDeviceInfo` and `useNetworkStatus` is still a plain string rather than an error object, and stays a string until 2.0. The shape of `useAI` is owned by the `catalyst-ai` package and sits outside this contract entirely.
76
+
77
+ `requestHapticFeedback` and `requestCameraPermission` remain available both as `catalyst-core/hooks` exports and as `WebBridge` methods, and the two versions still differ in their defaults and return types. The hooks exports are the ones to prefer in application code: they are SSR-safe and treat a denied permission as a rejection. The two surfaces are unified at 2.0.
78
+
79
+ ### Node 22.12 is now the minimum
80
+
81
+ The error registry is loaded from the native bridge, which is built as CommonJS, so the package relies on `require()` of an ES module. That is unflagged only from Node 22.12 onward, and `engines` now declares `>=22.12`. Node 20 installs will warn, and importing `catalyst-core/hooks` or `catalyst-core/WebBridge` there fails with `ERR_REQUIRE_ESM`.
82
+
83
+ ### App contract violations are reported at startup
84
+
85
+ The app contract validators in `server/utils/validator.js` used to log a bare message and return `undefined` when an app was missing a required export, which pushed the real failure into an unrelated `TypeError` deep inside a render. They now report through the shared error reporter instead, naming the specific file and export and what the app must provide, with detail governed by the output mode. Reporting is not fatal: startup continues, so an app that is only partly misconfigured still boots and the startup output explains what will fail.
86
+
87
+ The route and store checks moved out of the per-request path. `validateGetRoutes` and `validateConfigureStore` now run once when the renderer module loads — at server startup in production, and on the first SSR request in development, where the handler is loaded lazily — rather than once per request inside the handler's `try`/`catch`. The shape of `addMiddlewares` from `server/server.js` is checked during server setup.
88
+
89
+ Module aliases and `config/config.json` keys are not checked at load time; a missing alias or key still surfaces where it is used. An application that satisfies the contract sees no change. The full contract — the files Catalyst imports by fixed path and the required module aliases — is documented under File Conventions.
90
+
11
91
  ## [0.1.0-beta.2] - 2026-05-06
12
92
 
13
93
  - Moved Catalyst into a monorepo structure with `catalyst-core`, `create-catalyst-app`, the Catalyst docs app, and the Catalyst core test app managed from one repository.
@@ -0,0 +1,100 @@
1
+ import { mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync, existsSync } from "fs"
2
+ import path from "path"
3
+ import { fileURLToPath } from "url"
4
+ import { ERROR_DEFINITIONS } from "./registry.js"
5
+
6
+ const __filename = fileURLToPath(import.meta.url)
7
+ const __dirname = path.dirname(__filename)
8
+
9
+ // packages/catalyst-core/src/errors -> repo root /errors
10
+ const DEFAULT_ERRORS_DIR = path.resolve(__dirname, "../../../../errors")
11
+
12
+ function renderMarkdown(code, def) {
13
+ return `# ${code}
14
+
15
+ **Category:** ${def.category}
16
+
17
+ ## Message
18
+
19
+ ${def.defaultMessage}
20
+
21
+ ## Details
22
+
23
+ ${def.defaultDetails}
24
+
25
+ ## Suggested action
26
+
27
+ ${def.suggestedAction}
28
+ `
29
+ }
30
+
31
+ function clearGeneratedCategoryDirs(errorsDir) {
32
+ if (!existsSync(errorsDir)) return
33
+ const categories = new Set(Object.values(ERROR_DEFINITIONS).map((d) => d.category))
34
+ for (const category of categories) {
35
+ const dir = path.join(errorsDir, category)
36
+ if (existsSync(dir)) {
37
+ for (const file of readdirSync(dir)) {
38
+ if (file.endsWith(".md")) rmSync(path.join(dir, file))
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ // Other packages (e.g. create-catalyst-app) own their own categories and
45
+ // merge their entries into this same index.json. Only clear/overwrite keys
46
+ // for categories this registry itself defines, so a regen here never wipes
47
+ // entries owned by another package's generator.
48
+ function readExistingIndex(indexPath) {
49
+ if (!existsSync(indexPath)) return {}
50
+ try {
51
+ return JSON.parse(readFileSync(indexPath, "utf8"))
52
+ } catch {
53
+ return {}
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Regenerate errors/**\/*.md + errors/index.json from ERROR_DEFINITIONS.
59
+ *
60
+ * `errorsDir` defaults to the real repo-root errors/ dir (the CLI/prepublish
61
+ * use case) but can be overridden — e.g. by the docs-drift contract test
62
+ * (see test/errors/docsDrift.test.js), which regenerates into a temp dir and
63
+ * diffs against the committed output rather than mutating it.
64
+ */
65
+ export function generateDocs(errorsDir = DEFAULT_ERRORS_DIR) {
66
+ const indexPath = path.join(errorsDir, "index.json")
67
+
68
+ clearGeneratedCategoryDirs(errorsDir)
69
+
70
+ const ownedCategories = new Set(Object.values(ERROR_DEFINITIONS).map((d) => d.category))
71
+ const index = readExistingIndex(indexPath)
72
+ for (const code of Object.keys(index)) {
73
+ if (ownedCategories.has(index[code].category)) delete index[code]
74
+ }
75
+
76
+ for (const [code, def] of Object.entries(ERROR_DEFINITIONS)) {
77
+ const dir = path.join(errorsDir, def.category)
78
+ mkdirSync(dir, { recursive: true })
79
+ const filePath = path.join(dir, `${code}.md`)
80
+ writeFileSync(filePath, renderMarkdown(code, def))
81
+
82
+ index[code] = {
83
+ category: def.category,
84
+ message: def.defaultMessage,
85
+ details: def.defaultDetails,
86
+ suggestedAction: def.suggestedAction,
87
+ docUrl: `https://github.com/tata1mg/catalyst-core/blob/main/errors/${def.category}/${code}.md`,
88
+ }
89
+ }
90
+
91
+ mkdirSync(errorsDir, { recursive: true })
92
+ writeFileSync(indexPath, JSON.stringify(index, null, 4))
93
+
94
+ return { count: Object.keys(ERROR_DEFINITIONS).length, errorsDir }
95
+ }
96
+
97
+ if (import.meta.url === `file://${process.argv[1]}`) {
98
+ const { count, errorsDir } = generateDocs()
99
+ console.log(`Generated ${count} error doc(s) + index.json in ${errorsDir}`)
100
+ }
@@ -0,0 +1,243 @@
1
+ import pc from "ansis"
2
+ /**
3
+ * The "catalyst-core/errors" subpath export exists so catalyst's own
4
+ * packages (catalyst-ai, create-catalyst-app, etc.) can share this
5
+ * registry/CatalystError shape instead of each defining their own. It is
6
+ * not a recommendation for app code to throw CatalystError instead of
7
+ * Error — apps should keep using plain Error unless they're specifically
8
+ * interoperating with catalyst's own error codes.
9
+ */
10
+ import { ERROR_CODES, getDefinition, getDocUrl } from "./registry.js"
11
+
12
+ export { ERROR_CODES, getDocUrl }
13
+
14
+ export class CatalystError extends Error {
15
+ constructor(code, { message, details, suggestedAction, category, docUrl, cause } = {}) {
16
+ super(message)
17
+ this.name = "CatalystError"
18
+ this.code = code
19
+ this.category = category
20
+ this.details = details
21
+ this.suggestedAction = suggestedAction
22
+ this.docUrl = docUrl
23
+ if (cause !== undefined) this.cause = cause
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Create a CatalystError for a code we own, using registry.js defaults
29
+ * unless overridden.
30
+ */
31
+ export function createError(code, overrides = {}) {
32
+ const def = getDefinition(code)
33
+ return new CatalystError(code, {
34
+ category: def.category,
35
+ message: overrides.message || def.defaultMessage,
36
+ details: overrides.details || def.defaultDetails,
37
+ suggestedAction: overrides.suggestedAction || def.suggestedAction,
38
+ docUrl: getDocUrl(code),
39
+ cause: overrides.cause,
40
+ })
41
+ }
42
+
43
+ const STAGE_WRAPPER_CODE = {
44
+ BUNDLE: ERROR_CODES.BUNDLE_UPSTREAM_ERROR,
45
+ IOS: ERROR_CODES.IOS_UPSTREAM_ERROR,
46
+ ANDROID: ERROR_CODES.ANDROID_UPSTREAM_ERROR,
47
+ }
48
+
49
+ const STAGE_UPSTREAM_NAME = {
50
+ BUNDLE: "Vite/Rollup",
51
+ IOS: "Xcode/CocoaPods",
52
+ ANDROID: "Gradle",
53
+ }
54
+
55
+ /**
56
+ * Wrap a foreign error (Vite/Rollup/native toolchain) that already carries
57
+ * its own code/message. We do not replace or reinterpret it — we attach a
58
+ * generic per-stage wrapper code and preserve the original as `cause`, so
59
+ * the upstream code/message is always what gets shown to the user.
60
+ */
61
+ export function wrapForeignError(stage, err) {
62
+ const code = STAGE_WRAPPER_CODE[stage]
63
+ if (!code) {
64
+ throw new Error(`wrapForeignError: unknown stage "${stage}"`)
65
+ }
66
+ const upstreamName = STAGE_UPSTREAM_NAME[stage]
67
+ // Only show err.code when it's a real upstream identifier (e.g. Rollup's
68
+ // "PLUGIN_LOAD_ERROR"), not a bare numeric process exit status — a spawned
69
+ // child's exit code is not an "upstream error code" and would be misleading.
70
+ const hasNamedCode = err && typeof err.code === "string"
71
+ const upstreamCode = hasNamedCode ? ` ${upstreamName} ${err.code}` : ` ${upstreamName}`
72
+ const wrapped = createError(code, {
73
+ message: `Build failed (upstream:${upstreamCode})`,
74
+ cause: err,
75
+ })
76
+ return wrapped
77
+ }
78
+
79
+ const SSR_STAGE_CODE = {
80
+ RENDER: ERROR_CODES.RUNTIME_WEB_RENDER_FAILED,
81
+ FETCHER: ERROR_CODES.RUNTIME_WEB_FETCHER_FAILED,
82
+ SERVER_SIDE_FUNCTION: ERROR_CODES.RUNTIME_WEB_SERVER_SIDE_FUNCTION_FAILED,
83
+ REQUEST_HANDLING: ERROR_CODES.RUNTIME_WEB_REQUEST_HANDLING_FAILED,
84
+ }
85
+
86
+ /**
87
+ * Wrap an error caught during SSR (handler.jsx). Unlike wrapForeignError's
88
+ * build-stage wrapping, the caught error here could originate from the
89
+ * user's app code, a third-party dependency, or catalyst-core's own
90
+ * pipeline — there is no way to tell from the caught error object which.
91
+ * So, like the BUNDLE/IOS/ANDROID wrappers, we never reinterpret it: we
92
+ * attach a stage-specific code that identifies *where* in the SSR pipeline
93
+ * the failure happened, and preserve the original error as `cause`.
94
+ */
95
+ export function wrapSSRError(stage, err) {
96
+ const code = SSR_STAGE_CODE[stage]
97
+ if (!code) {
98
+ throw new Error(`wrapSSRError: unknown stage "${stage}"`)
99
+ }
100
+ return createError(code, { cause: err })
101
+ }
102
+
103
+ /**
104
+ * Wrap a failed AI provider HTTP response (OpenAI/Gemini). Unlike
105
+ * wrapForeignError (build toolchains, which carry a named err.code), provider
106
+ * failures are an HTTP status + response body — we preserve both verbatim
107
+ * as `cause` rather than reinterpreting them.
108
+ */
109
+ export function wrapProviderError(provider, status, bodyText) {
110
+ const cause = new Error(`${provider} API error (${status}): ${bodyText}`)
111
+ cause.provider = provider
112
+ cause.status = status
113
+ return createError(ERROR_CODES.AI_UPSTREAM_ERROR, {
114
+ message: `AI provider request failed (upstream: ${provider} ${status})`,
115
+ cause,
116
+ })
117
+ }
118
+
119
+ function formatDefault(err) {
120
+ const lines = [`[${err.code}] ${err.message}`]
121
+ if (err.cause) {
122
+ const causeMessage = err.cause.message || String(err.cause)
123
+ lines.push(`→ ${causeMessage}`)
124
+ } else if (err.details) {
125
+ lines.push(err.details)
126
+ }
127
+ if (err.suggestedAction) {
128
+ lines.push(`Suggested action: ${err.suggestedAction}`)
129
+ }
130
+ if (err.docUrl) {
131
+ lines.push(`Docs: ${err.docUrl}`)
132
+ }
133
+ return lines.join("\n")
134
+ }
135
+
136
+ const BOX_WIDTH = 70
137
+
138
+ function box(bodyLines) {
139
+ const top = pc.red(`┌${"─".repeat(BOX_WIDTH)}`)
140
+ const bottom = pc.red(`└${"─".repeat(BOX_WIDTH)}`)
141
+ const body = bodyLines.map((line) => (line === "" ? pc.red("│") : `${pc.red("│")} ${line}`))
142
+ return [top, ...body, bottom].join("\n")
143
+ }
144
+
145
+ function formatCauseChain(cause) {
146
+ const lines = []
147
+ let current = cause
148
+ let depth = 0
149
+ while (current) {
150
+ const prefix = depth === 0 ? "Caused by:" : ` ${" ".repeat(depth - 1)}Caused by:`
151
+ lines.push(`${prefix} ${current.message || String(current)}`)
152
+ current = current.cause
153
+ depth += 1
154
+ }
155
+ return lines
156
+ }
157
+
158
+ /**
159
+ * Verbose output: boxed per RFC #155 §3.2 — code, timestamp, problem,
160
+ * suggested action, docs link. Owns its own coloring (the box border and
161
+ * text are colored as a unit here) rather than leaving callers to wrap the
162
+ * whole multi-line block in a color function themselves.
163
+ */
164
+ function formatVerbose(err) {
165
+ const lines = [
166
+ pc.bold(`❌ ${err.message}`),
167
+ `Code: ${err.code}`,
168
+ `Category: ${err.category || "UNKNOWN"}`,
169
+ `Time: ${new Date().toISOString()}`,
170
+ "",
171
+ ]
172
+ if (err.cause) {
173
+ lines.push(`Problem: ${err.cause.message || String(err.cause)}`)
174
+ lines.push("")
175
+ } else if (err.details) {
176
+ lines.push(`Problem: ${err.details}`)
177
+ lines.push("")
178
+ }
179
+ if (err.suggestedAction) {
180
+ lines.push("Solution:", ` ${err.suggestedAction}`, "")
181
+ }
182
+ if (err.docUrl) {
183
+ lines.push(`Docs: ${err.docUrl}`)
184
+ }
185
+ return box(lines)
186
+ }
187
+
188
+ /**
189
+ * Debug output: verbose + full cause chain + stack trace + environment
190
+ * info. Environment gathering happens here (Node-side), not as module-level
191
+ * state, so errors/index.js stays free of os/process imports and safe to
192
+ * bundle into the browser (see formatError's mode parameter below).
193
+ */
194
+ function formatDebug(err, env) {
195
+ const lines = [
196
+ pc.bold(`❌ ${err.message}`),
197
+ `Code: ${err.code}`,
198
+ `Category: ${err.category || "UNKNOWN"}`,
199
+ `Time: ${new Date().toISOString()}`,
200
+ "",
201
+ ]
202
+ if (err.cause) {
203
+ lines.push(...formatCauseChain(err.cause), "")
204
+ } else if (err.details) {
205
+ lines.push(`Problem: ${err.details}`, "")
206
+ }
207
+ if (err.suggestedAction) {
208
+ lines.push("Solution:", ` ${err.suggestedAction}`, "")
209
+ }
210
+ if (err.docUrl) {
211
+ lines.push(`Docs: ${err.docUrl}`, "")
212
+ }
213
+ if (env) {
214
+ lines.push("Environment:")
215
+ for (const [key, value] of Object.entries(env)) {
216
+ lines.push(` ${key}: ${value}`)
217
+ }
218
+ lines.push("")
219
+ }
220
+ lines.push("Stack trace:")
221
+ const stack = err.cause?.stack || err.stack || "(no stack available)"
222
+ lines.push(...stack.split("\n").map((l) => ` ${l}`))
223
+ return box(lines)
224
+ }
225
+
226
+ /**
227
+ * Format a CatalystError for terminal output. Foreign-wrapped errors always
228
+ * show the original upstream message/code, never a paraphrase of it.
229
+ *
230
+ * `mode` is a parameter, not module-level state — WebBridge.js (browser) has
231
+ * no process.argv/TTY and keeps calling formatError(err) unchanged, getting
232
+ * "default". Node call sites resolve their own mode (see
233
+ * scripts/scriptUtils.js#resolveOutputMode) and pass it through explicitly.
234
+ *
235
+ * `env` (debug mode only) is gathered by the caller, not here — keeps this
236
+ * module free of os/process imports so it stays safe to bundle into the
237
+ * browser regardless of which mode a Node caller happens to request.
238
+ */
239
+ export function formatError(err, mode = "default", env) {
240
+ if (mode === "debug") return formatDebug(err, env)
241
+ if (mode === "verbose") return formatVerbose(err)
242
+ return formatDefault(err)
243
+ }