@softistx/alxia-react-router 0.0.0-stage → 0.83.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (609) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2085 -2
  3. package/dist/api-keys/api-keys.d.ts +93 -0
  4. package/dist/api-keys/api-keys.d.ts.map +1 -0
  5. package/dist/api-keys/index.d.ts +9 -0
  6. package/dist/api-keys/index.d.ts.map +1 -0
  7. package/dist/api-keys/index.js +66 -0
  8. package/dist/api-keys/index.js.map +10 -0
  9. package/dist/assets.d.ts +14 -0
  10. package/dist/assets.d.ts.map +1 -0
  11. package/dist/chunks/index-0786n4qe.js +25 -0
  12. package/dist/chunks/index-0786n4qe.js.map +10 -0
  13. package/dist/chunks/index-1nw5yeek.js +169 -0
  14. package/dist/chunks/index-1nw5yeek.js.map +11 -0
  15. package/dist/chunks/index-59vhfj6n.js +10 -0
  16. package/dist/chunks/index-59vhfj6n.js.map +10 -0
  17. package/dist/chunks/index-5gqcpyyg.js +34 -0
  18. package/dist/chunks/index-5gqcpyyg.js.map +10 -0
  19. package/dist/chunks/index-6jf7zpxz.js +119 -0
  20. package/dist/chunks/index-6jf7zpxz.js.map +11 -0
  21. package/dist/chunks/index-8as4j8m3.js +340 -0
  22. package/dist/chunks/index-8as4j8m3.js.map +16 -0
  23. package/dist/chunks/index-9xv2a8et.js +108 -0
  24. package/dist/chunks/index-9xv2a8et.js.map +11 -0
  25. package/dist/chunks/index-ajtvyq35.js +16 -0
  26. package/dist/chunks/index-ajtvyq35.js.map +10 -0
  27. package/dist/chunks/index-c55hxgr5.js +124 -0
  28. package/dist/chunks/index-c55hxgr5.js.map +14 -0
  29. package/dist/chunks/index-d42p3mdp.js +19 -0
  30. package/dist/chunks/index-d42p3mdp.js.map +10 -0
  31. package/dist/chunks/index-gac44rs5.js +42 -0
  32. package/dist/chunks/index-gac44rs5.js.map +11 -0
  33. package/dist/chunks/index-j4ktpcke.js +62 -0
  34. package/dist/chunks/index-j4ktpcke.js.map +10 -0
  35. package/dist/chunks/index-mscfme4r.js +12 -0
  36. package/dist/chunks/index-mscfme4r.js.map +10 -0
  37. package/dist/chunks/index-pghmb2dm.js +30 -0
  38. package/dist/chunks/index-pghmb2dm.js.map +10 -0
  39. package/dist/chunks/index-rfr02vg4.js +40 -0
  40. package/dist/chunks/index-rfr02vg4.js.map +10 -0
  41. package/dist/chunks/index-sfhshxqz.js +31 -0
  42. package/dist/chunks/index-sfhshxqz.js.map +10 -0
  43. package/dist/chunks/index-skwypsjz.js +357 -0
  44. package/dist/chunks/index-skwypsjz.js.map +12 -0
  45. package/dist/chunks/index-sxh06ged.js +118 -0
  46. package/dist/chunks/index-sxh06ged.js.map +11 -0
  47. package/dist/chunks/index-t2ph23wk.js +96 -0
  48. package/dist/chunks/index-t2ph23wk.js.map +13 -0
  49. package/dist/chunks/index-thyabr5n.js +19 -0
  50. package/dist/chunks/index-thyabr5n.js.map +10 -0
  51. package/dist/chunks/index-tx36swjx.js +134 -0
  52. package/dist/chunks/index-tx36swjx.js.map +11 -0
  53. package/dist/chunks/index-v2z5k640.js +54 -0
  54. package/dist/chunks/index-v2z5k640.js.map +11 -0
  55. package/dist/chunks/index-vr82typq.js +23 -0
  56. package/dist/chunks/index-vr82typq.js.map +11 -0
  57. package/dist/chunks/index-whj6h5eg.js +9 -0
  58. package/dist/chunks/index-whj6h5eg.js.map +10 -0
  59. package/dist/chunks/index-wyypkfdv.js +130 -0
  60. package/dist/chunks/index-wyypkfdv.js.map +13 -0
  61. package/dist/chunks/index-xd5aqy3g.js +90 -0
  62. package/dist/chunks/index-xd5aqy3g.js.map +10 -0
  63. package/dist/chunks/index-zdbqzcjp.js +97 -0
  64. package/dist/chunks/index-zdbqzcjp.js.map +12 -0
  65. package/dist/chunks/index-zyg8amjc.js +23 -0
  66. package/dist/chunks/index-zyg8amjc.js.map +10 -0
  67. package/dist/cli/index.d.ts +3 -0
  68. package/dist/cli/index.d.ts.map +1 -0
  69. package/dist/cli/index.js +215 -0
  70. package/dist/cli/index.js.map +13 -0
  71. package/dist/cli/main.d.ts +13 -0
  72. package/dist/cli/main.d.ts.map +1 -0
  73. package/dist/cli/reveal.d.ts +18 -0
  74. package/dist/cli/reveal.d.ts.map +1 -0
  75. package/dist/cli/template.d.ts +8 -0
  76. package/dist/cli/template.d.ts.map +1 -0
  77. package/dist/context.d.ts +104 -0
  78. package/dist/context.d.ts.map +1 -0
  79. package/dist/document/index.d.ts +11 -0
  80. package/dist/document/index.d.ts.map +1 -0
  81. package/dist/document/index.js +19 -0
  82. package/dist/document/index.js.map +9 -0
  83. package/dist/document/inline-script.d.ts +27 -0
  84. package/dist/document/inline-script.d.ts.map +1 -0
  85. package/dist/document/language-store.d.ts +8 -0
  86. package/dist/document/language-store.d.ts.map +1 -0
  87. package/dist/document/nonce.d.ts +34 -0
  88. package/dist/document/nonce.d.ts.map +1 -0
  89. package/dist/document/page-language.d.ts +39 -0
  90. package/dist/document/page-language.d.ts.map +1 -0
  91. package/dist/document/text-direction.d.ts +10 -0
  92. package/dist/document/text-direction.d.ts.map +1 -0
  93. package/dist/entry/abort.d.ts +21 -0
  94. package/dist/entry/abort.d.ts.map +1 -0
  95. package/dist/entry/create-entry.d.ts +41 -0
  96. package/dist/entry/create-entry.d.ts.map +1 -0
  97. package/dist/entry/index.d.ts +8 -0
  98. package/dist/entry/index.d.ts.map +1 -0
  99. package/dist/entry/index.js +154 -0
  100. package/dist/entry/index.js.map +13 -0
  101. package/dist/entry/root-data.d.ts +27 -0
  102. package/dist/entry/root-data.d.ts.map +1 -0
  103. package/dist/entry/whole-page.d.ts +10 -0
  104. package/dist/entry/whole-page.d.ts.map +1 -0
  105. package/dist/errors/api-error.d.ts +117 -0
  106. package/dist/errors/api-error.d.ts.map +1 -0
  107. package/dist/errors/api-errors.d.ts +122 -0
  108. package/dist/errors/api-errors.d.ts.map +1 -0
  109. package/dist/errors/call-failure.d.ts +45 -0
  110. package/dist/errors/call-failure.d.ts.map +1 -0
  111. package/dist/errors/catalogue-check.d.ts +24 -0
  112. package/dist/errors/catalogue-check.d.ts.map +1 -0
  113. package/dist/errors/catalogue-read.d.ts +33 -0
  114. package/dist/errors/catalogue-read.d.ts.map +1 -0
  115. package/dist/errors/catalogue.d.ts +59 -0
  116. package/dist/errors/catalogue.d.ts.map +1 -0
  117. package/dist/errors/code-resolver.d.ts +44 -0
  118. package/dist/errors/code-resolver.d.ts.map +1 -0
  119. package/dist/errors/cross-site.d.ts +8 -0
  120. package/dist/errors/cross-site.d.ts.map +1 -0
  121. package/dist/errors/describe-refusal.d.ts +6 -0
  122. package/dist/errors/describe-refusal.d.ts.map +1 -0
  123. package/dist/errors/describe.d.ts +3 -0
  124. package/dist/errors/describe.d.ts.map +1 -0
  125. package/dist/errors/fetcher-result.d.ts +33 -0
  126. package/dist/errors/fetcher-result.d.ts.map +1 -0
  127. package/dist/errors/field-placement.d.ts +12 -0
  128. package/dist/errors/field-placement.d.ts.map +1 -0
  129. package/dist/errors/form-errors.d.ts +8 -0
  130. package/dist/errors/form-errors.d.ts.map +1 -0
  131. package/dist/errors/form-refusal.d.ts +25 -0
  132. package/dist/errors/form-refusal.d.ts.map +1 -0
  133. package/dist/errors/index.d.ts +21 -0
  134. package/dist/errors/index.d.ts.map +1 -0
  135. package/dist/errors/index.js +588 -0
  136. package/dist/errors/index.js.map +26 -0
  137. package/dist/errors/json-actions.d.ts +38 -0
  138. package/dist/errors/json-actions.d.ts.map +1 -0
  139. package/dist/errors/log.d.ts +8 -0
  140. package/dist/errors/log.d.ts.map +1 -0
  141. package/dist/errors/message-values.d.ts +11 -0
  142. package/dist/errors/message-values.d.ts.map +1 -0
  143. package/dist/errors/messages.d.ts +63 -0
  144. package/dist/errors/messages.d.ts.map +1 -0
  145. package/dist/errors/page-path.d.ts +9 -0
  146. package/dist/errors/page-path.d.ts.map +1 -0
  147. package/dist/errors/problem-error.d.ts +50 -0
  148. package/dist/errors/problem-error.d.ts.map +1 -0
  149. package/dist/errors/provider.d.ts +20 -0
  150. package/dist/errors/provider.d.ts.map +1 -0
  151. package/dist/errors/request-id.d.ts +5 -0
  152. package/dist/errors/request-id.d.ts.map +1 -0
  153. package/dist/errors/route-error.d.ts +33 -0
  154. package/dist/errors/route-error.d.ts.map +1 -0
  155. package/dist/errors/route-refusal.d.ts +20 -0
  156. package/dist/errors/route-refusal.d.ts.map +1 -0
  157. package/dist/errors/same-site.d.ts +49 -0
  158. package/dist/errors/same-site.d.ts.map +1 -0
  159. package/dist/errors/section-action.d.ts +46 -0
  160. package/dist/errors/section-action.d.ts.map +1 -0
  161. package/dist/errors/standard-schema.d.ts +34 -0
  162. package/dist/errors/standard-schema.d.ts.map +1 -0
  163. package/dist/errors/submit-form.d.ts +16 -0
  164. package/dist/errors/submit-form.d.ts.map +1 -0
  165. package/dist/errors/upstream-headers.d.ts +18 -0
  166. package/dist/errors/upstream-headers.d.ts.map +1 -0
  167. package/dist/errors/use-json-fetcher.d.ts +18 -0
  168. package/dist/errors/use-json-fetcher.d.ts.map +1 -0
  169. package/dist/fetcher/auth-refusal.d.ts +29 -0
  170. package/dist/fetcher/auth-refusal.d.ts.map +1 -0
  171. package/dist/fetcher/index.d.ts +20 -0
  172. package/dist/fetcher/index.d.ts.map +1 -0
  173. package/dist/fetcher/index.js +392 -0
  174. package/dist/fetcher/index.js.map +21 -0
  175. package/dist/fetcher/section-form.d.ts +24 -0
  176. package/dist/fetcher/section-form.d.ts.map +1 -0
  177. package/dist/fetcher/section-reload.d.ts +17 -0
  178. package/dist/fetcher/section-reload.d.ts.map +1 -0
  179. package/dist/fetcher/section-save.d.ts +29 -0
  180. package/dist/fetcher/section-save.d.ts.map +1 -0
  181. package/dist/fetcher/use-debounced-fetcher.d.ts +57 -0
  182. package/dist/fetcher/use-debounced-fetcher.d.ts.map +1 -0
  183. package/dist/fetcher/use-fetcher-answer.d.ts +16 -0
  184. package/dist/fetcher/use-fetcher-answer.d.ts.map +1 -0
  185. package/dist/fetcher/use-fetcher-done.d.ts +15 -0
  186. package/dist/fetcher/use-fetcher-done.d.ts.map +1 -0
  187. package/dist/fetcher/use-fetcher-promise.d.ts +48 -0
  188. package/dist/fetcher/use-fetcher-promise.d.ts.map +1 -0
  189. package/dist/fetcher/use-form-refusal.d.ts +20 -0
  190. package/dist/fetcher/use-form-refusal.d.ts.map +1 -0
  191. package/dist/fetcher/use-revalidate-on-focus.d.ts +20 -0
  192. package/dist/fetcher/use-revalidate-on-focus.d.ts.map +1 -0
  193. package/dist/fetcher/use-row-save.d.ts +32 -0
  194. package/dist/fetcher/use-row-save.d.ts.map +1 -0
  195. package/dist/fetcher/use-section-save.d.ts +46 -0
  196. package/dist/fetcher/use-section-save.d.ts.map +1 -0
  197. package/dist/fetcher/use-visible-interval.d.ts +24 -0
  198. package/dist/fetcher/use-visible-interval.d.ts.map +1 -0
  199. package/dist/fetcher/use-visible-revalidation.d.ts +10 -0
  200. package/dist/fetcher/use-visible-revalidation.d.ts.map +1 -0
  201. package/dist/health.d.ts +21 -0
  202. package/dist/health.d.ts.map +1 -0
  203. package/dist/help/check/check.d.ts +35 -0
  204. package/dist/help/check/check.d.ts.map +1 -0
  205. package/dist/help/check/index.d.ts +8 -0
  206. package/dist/help/check/index.d.ts.map +1 -0
  207. package/dist/help/check/index.js +17 -0
  208. package/dist/help/check/index.js.map +9 -0
  209. package/dist/help/check/routes.d.ts +22 -0
  210. package/dist/help/check/routes.d.ts.map +1 -0
  211. package/dist/help/guide.d.ts +33 -0
  212. package/dist/help/guide.d.ts.map +1 -0
  213. package/dist/help/index.d.ts +16 -0
  214. package/dist/help/index.d.ts.map +1 -0
  215. package/dist/help/index.js +192 -0
  216. package/dist/help/index.js.map +14 -0
  217. package/dist/help/load.d.ts +39 -0
  218. package/dist/help/load.d.ts.map +1 -0
  219. package/dist/help/panel.d.ts +69 -0
  220. package/dist/help/panel.d.ts.map +1 -0
  221. package/dist/help/parse-flow.d.ts +27 -0
  222. package/dist/help/parse-flow.d.ts.map +1 -0
  223. package/dist/help/react.d.ts +12 -0
  224. package/dist/help/react.d.ts.map +1 -0
  225. package/dist/help/resolve.d.ts +24 -0
  226. package/dist/help/resolve.d.ts.map +1 -0
  227. package/dist/help/types.d.ts +50 -0
  228. package/dist/help/types.d.ts.map +1 -0
  229. package/dist/help/yaml.d.ts +18 -0
  230. package/dist/help/yaml.d.ts.map +1 -0
  231. package/dist/index.d.ts +7 -0
  232. package/dist/index.d.ts.map +1 -0
  233. package/dist/index.js +197 -0
  234. package/dist/index.js.map +14 -0
  235. package/dist/link/index.d.ts +7 -0
  236. package/dist/link/index.d.ts.map +1 -0
  237. package/dist/link/index.js +16 -0
  238. package/dist/link/index.js.map +10 -0
  239. package/dist/link/router-link.d.ts +27 -0
  240. package/dist/link/router-link.d.ts.map +1 -0
  241. package/dist/lists/connection-page.d.ts +50 -0
  242. package/dist/lists/connection-page.d.ts.map +1 -0
  243. package/dist/lists/index.d.ts +13 -0
  244. package/dist/lists/index.d.ts.map +1 -0
  245. package/dist/lists/index.js +205 -0
  246. package/dist/lists/index.js.map +15 -0
  247. package/dist/lists/newest-first.d.ts +5 -0
  248. package/dist/lists/newest-first.d.ts.map +1 -0
  249. package/dist/lists/nodes-of.d.ts +21 -0
  250. package/dist/lists/nodes-of.d.ts.map +1 -0
  251. package/dist/lists/or-failed.d.ts +19 -0
  252. package/dist/lists/or-failed.d.ts.map +1 -0
  253. package/dist/lists/use-paged-rows.d.ts +40 -0
  254. package/dist/lists/use-paged-rows.d.ts.map +1 -0
  255. package/dist/lists/use-same-route-loading.d.ts +8 -0
  256. package/dist/lists/use-same-route-loading.d.ts.map +1 -0
  257. package/dist/lists/use-search-change.d.ts +20 -0
  258. package/dist/lists/use-search-change.d.ts.map +1 -0
  259. package/dist/mcp/index.d.ts +8 -0
  260. package/dist/mcp/index.d.ts.map +1 -0
  261. package/dist/mcp/index.js +105 -0
  262. package/dist/mcp/index.js.map +11 -0
  263. package/dist/mcp/mcp-relay.d.ts +58 -0
  264. package/dist/mcp/mcp-relay.d.ts.map +1 -0
  265. package/dist/mcp/relay.d.ts +38 -0
  266. package/dist/mcp/relay.d.ts.map +1 -0
  267. package/dist/media/client/error.d.ts +29 -0
  268. package/dist/media/client/error.d.ts.map +1 -0
  269. package/dist/media/client/index.d.ts +8 -0
  270. package/dist/media/client/index.d.ts.map +1 -0
  271. package/dist/media/client/index.js +133 -0
  272. package/dist/media/client/index.js.map +11 -0
  273. package/dist/media/client/upload.d.ts +32 -0
  274. package/dist/media/client/upload.d.ts.map +1 -0
  275. package/dist/media/forward.d.ts +14 -0
  276. package/dist/media/forward.d.ts.map +1 -0
  277. package/dist/media/headers.d.ts +11 -0
  278. package/dist/media/headers.d.ts.map +1 -0
  279. package/dist/media/index.d.ts +9 -0
  280. package/dist/media/index.d.ts.map +1 -0
  281. package/dist/media/index.js +396 -0
  282. package/dist/media/index.js.map +16 -0
  283. package/dist/media/options.d.ts +114 -0
  284. package/dist/media/options.d.ts.map +1 -0
  285. package/dist/media/path.d.ts +12 -0
  286. package/dist/media/path.d.ts.map +1 -0
  287. package/dist/media/read.d.ts +11 -0
  288. package/dist/media/read.d.ts.map +1 -0
  289. package/dist/media/refusal.d.ts +11 -0
  290. package/dist/media/refusal.d.ts.map +1 -0
  291. package/dist/media/respond.d.ts +8 -0
  292. package/dist/media/respond.d.ts.map +1 -0
  293. package/dist/media/write.d.ts +13 -0
  294. package/dist/media/write.d.ts.map +1 -0
  295. package/dist/navigation/index.d.ts +9 -0
  296. package/dist/navigation/index.d.ts.map +1 -0
  297. package/dist/navigation/index.js +48 -0
  298. package/dist/navigation/index.js.map +11 -0
  299. package/dist/navigation/use-focus-on-navigate.d.ts +16 -0
  300. package/dist/navigation/use-focus-on-navigate.d.ts.map +1 -0
  301. package/dist/navigation/use-route-transition.d.ts +19 -0
  302. package/dist/navigation/use-route-transition.d.ts.map +1 -0
  303. package/dist/nonce.d.ts +16 -0
  304. package/dist/nonce.d.ts.map +1 -0
  305. package/dist/oauth/answer.d.ts +33 -0
  306. package/dist/oauth/answer.d.ts.map +1 -0
  307. package/dist/oauth/binding.d.ts +43 -0
  308. package/dist/oauth/binding.d.ts.map +1 -0
  309. package/dist/oauth/consent.d.ts +134 -0
  310. package/dist/oauth/consent.d.ts.map +1 -0
  311. package/dist/oauth/grants.d.ts +88 -0
  312. package/dist/oauth/grants.d.ts.map +1 -0
  313. package/dist/oauth/index.d.ts +16 -0
  314. package/dist/oauth/index.d.ts.map +1 -0
  315. package/dist/oauth/index.js +207 -0
  316. package/dist/oauth/index.js.map +12 -0
  317. package/dist/oauth/model.d.ts +13 -0
  318. package/dist/oauth/model.d.ts.map +1 -0
  319. package/dist/oauth/react/index.d.ts +7 -0
  320. package/dist/oauth/react/index.d.ts.map +1 -0
  321. package/dist/oauth/react/index.js +99 -0
  322. package/dist/oauth/react/index.js.map +10 -0
  323. package/dist/oauth/react/use-consent.d.ts +52 -0
  324. package/dist/oauth/react/use-consent.d.ts.map +1 -0
  325. package/dist/oidc/dpop.d.ts +80 -0
  326. package/dist/oidc/dpop.d.ts.map +1 -0
  327. package/dist/oidc/errors.d.ts +16 -0
  328. package/dist/oidc/errors.d.ts.map +1 -0
  329. package/dist/oidc/flow.d.ts +59 -0
  330. package/dist/oidc/flow.d.ts.map +1 -0
  331. package/dist/oidc/index.d.ts +11 -0
  332. package/dist/oidc/index.d.ts.map +1 -0
  333. package/dist/oidc/index.js +742 -0
  334. package/dist/oidc/index.js.map +15 -0
  335. package/dist/oidc/oidc.d.ts +132 -0
  336. package/dist/oidc/oidc.d.ts.map +1 -0
  337. package/dist/oidc/revoke.d.ts +28 -0
  338. package/dist/oidc/revoke.d.ts.map +1 -0
  339. package/dist/oidc/seal.d.ts +20 -0
  340. package/dist/oidc/seal.d.ts.map +1 -0
  341. package/dist/pwa/build/build-worker.d.ts +41 -0
  342. package/dist/pwa/build/build-worker.d.ts.map +1 -0
  343. package/dist/pwa/build/index.d.ts +9 -0
  344. package/dist/pwa/build/index.d.ts.map +1 -0
  345. package/dist/pwa/build/index.js +9 -0
  346. package/dist/pwa/build/index.js.map +9 -0
  347. package/dist/pwa/build/precache.d.ts +17 -0
  348. package/dist/pwa/build/precache.d.ts.map +1 -0
  349. package/dist/pwa/index.d.ts +16 -0
  350. package/dist/pwa/index.d.ts.map +1 -0
  351. package/dist/pwa/index.js +110 -0
  352. package/dist/pwa/index.js.map +12 -0
  353. package/dist/pwa/model/caching.d.ts +46 -0
  354. package/dist/pwa/model/caching.d.ts.map +1 -0
  355. package/dist/pwa/model/clear-app-caches.d.ts +9 -0
  356. package/dist/pwa/model/clear-app-caches.d.ts.map +1 -0
  357. package/dist/pwa/model/font-precache.d.ts +15 -0
  358. package/dist/pwa/model/font-precache.d.ts.map +1 -0
  359. package/dist/pwa/model/manifest.d.ts +80 -0
  360. package/dist/pwa/model/manifest.d.ts.map +1 -0
  361. package/dist/pwa/model/precache-list.d.ts +40 -0
  362. package/dist/pwa/model/precache-list.d.ts.map +1 -0
  363. package/dist/pwa/model/registration.d.ts +39 -0
  364. package/dist/pwa/model/registration.d.ts.map +1 -0
  365. package/dist/pwa/model/start-service-worker.d.ts +24 -0
  366. package/dist/pwa/model/start-service-worker.d.ts.map +1 -0
  367. package/dist/pwa/model/storable.d.ts +8 -0
  368. package/dist/pwa/model/storable.d.ts.map +1 -0
  369. package/dist/pwa/model/theme-color.d.ts +20 -0
  370. package/dist/pwa/model/theme-color.d.ts.map +1 -0
  371. package/dist/pwa/model/update-notice.d.ts +38 -0
  372. package/dist/pwa/model/update-notice.d.ts.map +1 -0
  373. package/dist/pwa/model/worker-contract.d.ts +61 -0
  374. package/dist/pwa/model/worker-contract.d.ts.map +1 -0
  375. package/dist/pwa/react/index.d.ts +9 -0
  376. package/dist/pwa/react/index.d.ts.map +1 -0
  377. package/dist/pwa/react/index.js +75 -0
  378. package/dist/pwa/react/index.js.map +13 -0
  379. package/dist/pwa/react/use-online.d.ts +6 -0
  380. package/dist/pwa/react/use-online.d.ts.map +1 -0
  381. package/dist/pwa/react/use-service-worker.d.ts +33 -0
  382. package/dist/pwa/react/use-service-worker.d.ts.map +1 -0
  383. package/dist/pwa/react/use-update-notice.d.ts +14 -0
  384. package/dist/pwa/react/use-update-notice.d.ts.map +1 -0
  385. package/dist/pwa/server/index.d.ts +7 -0
  386. package/dist/pwa/server/index.d.ts.map +1 -0
  387. package/dist/pwa/server/index.js +18 -0
  388. package/dist/pwa/server/index.js.map +10 -0
  389. package/dist/pwa/server/no-cache.d.ts +22 -0
  390. package/dist/pwa/server/no-cache.d.ts.map +1 -0
  391. package/dist/pwa/worker/index.d.ts +9 -0
  392. package/dist/pwa/worker/index.d.ts.map +1 -0
  393. package/dist/pwa/worker/index.js +144 -0
  394. package/dist/pwa/worker/index.js.map +12 -0
  395. package/dist/pwa/worker/injected.d.ts +15 -0
  396. package/dist/pwa/worker/injected.d.ts.map +1 -0
  397. package/dist/pwa/worker/plan.d.ts +65 -0
  398. package/dist/pwa/worker/plan.d.ts.map +1 -0
  399. package/dist/pwa/worker/scope.d.ts +18 -0
  400. package/dist/pwa/worker/scope.d.ts.map +1 -0
  401. package/dist/pwa/worker/start-worker.d.ts +17 -0
  402. package/dist/pwa/worker/start-worker.d.ts.map +1 -0
  403. package/dist/react-router.d.ts +68 -0
  404. package/dist/react-router.d.ts.map +1 -0
  405. package/dist/server.d.ts +127 -0
  406. package/dist/server.d.ts.map +1 -0
  407. package/dist/session/codes.d.ts +9 -0
  408. package/dist/session/codes.d.ts.map +1 -0
  409. package/dist/session/cookies.d.ts +128 -0
  410. package/dist/session/cookies.d.ts.map +1 -0
  411. package/dist/session/flow-types.d.ts +235 -0
  412. package/dist/session/flow-types.d.ts.map +1 -0
  413. package/dist/session/guard.d.ts +10 -0
  414. package/dist/session/guard.d.ts.map +1 -0
  415. package/dist/session/index.d.ts +22 -0
  416. package/dist/session/index.d.ts.map +1 -0
  417. package/dist/session/index.js +1090 -0
  418. package/dist/session/index.js.map +27 -0
  419. package/dist/session/land.d.ts +28 -0
  420. package/dist/session/land.d.ts.map +1 -0
  421. package/dist/session/link-json.d.ts +22 -0
  422. package/dist/session/link-json.d.ts.map +1 -0
  423. package/dist/session/link-land.d.ts +20 -0
  424. package/dist/session/link-land.d.ts.map +1 -0
  425. package/dist/session/link-token.d.ts +24 -0
  426. package/dist/session/link-token.d.ts.map +1 -0
  427. package/dist/session/link-types.d.ts +142 -0
  428. package/dist/session/link-types.d.ts.map +1 -0
  429. package/dist/session/links.d.ts +14 -0
  430. package/dist/session/links.d.ts.map +1 -0
  431. package/dist/session/model/index.d.ts +8 -0
  432. package/dist/session/model/index.d.ts.map +1 -0
  433. package/dist/session/model/index.js +35 -0
  434. package/dist/session/model/index.js.map +9 -0
  435. package/dist/session/model/link-post.d.ts +35 -0
  436. package/dist/session/model/link-post.d.ts.map +1 -0
  437. package/dist/session/model/paths.d.ts +24 -0
  438. package/dist/session/model/paths.d.ts.map +1 -0
  439. package/dist/session/model/safe-next.d.ts +15 -0
  440. package/dist/session/model/safe-next.d.ts.map +1 -0
  441. package/dist/session/model/second-factor.d.ts +16 -0
  442. package/dist/session/model/second-factor.d.ts.map +1 -0
  443. package/dist/session/model/site-path.d.ts +10 -0
  444. package/dist/session/model/site-path.d.ts.map +1 -0
  445. package/dist/session/model/step-up-answers.d.ts +45 -0
  446. package/dist/session/model/step-up-answers.d.ts.map +1 -0
  447. package/dist/session/model/step-up-props.d.ts +22 -0
  448. package/dist/session/model/step-up-props.d.ts.map +1 -0
  449. package/dist/session/model/step-up.d.ts +48 -0
  450. package/dist/session/model/step-up.d.ts.map +1 -0
  451. package/dist/session/react/index.d.ts +13 -0
  452. package/dist/session/react/index.d.ts.map +1 -0
  453. package/dist/session/react/index.js +196 -0
  454. package/dist/session/react/index.js.map +14 -0
  455. package/dist/session/react/step-up/answers.d.ts +9 -0
  456. package/dist/session/react/step-up/answers.d.ts.map +1 -0
  457. package/dist/session/react/step-up/dialog-props.d.ts +27 -0
  458. package/dist/session/react/step-up/dialog-props.d.ts.map +1 -0
  459. package/dist/session/react/step-up/index.d.ts +7 -0
  460. package/dist/session/react/step-up/index.d.ts.map +1 -0
  461. package/dist/session/react/step-up/pending-runs.d.ts +21 -0
  462. package/dist/session/react/step-up/pending-runs.d.ts.map +1 -0
  463. package/dist/session/react/step-up/phase.d.ts +8 -0
  464. package/dist/session/react/step-up/phase.d.ts.map +1 -0
  465. package/dist/session/react/step-up/use-step-up-replay.d.ts +59 -0
  466. package/dist/session/react/step-up/use-step-up-replay.d.ts.map +1 -0
  467. package/dist/session/react/step-up/use-step-up-runner.d.ts +70 -0
  468. package/dist/session/react/step-up/use-step-up-runner.d.ts.map +1 -0
  469. package/dist/session/react/step-up/use-step-up.d.ts +51 -0
  470. package/dist/session/react/step-up/use-step-up.d.ts.map +1 -0
  471. package/dist/session/react/use-code-field.d.ts +37 -0
  472. package/dist/session/react/use-code-field.d.ts.map +1 -0
  473. package/dist/session/react/use-link-fragment.d.ts +22 -0
  474. package/dist/session/react/use-link-fragment.d.ts.map +1 -0
  475. package/dist/session/react/use-link-param.d.ts +26 -0
  476. package/dist/session/react/use-link-param.d.ts.map +1 -0
  477. package/dist/session/react/use-link-post.d.ts +39 -0
  478. package/dist/session/react/use-link-post.d.ts.map +1 -0
  479. package/dist/session/react/use-sign-out.d.ts +46 -0
  480. package/dist/session/react/use-sign-out.d.ts.map +1 -0
  481. package/dist/session/second-factor.d.ts +22 -0
  482. package/dist/session/second-factor.d.ts.map +1 -0
  483. package/dist/session/serialize.d.ts +42 -0
  484. package/dist/session/serialize.d.ts.map +1 -0
  485. package/dist/session/sign-in.d.ts +19 -0
  486. package/dist/session/sign-in.d.ts.map +1 -0
  487. package/dist/session/signed.d.ts +44 -0
  488. package/dist/session/signed.d.ts.map +1 -0
  489. package/dist/session/social-flow.d.ts +22 -0
  490. package/dist/session/social-flow.d.ts.map +1 -0
  491. package/dist/session/social-land.d.ts +31 -0
  492. package/dist/session/social-land.d.ts.map +1 -0
  493. package/dist/session/social-types.d.ts +136 -0
  494. package/dist/session/social-types.d.ts.map +1 -0
  495. package/dist/session/social.d.ts +32 -0
  496. package/dist/session/social.d.ts.map +1 -0
  497. package/dist/session/step-up-codes.d.ts +9 -0
  498. package/dist/session/step-up-codes.d.ts.map +1 -0
  499. package/dist/session/step-up-signed-out.d.ts +21 -0
  500. package/dist/session/step-up-signed-out.d.ts.map +1 -0
  501. package/dist/session/step-up-types.d.ts +127 -0
  502. package/dist/session/step-up-types.d.ts.map +1 -0
  503. package/dist/session/step-up.d.ts +17 -0
  504. package/dist/session/step-up.d.ts.map +1 -0
  505. package/dist/session/step.d.ts +22 -0
  506. package/dist/session/step.d.ts.map +1 -0
  507. package/dist/session/throttle.d.ts +73 -0
  508. package/dist/session/throttle.d.ts.map +1 -0
  509. package/dist/session/timed-wait.d.ts +4 -0
  510. package/dist/session/timed-wait.d.ts.map +1 -0
  511. package/dist/session/viewer.d.ts +34 -0
  512. package/dist/session/viewer.d.ts.map +1 -0
  513. package/dist/subscription/documents.d.ts +3 -0
  514. package/dist/subscription/documents.d.ts.map +1 -0
  515. package/dist/subscription/index.d.ts +7 -0
  516. package/dist/subscription/index.d.ts.map +1 -0
  517. package/dist/subscription/index.js +359 -0
  518. package/dist/subscription/index.js.map +14 -0
  519. package/dist/subscription/proxy.d.ts +54 -0
  520. package/dist/subscription/proxy.d.ts.map +1 -0
  521. package/dist/subscription/react/backoff.d.ts +8 -0
  522. package/dist/subscription/react/backoff.d.ts.map +1 -0
  523. package/dist/subscription/react/classify.d.ts +15 -0
  524. package/dist/subscription/react/classify.d.ts.map +1 -0
  525. package/dist/subscription/react/controller.d.ts +40 -0
  526. package/dist/subscription/react/controller.d.ts.map +1 -0
  527. package/dist/subscription/react/fake-timers.d.ts +8 -0
  528. package/dist/subscription/react/fake-timers.d.ts.map +1 -0
  529. package/dist/subscription/react/index.d.ts +15 -0
  530. package/dist/subscription/react/index.d.ts.map +1 -0
  531. package/dist/subscription/react/index.js +227 -0
  532. package/dist/subscription/react/index.js.map +17 -0
  533. package/dist/subscription/react/reconnect.d.ts +9 -0
  534. package/dist/subscription/react/reconnect.d.ts.map +1 -0
  535. package/dist/subscription/react/scheduler.d.ts +13 -0
  536. package/dist/subscription/react/scheduler.d.ts.map +1 -0
  537. package/dist/subscription/react/timers.d.ts +7 -0
  538. package/dist/subscription/react/timers.d.ts.map +1 -0
  539. package/dist/subscription/react/use-live-subscription.d.ts +36 -0
  540. package/dist/subscription/react/use-live-subscription.d.ts.map +1 -0
  541. package/dist/subscription/react/versions.d.ts +6 -0
  542. package/dist/subscription/react/versions.d.ts.map +1 -0
  543. package/dist/subscription/read.d.ts +17 -0
  544. package/dist/subscription/read.d.ts.map +1 -0
  545. package/dist/subscription/refusal.d.ts +11 -0
  546. package/dist/subscription/refusal.d.ts.map +1 -0
  547. package/dist/subscription/relay.d.ts +16 -0
  548. package/dist/subscription/relay.d.ts.map +1 -0
  549. package/dist/vite/bun.d.ts +21 -0
  550. package/dist/vite/bun.d.ts.map +1 -0
  551. package/dist/vite/bundle.d.ts +33 -0
  552. package/dist/vite/bundle.d.ts.map +1 -0
  553. package/dist/vite/compress.d.ts +18 -0
  554. package/dist/vite/compress.d.ts.map +1 -0
  555. package/dist/vite/config.d.ts +33 -0
  556. package/dist/vite/config.d.ts.map +1 -0
  557. package/dist/vite/dev.d.ts +28 -0
  558. package/dist/vite/dev.d.ts.map +1 -0
  559. package/dist/vite/entry.d.ts +20 -0
  560. package/dist/vite/entry.d.ts.map +1 -0
  561. package/dist/vite/hosts.d.ts +16 -0
  562. package/dist/vite/hosts.d.ts.map +1 -0
  563. package/dist/vite/index.d.ts +68 -0
  564. package/dist/vite/index.d.ts.map +1 -0
  565. package/dist/vite/index.js +635 -0
  566. package/dist/vite/index.js.map +22 -0
  567. package/dist/vite/inline.d.ts +18 -0
  568. package/dist/vite/inline.d.ts.map +1 -0
  569. package/dist/vite/node.d.ts +16 -0
  570. package/dist/vite/node.d.ts.map +1 -0
  571. package/dist/vite/preview.d.ts +8 -0
  572. package/dist/vite/preview.d.ts.map +1 -0
  573. package/dist/vite/runtime.d.ts +8 -0
  574. package/dist/vite/runtime.d.ts.map +1 -0
  575. package/dist/vite/socket.d.ts +75 -0
  576. package/dist/vite/socket.d.ts.map +1 -0
  577. package/dist/vite/worker.d.ts +16 -0
  578. package/dist/vite/worker.d.ts.map +1 -0
  579. package/dist/with-alxia.d.ts +36 -0
  580. package/dist/with-alxia.d.ts.map +1 -0
  581. package/docs/README.md +42 -0
  582. package/docs/guide/api-keys.md +216 -0
  583. package/docs/guide/beside-the-pages.md +201 -0
  584. package/docs/guide/csp-nonce.md +166 -0
  585. package/docs/guide/customising-the-server.md +324 -0
  586. package/docs/guide/deploying.md +102 -0
  587. package/docs/guide/document.md +334 -0
  588. package/docs/guide/errors.md +1147 -0
  589. package/docs/guide/fetcher.md +355 -0
  590. package/docs/guide/getting-started.md +112 -0
  591. package/docs/guide/help.md +325 -0
  592. package/docs/guide/how-it-works.md +274 -0
  593. package/docs/guide/link.md +32 -0
  594. package/docs/guide/lists.md +225 -0
  595. package/docs/guide/mcp.md +173 -0
  596. package/docs/guide/media.md +273 -0
  597. package/docs/guide/navigation.md +52 -0
  598. package/docs/guide/oauth.md +342 -0
  599. package/docs/guide/oidc.md +262 -0
  600. package/docs/guide/openapi.md +51 -0
  601. package/docs/guide/pwa.md +670 -0
  602. package/docs/guide/session.md +2105 -0
  603. package/docs/guide/subscriptions.md +211 -0
  604. package/docs/guide/testing.md +42 -0
  605. package/docs/guide/typing-the-loaders.md +311 -0
  606. package/docs/guide.md +82 -0
  607. package/docs/roadmap.md +474 -0
  608. package/docs/troubleshooting.md +3837 -0
  609. package/package.json +301 -5
