@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.
- package/LICENSE +21 -0
- package/README.md +2085 -2
- package/dist/api-keys/api-keys.d.ts +93 -0
- package/dist/api-keys/api-keys.d.ts.map +1 -0
- package/dist/api-keys/index.d.ts +9 -0
- package/dist/api-keys/index.d.ts.map +1 -0
- package/dist/api-keys/index.js +66 -0
- package/dist/api-keys/index.js.map +10 -0
- package/dist/assets.d.ts +14 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/chunks/index-0786n4qe.js +25 -0
- package/dist/chunks/index-0786n4qe.js.map +10 -0
- package/dist/chunks/index-1nw5yeek.js +169 -0
- package/dist/chunks/index-1nw5yeek.js.map +11 -0
- package/dist/chunks/index-59vhfj6n.js +10 -0
- package/dist/chunks/index-59vhfj6n.js.map +10 -0
- package/dist/chunks/index-5gqcpyyg.js +34 -0
- package/dist/chunks/index-5gqcpyyg.js.map +10 -0
- package/dist/chunks/index-6jf7zpxz.js +119 -0
- package/dist/chunks/index-6jf7zpxz.js.map +11 -0
- package/dist/chunks/index-8as4j8m3.js +340 -0
- package/dist/chunks/index-8as4j8m3.js.map +16 -0
- package/dist/chunks/index-9xv2a8et.js +108 -0
- package/dist/chunks/index-9xv2a8et.js.map +11 -0
- package/dist/chunks/index-ajtvyq35.js +16 -0
- package/dist/chunks/index-ajtvyq35.js.map +10 -0
- package/dist/chunks/index-c55hxgr5.js +124 -0
- package/dist/chunks/index-c55hxgr5.js.map +14 -0
- package/dist/chunks/index-d42p3mdp.js +19 -0
- package/dist/chunks/index-d42p3mdp.js.map +10 -0
- package/dist/chunks/index-gac44rs5.js +42 -0
- package/dist/chunks/index-gac44rs5.js.map +11 -0
- package/dist/chunks/index-j4ktpcke.js +62 -0
- package/dist/chunks/index-j4ktpcke.js.map +10 -0
- package/dist/chunks/index-mscfme4r.js +12 -0
- package/dist/chunks/index-mscfme4r.js.map +10 -0
- package/dist/chunks/index-pghmb2dm.js +30 -0
- package/dist/chunks/index-pghmb2dm.js.map +10 -0
- package/dist/chunks/index-rfr02vg4.js +40 -0
- package/dist/chunks/index-rfr02vg4.js.map +10 -0
- package/dist/chunks/index-sfhshxqz.js +31 -0
- package/dist/chunks/index-sfhshxqz.js.map +10 -0
- package/dist/chunks/index-skwypsjz.js +357 -0
- package/dist/chunks/index-skwypsjz.js.map +12 -0
- package/dist/chunks/index-sxh06ged.js +118 -0
- package/dist/chunks/index-sxh06ged.js.map +11 -0
- package/dist/chunks/index-t2ph23wk.js +96 -0
- package/dist/chunks/index-t2ph23wk.js.map +13 -0
- package/dist/chunks/index-thyabr5n.js +19 -0
- package/dist/chunks/index-thyabr5n.js.map +10 -0
- package/dist/chunks/index-tx36swjx.js +134 -0
- package/dist/chunks/index-tx36swjx.js.map +11 -0
- package/dist/chunks/index-v2z5k640.js +54 -0
- package/dist/chunks/index-v2z5k640.js.map +11 -0
- package/dist/chunks/index-vr82typq.js +23 -0
- package/dist/chunks/index-vr82typq.js.map +11 -0
- package/dist/chunks/index-whj6h5eg.js +9 -0
- package/dist/chunks/index-whj6h5eg.js.map +10 -0
- package/dist/chunks/index-wyypkfdv.js +130 -0
- package/dist/chunks/index-wyypkfdv.js.map +13 -0
- package/dist/chunks/index-xd5aqy3g.js +90 -0
- package/dist/chunks/index-xd5aqy3g.js.map +10 -0
- package/dist/chunks/index-zdbqzcjp.js +97 -0
- package/dist/chunks/index-zdbqzcjp.js.map +12 -0
- package/dist/chunks/index-zyg8amjc.js +23 -0
- package/dist/chunks/index-zyg8amjc.js.map +10 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +215 -0
- package/dist/cli/index.js.map +13 -0
- package/dist/cli/main.d.ts +13 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/reveal.d.ts +18 -0
- package/dist/cli/reveal.d.ts.map +1 -0
- package/dist/cli/template.d.ts +8 -0
- package/dist/cli/template.d.ts.map +1 -0
- package/dist/context.d.ts +104 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/document/index.d.ts +11 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/index.js +19 -0
- package/dist/document/index.js.map +9 -0
- package/dist/document/inline-script.d.ts +27 -0
- package/dist/document/inline-script.d.ts.map +1 -0
- package/dist/document/language-store.d.ts +8 -0
- package/dist/document/language-store.d.ts.map +1 -0
- package/dist/document/nonce.d.ts +34 -0
- package/dist/document/nonce.d.ts.map +1 -0
- package/dist/document/page-language.d.ts +39 -0
- package/dist/document/page-language.d.ts.map +1 -0
- package/dist/document/text-direction.d.ts +10 -0
- package/dist/document/text-direction.d.ts.map +1 -0
- package/dist/entry/abort.d.ts +21 -0
- package/dist/entry/abort.d.ts.map +1 -0
- package/dist/entry/create-entry.d.ts +41 -0
- package/dist/entry/create-entry.d.ts.map +1 -0
- package/dist/entry/index.d.ts +8 -0
- package/dist/entry/index.d.ts.map +1 -0
- package/dist/entry/index.js +154 -0
- package/dist/entry/index.js.map +13 -0
- package/dist/entry/root-data.d.ts +27 -0
- package/dist/entry/root-data.d.ts.map +1 -0
- package/dist/entry/whole-page.d.ts +10 -0
- package/dist/entry/whole-page.d.ts.map +1 -0
- package/dist/errors/api-error.d.ts +117 -0
- package/dist/errors/api-error.d.ts.map +1 -0
- package/dist/errors/api-errors.d.ts +122 -0
- package/dist/errors/api-errors.d.ts.map +1 -0
- package/dist/errors/call-failure.d.ts +45 -0
- package/dist/errors/call-failure.d.ts.map +1 -0
- package/dist/errors/catalogue-check.d.ts +24 -0
- package/dist/errors/catalogue-check.d.ts.map +1 -0
- package/dist/errors/catalogue-read.d.ts +33 -0
- package/dist/errors/catalogue-read.d.ts.map +1 -0
- package/dist/errors/catalogue.d.ts +59 -0
- package/dist/errors/catalogue.d.ts.map +1 -0
- package/dist/errors/code-resolver.d.ts +44 -0
- package/dist/errors/code-resolver.d.ts.map +1 -0
- package/dist/errors/cross-site.d.ts +8 -0
- package/dist/errors/cross-site.d.ts.map +1 -0
- package/dist/errors/describe-refusal.d.ts +6 -0
- package/dist/errors/describe-refusal.d.ts.map +1 -0
- package/dist/errors/describe.d.ts +3 -0
- package/dist/errors/describe.d.ts.map +1 -0
- package/dist/errors/fetcher-result.d.ts +33 -0
- package/dist/errors/fetcher-result.d.ts.map +1 -0
- package/dist/errors/field-placement.d.ts +12 -0
- package/dist/errors/field-placement.d.ts.map +1 -0
- package/dist/errors/form-errors.d.ts +8 -0
- package/dist/errors/form-errors.d.ts.map +1 -0
- package/dist/errors/form-refusal.d.ts +25 -0
- package/dist/errors/form-refusal.d.ts.map +1 -0
- package/dist/errors/index.d.ts +21 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +588 -0
- package/dist/errors/index.js.map +26 -0
- package/dist/errors/json-actions.d.ts +38 -0
- package/dist/errors/json-actions.d.ts.map +1 -0
- package/dist/errors/log.d.ts +8 -0
- package/dist/errors/log.d.ts.map +1 -0
- package/dist/errors/message-values.d.ts +11 -0
- package/dist/errors/message-values.d.ts.map +1 -0
- package/dist/errors/messages.d.ts +63 -0
- package/dist/errors/messages.d.ts.map +1 -0
- package/dist/errors/page-path.d.ts +9 -0
- package/dist/errors/page-path.d.ts.map +1 -0
- package/dist/errors/problem-error.d.ts +50 -0
- package/dist/errors/problem-error.d.ts.map +1 -0
- package/dist/errors/provider.d.ts +20 -0
- package/dist/errors/provider.d.ts.map +1 -0
- package/dist/errors/request-id.d.ts +5 -0
- package/dist/errors/request-id.d.ts.map +1 -0
- package/dist/errors/route-error.d.ts +33 -0
- package/dist/errors/route-error.d.ts.map +1 -0
- package/dist/errors/route-refusal.d.ts +20 -0
- package/dist/errors/route-refusal.d.ts.map +1 -0
- package/dist/errors/same-site.d.ts +49 -0
- package/dist/errors/same-site.d.ts.map +1 -0
- package/dist/errors/section-action.d.ts +46 -0
- package/dist/errors/section-action.d.ts.map +1 -0
- package/dist/errors/standard-schema.d.ts +34 -0
- package/dist/errors/standard-schema.d.ts.map +1 -0
- package/dist/errors/submit-form.d.ts +16 -0
- package/dist/errors/submit-form.d.ts.map +1 -0
- package/dist/errors/upstream-headers.d.ts +18 -0
- package/dist/errors/upstream-headers.d.ts.map +1 -0
- package/dist/errors/use-json-fetcher.d.ts +18 -0
- package/dist/errors/use-json-fetcher.d.ts.map +1 -0
- package/dist/fetcher/auth-refusal.d.ts +29 -0
- package/dist/fetcher/auth-refusal.d.ts.map +1 -0
- package/dist/fetcher/index.d.ts +20 -0
- package/dist/fetcher/index.d.ts.map +1 -0
- package/dist/fetcher/index.js +392 -0
- package/dist/fetcher/index.js.map +21 -0
- package/dist/fetcher/section-form.d.ts +24 -0
- package/dist/fetcher/section-form.d.ts.map +1 -0
- package/dist/fetcher/section-reload.d.ts +17 -0
- package/dist/fetcher/section-reload.d.ts.map +1 -0
- package/dist/fetcher/section-save.d.ts +29 -0
- package/dist/fetcher/section-save.d.ts.map +1 -0
- package/dist/fetcher/use-debounced-fetcher.d.ts +57 -0
- package/dist/fetcher/use-debounced-fetcher.d.ts.map +1 -0
- package/dist/fetcher/use-fetcher-answer.d.ts +16 -0
- package/dist/fetcher/use-fetcher-answer.d.ts.map +1 -0
- package/dist/fetcher/use-fetcher-done.d.ts +15 -0
- package/dist/fetcher/use-fetcher-done.d.ts.map +1 -0
- package/dist/fetcher/use-fetcher-promise.d.ts +48 -0
- package/dist/fetcher/use-fetcher-promise.d.ts.map +1 -0
- package/dist/fetcher/use-form-refusal.d.ts +20 -0
- package/dist/fetcher/use-form-refusal.d.ts.map +1 -0
- package/dist/fetcher/use-revalidate-on-focus.d.ts +20 -0
- package/dist/fetcher/use-revalidate-on-focus.d.ts.map +1 -0
- package/dist/fetcher/use-row-save.d.ts +32 -0
- package/dist/fetcher/use-row-save.d.ts.map +1 -0
- package/dist/fetcher/use-section-save.d.ts +46 -0
- package/dist/fetcher/use-section-save.d.ts.map +1 -0
- package/dist/fetcher/use-visible-interval.d.ts +24 -0
- package/dist/fetcher/use-visible-interval.d.ts.map +1 -0
- package/dist/fetcher/use-visible-revalidation.d.ts +10 -0
- package/dist/fetcher/use-visible-revalidation.d.ts.map +1 -0
- package/dist/health.d.ts +21 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/help/check/check.d.ts +35 -0
- package/dist/help/check/check.d.ts.map +1 -0
- package/dist/help/check/index.d.ts +8 -0
- package/dist/help/check/index.d.ts.map +1 -0
- package/dist/help/check/index.js +17 -0
- package/dist/help/check/index.js.map +9 -0
- package/dist/help/check/routes.d.ts +22 -0
- package/dist/help/check/routes.d.ts.map +1 -0
- package/dist/help/guide.d.ts +33 -0
- package/dist/help/guide.d.ts.map +1 -0
- package/dist/help/index.d.ts +16 -0
- package/dist/help/index.d.ts.map +1 -0
- package/dist/help/index.js +192 -0
- package/dist/help/index.js.map +14 -0
- package/dist/help/load.d.ts +39 -0
- package/dist/help/load.d.ts.map +1 -0
- package/dist/help/panel.d.ts +69 -0
- package/dist/help/panel.d.ts.map +1 -0
- package/dist/help/parse-flow.d.ts +27 -0
- package/dist/help/parse-flow.d.ts.map +1 -0
- package/dist/help/react.d.ts +12 -0
- package/dist/help/react.d.ts.map +1 -0
- package/dist/help/resolve.d.ts +24 -0
- package/dist/help/resolve.d.ts.map +1 -0
- package/dist/help/types.d.ts +50 -0
- package/dist/help/types.d.ts.map +1 -0
- package/dist/help/yaml.d.ts +18 -0
- package/dist/help/yaml.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +14 -0
- package/dist/link/index.d.ts +7 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link/index.js +16 -0
- package/dist/link/index.js.map +10 -0
- package/dist/link/router-link.d.ts +27 -0
- package/dist/link/router-link.d.ts.map +1 -0
- package/dist/lists/connection-page.d.ts +50 -0
- package/dist/lists/connection-page.d.ts.map +1 -0
- package/dist/lists/index.d.ts +13 -0
- package/dist/lists/index.d.ts.map +1 -0
- package/dist/lists/index.js +205 -0
- package/dist/lists/index.js.map +15 -0
- package/dist/lists/newest-first.d.ts +5 -0
- package/dist/lists/newest-first.d.ts.map +1 -0
- package/dist/lists/nodes-of.d.ts +21 -0
- package/dist/lists/nodes-of.d.ts.map +1 -0
- package/dist/lists/or-failed.d.ts +19 -0
- package/dist/lists/or-failed.d.ts.map +1 -0
- package/dist/lists/use-paged-rows.d.ts +40 -0
- package/dist/lists/use-paged-rows.d.ts.map +1 -0
- package/dist/lists/use-same-route-loading.d.ts +8 -0
- package/dist/lists/use-same-route-loading.d.ts.map +1 -0
- package/dist/lists/use-search-change.d.ts +20 -0
- package/dist/lists/use-search-change.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +105 -0
- package/dist/mcp/index.js.map +11 -0
- package/dist/mcp/mcp-relay.d.ts +58 -0
- package/dist/mcp/mcp-relay.d.ts.map +1 -0
- package/dist/mcp/relay.d.ts +38 -0
- package/dist/mcp/relay.d.ts.map +1 -0
- package/dist/media/client/error.d.ts +29 -0
- package/dist/media/client/error.d.ts.map +1 -0
- package/dist/media/client/index.d.ts +8 -0
- package/dist/media/client/index.d.ts.map +1 -0
- package/dist/media/client/index.js +133 -0
- package/dist/media/client/index.js.map +11 -0
- package/dist/media/client/upload.d.ts +32 -0
- package/dist/media/client/upload.d.ts.map +1 -0
- package/dist/media/forward.d.ts +14 -0
- package/dist/media/forward.d.ts.map +1 -0
- package/dist/media/headers.d.ts +11 -0
- package/dist/media/headers.d.ts.map +1 -0
- package/dist/media/index.d.ts +9 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +396 -0
- package/dist/media/index.js.map +16 -0
- package/dist/media/options.d.ts +114 -0
- package/dist/media/options.d.ts.map +1 -0
- package/dist/media/path.d.ts +12 -0
- package/dist/media/path.d.ts.map +1 -0
- package/dist/media/read.d.ts +11 -0
- package/dist/media/read.d.ts.map +1 -0
- package/dist/media/refusal.d.ts +11 -0
- package/dist/media/refusal.d.ts.map +1 -0
- package/dist/media/respond.d.ts +8 -0
- package/dist/media/respond.d.ts.map +1 -0
- package/dist/media/write.d.ts +13 -0
- package/dist/media/write.d.ts.map +1 -0
- package/dist/navigation/index.d.ts +9 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +48 -0
- package/dist/navigation/index.js.map +11 -0
- package/dist/navigation/use-focus-on-navigate.d.ts +16 -0
- package/dist/navigation/use-focus-on-navigate.d.ts.map +1 -0
- package/dist/navigation/use-route-transition.d.ts +19 -0
- package/dist/navigation/use-route-transition.d.ts.map +1 -0
- package/dist/nonce.d.ts +16 -0
- package/dist/nonce.d.ts.map +1 -0
- package/dist/oauth/answer.d.ts +33 -0
- package/dist/oauth/answer.d.ts.map +1 -0
- package/dist/oauth/binding.d.ts +43 -0
- package/dist/oauth/binding.d.ts.map +1 -0
- package/dist/oauth/consent.d.ts +134 -0
- package/dist/oauth/consent.d.ts.map +1 -0
- package/dist/oauth/grants.d.ts +88 -0
- package/dist/oauth/grants.d.ts.map +1 -0
- package/dist/oauth/index.d.ts +16 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +207 -0
- package/dist/oauth/index.js.map +12 -0
- package/dist/oauth/model.d.ts +13 -0
- package/dist/oauth/model.d.ts.map +1 -0
- package/dist/oauth/react/index.d.ts +7 -0
- package/dist/oauth/react/index.d.ts.map +1 -0
- package/dist/oauth/react/index.js +99 -0
- package/dist/oauth/react/index.js.map +10 -0
- package/dist/oauth/react/use-consent.d.ts +52 -0
- package/dist/oauth/react/use-consent.d.ts.map +1 -0
- package/dist/oidc/dpop.d.ts +80 -0
- package/dist/oidc/dpop.d.ts.map +1 -0
- package/dist/oidc/errors.d.ts +16 -0
- package/dist/oidc/errors.d.ts.map +1 -0
- package/dist/oidc/flow.d.ts +59 -0
- package/dist/oidc/flow.d.ts.map +1 -0
- package/dist/oidc/index.d.ts +11 -0
- package/dist/oidc/index.d.ts.map +1 -0
- package/dist/oidc/index.js +742 -0
- package/dist/oidc/index.js.map +15 -0
- package/dist/oidc/oidc.d.ts +132 -0
- package/dist/oidc/oidc.d.ts.map +1 -0
- package/dist/oidc/revoke.d.ts +28 -0
- package/dist/oidc/revoke.d.ts.map +1 -0
- package/dist/oidc/seal.d.ts +20 -0
- package/dist/oidc/seal.d.ts.map +1 -0
- package/dist/pwa/build/build-worker.d.ts +41 -0
- package/dist/pwa/build/build-worker.d.ts.map +1 -0
- package/dist/pwa/build/index.d.ts +9 -0
- package/dist/pwa/build/index.d.ts.map +1 -0
- package/dist/pwa/build/index.js +9 -0
- package/dist/pwa/build/index.js.map +9 -0
- package/dist/pwa/build/precache.d.ts +17 -0
- package/dist/pwa/build/precache.d.ts.map +1 -0
- package/dist/pwa/index.d.ts +16 -0
- package/dist/pwa/index.d.ts.map +1 -0
- package/dist/pwa/index.js +110 -0
- package/dist/pwa/index.js.map +12 -0
- package/dist/pwa/model/caching.d.ts +46 -0
- package/dist/pwa/model/caching.d.ts.map +1 -0
- package/dist/pwa/model/clear-app-caches.d.ts +9 -0
- package/dist/pwa/model/clear-app-caches.d.ts.map +1 -0
- package/dist/pwa/model/font-precache.d.ts +15 -0
- package/dist/pwa/model/font-precache.d.ts.map +1 -0
- package/dist/pwa/model/manifest.d.ts +80 -0
- package/dist/pwa/model/manifest.d.ts.map +1 -0
- package/dist/pwa/model/precache-list.d.ts +40 -0
- package/dist/pwa/model/precache-list.d.ts.map +1 -0
- package/dist/pwa/model/registration.d.ts +39 -0
- package/dist/pwa/model/registration.d.ts.map +1 -0
- package/dist/pwa/model/start-service-worker.d.ts +24 -0
- package/dist/pwa/model/start-service-worker.d.ts.map +1 -0
- package/dist/pwa/model/storable.d.ts +8 -0
- package/dist/pwa/model/storable.d.ts.map +1 -0
- package/dist/pwa/model/theme-color.d.ts +20 -0
- package/dist/pwa/model/theme-color.d.ts.map +1 -0
- package/dist/pwa/model/update-notice.d.ts +38 -0
- package/dist/pwa/model/update-notice.d.ts.map +1 -0
- package/dist/pwa/model/worker-contract.d.ts +61 -0
- package/dist/pwa/model/worker-contract.d.ts.map +1 -0
- package/dist/pwa/react/index.d.ts +9 -0
- package/dist/pwa/react/index.d.ts.map +1 -0
- package/dist/pwa/react/index.js +75 -0
- package/dist/pwa/react/index.js.map +13 -0
- package/dist/pwa/react/use-online.d.ts +6 -0
- package/dist/pwa/react/use-online.d.ts.map +1 -0
- package/dist/pwa/react/use-service-worker.d.ts +33 -0
- package/dist/pwa/react/use-service-worker.d.ts.map +1 -0
- package/dist/pwa/react/use-update-notice.d.ts +14 -0
- package/dist/pwa/react/use-update-notice.d.ts.map +1 -0
- package/dist/pwa/server/index.d.ts +7 -0
- package/dist/pwa/server/index.d.ts.map +1 -0
- package/dist/pwa/server/index.js +18 -0
- package/dist/pwa/server/index.js.map +10 -0
- package/dist/pwa/server/no-cache.d.ts +22 -0
- package/dist/pwa/server/no-cache.d.ts.map +1 -0
- package/dist/pwa/worker/index.d.ts +9 -0
- package/dist/pwa/worker/index.d.ts.map +1 -0
- package/dist/pwa/worker/index.js +144 -0
- package/dist/pwa/worker/index.js.map +12 -0
- package/dist/pwa/worker/injected.d.ts +15 -0
- package/dist/pwa/worker/injected.d.ts.map +1 -0
- package/dist/pwa/worker/plan.d.ts +65 -0
- package/dist/pwa/worker/plan.d.ts.map +1 -0
- package/dist/pwa/worker/scope.d.ts +18 -0
- package/dist/pwa/worker/scope.d.ts.map +1 -0
- package/dist/pwa/worker/start-worker.d.ts +17 -0
- package/dist/pwa/worker/start-worker.d.ts.map +1 -0
- package/dist/react-router.d.ts +68 -0
- package/dist/react-router.d.ts.map +1 -0
- package/dist/server.d.ts +127 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/session/codes.d.ts +9 -0
- package/dist/session/codes.d.ts.map +1 -0
- package/dist/session/cookies.d.ts +128 -0
- package/dist/session/cookies.d.ts.map +1 -0
- package/dist/session/flow-types.d.ts +235 -0
- package/dist/session/flow-types.d.ts.map +1 -0
- package/dist/session/guard.d.ts +10 -0
- package/dist/session/guard.d.ts.map +1 -0
- package/dist/session/index.d.ts +22 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +1090 -0
- package/dist/session/index.js.map +27 -0
- package/dist/session/land.d.ts +28 -0
- package/dist/session/land.d.ts.map +1 -0
- package/dist/session/link-json.d.ts +22 -0
- package/dist/session/link-json.d.ts.map +1 -0
- package/dist/session/link-land.d.ts +20 -0
- package/dist/session/link-land.d.ts.map +1 -0
- package/dist/session/link-token.d.ts +24 -0
- package/dist/session/link-token.d.ts.map +1 -0
- package/dist/session/link-types.d.ts +142 -0
- package/dist/session/link-types.d.ts.map +1 -0
- package/dist/session/links.d.ts +14 -0
- package/dist/session/links.d.ts.map +1 -0
- package/dist/session/model/index.d.ts +8 -0
- package/dist/session/model/index.d.ts.map +1 -0
- package/dist/session/model/index.js +35 -0
- package/dist/session/model/index.js.map +9 -0
- package/dist/session/model/link-post.d.ts +35 -0
- package/dist/session/model/link-post.d.ts.map +1 -0
- package/dist/session/model/paths.d.ts +24 -0
- package/dist/session/model/paths.d.ts.map +1 -0
- package/dist/session/model/safe-next.d.ts +15 -0
- package/dist/session/model/safe-next.d.ts.map +1 -0
- package/dist/session/model/second-factor.d.ts +16 -0
- package/dist/session/model/second-factor.d.ts.map +1 -0
- package/dist/session/model/site-path.d.ts +10 -0
- package/dist/session/model/site-path.d.ts.map +1 -0
- package/dist/session/model/step-up-answers.d.ts +45 -0
- package/dist/session/model/step-up-answers.d.ts.map +1 -0
- package/dist/session/model/step-up-props.d.ts +22 -0
- package/dist/session/model/step-up-props.d.ts.map +1 -0
- package/dist/session/model/step-up.d.ts +48 -0
- package/dist/session/model/step-up.d.ts.map +1 -0
- package/dist/session/react/index.d.ts +13 -0
- package/dist/session/react/index.d.ts.map +1 -0
- package/dist/session/react/index.js +196 -0
- package/dist/session/react/index.js.map +14 -0
- package/dist/session/react/step-up/answers.d.ts +9 -0
- package/dist/session/react/step-up/answers.d.ts.map +1 -0
- package/dist/session/react/step-up/dialog-props.d.ts +27 -0
- package/dist/session/react/step-up/dialog-props.d.ts.map +1 -0
- package/dist/session/react/step-up/index.d.ts +7 -0
- package/dist/session/react/step-up/index.d.ts.map +1 -0
- package/dist/session/react/step-up/pending-runs.d.ts +21 -0
- package/dist/session/react/step-up/pending-runs.d.ts.map +1 -0
- package/dist/session/react/step-up/phase.d.ts +8 -0
- package/dist/session/react/step-up/phase.d.ts.map +1 -0
- package/dist/session/react/step-up/use-step-up-replay.d.ts +59 -0
- package/dist/session/react/step-up/use-step-up-replay.d.ts.map +1 -0
- package/dist/session/react/step-up/use-step-up-runner.d.ts +70 -0
- package/dist/session/react/step-up/use-step-up-runner.d.ts.map +1 -0
- package/dist/session/react/step-up/use-step-up.d.ts +51 -0
- package/dist/session/react/step-up/use-step-up.d.ts.map +1 -0
- package/dist/session/react/use-code-field.d.ts +37 -0
- package/dist/session/react/use-code-field.d.ts.map +1 -0
- package/dist/session/react/use-link-fragment.d.ts +22 -0
- package/dist/session/react/use-link-fragment.d.ts.map +1 -0
- package/dist/session/react/use-link-param.d.ts +26 -0
- package/dist/session/react/use-link-param.d.ts.map +1 -0
- package/dist/session/react/use-link-post.d.ts +39 -0
- package/dist/session/react/use-link-post.d.ts.map +1 -0
- package/dist/session/react/use-sign-out.d.ts +46 -0
- package/dist/session/react/use-sign-out.d.ts.map +1 -0
- package/dist/session/second-factor.d.ts +22 -0
- package/dist/session/second-factor.d.ts.map +1 -0
- package/dist/session/serialize.d.ts +42 -0
- package/dist/session/serialize.d.ts.map +1 -0
- package/dist/session/sign-in.d.ts +19 -0
- package/dist/session/sign-in.d.ts.map +1 -0
- package/dist/session/signed.d.ts +44 -0
- package/dist/session/signed.d.ts.map +1 -0
- package/dist/session/social-flow.d.ts +22 -0
- package/dist/session/social-flow.d.ts.map +1 -0
- package/dist/session/social-land.d.ts +31 -0
- package/dist/session/social-land.d.ts.map +1 -0
- package/dist/session/social-types.d.ts +136 -0
- package/dist/session/social-types.d.ts.map +1 -0
- package/dist/session/social.d.ts +32 -0
- package/dist/session/social.d.ts.map +1 -0
- package/dist/session/step-up-codes.d.ts +9 -0
- package/dist/session/step-up-codes.d.ts.map +1 -0
- package/dist/session/step-up-signed-out.d.ts +21 -0
- package/dist/session/step-up-signed-out.d.ts.map +1 -0
- package/dist/session/step-up-types.d.ts +127 -0
- package/dist/session/step-up-types.d.ts.map +1 -0
- package/dist/session/step-up.d.ts +17 -0
- package/dist/session/step-up.d.ts.map +1 -0
- package/dist/session/step.d.ts +22 -0
- package/dist/session/step.d.ts.map +1 -0
- package/dist/session/throttle.d.ts +73 -0
- package/dist/session/throttle.d.ts.map +1 -0
- package/dist/session/timed-wait.d.ts +4 -0
- package/dist/session/timed-wait.d.ts.map +1 -0
- package/dist/session/viewer.d.ts +34 -0
- package/dist/session/viewer.d.ts.map +1 -0
- package/dist/subscription/documents.d.ts +3 -0
- package/dist/subscription/documents.d.ts.map +1 -0
- package/dist/subscription/index.d.ts +7 -0
- package/dist/subscription/index.d.ts.map +1 -0
- package/dist/subscription/index.js +359 -0
- package/dist/subscription/index.js.map +14 -0
- package/dist/subscription/proxy.d.ts +54 -0
- package/dist/subscription/proxy.d.ts.map +1 -0
- package/dist/subscription/react/backoff.d.ts +8 -0
- package/dist/subscription/react/backoff.d.ts.map +1 -0
- package/dist/subscription/react/classify.d.ts +15 -0
- package/dist/subscription/react/classify.d.ts.map +1 -0
- package/dist/subscription/react/controller.d.ts +40 -0
- package/dist/subscription/react/controller.d.ts.map +1 -0
- package/dist/subscription/react/fake-timers.d.ts +8 -0
- package/dist/subscription/react/fake-timers.d.ts.map +1 -0
- package/dist/subscription/react/index.d.ts +15 -0
- package/dist/subscription/react/index.d.ts.map +1 -0
- package/dist/subscription/react/index.js +227 -0
- package/dist/subscription/react/index.js.map +17 -0
- package/dist/subscription/react/reconnect.d.ts +9 -0
- package/dist/subscription/react/reconnect.d.ts.map +1 -0
- package/dist/subscription/react/scheduler.d.ts +13 -0
- package/dist/subscription/react/scheduler.d.ts.map +1 -0
- package/dist/subscription/react/timers.d.ts +7 -0
- package/dist/subscription/react/timers.d.ts.map +1 -0
- package/dist/subscription/react/use-live-subscription.d.ts +36 -0
- package/dist/subscription/react/use-live-subscription.d.ts.map +1 -0
- package/dist/subscription/react/versions.d.ts +6 -0
- package/dist/subscription/react/versions.d.ts.map +1 -0
- package/dist/subscription/read.d.ts +17 -0
- package/dist/subscription/read.d.ts.map +1 -0
- package/dist/subscription/refusal.d.ts +11 -0
- package/dist/subscription/refusal.d.ts.map +1 -0
- package/dist/subscription/relay.d.ts +16 -0
- package/dist/subscription/relay.d.ts.map +1 -0
- package/dist/vite/bun.d.ts +21 -0
- package/dist/vite/bun.d.ts.map +1 -0
- package/dist/vite/bundle.d.ts +33 -0
- package/dist/vite/bundle.d.ts.map +1 -0
- package/dist/vite/compress.d.ts +18 -0
- package/dist/vite/compress.d.ts.map +1 -0
- package/dist/vite/config.d.ts +33 -0
- package/dist/vite/config.d.ts.map +1 -0
- package/dist/vite/dev.d.ts +28 -0
- package/dist/vite/dev.d.ts.map +1 -0
- package/dist/vite/entry.d.ts +20 -0
- package/dist/vite/entry.d.ts.map +1 -0
- package/dist/vite/hosts.d.ts +16 -0
- package/dist/vite/hosts.d.ts.map +1 -0
- package/dist/vite/index.d.ts +68 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +635 -0
- package/dist/vite/index.js.map +22 -0
- package/dist/vite/inline.d.ts +18 -0
- package/dist/vite/inline.d.ts.map +1 -0
- package/dist/vite/node.d.ts +16 -0
- package/dist/vite/node.d.ts.map +1 -0
- package/dist/vite/preview.d.ts +8 -0
- package/dist/vite/preview.d.ts.map +1 -0
- package/dist/vite/runtime.d.ts +8 -0
- package/dist/vite/runtime.d.ts.map +1 -0
- package/dist/vite/socket.d.ts +75 -0
- package/dist/vite/socket.d.ts.map +1 -0
- package/dist/vite/worker.d.ts +16 -0
- package/dist/vite/worker.d.ts.map +1 -0
- package/dist/with-alxia.d.ts +36 -0
- package/dist/with-alxia.d.ts.map +1 -0
- package/docs/README.md +42 -0
- package/docs/guide/api-keys.md +216 -0
- package/docs/guide/beside-the-pages.md +201 -0
- package/docs/guide/csp-nonce.md +166 -0
- package/docs/guide/customising-the-server.md +324 -0
- package/docs/guide/deploying.md +102 -0
- package/docs/guide/document.md +334 -0
- package/docs/guide/errors.md +1147 -0
- package/docs/guide/fetcher.md +355 -0
- package/docs/guide/getting-started.md +112 -0
- package/docs/guide/help.md +325 -0
- package/docs/guide/how-it-works.md +274 -0
- package/docs/guide/link.md +32 -0
- package/docs/guide/lists.md +225 -0
- package/docs/guide/mcp.md +173 -0
- package/docs/guide/media.md +273 -0
- package/docs/guide/navigation.md +52 -0
- package/docs/guide/oauth.md +342 -0
- package/docs/guide/oidc.md +262 -0
- package/docs/guide/openapi.md +51 -0
- package/docs/guide/pwa.md +670 -0
- package/docs/guide/session.md +2105 -0
- package/docs/guide/subscriptions.md +211 -0
- package/docs/guide/testing.md +42 -0
- package/docs/guide/typing-the-loaders.md +311 -0
- package/docs/guide.md +82 -0
- package/docs/roadmap.md +474 -0
- package/docs/troubleshooting.md +3837 -0
- package/package.json +301 -5
package/README.md
CHANGED
|
@@ -1,3 +1,2086 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @softistx/alxia-react-router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Moved from `@alxia/react-router`: see the [migration guide](https://github.com/softistx/alxia/blob/develop/packages/core/docs/guide/migrating-from-alxia-scope.md).
|
|
4
|
+
|
|
5
|
+
[alxia](https://www.npmjs.com/package/@softistx/alxia) as the HTTP server of a
|
|
6
|
+
[React Router](https://reactrouter.com) framework app, server rendered,
|
|
7
|
+
under Bun. One Vite plugin and no server file: the pages are served by
|
|
8
|
+
alxia in `react-router dev` and from the build. When you want more,
|
|
9
|
+
`app/server.ts` adds the app's middlewares — logger, compression, sessions,
|
|
10
|
+
guards — and an `/api` beside the pages, and each loader reads what those
|
|
11
|
+
middlewares built, typed.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
### A new app
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
bunx @softistx/alxia-create my-app --template react-router
|
|
19
|
+
cd my-app
|
|
20
|
+
bun dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
[`@softistx/alxia-create`](https://www.npmjs.com/package/@softistx/alxia-create) writes React
|
|
24
|
+
Router's official template with everything below already done: this
|
|
25
|
+
package and `@softistx/alxia` installed, `alxia()` in `vite.config.ts`, the
|
|
26
|
+
`bunfig.toml`, `start` on Bun, Biome, and a `Dockerfile` that builds on
|
|
27
|
+
`oven/bun` and runs `build/` alone on Alpine. Its dependencies are
|
|
28
|
+
moved to the newest releases alxia accepts.
|
|
29
|
+
|
|
30
|
+
### An existing React Router app
|
|
31
|
+
|
|
32
|
+
Start from the official template, `bunx create-react-router@latest`, or your
|
|
33
|
+
own app, and make four changes.
|
|
34
|
+
|
|
35
|
+
**1. Install** alxia and this package:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
bun add @softistx/alxia @softistx/alxia-react-router
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**2. Add the plugin** to `vite.config.ts`. It can go anywhere in `plugins`:
|
|
42
|
+
|
|
43
|
+
```diff
|
|
44
|
+
+import { alxia } from "@softistx/alxia-react-router/vite";
|
|
45
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
46
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
47
|
+
import { defineConfig } from "vite";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
- plugins: [tailwindcss(), reactRouter()],
|
|
51
|
+
+ plugins: [tailwindcss(), reactRouter(), alxia()],
|
|
52
|
+
resolve: {
|
|
53
|
+
tsconfigPaths: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**3. Run the scripts on Bun**, with a `bunfig.toml`:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
# bunfig.toml, beside package.json
|
|
62
|
+
[run]
|
|
63
|
+
bun = true
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The `react-router` CLI starts with `#!/usr/bin/env node`. Where a node is
|
|
67
|
+
installed, `bun run dev` would run it on Node, and alxia's server needs
|
|
68
|
+
Bun. `bun = true` makes `bun run` start it on Bun. Without it, the dev
|
|
69
|
+
server stops at startup with
|
|
70
|
+
[`alxia-react-router: react-router dev is running on Node, …`](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#alxia-react-router--is-running-on-node-and-alxias-server-runs-on-bun-).
|
|
71
|
+
|
|
72
|
+
**4. Start with Bun**, in `package.json`:
|
|
73
|
+
|
|
74
|
+
```diff
|
|
75
|
+
- "start": "react-router-serve ./build/server/index.js",
|
|
76
|
+
+ "start": "NODE_ENV=production bun build/server/index.js",
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
With the `bunfig.toml` in place, the template's `dev`, `build` and
|
|
80
|
+
`typecheck` scripts are unchanged. alxia's dev helps follow React Router's
|
|
81
|
+
mode, on under `react-router dev`; `bunx @softistx/alxia-create` writes
|
|
82
|
+
`NODE_ENV=development react-router dev` as `dev`, so that the app's own
|
|
83
|
+
`Bun.env` reads agree:
|
|
84
|
+
|
|
85
|
+
- **`bun run dev`**: every request Vite does not answer itself (pages,
|
|
86
|
+
data, `/api`, an upgrade to a `ws` route) reaches alxia, with HMR.
|
|
87
|
+
- **`bun run build`** writes `build/server/index.js`, a server you can run.
|
|
88
|
+
- **`bun run start`** serves the pages and the client build. It listens on
|
|
89
|
+
`PORT` (3000) and `HOST` (`0.0.0.0`), and shuts down gracefully on
|
|
90
|
+
`SIGTERM`: the requests in flight finish, then the `onStop` hooks run.
|
|
91
|
+
|
|
92
|
+
After a build, `bunx --bun vite preview` serves that built server through
|
|
93
|
+
Vite's preview server, as `bun run start` would: the pages, `/api`, the
|
|
94
|
+
client's files and the app's middlewares. So does React Router's prerendering.
|
|
95
|
+
|
|
96
|
+
`@softistx/alxia` and `react-router` 8 are peers, and `vite` 7 or 8 is an
|
|
97
|
+
optional peer, for `/vite`; `react` 19 is an optional peer, for `/pwa/react`, `/fetcher`, `/lists`, `/navigation` and `/oauth/react`; `jose` 6 is an optional peer, for `/oidc`. The six `workbox-*`
|
|
98
|
+
packages (`workbox-core`, `workbox-expiration`, `workbox-navigation-preload`,
|
|
99
|
+
`workbox-precaching`, `workbox-routing`, `workbox-strategies`) are optional
|
|
100
|
+
peers too, for `/pwa/worker` (the [PWA section](#installable-and-offline-pwa) has the install line). `@softistx/alxia-proxy` is an optional peer, for `/mcp` (`bun add @softistx/alxia-proxy`); `/mcp` also reads `@softistx/alxia`'s `MCP_RELAY_PATHS`. `react-hook-form` (7.55 or later) is an optional peer: `SectionForm`, the form `useSectionSave` and `useRowSave` take from `/fetcher`, is the shape of its `useForm()` result. `/errors` imports `react-router`, a required peer that is already installed. The package declares no dependency.
|
|
101
|
+
|
|
102
|
+
Its `typescript` peer is 6 or 7. The template's TypeScript 5.9 typechecks,
|
|
103
|
+
but `bun add` warns about it; `bun add -d typescript@^6` silences the
|
|
104
|
+
warning.
|
|
105
|
+
|
|
106
|
+
### Dev tunnels and other hostnames
|
|
107
|
+
|
|
108
|
+
Vite refuses any `Host` but `localhost` and `.localhost`. To open `vite dev`
|
|
109
|
+
(or `vite preview`) on a public name, such as a dev tunnel's, list it in
|
|
110
|
+
`DEV_ALLOWED_HOSTS`, comma-separated; a leading dot allows the subdomains:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
DEV_ALLOWED_HOSTS=my-app-mac.example.com bun run dev
|
|
114
|
+
DEV_ALLOWED_HOSTS=.example.com,other.example.com bun run dev
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Or in `vite.config.ts`, with `alxia({ allowedHosts: ['my-app-mac.example.com'] })`.
|
|
118
|
+
Both are added to `server.allowedHosts` and `preview.allowedHosts`, beside
|
|
119
|
+
what the app's own config sets; an app that set `allowedHosts: true` keeps
|
|
120
|
+
it, and alxia never sets it. Unset, nothing changes. HMR works over the
|
|
121
|
+
tunnel's 443 websocket unless the app pins `hmr.clientPort`.
|
|
122
|
+
`.example.com` lets any subdomain reach the dev server; prefer exact names.
|
|
123
|
+
See [troubleshooting](docs/troubleshooting.md) for Vite's `Blocked request`.
|
|
124
|
+
|
|
125
|
+
## Customising: `app/server.ts`
|
|
126
|
+
|
|
127
|
+
Start from the default server, written out:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
bunx alxia-react-router reveal
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
It writes `app/server.ts` (or the file `alxia({ entry })` names):
|
|
134
|
+
`createServer()` with `beforeAll`, `configure` and `getLoadContext`
|
|
135
|
+
commented, and the `Register` declaration. It refuses to overwrite a file
|
|
136
|
+
already there; `--force` overwrites it. Run it from the app's root, once
|
|
137
|
+
`@softistx/alxia-react-router` is installed.
|
|
138
|
+
|
|
139
|
+
The examples use `@softistx/alxia-logger` (`bun add @softistx/alxia-logger`); any middleware
|
|
140
|
+
works the same way (`use` the observers first). The Vite plugin picks the file up in dev and in the build:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// app/server.ts
|
|
144
|
+
import { logger } from '@softistx/alxia-logger';
|
|
145
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
146
|
+
|
|
147
|
+
const server = createServer({
|
|
148
|
+
configure: (app) =>
|
|
149
|
+
app
|
|
150
|
+
.use(logger())
|
|
151
|
+
.get('/api/health', ({ reply }) => reply.ok({ ok: true }))
|
|
152
|
+
.derive(({ request }) => {
|
|
153
|
+
const name = request.headers.get('x-user');
|
|
154
|
+
return { user: name === null ? null : { name } };
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export default server;
|
|
159
|
+
|
|
160
|
+
// What alxiaOf(context) reads in the loaders.
|
|
161
|
+
declare module '@softistx/alxia-react-router' {
|
|
162
|
+
interface Register {
|
|
163
|
+
server: typeof server;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`configure` receives the alxia app and returns it, so what it builds is
|
|
169
|
+
typed. The plugin wires React Router's build, the mode and the client
|
|
170
|
+
folder.
|
|
171
|
+
|
|
172
|
+
A request runs through `beforeAll`, then the client's files, then
|
|
173
|
+
`configure`, then the pages. So a guard in `configure` does not block the
|
|
174
|
+
login page's JavaScript.
|
|
175
|
+
|
|
176
|
+
### A health probe
|
|
177
|
+
|
|
178
|
+
`health` declares a probe ahead of everything: before `beforeAll`, the
|
|
179
|
+
client's files and every middleware, so it needs no session and sets no
|
|
180
|
+
cookie. It answers `200` `ok` as `text/plain`, with `cache-control: no-store`.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
// app/server.ts
|
|
184
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
185
|
+
|
|
186
|
+
// Stand-in for your dependency's ping.
|
|
187
|
+
const db = { ping: async () => true };
|
|
188
|
+
|
|
189
|
+
export default createServer({
|
|
190
|
+
// 503 `unavailable` when the check returns false, throws, rejects or
|
|
191
|
+
// outlasts `timeout` (1 000 ms by default). `undefined` counts as healthy.
|
|
192
|
+
health: { path: '/health', check: () => db.ping(), timeout: 500 },
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`health: '/health'` alone is the same without a check. The probe is
|
|
197
|
+
liveness only, not a `/ready`: it is `@softistx/alxia`'s `health()` mounted with
|
|
198
|
+
`format: 'text'` and `ready: false`, so for readiness checks and the JSON
|
|
199
|
+
report mount `health()` itself on another `path`, as below. Being core's
|
|
200
|
+
probe, it is left out by `@softistx/alxia-openapi`'s `matchesSpec`
|
|
201
|
+
(`isHealthRoute`).
|
|
202
|
+
|
|
203
|
+
To add `/ready` beside the probe, mount core's `health()` in `beforeAll` on
|
|
204
|
+
another path, since `health()` also declares `/health` by default:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { health } from '@softistx/alxia';
|
|
208
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
209
|
+
|
|
210
|
+
export default createServer({
|
|
211
|
+
health: '/health', // text liveness, first of all
|
|
212
|
+
beforeAll: (app) =>
|
|
213
|
+
app.plugin(health({ path: '/live', checks: { database: () => true } })),
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Reading the context in a loader
|
|
218
|
+
|
|
219
|
+
What alxia's middlewares built for a request reaches a loader, an action or
|
|
220
|
+
a middleware in three forms, each the same object, typed by the `Register`
|
|
221
|
+
declaration above:
|
|
222
|
+
|
|
223
|
+
| Form | Use it |
|
|
224
|
+
| --- | --- |
|
|
225
|
+
| `withAlxia(fn)` | with the generated `Route.LoaderArgs` and `Route.ActionArgs`: `alxia` beside the arguments |
|
|
226
|
+
| `alxiaOf(context)` | inside a plain function, or with a type argument where nothing is registered |
|
|
227
|
+
| `context.alxia` | with `LoaderFunctionArgs` and `ActionFunctionArgs` from `react-router` |
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
// app/routes/home.tsx
|
|
231
|
+
import { type AlxiaArgs, withAlxia } from '@softistx/alxia-react-router';
|
|
232
|
+
import type { Route } from './+types/home';
|
|
233
|
+
|
|
234
|
+
export const loader = withAlxia(({ alxia }: Route.LoaderArgs & AlxiaArgs) => {
|
|
235
|
+
alxia.log.info('home'); // typed: what configure built
|
|
236
|
+
return { name: alxia.user?.name ?? 'anonymous' };
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
`withAlxia` returns a function of React Router's arguments alone, with
|
|
241
|
+
`fn`'s return type: `Route.ComponentProps['loaderData']` and
|
|
242
|
+
`useLoaderData<typeof loader>` read what `fn` returns. It works for an
|
|
243
|
+
action, and for a middleware, whose `next` it passes on.
|
|
244
|
+
|
|
245
|
+
`alxiaOf(context)`, in a plain function:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { alxiaOf } from '@softistx/alxia-react-router';
|
|
249
|
+
|
|
250
|
+
export async function action({ context }: Route.ActionArgs) {
|
|
251
|
+
const { user, log } = alxiaOf(context);
|
|
252
|
+
log.info('saved', { by: user?.name });
|
|
253
|
+
return { ok: true };
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
How each is typed:
|
|
258
|
+
|
|
259
|
+
- with the `Register` declaration above, by that server: reading something
|
|
260
|
+
no middleware derives is a compile error;
|
|
261
|
+
- without it, `AlxiaArgs<typeof server>` or `alxiaOf<typeof server>(context)`
|
|
262
|
+
names the server;
|
|
263
|
+
- with neither, by the base `@softistx/alxia`'s own `Register` names
|
|
264
|
+
(`context: typeof base`), when the app has one;
|
|
265
|
+
- with none of them, `BaseContext`.
|
|
266
|
+
|
|
267
|
+
This package's `Register` wins over core's: the server's app is the base
|
|
268
|
+
and all `configure` adds after it.
|
|
269
|
+
|
|
270
|
+
### The shorthand: `context.alxia`
|
|
271
|
+
|
|
272
|
+
The same object, with no import and no call, where the arguments are
|
|
273
|
+
react-router's own types:
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
import type { LoaderFunctionArgs } from 'react-router';
|
|
277
|
+
|
|
278
|
+
export function loader({ context }: LoaderFunctionArgs) {
|
|
279
|
+
const { user, server } = context.alxia;
|
|
280
|
+
return { name: user?.name ?? 'anonymous' };
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
With the generated `Route.LoaderArgs` it is there at runtime, but `tsc`
|
|
285
|
+
reports `Property 'alxia' does not exist on type
|
|
286
|
+
'Readonly<RouterContextProvider>'` (TS2339): react-router's `./internal`
|
|
287
|
+
types, which the generated route types read, point at its development
|
|
288
|
+
build, a second declaration of `RouterContextProvider` that no package can
|
|
289
|
+
augment. Use `withAlxia` there until react-router ships one declaration.
|
|
290
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#property-alxia-does-not-exist-on-type-readonlyroutercontextprovider)
|
|
291
|
+
|
|
292
|
+
### The server: `server`
|
|
293
|
+
|
|
294
|
+
`alxiaOf(context).server` is the `Bun.Server` serving the request, core's
|
|
295
|
+
`ctx.server`: its `publish` reaches the app's [WebSocket](#websockets)
|
|
296
|
+
subscribers from an action.
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
export async function action({ context }: Route.ActionArgs) {
|
|
300
|
+
alxiaOf(context).server?.publish('todos', JSON.stringify({ changed: true }));
|
|
301
|
+
return { ok: true };
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
It is the listening server behind `bun build/server/index.js`. Under
|
|
306
|
+
`react-router dev` and `vite preview`, Vite's server is `node:http`, so it is
|
|
307
|
+
the `Bun.Server` the app's sockets are relayed to, on a loopback port:
|
|
308
|
+
`publish` reaches them, but its `url` is that port's, not Vite's, and its
|
|
309
|
+
`requestIP` and `timeout` know nothing of a request Vite took. Through
|
|
310
|
+
`app.request(…)`, as in a test, it is `undefined`.
|
|
311
|
+
It is not `Register`'s `server`, which names what `createServer()` returned
|
|
312
|
+
for the types.
|
|
313
|
+
|
|
314
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/typing-the-loaders.md#typing-the-loaders)
|
|
315
|
+
|
|
316
|
+
## A CSP nonce
|
|
317
|
+
|
|
318
|
+
Two headers middlewares from `@softistx/alxia-secure-headers`: `pageHeaders` in
|
|
319
|
+
`configure` for the pages (a policy with a fresh nonce per request, and
|
|
320
|
+
`Cache-Control: private, no-store`), and `secureHeaders` without a policy in
|
|
321
|
+
`beforeAll` for the client's files (`nosniff`, CORP, HSTS), which a
|
|
322
|
+
middleware in `configure` never reaches. `@softistx/alxia-react-router/entry` reads the
|
|
323
|
+
nonce with `nonceOf(loadContext)`, and React Router puts it on every script it
|
|
324
|
+
renders, so `script-src` needs no `'unsafe-inline'`:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
// app/server.ts
|
|
328
|
+
const production = process.env['NODE_ENV'] === 'production';
|
|
329
|
+
|
|
330
|
+
export default createServer({
|
|
331
|
+
beforeAll: (app) =>
|
|
332
|
+
app.use(
|
|
333
|
+
secureHeaders({
|
|
334
|
+
contentSecurityPolicy: false,
|
|
335
|
+
strictTransportSecurity: production
|
|
336
|
+
? 'max-age=31536000; includeSubDomains'
|
|
337
|
+
: false,
|
|
338
|
+
}),
|
|
339
|
+
),
|
|
340
|
+
configure: (app) => app.use(pageHeaders({ https: production })),
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The template has no `entry.server.tsx`; the package's own is one line:
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
// app/entry.server.tsx
|
|
348
|
+
export { handleRequest as default, streamTimeout } from '@softistx/alxia-react-router/entry';
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
To customise the entry, reveal React Router's and add the nonce yourself
|
|
352
|
+
([an entry of your own](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/csp-nonce.md#an-entry-of-your-own)).
|
|
353
|
+
|
|
354
|
+
`nonceOf` returns `undefined` when no middleware set a nonce, so the entry works
|
|
355
|
+
with or without secure-headers: neither package depends on the other. Any
|
|
356
|
+
`derive` that returns a string `nonce` works the same.
|
|
357
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/csp-nonce.md#a-csp-nonce)
|
|
358
|
+
|
|
359
|
+
## The document: nonce and boot scripts
|
|
360
|
+
|
|
361
|
+
`@softistx/alxia-react-router/document` renders the CSP nonce in the root, on the
|
|
362
|
+
server and in the browser, with `react` as its only import. The nonce comes
|
|
363
|
+
from `pageHeaders` ([A CSP nonce](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/csp-nonce.md)).
|
|
364
|
+
The server render provides it around the router; `useNonce()` reads it there,
|
|
365
|
+
and in the browser reads the one the document's scripts carry, so hydration
|
|
366
|
+
finds the attribute it rendered. `InlineScript` is an inline script with
|
|
367
|
+
that nonce, for a theme's boot script, which must run before the first
|
|
368
|
+
paint:
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
// app/root.tsx
|
|
372
|
+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router';
|
|
373
|
+
import {
|
|
374
|
+
CspNonceMeta,
|
|
375
|
+
InlineScript,
|
|
376
|
+
useNonce,
|
|
377
|
+
} from '@softistx/alxia-react-router/document';
|
|
378
|
+
import { themeBootScript } from '<your theme library>';
|
|
379
|
+
|
|
380
|
+
const THEME_BOOT = themeBootScript();
|
|
381
|
+
|
|
382
|
+
export function Layout({ children }: { children: React.ReactNode }) {
|
|
383
|
+
const nonce = useNonce();
|
|
384
|
+
return (
|
|
385
|
+
<html lang="en" suppressHydrationWarning>
|
|
386
|
+
<head>
|
|
387
|
+
<meta charSet="utf-8" />
|
|
388
|
+
<InlineScript code={THEME_BOOT} />
|
|
389
|
+
<CspNonceMeta />
|
|
390
|
+
<Meta />
|
|
391
|
+
<Links nonce={nonce} />
|
|
392
|
+
</head>
|
|
393
|
+
<body>
|
|
394
|
+
{children}
|
|
395
|
+
<ScrollRestoration />
|
|
396
|
+
<Scripts />
|
|
397
|
+
</body>
|
|
398
|
+
</html>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export default function App() {
|
|
403
|
+
return <Outlet />;
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
`THEME_BOOT` is your theme library's own boot script. With `/entry`,
|
|
408
|
+
`<Scripts>` and `<ScrollRestoration>` take the nonce from `<ServerRouter nonce>`
|
|
409
|
+
and need no prop. `<Links>` does not suppress the hydration warning for its
|
|
410
|
+
critical-CSS `<style nonce>` in development, so pass it `useNonce()`, as above;
|
|
411
|
+
`useNonce()` also serves `InlineScript`, `CspNonceMeta` and any script or style
|
|
412
|
+
the app inserts. An entry of your own
|
|
413
|
+
wraps the router:
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
// app/entry.server.tsx (inside handleRequest)
|
|
417
|
+
import { nonceOf } from '@softistx/alxia-react-router';
|
|
418
|
+
import { DocumentNonce } from '@softistx/alxia-react-router/document';
|
|
419
|
+
import { ServerRouter } from 'react-router';
|
|
420
|
+
|
|
421
|
+
<DocumentNonce nonce={nonceOf(loadContext)}>
|
|
422
|
+
<ServerRouter context={routerContext} url={request.url} />
|
|
423
|
+
</DocumentNonce>;
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
> The `InlineScript` code is written unescaped: keep it a constant of the
|
|
427
|
+
> app, never user input. It throws a `TypeError` on `</script` or `<!--`
|
|
428
|
+
> ([the message](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#typeerror-inlinescript-the-code-contains-script-or----which-ends-or-confuses-the-script-element-escape-it-such-as-script-inside-a-string)).
|
|
429
|
+
> A nonced page must never be made `public` by a route's `headers` export: a
|
|
430
|
+
> shared cache would hand the same nonce to every visitor.
|
|
431
|
+
|
|
432
|
+
### The page's language
|
|
433
|
+
|
|
434
|
+
`createPageLanguage` gives the root the page's language for `<html lang>` and
|
|
435
|
+
a route's `meta`, and `textDirection` the `dir` that goes with it. The server
|
|
436
|
+
side, negotiating the request's language from a cookie and `Accept-Language`,
|
|
437
|
+
is [`@softistx/alxia-language`](https://github.com/softistx/alxia/blob/develop/packages/language/README.md):
|
|
438
|
+
|
|
439
|
+
```ts
|
|
440
|
+
// app/server.ts
|
|
441
|
+
import { language } from '@softistx/alxia-language';
|
|
442
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
443
|
+
|
|
444
|
+
const server = createServer({
|
|
445
|
+
configure: (app) =>
|
|
446
|
+
app.use(language({ supported: ['en', 'fr', 'ar'], fallback: 'en', order: ['cookie', 'header'] })),
|
|
447
|
+
});
|
|
448
|
+
export default server;
|
|
449
|
+
declare module '@softistx/alxia-react-router' {
|
|
450
|
+
interface Register { server: typeof server }
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
// app/language.ts: one instance, imported by the root and the routes
|
|
456
|
+
import { createPageLanguage } from '@softistx/alxia-react-router/document';
|
|
457
|
+
|
|
458
|
+
export const { pageLanguage, metaLanguage, chooseLanguage, useChosenLanguage } =
|
|
459
|
+
createPageLanguage({ languages: ['en', 'fr', 'ar'], fallback: 'en' });
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
// app/root.tsx
|
|
464
|
+
import { type AlxiaArgs, withAlxia } from '@softistx/alxia-react-router';
|
|
465
|
+
import { textDirection } from '@softistx/alxia-react-router/document';
|
|
466
|
+
import { useRouteLoaderData } from 'react-router';
|
|
467
|
+
import { metaLanguage, pageLanguage, useChosenLanguage } from './language';
|
|
468
|
+
import type { Route } from './+types/root';
|
|
469
|
+
|
|
470
|
+
const titles = { en: 'Home', fr: 'Accueil', ar: 'الرئيسية' };
|
|
471
|
+
|
|
472
|
+
// the root loader returns alxia.language, set by the middleware
|
|
473
|
+
export const loader = withAlxia(({ alxia }: Route.LoaderArgs & AlxiaArgs) => ({ language: alxia.language }));
|
|
474
|
+
|
|
475
|
+
export function Layout({ children }: { children: React.ReactNode }) {
|
|
476
|
+
const data = useRouteLoaderData<typeof loader>('root');
|
|
477
|
+
const language = pageLanguage(data?.language);
|
|
478
|
+
useChosenLanguage(); // re-renders the shell when the menu picks a language
|
|
479
|
+
return (
|
|
480
|
+
<html lang={language} dir={textDirection(language)} suppressHydrationWarning>
|
|
481
|
+
{/* … */}
|
|
482
|
+
</html>
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export const meta: Route.MetaFunction = ({ matches }) => [
|
|
487
|
+
{ title: titles[metaLanguage(matches)] },
|
|
488
|
+
];
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
- `pageLanguage(language)` is the supported language, else the fallback. In
|
|
492
|
+
the browser the one picked with `chooseLanguage(language)` wins, and the
|
|
493
|
+
last one seen stands in when the root's data is gone. On the server it
|
|
494
|
+
remembers nothing: one module serves every request.
|
|
495
|
+
- `metaLanguage(matches)` reads `matches[0].loaderData.language`.
|
|
496
|
+
- `useChosenLanguage()` is the picked language, or `undefined`; it
|
|
497
|
+
re-renders on a pick, and is `undefined` in the server render so
|
|
498
|
+
hydration matches.
|
|
499
|
+
- `textDirection(tag)` is `'rtl'` for `ar`, `fa`, `he`, `ur`, `ps`, `yi`,
|
|
500
|
+
`dv`, `ckb`, `sd` and `ug` (and the legacy `iw` and `ji`), else `'ltr'`, reading the base tag whatever its
|
|
501
|
+
case (`ar-EG`, `AR`). A script subtag is not read: `az-Arab` is `'ltr'`.
|
|
502
|
+
- A fallback outside `languages` throws
|
|
503
|
+
([the message](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#typeerror-createpagelanguage-the-fallback--is-not-one-of-the-languages-got-)).
|
|
504
|
+
An error page keeps the root's data, so it keeps the language, except
|
|
505
|
+
for a URL that matches no route or a root loader that threw: there it
|
|
506
|
+
shows the last language seen in the browser, or the fallback ([why](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#the-error-page-shows-in-the-fallback-language)).
|
|
507
|
+
|
|
508
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/document.md)
|
|
509
|
+
|
|
510
|
+
## The entry
|
|
511
|
+
|
|
512
|
+
`@softistx/alxia-react-router/entry` is `entry.server.tsx` for an app on Bun, server
|
|
513
|
+
only: it streams the shell, waits for the whole page for a bot and in SPA
|
|
514
|
+
mode, answers HEAD with no body, and gives the router the response's CSP
|
|
515
|
+
nonce (`nonceOf`) and `DocumentNonce`. It renders with the web stream
|
|
516
|
+
renderer, so no `@react-router/node` and no `node:stream`. `react-dom` and
|
|
517
|
+
`isbot` (needed only without an `isBot` option) are optional peers, which React Router's templates install.
|
|
518
|
+
|
|
519
|
+
```tsx
|
|
520
|
+
// app/entry.server.tsx
|
|
521
|
+
export { handleRequest as default, streamTimeout } from '@softistx/alxia-react-router/entry';
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
To change `streamTimeout`, the nonce, the bot check or the error report,
|
|
525
|
+
`createEntry({ streamTimeout, nonce, isBot, rootData, onError })` returns
|
|
526
|
+
`{ handleRequest, streamTimeout }`.
|
|
527
|
+
|
|
528
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/document.md#the-entry)
|
|
529
|
+
|
|
530
|
+
## WebSockets
|
|
531
|
+
|
|
532
|
+
A `ws` route in `configure` connects under `react-router dev`, under
|
|
533
|
+
`vite preview` and from the build alike, with nothing else to write:
|
|
534
|
+
|
|
535
|
+
```ts
|
|
536
|
+
// app/server.ts
|
|
537
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
538
|
+
|
|
539
|
+
export default createServer({
|
|
540
|
+
configure: (app) =>
|
|
541
|
+
app
|
|
542
|
+
.derive(({ request }) => ({ user: request.headers.get('x-user') }))
|
|
543
|
+
.ws('/api/echo', {}, {
|
|
544
|
+
open: (socket) => socket.send({ hello: socket.data.user ?? 'anonymous' }),
|
|
545
|
+
message: (socket, message) => socket.send({ echo: String(message) }),
|
|
546
|
+
}),
|
|
547
|
+
});
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
In dev, the plugin hands each upgrade Vite does not claim (its HMR, its
|
|
551
|
+
`server.proxy`) to the app, run by `Bun.serve` as `listen` runs it: the
|
|
552
|
+
middlewares before the route, a refusal's status, `socket.data`, `publish`. An
|
|
553
|
+
edit to the server is used from the next connection. An action's
|
|
554
|
+
`alxiaOf(context).server.publish` reaches those sockets too
|
|
555
|
+
([The server](#the-server-server)).
|
|
556
|
+
[More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/beside-the-pages.md#websockets)
|
|
557
|
+
|
|
558
|
+
## Options
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
// app/server.ts
|
|
562
|
+
import { trustProxy } from '@softistx/alxia';
|
|
563
|
+
import { logger } from '@softistx/alxia-logger';
|
|
564
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
565
|
+
import { greetingContext } from './context'; // createContext<string>('unset'), in app/context.ts
|
|
566
|
+
|
|
567
|
+
export default createServer({
|
|
568
|
+
beforeAll: (app) => app.use(logger()), // runs before the client's files too
|
|
569
|
+
configure: (app) => app.get('/api/health', ({ reply }) => reply.ok({ ok: true })),
|
|
570
|
+
getLoadContext: (_ctx, context) => context.set(greetingContext, 'hello'),
|
|
571
|
+
proxy: trustProxy({ trusted: ['10.0.0.0/8'] }), // behind a TLS proxy: request.url is the public URL
|
|
572
|
+
listen: { idleTimeout: 30 }, // its port and hostname, if given, win over PORT and HOST
|
|
573
|
+
onListen: (server) => console.log(`up on ${server.url}`),
|
|
574
|
+
});
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
`proxy` is `alxia({ proxy })`'s option: behind the proxies it names,
|
|
578
|
+
`ctx.ip` is the client's and React Router's `request.url` the URL the
|
|
579
|
+
client asked for, `https://` and the public host, so a loader can build an
|
|
580
|
+
absolute link from it; from any other connection the forwarded headers are
|
|
581
|
+
ignored. A server of your own gives `alxia({ proxy })` the same option. [More](https://github.com/softistx/alxia/blob/develop/packages/core/docs/guide/serving.md#behind-a-proxy-proxy)
|
|
582
|
+
|
|
583
|
+
`build`, `mode` and `client` override what the plugin wires;
|
|
584
|
+
`client: false` serves no client files, so you can serve them yourself.
|
|
585
|
+
A server of your own, with no plugin, calls `reactRouter(app, { build,
|
|
586
|
+
client })` itself. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/customising-the-server.md#escape-hatches)
|
|
587
|
+
|
|
588
|
+
## The client's files
|
|
589
|
+
|
|
590
|
+
In a build, `build/client` is served before `configure`'s middlewares:
|
|
591
|
+
|
|
592
|
+
| path | `Cache-Control` |
|
|
593
|
+
| --- | --- |
|
|
594
|
+
| `/assets/*`, the hashed bundles | `public, max-age=31536000, immutable` |
|
|
595
|
+
| every other top-level file or folder, the copies of `public/` | `public, max-age=3600` |
|
|
596
|
+
|
|
597
|
+
A missing asset gets alxia's JSON 404, not a page. In dev, Vite serves
|
|
598
|
+
these files.
|
|
599
|
+
|
|
600
|
+
`react-router build` also writes `.br` and `.gz` copies beside every
|
|
601
|
+
compressible file of the client build (JavaScript, CSS, HTML, SVG, JSON,
|
|
602
|
+
text, XML, web manifests, source maps, WebAssembly, icons, fonts) of at least 1 kB, and the server sends the one a
|
|
603
|
+
browser accepts, with `Content-Encoding` and `Vary: Accept-Encoding`, the
|
|
604
|
+
`Cache-Control` above unchanged. `alxia({ precompress: false })` writes none,
|
|
605
|
+
`alxia({ precompress: { minSize: 4096 } })` moves the threshold, and
|
|
606
|
+
`createServer({ precompressed: false })` (or `reactRouter(app, {
|
|
607
|
+
precompressed: false })`) serves the files as they are, behind a proxy that
|
|
608
|
+
compresses. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/beside-the-pages.md#compressed)
|
|
609
|
+
|
|
610
|
+
## Leaving the pages out of `matchesSpec`
|
|
611
|
+
|
|
612
|
+
An API under `/api`, spec first, is checked against its OpenAPI document
|
|
613
|
+
by [`@softistx/alxia-openapi`](https://www.npmjs.com/package/@softistx/alxia-openapi)'s
|
|
614
|
+
`matchesSpec` (`bun add -d @softistx/alxia-openapi`), which reads `app.routes`. The
|
|
615
|
+
catch-all and the client's files are routes too, and no operation of the
|
|
616
|
+
document: left alone, they only come back as `extra`, and `strict: true`
|
|
617
|
+
makes them fail:
|
|
618
|
+
|
|
619
|
+
```ts
|
|
620
|
+
// app/server.test.ts
|
|
621
|
+
import { test } from 'bun:test';
|
|
622
|
+
import { matchesSpec } from '@softistx/alxia-openapi';
|
|
623
|
+
import { isReactRouterRoute } from '@softistx/alxia-react-router';
|
|
624
|
+
import type { ServerBuild } from 'react-router';
|
|
625
|
+
import { operations } from './generated/alxia';
|
|
626
|
+
import server from './server';
|
|
627
|
+
|
|
628
|
+
test('the API routes every operation of openapi.yaml, and nothing else', async () => {
|
|
629
|
+
const build: ServerBuild = await import(new URL('../build/server/index.js', import.meta.url).href);
|
|
630
|
+
const app = server.create({ build });
|
|
631
|
+
matchesSpec(app, operations, { strict: true, exclude: isReactRouterRoute });
|
|
632
|
+
});
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
`isReactRouterRoute` is true for each route this package declared, so
|
|
636
|
+
`matchesSpec` checks your own routes alone, under `strict`.
|
|
637
|
+
|
|
638
|
+
## Built for Bun
|
|
639
|
+
|
|
640
|
+
The server build runs on Bun, so the plugin builds it for Bun, with
|
|
641
|
+
nothing to configure. In Vite's `ssr` environment, in dev and in the
|
|
642
|
+
build, it adds:
|
|
643
|
+
|
|
644
|
+
- the `bun` export condition, to `resolve.conditions` and
|
|
645
|
+
`resolve.externalConditions`: a package that exports a `bun` variant is
|
|
646
|
+
bundled, and loaded in dev, as that variant;
|
|
647
|
+
- `bun` and `bun:*` to `resolve.builtins`: Bun's own modules stay imports
|
|
648
|
+
of `build/server/index.js`;
|
|
649
|
+
- `build.target: 'esnext'`, where Vite's default targets browsers;
|
|
650
|
+
- in the build only, `resolve.noExternal: true`: every package is bundled
|
|
651
|
+
into `build/server/index.js`, so `build/` runs with no `node_modules`.
|
|
652
|
+
- `/entry` and `/document` inlined, in dev by an alias and in the build, so
|
|
653
|
+
they share the app's `react-router`, even when the package is listed in
|
|
654
|
+
`ssr.external`.
|
|
655
|
+
|
|
656
|
+
```ts
|
|
657
|
+
// app/server.ts: Bun's modules, bundled as they are
|
|
658
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
659
|
+
import { Database } from 'bun:sqlite';
|
|
660
|
+
|
|
661
|
+
const db = new Database(':memory:');
|
|
662
|
+
|
|
663
|
+
export default createServer({
|
|
664
|
+
configure: (app) =>
|
|
665
|
+
app.get('/api/sqlite', ({ reply }) =>
|
|
666
|
+
reply.ok(db.query('select sqlite_version() as version').get()),
|
|
667
|
+
),
|
|
668
|
+
});
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
What the app sets wins: its own conditions and builtins are kept, `bun` is
|
|
672
|
+
added beside them, and a `build.target` it set is left as it is.
|
|
673
|
+
`ssr.target` stays `node`, and no polyfill is added; an app that sets
|
|
674
|
+
`ssr.target: 'webworker'` itself gets none of this, only Vite's defaults.
|
|
675
|
+
A package that cannot be bundled, a native addon, stays external when the
|
|
676
|
+
app names it, and every package does with `ssr.external: true`:
|
|
677
|
+
|
|
678
|
+
```ts
|
|
679
|
+
// vite.config.ts: sharp imported from node_modules at runtime
|
|
680
|
+
export default defineConfig({
|
|
681
|
+
ssr: { external: ['sharp'] },
|
|
682
|
+
plugins: [reactRouter(), alxia()],
|
|
683
|
+
});
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
The
|
|
687
|
+
[guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/how-it-works.md#built-for-bun)
|
|
688
|
+
has each option and why.
|
|
689
|
+
|
|
690
|
+
## Docker
|
|
691
|
+
|
|
692
|
+
A multi-stage `Dockerfile` on Bun's official images, built on Debian's
|
|
693
|
+
and run on Alpine's, as `@softistx/alxia-create`'s
|
|
694
|
+
`react-router` template ships it. For an app from `create-react-router`,
|
|
695
|
+
it replaces the template's, which runs on Node. The build is
|
|
696
|
+
self-contained, so the image holds `build/` alone, no `node_modules`:
|
|
697
|
+
|
|
698
|
+
```dockerfile
|
|
699
|
+
FROM oven/bun:1 AS build
|
|
700
|
+
WORKDIR /app
|
|
701
|
+
COPY package.json bun.lock* bunfig.toml* ./
|
|
702
|
+
RUN bun install --frozen-lockfile
|
|
703
|
+
COPY . .
|
|
704
|
+
RUN bun run build
|
|
705
|
+
|
|
706
|
+
FROM oven/bun:1-alpine
|
|
707
|
+
WORKDIR /app
|
|
708
|
+
ENV NODE_ENV=production
|
|
709
|
+
COPY --from=build /app/build ./build
|
|
710
|
+
USER bun
|
|
711
|
+
EXPOSE 3000
|
|
712
|
+
CMD ["bun", "--no-install", "build/server/index.js"]
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
```sh
|
|
716
|
+
docker build -t my-app .
|
|
717
|
+
docker run -p 3000:3000 my-app
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
Keep the template's `.dockerignore`, and commit `bun.lock`. The server
|
|
721
|
+
runs as the non-root `bun` user, on `PORT` (3000). The
|
|
722
|
+
[guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/deploying.md#docker)
|
|
723
|
+
has the commented file, and what to copy for a package left external.
|
|
724
|
+
|
|
725
|
+
## Installable and offline (PWA)
|
|
726
|
+
|
|
727
|
+
`@softistx/alxia-react-router/pwa` holds what an installable app shares and that has
|
|
728
|
+
no UI: the service worker's contract, which requests it caches and which
|
|
729
|
+
responses it may store, the precache list read from a build, the
|
|
730
|
+
registration and update notice, the web app manifest, and the cleaning at
|
|
731
|
+
sign-out. It imports nothing, so the worker, a build script, the page and
|
|
732
|
+
the server can all import it. The worker itself is `startWorker` in
|
|
733
|
+
`/pwa/worker`, its build `buildWorker` in `/pwa/build`, the hooks are in
|
|
734
|
+
`/pwa/react` (`react`, an optional peer) and `noCache` in `/pwa/server`; this
|
|
735
|
+
package never reads `import.meta.env`, so the app passes `enabled`.
|
|
736
|
+
|
|
737
|
+
With `app/service-worker.ts` in the app, `react-router build` writes
|
|
738
|
+
`build/client/service-worker.js` itself: `alxia()` bundles the file after the
|
|
739
|
+
client build, with the precache list written in, and there is no script to
|
|
740
|
+
add. It needs Bun (`bun --bun react-router build`, or a `bunfig.toml` with
|
|
741
|
+
`[run] bun = true`). `alxia({ worker: 'app/pwa/worker.ts' })` names another file
|
|
742
|
+
and `alxia({ worker: false })` builds none.
|
|
743
|
+
|
|
744
|
+
The worker bundles Workbox, whose six packages are optional peers:
|
|
745
|
+
|
|
746
|
+
```sh
|
|
747
|
+
bun add -d workbox-core workbox-expiration workbox-navigation-preload workbox-precaching workbox-routing workbox-strategies
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
```ts
|
|
751
|
+
// file: app/pwa-contract.ts
|
|
752
|
+
// Shared by the worker and the page: every cache is named `my-app-<kind>-<version>`.
|
|
753
|
+
import { defineWorkerContract } from '@softistx/alxia-react-router/pwa';
|
|
754
|
+
|
|
755
|
+
export const workerContract = defineWorkerContract({ cachePrefix: 'my-app' });
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
```ts
|
|
759
|
+
// file: app/service-worker.ts
|
|
760
|
+
import { startWorker } from '@softistx/alxia-react-router/pwa/worker';
|
|
761
|
+
import { workerContract } from './pwa-contract';
|
|
762
|
+
|
|
763
|
+
startWorker({ contract: workerContract });
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
```tsx
|
|
767
|
+
// file: app/root.tsx
|
|
768
|
+
import { manifestHref } from '@softistx/alxia-react-router/pwa';
|
|
769
|
+
import { useServiceWorker } from '@softistx/alxia-react-router/pwa/react';
|
|
770
|
+
import { Outlet } from 'react-router';
|
|
771
|
+
|
|
772
|
+
// The browser reads the manifest to offer the install.
|
|
773
|
+
export function links() {
|
|
774
|
+
return [{ rel: 'manifest', href: manifestHref('en') }];
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// A production build only, never under `react-router dev`.
|
|
778
|
+
export default function App() {
|
|
779
|
+
useServiceWorker({ enabled: import.meta.env.PROD });
|
|
780
|
+
return <Outlet />;
|
|
781
|
+
}
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
```ts
|
|
785
|
+
// file: app/server.ts
|
|
786
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
787
|
+
import {
|
|
788
|
+
MANIFEST_HEADERS,
|
|
789
|
+
MANIFEST_PATH,
|
|
790
|
+
SERVICE_WORKER_URL,
|
|
791
|
+
webAppManifest,
|
|
792
|
+
} from '@softistx/alxia-react-router/pwa';
|
|
793
|
+
import { noCache } from '@softistx/alxia-react-router/pwa/server';
|
|
794
|
+
|
|
795
|
+
// beforeAll runs before the client's files: the worker's script is
|
|
796
|
+
// revalidated. The manifest is a route, served with its own headers.
|
|
797
|
+
export default createServer({
|
|
798
|
+
beforeAll: (app) => app.use(SERVICE_WORKER_URL, noCache),
|
|
799
|
+
configure: (app) =>
|
|
800
|
+
app.get(MANIFEST_PATH, ({ reply }) => {
|
|
801
|
+
const manifest = webAppManifest({
|
|
802
|
+
name: 'My app',
|
|
803
|
+
description: 'My installable app',
|
|
804
|
+
lang: 'en',
|
|
805
|
+
themeColor: '#1e40af',
|
|
806
|
+
backgroundColor: '#ffffff',
|
|
807
|
+
});
|
|
808
|
+
return reply(200, JSON.stringify(manifest), { headers: MANIFEST_HEADERS });
|
|
809
|
+
}),
|
|
810
|
+
});
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
The manifest names four icons (`MINIMAL_2023_ICONS`): put
|
|
814
|
+
`pwa-64x64.png`, `pwa-192x192.png`, `pwa-512x512.png` and
|
|
815
|
+
`maskable-icon-512x512.png` in `public/`, which `@vite-pwa/assets-generator`'s
|
|
816
|
+
`minimal2023Preset` writes from one image. A browser offers the install with
|
|
817
|
+
a 192 and a 512.
|
|
818
|
+
|
|
819
|
+
The worker serves a page load from `public/offline.html` when the network
|
|
820
|
+
fails, and the build needs the file:
|
|
821
|
+
|
|
822
|
+
```html
|
|
823
|
+
<!-- file: public/offline.html -->
|
|
824
|
+
<!doctype html>
|
|
825
|
+
<html lang="en">
|
|
826
|
+
<head>
|
|
827
|
+
<meta charset="utf-8" />
|
|
828
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
829
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'" />
|
|
830
|
+
<title>Offline</title>
|
|
831
|
+
</head>
|
|
832
|
+
<body>
|
|
833
|
+
<h1>You are offline</h1>
|
|
834
|
+
<p>Check your connection and try again.</p>
|
|
835
|
+
</body>
|
|
836
|
+
</html>
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
Set `routeDiscovery: { mode: 'initial' }` in `react-router.config.ts`, so a
|
|
840
|
+
client navigation offline to a route never visited finds its modules
|
|
841
|
+
([more](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#offline-a-client-navigation-to-a-route-never-visited-shows-the-offline-page)):
|
|
842
|
+
|
|
843
|
+
```ts
|
|
844
|
+
import type { Config } from '@react-router/dev/config';
|
|
845
|
+
|
|
846
|
+
export default { ssr: true, routeDiscovery: { mode: 'initial' } } satisfies Config;
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
An app that built its worker with a script of its own has steps to drop:
|
|
850
|
+
[moving from a build script of your own](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/pwa.md#moving-from-a-build-script-of-your-own).
|
|
851
|
+
|
|
852
|
+
For a build pipeline of your own, `buildWorker` from `/pwa/build` does what
|
|
853
|
+
`alxia()` does. It needs Bun and runs after `react-router build`:
|
|
854
|
+
|
|
855
|
+
```ts
|
|
856
|
+
// file: scripts/build-worker.ts
|
|
857
|
+
import { buildWorker } from '@softistx/alxia-react-router/pwa/build';
|
|
858
|
+
|
|
859
|
+
await buildWorker({ file: 'app/service-worker.ts' });
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
The [PWA guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/pwa.md)
|
|
863
|
+
has the worker's options, the offline page, the manifest route, the update
|
|
864
|
+
banner and the rest.
|
|
865
|
+
|
|
866
|
+
## An API's refusals, worded for the page
|
|
867
|
+
|
|
868
|
+
`@softistx/alxia-react-router/errors` has no UI; its one runtime import is `react-router`, never `@softistx/alxia`. It
|
|
869
|
+
holds the shape of a GraphQL API's refusal, declared structurally (no `@nxgt/graphql-client` at
|
|
870
|
+
runtime), a REST API's RFC 9457 problem reply (`problemError`), the request id an API echoes, the page a request is for, the
|
|
871
|
+
catalogue of the API's messages an app keeps, the words of a form's checks,
|
|
872
|
+
the provider that fills the catalogue in the browser, the wording of a refusal, the loaders and actions that answer with it, the JSON actions (CSRF check) with their fetcher hook, and what a failed call to the API becomes (`apiCallFailure`):
|
|
873
|
+
|
|
874
|
+
```ts
|
|
875
|
+
import { isApiErrorLike, nextOf, requestIdOf } from '@softistx/alxia-react-router/errors';
|
|
876
|
+
|
|
877
|
+
export function describe(error: unknown, request: Request) {
|
|
878
|
+
return isApiErrorLike(error)
|
|
879
|
+
? { code: error.code, status: error.status, next: nextOf(request.url) }
|
|
880
|
+
: undefined;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export const idOf = (response: Response) => requestIdOf(response);
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
The catalogue is an instance made with the app's ICU formatter. A form's checks
|
|
887
|
+
read it through `apiCodeResolver`, and the provider fills it from the root's data:
|
|
888
|
+
|
|
889
|
+
```ts
|
|
890
|
+
import {
|
|
891
|
+
ApiMessagesProvider,
|
|
892
|
+
apiCodeResolver,
|
|
893
|
+
createApiMessages,
|
|
894
|
+
} from '@softistx/alxia-react-router/errors';
|
|
895
|
+
|
|
896
|
+
type Language = 'en' | 'fr';
|
|
897
|
+
|
|
898
|
+
export const apiMessages = createApiMessages<Language>({
|
|
899
|
+
format: (message) => message, // the app's ICU formatter goes here
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
export const resolver = apiCodeResolver(apiMessages, {
|
|
903
|
+
translate: (key) => key,
|
|
904
|
+
language: () => 'en',
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
// In the root: <ApiMessagesProvider messages={apiMessages} value={data.catalogue}>…
|
|
908
|
+
export const provider = ApiMessagesProvider({
|
|
909
|
+
messages: apiMessages,
|
|
910
|
+
value: { en: {}, fr: {} },
|
|
911
|
+
children: null,
|
|
912
|
+
});
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
A failed call is worded in the page's language by `createApiErrors`:
|
|
916
|
+
|
|
917
|
+
```ts
|
|
918
|
+
import { createApiErrors } from '@softistx/alxia-react-router/errors';
|
|
919
|
+
import { apiMessages } from './api-messages';
|
|
920
|
+
|
|
921
|
+
export const apiErrors = createApiErrors<'en' | 'fr'>({
|
|
922
|
+
messages: apiMessages,
|
|
923
|
+
unavailable: (language) => (language === 'en' ? 'Unavailable' : 'Indisponible'),
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
// In an action's catch: { message, status }, or undefined (rethrow it).
|
|
927
|
+
export const refusal = (error: unknown) => apiErrors.apiRefusal(error, 'en');
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
A loader throws the API's error as a route error, with the call's request id
|
|
931
|
+
for the error page; an action answers a refusal as data:
|
|
932
|
+
|
|
933
|
+
```ts
|
|
934
|
+
import { errorRequestId, routeError } from '@softistx/alxia-react-router/errors';
|
|
935
|
+
import { apiErrors } from './api-errors';
|
|
936
|
+
|
|
937
|
+
// In a loader's catch: a 401, 403, 404 or 503 ApiError becomes a route error.
|
|
938
|
+
export const thrown = (error: unknown) => routeError(error);
|
|
939
|
+
|
|
940
|
+
// In the root's ErrorBoundary: the reference the user can quote.
|
|
941
|
+
export const reference = (error: unknown) => errorRequestId(error);
|
|
942
|
+
|
|
943
|
+
// A fetcher's action: { ok: true, …value }, or { ok: false, error } with a status.
|
|
944
|
+
export const rename = (run: () => Promise<{ title: string }>) =>
|
|
945
|
+
apiErrors.fetcherResult('en', { intent: 'rename' }, run);
|
|
946
|
+
|
|
947
|
+
// A form's action: { ok: true, value }, or the form's errors with a status.
|
|
948
|
+
export const create = (run: () => Promise<{ id: string }>) =>
|
|
949
|
+
apiErrors.submitForm('en', run, (path) =>
|
|
950
|
+
path === 'todo.title' ? 'title' : undefined,
|
|
951
|
+
);
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
A caught `data(body, { status })` value or `Response` (what `oauthConsent`'s action throws) is
|
|
955
|
+
recognised with `isRouteRefusal(value)`, and `routeRefusalStatus(value)` reads its status:
|
|
956
|
+
|
|
957
|
+
```ts
|
|
958
|
+
import { routeRefusalStatus } from '@softistx/alxia-react-router/errors';
|
|
959
|
+
|
|
960
|
+
export const signedOut = (value: unknown) => routeRefusalStatus(value) === 401;
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
JSON actions refuse a post from another site, and read a Standard Schema's input:
|
|
964
|
+
|
|
965
|
+
```ts
|
|
966
|
+
import { jsonActions, useJsonFetcher } from '@softistx/alxia-react-router/errors';
|
|
967
|
+
import { z } from 'zod';
|
|
968
|
+
|
|
969
|
+
// Behind a TLS proxy named with createServer({ proxy }), nothing to set; else: origin: () => process.env.APP_ORIGIN
|
|
970
|
+
export const { readInput } = jsonActions();
|
|
971
|
+
|
|
972
|
+
const schema = z.object({ title: z.string().min(1) });
|
|
973
|
+
|
|
974
|
+
export async function action({ request }: { request: Request }) {
|
|
975
|
+
return readInput(request, schema); // 400 when the input is refused
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// In the component: const { post, busy } = useJsonFetcher<typeof action>();
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
A call that failed is turned into what a loader throws, and logged with the API's request id, by `apiCallFailure(error, { api, operation: operationName(document), requestId })`
|
|
982
|
+
(your own `execute` calls it in its `catch`):
|
|
983
|
+
|
|
984
|
+
```ts
|
|
985
|
+
import { apiCallFailure, operationName } from '@softistx/alxia-react-router/errors';
|
|
986
|
+
import type { DocumentNode } from 'graphql';
|
|
987
|
+
|
|
988
|
+
export function failed(error: unknown, document: DocumentNode, requestId?: string, signal?: AbortSignal) {
|
|
989
|
+
return apiCallFailure(error, { api: 'my-api', operation: operationName(document), requestId, signal });
|
|
990
|
+
}
|
|
991
|
+
// In execute(): catch (error) { throw failed(error, document, requestId, signal); }
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
The API's catalogue is read and kept fresh by `createErrorCatalogue`; the root's
|
|
995
|
+
middleware awaits `freshAll()`, its loader returns `clientMessages()` and
|
|
996
|
+
`server.ts` calls `warm()`:
|
|
997
|
+
|
|
998
|
+
```ts
|
|
999
|
+
import { createErrorCatalogue } from '@softistx/alxia-react-router/errors';
|
|
1000
|
+
import { apiMessages } from './api-messages';
|
|
1001
|
+
|
|
1002
|
+
export const catalogue = createErrorCatalogue<'en' | 'fr'>({
|
|
1003
|
+
messages: apiMessages,
|
|
1004
|
+
languages: ['en', 'fr'],
|
|
1005
|
+
read: async (language) => fetchCatalogue(language), // { version, messages }
|
|
1006
|
+
versions: async () => fetchVersions(), // { en: '…', fr: '…' }
|
|
1007
|
+
ttlMs: () => Number(process.env.CATALOGUE_TTL_MS ?? 60_000),
|
|
1008
|
+
clientCodes: ['validation.errors.required'],
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
declare function fetchCatalogue(
|
|
1012
|
+
language: string,
|
|
1013
|
+
): Promise<{ version: string; messages: { code: string; message: string; params: { name: string; kind: 'TEXT' }[] }[] }>;
|
|
1014
|
+
declare function fetchVersions(): Promise<{ en: string; fr: string }>;
|
|
1015
|
+
|
|
1016
|
+
// The root's middleware: await catalogue.freshAll();
|
|
1017
|
+
// The root's loader: return { messages: catalogue.clientMessages() };
|
|
1018
|
+
// server.ts, at startup: catalogue.warm();
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
The [errors guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/errors.md)
|
|
1022
|
+
has the rest.
|
|
1023
|
+
|
|
1024
|
+
## Sessions for a BFF
|
|
1025
|
+
|
|
1026
|
+
An app that renders its pages and calls a GraphQL API that signs users in
|
|
1027
|
+
with `@softistx/janus` keeps the API's token in its own HttpOnly cookie.
|
|
1028
|
+
`@softistx/alxia-react-router/session` holds that session's server side, built on
|
|
1029
|
+
`/errors`; `/session/react` holds the page's hooks around it (`useSignOut`, `useLinkParam`, `useLinkFragment`,
|
|
1030
|
+
`useCodeField`); `/session/model` imports nothing and is safe in a component.
|
|
1031
|
+
`/session` and `/session/model` add no peer; `/session/react` needs `react`, an optional peer.
|
|
1032
|
+
|
|
1033
|
+
```ts
|
|
1034
|
+
// app/session.server.ts
|
|
1035
|
+
import { sessionCookies, signInFlow } from '@softistx/alxia-react-router/session';
|
|
1036
|
+
import { errors, json } from './errors.server'; // createApiErrors, jsonActions
|
|
1037
|
+
import { SignOutMutation, execute } from './api.server';
|
|
1038
|
+
|
|
1039
|
+
export const cookies = sessionCookies({
|
|
1040
|
+
session: 'my-app_session',
|
|
1041
|
+
challenge: 'my-app_challenge',
|
|
1042
|
+
secure: !import.meta.env.DEV,
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
export const signIn = signInFlow({
|
|
1046
|
+
cookies,
|
|
1047
|
+
errors,
|
|
1048
|
+
json,
|
|
1049
|
+
revoke: (token, request) =>
|
|
1050
|
+
execute(SignOutMutation, {}, { token, signal: request.signal }),
|
|
1051
|
+
attemptsLeft: (count, language) => `${count} tries left`,
|
|
1052
|
+
});
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
```ts
|
|
1056
|
+
// app/routes/sign-in.tsx
|
|
1057
|
+
export async function action({ context, request }: Route.ActionArgs) {
|
|
1058
|
+
const { language } = alxiaOf(context);
|
|
1059
|
+
json.requireJsonPost(request); // a form posted before hydration goes back
|
|
1060
|
+
const input = await json.readInput(request, SignInInput);
|
|
1061
|
+
return signIn.signInStep(
|
|
1062
|
+
async () => toAnswer((await execute(SignInMutation, input)).signIn),
|
|
1063
|
+
{ request, language, next: signIn.nextParam(request), extra: {} },
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
A signed-in answer redirects to `next` (kept on the site by `safeNext`) with
|
|
1069
|
+
the session cookie set; a second factor goes to the code page; a refusal stays
|
|
1070
|
+
on the form. `stepUpSteps` asks for a code before a sensitive action, and
|
|
1071
|
+
`authLinks` serves the pages a mail's link opens. The
|
|
1072
|
+
[session guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md)
|
|
1073
|
+
has a complete sign-in route and the rest.
|
|
1074
|
+
|
|
1075
|
+
A password sign-in of your own gets `createSignInThrottle` from the same
|
|
1076
|
+
subpath: failures per key within a window, a bounded number of keys, a global
|
|
1077
|
+
bucket that delays rather than locks, and a cap on concurrent password
|
|
1078
|
+
hashes. It is per process.
|
|
1079
|
+
|
|
1080
|
+
```ts
|
|
1081
|
+
import { createSignInThrottle } from '@softistx/alxia-react-router/session';
|
|
1082
|
+
|
|
1083
|
+
const throttle = createSignInThrottle({ max: 5, windowMs: 15 * 60_000 });
|
|
1084
|
+
|
|
1085
|
+
const seconds = throttle.wait(email); // 0 when allowed
|
|
1086
|
+
if (seconds > 0) return tooMany(seconds);
|
|
1087
|
+
const checked = await throttle.verify(() => Bun.password.verify(password, hash));
|
|
1088
|
+
if (checked.busy) return tryLater();
|
|
1089
|
+
if (!checked.value) {
|
|
1090
|
+
throttle.fail(email);
|
|
1091
|
+
return refused();
|
|
1092
|
+
}
|
|
1093
|
+
throttle.clear(email);
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
Past the global limit the default is a refusal for every key. To only slow
|
|
1097
|
+
attempts down, use `globalMode: 'delay'`: `wait(key)` then answers per key
|
|
1098
|
+
alone, and `globalDelay()` gives a delay in milliseconds that grows with the
|
|
1099
|
+
failures past `globalMax` and stops at `maxDelayMs` (3 000 by default).
|
|
1100
|
+
|
|
1101
|
+
```ts
|
|
1102
|
+
const throttle = createSignInThrottle({
|
|
1103
|
+
globalMax: 20,
|
|
1104
|
+
globalWindowMs: 15 * 60_000,
|
|
1105
|
+
globalMode: 'delay',
|
|
1106
|
+
maxDelayMs: 3_000,
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
const delay = throttle.globalDelay(); // 0 below globalMax
|
|
1110
|
+
if (delay > 0) await Bun.sleep(delay);
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
## A GraphQL subscription for the browser
|
|
1114
|
+
|
|
1115
|
+
`@softistx/alxia-react-router/subscription` exposes subscriptions of your API to the
|
|
1116
|
+
browser through a resource route, without giving it the token or a way to
|
|
1117
|
+
write its own document. `allow` maps each operation name to the document the
|
|
1118
|
+
server sends for it; the client names an operation and sends variables, and
|
|
1119
|
+
its own `query` and `extensions` are ignored. The bearer comes from the
|
|
1120
|
+
session, both methods refuse a cross-site request, a heartbeat keeps the
|
|
1121
|
+
stream open, the browser leaving aborts the upstream request, and an upstream
|
|
1122
|
+
429 is passed on with its `retryAfter`. It speaks GraphQL over SSE in distinct
|
|
1123
|
+
connections mode, so `graphql-sse` works against it. It imports nothing and adds no peer.
|
|
1124
|
+
|
|
1125
|
+
```ts
|
|
1126
|
+
// app/routes/events.ts
|
|
1127
|
+
import { alxiaOf } from '@softistx/alxia-react-router';
|
|
1128
|
+
import {
|
|
1129
|
+
createSubscriptionProxy,
|
|
1130
|
+
type SubscriptionArgs,
|
|
1131
|
+
} from '@softistx/alxia-react-router/subscription';
|
|
1132
|
+
import { print } from 'graphql';
|
|
1133
|
+
import type { RouterContextProvider } from 'react-router';
|
|
1134
|
+
import { RoomEventsDocument } from '../generated/graphql';
|
|
1135
|
+
import { cookies } from '../session.server';
|
|
1136
|
+
|
|
1137
|
+
const events = createSubscriptionProxy({
|
|
1138
|
+
endpoint: 'https://api.example.com/graphql',
|
|
1139
|
+
allow: { RoomEvents: print(RoomEventsDocument) },
|
|
1140
|
+
getToken: (request) => cookies.token(request),
|
|
1141
|
+
// the route's context is the second argument: send the trusted client address
|
|
1142
|
+
headers: (
|
|
1143
|
+
request,
|
|
1144
|
+
{ context }: SubscriptionArgs<Readonly<RouterContextProvider>>,
|
|
1145
|
+
) => ({
|
|
1146
|
+
'x-forwarded-for': context ? alxiaOf(context).ip : null,
|
|
1147
|
+
'accept-language': request.headers.get('accept-language'),
|
|
1148
|
+
}),
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
export const loader = events.loader; // GET
|
|
1152
|
+
export const action = events.action; // POST
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
See the [subscription guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/subscriptions.md)
|
|
1156
|
+
for the rules, the options and the errors.
|
|
1157
|
+
|
|
1158
|
+
### Keep it alive in the page: `useLiveSubscription`
|
|
1159
|
+
|
|
1160
|
+
`@softistx/alxia-react-router/subscription/react` is the browser side. It wraps
|
|
1161
|
+
`useSubscription` of `@nxgt/graphql-client/react` (an optional peer, `^0.7.0`,
|
|
1162
|
+
under a `GraphQLProvider`) and owns what a long-lived stream needs: reconnect
|
|
1163
|
+
with a growing wait (1 s doubling to 30 s), a stop on a 401 or any 4xx repeating
|
|
1164
|
+
cannot change, a 429's `retryAfter` honoured, events older than the highest
|
|
1165
|
+
version seen per key dropped, and a debounced revalidate after every reopen but
|
|
1166
|
+
the first (nothing is replayed).
|
|
1167
|
+
|
|
1168
|
+
```tsx
|
|
1169
|
+
import { useLiveSubscription } from '@softistx/alxia-react-router/subscription/react';
|
|
1170
|
+
import { useRevalidator } from 'react-router';
|
|
1171
|
+
|
|
1172
|
+
function Room({ id }: { id: string }) {
|
|
1173
|
+
const revalidator = useRevalidator();
|
|
1174
|
+
const { status, retry } = useLiveSubscription(
|
|
1175
|
+
RoomChangedDocument,
|
|
1176
|
+
{ id },
|
|
1177
|
+
{
|
|
1178
|
+
keyOf: (event) => event.room.id,
|
|
1179
|
+
versionOf: (event) => event.room.version,
|
|
1180
|
+
onChange: (event) => setRoom(event.room), // fresh events only
|
|
1181
|
+
revalidate: () => revalidator.revalidate(),
|
|
1182
|
+
},
|
|
1183
|
+
);
|
|
1184
|
+
return status === 'stopped' ? <button onClick={retry}>Reconnect</button> : null;
|
|
1185
|
+
}
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
Leave out `versionOf` and `revalidate` for a stream whose every event is the
|
|
1189
|
+
whole state (a presence list): every event is delivered and a reopen reads
|
|
1190
|
+
nothing. See the [subscription guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/subscriptions.md#keep-it-alive-in-the-page).
|
|
1191
|
+
|
|
1192
|
+
## An API's MCP and OAuth endpoints on the app's origin
|
|
1193
|
+
|
|
1194
|
+
`@softistx/alxia-react-router/mcp` serves the API's MCP server and its OAuth endpoints
|
|
1195
|
+
on the app's own origin, so an MCP client only ever talks to the BFF.
|
|
1196
|
+
`mcpRelay` is a `beforeAll` plugin: it relays `/mcp`, `/oauth/authorize`,
|
|
1197
|
+
`/oauth/token`, `/oauth/register`, `/oauth/revoke`,
|
|
1198
|
+
`/.well-known/oauth-authorization-server` and
|
|
1199
|
+
`/.well-known/oauth-protected-resource/mcp` to the API. `/oauth/consent` (your
|
|
1200
|
+
consent route) and every other path stay the app's. The list is `MCP_RELAY_PATHS` of `@softistx/alxia`, which the API can guard with
|
|
1201
|
+
`requireProxySecret` so it accepts them from the relay alone ([MCP guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/mcp.md#let-the-api-accept-them-from-the-relay-alone)).
|
|
1202
|
+
|
|
1203
|
+
The relay runs on `@softistx/alxia-proxy`, an optional peer the app installs:
|
|
1204
|
+
`bun add @softistx/alxia-proxy` (without it, see
|
|
1205
|
+
[Cannot find package '@softistx/alxia-proxy'](./docs/troubleshooting.md#error-cannot-find-package-softistxalxia-proxy-from-softistxalxia-react-routerdistmcpindexjs)).
|
|
1206
|
+
|
|
1207
|
+
```ts
|
|
1208
|
+
// app/server.ts
|
|
1209
|
+
import { createServer } from '@softistx/alxia-react-router';
|
|
1210
|
+
import { mcpRelay } from '@softistx/alxia-react-router/mcp';
|
|
1211
|
+
|
|
1212
|
+
export default createServer({
|
|
1213
|
+
beforeAll: (app) =>
|
|
1214
|
+
app.plugin(
|
|
1215
|
+
mcpRelay({
|
|
1216
|
+
api: 'https://api.internal:3000',
|
|
1217
|
+
secret: { header: 'x-app-proxy-secret', value: process.env.API_PROXY_SECRET ?? '' },
|
|
1218
|
+
}),
|
|
1219
|
+
),
|
|
1220
|
+
});
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
The client's `Authorization`, `Origin`, method and body go through unchanged;
|
|
1224
|
+
its Cookie never does and no session Bearer is added. `X-Forwarded-For` is
|
|
1225
|
+
the client address the app resolved (set `createServer({ proxy })` behind a
|
|
1226
|
+
trusted proxy), and the shared secret header is set on every request so the
|
|
1227
|
+
API can trust it. Bodies over 256 KiB on `/mcp` and 64 KiB on `/oauth/*` are a
|
|
1228
|
+
413. The response keeps its status, streamed body (SSE included),
|
|
1229
|
+
`WWW-Authenticate` and `Retry-After`; the API's `Set-Cookie` is dropped (the relay sets one cookie of its own, below) and a
|
|
1230
|
+
`Content-Security-Policy: default-src 'none'; frame-ancestors 'none'` and
|
|
1231
|
+
`X-Content-Type-Options: nosniff` are added.
|
|
1232
|
+
|
|
1233
|
+
A pending consent request is bound to the browser that opened it. When
|
|
1234
|
+
`/oauth/authorize` is answered with a redirect to the app's own origin and
|
|
1235
|
+
consent path, the relay sets an httpOnly, `SameSite=Lax` cookie naming the
|
|
1236
|
+
request (never for a redirect to another host). `oauthConsent` reads it, hands
|
|
1237
|
+
its `caller` a `binding` and, with `requireBinding: true`, answers the expired
|
|
1238
|
+
state to a request this browser did not open:
|
|
1239
|
+
|
|
1240
|
+
```ts
|
|
1241
|
+
mcpRelay({ api, secret, consent: { origin: 'https://app.example' } }); // consent: false turns it off
|
|
1242
|
+
|
|
1243
|
+
const consent = oauthConsent({
|
|
1244
|
+
// …
|
|
1245
|
+
requireBinding: true,
|
|
1246
|
+
origin: 'https://app.example', // the relay's consent.origin: both name the cookie alike
|
|
1247
|
+
caller: (request, binding) => ({ token: cookies.token(request), headers: binding.headers }),
|
|
1248
|
+
});
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
See the [MCP relay guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/mcp.md) for the rules, the options and the errors.
|
|
1252
|
+
|
|
1253
|
+
### Media through the BFF
|
|
1254
|
+
|
|
1255
|
+
`@softistx/alxia-react-router/media` serves and uploads the API's `@softistx/alxia-media` files
|
|
1256
|
+
on the app's own origin: the browser never calls the API or the bucket.
|
|
1257
|
+
`proxyMediaRead` (`GET`, `HEAD`) and `proxyMediaWrite` (`PUT`, `DELETE`) are the
|
|
1258
|
+
`loader` and `action` of a `/media/*` resource route. It checks the request is
|
|
1259
|
+
same-site, sends the session's Bearer (never the browser's cookie, Authorization
|
|
1260
|
+
or API key), answers a `413` for an upload that declares more than the kind's
|
|
1261
|
+
`maxBytes` before calling the API, streams both bodies, forwards `Range`,
|
|
1262
|
+
`If-None-Match` and `If-Range`, and passes the API's status and headers through.
|
|
1263
|
+
A write needs a session (`getToken`, else 401). Opt-in: `onRefusal` / `onSuccess` to word the answers, `forwardQuery` to pass query parameters to the API, `requireHeaders` to demand a header on writes (403 `header_required`). It imports nothing. The page uploads with `uploadMedia` from `@softistx/alxia-react-router/media/client` (progress, abort, typed refusals). Do not apply a `Cache-Control: no-store` middleware to `/media`.
|
|
1264
|
+
|
|
1265
|
+
```ts
|
|
1266
|
+
// app/routes.ts: route('media/*', 'routes/media.ts')
|
|
1267
|
+
// app/routes/media.ts
|
|
1268
|
+
import { proxyMediaRead, proxyMediaWrite, type MediaProxyOptions } from '@softistx/alxia-react-router/media';
|
|
1269
|
+
import type { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
1270
|
+
|
|
1271
|
+
declare function sessionToken(request: Request): string | null;
|
|
1272
|
+
|
|
1273
|
+
const options: MediaProxyOptions = {
|
|
1274
|
+
api: 'https://api.internal:3000',
|
|
1275
|
+
kinds: { avatars: { maxBytes: 512 * 1024 } },
|
|
1276
|
+
getToken: (request) => sessionToken(request),
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
export const loader = (args: LoaderFunctionArgs) => proxyMediaRead(args, options);
|
|
1280
|
+
export const action = (args: ActionFunctionArgs) => proxyMediaWrite(args, options);
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1283
|
+
Opt-in extras on the same `options`:
|
|
1284
|
+
|
|
1285
|
+
```ts
|
|
1286
|
+
import type { MediaProxyOptions } from '@softistx/alxia-react-router/media';
|
|
1287
|
+
|
|
1288
|
+
const extras: Partial<MediaProxyOptions> = {
|
|
1289
|
+
forwardQuery: ['x', 'y', 'size'], // PUT /media/avatars?x=10&y=20&size=256 reaches the API
|
|
1290
|
+
requireHeaders: { 'x-example-client': 'example-ui' }, // else a write is a 403 header_required
|
|
1291
|
+
onRefusal: ({ code }) => ({ ok: false, error: code }),
|
|
1292
|
+
onSuccess: ({ body }) => ({ ok: true, key: (body as { key: string }).key }),
|
|
1293
|
+
};
|
|
1294
|
+
```
|
|
1295
|
+
|
|
1296
|
+
See the [media guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/media.md) for the rules, the options and the refusals.
|
|
1297
|
+
|
|
1298
|
+
## A UI library's links through React Router
|
|
1299
|
+
|
|
1300
|
+
A design system that renders its links through a component of its own (a
|
|
1301
|
+
`LinkComponentProvider`) hands it an `href`, while React Router's `Link` takes
|
|
1302
|
+
`to`. `@softistx/alxia-react-router/link` (`react` and `react-router` are its only
|
|
1303
|
+
imports) exports the adapter, so no app copies it:
|
|
1304
|
+
|
|
1305
|
+
```tsx
|
|
1306
|
+
// app/root.tsx
|
|
1307
|
+
import { RouterLink } from '@softistx/alxia-react-router/link';
|
|
1308
|
+
|
|
1309
|
+
<LinkComponentProvider component={RouterLink}>
|
|
1310
|
+
<Outlet />
|
|
1311
|
+
</LinkComponentProvider>
|
|
1312
|
+
```
|
|
1313
|
+
|
|
1314
|
+
## A fetcher's fresh answer
|
|
1315
|
+
|
|
1316
|
+
A keyed fetcher outlives its page, so a `useEffect` on its data replays an
|
|
1317
|
+
earlier visit's answer on remount. `@softistx/alxia-react-router/fetcher` (`react` and
|
|
1318
|
+
`react-router` are its imports) calls your handler once per new answer:
|
|
1319
|
+
|
|
1320
|
+
```tsx
|
|
1321
|
+
import { useJsonFetcher } from '@softistx/alxia-react-router/errors';
|
|
1322
|
+
import { useFetcherAnswer } from '@softistx/alxia-react-router/fetcher';
|
|
1323
|
+
|
|
1324
|
+
const { fetcher } = useJsonFetcher<typeof action>('save');
|
|
1325
|
+
const answer = useFetcherAnswer(fetcher, (result) => toast(result.message));
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
To react only when a write succeeded (close the dialog that sent it), `useFetcherDone(fetcher, (result) => result.ok, () => setOpen(false))` runs the callback once per new accepted answer, and not again when the dialog reopens with the fetcher's old data.
|
|
1329
|
+
|
|
1330
|
+
To await one submission's answer as a Promise (a confirm dialog whose `onConfirm` stays open and shows the error until it settles), `useFetcherPromise` resolves with the next new answer, or rejects with an `Error` when your `refusal(answer)` returns a message:
|
|
1331
|
+
|
|
1332
|
+
```tsx
|
|
1333
|
+
import { useJsonFetcher } from '@softistx/alxia-react-router/errors';
|
|
1334
|
+
import { useFetcherPromise } from '@softistx/alxia-react-router/fetcher';
|
|
1335
|
+
|
|
1336
|
+
const { fetcher, post } = useJsonFetcher<typeof action>('delete');
|
|
1337
|
+
const run = useFetcherPromise(fetcher, {
|
|
1338
|
+
refusal: (result) => (result.ok ? undefined : result.error),
|
|
1339
|
+
});
|
|
1340
|
+
// a confirm dialog that stays open, and shows the error, while this rejects
|
|
1341
|
+
const onConfirm = () => run(() => post({ intent: 'delete', id }));
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
A resource route loaded for what is typed (a typeahead, a preview): one load
|
|
1345
|
+
after a pause, from a minimum length, the previous answer kept (`stale`) until
|
|
1346
|
+
the new one lands, and a retry:
|
|
1347
|
+
|
|
1348
|
+
```tsx
|
|
1349
|
+
import { useDebouncedFetcher } from '@softistx/alxia-react-router/fetcher';
|
|
1350
|
+
|
|
1351
|
+
const { data, stale, state, retry } = useDebouncedFetcher<Found>(
|
|
1352
|
+
typed,
|
|
1353
|
+
(q) => `/suggest?${new URLSearchParams({ q })}`,
|
|
1354
|
+
{ minLength: 2, delayMs: 250 },
|
|
1355
|
+
);
|
|
1356
|
+
```
|
|
1357
|
+
|
|
1358
|
+
A screen with no real-time channel reads its data again every N ms, **only while the page is visible**, and at once when a hidden page comes back after more than N ms. `useRevalidateOnFocus` has no timer: it revalidates once when the user returns after being away:
|
|
1359
|
+
|
|
1360
|
+
```tsx
|
|
1361
|
+
import { useFetcher } from 'react-router';
|
|
1362
|
+
import {
|
|
1363
|
+
useRevalidateOnFocus,
|
|
1364
|
+
useVisibleInterval,
|
|
1365
|
+
useVisibleRevalidation,
|
|
1366
|
+
} from '@softistx/alxia-react-router/fetcher';
|
|
1367
|
+
|
|
1368
|
+
// inside a component: the route's loaders, every minute
|
|
1369
|
+
useVisibleRevalidation(60_000);
|
|
1370
|
+
|
|
1371
|
+
// or no timer: once when the user comes back after 30 s away (the default)
|
|
1372
|
+
useRevalidateOnFocus({ minHiddenMs: 30_000 });
|
|
1373
|
+
|
|
1374
|
+
// any callback, such as a fetcher's load; `enabled: false` pauses it
|
|
1375
|
+
const fetcher = useFetcher<Counts>();
|
|
1376
|
+
useVisibleInterval(() => void fetcher.load('/counts'), 300_000, {
|
|
1377
|
+
enabled: !menuOpen,
|
|
1378
|
+
});
|
|
1379
|
+
```
|
|
1380
|
+
|
|
1381
|
+
See the [fetcher guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md).
|
|
1382
|
+
|
|
1383
|
+
### Saving a section or a row in place
|
|
1384
|
+
|
|
1385
|
+
A read-only record edited card by card posts one section to the route's action.
|
|
1386
|
+
`sectionAction` (`/errors`) answers it and `useSectionSave` (`/fetcher`) shows
|
|
1387
|
+
the answer: field refusals under the fields (the first focused), a stale
|
|
1388
|
+
version as a `notice` with a reload, a reset from `record` on success. The hook
|
|
1389
|
+
is headless: `notice` is data for your own alert.
|
|
1390
|
+
|
|
1391
|
+
```tsx
|
|
1392
|
+
// action: `const { intent, ...input } = await readJson(request)`, then
|
|
1393
|
+
return sectionAction(apiErrors, 'en', intent, () => api.update(input), {
|
|
1394
|
+
fieldOf: (path) => (path.startsWith('input.') ? path.slice(6) : undefined),
|
|
1395
|
+
isStale: (error) => isVersionConflict(error), // yours
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// component
|
|
1399
|
+
const { onSubmit, busy, notice, onCancel } = useSectionSave({
|
|
1400
|
+
form, // React Hook Form's useForm() fits
|
|
1401
|
+
intent: 'update-identity',
|
|
1402
|
+
toInput: (values) => (changed(values) ? { ...values, version } : null),
|
|
1403
|
+
record,
|
|
1404
|
+
onSaved: () => setEditing(false),
|
|
1405
|
+
});
|
|
1406
|
+
```
|
|
1407
|
+
|
|
1408
|
+
`useRowSave` is the same for one row of a list, posting the version the row was
|
|
1409
|
+
opened on. See the [fetcher guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md#saving-a-section-or-a-row-in-place-usesectionsave-userowsave).
|
|
1410
|
+
|
|
1411
|
+
## Flow docs per role and a help panel
|
|
1412
|
+
|
|
1413
|
+
`@softistx/alxia-react-router/help` loads the flows an app documents per role
|
|
1414
|
+
(`docs/flows/<name>.<lang>.md`, a front-matter and one `##` section per step,
|
|
1415
|
+
four WebP captures per screenshot) and answers the ones for the current screen.
|
|
1416
|
+
|
|
1417
|
+
```ts no-check
|
|
1418
|
+
// app/help.ts
|
|
1419
|
+
import { loadHelpFlows } from '@softistx/alxia-react-router/help';
|
|
1420
|
+
|
|
1421
|
+
export const help = loadHelpFlows({
|
|
1422
|
+
docs: import.meta.glob('/docs/flows/*.md', { query: '?raw', import: 'default', eager: true }),
|
|
1423
|
+
captures: import.meta.glob('/docs/flows/captures/*.webp', { query: '?url', import: 'default', eager: true }),
|
|
1424
|
+
lang: 'fr', // fallbackLang: none by default
|
|
1425
|
+
});
|
|
1426
|
+
```
|
|
1427
|
+
|
|
1428
|
+
`useHelpFlows(help, { roles })` returns the flows, the tabs and the role to
|
|
1429
|
+
preselect; `bunx alxia-react-router help check` fails the green bar when a
|
|
1430
|
+
screen has no flow, a flow cites an unknown route, or a capture is missing. See
|
|
1431
|
+
the [flow docs guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/help.md).
|
|
1432
|
+
|
|
1433
|
+
`HelpPanel` is the header's help button with its sheet, loaded on the first
|
|
1434
|
+
open (headless: the button and the sheet are yours), and `useGuideRole` is the
|
|
1435
|
+
state of a role guide reader:
|
|
1436
|
+
|
|
1437
|
+
```tsx no-check
|
|
1438
|
+
import { HelpPanel } from '@softistx/alxia-react-router/help';
|
|
1439
|
+
|
|
1440
|
+
<HelpPanel
|
|
1441
|
+
load={() => import('./help').then((m) => m.bundle)}
|
|
1442
|
+
loadSheet={() => import('./help-sheet')}
|
|
1443
|
+
sheetProps={{ itemId }} // the sheet's own props: HelpPanelSheetProps & { itemId: string }
|
|
1444
|
+
language={language}
|
|
1445
|
+
roles={roles}
|
|
1446
|
+
renderButton={({ onOpen }) => <button type="button" onClick={onOpen}>Help</button>}
|
|
1447
|
+
onLoadError={() => toast.error('The help could not be loaded')}
|
|
1448
|
+
/>;
|
|
1449
|
+
```
|
|
1450
|
+
|
|
1451
|
+
`sheetProps` reaches the sheet next to `help`, `roles`, `open` and `onOpenChange`. A failure of either import calls `onLoadError` once and the next open retries.
|
|
1452
|
+
The [flow docs guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/help.md#the-lazy-panel-helppanel)
|
|
1453
|
+
has the complete example and the [role guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/help.md#the-role-guide-useguiderole).
|
|
1454
|
+
|
|
1455
|
+
## A list whose state is the URL
|
|
1456
|
+
|
|
1457
|
+
`@softistx/alxia-react-router/lists` (`react` and `react-router` are its only imports; every hook renders on the server)
|
|
1458
|
+
holds the three hooks a search, filters and a "load more" button need.
|
|
1459
|
+
|
|
1460
|
+
```tsx
|
|
1461
|
+
// app/routes/users.tsx
|
|
1462
|
+
import { usePagedRows, useSameRouteLoading, useSearchChange } from '@softistx/alxia-react-router/lists';
|
|
1463
|
+
import type { Route } from './+types/users';
|
|
1464
|
+
|
|
1465
|
+
const USERS = Array.from({ length: 45 }, (_, i) => `user ${i + 1}`);
|
|
1466
|
+
|
|
1467
|
+
// ?q=<search>&after=<cursor>: 20 rows a page, `next` is null on the last one
|
|
1468
|
+
export function loader({ request }: Route.LoaderArgs) {
|
|
1469
|
+
const url = new URL(request.url);
|
|
1470
|
+
const q = url.searchParams.get('q') ?? '';
|
|
1471
|
+
const start = Number(url.searchParams.get('after') ?? 0);
|
|
1472
|
+
const found = USERS.filter((name) => name.includes(q));
|
|
1473
|
+
const rows = found.slice(start, start + 20);
|
|
1474
|
+
return { rows, next: start + 20 < found.length ? String(start + 20) : null };
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
export default function Users({ loaderData }: Route.ComponentProps) {
|
|
1478
|
+
const change = useSearchChange(); // drops ?after on every change
|
|
1479
|
+
const reloading = useSameRouteLoading(); // another search of this page: show the skeleton
|
|
1480
|
+
const { rows, next, loading, error, loadMore } = usePagedRows(loaderData, (page) => page.rows);
|
|
1481
|
+
return (
|
|
1482
|
+
<main>
|
|
1483
|
+
<input type="search" placeholder="Search" onChange={(event) => change({ q: event.target.value || null })} />
|
|
1484
|
+
{reloading ? (
|
|
1485
|
+
<p>Loading…</p>
|
|
1486
|
+
) : (
|
|
1487
|
+
<ul>
|
|
1488
|
+
{rows.map((name) => (
|
|
1489
|
+
<li key={name}>{name}</li>
|
|
1490
|
+
))}
|
|
1491
|
+
</ul>
|
|
1492
|
+
)}
|
|
1493
|
+
{error ? <p role="alert">The next rows could not be loaded.</p> : null}
|
|
1494
|
+
{next ? (
|
|
1495
|
+
<button type="button" disabled={loading} onClick={loadMore}>
|
|
1496
|
+
{error ? 'Retry' : 'Load more'}
|
|
1497
|
+
</button>
|
|
1498
|
+
) : null}
|
|
1499
|
+
</main>
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
```
|
|
1503
|
+
|
|
1504
|
+
The loader answers `?after=<cursor>` with the next page. A loader that throws on a cursor request lands on the route's `ErrorBoundary`; wrap the read in `orFailed(after, run)` to keep the rows and offer a retry instead:
|
|
1505
|
+
|
|
1506
|
+
```ts
|
|
1507
|
+
import { orFailed } from '@softistx/alxia-react-router/lists';
|
|
1508
|
+
|
|
1509
|
+
export function loader({ request }: Route.LoaderArgs) {
|
|
1510
|
+
const url = new URL(request.url);
|
|
1511
|
+
// no ?after: a failure throws (ErrorBoundary); with ?after: it answers { failed: true }
|
|
1512
|
+
return orFailed(url.searchParams.get('after'), () => listUsers(url.searchParams));
|
|
1513
|
+
}
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
Numbered pages (`?page=3`) over a GraphQL connection paged by cursor: `connectionPage` walks the cursors on the server, keeps `first` under the API's cap and gives the last page when the address asks for one past it:
|
|
1517
|
+
|
|
1518
|
+
```ts
|
|
1519
|
+
import { connectionPage } from '@softistx/alxia-react-router/lists';
|
|
1520
|
+
|
|
1521
|
+
export async function loader({ request }: Route.LoaderArgs) {
|
|
1522
|
+
const asked = Number(new URL(request.url).searchParams.get('page') ?? 1);
|
|
1523
|
+
const wanted = Number.isInteger(asked) && asked >= 1 ? asked : 1;
|
|
1524
|
+
const { rows, total, page, pageCount } = await connectionPage(wanted, 20, async (first, after) => {
|
|
1525
|
+
const { users } = await api.users({ first, after });
|
|
1526
|
+
return { rows: users.nodes, connection: users }; // connection: { totalCount, pageInfo: { hasNextPage, endCursor } }
|
|
1527
|
+
}, { maxFirst: 100 });
|
|
1528
|
+
return { users: rows, total, page, pageCount };
|
|
1529
|
+
}
|
|
1530
|
+
```
|
|
1531
|
+
|
|
1532
|
+
`usePagedRows` reads `{ failed: true }` as a page without rows, so it sets `error` and keeps the rows. See [troubleshooting](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md). See the
|
|
1533
|
+
[lists guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/lists.md).
|
|
1534
|
+
|
|
1535
|
+
A loader that only needs a connection's rows reads them with `nodesOf`: the nodes of `edges { node }` in order, `[]` when the connection is `null` (a refused or missing read):
|
|
1536
|
+
|
|
1537
|
+
```ts
|
|
1538
|
+
import { nodesOf } from '@softistx/alxia-react-router/lists';
|
|
1539
|
+
|
|
1540
|
+
export async function loader() {
|
|
1541
|
+
const { items } = await api.items({ first: 50 }); // { edges: { node: Item }[] } | null
|
|
1542
|
+
return { items: nodesOf(items) }; // Item[]
|
|
1543
|
+
}
|
|
1544
|
+
```
|
|
1545
|
+
|
|
1546
|
+
## Focus and fade on navigation
|
|
1547
|
+
|
|
1548
|
+
`@softistx/alxia-react-router/navigation` (`react` and `react-router` are its only imports; both hooks render on the server).
|
|
1549
|
+
|
|
1550
|
+
```tsx
|
|
1551
|
+
import { useFocusOnNavigate, useRouteTransition } from '@softistx/alxia-react-router/navigation';
|
|
1552
|
+
|
|
1553
|
+
const headingRef = useFocusOnNavigate(); // <h1 ref={headingRef}>
|
|
1554
|
+
const { pathname, transitioning } = useRouteTransition(); // <div key={pathname} className={transitioning ? 'fade-in' : undefined}>
|
|
1555
|
+
```
|
|
1556
|
+
|
|
1557
|
+
See the
|
|
1558
|
+
[navigation guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/navigation.md).
|
|
1559
|
+
|
|
1560
|
+
## The consent screen of an OAuth server
|
|
1561
|
+
|
|
1562
|
+
`@softistx/alxia-react-router/oauth` (the server side, `react-router` its only package import) and `@softistx/alxia-react-router/oauth/react`
|
|
1563
|
+
(the hook, `react` and `react-router`) hold the decision logic of the screen where a viewer allows or denies an OAuth
|
|
1564
|
+
client, over the GraphQL of `@softistx/janus-oauth/graphql`. You pass the three calls as functions; the card and its words stay yours.
|
|
1565
|
+
|
|
1566
|
+
```tsx
|
|
1567
|
+
// app/routes/oauth/consent.tsx
|
|
1568
|
+
import { alxiaOf } from '@softistx/alxia-react-router';
|
|
1569
|
+
import { consentShouldRevalidate, oauthConsent } from '@softistx/alxia-react-router/oauth';
|
|
1570
|
+
import { useConsent } from '@softistx/alxia-react-router/oauth/react';
|
|
1571
|
+
import type { Route } from './+types/consent';
|
|
1572
|
+
|
|
1573
|
+
const consent = oauthConsent({
|
|
1574
|
+
json, // your jsonActions()
|
|
1575
|
+
errors, // your createApiErrors(...)
|
|
1576
|
+
viewer: (request) => requireViewer(request), // throws a redirect to sign in, back to this address
|
|
1577
|
+
caller: (request) => sessionCaller(request),
|
|
1578
|
+
find: async (id, caller) => (await execute(OAuthRequestQuery, { id }, caller)).oauthRequest,
|
|
1579
|
+
approve: async ({ id, scopes }, caller) =>
|
|
1580
|
+
(await execute(ApproveOAuthRequestMutation, { id, scopes }, caller)).approveOAuthRequest,
|
|
1581
|
+
deny: async ({ id }, caller) => (await execute(DenyOAuthRequestMutation, { id }, caller)).denyOAuthRequest,
|
|
1582
|
+
});
|
|
1583
|
+
|
|
1584
|
+
export const loader = ({ request }: Route.LoaderArgs) => consent.loader(request); // { pending, viewer, choices }, no-store
|
|
1585
|
+
export const action = ({ context, request }: Route.ActionArgs) => consent.action(request, alxiaOf(context).language);
|
|
1586
|
+
export const shouldRevalidate = consentShouldRevalidate;
|
|
1587
|
+
|
|
1588
|
+
export default function Consent({ loaderData }: Route.ComponentProps) {
|
|
1589
|
+
const { pending: request } = loaderData;
|
|
1590
|
+
if (!request) return <p>This request has expired.</p>;
|
|
1591
|
+
const { approve, deny, pending, expired, error, dialogProps } = useConsent(request.id, {
|
|
1592
|
+
request: stepUpRequest, // the step-up channels of useStepUpReplay
|
|
1593
|
+
confirm: stepUpConfirm,
|
|
1594
|
+
});
|
|
1595
|
+
return (
|
|
1596
|
+
<>
|
|
1597
|
+
<button type="button" disabled={Boolean(pending)} onClick={() => approve()}>Allow</button>
|
|
1598
|
+
<button type="button" disabled={Boolean(pending)} onClick={deny}>Deny</button>
|
|
1599
|
+
{expired ? <p role="alert">This request has expired.</p> : null}
|
|
1600
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
1601
|
+
<StepUpDialog {...dialogProps} />
|
|
1602
|
+
</>
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
```
|
|
1606
|
+
|
|
1607
|
+
When the grant belongs to something the viewer picks (a workspace), give `choices` (the loader answers them) and
|
|
1608
|
+
`requireBound`, and the page calls `approve({ type, id })`; `approve` of `oauthConsent` receives it as `bound`
|
|
1609
|
+
([binding a grant](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/oauth.md#binding-the-grant-to-something-the-user-picks)).
|
|
1610
|
+
Call `approve` from an arrow function, not as `onClick={approve}`.
|
|
1611
|
+
|
|
1612
|
+
A decision lands as a hard navigation to the client's callback (only `http:` and `https:` are followed); a session not
|
|
1613
|
+
confirmed lately opens the shared step-up and the decision is posted again by itself. See the
|
|
1614
|
+
[OAuth consent guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/oauth.md).
|
|
1615
|
+
|
|
1616
|
+
The account's connected apps use `oauthGrants`: `list(ctx)` answers the grants newest first with their scopes mapped, and
|
|
1617
|
+
`revoke(ctx, id)` answers `revoked`, `already-revoked` (the API no longer knows it) or `step-up`.
|
|
1618
|
+
|
|
1619
|
+
```ts
|
|
1620
|
+
import { oauthGrants } from '@softistx/alxia-react-router/oauth';
|
|
1621
|
+
|
|
1622
|
+
const grants = oauthGrants({
|
|
1623
|
+
list: async (caller) => (await execute(ConnectedAppsQuery, {}, caller)).connectedApps,
|
|
1624
|
+
revoke: (caller, id) => execute(RevokeConnectedAppMutation, { id }, caller),
|
|
1625
|
+
scopes: { 'mcp:read': { key: 'read', access: 'read' } }, // a listed scope's `key` is typed 'read', no cast
|
|
1626
|
+
});
|
|
1627
|
+
const apps = await grants.list(caller); // newest first
|
|
1628
|
+
const { status } = await grants.revoke(caller, apps[0].id); // 'revoked' | 'already-revoked' | 'step-up'
|
|
1629
|
+
```
|
|
1630
|
+
|
|
1631
|
+
## A user's API keys
|
|
1632
|
+
|
|
1633
|
+
`@softistx/alxia-react-router/api-keys` (`react-router` is its only import) lists a user's API keys, creates one behind a step-up and
|
|
1634
|
+
revokes one. A creation answers the secret once, `no-store`; a revocation of a key the API no longer knows counts as done.
|
|
1635
|
+
|
|
1636
|
+
```ts
|
|
1637
|
+
// app/routes/account/keys.tsx
|
|
1638
|
+
import { alxiaOf } from '@softistx/alxia-react-router';
|
|
1639
|
+
import { apiKeys } from '@softistx/alxia-react-router/api-keys';
|
|
1640
|
+
import { jsonActions } from '@softistx/alxia-react-router/errors';
|
|
1641
|
+
import type { Route } from './+types/keys';
|
|
1642
|
+
|
|
1643
|
+
const keys = apiKeys({
|
|
1644
|
+
errors, // your createApiErrors(...)
|
|
1645
|
+
list: async (caller) => (await execute(ApiKeysQuery, {}, caller)).apiKeys,
|
|
1646
|
+
create: async (caller, input: { name: string }) =>
|
|
1647
|
+
(await execute(CreateApiKeyMutation, { input }, caller)).createApiKey, // { secret, apiKey }
|
|
1648
|
+
revoke: (caller, id) => execute(RevokeApiKeyMutation, { id }, caller),
|
|
1649
|
+
});
|
|
1650
|
+
const { readJson } = jsonActions(); // the same-site check, then the JSON body
|
|
1651
|
+
|
|
1652
|
+
export const loader = async ({ request }: Route.LoaderArgs) => ({ keys: await keys.list(sessionCaller(request)) }); // newest first
|
|
1653
|
+
export const action = async ({ context, request }: Route.ActionArgs) =>
|
|
1654
|
+
keys.create(sessionCaller(request), (await readJson(request)) as { name: string }, alxiaOf(context).language);
|
|
1655
|
+
```
|
|
1656
|
+
|
|
1657
|
+
The page replays a refused creation with `useStepUpReplay` and shows the secret from its fetcher, once. See the
|
|
1658
|
+
[API keys guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/api-keys.md).
|
|
1659
|
+
|
|
1660
|
+
## A relying party of an external OpenID Connect issuer
|
|
1661
|
+
|
|
1662
|
+
`@softistx/alxia-react-router/oidc` signs users in with an issuer you do not own (Keycloak, Authentik, Google, Entra): authorization
|
|
1663
|
+
code with PKCE (S256), state and nonce in a short-lived `__Host-` challenge cookie, cached discovery, the code exchange
|
|
1664
|
+
(`client_secret_basic` for a confidential client), the id token validated against the issuer's JWKS (`iss`, `aud`, `exp`,
|
|
1665
|
+
`nonce`, signature; `jose` is an optional peer: `bun add jose`), a sealed `__Host-` token cookie, a single-flight refresh
|
|
1666
|
+
and RP-initiated logout.
|
|
1667
|
+
|
|
1668
|
+
```ts
|
|
1669
|
+
// app/oidc.server.ts
|
|
1670
|
+
import { oidcClient } from '@softistx/alxia-react-router/oidc';
|
|
1671
|
+
|
|
1672
|
+
export const oidc = oidcClient({
|
|
1673
|
+
issuer: 'https://id.example.com',
|
|
1674
|
+
clientId: 'my-app',
|
|
1675
|
+
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
1676
|
+
redirectUri: 'https://app.example.com/auth/callback',
|
|
1677
|
+
scopes: ['profile', 'email', 'offline_access'],
|
|
1678
|
+
secret: process.env.SESSION_SECRET!,
|
|
1679
|
+
name: 'my-app_oidc',
|
|
1680
|
+
secure: !import.meta.env.DEV,
|
|
1681
|
+
postLogoutRedirectUri: 'https://app.example.com/',
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
// sign-in route: export const loader = ({ request }) => oidc.signIn(request);
|
|
1685
|
+
// callback route: export const loader = ({ request }) => oidc.callback(request); // throws OidcError
|
|
1686
|
+
// protected loader: const { claims, accessToken, headers } = await oidc.requireOidcUser(request);
|
|
1687
|
+
// sign-out action: export const action = ({ request }) => oidc.logout(request);
|
|
1688
|
+
```
|
|
1689
|
+
|
|
1690
|
+
An issuer that requires pushed authorization requests (RFC 9126) is handled by the default `par: 'auto'`
|
|
1691
|
+
(`'always'` and `'never'` force it); `dpop: {}` (or `{ alg: 'EdDSA' }`) binds the tokens to a per-session key (RFC 9449):
|
|
1692
|
+
`token_type: DPoP` answers get a proof at `/token` with the `use_dpop_nonce` retry, and `user.dpop.fetch(url)` calls an API
|
|
1693
|
+
with `Authorization: DPoP` and a proof for it.
|
|
1694
|
+
|
|
1695
|
+
`revokeOnLogout: true` makes `logout` also revoke the refresh and access tokens at the issuer's `revocation_endpoint`
|
|
1696
|
+
(RFC 7009, same client authentication and DPoP proof as the token endpoint); a failure never blocks the sign-out and goes
|
|
1697
|
+
to `onRevokeError(error)`, and a stalled endpoint is aborted after `revokeTimeoutMs` (3000 ms, a positive finite number or `oidcClient` throws a `TypeError`):
|
|
1698
|
+
|
|
1699
|
+
```ts
|
|
1700
|
+
const oidc = oidcClient({ /* … */ revokeOnLogout: true, onRevokeError: (e) => console.warn(e.code) });
|
|
1701
|
+
export const action = ({ request }: { request: Request }) => oidc.logout(request); // revokes, clears, redirects
|
|
1702
|
+
```
|
|
1703
|
+
|
|
1704
|
+
`requireOidcUser` redirects to `/sign-in?next=…` (a path of this site only) when there is no session; pass its `headers`
|
|
1705
|
+
with your answer, they carry the refreshed cookie. See the
|
|
1706
|
+
[OIDC guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/oidc.md).
|
|
1707
|
+
|
|
1708
|
+
## Traps
|
|
1709
|
+
|
|
1710
|
+
- **A context key made in `app/` reaches the loaders only through the
|
|
1711
|
+
plugin**, which builds the server with the routes. A server of your own,
|
|
1712
|
+
without the plugin, holds another copy of the key: read alxia's context
|
|
1713
|
+
with `alxiaOf`. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#error-no-value-found-for-context)
|
|
1714
|
+
- **Bun's user agent is a bot to `isbot`**, so a test client gets the
|
|
1715
|
+
finished page, never a stream. Send a browser's `user-agent`. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#a-streamed-page-arrives-in-one-piece)
|
|
1716
|
+
- **An index route's action is `POST /?index`**; `POST /` gets React
|
|
1717
|
+
Router's 405. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#you-made-a-post-request-to--but-did-not-provide-an-action-for-route-root-so-there-is-no-way-to-handle-the-request)
|
|
1718
|
+
- **`@softistx/alxia-secure-headers`' default policy blocks the page's scripts**
|
|
1719
|
+
and forms: give the pages a policy of their own, with `nonce: true` and
|
|
1720
|
+
`nonceOf` in `entry.server.tsx` rather than `'unsafe-inline'`. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#refused-to-execute-inline-script-because-it-violates-the-following-content-security-policy-directive-default-src-none)
|
|
1721
|
+
- **Under `react-router dev`, `page()` is not served**, and an HTTP
|
|
1722
|
+
request's `ctx.server` is the loopback server the sockets are relayed to:
|
|
1723
|
+
its `publish` reaches them, its `url` and `requestIP` are not Vite's. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#a-page-is-not-served-under-react-router-dev)
|
|
1724
|
+
- **An alxia route whose path covers a page takes it**, wherever it is
|
|
1725
|
+
declared: `GET /:slug` answers `/about`. Keep alxia's routes under
|
|
1726
|
+
`/api`. [More](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md#a-page-answers-alxias-json-404-or-405-instead-of-rendering)
|
|
1727
|
+
|
|
1728
|
+
## API
|
|
1729
|
+
|
|
1730
|
+
| export | |
|
|
1731
|
+
| --- | --- |
|
|
1732
|
+
| `createServer(options?)`, `ServerHealth` | the server of `app/server.ts`. `health` (a path or `{ path, check, timeout }`: a liveness probe declared first, in text), `beforeAll`, `configure`, `getLoadContext`, `proxy` (`alxia({ proxy })`'s, `trustProxy(…)` from `@softistx/alxia`), `build`, `mode`, `client`, `precompressed`, `listen`, `onListen` |
|
|
1733
|
+
| `ServerOptions<Before, App>` | its options |
|
|
1734
|
+
| `ReactRouterServer<App>` | what it returns: `create(wiring)` makes the app, `start(app)` listens |
|
|
1735
|
+
| `ServerWiring` | what `create` takes: `build`, `mode`, `client` |
|
|
1736
|
+
| `FreshApp` | the app `beforeAll`, or `configure` without it, receives |
|
|
1737
|
+
| `alxiaOf<App>(context)` | what alxia's middlewares built, in a loader, an action or a middleware. Typed by the registered server, by the type argument (a server or an app), or as `BaseContext`. Its `server` is the `Bun.Server` serving the request |
|
|
1738
|
+
| `context.alxia` | the same object, on React Router's `RouterContextProvider` (this package augments its type, as `alxiaOf(context)` with no type argument): typed with `LoaderFunctionArgs` and `ActionFunctionArgs` from `react-router`, not yet with the generated `Route.LoaderArgs`: use `withAlxia` there |
|
|
1739
|
+
| `withAlxia(fn)` | a loader, an action or a middleware given `alxia`, the alxia context, beside React Router's arguments: annotate `Route.LoaderArgs & AlxiaArgs`. Returns a function of the arguments alone, with `fn`'s return type |
|
|
1740
|
+
| `AlxiaArgs<App>` | what `withAlxia` adds: `{ alxia }`, typed by `Register`, or by the server it names |
|
|
1741
|
+
| `AlxiaContextOf<App>` | what `alxiaOf<App>(context)` returns: the app's context and the catch-all's `route` |
|
|
1742
|
+
| `ProviderLike` | what `alxiaOf` and `nonceOf` take: any React Router context provider's `get`, the generated route types' included |
|
|
1743
|
+
| `Register` | the interface to augment with `server: typeof server` |
|
|
1744
|
+
| `RegisteredApp` | the app `alxiaOf` reads with no type argument: the registered server's, else the one `@softistx/alxia`'s `Register` names, else a fresh app |
|
|
1745
|
+
| `RegisteredOf<R, Core?>` | the app a `Register`-shaped interface names: its server's, `InvalidRegister`, or with no server `Core`, by default core's `RegisteredBase` |
|
|
1746
|
+
| `InvalidRegister` | what a `Register` naming neither a server nor an app reads as: every key of the app's own a compile error |
|
|
1747
|
+
| `AppOf<Server>` | the app a server makes |
|
|
1748
|
+
| `alxiaContext` | the React Router context key `alxiaOf` and `context.alxia` read, set on every request |
|
|
1749
|
+
| `nonceOf(context)` | the request's CSP nonce, for `entry.server.tsx`: the context's `nonce` when a middleware set one, such as `pageHeaders` or `secureHeaders({ nonce: true })`, else `undefined` |
|
|
1750
|
+
| `reactRouter(app, options)` | the catch-all and the client's files, for a server of your own. `build`, `mode`, `getLoadContext`, `client`, `precompressed` |
|
|
1751
|
+
| `ReactRouterOptions<Ctx>` | its options |
|
|
1752
|
+
| `isReactRouterRoute(route)` | whether this package declared a route, for `matchesSpec`'s `exclude` |
|
|
1753
|
+
|
|
1754
|
+
From `@softistx/alxia-react-router/vite`:
|
|
1755
|
+
|
|
1756
|
+
| export | |
|
|
1757
|
+
| --- | --- |
|
|
1758
|
+
| `alxia(options?)` | the Vite plugin, for `react-router dev`, `react-router build` and `vite preview`, building the server for Bun. `entry` is the server file: `app/server.ts` by default, or the default server when there is none. `worker` is the service worker built after `react-router build`: `app/service-worker.ts` by default when it exists, a file, `AlxiaWorkerOptions`, or `false`. `precompress` writes the `.br` and `.gz` copies of the client build: on by default, `false`, or `PrecompressOptions` (`minSize`). `allowedHosts` adds hostnames to Vite's `server.allowedHosts` and `preview.allowedHosts` (also `DEV_ALLOWED_HOSTS`, comma-separated); see [Dev tunnels](#dev-tunnels-and-other-hostnames) |
|
|
1759
|
+
| `AlxiaOptions`, `AlxiaWorkerOptions`, `PrecompressOptions` | its options, the worker's (`buildWorker()`'s but `root`, `client` and `file`, which is optional) |
|
|
1760
|
+
|
|
1761
|
+
From `@softistx/alxia-react-router/pwa`:
|
|
1762
|
+
|
|
1763
|
+
| export | |
|
|
1764
|
+
| --- | --- |
|
|
1765
|
+
| `defineWorkerContract(options)` | the contract of one app's worker from its `cachePrefix` (required), with `cacheVersion` (`v1`), `serviceWorkerUrl` and `offlineUrl`: its `cacheNames`, `obsoleteCaches(names)` and `clearableCaches(names)`. Throws on an empty prefix or one ending with `-`, and on an empty `cacheVersion` or one with a `-` |
|
|
1766
|
+
| `WorkerContract`, `WorkerContractOptions`, `CacheNames` | its types |
|
|
1767
|
+
| `SERVICE_WORKER_URL`, `OFFLINE_URL`, `SKIP_WAITING` | `/service-worker.js`, `/offline.html` and the message that applies an update |
|
|
1768
|
+
| `cachingFor(request, origin, options?)` | `navigation`, `immutable`, `static` or `none` for a request. `options`: `never(path)`, `immutable(path)` (everything under `/assets/` by default), `serviceWorkerUrl`, `contract` (whose `serviceWorkerUrl` is never cached), `manifestPath` |
|
|
1769
|
+
| `Caching`, `RequestFacts`, `CachingOptions` | its types |
|
|
1770
|
+
| `isStorable(response)` | whether a response may be stored: a full, same-origin, `public` 200 of a script, style, font or image, not varying on who asks |
|
|
1771
|
+
| `parseBrowserManifest(source)` | React Router's browser manifest, read from `build/client/assets/manifest-*.js` |
|
|
1772
|
+
| `precacheList(manifest)` | the hashed scripts and stylesheets every route needs, as Workbox precache entries |
|
|
1773
|
+
| `assetPrecache(files, include, base?)` | the entries of the files in `build/client/assets` that a regex of yours matches, such as fonts |
|
|
1774
|
+
| `BrowserManifest`, `PrecacheEntry` | their types |
|
|
1775
|
+
| `fontPrecachePattern(families)` | the `precacheAssets` regex for `<family>-<8 hash chars>.woff2` files, from the file-name stems you keep offline (`['inter-latin', 'display-latin-wght-normal']`); a stem matches whole, regex characters are escaped, throws on an empty list |
|
|
1776
|
+
| `themeColorHex(token)`, `themeColors(tokens)` | a theme colour token (`#rgb`, `#rrggbb` or `oklch(L C H)`) as the `#rrggbb` a manifest `themeColor` and a `theme-color` meta need; `themeColors` converts a record of tokens and keeps its keys |
|
|
1777
|
+
| `clearAppCaches(contract)` | deletes the caches the worker filled but the offline page; for sign-out. Does nothing without Cache Storage |
|
|
1778
|
+
| `registerServiceWorker(container, onWaiting, options?)` | registers the worker (`url`, `scope` options) and calls `onWaiting(worker, apply)` for each new version waiting behind a controller; checks for an update when the tab shows again. `apply` activates the worker and reloads once |
|
|
1779
|
+
| `watchForUpdates(registration, container, onWaiting)`, `createUpdater(container, reload?)`, `afterLoad(run)` | its parts: offering waiting workers, the one update path of a page, and running once the page has loaded |
|
|
1780
|
+
| `ApplyUpdate`, `RegisterOptions`, `ServiceWorkerContainerLike` | their types |
|
|
1781
|
+
| `createUpdateNotice(storage, key?)` | the update notice's store (`offer`, `current`, `subscribe`, as `useSyncExternalStore` takes it): hidden for the session by "Later", kept in `storage()`, which may be missing or throw |
|
|
1782
|
+
| `UpdateNotice`, `UpdateNoticeStore`, `NoticeStorage` | its types. `NoticeStorage` is any object with `getItem(key)` and `setItem(key, value)` |
|
|
1783
|
+
| `sessionStore`, `UPDATE_LATER_KEY` | `sessionStorage` or nothing, and the default key, `alxia.update-later` |
|
|
1784
|
+
| `MANIFEST_PATH`, `MANIFEST_HEADERS` | `/manifest.webmanifest`, and the headers to serve it with: cacheable for an hour, varying on `Accept-Language`, a policy that loads nothing |
|
|
1785
|
+
| `webAppManifest(options)` | the web app manifest's JSON from the app's `name`, `description`, `lang`, `themeColor`, `backgroundColor` and the optional rest; `id`, `start_url` and `scope` are `/` in every language |
|
|
1786
|
+
| `WebAppManifest`, `WebAppManifestOptions`, `ManifestIcon` | its types |
|
|
1787
|
+
| `MINIMAL_2023_ICONS` | the four icons `@vite-pwa/assets-generator`'s `minimal2023Preset` writes |
|
|
1788
|
+
| `manifestHref(language, path?)` | the manifest's URL for a page: `/manifest.webmanifest?lang=fr` |
|
|
1789
|
+
| `manifestLanguage(url, supported, fallback)` | `?lang=` when it is one of `supported`, else `fallback` |
|
|
1790
|
+
|
|
1791
|
+
From `@softistx/alxia-react-router/pwa/react` (`react`, an optional peer, is its only package import):
|
|
1792
|
+
|
|
1793
|
+
| export | |
|
|
1794
|
+
| --- | --- |
|
|
1795
|
+
| `useOnline()` | whether the browser says it is online; online on the server and while hydrating |
|
|
1796
|
+
| `useServiceWorker(options)` | registers the worker after `load` when `options.enabled` (required; the app passes `import.meta.env.PROD`), in a browser that has one. `url`, `scope`, `notice` (where a waiting version is offered), `onError` (registering failed; dropped by default) |
|
|
1797
|
+
| `ServiceWorkerOptions` | its options |
|
|
1798
|
+
| `useUpdateNotice(notice?)` | the `{ reload, later }` to show while a new version waits and "Later" was not asked, else `undefined`; always `undefined` on the server |
|
|
1799
|
+
| `updateNotice` | the page's one `UpdateNoticeStore`, which `useServiceWorker` offers and `useUpdateNotice` reads by default |
|
|
1800
|
+
|
|
1801
|
+
From `@softistx/alxia-react-router/pwa/server` (`@softistx/alxia` is its only package import):
|
|
1802
|
+
|
|
1803
|
+
| export | |
|
|
1804
|
+
| --- | --- |
|
|
1805
|
+
| `noCache` | a middleware: the response it wraps gets `Cache-Control: no-cache` and the worker's policy. For `use(SERVICE_WORKER_URL, noCache)` in `beforeAll` |
|
|
1806
|
+
| `revalidated(response, policy?)` | a response with those two headers set, on a copy when its headers are immutable; `policy` is `WORKER_POLICY` by default |
|
|
1807
|
+
| `WORKER_POLICY` | `default-src 'none'; connect-src 'self'`: the worker runs no other script and fetches this site only |
|
|
1808
|
+
|
|
1809
|
+
From `@softistx/alxia-react-router/pwa/worker` (the six `workbox-*` packages, optional peers, are its only package imports):
|
|
1810
|
+
|
|
1811
|
+
| export | |
|
|
1812
|
+
| --- | --- |
|
|
1813
|
+
| `startWorker(options)` | the worker's strategies: the precache route, `NetworkOnly` for a page load with the precached offline page as its fallback, `CacheFirst` for hashed bundles, `StaleWhileRevalidate` for other static files (both storing only what `isStorable` accepts), the obsolete caches swept on `activate`, and `SKIP_WAITING` applied |
|
|
1814
|
+
| `WorkerOptions` | `contract` (required), `caching`, `assets`, `static`, `navigationPreload`, `precache` |
|
|
1815
|
+
| `ExpirationOptions` | `{ maxEntries?, maxAgeSeconds? }` |
|
|
1816
|
+
|
|
1817
|
+
From `@softistx/alxia-react-router/pwa/build` (Bun; Node's built-ins its only imports):
|
|
1818
|
+
|
|
1819
|
+
| export | |
|
|
1820
|
+
| --- | --- |
|
|
1821
|
+
| `buildWorker(options)` | bundles the worker into `build/client/service-worker.js` with its precache list (the offline page by its content, every route's code, `precacheAssets`), after `react-router build` |
|
|
1822
|
+
| `BuildWorkerOptions` | `file` (required), `root`, `client`, `contract`, `offline`, `precacheAssets`, `minify` |
|
|
1823
|
+
| `WorkerBuild` | `{ file, precache, precacheBytes, bytes }` |
|
|
1824
|
+
|
|
1825
|
+
From `@softistx/alxia-react-router/errors` (`react-router` is its only package import, and never `@softistx/alxia`):
|
|
1826
|
+
|
|
1827
|
+
| export | |
|
|
1828
|
+
| --- | --- |
|
|
1829
|
+
| `isApiErrorLike(error)` | whether `error` is an `@nxgt/graphql-client` `ApiError`, like the client's `isApiError`, plus a numeric `status`, which `ApiErrorLike` promises; it holds across two copies of the client |
|
|
1830
|
+
| `isStaleVersion(error)` | whether `error` is an API's refusal of an out-of-date update: an `ApiErrorLike` with status 409 whose `code` ends with `.errors.stale-version`; false for any other value |
|
|
1831
|
+
| `ApiErrorLike`, `ApiErrorEntryLike`, `ApiErrorExtensionsLike`, `ApiErrorParamsLike`, `ApiFieldErrorLike` | the shape of the refusal: `errors`, `code`, `status`, `requestId?`, and each error's `extensions` (`code`, `params`, `fields`, `field`, `minutes`, `retryAfter`) |
|
|
1832
|
+
| `waitMinutes(extensions)` | the minutes of a throttle's wait: `minutes` (at least one), else `retryAfter` rounded up |
|
|
1833
|
+
| `retryAfterOf(error)` | the seconds a 429 asks to wait, for a countdown on your own forms: `retryAfter` of the first error's `params`, else of its `extensions`; a finite number from 0 or a decimal string, rounded up, held at a day (86 400); `undefined` when none is usable |
|
|
1834
|
+
| `attemptsLeftOf(error)` | the tries a refused code leaves, as `@softistx/janus` counts them: `extensions.attemptsLeft` of the first error, else `params.attemptsLeft`; `undefined` when it is not a whole number from 0 up, or when the refusal is throttled (a rate limit spends no try) |
|
|
1835
|
+
| `isThrottledReason(error)` | whether the first error's `extensions.reason` (else `params.reason`) is `'throttled'`: a rate limit that asks to wait, whatever its code; use it in a `refused` callback to skip any tries-left logic |
|
|
1836
|
+
| `REQUEST_ID_HEADER`, `requestIdOf(response)` | `x-request-id`, and the id a response carries, if the API sent one |
|
|
1837
|
+
| `nextOf(url)` | the path and search of the page a request is for, without React Router's `.data`, `/_.data`, `_routes` and empty `index`; it never starts with two slashes, but an app still validates `next` before redirecting to it |
|
|
1838
|
+
| `FormErrors` | what a form action answers when the API refused the input: `fieldErrors` by field and a `formError` (`undefined` when every message sits under a field), already translated; `submitForm` answers it |
|
|
1839
|
+
| `routeError(error, { statuses? }?)`, `RouteErrorOptions` | what a loader throws for the API's error: an `ApiError` (or a REST `ProblemError`, which has no `code`) of 401, 403, 404 or 503, or such a `Response` carrying a request id, becomes a route error of that status with the `code`, `message` and `requestId`; any other `ApiError` with an id becomes a 500 carrying the id; anything else is returned as it is |
|
|
1840
|
+
| `problemError(reply, { requestId? }?)`, `ProblemError`, `isProblemErrorLike`, `ProblemErrorLike`, `ProblemReply`, `ProblemErrorOptions` | the typed error (`status`, `title`, `detail`, `type`, `instance`) of a REST API's RFC 9457 problem reply built from `{ status, data }`, `Error <status>` on a non-problem body; `routeError` and `apiCallFailure` recognise it like an `ApiError` |
|
|
1841
|
+
| `errorRequestId(error)`, `RouteErrorData` | the support reference an error page shows: the `requestId` a route error carries, else `undefined`; `RouteErrorData` is the data `routeError` carries (`code?`, `message?`, `requestId?`) |
|
|
1842
|
+
| `isRouteRefusal(value)`, `routeRefusalStatus(value)`, `RouteRefusal`, `DataRefusal` | the test for a caught React Router `data(body, { status })` value or `Response` (what `oauthConsent`'s action throws), and its status |
|
|
1843
|
+
| `createApiMessages({ format })`, `ApiMessages`, `ApiMessagesOptions` | the catalogue store of an app, an instance (`set`, `add`, `clear` (for tests), `messageOf`, `format`, `apiMessage(code, values, language)`); `format` is the app's ICU formatter, such as `@nxgt/material`'s `formatMessage` |
|
|
1844
|
+
| `CatalogueMessage`, `CatalogueMessages`, `ParamKind`, `MessageFormat`, `MessageValues` | one API message with the kind of each argument (`TEXT`, `NUMBER`, `DATE`, `PLURAL`, `SELECT`), a language's messages by code, and the formatter's type |
|
|
1845
|
+
| `apiCodeResolver(messages, { translate, language, codeOf?, isApiCode? })`, `ApiCodeResolver`, `ApiCodeResolverOptions`, `CodeIssueLike` | the `{ translate, codeOf }` a form's `useCodeResolver(schema, resolver)` takes: a check's API code is worded as the API words it, any other key by the app's translator; `CodeIssueLike` is the issue a custom `codeOf` receives |
|
|
1846
|
+
| `ApiMessagesProvider({ messages, value, children })`, `ApiMessagesProviderProps` | `messages` is the store and `value` the root loader's data; fills the store in the browser from the root's data before the children render; a server render writes nothing. A function with no JSX, so no React import |
|
|
1847
|
+
| `createApiErrors({ messages, unavailable, refused?, byCode?, reword?, isApiCode? })`, `ApiErrors`, `ApiErrorsOptions`, `FetcherResultOptions` | what a page says of a refusal, in a language: `apiErrorMessage(error, language)` (the catalogue's text of the code, else the API's message; `refused` replaces it for an error with no API code and `byCode` words given codes, such as a query's limits; `reword(text, error, { code, values, language })` words a family of codes once, on the final text of the catalogue, the API or `byCode`, returning `undefined` to keep it), `fieldErrors(error, language)` by input path, `translateCode(code, fallback, language, values?)`, `unavailableMessage(language)` and `apiRefusal(error, language)`; for an action, `fetcherResult(language, about, run, options?)` (`{ ok: true, …about, …value }`, or `{ ok: false, …about, error }` with the refusal's status; `options` is `FetcherResultOptions`: the `route` options plus `reword(error: ApiErrorLike)`, called for an API's own refusal only: the message of this call, or `undefined` to keep the worded one), `fetcherRefusal(error, language, route?)` (the refusal, or the thrown route error) and `submitForm(language, run, fieldOf, route?)` (`{ ok: true, value }`, or a `FormErrors` with the refusal's status); `formRefusal(error, language, fieldOf, route?)` (`{ error, fieldErrors, status }` for a fetcher form: each field issue under the form field `fieldOf` names, `error` empty when every issue found its field); `route` is the `RouteErrorOptions` of the `routeError` they throw through |
|
|
1848
|
+
| `apiCallFailure(error, { api, operation?, requestId?, signal?, passedThrough?, log? })`, `CallFailureOptions` | what a failed call to the API becomes, for a loader or an action to throw, logged with the request id: an `ApiError` as it is (with `requestId`), a `Response` of its own status for a 401, 403 or 404 without a GraphQL body, a 503 `Response` with no body for an unreachable, slow, garbled or aborted call (the reason is in the log), any other error as it is; the log lines start with `api`, and a `log` that throws never replaces the outcome. It recognises `@nxgt/graphql-client`'s errors by `name`, not `instanceof` |
|
|
1849
|
+
| `operationName(document)`, `DocumentLike` | the name of the operation a document holds, for the log (else `query`, `mutation` or `subscription`); a structural `{ definitions }`, so `graphql`'s `DocumentNode` fits |
|
|
1850
|
+
| `createErrorCatalogue({ messages, languages, read, versions, ttlMs, clientCodes, retryMs?, firstReadWaitMs?, log? })`, `ErrorCatalogue`, `ErrorCatalogueOptions`, `CatalogueReply` | keeps the API's error catalogue in the store: `fresh(language, now?)` and `freshAll(now?)` (a cold language is awaited for `firstReadWaitMs`, 1500 by default, and read once however many requests ask; a held one is served, and its version checked in the background once per `ttlMs`, a number or a getter; only a language whose version moved is read again; a failure is retried after `retryMs`, 5000 by default), `warm()` for startup, `clientMessages()` (the `clientCodes` the browser words itself, by language, for the root's loader), and, for tests, `reset()`, `heldVersion(language)`, `settled()` and the `now` parameters. `read` and `versions` are the app's calls to its API |
|
|
1851
|
+
| `ApiRefusal` | `{ message, status }`: a failed call as a page says it; what `apiRefusal` returns for an API refusal (its status) or an unreachable API (503), else `undefined` |
|
|
1852
|
+
| `requireSameSite(request, from?)`, `SameSiteOptions` | the same-site guard for any POST, a native form or JSON: 403 `Cross-site request refused` for `Origin: null`, a foreign `Origin` and a `Sec-Fetch-Site` of `cross-site` or `same-site`; a request with neither header goes on (as for `readJson`); headers only, the body stays unread. The reference is the request's own origin, `{ origin }` (a string or getter) or a `jsonActions()` instance |
|
|
1853
|
+
| `jsonActions({ origin? })`, `JsonActions`, `JsonActionsOptions` | the JSON helpers of the actions, bound to the app's origin (a string, or a getter read at each request; the request's own by default): `readJson(request)` (403 `Cross-site request refused` for another origin or a cross-site fetch, 415 `Expected a JSON body`, 400 `Malformed JSON body`), `requireJsonPost(request)` (a native post goes back to its page) and `readInput(request, schema)` (the body's `input` through a Standard Schema, async allowed; 400 `The form sent an input the API would refuse`) |
|
|
1854
|
+
| `useJsonFetcher(key?, action?)`, `JsonBody` | a fetcher that posts JSON: `{ fetcher, post(body, to?), busy }`; `to` is the action of one call |
|
|
1855
|
+
| `StandardSchemaV1` | the Standard Schema v1 type `readInput` takes, declared in `/errors` (type only, so no `@softistx/alxia`; `readInput`'s output is inferred from the schema's `~standard.types`); a Zod 4, Valibot or ArkType schema fits |
|
|
1856
|
+
|
|
1857
|
+
From `@softistx/alxia-react-router/session` (`react-router` and `/errors`' files are its only imports):
|
|
1858
|
+
|
|
1859
|
+
| export | |
|
|
1860
|
+
| --- | --- |
|
|
1861
|
+
| `sessionCookies({ session, challenge?, secure, sameSite?, challengePath?, challengeHostPrefix?, challengeSeconds? })`, `SessionCookies`, `SessionCookiesOptions`, `SessionCookiesWithoutChallengeOptions`, `SessionCookiesBase`, `ChallengeCookies`, `NoChallengeCookies`, `CookieSession` | the session and, when `challenge` is given, second-factor challenge cookies (without it the result is `SessionCookies<false>`, with no challenge helper on the type), `HttpOnly; SameSite=Lax` (`sameSite: 'strict' \| 'none'` changes it), `__Host-` and `__Secure-` when `secure` (required, never read from the environment; `challengeHostPrefix: true` with `challengePath: '/'` makes the challenge `__Host-` too): `commit(token, expiresAt)`, `read(request)`, `token(request)`, `present(request)` (the cookie is in the request, readable or not), `destroy()`, `refreshed(session, expiresAt)` (a `Set-Cookie` only when the expiry moved), `commitChallenge`, `challengeOf`, `destroyChallenge` (these three: with a second factor), `signInPageHeaders(deadSession)` and `names` (the cookie names as sent, prefixes included); a cookie written by an app's own code in `<expiry ms>.<token>` is read as it is |
|
|
1862
|
+
| `signedSession({ secret, name, maxAge, secure, sameSite? })`, `SignedSession`, `SignedSessionOptions` | a stateless, tokenless session for one local operator with no Janus: an HMAC-SHA256 over `<expiresAt>.<nonce>`, `__Host-` when `secure`, `HttpOnly; Path=/`: `await commit(now?)`, `destroy()`, `await valid(request, now?)` (Web Crypto, so async; constant time, the expiry inside the signed part, `false` and never a throw on anything malformed) |
|
|
1863
|
+
| `serializeCookie(name, value, { maxAge, path?, secure, sameSite? })`, `readCookie(request, name)`, `secondsUntil(expiresAt, now?)`, `SerializeOptions` | the bytes `sessionCookies` writes, for the cookies of your own; a name that is not an RFC 6265 token throws a `TypeError` |
|
|
1864
|
+
| `signInFlow({ cookies, errors, json, revoke, attemptsLeft?, throttled?, paths?, clear?, unavailable?, codes?, endedParam? })`, `SignInFlow`, `SignInFlowOptions`, `SignInFlowWithoutSecondFactorOptions`, `SignInFlowBase`, `SecondFactorSteps` | the server side of the sign-in pages; `attemptsLeft` and cookies with a `challenge` go together (giving only one is a compile error, and a `TypeError` at runtime), and without them the flow is `SignInFlow<L, C, false>`, with no `readCodeInput`, `codeStep`, `codeRefusal` or `attemptsLeft`. It also exposes what it was built with (`cookies`, `errors`, `json`, `attemptsLeft`, `unavailable(language)`, `clear()`) and `guard(request)`, the check an app's own POST step runs first: `nextParam`, `signInRedirect`, `landing`, `landReplacing` (revokes the session the browser held), `signInStep` (a same-site JSON post only; an API refusal as the form's message and status, a `reason: 'throttled'` one also with `throttled: true` and `retryAfter` in seconds, an unreachable API as a 503), `readCodeInput`, `codeStep`, `codeRefusal` (with the tries left, or the wait of a `reason: 'throttled'` refusal, worded by the optional `throttled(minutes, language)`) (these four and `attemptsLeft`: with a second factor), `revokeSession`, `signOut` (JSON and same-origin only; it clears the challenge cookie too), `viewer` (`null` for a 401, `undefined` when unknown) and `requireViewer` (throws the sign-in redirect); `revoke(token, request, context)` gets the caller context (`C`, inferred from the annotation of `revoke`'s third parameter) that `signOut`, `revokeSession`, `landReplacing` and `signInStep` take as `context` |
|
|
1865
|
+
| `SignInAnswer`, `SignInFormError`, `SignInStayed`, `SignInCodes` | what a step answers (`signedIn`, `secondFactor` or `other`), a form step's answer when it stays on the page (`formError`, plus optional `throttled` and `retryAfter` for a throttled refusal), and the `codes` option (`invalidCode`, `challengeOver`) |
|
|
1866
|
+
| `stepUpSteps({ signIn, spent, locked? (deprecated, ignored), wording?, codes?, onSignedOut? })`, `StepUpSteps`, `StepUpStepsOptions`, `StepUpSignIn`, `StepUpCall` | a step-up for a route's action, reading the sign-in's `errors`, `json` and `attemptsLeft` (and `signInRedirect` with `onSignedOut`): `signIn` is a `signInFlow(...)` or a hand-written object with those members (`StepUpSignIn`), no cast, and `onSignedOut: 'sign-in'` without `signInRedirect` throws a `TypeError`, each step taking `{ request, language }` and refusing a post that is not a same-site JSON one: `request(run, { request, language })` answers the challenge and how it is confirmed (a throttled mail or any 429 is `error: 'throttled'` with `retryAfter`), `confirm(run, { request, language, via? (deprecated, ignored) })` answers `error: 'invalid'` with the tries left, `expired` (also with no try left and no `reason`, whatever the factor: ask for a new code) or `failed`; `request` and `confirm` answer `throttled` with `retryAfter` on any 429, and `confirm` also on `extensions.reason === 'throttled'` (the challenge and its tries stay, `locked` is always `false`); **breaking in 0.51**: see [Changed in 0.51](./docs/guide/session.md); and `isStepUpRequired(error)`; and `route(run, { request, language })`, the whole action of one resource route that any page posts `request-step-up` and `confirm-step-up` to (`run.request()`, `run.confirm({ challenge, code })`; `StepUpRun`); with `onSignedOut: 'sign-in'` it throws the sign-in redirect for a signed-out user (an `ApiError` with `codes.unauthenticated`, default `'UNAUTHENTICATED'`; from `request` also a bare 401 response, from `confirm` never), `next` being a same-site `Referer`'s page, else the route's own path, while a wrong code stays a refusal; `wording`, when it returns a string for a `codes.challengeOver` code, words an ended challenge instead of `spent` (which stays the text when the tries run out) |
|
|
1867
|
+
| `StepUpCodes`, `StepUpStayed`, `INVALID_CODE`, `CHALLENGE_OVER`, `MAIL_THROTTLED`, `UNAUTHENTICATED`, `STEP_UP_REQUIRED`, `STEP_UP_OVER` | the `codes` option (`invalidCode`, `challengeOver`, `stepUpRequired`, `mailThrottled`, `unauthenticated`), a step's answer that stays on the page, and janus's default codes, which an app can extend |
|
|
1868
|
+
| `authLinks({ signIn, codes?, wording?, start?, resetDone?, invalidState? })`, `AuthLinks`, `AuthLinksOptions`, `AuthLinksCodes` | the pages a mail's link opens, over the flow's cookies, errors and json: `linkArgs`, `spendToken(run, { request, language, path, states, fields? })` (a wait, `codes.mailThrottled`, stays on the page as a 429 with `throttled: true` and `retryAfter`), `answerOf`, `landByLink` (`context?`), `afterReset(request, { context? })` (clears the session, the challenge and the flow's cookies), `requestLink(run, { request, language })` (a wait, whose `codes.mailThrottled` is one code or a list of them, answers `throttled: true` and `retryAfter` when the API gives the seconds; `wording` words every refusal that is not a field's), `statePath` and `ended` |
|
|
1869
|
+
| `handOver(response)`, `handingOver(action)` | a link route's redirects, returned or thrown, as a 200 `{ redirect: location }` (with `replace: true` for a `replace()` redirect; the cookies kept) for a `fetch` caller. `handOver(response)` on its own swaps any request without checking the header; `handingOver` swaps only a request with the `X-Alxia-Link: json` header that `postLinkArgs` sends, so a native form post keeps its redirect; the route must be a resource route (no default export) |
|
|
1870
|
+
| `Spent`, `SpentRefusal` (`FormErrors` plus `throttled?` and `retryAfter?`), `SpendOptions`, `LinkStayed`, `RequestLinkAnswer` | their types |
|
|
1871
|
+
| `socialRoutes({ providers, flowCookie, start, complete, cookies, linkStart?, invalidSessionCode?, paths?, errorParam?, socialParam?, missingFlowCode?, crossSiteCode? })`, `SocialRoutes`, `SocialRoutesOptions`, `SocialStart`, `SocialStartContext`, `SocialFlowKind`, `SocialCompleteInput`, `SocialOutcome`, `SocialFlowCookie`, `SocialArgs` | the loaders of a social sign-in (`start`, `callback`) and, with `linkStart`, of linking a provider to a signed-in account (`link`, a `linked` outcome landing on `returnTo`, else the kept `?next` when not `/`, else `paths.linked`, with `?social=linked`, `complete` told the `kind`; `link` refuses a request whose `Sec-Fetch-Site` is `cross-site` or `same-site` and lands on the link landing with `?error=social_cross_site`, `crossSiteCode` renaming it) over the app's own `socialSignInStart` and `socialSignInComplete` calls: an `HttpOnly; SameSite=Lax; Path=/auth` flow cookie for 10 minutes, the checked `?next` kept in that same cookie and given back to `complete` as `returnTo` (a session or second factor lands on it unless the outcome sets its own), a 404 for a provider outside `providers`, then a session cookie, the second-factor page or `/sign-in?error=<code>` (an `error` outcome's optional `params`, e.g. `{ minutes: 5 }`, are added as `&minutes=5`); see the [session guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md#social-sign-in) |
|
|
1872
|
+
| `TOKEN_PAGE_HEADERS` | `Referrer-Policy: no-referrer` and `X-Robots-Tag: noindex, nofollow`, for a page whose URL carries a token |
|
|
1873
|
+
|
|
1874
|
+
From `@softistx/alxia-react-router/session/react` (`react` and `react-router` are its only imports; every hook renders on the server):
|
|
1875
|
+
|
|
1876
|
+
| export | |
|
|
1877
|
+
| --- | --- |
|
|
1878
|
+
| `useSignOut({ action?, before?, next? })` | `{ signOut(call?), busy }`: posts `{}` (or `{ next }`) as JSON to `action` (default `/sign-out`) after `before()`, whose failure never keeps the user signed in; `busy` until the navigation ends. `next` (or `signOut({ next })`, which wins) is the path to come back to after signing in again: the sign-out action redirects to `/sign-in?signed-out=1&next=…`; a path that leaves the site is dropped |
|
|
1879
|
+
| `SIGN_OUT_PATH`, `SignOutOptions`, `SignOutCall`, `signOutBody(next)`, `signOutAfter(before, submit)` | `/sign-out`, the options, a call's, the body posted (`{}` for an unsafe `next`), and the step `useSignOut` is built on |
|
|
1880
|
+
| `useLinkPost()`, `refusalOf(answer)`, `LinkAnswer`, `LinkPostOptions`, `LinkRefusal` | `{ send, busy }`: `send(body)` posts JSON to the page's action (`useLinkPost({ action })` or `send(body, { action })` post to another route's, such as a resource route) and resolves the form refusal `{ form?, retryAfter?, email? }` (from the answer's `formError`, `retryAfter`, `fieldErrors.email`), or `undefined` when nothing was refused or a navigation aborted the post; any other failure rejects. `refusalOf` is the pure mapping |
|
|
1881
|
+
| `useLinkFragment({ drop? }?)`, `LinkFragmentOptions` | the fragment a mail link carries (`/accept#<code>`, which never reaches a server or a `Referer`), decoded, read once: `undefined` until hydrated, `null` when absent or empty; `drop: true` removes it from the address bar with `history.replaceState`; the value survives Strict Mode's second effect run |
|
|
1882
|
+
| `useLinkParam(name, { drop?, live? }?)`, `LinkParamOptions` | a mail link's query parameter, read once (`null` when absent or empty); `drop: true` removes it from the address bar with `history.replaceState`; `live: true` follows the URL, for a parameter a redirect adds to the same mounted route |
|
|
1883
|
+
| `useCodeField(schema, refusal)`, `CodeField`, `CodeSchema` | a one-code field with no form library: `{ code, setCode, ref, error, check() }` over a synchronous Standard Schema; each new `refusal` object clears the refused code and focuses the input |
|
|
1884
|
+
| `useStepUpReplay({ answer, replay, request, confirm, action?, spendsCode? })`, `StepUpReplayOptions` | a refusal carrying `stepUp` opens the step-up; `request` and `confirm` are your own typed `post`s (a `StepUpChannel`: `post`, settled `answer`, `busy`, `reset?`); once the code is accepted `replay()` sends the refused action again, except an action that `spendsCode` after a second-factor step-up (then `confirmedNotice` is true until `action` changes to a new value, i.e. a new action is posted, or `cancel()`). A `replay()` that posts nothing leaves the dialog confirming: call `cancel()`. A cancel forgets late answers. Returns `{ open, dialogProps, cancel, confirmedNotice, dismissNotice, stepUp }` (`dismissNotice()` clears the notice without a new action) |
|
|
1885
|
+
| `useStepUpRunner<Request, Outcome>({ answer, post, request, confirm, spendsCode? })`, `StepUpRunnerOptions` | `useStepUpReplay` with the bookkeeping done: `run(request)` posts it and resolves with the settling answer, or `'cancelled'` (dialog cancelled). `post` may return a promise of the outcome, which then settles the run; an error thrown by `post` rejects `run()`; a replaced run settles with its own outcome. A `stepUp` answer opens the dialog and the same request is posted again once confirmed. One runner per fetcher key. Returns `{ run, busy, dialogProps, cancel, confirmedNotice, dismissNotice }` |
|
|
1886
|
+
| `useStepUp({ request, confirm, onConfirmed })`, `StepUpOptions`, `StepUpChannel` | the step-up under it: `{ phase, via, props, message, busy, start(), submit(code), release() }` |
|
|
1887
|
+
| `asksStepUp(answer)`, `stepUpDialogPhase(state)`, `StepUpDialogPhase` | whether an answer asks for a step-up, and the dialog's phase (`'asking' \| 'failed' \| 'code' \| 'expired' \| 'confirmed'`) |
|
|
1888
|
+
| `requestAnswerOf(data)`, `confirmAnswerOf(data)` | narrow the data of `route()`'s union to one intent's answer, to type each channel |
|
|
1889
|
+
| `dialogPropsOf(stepUp, open, cancel)`, `StepUpDialogProps` | the props a step-up dialog is given: `open`, `phase`, `via` (kept in every phase once a challenge was granted), `props`, `message`, `busy`, `confirming` and the handlers |
|
|
1890
|
+
| `useOnRefusal(refusal, handler)` | the core under it, for any form library: `handler` runs once per new refusal, not for one present at mount |
|
|
1891
|
+
|
|
1892
|
+
```tsx
|
|
1893
|
+
import { useLinkFragment, useLinkParam, useLinkPost, useSignOut } from '@softistx/alxia-react-router/session/react';
|
|
1894
|
+
|
|
1895
|
+
const token = useLinkParam('token', { drop: true });
|
|
1896
|
+
const linked = useLinkParam('state', { live: true }); // follows a redirect to this same route
|
|
1897
|
+
const code = useLinkFragment({ drop: true }); // /accept#<code>: undefined until hydrated, then string | null
|
|
1898
|
+
const { signOut, busy } = useSignOut({ next: '/orders' }); // or signOut({ next }) per call
|
|
1899
|
+
const { send, busy: posting } = useLinkPost(); // send({ link }) resolves { form, retryAfter, email } | undefined
|
|
1900
|
+
```
|
|
1901
|
+
|
|
1902
|
+
From `@softistx/alxia-react-router/session/model` (it pulls in no other module):
|
|
1903
|
+
|
|
1904
|
+
| export | |
|
|
1905
|
+
| --- | --- |
|
|
1906
|
+
| `safeNext(value)`, `HOME` | `value` when it is a path of this site (search and hash kept), else `/` (`HOME`): a `//`, a scheme, a backslash, a control character, more than 2000 characters or a dot segment that leaves the site |
|
|
1907
|
+
| `signInPath(next, { query?, path? }?)` (`path` must be a path of this site with no query or fragment, a `TypeError` otherwise), `secondFactorPath(next)`, `SIGN_IN_PATHS`, `SignInPaths` | the sign-in page's URL coming back to `next`, the second-factor page's, and the default paths `/sign-in` and `/sign-in/second-factor` |
|
|
1908
|
+
| `TOTP_CODE` | the regular expression of an authenticator app's code: six digits |
|
|
1909
|
+
| `SecondFactorKind`, `SignInStatus`, `StepUpVia` | `'code' \| 'recovery'`, `'signedIn' \| 'secondFactor'` and `'email' \| 'secondFactor'` |
|
|
1910
|
+
| `stepUpReducer`, `INITIAL_STEP_UP`, `StepUpState`, `StepUpAction`, `StepUpPhase` | the step-up's state on the page, with no React: `phase`, `via`, `challenge`, `attemptsLeft`, `locked`, `error`, `message` (the last refusal worded), `retryAfter`, `pending`, `resent` |
|
|
1911
|
+
| `stepUpProps(state)`, `StepUpProps` | what a code form shows (`via`, `attemptsLeft`, `locked`, `error`, `retryAfter`, `pending`, `resent`; never the challenge or the message), for a step-up dialog's props |
|
|
1912
|
+
| `StepUpRequestAnswer`, `StepUpConfirmAnswer`, `StepUpError` | what `stepUpSteps` answers, which the reducer takes as it is (a throttle carries `retryAfter`); `StepUpError` is `'invalid' \| 'expired' \| 'failed' \| 'throttled'` |
|
|
1913
|
+
| `postLinkRequest(path, email, options?)`, `postLinkArgs(path, body, fields, options?)`, `LinkPostRefusal`, `LinkPostOptions`, `LINK_JSON_HEADER` | post JSON to a link route behind `handingOver` and return a promise form's refusal (`{ form, retryAfter, ...fields }`, `undefined` when accepted or a redirect is followed); `options` is `{ fetch?, navigate?(location, { replace }), unreachable? }` |
|
|
1914
|
+
|
|
1915
|
+
From `@softistx/alxia-react-router/document`:
|
|
1916
|
+
|
|
1917
|
+
| export | |
|
|
1918
|
+
| --- | --- |
|
|
1919
|
+
| `DocumentNonce({ nonce, children })`, `DocumentNonceProps` | the provider of this response's CSP nonce, for the server render: wrap the router with `nonceOf(loadContext)` in `entry.server.tsx` |
|
|
1920
|
+
| `useNonce()` | the page's CSP nonce: the provider's on the server, the first script or `csp-nonce` meta of the `<head>`'s (else the first `script[nonce]`'s) in the browser (read once and cached), `undefined` when there is none |
|
|
1921
|
+
| `InlineScript({ code, nonce? })`, `InlineScriptProps` | an inline `<script>` with `nonce ?? useNonce()`; the code is not escaped, so it is a constant of yours, and `</script` or `<!--` in it throws a `TypeError`; no `nonce` attribute when there is no nonce |
|
|
1922
|
+
| `CspNonceMeta()` | `<meta property="csp-nonce" nonce>`, the nonce for what a UI library adds at runtime |
|
|
1923
|
+
| `createPageLanguage({ languages, fallback, browser? })` | `PageLanguage`: `pageLanguage`, `metaLanguage`, `chooseLanguage`, `useChosenLanguage`, for `<html lang>`, a route's `meta` and a language menu |
|
|
1924
|
+
| `PageLanguage`, `PageLanguageOptions` | the types of the instance and of its options |
|
|
1925
|
+
| `textDirection(language)` | `'ltr'` or `'rtl'` for `<html dir>`, from the base language |
|
|
1926
|
+
|
|
1927
|
+
From `@softistx/alxia-react-router/entry`:
|
|
1928
|
+
|
|
1929
|
+
| export | |
|
|
1930
|
+
| --- | --- |
|
|
1931
|
+
| `createEntry({ streamTimeout?, nonce?, isBot?, rootData?, onError? })`, `EntryOptions`, `Entry` | `/entry`: `{ handleRequest, streamTimeout }` (`Entry`), `entry.server.tsx` for Bun on the web stream renderer |
|
|
1932
|
+
| `handleRequest`, `streamTimeout`, `HandleRequest` | `/entry`: the default entry (`createEntry()`), its `5_000` and the type of `handleRequest` (assignable to React Router's `ServerEntryModule['default']`) |
|
|
1933
|
+
|
|
1934
|
+
From `@softistx/alxia-react-router/navigation` (`react` and `react-router` are its only imports; both hooks render on the server):
|
|
1935
|
+
|
|
1936
|
+
| export | |
|
|
1937
|
+
| --- | --- |
|
|
1938
|
+
| `useFocusOnNavigate()` | a ref to put on the page heading: focus moves to it after a `PUSH` or `POP` that changed the pathname, not on the first render, a `REPLACE` or a search-only change; it gets `tabIndex={-1}` when it has none |
|
|
1939
|
+
| `useRouteTransition(duration?)`, `RouteTransition`, `DEFAULT_TRANSITION_MS` | `{ pathname, transitioning }`: `transitioning` is `true` for `duration` ms (default `200`) after the pathname changed, `false` on the first render and for a search or hash change |
|
|
1940
|
+
|
|
1941
|
+
From `@softistx/alxia-react-router/lists` (`react` and `react-router` are its only imports; every hook renders on the server):
|
|
1942
|
+
|
|
1943
|
+
| export | |
|
|
1944
|
+
| --- | --- |
|
|
1945
|
+
| `useSearchChange({ resetKeys? })`, `SearchChange`, `SearchChangeOptions` | `(changes: SearchChange) => void`: a record sets a parameter given a string, deletes one given `null` or `undefined`, and deletes `resetKeys` (default `['after']`); a `URLSearchParams` replaces the whole search, and an updater `(prev) => URLSearchParams` computes it (`resetKeys` does not apply to these two); the history entry is replaced and the scroll position kept |
|
|
1946
|
+
| `useSameRouteLoading()` | `true` while a navigation is loading and its pathname is the current one (another search of the list), `false` for any other page |
|
|
1947
|
+
| `usePagedRows(firstPage, rowsOf, { cursorParam?, nextOf? }?)`, `PagedRows`, `PagedRowsOptions` | `{ rows, next, loading, error, loadMore }`: appends the pages the same route answers to `?<cursorParam>=<next>` (default `after`, `nextOf` default `page.next`) through `useFetcher`; starts over when `firstPage` is another object; a failure keeps the rows and sets `error` (an answer that is not a page), and data that is not a page is ignored |
|
|
1948
|
+
| `connectionPage(wanted, pageSize, fetchPage, { maxFirst? }?)`, `ConnectionPage`, `ConnectionPageOptions`, `ConnectionSlice`, `FetchConnectionPage`, `DEFAULT_MAX_FIRST` | a loader's numbered page over a cursor-paged connection: calls `fetchPage(first, after)` from the start, following `endCursor`, never asking more than `maxFirst` (default `100`), until page `wanted` is filled; answers `{ rows, total, page, pageCount, skip }`, `rows` being that page's alone; a page past the last gives the last one; stops on `hasNextPage: false`, a missing or repeated `endCursor` or an empty answer; a `RangeError` when `wanted`, `pageSize` or `maxFirst` is not an integer of at least 1 |
|
|
1949
|
+
| `nodesOf(connection)`, `EdgesConnection` | the nodes of a connection's `edges { node }`, in order, as a new array; `[]` for a `null` or `undefined` connection or `edges`, and a `null` edge or node is skipped |
|
|
1950
|
+
| `orFailed(after, run)`, `FAILED`, `isFailedPage(value)`, `FailedPage` | the loader half of `usePagedRows`: `run()`'s answer; an error is rethrown when `after` is empty, and with an `after` it answers `FAILED` (`{ failed: true }`, typed `Promise<T \| FailedPage>`), except a 3xx `Response`, which is rethrown. `isFailedPage` narrows an answer |
|
|
1951
|
+
|
|
1952
|
+
From `@softistx/alxia-react-router/help` (`react` and `react-router` are its only imports) and `/help/check` (Node and Bun):
|
|
1953
|
+
|
|
1954
|
+
| export | |
|
|
1955
|
+
| --- | --- |
|
|
1956
|
+
| `loadHelpFlows({ docs, captures, lang, fallbackLang? })`, `HelpFlows`, `LoadHelpFlowsOptions` | parses and validates the `docs/flows/*.md` of `import.meta.glob` (`?raw`) and resolves each capture to its four URLs (`?url` glob); throws a `FlowFormatError` naming file and line |
|
|
1957
|
+
| `useHelpFlows(help, { roles })`, `resolveHelp(help, routeIds, roles)`, `HelpAnswer` | `{ flows, fallback, roles, role, allRoles, otherRoles }`: the flows citing a current route match (the role overviews when none does), the user's roles with a flow (the tabs), the one to preselect and the other roles; the shape of `HelpSheet` |
|
|
1958
|
+
| `HelpPanel(props)`, `HelpPanelProps`, `HelpPanelSheetProps`, `HelpPanelSheetExtra`, `HelpPanelSheetPropsProp`, `HelpPanelButtonState`, `HelpBundle` | the help button and its sheet, loaded on the first open: `load` (flows per language) and `loadSheet` (a module with a default export taking `HelpPanelSheetProps`) together, one `onLoadError` and a retry on failure, no double load, nothing rendered without `roles`; `renderButton({ onOpen, open, loading })` draws the button; headless. Generic over the sheet's props: `sheetProps` is forwarded to the sheet, required only when the sheet declares required extra props, and it cannot override `help`, `roles`, `open` or `onOpenChange` ([guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/help.md#passing-data-to-the-sheet-sheetprops)) |
|
|
1959
|
+
| `useGuideRole({ roles, initialRole, guideUrl })`, `UseGuideRoleOptions`, `GuideRoleState`, `highestGuideRole(roles, order, fallback?)` | `{ role, roles, canPick, setRole, file }`: the picked role (always one of `roles`) and `guideUrl(role)` for the PDF reader; `highestGuideRole` is the role to open on: the first of `order` the viewer may read, else their first role, else `fallback` (the last of `order`) |
|
|
1960
|
+
| `parseFlow(source, file)`, `FlowFormatError`, `HelpFlow`, `HelpStep`, `HelpCapture`, `captureFile(name, width, theme)`, `CAPTURE_WIDTHS`, `CAPTURE_THEMES`, `CaptureWidth`, `CaptureTheme`, `ParsedFlow` | one flow file and its types; a capture is `<name>.<1440\|360>.<light\|dark>.webp` |
|
|
1961
|
+
| `checkHelp({ root?, routes?, flows?, ignore?, config? })`, `readRouteConfig`, `flattenRoutes`, `matchesIgnore`, `routeId`, `RouteEntry`, `FlatRoute`, `CheckHelpOptions`, `CheckHelpResult`, `HelpProblem` | `/help/check`: fails on a screen route no flow covers (a flow citing a layout covers the screens under it), a route a flow cites that does not exist, a missing capture; also `alxia-react-router help check` |
|
|
1962
|
+
|
|
1963
|
+
From `@softistx/alxia-react-router/oauth` (`react-router` is its only package import):
|
|
1964
|
+
|
|
1965
|
+
| export | |
|
|
1966
|
+
| --- | --- |
|
|
1967
|
+
| `oauthConsent({ json, errors, viewer, caller, find, approve, deny, choices?, requireBound?, requireBinding?, bindingHeader?, origin?, notFound?, stepUpRequired? })`, `ConsentOptions`, `ConsentRoute`, `ConsentRedirect`, `ConsentInput`, `ConsentBound` | `{ loader(request), action(request, language) }` for the consent route: the loader answers `{ pending, viewer, choices }` with `Cache-Control: no-store` (a 404 with `pending: null` for an unknown request); the action approves or denies the posted JSON and answers a `ConsentAnswer` |
|
|
1968
|
+
| `oauthGrants({ list, revoke, scopes?, notFound?, stepUpRequired? })`, `GrantsOptions`, `GrantsRoute`, `GrantScope`, `GrantScopeInfo` (each takes the key type `K extends string`, inferred from `scopes`), `GrantLike`, `ListedGrant`, `RevokeResult` | `{ list(ctx), revoke(ctx, id) }` for the connected apps: grants newest first with mapped scopes; `revoke` answers `revoked`, `already-revoked` or `step-up` |
|
|
1969
|
+
| `consentShouldRevalidate(args)` | the route's `shouldRevalidate`: `false` after a submission, React Router's default otherwise |
|
|
1970
|
+
| `requestIdOf(url)` | the `request_id` (else `request`) of an authorization link, trimmed; `undefined` when empty |
|
|
1971
|
+
| `boundConsentRequest(request, origin?)`, `consentBindingOf(request, header?, origin?)`, `consentRequestOf(response, origin, path?)`, `consentBindingCookie(id, secure)`, `consentCookieName(secure)`, `ConsentBinding`, `CONSENT_COOKIE`, `CONSENT_COOKIE_PLAIN`, `CONSENT_PATH`, `CONSENT_REQUEST_HEADER`, `CONSENT_COOKIE_MAX_AGE` | the request binding: the id the cookie names, `{ requestId, headers }` for the `caller`, and the pieces `mcpRelay` uses to set the cookie. `/mcp` also exports the four names |
|
|
1972
|
+
| `followableRedirect(value)` | the normalised address when `http:` or `https:`, else `undefined` |
|
|
1973
|
+
| `isRouteRefusal(value)`, `routeRefusalStatus(value)`, `RouteRefusal`, `DataRefusal` | re-exported from `/errors`, to recognise what the consent action throws and read its status |
|
|
1974
|
+
| `ConsentAnswer`, `ConsentDecisionIntent` | the types of the action's answer and of `'approve' \| 'deny'` |
|
|
1975
|
+
|
|
1976
|
+
From `@softistx/alxia-react-router/oidc` (`react-router`, `/session`'s cookies and `jose`, an optional peer):
|
|
1977
|
+
|
|
1978
|
+
| export | |
|
|
1979
|
+
| --- | --- |
|
|
1980
|
+
| `oidcClient(options)`, `OidcOptions`, `OidcClient`, `OidcUser` | `{ signIn(request), callback(request), oidcUser(request), requireOidcUser(request), logout(request), names }`; `oidcUser` is `{ claims, accessToken, idToken, expiresAt, headers, dpop }`; options `par` (`'auto' \| 'always' \| 'never'`), `dpop` (`{ alg?: 'ES256' \| 'EdDSA' }`), `revokeOnLogout`, `revokeTimeoutMs` and `onRevokeError` |
|
|
1981
|
+
| `generateDpopKey(alg?)`, `signDpopProof(key, { method, url, accessToken?, nonce? })`, `DpopKey`, `DpopBinding`, `DpopAlgorithm`, `DpopProofInput` | DPoP proofs (RFC 9449) for code that keeps its own key; `OidcUser.dpop` is a `DpopBinding` (`thumbprint`, `proof`, `headers`, `fetch`) or `null` |
|
|
1982
|
+
| `OidcError`, `OidcErrorCode` | what `callback` throws: a `code` and the `headers` that clear the spent challenge |
|
|
1983
|
+
|
|
1984
|
+
From `@softistx/alxia-react-router/api-keys` (`react-router` is its only import):
|
|
1985
|
+
|
|
1986
|
+
| export | |
|
|
1987
|
+
| --- | --- |
|
|
1988
|
+
| `apiKeys({ errors, list, create, revoke, notFound?, stepUpRequired? })`, `ApiKeysOptions`, `ApiKeysRoute`, `ApiKeyLike`, `CreatedApiKey` | `{ list(ctx), create(ctx, input, language), revoke(ctx, id, language) }`: the keys newest first; a creation answers `CreateKeyAnswer` (`{ ok: true, intent: 'create-key', secret, apiKey }`, `no-store`, or a refusal with `stepUp`); a revocation answers `RevokeKeyAnswer` (an unknown key is `alreadyRevoked`) |
|
|
1989
|
+
| `CreateKeyAnswer`, `RevokeKeyAnswer` | what the page's fetcher reads |
|
|
1990
|
+
|
|
1991
|
+
From `@softistx/alxia-react-router/oauth/react` (`react` and `react-router` are its only imports):
|
|
1992
|
+
|
|
1993
|
+
| export | |
|
|
1994
|
+
| --- | --- |
|
|
1995
|
+
| `useConsent(requestId, { request, confirm, go?, action? })`, `UseConsentOptions` | `{ approve(bound?), deny, pending, expired, error, dialogProps }`: posts the decision as JSON (`approve`'s `bound`, a `ConsentBound`, with it), replays it after the shared step-up (`useStepUpReplay`), follows the callback with a hard navigation (`go`) and holds `pending` until the page is left |
|
|
1996
|
+
|
|
1997
|
+
From `@softistx/alxia-react-router/link` (`react` and `react-router` are its only imports; it renders on the server):
|
|
1998
|
+
|
|
1999
|
+
| export | |
|
|
2000
|
+
| --- | --- |
|
|
2001
|
+
| `RouterLink`, `RouterLinkProps` | React Router's `Link` as a UI library's link component: takes `href` (or `to`), spreads `className`, `children`, `ref` and every anchor prop onto the `<a>`, keeps `Link`'s own props (`replace`, `prefetch`, `reloadDocument`, ...) |
|
|
2002
|
+
|
|
2003
|
+
From `@softistx/alxia-react-router/fetcher` (`react` and `react-router` are its imports; it renders on the server):
|
|
2004
|
+
|
|
2005
|
+
| export | |
|
|
2006
|
+
| --- | --- |
|
|
2007
|
+
| `useFetcherAnswer(fetcher, onAnswer?)`, `AnswerSource` | `onAnswer(answer)` once per answer that arrives while the fetcher is idle and differs from the last one seen (the data present at mount counts as seen); the handler is read from a ref; returns the latest answer handed over, `undefined` before the first |
|
|
2008
|
+
| `useFetcherDone(fetcher, isDone, onDone)` | `onDone()` once per new answer that `isDone(data)` accepts, while the fetcher is idle (a save done: close the dialog); the data present at mount counts as handled, so a dialog that reopens does not fire again; `isDone` and `onDone` are read from refs |
|
|
2009
|
+
| `authRefusal(answer, fields)`, `AuthAnswer`, `AuthRefusal` | maps an auth route action's answer `{ sent?, formError?, retryAfter?, fieldErrors? }` to the refusal an auth form's `onSubmit` returns, `{ form, retryAfter, <field> }` for the listed `fields`, or `undefined` when `sent` is true |
|
|
2010
|
+
| `useFetcherPromise(fetcher, { refusal? }?)`, `FetcherPromiseOptions`, `FetcherPromiseAborted`, `FetcherPromiseNoAnswer` | returns a stable `run(submit)` that calls `submit` (`() => fetcher.submit(...)`) and returns a Promise settled by the fetcher's next new answer: resolved with it, or rejected with an `Error` when `refusal(answer)` returns a message (or your own `Error`); an answer held before the call never settles it; a second `run` while one is pending rejects the older with `FetcherPromiseAborted` (`reason: 'superseded'`); an unmount rejects the pending one (`'unmounted'`); a submission that ends idle with no new answer (`null`, `undefined` or the same data) rejects with `FetcherPromiseNoAnswer`; a `submit` that throws rejects with its error |
|
|
2011
|
+
| `useFormRefusal(result)`, `FormRefusalResult` | `useFormRefusal(fetcher.data)` returns the `FormErrors` of a fetcher answer that carries `fieldErrors` (`apiErrors.formRefusal`'s), `undefined` for no answer, a done step or a refusal without them; stable for one answer |
|
|
2012
|
+
| `useVisibleInterval(callback, ms, { enabled?, runOnVisible? }?)`, `VisibleIntervalOptions` | runs `callback` every `ms` only while `document.visibilityState` is `'visible'` (a tick while hidden is skipped); when a hidden page becomes visible after at least `ms` since the last run it runs at once (`runOnVisible`, default `true`); `enabled: false` stops it; the callback is read from a ref, so a new function never restarts the timer; the timer and listener are cleared on unmount; nothing starts on the server |
|
|
2013
|
+
| `useVisibleRevalidation(ms, { enabled? }?)` | `useVisibleInterval` over `useRevalidator`: revalidates the route's loaders every `ms` while the page is visible, skipping a tick while a revalidation is in flight |
|
|
2014
|
+
| `useRevalidateOnFocus({ minHiddenMs?, enabled? }?)`, `RevalidateOnFocusOptions` | `useRevalidator` on the page's return, no timer: when the tab becomes visible or the window gains focus after being hidden or blurred for at least `minHiddenMs` (default `30_000`), revalidates the route's loaders once; skips a revalidation already in flight; `enabled: false` removes the listeners |
|
|
2015
|
+
| `useDebouncedFetcher(value, to, { delayMs?, minLength?, enabled?, key?, keep? }?)`, `DebouncedFetcher`, `DebouncedFetcherOptions`, `DebouncedFetcherState` | a resource route loaded for what is typed: one `fetcher.load` after `delayMs` (250) without a change and from `minLength` (1) trimmed characters; `to` is a URL or `(value) => url`; returns `{ data, stale, state, retry }`: `data` is the answer for the value as it stands, else the previous one with `stale` set; `state` is `'idle' \| 'waiting' \| 'loading' \| 'done'`; `keep(answer)` filters what may stay as the stale answer; `retry()` (stable) asks again at once |
|
|
2016
|
+
|
|
2017
|
+
From `@softistx/alxia-react-router/mcp` (needs `@softistx/alxia-proxy`, installed by the app):
|
|
2018
|
+
|
|
2019
|
+
| export | |
|
|
2020
|
+
| --- | --- |
|
|
2021
|
+
| `mcpRelay({ api, secret: { header, value }, timeout?, consent? })`, `McpRelayOptions` | a `beforeAll` plugin relaying the paths of `MCP_RELAY_PATHS` (`@softistx/alxia`) to `api`; see the guide |
|
|
2022
|
+
| `CONSENT_COOKIE`, `CONSENT_COOKIE_PLAIN`, `CONSENT_PATH`, `CONSENT_REQUEST_HEADER` | the binding cookie's names (`__Host-` over HTTPS, plain over HTTP), the consent path and the header `oauthConsent` forwards; the same names as `/oauth` |
|
|
2023
|
+
|
|
2024
|
+
From `@softistx/alxia-react-router/subscription` (no import, no peer):
|
|
2025
|
+
|
|
2026
|
+
| export | |
|
|
2027
|
+
| --- | --- |
|
|
2028
|
+
| `createSubscriptionProxy({ endpoint, allow, getToken, headers?, origin?, heartbeatMs?, fetch? })`, `SubscriptionProxy`, `SubscriptionProxyOptions`, `SubscriptionArgs` | a resource route's `loader` (GET) and `action` (POST) relaying GraphQL subscriptions over SSE (graphql-sse's distinct connections mode). `allow` is `{ [operationName]: document }`: the proxy sends its own document, the client's `query` and `extensions` are ignored and an unknown name is a 403. Both methods refuse a cross-site request (403) and a POST that is not JSON (415); 401 without a token; 400 for a malformed or oversize request (body 64 KiB, query string and variables 16 KiB); the bearer and `headers` upstream (`headers(request, { request, context, params })`: a function gets the route's context, which never leaves it), a heartbeat comment every `heartbeatMs` (15000), the upstream aborted with the client, a pulled relay with a 1 MiB cap per event, an upstream 429 passed on with `Retry-After` and `retryAfter`, 502 for an upstream failure |
|
|
2029
|
+
|
|
2030
|
+
From `@softistx/alxia-react-router/subscription/react` (imports `react` and `@nxgt/graphql-client/react`, an optional peer):
|
|
2031
|
+
|
|
2032
|
+
| export | |
|
|
2033
|
+
| --- | --- |
|
|
2034
|
+
| `useLiveSubscription(document, variables, { keyOf?, versionOf?, onChange, revalidate?, skip? })`, `UseLiveSubscriptionOptions`, `LiveSubscription`, `LiveControls` | a subscription kept alive: returns `{ status, retry, revalidate }`. `status` is `'connecting' \| 'live' \| 'reconnecting' \| 'stopped'`; `onChange(event, { revalidate })` gets each fresh event (one with a lower `versionOf` than the highest seen for its `keyOf` is dropped); `revalidate()` runs at most once per 300 ms of quiet (2 s at most under a steady stream) and after every reopen but the first. Without `versionOf` and `revalidate` every event is delivered and nothing is read again. `retry()` reopens a stopped stream; `skip` connects nothing |
|
|
2035
|
+
| `createLiveController(options)`, `LiveControllerOptions`, `LiveStatus` | the rules apart from React, with an injectable `timers` and `random`, for a hook of your own |
|
|
2036
|
+
| `classifyEnd(error?)`, `EndKind` | what an ended stream calls for: `{ kind: 'stop' }` (a 401, any other 4xx) or `{ kind: 'retry', afterMs? }` (a 429's `retryAfter`, a 5xx, a network error, `realtime.session-ended`, a clean complete) |
|
|
2037
|
+
| `backoffDelay(attempt, random)`, `BACKOFF_MIN_MS`, `BACKOFF_MAX_MS` | the wait before reconnect `attempt`: 1 s doubling to 30 s, spread over its upper half |
|
|
2038
|
+
| `createVersions()`, `createRevalidateScheduler(timers, fire)`, `REVALIDATE_DEBOUNCE_MS`, `REVALIDATE_MAX_WAIT_MS` | the highest version per key, and the debounced read |
|
|
2039
|
+
|
|
2040
|
+
From `@softistx/alxia-react-router/media` (no import, no peer):
|
|
2041
|
+
|
|
2042
|
+
| export | |
|
|
2043
|
+
| --- | --- |
|
|
2044
|
+
| `proxyMediaRead(args, options)` | a resource route's `loader`: `GET` and `HEAD` of a file or a rendition, relayed with the session's Bearer |
|
|
2045
|
+
| `proxyMediaWrite(args, options)` | a resource route's `action`: `PUT <kind>` (the raw file, streamed; 413 before the API when the declared length is over `maxBytes`) and `DELETE <kind>/<key>`; 401 without a session |
|
|
2046
|
+
| `MediaProxyOptions` (`api`, `kinds`, `getToken`, `headers?`, `origin?`, `prefix?`, `apiPrefix?`, `fetch?`, `onRefusal?`, `onSuccess?`, `forwardQuery?`, `requireHeaders?`), `MediaArgs`, `MediaKindLimit`, `MediaRefusal`, `MediaSuccess`, `MediaHookResult` | the options and the route's arguments |
|
|
2047
|
+
|
|
2048
|
+
From `@softistx/alxia-react-router/media/client` (no import, no peer; browser only, safe in the client bundle):
|
|
2049
|
+
|
|
2050
|
+
| export | |
|
|
2051
|
+
| --- | --- |
|
|
2052
|
+
| `uploadMedia(kind, file, { onProgress?, signal?, basePath?, timeoutMs?, headers?, query? })` | `PUT /media/<kind>?<query>` on `XMLHttpRequest`: `onProgress(0..100)` while the body goes up, abort through `signal`; resolves `{ key, contentType, size }`. Fits an upload field's `onUpload(file, onProgress, signal)` |
|
|
2053
|
+
| `MediaUploadError` (`reason`, `status`, `code?`, `body?` (the whole JSON refusal), `retryAfter?`, seconds from `Retry-After` as seconds or an HTTP date, `undefined` when absent), `MediaUploadReason`, `reasonOf(status)` | what it rejects with; `reason` is `unauthenticated`, `forbidden`, `length_required`, `too_large`, `type_refused`, `rate_limited`, `unavailable`, `timeout`, `failed`, `network`, `invalid_response` or `aborted` |
|
|
2054
|
+
| `MediaUploadResult`, `UploadMediaOptions` | the types |
|
|
2055
|
+
|
|
2056
|
+
The `alxia-react-router` bin, run with `bunx`:
|
|
2057
|
+
|
|
2058
|
+
| command | |
|
|
2059
|
+
| --- | --- |
|
|
2060
|
+
| `reveal [--force]` | writes the default server to `app/server.ts`, or to `alxia({ entry })`'s file; refuses an existing file without `--force` |
|
|
2061
|
+
|
|
2062
|
+
## Documentation
|
|
2063
|
+
|
|
2064
|
+
- [Documentation index](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/README.md): every page, and when to read it.
|
|
2065
|
+
- [A relying party of an OIDC issuer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/oidc.md): `oidcClient`, the routes, the options and the limits.
|
|
2066
|
+
- [Flow docs per role](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/help.md): the `docs/flows` format, loading, `useHelpFlows`, the lazy `HelpPanel`, `useGuideRole` and the coverage check.
|
|
2067
|
+
- [Getting started](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/getting-started.md): a new app, the official template or an existing app.
|
|
2068
|
+
- [How it works](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/how-it-works.md): dev, the build and `vite preview`, and what the build sets for Bun.
|
|
2069
|
+
- [Customising the server](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/customising-the-server.md): `createServer()`, and the escape hatches.
|
|
2070
|
+
- [The document](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/document.md): the CSP nonce in the root, `InlineScript` for a theme's boot script with no flash, `CspNonceMeta`, and the entry.
|
|
2071
|
+
- [Typing the loaders](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/typing-the-loaders.md): `Register`, and the app's own context keys.
|
|
2072
|
+
- [The security headers](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/csp-nonce.md) (pages and assets, the nonce), [Beside the pages](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/beside-the-pages.md) (middlewares, routes, WebSockets, the client's files), [OpenAPI](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/openapi.md), [Testing](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/testing.md) and [Deploying](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/deploying.md), with Docker.
|
|
2073
|
+
- [Installable and offline](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/pwa.md): what the subpaths hold, the worker's contract, the worker, what it caches, the offline page, building the worker with `alxia()` or `buildWorker`, the hooks in React, registering the worker and offering an update, serving the worker's script, the web app manifest, and clearing at sign-out.
|
|
2074
|
+
- [An API's refusals](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/errors.md): what `/errors` holds, recognising an API error, the request id, the page a request is for, the catalogue store, the form checks in the API's words, the provider, wording a refusal, loaders and the error page, actions, JSON actions and CSRF, and keeping the catalogue fresh.
|
|
2075
|
+
- [A BFF session](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md): redirects that stay on the site, the cookies, the sign-in route, the second factor, the viewer and sign-out, the step-up, and the pages a mail's link opens.
|
|
2076
|
+
- [A fetcher's fresh answer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md): `useFetcherAnswer`: a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useFetcherDone`: a callback once when a write is done; `useFetcherPromise`: one submission's answer as a Promise; `useDebouncedFetcher`: a resource route loaded for what is typed; `useVisibleInterval` and `useVisibleRevalidation`: a callback or a revalidation on an interval while the page is visible.
|
|
2077
|
+
- [Lists whose state is the URL](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/lists.md): `useSearchChange`, `useSameRouteLoading`, `usePagedRows`, `connectionPage`, `nodesOf`: a search that drops the cursor, a skeleton for the same page reloading, a load-more button, numbered pages over a cursor connection, a connection's nodes.
|
|
2078
|
+
- [Focus and fade on navigation](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/navigation.md): `useFocusOnNavigate`, `useRouteTransition`: focus on the page heading after a client navigation, a fade only when the pathname changes.
|
|
2079
|
+
- [The consent screen of an OAuth server](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/oauth.md): `oauthConsent`, a loader and an action over the janus-oauth GraphQL, and `useConsent`: the decision, the step-up replay and the callback.
|
|
2080
|
+
- [MCP and OAuth through the BFF](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/mcp.md): `mcpRelay`, the paths it relays, what it strips and sets on each side, the body limits and the errors.
|
|
2081
|
+
- [A user's API keys](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/api-keys.md): `apiKeys`, a list, a creation whose secret shows once and a revocation, with the step-up replayed by the page.
|
|
2082
|
+
- [Subscriptions for a BFF](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/subscriptions.md): exposing a GraphQL subscription to the browser through a resource route: the allow-list, the session's bearer, the headers, the heartbeat, abort and rate limits.
|
|
2083
|
+
- [Troubleshooting](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md): each message, and the traps that print none.
|
|
2084
|
+
- [Roadmap](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/roadmap.md): what is coming, and what is not planned.
|
|
2085
|
+
- [Example](https://github.com/softistx/alxia/tree/develop/examples/react-router): the official template, these four changes, then an `app/server.ts` with a session, an `/api`, secure headers with a nonce and a streamed page.
|
|
2086
|
+
- [Recipes](https://github.com/softistx/alxia/blob/develop/docs/recipes/README.md): [Deploy with Docker](https://github.com/softistx/alxia/blob/develop/docs/recipes/deploying.md), [Health checks and graceful shutdown](https://github.com/softistx/alxia/blob/develop/docs/recipes/health-and-shutdown.md).
|