@softistx/alxia-react-router 0.86.4 → 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +81 -5
  2. package/dist/chunks/{index-t2ph23wk.js → index-5hjhzztk.js} +6 -17
  3. package/dist/chunks/{index-t2ph23wk.js.map → index-5hjhzztk.js.map} +3 -4
  4. package/dist/chunks/{index-v2z5k640.js → index-6zx9dfvs.js} +3 -18
  5. package/dist/chunks/{index-v2z5k640.js.map → index-6zx9dfvs.js.map} +3 -4
  6. package/dist/chunks/{index-xd5aqy3g.js → index-c721mm5a.js} +26 -3
  7. package/dist/chunks/{index-xd5aqy3g.js.map → index-c721mm5a.js.map} +4 -3
  8. package/dist/chunks/index-njfh26ez.js +19 -0
  9. package/dist/chunks/index-njfh26ez.js.map +10 -0
  10. package/dist/chunks/index-t68hwhz1.js +37 -0
  11. package/dist/chunks/{index-0786n4qe.js.map → index-t68hwhz1.js.map} +5 -4
  12. package/dist/errors/index.js +7 -4
  13. package/dist/errors/index.js.map +2 -2
  14. package/dist/errors/use-json-fetcher.d.ts +10 -1
  15. package/dist/errors/use-json-fetcher.d.ts.map +1 -1
  16. package/dist/fetcher/index.js +3 -5
  17. package/dist/fetcher/index.js.map +2 -2
  18. package/dist/oidc/dpop-fetch.d.ts +39 -0
  19. package/dist/oidc/dpop-fetch.d.ts.map +1 -0
  20. package/dist/oidc/env.d.ts +52 -0
  21. package/dist/oidc/env.d.ts.map +1 -0
  22. package/dist/oidc/index.d.ts +3 -0
  23. package/dist/oidc/index.d.ts.map +1 -1
  24. package/dist/oidc/index.js +248 -24
  25. package/dist/oidc/index.js.map +8 -5
  26. package/dist/oidc/oidc.d.ts +18 -0
  27. package/dist/oidc/oidc.d.ts.map +1 -1
  28. package/dist/oidc/routes.d.ts +76 -0
  29. package/dist/oidc/routes.d.ts.map +1 -0
  30. package/dist/session/index.js +9 -7
  31. package/dist/session/index.js.map +2 -2
  32. package/dist/session/model/index.js +2 -2
  33. package/dist/session/react/index.js +4 -6
  34. package/dist/session/react/index.js.map +2 -2
  35. package/docs/README.md +1 -1
  36. package/docs/guide/errors.md +21 -2
  37. package/docs/guide/fetcher.md +28 -0
  38. package/docs/guide/oidc.md +172 -6
  39. package/docs/roadmap.md +13 -0
  40. package/docs/troubleshooting.md +109 -0
  41. package/package.json +7 -7
  42. package/dist/chunks/index-0786n4qe.js +0 -25
  43. package/dist/chunks/index-ajtvyq35.js +0 -16
  44. package/dist/chunks/index-ajtvyq35.js.map +0 -10
@@ -9,6 +9,11 @@ a loader, a message React Router or the browser prints, or an error from
9
9
 
