@softistx/janus-hono 0.0.0-stage → 0.11.35

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +547 -2
  3. package/dist/bind.d.ts +104 -0
  4. package/dist/bind.d.ts.map +1 -0
  5. package/dist/device.d.ts +15 -0
  6. package/dist/device.d.ts.map +1 -0
  7. package/dist/errors.d.ts +60 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/fresh.d.ts +41 -0
  10. package/dist/fresh.d.ts.map +1 -0
  11. package/dist/index.d.ts +47 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +496 -0
  14. package/dist/index.js.map +22 -0
  15. package/dist/no-store.d.ts +8 -0
  16. package/dist/no-store.d.ts.map +1 -0
  17. package/dist/passkeys/body.d.ts +12 -0
  18. package/dist/passkeys/body.d.ts.map +1 -0
  19. package/dist/passkeys/index.d.ts +8 -0
  20. package/dist/passkeys/index.d.ts.map +1 -0
  21. package/dist/passkeys/routes.d.ts +32 -0
  22. package/dist/passkeys/routes.d.ts.map +1 -0
  23. package/dist/passkeys/types.d.ts +105 -0
  24. package/dist/passkeys/types.d.ts.map +1 -0
  25. package/dist/permission.d.ts +80 -0
  26. package/dist/permission.d.ts.map +1 -0
  27. package/dist/provide.d.ts +19 -0
  28. package/dist/provide.d.ts.map +1 -0
  29. package/dist/session.d.ts +156 -0
  30. package/dist/session.d.ts.map +1 -0
  31. package/dist/social/index.d.ts +9 -0
  32. package/dist/social/index.d.ts.map +1 -0
  33. package/dist/social/redirect.d.ts +9 -0
  34. package/dist/social/redirect.d.ts.map +1 -0
  35. package/dist/social/refusals.d.ts +14 -0
  36. package/dist/social/refusals.d.ts.map +1 -0
  37. package/dist/social/routes.d.ts +32 -0
  38. package/dist/social/routes.d.ts.map +1 -0
  39. package/dist/social/types.d.ts +90 -0
  40. package/dist/social/types.d.ts.map +1 -0
  41. package/docs/README.md +15 -0
  42. package/docs/guide/permissions.md +225 -0
  43. package/docs/guide/routes.md +1164 -0
  44. package/docs/roadmap.md +76 -0
  45. package/docs/troubleshooting.md +871 -0
  46. package/package.json +62 -5
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/passkeys/routes.ts", "../src/device.ts", "../src/no-store.ts", "../src/session.ts", "../src/passkeys/body.ts", "../src/permission.ts", "../src/provide.ts", "../src/social/routes.ts", "../src/fresh.ts", "../src/social/redirect.ts", "../src/social/refusals.ts", "../src/bind.ts", "../src/errors.ts"],
4
+ "sourcesContent": [
5
+ "/** The passkey routes: one named handler per route, assembled by `passkeyRoutes()`. */\n\nimport type { Authenticated } from '@softistx/janus';\nimport { type Context, Hono, type MiddlewareHandler } from 'hono';\nimport { deviceOf } from '../device';\nimport { noStore } from '../no-store';\nimport { sendSession, session } from '../session';\nimport { bodyOf, textOf } from './body';\nimport type {\n\tPasskeyAuth,\n\tPasskeyRoutesOptions,\n\tPasskeySurface,\n\tPasskeyTypeApi,\n\tStepUpPasskeySurface,\n} from './types';\n\n/** What every handler needs, resolved once by `passkeyRoutes()`. */\ninterface Wiring {\n\treadonly auth: PasskeyAuth;\n\t/** The surface of the user type: the instance itself with one type, `auth[type]` with several. */\n\treadonly api: PasskeyTypeApi;\n\treadonly options: PasskeyRoutesOptions;\n\t/** The session of the request, or `null`. */\n\tcurrent(c: Context): Promise<Authenticated<{ readonly id: string }> | null>;\n}\n\n/**\n * The passkey routes, as a Hono sub-app to `route()` under a prefix. All are\n * JSON; the five behind `session()` answer 401 with no body to an anonymous\n * request:\n *\n * - `GET /` — the user's passkeys: `{ passkeys }`;\n * - `POST /registration-options` — `{ options, challenge, expiresAt }`\n * (`Cache-Control: no-store`, as `POST /step-up`: the challenge is single-use);\n * - `POST /` — `{ challenge, response, name }`: registers, 201 with the\n * passkey (fresh: `STEP_UP_REQUIRED` past the core's `freshWithin`);\n * - `POST /:credentialId/rename` — `{ name }`: 204, or 404;\n * - `DELETE /:credentialId` — 204, or 404 (fresh, like registering);\n * - `POST /sign-in` — `{ challenge, assertion }`, no session needed: answers\n * a sign-in's second factor, sets the session cookie, `200 { id }`;\n * - `POST /step-up` and `POST /step-up/confirm` — behind `session()`:\n * `{ challenge, options, expiresAt }`, then `{ challenge, assertion }` →\n * 204, or 409 when the user cannot step up by passkey.\n *\n * ```ts\n * app.route('/auth/passkeys', passkeyRoutes(auth));\n * app.onError(janusErrors());\n * ```\n *\n * Every refusal is thrown to `app.onError`: with `janusErrors()`,\n * `PASSKEY_INVALID` is 400, `PASSKEY_TAKEN` and `PASSKEY_LIMIT` 409,\n * `CODE_INVALID` 401 with `attemptsLeft`, `STORE_FAILED` 503.\n */\nexport function passkeyRoutes<\n\tA extends PasskeyAuth,\n\tconst T extends string = never,\n>(auth: A & PasskeySurface<T>, options: PasskeyRoutesOptions<T> = {}): Hono {\n\tconst typeOption = options.type === undefined ? {} : { type: options.type };\n\tconst api = apiOf(auth, options.type);\n\tconst wiring: Wiring = {\n\t\tauth,\n\t\tapi,\n\t\toptions,\n\t\tcurrent: (c) =>\n\t\t\tauth.authenticate(\n\t\t\t\tc.req.raw,\n\t\t\t\toptions.type === undefined ? undefined : typeOption,\n\t\t\t) as Promise<Authenticated<{ readonly id: string }> | null>,\n\t};\n\tconst signedIn: MiddlewareHandler =\n\t\toptions.session ?? session(auth, { required: true, ...typeOption });\n\n\tconst app = new Hono()\n\t\t.get('/', signedIn, listHandler(wiring))\n\t\t.post('/registration-options', signedIn, optionsHandler(wiring))\n\t\t.post('/', signedIn, registerHandler(wiring))\n\t\t.post('/sign-in', signInHandler(wiring))\n\t\t.post('/:credentialId/rename', signedIn, renameHandler(wiring))\n\t\t.delete('/:credentialId', signedIn, removeHandler(wiring));\n\tconst { stepUp } = api;\n\tif (stepUp !== undefined) {\n\t\tapp\n\t\t\t.post('/step-up', signedIn, stepUpHandler(wiring, stepUp))\n\t\t\t.post('/step-up/confirm', signedIn, stepUpConfirmHandler(stepUp));\n\t}\n\treturn app;\n}\n\n/** The surface of the user type: the instance itself with one type, `auth[type]` with several. */\nfunction apiOf(auth: PasskeyAuth, type: string | undefined): PasskeyTypeApi {\n\tconst top = auth as unknown as Partial<PasskeyTypeApi>;\n\t// One user type puts the surface on `auth`; several, under the type's name.\n\tconst holder: Partial<PasskeyTypeApi> | undefined =\n\t\ttype === undefined || top.passkeys !== undefined\n\t\t\t? top\n\t\t\t: (\n\t\t\t\t\tauth as unknown as Record<string, Partial<PasskeyTypeApi> | undefined>\n\t\t\t\t)[type];\n\tif (\n\t\tholder?.passkeys === undefined ||\n\t\tholder.secondFactor?.confirmPasskey === undefined\n\t) {\n\t\tthrow new TypeError(\n\t\t\ttype === undefined\n\t\t\t\t? 'passkeyRoutes(): auth has no passkeys — give janus() `passkeys` and a `secondFactor`; with several user types, name the one with `type`'\n\t\t\t\t: `passkeyRoutes(): auth.${type} has no passkeys — give janus() \\`passkeys\\` and a \\`secondFactor\\`, and name a user type that exists`,\n\t\t);\n\t}\n\treturn holder as PasskeyTypeApi;\n}\n\n/** `GET /`: `{ passkeys }`. */\nfunction listHandler(wiring: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\treturn c.json({ passkeys: await wiring.api.passkeys.list(current.user) });\n\t};\n}\n\n/** `POST /registration-options`: `{ options, challenge, expiresAt }`. */\nfunction optionsHandler(wiring: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tnoStore(c);\n\t\treturn c.json(await wiring.api.passkeys.registrationOptions(current.user));\n\t};\n}\n\n/** `POST /`: registers the browser's credential, 201 with the passkey. */\nfunction registerHandler(wiring: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst body = await bodyOf(c);\n\t\tconst passkey = await wiring.api.passkeys.register(current, {\n\t\t\tchallenge: textOf(body, 'challenge'),\n\t\t\tresponse: body['response'],\n\t\t\tname: textOf(body, 'name'),\n\t\t});\n\t\treturn c.json(passkey, 201);\n\t};\n}\n\n/** `POST /:credentialId/rename`: 204, or 404 for a passkey that is not the user's. */\nfunction renameHandler(wiring: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst body = await bodyOf(c);\n\t\tconst renamed = await wiring.api.passkeys.rename(\n\t\t\tcurrent.user,\n\t\t\tc.req.param('credentialId') ?? '',\n\t\t\ttextOf(body, 'name'),\n\t\t);\n\t\treturn c.body(null, renamed ? 204 : 404);\n\t};\n}\n\n/** `DELETE /:credentialId`: 204, or 404 for a passkey that is not the user's. */\nfunction removeHandler(wiring: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst removed = await wiring.api.passkeys.remove(\n\t\t\tcurrent,\n\t\t\tc.req.param('credentialId') ?? '',\n\t\t);\n\t\treturn c.body(null, removed ? 204 : 404);\n\t};\n}\n\n/** `POST /sign-in`: answers `signIn`'s second factor, then the session cookie. */\nfunction signInHandler({ auth, api, options }: Wiring) {\n\treturn async (c: Context) => {\n\t\tconst body = await bodyOf(c);\n\t\tconst signedIn = await api.secondFactor.confirmPasskey(\n\t\t\ttextOf(body, 'challenge'),\n\t\t\tbody['assertion'],\n\t\t\toptions.device === undefined\n\t\t\t\t? undefined\n\t\t\t\t: { device: deviceOf(c, options.device) },\n\t\t);\n\t\tconst user = sendSession(\n\t\t\tc,\n\t\t\tauth,\n\t\t\tsignedIn,\n\t\t\toptions.device === undefined ? {} : { device: options.device },\n\t\t);\n\t\treturn options.onSignedIn === undefined\n\t\t\t? c.json({ id: user.id })\n\t\t\t: options.onSignedIn(c, signedIn);\n\t};\n}\n\n/** `POST /step-up`: `{ challenge, options, expiresAt }`. */\nfunction stepUpHandler(wiring: Wiring, stepUp: StepUpPasskeySurface) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.current(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst issued = await stepUp.request(current.user, { via: 'passkey' });\n\t\tnoStore(c);\n\t\treturn c.json({\n\t\t\tchallenge: issued.challenge,\n\t\t\toptions: issued.options,\n\t\t\texpiresAt: issued.expiresAt,\n\t\t});\n\t};\n}\n\n/** `POST /step-up/confirm`: stamps the request's session, 204. */\nfunction stepUpConfirmHandler(stepUp: StepUpPasskeySurface) {\n\treturn async (c: Context) => {\n\t\tconst body = await bodyOf(c);\n\t\tawait stepUp.confirmPasskey(\n\t\t\tc.req.raw,\n\t\t\ttextOf(body, 'challenge'),\n\t\t\tbody['assertion'],\n\t\t);\n\t\treturn c.body(null, 204);\n\t};\n}\n",
6
+ "import {\n\tDEVICE_COOKIE,\n\ttype DeviceCookieOptions,\n\tdeviceCookie,\n\tdeviceFromCookieHeader,\n} from '@softistx/janus';\nimport type { Context } from 'hono';\n\n// The cookie's name, options and wire format belong to `@softistx/janus`.\nexport { DEVICE_COOKIE, type DeviceCookieOptions };\n\n/**\n * The device token the request's cookie holds, or `null` when it holds none:\n * what a sign-in takes as `device`.\n *\n * ```ts\n * const signedIn = await auth.signIn({ email, password }, { device: deviceOf(c) });\n * ```\n */\nexport function deviceOf(\n\tc: Context,\n\toptions: DeviceCookieOptions = {},\n): string | null {\n\treturn deviceFromCookieHeader(c.req.header('cookie'), options);\n}\n\n/** Sets the device cookie, or sets it again so it lasts another `maxAge`. Appends. */\nexport function sendDevice(\n\tc: Context,\n\tdeviceToken: string,\n\toptions: DeviceCookieOptions = {},\n): void {\n\tc.header('Set-Cookie', deviceCookie(deviceToken, options), { append: true });\n}\n",
7
+ "import type { Context } from 'hono';\n\n/**\n * Marks the response of this request as not cacheable: `Cache-Control:\n * no-store`. A body, a redirect or a cookie that carries a session token, a\n * single-use challenge or a social flow is a secret no cache may keep.\n */\nexport function noStore(c: Context): void {\n\tc.header('Cache-Control', 'no-store');\n}\n",
8
+ "import type { ApiKey, Principal, Session, SharedApi } from '@softistx/janus';\nimport type { Context, MiddlewareHandler } from 'hono';\nimport { getCookie } from 'hono/cookie';\nimport { type DeviceCookieOptions, sendDevice } from './device';\nimport { noStore } from './no-store';\n\n/** Anything `janus()` answered: the part of it this package calls. */\nexport type Auth<U extends { readonly type: string }> = Pick<\n\tSharedApi<U>,\n\t'authenticate' | 'signOut' | 'cookie'\n>;\n\n/** The users an `auth` instance knows, as a union narrowed by `user.type`. */\nexport type UserOfAuth<A> = A extends Auth<infer U> ? U : never;\n\n/**\n * What `session()` sets on the context: `c.var.user` and `c.var.session`,\n * both `null` for an anonymous request unless the route requires a user.\n *\n * `new Hono<SessionEnv<typeof auth>>()` types every route of an app that\n * wires `app.use(session(auth))` once.\n */\nexport type SessionEnv<\n\tA,\n\tT extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n\tRequired extends boolean = false,\n> = {\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: Required extends true\n\t\t? {\n\t\t\t\tuser: Extract<UserOfAuth<A>, { readonly type: T }>;\n\t\t\t\tsession: Session;\n\t\t\t}\n\t\t: {\n\t\t\t\tuser: Extract<UserOfAuth<A>, { readonly type: T }> | null;\n\t\t\t\tsession: Session | null;\n\t\t\t};\n};\n\n/**\n * What `session(auth, { apiKey: true })` sets: `c.var.user` of whoever was\n * authenticated, and beside them `c.var.principal` (narrow on `via`),\n * `c.var.apiKey` (`null` for a session) and `c.var.session` — **`null` for a\n * key**, which has none. Read `c.var.principal.via` before `c.var.session`.\n */\nexport type PrincipalEnv<\n\tA,\n\tT extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n\tRequired extends boolean = false,\n> = {\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: Required extends true\n\t\t? {\n\t\t\t\tuser: Extract<UserOfAuth<A>, { readonly type: T }>;\n\t\t\t\tsession: Session | null;\n\t\t\t\tprincipal: Principal<Extract<UserOfAuth<A>, { readonly type: T }>>;\n\t\t\t\tapiKey: ApiKey | null;\n\t\t\t}\n\t\t: {\n\t\t\t\tuser: Extract<UserOfAuth<A>, { readonly type: T }> | null;\n\t\t\t\tsession: Session | null;\n\t\t\t\tprincipal: Principal<\n\t\t\t\t\tExtract<UserOfAuth<A>, { readonly type: T }>\n\t\t\t\t> | null;\n\t\t\t\tapiKey: ApiKey | null;\n\t\t\t};\n};\n\nexport interface SessionOptions<T extends string> {\n\t/** Only a user of this type is authenticated here; any other is anonymous. */\n\treadonly type?: T;\n\t/**\n\t * `true`: an anonymous request is answered 401, with no body, and the\n\t * route never runs — so `c.var.user` is never `null` in it. Only a literal\n\t * `true` types it so: a computed `boolean` leaves `c.var.user` nullable.\n\t */\n\treadonly required?: boolean;\n\t/**\n\t * `true`: a bearer shaped like an API key is accepted too, and the route\n\t * runs for the key's user. Opt-in per route group — a key reaches only\n\t * the routes behind a `session(auth, { apiKey: true })`. Sets\n\t * `c.var.principal` and `c.var.apiKey`; `c.var.session` is `null` for a\n\t * key. Needs `janus({ apiKeys })`, a `TypeError` at the first request\n\t * otherwise. Only a literal `true` types the extra variables.\n\t */\n\treadonly apiKey?: boolean;\n}\n\n/**\n * The middleware that reads who a request belongs to — `auth.authenticate`\n * on the request — and sets `c.var.user` and `c.var.session`.\n *\n * With `apiKey: true` a key-shaped bearer is accepted as well, and\n * `c.var.principal` / `c.var.apiKey` say which one it was (see `PrincipalEnv`).\n *\n * **An outage is not anonymous**: a store that cannot answer rejects with\n * `STORE_FAILED`, and this middleware lets it through to `app.onError` —\n * `janusErrors()` answers it 503, never 401.\n *\n * A session renewed in passing is sent again as a cookie, after the route\n * ran — but only to a request that presented it as one: a client that sends\n * `Authorization: Bearer` is not handed a cookie it never asked for. And\n * never over a session cookie the route set itself — `sendSession` after a\n * sign-in, `signOut`'s clearing — which a browser would otherwise overwrite.\n */\nexport function session<\n\tA extends Auth<{ readonly type: string }>,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(\n\tauth: A,\n\toptions: SessionOptions<T> & {\n\t\treadonly required: true;\n\t\treadonly apiKey: true;\n\t},\n): MiddlewareHandler<PrincipalEnv<A, T, true>>;\nexport function session<\n\tA extends Auth<{ readonly type: string }>,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(\n\tauth: A,\n\toptions: SessionOptions<T> & { readonly apiKey: true },\n): MiddlewareHandler<PrincipalEnv<A, T>>;\nexport function session<\n\tA extends Auth<{ readonly type: string }>,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(\n\tauth: A,\n\toptions: SessionOptions<T> & {\n\t\treadonly required: true;\n\t\treadonly apiKey?: false;\n\t},\n): MiddlewareHandler<SessionEnv<A, T, true>>;\nexport function session<\n\tA extends Auth<{ readonly type: string }>,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(\n\tauth: A,\n\toptions?: SessionOptions<T> & {\n\t\treadonly required?: false;\n\t\treadonly apiKey?: false;\n\t},\n): MiddlewareHandler<SessionEnv<A, T>>;\nexport function session<\n\tA extends Auth<{ readonly type: string }>,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(auth: A, options: SessionOptions<T>): MiddlewareHandler<SessionEnv<A, T>>;\nexport function session(\n\tauth: Auth<{ readonly type: string }>,\n\toptions: SessionOptions<string> = {},\n): MiddlewareHandler {\n\treturn async (c, next) => {\n\t\tconst type = options.type === undefined ? {} : { type: options.type };\n\t\tconst current =\n\t\t\toptions.apiKey === true\n\t\t\t\t? await auth.authenticate(c.req.raw, { ...type, apiKey: true })\n\t\t\t\t: await auth.authenticate(\n\t\t\t\t\t\tc.req.raw,\n\t\t\t\t\t\toptions.type === undefined ? undefined : { type: options.type },\n\t\t\t\t\t);\n\n\t\tif (current === null && options.required === true) {\n\t\t\treturn c.body(null, 401);\n\t\t}\n\t\tc.set('user', current?.user ?? null);\n\t\tc.set('session', current?.session ?? null);\n\t\tif (options.apiKey === true) {\n\t\t\tc.set('principal', current);\n\t\t\tc.set('apiKey', current?.via === 'apiKey' ? current.apiKey : null);\n\t\t}\n\n\t\tawait next();\n\n\t\t// The route's own cookie wins: a sign-in or a sign-out behind this\n\t\t// middleware must not be undone by the session it replaced.\n\t\tconst name = `${auth.cookie.name}=`;\n\t\tif (\n\t\t\tcurrent?.via !== 'apiKey' &&\n\t\t\tcurrent?.renewed === true &&\n\t\t\tgetCookie(c, auth.cookie.name) === current.token &&\n\t\t\t!c.res.headers.getSetCookie().some((value) => value.startsWith(name))\n\t\t) {\n\t\t\tsendSession(c, auth, current);\n\t\t}\n\t\treturn undefined;\n\t};\n}\n\n/** What `sendSession` takes besides: the device cookie's options. */\nexport interface SendSessionOptions {\n\treadonly device?: DeviceCookieOptions;\n}\n\n/**\n * Sends the session cookie — after `signUp`, `signIn`, or anything else that\n * answered a session token and its session — and answers the user. Appends: a\n * cookie set before stays. The response says `Cache-Control: no-store`: it\n * carries a session token. `session()` calls it for a renewal too, and only\n * then.\n *\n * When the answer carries a `deviceToken` — the sign-in was given a\n * `device` — the device cookie is set too, or set again so it lasts another\n * four hundred days.\n *\n * ```ts\n * const signedIn = await auth.signIn({ email, password }, { device: deviceOf(c) });\n * const user = sendSession(c, auth, signedIn);\n * return c.json({ id: user.id }); // the token is in the cookie, never in the body\n * ```\n */\nexport function sendSession<U>(\n\tc: Context,\n\tauth: Pick<Auth<{ readonly type: string }>, 'cookie'>,\n\tsignedIn: {\n\t\treadonly token: string;\n\t\treadonly session: Session;\n\t\treadonly user: U;\n\t\treadonly deviceToken?: string | null;\n\t},\n\toptions: SendSessionOptions = {},\n): U {\n\tnoStore(c);\n\tc.header(\n\t\t'Set-Cookie',\n\t\tauth.cookie.serialize(signedIn.token, signedIn.session),\n\t\t{\n\t\t\tappend: true,\n\t\t},\n\t);\n\tif (typeof signedIn.deviceToken === 'string') {\n\t\tsendDevice(c, signedIn.deviceToken, options.device);\n\t}\n\treturn signedIn.user;\n}\n\n/**\n * Revokes the session the request presents and clears the cookie — cleared\n * whatever the answer, so a browser holding a stale cookie drops it too.\n * `false` when the request presented no session, or an unknown one.\n */\nexport async function signOut(\n\tc: Context,\n\tauth: Pick<Auth<{ readonly type: string }>, 'signOut' | 'cookie'>,\n): Promise<boolean> {\n\tconst revoked = await auth.signOut(c.req.raw);\n\tc.header('Set-Cookie', auth.cookie.clear(), { append: true });\n\treturn revoked;\n}\n",
9
+ "/** Reading the JSON body of a passkey route: never a refusal of its own, the core's answer does. */\n\nimport type { Context } from 'hono';\n\n/**\n * The request's JSON object, or `{}` for a body that is missing, is not JSON\n * or is not an object. The core then refuses the absent field with its own\n * code (`TOKEN_UNKNOWN` for a challenge, `PASSKEY_INVALID` for a name), so a\n * malformed request costs the visitor nothing and gets a code, not a 500.\n */\nexport async function bodyOf(\n\tc: Context,\n): Promise<Readonly<Record<string, unknown>>> {\n\tconst body: unknown = await c.req.json().catch(() => null);\n\treturn typeof body === 'object' && body !== null && !Array.isArray(body)\n\t\t? (body as Record<string, unknown>)\n\t\t: {};\n}\n\n/** A string field, or `''` for anything else: the core refuses an empty challenge. */\nexport function textOf(body: Readonly<Record<string, unknown>>, key: string) {\n\tconst value = body[key];\n\treturn typeof value === 'string' ? value : '';\n}\n",
10
+ "import type {\n\tCheckableOf,\n\tCtxOf,\n\tFieldsOf,\n\tModelConfig,\n\tObjectTypeOf,\n\tPermissions,\n\tSubjectRef,\n} from '@softistx/janus/permissions';\nimport type { Context, MiddlewareHandler } from 'hono';\n\n/**\n * An object of type `T` as the application loads it: its id, **every field a\n * `fromField` of its type reads**, and whatever else it carries. The type is\n * the middleware's to add.\n */\nexport type ObjectData<C extends ModelConfig, T extends ObjectTypeOf<C>> = {\n\treadonly id: string;\n} & { readonly [F in FieldsOf<C, T>]: string | null };\n\nexport type Awaitable<V> = V | Promise<V>;\n\n/**\n * The options of `permission()`: `ctx` required exactly when a condition of\n * the permission is reachable, as for `can()`.\n */\nexport type PermissionOptions<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n\tO,\n> = {\n\t/**\n\t * Who asks. `c.var.user` — set by `session()` — when absent; pass it when\n\t * your users are not `janus()`'s. `null` is anonymous.\n\t */\n\treadonly subject?: (c: Context) => Awaitable<SubjectRef<C> | null>;\n} & ([CtxOf<C, T, P>] extends [never]\n\t? { readonly ctx?: never }\n\t: {\n\t\t\t/** The condition's context, read from the request and the loaded object. */\n\t\t\treadonly ctx: (c: Context, object: O) => Awaitable<CtxOf<C, T, P>>;\n\t\t});\n\n/**\n * The options argument: required exactly when `ctx` is. Loose when `T` or `P`\n * is its whole constraint — what the compiler falls back to when the object\n * type or the permission was wrong — so the error names that argument, not a\n * missing one; the rule `can()` follows.\n */\nexport type OptionsArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n\tO,\n> = [ObjectTypeOf<C>] extends [T]\n\t? IsSingle<ObjectTypeOf<C>> extends true\n\t\t? PermissionArgs<C, T, P, O>\n\t\t: [options?: LooseOptions]\n\t: PermissionArgs<C, T, P, O>;\n\n/** `OptionsArgs` once `T` is known right: loose when `P` is its whole constraint. */\ntype PermissionArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n\tO,\n> = [CheckableOf<C, T>] extends [P]\n\t? IsSingle<CheckableOf<C, T>> extends true\n\t\t? StrictArgs<C, T, P, O>\n\t\t: [options?: LooseOptions]\n\t: StrictArgs<C, T, P, O>;\n\ntype StrictArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n\tO,\n> = [CtxOf<C, T, P>] extends [never]\n\t? [options?: PermissionOptions<C, T, P, O>]\n\t: [options: PermissionOptions<C, T, P, O>];\n\ntype LooseOptions = {\n\treadonly subject?: (c: Context) => unknown;\n\treadonly ctx?: (c: Context, object: never) => unknown;\n};\n\ntype UnionToIntersection<U> = (\n\tU extends unknown\n\t\t? (union: U) => void\n\t\t: never\n) extends (intersection: infer I) => void\n\t? I\n\t: never;\n\n/** Whether `U` is one type rather than a union of several. */\ntype IsSingle<U> = [U] extends [UnionToIntersection<U>] ? true : false;\n\ntype LooseCan = (\n\tsubject: SubjectRef<ModelConfig> | null,\n\tpermission: string,\n\tobject: { readonly type: string; readonly id: string },\n\toptions?: { readonly ctx: unknown },\n) => Promise<boolean>;\n\n/**\n * The middleware that lets a request through only if its subject holds\n * `permission` on an object of `type`: it loads the object once, with `load`,\n * checks it with `access.can`, and hands it to the route as `c.var.object`.\n *\n * | The request | Answered |\n * | --- | --- |\n * | anonymous | 401, no body — before the object is loaded |\n * | `load` answers `null` | 404, no body |\n * | a denial | 403, no body |\n * | allowed | the route runs, `c.var.object` set |\n *\n * One per route: a second one throws a `TypeError`, since both would claim\n * `c.var.object`. A parent object is checked through an arrow in the model.\n *\n * **A failure throws**, as everywhere: a store that cannot answer is\n * `STORE_FAILED`, never a 403 — `janusErrors()` answers it 503.\n */\nexport function permission<\n\tC extends ModelConfig,\n\tconst T extends ObjectTypeOf<C>,\n\tconst P extends CheckableOf<C, T>,\n\tO extends ObjectData<C, T>,\n>(\n\taccess: Pick<Permissions<C>, 'can'>,\n\tpermission: P,\n\ttype: T,\n\tload: (c: Context) => Awaitable<O | null>,\n\t...options: OptionsArgs<C, T, P, O>\n): MiddlewareHandler<{\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: { object: O };\n}>;\nexport function permission(\n\taccess: { readonly can: unknown },\n\tpermission: string,\n\ttype: string,\n\tload: (c: Context) => Awaitable<{ readonly id: string } | null>,\n\toptions: {\n\t\treadonly subject?: (\n\t\t\tc: Context,\n\t\t) => Awaitable<SubjectRef<ModelConfig> | null>;\n\t\treadonly ctx?: (c: Context, object: unknown) => Awaitable<unknown>;\n\t} = {},\n): MiddlewareHandler {\n\tconst can = access.can as LooseCan;\n\n\treturn async (c, next) => {\n\t\tif (c.get('object') !== undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'permission(): c.var.object is already set — one permission() per route; check a parent object through an arrow in the model',\n\t\t\t);\n\t\t}\n\t\tconst subject =\n\t\t\toptions.subject === undefined ? userOf(c) : await options.subject(c);\n\t\tif (subject === null || subject === undefined) return c.body(null, 401);\n\n\t\tconst object = await load(c);\n\t\tif (object === null) return c.body(null, 404);\n\n\t\tconst allowed = await can(\n\t\t\tsubject,\n\t\t\tpermission,\n\t\t\tview(object, type),\n\t\t\toptions.ctx === undefined\n\t\t\t\t? undefined\n\t\t\t\t: { ctx: await options.ctx(c, object) },\n\t\t);\n\t\tif (!allowed) return c.body(null, 403);\n\n\t\tc.set('object', object);\n\t\tawait next();\n\t\treturn undefined;\n\t};\n}\n\n/**\n * A `load` reading one path parameter: `find(id)`, or `null` — a 404 — when\n * the route has no such parameter.\n *\n * ```ts\n * permission(access, 'view', 'record', byParam('id', (id) => records.find(id)))\n * ```\n */\nexport function byParam<O>(\n\tname: string,\n\tfind: (id: string) => Awaitable<O | null>,\n): (c: Context) => Awaitable<O | null> {\n\treturn (c) => {\n\t\tconst id = c.req.param(name);\n\t\treturn id === undefined ? null : find(id);\n\t};\n}\n\n/**\n * The object as `can()` reads it: `type` added, every other field read from\n * the loaded object itself — so a getter, a class's `#private` state or an\n * ORM document's accessors answer as they do in the route. A spread would\n * copy own enumerable fields only.\n */\nfunction view(\n\tobject: object,\n\ttype: string,\n): { readonly type: string; readonly id: string } {\n\treturn new Proxy(object, {\n\t\tget: (target, key) => (key === 'type' ? type : Reflect.get(target, key)),\n\t\thas: (target, key) => key === 'type' || Reflect.has(target, key),\n\t}) as { readonly type: string; readonly id: string };\n}\n\n/** `c.var.user`, which `session()` sets — or a wiring error when nothing did. */\nfunction userOf(c: Context): SubjectRef<ModelConfig> | null {\n\tconst user: unknown = c.get('user');\n\tif (user === undefined) {\n\t\tthrow new TypeError(\n\t\t\t'permission(): c.var.user is not set — put session(auth) before it, or pass { subject }',\n\t\t);\n\t}\n\treturn user as SubjectRef<ModelConfig> | null;\n}\n",
11
+ "import type { MiddlewareHandler } from 'hono';\n\n/** What `provide()` takes: the `janus()` instance, the `permissions()` one, or both. */\nexport interface Instances {\n\treadonly auth?: object;\n\treadonly access?: object;\n}\n\n/**\n * The middleware that puts the instances on the context — `c.var.auth`, and\n * `c.var.access` — so a route writes users and tuples through them rather\n * than through a module import: `c.var.access.grant(record, 'owners', user)`.\n *\n * Only what is passed is set, and typed.\n */\nexport function provide<const I extends Instances>(\n\tinstances: I,\n): MiddlewareHandler<{\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: { [K in keyof I & keyof Instances]: I[K] };\n}> {\n\treturn async (c, next) => {\n\t\tif (instances.auth !== undefined) c.set('auth', instances.auth);\n\t\tif (instances.access !== undefined) c.set('access', instances.access);\n\t\tawait next();\n\t};\n}\n",
12
+ "/** The social sign-in routes: one named handler per route, assembled by `socialRoutes()`. */\n\nimport {\n\ttype Authenticated,\n\tisReturnTo,\n\ttype SocialFlowStart,\n} from '@softistx/janus';\nimport { type Context, Hono, type MiddlewareHandler } from 'hono';\nimport { getCookie } from 'hono/cookie';\nimport { deviceOf } from '../device';\nimport { fresh } from '../fresh';\nimport { noStore } from '../no-store';\nimport { sendSession, session } from '../session';\nimport { localPathOr } from './redirect';\nimport { isRefusal, refusedResponse } from './refusals';\nimport type { SecondFactorOf, SocialAuth, SocialRoutesOptions } from './types';\n\nconst FALLBACK = '/';\n\n/** What every handler needs, resolved once by `socialRoutes()`. */\ninterface Wiring<A extends SocialAuth> {\n\treadonly auth: A;\n\treadonly options: SocialRoutesOptions<A>;\n\treadonly defaultReturnTo: string;\n\t/** `{ type }` when the application named one, else nothing. */\n\treadonly typeOption: { readonly type?: string };\n\tauthenticate(c: Context): ReturnType<A['authenticate']>;\n}\n\n/**\n * The social sign-in routes, as a Hono sub-app to `route()` under a prefix:\n *\n * - `GET /:provider?returnTo=/path` — starts a sign-in: the flow cookie and a\n * 302 to the provider;\n * - `GET /:provider/callback` — completes it: clears the flow cookie (but\n * keeps it when the callback was refused before the flow was spent, so a\n * forged callback cannot burn the visitor's flow), sends the session cookie\n * and 302s to the path the flow was started with; a second factor goes to\n * `onSecondFactor`; a refusal 302s to that path with `?socialError=<code>`;\n * - `POST /:provider/link` — behind `session()` and `fresh()`: starts linking\n * an account to the signed-in user, 303 to the provider;\n * - `DELETE /links/:provider/:accountId` — behind the same: unlinks, 204, or\n * 404 for a link that is not the user's.\n *\n * ```ts\n * app.route('/auth/social', socialRoutes(auth, {\n * onSecondFactor: (c, result) => c.redirect(`/2fa?c=${result.challenge}`),\n * }));\n * ```\n *\n * The callback redirects only for the refusals of a visitor (the ten social\n * codes, `USER_INACTIVE`, `EMAIL_UNVERIFIED`, `STEP_UP_REQUIRED`). Every other\n * error — `STORE_FAILED` first — is thrown to `app.onError`: an outage is 503\n * with `janusErrors()`, never a redirect. A bad `returnTo` or an unknown\n * provider at the *start* is thrown too (400, 404).\n */\nexport function socialRoutes<const A extends SocialAuth>(\n\tauth: A,\n\toptions: SocialRoutesOptions<A>,\n): Hono {\n\tconst defaultReturnTo = options.defaultReturnTo ?? FALLBACK;\n\tif (!isReturnTo(defaultReturnTo)) {\n\t\tthrow new TypeError(\n\t\t\t'socialRoutes: defaultReturnTo must be a path of this site, starting with a single \"/\"',\n\t\t);\n\t}\n\tconst typeOption = options.type === undefined ? {} : { type: options.type };\n\tconst wiring: Wiring<A> = {\n\t\tauth,\n\t\toptions,\n\t\tdefaultReturnTo,\n\t\ttypeOption,\n\t\tauthenticate: (c) =>\n\t\t\tauth.authenticate(\n\t\t\t\tc.req.raw,\n\t\t\t\toptions.type === undefined ? undefined : typeOption,\n\t\t\t) as ReturnType<A['authenticate']>,\n\t};\n\tconst signedIn: MiddlewareHandler =\n\t\toptions.session ?? session(auth, { required: true, ...typeOption });\n\tconst recent: MiddlewareHandler = fresh(options.freshWithin ?? '10m', {\n\t\t...(options.clock === undefined ? {} : { clock: options.clock }),\n\t});\n\n\treturn new Hono()\n\t\t.get('/:provider', startHandler(wiring))\n\t\t.get('/:provider/callback', callbackHandler(wiring))\n\t\t.post('/:provider/link', signedIn, recent, linkHandler(wiring))\n\t\t.delete(\n\t\t\t'/links/:provider/:accountId',\n\t\t\tsignedIn,\n\t\t\trecent,\n\t\t\tunlinkHandler(wiring),\n\t\t);\n}\n\n/** `GET /:provider`: the flow cookie and a 302 to the provider. */\nfunction startHandler<A extends SocialAuth>({ auth, typeOption }: Wiring<A>) {\n\treturn async (c: Context) => {\n\t\tconst returnTo = c.req.query('returnTo');\n\t\tconst started = await auth.social.start({\n\t\t\tprovider: c.req.param('provider') ?? '',\n\t\t\t...typeOption,\n\t\t\t...(returnTo === undefined ? {} : { returnTo }),\n\t\t});\n\t\treturn redirectTo(c, started, 302);\n\t};\n}\n\n/** `GET /:provider/callback`: completes the flow, then answers by what it decided. */\nfunction callbackHandler<A extends SocialAuth>(wiring: Wiring<A>) {\n\tconst { auth, options, defaultReturnTo } = wiring;\n\tconst { social } = auth;\n\treturn async (c: Context) => {\n\t\tconst flow = getCookie(c, social.cookie.name) ?? '';\n\t\t// A link flow is completed by the user who started it; for a sign-in\n\t\t// the core ignores it.\n\t\tconst current = await wiring.authenticate(c);\n\n\t\tlet done: Awaited<ReturnType<A['social']['complete']>>;\n\t\ttry {\n\t\t\tdone = (await social.complete(\n\t\t\t\t{ callback: new URL(c.req.url).searchParams, flow, current },\n\t\t\t\toptions.device === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { device: deviceOf(c, options.device) },\n\t\t\t)) as typeof done;\n\t\t} catch (error) {\n\t\t\tif (!isRefusal(error)) throw error;\n\t\t\treturn refusedResponse(\n\t\t\t\tc,\n\t\t\t\terror,\n\t\t\t\tsocial.cookie.clear(),\n\t\t\t\toptions,\n\t\t\t\tdefaultReturnTo,\n\t\t\t);\n\t\t}\n\n\t\tc.header('Set-Cookie', social.cookie.clear(), { append: true });\n\t\t// the session cookie (`sendSession` marks it) or the challenge follows\n\t\tnoStore(c);\n\t\tif (done.status === 'secondFactor') {\n\t\t\treturn options.onSecondFactor(c, done as SecondFactorOf<A>);\n\t\t}\n\t\tif (done.status === 'signedIn') {\n\t\t\tsendSession(\n\t\t\t\tc,\n\t\t\t\tauth,\n\t\t\t\tdone,\n\t\t\t\toptions.device === undefined ? {} : { device: options.device },\n\t\t\t);\n\t\t}\n\t\treturn c.redirect(localPathOr(done.returnTo, defaultReturnTo), 302);\n\t};\n}\n\n/** `POST /:provider/link`: starts linking an account to the signed-in user, 303 to the provider. */\nfunction linkHandler<A extends SocialAuth>(wiring: Wiring<A>) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.authenticate(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst returnTo = c.req.query('returnTo');\n\t\tconst started = await wiring.auth.social.link(\n\t\t\tcurrent as Authenticated<never>,\n\t\t\t{\n\t\t\t\tprovider: c.req.param('provider') ?? '',\n\t\t\t\t...(returnTo === undefined ? {} : { returnTo }),\n\t\t\t},\n\t\t);\n\t\treturn redirectTo(c, started, 303);\n\t};\n}\n\n/** `DELETE /links/:provider/:accountId`: unlinks, 204, or 404 for a link that is not the user's. */\nfunction unlinkHandler<A extends SocialAuth>(wiring: Wiring<A>) {\n\treturn async (c: Context) => {\n\t\tconst current = await wiring.authenticate(c);\n\t\tif (current === null) return c.body(null, 401);\n\t\tconst unlinked = await wiring.auth.social.unlink(current.user, {\n\t\t\tprovider: c.req.param('provider') ?? '',\n\t\t\taccountId: c.req.param('accountId') ?? '',\n\t\t});\n\t\treturn c.body(null, unlinked ? 204 : 404);\n\t};\n}\n\n/** The flow cookie and the redirect to the provider, `no-store`: the flow is a secret. */\nfunction redirectTo(c: Context, started: SocialFlowStart, status: 302 | 303) {\n\tnoStore(c);\n\tc.header('Set-Cookie', started.setCookie, { append: true });\n\treturn c.redirect(started.url, status);\n}\n",
13
+ "import {\n\ttype Clock,\n\ttype Duration,\n\ttype Principal,\n\tparseDuration,\n\ttype Session,\n\tStepUpRequiredError,\n\tsystemClock,\n} from '@softistx/janus';\nimport type { MiddlewareHandler } from 'hono';\n\n/** What `fresh()` takes besides `maxAge`. */\nexport interface FreshOptions {\n\t/** The clock given to `janus()`, when it is not the system's: `fixedClock` in a spec. */\n\treadonly clock?: Clock;\n}\n\n/**\n * The middleware that lets a route run only for a session that proved who\n * it is less than `maxAge` ago — signed in, or confirmed by\n * `auth.stepUp.confirm`, since. Behind `session(auth)`, which sets\n * `c.var.session`:\n *\n * ```ts\n * app.delete('/account', session(auth, { required: true }), fresh('10m'), deleteAccount);\n * ```\n *\n * A session older than that throws `STEP_UP_REQUIRED`, which `janusErrors()`\n * answers 403 with `{ code: 'STEP_UP_REQUIRED' }`: the client asks for a\n * step-up, then sends the request again. An anonymous request is answered\n * 401, with no body, as `session(auth, { required: true })` answers it.\n *\n * **A key is never fresh**: behind `session(auth, { apiKey: true })`, a\n * request that presented an API key throws `STEP_UP_REQUIRED` with\n * `reason: 'apiKey'` (a 403 `{ code: 'STEP_UP_REQUIRED' }`) — a step-up cannot\n * make a key fresh, so the client must use a signed-in session.\n *\n * A `maxAge` that is not a duration is a `TypeError` here, when the app is\n * wired — not on the first request.\n * No `session()` before it is a `TypeError` at the first request — a\n * wiring error, not an anonymous 401 — as for `permission()`.\n */\nexport function fresh(\n\tmaxAge: Duration,\n\toptions: FreshOptions = {},\n): MiddlewareHandler<{\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: {\n\t\tsession: Session | null;\n\t\tprincipal?: Principal<{ readonly id: string }> | null;\n\t};\n}> {\n\tconst maxAgeMs = parseDuration(maxAge, 'fresh: maxAge');\n\treturn async (c, next) => {\n\t\tconst current = c.var.session;\n\t\tif (current === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'fresh(): c.var.session is not set — put session(auth) before it',\n\t\t\t);\n\t\t}\n\t\tconst principal = c.var.principal;\n\t\tif (principal?.via === 'apiKey') {\n\t\t\tthrow new StepUpRequiredError(\n\t\t\t\t'fresh(): an API key is never fresh — the caller needs a signed-in session',\n\t\t\t\t{ userId: principal.apiKey.userId, reason: 'apiKey' },\n\t\t\t);\n\t\t}\n\t\tif (current === null) return c.body(null, 401);\n\t\t// `assertFresh`'s rule, with a message naming the call written here.\n\t\tconst now = (options.clock ?? systemClock).now().getTime();\n\t\tif (now - current.authenticatedAt.getTime() >= maxAgeMs) {\n\t\t\tthrow new StepUpRequiredError(\n\t\t\t\t'fresh(): the session proved who it is longer ago than maxAge — confirm with a step-up',\n\t\t\t\t{ userId: current.userId },\n\t\t\t);\n\t\t}\n\t\tawait next();\n\t\treturn undefined;\n\t};\n}\n",
14
+ "/**\n * Where the social callback sends the visitor: the core's `returnTo` check\n * run again as a backstop, and the `?socialError=<code>` a refusal adds.\n */\n\nimport { isReturnTo } from '@softistx/janus';\n\n/** `value` when it is a path of this site (the core's `isReturnTo`), else `fallback`. */\nexport function localPathOr(value: unknown, fallback: string): string {\n\treturn isReturnTo(value) ? value : fallback;\n}\n\n/** `path` with `socialError=<code>` in its query, before any fragment. No URL parsing: it would normalise `/.//x` into `//x`. */\nexport function withSocialError(path: string, code: string): string {\n\tconst hash = path.indexOf('#');\n\tconst head = hash === -1 ? path : path.slice(0, hash);\n\tconst tail = hash === -1 ? '' : path.slice(hash);\n\tconst joined = head.includes('?') ? '&' : '?';\n\treturn `${head}${joined}socialError=${encodeURIComponent(code)}${tail}`;\n}\n",
15
+ "/** Which errors of the callback are a visitor's refusal, and the redirect that answers one. */\n\nimport { JanusError, type JanusErrorCode } from '@softistx/janus';\nimport type { Context } from 'hono';\nimport { localPathOr, withSocialError } from './redirect';\nimport type { SocialAuth, SocialRoutesOptions } from './types';\n\n/**\n * The codes `complete` refuses a visitor with, answered as a redirect: the ten\n * of `SocialError`, plus the user's own (`USER_INACTIVE`, `EMAIL_UNVERIFIED`)\n * and `STEP_UP_REQUIRED` of a link. Anything else is not the visitor's refusal\n * (`STORE_FAILED` is an outage, the rest a bug) and goes to `app.onError`.\n */\nconst REFUSALS: ReadonlySet<JanusErrorCode> = new Set<JanusErrorCode>([\n\t'FLOW_EXPIRED',\n\t'FLOW_MISMATCH',\n\t'FLOW_PURPOSE_MISMATCH',\n\t'RETURN_TO_INVALID',\n\t'PROVIDER_ERROR',\n\t'SOCIAL_PROVIDER_UNKNOWN',\n\t'SOCIAL_STEP_UP_UNMET',\n\t'SIGN_UP_DISABLED',\n\t'EMAIL_NOT_VERIFIED_FOR_LINK',\n\t'SOCIAL_ACCOUNT_TAKEN',\n\t'LAST_SIGN_IN_METHOD',\n\t'USER_INACTIVE',\n\t'EMAIL_UNVERIFIED',\n\t'STEP_UP_REQUIRED',\n]);\n\n/** Whether `error` is one of the visitor's refusals, rather than an outage or a bug. */\nexport function isRefusal(error: unknown): error is JanusError {\n\treturn error instanceof JanusError && REFUSALS.has(error.code);\n}\n\n/**\n * The answer to a refused callback: 302 to the flow's `returnTo` (or the\n * default) with `?socialError=<code>`, or the application's `onRefusal`.\n * The flow cookie is cleared unless the error was raised before the flow was\n * spent: the real callback may still come.\n */\nexport function refusedResponse<A extends SocialAuth>(\n\tc: Context,\n\terror: JanusError,\n\tflowCookieClear: string,\n\toptions: SocialRoutesOptions<A>,\n\tdefaultReturnTo: string,\n): Response | Promise<Response> {\n\tif (error.flowSpent !== false) {\n\t\tc.header('Set-Cookie', flowCookieClear, { append: true });\n\t}\n\tconst location = withSocialError(\n\t\tlocalPathOr(error.returnTo, defaultReturnTo),\n\t\terror.code,\n\t);\n\treturn options.onRefusal === undefined\n\t\t? c.redirect(location, 302)\n\t\t: options.onRefusal(c, error, location);\n}\n",
16
+ "import type { Session } from '@softistx/janus';\nimport type {\n\tCheckableOf,\n\tModelConfig,\n\tObjectTypeOf,\n\tPermissions,\n} from '@softistx/janus/permissions';\nimport type { Context, Hono, MiddlewareHandler } from 'hono';\nimport {\n\ttype PasskeyAuth,\n\ttype PasskeyRoutesOptions,\n\ttype PasskeyTypeApi,\n\ttype PasskeyTypeNames,\n\tpasskeyRoutes,\n} from './passkeys';\nimport {\n\ttype Awaitable,\n\ttype ObjectData,\n\ttype OptionsArgs,\n\tpermission,\n} from './permission';\nimport { provide } from './provide';\nimport {\n\ttype Auth,\n\ttype PrincipalEnv,\n\ttype SendSessionOptions,\n\ttype SessionEnv,\n\ttype SessionOptions,\n\tsendSession,\n\tsession,\n\tsignOut,\n\ttype UserOfAuth,\n} from './session';\nimport {\n\ttype SocialAuth,\n\ttype SocialRoutesOptions,\n\tsocialRoutes,\n} from './social';\n\n/** `session(auth, options?)`, with `auth` bound: the same three forms. */\nexport interface BoundSession<A> {\n\t<const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(\n\t\toptions: SessionOptions<T> & {\n\t\t\treadonly required: true;\n\t\t\treadonly apiKey: true;\n\t\t},\n\t): MiddlewareHandler<PrincipalEnv<A, T, true>>;\n\t<const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(\n\t\toptions: SessionOptions<T> & { readonly apiKey: true },\n\t): MiddlewareHandler<PrincipalEnv<A, T>>;\n\t<const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(\n\t\toptions: SessionOptions<T> & {\n\t\t\treadonly required: true;\n\t\t\treadonly apiKey?: false;\n\t\t},\n\t): MiddlewareHandler<SessionEnv<A, T, true>>;\n\t<const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(\n\t\toptions?: SessionOptions<T> & {\n\t\t\treadonly required?: false;\n\t\t\treadonly apiKey?: false;\n\t\t},\n\t): MiddlewareHandler<SessionEnv<A, T>>;\n\t<const T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type']>(\n\t\toptions: SessionOptions<T>,\n\t): MiddlewareHandler<SessionEnv<A, T>>;\n}\n\n/** `permission(access, …)`, with `access` bound. */\nexport type BoundPermission<C extends ModelConfig> = <\n\tconst T extends ObjectTypeOf<C>,\n\tconst P extends CheckableOf<C, T>,\n\tO extends ObjectData<C, T>,\n>(\n\tpermission: P,\n\ttype: T,\n\tload: (c: Context) => Awaitable<O | null>,\n\t...options: OptionsArgs<C, T, P, O>\n) => MiddlewareHandler<{\n\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\tVariables: { object: O };\n}>;\n\n/** The functions of this package that take `auth`, with `auth` bound. */\nexport interface BoundAuth<A> {\n\treadonly session: BoundSession<A>;\n\t/** `sendSession(c, auth, signedIn, options?)`: sets the cookies, answers the user. */\n\treadonly sendSession: <U>(\n\t\tc: Context,\n\t\tsignedIn: {\n\t\t\treadonly token: string;\n\t\t\treadonly session: Session;\n\t\t\treadonly user: U;\n\t\t\treadonly deviceToken?: string | null;\n\t\t},\n\t\toptions?: SendSessionOptions,\n\t) => U;\n\t/** `signOut(c, auth)`. */\n\treadonly signOut: (c: Context) => Promise<boolean>;\n}\n\n/** `socialRoutes(auth, options)`, with `auth` bound: present when `auth` configures `social`. */\nexport interface BoundSocial<A extends SocialAuth> {\n\treadonly socialRoutes: (options: SocialRoutesOptions<A>) => Hono;\n}\n\n/**\n * `passkeyRoutes(auth, options?)`, with `auth` bound: present when `auth`\n * configures `passkeys`. With several user types the `type` is required and\n * names one that does.\n */\nexport type BoundPasskeys<A> = A extends PasskeyTypeApi\n\t? { readonly passkeyRoutes: (options?: PasskeyRoutesOptions) => Hono }\n\t: [PasskeyTypeNames<A>] extends [never]\n\t\t? unknown\n\t\t: {\n\t\t\t\treadonly passkeyRoutes: <const T extends PasskeyTypeNames<A>>(\n\t\t\t\t\toptions: PasskeyRoutesOptions<T> & { readonly type: T },\n\t\t\t\t) => Hono;\n\t\t\t};\n\n/** What `bindJanus()` takes: the `janus()` instance, the `permissions()` one, or both. */\nexport interface Bindable {\n\treadonly auth?: Auth<{ readonly type: string }>;\n\t/** What `permission()` takes: a `permissions()` instance, or its `can`. */\n\treadonly access?: { readonly can: unknown };\n}\n\n/**\n * What `bindJanus(instances)` answers: `provide()` always; `session`,\n * `sendSession` and `signOut` with `auth`, `socialRoutes` when it configures `social`, `passkeyRoutes` when it configures `passkeys`; `permission` with `access`.\n */\nexport type Bound<I extends Bindable> = {\n\t/** `provide(instances)`: every instance bound, on the context. */\n\treadonly provide: () => MiddlewareHandler<{\n\t\t// biome-ignore lint/style/useNamingConvention: Hono's `Env` names the key, not us.\n\t\tVariables: { [K in keyof I & keyof Bindable]: I[K] };\n\t}>;\n} & (I['auth'] extends Auth<{ readonly type: string }>\n\t? BoundAuth<I['auth']> &\n\t\t\t(I['auth'] extends SocialAuth ? BoundSocial<I['auth']> : unknown) &\n\t\t\tBoundPasskeys<I['auth']>\n\t: unknown) &\n\t(I['access'] extends Pick<Permissions<infer C>, 'can'>\n\t\t? { readonly permission: BoundPermission<C> }\n\t\t: unknown);\n\n/**\n * This package's functions with the instances bound once, so no route\n * repeats them:\n *\n * ```ts\n * const j = bindJanus({ auth, access });\n * const app = new Hono()\n * .use(j.session(), j.provide())\n * .get('/records/:id', j.permission('view', 'record', recordOf), (c) => c.json(c.var.object));\n * ```\n *\n * The same functions, typed the same way: `j.session({ required: true })` is\n * `session(auth, { required: true })`. Only what is given is bound — a\n * `permission` without `access` is absent from the type.\n */\nexport function bindJanus<const I extends Bindable>(instances: I): Bound<I> {\n\tconst { auth, access } = instances;\n\tconst bound: Record<string, unknown> = {\n\t\tprovide: () => provide(instances),\n\t};\n\tif (auth !== undefined) {\n\t\tbound['session'] = (options: SessionOptions<string> = {}) =>\n\t\t\tsession(auth, options);\n\t\tbound['sendSession'] = (\n\t\t\tc: Context,\n\t\t\tsignedIn: Parameters<typeof sendSession>[2],\n\t\t\toptions?: SendSessionOptions,\n\t\t) => sendSession(c, auth, signedIn, options);\n\t\tbound['signOut'] = (c: Context) => signOut(c, auth);\n\t\tif ('social' in auth) {\n\t\t\tconst social = auth as SocialAuth;\n\t\t\tbound['socialRoutes'] = (options: SocialRoutesOptions<SocialAuth>) =>\n\t\t\t\tsocialRoutes(social, options);\n\t\t}\n\t\t// No runtime marker tells that `janus()` was given `passkeys`: the core\n\t\t// builds `auth.passkeys` for every type and throws on use. The types gate\n\t\t// `passkeyRoutes`; at runtime `passkeyRoutes()` refuses an `auth` or a\n\t\t// `type` with no surface, with a TypeError.\n\t\tbound['passkeyRoutes'] = (options?: PasskeyRoutesOptions) =>\n\t\t\tpasskeyRoutes(auth as PasskeyAuth & PasskeyTypeApi, options);\n\t}\n\tif (access !== undefined) {\n\t\tconst guard = permission as unknown as (\n\t\t\taccess: object,\n\t\t\t...rest: unknown[]\n\t\t) => MiddlewareHandler;\n\t\tbound['permission'] = (...rest: unknown[]) => guard(access, ...rest);\n\t}\n\treturn bound as Bound<I>;\n}\n",
17
+ "import {\n\tJanusError,\n\ttype JanusErrorCode,\n\tstatusOf as janusStatusOf,\n} from '@softistx/janus';\nimport type { Context, ErrorHandler } from 'hono';\nimport type { HTTPException } from 'hono/http-exception';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\n\n/**\n * The status each code deserves: `@softistx/janus`'s own table, typed as the\n * `ContentfulStatusCode` `c.json()` takes. Kept as an export of its own so a\n * route that answers by hand reads the same status `janusErrors()` does.\n *\n * `STORE_FAILED` is 503 and nothing else — **an outage is not a negative\n * answer**, and a 401 or a 404 would tell every user they do not exist.\n */\nexport function statusOf(code: JanusErrorCode): ContentfulStatusCode {\n\treturn janusStatusOf(code);\n}\n\n/**\n * The body a refusal is answered with: its `code`, and only what the client\n * can act on — the fields that failed the schema, the policy's minimum, the\n * attempts a challenge has left, the key or passkey limit a user hit, the field of an API key or a passkey's name that was refused, the seconds a throttled sign-in, a\n * throttled request for an e-mail or an app's code past the user's window waits.\n * Never `reason` (an invitation code's refusal reason is GraphQL's alone for now), `login`, a hash prefix or a cause: those are for your logs.\n */\nexport function bodyOf(error: JanusError): {\n\treadonly code: JanusErrorCode;\n\treadonly issues?: JanusError['issues'];\n\treadonly minLength?: number;\n\treadonly attemptsLeft?: number;\n\treadonly retryAfter?: number;\n\treadonly maxActive?: number;\n\treadonly field?: JanusError['field'];\n} {\n\tswitch (error.code) {\n\t\tcase 'USER_INVALID':\n\t\t\treturn { code: error.code, issues: error.issues ?? [] };\n\t\tcase 'PASSWORD_TOO_SHORT':\n\t\t\treturn error.minLength === undefined\n\t\t\t\t? { code: error.code }\n\t\t\t\t: { code: error.code, minLength: error.minLength };\n\t\tcase 'CODE_INVALID':\n\t\t\treturn {\n\t\t\t\tcode: error.code,\n\t\t\t\t...(error.attemptsLeft === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { attemptsLeft: error.attemptsLeft }),\n\t\t\t\t...(error.retryAfter === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { retryAfter: error.retryAfter }),\n\t\t\t};\n\t\tcase 'CREDENTIALS_INVALID':\n\t\tcase 'MAIL_THROTTLED':\n\t\t\treturn error.retryAfter === undefined\n\t\t\t\t? { code: error.code }\n\t\t\t\t: { code: error.code, retryAfter: error.retryAfter };\n\t\tcase 'API_KEY_LIMIT':\n\t\tcase 'INVITATION_LIMIT':\n\t\tcase 'PASSKEY_LIMIT':\n\t\t\treturn error.maxActive === undefined\n\t\t\t\t? { code: error.code }\n\t\t\t\t: { code: error.code, maxActive: error.maxActive };\n\t\tcase 'API_KEY_INVALID':\n\t\tcase 'INVITATION_INVALID':\n\t\tcase 'PASSKEY_INVALID':\n\t\t\treturn error.field === undefined\n\t\t\t\t? { code: error.code }\n\t\t\t\t: { code: error.code, field: error.field };\n\t\tdefault:\n\t\t\treturn { code: error.code };\n\t}\n}\n\n/**\n * Hono's own answer to an error it was not told about, copied from its\n * default handler: the response of an `HTTPException` — merged with the\n * headers the route set before throwing — and a logged 500 for anything else.\n */\nfunction honoDefault(error: Error | HTTPException, c: Context): Response {\n\tif ('getResponse' in error) {\n\t\tconst response = error.getResponse();\n\t\treturn c.newResponse(response.body, response);\n\t}\n\tconsole.error(error);\n\treturn c.text('Internal Server Error', 500);\n}\n\n/** What `janusErrors()` takes. */\nexport interface JanusErrorsOptions {\n\t/**\n\t * Called with every `JanusError` answered 5xx — `STORE_FAILED`,\n\t * `UNSUPPORTED`, `PERMISSION_DEPTH`: the ones the server must fix, not the\n\t * client — before it is answered. Its `slot`, `operation`, `reason` and\n\t * `cause` are for your logs; the body never carries them.\n\t *\n\t * **It cannot stop the answer**: one that throws, or rejects, is a\n\t * `process.emitWarning`, and the 503 is sent all the same.\n\t */\n\treadonly report?: (error: JanusError, c: Context) => unknown;\n\t/** Every error that is not a `JanusError`. Hono's own handling when absent. */\n\treadonly fallback?: ErrorHandler;\n}\n\n/**\n * An `app.onError` handler: every `JanusError` answered with its status and\n * `bodyOf(error)` — and a throttled sign-in, or a request past its e-mails\n * (`MAIL_THROTTLED`, 429) or an app's code past the user's window\n * (`CODE_INVALID`, 401), with a `Retry-After` header, its `retryAfter` in\n * seconds; anything else handed to `fallback` — Hono's own\n * behaviour when absent.\n *\n * Works for either side of `@softistx/janus`: `can()`'s `STORE_FAILED` is a 503\n * here too, never a 403.\n *\n * ```ts\n * app.onError(janusErrors({ report: (error) => logger.error(error) }));\n * ```\n */\nexport function janusErrors(options: JanusErrorsOptions = {}): ErrorHandler {\n\tconst { report, fallback = honoDefault } = options;\n\treturn (error, c) => {\n\t\tif (!(error instanceof JanusError)) return fallback(error, c);\n\t\tconst status = statusOf(error.code);\n\t\tif (status >= 500 && report !== undefined) reportSafely(report, error, c);\n\t\tconst headers =\n\t\t\terror.retryAfter === undefined\n\t\t\t\t? undefined\n\t\t\t\t: { 'retry-after': String(error.retryAfter) };\n\t\treturn c.json(bodyOf(error), status, headers);\n\t};\n}\n\n/** `report`, whose own failure is a warning — never a lost answer. */\nfunction reportSafely(\n\treport: NonNullable<JanusErrorsOptions['report']>,\n\terror: JanusError,\n\tc: Context,\n): void {\n\tconst warn = (failure: unknown) =>\n\t\tprocess.emitWarning(\n\t\t\t`janusErrors: report failed on ${error.code}: ${failure instanceof Error ? failure.name : typeof failure}`,\n\t\t);\n\ttry {\n\t\t// A thenable of any make, as a native promise: its rejection warns too.\n\t\tPromise.resolve(report(error, c)).then(undefined, warn);\n\t} catch (failure) {\n\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MAAM,OAAO,CAAC,YACb,QAAQ,YACP,iCAAiC,MAAM,SAAS,mBAAmB,QAAQ,QAAQ,OAAO,OAAO,SAClG;AAAA,EACD,IAAI;AAAA,IAEH,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAAC,EAAE,KAAK,WAAW,IAAI;AAAA,IACrD,OAAO,SAAS;AAAA,IACjB,KAAK,OAAO;AAAA;AAAA;",
20
+ "debugId": "DADF220056EDEB4964756E2164756E21",
21
+ "names": []
22
+ }
@@ -0,0 +1,8 @@
1
+ import type { Context } from 'hono';
2
+ /**
3
+ * Marks the response of this request as not cacheable: `Cache-Control:
4
+ * no-store`. A body, a redirect or a cookie that carries a session token, a
5
+ * single-use challenge or a social flow is a secret no cache may keep.
6
+ */
7
+ export declare function noStore(c: Context): void;
8
+ //# sourceMappingURL=no-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-store.d.ts","sourceRoot":"","sources":["../src/no-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAExC"}
@@ -0,0 +1,12 @@
1
+ /** Reading the JSON body of a passkey route: never a refusal of its own, the core's answer does. */
2
+ import type { Context } from 'hono';
3
+ /**
4
+ * The request's JSON object, or `{}` for a body that is missing, is not JSON
5
+ * or is not an object. The core then refuses the absent field with its own
6
+ * code (`TOKEN_UNKNOWN` for a challenge, `PASSKEY_INVALID` for a name), so a
7
+ * malformed request costs the visitor nothing and gets a code, not a 500.
8
+ */
9
+ export declare function bodyOf(c: Context): Promise<Readonly<Record<string, unknown>>>;
10
+ /** A string field, or `''` for anything else: the core refuses an empty challenge. */
11
+ export declare function textOf(body: Readonly<Record<string, unknown>>, key: string): string;
12
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/passkeys/body.ts"],"names":[],"mappings":"AAAA,oGAAoG;AAEpG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,wBAAsB,MAAM,CAC3B,CAAC,EAAE,OAAO,GACR,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAK5C;AAED,sFAAsF;AACtF,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,UAG1E"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The passkey routes for Hono, gathered from the files beside this one:
3
+ * `routes.ts` (the sub-app) and `types.ts` (its options and the part of
4
+ * `auth` it calls).
5
+ */
6
+ export { passkeyRoutes } from './routes';
7
+ export type { PasskeyAuth, PasskeyRoutesOptions, PasskeySurface, PasskeysSurface, PasskeyTypeApi, PasskeyTypeNames, StepUpPasskeySurface, } from './types';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/passkeys/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EACX,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** The passkey routes: one named handler per route, assembled by `passkeyRoutes()`. */
2
+ import { Hono } from 'hono';
3
+ import type { PasskeyAuth, PasskeyRoutesOptions, PasskeySurface } from './types';
4
+ /**
5
+ * The passkey routes, as a Hono sub-app to `route()` under a prefix. All are
6
+ * JSON; the five behind `session()` answer 401 with no body to an anonymous
7
+ * request:
8
+ *
9
+ * - `GET /` — the user's passkeys: `{ passkeys }`;
10
+ * - `POST /registration-options` — `{ options, challenge, expiresAt }`
11
+ * (`Cache-Control: no-store`, as `POST /step-up`: the challenge is single-use);
12
+ * - `POST /` — `{ challenge, response, name }`: registers, 201 with the
13
+ * passkey (fresh: `STEP_UP_REQUIRED` past the core's `freshWithin`);
14
+ * - `POST /:credentialId/rename` — `{ name }`: 204, or 404;
15
+ * - `DELETE /:credentialId` — 204, or 404 (fresh, like registering);
16
+ * - `POST /sign-in` — `{ challenge, assertion }`, no session needed: answers
17
+ * a sign-in's second factor, sets the session cookie, `200 { id }`;
18
+ * - `POST /step-up` and `POST /step-up/confirm` — behind `session()`:
19
+ * `{ challenge, options, expiresAt }`, then `{ challenge, assertion }` →
20
+ * 204, or 409 when the user cannot step up by passkey.
21
+ *
22
+ * ```ts
23
+ * app.route('/auth/passkeys', passkeyRoutes(auth));
24
+ * app.onError(janusErrors());
25
+ * ```
26
+ *
27
+ * Every refusal is thrown to `app.onError`: with `janusErrors()`,
28
+ * `PASSKEY_INVALID` is 400, `PASSKEY_TAKEN` and `PASSKEY_LIMIT` 409,
29
+ * `CODE_INVALID` 401 with `attemptsLeft`, `STORE_FAILED` 503.
30
+ */
31
+ export declare function passkeyRoutes<A extends PasskeyAuth, const T extends string = never>(auth: A & PasskeySurface<T>, options?: PasskeyRoutesOptions<T>): Hono;
32
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/passkeys/routes.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAGvF,OAAO,EAAgB,IAAI,EAA0B,MAAM,MAAM,CAAC;AAKlE,OAAO,KAAK,EACX,WAAW,EACX,oBAAoB,EACpB,cAAc,EAGd,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAC5B,CAAC,SAAS,WAAW,EACrB,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,KAAK,EAC7B,IAAI,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,oBAAoB,CAAC,CAAC,CAAM,GAAG,IAAI,CA8B1E"}
@@ -0,0 +1,105 @@
1
+ /** What `passkeyRoutes()` takes and what it needs of `auth`. */
2
+ import type { Authenticated, Passkey, PasskeyRegistrationOptions, Session, SignedIn, SignInOptions, StepUpByPasskey } from '@softistx/janus';
3
+ import type { Context, MiddlewareHandler } from 'hono';
4
+ import type { DeviceCookieOptions } from '../device';
5
+ import type { Auth } from '../session';
6
+ /** The part of `auth.passkeys` these routes call. */
7
+ export interface PasskeysSurface {
8
+ registrationOptions(user: {
9
+ readonly id: string;
10
+ }): Promise<PasskeyRegistrationOptions>;
11
+ register(current: Authenticated<{
12
+ readonly id: string;
13
+ }>, input: {
14
+ readonly challenge: string;
15
+ readonly response: unknown;
16
+ readonly name: string;
17
+ }): Promise<Passkey>;
18
+ list(user: {
19
+ readonly id: string;
20
+ }): Promise<readonly Passkey[]>;
21
+ rename(user: {
22
+ readonly id: string;
23
+ }, credentialId: string, name: string): Promise<boolean>;
24
+ remove(current: Authenticated<{
25
+ readonly id: string;
26
+ }>, credentialId: string): Promise<boolean>;
27
+ }
28
+ /** The part of `auth.stepUp` the step-up routes call. */
29
+ export interface StepUpPasskeySurface {
30
+ request(user: {
31
+ readonly id: string;
32
+ }, options: {
33
+ readonly via: 'passkey';
34
+ }): Promise<StepUpByPasskey<unknown>>;
35
+ confirmPasskey(request: Request, challenge: string, assertion: unknown): Promise<Session>;
36
+ }
37
+ /**
38
+ * What a user type answers once `janus()` is given `passkeys` and a
39
+ * `secondFactor`. The core builds `stepUp` for every type; it is optional
40
+ * only in this structural type.
41
+ */
42
+ export interface PasskeyTypeApi {
43
+ readonly passkeys: PasskeysSurface;
44
+ readonly secondFactor: {
45
+ confirmPasskey(challenge: string, assertion: unknown, options?: SignInOptions): Promise<SignedIn<{
46
+ readonly id: string;
47
+ }>>;
48
+ };
49
+ readonly stepUp?: StepUpPasskeySurface;
50
+ }
51
+ /**
52
+ * What `passkeyRoutes()` calls of every `janus()` answer: `authenticate` and
53
+ * the session `cookie`. The passkey surface is required beside it by
54
+ * {@link PasskeySurface}.
55
+ */
56
+ export type PasskeyAuth = Auth<{
57
+ readonly type: string;
58
+ readonly id: string;
59
+ }>;
60
+ /**
61
+ * What `auth` must carry besides {@link PasskeyAuth}: the surface of
62
+ * {@link PasskeyTypeApi} at its top (one user type; `type` then only names
63
+ * it for the session), or under the named `type` with several (`T` is the
64
+ * `type` given). An instance whose `janus()` was given no `passkeys` carries
65
+ * neither, and is refused.
66
+ */
67
+ export type PasskeySurface<T extends string> = [T] extends [never] ? PasskeyTypeApi : PasskeyTypeApi | {
68
+ readonly [K in T]: PasskeyTypeApi;
69
+ };
70
+ /** The user types of `A` that answer the passkey surface: what `type` may name. */
71
+ export type PasskeyTypeNames<A> = Extract<{
72
+ [K in keyof A]: A[K] extends PasskeyTypeApi ? K : never;
73
+ }[keyof A], string>;
74
+ /** What `passkeyRoutes()` takes besides `auth`. */
75
+ export interface PasskeyRoutesOptions<T extends string = string> {
76
+ /**
77
+ * The user type that registers, lists and signs in with passkeys. Needed
78
+ * when several user types are configured (`auth.<type>.passkeys` is then
79
+ * the surface); it also limits the session to that type's users.
80
+ */
81
+ readonly type?: T;
82
+ /**
83
+ * The middleware that guards the routes behind a session, when
84
+ * `session(auth, { required: true })` is not it. It must answer 401 to an
85
+ * anonymous request. The handlers re-read the session from the request
86
+ * (`auth.authenticate`), as `socialRoutes` does, so it need not set
87
+ * anything on the context.
88
+ */
89
+ readonly session?: MiddlewareHandler;
90
+ /**
91
+ * Present when `janus({ devices })` is wired: the sign-in route reads the
92
+ * device cookie (named by these options) as the sign-in's `device`, and
93
+ * sets it again.
94
+ */
95
+ readonly device?: DeviceCookieOptions;
96
+ /**
97
+ * What `POST /sign-in` answers once the session cookie is set. Default:
98
+ * `200 { id }`. A route that also hands the token to a bearer client, or
99
+ * redirects, answers here.
100
+ */
101
+ readonly onSignedIn?: (c: Context, signedIn: SignedIn<{
102
+ readonly id: string;
103
+ }>) => Response | Promise<Response>;
104
+ }
105
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/passkeys/types.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,KAAK,EACX,aAAa,EACb,OAAO,EACP,0BAA0B,EAC1B,OAAO,EACP,QAAQ,EACR,aAAa,EACb,eAAe,EACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC/B,mBAAmB,CAAC,IAAI,EAAE;QACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACxC,QAAQ,CACP,OAAO,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,EAC/C,KAAK,EAAE;QACN,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;QAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACtB,GACC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;IACjE,MAAM,CACL,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAC7B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACV,OAAO,C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E,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,cAAc;CAAE,CAAC;AAE1D,mFAAmF;AACnF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,OAAO,CACxC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,cAAc,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,EACpE,MAAM,CACN,CAAC;AAEF,mDAAmD;AACnD,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC9D;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,CACrB,CAAC,EAAE,OAAO,EACV,QAAQ,EAAE,QAAQ,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,KACvC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClC"}
@@ -0,0 +1,80 @@
1
+ import type { CheckableOf, CtxOf, FieldsOf, ModelConfig, ObjectTypeOf, Permissions, SubjectRef } from '@softistx/janus/permissions';
2
+ import type { Context, MiddlewareHandler } from 'hono';
3
+ /**
4
+ * An object of type `T` as the application loads it: its id, **every field a
5
+ * `fromField` of its type reads**, and whatever else it carries. The type is
6
+ * the middleware's to add.
7
+ */
8
+ export type ObjectData<C extends ModelConfig, T extends ObjectTypeOf<C>> = {
9
+ readonly id: string;
10
+ } & {
11
+ readonly [F in FieldsOf<C, T>]: string | null;
12
+ };
13
+ export type Awaitable<V> = V | Promise<V>;
14
+ /**
15
+ * The options of `permission()`: `ctx` required exactly when a condition of
16
+ * the permission is reachable, as for `can()`.
17
+ */
18
+ export type PermissionOptions<C extends ModelConfig, T extends ObjectTypeOf<C>, P extends string, O> = {
19
+ /**
20
+ * Who asks. `c.var.user` — set by `session()` — when absent; pass it when
21
+ * your users are not `janus()`'s. `null` is anonymous.
22
+ */
23
+ readonly subject?: (c: Context) => Awaitable<SubjectRef<C> | null>;
24
+ } & ([CtxOf<C, T, P>] extends [never] ? {
25
+ readonly ctx?: never;
26
+ } : {
27
+ /** The condition's context, read from the request and the loaded object. */
28
+ readonly ctx: (c: Context, object: O) => Awaitable<CtxOf<C, T, P>>;
29
+ });
30
+ /**
31
+ * The options argument: required exactly when `ctx` is. Loose when `T` or `P`
32
+ * is its whole constraint — what the compiler falls back to when the object
33
+ * type or the permission was wrong — so the error names that argument, not a
34
+ * missing one; the rule `can()` follows.
35
+ */
36
+ export type OptionsArgs<C extends ModelConfig, T extends ObjectTypeOf<C>, P extends string, O> = [ObjectTypeOf<C>] extends [T] ? IsSingle<ObjectTypeOf<C>> extends true ? PermissionArgs<C, T, P, O> : [options?: LooseOptions] : PermissionArgs<C, T, P, O>;
37
+ /** `OptionsArgs` once `T` is known right: loose when `P` is its whole constraint. */
38
+ type PermissionArgs<C extends ModelConfig, T extends ObjectTypeOf<C>, P extends string, O> = [CheckableOf<C, T>] extends [P] ? IsSingle<CheckableOf<C, T>> extends true ? StrictArgs<C, T, P, O> : [options?: LooseOptions] : StrictArgs<C, T, P, O>;
39
+ type StrictArgs<C extends ModelConfig, T extends ObjectTypeOf<C>, P extends string, O> = [CtxOf<C, T, P>] extends [never] ? [options?: PermissionOptions<C, T, P, O>] : [options: PermissionOptions<C, T, P, O>];
40
+ type LooseOptions = {
41
+ readonly subject?: (c: Context) => unknown;
42
+ readonly ctx?: (c: Context, object: never) => unknown;
43
+ };
44
+ type UnionToIntersection<U> = (U extends unknown ? (union: U) => void : never) extends (intersection: infer I) => void ? I : never;
45
+ /** Whether `U` is one type rather than a union of several. */
46
+ type IsSingle<U> = [U] extends [UnionToIntersection<U>] ? true : false;
47
+ /**
48
+ * The middleware that lets a request through only if its subject holds
49
+ * `permission` on an object of `type`: it loads the object once, with `load`,
50
+ * checks it with `access.can`, and hands it to the route as `c.var.object`.
51
+ *
52
+ * | The request | Answered |
53
+ * | --- | --- |
54
+ * | anonymous | 401, no body — before the object is loaded |
55
+ * | `load` answers `null` | 404, no body |
56
+ * | a denial | 403, no body |
57
+ * | allowed | the route runs, `c.var.object` set |
58
+ *
59
+ * One per route: a second one throws a `TypeError`, since both would claim
60
+ * `c.var.object`. A parent object is checked through an arrow in the model.
61
+ *
62
+ * **A failure throws**, as everywhere: a store that cannot answer is
63
+ * `STORE_FAILED`, never a 403 — `janusErrors()` answers it 503.
64
+ */
65
+ export declare function permission<C extends ModelConfig, const T extends ObjectTypeOf<C>, const P extends CheckableOf<C, T>, O extends ObjectData<C, T>>(access: Pick<Permissions<C>, 'can'>, permission: P, type: T, load: (c: Context) => Awaitable<O | null>, ...options: OptionsArgs<C, T, P, O>): MiddlewareHandler<{
66
+ Variables: {
67
+ object: O;
68
+ };
69
+ }>;
70
+ /**
71
+ * A `load` reading one path parameter: `find(id)`, or `null` — a 404 — when
72
+ * the route has no such parameter.
73
+ *
74
+ * ```ts
75
+ * permission(access, 'view', 'record', byParam('id', (id) => records.find(id)))
76
+ * ```
77
+ */
78
+ export declare function byParam<O>(name: string, find: (id: string) => Awaitable<O | null>): (c: Context) => Awaitable<O | null>;
79
+ export {};
80
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,KAAK,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,UAAU,EACV,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,C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CAAC,GAAG,IAAI,CAAC,CAKrC"}
@@ -0,0 +1,19 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ /** What `provide()` takes: the `janus()` instance, the `permissions()` one, or both. */
3
+ export interface Instances {
4
+ readonly auth?: object;
5
+ readonly access?: object;
6
+ }
7
+ /**
8
+ * The middleware that puts the instances on the context — `c.var.auth`, and
9
+ * `c.var.access` — so a route writes users and tuples through them rather
10
+ * than through a module import: `c.var.access.grant(record, 'owners', user)`.
11
+ *
12
+ * Only what is passed is set, and typed.
13
+ */
14
+ export declare function provide<const I extends Instances>(instances: I): MiddlewareHandler<{
15
+ Variables: {
16
+ [K in keyof I & keyof Instances]: I[K];
17
+ };
18
+ }>;
19
+ //# sourceMappingURL=provide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provide.d.ts","sourceRoot":"","sources":["../src/provide.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C,wFAAwF;AACxF,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,EAChD,SAAS,EAAE,CAAC,GACV,iBAAiB,CAAC;IAEpB,SAAS,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;KAAE,CAAC;CACtD,CAAC,CAMD"}