tempest-react-sdk 0.53.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/README.md +27 -6
  2. package/dist/access/Can.cjs +1 -1
  3. package/dist/access/Can.cjs.map +1 -1
  4. package/dist/access/Can.js +3 -3
  5. package/dist/access/Can.js.map +1 -1
  6. package/dist/audio/level-meter.cjs +1 -1
  7. package/dist/audio/level-meter.cjs.map +1 -1
  8. package/dist/audio/level-meter.js +15 -15
  9. package/dist/audio/level-meter.js.map +1 -1
  10. package/dist/audio/noise-floor.cjs +2 -0
  11. package/dist/audio/noise-floor.cjs.map +1 -0
  12. package/dist/audio/noise-floor.js +27 -0
  13. package/dist/audio/noise-floor.js.map +1 -0
  14. package/dist/audio/voice-activity.cjs +2 -0
  15. package/dist/audio/voice-activity.cjs.map +1 -0
  16. package/dist/audio/voice-activity.js +26 -0
  17. package/dist/audio/voice-activity.js.map +1 -0
  18. package/dist/audio/voice-chain-stages.cjs +2 -0
  19. package/dist/audio/voice-chain-stages.cjs.map +1 -0
  20. package/dist/audio/voice-chain-stages.js +82 -0
  21. package/dist/audio/voice-chain-stages.js.map +1 -0
  22. package/dist/audio/voice-chain.cjs +2 -0
  23. package/dist/audio/voice-chain.cjs.map +1 -0
  24. package/dist/audio/voice-chain.js +74 -0
  25. package/dist/audio/voice-chain.js.map +1 -0
  26. package/dist/auth/lazy-with-retry.cjs.map +1 -1
  27. package/dist/auth/lazy-with-retry.js.map +1 -1
  28. package/dist/auth/passkey.cjs.map +1 -1
  29. package/dist/auth/passkey.js.map +1 -1
  30. package/dist/br/BrazilStateCitySelect.cjs +1 -1
  31. package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
  32. package/dist/br/BrazilStateCitySelect.js +36 -28
  33. package/dist/br/BrazilStateCitySelect.js.map +1 -1
  34. package/dist/br/data/br-centroids.cjs +1 -1
  35. package/dist/br/data/br-centroids.cjs.map +1 -1
  36. package/dist/br/data/br-centroids.js +11105 -11045
  37. package/dist/br/data/br-centroids.js.map +1 -1
  38. package/dist/br/data/br-locations.cjs +1 -1
  39. package/dist/br/data/br-locations.cjs.map +1 -1
  40. package/dist/br/data/br-locations.js +5803 -137
  41. package/dist/br/data/br-locations.js.map +1 -1
  42. package/dist/br/data/br-uf-geo.cjs +1 -1
  43. package/dist/br/data/br-uf-geo.cjs.map +1 -1
  44. package/dist/br/data/br-uf-geo.js +5721 -6777
  45. package/dist/br/data/br-uf-geo.js.map +1 -1
  46. package/dist/br/data/mun/AC.cjs +1 -1
  47. package/dist/br/data/mun/AC.cjs.map +1 -1
  48. package/dist/br/data/mun/AC.js +681 -689
  49. package/dist/br/data/mun/AC.js.map +1 -1
  50. package/dist/br/data/mun/AL.cjs +1 -1
  51. package/dist/br/data/mun/AL.cjs.map +1 -1
  52. package/dist/br/data/mun/AL.js +949 -844
  53. package/dist/br/data/mun/AL.js.map +1 -1
  54. package/dist/br/data/mun/AM.cjs +1 -1
  55. package/dist/br/data/mun/AM.cjs.map +1 -1
  56. package/dist/br/data/mun/AM.js +4337 -4218
  57. package/dist/br/data/mun/AM.js.map +1 -1
  58. package/dist/br/data/mun/AP.cjs +1 -1
  59. package/dist/br/data/mun/AP.cjs.map +1 -1
  60. package/dist/br/data/mun/AP.js +786 -780
  61. package/dist/br/data/mun/AP.js.map +1 -1
  62. package/dist/br/data/mun/BA.cjs +1 -1
  63. package/dist/br/data/mun/BA.cjs.map +1 -1
  64. package/dist/br/data/mun/BA.js +6329 -5633
  65. package/dist/br/data/mun/BA.js.map +1 -1
  66. package/dist/br/data/mun/CE.cjs +1 -1
  67. package/dist/br/data/mun/CE.cjs.map +1 -1
  68. package/dist/br/data/mun/CE.js +2544 -2487
  69. package/dist/br/data/mun/CE.js.map +1 -1
  70. package/dist/br/data/mun/DF.cjs +1 -1
  71. package/dist/br/data/mun/DF.cjs.map +1 -1
  72. package/dist/br/data/mun/DF.js +17 -16
  73. package/dist/br/data/mun/DF.js.map +1 -1
  74. package/dist/br/data/mun/ES.cjs +1 -1
  75. package/dist/br/data/mun/ES.cjs.map +1 -1
  76. package/dist/br/data/mun/ES.js +1101 -1070
  77. package/dist/br/data/mun/ES.js.map +1 -1
  78. package/dist/br/data/mun/GO.cjs +1 -1
  79. package/dist/br/data/mun/GO.cjs.map +1 -1
  80. package/dist/br/data/mun/GO.js +4632 -4636
  81. package/dist/br/data/mun/GO.js.map +1 -1
  82. package/dist/br/data/mun/MA.cjs +1 -1
  83. package/dist/br/data/mun/MA.cjs.map +1 -1
  84. package/dist/br/data/mun/MA.js +3603 -3457
  85. package/dist/br/data/mun/MA.js.map +1 -1
  86. package/dist/br/data/mun/MG.cjs +1 -1
  87. package/dist/br/data/mun/MG.cjs.map +1 -1
  88. package/dist/br/data/mun/MG.js +12716 -11739
  89. package/dist/br/data/mun/MG.js.map +1 -1
  90. package/dist/br/data/mun/MS.cjs +1 -1
  91. package/dist/br/data/mun/MS.cjs.map +1 -1
  92. package/dist/br/data/mun/MS.js +2182 -2335
  93. package/dist/br/data/mun/MS.js.map +1 -1
  94. package/dist/br/data/mun/MT.cjs +1 -1
  95. package/dist/br/data/mun/MT.cjs.map +1 -1
  96. package/dist/br/data/mun/MT.js +4808 -4896
  97. package/dist/br/data/mun/MT.js.map +1 -1
  98. package/dist/br/data/mun/PA.cjs +1 -1
  99. package/dist/br/data/mun/PA.cjs.map +1 -1
  100. package/dist/br/data/mun/PA.js +4981 -4901
  101. package/dist/br/data/mun/PA.js.map +1 -1
  102. package/dist/br/data/mun/PB.cjs +1 -1
  103. package/dist/br/data/mun/PB.cjs.map +1 -1
  104. package/dist/br/data/mun/PB.js +2418 -1956
  105. package/dist/br/data/mun/PB.js.map +1 -1
  106. package/dist/br/data/mun/PE.cjs +1 -1
  107. package/dist/br/data/mun/PE.cjs.map +1 -1
  108. package/dist/br/data/mun/PE.js +2164 -1987
  109. package/dist/br/data/mun/PE.js.map +1 -1
  110. package/dist/br/data/mun/PI.cjs +1 -1
  111. package/dist/br/data/mun/PI.cjs.map +1 -1
  112. package/dist/br/data/mun/PI.js +2982 -2844
  113. package/dist/br/data/mun/PI.js.map +1 -1
  114. package/dist/br/data/mun/PR.cjs +1 -1
  115. package/dist/br/data/mun/PR.cjs.map +1 -1
  116. package/dist/br/data/mun/PR.js +5425 -5240
  117. package/dist/br/data/mun/PR.js.map +1 -1
  118. package/dist/br/data/mun/RJ.cjs +1 -1
  119. package/dist/br/data/mun/RJ.cjs.map +1 -1
  120. package/dist/br/data/mun/RJ.js +1395 -1178
  121. package/dist/br/data/mun/RJ.js.map +1 -1
  122. package/dist/br/data/mun/RN.cjs +1 -1
  123. package/dist/br/data/mun/RN.cjs.map +1 -1
  124. package/dist/br/data/mun/RN.js +1608 -1382
  125. package/dist/br/data/mun/RN.js.map +1 -1
  126. package/dist/br/data/mun/RO.cjs +1 -1
  127. package/dist/br/data/mun/RO.cjs.map +1 -1
  128. package/dist/br/data/mun/RO.js +1392 -1470
  129. package/dist/br/data/mun/RO.js.map +1 -1
  130. package/dist/br/data/mun/RR.cjs +1 -1
  131. package/dist/br/data/mun/RR.cjs.map +1 -1
  132. package/dist/br/data/mun/RR.js +795 -778
  133. package/dist/br/data/mun/RR.js.map +1 -1
  134. package/dist/br/data/mun/RS.cjs +1 -1
  135. package/dist/br/data/mun/RS.cjs.map +1 -1
  136. package/dist/br/data/mun/RS.js +7579 -6424
  137. package/dist/br/data/mun/RS.js.map +1 -1
  138. package/dist/br/data/mun/SC.cjs +1 -1
  139. package/dist/br/data/mun/SC.cjs.map +1 -1
  140. package/dist/br/data/mun/SC.js +3979 -3357
  141. package/dist/br/data/mun/SC.js.map +1 -1
  142. package/dist/br/data/mun/SE.cjs +1 -1
  143. package/dist/br/data/mun/SE.cjs.map +1 -1
  144. package/dist/br/data/mun/SE.js +812 -625
  145. package/dist/br/data/mun/SE.js.map +1 -1
  146. package/dist/br/data/mun/SP.cjs +1 -1
  147. package/dist/br/data/mun/SP.cjs.map +1 -1
  148. package/dist/br/data/mun/SP.js +7866 -6803
  149. package/dist/br/data/mun/SP.js.map +1 -1
  150. package/dist/br/data/mun/TO.cjs +1 -1
  151. package/dist/br/data/mun/TO.cjs.map +1 -1
  152. package/dist/br/data/mun/TO.js +2763 -2817
  153. package/dist/br/data/mun/TO.js.map +1 -1
  154. package/dist/br/locations.cjs +1 -1
  155. package/dist/br/locations.cjs.map +1 -1
  156. package/dist/br/locations.js +97 -24
  157. package/dist/br/locations.js.map +1 -1
  158. package/dist/br/scales.cjs +1 -1
  159. package/dist/br/scales.cjs.map +1 -1
  160. package/dist/br/scales.js +8 -4
  161. package/dist/br/scales.js.map +1 -1
  162. package/dist/br/whatsapp.cjs +2 -0
  163. package/dist/br/whatsapp.cjs.map +1 -0
  164. package/dist/br/whatsapp.js +21 -0
  165. package/dist/br/whatsapp.js.map +1 -0
  166. package/dist/br.cjs +1 -1
  167. package/dist/br.cjs.map +1 -1
  168. package/dist/br.d.ts +188 -10
  169. package/dist/br.js +18 -17
  170. package/dist/br.js.map +1 -1
  171. package/dist/components/BottomSheet/BottomSheet.cjs +1 -1
  172. package/dist/components/BottomSheet/BottomSheet.cjs.map +1 -1
  173. package/dist/components/BottomSheet/BottomSheet.js +30 -27
  174. package/dist/components/BottomSheet/BottomSheet.js.map +1 -1
  175. package/dist/components/Command/Command.cjs +1 -1
  176. package/dist/components/Command/Command.cjs.map +1 -1
  177. package/dist/components/Command/Command.js +78 -75
  178. package/dist/components/Command/Command.js.map +1 -1
  179. package/dist/components/Drawer/Drawer.cjs +1 -1
  180. package/dist/components/Drawer/Drawer.cjs.map +1 -1
  181. package/dist/components/Drawer/Drawer.js +42 -39
  182. package/dist/components/Drawer/Drawer.js.map +1 -1
  183. package/dist/components/DropdownMenu/DropdownMenu.cjs +1 -1
  184. package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  185. package/dist/components/DropdownMenu/DropdownMenu.js +111 -67
  186. package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
  187. package/dist/components/Modal/Modal.cjs +1 -1
  188. package/dist/components/Modal/Modal.cjs.map +1 -1
  189. package/dist/components/Modal/Modal.js +45 -42
  190. package/dist/components/Modal/Modal.js.map +1 -1
  191. package/dist/components/Money/Money.cjs +1 -1
  192. package/dist/components/Money/Money.cjs.map +1 -1
  193. package/dist/components/Money/Money.js +10 -9
  194. package/dist/components/Money/Money.js.map +1 -1
  195. package/dist/components/Pagination/Pagination.cjs +1 -1
  196. package/dist/components/Pagination/Pagination.cjs.map +1 -1
  197. package/dist/components/Pagination/Pagination.js +38 -31
  198. package/dist/components/Pagination/Pagination.js.map +1 -1
  199. package/dist/components/Pagination/Pagination.module.cjs +1 -1
  200. package/dist/components/Pagination/Pagination.module.cjs.map +1 -1
  201. package/dist/components/Pagination/Pagination.module.js +4 -4
  202. package/dist/components/Pagination/Pagination.module.js.map +1 -1
  203. package/dist/components/Portal/Portal.cjs +1 -1
  204. package/dist/components/Portal/Portal.cjs.map +1 -1
  205. package/dist/components/Portal/Portal.js +9 -6
  206. package/dist/components/Portal/Portal.js.map +1 -1
  207. package/dist/components/Portal/portal-host.cjs +2 -0
  208. package/dist/components/Portal/portal-host.cjs.map +1 -0
  209. package/dist/components/Portal/portal-host.js +11 -0
  210. package/dist/components/Portal/portal-host.js.map +1 -0
  211. package/dist/components/Scheduler/Scheduler.cjs +1 -1
  212. package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
  213. package/dist/components/Scheduler/Scheduler.js +83 -82
  214. package/dist/components/Scheduler/Scheduler.js.map +1 -1
  215. package/dist/components/Toast/ToastProvider.cjs +1 -1
  216. package/dist/components/Toast/ToastProvider.cjs.map +1 -1
  217. package/dist/components/Toast/ToastProvider.js +55 -53
  218. package/dist/components/Toast/ToastProvider.js.map +1 -1
  219. package/dist/components/VirtualList/VirtualList.cjs +1 -1
  220. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  221. package/dist/components/VirtualList/VirtualList.js +41 -31
  222. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  223. package/dist/components/VirtualTable/VirtualTable.cjs +1 -1
  224. package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
  225. package/dist/components/VirtualTable/VirtualTable.js +78 -68
  226. package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
  227. package/dist/forms/masked-inputs.cjs +1 -1
  228. package/dist/forms/masked-inputs.cjs.map +1 -1
  229. package/dist/forms/masked-inputs.js +20 -19
  230. package/dist/forms/masked-inputs.js.map +1 -1
  231. package/dist/hooks/use-fullscreen-element.cjs +2 -0
  232. package/dist/hooks/use-fullscreen-element.cjs.map +1 -0
  233. package/dist/hooks/use-fullscreen-element.js +20 -0
  234. package/dist/hooks/use-fullscreen-element.js.map +1 -0
  235. package/dist/hooks/use-fullscreen.cjs +2 -0
  236. package/dist/hooks/use-fullscreen.cjs.map +1 -0
  237. package/dist/hooks/use-fullscreen.js +66 -0
  238. package/dist/hooks/use-fullscreen.js.map +1 -0
  239. package/dist/hooks/use-push-to-talk.cjs +2 -0
  240. package/dist/hooks/use-push-to-talk.cjs.map +1 -0
  241. package/dist/hooks/use-push-to-talk.js +61 -0
  242. package/dist/hooks/use-push-to-talk.js.map +1 -0
  243. package/dist/http/describe-api-error.cjs.map +1 -1
  244. package/dist/http/describe-api-error.js.map +1 -1
  245. package/dist/http/errors.cjs +1 -1
  246. package/dist/http/errors.cjs.map +1 -1
  247. package/dist/http/errors.js +34 -16
  248. package/dist/http/errors.js.map +1 -1
  249. package/dist/http/parse-response.cjs +2 -2
  250. package/dist/http/parse-response.cjs.map +1 -1
  251. package/dist/http/parse-response.js +9 -8
  252. package/dist/http/parse-response.js.map +1 -1
  253. package/dist/i18n/create-i18n.cjs +1 -1
  254. package/dist/i18n/create-i18n.cjs.map +1 -1
  255. package/dist/i18n/create-i18n.js +28 -27
  256. package/dist/i18n/create-i18n.js.map +1 -1
  257. package/dist/router/AppRouter.cjs +1 -1
  258. package/dist/router/AppRouter.cjs.map +1 -1
  259. package/dist/router/AppRouter.js +28 -21
  260. package/dist/router/AppRouter.js.map +1 -1
  261. package/dist/router/RouteGuard.cjs +1 -1
  262. package/dist/router/RouteGuard.cjs.map +1 -1
  263. package/dist/router/RouteGuard.js +4 -4
  264. package/dist/router/RouteGuard.js.map +1 -1
  265. package/dist/sse/create-event-stream.cjs +1 -1
  266. package/dist/sse/create-event-stream.cjs.map +1 -1
  267. package/dist/sse/create-event-stream.js +34 -38
  268. package/dist/sse/create-event-stream.js.map +1 -1
  269. package/dist/styles/AIChat.css +79 -0
  270. package/dist/styles/Accordion.css +12 -0
  271. package/dist/styles/Alert.css +32 -0
  272. package/dist/styles/AppBar.css +17 -0
  273. package/dist/styles/AppShell.css +8 -0
  274. package/dist/styles/AspectRatio.css +3 -0
  275. package/dist/styles/AudioPlayer.css +13 -0
  276. package/dist/styles/AudioRecorder.css +20 -0
  277. package/dist/styles/Avatar.css +13 -0
  278. package/dist/styles/AvatarGroup.css +18 -0
  279. package/dist/styles/Badge.css +25 -0
  280. package/dist/styles/Banner.css +13 -0
  281. package/dist/styles/BarList.css +10 -0
  282. package/dist/styles/BarcodeScanner.css +21 -0
  283. package/dist/styles/BottomNavigation.css +10 -0
  284. package/dist/styles/BottomSheet.css +11 -0
  285. package/dist/styles/BrazilMap.css +20 -0
  286. package/dist/styles/Breadcrumbs.css +8 -0
  287. package/dist/styles/Button.css +42 -0
  288. package/dist/styles/Calendar.css +16 -0
  289. package/dist/styles/Card.css +15 -0
  290. package/dist/styles/Carousel.css +17 -0
  291. package/dist/styles/Center.css +5 -0
  292. package/dist/styles/Chat.css +35 -0
  293. package/dist/styles/Checkbox.css +11 -0
  294. package/dist/styles/ChipInput.css +13 -0
  295. package/dist/styles/CodeBlock.css +25 -0
  296. package/dist/styles/Collapsible.css +6 -0
  297. package/dist/styles/Combobox.css +18 -0
  298. package/dist/styles/Command.css +20 -0
  299. package/dist/styles/ContextMenu.css +11 -0
  300. package/dist/styles/CopyButton.css +4 -0
  301. package/dist/styles/DataList.css +3 -0
  302. package/dist/styles/DataTable.css +19 -0
  303. package/dist/styles/DateRangePicker.css +22 -0
  304. package/dist/styles/DescriptionList.css +4 -0
  305. package/dist/styles/Divider.css +11 -0
  306. package/dist/styles/Drawer.css +22 -0
  307. package/dist/styles/DropdownMenu.css +16 -0
  308. package/dist/styles/Dropzone.css +7 -0
  309. package/dist/styles/EmptyState.css +6 -0
  310. package/dist/styles/ErrorState.css +6 -0
  311. package/dist/styles/ErrorText.css +2 -0
  312. package/dist/styles/FileUpload.css +17 -0
  313. package/dist/styles/FilterBar.css +19 -0
  314. package/dist/styles/FloatingActionButton.css +23 -0
  315. package/dist/styles/Form.css +21 -0
  316. package/dist/styles/HoverCard.css +11 -0
  317. package/dist/styles/IconPicker.css +6 -0
  318. package/dist/styles/Image.css +2 -0
  319. package/dist/styles/ImageCropper.css +16 -0
  320. package/dist/styles/Input.css +24 -0
  321. package/dist/styles/InstallBanner.css +8 -0
  322. package/dist/styles/Kanban.css +15 -0
  323. package/dist/styles/Kbd.css +5 -0
  324. package/dist/styles/Label.css +3 -0
  325. package/dist/styles/Layout.css +22 -0
  326. package/dist/styles/Lightbox.css +21 -0
  327. package/dist/styles/ListTile.css +14 -0
  328. package/dist/styles/MapLegend.css +9 -0
  329. package/dist/styles/Markdown.css +24 -0
  330. package/dist/styles/Masonry.css +4 -0
  331. package/dist/styles/Menubar.css +17 -0
  332. package/dist/styles/Modal.css +21 -0
  333. package/dist/styles/ModalsManager.css +2 -0
  334. package/dist/styles/MultiSelect.css +21 -0
  335. package/dist/styles/MunicipalitySearch.css +6 -0
  336. package/dist/styles/NProgress.css +2 -0
  337. package/dist/styles/Navbar.css +10 -0
  338. package/dist/styles/NavigationMenu.css +12 -0
  339. package/dist/styles/NavigationRail.css +14 -0
  340. package/dist/styles/NotificationCenter.css +21 -0
  341. package/dist/styles/OfflineIndicator.css +7 -0
  342. package/dist/styles/Page.css +13 -0
  343. package/dist/styles/Pagination.css +12 -0
  344. package/dist/styles/PasswordInput.css +21 -0
  345. package/dist/styles/PinInput.css +13 -0
  346. package/dist/styles/PixQRCode.css +9 -0
  347. package/dist/styles/Popover.css +10 -0
  348. package/dist/styles/Progress.css +11 -0
  349. package/dist/styles/QRCode.css +3 -0
  350. package/dist/styles/Radio.css +14 -0
  351. package/dist/styles/RangeSlider.css +15 -0
  352. package/dist/styles/RatingStars.css +11 -0
  353. package/dist/styles/RefreshIndicator.css +5 -0
  354. package/dist/styles/Resizable.css +13 -0
  355. package/dist/styles/RichTextEditor.css +19 -0
  356. package/dist/styles/SafeArea.css +7 -0
  357. package/dist/styles/Scheduler.css +24 -0
  358. package/dist/styles/ScrollArea.css +7 -0
  359. package/dist/styles/SearchBar.css +11 -0
  360. package/dist/styles/SegmentedControl.css +12 -0
  361. package/dist/styles/Select.css +14 -0
  362. package/dist/styles/Sidebar.css +19 -0
  363. package/dist/styles/SignaturePad.css +6 -0
  364. package/dist/styles/Skeleton.css +7 -0
  365. package/dist/styles/Slider.css +15 -0
  366. package/dist/styles/Spacer.css +4 -0
  367. package/dist/styles/Sparkline.css +4 -0
  368. package/dist/styles/Spinner.css +12 -0
  369. package/dist/styles/Stat.css +12 -0
  370. package/dist/styles/Stepper.css +17 -0
  371. package/dist/styles/StepperInput.css +15 -0
  372. package/dist/styles/Switch.css +11 -0
  373. package/dist/styles/SyncStatusBadge.css +13 -0
  374. package/dist/styles/Table.css +16 -0
  375. package/dist/styles/Tabs.css +14 -0
  376. package/dist/styles/Tag.css +14 -0
  377. package/dist/styles/Textarea.css +13 -0
  378. package/dist/styles/TimePicker.css +14 -0
  379. package/dist/styles/Timeline.css +17 -0
  380. package/dist/styles/Toast.css +21 -0
  381. package/dist/styles/Toggle.css +12 -0
  382. package/dist/styles/ToggleGroup.css +9 -0
  383. package/dist/styles/Tooltip.css +10 -0
  384. package/dist/styles/Tour.css +20 -0
  385. package/dist/styles/TrajectoryMap.css +16 -0
  386. package/dist/styles/Transfer.css +21 -0
  387. package/dist/styles/TreeView.css +17 -0
  388. package/dist/styles/TruncateText.css +2 -0
  389. package/dist/styles/UpdatePrompt.css +10 -0
  390. package/dist/styles/VirtualList.css +5 -0
  391. package/dist/styles/VirtualTable.css +17 -0
  392. package/dist/styles/VisuallyHidden.css +2 -0
  393. package/dist/styles/Wizard.css +4 -0
  394. package/dist/styles/actions.css +104 -0
  395. package/dist/styles/advanced.css +66 -0
  396. package/dist/styles/br.css +41 -0
  397. package/dist/styles/chat.css +113 -0
  398. package/dist/styles/core.css +40 -0
  399. package/dist/styles/data.css +222 -0
  400. package/dist/styles/editor.css +19 -0
  401. package/dist/styles/feedback.css +201 -0
  402. package/dist/styles/forms.css +321 -0
  403. package/dist/styles/geo.css +16 -0
  404. package/dist/styles/icons.css +6 -0
  405. package/dist/styles/identity.css +48 -0
  406. package/dist/styles/layout.css +122 -0
  407. package/dist/styles/media.css +52 -0
  408. package/dist/styles/navigation.css +167 -0
  409. package/dist/styles/overlay.css +73 -0
  410. package/dist/styles/utility.css +39 -0
  411. package/dist/styles.css +1 -1
  412. package/dist/sw/register-service-worker.cjs +1 -1
  413. package/dist/sw/register-service-worker.cjs.map +1 -1
  414. package/dist/sw/register-service-worker.js +21 -17
  415. package/dist/sw/register-service-worker.js.map +1 -1
  416. package/dist/sw.d.ts +17 -1
  417. package/dist/tempest-react-sdk.cjs +1 -1
  418. package/dist/tempest-react-sdk.d.ts +904 -41
  419. package/dist/tempest-react-sdk.js +293 -286
  420. package/dist/utils/dev-mode.cjs.map +1 -1
  421. package/dist/utils/dev-mode.js.map +1 -1
  422. package/dist/utils/format.cjs +1 -1
  423. package/dist/utils/format.cjs.map +1 -1
  424. package/dist/utils/format.js +22 -14
  425. package/dist/utils/format.js.map +1 -1
  426. package/dist/utils/intl-cache.cjs +2 -0
  427. package/dist/utils/intl-cache.cjs.map +1 -0
  428. package/dist/utils/intl-cache.js +23 -0
  429. package/dist/utils/intl-cache.js.map +1 -0
  430. package/dist/utils/json-frame.cjs +2 -0
  431. package/dist/utils/json-frame.cjs.map +1 -0
  432. package/dist/utils/json-frame.js +30 -0
  433. package/dist/utils/json-frame.js.map +1 -0
  434. package/dist/utils/numbers.cjs +1 -1
  435. package/dist/utils/numbers.cjs.map +1 -1
  436. package/dist/utils/numbers.js +8 -7
  437. package/dist/utils/numbers.js.map +1 -1
  438. package/dist/vision/results.cjs +1 -1
  439. package/dist/vision/results.cjs.map +1 -1
  440. package/dist/vision/results.js +26 -17
  441. package/dist/vision/results.js.map +1 -1
  442. package/dist/vision.d.ts +29 -0
  443. package/dist/vite/tempest-icons.cjs +1 -1
  444. package/dist/vite/tempest-icons.cjs.map +1 -1
  445. package/dist/vite/tempest-icons.js +1 -1
  446. package/dist/vite/tempest-icons.js.map +1 -1
  447. package/dist/webrtc/link-stats.cjs +2 -0
  448. package/dist/webrtc/link-stats.cjs.map +1 -0
  449. package/dist/webrtc/link-stats.js +74 -0
  450. package/dist/webrtc/link-stats.js.map +1 -0
  451. package/dist/webrtc/use-link-stats.cjs +2 -0
  452. package/dist/webrtc/use-link-stats.cjs.map +1 -0
  453. package/dist/webrtc/use-link-stats.js +22 -0
  454. package/dist/webrtc/use-link-stats.js.map +1 -0
  455. package/dist/ws/create-web-socket.cjs +1 -1
  456. package/dist/ws/create-web-socket.cjs.map +1 -1
  457. package/dist/ws/create-web-socket.js +81 -85
  458. package/dist/ws/create-web-socket.js.map +1 -1
  459. package/dist/ws/use-web-socket.cjs +1 -1
  460. package/dist/ws/use-web-socket.cjs.map +1 -1
  461. package/dist/ws/use-web-socket.js +42 -48
  462. package/dist/ws/use-web-socket.js.map +1 -1
  463. package/package.json +5 -2
