@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,133 @@
1
+ // src/media/client/error.ts
2
+ var BY_STATUS = {
3
+ 401: "unauthenticated",
4
+ 403: "forbidden",
5
+ 411: "length_required",
6
+ 413: "too_large",
7
+ 415: "type_refused",
8
+ 429: "rate_limited",
9
+ 502: "unavailable",
10
+ 503: "unavailable",
11
+ 504: "timeout"
12
+ };
13
+ var reasonOf = (status) => BY_STATUS[status] ?? "failed";
14
+
15
+ class MediaUploadError extends Error {
16
+ reason;
17
+ status;
18
+ code;
19
+ retryAfter;
20
+ body;
21
+ name = "MediaUploadError";
22
+ constructor(reason, status, code, retryAfter, body) {
23
+ super(`media upload failed: ${reason}${status ? ` (${status})` : ""}`);
24
+ this.reason = reason;
25
+ this.status = status;
26
+ this.code = code;
27
+ this.retryAfter = retryAfter;
28
+ this.body = body;
29
+ }
30
+ }
31
+ function parseRetryAfter(value, now = Date.now()) {
32
+ const text = value?.trim();
33
+ if (!text)
34
+ return;
35
+ if (/^\d+$/.test(text))
36
+ return Number(text);
37
+ if (!/[a-z]/i.test(text))
38
+ return;
39
+ const at = Date.parse(text);
40
+ if (Number.isNaN(at))
41
+ return;
42
+ return Math.max(0, Math.ceil((at - now) / 1000));
43
+ }
44
+ // src/media/client/upload.ts
45
+ var isResult = (value) => typeof value === "object" && value !== null && typeof value.key === "string" && value.key !== "" && typeof value.contentType === "string" && typeof value.size === "number";
46
+ function bodyOf(text) {
47
+ try {
48
+ const body = JSON.parse(text);
49
+ return typeof body === "object" && body !== null && !Array.isArray(body) ? body : undefined;
50
+ } catch {
51
+ return;
52
+ }
53
+ }
54
+ function queryOf(query) {
55
+ const params = new URLSearchParams;
56
+ for (const [name, value] of Object.entries(query ?? {})) {
57
+ if (value !== undefined && value !== null)
58
+ params.set(name, String(value));
59
+ }
60
+ const text = params.toString();
61
+ return text ? `?${text}` : "";
62
+ }
63
+ function uploadMedia(kind, file, options = {}) {
64
+ const {
65
+ onProgress,
66
+ signal,
67
+ basePath = "/media",
68
+ headers,
69
+ timeoutMs,
70
+ query
71
+ } = options;
72
+ return new Promise((resolve, reject) => {
73
+ if (signal?.aborted) {
74
+ reject(new MediaUploadError("aborted", 0));
75
+ return;
76
+ }
77
+ const xhr = new XMLHttpRequest;
78
+ const onAbort = () => xhr.abort();
79
+ const done = () => signal?.removeEventListener("abort", onAbort);
80
+ const fail = (error) => {
81
+ done();
82
+ reject(error);
83
+ };
84
+ xhr.open("PUT", `${basePath.replace(/\/+$/, "")}/${encodeURIComponent(kind)}${queryOf(query)}`);
85
+ xhr.setRequestHeader("content-type", file.type || "application/octet-stream");
86
+ if (timeoutMs)
87
+ xhr.timeout = timeoutMs;
88
+ for (const [name, value] of Object.entries(headers ?? {})) {
89
+ xhr.setRequestHeader(name, value);
90
+ }
91
+ xhr.responseType = "text";
92
+ xhr.upload.onprogress = (event) => {
93
+ if (event.lengthComputable && event.total > 0) {
94
+ onProgress?.(Math.min(100, Math.floor(event.loaded / event.total * 100)));
95
+ }
96
+ };
97
+ xhr.onerror = () => fail(new MediaUploadError("network", 0));
98
+ xhr.ontimeout = () => fail(new MediaUploadError("timeout", 0));
99
+ xhr.onabort = () => fail(new MediaUploadError("aborted", 0));
100
+ xhr.onload = () => {
101
+ const text = xhr.responseText;
102
+ if (xhr.status < 200 || xhr.status >= 300) {
103
+ const refusal = bodyOf(text);
104
+ const { error: code } = refusal ?? {};
105
+ fail(new MediaUploadError(reasonOf(xhr.status), xhr.status, typeof code === "string" ? code : undefined, parseRetryAfter(xhr.getResponseHeader("retry-after")), refusal));
106
+ return;
107
+ }
108
+ let body;
109
+ try {
110
+ body = JSON.parse(text);
111
+ } catch {
112
+ body = undefined;
113
+ }
114
+ if (!isResult(body)) {
115
+ fail(new MediaUploadError("invalid_response", xhr.status));
116
+ return;
117
+ }
118
+ done();
119
+ onProgress?.(100);
120
+ resolve(body);
121
+ };
122
+ signal?.addEventListener("abort", onAbort, { once: true });
123
+ xhr.send(file);
124
+ });
125
+ }
126
+ export {
127
+ MediaUploadError,
128
+ reasonOf,
129
+ uploadMedia
130
+ };
131
+
132
+ //# debugId=304E5E40BEF598CF64756E2164756E21
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/media/client/error.ts", "../src/media/client/upload.ts"],
4
+ "sourcesContent": [
5
+ "/** Why an upload failed, from the status the app's media route answered. */\nexport type MediaUploadReason =\n\t| 'unauthenticated' // 401\n\t| 'forbidden' // 403\n\t| 'length_required' // 411\n\t| 'too_large' // 413\n\t| 'type_refused' // 415\n\t| 'rate_limited' // 429\n\t| 'unavailable' // 502, 503\n\t| 'timeout' // 504, or `timeoutMs` passed\n\t| 'failed' // any other refusal\n\t| 'network' // the request never got an answer\n\t| 'invalid_response' // a 2xx whose body is not `{ key, contentType, size }`\n\t| 'aborted'; // the signal fired\n\nconst BY_STATUS: Record<number, MediaUploadReason> = {\n\t401: 'unauthenticated',\n\t403: 'forbidden',\n\t411: 'length_required',\n\t413: 'too_large',\n\t415: 'type_refused',\n\t429: 'rate_limited',\n\t502: 'unavailable',\n\t503: 'unavailable',\n\t504: 'timeout',\n};\n\n/** The reason a refusal status stands for. */\nexport const reasonOf = (status: number): MediaUploadReason =>\n\tBY_STATUS[status] ?? 'failed';\n\n/**\n * What `uploadMedia` rejects with. `status` is the HTTP status, `0` when there\n * was none (`network`, `aborted`); `code` is the `error` of the JSON refusal\n * when the answer had one, and `body` the whole JSON refusal (`{ error,\n * reason, ... }`, any shape the route's `onRefusal` gave it), `undefined` when\n * the answer was no JSON object. `retryAfter` is the wait in seconds the answer's\n * `Retry-After` header states (a 429 or 503 usually sends it), `undefined`\n * when the header is absent or invalid.\n */\nexport class MediaUploadError extends Error {\n\toverride readonly name = 'MediaUploadError';\n\tconstructor(\n\t\treadonly reason: MediaUploadReason,\n\t\treadonly status: number,\n\t\treadonly code?: string,\n\t\treadonly retryAfter?: number,\n\t\treadonly body?: Record<string, unknown>,\n\t) {\n\t\tsuper(`media upload failed: ${reason}${status ? ` (${status})` : ''}`);\n\t}\n}\n\n/**\n * The seconds a `Retry-After` header value asks to wait: whole seconds, or an\n * HTTP date (the seconds left until it, `0` once past). `undefined` when the\n * value is absent or neither.\n */\nexport function parseRetryAfter(\n\tvalue: string | null | undefined,\n\tnow: number = Date.now(),\n): number | undefined {\n\tconst text = value?.trim();\n\tif (!text) return undefined;\n\tif (/^\\d+$/.test(text)) return Number(text);\n\tif (!/[a-z]/i.test(text)) return undefined; // `-5` or `1.5` is no date\n\tconst at = Date.parse(text);\n\tif (Number.isNaN(at)) return undefined;\n\treturn Math.max(0, Math.ceil((at - now) / 1000));\n}\n",
6
+ "import { MediaUploadError, parseRetryAfter, reasonOf } from './error';\n\n/** What the API stored, as `PUT /media/<kind>` answers it. */\nexport type MediaUploadResult = {\n\tkey: string;\n\tcontentType: string;\n\tsize: number;\n};\n\nexport type UploadMediaOptions = {\n\t/** Called with 0 to 100 as the body goes up, and with 100 once stored. */\n\tonProgress?: (percent: number) => void;\n\t/** Aborts the request; the promise rejects with reason `aborted`. */\n\tsignal?: AbortSignal;\n\t/** Where the media route is mounted on the app, `/media` by default. */\n\tbasePath?: string;\n\t/** Milliseconds the whole request may take; past it, reason `timeout`. None by default. */\n\ttimeoutMs?: number;\n\t/** Extra request headers, such as one the route's `requireHeaders` demands. */\n\theaders?: Record<string, string>;\n\t/**\n\t * Query parameters added to the URL (`{ fx: 0.4 }` gives `?fx=0.4`), for a\n\t * route that reads them (see `forwardQuery`). `undefined` and `null` values\n\t * are left out.\n\t */\n\tquery?: Record<string, string | number | boolean | null | undefined>;\n};\n\nconst isResult = (value: unknown): value is MediaUploadResult =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\ttypeof (value as MediaUploadResult).key === 'string' &&\n\t(value as MediaUploadResult).key !== '' &&\n\ttypeof (value as MediaUploadResult).contentType === 'string' &&\n\ttypeof (value as MediaUploadResult).size === 'number';\n\nfunction bodyOf(text: string): Record<string, unknown> | undefined {\n\ttry {\n\t\tconst body: unknown = JSON.parse(text);\n\t\treturn typeof body === 'object' && body !== null && !Array.isArray(body)\n\t\t\t? (body as Record<string, unknown>)\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction queryOf(query: UploadMediaOptions['query']): string {\n\tconst params = new URLSearchParams();\n\tfor (const [name, value] of Object.entries(query ?? {})) {\n\t\tif (value !== undefined && value !== null) params.set(name, String(value));\n\t}\n\tconst text = params.toString();\n\treturn text ? `?${text}` : '';\n}\n\n/**\n * Uploads `file` to the app's media route with `PUT <basePath>/<kind>`, on\n * `XMLHttpRequest` since `fetch` cannot report upload progress. Resolves with\n * the stored file's `{ key, contentType, size }`; rejects with a\n * `MediaUploadError`.\n */\nexport function uploadMedia(\n\tkind: string,\n\tfile: Blob,\n\toptions: UploadMediaOptions = {},\n): Promise<MediaUploadResult> {\n\tconst {\n\t\tonProgress,\n\t\tsignal,\n\t\tbasePath = '/media',\n\t\theaders,\n\t\ttimeoutMs,\n\t\tquery,\n\t} = options;\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new MediaUploadError('aborted', 0));\n\t\t\treturn;\n\t\t}\n\t\tconst xhr = new XMLHttpRequest();\n\t\tconst onAbort = () => xhr.abort();\n\t\tconst done = () => signal?.removeEventListener('abort', onAbort);\n\t\tconst fail = (error: MediaUploadError) => {\n\t\t\tdone();\n\t\t\treject(error);\n\t\t};\n\n\t\txhr.open(\n\t\t\t'PUT',\n\t\t\t`${basePath.replace(/\\/+$/, '')}/${encodeURIComponent(kind)}${queryOf(query)}`,\n\t\t);\n\t\txhr.setRequestHeader(\n\t\t\t'content-type',\n\t\t\tfile.type || 'application/octet-stream',\n\t\t);\n\t\tif (timeoutMs) xhr.timeout = timeoutMs;\n\t\tfor (const [name, value] of Object.entries(headers ?? {})) {\n\t\t\txhr.setRequestHeader(name, value);\n\t\t}\n\t\txhr.responseType = 'text';\n\n\t\txhr.upload.onprogress = (event) => {\n\t\t\tif (event.lengthComputable && event.total > 0) {\n\t\t\t\tonProgress?.(\n\t\t\t\t\tMath.min(100, Math.floor((event.loaded / event.total) * 100)),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\txhr.onerror = () => fail(new MediaUploadError('network', 0));\n\t\txhr.ontimeout = () => fail(new MediaUploadError('timeout', 0));\n\t\txhr.onabort = () => fail(new MediaUploadError('aborted', 0));\n\t\txhr.onload = () => {\n\t\t\tconst text = xhr.responseText;\n\t\t\tif (xhr.status < 200 || xhr.status >= 300) {\n\t\t\t\tconst refusal = bodyOf(text);\n\t\t\t\tconst { error: code } = refusal ?? {};\n\t\t\t\tfail(\n\t\t\t\t\tnew MediaUploadError(\n\t\t\t\t\t\treasonOf(xhr.status),\n\t\t\t\t\t\txhr.status,\n\t\t\t\t\t\ttypeof code === 'string' ? code : undefined,\n\t\t\t\t\t\tparseRetryAfter(xhr.getResponseHeader('retry-after')),\n\t\t\t\t\t\trefusal,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet body: unknown;\n\t\t\ttry {\n\t\t\t\tbody = JSON.parse(text);\n\t\t\t} catch {\n\t\t\t\tbody = undefined;\n\t\t\t}\n\t\t\tif (!isResult(body)) {\n\t\t\t\tfail(new MediaUploadError('invalid_response', xhr.status));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdone();\n\t\t\tonProgress?.(100);\n\t\t\tresolve(body);\n\t\t};\n\n\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t\txhr.send(file);\n\t});\n}\n"
7
+ ],
8
+ "mappings": "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",
9
+ "debugId": "304E5E40BEF598CF64756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,32 @@
1
+ /** What the API stored, as `PUT /media/<kind>` answers it. */
2
+ export type MediaUploadResult = {
3
+ key: string;
4
+ contentType: string;
5
+ size: number;
6
+ };
7
+ export type UploadMediaOptions = {
8
+ /** Called with 0 to 100 as the body goes up, and with 100 once stored. */
9
+ onProgress?: (percent: number) => void;
10
+ /** Aborts the request; the promise rejects with reason `aborted`. */
11
+ signal?: AbortSignal;
12
+ /** Where the media route is mounted on the app, `/media` by default. */
13
+ basePath?: string;
14
+ /** Milliseconds the whole request may take; past it, reason `timeout`. None by default. */
15
+ timeoutMs?: number;
16
+ /** Extra request headers, such as one the route's `requireHeaders` demands. */
17
+ headers?: Record<string, string>;
18
+ /**
19
+ * Query parameters added to the URL (`{ fx: 0.4 }` gives `?fx=0.4`), for a
20
+ * route that reads them (see `forwardQuery`). `undefined` and `null` values
21
+ * are left out.
22
+ */
23
+ query?: Record<string, string | number | boolean | null | undefined>;
24
+ };
25
+ /**
26
+ * Uploads `file` to the app's media route with `PUT <basePath>/<kind>`, on
27
+ * `XMLHttpRequest` since `fetch` cannot report upload progress. Resolves with
28
+ * the stored file's `{ key, contentType, size }`; rejects with a
29
+ * `MediaUploadError`.
30
+ */
31
+ export declare function uploadMedia(kind: string, file: Blob, options?: UploadMediaOptions): Promise<MediaUploadResult>;
32
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/media/client/upload.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAChC,0EAA0E;IAC1E,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,qEAAqE;IACrE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACrE,CAAC;AA8BF;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,kBAAuB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAgF5B"}
@@ -0,0 +1,14 @@
1
+ import type { MediaProxyOptions } from './options';
2
+ import { type Target } from './path';
3
+ export interface Upstream {
4
+ readonly method: string;
5
+ readonly headers: Headers;
6
+ readonly body?: ReadableStream | null;
7
+ }
8
+ /**
9
+ * Sends the request to the API and answers with its response. One
10
+ * `AbortController` is the client's way out (it aborts when the client leaves),
11
+ * the deadline's and the answer's: whichever fires cuts the upstream request.
12
+ */
13
+ export declare function forward(options: MediaProxyOptions<never>, request: Request, target: Target, init: Upstream): Promise<Response>;
14
+ //# sourceMappingURL=forward.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward.d.ts","sourceRoot":"","sources":["../../src/media/forward.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAc/C,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACtC;AAqBD;;;;GAIG;AACH,wBAAsB,OAAO,CAC5B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EACjC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,GACZ,OAAO,CAAC,QAAQ,CAAC,CAwDnB"}
@@ -0,0 +1,11 @@
1
+ import type { MediaArgs, MediaProxyOptions } from './options';
2
+ /** Request headers that reach the API, besides the proxy's own: a conditional or ranged read, an upload's type and length. */
3
+ export declare const READ_HEADERS: readonly ["range", "if-none-match", "if-range", "accept"];
4
+ export declare const WRITE_HEADERS: readonly ["content-type", "content-length"];
5
+ /** The API's response headers the browser may see. */
6
+ export declare function answerHeaders(upstream: Headers): Headers;
7
+ /** The headers sent to the API, or the 500 that says the app's `headers` or `getToken` is broken. */
8
+ export declare function build(options: MediaProxyOptions<never>, args: MediaArgs, token: string | undefined, forwarded: readonly string[]): Promise<Headers | Response>;
9
+ /** The session's token: `undefined` for none, or the 500 for a `getToken` that throws. */
10
+ export declare function tokenOf(options: MediaProxyOptions<never>, request: Request): Promise<string | undefined | Response>;
11
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/media/headers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9D,8HAA8H;AAC9H,eAAO,MAAM,YAAY,2DAKf,CAAC;AACX,eAAO,MAAM,aAAa,6CAA8C,CAAC;AAuBzE,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAQxD;AAED,qGAAqG;AACrG,wBAAsB,KAAK,CAC1B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EACjC,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC,CAoB7B;AAED,0FAA0F;AAC1F,wBAAsB,OAAO,CAC5B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EACjC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC,CAMxC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@softistx/alxia-react-router/media`: `@softistx/alxia-media`'s routes served on the app's
3
+ * own origin, relayed to the API as a resource route. It imports nothing
4
+ * (web APIs only), so it adds no peer.
5
+ */
6
+ export type { MediaArgs, MediaHookResult, MediaKindLimit, MediaProxyOptions, MediaRefusal, MediaSuccess, } from './options';
7
+ export { proxyMediaRead } from './read';
8
+ export { proxyMediaWrite } from './write';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/media/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EACX,SAAS,EACT,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,396 @@
1
+ import {
2
+ usableToken,
3
+ extraHeaders
4
+ } from "../chunks/index-d42p3mdp.js";
5
+ import {
6
+ isCrossSite
7
+ } from "../chunks/index-mscfme4r.js";
8
+
9
+ // src/media/refusal.ts
10
+ var ownRefusals = new WeakSet;
11
+ function refuse(status, code, extras = {}, headers = {}) {
12
+ const response = new Response(JSON.stringify({ error: code, ...extras }), {
13
+ status,
14
+ headers: {
15
+ "content-type": "application/json",
16
+ "cache-control": "no-store",
17
+ "x-content-type-options": "nosniff",
18
+ ...headers
19
+ }
20
+ });
21
+ ownRefusals.add(response);
22
+ return response;
23
+ }
24
+ var notFound = () => refuse(404, "not_found");
25
+
26
+ // src/media/headers.ts
27
+ var READ_HEADERS = [
28
+ "range",
29
+ "if-none-match",
30
+ "if-range",
31
+ "accept"
32
+ ];
33
+ var WRITE_HEADERS = ["content-type", "content-length"];
34
+ var ANSWERED = new Set([
35
+ "content-type",
36
+ "content-length",
37
+ "content-range",
38
+ "accept-ranges",
39
+ "etag",
40
+ "last-modified",
41
+ "cache-control",
42
+ "content-disposition",
43
+ "x-content-type-options",
44
+ "cross-origin-resource-policy",
45
+ "content-security-policy",
46
+ "retry-after",
47
+ "vary"
48
+ ]);
49
+ function answerHeaders(upstream) {
50
+ const headers = new Headers;
51
+ for (const [name, value] of upstream) {
52
+ if (ANSWERED.has(name))
53
+ headers.append(name, value);
54
+ }
55
+ if (upstream.has("content-encoding"))
56
+ headers.delete("content-length");
57
+ return headers;
58
+ }
59
+ async function build(options, args, token, forwarded) {
60
+ try {
61
+ const out = await extraHeaders(options.headers, args.request, args);
62
+ for (const name of forwarded) {
63
+ const value = args.request.headers.get(name);
64
+ if (value !== null)
65
+ out.set(name, value);
66
+ }
67
+ if (token !== undefined)
68
+ out.set("authorization", `Bearer ${token}`);
69
+ return out;
70
+ } catch {
71
+ return misconfigured("The proxy's upstream headers are not valid (a name or a value no header can hold, or the headers function threw).");
72
+ }
73
+ }
74
+ async function tokenOf(options, request) {
75
+ try {
76
+ return usableToken(await options.getToken(request));
77
+ } catch {
78
+ return misconfigured("The proxy's getToken threw.");
79
+ }
80
+ }
81
+ function misconfigured(message) {
82
+ return refuse(500, "proxy_misconfigured", { message });
83
+ }
84
+
85
+ // src/media/path.ts
86
+ var KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
87
+ var SIZE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
88
+ var prefixOf = (value, fallback) => (value ?? fallback).replace(/\/+$/, "");
89
+ function parse(request, options) {
90
+ const prefix = prefixOf(options.prefix, "/media");
91
+ const { pathname } = new URL(request.url);
92
+ if (!pathname.startsWith(`${prefix}/`))
93
+ return;
94
+ const [kind, key, size, ...extra] = pathname.slice(prefix.length + 1).split("/");
95
+ if (kind === undefined || !Object.hasOwn(options.kinds, kind)) {
96
+ return;
97
+ }
98
+ const limit = options.kinds[kind];
99
+ if (key === undefined)
100
+ return { kind, limit, rest: "", key: undefined };
101
+ if (extra.length > 0 || !KEY.test(key))
102
+ return;
103
+ if (size === undefined)
104
+ return { kind, limit, rest: `/${key}`, key };
105
+ if (!SIZE.test(size))
106
+ return;
107
+ return { kind, limit, rest: `/${key}/${size}`, key };
108
+ }
109
+ function checked(options, args, methods) {
110
+ const { request } = args;
111
+ if (!methods.includes(request.method)) {
112
+ return refuse(405, "method_not_allowed", {}, { allow: methods.join(", ") });
113
+ }
114
+ const origin = typeof options.origin === "function" ? options.origin() : options.origin;
115
+ if (isCrossSite(request, origin))
116
+ return refuse(403, "forbidden");
117
+ return parse(request, options) ?? notFound();
118
+ }
119
+
120
+ // src/media/forward.ts
121
+ var MAX_TIMER = 2147483647;
122
+ var validTimeout = (wait) => wait === Number.POSITIVE_INFINITY || Number.isFinite(wait) && wait > 0 && wait <= MAX_TIMER;
123
+ var TIMEOUT = 60000;
124
+ function answer(upstream, abort) {
125
+ if (upstream.status >= 300 && upstream.status < 400 && upstream.status !== 304) {
126
+ abort.abort();
127
+ return refuse(502, "unavailable");
128
+ }
129
+ const headers = answerHeaders(upstream.headers);
130
+ if (upstream.body === null || upstream.status === 304) {
131
+ abort.abort();
132
+ return new Response(null, { status: upstream.status, headers });
133
+ }
134
+ return new Response(upstream.body, { status: upstream.status, headers });
135
+ }
136
+ async function forward(options, request, target, init) {
137
+ if (options.timeout !== undefined && !validTimeout(options.timeout)) {
138
+ return refuse(500, "proxy_misconfigured", {
139
+ message: "The proxy timeout must be Infinity or a number of milliseconds above 0 and at most 2147483647."
140
+ });
141
+ }
142
+ const abort = new AbortController;
143
+ if (request.signal.aborted)
144
+ abort.abort();
145
+ else {
146
+ request.signal.addEventListener("abort", () => abort.abort(), {
147
+ once: true
148
+ });
149
+ }
150
+ const url = new URL(`${prefixOf(options.apiPrefix ?? options.prefix, "/media")}/${target.kind}${target.rest}`, options.api);
151
+ const query = options.forwardQuery;
152
+ if (query !== undefined) {
153
+ const incoming = new URL(request.url).searchParams;
154
+ for (const [name, value] of incoming) {
155
+ if (query === true || query.includes(name)) {
156
+ url.searchParams.append(name, value);
157
+ }
158
+ }
159
+ }
160
+ const upstreamFetch = options.fetch ?? ((r) => fetch(r));
161
+ let expired = false;
162
+ const wait = options.timeout ?? TIMEOUT;
163
+ const timer = wait === Number.POSITIVE_INFINITY ? undefined : setTimeout(() => {
164
+ expired = true;
165
+ abort.abort();
166
+ }, wait);
167
+ let upstream;
168
+ try {
169
+ upstream = await upstreamFetch(new Request(url, {
170
+ method: init.method,
171
+ headers: init.headers,
172
+ signal: abort.signal,
173
+ redirect: "manual",
174
+ ...init.body ? { body: init.body, duplex: "half" } : {}
175
+ }));
176
+ } catch {
177
+ return expired ? refuse(504, "unavailable") : refuse(502, "unavailable");
178
+ } finally {
179
+ if (timer !== undefined)
180
+ clearTimeout(timer);
181
+ }
182
+ return answer(upstream, abort);
183
+ }
184
+
185
+ // src/media/respond.ts
186
+ var MAX_BODY = 65536;
187
+ var isJson = (headers) => /json/i.test(headers.get("content-type") ?? "");
188
+ function codeOf(body) {
189
+ const text = (value, name) => {
190
+ if (typeof value !== "object" || value === null)
191
+ return;
192
+ const found = value[name];
193
+ return typeof found === "string" ? found : undefined;
194
+ };
195
+ const errors = body?.["errors"];
196
+ const first = Array.isArray(errors) ? errors[0] : undefined;
197
+ return text(body, "error") ?? text(body, "code") ?? text(first, "code") ?? text(first, "error");
198
+ }
199
+ async function readCapped(response) {
200
+ const source = response.body;
201
+ const untouched = {
202
+ body: undefined,
203
+ keep: () => response,
204
+ cancel: async () => {
205
+ await source?.cancel();
206
+ }
207
+ };
208
+ const declared = Number(response.headers.get("content-length") ?? 0);
209
+ if (source === null || !isJson(response.headers) || declared > MAX_BODY) {
210
+ return untouched;
211
+ }
212
+ const reader = source.getReader();
213
+ const chunks = [];
214
+ let total = 0;
215
+ for (;; ) {
216
+ const { done, value } = await reader.read();
217
+ if (done)
218
+ break;
219
+ chunks.push(value);
220
+ total += value.byteLength;
221
+ if (total > MAX_BODY) {
222
+ const rest = new ReadableStream({
223
+ start(controller) {
224
+ for (const chunk of chunks)
225
+ controller.enqueue(chunk);
226
+ },
227
+ async pull(controller) {
228
+ const next = await reader.read();
229
+ if (next.done)
230
+ controller.close();
231
+ else
232
+ controller.enqueue(next.value);
233
+ },
234
+ cancel: (reason) => reader.cancel(reason)
235
+ });
236
+ return {
237
+ body: undefined,
238
+ keep: () => new Response(rest, {
239
+ status: response.status,
240
+ headers: response.headers
241
+ }),
242
+ cancel: () => reader.cancel()
243
+ };
244
+ }
245
+ }
246
+ const bytes = new Uint8Array(total);
247
+ let at = 0;
248
+ for (const chunk of chunks) {
249
+ bytes.set(chunk, at);
250
+ at += chunk.byteLength;
251
+ }
252
+ let body;
253
+ try {
254
+ body = JSON.parse(new TextDecoder().decode(bytes));
255
+ } catch {}
256
+ return {
257
+ body,
258
+ keep: () => new Response(bytes, {
259
+ status: response.status,
260
+ headers: response.headers
261
+ }),
262
+ cancel: async () => {}
263
+ };
264
+ }
265
+ function toResponse(result, statusOf, headers) {
266
+ if (result instanceof Response)
267
+ return result;
268
+ let status = statusOf;
269
+ const out = new Headers(headers);
270
+ out.delete("content-length");
271
+ if (status === 204 || status === 205)
272
+ status = 200;
273
+ out.set("content-type", "application/json");
274
+ if (status >= 400)
275
+ out.set("cache-control", "no-store");
276
+ return new Response(JSON.stringify(result), { status, headers: out });
277
+ }
278
+ async function respond(options, request, write, relay) {
279
+ const response = await relay();
280
+ const refused = response.status >= 400;
281
+ const hook = refused ? options.onRefusal : write && response.status >= 200 && response.status < 300 ? options.onSuccess : undefined;
282
+ if (hook === undefined)
283
+ return response;
284
+ let read;
285
+ try {
286
+ read = await readCapped(response);
287
+ } catch {
288
+ return refuse(502, "unavailable");
289
+ }
290
+ const common = {
291
+ status: response.status,
292
+ body: read.body,
293
+ headers: response.headers
294
+ };
295
+ let result;
296
+ try {
297
+ result = refused ? await options.onRefusal?.({
298
+ ...common,
299
+ source: ownRefusals.has(response) ? "proxy" : "api",
300
+ code: codeOf(read.body)
301
+ }, request) : await options.onSuccess?.(common, request);
302
+ } catch {
303
+ await read.cancel().catch(() => {});
304
+ return refuse(500, "proxy_misconfigured", {
305
+ message: refused ? "The proxy's onRefusal threw." : "The proxy's onSuccess threw."
306
+ });
307
+ }
308
+ if (result !== undefined && result !== null) {
309
+ await read.cancel().catch(() => {});
310
+ return toResponse(result, response.status, response.headers);
311
+ }
312
+ return read.keep();
313
+ }
314
+
315
+ // src/media/read.ts
316
+ async function proxyMediaRead(args, options) {
317
+ return respond(options, args.request, false, () => relay(args, options));
318
+ }
319
+ async function relay(args, options) {
320
+ const opts = options;
321
+ const target = checked(opts, args, ["GET", "HEAD"]);
322
+ if (target instanceof Response)
323
+ return target;
324
+ if (target.key === undefined)
325
+ return notFound();
326
+ const token = await tokenOf(opts, args.request);
327
+ if (token instanceof Response)
328
+ return token;
329
+ const headers = await build(opts, args, token, READ_HEADERS);
330
+ if (headers instanceof Response)
331
+ return headers;
332
+ return forward(opts, args.request, target, {
333
+ method: args.request.method,
334
+ headers
335
+ });
336
+ }
337
+ // src/media/write.ts
338
+ async function proxyMediaWrite(args, options) {
339
+ return respond(options, args.request, true, () => relay2(args, options));
340
+ }
341
+ async function relay2(args, options) {
342
+ const opts = options;
343
+ const { request } = args;
344
+ const target = checked(opts, args, ["PUT", "DELETE"]);
345
+ if (target instanceof Response)
346
+ return target;
347
+ const isPut = request.method === "PUT";
348
+ if (isPut !== (target.key === undefined))
349
+ return notFound();
350
+ if (target.rest.split("/").length > 2)
351
+ return notFound();
352
+ try {
353
+ for (const [name, expected] of Object.entries(opts.requireHeaders ?? {})) {
354
+ if (request.headers.get(name) !== expected) {
355
+ return refuse(403, "header_required");
356
+ }
357
+ }
358
+ } catch {
359
+ return refuse(500, "proxy_misconfigured", {
360
+ message: "The proxy's requireHeaders names a header no request can hold."
361
+ });
362
+ }
363
+ const token = await tokenOf(opts, request);
364
+ if (token instanceof Response)
365
+ return token;
366
+ if (token === undefined)
367
+ return refuse(401, "unauthenticated");
368
+ if (isPut) {
369
+ const declared = request.headers.get("content-length");
370
+ if (declared === null) {
371
+ if (opts.allowUnsized !== true)
372
+ return refuse(411, "length_required");
373
+ } else {
374
+ if (!/^\d+$/.test(declared))
375
+ return refuse(400, "size_mismatch");
376
+ if (Number(declared) > target.limit.maxBytes) {
377
+ return refuse(413, "too_large", { limit: target.limit.maxBytes });
378
+ }
379
+ }
380
+ }
381
+ const headers = await build(opts, args, token, isPut ? WRITE_HEADERS : []);
382
+ if (headers instanceof Response)
383
+ return headers;
384
+ return forward(opts, request, target, {
385
+ method: request.method,
386
+ headers,
387
+ body: isPut ? request.body : null
388
+ });
389
+ }
390
+ export {
391
+ proxyMediaRead,
392
+ proxyMediaWrite
393
+ };
394
+
395
+ //# debugId=AD04888A858C253D64756E2164756E21
396
+ //# sourceMappingURL=index.js.map