@@ -0,0 +1,1147 @@
1
+ # An API's refusals, worded for the page
2
+
3
+ This page covers how an app that calls a GraphQL API words that API's refusals
4
+ for its pages: the error's shape (and a REST API's RFC 9457 problem replies), the request id it carries, the page a
5
+ request is for, the catalogue store of the API's messages, the form checks in
6
+ the API's words, the provider that fills the catalogue, the wording of a
7
+ refusal, the loaders, the error page and the actions that answer with it, the JSON those actions read and the fetcher hook that posts it, calling the API from a loader, and keeping the API's catalogue fresh.
8
+ The code is in `@softistx/alxia-react-router/errors`, which has no UI. Its one runtime
9
+ import is `react-router`, never `@softistx/alxia`, so a page can import it
10
+ (`boundary.spec.ts` checks the built files).
11
+
12
+ - [What the subpath holds](#what-the-subpath-holds)
13
+ - [Recognising an API error](#recognising-an-api-error)
14
+ - [A REST API's problem replies](#a-rest-apis-problem-replies)
15
+ - [The request id](#the-request-id)
16
+ - [The page a request is for](#the-page-a-request-is-for)
17
+ - [The catalogue store](#the-catalogue-store)
18
+ - [Form checks in the API's words](#form-checks-in-the-apis-words)
19
+ - [Wording a refusal](#wording-a-refusal)
20
+ - [Loaders and the error page](#loaders-and-the-error-page)
21
+ - [Actions](#actions)
22
+ - [JSON actions and CSRF](#json-actions-and-csrf)
23
+ - [Calling the API from a loader](#calling-the-api-from-a-loader)
24
+ - [Keeping the catalogue fresh](#keeping-the-catalogue-fresh)
25
+
26
+ ## What the subpath holds
27
+
28
+ | export | what it is |
29
+ | --- | --- |
30
+ | `ApiErrorLike`, `isApiErrorLike(error)` | the shape of `@nxgt/graphql-client`'s `ApiError`, and the test for it |
31
+ | `isStaleVersion(error)` | whether `error` is an API's refusal of an out-of-date update: an `ApiErrorLike` with status 409 whose `code` ends with `.errors.stale-version`; false for any other value |
32
+ | `ApiErrorEntryLike`, `ApiErrorExtensionsLike`, `ApiErrorParamsLike`, `ApiFieldErrorLike` | one error of the response, its `extensions`, their `params`, and one refused field |
33
+ | `waitMinutes(extensions)` | the minutes of a throttle's wait: `minutes` (at least one), else `retryAfter` rounded up to minutes |
34
+ | `retryAfterOf(error)` | the seconds a 429 asks to wait, for a countdown on your own forms: `retryAfter` of the first error's `params`, else of its `extensions`, rounded up and held at a day; `undefined` when none is usable |
35
+ | `attemptsLeftOf(error)` | the tries a refused code leaves, as `@softistx/janus` counts them: `extensions.attemptsLeft` of the first error, else `params.attemptsLeft`; `undefined` when it is not a whole number from 0 up, or when the refusal is throttled (a rate limit spends no try) |
36
+ | `isThrottledReason(error)` | whether the first error's `extensions.reason` (else `params.reason`) is `'throttled'`: a rate limit that asks to wait, whatever its code; use it in a `refused` callback to skip any tries-left logic |
37
+ | `REQUEST_ID_HEADER`, `requestIdOf(response)` | the header an API echoes on every response, and its value |
38
+ | `nextOf(url)` | the page a request is for, as `next` carries it back after sign-in |
39
+ | `FormErrors` | what a form action answers when the API refused the input |
40
+ | `routeError(error, options?)`, `errorRequestId(error)`, `RouteErrorData`, `RouteErrorOptions` | what a loader throws for the API's error, and the support reference its error page reads |
41
+ | `isRouteRefusal(value)`, `routeRefusalStatus(value)`, `RouteRefusal`, `DataRefusal` | the test for a caught React Router `data(body, { status })` value or `Response`, and its status |
42
+ | `problemError(reply, options?)`, `ProblemError`, `isProblemErrorLike`, `ProblemErrorLike`, `ProblemReply`, `ProblemErrorOptions` | the typed error of a REST API's RFC 9457 problem reply, built from `{ status, data }`; `routeError` and `apiCallFailure` recognise it |
43
+ | `createApiMessages`, `ApiMessages`, `ApiMessagesOptions`, `CatalogueMessage(s)`, `ParamKind`, `MessageFormat`, `MessageValues` | the catalogue of the API's messages, held by the app |
44
+ | `apiCodeResolver`, `ApiCodeResolver`, `ApiCodeResolverOptions`, `CodeIssueLike` | the words of a form's checks, from that catalogue; `CodeIssueLike` is the issue a custom `codeOf` receives |
45
+ | `ApiMessagesProvider`, `ApiMessagesProviderProps` | fills the catalogue in the browser from the root's data |
46
+ | `createApiErrors`, `ApiErrors`, `ApiErrorsOptions` | what a page says of a refusal, from that catalogue: the message, the fields, the status |
47
+ | `ApiRefusal` | a refused call as a page says it: `{ message, status }` |
48
+ | `requireSameSite(request, from?)`, `SameSiteOptions` | the same-site guard for any POST, form or JSON |
49
+ | `jsonActions({ origin? })`, `JsonActions`, `JsonActionsOptions` | `readJson`, `requireJsonPost` and `readInput` for the actions: JSON only, from this site only |
50
+ | `useJsonFetcher(key?, action?)`, `JsonBody` | a fetcher that posts JSON: `{ fetcher, post(body, to?), busy }` |
51
+ | `apiCallFailure(error, options)`, `CallFailureOptions`, `operationName(document)`, `DocumentLike` | what a failed call to the API becomes for a loader to throw, logged with the request id, and the operation's name for the log |
52
+ | `createErrorCatalogue`, `ErrorCatalogue`, `ErrorCatalogueOptions`, `CatalogueReply` | reads the API's catalogue into the store and keeps it fresh: `fresh`, `freshAll`, `warm`, `clientMessages`; `reset`, `settled`, `heldVersion` and the `now` parameters are for tests |
53
+ | `StandardSchemaV1` | the Standard Schema v1 type `readInput` takes, declared here (type only; `readInput`'s output is inferred from the schema's `~standard.types`) |
54
+
55
+ ## Recognising an API error
56
+
57
+ The subpath does not depend on `@nxgt/graphql-client`. `isApiErrorLike` tests
58
+ an `Error` named `ApiError` that has an `errors` array, like the client's
59
+ `isApiError`, plus a numeric `status`, which `ApiErrorLike` promises. It holds
60
+ when two copies of the client are installed.
61
+
62
+ ```ts
63
+ import { isApiErrorLike } from '@softistx/alxia-react-router/errors';
64
+
65
+ export function codeOf(error: unknown) {
66
+ return isApiErrorLike(error) ? error.code : undefined;
67
+ }
68
+ ```
69
+
70
+ `isStaleVersion` recognises the refusal of an update whose version is out of
71
+ date: a 409 whose code ends with `.errors.stale-version`.
72
+
73
+ ```ts
74
+ import { isStaleVersion } from '@softistx/alxia-react-router/errors';
75
+
76
+ export function needsReload(error: unknown) {
77
+ return isStaleVersion(error);
78
+ }
79
+ ```
80
+
81
+ An `ApiError` is assignable to `ApiErrorLike` as it is. The shape's code is
82
+ the API's own `<module>.errors.<slug>`, such as `todos.errors.title-taken`
83
+ or `userProfiles.errors.slug-taken` (the module is kebab-case or camelCase).
84
+
85
+ `waitMinutes` reads a throttle's wait the way the API words it: the
86
+ `minutes` of `extensions.params` or beside it, at least one, else the
87
+ `retryAfter` seconds rounded up.
88
+
89
+ ```ts
90
+ import { waitMinutes } from '@softistx/alxia-react-router/errors';
91
+
92
+ waitMinutes({ retryAfter: 90 }); // 2
93
+ waitMinutes({ params: { minutes: 4 } }); // 4
94
+ ```
95
+
96
+ ### The seconds a 429 asks to wait
97
+
98
+ `retryAfterOf(error)` reads the wait of a rate-limited call in seconds, from
99
+ `retryAfter` in the first error's `extensions.params`, else in its
100
+ `extensions`. Only a finite number from 0 or a decimal string counts; it is
101
+ rounded up and held at a day (86 400). It answers `undefined` when the API sent
102
+ no usable value, so a form can fall back to `waitMinutes` or to no countdown.
103
+ `/session`'s flows return the same value as `retryAfter` on a `throttled`
104
+ answer; use `retryAfterOf` on your own actions (sign-up, set password, any
105
+ rate-limited mutation).
106
+
107
+ ```ts
108
+ import { data } from 'react-router';
109
+ import { isApiErrorLike, retryAfterOf } from '@softistx/alxia-react-router/errors';
110
+
111
+ export async function action({ request }: { request: Request }) {
112
+ try {
113
+ await signUp(await request.json());
114
+ } catch (error) {
115
+ if (isApiErrorLike(error) && error.status === 429) {
116
+ return data({ retryAfter: retryAfterOf(error) }, { status: 429 });
117
+ }
118
+ throw error;
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### The tries a code leaves
124
+
125
+ A wrong second-factor or step-up code is refused with `@softistx/janus`'s
126
+ `CODE_INVALID` and the tries left in `extensions.attemptsLeft`.
127
+ `attemptsLeftOf(error)` reads that count from the first error, else from its
128
+ `params`, and answers `undefined` for anything that is not a whole number from
129
+ 0 up (a string, a negative number, a missing key). `0` is a count: no try is
130
+ left.
131
+
132
+ ```ts
133
+ import { attemptsLeftOf } from '@softistx/alxia-react-router/errors';
134
+
135
+ attemptsLeftOf(error); // 3 after a wrong code, 0 on the last, undefined if uncounted
136
+ ```
137
+
138
+ A throttled refusal (`reason: 'throttled'`) spends no try, so
139
+ `attemptsLeftOf` answers `undefined` for it even when the API sends
140
+ `attemptsLeft: 0` beside it: a challenge that is only rate-limited is not
141
+ spent. `isThrottledReason(error)` is the same test, exported for a `refused`
142
+ callback that handles the wait apart from the tries:
143
+
144
+ ```ts
145
+ import {
146
+ attemptsLeftOf,
147
+ isThrottledReason,
148
+ retryAfterOf,
149
+ type ApiErrorLike,
150
+ } from '@softistx/alxia-react-router/errors';
151
+
152
+ // A throttled code asks to wait; any other refusal says the tries it leaves.
153
+ const reading = (error: ApiErrorLike) =>
154
+ isThrottledReason(error)
155
+ ? { retryAfter: retryAfterOf(error) }
156
+ : { attemptsLeft: attemptsLeftOf(error) };
157
+ ```
158
+
159
+ [`signInFlow`'s `codeRefusal`](session.md#the-second-factor) words it for a
160
+ sign-in's code page, and tells a throttled refusal
161
+ (`reason: 'throttled'`, with `retryAfter`) as a wait.
162
+
163
+ ## A REST API's problem replies
164
+
165
+ An API that answers `application/problem+json` (RFC 9457) through an
166
+ OpenAPI client has no GraphQL `errors`. Turn its `{ status, data }` reply into
167
+ a typed error with `problemError`:
168
+
169
+ ```ts
170
+ import { problemError, routeError } from '@softistx/alxia-react-router/errors';
171
+
172
+ // A reply from an OpenAPI client.
173
+ const reply = {
174
+ status: 409,
175
+ data: { type: 'about:blank', title: 'Conflict', detail: 'item exists' },
176
+ };
177
+ const error = problemError(reply, { requestId: 'req-1' });
178
+ error.status; // 409
179
+ error.title; // 'Conflict'
180
+ error.detail; // 'item exists'
181
+ error.message; // 'item exists' (the detail, else the title)
182
+ throw routeError(error); // 401, 403, 404 and 503 become route errors
183
+ ```
184
+
185
+ A body that is not a problem document (empty, text, no string `title`) gives
186
+ the title `Error <status>`. `routeError` words a routed status like an
187
+ `ApiError`, with the `message` and the `requestId` (a problem has no `code`),
188
+ and `apiCallFailure` returns it as it is, with `requestId` set and a log line.
189
+ `isProblemErrorLike` recognises it by its `name`, so it holds across two copies
190
+ of the package.
191
+
192
+ ## Recognising a thrown refusal
193
+
194
+ A route can throw a React Router `data(body, { status })` value (the consent
195
+ route's action does, on a 400 or the viewer callback's 401) or a `Response`.
196
+ `isRouteRefusal` narrows a caught value to one of them, and `routeRefusalStatus`
197
+ reads its status, so no check on React Router's internals is needed.
198
+
199
+ ```ts
200
+ import { isRouteRefusal, routeRefusalStatus } from '@softistx/alxia-react-router/errors';
201
+
202
+ export async function action(run: () => Promise<unknown>) {
203
+ try {
204
+ return await run();
205
+ } catch (value) {
206
+ if (routeRefusalStatus(value) === 401) return { signedOut: true };
207
+ if (isRouteRefusal(value) && !(value instanceof Response)) {
208
+ console.warn(value.init.status, value.data);
209
+ }
210
+ throw value;
211
+ }
212
+ }
213
+ ```
214
+
215
+ Any thrown `Response` counts, whatever its status (a route may throw a redirect), so read the status before treating it as an error. A plain `Error`, a non-object, or a `data()` with no status is not a refusal. The `data()` test reads React Router's `type` and `init.status`; its spec builds the value with the real `data()`, so a change there fails it.
216
+ `@softistx/alxia-react-router/oauth` re-exports both.
217
+
218
+ ## The request id
219
+
220
+ An API that echoes `x-request-id` lets a page tell the user which request
221
+ failed, and the API's log find it.
222
+
223
+ ```ts
224
+ import { requestIdOf } from '@softistx/alxia-react-router/errors';
225
+
226
+ export function idOf(response: Response) {
227
+ return requestIdOf(response); // undefined when the API sent none
228
+ }
229
+ ```
230
+
231
+ ## The page a request is for
232
+
233
+ On a client navigation, `request.url` is `/todos/list.data?q=a&_routes=…`
234
+ (`/_.data` for `/`), React Router's single-fetch details. `nextOf` returns the
235
+ page itself, for the `next` a sign-in carries back. It never starts with two
236
+ slashes (`//evil.com` and `/\evil.com` both read as another site to a
237
+ redirect), but it is not a validation: an app must still check `next` before
238
+ redirecting to it after sign-in.
239
+
240
+
241
+ ```ts
242
+ import { nextOf } from '@softistx/alxia-react-router/errors';
243
+
244
+ nextOf('https://app.test/todos/list.data?q=a&_routes=root'); // '/todos/list?q=a'
245
+ ```
246
+
247
+ ## The catalogue store
248
+
249
+ An API that words its refusals by code (`todos.errors.title-taken`) can list
250
+ its messages: the uninterpolated ICU text, and the kind of each argument.
251
+ `createApiMessages` holds them for the languages the app speaks. It is an
252
+ instance, not module state, so a spec makes its own and two copies of the
253
+ package never split it. Make one in a module of its own:
254
+
255
+ ```ts
256
+ // app/api-messages.ts
257
+ import { formatMessage } from '@nxgt/material/i18n';
258
+ import { createApiMessages } from '@softistx/alxia-react-router/errors';
259
+
260
+ export const apiMessages = createApiMessages<'en' | 'fr'>({
261
+ format: formatMessage,
262
+ });
263
+ ```
264
+
265
+ `format` is the app's ICU formatter, the engine of its own translator, so the
266
+ API's messages and the app's read alike. It is called as
267
+ `format(message, language, values, { onError })` and reports a message it
268
+ could not format to `onError`; material's `formatMessage` fits as it is.
269
+
270
+ ```ts
271
+ apiMessages.set('en', {
272
+ 'todos.errors.items-outside-list': {
273
+ message: '{count, plural, one {One item is} other {# items are}} outside {name}.',
274
+ params: [
275
+ { name: 'count', kind: 'PLURAL' },
276
+ { name: 'name', kind: 'TEXT' },
277
+ ],
278
+ },
279
+ });
280
+
281
+ apiMessages.apiMessage('todos.errors.items-outside-list', { count: '3', name: 'Home' }, 'en');
282
+ // '3 items are outside Home.'
283
+ ```
284
+
285
+ The `kind` of an argument says what to supply without parsing the message: a
286
+ `DATE` given as `YYYY-MM-DD` becomes a local `Date` (by calendar parts, so
287
+ the day is the same in every time zone), and a `NUMBER` or `PLURAL` given as a
288
+ numeric string a number. `apiMessage` returns `undefined` for a code the store
289
+ lacks or a message that cannot be formatted with those values (a missing
290
+ argument, a day it cannot read), so the caller falls back to the message the
291
+ API already worded.
292
+
293
+ `set(language, messages)` replaces a language, which is what a server does
294
+ with the whole catalogue. `add` merges, which is what the browser does with
295
+ the few messages its forms word. `clear` forgets everything, for specs.
296
+
297
+ In the browser, `ApiMessagesProvider` adds the messages the root's data
298
+ carries (`value` is the root loader's data, `messages` the store to fill) before the children render, since the resolver reads them
299
+ synchronously. It is a plain function with no JSX, and it imports React for its
300
+ types only:
301
+
302
+ ```tsx
303
+ // app/root.tsx
304
+ import { ApiMessagesProvider } from '@softistx/alxia-react-router/errors';
305
+ import { apiMessages } from './api-messages';
306
+
307
+ export default function App({ loaderData }: Route.ComponentProps) {
308
+ return (
309
+ <ApiMessagesProvider messages={apiMessages} value={loaderData.apiMessages}>
310
+ <Outlet />
311
+ </ApiMessagesProvider>
312
+ );
313
+ }
314
+ ```
315
+
316
+ It writes in the browser only. A server render leaves the store as it is,
317
+ because the server holds the whole, fresher catalogue and a render's data may
318
+ be older than it.
319
+
320
+ ## Form checks in the API's words
321
+
322
+ A form validates before it posts, and a check that mirrors the API's rule
323
+ should read as the API words it. A refinement carries the API's code in
324
+ `params.code`, and `apiCodeResolver` turns that into the catalogue's text:
325
+
326
+ ```ts
327
+ // app/code-resolver.ts
328
+ import { apiCodeResolver } from '@softistx/alxia-react-router/errors';
329
+ import { apiMessages } from './api-messages';
330
+ import { getLanguage, translate } from './i18n';
331
+
332
+ export const CODE_RESOLVER = apiCodeResolver(apiMessages, {
333
+ translate,
334
+ language: getLanguage,
335
+ });
336
+ ```
337
+
338
+ ```tsx
339
+ import { useCodeResolver } from '@nxgt/material/components';
340
+
341
+ const schema = z.object({ title: z.string() }).refine(isFree, {
342
+ path: ['title'],
343
+ params: { code: 'todos.errors.title-taken' },
344
+ });
345
+
346
+ const resolver = useCodeResolver(schema, CODE_RESOLVER);
347
+ ```
348
+
349
+ The result is `{ translate, codeOf }`, assignable to material's
350
+ `CodeResolverOptions`. An API code (`<module>.errors.<slug>`) takes the
351
+ catalogue's message in the page's language; any other key takes the app's
352
+ `translate`; a code the catalogue lacks comes back as it is, so the form
353
+ library words the issue with its own locale and never shows the code. Make
354
+ it once, at module scope: a new function re-creates the resolver.
355
+
356
+ Two options adapt it. `codeOf(issue)` says which code an issue carries (the
357
+ refinement's `params.code` by default); an app that also words an empty field
358
+ as the API's `validation.errors.required` passes its own. `isApiCode(key)`
359
+ says which keys are API codes (`<module>.errors.<slug>` by default, the
360
+ module in kebab-case or camelCase).
361
+
362
+ ```ts
363
+ import { apiCodeResolver } from '@softistx/alxia-react-router/errors';
364
+ import { apiMessages } from './api-messages';
365
+ import { getLanguage, translate } from './i18n';
366
+
367
+ export const CODE_RESOLVER = apiCodeResolver(apiMessages, {
368
+ translate,
369
+ language: getLanguage,
370
+ // An empty string field is the API's "required" refusal.
371
+ codeOf: (issue) =>
372
+ issue.code === 'too_small' && issue.origin === 'string'
373
+ ? 'validation.errors.required'
374
+ : (issue.params?.code as string | undefined),
375
+ // Only the API's own modules are worded by the catalogue.
376
+ isApiCode: (key) => /^(todos|validation)\.errors\./.test(key),
377
+ });
378
+ ```
379
+
380
+ The codes a browser can word are the ones the root's data brought, so the
381
+ app lists the few its forms use. A code missing from that list shows its
382
+ fallback ([troubleshooting](../troubleshooting.md#a-forms-own-check-shows-the-code-todoserrors-instead-of-words)).
383
+
384
+ ## Wording a refusal
385
+
386
+ An action or a loader that calls the API meets a refusal as an `ApiError`.
387
+ `createApiErrors` says it in the page's language, from the catalogue the app
388
+ keeps. Make one beside the catalogue:
389
+
390
+ ```ts
391
+ // app/api-errors.ts
392
+ import { createApiErrors } from '@softistx/alxia-react-router/errors';
393
+ import { apiMessages } from './api-messages';
394
+ import { translate } from './i18n';
395
+
396
+ export const apiErrors = createApiErrors<'en' | 'fr'>({
397
+ messages: apiMessages,
398
+ // The app's own word for an API it cannot reach: never an API code.
399
+ unavailable: (language) => translate('app.error.unavailable', language),
400
+ });
401
+ ```
402
+
403
+ - `apiErrorMessage(error, language)` is the catalogue's text of the error's
404
+ code with its `params` filled in (`extensions.params` over the extensions
405
+ themselves), else the message the API already worded.
406
+ - `fieldErrors(error, language)` is the message of each refused field by
407
+ input path, from `extensions.fields`; a refusal that names one field
408
+ (`extensions.field`) gives it the error's message. It is a `FormErrors`'
409
+ `fieldErrors`.
410
+ - `apiRefusal(error, language)` is what a failed call says to the user, as
411
+ `{ message, status }` (an `ApiRefusal`): the refusal's message with its
412
+ status, or `unavailable` with 503 for a 503 `Response` (an API that could
413
+ not be reached). It is `undefined` for anything else, which the caller
414
+ rethrows.
415
+ - `translateCode(code, fallback, language, values?)` words one code; use it
416
+ for a code the app words itself, such as a mail throttle's
417
+ `notes.errors.too-many-attempts` with `{ minutes: waitMinutes(extensions) }`.
418
+
419
+ ```ts
420
+ import { data } from 'react-router';
421
+ import { apiErrors } from './api-errors';
422
+ import type { Route } from './+types/todos';
423
+
424
+ // Your own call to the API, declared here as a stub.
425
+ declare function createTodo(input: unknown): Promise<void>;
426
+
427
+ export async function action({ request }: Route.ActionArgs) {
428
+ try {
429
+ await createTodo(await request.json());
430
+ return { ok: true };
431
+ } catch (error) {
432
+ const refusal = apiErrors.apiRefusal(error, 'en');
433
+ if (!refusal) throw error;
434
+ return data(
435
+ { formError: refusal.message },
436
+ { status: refusal.status },
437
+ );
438
+ }
439
+ }
440
+ ```
441
+
442
+ Two options are for an API that is stricter than the default. An error with
443
+ no API code (a raw `BAD_USER_INPUT`, from a constraint that failed before the
444
+ API's validation layer) says the API's own message unless the app gives
445
+ `refused`, its generic refusal, which then replaces it; the raw message is
446
+ never shown. `byCode` words given codes in the app's own way, for refusals
447
+ whose params differ and name no field, such as a query's depth or cost:
448
+
449
+ ```ts
450
+ export const apiErrors = createApiErrors<'en' | 'fr'>({
451
+ messages: apiMessages,
452
+ unavailable: (language) => translate('app.error.unavailable', language),
453
+ refused: (language) => translate('app.error.refused', language),
454
+ byCode: {
455
+ 'validation.errors.query-too-deep': (_error, language) =>
456
+ translate('app.error.too-heavy', language),
457
+ 'validation.errors.query-too-wide': (_error, language) =>
458
+ translate('app.error.too-heavy', language),
459
+ },
460
+ });
461
+ ```
462
+
463
+ The order is exact. `refused` applies only when the error has no API code,
464
+ or a code that `isApiCode` rejects; it outranks `byCode`. Then comes the
465
+ catalogue, then the API's own message. `fieldErrors` uses the same order for
466
+ a single `extensions.field`, while the entries of `extensions.fields` go
467
+ straight to the catalogue.
468
+
469
+ `reword` words a whole family of codes once, after the text is worded, so
470
+ there is no list of codes to keep in step with the catalogue. It receives the
471
+ final text, the error, and `{ code, values, language }`: `values` are the
472
+ merged values the catalogue formats with (`extensions` and
473
+ `extensions.params`, the params winning). Return the text to show, or
474
+ `undefined` to keep it:
475
+
476
+ ```ts
477
+ export const apiErrors = createApiErrors<'en' | 'fr'>({
478
+ messages: apiMessages,
479
+ unavailable: (language) => translate('app.error.unavailable', language),
480
+ reword: (text, error, { code }) =>
481
+ code.endsWith('.errors.referenced')
482
+ ? `${text} ${stillLinkedTo(error)}`
483
+ : undefined,
484
+ });
485
+ ```
486
+
487
+ `reword` sees the text `apiErrorMessage` returns for an error with a code,
488
+ whichever produced it: the catalogue, the API's own message, or `byCode`; so
489
+ `apiRefusal`, `fetcherResult`, `fetcherRefusal`, `formRefusal`, `submitForm` and a single
490
+ `extensions.field` are reworded too. It does not see `refused`'s text (an
491
+ error with no API code), `unavailable`'s (a network failure, which is no API
492
+ code), `translateCode`'s, nor the entries of `extensions.fields`, which go
493
+ straight to the catalogue.
494
+
495
+ `isApiCode` changes what counts as an API code (`<module>.errors.<slug>` by
496
+ default, the module in kebab-case or camelCase). Here only the codes of the
497
+ `todos` module are the catalogue's; any other code, even one shaped like a
498
+ catalogue code, says `refused`:
499
+
500
+ ```ts
501
+ export const apiErrors = createApiErrors<'en' | 'fr'>({
502
+ messages: apiMessages,
503
+ unavailable: (language) => translate('app.error.unavailable', language),
504
+ refused: (language) => translate('app.error.refused', language),
505
+ isApiCode: (code) => code.startsWith('todos.errors.'),
506
+ });
507
+ ```
508
+
509
+ `fieldErrors` gives a form its messages by input path:
510
+
511
+ ```ts
512
+ import { data } from 'react-router';
513
+ import { isApiErrorLike } from '@softistx/alxia-react-router/errors';
514
+ import { apiErrors } from './api-errors';
515
+ import type { Route } from './+types/todos';
516
+
517
+ declare function createTodo(input: unknown): Promise<void>;
518
+
519
+ export async function action({ request }: Route.ActionArgs) {
520
+ try {
521
+ await createTodo(await request.json());
522
+ return { ok: true };
523
+ } catch (error) {
524
+ const refusal = apiErrors.apiRefusal(error, 'en');
525
+ if (!refusal || !isApiErrorLike(error)) throw error;
526
+ return data(
527
+ { fieldErrors: apiErrors.fieldErrors(error, 'en') },
528
+ { status: refusal.status },
529
+ );
530
+ }
531
+ }
532
+ ```
533
+
534
+ ## Loaders and the error page
535
+
536
+ A loader that calls the API lets a refusal reach the error page. Throw
537
+ `routeError(error)`: an `ApiError` whose status is 401, 403, 404 or 503
538
+ becomes a route error response of that status, carrying the API's `code` and
539
+ `message` and the call's `requestId`; any other `ApiError` with a request id
540
+ becomes a 500 that carries only the id; anything else is returned as it is,
541
+ so `throw` it too.
542
+
543
+ ```ts
544
+ import { routeError } from '@softistx/alxia-react-router/errors';
545
+ import type { Route } from './+types/todo';
546
+
547
+ // Your own call to the API, declared here as a stub.
548
+ declare function readTodo(id: string): Promise<{ title: string }>;
549
+
550
+ export async function loader({ params }: Route.LoaderArgs) {
551
+ try {
552
+ return await readTodo(params.id);
553
+ } catch (error) {
554
+ throw routeError(error);
555
+ }
556
+ }
557
+ ```
558
+
559
+ The root's `ErrorBoundary` words the error and shows the support reference
560
+ the user can quote, `errorRequestId(error)` (`undefined` for an error that
561
+ carries none):
562
+
563
+ ```tsx
564
+ import { errorRequestId } from '@softistx/alxia-react-router/errors';
565
+ import { isRouteErrorResponse, useRouteError } from 'react-router';
566
+
567
+ export function ErrorBoundary() {
568
+ const error = useRouteError();
569
+ const requestId = errorRequestId(error);
570
+ return (
571
+ <main>
572
+ <h1>{isRouteErrorResponse(error) ? error.status : 'Oops'}</h1>
573
+ {requestId ? <p>Reference: {requestId}</p> : null}
574
+ </main>
575
+ );
576
+ }
577
+ ```
578
+
579
+ A thrown `Response` of one of those statuses with an `x-request-id` header
580
+ becomes a route error too (a bare `Response` hands the browser its body
581
+ only). `routeError(error, { statuses })` changes the routed statuses (a
582
+ `ReadonlySet<number>`). The id is read from `x-request-id` (`REQUEST_ID_HEADER`,
583
+ through `requestIdOf`), the one header name the subpath knows.
584
+
585
+ An `ApiError` has a `requestId` only if the code that called the API set it
586
+ (read `requestIdOf(response)` and keep it on the error); see
587
+ [the error page shows no request id](../troubleshooting.md#the-error-page-shows-no-request-id).
588
+
589
+ ## Actions
590
+
591
+ An action that calls the API answers a refusal as data, so the page stays
592
+ where it was. `apiErrors` (from [wording a refusal](#wording-a-refusal)) has
593
+ two helpers; each throws, through `routeError`, what the page cannot word (a
594
+ 401, which the session code redirects first, or any failure that is not an
595
+ API refusal), for the error page.
596
+
597
+ `fetcherResult(language, about, run)` is for a fetcher's action: `{ ok: true }`
598
+ with `about` and the value `run` resolved, or `{ ok: false, error }` with
599
+ `about` and the worded message, answered with the refusal's HTTP status. An
600
+ unreachable API (a 503 `Response`) is worded too.
601
+
602
+ A module that words one of its API errors its own way passes `reword` as the
603
+ last argument: it receives the caught API error (an `ApiErrorLike`) and returns
604
+ the message to answer, or `undefined` to keep the worded one. The status stays
605
+ the refusal's. `reword` is called for the API's own refusals only: not for an
606
+ unreachable API or another failure, and not for what goes to the error page.
607
+
608
+ ```ts
609
+ import { apiErrors } from './api-errors';
610
+
611
+ // Your own call to the API, declared here as a stub.
612
+ declare function renameTodo(input: unknown): Promise<{ title: string }>;
613
+
614
+ export const rename = (input: unknown) =>
615
+ apiErrors.fetcherResult('en', { intent: 'rename' }, () => renameTodo(input), {
616
+ reword: (error) =>
617
+ error.code === 'todos.errors.title-taken'
618
+ ? 'Pick another title.'
619
+ : undefined,
620
+ });
621
+ ```
622
+
623
+ ```ts
624
+ import { apiErrors } from './api-errors';
625
+ import type { Route } from './+types/todos';
626
+
627
+ // Your own call to the API, declared here as a stub.
628
+ declare function renameTodo(input: unknown): Promise<{ title: string }>;
629
+
630
+ export async function action({ request }: Route.ActionArgs) {
631
+ const input = await request.json();
632
+ return apiErrors.fetcherResult('en', { intent: 'rename' }, () =>
633
+ renameTodo(input),
634
+ );
635
+ }
636
+ ```
637
+
638
+ `submitForm(language, run, fieldOf)` is for a form: `{ ok: true, value }`, or
639
+ the form's `FormErrors` with the refusal's status. `fieldOf` names the form
640
+ field of an input path (`undefined` when the form does not show it): a
641
+ placed field's message goes under that field (`fieldErrors`), and any other
642
+ message, with the API's own for the code, joins the `formError`. A 404 that
643
+ names none of the form's fields (the record itself is gone) goes to the error
644
+ page.
645
+
646
+ ```ts
647
+ import { apiErrors } from './api-errors';
648
+ import type { Route } from './+types/todos';
649
+
650
+ // Your own call to the API, declared here as a stub.
651
+ declare function createTodo(input: unknown): Promise<{ id: string }>;
652
+
653
+ export async function action({ request }: Route.ActionArgs) {
654
+ const input = await request.json();
655
+ return apiErrors.submitForm(
656
+ 'en',
657
+ () => createTodo(input),
658
+ (path) => (path === 'todo.title' ? 'title' : undefined),
659
+ );
660
+ }
661
+ ```
662
+
663
+ `fetcherRefusal(error, language)` is the refusal both build on, for an action
664
+ of your own: it returns `apiRefusal`'s `{ message, status }`, or throws what
665
+ the page cannot word.
666
+
667
+ ```ts
668
+ import { apiErrors } from './api-errors';
669
+ import type { Route } from './+types/todos';
670
+
671
+ // Your own call to the API, declared here as a stub.
672
+ declare function archiveTodo(id: string): Promise<{ archivedAt: string }>;
673
+
674
+ export async function action({ request }: Route.ActionArgs) {
675
+ const { id } = await request.json();
676
+ try {
677
+ return { ok: true as const, ...(await archiveTodo(id)) };
678
+ } catch (error) {
679
+ // The API's refusal: { message, status }. A 401 or any other failure throws.
680
+ const { message, status } = apiErrors.fetcherRefusal(error, 'en');
681
+ return Response.json({ ok: false, error: message }, { status });
682
+ }
683
+ }
684
+ ```
685
+
686
+ `apiErrors.formRefusal(error, language, fieldOf)` is `fetcherRefusal` for a dialog that
687
+ posts through a fetcher and shows field errors: it answers `{ error,
688
+ fieldErrors, status }`, each refused field under the form field `fieldOf`
689
+ names for its input path. `error` is empty when every field message found its
690
+ field; otherwise it is the refusal's message followed by the messages of the
691
+ issues that map to no field (the `formError` of `submitForm`), and it is the
692
+ refusal's message alone for a refusal that names no field or an API it cannot
693
+ reach.
694
+ On the page, `useFormRefusal(fetcher.data)` (from `@softistx/alxia-react-router/fetcher`) returns the `FormErrors` of the
695
+ last answer, or `undefined` for no answer, a done step or a refusal without
696
+ `fieldErrors`.
697
+
698
+ ```tsx
699
+ import { useFetcher } from 'react-router';
700
+ import { useFormRefusal } from '@softistx/alxia-react-router/fetcher';
701
+ import { apiErrors } from './api-errors';
702
+ import type { Route } from './+types/items';
703
+
704
+ // Your own call to the API, declared here as a stub.
705
+ declare function saveItem(input: unknown): Promise<void>;
706
+
707
+ export async function action({ request }: Route.ActionArgs) {
708
+ try {
709
+ await saveItem(Object.fromEntries(await request.formData()));
710
+ return { ok: true as const };
711
+ } catch (error) {
712
+ // 'input.name' is the form's 'name' field; other paths stay in `error`.
713
+ return apiErrors.formRefusal(error, 'en', (path) =>
714
+ path.startsWith('input.') ? path.slice('input.'.length) : undefined,
715
+ );
716
+ }
717
+ }
718
+
719
+ export function ItemDialog() {
720
+ const fetcher = useFetcher<typeof action>();
721
+ const errors = useFormRefusal(fetcher.data);
722
+ return (
723
+ <fetcher.Form method="post">
724
+ <input name="name" aria-invalid={Boolean(errors?.fieldErrors?.['name'])} />
725
+ {errors?.fieldErrors?.['name']}
726
+ {errors?.formError}
727
+ </fetcher.Form>
728
+ );
729
+ }
730
+ ```
731
+
732
+ The helpers route with `routeError`'s defaults (401, 403, 404 and 503). Each
733
+ takes an optional last argument, `route?: RouteErrorOptions`, passed to
734
+ `routeError` for what it throws: `apiErrors.fetcherRefusal(error, 'en', {
735
+ statuses })`, `fetcherResult(language, about, run, { statuses, reword })` and
736
+ `submitForm(language, run, fieldOf, { statuses })`.
737
+
738
+ ## Saving a section: `sectionAction`
739
+
740
+ The action half of `useSectionSave` (`@softistx/alxia-react-router/fetcher`, see the
741
+ [fetcher guide](fetcher.md#saving-a-section-or-a-row-in-place-usesectionsave-userowsave)).
742
+ `sectionAction(errors, language, intent, run, { fieldOf, isStale })` runs one
743
+ section's write and answers `{ ok: true, intent }`, or, through `data()`, the
744
+ refusal `{ ok: false, intent, stale, error, fieldErrors }` with the refusal's
745
+ status (`formRefusal` words it). A 401 and any failure that is not the API's
746
+ refusal are thrown for the error page. Both callbacks are the app's:
747
+ `fieldOf` names the form field of an input path (as in `formRefusal`) and
748
+ `isStale` says whether the failure is the API's version conflict, so the
749
+ package knows no error class or code.
750
+
751
+ ```ts
752
+ import { sectionAction } from '@softistx/alxia-react-router/errors';
753
+
754
+ export async function action({ request }: Route.ActionArgs) {
755
+ const { intent, ...input } = (await jsonActions().readJson(request)) as {
756
+ intent: string;
757
+ };
758
+ return sectionAction(
759
+ apiErrors,
760
+ 'en',
761
+ intent,
762
+ () => api.updateItem(input),
763
+ {
764
+ fieldOf: (path) =>
765
+ path.startsWith('input.') ? path.slice('input.'.length) : undefined,
766
+ isStale: (error) =>
767
+ isApiErrorLike(error) &&
768
+ error.errors.some((entry) => entry.extensions?.code?.endsWith('.stale-version')),
769
+ },
770
+ );
771
+ }
772
+ ```
773
+
774
+ `SectionResult` is the answer's type, for a client that reads it itself.
775
+
776
+ ## JSON actions and CSRF
777
+
778
+ Every action of the examples above reads JSON. That is a choice: a page of
779
+ another site can post a form, or `text/plain`, to your URL without a
780
+ preflight, and the browser sends the user's cookies with it. Taking
781
+ `application/json` alone, and only from this site, stops that before the
782
+ session cookie's `SameSite` is even consulted. `jsonActions` holds the three
783
+ helpers that do it.
784
+
785
+ ```ts
786
+ // app/json.ts
787
+ import { jsonActions } from '@softistx/alxia-react-router/errors';
788
+
789
+ export const { readJson, requireJsonPost, readInput } = jsonActions();
790
+ ```
791
+
792
+ `readJson(request)` answers the parsed body, or throws a response: 403
793
+ `Cross-site request refused` when the `Origin` is not this site's, or the
794
+ `Sec-Fetch-Site` is neither `same-origin` nor `none`; 415 `Expected a JSON body`
795
+ when the content type is not `application/json`; 400 `Malformed JSON body`
796
+ when the body does not parse.
797
+
798
+ ```ts
799
+ import { readJson } from './json';
800
+ import type { Route } from './+types/todos';
801
+
802
+ export async function action({ request }: Route.ActionArgs) {
803
+ const body = (await readJson(request)) as { title?: string };
804
+ // …
805
+ }
806
+ ```
807
+
808
+ The body is limited only by the server's `maxRequestBodySize` (Bun's default
809
+ is 128 MB), so an app should set it to what its largest form needs.
810
+
811
+ `readInput(request, schema)` reads the body's `input` and checks it against
812
+ a [Standard Schema](https://standardschema.dev) (Zod 4, Valibot, ArkType,
813
+ or one of your own), awaiting the check when it is async. It answers the
814
+ schema's output, typed, or throws a 400 `The form sent an input the API would
815
+ refuse`. It checks the origin the same way, since it reads through `readJson`.
816
+
817
+ ```ts
818
+ import { z } from 'zod';
819
+ import { apiErrors } from './api-errors';
820
+ import { readInput } from './json';
821
+ import type { Route } from './+types/todos';
822
+
823
+ const createTodo = z.object({ title: z.string().min(1) });
824
+
825
+ // Your own call to the API, declared here as a stub.
826
+ declare function create(input: { title: string }): Promise<{ id: string }>;
827
+
828
+ export async function action({ request }: Route.ActionArgs) {
829
+ const input = await readInput(request, createTodo);
830
+ return apiErrors.submitForm(
831
+ 'en',
832
+ () => create(input),
833
+ (path) => (path === 'title' ? 'title' : undefined),
834
+ );
835
+ }
836
+ ```
837
+
838
+ The Standard Schema types are declared in `/errors` itself (a few lines,
839
+ the specification's own interface), so the subpath never imports
840
+ `@softistx/alxia`, not even a type. `@softistx/alxia`'s `StandardSchemaV1`, and every
841
+ vendor's schema, fit them as they are.
842
+
843
+ `requireJsonPost(request)` is for an action that a native form also posts to:
844
+ before the page hydrates, a click posts the form natively, and `readJson`
845
+ would answer 415. `requireJsonPost` sends that post back to its page, its
846
+ search kept (`nextOf`), which then posts JSON once hydrated.
847
+
848
+ ```ts
849
+ export async function action({ request }: Route.ActionArgs) {
850
+ requireJsonPost(request);
851
+ const body = await readJson(request);
852
+ // …
853
+ }
854
+ ```
855
+
856
+ ### The same-site guard for a native form post
857
+
858
+ `readJson` refuses another site, but only for a JSON body. A page whose forms
859
+ still post natively (a `<form method="post">` handled by `request.formData()`)
860
+ needs the same refusal without the JSON requirement: `requireSameSite`.
861
+
862
+ ```ts
863
+ import { requireSameSite } from '@softistx/alxia-react-router/errors';
864
+ import type { Route } from './+types/account';
865
+
866
+ export async function action({ request }: Route.ActionArgs) {
867
+ requireSameSite(request); // 403 before the body is read
868
+ const form = await request.formData();
869
+ // …
870
+ }
871
+ ```
872
+
873
+ It throws the 403 `Cross-site request refused` of `readJson` for `Origin:
874
+ null` (a sandboxed or redirected context), an `Origin` that is not this
875
+ site's, and a `Sec-Fetch-Site` of `cross-site` or `same-site`. It reads
876
+ headers only, so the body is still there to read. A request with neither
877
+ `Origin` nor `Sec-Fetch-Site` goes on, as it does for `readJson`: a browser
878
+ sends at least one of them on a POST, and what sends neither is not a
879
+ browser carrying the user's cookies.
880
+
881
+ The reference origin is the request's own, so a host that serves several
882
+ tenants on several hostnames needs no setting. Behind a TLS-terminating
883
+ proxy (see [the origin behind a proxy](#the-origin-behind-a-proxy)), pass the public one, or the `jsonActions()` instance you already have:
884
+
885
+ ```ts
886
+ requireSameSite(request, { origin: () => process.env.APP_ORIGIN });
887
+ requireSameSite(request, json); // the origin of jsonActions({ origin })
888
+ ```
889
+
890
+ ### The origin behind a proxy
891
+
892
+ A request is "this site" when its `Origin` is the origin of `request.url`.
893
+ Behind a proxy that terminates TLS that origin is the internal one, so give
894
+ `jsonActions` the public one. A getter is read at each request, and when it
895
+ answers `undefined` the request's own origin is used:
896
+
897
+ ```ts
898
+ export const { readJson, requireJsonPost, readInput } = jsonActions({
899
+ origin: () => process.env.APP_ORIGIN,
900
+ });
901
+ ```
902
+
903
+ Without it, every post is refused: see
904
+ [Behind a TLS proxy every action answers 403](../troubleshooting.md#behind-a-tls-proxy-every-action-answers-403).
905
+
906
+ ### Posting from the page
907
+
908
+ `useJsonFetcher<Action, Body>(key?, action?)` is a React Router fetcher that
909
+ posts its body as JSON to the page's action (or to the `action` it is given):
910
+ `post(body, to?)` sends it, `busy` is true while it is in flight, and
911
+ `fetcher` is the fetcher, whose `data` is what the action answered. `key`
912
+ shares the fetcher between the component that posts and the one that reads
913
+ the answer. `post`'s second argument is the action of one call, for a list
914
+ whose rows each post to their own record.
915
+
916
+ ```tsx
917
+ import { useJsonFetcher } from '@softistx/alxia-react-router/errors';
918
+ import type { action } from './todos';
919
+
920
+ export function RenameTodo({ id }: { id: string }) {
921
+ const { fetcher, post, busy } = useJsonFetcher<typeof action>();
922
+ return (
923
+ <>
924
+ <button
925
+ type="button"
926
+ disabled={busy}
927
+ onClick={() => post({ input: { title: 'Done' } }, `/todos/${id}`)}
928
+ >
929
+ Rename
930
+ </button>
931
+ {fetcher.data && !fetcher.data.ok ? <p>{fetcher.data.error}</p> : null}
932
+ </>
933
+ );
934
+ }
935
+ ```
936
+
937
+ The action answers `{ ok, error }`, the shape of `fetcherResult` and `submitForm`, so `fetcher.data` is read as above.
938
+
939
+ `Body` types what `post` takes: `useJsonFetcher<typeof action, { input: { title: string } }>()`.
940
+ The hook imports `react-router` alone, so a page can import it from `/errors`.
941
+
942
+ ## Calling the API from a loader
943
+
944
+ The subpath does not send the call: the headers, the caller and the API's
945
+ address are the app's. It holds what happens once a call failed.
946
+ `apiCallFailure(error, options)` returns what the loader or action should
947
+ throw, and logs it:
948
+
949
+ | the call failed with | `apiCallFailure` returns | log |
950
+ | --- | --- | --- |
951
+ | an `ApiError` (the API refused) | the same error, with `requestId` set when you pass one | a warning for a 4xx, an error for a 5xx, with the status and the API's code |
952
+ | an `ApiStatusError` of 401, 403 or 404 (no GraphQL body) | a `Response` of that status and reason phrase, with an `x-request-id` header | a warning |
953
+ | an `ApiStatusError` of another status | a 503 `Response` with no body | an error |
954
+ | an `ApiUnavailableError` (`unreachable`, `timeout`, `invalid-response`) | a 503 `Response` with no body | an error with the reason |
955
+ | anything else, once `signal` is aborted | a 503 `Response` with no body | an error: `aborted` |
956
+ | anything else | the same error | none |
957
+
958
+ It recognises the client's errors by their `name`, never with `instanceof`, so
959
+ it imports nothing from `@nxgt/graphql-client` and holds across two copies of
960
+ it. Pass `requestId` from the response (`requestIdOf(response)`), and the id
961
+ rides on the `ApiError` and on the `Response`, where `routeError` reads it.
962
+ `passedThrough` replaces the statuses that keep their own (401, 403 and 404),
963
+ and `log` replaces `console`. A `passedThrough` status that cannot carry a
964
+ body (204 and the like) is answered with an empty body. The log lines start
965
+ with the `api` name you pass (`<api>: <operation> …`), not
966
+ `alxia-react-router:`, because they describe your app's call, not a package
967
+ diagnostic. Nothing logged holds a header, a variable or a token. A `log` that
968
+ throws never replaces the outcome: the error or `Response` is returned as if
969
+ the line had been written.
970
+
971
+ An app writes one `execute` that sends the call and ends in `apiCallFailure`.
972
+ The example uses `@nxgt/graphql-client`; `operationName` reads a document
973
+ structurally, so `graphql` is not imported by the subpath.
974
+
975
+ ```ts
976
+ import { createGraphQLClient } from '@nxgt/graphql-client';
977
+ import {
978
+ apiCallFailure,
979
+ operationName,
980
+ requestIdOf,
981
+ routeError,
982
+ } from '@softistx/alxia-react-router/errors';
983
+ import type { DocumentNode } from 'graphql';
984
+
985
+ const url = 'https://api.example.com/graphql';
986
+
987
+ export async function execute(
988
+ document: DocumentNode,
989
+ variables: Record<string, unknown>,
990
+ caller: { language: string; token?: string; signal?: AbortSignal },
991
+ ) {
992
+ let requestId: string | undefined;
993
+ const client = createGraphQLClient({
994
+ url,
995
+ dedupe: false,
996
+ fetch: async (request: Request) => {
997
+ const response = await fetch(request);
998
+ requestId = requestIdOf(response); // the client hands none back
999
+ return response;
1000
+ },
1001
+ });
1002
+ try {
1003
+ return await client.execute(document as never, variables as never, {
1004
+ signal: caller.signal,
1005
+ headers: { 'accept-language': caller.language },
1006
+ timeout: 10_000,
1007
+ });
1008
+ } catch (error) {
1009
+ throw apiCallFailure(error, {
1010
+ api: `my-api ${url}`,
1011
+ operation: operationName(document),
1012
+ requestId,
1013
+ signal: caller.signal,
1014
+ });
1015
+ }
1016
+ }
1017
+
1018
+ // A loader: throw routeError(error) for what execute() threw.
1019
+ export async function loader() {
1020
+ try {
1021
+ return await execute(todosQuery, {}, { language: 'en' });
1022
+ } catch (error) {
1023
+ throw routeError(error);
1024
+ }
1025
+ }
1026
+
1027
+ declare const todosQuery: DocumentNode;
1028
+ ```
1029
+
1030
+ Each log line is in the troubleshooting page:
1031
+ [answered 403](../troubleshooting.md#api-operation-request-id-answered-status-code),
1032
+ [answered 502 without GraphQL](../troubleshooting.md#api-operation-request-id-answered-status-without-graphql),
1033
+ [unreachable, timeout, invalid-response](../troubleshooting.md#api-operation-request-id-unreachable-timeout-or-invalid-response)
1034
+ and [aborted](../troubleshooting.md#api-operation-request-id-aborted).
1035
+
1036
+ ## Keeping the catalogue fresh
1037
+
1038
+ The store of [the catalogue](#the-catalogue-store) is empty until something
1039
+ fills it. On the server, `createErrorCatalogue` does: it reads each
1040
+ language's messages from the API on first use, serves them from memory, and
1041
+ checks the API's versions once per TTL, re-reading only the languages whose
1042
+ version moved. It is an instance, made once in a module of the app's own, and
1043
+ it imports nothing: the app's two calls to its API are options.
1044
+
1045
+ ```ts
1046
+ // app/catalogue.server.ts
1047
+ import { createErrorCatalogue } from '@softistx/alxia-react-router/errors';
1048
+ import { apiMessages } from './api-messages';
1049
+ import { api } from './api.server';
1050
+
1051
+ export const catalogue = createErrorCatalogue<'en' | 'fr'>({
1052
+ messages: apiMessages,
1053
+ languages: ['en', 'fr'],
1054
+ // { version, messages: [{ code, message, params }] }
1055
+ read: (language) => api.errorCatalogue(language),
1056
+ // { en: 'v7', fr: 'v7' }: one call for every language
1057
+ versions: () => api.errorCatalogueVersions(),
1058
+ ttlMs: () => Number(process.env.CATALOGUE_TTL_MS ?? 60_000),
1059
+ // The codes the browser words itself, such as a form's checks.
1060
+ clientCodes: ['validation.errors.required', 'todos.errors.title-taken'],
1061
+ });
1062
+ ```
1063
+
1064
+ `ttlMs` has no default and must be given: a number, or a getter read at each
1065
+ check, so a value set at startup or changed by a test is found. A getter that
1066
+ throws, or a value that is not a finite number of at least 0, is logged and
1067
+ `retryMs` is used in its place (see
1068
+ [`ttlMs is not a duration`](../troubleshooting.md#alxia-react-router-ttlms-is-not-a-duration-using-retryms)). `retryMs` (5000 by default) is how soon a
1069
+ failed read or check is tried again, and `firstReadWaitMs` (1500 by default)
1070
+ is how long a request waits for a language's first read. `log` receives the
1071
+ failures (`console` by default); its lines start with `alxia-react-router:`.
1072
+ `languages` may not be empty: it throws a `TypeError` otherwise.
1073
+
1074
+ ### Awaiting it in the root's middleware
1075
+
1076
+ `freshAll()` makes every language ready before a loader or an action words a
1077
+ refusal. It waits only for a language with no catalogue yet, and only up to
1078
+ `firstReadWaitMs`; a held catalogue is served at once, and an old one is
1079
+ checked in the background, so a request never waits for a check.
1080
+
1081
+ ```ts
1082
+ // app/root.tsx
1083
+ import { catalogue } from './catalogue.server';
1084
+
1085
+ export const middleware = [
1086
+ async (_args: unknown, next: () => Promise<unknown>) => {
1087
+ await catalogue.freshAll();
1088
+ return next();
1089
+ },
1090
+ ];
1091
+ ```
1092
+
1093
+ A language whose first read is slow or failed is not waited for twice: the
1094
+ wait is counted from when the read started, one read is in flight however many
1095
+ requests ask, and a failure is retried after `retryMs`. Meanwhile the refusals
1096
+ of that language read in the API's words: see
1097
+ [Right after start](../troubleshooting.md#right-after-start-refusals-read-in-the-apis-words).
1098
+
1099
+ ### Returning the browser's messages from the root's loader
1100
+
1101
+ The browser words a form's checks itself, so it needs the messages of the
1102
+ `clientCodes`. `clientMessages()` returns them by language, leaving out a code
1103
+ the catalogue does not hold; `ApiMessagesProvider` adds them to the browser's
1104
+ store.
1105
+
1106
+ ```tsx
1107
+ // app/root.tsx
1108
+ import { catalogue } from './catalogue.server';
1109
+
1110
+ export function loader() {
1111
+ return { catalogue: catalogue.clientMessages() };
1112
+ }
1113
+
1114
+ // In the component:
1115
+ // <ApiMessagesProvider messages={apiMessages} value={data.catalogue}>
1116
+ ```
1117
+
1118
+ ### Warming it at startup
1119
+
1120
+ `warm()` reads every language without holding the boot back, so the first
1121
+ request finds the messages held. It never throws: a failure is logged.
1122
+
1123
+ ```ts
1124
+ // app/server.ts
1125
+ import { createServer } from '@softistx/alxia-react-router';
1126
+ import { catalogue } from './catalogue.server';
1127
+
1128
+ catalogue.warm();
1129
+
1130
+ export default createServer();
1131
+ ```
1132
+
1133
+ ### In a spec
1134
+
1135
+ `fresh(language, now)` and `freshAll(now)` take the time as an argument, in
1136
+ milliseconds, so a spec moves the clock instead of sleeping: a call at
1137
+ `now = ttl` starts the check, `settled()` waits for it, and `heldVersion`
1138
+ says which version is held. `reset()`, `settled()`, `heldVersion()`, the `now`
1139
+ parameters and the store's `clear()` are for tests. `reset()` forgets what is held and empties the
1140
+ store. It is for use between tests, with nothing in flight: a read or check
1141
+ still running when it is called finishes and holds its result again.
1142
+
1143
+ ```ts
1144
+ await catalogue.fresh('en', 0);
1145
+ await catalogue.fresh('en', 60_000); // past the TTL: checks in the background
1146
+ await catalogue.settled();
1147
+ ```