@softistx/alxia-react-router 0.0.0-stage → 0.83.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 (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,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/session/model/link-post.ts", "../src/session/model/site-path.ts", "../src/session/model/paths.ts", "../src/session/model/second-factor.ts"],
4
+ "sourcesContent": [
5
+ "/** The refusal a promise-based auth form takes back: `form`, a wait, a field's word. */\nexport type LinkPostRefusal<F extends string = string> = {\n\tform?: string | undefined;\n\tretryAfter?: number | undefined;\n} & { [K in F]?: string | undefined };\n\n/** The request header that asks a link route for its redirects as data; `postLinkArgs` sends it. */\nexport const LINK_JSON_HEADER = 'x-alxia-link';\n\nexport interface LinkPostOptions {\n\t/** The `fetch` to use; the global one by default. */\n\treadonly fetch?: typeof fetch | undefined;\n\t/**\n\t * Where a `{ redirect }` answer leads; `location.assign`, or\n\t * `location.replace` when the answer says `replace` (the token page's\n\t * entry must not stay in the history), by default.\n\t */\n\treadonly navigate?:\n\t\t| ((location: string, how: { readonly replace: boolean }) => void)\n\t\t| undefined;\n\t/** The form's message for a failed call or an answer with no shape; English by default. */\n\treadonly unreachable?: string | undefined;\n}\n\nconst text = (value: unknown): string | undefined =>\n\ttypeof value === 'string' ? value : undefined;\n\nconst UNREACHABLE = 'Something went wrong. Try again.';\n\n/**\n * Posts `body` as JSON to a link route (whose action runs through\n * `handingOver`) and maps the answer to a promise form's refusal:\n * `undefined` when it is accepted (`sent`, or a `{ redirect }` it follows),\n * else `{ form, retryAfter, ...fields }`, `fields` naming the `fieldErrors`\n * to carry over. A network failure or an answer with no shape is the form's\n * message, never a success.\n */\nexport async function postLinkArgs<const F extends string>(\n\tpath: string,\n\tbody: unknown,\n\tfields: readonly F[],\n\toptions: LinkPostOptions = {},\n): Promise<LinkPostRefusal<F> | undefined> {\n\tconst send = options.fetch ?? fetch;\n\tconst unreachable = options.unreachable ?? UNREACHABLE;\n\tlet answer: Record<string, unknown> | undefined;\n\tlet ok = false;\n\ttry {\n\t\tconst response = await send(path, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'content-type': 'application/json',\n\t\t\t\t[LINK_JSON_HEADER]: 'json',\n\t\t\t},\n\t\t\tbody: JSON.stringify(body),\n\t\t\tcredentials: 'same-origin',\n\t\t});\n\t\tok = response.ok;\n\t\tconst parsed: unknown = await response.json().catch(() => undefined);\n\t\tif (parsed && typeof parsed === 'object') {\n\t\t\tanswer = parsed as Record<string, unknown>;\n\t\t}\n\t} catch {\n\t\treturn { form: unreachable } as LinkPostRefusal<F>;\n\t}\n\tconst redirect = text(answer?.['redirect']);\n\tif (ok && redirect !== undefined) {\n\t\tconst replace = answer?.['replace'] === true;\n\t\t(\n\t\t\toptions.navigate ??\n\t\t\t((to, how) =>\n\t\t\t\thow.replace\n\t\t\t\t\t? globalThis.location.replace(to)\n\t\t\t\t\t: globalThis.location.assign(to))\n\t\t)(redirect, { replace });\n\t\treturn undefined;\n\t}\n\tif (ok && answer?.['sent'] === true) return undefined;\n\tconst refusal: Record<string, string | number | undefined> = {\n\t\tform: text(answer?.['formError']),\n\t\tretryAfter:\n\t\t\ttypeof answer?.['retryAfter'] === 'number'\n\t\t\t\t? answer['retryAfter']\n\t\t\t\t: undefined,\n\t};\n\tconst errors = answer?.['fieldErrors'];\n\tif (errors && typeof errors === 'object') {\n\t\tfor (const field of fields) {\n\t\t\trefusal[field] = text((errors as Record<string, unknown>)[field]);\n\t\t}\n\t}\n\tif (refusal['form'] === undefined && !fields.some((f) => refusal[f])) {\n\t\trefusal['form'] = unreachable;\n\t}\n\treturn refusal as LinkPostRefusal<F>;\n}\n\n/** Requests a mail's link: posts `{ input: { email } }`; see {@link postLinkArgs}. */\nexport const postLinkRequest = (\n\tpath: string,\n\temail: string,\n\toptions?: LinkPostOptions,\n) => postLinkArgs(path, { input: { email } }, ['email'], options);\n",
6
+ "import { safeNext } from './safe-next';\n\n/**\n * A path of this site, or a `TypeError` naming `label`. With no `query`, the\n * path holds no `?` or `#` either, and the message prints it only up to\n * there, since what follows may be a token.\n */\nexport function sitePath(\n\tpath: string,\n\t{\n\t\tlabel,\n\t\tquery = false,\n\t}: { readonly label: string; readonly query?: boolean | undefined },\n): string {\n\tif (safeNext(path) !== path || (!query && /[?#]/.test(path))) {\n\t\tconst shown = query ? path : path.replace(/[?#].*$/s, '?…');\n\t\tthrow new TypeError(\n\t\t\t`${label} must be a path of this site${query ? '' : ' with no query or fragment'}, starting with a single \"/\"; got ${JSON.stringify(shown)}.`,\n\t\t);\n\t}\n\treturn path;\n}\n",
7
+ "import { HOME, safeNext } from './safe-next';\nimport { sitePath } from './site-path';\n\n/** The two pages of a sign-in. */\nexport interface SignInPaths {\n\treadonly signIn: string;\n\treadonly secondFactor: string;\n}\n\n/** The defaults: `/sign-in` and `/sign-in/second-factor`. */\nexport const SIGN_IN_PATHS: SignInPaths = {\n\tsignIn: '/sign-in',\n\tsecondFactor: '/sign-in/second-factor',\n};\n\nfunction withNext(\n\tpath: string,\n\tnext: string,\n\tquery?: Record<string, string>,\n): string {\n\tconst params = new URLSearchParams(query);\n\tconst target = safeNext(next);\n\tif (target !== HOME) params.set('next', target);\n\tconst search = params.toString();\n\treturn search ? `${path}?${search}` : path;\n}\n\n/**\n * The sign-in page's URL, coming back to `next` (none for the home page, and\n * `next` goes through `safeNext`). `query` adds parameters, such as\n * `{ expired: '1' }`; `path` replaces `/sign-in` and must be a path of this\n * site with no query or fragment (a `TypeError` otherwise).\n *\n * @example\n * signInPath('/orders'); // '/sign-in?next=%2Forders'\n * signInPath('/', { query: { expired: '1' } }); // '/sign-in?expired=1'\n */\nexport function signInPath(\n\tnext: string,\n\toptions: {\n\t\treadonly query?: Record<string, string> | undefined;\n\t\treadonly path?: string | undefined;\n\t} = {},\n): string {\n\tconst path =\n\t\toptions.path === undefined\n\t\t\t? SIGN_IN_PATHS.signIn\n\t\t\t: sitePath(options.path, { label: 'signInPath(): options.path' });\n\treturn withNext(path, next, options.query);\n}\n\n/** The second-factor page's URL, coming back to `next` as `signInPath` does. */\nexport function secondFactorPath(\n\tnext: string,\n\tpath: string = SIGN_IN_PATHS.secondFactor,\n): string {\n\treturn withNext(path, next);\n}\n",
8
+ "/** A code of an authenticator app: six digits. */\nexport const TOTP_CODE: RegExp = /^\\d{6}$/;\n\n/**\n * What a second-factor form sends: `code` is the issued code (an app's, or\n * the one mailed), `recovery` a recovery code. Janus has no name for it, only\n * `confirm` and `recover`.\n */\nexport type SecondFactorKind = 'code' | 'recovery';\n\n/** How a sign-in ended, in `@softistx/janus`'s words (`SignInResult['status']`). */\nexport type SignInStatus = 'signedIn' | 'secondFactor';\n\n/**\n * How a step-up is confirmed, in `@softistx/janus`'s words: a code mailed to the\n * current address, or the account's second factor.\n */\nexport type StepUpVia = 'email' | 'secondFactor';\n"
9
+ ],
10
+ "mappings": ";;;;;;AAOO,IAAM,oBAAmB;AAiBhC,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,WAAW,QAAQ;AAErC,IAAM,cAAc;AAUb,eAAe,aAAoC,CACzD,MACA,MACA,QACA,UAA2B,CAAC,GACc;AAAA,EAC1C,MAAM,OAAO,QAAQ,SAAS;AAAA,EAC9B,MAAM,cAAc,QAAQ,eAAe;AAAA,EAC3C,IAAI;AAAA,EACJ,IAAI,KAAK;AAAA,EACT,IAAI;AAAA,IACH,MAAM,WAAW,MAAM,KAAK,MAAM;AAAA,MACjC,QAAQ;AAAA,MACR,SAAS;AAAA,QACR,gBAAgB;AAAA,SACf,oBAAmB;AAAA,MACrB;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,MACzB,aAAa;AAAA,IACd,CAAC;AAAA,IACD,KAAK,SAAS;AAAA,IACd,MAAM,SAAkB,MAAM,SAAS,KAAK,EAAE,MAAM,MAAG;AAAA,MAAG;AAAA,KAAS;AAAA,IACnE,IAAI,UAAU,OAAO,WAAW,UAAU;AAAA,MACzC,SAAS;AAAA,IACV;AAAA,IACC,MAAM;AAAA,IACP,OAAO,EAAE,MAAM,YAAY;AAAA;AAAA,EAE5B,MAAM,WAAW,KAAK,SAAS,WAAW;AAAA,EAC1C,IAAI,MAAM,aAAa,WAAW;AAAA,IACjC,MAAM,UAAU,SAAS,eAAe;AAAA,KAEvC,QAAQ,aACP,CAAC,IAAI,QACL,IAAI,UACD,WAAW,SAAS,QAAQ,EAAE,IAC9B,WAAW,SAAS,OAAO,EAAE,IAChC,UAAU,EAAE,QAAQ,CAAC;AAAA,IACvB;AA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AS;AAAA,EAC/B,OAAO,SAAS,GAAG,QAAQ,WAAW;AAAA;AAahC,SAAS,WAAU,CACzB,MACA,UAGI,CAAC,GACI;AAAA,EACT,MAAM,OACL,QAAQ,SAAS,YACd,eAAc,SACd,SAAS,QAAQ,MAAM,EAAE,OAAO,6BAA6B,CAAC;AAAA,EAClE,OAAO,SAAS,MAAM,MAAM,QAAQ,KAAK;AAAA;AAInC,SAAS,iBAAgB,CAC/B,MACA,OAAe,eAAc,cACpB;AAAA,EACT,OAAO,SAAS,MAAM,IAAI;AAAA;;ACvDpB,IAAM,aAAoB;",
11
+ "debugId": "E3526C4DF7133D6B64756E2164756E21",
12
+ "names": []
13
+ }
@@ -0,0 +1,19 @@
1
+ // src/errors/route-refusal.ts
2
+ function isRouteRefusal2(value) {
3
+ if (value instanceof Response)
4
+ return true;
5
+ if (typeof value !== "object" || value === null)
6
+ return false;
7
+ const v = value;
8
+ return v.type === "DataWithResponseInit" && typeof v.init?.status === "number";
9
+ }
10
+ function routeRefusalStatus2(value) {
11
+ if (!isRouteRefusal2(value))
12
+ return;
13
+ return value instanceof Response ? value.status : value.init.status;
14
+ }
15
+
16
+ export { isRouteRefusal2, routeRefusalStatus2 };
17
+
18
+ //# debugId=EA496CBC8425EABD64756E2164756E21
19
+ //# sourceMappingURL=index-thyabr5n.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors/route-refusal.ts"],
4
+ "sourcesContent": [
5
+ "/** A React Router `data(body, { status })` value, as a route throws it. */\nexport type DataRefusal = {\n\ttype: 'DataWithResponseInit';\n\tdata: unknown;\n\tinit: { status: number };\n};\n\n/** What `isRouteRefusal` narrows to: a thrown `data()` with a status, or a thrown `Response`. */\nexport type RouteRefusal = DataRefusal | Response;\n\n/**\n * Whether a caught value is a route refusal: a React Router `data(body, {\n * status })` value (what `oauthConsent`'s action throws) or a thrown\n * `Response`. Read its status with `routeRefusalStatus`. A plain `Error`, a\n * non-object, or a `data()` with no status is not one.\n */\nexport function isRouteRefusal(value: unknown): value is RouteRefusal {\n\tif (value instanceof Response) return true;\n\tif (typeof value !== 'object' || value === null) return false;\n\tconst v = value as { type?: unknown; init?: { status?: unknown } | null };\n\treturn (\n\t\tv.type === 'DataWithResponseInit' && typeof v.init?.status === 'number'\n\t);\n}\n\n/** The status of a route refusal, or `undefined` for any other value. */\nexport function routeRefusalStatus(value: unknown): number | undefined {\n\tif (!isRouteRefusal(value)) return undefined;\n\treturn value instanceof Response ? value.status : value.init.status;\n}\n"
6
+ ],
7
+ "mappings": ";AAgBO,SAAS,eAAc,CAAC,OAAuC;AAAA,EACrE,IAAI,iBAAiB;AAAA,IAAU,OAAO;AAAA,EACtC,IAAI,OAAO,UAAU,YAAY,UAAU;AAAA,IAAM,OAAO;AAAA,EACxD,MAAM,IAAI;AAAA,EACV,OACC,EAAE,SAAS,0BAA0B,OAAO,EAAE,MAAM,WAAW;AAAA;AAK1D,SAAS,mBAAkB,CAAC,OAAoC;AAAA,EACtE,IAAI,CAAC,gBAAe,KAAK;AAAA,IAAG;AAAA,EAC5B,OAAO,iBAAiB,WAAW,MAAM,SAAS,MAAM,KAAK;AAAA;",
8
+ "debugId": "EA496CBC8425EABD64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,134 @@
1
+ import {
2
+ FlowFormatError2,
3
+ langOfFile,
4
+ parseFlow2,
5
+ CAPTURE_WIDTHS2,
6
+ CAPTURE_THEMES2,
7
+ captureFile2
8
+ } from "./index-skwypsjz.js";
9
+
10
+ // src/help/check/check.ts
11
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
12
+ import { join, resolve } from "node:path";
13
+ import { pathToFileURL } from "node:url";
14
+
15
+ // src/help/check/routes.ts
16
+ function routeId2(entry) {
17
+ if (entry.id)
18
+ return entry.id;
19
+ return entry.file.replace(/^\.?\//, "").replace(/\.[cm]?[jt]sx?$/, "");
20
+ }
21
+ function flattenRoutes2(entries) {
22
+ const result = [{ id: "root", screen: false, ancestors: [] }];
23
+ const walk = (list, ancestors) => {
24
+ for (const entry of list) {
25
+ const children = entry.children ?? [];
26
+ const id = routeId2(entry);
27
+ result.push({ id, screen: children.length === 0, ancestors });
28
+ walk(children, [...ancestors, id]);
29
+ }
30
+ };
31
+ walk(entries, ["root"]);
32
+ return result;
33
+ }
34
+ function matchesIgnore2(id, patterns) {
35
+ return patterns.some((pattern) => new RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`).test(id));
36
+ }
37
+
38
+ // src/help/check/check.ts
39
+ async function readRouteConfig2(file) {
40
+ const module = await import(pathToFileURL(file).href);
41
+ const config = await module.default;
42
+ if (!Array.isArray(config)) {
43
+ throw new Error(`${file}: the default export must be the route config (an array)`);
44
+ }
45
+ return config;
46
+ }
47
+ async function checkHelp2(options = {}) {
48
+ const root = resolve(options.root ?? ".");
49
+ const flowsDir = resolve(root, options.flows ?? "docs/flows");
50
+ const ignore = options.ignore ?? [];
51
+ const entries = options.config ?? await readRouteConfig2(resolve(root, options.routes ?? "app/routes.ts"));
52
+ const routes = flattenRoutes2(entries);
53
+ const known = new Set(routes.map((route) => route.id));
54
+ const problems = [];
55
+ const cited = new Set;
56
+ const files = existsSync(flowsDir) ? readdirSync(flowsDir).filter((name) => name.endsWith(".md") && langOfFile(name) !== undefined).sort() : [];
57
+ let flows = 0;
58
+ const flowIds = new Map;
59
+ for (const name of files) {
60
+ const path = join(flowsDir, name);
61
+ const shown = `${options.flows ?? "docs/flows"}/${name}`;
62
+ let flow;
63
+ try {
64
+ flow = parseFlow2(readFileSync(path, "utf8"), shown);
65
+ } catch (error) {
66
+ if (error instanceof FlowFormatError2) {
67
+ problems.push({ kind: "bad-flow", message: error.message });
68
+ continue;
69
+ }
70
+ throw error;
71
+ }
72
+ flows++;
73
+ const idKey = `${flow.lang}:${flow.id}`;
74
+ const other = flowIds.get(idKey);
75
+ if (other === undefined)
76
+ flowIds.set(idKey, shown);
77
+ else {
78
+ problems.push({
79
+ kind: "bad-flow",
80
+ message: `${shown}: flow id "${flow.id}" is already used by ${other}`
81
+ });
82
+ }
83
+ for (const id of flow.routes) {
84
+ cited.add(id);
85
+ if (!known.has(id)) {
86
+ problems.push({
87
+ kind: "unknown-route",
88
+ message: `${shown}: cites route "${id}", which is not in the route config`
89
+ });
90
+ }
91
+ }
92
+ for (const capture of flow.captures) {
93
+ for (const width of CAPTURE_WIDTHS2) {
94
+ for (const theme of CAPTURE_THEMES2) {
95
+ const file = captureFile2(capture.name, width, theme);
96
+ if (!existsSync(join(flowsDir, "captures", file))) {
97
+ problems.push({
98
+ kind: "missing-capture",
99
+ message: `${shown}: capture ${file} is missing from ${options.flows ?? "docs/flows"}/captures/`
100
+ });
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ const screens = routes.filter((route) => route.screen);
107
+ for (const screen of screens) {
108
+ const covered = cited.has(screen.id) || screen.ancestors.some((id) => cited.has(id));
109
+ if (!covered && !matchesIgnore2(screen.id, ignore)) {
110
+ problems.push({
111
+ kind: "uncovered-route",
112
+ message: `route "${screen.id}" is covered by no flow: cite it in a flow's routes, or add it to the ignore list`
113
+ });
114
+ }
115
+ }
116
+ for (const pattern of ignore) {
117
+ if (!routes.some((route) => matchesIgnore2(route.id, [pattern]))) {
118
+ problems.push({
119
+ kind: "unused-ignore",
120
+ message: `ignore "${pattern}" matches no route`
121
+ });
122
+ }
123
+ }
124
+ return {
125
+ ok: problems.length === 0,
126
+ problems,
127
+ flows,
128
+ screens: screens.length
129
+ };
130
+ }
131
+ export { routeId2, flattenRoutes2, matchesIgnore2, readRouteConfig2, checkHelp2 };
132
+
133
+ //# debugId=525272F993E242D864756E2164756E21
134
+ //# sourceMappingURL=index-tx36swjx.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/help/check/check.ts", "../src/help/check/routes.ts"],
4
+ "sourcesContent": [
5
+ "import { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { FlowFormatError, langOfFile, parseFlow } from '../parse-flow';\nimport { CAPTURE_THEMES, CAPTURE_WIDTHS, captureFile } from '../types';\nimport { flattenRoutes, matchesIgnore, type RouteEntry } from './routes';\n\nexport interface CheckHelpOptions {\n\t/** The app's root. Default: the current directory. */\n\treadonly root?: string;\n\t/** The route config file. Default: `app/routes.ts`. */\n\treadonly routes?: string;\n\t/** The flows folder. Default: `docs/flows`. */\n\treadonly flows?: string;\n\t/** Route ids (with `*`) that need no flow: resource routes, redirects. */\n\treadonly ignore?: readonly string[];\n\t/** The routes, instead of reading `routes`: a spec's or a custom loader's. */\n\treadonly config?: readonly RouteEntry[];\n}\n\nexport interface HelpProblem {\n\treadonly kind:\n\t\t| 'uncovered-route'\n\t\t| 'unknown-route'\n\t\t| 'missing-capture'\n\t\t| 'bad-flow'\n\t\t| 'unused-ignore';\n\treadonly message: string;\n}\n\nexport interface CheckHelpResult {\n\treadonly ok: boolean;\n\treadonly problems: readonly HelpProblem[];\n\treadonly flows: number;\n\treadonly screens: number;\n}\n\n/** The route config of an app: its default export, awaited. */\nexport async function readRouteConfig(\n\tfile: string,\n): Promise<readonly RouteEntry[]> {\n\tconst module = (await import(pathToFileURL(file).href)) as {\n\t\tdefault?: unknown;\n\t};\n\tconst config = await module.default;\n\tif (!Array.isArray(config)) {\n\t\tthrow new Error(\n\t\t\t`${file}: the default export must be the route config (an array)`,\n\t\t);\n\t}\n\treturn config as RouteEntry[];\n}\n\n/**\n * Checks the flows against the routes and the captures:\n * - every screen route (no children, not ignored) is cited by a flow, or sits\n * under a layout a flow cites (as `resolveHelp` does at runtime);\n * - every route a flow cites exists;\n * - every capture a flow cites has its four WebP variants;\n * - every flow file parses (the format errors are reported, not thrown).\n */\nexport async function checkHelp(\n\toptions: CheckHelpOptions = {},\n): Promise<CheckHelpResult> {\n\tconst root = resolve(options.root ?? '.');\n\tconst flowsDir = resolve(root, options.flows ?? 'docs/flows');\n\tconst ignore = options.ignore ?? [];\n\tconst entries =\n\t\toptions.config ??\n\t\t(await readRouteConfig(resolve(root, options.routes ?? 'app/routes.ts')));\n\tconst routes = flattenRoutes(entries);\n\tconst known = new Set(routes.map((route) => route.id));\n\tconst problems: HelpProblem[] = [];\n\tconst cited = new Set<string>();\n\n\tconst files = existsSync(flowsDir)\n\t\t? readdirSync(flowsDir)\n\t\t\t\t.filter(\n\t\t\t\t\t(name) => name.endsWith('.md') && langOfFile(name) !== undefined,\n\t\t\t\t)\n\t\t\t\t.sort()\n\t\t: [];\n\tlet flows = 0;\n\tconst flowIds = new Map<string, string>();\n\tfor (const name of files) {\n\t\tconst path = join(flowsDir, name);\n\t\tconst shown = `${options.flows ?? 'docs/flows'}/${name}`;\n\t\tlet flow: ReturnType<typeof parseFlow>;\n\t\ttry {\n\t\t\tflow = parseFlow(readFileSync(path, 'utf8'), shown);\n\t\t} catch (error) {\n\t\t\tif (error instanceof FlowFormatError) {\n\t\t\t\tproblems.push({ kind: 'bad-flow', message: error.message });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tflows++;\n\t\tconst idKey = `${flow.lang}:${flow.id}`;\n\t\tconst other = flowIds.get(idKey);\n\t\tif (other === undefined) flowIds.set(idKey, shown);\n\t\telse {\n\t\t\tproblems.push({\n\t\t\t\tkind: 'bad-flow',\n\t\t\t\tmessage: `${shown}: flow id \"${flow.id}\" is already used by ${other}`,\n\t\t\t});\n\t\t}\n\t\tfor (const id of flow.routes) {\n\t\t\tcited.add(id);\n\t\t\tif (!known.has(id)) {\n\t\t\t\tproblems.push({\n\t\t\t\t\tkind: 'unknown-route',\n\t\t\t\t\tmessage: `${shown}: cites route \"${id}\", which is not in the route config`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tfor (const capture of flow.captures) {\n\t\t\tfor (const width of CAPTURE_WIDTHS) {\n\t\t\t\tfor (const theme of CAPTURE_THEMES) {\n\t\t\t\t\tconst file = captureFile(capture.name, width, theme);\n\t\t\t\t\tif (!existsSync(join(flowsDir, 'captures', file))) {\n\t\t\t\t\t\tproblems.push({\n\t\t\t\t\t\t\tkind: 'missing-capture',\n\t\t\t\t\t\t\tmessage: `${shown}: capture ${file} is missing from ${options.flows ?? 'docs/flows'}/captures/`,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst screens = routes.filter((route) => route.screen);\n\tfor (const screen of screens) {\n\t\tconst covered =\n\t\t\tcited.has(screen.id) || screen.ancestors.some((id) => cited.has(id));\n\t\tif (!covered && !matchesIgnore(screen.id, ignore)) {\n\t\t\tproblems.push({\n\t\t\t\tkind: 'uncovered-route',\n\t\t\t\tmessage: `route \"${screen.id}\" is covered by no flow: cite it in a flow's routes, or add it to the ignore list`,\n\t\t\t});\n\t\t}\n\t}\n\tfor (const pattern of ignore) {\n\t\tif (!routes.some((route) => matchesIgnore(route.id, [pattern]))) {\n\t\t\tproblems.push({\n\t\t\t\tkind: 'unused-ignore',\n\t\t\t\tmessage: `ignore \"${pattern}\" matches no route`,\n\t\t\t});\n\t\t}\n\t}\n\treturn {\n\t\tok: problems.length === 0,\n\t\tproblems,\n\t\tflows,\n\t\tscreens: screens.length,\n\t};\n}\n",
6
+ "/** The part of React Router's `RouteConfigEntry` the check reads. */\nexport interface RouteEntry {\n\treadonly id?: string;\n\treadonly path?: string;\n\treadonly file: string;\n\treadonly index?: boolean;\n\treadonly children?: readonly RouteEntry[];\n}\n\nexport interface FlatRoute {\n\treadonly id: string;\n\t/** A screen: a route with no children. Layouts are not screens. */\n\treadonly screen: boolean;\n\t/** The ids of the routes above it, root first (`root` included). */\n\treadonly ancestors: readonly string[];\n}\n\n/** React Router's route id: the entry's `id`, else its file without extension. */\nexport function routeId(entry: RouteEntry): string {\n\tif (entry.id) return entry.id;\n\treturn entry.file.replace(/^\\.?\\//, '').replace(/\\.[cm]?[jt]sx?$/, '');\n}\n\n/** Every route of a config, depth first; `root` is added as React Router does. */\nexport function flattenRoutes(entries: readonly RouteEntry[]): FlatRoute[] {\n\tconst result: FlatRoute[] = [{ id: 'root', screen: false, ancestors: [] }];\n\tconst walk = (list: readonly RouteEntry[], ancestors: readonly string[]) => {\n\t\tfor (const entry of list) {\n\t\t\tconst children = entry.children ?? [];\n\t\t\tconst id = routeId(entry);\n\t\t\tresult.push({ id, screen: children.length === 0, ancestors });\n\t\t\twalk(children, [...ancestors, id]);\n\t\t}\n\t};\n\twalk(entries, ['root']);\n\treturn result;\n}\n\n/** `*` in an ignore pattern matches any run of characters. */\nexport function matchesIgnore(\n\tid: string,\n\tpatterns: readonly string[],\n): boolean {\n\treturn patterns.some((pattern) =>\n\t\tnew RegExp(\n\t\t\t`^${pattern.replace(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*')}$`,\n\t\t).test(id),\n\t);\n}\n"
7
+ ],
8
+ "mappings": ";;;;;;;;;;AAAA;AACA;AACA;;;ACgBO,SAAS,QAAO,CAAC,OAA2B;AAAA,EAClD,IAAI,MAAM;AAAA,IAAI,OAAO,MAAM;AAAA,EAC3B,OAAO,MAAM,KAAK,QAAQ,UAAU,EAAE,EAAE,QAAQ,mBAAmB,EAAE;AAAA;AAI/D,SAAS,cAAa,CAAC,SAA6C;AAAA,EAC1E,MAAM,SAAsB,CAAC,EAAE,IAAI,QAAQ,QAAQ,OAAO,WAAW,CAAC,EAAE,CAAC;AAAA,EACzE,MAAM,OAAO,CAAC,MAA6B,cAAiC;AAAA,IAC3E,WAAW,SAAS,MAAM;AAAA,MACzB,MAAM,WAAW,MAAM,YAAY,CAAC;AAAA,MACpC,MAAM,KAAK,SAAQ,KAAK;AAAA,MACxB,OAAO,KAAK,EAAE,IAAI,QAAQ,SAAS,WAAW,GAAG,UAAU,CAAC;AAAA,MAC5D,KAAK,UAAU,CAAC,GAAG,WAAW,EAAE,CAAC;AAAA,IAClC;AAAA;AAAA,EAED,KAAK,SAAS,CAAC,MAAM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O,OAAO,CAAC,UAAU,MAAM,MAAM;AAAA,EACrD,WAAW,UAAU,SAAS;AAAA,IAC7B,MAAM,UACL,MAAM,IAAI,OAAO,EAAE,KAAK,OAAO,UAAU,KAAK,CAAC,OAAO,MAAM,IAAI,EAAE,CAAC;AAAA,IACpE,IAAI,CAAC,WAAW,CAAC,eAAc,OAAO,IAAI,MAAM,GAAG;AAAA,MAClD,SAAS,KAAK;AAAA,QACb,MAAM;AAAA,QACN,SAAS,UAAU,OAAO;AAAA,MAC3B,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EACA,WAAW,WAAW,QAAQ;AAAA,IAC7B,IAAI,CAAC,OAAO,KAAK,CAAC,UAAU,eAAc,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG;AAAA,MAChE,SAAS,KAAK;AAAA,QACb,MAAM;AAAA,QACN,SAAS,WAAW;AAAA,MACrB,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EACA,OAAO;AAAA,IACN,IAAI,SAAS,WAAW;AAAA,IACxB;AAAA,IACA;AAAA,IACA,SAAS,QAAQ;AAAA,EAClB;AAAA;",
9
+ "debugId": "525272F993E242D864756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ isCrossSite
3
+ } from "./index-mscfme4r.js";
4
+
5
+ // src/errors/page-path.ts
6
+ function nextOf2(url) {
7
+ const { pathname, searchParams } = new URL(url);
8
+ const trimmed = pathname.endsWith("/_.data") ? pathname.slice(0, -"_.data".length) : pathname.replace(/\.data$/, "");
9
+ const path = trimmed.replace(/^\/{2,}/, "/");
10
+ const params = new URLSearchParams(searchParams);
11
+ params.delete("_routes");
12
+ for (const value of params.getAll("index")) {
13
+ if (!value)
14
+ params.delete("index", value);
15
+ }
16
+ const search = params.toString();
17
+ return search ? `${path}?${search}` : path;
18
+ }
19
+
20
+ // src/errors/same-site.ts
21
+ import { data } from "react-router";
22
+ function siteCheck(origin) {
23
+ return (request) => {
24
+ const set = typeof origin === "function" ? origin() : origin;
25
+ if (isCrossSite(request, set)) {
26
+ throw data("Cross-site request refused", { status: 403 });
27
+ }
28
+ };
29
+ }
30
+ var SITE_CHECK = Symbol.for("@softistx/alxia-react-router:site-check@1");
31
+ function rememberSiteCheck(actions, check) {
32
+ Object.defineProperty(actions, SITE_CHECK, {
33
+ value: check,
34
+ enumerable: true,
35
+ writable: false
36
+ });
37
+ }
38
+ var hasSiteCheck = (actions) => typeof actions[SITE_CHECK] === "function";
39
+ function refuseCrossSite(actions, request) {
40
+ const check = actions[SITE_CHECK];
41
+ (typeof check === "function" ? check : siteCheck())(request);
42
+ }
43
+ function requireSameSite2(request, from) {
44
+ if (from && hasSiteCheck(from)) {
45
+ refuseCrossSite(from, request);
46
+ return;
47
+ }
48
+ siteCheck(from?.origin)(request);
49
+ }
50
+
51
+ export { nextOf2, siteCheck, rememberSiteCheck, hasSiteCheck, requireSameSite2 };
52
+
53
+ //# debugId=E9E721BA392D2DE664756E2164756E21
54
+ //# sourceMappingURL=index-v2z5k640.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors/page-path.ts", "../src/errors/same-site.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The page a request is for, as `next` carries it back after sign-in: its\n * path and search, without React Router's single-fetch details. A client\n * navigation's `request.url` is `/todos/demo/list.data?q=a&_routes=…`\n * (`/_.data` for `/`, `?index` for an index action), as the server\n * runtime's own `normalizeUrl` strips them.\n */\nexport function nextOf(url: string): string {\n\tconst { pathname, searchParams } = new URL(url);\n\tconst trimmed = pathname.endsWith('/_.data')\n\t\t? pathname.slice(0, -'_.data'.length)\n\t\t: pathname.replace(/\\.data$/, '');\n\t// `new URL('http://h/\\\\evil.com')` has the path `//evil.com`: never let a\n\t// `next` start with two slashes, which a redirect reads as another site.\n\tconst path = trimmed.replace(/^\\/{2,}/, '/');\n\tconst params = new URLSearchParams(searchParams);\n\tparams.delete('_routes');\n\t// An empty `index` names the index route; a valued one is the page's own.\n\tfor (const value of params.getAll('index')) {\n\t\tif (!value) params.delete('index', value);\n\t}\n\tconst search = params.toString();\n\treturn search ? `${path}?${search}` : path;\n}\n",
6
+ "import { data } from 'react-router';\nimport { isCrossSite } from './cross-site';\nimport type { JsonActions } from './json-actions';\n\n/** Refuses a request from another site with a 403; reads headers only. */\nexport type SiteCheck = (request: Request) => void;\n\n/**\n * The same-site rule of `readJson`: an `Origin` that is not the app's own, or\n * a `Sec-Fetch-Site` that is neither `same-origin` nor `none`, is a 403.\n * `origin` is the app's configured origin (or a getter), else the request's.\n */\nexport function siteCheck(\n\torigin?: string | (() => string | undefined) | undefined,\n): SiteCheck {\n\treturn (request) => {\n\t\tconst set = typeof origin === 'function' ? origin() : origin;\n\t\tif (isCrossSite(request, set)) {\n\t\t\tthrow data('Cross-site request refused', { status: 403 });\n\t\t}\n\t};\n}\n\n/**\n * Where a `jsonActions` instance keeps its site check: an enumerable property\n * under a registered symbol, so it survives `{ ...json }` and a second copy of\n * the package. Not public.\n */\nexport const SITE_CHECK = Symbol.for(\n\t'@softistx/alxia-react-router:site-check@1',\n);\n\n/** Puts the check on a `jsonActions` instance. */\nexport function rememberSiteCheck(actions: object, check: SiteCheck): void {\n\tObject.defineProperty(actions, SITE_CHECK, {\n\t\tvalue: check,\n\t\tenumerable: true,\n\t\twritable: false,\n\t});\n}\n\n/** Whether `actions` carries a site check, as every `jsonActions()` instance does. */\nexport const hasSiteCheck = (actions: object): boolean =>\n\ttypeof (actions as Record<symbol, unknown>)[SITE_CHECK] === 'function';\n\n/**\n * Refuses a cross-site request with the rule of the `jsonActions` instance\n * (its configured origin, read at each request); an object without a check\n * gets the request's own origin. It reads headers only, never the body.\n */\nexport function refuseCrossSite(actions: object, request: Request): void {\n\tconst check = (actions as Record<symbol, unknown>)[SITE_CHECK];\n\t(typeof check === 'function' ? (check as SiteCheck) : siteCheck())(request);\n}\n\n/** Options of {@link requireSameSite}. */\nexport interface SameSiteOptions {\n\t/**\n\t * The origin a request must come from, such as `https://app.example.com`:\n\t * required behind a TLS-terminating proxy, where the request's own URL\n\t * says `http:`. A getter is read at each request. Else the request's own\n\t * origin, which is right for a host that serves several tenants.\n\t */\n\torigin?: string | (() => string | undefined);\n}\n\n/**\n * The same-site guard for any POST, a native form or JSON: throws a 403\n * `Cross-site request refused` for an `Origin` that is not the app's own\n * (`Origin: null` and a foreign origin included) and for a `Sec-Fetch-Site`\n * that is neither `same-origin` nor `none`. A request with no `Origin` and no\n * `Sec-Fetch-Site` (a non-browser client, an old browser) goes on, as it does\n * for `readJson`: CSRF is a browser attack, and a browser sends one of them.\n * It reads headers only, never the body, so the form can still be read after.\n *\n * Pass a `jsonActions()` instance to apply its configured origin, or\n * `{ origin }`; else the request's own origin is the reference.\n */\nexport function requireSameSite(\n\trequest: Request,\n\tfrom?: JsonActions | SameSiteOptions,\n): void {\n\tif (from && hasSiteCheck(from)) {\n\t\trefuseCrossSite(from, request);\n\t\treturn;\n\t}\n\tsiteCheck((from as SameSiteOptions | undefined)?.origin)(request);\n}\n"
7
+ ],
8
+ "mappings": ";;;;;AAOO,SAAS,OAAM,CAAC,KAAqB;AAAA,EAC3C,QAAQ,UAAU,iBAAiB,IAAI,IAAI,GAAG;AAAA,EAC9C,MAAM,UAAU,SAAS,SAAS,SAAS,IACxC,SAAS,MAAM,GAAG,CAAC,SAAS,MAAM,IAClC,SAAS,QAAQ,WAAW,EAAE;AAAA,EAGjC,MAAM,OAAO,QAAQ,QAAQ,WAAW,GAAG;AAAA,EAC3C,MAAM,SAAS,IAAI,gBAAgB,YAAY;AAAA,EAC/C,OAAO,OAAO,SAAS;AAAA,EAEvB,WAAW,SAAS,OAAO,OAAO,OAAO,GAAG;AAAA,IAC3C,IAAI,CAAC;AAAA,MAAO,OAAO,OAAO,SAAS,KAAK;AAAA,EACzC;AAAA,EACA,MAAM,SAAS,OAAO,SAAS;AAAA,EAC/B,OAAO,SAAS,GAAG,QAAQ,WAAW;AAAA;;;ACtBvC;AAYO,SAAS,SAAS,CACxB,QACY;AAAA,EACZ,OAAO,CAAC,YAAY;AAAA,IACnB,MAAM,MAAM,OAAO,WAAW,aAAa,OAAO,IAAI;AAAA,IACtD,IAAI,YAAY,SAAS,GAAG,GAAG;AAAA,MAC9B,MAAM,KAAK,8BAA8B,EAAE,QAAQ,IAAI,CAAC;AAAA,IACzD;AAAA;AAAA;AASK,IAAM,aAAa,OAAO,IAChC,2CACD;AAGO,SAAS,iBAAiB,CAAC,SAAiB,OAAwB;AAAA,EAC1E,OAAO,eAAe,SAAS,YAAY;AAAA,IAC1C,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,EACX,CAAC;AAAA;AAIK,IAAM,eAAe,CAAC,YAC5B,OAAQ,QAAoC,gBAAgB;AAOtD,SAAS,eAAe,CAAC,SAAiB,SAAwB;AAAA,EACxE,MAAM,QAAS,QAAoC;AAAA,GAClD,OAAO,UAAU,aAAc,QAAsB,UAAU,GAAG,OAAO;AAAA;AA0BpE,SAAS,gBAAe,CAC9B,SACA,MACO;AAAA,EACP,IAAI,QAAQ,aAAa,IAAI,GAAG;AAAA,IAC/B,gBAAgB,MAAM,OAAO;AAAA,IAC7B;AAAA,EACD;AAAA,EACA,UAAW,MAAsC,MAAM,EAAE,OAAO;AAAA;",
9
+ "debugId": "E9E721BA392D2DE664756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,23 @@
1
+ // src/session/codes.ts
2
+ var INVALID_CODE2 = "CODE_INVALID";
3
+ var CHALLENGE_OVER2 = [
4
+ "TOKEN_UNKNOWN",
5
+ "TOKEN_SPENT",
6
+ "TOKEN_EXPIRED"
7
+ ];
8
+ var MAIL_THROTTLED2 = "MAIL_THROTTLED";
9
+ var UNAUTHENTICATED2 = "UNAUTHENTICATED";
10
+
11
+ // src/session/step-up-codes.ts
12
+ var STEP_UP_REQUIRED2 = "STEP_UP_REQUIRED";
13
+ var STEP_UP_OVER2 = [
14
+ ...CHALLENGE_OVER2,
15
+ "TOKEN_STALE",
16
+ "SECOND_FACTOR_ACTIVE",
17
+ "SECOND_FACTOR_NOT_ENROLLED"
18
+ ];
19
+
20
+ export { INVALID_CODE2, CHALLENGE_OVER2, MAIL_THROTTLED2, UNAUTHENTICATED2, STEP_UP_REQUIRED2, STEP_UP_OVER2 };
21
+
22
+ //# debugId=B8AC536A588833B064756E2164756E21
23
+ //# sourceMappingURL=index-vr82typq.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/session/codes.ts", "../src/session/step-up-codes.ts"],
4
+ "sourcesContent": [
5
+ "/** `@softistx/janus`'s code for a wrong second-factor or step-up code. */\nexport const INVALID_CODE = 'CODE_INVALID';\n\n/** `@softistx/janus`'s codes for a challenge that is gone: unknown, spent or expired. */\nexport const CHALLENGE_OVER = [\n\t'TOKEN_UNKNOWN',\n\t'TOKEN_SPENT',\n\t'TOKEN_EXPIRED',\n] as const;\n\n/** `@softistx/janus`'s code for a mail the API holds back: a link or a code asked for too often. */\nexport const MAIL_THROTTLED = 'MAIL_THROTTLED';\n\n/** The code of an API answer for no session, or a dead one. */\nexport const UNAUTHENTICATED = 'UNAUTHENTICATED';\n",
6
+ "import { CHALLENGE_OVER } from './codes';\n\n/** `@softistx/janus`'s code for a mutation that needs a recent step-up. */\nexport const STEP_UP_REQUIRED = 'STEP_UP_REQUIRED';\n\n/**\n * The codes that end a step-up's challenge: unknown, spent, expired or stale,\n * and a second factor that changed since the request (`SECOND_FACTOR_ACTIVE`,\n * `SECOND_FACTOR_NOT_ENROLLED`). The user asks again.\n */\nexport const STEP_UP_OVER = [\n\t...CHALLENGE_OVER,\n\t'TOKEN_STALE',\n\t'SECOND_FACTOR_ACTIVE',\n\t'SECOND_FACTOR_NOT_ENROLLED',\n] as const;\n"
7
+ ],
8
+ "mappings": ";AACO,IAAM,gBAAe;AAGrB,IAAM,kBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACD;AAGO,IAAM,kBAAiB;AAGvB,IAAM,mBAAkB;;;ACXxB,IAAM,oBAAmB;AAOzB,IAAM,gBAAe;AAAA,EAC3B,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACD;",
9
+ "debugId": "B8AC536A588833B064756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,9 @@
1
+ // src/lists/newest-first.ts
2
+ function newestFirst(items) {
3
+ return [...items].sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
4
+ }
5
+
6
+ export { newestFirst };
7
+
8
+ //# debugId=54A83376C509AC4B64756E2164756E21
9
+ //# sourceMappingURL=index-whj6h5eg.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lists/newest-first.ts"],
4
+ "sourcesContent": [
5
+ "/** Newest first by `createdAt`, without touching the input: what `oauthGrants` and `apiKeys` list. */\nexport function newestFirst<T extends { createdAt: string }>(\n\titems: readonly T[],\n): T[] {\n\treturn [...items].sort(\n\t\t(a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt),\n\t);\n}\n"
6
+ ],
7
+ "mappings": ";AACO,SAAS,WAA4C,CAC3D,OACM;AAAA,EACN,OAAO,CAAC,GAAG,KAAK,EAAE,KACjB,CAAC,GAAG,MAAM,KAAK,MAAM,EAAE,SAAS,IAAI,KAAK,MAAM,EAAE,SAAS,CAC3D;AAAA;",
8
+ "debugId": "54A83376C509AC4B64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,130 @@
1
+ // src/errors/api-error.ts
2
+ var isNamed = (error, name) => error instanceof Error && error.name === name;
3
+ function isApiErrorLike2(error) {
4
+ return isNamed(error, "ApiError") && Array.isArray(error.errors) && typeof error.status === "number";
5
+ }
6
+ function isStaleVersion2(error) {
7
+ return isApiErrorLike2(error) && error.status === 409 && typeof error.code === "string" && error.code.endsWith(".errors.stale-version");
8
+ }
9
+ function waitMinutes2(extensions) {
10
+ const minutes = extensions?.params?.minutes ?? extensions?.minutes;
11
+ if (minutes !== undefined)
12
+ return Math.max(1, Number(minutes) || 1);
13
+ const seconds = extensions?.params?.retryAfter ?? extensions?.retryAfter;
14
+ return Math.max(1, Math.ceil(Number(seconds) / 60) || 1);
15
+ }
16
+ var MAX_RETRY_AFTER = 86400;
17
+ function secondsOf(value) {
18
+ const seconds = typeof value === "string" && /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value.trim()) : value;
19
+ return typeof seconds === "number" && Number.isFinite(seconds) && seconds >= 0 ? Math.min(MAX_RETRY_AFTER, Math.ceil(seconds)) + 0 : undefined;
20
+ }
21
+ function retryAfterOf2(error) {
22
+ const extensions = error.errors[0]?.extensions;
23
+ return secondsOf(extensions?.params?.retryAfter) ?? secondsOf(extensions?.retryAfter);
24
+ }
25
+ function reasonOf(error) {
26
+ const extensions = error.errors[0]?.extensions;
27
+ return extensions?.["reason"] ?? extensions?.params?.["reason"];
28
+ }
29
+ var isThrottledReason2 = (error) => reasonOf(error) === "throttled";
30
+ function attemptsLeftOf2(error) {
31
+ if (isThrottledReason2(error))
32
+ return;
33
+ const extensions = error.errors[0]?.extensions;
34
+ for (const value of [
35
+ extensions?.attemptsLeft,
36
+ extensions?.params?.attemptsLeft
37
+ ]) {
38
+ if (typeof value === "number" && Number.isInteger(value) && value >= 0) {
39
+ return value;
40
+ }
41
+ }
42
+ return;
43
+ }
44
+ function valuesOf(extensions) {
45
+ if (!extensions)
46
+ return;
47
+ return extensions.params ? { ...extensions, ...extensions.params } : extensions;
48
+ }
49
+ var isStatusError = (error) => isNamed(error, "ApiStatusError") && typeof error.status === "number";
50
+ var isUnavailableError = (error) => isNamed(error, "ApiUnavailableError") && typeof error.reason === "string";
51
+
52
+ // src/errors/route-error.ts
53
+ import { data } from "react-router";
54
+
55
+ // src/errors/problem-error.ts
56
+ var text = (value) => typeof value === "string" && value ? value : undefined;
57
+
58
+ class ProblemError2 extends Error {
59
+ name = "ProblemError";
60
+ status;
61
+ title;
62
+ detail;
63
+ type;
64
+ instance;
65
+ requestId;
66
+ constructor(reply, { requestId } = {}) {
67
+ const body = typeof reply.data === "object" && reply.data !== null ? reply.data : {};
68
+ const title = text(body.title) ?? `Error ${reply.status}`;
69
+ const detail = text(body.detail);
70
+ super(detail ?? title);
71
+ this.status = reply.status;
72
+ this.title = title;
73
+ this.detail = detail;
74
+ this.type = text(body.type);
75
+ this.instance = text(body.instance);
76
+ this.requestId = requestId;
77
+ }
78
+ }
79
+ function problemError2(reply, options) {
80
+ return new ProblemError2(reply, options);
81
+ }
82
+ function isProblemErrorLike2(error) {
83
+ return isNamed(error, "ProblemError") && typeof error.status === "number";
84
+ }
85
+
86
+ // src/errors/request-id.ts
87
+ var REQUEST_ID_HEADER2 = "x-request-id";
88
+ function requestIdOf2(response) {
89
+ return response.headers.get(REQUEST_ID_HEADER2) || undefined;
90
+ }
91
+
92
+ // src/errors/route-error.ts
93
+ var ROUTED = new Set([401, 403, 404, 503]);
94
+ function routeError2(error, { statuses = ROUTED } = {}) {
95
+ if (isApiErrorLike2(error)) {
96
+ const { requestId } = error;
97
+ if (statuses.has(error.status)) {
98
+ return data({ code: error.code, message: error.message, requestId }, { status: error.status });
99
+ }
100
+ return requestId ? data({ requestId }, { status: 500 }) : error;
101
+ }
102
+ if (isProblemErrorLike2(error)) {
103
+ const { requestId } = error;
104
+ if (statuses.has(error.status)) {
105
+ return data({ message: error.message, requestId }, { status: error.status });
106
+ }
107
+ return requestId ? data({ requestId }, { status: 500 }) : error;
108
+ }
109
+ if (error instanceof Response && statuses.has(error.status)) {
110
+ const requestId = requestIdOf2(error);
111
+ if (requestId) {
112
+ return data({ requestId }, { status: error.status });
113
+ }
114
+ }
115
+ return error;
116
+ }
117
+ function errorRequestId2(error) {
118
+ if (typeof error !== "object" || error === null)
119
+ return;
120
+ const { data: body } = error;
121
+ if (typeof body !== "object" || body === null)
122
+ return;
123
+ const { requestId } = body;
124
+ return typeof requestId === "string" && requestId ? requestId : undefined;
125
+ }
126
+
127
+ export { isApiErrorLike2, isStaleVersion2, waitMinutes2, retryAfterOf2, isThrottledReason2, attemptsLeftOf2, valuesOf, isStatusError, isUnavailableError, ProblemError2, problemError2, isProblemErrorLike2, REQUEST_ID_HEADER2, requestIdOf2, routeError2, errorRequestId2 };
128
+
129
+ //# debugId=C5A85AE98DF89B6E64756E2164756E21
130
+ //# sourceMappingURL=index-wyypkfdv.js.map
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors/api-error.ts", "../src/errors/route-error.ts", "../src/errors/problem-error.ts", "../src/errors/request-id.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The shape of an API's refusal, as `@nxgt/graphql-client`'s `ApiError`\n * carries it, declared structurally: `/errors` never imports the client, so\n * an app needs it only if it calls the API through it. `api-error.spec.ts`\n * holds the two in step.\n */\n\n/** One refused input field: `extensions.fields` of a validation refusal. */\nexport interface ApiFieldErrorLike {\n\treadonly path: string;\n\treadonly code: string;\n\treadonly message: string;\n\t/** The values the field's message interpolates. */\n\treadonly params?: Readonly<Record<string, unknown>>;\n}\n\n/** The values a message interpolates; a throttle's wait is `minutes` or `retryAfter`. */\nexport interface ApiErrorParamsLike {\n\treadonly minutes?: unknown;\n\treadonly retryAfter?: unknown;\n\treadonly attemptsLeft?: unknown;\n\treadonly [key: string]: unknown;\n}\n\n/**\n * One GraphQL error's `extensions`. `code` is the API's own\n * `<module>.errors.<slug>`; the rest is what its messages name.\n */\nexport interface ApiErrorExtensionsLike {\n\treadonly code?: string;\n\t/** The values the message interpolates, when the API sends them. */\n\treadonly params?: ApiErrorParamsLike;\n\t/** A validation refusal: every field at fault, by input path. */\n\treadonly fields?: readonly ApiFieldErrorLike[];\n\t/** Any other refusal about one input field, by its path. */\n\treadonly field?: string;\n\t/** A throttle's wait, in minutes (`waitMinutes` coerces a string). */\n\treadonly minutes?: unknown;\n\t/** A throttle's wait, in seconds. */\n\treadonly retryAfter?: unknown;\n\t/** The tries a refused code leaves, as `@softistx/janus` counts them. */\n\treadonly attemptsLeft?: unknown;\n\treadonly [key: string]: unknown;\n}\n\n/** One error of a response's `errors`. */\nexport interface ApiErrorEntryLike {\n\treadonly message: string;\n\treadonly extensions?: ApiErrorExtensionsLike;\n}\n\n/** A refusal read from a GraphQL API: what `ApiError` has, and the request id. */\nexport interface ApiErrorLike extends Error {\n\treadonly errors: readonly ApiErrorEntryLike[];\n\t/** The first error's `extensions.code`. */\n\treadonly code: string | undefined;\n\t/** The HTTP status to answer with. */\n\treadonly status: number;\n\t/** The id the API logged the request under, when the caller kept it. */\n\treadonly requestId?: string;\n}\n\n/** Whether `error` is an `Error` of this `name`: the client's errors are told by it, never `instanceof`. */\nexport const isNamed = (error: unknown, name: string): error is Error =>\n\terror instanceof Error && error.name === name;\n\n/**\n * Whether `error` is an `ApiError` of `@nxgt/graphql-client`, by the test\n * that client's `isApiError` makes (an `Error` named `ApiError` with an\n * `errors` array), plus a numeric `status`, which `ApiErrorLike` promises.\n * It holds across two copies of the client.\n */\nexport function isApiErrorLike(error: unknown): error is ApiErrorLike {\n\treturn (\n\t\tisNamed(error, 'ApiError') &&\n\t\tArray.isArray((error as { errors?: unknown }).errors) &&\n\t\ttypeof (error as { status?: unknown }).status === 'number'\n\t);\n}\n\n/**\n * Whether `error` is an API's refusal of an update whose version is out of\n * date: an `ApiError` with status 409 whose `code` ends with\n * `.errors.stale-version`. False for any other value.\n */\nexport function isStaleVersion(error: unknown): error is ApiErrorLike {\n\treturn (\n\t\tisApiErrorLike(error) &&\n\t\terror.status === 409 &&\n\t\ttypeof error.code === 'string' &&\n\t\terror.code.endsWith('.errors.stale-version')\n\t);\n}\n\n/**\n * The minutes a wait lasts, as the API words it: `minutes` (at least one, in\n * `extensions.params` or beside it), else the `retryAfter` seconds rounded\n * up, else one.\n */\nexport function waitMinutes(\n\textensions: ApiErrorExtensionsLike | undefined,\n): number {\n\tconst minutes = extensions?.params?.minutes ?? extensions?.minutes;\n\tif (minutes !== undefined) return Math.max(1, Number(minutes) || 1);\n\tconst seconds = extensions?.params?.retryAfter ?? extensions?.retryAfter;\n\treturn Math.max(1, Math.ceil(Number(seconds) / 60) || 1);\n}\n\nconst MAX_RETRY_AFTER = 86_400;\n\n/** A wait in seconds from one value: a finite number from 0, or a decimal string. */\nfunction secondsOf(value: unknown): number | undefined {\n\tconst seconds =\n\t\ttypeof value === 'string' && /^\\d+(\\.\\d+)?$/.test(value.trim())\n\t\t\t? Number(value.trim())\n\t\t\t: value;\n\treturn typeof seconds === 'number' && Number.isFinite(seconds) && seconds >= 0\n\t\t? Math.min(MAX_RETRY_AFTER, Math.ceil(seconds)) + 0\n\t\t: undefined;\n}\n\n/**\n * The seconds a throttle asks to wait: `retryAfter` of the first error's\n * `extensions.params`, else (when that is unusable) of its `extensions`.\n * Only a finite number from 0, or a decimal string, counts; it is rounded up\n * and held at a day (86 400), and `-0` is 0. `undefined` when the API sent\n * none usable. Exported from `/errors`; `/session` words it as a typed\n * `retryAfter`.\n */\nexport function retryAfterOf(error: ApiErrorLike): number | undefined {\n\tconst extensions = error.errors[0]?.extensions;\n\treturn (\n\t\tsecondsOf(extensions?.params?.retryAfter) ??\n\t\tsecondsOf(extensions?.retryAfter)\n\t);\n}\n\n/** The API's `extensions.reason` of the first error (also in its `params`): `'throttled'` is a timed wait. */\nexport function reasonOf(error: ApiErrorLike): unknown {\n\tconst extensions = error.errors[0]?.extensions;\n\treturn extensions?.['reason'] ?? extensions?.params?.['reason'];\n}\n\n/** Whether the refusal carries `reason: 'throttled'`: a rate limit that asks to wait, whatever its code. */\nexport const isThrottledReason = (error: ApiErrorLike): boolean =>\n\treasonOf(error) === 'throttled';\n\n/**\n * The tries a refused code leaves, as `@softistx/janus` counts them:\n * `extensions.attemptsLeft` of the first error, else the same key in its\n * `params`. A whole number from 0 up; `undefined` when the API sent none or\n * something that is not a count. A throttled refusal (`isThrottledReason`)\n * spends no try: whatever count it carries (`0` included), it answers\n * `undefined`.\n */\nexport function attemptsLeftOf(error: ApiErrorLike): number | undefined {\n\tif (isThrottledReason(error)) return undefined;\n\tconst extensions = error.errors[0]?.extensions;\n\tfor (const value of [\n\t\textensions?.attemptsLeft,\n\t\textensions?.params?.attemptsLeft,\n\t]) {\n\t\tif (typeof value === 'number' && Number.isInteger(value) && value >= 0) {\n\t\t\treturn value;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * The values a message names: `extensions.params` over the extensions\n * themselves, where older errors and the extras of a few sit.\n */\nexport function valuesOf(\n\textensions: ApiErrorExtensionsLike | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return undefined;\n\treturn extensions.params\n\t\t? { ...extensions, ...extensions.params }\n\t\t: extensions;\n}\n\n/** `@nxgt/graphql-client`'s `ApiStatusError`, as far as the failure reads it. */\nexport interface StatusErrorLike extends Error {\n\tstatus: number;\n\tstatusText?: string | undefined;\n\tbody?: unknown;\n}\n\n/** `@nxgt/graphql-client`'s `ApiUnavailableError`, as far as the failure reads it. */\nexport interface UnavailableErrorLike extends Error {\n\treason: string;\n}\n\nexport const isStatusError = (error: unknown): error is StatusErrorLike =>\n\tisNamed(error, 'ApiStatusError') &&\n\ttypeof (error as { status?: unknown }).status === 'number';\n\nexport const isUnavailableError = (\n\terror: unknown,\n): error is UnavailableErrorLike =>\n\tisNamed(error, 'ApiUnavailableError') &&\n\ttypeof (error as { reason?: unknown }).reason === 'string';\n",
6
+ "import { data } from 'react-router';\nimport { isApiErrorLike } from './api-error';\nimport { isProblemErrorLike } from './problem-error';\nimport { requestIdOf } from './request-id';\n\n/** The statuses an error page words: unauthenticated, forbidden, missing, unavailable. */\nconst ROUTED: ReadonlySet<number> = new Set([401, 403, 404, 503]);\n\n/**\n * What a route error of the API carries to the error page: the API's code\n * and message when it gave a code, and the `X-Request-Id` of the call as the\n * support reference (`errorRequestId`).\n */\nexport type RouteErrorData = {\n\tcode?: string | undefined;\n\tmessage?: string | undefined;\n\trequestId?: string | undefined;\n};\n\nexport interface RouteErrorOptions {\n\t/** The statuses that become a route error of their own; 401, 403, 404 and 503 by default. */\n\tstatuses?: ReadonlySet<number>;\n}\n\n/**\n * What a loader throws for an error from the API: an `ApiError` whose\n * status is routed (401, 403, 404 or 503) becomes a route error response of\n * that status, which the root `ErrorBoundary` renders as its page, with the\n * call's request id when the API gave one. A thrown routed `Response` that\n * carries a request id becomes one too (a bare `Response` hands the browser\n * its body only). Any other `ApiError` that has a request id becomes a 500\n * with just that id, so the generic error page can show it. A `ProblemError`\n * (`problemError`, a REST API's RFC 9457 reply) is treated alike, its message\n * being the problem's detail or title. Anything else\n * is returned as it is.\n */\nexport function routeError(\n\terror: unknown,\n\t{ statuses = ROUTED }: RouteErrorOptions = {},\n): unknown {\n\tif (isApiErrorLike(error)) {\n\t\tconst { requestId } = error;\n\t\tif (statuses.has(error.status)) {\n\t\t\treturn data<RouteErrorData>(\n\t\t\t\t{ code: error.code, message: error.message, requestId },\n\t\t\t\t{ status: error.status },\n\t\t\t);\n\t\t}\n\t\treturn requestId\n\t\t\t? data<RouteErrorData>({ requestId }, { status: 500 })\n\t\t\t: error;\n\t}\n\tif (isProblemErrorLike(error)) {\n\t\tconst { requestId } = error;\n\t\tif (statuses.has(error.status)) {\n\t\t\treturn data<RouteErrorData>(\n\t\t\t\t{ message: error.message, requestId },\n\t\t\t\t{ status: error.status },\n\t\t\t);\n\t\t}\n\t\treturn requestId\n\t\t\t? data<RouteErrorData>({ requestId }, { status: 500 })\n\t\t\t: error;\n\t}\n\tif (error instanceof Response && statuses.has(error.status)) {\n\t\tconst requestId = requestIdOf(error);\n\t\tif (requestId) {\n\t\t\treturn data<RouteErrorData>({ requestId }, { status: error.status });\n\t\t}\n\t}\n\treturn error;\n}\n\n/**\n * The support reference an error page shows: the API's `X-Request-Id` a\n * route error carries (`routeError`), if it carries one.\n */\nexport function errorRequestId(error: unknown): string | undefined {\n\tif (typeof error !== 'object' || error === null) return undefined;\n\tconst { data: body } = error as { data?: unknown };\n\tif (typeof body !== 'object' || body === null) return undefined;\n\tconst { requestId } = body as { requestId?: unknown };\n\treturn typeof requestId === 'string' && requestId ? requestId : undefined;\n}\n",
7
+ "import { isNamed } from './api-error';\n\n/** A reply of a REST/OpenAPI client, as far as `problemError` reads it: `{ status, data }`. */\nexport interface ProblemReply {\n\treadonly status: number;\n\t/** The parsed body; a problem document (RFC 9457) when the API refused. */\n\treadonly data?: unknown;\n}\n\nexport interface ProblemErrorOptions {\n\t/** The `x-request-id` the API answered (`requestIdOf(response)`). */\n\trequestId?: string | undefined;\n}\n\n/** A refusal read from a REST API's RFC 9457 problem reply. */\nexport interface ProblemErrorLike extends Error {\n\t/** The HTTP status of the reply. */\n\treadonly status: number;\n\t/** The problem's `title`, else `Error <status>`. */\n\treadonly title: string;\n\t/** The problem's `detail`, when it has one. */\n\treadonly detail?: string | undefined;\n\t/** The problem's `type` URI, when it has one. */\n\treadonly type?: string | undefined;\n\t/** The problem's `instance` URI, when it has one. */\n\treadonly instance?: string | undefined;\n\t/** The id the API logged the request under, when the caller kept it. */\n\trequestId?: string | undefined;\n}\n\nconst text = (value: unknown): string | undefined =>\n\ttypeof value === 'string' && value ? value : undefined;\n\n/**\n * The error of an RFC 9457 problem reply. Its `message` is the problem's\n * `detail`, else its `title`, else `Error <status>`.\n */\nexport class ProblemError extends Error implements ProblemErrorLike {\n\toverride readonly name = 'ProblemError';\n\treadonly status: number;\n\treadonly title: string;\n\treadonly detail: string | undefined;\n\treadonly type: string | undefined;\n\treadonly instance: string | undefined;\n\trequestId: string | undefined;\n\n\tconstructor(reply: ProblemReply, { requestId }: ProblemErrorOptions = {}) {\n\t\tconst body =\n\t\t\ttypeof reply.data === 'object' && reply.data !== null\n\t\t\t\t? (reply.data as {\n\t\t\t\t\t\ttitle?: unknown;\n\t\t\t\t\t\tdetail?: unknown;\n\t\t\t\t\t\ttype?: unknown;\n\t\t\t\t\t\tinstance?: unknown;\n\t\t\t\t\t})\n\t\t\t\t: {};\n\t\tconst title = text(body.title) ?? `Error ${reply.status}`;\n\t\tconst detail = text(body.detail);\n\t\tsuper(detail ?? title);\n\t\tthis.status = reply.status;\n\t\tthis.title = title;\n\t\tthis.detail = detail;\n\t\tthis.type = text(body.type);\n\t\tthis.instance = text(body.instance);\n\t\tthis.requestId = requestId;\n\t}\n}\n\n/**\n * Turns a REST/OpenAPI client's `{ status, data }` reply into a\n * `ProblemError`; a body that is not a problem document gives `Error <status>`.\n */\nexport function problemError(\n\treply: ProblemReply,\n\toptions?: ProblemErrorOptions,\n): ProblemError {\n\treturn new ProblemError(reply, options);\n}\n\n/**\n * Whether `error` is a `ProblemError`, told by its name and a numeric\n * `status`, never `instanceof`, so it holds across two copies of the package.\n */\nexport function isProblemErrorLike(error: unknown): error is ProblemErrorLike {\n\treturn (\n\t\tisNamed(error, 'ProblemError') &&\n\t\ttypeof (error as { status?: unknown }).status === 'number'\n\t);\n}\n",
8
+ "/** The header an API echoes on every response: the id its logs carry. */\nexport const REQUEST_ID_HEADER = 'x-request-id';\n\n/** The request id a response carries, if the API sent one. */\nexport function requestIdOf(response: Response): string | undefined {\n\treturn response.headers.get(REQUEST_ID_HEADER) || undefined;\n}\n"
9
+ ],
10
+ "mappings": ";AA+DO,IAAM,UAAU,CAAC,OAAgB,SACvC,iBAAiB,SAAS,MAAM,SAAS;AAQnC,SAAS,eAAc,CAAC,OAAuC;AAAA,EACrE,OACC,QAAQ,OAAO,UAAU,KACzB,MAAM,QAAS,MAA+B,MAAM,KACpD,OAAQ,MAA+B,WAAW;AAAA;AAS7C,SAAS,eAAc,CAAC,OAAuC;AAAA,EACrE,OACC,gBAAe,KAAK,KACpB,MAAM,WAAW,OACjB,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,SAAS,uBAAuB;AAAA;AAStC,SAAS,YAAW,CAC1B,YACS;AAAA,EACT,MAAM,UAAU,YAAY,QAAQ,WAAW,YAAY;AAAA,EAC3D,IAAI,YAAY;AAAA,IAAW,OAAO,KAAK,IAAI,GAAG,OAAO,OAAO,KAAK,CAAC;AAAA,EAClE,MAAM,UAAU,YAAY,QAAQ,cAAc,YAAY;AAAA,EAC9D,OAA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etcher-promise.ts
6
+ import { useCallback, useEffect, useRef } from "react";
7
+ class FetcherPromiseAborted2 extends Error {
8
+ name = "FetcherPromiseAborted";
9
+ reason;
10
+ constructor(reason) {
11
+ super(reason === "superseded" ? "useFetcherPromise: a newer call replaced this one before the fetcher answered" : "useFetcherPromise: the component unmounted before the fetcher answered");
12
+ this.reason = reason;
13
+ }
14
+ }
15
+
16
+ class FetcherPromiseNoAnswer2 extends Error {
17
+ name = "FetcherPromiseNoAnswer";
18
+ constructor() {
19
+ super("useFetcherPromise: the submission ended without a new answer (the action answered null, undefined or the same data)");
20
+ }
21
+ }
22
+ function useFetcherPromise2(fetcher, options = {}) {
23
+ const waiting = useRef(null);
24
+ const refusal = useRef(options.refusal);
25
+ refusal.current = options.refusal;
26
+ useFetcherAnswer2(fetcher, (answer) => {
27
+ const pending = waiting.current;
28
+ if (!pending)
29
+ return;
30
+ waiting.current = null;
31
+ let refused;
32
+ try {
33
+ refused = refusal.current?.(answer);
34
+ } catch (error) {
35
+ pending.reject(error);
36
+ return;
37
+ }
38
+ if (refused === undefined)
39
+ pending.resolve(answer);
40
+ else
41
+ pending.reject(typeof refused === "string" ? new Error(refused) : refused);
42
+ });
43
+ const busy = useRef(false);
44
+ const lastWaiting = useRef(null);
45
+ useEffect(() => {
46
+ const pending = waiting.current;
47
+ if (pending !== lastWaiting.current) {
48
+ lastWaiting.current = pending;
49
+ busy.current = false;
50
+ }
51
+ if (!pending)
52
+ return;
53
+ if (fetcher.state !== "idle") {
54
+ busy.current = true;
55
+ return;
56
+ }
57
+ if (!busy.current)
58
+ return;
59
+ busy.current = false;
60
+ waiting.current = null;
61
+ pending.reject(new FetcherPromiseNoAnswer2);
62
+ });
63
+ useEffect(() => () => {
64
+ const pending = waiting.current;
65
+ waiting.current = null;
66
+ pending?.reject(new FetcherPromiseAborted2("unmounted"));
67
+ }, []);
68
+ return useCallback((submit) => {
69
+ waiting.current?.reject(new FetcherPromiseAborted2("superseded"));
70
+ return new Promise((resolve, reject) => {
71
+ const mine = { resolve, reject };
72
+ waiting.current = mine;
73
+ const fail = (error) => {
74
+ if (waiting.current === mine)
75
+ waiting.current = null;
76
+ reject(error);
77
+ };
78
+ try {
79
+ Promise.resolve(submit()).catch(fail);
80
+ } catch (error) {
81
+ fail(error);
82
+ }
83
+ });
84
+ }, []);
85
+ }
86
+
87
+ export { FetcherPromiseAborted2, FetcherPromiseNoAnswer2, useFetcherPromise2 };
88
+
89
+ //# debugId=168A29751AB1357864756E2164756E21
90
+ //# sourceMappingURL=index-xd5aqy3g.js.map