@@ -33,19 +33,37 @@ function a(e) {
33
33
  if (typeof n != "object" || !n) continue;
34
34
  let e = n, i = r(e.loc);
35
35
  if (i === void 0 || i in t) continue;
36
- let a = o(e.msg) ?? o(e.message);
36
+ let a = l(e.msg) ?? l(e.message);
37
37
  a !== void 0 && (t[i] = a);
38
38
  }
39
39
  return Object.keys(t).length > 0 ? t : void 0;
40
40
  }
41
- function o(e, t = 0) {
41
+ function o(e) {
42
+ return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
43
+ }
44
+ function s(e) {
45
+ if (e === null) return;
46
+ let t = [
47
+ o(e.detail)?.field,
48
+ e.field,
49
+ o(e.details)?.field
50
+ ];
51
+ for (let e of t) if (typeof e == "string" && e !== "") return e;
52
+ }
53
+ function c(e, t) {
54
+ let n = a(e?.detail);
55
+ if (n !== void 0) return n;
56
+ let r = s(e);
57
+ if (r !== void 0 && t !== void 0) return { [r]: t };
58
+ }
59
+ function l(e, t = 0) {
42
60
  if (e != null) {
43
61
  if (typeof e == "string") return e === "" ? void 0 : e;
44
62
  if (typeof e == "number" || typeof e == "boolean") return String(e);
45
63
  if (!(t >= i)) {
46
64
  if (Array.isArray(e)) {
47
65
  let n = e.map((e) => {
48
- let n = o(e, t + 1);
66
+ let n = l(e, t + 1);
49
67
  if (n === void 0) return;
50
68
  let i = typeof e == "object" && e ? r(e.loc) : void 0;
51
69
  return i === void 0 ? n : `${i}: ${n}`;
@@ -54,36 +72,36 @@ function o(e, t = 0) {
54
72
  }
55
73
  if (typeof e == "object") {
56
74
  let n = e;
57
- return o(n.msg, t + 1) ?? o(n.message, t + 1) ?? o(n.detail, t + 1);
75
+ return l(n.msg, t + 1) ?? l(n.message, t + 1) ?? l(n.detail, t + 1);
58
76
  }
59
77
  }
60
78
  }
61
79
  }
62
- var s = /* @__PURE__ */ new Set([
80
+ var u = /* @__PURE__ */ new Set([
63
81
  0,
64
82
  408,
65
83
  425,
66
84
  429
67
85
  ]);
68
- function c(e) {
69
- return s.has(e) || e >= 500;
86
+ function d(e) {
87
+ return u.has(e) || e >= 500;
70
88
  }
71
- function l(e) {
89
+ function f(e) {
72
90
  return `Erro ${e}`;
73
91
  }
74
- function u(e, t, n, r) {
75
- let i = typeof t == "object" && t ? t : null, s = o(i?.detail) ?? o(i?.message) ?? l(e), c = typeof i?.code == "string" ? i.code : void 0, u = typeof i?.details == "object" && i.details !== null ? i.details : null;
92
+ function p(e, t, n, r) {
93
+ let i = typeof t == "object" && t ? t : null, a = l(i?.detail) ?? l(i?.message), o = a ?? f(e), s = typeof i?.code == "string" ? i.code : void 0, u = typeof i?.details == "object" && i.details !== null ? i.details : null;
76
94
  return {
77
95
  status: e,
78
- detail: s,
79
- code: c,
96
+ detail: o,
97
+ code: s,
80
98
  requestId: (typeof u?.request_id == "string" ? u.request_id : void 0) ?? n?.get("X-Request-ID") ?? r ?? void 0 ?? void 0,
81
- retryAfter: d(n?.get("Retry-After")),
82
- fields: a(i?.detail),
99
+ retryAfter: m(n?.get("Retry-After")),
100
+ fields: c(i, a),
83
101
  body: t
84
102
  };
85
103
  }
86
- function d(e) {
104
+ function m(e) {
87
105
  if (!e) return;
88
106
  let t = e.trim();
89
107
  if (/^\d+$/.test(t)) return Number(t);
@@ -91,6 +109,6 @@ function d(e) {
91
109
  if (!Number.isNaN(n)) return Math.max(0, Math.round((n - Date.now()) / 1e3));
92
110
  }
93
111
  //#endregion
94
- export { e as TempestApiError, u as buildApiError, t as isApiError, c as isRetriableStatus, d as parseRetryAfter, l as syntheticDetail };
112
+ export { e as TempestApiError, p as buildApiError, t as isApiError, d as isRetriableStatus, m as parseRetryAfter, f as syntheticDetail };
95
113
 
96
114
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../src/http/errors.ts"],"sourcesContent":["import type { ApiError } from \"./types\";\n\n/**\n * Error thrown by {@link createApiClient} / {@link uploadWithProgress} on a\n * non-2xx response. Mirrors the Tempest FastAPI SDK error envelope\n * (`{ detail, code, details.request_id }`) so callers get a typed `code` and a\n * `requestId` for log correlation, while still being a real `Error` (stack\n * trace, `instanceof Error`).\n *\n * @example\n * try {\n * await api.post(\"/users\", { body });\n * } catch (err) {\n * if (isApiError(err) && err.code === \"EMAIL_TAKEN\") {\n * showFieldError(\"email\", err.detail);\n * }\n * }\n */\nexport class TempestApiError extends Error implements ApiError {\n readonly status: number;\n readonly detail: string;\n readonly code?: string;\n readonly requestId?: string;\n readonly fields?: Record<string, string>;\n readonly body?: unknown;\n\n constructor(init: ApiError) {\n super(init.detail);\n this.name = \"TempestApiError\";\n this.status = init.status;\n this.detail = init.detail;\n this.code = init.code;\n this.requestId = init.requestId;\n this.fields = init.fields;\n this.body = init.body;\n }\n}\n\n/**\n * Type guard for the {@link ApiError} shape. Matches both {@link TempestApiError}\n * instances and plain objects carrying `status` + `detail`.\n *\n * @param error - The unknown value (typically a caught error).\n * @returns Whether `error` conforms to the `ApiError` contract.\n */\nexport function isApiError(error: unknown): error is ApiError {\n return (\n typeof error === \"object\" &&\n error !== null &&\n typeof (error as ApiError).status === \"number\" &&\n typeof (error as ApiError).detail === \"string\"\n );\n}\n\n/**\n * Location prefixes FastAPI puts at the head of a validation error's `loc`,\n * naming the part of the request rather than the field. Dropped from the\n * rendered path, so `[\"body\", \"email\"]` reads as `email`.\n */\nconst LOC_ROOTS: ReadonlySet<string> = new Set([\"body\", \"query\", \"path\", \"header\", \"cookie\"]);\n\n/**\n * Render a FastAPI validation error's `loc` tuple as a dotted field path.\n *\n * @param loc - The raw `loc` value from one validation error entry.\n * @returns The dotted path (`\"items.0.price\"`), or undefined when `loc` carries\n * nothing addressable.\n */\nfunction formatLoc(loc: unknown): string | undefined {\n if (!Array.isArray(loc)) return undefined;\n const parts = loc\n .filter(\n (part): part is string | number => typeof part === \"string\" || typeof part === \"number\",\n )\n .filter((part, index) => !(index === 0 && LOC_ROOTS.has(String(part))));\n return parts.length > 0 ? parts.join(\".\") : undefined;\n}\n\n/**\n * How deep {@link normalizeDetail} follows a nested `detail` before giving up.\n *\n * A real envelope needs two or three levels: the list, an entry, the entry's\n * own `detail`. The cap exists because the body is untrusted input arriving on\n * the error path — a response nesting `{\"detail\":{\"detail\":…}}` twenty thousand\n * deep (a 220 KB body) overflowed the stack, and a `RangeError` thrown while\n * *building* the error is worse than the error: the caller's `catch` stops\n * receiving a `TempestApiError`, so `isApiError` is false, `describeApiError`\n * has nothing to read and the `401` handling never runs.\n */\nconst MAX_DETAIL_DEPTH = 4;\n\n/**\n * Pull field-level messages out of a validation `detail` list.\n *\n * FastAPI's `422` body is `detail: [{ loc, msg, type }]`, which is exactly what\n * a form needs and exactly what the flattened `detail` string destroys. Only the\n * top level is read: a validation error names one field per entry, and following\n * nesting here would invent paths the backend never sent.\n *\n * @param raw - The `detail` value from the error body.\n * @returns Field path to message, or undefined when the body is not a\n * validation list (or carries no entry naming a field).\n */\nfunction collectFields(raw: unknown): Record<string, string> | undefined {\n if (!Array.isArray(raw)) return undefined;\n\n const fields: Record<string, string> = {};\n for (const entry of raw) {\n if (typeof entry !== \"object\" || entry === null) continue;\n const record = entry as Record<string, unknown>;\n const field = formatLoc(record.loc);\n if (field === undefined || field in fields) continue;\n const message = normalizeDetail(record.msg) ?? normalizeDetail(record.message);\n if (message === undefined) continue;\n fields[field] = message;\n }\n\n return Object.keys(fields).length > 0 ? fields : undefined;\n}\n\n/**\n * Collapse a backend `detail` of any shape into a single readable line.\n *\n * FastAPI answers a `422` with `detail` as a **list** of\n * `{ loc, msg, type }` entries, not a string. Passing that through `String()`\n * yields `\"[object Object]\"` — an error message that tells the user nothing and\n * hides which field failed. Each entry becomes `\"<field>: <msg>\"` and the\n * entries are joined with `\"; \"`; a nested object is read through its\n * `msg`/`message`/`detail` string.\n *\n * @param raw - The `detail` (or `message`) value from the error body.\n * @param depth - Current nesting level. Past {@link MAX_DETAIL_DEPTH} the value\n * is treated as unreadable instead of followed further.\n * @returns The rendered message, or undefined when nothing readable is there —\n * letting the caller fall back to the synthetic `Erro <status>`.\n */\nfunction normalizeDetail(raw: unknown, depth: number = 0): string | undefined {\n if (raw === null || raw === undefined) return undefined;\n if (typeof raw === \"string\") return raw === \"\" ? undefined : raw;\n if (typeof raw === \"number\" || typeof raw === \"boolean\") return String(raw);\n if (depth >= MAX_DETAIL_DEPTH) return undefined;\n\n if (Array.isArray(raw)) {\n const lines = raw\n .map((entry) => {\n const message = normalizeDetail(entry, depth + 1);\n if (message === undefined) return undefined;\n const field =\n typeof entry === \"object\" && entry !== null\n ? formatLoc((entry as Record<string, unknown>).loc)\n : undefined;\n return field === undefined ? message : `${field}: ${message}`;\n })\n .filter((line): line is string => line !== undefined);\n return lines.length > 0 ? lines.join(\"; \") : undefined;\n }\n\n if (typeof raw === \"object\") {\n const entry = raw as Record<string, unknown>;\n return (\n normalizeDetail(entry.msg, depth + 1) ??\n normalizeDetail(entry.message, depth + 1) ??\n normalizeDetail(entry.detail, depth + 1)\n );\n }\n\n return undefined;\n}\n\n/**\n * Statuses worth a second attempt, as a set for the sub-500 cases.\n *\n * A network failure (status `0`), a request timeout, a too-early replay, and a\n * rate limit — which usually carries the `Retry-After` the backoff honours.\n * Everything else below 500 is the server refusing on purpose.\n */\nconst RETRIABLE_STATUSES: ReadonlySet<number> = new Set([0, 408, 425, 429]);\n\n/**\n * Whether an HTTP status describes a condition a replay can plausibly fix.\n *\n * The single owner of that decision. It used to be spelled out in three places —\n * the client's own policy, the react-query default and the bare `retry()` helper\n * — and they had already drifted: the query default was missing `425`, so the\n * same `425 Too Early` was replayed through `createApiClient({ retry: true })`\n * and not replayed through `useQuery`. Same app, same error, two behaviours, and\n * no test caught it because each file asserted against its own copy.\n *\n * Deliberately about the status and nothing else. Whether a *non*-API error is\n * worth replaying, and whether the request's method may be replayed at all, are\n * the caller's calls: {@link createApiClient} refuses a non-idempotent method,\n * while a bare `retry()` has no method to inspect.\n *\n * @example\n * await api.get(\"/report\", {\n * retry: { shouldRetry: (error) => isApiError(error) && isRetriableStatus(error.status) },\n * });\n *\n * @param status - The HTTP status, where `0` means the request never landed.\n * @returns Whether a retry is worth attempting.\n */\nexport function isRetriableStatus(status: number): boolean {\n return RETRIABLE_STATUSES.has(status) || status >= 500;\n}\n\n/**\n * Detail text synthesised when a response body carries none.\n *\n * Exported because {@link describeApiError} has to recognise it: a detail the\n * server never sent says strictly less than the caller's own fallback, so the\n * funnel drops it. Comparing against a copied literal would silently stop\n * matching the day this sentence is reworded — no type error, no failing test.\n *\n * @param status - The HTTP status of the error.\n * @returns The synthetic detail for that status.\n */\nexport function syntheticDetail(status: number): string {\n return `Erro ${status}`;\n}\n\n/**\n * Parse an error body + response into the Tempest {@link ApiError} envelope.\n *\n * Reads `detail`/`message`, the programmatic `code`, and the correlation id\n * from `details.request_id` (falling back to the `X-Request-ID` header, then\n * the id the client sent).\n *\n * A `422` from FastAPI carries `detail` as a list of `{ loc, msg, type }`\n * entries, so it is flattened to `\"<field>: <msg>; <field>: <msg>\"` instead of\n * being stringified into `\"[object Object]\"`, and the same entries are indexed\n * on `fields` (`{ email: \"Field required\" }`) for a form to consume without\n * parsing that line back apart. The untouched body stays on `body`.\n *\n * That flattened `detail` is developer-facing: it carries the backend's field\n * paths and the validator's own wording. `describeApiError` knows not to show it\n * to a person when `fields` is set.\n *\n * @param status - HTTP status code.\n * @param body - The parsed error body (object, string, or null).\n * @param headers - The response headers (for the `X-Request-ID` fallback).\n * @param sentRequestId - The id the client sent on the request, if any.\n * @returns A fully-populated `ApiError`.\n *\n * @tempest-limits param-count — the arguments are the response as it arrives\n * (`status`, `body`, `headers`) plus the id the request was sent with, and they are\n * passed at exactly one place: the client's response path. Exported from the package\n * root, so the rewrite would be breaking for callers that build their own errors.\n */\nexport function buildApiError(\n status: number,\n body: unknown,\n headers?: Headers | { get(name: string): string | null },\n sentRequestId?: string,\n): ApiError {\n const obj =\n typeof body === \"object\" && body !== null ? (body as Record<string, unknown>) : null;\n const detail =\n normalizeDetail(obj?.detail) ?? normalizeDetail(obj?.message) ?? syntheticDetail(status);\n const code = typeof obj?.code === \"string\" ? obj.code : undefined;\n const details =\n typeof obj?.details === \"object\" && obj.details !== null\n ? (obj.details as Record<string, unknown>)\n : null;\n const requestId =\n (typeof details?.request_id === \"string\" ? details.request_id : undefined) ??\n headers?.get(\"X-Request-ID\") ??\n sentRequestId ??\n undefined;\n\n return {\n status,\n detail,\n code,\n requestId: requestId ?? undefined,\n retryAfter: parseRetryAfter(headers?.get(\"Retry-After\")),\n fields: collectFields(obj?.detail),\n body,\n };\n}\n\n/**\n * Parse a `Retry-After` header into seconds. Accepts a delta-seconds integer\n * (`\"120\"`) or an HTTP-date (`\"Wed, 21 Oct 2015 07:28:00 GMT\"`).\n *\n * @param value - The raw header value, or null.\n * @returns The delay in seconds (>= 0), or undefined when absent/unparseable.\n */\nexport function parseRetryAfter(value: string | null | undefined): number | undefined {\n if (!value) return undefined;\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) return Number(trimmed);\n const when = Date.parse(trimmed);\n if (Number.isNaN(when)) return undefined;\n return Math.max(0, Math.round((when - Date.now()) / 1000));\n}\n"],"mappings":";AAkBA,IAAa,IAAb,cAAqC,MAA0B;CAC3D;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,GAAgB;EAQxB,AAPA,MAAM,EAAK,MAAM,GACjB,KAAK,OAAO,mBACZ,KAAK,SAAS,EAAK,QACnB,KAAK,SAAS,EAAK,QACnB,KAAK,OAAO,EAAK,MACjB,KAAK,YAAY,EAAK,WACtB,KAAK,SAAS,EAAK,QACnB,KAAK,OAAO,EAAK;CACrB;AACJ;AASA,SAAgB,EAAW,GAAmC;CAC1D,OACI,OAAO,KAAU,cACjB,KACA,OAAQ,EAAmB,UAAW,YACtC,OAAQ,EAAmB,UAAW;AAE9C;AAOA,IAAM,oBAAiC,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAQ;CAAU;AAAQ,CAAC;AAS5F,SAAS,EAAU,GAAkC;CACjD,IAAI,CAAC,MAAM,QAAQ,CAAG,GAAG;CACzB,IAAM,IAAQ,EACT,QACI,MAAkC,OAAO,KAAS,YAAY,OAAO,KAAS,QACnF,CAAC,CACA,QAAQ,GAAM,MAAU,EAAE,MAAU,KAAK,EAAU,IAAI,OAAO,CAAI,CAAC,EAAE;CAC1E,OAAO,EAAM,SAAS,IAAI,EAAM,KAAK,GAAG,IAAI,KAAA;AAChD;AAaA,IAAM,IAAmB;AAczB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oBAA0C,IAAI,IAAI;CAAC;CAAG;CAAK;CAAK;AAAG,CAAC;AAyB1E,SAAgB,EAAkB,GAAyB;CACvD,OAAO,EAAmB,IAAI,CAAM,KAAK,KAAU;AACvD;AAaA,SAAgB,EAAgB,GAAwB;CACpD,OAAO,QAAQ;AACnB;AA8BA,SAAgB,EACZ,GACA,GACA,GACA,GACQ;CACR,IAAM,IACF,OAAO,KAAS,YAAY,IAAiB,IAAmC,MAC9E,IACF,EAAgB,GAAK,MAAM,KAAK,EAAgB,GAAK,OAAO,KAAK,EAAgB,CAAM,GACrF,IAAO,OAAO,GAAK,QAAS,WAAW,EAAI,OAAO,KAAA,GAClD,IACF,OAAO,GAAK,WAAY,YAAY,EAAI,YAAY,OAC7C,EAAI,UACL;CAOV,OAAO;EACH;EACA;EACA;EACA,YATC,OAAO,GAAS,cAAe,WAAW,EAAQ,aAAa,KAAA,MAChE,GAAS,IAAI,cAAc,KAC3B,KACA,KAAA,KAMwB,KAAA;EACxB,YAAY,EAAgB,GAAS,IAAI,aAAa,CAAC;EACvD,QAAQ,EAAc,GAAK,MAAM;EACjC;CACJ;AACJ;AASA,SAAgB,EAAgB,GAAsD;CAClF,IAAI,CAAC,GAAO;CACZ,IAAM,IAAU,EAAM,KAAK;CAC3B,IAAI,QAAQ,KAAK,CAAO,GAAG,OAAO,OAAO,CAAO;CAChD,IAAM,IAAO,KAAK,MAAM,CAAO;CAC3B,YAAO,MAAM,CAAI,GACrB,OAAO,KAAK,IAAI,GAAG,KAAK,OAAO,IAAO,KAAK,IAAI,KAAK,GAAI,CAAC;AAC7D"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../src/http/errors.ts"],"sourcesContent":["import type { ApiError } from \"./types\";\n\n/**\n * Error thrown by {@link createApiClient} / {@link uploadWithProgress} on a\n * non-2xx response. Mirrors the Tempest FastAPI SDK error envelope\n * (`{ detail, code, details.request_id }`) so callers get a typed `code` and a\n * `requestId` for log correlation, while still being a real `Error` (stack\n * trace, `instanceof Error`).\n *\n * @example\n * try {\n * await api.post(\"/users\", { body });\n * } catch (err) {\n * if (isApiError(err) && err.code === \"EMAIL_TAKEN\") {\n * showFieldError(\"email\", err.detail);\n * }\n * }\n */\nexport class TempestApiError extends Error implements ApiError {\n readonly status: number;\n readonly detail: string;\n readonly code?: string;\n readonly requestId?: string;\n readonly fields?: Record<string, string>;\n readonly body?: unknown;\n\n constructor(init: ApiError) {\n super(init.detail);\n this.name = \"TempestApiError\";\n this.status = init.status;\n this.detail = init.detail;\n this.code = init.code;\n this.requestId = init.requestId;\n this.fields = init.fields;\n this.body = init.body;\n }\n}\n\n/**\n * Type guard for the {@link ApiError} shape. Matches both {@link TempestApiError}\n * instances and plain objects carrying `status` + `detail`.\n *\n * @param error - The unknown value (typically a caught error).\n * @returns Whether `error` conforms to the `ApiError` contract.\n */\nexport function isApiError(error: unknown): error is ApiError {\n return (\n typeof error === \"object\" &&\n error !== null &&\n typeof (error as ApiError).status === \"number\" &&\n typeof (error as ApiError).detail === \"string\"\n );\n}\n\n/**\n * Location prefixes FastAPI puts at the head of a validation error's `loc`,\n * naming the part of the request rather than the field. Dropped from the\n * rendered path, so `[\"body\", \"email\"]` reads as `email`.\n */\nconst LOC_ROOTS: ReadonlySet<string> = new Set([\"body\", \"query\", \"path\", \"header\", \"cookie\"]);\n\n/**\n * Render a FastAPI validation error's `loc` tuple as a dotted field path.\n *\n * @param loc - The raw `loc` value from one validation error entry.\n * @returns The dotted path (`\"items.0.price\"`), or undefined when `loc` carries\n * nothing addressable.\n */\nfunction formatLoc(loc: unknown): string | undefined {\n if (!Array.isArray(loc)) return undefined;\n const parts = loc\n .filter(\n (part): part is string | number => typeof part === \"string\" || typeof part === \"number\",\n )\n .filter((part, index) => !(index === 0 && LOC_ROOTS.has(String(part))));\n return parts.length > 0 ? parts.join(\".\") : undefined;\n}\n\n/**\n * How deep {@link normalizeDetail} follows a nested `detail` before giving up.\n *\n * A real envelope needs two or three levels: the list, an entry, the entry's\n * own `detail`. The cap exists because the body is untrusted input arriving on\n * the error path — a response nesting `{\"detail\":{\"detail\":…}}` twenty thousand\n * deep (a 220 KB body) overflowed the stack, and a `RangeError` thrown while\n * *building* the error is worse than the error: the caller's `catch` stops\n * receiving a `TempestApiError`, so `isApiError` is false, `describeApiError`\n * has nothing to read and the `401` handling never runs.\n */\nconst MAX_DETAIL_DEPTH = 4;\n\n/**\n * Pull field-level messages out of a validation `detail` **list**.\n *\n * FastAPI's `422` body is `detail: [{ loc, msg, type }]`, which is exactly what\n * a form needs and exactly what the flattened `detail` string destroys. Only the\n * top level is read: a validation error names one field per entry, and following\n * nesting here would invent paths the backend never sent.\n *\n * This is one of two ways a body names a field — see {@link collectFields}, which\n * is the entry point and falls back to the singular keys when the list names\n * nothing addressable.\n *\n * @param raw - The `detail` value from the error body.\n * @returns Field path to message, or undefined when the body is not a\n * validation list (or carries no entry naming a field).\n */\nfunction collectListFields(raw: unknown): Record<string, string> | undefined {\n if (!Array.isArray(raw)) return undefined;\n\n const fields: Record<string, string> = {};\n for (const entry of raw) {\n if (typeof entry !== \"object\" || entry === null) continue;\n const record = entry as Record<string, unknown>;\n const field = formatLoc(record.loc);\n if (field === undefined || field in fields) continue;\n const message = normalizeDetail(record.msg) ?? normalizeDetail(record.message);\n if (message === undefined) continue;\n fields[field] = message;\n }\n\n return Object.keys(fields).length > 0 ? fields : undefined;\n}\n\n/**\n * Narrow a value to a plain object — a record, and not an array.\n *\n * Arrays are excluded because `typeof [] === \"object\"` while a list means\n * something else entirely here: FastAPI's `detail` list is read by\n * {@link collectListFields}, and reading `.field` off it would only ever be\n * undefined.\n *\n * @param value - The candidate value from the error body.\n * @returns The value as a record, or undefined when it is not a plain object.\n */\nfunction plainRecord(value: unknown): Record<string, unknown> | undefined {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\n/**\n * Read the field a **singular** error envelope names.\n *\n * A backend built on `tempest-fastapi-sdk` never answers with FastAPI's `detail`\n * list once it owns the handler: it names the guilty field in a key beside the\n * message. Three shapes are seen in the wild, and they are read inner-out:\n *\n * 1. `detail.field` — the field sits in the same object as the message it\n * describes (`{ detail: { detail: \"Cidade não encontrada…\", field: \"city\" } }`),\n * so it is the least ambiguous claim about which message belongs to which input.\n * 2. `field` at the top level — a flattened `RequestValidationError`\n * (`{ detail: \"Value error, … for field 'phone' in 'body'\", field: \"phone\" }`)\n * makes the same claim one level out.\n * 3. `details.field` — `details` is the envelope's free-form context bag, not a\n * validation channel, and its `field` may be about something no input on screen\n * carries (an unknown sort column, say). It answers last for exactly that reason.\n *\n * `location` (`\"body -> phone\"`) is deliberately not parsed: it renders the same\n * path `field` already names, no observed envelope sends it without `field`, and\n * splitting an arrow-separated string would invent a path the backend never sent.\n *\n * @param body - The parsed error body, or null when it was not an object.\n * @returns The field name, or undefined when none of the three keys carried a\n * non-empty string — anything else is not usable as a key on `fields`.\n */\nfunction namedField(body: Record<string, unknown> | null): string | undefined {\n if (body === null) return undefined;\n const candidates: readonly unknown[] = [\n plainRecord(body.detail)?.field,\n body.field,\n plainRecord(body.details)?.field,\n ];\n for (const candidate of candidates) {\n if (typeof candidate === \"string\" && candidate !== \"\") return candidate;\n }\n return undefined;\n}\n\n/**\n * Index the body's field-level messages, whichever envelope carried them.\n *\n * The single entry point behind `ApiError.fields`, and it applies two rules the\n * tests pin:\n *\n * - FastAPI's `detail` list wins whenever it names at least one addressable\n * field. A plain FastAPI app still answers a schema-level `422` with that list\n * even on a `tempest-fastapi-sdk` backend, so it stays authoritative.\n * - A named field with no readable message produces nothing. The only string\n * left at that point is the synthetic `Erro <status>`, and `{ phone: \"Erro 422\" }`\n * on an input is noise rather than an error message.\n *\n * @param body - The parsed error body, or null when it was not an object.\n * @param message - The readable message the same body produced, before the\n * synthetic fallback — the string that also becomes `ApiError.detail`.\n * @returns Field name to message, or undefined when nothing named a field.\n */\nfunction collectFields(\n body: Record<string, unknown> | null,\n message: string | undefined,\n): Record<string, string> | undefined {\n const listed = collectListFields(body?.detail);\n if (listed !== undefined) return listed;\n const field = namedField(body);\n if (field === undefined || message === undefined) return undefined;\n return { [field]: message };\n}\n\n/**\n * Collapse a backend `detail` of any shape into a single readable line.\n *\n * FastAPI answers a `422` with `detail` as a **list** of\n * `{ loc, msg, type }` entries, not a string. Passing that through `String()`\n * yields `\"[object Object]\"` — an error message that tells the user nothing and\n * hides which field failed. Each entry becomes `\"<field>: <msg>\"` and the\n * entries are joined with `\"; \"`; a nested object is read through its\n * `msg`/`message`/`detail` string.\n *\n * @param raw - The `detail` (or `message`) value from the error body.\n * @param depth - Current nesting level. Past {@link MAX_DETAIL_DEPTH} the value\n * is treated as unreadable instead of followed further.\n * @returns The rendered message, or undefined when nothing readable is there —\n * letting the caller fall back to the synthetic `Erro <status>`.\n */\nfunction normalizeDetail(raw: unknown, depth: number = 0): string | undefined {\n if (raw === null || raw === undefined) return undefined;\n if (typeof raw === \"string\") return raw === \"\" ? undefined : raw;\n if (typeof raw === \"number\" || typeof raw === \"boolean\") return String(raw);\n if (depth >= MAX_DETAIL_DEPTH) return undefined;\n\n if (Array.isArray(raw)) {\n const lines = raw\n .map((entry) => {\n const message = normalizeDetail(entry, depth + 1);\n if (message === undefined) return undefined;\n const field =\n typeof entry === \"object\" && entry !== null\n ? formatLoc((entry as Record<string, unknown>).loc)\n : undefined;\n return field === undefined ? message : `${field}: ${message}`;\n })\n .filter((line): line is string => line !== undefined);\n return lines.length > 0 ? lines.join(\"; \") : undefined;\n }\n\n if (typeof raw === \"object\") {\n const entry = raw as Record<string, unknown>;\n return (\n normalizeDetail(entry.msg, depth + 1) ??\n normalizeDetail(entry.message, depth + 1) ??\n normalizeDetail(entry.detail, depth + 1)\n );\n }\n\n return undefined;\n}\n\n/**\n * Statuses worth a second attempt, as a set for the sub-500 cases.\n *\n * A network failure (status `0`), a request timeout, a too-early replay, and a\n * rate limit — which usually carries the `Retry-After` the backoff honours.\n * Everything else below 500 is the server refusing on purpose.\n */\nconst RETRIABLE_STATUSES: ReadonlySet<number> = new Set([0, 408, 425, 429]);\n\n/**\n * Whether an HTTP status describes a condition a replay can plausibly fix.\n *\n * The single owner of that decision. It used to be spelled out in three places —\n * the client's own policy, the react-query default and the bare `retry()` helper\n * — and they had already drifted: the query default was missing `425`, so the\n * same `425 Too Early` was replayed through `createApiClient({ retry: true })`\n * and not replayed through `useQuery`. Same app, same error, two behaviours, and\n * no test caught it because each file asserted against its own copy.\n *\n * Deliberately about the status and nothing else. Whether a *non*-API error is\n * worth replaying, and whether the request's method may be replayed at all, are\n * the caller's calls: {@link createApiClient} refuses a non-idempotent method,\n * while a bare `retry()` has no method to inspect.\n *\n * @example\n * await api.get(\"/report\", {\n * retry: { shouldRetry: (error) => isApiError(error) && isRetriableStatus(error.status) },\n * });\n *\n * @param status - The HTTP status, where `0` means the request never landed.\n * @returns Whether a retry is worth attempting.\n */\nexport function isRetriableStatus(status: number): boolean {\n return RETRIABLE_STATUSES.has(status) || status >= 500;\n}\n\n/**\n * Detail text synthesised when a response body carries none.\n *\n * Exported because {@link describeApiError} has to recognise it: a detail the\n * server never sent says strictly less than the caller's own fallback, so the\n * funnel drops it. Comparing against a copied literal would silently stop\n * matching the day this sentence is reworded — no type error, no failing test.\n *\n * @param status - The HTTP status of the error.\n * @returns The synthetic detail for that status.\n */\nexport function syntheticDetail(status: number): string {\n return `Erro ${status}`;\n}\n\n/**\n * Parse an error body + response into the Tempest {@link ApiError} envelope.\n *\n * Reads `detail`/`message`, the programmatic `code`, and the correlation id\n * from `details.request_id` (falling back to the `X-Request-ID` header, then\n * the id the client sent).\n *\n * A `422` from FastAPI carries `detail` as a list of `{ loc, msg, type }`\n * entries, so it is flattened to `\"<field>: <msg>; <field>: <msg>\"` instead of\n * being stringified into `\"[object Object]\"`, and the same entries are indexed\n * on `fields` (`{ email: \"Field required\" }`) for a form to consume without\n * parsing that line back apart. The untouched body stays on `body`.\n *\n * A backend that owns its handlers — every `tempest-fastapi-sdk` app — sends no\n * such list, and names the field in a key instead:\n *\n * ```json\n * { \"detail\": \"Value error, … for field 'phone' in 'body'\", \"field\": \"phone\" }\n * { \"detail\": { \"detail\": \"Cidade não encontrada…\", \"field\": \"city\" },\n * \"code\": \"VALIDATION_ERROR\", \"details\": { \"field\": \"city\" } }\n * ```\n *\n * Those are indexed too, keyed by the field the backend named and valued with the\n * same sentence that becomes `detail`. Precedence is the list first, then\n * `detail.field`, `field`, `details.field` — see {@link collectFields}.\n *\n * A flattened `detail` from the list is developer-facing: it carries the\n * backend's field paths and the validator's own wording. `describeApiError` knows\n * not to show it to a person when `fields` is set — which now also covers a\n * business error that named a field, whose `detail` was a finished sentence. That\n * sentence is not lost: it is on `fields`, attached to the input that failed.\n *\n * @param status - HTTP status code.\n * @param body - The parsed error body (object, string, or null).\n * @param headers - The response headers (for the `X-Request-ID` fallback).\n * @param sentRequestId - The id the client sent on the request, if any.\n * @returns A fully-populated `ApiError`.\n *\n * @tempest-limits param-count — the arguments are the response as it arrives\n * (`status`, `body`, `headers`) plus the id the request was sent with, and they are\n * passed at exactly three places, all of them a client's response path\n * (`createApiClient`, `uploadWithProgress`, `createResumableUpload`). Wrapping them\n * in an options object would name each argument twice at every call site to say\n * nothing new.\n */\nexport function buildApiError(\n status: number,\n body: unknown,\n headers?: Headers | { get(name: string): string | null },\n sentRequestId?: string,\n): ApiError {\n const obj =\n typeof body === \"object\" && body !== null ? (body as Record<string, unknown>) : null;\n const message = normalizeDetail(obj?.detail) ?? normalizeDetail(obj?.message);\n const detail = message ?? syntheticDetail(status);\n const code = typeof obj?.code === \"string\" ? obj.code : undefined;\n const details =\n typeof obj?.details === \"object\" && obj.details !== null\n ? (obj.details as Record<string, unknown>)\n : null;\n const requestId =\n (typeof details?.request_id === \"string\" ? details.request_id : undefined) ??\n headers?.get(\"X-Request-ID\") ??\n sentRequestId ??\n undefined;\n\n return {\n status,\n detail,\n code,\n requestId: requestId ?? undefined,\n retryAfter: parseRetryAfter(headers?.get(\"Retry-After\")),\n fields: collectFields(obj, message),\n body,\n };\n}\n\n/**\n * Parse a `Retry-After` header into seconds. Accepts a delta-seconds integer\n * (`\"120\"`) or an HTTP-date (`\"Wed, 21 Oct 2015 07:28:00 GMT\"`).\n *\n * @param value - The raw header value, or null.\n * @returns The delay in seconds (>= 0), or undefined when absent/unparseable.\n */\nexport function parseRetryAfter(value: string | null | undefined): number | undefined {\n if (!value) return undefined;\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) return Number(trimmed);\n const when = Date.parse(trimmed);\n if (Number.isNaN(when)) return undefined;\n return Math.max(0, Math.round((when - Date.now()) / 1000));\n}\n"],"mappings":";AAkBA,IAAa,IAAb,cAAqC,MAA0B;CAC3D;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,GAAgB;EAQxB,AAPA,MAAM,EAAK,MAAM,GACjB,KAAK,OAAO,mBACZ,KAAK,SAAS,EAAK,QACnB,KAAK,SAAS,EAAK,QACnB,KAAK,OAAO,EAAK,MACjB,KAAK,YAAY,EAAK,WACtB,KAAK,SAAS,EAAK,QACnB,KAAK,OAAO,EAAK;CACrB;AACJ;AASA,SAAgB,EAAW,GAAmC;CAC1D,OACI,OAAO,KAAU,cACjB,KACA,OAAQ,EAAmB,UAAW,YACtC,OAAQ,EAAmB,UAAW;AAE9C;AAOA,IAAM,oBAAiC,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAQ;CAAU;AAAQ,CAAC;AAS5F,SAAS,EAAU,GAAkC;CACjD,IAAI,CAAC,MAAM,QAAQ,CAAG,GAAG;CACzB,IAAM,IAAQ,EACT,QACI,MAAkC,OAAO,KAAS,YAAY,OAAO,KAAS,QACnF,CAAC,CACA,QAAQ,GAAM,MAAU,EAAE,MAAU,KAAK,EAAU,IAAI,OAAO,CAAI,CAAC,EAAE;CAC1E,OAAO,EAAM,SAAS,IAAI,EAAM,KAAK,GAAG,IAAI,KAAA;AAChD;AAaA,IAAM,IAAmB;AAkBzB,SAAS,EAAkB,GAAkD;CACzE,IAAI,CAAC,MAAM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AASA,SAAgB,EAAgB,GAAsD;CAClF,IAAI,CAAC,GAAO;CACZ,IAAM,IAAU,EAAM,KAAK;CAC3B,IAAI,QAAQ,KAAK,CAAO,GAAG,OAAO,OAAO,CAAO;CAChD,IAAM,IAAO,KAAK,MAAM,CAAO;CAC3B,YAAO,MAAM,CAAI,GACrB,OAAO,KAAK,IAAI,GAAG,KAAK,OAAO,IAAO,KAAK,IAAI,KAAK,GAAI,CAAC;AAC7D"}
@@ -1,3 +1,3 @@
1
- function e(e,t,n){let r=e.safeParse(t);if(r.success)return r.data;if(typeof process<`u`&&(process.env.NODE_ENV===`development`||process.env.NODE_ENV===`test`)){let e=r.error.issues.map(e=>` - ${e.path.join(`.`)||`<root>`}: ${e.message}`).join(`
2
- `);throw Error(`[parseResponse] Contract drift on ${n}:\n${e}\n\nRaw payload: ${JSON.stringify(t,null,2)}`)}throw Error(`Resposta inválida do servidor (${n}).`)}exports.parseResponse=e;
1
+ const e=require("../utils/dev-mode.cjs");function t(t,n,r){let i=t.safeParse(n);if(i.success)return i.data;if(e.isDevBuild()){let e=i.error.issues.map(e=>` - ${e.path.join(`.`)||`<root>`}: ${e.message}`).join(`
2
+ `);throw Error(`[parseResponse] Contract drift on ${r}:\n${e}\n\nRaw payload: ${JSON.stringify(n,null,2)}`)}throw Error(`Resposta inválida do servidor (${r}).`)}exports.parseResponse=t;
3
3
  //# sourceMappingURL=parse-response.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-response.cjs","names":[],"sources":["../../src/http/parse-response.ts"],"sourcesContent":["import type { z } from \"zod\";\n\n/**\n * Validate an unknown response payload against a zod schema.\n *\n * In development, throws a detailed error pointing at the divergent field.\n * In production, throws a generic error so internals do not leak to users.\n *\n * @param schema - The zod schema to parse against.\n * @param raw - The raw response payload.\n * @param context - A label used in error messages, e.g. \"POST /auth/login\".\n * @returns The parsed, typed payload.\n */\nexport function parseResponse<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n raw: unknown,\n context: string,\n): z.infer<TSchema> {\n const result = schema.safeParse(raw);\n if (result.success) {\n return result.data;\n }\n\n const isDev =\n typeof process !== \"undefined\" &&\n (process.env?.NODE_ENV === \"development\" || process.env?.NODE_ENV === \"test\");\n\n if (isDev) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(\n `[parseResponse] Contract drift on ${context}:\\n${issues}\\n\\nRaw payload: ${JSON.stringify(raw, null, 2)}`,\n );\n }\n throw new Error(`Resposta inválida do servidor (${context}).`);\n}\n"],"mappings":"AAaA,SAAgB,EACZ,EACA,EACA,EACgB,CAChB,IAAM,EAAS,EAAO,UAAU,CAAG,EACnC,GAAI,EAAO,QACP,OAAO,EAAO,KAOlB,GAHI,OAAO,QAAY,MAAA,QAAA,IAAA,WACQ,eAAA,QAAA,IAAA,WAA2C,QAE/D,CACP,IAAM,EAAS,EAAO,MAAM,OACvB,IAAK,GAAM,OAAO,EAAE,KAAK,KAAK,GAAG,GAAK,SAAS,IAAI,EAAE,SAAS,CAAC,CAC/D,KAAK;CAAI,EACd,MAAU,MACN,qCAAqC,EAAQ,KAAK,EAAO,mBAAmB,KAAK,UAAU,EAAK,KAAM,CAAC,GAC3G,CACJ,CACA,MAAU,MAAM,kCAAkC,EAAQ,GAAG,CACjE"}
1
+ {"version":3,"file":"parse-response.cjs","names":[],"sources":["../../src/http/parse-response.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nimport { isDevBuild } from \"../utils/dev-mode\";\n\n/**\n * Validate an unknown response payload against a zod schema.\n *\n * A development build throws a detailed error naming every divergent field path\n * and embedding the raw payload; every other build throws a generic sentence, so\n * server internals never reach a user's screen or an error tracker.\n *\n * Which one you get comes from `isDevBuild()`, the SDK's single answer to that\n * question, rather than from a check written here. This function used to ask\n * `typeof process !== \"undefined\" && process.env?.NODE_ENV === \"development\"`,\n * and a browser has no `process` identifier at all — so the guard short-circuited\n * and the detailed branch was dead in exactly the build it was written for, no\n * matter what the bundler substituted behind it.\n *\n * The rule `isDevBuild()` applies is `NODE_ENV !== \"production\"`, which is wider\n * than the old `\"development\" || \"test\"`: a staging build that never sets\n * `NODE_ENV=production` gets the drift report, raw payload included.\n *\n * @param schema - The zod schema to parse against.\n * @param raw - The raw response payload.\n * @param context - A label used in error messages, e.g. \"POST /auth/login\".\n * @returns The parsed, typed payload.\n * @throws Error When the payload does not match the schema: `[parseResponse]\n * Contract drift on <context>` with the field paths and the raw payload in a\n * development build, `Resposta inválida do servidor (<context>).` otherwise.\n */\nexport function parseResponse<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n raw: unknown,\n context: string,\n): z.infer<TSchema> {\n const result = schema.safeParse(raw);\n if (result.success) {\n return result.data;\n }\n\n if (isDevBuild()) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(\n `[parseResponse] Contract drift on ${context}:\\n${issues}\\n\\nRaw payload: ${JSON.stringify(raw, null, 2)}`,\n );\n }\n throw new Error(`Resposta inválida do servidor (${context}).`);\n}\n"],"mappings":"yCA8BA,SAAgB,EACZ,EACA,EACA,EACgB,CAChB,IAAM,EAAS,EAAO,UAAU,CAAG,EACnC,GAAI,EAAO,QACP,OAAO,EAAO,KAGlB,GAAI,EAAA,WAAW,EAAG,CACd,IAAM,EAAS,EAAO,MAAM,OACvB,IAAK,GAAM,OAAO,EAAE,KAAK,KAAK,GAAG,GAAK,SAAS,IAAI,EAAE,SAAS,CAAC,CAC/D,KAAK;CAAI,EACd,MAAU,MACN,qCAAqC,EAAQ,KAAK,EAAO,mBAAmB,KAAK,UAAU,EAAK,KAAM,CAAC,GAC3G,CACJ,CACA,MAAU,MAAM,kCAAkC,EAAQ,GAAG,CACjE"}
@@ -1,14 +1,15 @@
1
+ import { isDevBuild as e } from "../utils/dev-mode.js";
1
2
  //#region src/http/parse-response.ts
2
- function e(e, t, n) {
3
- let r = e.safeParse(t);
4
- if (r.success) return r.data;
5
- if (typeof process < "u" && (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")) {
6
- let e = r.error.issues.map((e) => ` - ${e.path.join(".") || "<root>"}: ${e.message}`).join("\n");
7
- throw Error(`[parseResponse] Contract drift on ${n}:\n${e}\n\nRaw payload: ${JSON.stringify(t, null, 2)}`);
3
+ function t(t, n, r) {
4
+ let i = t.safeParse(n);
5
+ if (i.success) return i.data;
6
+ if (e()) {
7
+ let e = i.error.issues.map((e) => ` - ${e.path.join(".") || "<root>"}: ${e.message}`).join("\n");
8
+ throw Error(`[parseResponse] Contract drift on ${r}:\n${e}\n\nRaw payload: ${JSON.stringify(n, null, 2)}`);
8
9
  }
9
- throw Error(`Resposta inválida do servidor (${n}).`);
10
+ throw Error(`Resposta inválida do servidor (${r}).`);
10
11
  }
11
12
  //#endregion
12
- export { e as parseResponse };
13
+ export { t as parseResponse };
13
14
 
14
15
  //# sourceMappingURL=parse-response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-response.js","names":[],"sources":["../../src/http/parse-response.ts"],"sourcesContent":["import type { z } from \"zod\";\n\n/**\n * Validate an unknown response payload against a zod schema.\n *\n * In development, throws a detailed error pointing at the divergent field.\n * In production, throws a generic error so internals do not leak to users.\n *\n * @param schema - The zod schema to parse against.\n * @param raw - The raw response payload.\n * @param context - A label used in error messages, e.g. \"POST /auth/login\".\n * @returns The parsed, typed payload.\n */\nexport function parseResponse<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n raw: unknown,\n context: string,\n): z.infer<TSchema> {\n const result = schema.safeParse(raw);\n if (result.success) {\n return result.data;\n }\n\n const isDev =\n typeof process !== \"undefined\" &&\n (process.env?.NODE_ENV === \"development\" || process.env?.NODE_ENV === \"test\");\n\n if (isDev) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(\n `[parseResponse] Contract drift on ${context}:\\n${issues}\\n\\nRaw payload: ${JSON.stringify(raw, null, 2)}`,\n );\n }\n throw new Error(`Resposta inválida do servidor (${context}).`);\n}\n"],"mappings":";AAaA,SAAgB,EACZ,GACA,GACA,GACgB;CAChB,IAAM,IAAS,EAAO,UAAU,CAAG;CACnC,IAAI,EAAO,SACP,OAAO,EAAO;CAOlB,IAHI,OAAO,UAAY,QAAA,QAAA,IAAA,aACQ,iBAAA,QAAA,IAAA,aAA2C,SAE/D;EACP,IAAM,IAAS,EAAO,MAAM,OACvB,KAAK,MAAM,OAAO,EAAE,KAAK,KAAK,GAAG,KAAK,SAAS,IAAI,EAAE,SAAS,CAAC,CAC/D,KAAK,IAAI;EACd,MAAU,MACN,qCAAqC,EAAQ,KAAK,EAAO,mBAAmB,KAAK,UAAU,GAAK,MAAM,CAAC,GAC3G;CACJ;CACA,MAAU,MAAM,kCAAkC,EAAQ,GAAG;AACjE"}
1
+ {"version":3,"file":"parse-response.js","names":[],"sources":["../../src/http/parse-response.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nimport { isDevBuild } from \"../utils/dev-mode\";\n\n/**\n * Validate an unknown response payload against a zod schema.\n *\n * A development build throws a detailed error naming every divergent field path\n * and embedding the raw payload; every other build throws a generic sentence, so\n * server internals never reach a user's screen or an error tracker.\n *\n * Which one you get comes from `isDevBuild()`, the SDK's single answer to that\n * question, rather than from a check written here. This function used to ask\n * `typeof process !== \"undefined\" && process.env?.NODE_ENV === \"development\"`,\n * and a browser has no `process` identifier at all — so the guard short-circuited\n * and the detailed branch was dead in exactly the build it was written for, no\n * matter what the bundler substituted behind it.\n *\n * The rule `isDevBuild()` applies is `NODE_ENV !== \"production\"`, which is wider\n * than the old `\"development\" || \"test\"`: a staging build that never sets\n * `NODE_ENV=production` gets the drift report, raw payload included.\n *\n * @param schema - The zod schema to parse against.\n * @param raw - The raw response payload.\n * @param context - A label used in error messages, e.g. \"POST /auth/login\".\n * @returns The parsed, typed payload.\n * @throws Error When the payload does not match the schema: `[parseResponse]\n * Contract drift on <context>` with the field paths and the raw payload in a\n * development build, `Resposta inválida do servidor (<context>).` otherwise.\n */\nexport function parseResponse<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n raw: unknown,\n context: string,\n): z.infer<TSchema> {\n const result = schema.safeParse(raw);\n if (result.success) {\n return result.data;\n }\n\n if (isDevBuild()) {\n const issues = result.error.issues\n .map((i) => ` - ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(\n `[parseResponse] Contract drift on ${context}:\\n${issues}\\n\\nRaw payload: ${JSON.stringify(raw, null, 2)}`,\n );\n }\n throw new Error(`Resposta inválida do servidor (${context}).`);\n}\n"],"mappings":";;AA8BA,SAAgB,EACZ,GACA,GACA,GACgB;CAChB,IAAM,IAAS,EAAO,UAAU,CAAG;CACnC,IAAI,EAAO,SACP,OAAO,EAAO;CAGlB,IAAI,EAAW,GAAG;EACd,IAAM,IAAS,EAAO,MAAM,OACvB,KAAK,MAAM,OAAO,EAAE,KAAK,KAAK,GAAG,KAAK,SAAS,IAAI,EAAE,SAAS,CAAC,CAC/D,KAAK,IAAI;EACd,MAAU,MACN,qCAAqC,EAAQ,KAAK,EAAO,mBAAmB,KAAK,UAAU,GAAK,MAAM,CAAC,GAC3G;CACJ;CACA,MAAU,MAAM,kCAAkC,EAAQ,GAAG;AACjE"}
@@ -1,2 +1,2 @@
1
- function e(e,t){return t?e.replace(/\{(\w+)\}/g,(e,n)=>{let r=t[n];return r===void 0?`{${n}}`:String(r)}):e}function t(e,t,n,r){let i=e[t]?.[r];if(i!==void 0)return i;if(n){let t=e[n]?.[r];if(t!==void 0)return t}return null}function n(r){let{locale:i,fallbackLocale:a=null,messages:o}=r;function s(n,r,s){let c=t(o,i,a,n)??s?.default;return c===void 0?n:e(c,r)}function c(n,r,s,c){let l=t(o,i,a,`${n}${r===1?`_one`:`_other`}`)??t(o,i,a,n)??c?.default;return l===void 0?n:e(l,{count:r,...s??{}})}function l(e,t){return new Intl.NumberFormat(i,t).format(e)}function u(e,t){let n=typeof e==`string`?new Date(e):e;return Number.isNaN(n.getTime())?``:new Intl.DateTimeFormat(i,t).format(n)}return{locale:i,fallbackLocale:a,t:s,plural:c,formatNumber:l,formatDate:u,withLocale:e=>n({locale:e,fallbackLocale:a??void 0,messages:o})}}exports.createI18n=n;
1
+ const e=require("../utils/intl-cache.cjs");function t(e,t){return t?e.replace(/\{(\w+)\}/g,(e,n)=>{let r=t[n];return r===void 0?`{${n}}`:String(r)}):e}function n(e,t,n,r){let i=e[t]?.[r];if(i!==void 0)return i;if(n){let t=e[n]?.[r];if(t!==void 0)return t}return null}function r(i){let{locale:a,fallbackLocale:o=null,messages:s}=i;function c(e,r,i){let c=n(s,a,o,e)??i?.default;return c===void 0?e:t(c,r)}function l(e,r,i,c){let l=n(s,a,o,`${e}${r===1?`_one`:`_other`}`)??n(s,a,o,e)??c?.default;return l===void 0?e:t(l,{count:r,...i??{}})}function u(t,n){return e.numberFormat(a,n).format(t)}function d(t,n){let r=typeof t==`string`?new Date(t):t;return Number.isNaN(r.getTime())?``:e.dateTimeFormat(a,n).format(r)}return{locale:a,fallbackLocale:o,t:c,plural:l,formatNumber:u,formatDate:d,withLocale:e=>r({locale:e,fallbackLocale:o??void 0,messages:s})}}exports.createI18n=r;
2
2
  //# sourceMappingURL=create-i18n.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-i18n.cjs","names":[],"sources":["../../src/i18n/create-i18n.ts"],"sourcesContent":["export type Messages = Record<string, string>;\nexport type Catalog = Record<string, Messages>;\nexport type InterpolationValues = Record<string, string | number>;\n\nexport interface CreateI18nOptions {\n /** Initial locale. */\n locale: string;\n /** Fallback locale used when a key is missing in the active locale. */\n fallbackLocale?: string;\n /** Catalog `{ [locale]: { [key]: \"...\" } }`. */\n messages: Catalog;\n}\n\n/** Per-call options for {@link I18n.t} and {@link I18n.plural}. */\nexport interface TranslateOptions {\n /**\n * Text to use when the catalog defines neither the key nor its fallback.\n *\n * Without this, a miss returns the key, and a caller that wants its own text\n * instead has to *detect* the miss — which from the outside means comparing\n * the result against the key it just passed in. That heuristic is wrong for a\n * catalog that legitimately maps a key to itself, and it is what every\n * translatable string the SDK ships would otherwise have to copy.\n *\n * Interpolated like any other message, so a default carries `{placeholders}`\n * too and is not second-class.\n */\n default?: string;\n}\n\nexport interface I18n {\n /** Currently active locale. */\n locale: string;\n /** Fallback locale (or `null` when not configured). */\n fallbackLocale: string | null;\n /**\n * Translate `key`, interpolating `{name}` placeholders from `params`.\n * Falls back to the configured fallback locale, then to `options.default`,\n * then to the key itself.\n */\n t: (key: string, params?: InterpolationValues, options?: TranslateOptions) => string;\n /**\n * Plural-aware translation. Tries `${key}_one` for `count === 1` and\n * `${key}_other` otherwise, with `{count}` available for interpolation.\n * Falls back to `options.default`, then to the key itself.\n */\n plural: (\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ) => string;\n /** Format a number using `Intl.NumberFormat` on the active locale. */\n formatNumber: (value: number, options?: Intl.NumberFormatOptions) => string;\n /** Format a Date using `Intl.DateTimeFormat` on the active locale. */\n formatDate: (value: Date | string, options?: Intl.DateTimeFormatOptions) => string;\n /** Build a new `I18n` instance pointing at a different locale. */\n withLocale: (locale: string) => I18n;\n}\n\nfunction interpolate(template: string, params?: InterpolationValues): string {\n if (!params) return template;\n return template.replace(/\\{(\\w+)\\}/g, (_match, name: string) => {\n const value = params[name];\n return value === undefined ? `{${name}}` : String(value);\n });\n}\n\nfunction lookup(\n catalog: Catalog,\n locale: string,\n fallback: string | null,\n key: string,\n): string | null {\n const direct = catalog[locale]?.[key];\n if (direct !== undefined) return direct;\n if (fallback) {\n const fallbackValue = catalog[fallback]?.[key];\n if (fallbackValue !== undefined) return fallbackValue;\n }\n return null;\n}\n\n/**\n * Create an i18n object with translation, pluralization and Intl helpers.\n *\n * The catalog is a plain `{ [locale]: { [key]: \"...\" } }` map — bring your\n * own keys, namespaces, or nested-key conventions. The SDK does not enforce\n * a schema so you can plug it into any string-loading pipeline.\n *\n * @example\n * const i18n = createI18n({\n * locale: \"pt-BR\",\n * fallbackLocale: \"en\",\n * messages: {\n * \"pt-BR\": {\n * \"greet\": \"Olá, {name}\",\n * \"alos_one\": \"{count} Alô\",\n * \"alos_other\": \"{count} Alôs\",\n * },\n * \"en\": { greet: \"Hi, {name}\", alos_one: \"{count} Alo\", alos_other: \"{count} Alos\" },\n * },\n * });\n * i18n.t(\"greet\", { name: \"Mau\" }); // \"Olá, Mau\"\n * i18n.plural(\"alos\", 3); // \"3 Alôs\"\n *\n * @example\n * // A key the catalog does not define, with text to show instead of the key.\n * i18n.t(\"cart.empty\", undefined, { default: \"Seu carrinho está vazio\" });\n */\nexport function createI18n(options: CreateI18nOptions): I18n {\n const { locale, fallbackLocale = null, messages } = options;\n\n function t(key: string, params?: InterpolationValues, options?: TranslateOptions): string {\n const template = lookup(messages, locale, fallbackLocale, key) ?? options?.default;\n if (template === undefined) return key;\n return interpolate(template, params);\n }\n\n function plural(\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ): string {\n const suffix = count === 1 ? \"_one\" : \"_other\";\n const template =\n lookup(messages, locale, fallbackLocale, `${key}${suffix}`) ??\n lookup(messages, locale, fallbackLocale, key) ??\n options?.default;\n if (template === undefined) return key;\n return interpolate(template, { count, ...(params ?? {}) });\n }\n\n function formatNumber(value: number, opts?: Intl.NumberFormatOptions): string {\n return new Intl.NumberFormat(locale, opts).format(value);\n }\n\n function formatDate(value: Date | string, opts?: Intl.DateTimeFormatOptions): string {\n const date = typeof value === \"string\" ? new Date(value) : value;\n if (Number.isNaN(date.getTime())) return \"\";\n return new Intl.DateTimeFormat(locale, opts).format(date);\n }\n\n return {\n locale,\n fallbackLocale,\n t,\n plural,\n formatNumber,\n formatDate,\n withLocale: (nextLocale) =>\n createI18n({\n locale: nextLocale,\n fallbackLocale: fallbackLocale ?? undefined,\n messages,\n }),\n };\n}\n"],"mappings":"AA4DA,SAAS,EAAY,EAAkB,EAAsC,CAEzE,OADK,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ACA,SACA,eACA,aACA,WAAa,GACT,EAAW,CACP,OAAQ,EACR,eAAgB,GAAkB,IAAA,GAClC,UACJ,CAAC,CACT,CACJ"}
1
+ {"version":3,"file":"create-i18n.cjs","names":[],"sources":["../../src/i18n/create-i18n.ts"],"sourcesContent":["import { dateTimeFormat, numberFormat } from \"@/utils/intl-cache\";\nexport type Messages = Record<string, string>;\nexport type Catalog = Record<string, Messages>;\nexport type InterpolationValues = Record<string, string | number>;\n\nexport interface CreateI18nOptions {\n /** Initial locale. */\n locale: string;\n /** Fallback locale used when a key is missing in the active locale. */\n fallbackLocale?: string;\n /** Catalog `{ [locale]: { [key]: \"...\" } }`. */\n messages: Catalog;\n}\n\n/** Per-call options for {@link I18n.t} and {@link I18n.plural}. */\nexport interface TranslateOptions {\n /**\n * Text to use when the catalog defines neither the key nor its fallback.\n *\n * Without this, a miss returns the key, and a caller that wants its own text\n * instead has to *detect* the miss — which from the outside means comparing\n * the result against the key it just passed in. That heuristic is wrong for a\n * catalog that legitimately maps a key to itself, and it is what every\n * translatable string the SDK ships would otherwise have to copy.\n *\n * Interpolated like any other message, so a default carries `{placeholders}`\n * too and is not second-class.\n */\n default?: string;\n}\n\nexport interface I18n {\n /** Currently active locale. */\n locale: string;\n /** Fallback locale (or `null` when not configured). */\n fallbackLocale: string | null;\n /**\n * Translate `key`, interpolating `{name}` placeholders from `params`.\n * Falls back to the configured fallback locale, then to `options.default`,\n * then to the key itself.\n */\n t: (key: string, params?: InterpolationValues, options?: TranslateOptions) => string;\n /**\n * Plural-aware translation. Tries `${key}_one` for `count === 1` and\n * `${key}_other` otherwise, with `{count}` available for interpolation.\n * Falls back to `options.default`, then to the key itself.\n */\n plural: (\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ) => string;\n /** Format a number using `Intl.NumberFormat` on the active locale. */\n formatNumber: (value: number, options?: Intl.NumberFormatOptions) => string;\n /** Format a Date using `Intl.DateTimeFormat` on the active locale. */\n formatDate: (value: Date | string, options?: Intl.DateTimeFormatOptions) => string;\n /** Build a new `I18n` instance pointing at a different locale. */\n withLocale: (locale: string) => I18n;\n}\n\nfunction interpolate(template: string, params?: InterpolationValues): string {\n if (!params) return template;\n return template.replace(/\\{(\\w+)\\}/g, (_match, name: string) => {\n const value = params[name];\n return value === undefined ? `{${name}}` : String(value);\n });\n}\n\nfunction lookup(\n catalog: Catalog,\n locale: string,\n fallback: string | null,\n key: string,\n): string | null {\n const direct = catalog[locale]?.[key];\n if (direct !== undefined) return direct;\n if (fallback) {\n const fallbackValue = catalog[fallback]?.[key];\n if (fallbackValue !== undefined) return fallbackValue;\n }\n return null;\n}\n\n/**\n * Create an i18n object with translation, pluralization and Intl helpers.\n *\n * The catalog is a plain `{ [locale]: { [key]: \"...\" } }` map — bring your\n * own keys, namespaces, or nested-key conventions. The SDK does not enforce\n * a schema so you can plug it into any string-loading pipeline.\n *\n * @example\n * const i18n = createI18n({\n * locale: \"pt-BR\",\n * fallbackLocale: \"en\",\n * messages: {\n * \"pt-BR\": {\n * \"greet\": \"Olá, {name}\",\n * \"alos_one\": \"{count} Alô\",\n * \"alos_other\": \"{count} Alôs\",\n * },\n * \"en\": { greet: \"Hi, {name}\", alos_one: \"{count} Alo\", alos_other: \"{count} Alos\" },\n * },\n * });\n * i18n.t(\"greet\", { name: \"Mau\" }); // \"Olá, Mau\"\n * i18n.plural(\"alos\", 3); // \"3 Alôs\"\n *\n * @example\n * // A key the catalog does not define, with text to show instead of the key.\n * i18n.t(\"cart.empty\", undefined, { default: \"Seu carrinho está vazio\" });\n */\nexport function createI18n(options: CreateI18nOptions): I18n {\n const { locale, fallbackLocale = null, messages } = options;\n\n function t(key: string, params?: InterpolationValues, options?: TranslateOptions): string {\n const template = lookup(messages, locale, fallbackLocale, key) ?? options?.default;\n if (template === undefined) return key;\n return interpolate(template, params);\n }\n\n function plural(\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ): string {\n const suffix = count === 1 ? \"_one\" : \"_other\";\n const template =\n lookup(messages, locale, fallbackLocale, `${key}${suffix}`) ??\n lookup(messages, locale, fallbackLocale, key) ??\n options?.default;\n if (template === undefined) return key;\n return interpolate(template, { count, ...(params ?? {}) });\n }\n\n function formatNumber(value: number, opts?: Intl.NumberFormatOptions): string {\n return numberFormat(locale, opts).format(value);\n }\n\n function formatDate(value: Date | string, opts?: Intl.DateTimeFormatOptions): string {\n const date = typeof value === \"string\" ? new Date(value) : value;\n if (Number.isNaN(date.getTime())) return \"\";\n return dateTimeFormat(locale, opts).format(date);\n }\n\n return {\n locale,\n fallbackLocale,\n t,\n plural,\n formatNumber,\n formatDate,\n withLocale: (nextLocale) =>\n createI18n({\n locale: nextLocale,\n fallbackLocale: fallbackLocale ?? undefined,\n messages,\n }),\n };\n}\n"],"mappings":"2CA6DA,SAAS,EAAY,EAAkB,EAAsC,CAEzE,OADK,EACE,EAAS,QAAQ,cAAe,EAAQ,IAAiB,CAC5D,IAAM,EAAQ,EAAO,GACrB,OAAO,IAAU,IAAA,GAAY,IAAI,EAAK,GAAK,OAAO,CAAK,CAC3D,CAAC,EAJmB,CAKxB,CAEA,SAAS,EACL,EACA,EACA,EACA,EACa,CACb,IAAM,EAAS,EAAQ,EAAO,GAAG,GACjC,GAAI,IAAW,IAAA,GAAW,OAAO,EACjC,GAAI,EAAU,CACV,IAAM,EAAgB,EAAQ,EAAS,GAAG,GAC1C,GAAI,IAAkB,IAAA,GAAW,OAAO,CAC5C,CACA,OAAO,IACX,CA6BA,SAAgB,EAAW,EAAkC,CACzD,GAAM,CAAE,SAAQ,iBAAiB,KAAM,YAAa,EAEpD,SAAS,EAAE,EAAa,EAA8B,EAAoC,CACtF,IAAM,EAAW,EAAO,EAAU,EAAQ,EAAgB,CAAG,GAAK,GAAS,QAE3E,OADI,IAAa,IAAA,GAAkB,EAC5B,EAAY,EAAU,CAAM,CACvC,CAEA,SAAS,EACL,EACA,EACA,EACA,EACM,CAEN,IAAM,EACF,EAAO,EAAU,EAAQ,EAAgB,GAAG,IAFjC,IAAU,EAAI,OAAS,UAEwB,GAC1D,EAAO,EAAU,EAAQ,EAAgB,CAAG,GAC5C,GAAS,QAEb,OADI,IAAa,IAAA,GAAkB,EAC5B,EAAY,EAAU,CAAE,QAAO,GAAI,GAAU,CAAC,CAAG,CAAC,CAC7D,CAEA,SAAS,EAAa,EAAe,EAAyC,CAC1E,OAAO,EAAA,aAAa,EAAQ,CAAI,CAAC,CAAC,OAAO,CAAK,CAClD,CAEA,SAAS,EAAW,EAAsB,EAA2C,CACjF,IAAM,EAAO,OAAO,GAAU,SAAW,IAAI,KAAK,CAAK,EAAI,EAE3D,OADI,OAAO,MAAM,EAAK,QAAQ,CAAC,EAAU,GAClC,EAAA,eAAe,EAAQ,CAAI,CAAC,CAAC,OAAO,CAAI,CACnD,CAEA,MAAO,CACH,SACA,iBACA,IACA,SACA,eACA,aACA,WAAa,GACT,EAAW,CACP,OAAQ,EACR,eAAgB,GAAkB,IAAA,GAClC,UACJ,CAAC,CACT,CACJ"}
@@ -1,11 +1,12 @@
1
+ import { dateTimeFormat as e, numberFormat as t } from "../utils/intl-cache.js";
1
2
  //#region src/i18n/create-i18n.ts
2
- function e(e, t) {
3
+ function n(e, t) {
3
4
  return t ? e.replace(/\{(\w+)\}/g, (e, n) => {
4
5
  let r = t[n];
5
6
  return r === void 0 ? `{${n}}` : String(r);
6
7
  }) : e;
7
8
  }
8
- function t(e, t, n, r) {
9
+ function r(e, t, n, r) {
9
10
  let i = e[t]?.[r];
10
11
  if (i !== void 0) return i;
11
12
  if (n) {
@@ -14,41 +15,41 @@ function t(e, t, n, r) {
14
15
  }
15
16
  return null;
16
17
  }
17
- function n(r) {
18
- let { locale: i, fallbackLocale: a = null, messages: o } = r;
19
- function s(n, r, s) {
20
- let c = t(o, i, a, n) ?? s?.default;
21
- return c === void 0 ? n : e(c, r);
18
+ function i(a) {
19
+ let { locale: o, fallbackLocale: s = null, messages: c } = a;
20
+ function l(e, t, i) {
21
+ let a = r(c, o, s, e) ?? i?.default;
22
+ return a === void 0 ? e : n(a, t);
22
23
  }
23
- function c(n, r, s, c) {
24
- let l = t(o, i, a, `${n}${r === 1 ? "_one" : "_other"}`) ?? t(o, i, a, n) ?? c?.default;
25
- return l === void 0 ? n : e(l, {
26
- count: r,
27
- ...s ?? {}
24
+ function u(e, t, i, a) {
25
+ let l = r(c, o, s, `${e}${t === 1 ? "_one" : "_other"}`) ?? r(c, o, s, e) ?? a?.default;
26
+ return l === void 0 ? e : n(l, {
27
+ count: t,
28
+ ...i ?? {}
28
29
  });
29
30
  }
30
- function l(e, t) {
31
- return new Intl.NumberFormat(i, t).format(e);
31
+ function d(e, n) {
32
+ return t(o, n).format(e);
32
33
  }
33
- function u(e, t) {
34
- let n = typeof e == "string" ? new Date(e) : e;
35
- return Number.isNaN(n.getTime()) ? "" : new Intl.DateTimeFormat(i, t).format(n);
34
+ function f(t, n) {
35
+ let r = typeof t == "string" ? new Date(t) : t;
36
+ return Number.isNaN(r.getTime()) ? "" : e(o, n).format(r);
36
37
  }
37
38
  return {
38
- locale: i,
39
- fallbackLocale: a,
40
- t: s,
41
- plural: c,
42
- formatNumber: l,
43
- formatDate: u,
44
- withLocale: (e) => n({
39
+ locale: o,
40
+ fallbackLocale: s,
41
+ t: l,
42
+ plural: u,
43
+ formatNumber: d,
44
+ formatDate: f,
45
+ withLocale: (e) => i({
45
46
  locale: e,
46
- fallbackLocale: a ?? void 0,
47
- messages: o
47
+ fallbackLocale: s ?? void 0,
48
+ messages: c
48
49
  })
49
50
  };
50
51
  }
51
52
  //#endregion
52
- export { n as createI18n };
53
+ export { i as createI18n };
53
54
 
54
55
  //# sourceMappingURL=create-i18n.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-i18n.js","names":[],"sources":["../../src/i18n/create-i18n.ts"],"sourcesContent":["export type Messages = Record<string, string>;\nexport type Catalog = Record<string, Messages>;\nexport type InterpolationValues = Record<string, string | number>;\n\nexport interface CreateI18nOptions {\n /** Initial locale. */\n locale: string;\n /** Fallback locale used when a key is missing in the active locale. */\n fallbackLocale?: string;\n /** Catalog `{ [locale]: { [key]: \"...\" } }`. */\n messages: Catalog;\n}\n\n/** Per-call options for {@link I18n.t} and {@link I18n.plural}. */\nexport interface TranslateOptions {\n /**\n * Text to use when the catalog defines neither the key nor its fallback.\n *\n * Without this, a miss returns the key, and a caller that wants its own text\n * instead has to *detect* the miss — which from the outside means comparing\n * the result against the key it just passed in. That heuristic is wrong for a\n * catalog that legitimately maps a key to itself, and it is what every\n * translatable string the SDK ships would otherwise have to copy.\n *\n * Interpolated like any other message, so a default carries `{placeholders}`\n * too and is not second-class.\n */\n default?: string;\n}\n\nexport interface I18n {\n /** Currently active locale. */\n locale: string;\n /** Fallback locale (or `null` when not configured). */\n fallbackLocale: string | null;\n /**\n * Translate `key`, interpolating `{name}` placeholders from `params`.\n * Falls back to the configured fallback locale, then to `options.default`,\n * then to the key itself.\n */\n t: (key: string, params?: InterpolationValues, options?: TranslateOptions) => string;\n /**\n * Plural-aware translation. Tries `${key}_one` for `count === 1` and\n * `${key}_other` otherwise, with `{count}` available for interpolation.\n * Falls back to `options.default`, then to the key itself.\n */\n plural: (\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ) => string;\n /** Format a number using `Intl.NumberFormat` on the active locale. */\n formatNumber: (value: number, options?: Intl.NumberFormatOptions) => string;\n /** Format a Date using `Intl.DateTimeFormat` on the active locale. */\n formatDate: (value: Date | string, options?: Intl.DateTimeFormatOptions) => string;\n /** Build a new `I18n` instance pointing at a different locale. */\n withLocale: (locale: string) => I18n;\n}\n\nfunction interpolate(template: string, params?: InterpolationValues): string {\n if (!params) return template;\n return template.replace(/\\{(\\w+)\\}/g, (_match, name: string) => {\n const value = params[name];\n return value === undefined ? `{${name}}` : String(value);\n });\n}\n\nfunction lookup(\n catalog: Catalog,\n locale: string,\n fallback: string | null,\n key: string,\n): string | null {\n const direct = catalog[locale]?.[key];\n if (direct !== undefined) return direct;\n if (fallback) {\n const fallbackValue = catalog[fallback]?.[key];\n if (fallbackValue !== undefined) return fallbackValue;\n }\n return null;\n}\n\n/**\n * Create an i18n object with translation, pluralization and Intl helpers.\n *\n * The catalog is a plain `{ [locale]: { [key]: \"...\" } }` map — bring your\n * own keys, namespaces, or nested-key conventions. The SDK does not enforce\n * a schema so you can plug it into any string-loading pipeline.\n *\n * @example\n * const i18n = createI18n({\n * locale: \"pt-BR\",\n * fallbackLocale: \"en\",\n * messages: {\n * \"pt-BR\": {\n * \"greet\": \"Olá, {name}\",\n * \"alos_one\": \"{count} Alô\",\n * \"alos_other\": \"{count} Alôs\",\n * },\n * \"en\": { greet: \"Hi, {name}\", alos_one: \"{count} Alo\", alos_other: \"{count} Alos\" },\n * },\n * });\n * i18n.t(\"greet\", { name: \"Mau\" }); // \"Olá, Mau\"\n * i18n.plural(\"alos\", 3); // \"3 Alôs\"\n *\n * @example\n * // A key the catalog does not define, with text to show instead of the key.\n * i18n.t(\"cart.empty\", undefined, { default: \"Seu carrinho está vazio\" });\n */\nexport function createI18n(options: CreateI18nOptions): I18n {\n const { locale, fallbackLocale = null, messages } = options;\n\n function t(key: string, params?: InterpolationValues, options?: TranslateOptions): string {\n const template = lookup(messages, locale, fallbackLocale, key) ?? options?.default;\n if (template === undefined) return key;\n return interpolate(template, params);\n }\n\n function plural(\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ): string {\n const suffix = count === 1 ? \"_one\" : \"_other\";\n const template =\n lookup(messages, locale, fallbackLocale, `${key}${suffix}`) ??\n lookup(messages, locale, fallbackLocale, key) ??\n options?.default;\n if (template === undefined) return key;\n return interpolate(template, { count, ...(params ?? {}) });\n }\n\n function formatNumber(value: number, opts?: Intl.NumberFormatOptions): string {\n return new Intl.NumberFormat(locale, opts).format(value);\n }\n\n function formatDate(value: Date | string, opts?: Intl.DateTimeFormatOptions): string {\n const date = typeof value === \"string\" ? new Date(value) : value;\n if (Number.isNaN(date.getTime())) return \"\";\n return new Intl.DateTimeFormat(locale, opts).format(date);\n }\n\n return {\n locale,\n fallbackLocale,\n t,\n plural,\n formatNumber,\n formatDate,\n withLocale: (nextLocale) =>\n createI18n({\n locale: nextLocale,\n fallbackLocale: fallbackLocale ?? undefined,\n messages,\n }),\n };\n}\n"],"mappings":";AA4DA,SAAS,EAAY,GAAkB,GAAsC;CAEzE,OADK,IACE,EAAS,QAAQ,eAAe,GAAQ,MAAiB;EAC5D,IAAM,IAAQ,EAAO;EACrB,OAAO,MAAU,KAAA,IAAY,IAAI,EAAK,KAAK,OAAO,CAAK;CAC3D,CAAC,IAJmB;AAKxB;AAEA,SAAS,EACL,GACA,GACA,GACA,GACa;CACb,IAAM,IAAS,EAAQ,EAAO,GAAG;CACjC,IAAI,MAAW,KAAA,GAAW,OAAO;CACjC,IAAI,GAAU;EACV,IAAM,IAAgB,EAAQ,EAAS,GAAG;EAC1C,IAAI,MAAkB,KAAA,GAAW,OAAO;CAC5C;CACA,OAAO;AACX;AA6BA,SAAgB,EAAW,GAAkC;CACzD,IAAM,EAAE,WAAQ,oBAAiB,MAAM,gBAAa;CAEpD,SAAS,EAAE,GAAa,GAA8B,GAAoC;EACtF,IAAM,IAAW,EAAO,GAAU,GAAQ,GAAgB,CAAG,KAAK,GAAS;EAE3E,OADI,MAAa,KAAA,IAAkB,IAC5B,EAAY,GAAU,CAAM;CACvC;CAEA,SAAS,EACL,GACA,GACA,GACA,GACM;EAEN,IAAM,IACF,EAAO,GAAU,GAAQ,GAAgB,GAAG,IAFjC,MAAU,IAAI,SAAS,UAEwB,KAC1D,EAAO,GAAU,GAAQ,GAAgB,CAAG,KAC5C,GAAS;EAEb,OADI,MAAa,KAAA,IAAkB,IAC5B,EAAY,GAAU;GAAE;GAAO,GAAI,KAAU,CAAC;EAAG,CAAC;CAC7D;CAEA,SAAS,EAAa,GAAe,GAAyC;EAC1E,OAAO,IAAI,KAAK,aAAa,GAAQ,CAAI,CAAC,CAAC,OAAO,CAAK;CAC3D;CAEA,SAAS,EAAW,GAAsB,GAA2C;EACjF,IAAM,IAAO,OAAO,KAAU,WAAW,IAAI,KAAK,CAAK,IAAI;EAE3D,OADI,OAAO,MAAM,EAAK,QAAQ,CAAC,IAAU,KAClC,IAAI,KAAK,eAAe,GAAQ,CAAI,CAAC,CAAC,OAAO,CAAI;CAC5D;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,MACT,EAAW;GACP,QAAQ;GACR,gBAAgB,KAAkB,KAAA;GAClC;EACJ,CAAC;CACT;AACJ"}
1
+ {"version":3,"file":"create-i18n.js","names":[],"sources":["../../src/i18n/create-i18n.ts"],"sourcesContent":["import { dateTimeFormat, numberFormat } from \"@/utils/intl-cache\";\nexport type Messages = Record<string, string>;\nexport type Catalog = Record<string, Messages>;\nexport type InterpolationValues = Record<string, string | number>;\n\nexport interface CreateI18nOptions {\n /** Initial locale. */\n locale: string;\n /** Fallback locale used when a key is missing in the active locale. */\n fallbackLocale?: string;\n /** Catalog `{ [locale]: { [key]: \"...\" } }`. */\n messages: Catalog;\n}\n\n/** Per-call options for {@link I18n.t} and {@link I18n.plural}. */\nexport interface TranslateOptions {\n /**\n * Text to use when the catalog defines neither the key nor its fallback.\n *\n * Without this, a miss returns the key, and a caller that wants its own text\n * instead has to *detect* the miss — which from the outside means comparing\n * the result against the key it just passed in. That heuristic is wrong for a\n * catalog that legitimately maps a key to itself, and it is what every\n * translatable string the SDK ships would otherwise have to copy.\n *\n * Interpolated like any other message, so a default carries `{placeholders}`\n * too and is not second-class.\n */\n default?: string;\n}\n\nexport interface I18n {\n /** Currently active locale. */\n locale: string;\n /** Fallback locale (or `null` when not configured). */\n fallbackLocale: string | null;\n /**\n * Translate `key`, interpolating `{name}` placeholders from `params`.\n * Falls back to the configured fallback locale, then to `options.default`,\n * then to the key itself.\n */\n t: (key: string, params?: InterpolationValues, options?: TranslateOptions) => string;\n /**\n * Plural-aware translation. Tries `${key}_one` for `count === 1` and\n * `${key}_other` otherwise, with `{count}` available for interpolation.\n * Falls back to `options.default`, then to the key itself.\n */\n plural: (\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ) => string;\n /** Format a number using `Intl.NumberFormat` on the active locale. */\n formatNumber: (value: number, options?: Intl.NumberFormatOptions) => string;\n /** Format a Date using `Intl.DateTimeFormat` on the active locale. */\n formatDate: (value: Date | string, options?: Intl.DateTimeFormatOptions) => string;\n /** Build a new `I18n` instance pointing at a different locale. */\n withLocale: (locale: string) => I18n;\n}\n\nfunction interpolate(template: string, params?: InterpolationValues): string {\n if (!params) return template;\n return template.replace(/\\{(\\w+)\\}/g, (_match, name: string) => {\n const value = params[name];\n return value === undefined ? `{${name}}` : String(value);\n });\n}\n\nfunction lookup(\n catalog: Catalog,\n locale: string,\n fallback: string | null,\n key: string,\n): string | null {\n const direct = catalog[locale]?.[key];\n if (direct !== undefined) return direct;\n if (fallback) {\n const fallbackValue = catalog[fallback]?.[key];\n if (fallbackValue !== undefined) return fallbackValue;\n }\n return null;\n}\n\n/**\n * Create an i18n object with translation, pluralization and Intl helpers.\n *\n * The catalog is a plain `{ [locale]: { [key]: \"...\" } }` map — bring your\n * own keys, namespaces, or nested-key conventions. The SDK does not enforce\n * a schema so you can plug it into any string-loading pipeline.\n *\n * @example\n * const i18n = createI18n({\n * locale: \"pt-BR\",\n * fallbackLocale: \"en\",\n * messages: {\n * \"pt-BR\": {\n * \"greet\": \"Olá, {name}\",\n * \"alos_one\": \"{count} Alô\",\n * \"alos_other\": \"{count} Alôs\",\n * },\n * \"en\": { greet: \"Hi, {name}\", alos_one: \"{count} Alo\", alos_other: \"{count} Alos\" },\n * },\n * });\n * i18n.t(\"greet\", { name: \"Mau\" }); // \"Olá, Mau\"\n * i18n.plural(\"alos\", 3); // \"3 Alôs\"\n *\n * @example\n * // A key the catalog does not define, with text to show instead of the key.\n * i18n.t(\"cart.empty\", undefined, { default: \"Seu carrinho está vazio\" });\n */\nexport function createI18n(options: CreateI18nOptions): I18n {\n const { locale, fallbackLocale = null, messages } = options;\n\n function t(key: string, params?: InterpolationValues, options?: TranslateOptions): string {\n const template = lookup(messages, locale, fallbackLocale, key) ?? options?.default;\n if (template === undefined) return key;\n return interpolate(template, params);\n }\n\n function plural(\n key: string,\n count: number,\n params?: InterpolationValues,\n options?: TranslateOptions,\n ): string {\n const suffix = count === 1 ? \"_one\" : \"_other\";\n const template =\n lookup(messages, locale, fallbackLocale, `${key}${suffix}`) ??\n lookup(messages, locale, fallbackLocale, key) ??\n options?.default;\n if (template === undefined) return key;\n return interpolate(template, { count, ...(params ?? {}) });\n }\n\n function formatNumber(value: number, opts?: Intl.NumberFormatOptions): string {\n return numberFormat(locale, opts).format(value);\n }\n\n function formatDate(value: Date | string, opts?: Intl.DateTimeFormatOptions): string {\n const date = typeof value === \"string\" ? new Date(value) : value;\n if (Number.isNaN(date.getTime())) return \"\";\n return dateTimeFormat(locale, opts).format(date);\n }\n\n return {\n locale,\n fallbackLocale,\n t,\n plural,\n formatNumber,\n formatDate,\n withLocale: (nextLocale) =>\n createI18n({\n locale: nextLocale,\n fallbackLocale: fallbackLocale ?? undefined,\n messages,\n }),\n };\n}\n"],"mappings":";;AA6DA,SAAS,EAAY,GAAkB,GAAsC;CAEzE,OADK,IACE,EAAS,QAAQ,eAAe,GAAQ,MAAiB;EAC5D,IAAM,IAAQ,EAAO;EACrB,OAAO,MAAU,KAAA,IAAY,IAAI,EAAK,KAAK,OAAO,CAAK;CAC3D,CAAC,IAJmB;AAKxB;AAEA,SAAS,EACL,GACA,GACA,GACA,GACa;CACb,IAAM,IAAS,EAAQ,EAAO,GAAG;CACjC,IAAI,MAAW,KAAA,GAAW,OAAO;CACjC,IAAI,GAAU;EACV,IAAM,IAAgB,EAAQ,EAAS,GAAG;EAC1C,IAAI,MAAkB,KAAA,GAAW,OAAO;CAC5C;CACA,OAAO;AACX;AA6BA,SAAgB,EAAW,GAAkC;CACzD,IAAM,EAAE,WAAQ,oBAAiB,MAAM,gBAAa;CAEpD,SAAS,EAAE,GAAa,GAA8B,GAAoC;EACtF,IAAM,IAAW,EAAO,GAAU,GAAQ,GAAgB,CAAG,KAAK,GAAS;EAE3E,OADI,MAAa,KAAA,IAAkB,IAC5B,EAAY,GAAU,CAAM;CACvC;CAEA,SAAS,EACL,GACA,GACA,GACA,GACM;EAEN,IAAM,IACF,EAAO,GAAU,GAAQ,GAAgB,GAAG,IAFjC,MAAU,IAAI,SAAS,UAEwB,KAC1D,EAAO,GAAU,GAAQ,GAAgB,CAAG,KAC5C,GAAS;EAEb,OADI,MAAa,KAAA,IAAkB,IAC5B,EAAY,GAAU;GAAE;GAAO,GAAI,KAAU,CAAC;EAAG,CAAC;CAC7D;CAEA,SAAS,EAAa,GAAe,GAAyC;EAC1E,OAAO,EAAa,GAAQ,CAAI,CAAC,CAAC,OAAO,CAAK;CAClD;CAEA,SAAS,EAAW,GAAsB,GAA2C;EACjF,IAAM,IAAO,OAAO,KAAU,WAAW,IAAI,KAAK,CAAK,IAAI;EAE3D,OADI,OAAO,MAAM,EAAK,QAAQ,CAAC,IAAU,KAClC,EAAe,GAAQ,CAAI,CAAC,CAAC,OAAO,CAAI;CACnD;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,MACT,EAAW;GACP,QAAQ;GACR,gBAAgB,KAAkB,KAAA;GAClC;EACJ,CAAC;CACT;AACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("../auth/lazy-with-retry.cjs"),t=require("./RouteGuard.cjs");let n=require("react"),r=require("react/jsx-runtime"),i=require("react-router");function a(e){return e}var o=new WeakMap;function s(t){let n=o.get(t);return n||(n=e.lazyWithRetry(t.lazy),o.set(t,n)),n}function c({guard:e,redirectTo:n,children:i}){let a=typeof e==`function`?e():e;return(0,r.jsx)(t.RouteGuard,{when:a,redirectTo:n,children:i})}function l(e){return e.map((e,t)=>{let n=e.element;if(e.lazy){let t=s(e);n=(0,r.jsx)(t,{})}return e.guard!==void 0&&(n=(0,r.jsx)(c,{guard:e.guard,redirectTo:e.redirectTo,children:n})),e.index?(0,r.jsx)(i.Route,{index:!0,element:n},`index-${t}`):(0,r.jsx)(i.Route,{path:e.path,element:n,caseSensitive:e.caseSensitive,children:e.children?l(e.children):null},e.path??`route-${t}`)})}var u={browser:i.BrowserRouter,hash:i.HashRouter,memory:i.MemoryRouter};function d({routes:e,router:t=`browser`,basename:a,initialEntries:o,fallback:s=null}){let c=(0,n.useMemo)(()=>l(e),[e]),d=u[t];return(0,r.jsx)(d,{...t===`memory`?{basename:a,initialEntries:o}:{basename:a},children:(0,r.jsx)(n.Suspense,{fallback:s,children:(0,r.jsx)(i.Routes,{children:c})})})}exports.AppRouter=d,exports.defineRoutes=a;
1
+ const e=require("../auth/lazy-with-retry.cjs"),t=require("./RouteGuard.cjs");let n=require("react"),r=require("react/jsx-runtime"),i=require("react-router");function a(e){return e}var o=new WeakMap;function s(t){let n=o.get(t);return n||(n=e.lazyWithRetry(t.lazy),o.set(t,n)),n}function c({guard:e,guardFallback:n,redirectTo:i,children:a}){let o=typeof e==`function`?e():e;return(0,r.jsx)(t.RouteGuard,{when:o,fallback:n,redirectTo:i,children:a})}var l=new WeakMap,u=0;function d(e){let t=l.get(e);return t||(t=`guard-${++u}`,l.set(e,t)),t}function f(e,t){return e.map((e,n)=>{let a=e.element;if(e.lazy){let t=s(e);a=(0,r.jsx)(t,{})}return e.guard!==void 0&&(a=(0,r.jsx)(c,{guard:e.guard,guardFallback:e.guardFallback??t,redirectTo:e.redirectTo,children:a},d(e))),e.index?(0,r.jsx)(i.Route,{index:!0,element:a},`index-${n}`):(0,r.jsx)(i.Route,{path:e.path,element:a,caseSensitive:e.caseSensitive,children:e.children?f(e.children,t):null},e.path??`route-${n}`)})}var p={browser:i.BrowserRouter,hash:i.HashRouter,memory:i.MemoryRouter};function m({routes:e,router:t=`browser`,basename:a,initialEntries:o,fallback:s=null}){let c=(0,n.useMemo)(()=>f(e,s),[e,s]),l=p[t];return(0,r.jsx)(l,{...t===`memory`?{basename:a,initialEntries:o}:{basename:a},children:(0,r.jsx)(n.Suspense,{fallback:s,children:(0,r.jsx)(i.Routes,{children:c})})})}exports.AppRouter=m,exports.defineRoutes=a;
2
2
  //# sourceMappingURL=AppRouter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppRouter.cjs","names":[],"sources":["../../src/router/AppRouter.tsx"],"sourcesContent":["import { Suspense, useMemo } from \"react\";\nimport type { ComponentType, ReactNode } from \"react\";\nimport { BrowserRouter, HashRouter, MemoryRouter, Routes, Route } from \"react-router\";\nimport { lazyWithRetry } from \"../auth/lazy-with-retry\";\nimport { RouteGuard } from \"./RouteGuard\";\nimport type { RouterKind, TempestRouteObject } from \"./types\";\n\n/**\n * Identity helper that types a declarative route tree. Use it so editors give\n * autocomplete and type-checking on every node; the array is returned as-is.\n *\n * @example\n * export const routes = defineRoutes([\n * { path: \"/\", element: <Layout />, children: [\n * { index: true, lazy: () => import(\"./pages/Home\") },\n * { path: \"settings\", lazy: () => import(\"./pages/Settings\"),\n * guard: () => useAuth.getState().isAuthenticated, redirectTo: \"/login\" },\n * ] },\n * ]);\n */\nexport function defineRoutes(routes: TempestRouteObject[]): TempestRouteObject[] {\n return routes;\n}\n\nconst lazyCache = new WeakMap<TempestRouteObject, ComponentType<unknown>>();\n\nfunction resolveLazy(route: TempestRouteObject): ComponentType<unknown> {\n let comp = lazyCache.get(route);\n if (!comp) {\n comp = lazyWithRetry(route.lazy!);\n lazyCache.set(route, comp);\n }\n return comp;\n}\n\nfunction GuardedElement({\n guard,\n redirectTo,\n children,\n}: {\n guard: boolean | (() => boolean);\n redirectTo?: string;\n children: ReactNode;\n}) {\n const allowed = typeof guard === \"function\" ? guard() : guard;\n return (\n <RouteGuard when={allowed} redirectTo={redirectTo}>\n {children}\n </RouteGuard>\n );\n}\n\nfunction toRouteElements(routes: TempestRouteObject[]): ReactNode {\n return routes.map((route, i) => {\n let element: ReactNode = route.element;\n if (route.lazy) {\n const LazyComponent = resolveLazy(route);\n element = <LazyComponent />;\n }\n if (route.guard !== undefined) {\n element = (\n <GuardedElement guard={route.guard} redirectTo={route.redirectTo}>\n {element}\n </GuardedElement>\n );\n }\n\n if (route.index) {\n return <Route key={`index-${i}`} index element={element} />;\n }\n\n return (\n <Route\n key={route.path ?? `route-${i}`}\n path={route.path}\n element={element}\n caseSensitive={route.caseSensitive}\n >\n {route.children ? toRouteElements(route.children) : null}\n </Route>\n );\n });\n}\n\nconst ROUTERS: Record<RouterKind, typeof BrowserRouter> = {\n browser: BrowserRouter,\n hash: HashRouter,\n memory: MemoryRouter,\n};\n\nexport interface AppRouterProps {\n /** Declarative route tree, ideally built with {@link defineRoutes}. */\n routes: TempestRouteObject[];\n /** History strategy (default: `\"browser\"`). */\n router?: RouterKind;\n /** App-wide base path forwarded to the underlying router. */\n basename?: string;\n /** Initial URLs for the `\"memory\"` router (tests / non-DOM hosts). */\n initialEntries?: string[];\n /** Suspense fallback shown while a `lazy` route chunk loads. */\n fallback?: ReactNode;\n}\n\n/**\n * Render a full React Router (v7 or v8, declarative mode) from a\n * {@link defineRoutes}\n * tree: picks the history strategy, wraps everything in a `<Suspense>` boundary\n * for `lazy` routes, and applies per-route `guard` redirects. This is the\n * single entry point apps mount at their root.\n *\n * @example\n * <AppRouter routes={routes} fallback={<Spinner />} />\n */\nexport function AppRouter({\n routes,\n router = \"browser\",\n basename,\n initialEntries,\n fallback = null,\n}: AppRouterProps) {\n const tree = useMemo(() => toRouteElements(routes), [routes]);\n const Router = ROUTERS[router];\n const routerProps = router === \"memory\" ? { basename, initialEntries } : { basename };\n\n return (\n <Router {...routerProps}>\n <Suspense fallback={fallback}>\n <Routes>{tree}</Routes>\n </Suspense>\n </Router>\n );\n}\n"],"mappings":"6JAoBA,SAAgB,EAAa,EAAoD,CAC7E,OAAO,CACX,CAEA,IAAM,EAAY,IAAI,QAEtB,SAAS,EAAY,EAAmD,CACpE,IAAI,EAAO,EAAU,IAAI,CAAK,EAK9B,OAJK,IACD,EAAO,EAAA,cAAc,EAAM,I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AC,EAAA,SAAD,CAAoB,WAChB,UAAA,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CAAA,SAAS,CAAa,CAAA,CAChB,CAAA,CACN,CAAA,CAEhB"}
1
+ {"version":3,"file":"AppRouter.cjs","names":[],"sources":["../../src/router/AppRouter.tsx"],"sourcesContent":["import { Suspense, useMemo } from \"react\";\nimport type { ComponentType, ReactNode } from \"react\";\nimport { BrowserRouter, HashRouter, MemoryRouter, Routes, Route } from \"react-router\";\nimport { lazyWithRetry } from \"../auth/lazy-with-retry\";\nimport { RouteGuard } from \"./RouteGuard\";\nimport type { RouteGuardResult, RouterKind, TempestRouteObject } from \"./types\";\n\n/**\n * Identity helper that types a declarative route tree. Use it so editors give\n * autocomplete and type-checking on every node; the array is returned as-is.\n *\n * @example\n * export const routes = defineRoutes([\n * { path: \"/\", element: <Layout />, children: [\n * { index: true, lazy: () => import(\"./pages/Home\") },\n * { path: \"settings\", lazy: () => import(\"./pages/Settings\"),\n * guard: () => useAuth.getState().isAuthenticated, redirectTo: \"/login\" },\n * ] },\n * ]);\n */\nexport function defineRoutes(routes: TempestRouteObject[]): TempestRouteObject[] {\n return routes;\n}\n\nconst lazyCache = new WeakMap<TempestRouteObject, ComponentType<unknown>>();\n\nfunction resolveLazy(route: TempestRouteObject): ComponentType<unknown> {\n let comp = lazyCache.get(route);\n if (!comp) {\n comp = lazyWithRetry(route.lazy!);\n lazyCache.set(route, comp);\n }\n return comp;\n}\n\n/**\n * Runs one route's `guard` and renders the outcome.\n *\n * The guard is called during this component's render, which is what lets it\n * call hooks — `useCan` returning `{ allowed, isLoading }` maps straight onto\n * the three outcomes. See {@link guardKey} for why each guarded route gets its\n * own instance.\n */\nfunction GuardedElement({\n guard,\n guardFallback,\n redirectTo,\n children,\n}: {\n guard: boolean | (() => RouteGuardResult);\n guardFallback?: ReactNode;\n redirectTo?: string;\n children: ReactNode;\n}) {\n const allowed = typeof guard === \"function\" ? guard() : guard;\n return (\n <RouteGuard when={allowed} fallback={guardFallback} redirectTo={redirectTo}>\n {children}\n </RouteGuard>\n );\n}\n\nconst guardKeys = new WeakMap<TempestRouteObject, string>();\nlet guardKeySeq = 0;\n\n/**\n * A key unique to each route object, so React remounts `GuardedElement` when\n * the matched route changes instead of reusing the instance.\n *\n * Load-bearing once guards may call hooks. React Router renders the matched\n * route's element at the same position in the tree, so without a differing key\n * React reconciles two different routes onto the same `GuardedElement`\n * instance and the previous route's guard state survives into the next one's —\n * a guard reading `useState(\"from-a\")` still reads `\"from-a\"` after navigating\n * to a route whose guard initialises it to `\"from-b\"`. Path is not enough on\n * its own: two routes in different branches can share one.\n */\nfunction guardKey(route: TempestRouteObject): string {\n let key = guardKeys.get(route);\n if (!key) {\n key = `guard-${++guardKeySeq}`;\n guardKeys.set(route, key);\n }\n return key;\n}\n\nfunction toRouteElements(routes: TempestRouteObject[], fallback: ReactNode): ReactNode {\n return routes.map((route, i) => {\n let element: ReactNode = route.element;\n if (route.lazy) {\n const LazyComponent = resolveLazy(route);\n element = <LazyComponent />;\n }\n if (route.guard !== undefined) {\n element = (\n <GuardedElement\n key={guardKey(route)}\n guard={route.guard}\n guardFallback={route.guardFallback ?? fallback}\n redirectTo={route.redirectTo}\n >\n {element}\n </GuardedElement>\n );\n }\n\n if (route.index) {\n return <Route key={`index-${i}`} index element={element} />;\n }\n\n return (\n <Route\n key={route.path ?? `route-${i}`}\n path={route.path}\n element={element}\n caseSensitive={route.caseSensitive}\n >\n {route.children ? toRouteElements(route.children, fallback) : null}\n </Route>\n );\n });\n}\n\nconst ROUTERS: Record<RouterKind, typeof BrowserRouter> = {\n browser: BrowserRouter,\n hash: HashRouter,\n memory: MemoryRouter,\n};\n\nexport interface AppRouterProps {\n /** Declarative route tree, ideally built with {@link defineRoutes}. */\n routes: TempestRouteObject[];\n /** History strategy (default: `\"browser\"`). */\n router?: RouterKind;\n /** App-wide base path forwarded to the underlying router. */\n basename?: string;\n /** Initial URLs for the `\"memory\"` router (tests / non-DOM hosts). */\n initialEntries?: string[];\n /**\n * Suspense fallback shown while a `lazy` route chunk loads, and the default\n * for a route whose `guard` answers `\"pending\"` — one spinner covers both\n * kinds of \"not ready yet\". A route overrides it with its own\n * `guardFallback`.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Render a full React Router (v7 or v8, declarative mode) from a\n * {@link defineRoutes}\n * tree: picks the history strategy, wraps everything in a `<Suspense>` boundary\n * for `lazy` routes, and applies per-route `guard` redirects. This is the\n * single entry point apps mount at their root.\n *\n * @example\n * <AppRouter routes={routes} fallback={<Spinner />} />\n */\nexport function AppRouter({\n routes,\n router = \"browser\",\n basename,\n initialEntries,\n fallback = null,\n}: AppRouterProps) {\n const tree = useMemo(() => toRouteElements(routes, fallback), [routes, fallback]);\n const Router = ROUTERS[router];\n const routerProps = router === \"memory\" ? { basename, initialEntries } : { basename };\n\n return (\n <Router {...routerProps}>\n <Suspense fallback={fallback}>\n <Routes>{tree}</Routes>\n </Suspense>\n </Router>\n );\n}\n"],"mappings":"6JAoBA,SAAgB,EAAa,EAAoD,CAC7E,OAAO,CACX,CAEA,IAAM,EAAY,IAAI,QAEtB,SAAS,EAAY,EAAmD,CACpE,IAAI,EAAO,EAAU,IAAI,CAAK,EAK9B,OAJK,IACD,EAAO,EAAA,cAAc,EAAM,IAAK,EAChC,EAAU,IAAI,EAAO,CAAI,GAEtB,CACX,CAUA,SAAS,EAAe,CACpB,QACA,gBACA,aACA,YAMD,CACC,IAAM,EAAU,OAAO,GAAU,WAAa,EAAM,EAAI,EACxD,OACI,EAAA,EAAA,IAAA,CAAC,EAAA,WAAD,CAAY,KAAM,EAAS,SAAU,EAA2B,aAC3D,UACO,CAAA,CAEpB,CAEA,IAAM,EAAY,IAAI,QAClB,EAAc,EAclB,SAAS,EAAS,EAAmC,CACjD,IAAI,EAAM,EAAU,IAAI,CAAK,EAK7B,OAJK,IACD,EAAM,SAAS,EAAE,IACjB,EAAU,IAAI,EAAO,CAAG,GAErB,CACX,CAEA,SAAS,EAAgB,EAA8B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
13
  return n || (n = e(t.lazy), d.set(t, n)), n;
14
14
  }
15
- function p({ guard: e, redirectTo: n, children: r }) {
16
- let a = typeof e == "function" ? e() : e;
15
+ function p({ guard: e, guardFallback: n, redirectTo: r, children: a }) {
16
+ let o = typeof e == "function" ? e() : e;
17
17
  return /* @__PURE__ */ i(t, {
18
- when: a,
19
- redirectTo: n,
20
- children: r
18
+ when: o,
19
+ fallback: n,
20
+ redirectTo: r,
21
+ children: a
21
22
  });
22
23
  }
23
- function m(e) {
24
- return e.map((e, t) => {
25
- let n = e.element;
24
+ var m = /* @__PURE__ */ new WeakMap(), h = 0;
25
+ function g(e) {
26
+ let t = m.get(e);
27
+ return t || (t = `guard-${++h}`, m.set(e, t)), t;
28
+ }
29
+ function _(e, t) {
30
+ return e.map((e, n) => {
31
+ let r = e.element;
26
32
  if (e.lazy) {
27
33
  let t = f(e);
28
- n = /* @__PURE__ */ i(t, {});
34
+ r = /* @__PURE__ */ i(t, {});
29
35
  }
30
- return e.guard !== void 0 && (n = /* @__PURE__ */ i(p, {
36
+ return e.guard !== void 0 && (r = /* @__PURE__ */ i(p, {
31
37
  guard: e.guard,
38
+ guardFallback: e.guardFallback ?? t,
32
39
  redirectTo: e.redirectTo,
33
- children: n
34
- })), e.index ? /* @__PURE__ */ i(c, {
40
+ children: r
41
+ }, g(e))), e.index ? /* @__PURE__ */ i(c, {
35
42
  index: !0,
36
- element: n
37
- }, `index-${t}`) : /* @__PURE__ */ i(c, {
43
+ element: r
44
+ }, `index-${n}`) : /* @__PURE__ */ i(c, {
38
45
  path: e.path,
39
- element: n,
46
+ element: r,
40
47
  caseSensitive: e.caseSensitive,
41
- children: e.children ? m(e.children) : null
42
- }, e.path ?? `route-${t}`);
48
+ children: e.children ? _(e.children, t) : null
49
+ }, e.path ?? `route-${n}`);
43
50
  });
44
51
  }
45
- var h = {
52
+ var v = {
46
53
  browser: a,
47
54
  hash: o,
48
55
  memory: s
49
56
  };
50
- function g({ routes: e, router: t = "browser", basename: a, initialEntries: o, fallback: s = null }) {
51
- let c = r(() => m(e), [e]), u = h[t];
57
+ function y({ routes: e, router: t = "browser", basename: a, initialEntries: o, fallback: s = null }) {
58
+ let c = r(() => _(e, s), [e, s]), u = v[t];
52
59
  return /* @__PURE__ */ i(u, {
53
60
  ...t === "memory" ? {
54
61
  basename: a,
@@ -61,6 +68,6 @@ function g({ routes: e, router: t = "browser", basename: a, initialEntries: o, f
61
68
  });
62
69
  }
63
70
  //#endregion
64
- export { g as AppRouter, u as defineRoutes };
71
+ export { y as AppRouter, u as defineRoutes };
65
72
 
66
73
  //# sourceMappingURL=AppRouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppRouter.js","names":[],"sources":["../../src/router/AppRouter.tsx"],"sourcesContent":["import { Suspense, useMemo } from \"react\";\nimport type { ComponentType, ReactNode } from \"react\";\nimport { BrowserRouter, HashRouter, MemoryRouter, Routes, Route } from \"react-router\";\nimport { lazyWithRetry } from \"../auth/lazy-with-retry\";\nimport { RouteGuard } from \"./RouteGuard\";\nimport type { RouterKind, TempestRouteObject } from \"./types\";\n\n/**\n * Identity helper that types a declarative route tree. Use it so editors give\n * autocomplete and type-checking on every node; the array is returned as-is.\n *\n * @example\n * export const routes = defineRoutes([\n * { path: \"/\", element: <Layout />, children: [\n * { index: true, lazy: () => import(\"./pages/Home\") },\n * { path: \"settings\", lazy: () => import(\"./pages/Settings\"),\n * guard: () => useAuth.getState().isAuthenticated, redirectTo: \"/login\" },\n * ] },\n * ]);\n */\nexport function defineRoutes(routes: TempestRouteObject[]): TempestRouteObject[] {\n return routes;\n}\n\nconst lazyCache = new WeakMap<TempestRouteObject, ComponentType<unknown>>();\n\nfunction resolveLazy(route: TempestRouteObject): ComponentType<unknown> {\n let comp = lazyCache.get(route);\n if (!comp) {\n comp = lazyWithRetry(route.lazy!);\n lazyCache.set(route, comp);\n }\n return comp;\n}\n\nfunction GuardedElement({\n guard,\n redirectTo,\n children,\n}: {\n guard: boolean | (() => boolean);\n redirectTo?: string;\n children: ReactNode;\n}) {\n const allowed = typeof guard === \"function\" ? guard() : guard;\n return (\n <RouteGuard when={allowed} redirectTo={redirectTo}>\n {children}\n </RouteGuard>\n );\n}\n\nfunction toRouteElements(routes: TempestRouteObject[]): ReactNode {\n return routes.map((route, i) => {\n let element: ReactNode = route.element;\n if (route.lazy) {\n const LazyComponent = resolveLazy(route);\n element = <LazyComponent />;\n }\n if (route.guard !== undefined) {\n element = (\n <GuardedElement guard={route.guard} redirectTo={route.redirectTo}>\n {element}\n </GuardedElement>\n );\n }\n\n if (route.index) {\n return <Route key={`index-${i}`} index element={element} />;\n }\n\n return (\n <Route\n key={route.path ?? `route-${i}`}\n path={route.path}\n element={element}\n caseSensitive={route.caseSensitive}\n >\n {route.children ? toRouteElements(route.children) : null}\n </Route>\n );\n });\n}\n\nconst ROUTERS: Record<RouterKind, typeof BrowserRouter> = {\n browser: BrowserRouter,\n hash: HashRouter,\n memory: MemoryRouter,\n};\n\nexport interface AppRouterProps {\n /** Declarative route tree, ideally built with {@link defineRoutes}. */\n routes: TempestRouteObject[];\n /** History strategy (default: `\"browser\"`). */\n router?: RouterKind;\n /** App-wide base path forwarded to the underlying router. */\n basename?: string;\n /** Initial URLs for the `\"memory\"` router (tests / non-DOM hosts). */\n initialEntries?: string[];\n /** Suspense fallback shown while a `lazy` route chunk loads. */\n fallback?: ReactNode;\n}\n\n/**\n * Render a full React Router (v7 or v8, declarative mode) from a\n * {@link defineRoutes}\n * tree: picks the history strategy, wraps everything in a `<Suspense>` boundary\n * for `lazy` routes, and applies per-route `guard` redirects. This is the\n * single entry point apps mount at their root.\n *\n * @example\n * <AppRouter routes={routes} fallback={<Spinner />} />\n */\nexport function AppRouter({\n routes,\n router = \"browser\",\n basename,\n initialEntries,\n fallback = null,\n}: AppRouterProps) {\n const tree = useMemo(() => toRouteElements(routes), [routes]);\n const Router = ROUTERS[router];\n const routerProps = router === \"memory\" ? { basename, initialEntries } : { basename };\n\n return (\n <Router {...routerProps}>\n <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D;EAAQ,GAHQ,MAAW,WAAW;GAAE;GAAU;EAAe,IAAI,EAAE,YAAS;EAI5E,UAAA,kBAAC,GAAD;GAAoB;GAChB,UAAA,kBAAC,GAAD,EAAA,UAAS,EAAa,CAAA;EAChB,CAAA;CACN,CAAA;AAEhB"}
1
+ {"version":3,"file":"AppRouter.js","names":[],"sources":["../../src/router/AppRouter.tsx"],"sourcesContent":["import { Suspense, useMemo } from \"react\";\nimport type { ComponentType, ReactNode } from \"react\";\nimport { BrowserRouter, HashRouter, MemoryRouter, Routes, Route } from \"react-router\";\nimport { lazyWithRetry } from \"../auth/lazy-with-retry\";\nimport { RouteGuard } from \"./RouteGuard\";\nimport type { RouteGuardResult, RouterKind, TempestRouteObject } from \"./types\";\n\n/**\n * Identity helper that types a declarative route tree. Use it so editors give\n * autocomplete and type-checking on every node; the array is returned as-is.\n *\n * @example\n * export const routes = defineRoutes([\n * { path: \"/\", element: <Layout />, children: [\n * { index: true, lazy: () => import(\"./pages/Home\") },\n * { path: \"settings\", lazy: () => import(\"./pages/Settings\"),\n * guard: () => useAuth.getState().isAuthenticated, redirectTo: \"/login\" },\n * ] },\n * ]);\n */\nexport function defineRoutes(routes: TempestRouteObject[]): TempestRouteObject[] {\n return routes;\n}\n\nconst lazyCache = new WeakMap<TempestRouteObject, ComponentType<unknown>>();\n\nfunction resolveLazy(route: TempestRouteObject): ComponentType<unknown> {\n let comp = lazyCache.get(route);\n if (!comp) {\n comp = lazyWithRetry(route.lazy!);\n lazyCache.set(route, comp);\n }\n return comp;\n}\n\n/**\n * Runs one route's `guard` and renders the outcome.\n *\n * The guard is called during this component's render, which is what lets it\n * call hooks — `useCan` returning `{ allowed, isLoading }` maps straight onto\n * the three outcomes. See {@link guardKey} for why each guarded route gets its\n * own instance.\n */\nfunction GuardedElement({\n guard,\n guardFallback,\n redirectTo,\n children,\n}: {\n guard: boolean | (() => RouteGuardResult);\n guardFallback?: ReactNode;\n redirectTo?: string;\n children: ReactNode;\n}) {\n const allowed = typeof guard === \"function\" ? guard() : guard;\n return (\n <RouteGuard when={allowed} fallback={guardFallback} redirectTo={redirectTo}>\n {children}\n </RouteGuard>\n );\n}\n\nconst guardKeys = new WeakMap<TempestRouteObject, string>();\nlet guardKeySeq = 0;\n\n/**\n * A key unique to each route object, so React remounts `GuardedElement` when\n * the matched route changes instead of reusing the instance.\n *\n * Load-bearing once guards may call hooks. React Router renders the matched\n * route's element at the same position in the tree, so without a differing key\n * React reconciles two different routes onto the same `GuardedElement`\n * instance and the previous route's guard state survives into the next one's —\n * a guard reading `useState(\"from-a\")` still reads `\"from-a\"` after navigating\n * to a route whose guard initialises it to `\"from-b\"`. Path is not enough on\n * its own: two routes in different branches can share one.\n */\nfunction guardKey(route: TempestRouteObject): string {\n let key = guardKeys.get(route);\n if (!key) {\n key = `guard-${++guardKeySeq}`;\n guardKeys.set(route, key);\n }\n return key;\n}\n\nfunction toRouteElements(routes: TempestRouteObject[], fallback: ReactNode): ReactNode {\n return routes.map((route, i) => {\n let element: ReactNode = route.element;\n if (route.lazy) {\n const LazyComponent = resolveLazy(route);\n element = <LazyComponent />;\n }\n if (route.guard !== undefined) {\n element = (\n <GuardedElement\n key={guardKey(route)}\n guard={route.guard}\n guardFallback={route.guardFallback ?? fallback}\n redirectTo={route.redirectTo}\n >\n {element}\n </GuardedElement>\n );\n }\n\n if (route.index) {\n return <Route key={`index-${i}`} index element={element} />;\n }\n\n return (\n <Route\n key={route.path ?? `route-${i}`}\n path={route.path}\n element={element}\n caseSensitive={route.caseSensitive}\n >\n {route.children ? toRouteElements(route.children, fallback) : null}\n </Route>\n );\n });\n}\n\nconst ROUTERS: Record<RouterKind, typeof BrowserRouter> = {\n browser: BrowserRouter,\n hash: HashRouter,\n memory: MemoryRouter,\n};\n\nexport interface AppRouterProps {\n /** Declarative route tree, ideally built with {@link defineRoutes}. */\n routes: TempestRouteObject[];\n /** History strategy (default: `\"browser\"`). */\n router?: RouterKind;\n /** App-wide base path forwarded to the underlying router. */\n basename?: string;\n /** Initial URLs for the `\"memory\"` router (tests / non-DOM hosts). */\n initialEntries?: string[];\n /**\n * Suspense fallback shown while a `lazy` route chunk loads, and the default\n * for a route whose `guard` answers `\"pending\"` — one spinner covers both\n * kinds of \"not ready yet\". A route overrides it with its own\n * `guardFallback`.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Render a full React Router (v7 or v8, declarative mode) from a\n * {@link defineRoutes}\n * tree: picks the history strategy, wraps everything in a `<Suspense>` boundary\n * for `lazy` routes, and applies per-route `guard` redirects. This is the\n * single entry point apps mount at their root.\n *\n * @example\n * <AppRouter routes={routes} fallback={<Spinner />} />\n */\nexport function AppRouter({\n routes,\n router = \"browser\",\n basename,\n initialEntries,\n fallback = null,\n}: AppRouterProps) {\n const tree = useMemo(() => toRouteElements(routes, fallback), [routes, fallback]);\n const Router = ROUTERS[router];\n const routerProps = router === \"memory\" ? { basename, initialEntries } : { basename };\n\n return (\n <Router {...routerProps}>\n <Suspense fallback={fallback}>\n <Routes>{tree}</Routes>\n </Suspense>\n </Router>\n );\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,EAAa,GAAoD;CAC7E,OAAO;AACX;AAEA,IAAM,oBAAY,IAAI,QAAoD;AAE1E,SAAS,EAAY,GAAmD;CACpE,IAAI,IAAO,EAAU,IAAI,CAAK;CAK9B,OAJK,MACD,IAAO,EAAc,EAAM,IAAK,GAChC,EAAU,IAAI,GAAO,CAAI,IAEtB;AACX;AAUA,SAAS,EAAe,EACpB,UACA,kBACA,eACA,eAMD;CACC,IAAM,IAAU,OAAO,KAAU,aAAa,EAAM,IAAI;CACxD,OACI,kBAAC,GAAD;EAAY,MAAM;EAAS,UAAU;EAA2B;EAC3D;CACO,CAAA;AAEpB;AAEA,IAAM,oBAAY,IAAI,QAAoC,GACtD,IAAc;AAclB,SAAS,EAAS,GAAmC;CACjD,IAAI,IAAM,EAAU,IAAI,CAAK;CAK7B,OAJK,MACD,IAAM,SAAS,EAAE,KACjB,EAAU,IAAI,GAAO,CAAG,IAErB;AACX;AAEA,SAAS,EAAgB,GAA8B,GAAgC;CACnF,OAAO,EAAO,KAAK,GAAO,MAAM;EAC5B,IAAI,IAAqB,EAAM;EAC/B,IAAI,EAAM,MAAM;GACZ,IAAM,IAAgB,EAAY,CAAK;GACvC,IAAU,kBAAC,GAAD,CAAgB,CAAA;EAC9B;EAkBA,OAjBI,EAAM,UAAU,KAAA,MAChB,IACI,kBAAC,GAAD;GAEI,OAAO,EAAM;GACb,eAAe,EAAM,iBAAiB;GACtC,YAAY,EAAM;GAEjB,UAAA;EACW,GANP,EAAS,CAAK,CAMP,IAIpB,EAAM,QACC,kBAAC,GAAD;GAA0B,OAAA;GAAe;EAAU,GAAvC,SAAS,GAA8B,IAI1D,kBAAC,GAAD;GAEI,MAAM,EAAM;GACH;GACT,eAAe,EAAM;GAEpB,UAAA,EAAM,WAAW,EAAgB,EAAM,UAAU,CAAQ,IAAI;EAC3D,GANE,EAAM,QAAQ,SAAS,GAMzB;CAEf,CAAC;AACL;AAEA,IAAM,IAAoD;CACtD,SAAS;CACT,MAAM;CACN,QAAQ;AACZ;AA8BA,SAAgB,EAAU,EACtB,WACA,YAAS,WACT,aACA,mBACA,cAAW,QACI;CACf,IAAM,IAAO,QAAc,EAAgB,GAAQ,CAAQ,GAAG,CAAC,GAAQ,CAAQ,CAAC,GAC1E,IAAS,EAAQ;CAGvB,OACI,kBAAC,GAAD;EAAQ,GAHQ,MAAW,WAAW;GAAE;GAAU;EAAe,IAAI,EAAE,YAAS;EAI5E,UAAA,kBAAC,GAAD;GAAoB;GAChB,UAAA,kBAAC,GAAD,EAAA,UAAS,EAAa,CAAA;EAChB,CAAA;CACN,CAAA;AAEhB"}
@@ -1,2 +1,2 @@
1
- let e=require("react/jsx-runtime"),t=require("react-router");function n({when:n,redirectTo:r=`/`,replace:i=!0,children:a}){return(0,e.jsx)(e.Fragment,{children:n?a:(0,e.jsx)(t.Navigate,{to:r,replace:i})})}exports.RouteGuard=n;
1
+ let e=require("react/jsx-runtime"),t=require("react-router");function n({when:n,fallback:r=null,redirectTo:i=`/`,replace:a=!0,children:o}){return n===`pending`?(0,e.jsx)(e.Fragment,{children:r}):(0,e.jsx)(e.Fragment,{children:n?o:(0,e.jsx)(t.Navigate,{to:i,replace:a})})}exports.RouteGuard=n;
2
2
  //# sourceMappingURL=RouteGuard.cjs.map