10
10
  - [`GET https://registry.npmjs.org/@softistx/… - 401`, or `404` on a `@softistx` package](#get-httpsregistrynpmjsorgsoftistx---401-or-404-on-a-softistx-package)
11
11
  - [`docs/flows/…: <what is wrong with the front-matter>`](#docsflows-what-is-wrong-with-the-front-matter)
12
+ - [`The OIDC environment is not usable:` (`/oidc`)](#the-oidc-environment-is-not-usable-oidc)
13
+ - [`TypeError: callbackRoute(): errorPath must be a path of this site with no query or fragment, starting with a single "/"; got ….` (`/oidc`)](#typeerror-callbackroute-errorpath-must-be-a-path-of-this-site-with-no-query-or-fragment-starting-with-a-single--got--oidc)
14
+ - [`TypeError: signOutRoute(): redirectTo must be a path of this site, starting with a single "/"; got ….` (`/oidc`)](#typeerror-signoutroute-redirectto-must-be-a-path-of-this-site-starting-with-a-single--got--oidc)
15
+ - [`TypeError: oidcClient(): refreshFlightMs must be a finite number of milliseconds, from 0 to 2147483647.` (`/oidc`)](#typeerror-oidcclient-refreshflightms-must-be-a-finite-number-of-milliseconds-from-0-to-2147483647-oidc)
16
+ - [`TypeError: oidc.refresh(): the user was not returned by this client.` (`/oidc`)](#typeerror-oidcrefresh-the-user-was-not-returned-by-this-client-oidc)
12
17
  - [`The returned state is not the one this sign-in sent.` and the other `OidcError` messages (`/oidc`)](#the-returned-state-is-not-the-one-this-sign-in-sent-and-the-other-oidcerror-messages-oidc)
13
18
  - [`capture file x.1440.light.webp is missing from docs/flows/captures/`](#capture-file-x1440lightwebp-is-missing-from-docsflowscaptures)
14
19
  - [`route "x" is covered by no flow: …`](#route-x-is-covered-by-no-flow-cite-it-in-a-flows-routes-or-add-it-to-the-ignore-list)
@@ -2414,6 +2419,110 @@ catch (error) {
2414
2419
  }
2415
2420
  ```
2416
2421
 
2422
+ `callbackRoute(oidc, { errorPath })` does this for you.
2423
+
2424
+ See the [OIDC guide](guide/oidc.md).
2425
+
2426
+ ### `TypeError: callbackRoute(): errorPath must be a path of this site with no query or fragment, starting with a single "/"; got ….` (`/oidc`)
2427
+
2428
+ ```
2429
+ TypeError: callbackRoute(): errorPath must be a path of this site with no query or fragment, starting with a single "/"; got "https://evil.test".
2430
+ ```
2431
+
2432
+ **When:** the app calls `callbackRoute(oidc, { errorPath })` at startup.
2433
+
2434
+ **Why:** a failed callback redirects to `errorPath?sign-in-error=<code>`, so `errorPath` must be a path of this site: relative, starting with `//` or `/\`, an absolute URL, or holding a query (`?`) or fragment (`#`) is refused when the route is created, not at the first failure.
2435
+
2436
+ **Fix:** give the path alone; the code is added for you:
2437
+
2438
+ ```ts
2439
+ export const { loader } = callbackRoute(oidc, { errorPath: '/sign-in/failed' });
2440
+ ```
2441
+
2442
+ ### `TypeError: signOutRoute(): redirectTo must be a path of this site, starting with a single "/"; got ….` (`/oidc`)
2443
+
2444
+ ```
2445
+ TypeError: signOutRoute(): redirectTo must be a path of this site, starting with a single "/"; got "//evil.test".
2446
+ ```
2447
+
2448
+ **When:** the app calls `signOutRoute(oidc, { redirectTo })` at startup.
2449
+
2450
+ **Why:** after a local sign-out the route redirects to `redirectTo`, so it must be a path of this site: relative, an absolute URL, or starting with `//` or `/\` (which a redirect reads as another site) is refused. A query (`/?signed-out=1`) and a fragment (`/bye#done`) are allowed here.
2451
+
2452
+ **Fix:** pass a path of this site:
2453
+
2454
+ ```ts
2455
+ export const { action, loader } = signOutRoute(oidc, { redirectTo: '/?signed-out=1' });
2456
+ ```
2457
+
2458
+ ### `TypeError: oidcClient(): refreshFlightMs must be a finite number of milliseconds, from 0 to 2147483647.` (`/oidc`)
2459
+
2460
+ ```
2461
+ TypeError: oidcClient(): refreshFlightMs must be a finite number of milliseconds, from 0 to 2147483647.
2462
+ ```
2463
+
2464
+ **When:** the app calls `oidcClient({ refreshFlightMs })` at startup.
2465
+
2466
+ **Why:** `refreshFlightMs` is how long parallel refreshes share one flight. A negative number, `NaN`, `Infinity` or a value past 2147483647 (the longest a timer can wait; 2147483647 itself is allowed) is refused when the client is made. `0` is allowed: the flight is forgotten at once.
2467
+
2468
+ **Fix:** leave it out (10 s), or give a number of milliseconds well under the access token's lifetime:
2469
+
2470
+ ```ts
2471
+ oidcClient({ ...options, refreshFlightMs: 5_000 });
2472
+ ```
2473
+
2474
+ ### `TypeError: oidc.refresh(): the user was not returned by this client.` (`/oidc`)
2475
+
2476
+ ```
2477
+ TypeError: oidc.refresh(): the user was not returned by this client.
2478
+ ```
2479
+
2480
+ **When:** the app calls `oidc.refresh(user)` or `dpopFetch(oidc, user)` with a user that `oidc` did not return.
2481
+
2482
+ **Why:** the client refreshes from the tokens it holds for each user it returned (`oidcUser`, `requireOidcUser`, a previous `refresh`), not from the fields of the object. A spread copy (`{ ...user }`), a hand-made double or a user of another `oidcClient` has none, so it is refused rather than refreshed from a guess.
2483
+
2484
+ **Fix:** pass the user as `oidcUser` or `requireOidcUser` returned it, or the one `refresh` or `onUser` gave back:
2485
+
2486
+ ```ts
2487
+ const user = await oidc.requireOidcUser(request);
2488
+ const fresh = await oidc.refresh(user, { force: true });
2489
+ ```
2490
+
2491
+ See the [OIDC guide](guide/oidc.md).
2492
+
2493
+ ### `The OIDC environment is not usable:` (`/oidc`)
2494
+
2495
+ **When:** the server starts and `await oidcFromEnv()` throws an `OidcEnvError`
2496
+ whose message lists the problems, one per line. `error.problems` holds them.
2497
+
2498
+ **Why, by line:**
2499
+
2500
+ - `OIDC_ISSUER is not an absolute URL.` or `OIDC_ISSUER must be an https: URL.`
2501
+ (also `OIDC_REDIRECT_URI` and `OIDC_POST_LOGOUT_REDIRECT_URI`): the value has
2502
+ no scheme and host, or it is `http:` and not on loopback (`localhost`,
2503
+ `127.0.0.1`, `[::1]`); an address is `https:`, or `http:` on loopback.
2504
+ - `OIDC_ISSUER is not set.` (or `OIDC_CLIENT_ID`, `OIDC_REDIRECT_URI`) and
2505
+ `OIDC_SESSION_SECRET_FILE (or OIDC_SESSION_SECRET) is not set.`: a required
2506
+ variable is missing.
2507
+ - `Set OIDC_CLIENT_SECRET or OIDC_CLIENT_SECRET_FILE, not both.`: a secret is
2508
+ given directly and through a file.
2509
+ - `OIDC_SESSION_SECRET_FILE names a file that cannot be read: check the path and its permissions.`: the path,
2510
+ the mount, or the permissions. Without Bun the default reader is missing: pass
2511
+ `readFile` and `statFile`.
2512
+ - `OIDC_SESSION_SECRET_FILE names a file readable by group or others (mode …)`:
2513
+ `chmod 600` the file.
2514
+ - `OIDC_SESSION_SECRET_FILE names a file with whitespace inside: it must hold one value.`:
2515
+ a secret is one token; a space or a line break inside the file refuses it (a
2516
+ trailing newline is trimmed). The message never prints the path.
2517
+ - `OIDC_SESSION_SECRET_FILE names an empty file.`: the secret file has only
2518
+ whitespace.
2519
+ - `The session secret must be 32 characters or more (OIDC_SESSION_SECRET_FILE).`:
2520
+ the variable it came from is named.
2521
+
2522
+ **Fix:** set what the list names; the error holds every problem at once. A
2523
+ prefix other than `OIDC` is passed as `oidcFromEnv({ prefix })`. `secure` is not
2524
+ a variable: pass `secure: !import.meta.env.DEV` to `oidcClient`.
2525
+
2417
2526
  See the [OIDC guide](guide/oidc.md).
2418
2527
 
2419
2528
  ## Types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softistx/alxia-react-router",
3
- "version": "0.86.4",
3
+ "version": "0.88.0",
4
4
  "description": "alxia as the server of a React Router framework app: server rendering behind the app's hooks, loaders reading its typed context, the client's assets served; the code with no UI an installable app shares (`/pwa`), its hooks (`/pwa/react`), `noCache` for the worker's script (`/pwa/server`), the service worker on Workbox (`/pwa/worker`) and its build (`/pwa/build`), an API's refusals worded for the page (`/errors`), the BFF session: cookies, sign-in, step-up and mail links (`/session`), its page hooks (`/session/react`) and what it shares with the page (`/session/model`), a GraphQL subscription relayed to the browser over SSE (`/subscription`) and kept alive in the page (`/subscription/react`), an API's MCP and OAuth endpoints relayed on the app's origin (`/mcp`), per-role flow docs, the help panel's data and its lazy `HelpPanel`, and the role guide's `useGuideRole` (`/help`, `/help/check`), an API's media files read and uploaded through the app (`/media`) and uploaded from the page with progress (`/media/client`), the page's CSP nonce and inline boot scripts (`/document`) and a streaming `entry.server` (`/entry`), the consent screen of an OAuth server: a route's loader and action, the connected apps' list and revoke (`/oauth`) and the decision hook (`/oauth/react`), a user's API keys listed, created behind a step-up and revoked (`/api-keys`) and `/oidc`: a relying party of an external OpenID Connect issuer (authorization code + PKCE, id token validation, a sealed token cookie, refresh and RP-initiated logout)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -213,20 +213,20 @@
213
213
  "@softistx/alxia-proxy": "^0.5.0",
214
214
  "@softistx/alxia-secure-headers": "^0.6.0",
215
215
  "@softistx/graphql-client": "^0.13.0",
216
- "@react-router/dev": "^8.5.0",
217
- "@softistx/janus": "^0.80.0",
216
+ "@react-router/dev": "^8.5.3",
217
+ "@softistx/janus": "^0.85.0",
218
218
  "@types/bun": "^1.4.5",
219
- "@types/react": "^19.3.0",
219
+ "@types/react": "^19.3.3",
220
220
  "@types/react-dom": "^19.3.0",
221
221
  "graphql": "^17.0.2",
222
222
  "happy-dom": "^21.0.4",
223
- "intl-messageformat": "^12.1.4",
224
- "isbot": "^5.2.2",
223
+ "intl-messageformat": "^12.2.1",
224
+ "isbot": "^5.2.4",
225
225
  "jose": "^6.2.0",
226
226
  "react": "^19.3.1",
227
227
  "react-dom": "^19.3.1",
228
228
  "react-hook-form": "^7.91.0",
229
- "react-router": "^8.5.0",
229
+ "react-router": "^8.5.3",
230
230
  "vite": "^7.0.0",
231
231
  "workbox-core": "^7.4.1",
232
232
  "workbox-expiration": "^7.4.1",
@@ -1,25 +0,0 @@
1
- // src/session/model/safe-next.ts
2
- var HOME2 = "/";
3
- var BASE = "http://next.invalid";
4
- function safeNext2(value) {
5
- if (!value || value.length > 2000)
6
- return HOME2;
7
- if (!value.startsWith("/") || value.startsWith("//"))
8
- return HOME2;
9
- if (/[\\\p{Cc}\s]/u.test(value))
10
- return HOME2;
11
- try {
12
- const url = new URL(value, BASE);
13
- const path = `${url.pathname}${url.search}${url.hash}`;
14
- if (url.origin !== BASE || path.startsWith("//"))
15
- return HOME2;
16
- return path;
17
- } catch {
18
- return HOME2;
19
- }
20
- }
21
-
22
- export { HOME2, safeNext2 };
23
-
24
- //# debugId=DC9B9B90F989919264756E2164756E21
25
- //# sourceMappingURL=index-0786n4qe.js.map
@@ -1,16 +0,0 @@
1
- // src/errors/use-json-fetcher.ts
2
- import { useFetcher } from "react-router";
3
- function useJsonFetcher2(key, action) {
4
- const fetcher = useFetcher(key ? { key } : undefined);
5
- const post = (body, to = action) => fetcher.submit(body, {
6
- method: "post",
7
- encType: "application/json",
8
- ...to ? { action: to } : {}
9
- });
10
- return { fetcher, post, busy: fetcher.state !== "idle" };
11
- }
12
-
13
- export { useJsonFetcher2 };
14
-
15
- //# debugId=4A99F5857CB639C064756E2164756E21
16
- //# sourceMappingURL=index-ajtvyq35.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/errors/use-json-fetcher.ts"],
4
- "sourcesContent": [
5
- "import { type FetcherWithComponents, useFetcher } from 'react-router';\n\n/** What a fetcher can post as JSON. */\nexport type JsonBody = Parameters<FetcherWithComponents<unknown>['submit']>[0];\n\n/**\n * A fetcher posting JSON to its page's action (which reads it with\n * `readJson`, and answers `fetcherResult` or the like): `post` sends a\n * body, `busy` while it is in flight. `key` shares the fetcher between the\n * form that posts and the component that reads the answer; `action` posts to\n * another route's action instead (a resource route's, such as a\n * `notifications/poll`). `post` takes the target of one call as its second\n * argument (a list's rows each post to their own record's action).\n */\nexport function useJsonFetcher<Action, Body extends JsonBody = JsonBody>(\n\tkey?: string,\n\taction?: string,\n): {\n\tfetcher: ReturnType<typeof useFetcher<Action>>;\n\tpost(body: Body, to?: string): Promise<void>;\n\tbusy: boolean;\n} {\n\tconst fetcher = useFetcher<Action>(key ? { key } : undefined);\n\tconst post = (body: Body, to = action) =>\n\t\tfetcher.submit(body, {\n\t\t\tmethod: 'post',\n\t\t\tencType: 'application/json',\n\t\t\t...(to ? { action: to } : {}),\n\t\t});\n\treturn { fetcher, post, busy: fetcher.state !== 'idle' };\n}\n"
6
- ],
7
- "mappings": ";AAAA;AAcO,SAAS,eAAwD,CACvE,KACA,QAKC;AAAA,EACD,MAAM,UAAU,WAAmB,MAAM,EAAE,IAAI,IAAI,SAAS;AAAA,EAC5D,MAAM,OAAO,CAAC,MAAY,KAAK,WAC9B,QAAQ,OAAO,MAAM;AAAA,IACpB,QAAQ;AAAA,IACR,SAAS;AAAA,OACL,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;AAAA,EAC5B,CAAC;AAAA,EACF,OAAO,EAAE,SAAS,MAAM,MAAM,QAAQ,UAAU,OAAO;AAAA;",
8
- "debugId": "4A99F5857CB639C064756E2164756E21",
9
- "names": []
10
- }