@softistx/alxia-react-router 0.89.4 → 0.90.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 (51) hide show
  1. package/README.md +31 -2
  2. package/dist/chunks/{index-1nw5yeek.js → index-qkyt0bka.js} +3 -3
  3. package/dist/chunks/{index-1nw5yeek.js.map → index-qkyt0bka.js.map} +1 -1
  4. package/dist/chunks/index-w61bjnkw.js +1019 -0
  5. package/dist/chunks/index-w61bjnkw.js.map +27 -0
  6. package/dist/clavix/api-url.d.ts +43 -0
  7. package/dist/clavix/api-url.d.ts.map +1 -0
  8. package/dist/clavix/client.d.ts +22 -0
  9. package/dist/clavix/client.d.ts.map +1 -0
  10. package/dist/clavix/core.d.ts +39 -0
  11. package/dist/clavix/core.d.ts.map +1 -0
  12. package/dist/clavix/env.d.ts +26 -0
  13. package/dist/clavix/env.d.ts.map +1 -0
  14. package/dist/clavix/index.d.ts +19 -0
  15. package/dist/clavix/index.d.ts.map +1 -0
  16. package/dist/clavix/index.js +673 -0
  17. package/dist/clavix/index.js.map +22 -0
  18. package/dist/clavix/landing.d.ts +67 -0
  19. package/dist/clavix/landing.d.ts.map +1 -0
  20. package/dist/clavix/messages.d.ts +53 -0
  21. package/dist/clavix/messages.d.ts.map +1 -0
  22. package/dist/clavix/notice.d.ts +32 -0
  23. package/dist/clavix/notice.d.ts.map +1 -0
  24. package/dist/clavix/refusal.d.ts +29 -0
  25. package/dist/clavix/refusal.d.ts.map +1 -0
  26. package/dist/clavix/relay.d.ts +41 -0
  27. package/dist/clavix/relay.d.ts.map +1 -0
  28. package/dist/clavix/routes.d.ts +5 -0
  29. package/dist/clavix/routes.d.ts.map +1 -0
  30. package/dist/clavix/send.d.ts +32 -0
  31. package/dist/clavix/send.d.ts.map +1 -0
  32. package/dist/clavix/state.d.ts +20 -0
  33. package/dist/clavix/state.d.ts.map +1 -0
  34. package/dist/clavix/types.d.ts +97 -0
  35. package/dist/clavix/types.d.ts.map +1 -0
  36. package/dist/clavix/viewer.d.ts +12 -0
  37. package/dist/clavix/viewer.d.ts.map +1 -0
  38. package/dist/fetcher/auth-refusal.d.ts +5 -1
  39. package/dist/fetcher/auth-refusal.d.ts.map +1 -1
  40. package/dist/fetcher/index.js +2 -5
  41. package/dist/fetcher/index.js.map +3 -3
  42. package/dist/oidc/index.js +23 -1025
  43. package/dist/oidc/index.js.map +3 -21
  44. package/dist/session/index.js +1 -1
  45. package/docs/README.md +2 -1
  46. package/docs/guide/clavix.md +332 -0
  47. package/docs/guide/fetcher.md +4 -0
  48. package/docs/guide/oidc.md +3 -0
  49. package/docs/roadmap.md +6 -0
  50. package/docs/troubleshooting.md +41 -0
  51. package/package.json +8 -2
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/clavix/api-url.ts", "../src/clavix/env.ts", "../src/clavix/core.ts", "../src/clavix/landing.ts", "../src/clavix/refusal.ts", "../src/clavix/notice.ts", "../src/clavix/relay.ts", "../src/clavix/routes.ts", "../src/clavix/state.ts", "../src/clavix/send.ts", "../src/clavix/viewer.ts", "../src/clavix/client.ts", "../src/clavix/messages.ts"],
4
+ "sourcesContent": [
5
+ "/** What sends a request: `fetch`'s shape. */\nexport type Send = (input: string, init?: RequestInit) => Promise<Response>;\n\n/** The API's public address and the one this server reaches it at. */\nexport interface ApiUrls {\n\t/** What a DPoP proof's `htu` names, such as `https://api.example.com`: no query, no fragment. */\n\treadonly publicUrl: string;\n\t/** What this server calls instead, such as `http://api:3000`. Omit it when the API is reached at its public address. */\n\treadonly internalUrl?: string | undefined;\n}\n\nconst trimmed = (value: string) => value.replace(/\\/+$/, '');\n\n/** Checks the two addresses once, at the factory: absolute `http(s)` URLs, no query or fragment. */\nexport function checkApiUrls(api: ApiUrls): {\n\tpublicBase: string;\n\tinternalBase: string;\n} {\n\tconst check = (name: string, value: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(value);\n\t\t} catch {\n\t\t\tthrow new TypeError(\n\t\t\t\t`clavixRoutes(): api.${name} is not an absolute URL.`,\n\t\t\t);\n\t\t}\n\t\tif (!/^https?:$/.test(url.protocol) || url.search || url.hash) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`clavixRoutes(): api.${name} must be an http(s) URL with no query or fragment.`,\n\t\t\t);\n\t\t}\n\t\treturn trimmed(value);\n\t};\n\tconst publicBase = check('publicUrl', api.publicUrl);\n\treturn {\n\t\tpublicBase,\n\t\tinternalBase:\n\t\t\tapi.internalUrl === undefined\n\t\t\t\t? publicBase\n\t\t\t\t: check('internalUrl', api.internalUrl),\n\t};\n}\n\nconst startsAt = (url: string, base: string) =>\n\turl === base || url.startsWith(`${base}/`) || url.startsWith(`${base}?`);\n\n/**\n * A `fetch` that connects a call addressed to the API's public address to its\n * internal one: a proof is signed for the public URL (the one the API checks\n * `htu` against) while this server reaches the API at the internal one. Every\n * other URL (the issuer's endpoints) goes through `base` unchanged.\n */\nexport function rewritingFetch(\n\tbase: Send,\n\tpublicUrl: string,\n\tinternalUrl: string,\n): Send {\n\tconst from = trimmed(publicUrl);\n\tconst to = trimmed(internalUrl);\n\tif (from === to) return base;\n\treturn (input, init) =>\n\t\tstartsAt(input, from)\n\t\t\t? base(`${to}${input.slice(from.length)}`, init)\n\t\t\t: base(input, init);\n}\n\n/** The URL a proof names for a call made to the internal address: the public address in its place. */\nexport function publicUrlOf(\n\turl: string,\n\tinternalUrl: string,\n\tpublicUrl: string,\n): string {\n\tconst from = trimmed(internalUrl);\n\treturn startsAt(url, from)\n\t\t? `${trimmed(publicUrl)}${url.slice(from.length)}`\n\t\t: url;\n}\n\n/** A call to an address that is neither the API's public nor its internal one: no DPoP-bound token goes there. */\nexport class ClavixOriginError extends Error {\n\toverride readonly name = 'ClavixOriginError';\n\tconstructor(origin: string) {\n\t\tsuper(\n\t\t\t`clavixRoutes(): refusing to sign a call to ${origin}: it is not api.publicUrl or api.internalUrl.`,\n\t\t);\n\t}\n}\n\n/**\n * Whether `url` is under one of the API's two addresses: the same origin\n * (scheme, host and port, parsed, so a lookalike host or a `user@host` trick\n * does not match), no credentials, and a path inside the address's own path.\n */\nexport function isApiUrl(\n\turl: string,\n\turls: { readonly publicBase: string; readonly internalBase: string },\n): boolean {\n\tlet target: URL;\n\ttry {\n\t\ttarget = new URL(url);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (target.username || target.password) return false;\n\treturn [urls.publicBase, urls.internalBase].some((base) => {\n\t\tconst root = new URL(base);\n\t\tconst prefix = root.pathname.replace(/\\/+$/, '');\n\t\treturn (\n\t\t\ttarget.origin === root.origin &&\n\t\t\t(prefix === '' ||\n\t\t\t\ttarget.pathname === prefix ||\n\t\t\t\ttarget.pathname.startsWith(`${prefix}/`))\n\t\t);\n\t});\n}\n\n/** Throws {@link ClavixOriginError} unless `url` is under the API's addresses. */\nexport function assertApiUrl(\n\turl: string,\n\turls: { readonly publicBase: string; readonly internalBase: string },\n): void {\n\tif (isApiUrl(url, urls)) return;\n\tlet origin = 'an invalid URL';\n\ttry {\n\t\torigin = new URL(url).origin;\n\t} catch {}\n\tthrow new ClavixOriginError(origin);\n}\n",
6
+ "import {\n\tOidcEnvError,\n\ttype OidcEnvOptions,\n\ttype OidcEnvSource,\n\toidcFromEnv,\n} from '../oidc';\n\n/** The issuer's settings, checked, with the extras Clavix adds. */\nexport interface ClavixSettings extends OidcEnvOptions {\n\t/** `CLAVIX_AUDIENCE`: the resource (RFC 8707) the access token is for, when it is not the API's GraphQL URL. */\n\treadonly audience: string | undefined;\n}\n\n/** Where the registered addresses default to. */\nexport interface ClavixDefaults {\n\treadonly appOrigin: string | undefined;\n\treadonly callbackPath: string;\n\treadonly signInPath: string;\n}\n\n/**\n * The `CLAVIX_*` variables with their defaults applied: the cookie name\n * `clavix`, and the registered addresses from the app's origin.\n */\nexport function withDefaults(\n\tenv: Readonly<Record<string, string | undefined>>,\n\t{ appOrigin, callbackPath, signInPath }: ClavixDefaults,\n): Record<string, string | undefined> {\n\tconst origin = appOrigin?.replace(/\\/+$/, '');\n\treturn {\n\t\t...env,\n\t\tCLAVIX_COOKIE_NAME: env['CLAVIX_COOKIE_NAME'] || 'clavix',\n\t\tCLAVIX_REDIRECT_URI:\n\t\t\tenv['CLAVIX_REDIRECT_URI'] ||\n\t\t\t(origin ? `${origin}${callbackPath}` : undefined),\n\t\tCLAVIX_POST_LOGOUT_REDIRECT_URI:\n\t\t\tenv['CLAVIX_POST_LOGOUT_REDIRECT_URI'] ||\n\t\t\t(origin ? `${origin}${signInPath}` : undefined),\n\t};\n}\n\n/**\n * Reads and checks `CLAVIX_*` once: every missing or malformed variable is\n * listed in one `OidcEnvError`, never a value. A secret goes in a `_FILE`\n * variable (mode 0600).\n */\nexport async function readSettings(\n\tsource: Omit<OidcEnvSource, 'prefix'> & {\n\t\treadonly env: Readonly<Record<string, string | undefined>>;\n\t},\n): Promise<ClavixSettings> {\n\tconst problems: string[] = [];\n\tlet base: OidcEnvOptions | undefined;\n\ttry {\n\t\tbase = await oidcFromEnv({ ...source, prefix: 'CLAVIX' });\n\t} catch (error) {\n\t\tif (!(error instanceof OidcEnvError)) throw error;\n\t\tproblems.push(...error.problems);\n\t}\n\tconst audience = source.env['CLAVIX_AUDIENCE']?.trim() || undefined;\n\tif (audience !== undefined) {\n\t\ttry {\n\t\t\tnew URL(audience);\n\t\t} catch {\n\t\t\tproblems.push('CLAVIX_AUDIENCE is not an absolute URL.');\n\t\t}\n\t}\n\tif (problems.length > 0 || base === undefined)\n\t\tthrow new OidcEnvError(problems);\n\treturn { ...base, audience };\n}\n",
7
+ "import { type OidcClient, oidcClient } from '../oidc';\nimport { hasCookie, serializeCookie } from '../session/serialize';\nimport { checkApiUrls, rewritingFetch, type Send } from './api-url';\nimport { type ClavixSettings, readSettings, withDefaults } from './env';\nimport type { ClavixRoutesOptions } from './types';\n\ninterface Built {\n\treadonly client: OidcClient;\n\treadonly settings: ClavixSettings;\n}\n\n/** The relying party of {@link clavixRoutes}, built on first use, and what every part shares. */\nexport function clavixCore(options: ClavixRoutesOptions) {\n\tconst urls = checkApiUrls(options.api);\n\tconst graphqlPath = options.api.graphqlPath ?? '/graphql';\n\tconst paths = {\n\t\tstart: options.paths?.start ?? '/auth/clavix',\n\t\tcallback: options.paths?.callback ?? '/auth/clavix/callback',\n\t\tsignIn: options.paths?.signIn ?? '/sign-in',\n\t};\n\tconst origin = () =>\n\t\ttypeof options.appOrigin === 'function'\n\t\t\t? options.appOrigin()\n\t\t\t: options.appOrigin;\n\tconst transport: Send = (input, init) =>\n\t\t(options.fetch ?? fetch)(input, init);\n\tconst log = options.log ?? console;\n\n\tconst build = async (): Promise<Built> => {\n\t\tconst settings = await readSettings({\n\t\t\tenv: withDefaults(options.env ?? process.env, {\n\t\t\t\tappOrigin: origin(),\n\t\t\t\tcallbackPath: paths.callback,\n\t\t\t\tsignInPath: paths.signIn,\n\t\t\t}),\n\t\t\treadFile: options.readFile,\n\t\t\tstatFile: options.statFile,\n\t\t});\n\t\tconst resource = settings.audience ?? `${urls.publicBase}${graphqlPath}`;\n\t\tconst client = oidcClient({\n\t\t\t...settings,\n\t\t\tsecure: options.secure,\n\t\t\tscopes: ['profile', 'email', ...(options.scopes ?? []), 'offline_access'],\n\t\t\t// The access token is for the API, whose public GraphQL URL is the resource (RFC 8707).\n\t\t\ttokenParams: { resource },\n\t\t\tauthorizationParams: { resource },\n\t\t\tpar: 'always',\n\t\t\tdpop: {},\n\t\t\trevokeOnLogout: true,\n\t\t\tfetch: rewritingFetch(transport, urls.publicBase, urls.internalBase),\n\t\t\tsignInPath: paths.signIn,\n\t\t\tonRevokeError:\n\t\t\t\toptions.onRevokeError ??\n\t\t\t\t((error) => log.warn(`clavix: revocation failed (${error.code})`)),\n\t\t});\n\t\treturn { client, settings };\n\t};\n\tlet built: Promise<Built> | undefined;\n\t/** Reads the environment once; a failure is not cached, so a fixed environment is read again. */\n\tconst core = (): Promise<Built> => {\n\t\tbuilt ??= build().catch((error) => {\n\t\t\tbuilt = undefined;\n\t\t\tthrow error;\n\t\t});\n\t\treturn built;\n\t};\n\tconst oidc = async () => (await core()).client;\n\tconst secure = options.secure;\n\n\treturn {\n\t\turls,\n\t\tgraphqlPath,\n\t\tpaths,\n\t\torigin,\n\t\tlog,\n\t\tsecure,\n\t\tcore,\n\t\toidc,\n\t\t/** The `Set-Cookie` that ends the sealed token cookie. */\n\t\tasync clearCookie() {\n\t\t\treturn serializeCookie((await oidc()).names.session, '', {\n\t\t\t\tmaxAge: 0,\n\t\t\t\tsecure,\n\t\t\t});\n\t\t},\n\t\tasync hasSession(request: Request) {\n\t\t\treturn hasCookie(request, (await oidc()).names.session);\n\t\t},\n\t\t/** The cookie sign-out sets, since the end-session redirect cannot carry a query. */\n\t\tasync signedOutName() {\n\t\t\tconst { settings } = await core();\n\t\t\treturn `${secure ? '__Host-' : ''}${settings.name}_signed_out`;\n\t\t},\n\t\t/** The routes' view of the relying party: each call builds it first. */\n\t\tlazy: {\n\t\t\tcallback: async (request: Request) => (await oidc()).callback(request),\n\t\t\tlogout: async (request: Request) => (await oidc()).logout(request),\n\t\t\tsignIn: async (request: Request) => (await oidc()).signIn(request),\n\t\t},\n\t};\n}\n\nexport type ClavixCore = ReturnType<typeof clavixCore>;\n",
8
+ "import { redirect, redirectDocument } from 'react-router';\nimport { nextOf } from '../errors/page-path';\nimport { safeNext } from '../session/model/safe-next';\nimport { CLAVIX_PARAMS, type ClavixNotice, clavixNoticeOf } from './notice';\n\n/** What the sign-in loader gives the page. */\nexport interface ClavixLanding {\n\t/** The `Set-Cookie` the page's answer must carry (a dead session cookie cleared). Pass it as the loader's `headers`. */\n\treadonly headers: Headers;\n\t/** What the page has to say, `null` for none. */\n\treadonly notice: ClavixNotice | null;\n\t/** The link of the sign-in button: a GET on the start route, `next` kept (a GET, since a CSP `form-action` may refuse a form post to the issuer). */\n\treadonly startHref: string;\n\t/** Where the visitor goes after signing in: a path of this site. */\n\treadonly next: string;\n\t/** The issuer's own sign-out, for the « also sign out of Clavix » link; `null` unless the notice is `signed-out`. */\n\treadonly endSessionUrl: string | null;\n}\n\n/** Options of `landing`. */\nexport interface LandingOptions {\n\t/** The app also offers another way to sign in (a password, a mailed link): the page always shows, with the Clavix button beside it. `false` by default: provider-only. */\n\treadonly otherMethods?: boolean | undefined;\n\t/** Query parameters of the app's own that also keep the page (a spent link, an accepted invitation). */\n\treadonly speakingParams?: readonly string[] | undefined;\n}\n\n/** The link that starts a sign-in, `next` kept. */\nexport const startHrefOf = (startPath: string, next: string | null): string =>\n\tnext && next !== '/'\n\t\t? `${startPath}?${new URLSearchParams({ next })}`\n\t\t: startPath;\n\n/** The inputs `landing` is built over. */\nexport interface LandingContext {\n\treadonly paths: { readonly start: string; readonly signIn: string };\n\treadonly signedOut: {\n\t\treadonly was: (request: Request) => boolean;\n\t\treadonly clear: () => string;\n\t};\n\t/** The issuer's `end-session` address for the signed-out page. */\n\treadonly endSessionUrl: () => Promise<string | null>;\n\t/** The request's session state: the cookie, and whether it opens. */\n\treadonly session: (request: Request) => Promise<{\n\t\treadonly has: boolean;\n\t\treadonly live: boolean;\n\t\treadonly cookies: readonly string[];\n\t}>;\n\treadonly clearCookie: () => Promise<string>;\n}\n\n/**\n * The sign-in page's loader decision, for a visitor with the app's provider\n * as its way in:\n *\n * - a signed-in visitor goes to `next`;\n * - a dead session cookie (its refresh token is gone) is cleared, so `/` stops\n * sending the visitor back;\n * - the signed-out cookie (set by sign-out, since the end-session redirect\n * cannot carry a query) turns into `?signed-out=1`, so a reload keeps the page\n * instead of sending the visitor to the issuer, whose single sign-on would sign\n * them straight back in;\n * - with nothing to say and no other method, a document redirect to the start\n * route: no page with a lone button is shown.\n */\nexport async function landingOf(\n\tcontext: LandingContext,\n\trequest: Request,\n\toptions: LandingOptions = {},\n): Promise<ClavixLanding> {\n\tconst url = new URL(request.url);\n\tconst params = url.searchParams;\n\tconst next = safeNext(params.get('next') ?? undefined);\n\tconst state = await context.session(request);\n\tconst headers = new Headers();\n\tif (state.live) {\n\t\tconst target = new Headers();\n\t\tfor (const cookie of state.cookies) target.append('Set-Cookie', cookie);\n\t\tthrow redirect(next, { headers: target });\n\t}\n\tif (state.has) headers.append('Set-Cookie', await context.clearCookie());\n\tif (context.signedOut.was(request)) {\n\t\theaders.append('Set-Cookie', context.signedOut.clear());\n\t\tconst query = new URLSearchParams({ [CLAVIX_PARAMS.signedOut]: '1' });\n\t\tif (params.has('next')) query.set('next', next);\n\t\tthrow redirect(`${context.paths.signIn}?${query}`, { headers });\n\t}\n\tconst notice = clavixNoticeOf(params);\n\tconst startHref = startHrefOf(\n\t\tcontext.paths.start,\n\t\tparams.has('next') ? next : null,\n\t);\n\tconst speaks =\n\t\tnotice !== null ||\n\t\toptions.otherMethods === true ||\n\t\t(options.speakingParams ?? []).some((name) => params.has(name));\n\tif (!speaks) throw redirectDocument(startHref, { headers });\n\treturn {\n\t\theaders,\n\t\tnotice,\n\t\tstartHref,\n\t\tnext,\n\t\tendSessionUrl:\n\t\t\tnotice?.kind === 'signed-out' ? await context.endSessionUrl() : null,\n\t};\n}\n\n/** What the request of a page with no session gets for an ended one: a redirect to sign-in for a GET or HEAD, a 401 JSON `session-expired` otherwise. */\nexport function expiredAnswerOf(\n\tsignInPath: string,\n\trequest: Request,\n): Response {\n\tif (request.method === 'GET' || request.method === 'HEAD') {\n\t\tconst query = new URLSearchParams({\n\t\t\tnext: safeNext(nextOf(request.url)),\n\t\t\t[CLAVIX_PARAMS.expired]: '1',\n\t\t});\n\t\treturn redirect(`${signInPath}?${query}`);\n\t}\n\treturn Response.json({ code: 'session-expired' }, { status: 401 });\n}\n\n/** The issuer's `end-session` address for the signed-out page. With no `id_token_hint` (the tokens are gone), Clavix shows its own confirmation page before it ends anything. */\nexport function endSessionUrlOf(settings: {\n\treadonly issuer: string;\n\treadonly clientId: string;\n\treadonly postLogoutRedirectUri?: string | undefined;\n}): string {\n\tconst url = new URL(`${settings.issuer.replace(/\\/+$/, '')}/end-session`);\n\turl.searchParams.set('client_id', settings.clientId);\n\tif (settings.postLogoutRedirectUri) {\n\t\turl.searchParams.set(\n\t\t\t'post_logout_redirect_uri',\n\t\t\tsettings.postLogoutRedirectUri,\n\t\t);\n\t}\n\treturn url.toString();\n}\n",
9
+ "import type { OidcErrorCode } from '../oidc';\n\n/** What a refused sign-in stands for: a bounded set, so a crafted URL shows no free text. */\nexport type ClavixRefusal =\n\t| 'cancelled'\n\t| 'suspended'\n\t| 'expired'\n\t| 'down'\n\t| 'provider'\n\t| 'generic';\n\n/** The refusals, in the order the catalogue lists them. */\nexport const CLAVIX_REFUSALS: readonly ClavixRefusal[] = [\n\t'cancelled',\n\t'suspended',\n\t'expired',\n\t'down',\n\t'provider',\n\t'generic',\n];\n\n/**\n * The kind of sentence an `OidcError` stands for. The issuer's `access_denied`\n * is a visitor who backed out (`cancelled`), unless its description says the\n * account or tenant is suspended; a spent or lost challenge is `expired`;\n * the issuer not answering (discovery, PAR, the token endpoint) is `down`;\n * any other `error` it sends is `provider`; the rest (a state, issuer or\n * token that does not check out) is `generic`.\n */\nexport function clavixRefusalOf(\n\tcode: OidcErrorCode,\n\tmessage: string,\n): ClavixRefusal {\n\tswitch (code) {\n\t\tcase 'provider-error':\n\t\t\tif (/suspend|disabled|inactive|deactivat/i.test(message)) {\n\t\t\t\treturn 'suspended';\n\t\t\t}\n\t\t\treturn /access_denied/i.test(message) ? 'cancelled' : 'provider';\n\t\tcase 'challenge-expired':\n\t\tcase 'missing-challenge':\n\t\t\treturn 'expired';\n\t\tcase 'discovery-failed':\n\t\tcase 'par-failed':\n\t\tcase 'token-exchange-failed':\n\t\t\treturn 'down';\n\t\tdefault:\n\t\t\treturn 'generic';\n\t}\n}\n\n/**\n * Whether the visitor cannot fix a refusal by trying again, so the support\n * needs its reference. A cancel, an expired challenge or a service that is\n * down are theirs to retry: no reference.\n */\nexport const needsReference = (kind: ClavixRefusal): boolean =>\n\tkind === 'suspended' || kind === 'provider' || kind === 'generic';\n\n/** Eight random bytes by default; a test passes its own. */\nconst randomBytes = (count: number) =>\n\tcrypto.getRandomValues(new Uint8Array(count));\n\n/**\n * A short code (`K7QM-2XPD`) the visitor can quote to the support: the\n * server's log holds it beside the refusal. No ambiguous character (no `0`,\n * `O`, `1`, `I`).\n */\nexport function supportReference(\n\tbytes: (count: number) => Uint8Array = randomBytes,\n): string {\n\t// 32 characters: the low five bits of a byte pick one, with no bias.\n\tconst alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';\n\tlet out = '';\n\tfor (const byte of bytes(8)) out += alphabet[byte & 31];\n\treturn `${out.slice(0, 4)}-${out.slice(4)}`;\n}\n\n/** A reference as {@link supportReference} makes it. */\nexport const isSupportReference = (value: string | null): value is string =>\n\tvalue !== null && /^[A-Z0-9]{4}-[A-Z0-9]{4}$/.test(value);\n",
10
+ "import {\n\tCLAVIX_REFUSALS,\n\ttype ClavixRefusal,\n\tisSupportReference,\n} from './refusal';\n\n/** The query parameters the routes put on the sign-in page. */\nexport const CLAVIX_PARAMS = {\n\t/** A refused sign-in: a {@link ClavixRefusal}. */\n\terror: 'clavix-error',\n\t/** The support reference of a refusal. */\n\treference: 'ref',\n\t/** The visitor just signed out. */\n\tsignedOut: 'signed-out',\n\t/** The session ended and could not be refreshed. */\n\texpired: 'expired',\n} as const;\n\n/** What the sign-in page has to say. */\nexport type ClavixNotice =\n\t| { readonly kind: 'signed-out' }\n\t| { readonly kind: 'session-expired' }\n\t| {\n\t\t\treadonly kind: ClavixRefusal;\n\t\t\t/** The code to quote to the support; `null` for a refusal the visitor can retry. */\n\t\t\treadonly reference: string | null;\n\t };\n\n/** How loud a notice is: the tone of its alert. */\nexport type ClavixTone = 'error' | 'warning' | 'info';\n\n/** The tone of a notice. A refusal the visitor caused or can retry is not an error. */\nexport function clavixToneOf(notice: ClavixNotice): ClavixTone {\n\tswitch (notice.kind) {\n\t\tcase 'signed-out':\n\t\tcase 'cancelled':\n\t\tcase 'expired':\n\t\t\treturn 'info';\n\t\tcase 'session-expired':\n\t\tcase 'down':\n\t\t\treturn 'warning';\n\t\tdefault:\n\t\t\treturn 'error';\n\t}\n}\n\n/**\n * The notice a sign-in URL asks for, or `null`. Only the bounded set is read: a\n * refusal outside it, or a reference of another shape, is dropped.\n */\nexport function clavixNoticeOf(params: URLSearchParams): ClavixNotice | null {\n\tconst error = params.get(CLAVIX_PARAMS.error);\n\tconst refusal = CLAVIX_REFUSALS.find((kind) => kind === error);\n\tif (refusal) {\n\t\tconst reference = params.get(CLAVIX_PARAMS.reference);\n\t\treturn {\n\t\t\tkind: refusal,\n\t\t\treference: isSupportReference(reference) ? reference : null,\n\t\t};\n\t}\n\tif (params.has(CLAVIX_PARAMS.signedOut)) return { kind: 'signed-out' };\n\tif (params.has(CLAVIX_PARAMS.expired)) return { kind: 'session-expired' };\n\treturn null;\n}\n",
11
+ "import type { OidcUser } from '../oidc';\nimport { assertApiUrl, publicUrlOf } from './api-url';\n\n/** What a relay (`/media`, `/live`) needs of the session. */\ninterface Session {\n\thasSession(request: Request): Promise<boolean>;\n\tlatestOf(request: Request): Promise<OidcUser | null>;\n}\n\n/** The requests a relay built once for every call (`/live`) took a token for, under a SHA-256 of the token. */\nconst tokenKey = (token: string) =>\n\tnew Bun.CryptoHasher('sha256').update(token).digest('hex');\n\nconst bearerOf = (request: Request) =>\n\t/^Bearer (.+)$/i.exec(request.headers.get('authorization') ?? '')?.[1];\n\n/**\n * The relays' side of the session. The relay libraries put the access token in\n * `Authorization: Bearer`; `fetch` turns that into `DPoP` and a proof for the\n * API's public URL.\n */\nexport function relays(\n\tsession: Session,\n\turls: { readonly publicBase: string; readonly internalBase: string },\n) {\n\tconst live = new Map<string, Set<Request>>();\n\tconst liveKeys = new WeakMap<Request, string>();\n\n\tasync function tokenOf(request: Request): Promise<string | null> {\n\t\tif (!(await session.hasSession(request))) return null;\n\t\treturn (await session.latestOf(request))?.accessToken ?? null;\n\t}\n\n\treturn {\n\t\t/** The access token a relay sends upstream, `null` without a session. */\n\t\ttokenOf,\n\t\t/**\n\t\t * `tokenOf` for a relay built once for every call (`/live`): its `fetch` is\n\t\t * not given the request, so this remembers it (under the token's hash, never\n\t\t * the token) for `fetch` to find the user to sign with. Pair it with `forget`.\n\t\t */\n\t\tasync liveTokenOf(request: Request): Promise<string | null> {\n\t\t\tconst token = await tokenOf(request);\n\t\t\tif (!token) return null;\n\t\t\tconst key = tokenKey(token);\n\t\t\tconst sources = live.get(key) ?? new Set<Request>();\n\t\t\tsources.add(request);\n\t\t\tlive.set(key, sources);\n\t\t\tliveKeys.set(request, key);\n\t\t\treturn token;\n\t\t},\n\t\t/** Drops what `liveTokenOf` kept: the relay answered (its stream is open, or it failed). */\n\t\tforget(request: Request): void {\n\t\t\tconst key = liveKeys.get(request);\n\t\t\tif (!key) return;\n\t\t\tliveKeys.delete(request);\n\t\t\tconst sources = live.get(key);\n\t\t\tsources?.delete(request);\n\t\t\tif (sources?.size === 0) live.delete(key);\n\t\t},\n\t\t/**\n\t\t * The relays' `fetch`: the bearer token they set becomes `Authorization:\n\t\t * DPoP` with a proof for the API's public URL. `source` is the incoming\n\t\t * request (the media relays build their options per request); without it\n\t\t * the user is found through `liveTokenOf`. A call whose user is not found\n\t\t * is answered 401, never forwarded with a bare bearer token. A\n\t\t * `use_dpop_nonce` answer is signed again and sent once more when the call\n\t\t * has no body to replay; one with a body (an upload) is not retried, since a\n\t\t * stream cannot be sent twice.\n\t\t */\n\t\tfetch(upstream: (request: Request) => Promise<Response>, source?: Request) {\n\t\t\treturn async (request: Request): Promise<Response> => {\n\t\t\t\tassertApiUrl(request.url, urls);\n\t\t\t\tconst token = bearerOf(request);\n\t\t\t\tconst from =\n\t\t\t\t\tsource ??\n\t\t\t\t\t(token\n\t\t\t\t\t\t? live.get(tokenKey(token))?.values().next().value\n\t\t\t\t\t\t: undefined);\n\t\t\t\tconst dpop = from ? (await session.latestOf(from))?.dpop : undefined;\n\t\t\t\tif (!token || !dpop) return new Response(null, { status: 401 });\n\t\t\t\tconst url = publicUrlOf(\n\t\t\t\t\trequest.url,\n\t\t\t\t\turls.internalBase,\n\t\t\t\t\turls.publicBase,\n\t\t\t\t);\n\t\t\t\tconst retry =\n\t\t\t\t\trequest.body === null\n\t\t\t\t\t\t? new Request(request, { redirect: 'manual' })\n\t\t\t\t\t\t: null;\n\t\t\t\tconst sign = async (target: Request, nonce?: string) => {\n\t\t\t\t\tconst { authorization, dpop: proof } = await dpop.headers({\n\t\t\t\t\t\tmethod: target.method,\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tnonce,\n\t\t\t\t\t});\n\t\t\t\t\ttarget.headers.set('authorization', authorization);\n\t\t\t\t\ttarget.headers.set('dpop', proof);\n\t\t\t\t};\n\t\t\t\t// The upstream never follows a redirect: it would carry the proof elsewhere.\n\t\t\t\tconst signed = new Request(request, { redirect: 'manual' });\n\t\t\t\tawait sign(signed);\n\t\t\t\tconst response = await upstream(signed);\n\t\t\t\tconst nonce = response.headers.get('dpop-nonce');\n\t\t\t\tif (response.status === 401 && nonce && retry) {\n\t\t\t\t\tawait sign(retry, nonce);\n\t\t\t\t\treturn upstream(retry);\n\t\t\t\t}\n\t\t\t\treturn response;\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** What {@link relays} gives: the relay side of the session. */\nexport type ClavixRelay = ReturnType<typeof relays>;\n",
12
+ "import { redirect } from 'react-router';\nimport { callbackRoute, type OidcError, signOutRoute } from '../oidc';\nimport { serializeCookie } from '../session/serialize';\nimport type { ClavixCore } from './core';\nimport { CLAVIX_PARAMS } from './notice';\nimport { clavixRefusalOf, needsReference, supportReference } from './refusal';\nimport { appendSetCookies } from './state';\nimport type { ClavixRoutes } from './types';\n\n/** The callback's answer to a refusal: logged under a reference, then the sign-in page with the kind. */\nconst refusal =\n\t(c: ClavixCore) =>\n\t(error: OidcError): Response => {\n\t\tconst reference = supportReference();\n\t\tc.log.warn(\n\t\t\t`clavix sign-in refused [${reference}] ${error.code}: ${error.message}`,\n\t\t);\n\t\tconst kind = clavixRefusalOf(error.code, error.message);\n\t\t// Logged for every refusal; shown only when the visitor cannot fix it alone.\n\t\tconst query = new URLSearchParams({ [CLAVIX_PARAMS.error]: kind });\n\t\tif (needsReference(kind)) query.set(CLAVIX_PARAMS.reference, reference);\n\t\treturn redirect(`${c.paths.signIn}?${query}`, { headers: error.headers });\n\t};\n\n/** The three route modules of {@link clavixRoutes}. */\nexport function routeModules(c: ClavixCore): ClavixRoutes['routes'] {\n\tconst callback = callbackRoute(c.lazy, { onError: refusal(c) });\n\tconst signOut = signOutRoute(c.lazy, { origin: c.origin });\n\treturn {\n\t\tstart: {\n\t\t\tasync loader({ request }) {\n\t\t\t\tawait c.core();\n\t\t\t\treturn c.lazy.signIn(request);\n\t\t\t},\n\t\t},\n\t\tcallback: {\n\t\t\tasync loader({ request }) {\n\t\t\t\tawait c.core();\n\t\t\t\treturn callback.loader({ request });\n\t\t\t},\n\t\t},\n\t\tsignOut: {\n\t\t\t/**\n\t\t\t * Ends the session at once: the tokens are revoked (a slow revocation never\n\t\t\t * holds it), the cookie goes, and the browser leaves for the issuer's\n\t\t\t * `end-session` with the id token as hint, which returns to the sign-in page,\n\t\t\t * where a notice says so.\n\t\t\t */\n\t\t\tasync action({ request }) {\n\t\t\t\tawait c.core();\n\t\t\t\tconst response = await signOut.action({ request });\n\t\t\t\tconst name = await c.signedOutName();\n\t\t\t\treturn appendSetCookies(response, [\n\t\t\t\t\tserializeCookie(name, '1', { maxAge: 120, secure: c.secure }),\n\t\t\t\t]);\n\t\t\t},\n\t\t\tasync loader({ request }) {\n\t\t\t\tawait c.core();\n\t\t\t\treturn signOut.loader({ request });\n\t\t\t},\n\t\t},\n\t};\n}\n",
13
+ "import type { OidcClient, OidcUser } from '../oidc';\n\n/** What a request holds while it runs: the user read from its cookie, and the newest one after a refresh. */\nexport interface RequestState {\n\tuser: OidcUser | null;\n\tlatest: OidcUser | null;\n}\n\n/** The request-scoped reads of the session, over one relying party. */\nexport function requestStates(oidc: () => Promise<OidcClient>) {\n\tconst states = new WeakMap<Request, Promise<RequestState>>();\n\treturn {\n\t\t/** The signed-in user of the request, read once per request. `null` without a cookie, or when a refresh failed on an ended access token. */\n\t\tof(request: Request): Promise<RequestState> {\n\t\t\tlet state = states.get(request);\n\t\t\tif (!state) {\n\t\t\t\tstate = oidc()\n\t\t\t\t\t.then((client) => client.oidcUser(request))\n\t\t\t\t\t.then((user) => ({ user, latest: user }));\n\t\t\t\tstates.set(request, state);\n\t\t\t}\n\t\t\treturn state;\n\t\t},\n\t\t/** The `Set-Cookie` of a rotation this request made, `[]` when the cookie it came with is current. */\n\t\tasync refreshed(request: Request): Promise<string[]> {\n\t\t\tconst state = states.get(request);\n\t\t\tif (!state) return [];\n\t\t\tconst { user, latest } = await state;\n\t\t\treturn latest && latest !== user ? latest.headers.getSetCookie() : [];\n\t\t},\n\t};\n}\n\n/**\n * The response with `cookies` added to its `Set-Cookie`. A Response made by\n * `fetch` or `redirect()` may have immutable headers, so a new one is built\n * from it; the same response when there is nothing to add.\n */\nexport function appendSetCookies(\n\tresponse: Response,\n\tcookies: Iterable<string>,\n): Response {\n\tconst added = [...cookies];\n\tif (added.length === 0) return response;\n\tconst headers = new Headers(response.headers);\n\tfor (const cookie of added) headers.append('Set-Cookie', cookie);\n\treturn new Response(response.body, {\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t\theaders,\n\t});\n}\n",
14
+ "import { dpopFetch, type OidcClient, OidcError, type OidcUser } from '../oidc';\nimport { assertApiUrl, type Send } from './api-url';\nimport type { RequestState } from './state';\n\n/**\n * The session ended and cannot be refreshed: the visitor signs in again.\n * `answer` is what the request gets for it (a redirect to sign-in for a GET, a\n * 401 `session-expired` otherwise); throw it where a GraphQL client would turn\n * any error from `fetch` into a 503, and answer `answer` from the route.\n */\nexport class SessionExpired extends Error {\n\toverride readonly name = 'SessionExpired';\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly answer: Response,\n\t) {\n\t\tsuper(message);\n\t\texpiredAnswers.add(answer);\n\t}\n}\n\nconst expiredAnswers = new WeakSet<object>();\n\n/** The ending a request met, whatever a client did with the error it was thrown through. */\nconst endings = new WeakMap<Request, SessionExpired>();\n\n/** The `SessionExpired` the calls of `request` met, if any. */\nexport const endedOf = (request: Request): SessionExpired | undefined =>\n\tendings.get(request);\n\n/** Whether a thrown value is the answer of an ended session (what a route may rethrow for a `SessionExpired`). */\nexport const isExpiredAnswer = (value: unknown): value is Response =>\n\ttypeof value === 'object' && value !== null && expiredAnswers.has(value);\n\n/**\n * A `fetch` for the calls of one request to the API, as the signed-in user:\n * `Authorization: DPoP` and a proof for the URL given (the public one), the\n * nonce retry, a refresh before the token ends, and, on a 401 that remains,\n * one forced refresh and one retry. A refresh that fails throws\n * `SessionExpired` carrying `expired()`. Any other answer (a 503 included) is\n * returned as it is: an unreachable API is never a sign-out. A URL outside\n * the API's two addresses throws `ClavixOriginError` before anything is signed.\n */\nexport function sender(\n\toidc: () => Promise<OidcClient>,\n\tstateOf: (request: Request) => Promise<RequestState>,\n\trequest: Request,\n\texpired: () => Response,\n\turls: { readonly publicBase: string; readonly internalBase: string },\n): Send {\n\tconst ended = (reason: string) => {\n\t\tconst error = new SessionExpired(reason, expired());\n\t\tendings.set(request, error);\n\t\treturn error;\n\t};\n\treturn async (input, init) => {\n\t\t// A DPoP-bound token is only ever signed for the API's own addresses.\n\t\tassertApiUrl(input, urls);\n\t\tconst client = await oidc();\n\t\tconst state = await stateOf(request);\n\t\tif (!state.latest) throw ended('no session');\n\t\tconst attempt = (user: OidcUser) =>\n\t\t\tdpopFetch(client, user, {\n\t\t\t\tonUser: (next) => {\n\t\t\t\t\tstate.latest = next;\n\t\t\t\t},\n\t\t\t\t// A redirect is never followed: it could carry the proof to another origin.\n\t\t\t})(input, { ...init, redirect: 'manual' });\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await attempt(state.latest);\n\t\t} catch (error) {\n\t\t\tif (error instanceof OidcError) throw ended(error.code);\n\t\t\tthrow error;\n\t\t}\n\t\tif (response.status !== 401) return response;\n\t\ttry {\n\t\t\tconst refreshed = await client.refresh(state.latest, { force: true });\n\t\t\t// A refresh that failed while the access token still looks valid gives the same user\n\t\t\t// back; the API just refused it, so that is an ended session too.\n\t\t\tif (refreshed === state.latest) throw ended('refresh-failed');\n\t\t\tstate.latest = refreshed;\n\t\t} catch (error) {\n\t\t\tif (error instanceof OidcError) throw ended(error.code);\n\t\t\tthrow error;\n\t\t}\n\t\treturn attempt(state.latest);\n\t};\n}\n",
15
+ "import type { Send } from './api-url';\nimport { endedOf, SessionExpired } from './send';\n\n/**\n * `viewer(request, load)`: the app's own `load(send)` (its GraphQL query for\n * the signed-in user) run once per request, so the middleware plumbing is not\n * the app's. No session cookie gives `null` without calling `load`. A session\n * that ended throws the request's answer (what a router turns into the\n * redirect to sign-in): both when `load` throws the `SessionExpired`, and when\n * a GraphQL client swallowed it into an error of its own or a `null`. The\n * answer is kept per request and per `load` function.\n */\nexport function viewers(\n\thasSession: (request: Request) => Promise<boolean>,\n\tsendOf: (request: Request) => Send,\n) {\n\t// Per request, then per `load`: another query on the same request is run.\n\tconst cache = new WeakMap<Request, WeakMap<object, Promise<unknown>>>();\n\treturn <T>(\n\t\trequest: Request,\n\t\tload: (send: Send) => Promise<T | null>,\n\t): Promise<T | null> => {\n\t\tconst loads = cache.get(request) ?? new WeakMap<object, Promise<unknown>>();\n\t\tcache.set(request, loads);\n\t\tconst hit = loads.get(load);\n\t\tif (hit) return hit as Promise<T | null>;\n\t\tconst run = (async () => {\n\t\t\tif (!(await hasSession(request))) return null;\n\t\t\tlet viewer: T | null;\n\t\t\ttry {\n\t\t\t\tviewer = await load(sendOf(request));\n\t\t\t} catch (error) {\n\t\t\t\tconst ended =\n\t\t\t\t\terror instanceof SessionExpired ? error : endedOf(request);\n\t\t\t\tif (ended) throw ended.answer;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst ended = endedOf(request);\n\t\t\tif (ended) throw ended.answer;\n\t\t\treturn viewer;\n\t\t})();\n\t\tloads.set(load, run);\n\t\t// A failure is not kept: the next read of the same request tries again.\n\t\trun.catch(() => loads.delete(load));\n\t\treturn run;\n\t};\n}\n",
16
+ "import { readCookie, serializeCookie } from '../session/serialize';\nimport { clavixCore } from './core';\nimport { endSessionUrlOf, expiredAnswerOf, landingOf } from './landing';\nimport { relays } from './relay';\nimport { routeModules } from './routes';\nimport { sender } from './send';\nimport { appendSetCookies, requestStates } from './state';\nimport type { ClavixRoutes, ClavixRoutesOptions } from './types';\nimport { viewers } from './viewer';\n\nexport type {\n\tArgs,\n\tClavixPaths,\n\tClavixRoutes,\n\tClavixRoutesOptions,\n} from './types';\n\n/**\n * A BFF that signs in with Clavix, provider-only by default: the routes, the\n * sign-in page's decision, the session helpers and the relays, over\n * `oidcClient` with PAR, PKCE and DPoP, tokens sealed in a `__Host-` cookie,\n * a refresh in one flight and a sign-out that revokes. The API is called at\n * its internal address while the proofs name its public one, and a call to any\n * other address is refused.\n *\n * @example\n * export const clavix = clavixRoutes({\n * secure: !import.meta.env.DEV,\n * api: { publicUrl: process.env.API_PUBLIC_URL!, internalUrl: process.env.API_URL },\n * appOrigin: process.env.APP_ORIGIN,\n * scopes: ['app:api'],\n * });\n * await clavix.ready();\n * // app/routes/auth.clavix.ts: export const { loader } = clavix.routes.start;\n */\nexport function clavixRoutes(options: ClavixRoutesOptions): ClavixRoutes {\n\tconst c = clavixCore(options);\n\tconst states = requestStates(c.oidc);\n\tconst expiredFor = (request: Request) =>\n\t\texpiredAnswerOf(c.paths.signIn, request);\n\tconst sendOf: ClavixRoutes['sendOf'] = (request, sendOptions) =>\n\t\tsender(\n\t\t\tc.oidc,\n\t\t\tstates.of,\n\t\t\trequest,\n\t\t\tsendOptions?.expired ?? (() => expiredFor(request)),\n\t\t\tc.urls,\n\t\t);\n\tconst relay = relays(\n\t\t{\n\t\t\thasSession: c.hasSession,\n\t\t\tlatestOf: async (request) => (await states.of(request)).latest,\n\t\t},\n\t\tc.urls,\n\t);\n\n\treturn {\n\t\tasync ready() {\n\t\t\tawait c.core();\n\t\t},\n\t\toidc: c.oidc,\n\t\tapiUrl: (path = c.graphqlPath) => `${c.urls.publicBase}${path}`,\n\t\troutes: routeModules(c),\n\t\tasync landing(request, landingOptions) {\n\t\t\tconst { settings } = await c.core();\n\t\t\tconst name = await c.signedOutName();\n\t\t\tconst clear = () =>\n\t\t\t\tserializeCookie(name, '', { maxAge: 0, secure: c.secure });\n\t\t\treturn landingOf(\n\t\t\t\t{\n\t\t\t\t\tpaths: c.paths,\n\t\t\t\t\tsignedOut: { was: (req) => readCookie(req, name) === '1', clear },\n\t\t\t\t\tclearCookie: c.clearCookie,\n\t\t\t\t\tendSessionUrl: async () => endSessionUrlOf(settings),\n\t\t\t\t\tsession: async (req) => {\n\t\t\t\t\t\tconst has = await c.hasSession(req);\n\t\t\t\t\t\tconst user = has ? (await states.of(req)).user : null;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\thas,\n\t\t\t\t\t\t\tlive: user !== null,\n\t\t\t\t\t\t\tcookies: user ? await states.refreshed(req) : [],\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequest,\n\t\t\t\tlandingOptions,\n\t\t\t);\n\t\t},\n\t\thasSession: c.hasSession,\n\t\tasync userOf(request) {\n\t\t\treturn (await states.of(request)).user;\n\t\t},\n\t\tsendOf,\n\t\tviewer: viewers(c.hasSession, (request) => sendOf(request)),\n\t\texpiredAnswer: expiredFor,\n\t\trefreshedCookies: (request) => states.refreshed(request),\n\t\tasync withRefreshedCookies(request, response) {\n\t\t\tif (!(await c.hasSession(request))) return response;\n\t\t\treturn appendSetCookies(response, await states.refreshed(request));\n\t\t},\n\t\tclearCookie: c.clearCookie,\n\t\trelay,\n\t};\n}\n",
17
+ "import type { ClavixNotice } from './notice';\n\n/** The words of the sign-in page's notices, for one language. */\nexport interface ClavixMessages {\n\treadonly 'signed-out': string;\n\treadonly 'session-expired': string;\n\treadonly cancelled: string;\n\treadonly suspended: string;\n\treadonly expired: string;\n\treadonly down: string;\n\treadonly provider: string;\n\treadonly generic: string;\n\t/** Before a support reference: `{reference}` is replaced. */\n\treadonly reference: string;\n\t/** The link that also ends the visitor's session at the identity provider. */\n\treadonly signOutOfProvider: string;\n\t/** The sign-in button. */\n\treadonly continue: string;\n}\n\n/** English and French. */\nexport const clavixMessages = {\n\ten: {\n\t\t'signed-out': 'You are signed out.',\n\t\t'session-expired': 'Your session ended. Sign in again to continue.',\n\t\tcancelled: 'The sign-in was cancelled. You can try again.',\n\t\tsuspended:\n\t\t\t'This account or organisation is suspended. Contact your administrator or the support.',\n\t\texpired: 'The sign-in took too long or was already used. Start again.',\n\t\tdown: 'The sign-in service did not answer. Try again in a moment.',\n\t\tprovider: 'The sign-in service refused the request.',\n\t\tgeneric: 'The sign-in could not be completed.',\n\t\treference: 'Reference to quote to the support: {reference}',\n\t\tsignOutOfProvider: 'Also sign out of Clavix',\n\t\tcontinue: 'Continue with Clavix',\n\t},\n\tfr: {\n\t\t'signed-out': 'Vous êtes déconnecté.',\n\t\t'session-expired':\n\t\t\t'Votre session a pris fin. Reconnectez-vous pour continuer.',\n\t\tcancelled: 'La connexion a été annulée. Vous pouvez réessayer.',\n\t\tsuspended:\n\t\t\t'Ce compte ou cette organisation est suspendu. Contactez votre administrateur ou le support.',\n\t\texpired:\n\t\t\t'La connexion a pris trop de temps ou a déjà été utilisée. Recommencez.',\n\t\tdown: 'Le service de connexion ne répond pas. Réessayez dans un instant.',\n\t\tprovider: 'Le service de connexion a refusé la demande.',\n\t\tgeneric: 'La connexion n’a pas pu aboutir.',\n\t\treference: 'Référence à communiquer au support : {reference}',\n\t\tsignOutOfProvider: 'Me déconnecter aussi de Clavix',\n\t\tcontinue: 'Continuer avec Clavix',\n\t},\n} as const satisfies Record<'en' | 'fr', ClavixMessages>;\n\n/** The sentence of a notice, and the reference line when it has one. */\nexport function clavixNoticeText(\n\tnotice: ClavixNotice,\n\tmessages: ClavixMessages = clavixMessages.en,\n): { readonly text: string; readonly reference: string | null } {\n\tconst reference =\n\t\t'reference' in notice && notice.reference\n\t\t\t? messages.reference.replace('{reference}', notice.reference)\n\t\t\t: null;\n\treturn { text: messages[notice.kind], reference };\n}\n"
18
+ ],
19
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAM,UAAU,CAAC,UAAkB,MAAM,QAAQ,QAAQ,EAAE;AAGpD,SAAS,YAAY,CAAC,KAG3B;AAAA,EACD,MAAM,QAAQ,CAAC,MAAc,UAAkB;AAAA,IAC9C,IAAI;AAAA,IACJ,IAAI;AAAA,MACH,MAAM,IAAI,IAAI,KAAK;AAAA,MAClB,MAAM;AAAA,MACP,MAAM,IAAI,UACT,uBAAuB,8BACxB;AAAA;AAAA,IAED,IAAI,CAAC,YAAY,KAAK,IAAI,QAAQ,KAAK,IAAI,UAAU,IAAI,MAAM;AAAA,MAC9D,MAAM,IAAI,UACT,uBAAuB,wDACxB;AAAA,IACD;AAAA,IACA,OAAO,QAAQ,KAAK;AAAA;AAAA,EAErB,MAAM,aAAa,MAAM,aAAa,IAAI,SAAS;AAAA,EACnD,OAAO;AAAA,IACN;AAAA,IACA,cACC,IAAI,gBAAgB,YACjB,aACA,MAAM,eAAe,IAAI,WAAW;AAAA,EACzC;AAAA;AAGD,IAAM,WAAW,CAAC,KAAa,SAC9B,QAAQ,QAAQ,IAAI,WAAW,GAAG,OAAO,KAAK,IAAI,WAAW,GAAG,OAAO;AAQjE,SAAS,cAAc,CAC7B,MACA,WACA,aACO;AAAA,EACP,MAAM,OAAO,QAAQ,SAAS;AAAA,EAC9B,MAAM,KAAK,QAAQ,WAAW;AAAA,EAC9B,IAAI,SAAS;AAAA,IAAI,OAAO;AAAA,EACxB,OAAO,CAAC,OAAO,SACd,SAAS,OAAO,IAAI,IACjB,KAAK,GAAG,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAC7C,KAAK,OAAO,IAAI;AAAA;AAId,SAAS,WAAW,CAC1B,KACA,aACA,WACS;AAAA,EACT,MA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AW;AAAA,IACX,mBAAmB;AAAA,IACnB,UAAU;AAAA,EACX;AACD;AAGO,SAAS,gBAAgB,CAC/B,QACA,WAA2B,eAAe,IACqB;AAAA,EAC/D,MAAM,YACL,eAAe,UAAU,OAAO,YAC7B,SAAS,UAAU,QAAQ,eAAe,OAAO,SAAS,IAC1D;AAAA,EACJ,OAAO,EAAE,MAAM,SAAS,OAAO,OAAO,UAAU;AAAA;",
20
+ "debugId": "EDF205BF8BB6B88864756E2164756E21",
21
+ "names": []
22
+ }
@@ -0,0 +1,67 @@
1
+ import { type ClavixNotice } from './notice';
2
+ /** What the sign-in loader gives the page. */
3
+ export interface ClavixLanding {
4
+ /** The `Set-Cookie` the page's answer must carry (a dead session cookie cleared). Pass it as the loader's `headers`. */
5
+ readonly headers: Headers;
6
+ /** What the page has to say, `null` for none. */
7
+ readonly notice: ClavixNotice | null;
8
+ /** The link of the sign-in button: a GET on the start route, `next` kept (a GET, since a CSP `form-action` may refuse a form post to the issuer). */
9
+ readonly startHref: string;
10
+ /** Where the visitor goes after signing in: a path of this site. */
11
+ readonly next: string;
12
+ /** The issuer's own sign-out, for the « also sign out of Clavix » link; `null` unless the notice is `signed-out`. */
13
+ readonly endSessionUrl: string | null;
14
+ }
15
+ /** Options of `landing`. */
16
+ export interface LandingOptions {
17
+ /** The app also offers another way to sign in (a password, a mailed link): the page always shows, with the Clavix button beside it. `false` by default: provider-only. */
18
+ readonly otherMethods?: boolean | undefined;
19
+ /** Query parameters of the app's own that also keep the page (a spent link, an accepted invitation). */
20
+ readonly speakingParams?: readonly string[] | undefined;
21
+ }
22
+ /** The link that starts a sign-in, `next` kept. */
23
+ export declare const startHrefOf: (startPath: string, next: string | null) => string;
24
+ /** The inputs `landing` is built over. */
25
+ export interface LandingContext {
26
+ readonly paths: {
27
+ readonly start: string;
28
+ readonly signIn: string;
29
+ };
30
+ readonly signedOut: {
31
+ readonly was: (request: Request) => boolean;
32
+ readonly clear: () => string;
33
+ };
34
+ /** The issuer's `end-session` address for the signed-out page. */
35
+ readonly endSessionUrl: () => Promise<string | null>;
36
+ /** The request's session state: the cookie, and whether it opens. */
37
+ readonly session: (request: Request) => Promise<{
38
+ readonly has: boolean;
39
+ readonly live: boolean;
40
+ readonly cookies: readonly string[];
41
+ }>;
42
+ readonly clearCookie: () => Promise<string>;
43
+ }
44
+ /**
45
+ * The sign-in page's loader decision, for a visitor with the app's provider
46
+ * as its way in:
47
+ *
48
+ * - a signed-in visitor goes to `next`;
49
+ * - a dead session cookie (its refresh token is gone) is cleared, so `/` stops
50
+ * sending the visitor back;
51
+ * - the signed-out cookie (set by sign-out, since the end-session redirect
52
+ * cannot carry a query) turns into `?signed-out=1`, so a reload keeps the page
53
+ * instead of sending the visitor to the issuer, whose single sign-on would sign
54
+ * them straight back in;
55
+ * - with nothing to say and no other method, a document redirect to the start
56
+ * route: no page with a lone button is shown.
57
+ */
58
+ export declare function landingOf(context: LandingContext, request: Request, options?: LandingOptions): Promise<ClavixLanding>;
59
+ /** What the request of a page with no session gets for an ended one: a redirect to sign-in for a GET or HEAD, a 401 JSON `session-expired` otherwise. */
60
+ export declare function expiredAnswerOf(signInPath: string, request: Request): Response;
61
+ /** The issuer's `end-session` address for the signed-out page. With no `id_token_hint` (the tokens are gone), Clavix shows its own confirmation page before it ends anything. */
62
+ export declare function endSessionUrlOf(settings: {
63
+ readonly issuer: string;
64
+ readonly clientId: string;
65
+ readonly postLogoutRedirectUri?: string | undefined;
66
+ }): string;
67
+ //# sourceMappingURL=landing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"landing.d.ts","sourceRoot":"","sources":["../../src/clavix/landing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,YAAY,EAAkB,MAAM,UAAU,CAAC;AAE5E,8CAA8C;AAC9C,MAAM,WAAW,aAAa;IAC7B,wHAAwH;IACxH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,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C,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAC9B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAoCxB;AAED,yJAAyJ;AACzJ,wBAAgB,eAAe,CAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GACd,QAAQ,CASV;AAED,iLAAiL;AACjL,wBAAgB,eAAe,CAAC,QAAQ,EAAE;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpD,GAAG,MAAM,CAUT"}
@@ -0,0 +1,53 @@
1
+ import type { ClavixNotice } from './notice';
2
+ /** The words of the sign-in page's notices, for one language. */
3
+ export interface ClavixMessages {
4
+ readonly 'signed-out': string;
5
+ readonly 'session-expired': string;
6
+ readonly cancelled: string;
7
+ readonly suspended: string;
8
+ readonly expired: string;
9
+ readonly down: string;
10
+ readonly provider: string;
11
+ readonly generic: string;
12
+ /** Before a support reference: `{reference}` is replaced. */
13
+ readonly reference: string;
14
+ /** The link that also ends the visitor's session at the identity provider. */
15
+ readonly signOutOfProvider: string;
16
+ /** The sign-in button. */
17
+ readonly continue: string;
18
+ }
19
+ /** English and French. */
20
+ export declare const clavixMessages: {
21
+ readonly en: {
22
+ readonly 'signed-out': "You are signed out.";
23
+ readonly 'session-expired': "Your session ended. Sign in again to continue.";
24
+ readonly cancelled: "The sign-in was cancelled. You can try again.";
25
+ readonly suspended: "This account or organisation is suspended. Contact your administrator or the support.";
26
+ readonly expired: "The sign-in took too long or was already used. Start again.";
27
+ readonly down: "The sign-in service did not answer. Try again in a moment.";
28
+ readonly provider: "The sign-in service refused the request.";
29
+ readonly generic: "The sign-in could not be completed.";
30
+ readonly reference: "Reference to quote to the support: {reference}";
31
+ readonly signOutOfProvider: "Also sign out of Clavix";
32
+ readonly continue: "Continue with Clavix";
33
+ };
34
+ readonly fr: {
35
+ readonly 'signed-out': "Vous êtes déconnecté.";
36
+ readonly 'session-expired': "Votre session a pris fin. Reconnectez-vous pour continuer.";
37
+ readonly cancelled: "La connexion a été annulée. Vous pouvez réessayer.";
38
+ readonly suspended: "Ce compte ou cette organisation est suspendu. Contactez votre administrateur ou le support.";
39
+ readonly expired: "La connexion a pris trop de temps ou a déjà été utilisée. Recommencez.";
40
+ readonly down: "Le service de connexion ne répond pas. Réessayez dans un instant.";
41
+ readonly provider: "Le service de connexion a refusé la demande.";
42
+ readonly generic: "La connexion n’a pas pu aboutir.";
43
+ readonly reference: "Référence à communiquer au support : {reference}";
44
+ readonly signOutOfProvider: "Me déconnecter aussi de Clavix";
45
+ readonly continue: "Continuer avec Clavix";
46
+ };
47
+ };
48
+ /** The sentence of a notice, and the reference line when it has one. */
49
+ export declare function clavixNoticeText(notice: ClavixNotice, messages?: ClavixMessages): {
50
+ readonly text: string;
51
+ readonly reference: string | null;
52
+ };
53
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/clavix/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,0BAA0B;AAC1B,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B6B,CAAC;AAEzD,wEAAwE;AACxE,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,YAAY,EACpB,QAAQ,GAAE,cAAkC,GAC1C;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAM9D"}
@@ -0,0 +1,32 @@
1
+ import { type ClavixRefusal } from './refusal';
2
+ /** The query parameters the routes put on the sign-in page. */
3
+ export declare const CLAVIX_PARAMS: {
4
+ /** A refused sign-in: a {@link ClavixRefusal}. */
5
+ readonly error: "clavix-error";
6
+ /** The support reference of a refusal. */
7
+ readonly reference: "ref";
8
+ /** The visitor just signed out. */
9
+ readonly signedOut: "signed-out";
10
+ /** The session ended and could not be refreshed. */
11
+ readonly expired: "expired";
12
+ };
13
+ /** What the sign-in page has to say. */
14
+ export type ClavixNotice = {
15
+ readonly kind: 'signed-out';
16
+ } | {
17
+ readonly kind: 'session-expired';
18
+ } | {
19
+ readonly kind: ClavixRefusal;
20
+ /** The code to quote to the support; `null` for a refusal the visitor can retry. */
21
+ readonly reference: string | null;
22
+ };
23
+ /** How loud a notice is: the tone of its alert. */
24
+ export type ClavixTone = 'error' | 'warning' | 'info';
25
+ /** The tone of a notice. A refusal the visitor caused or can retry is not an error. */
26
+ export declare function clavixToneOf(notice: ClavixNotice): ClavixTone;
27
+ /**
28
+ * The notice a sign-in URL asks for, or `null`. Only the bounded set is read: a
29
+ * refusal outside it, or a reference of another shape, is dropped.
30
+ */
31
+ export declare function clavixNoticeOf(params: URLSearchParams): ClavixNotice | null;
32
+ //# sourceMappingURL=notice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notice.d.ts","sourceRoot":"","sources":["../../src/clavix/notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,WAAW,CAAC;AAEnB,+DAA+D;AAC/D,eAAO,MAAM,aAAa;IACzB,kDAAkD;;IAElD,0CAA0C;;IAE1C,mCAAmC;;IAEnC,oDAAoD;;CAE3C,CAAC;AAEX,wCAAwC;AACxC,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GACpC;IACA,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAEL,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEtD,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAY7D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,YAAY,GAAG,IAAI,CAa3E"}
@@ -0,0 +1,29 @@
1
+ import type { OidcErrorCode } from '../oidc';
2
+ /** What a refused sign-in stands for: a bounded set, so a crafted URL shows no free text. */
3
+ export type ClavixRefusal = 'cancelled' | 'suspended' | 'expired' | 'down' | 'provider' | 'generic';
4
+ /** The refusals, in the order the catalogue lists them. */
5
+ export declare const CLAVIX_REFUSALS: readonly ClavixRefusal[];
6
+ /**
7
+ * The kind of sentence an `OidcError` stands for. The issuer's `access_denied`
8
+ * is a visitor who backed out (`cancelled`), unless its description says the
9
+ * account or tenant is suspended; a spent or lost challenge is `expired`;
10
+ * the issuer not answering (discovery, PAR, the token endpoint) is `down`;
11
+ * any other `error` it sends is `provider`; the rest (a state, issuer or
12
+ * token that does not check out) is `generic`.
13
+ */
14
+ export declare function clavixRefusalOf(code: OidcErrorCode, message: string): ClavixRefusal;
15
+ /**
16
+ * Whether the visitor cannot fix a refusal by trying again, so the support
17
+ * needs its reference. A cancel, an expired challenge or a service that is
18
+ * down are theirs to retry: no reference.
19
+ */
20
+ export declare const needsReference: (kind: ClavixRefusal) => boolean;
21
+ /**
22
+ * A short code (`K7QM-2XPD`) the visitor can quote to the support: the
23
+ * server's log holds it beside the refusal. No ambiguous character (no `0`,
24
+ * `O`, `1`, `I`).
25
+ */
26
+ export declare function supportReference(bytes?: (count: number) => Uint8Array): string;
27
+ /** A reference as {@link supportReference} makes it. */
28
+ export declare const isSupportReference: (value: string | null) => value is string;
29
+ //# sourceMappingURL=refusal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../../src/clavix/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,6FAA6F;AAC7F,MAAM,MAAM,aAAa,GACtB,WAAW,GACX,WAAW,GACX,SAAS,GACT,MAAM,GACN,UAAU,GACV,SAAS,CAAC;AAEb,2DAA2D;AAC3D,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAOnD,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,MAAM,GACb,aAAa,CAiBf;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,aAAa,KAAG,OACa,CAAC;AAMnE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,UAAwB,GAChD,MAAM,CAMR;AAED,wDAAwD;AACxD,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,GAAG,IAAI,KAAG,KAAK,IAAI,MACT,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { OidcUser } from '../oidc';
2
+ /** What a relay (`/media`, `/live`) needs of the session. */
3
+ interface Session {
4
+ hasSession(request: Request): Promise<boolean>;
5
+ latestOf(request: Request): Promise<OidcUser | null>;
6
+ }
7
+ /**
8
+ * The relays' side of the session. The relay libraries put the access token in
9
+ * `Authorization: Bearer`; `fetch` turns that into `DPoP` and a proof for the
10
+ * API's public URL.
11
+ */
12
+ export declare function relays(session: Session, urls: {
13
+ readonly publicBase: string;
14
+ readonly internalBase: string;
15
+ }): {
16
+ /** The access token a relay sends upstream, `null` without a session. */
17
+ tokenOf: (request: Request) => Promise<string | null>;
18
+ /**
19
+ * `tokenOf` for a relay built once for every call (`/live`): its `fetch` is
20
+ * not given the request, so this remembers it (under the token's hash, never
21
+ * the token) for `fetch` to find the user to sign with. Pair it with `forget`.
22
+ */
23
+ liveTokenOf(request: Request): Promise<string | null>;
24
+ /** Drops what `liveTokenOf` kept: the relay answered (its stream is open, or it failed). */
25
+ forget(request: Request): void;
26
+ /**
27
+ * The relays' `fetch`: the bearer token they set becomes `Authorization:
28
+ * DPoP` with a proof for the API's public URL. `source` is the incoming
29
+ * request (the media relays build their options per request); without it
30
+ * the user is found through `liveTokenOf`. A call whose user is not found
31
+ * is answered 401, never forwarded with a bare bearer token. A
32
+ * `use_dpop_nonce` answer is signed again and sent once more when the call
33
+ * has no body to replay; one with a body (an upload) is not retried, since a
34
+ * stream cannot be sent twice.
35
+ */
36
+ fetch(upstream: (request: Request) => Promise<Response>, source?: Request): (request: Request) => Promise<Response>;
37
+ };
38
+ /** What {@link relays} gives: the relay side of the session. */
39
+ export type ClavixRelay = ReturnType<typeof relays>;
40
+ export {};
41
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/clavix/relay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,6DAA6D;AAC7D,UAAU,OAAO;IAChB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACrD;AASD;;;;GAIG;AACH,wBAAgB,MAAM,CACrB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE;IAWnE,yEAAyE;uBAN1C,OAAO,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ/D;;;;OAIG;yBACwB,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAU3D,4FAA4F;oBAC5E,OAAO,GAAG,IAAI;IAQ9B;;;;;;;;;OASG;oBACa,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,WAAW,OAAO,IAC1D,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;EAyCpD;AAED,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ClavixCore } from './core';
2
+ import type { ClavixRoutes } from './types';
3
+ /** The three route modules of {@link clavixRoutes}. */
4
+ export declare function routeModules(c: ClavixCore): ClavixRoutes['routes'];
5
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/clavix/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiB5C,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC,CAqClE"}
@@ -0,0 +1,32 @@
1
+ import { type OidcClient } from '../oidc';
2
+ import { type Send } from './api-url';
3
+ import type { RequestState } from './state';
4
+ /**
5
+ * The session ended and cannot be refreshed: the visitor signs in again.
6
+ * `answer` is what the request gets for it (a redirect to sign-in for a GET, a
7
+ * 401 `session-expired` otherwise); throw it where a GraphQL client would turn
8
+ * any error from `fetch` into a 503, and answer `answer` from the route.
9
+ */
10
+ export declare class SessionExpired extends Error {
11
+ readonly answer: Response;
12
+ readonly name = "SessionExpired";
13
+ constructor(message: string, answer: Response);
14
+ }
15
+ /** The `SessionExpired` the calls of `request` met, if any. */
16
+ export declare const endedOf: (request: Request) => SessionExpired | undefined;
17
+ /** Whether a thrown value is the answer of an ended session (what a route may rethrow for a `SessionExpired`). */
18
+ export declare const isExpiredAnswer: (value: unknown) => value is Response;
19
+ /**
20
+ * A `fetch` for the calls of one request to the API, as the signed-in user:
21
+ * `Authorization: DPoP` and a proof for the URL given (the public one), the
22
+ * nonce retry, a refresh before the token ends, and, on a 401 that remains,
23
+ * one forced refresh and one retry. A refresh that fails throws
24
+ * `SessionExpired` carrying `expired()`. Any other answer (a 503 included) is
25
+ * returned as it is: an unreachable API is never a sign-out. A URL outside
26
+ * the API's two addresses throws `ClavixOriginError` before anything is signed.
27
+ */
28
+ export declare function sender(oidc: () => Promise<OidcClient>, stateOf: (request: Request) => Promise<RequestState>, request: Request, expired: () => Response, urls: {
29
+ readonly publicBase: string;
30
+ readonly internalBase: string;
31
+ }): Send;
32
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/clavix/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,UAAU,EAA4B,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAgB,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAIvC,QAAQ,CAAC,MAAM,EAAE,QAAQ;IAH1B,SAAkB,IAAI,oBAAoB;gBAEzC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,QAAQ;CAK1B;AAOD,+DAA+D;AAC/D,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,KAAG,cAAc,GAAG,SACvC,CAAC;AAEtB,kHAAkH;AAClH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QACe,CAAC;AAE1E;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAC/B,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,EACpD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,QAAQ,EACvB,IAAI,EAAE;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAClE,IAAI,CAuCN"}
@@ -0,0 +1,20 @@
1
+ import type { OidcClient, OidcUser } from '../oidc';
2
+ /** What a request holds while it runs: the user read from its cookie, and the newest one after a refresh. */
3
+ export interface RequestState {
4
+ user: OidcUser | null;
5
+ latest: OidcUser | null;
6
+ }
7
+ /** The request-scoped reads of the session, over one relying party. */
8
+ export declare function requestStates(oidc: () => Promise<OidcClient>): {
9
+ /** The signed-in user of the request, read once per request. `null` without a cookie, or when a refresh failed on an ended access token. */
10
+ of(request: Request): Promise<RequestState>;
11
+ /** The `Set-Cookie` of a rotation this request made, `[]` when the cookie it came with is current. */
12
+ refreshed(request: Request): Promise<string[]>;
13
+ };
14
+ /**
15
+ * The response with `cookies` added to its `Set-Cookie`. A Response made by
16
+ * `fetch` or `redirect()` may have immutable headers, so a new one is built
17
+ * from it; the same response when there is nothing to add.
18
+ */
19
+ export declare function appendSetCookies(response: Response, cookies: Iterable<string>): Response;
20
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/clavix/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEpD,6GAA6G;AAC7G,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;CACxB;AAED,uEAAuE;AACvE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC;IAG3D,4IAA4I;gBAChI,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAU3C,sGAAsG;uBAC7E,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;EAOrD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GACvB,QAAQ,CAUV"}
@@ -0,0 +1,97 @@
1
+ import type { OidcClient, OidcEnvSource, OidcError, OidcUser } from '../oidc';
2
+ import type { ApiUrls, Send } from './api-url';
3
+ import type { ClavixLanding, LandingOptions } from './landing';
4
+ import type { ClavixRelay } from './relay';
5
+ /** The route paths; each has a default. */
6
+ export interface ClavixPaths {
7
+ /** Starts the sign-in (PAR, PKCE, DPoP). `/auth/clavix` by default. */
8
+ readonly start?: string | undefined;
9
+ /** The issuer's return address. `/auth/clavix/callback` by default; register it with the client. */
10
+ readonly callback?: string | undefined;
11
+ /** The app's sign-in page. `/sign-in` by default. */
12
+ readonly signIn?: string | undefined;
13
+ }
14
+ /** Options of {@link clavixRoutes}. */
15
+ export interface ClavixRoutesOptions {
16
+ /** Whether cookies are `Secure` and `__Host-` prefixed: `!import.meta.env.DEV`. Not read from the environment: a built `dist` has no `import.meta.env`. */
17
+ readonly secure: boolean;
18
+ /** The API the session calls, at its public and internal addresses. */
19
+ readonly api: ApiUrls & {
20
+ /** The API's GraphQL path, under `publicUrl`; the resource (RFC 8707) the token is for unless `CLAVIX_AUDIENCE` says otherwise. `/graphql` by default. */
21
+ readonly graphqlPath?: string | undefined;
22
+ };
23
+ /** The app's own origin (or a function giving it), from which `CLAVIX_REDIRECT_URI` and `CLAVIX_POST_LOGOUT_REDIRECT_URI` default, and which sign-out checks the request against. */
24
+ readonly appOrigin?: string | (() => string | undefined) | undefined;
25
+ /** Scopes beside `openid`, `profile`, `email` and `offline_access`, such as the API's own scope. */
26
+ readonly scopes?: readonly string[] | undefined;
27
+ readonly paths?: ClavixPaths | undefined;
28
+ /** The environment; `process.env` by default. */
29
+ readonly env?: OidcEnvSource['env'];
30
+ /** Reads a secret file; for a test. */
31
+ readonly readFile?: OidcEnvSource['readFile'];
32
+ /** Stats a secret file; for a test. */
33
+ readonly statFile?: OidcEnvSource['statFile'];
34
+ /** Every call to the issuer and the API; the global `fetch` by default (read at each call). */
35
+ readonly fetch?: Send | undefined;
36
+ /** Logs a refusal under its reference; `console` by default. */
37
+ readonly log?: Pick<Console, 'warn'> | undefined;
38
+ /** Called when a token revocation at sign-out fails (the sign-out goes on). Logs a warning by default. */
39
+ readonly onRevokeError?: ((error: OidcError) => void) | undefined;
40
+ }
41
+ export type Args = {
42
+ readonly request: Request;
43
+ };
44
+ /** What {@link clavixRoutes} gives. */
45
+ export interface ClavixRoutes {
46
+ /** Reads and checks `CLAVIX_*` now, so a bad environment stops the boot with named problems (`OidcEnvError`). Called by every route, so a first request fails the same way. A failure is not cached. */
47
+ ready(): Promise<void>;
48
+ /** The relying party, built on first use. */
49
+ oidc(): Promise<OidcClient>;
50
+ /** The API's public URL for a path (`/graphql` by default): the one a proof names. Pass it to the client you send with `sendOf`. */
51
+ apiUrl(path?: string): string;
52
+ /** The route modules, as the router file exports them. */
53
+ readonly routes: {
54
+ /** `/auth/clavix`: `loader` redirects to the issuer. */
55
+ readonly start: {
56
+ loader: (args: Args) => Promise<Response>;
57
+ };
58
+ /** `/auth/clavix/callback`: `loader` finishes the sign-in, or redirects a refusal to the sign-in page. */
59
+ readonly callback: {
60
+ loader: (args: Args) => Promise<Response>;
61
+ };
62
+ /** `/sign-out`: `action` ends the session and goes to the issuer's `end_session_endpoint`; a GET only redirects home. */
63
+ readonly signOut: {
64
+ action: (args: Args) => Promise<Response>;
65
+ loader: (args: Args) => Promise<Response>;
66
+ };
67
+ };
68
+ /** The sign-in page's loader decision; see {@link LandingOptions}. Throws a redirect when the page is not shown. */
69
+ landing(request: Request, options?: LandingOptions): Promise<ClavixLanding>;
70
+ /** Whether the request carries the sealed token cookie, read from its `Cookie` header alone. */
71
+ hasSession(request: Request): Promise<boolean>;
72
+ /** The signed-in user (refreshed when due), `null` without a session; read once per request. */
73
+ userOf(request: Request): Promise<OidcUser | null>;
74
+ /** A `fetch` for the request's calls to the API as the user. Throws `SessionExpired` when the session ended. */
75
+ sendOf(request: Request, options?: {
76
+ readonly expired?: (() => Response) | undefined;
77
+ }): Send;
78
+ /** What a request gets for an ended session: a redirect to sign-in for a GET or HEAD, a 401 `session-expired` JSON otherwise. */
79
+ expiredAnswer(request: Request): Response;
80
+ /** The `Set-Cookie` of a refresh this request made, to put on its response. */
81
+ refreshedCookies(request: Request): Promise<string[]>;
82
+ /** The response with the request's refreshed cookies added (the relays cannot set a cookie themselves). */
83
+ withRefreshedCookies(request: Request, response: Response): Promise<Response>;
84
+ /** A `Set-Cookie` that ends the sealed token cookie, for one that no longer opens. */
85
+ clearCookie(): Promise<string>;
86
+ /**
87
+ * The signed-in viewer of the request, loaded once per request through the app's own
88
+ * function: `load(send)` runs the app's GraphQL query with `send` (the request's `sendOf`).
89
+ * `null` without a session. A session that ended throws the answer (a redirect to sign-in
90
+ * for a GET, a 401 otherwise), even when the GraphQL client swallowed the `SessionExpired`.
91
+ * Put `withRefreshedCookies` on the response as usual.
92
+ */
93
+ viewer<T>(request: Request, load: (send: Send) => Promise<T | null>): Promise<T | null>;
94
+ /** The relays' side: `/media` and `/live` through DPoP. */
95
+ readonly relay: ClavixRelay;
96
+ }
97
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/clavix/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,2CAA2C;AAC3C,MAAM,WAAW,WAAW;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,oGAAoG;IACpG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,qDAAqD;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IACnC,2JAA2J;IAC3J,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG;QACvB,0JAA0J;QAC1J,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAC1C,CAAC;IACF,qLAAqL;IACrL,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;I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ACP,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GACrC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACrB,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC5B"}
@@ -0,0 +1,12 @@
1
+ import type { Send } from './api-url';
2
+ /**
3
+ * `viewer(request, load)`: the app's own `load(send)` (its GraphQL query for
4
+ * the signed-in user) run once per request, so the middleware plumbing is not
5
+ * the app's. No session cookie gives `null` without calling `load`. A session
6
+ * that ended throws the request's answer (what a router turns into the
7
+ * redirect to sign-in): both when `load` throws the `SessionExpired`, and when
8
+ * a GraphQL client swallowed it into an error of its own or a `null`. The
9
+ * answer is kept per request and per `load` function.
10
+ */
11
+ export declare function viewers(hasSession: (request: Request) => Promise<boolean>, sendOf: (request: Request) => Send): <T>(request: Request, load: (send: Send) => Promise<T | null>) => Promise<T | null>;
12
+ //# sourceMappingURL=viewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewer.d.ts","sourceRoot":"","sources":["../../src/clavix/viewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACtB,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,EAClD,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,IAI1B,CAAC,EACR,SAAS,OAAO,EAChB,MAAM,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,KACrC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAyBpB"}