@softistx/janus-graphql 0.0.0-stage → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +716 -2
  3. package/dist/api-keys/index.d.ts +11 -0
  4. package/dist/api-keys/index.d.ts.map +1 -0
  5. package/dist/api-keys/resolvers/deps.d.ts +39 -0
  6. package/dist/api-keys/resolvers/deps.d.ts.map +1 -0
  7. package/dist/api-keys/resolvers/index.d.ts +39 -0
  8. package/dist/api-keys/resolvers/index.d.ts.map +1 -0
  9. package/dist/api-keys/resolvers/list.d.ts +16 -0
  10. package/dist/api-keys/resolvers/list.d.ts.map +1 -0
  11. package/dist/api-keys/resolvers/manage.d.ts +17 -0
  12. package/dist/api-keys/resolvers/manage.d.ts.map +1 -0
  13. package/dist/api-keys/sdl.d.ts +14 -0
  14. package/dist/api-keys/sdl.d.ts.map +1 -0
  15. package/dist/api-keys/shape.d.ts +38 -0
  16. package/dist/api-keys/shape.d.ts.map +1 -0
  17. package/dist/api-keys/types.d.ts +149 -0
  18. package/dist/api-keys/types.d.ts.map +1 -0
  19. package/dist/avatar/index.d.ts +32 -0
  20. package/dist/avatar/index.d.ts.map +1 -0
  21. package/dist/avatar/resolvers.d.ts +41 -0
  22. package/dist/avatar/resolvers.d.ts.map +1 -0
  23. package/dist/avatar/sdl.d.ts +16 -0
  24. package/dist/avatar/sdl.d.ts.map +1 -0
  25. package/dist/bad-input.d.ts +17 -0
  26. package/dist/bad-input.d.ts.map +1 -0
  27. package/dist/connection/connection.d.ts +36 -0
  28. package/dist/connection/connection.d.ts.map +1 -0
  29. package/dist/connection/credential.d.ts +34 -0
  30. package/dist/connection/credential.d.ts.map +1 -0
  31. package/dist/connection/types.d.ts +61 -0
  32. package/dist/connection/types.d.ts.map +1 -0
  33. package/dist/context/create.d.ts +32 -0
  34. package/dist/context/create.d.ts.map +1 -0
  35. package/dist/context/index.d.ts +9 -0
  36. package/dist/context/index.d.ts.map +1 -0
  37. package/dist/context/registry.d.ts +72 -0
  38. package/dist/context/registry.d.ts.map +1 -0
  39. package/dist/context/resolve.d.ts +20 -0
  40. package/dist/context/resolve.d.ts.map +1 -0
  41. package/dist/device.d.ts +28 -0
  42. package/dist/device.d.ts.map +1 -0
  43. package/dist/directives/apply.d.ts +51 -0
  44. package/dist/directives/apply.d.ts.map +1 -0
  45. package/dist/directives/guard.d.ts +22 -0
  46. package/dist/directives/guard.d.ts.map +1 -0
  47. package/dist/directives/permission/enforce.d.ts +24 -0
  48. package/dist/directives/permission/enforce.d.ts.map +1 -0
  49. package/dist/directives/permission/model.d.ts +35 -0
  50. package/dist/directives/permission/model.d.ts.map +1 -0
  51. package/dist/directives/permission/path.d.ts +31 -0
  52. package/dist/directives/permission/path.d.ts.map +1 -0
  53. package/dist/directives/permission/validate.d.ts +42 -0
  54. package/dist/directives/permission/validate.d.ts.map +1 -0
  55. package/dist/directives/read.d.ts +43 -0
  56. package/dist/directives/read.d.ts.map +1 -0
  57. package/dist/directives/validate.d.ts +39 -0
  58. package/dist/directives/validate.d.ts.map +1 -0
  59. package/dist/directives/words.d.ts +7 -0
  60. package/dist/directives/words.d.ts.map +1 -0
  61. package/dist/errors/denial.d.ts +6 -0
  62. package/dist/errors/denial.d.ts.map +1 -0
  63. package/dist/errors/index.d.ts +12 -0
  64. package/dist/errors/index.d.ts.map +1 -0
  65. package/dist/errors/janus-error.d.ts +20 -0
  66. package/dist/errors/janus-error.d.ts.map +1 -0
  67. package/dist/errors/mask.d.ts +69 -0
  68. package/dist/errors/mask.d.ts.map +1 -0
  69. package/dist/fresh.d.ts +44 -0
  70. package/dist/fresh.d.ts.map +1 -0
  71. package/dist/helpers.d.ts +56 -0
  72. package/dist/helpers.d.ts.map +1 -0
  73. package/dist/index.d.ts +86 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +3393 -0
  76. package/dist/index.js.map +75 -0
  77. package/dist/invitations/index.d.ts +12 -0
  78. package/dist/invitations/index.d.ts.map +1 -0
  79. package/dist/invitations/resolvers/anonymous.d.ts +11 -0
  80. package/dist/invitations/resolvers/anonymous.d.ts.map +1 -0
  81. package/dist/invitations/resolvers/deps.d.ts +38 -0
  82. package/dist/invitations/resolvers/deps.d.ts.map +1 -0
  83. package/dist/invitations/resolvers/index.d.ts +37 -0
  84. package/dist/invitations/resolvers/index.d.ts.map +1 -0
  85. package/dist/invitations/resolvers/owner.d.ts +17 -0
  86. package/dist/invitations/resolvers/owner.d.ts.map +1 -0
  87. package/dist/invitations/sdl/accept.d.ts +7 -0
  88. package/dist/invitations/sdl/accept.d.ts.map +1 -0
  89. package/dist/invitations/sdl/index.d.ts +14 -0
  90. package/dist/invitations/sdl/index.d.ts.map +1 -0
  91. package/dist/invitations/sdl/owner.d.ts +8 -0
  92. package/dist/invitations/sdl/owner.d.ts.map +1 -0
  93. package/dist/invitations/shape.d.ts +63 -0
  94. package/dist/invitations/shape.d.ts.map +1 -0
  95. package/dist/invitations/types/index.d.ts +5 -0
  96. package/dist/invitations/types/index.d.ts.map +1 -0
  97. package/dist/invitations/types/options.d.ts +104 -0
  98. package/dist/invitations/types/options.d.ts.map +1 -0
  99. package/dist/invitations/types/out.d.ts +136 -0
  100. package/dist/invitations/types/out.d.ts.map +1 -0
  101. package/dist/invitations/types/surface.d.ts +18 -0
  102. package/dist/invitations/types/surface.d.ts.map +1 -0
  103. package/dist/map-code.d.ts +10 -0
  104. package/dist/map-code.d.ts.map +1 -0
  105. package/dist/mask-error.d.ts +18 -0
  106. package/dist/mask-error.d.ts.map +1 -0
  107. package/dist/memo.d.ts +16 -0
  108. package/dist/memo.d.ts.map +1 -0
  109. package/dist/options.d.ts +17 -0
  110. package/dist/options.d.ts.map +1 -0
  111. package/dist/passkeys/deps.d.ts +23 -0
  112. package/dist/passkeys/deps.d.ts.map +1 -0
  113. package/dist/passkeys/first-factor.types.d.ts +38 -0
  114. package/dist/passkeys/first-factor.types.d.ts.map +1 -0
  115. package/dist/passkeys/index.d.ts +14 -0
  116. package/dist/passkeys/index.d.ts.map +1 -0
  117. package/dist/passkeys/resolvers.d.ts +23 -0
  118. package/dist/passkeys/resolvers.d.ts.map +1 -0
  119. package/dist/passkeys/sdl.d.ts +14 -0
  120. package/dist/passkeys/sdl.d.ts.map +1 -0
  121. package/dist/passkeys/shape.d.ts +14 -0
  122. package/dist/passkeys/shape.d.ts.map +1 -0
  123. package/dist/passkeys/sign-in.resolvers.d.ts +19 -0
  124. package/dist/passkeys/sign-in.resolvers.d.ts.map +1 -0
  125. package/dist/passkeys/sign-in.sdl.d.ts +16 -0
  126. package/dist/passkeys/sign-in.sdl.d.ts.map +1 -0
  127. package/dist/passkeys/types.d.ts +193 -0
  128. package/dist/passkeys/types.d.ts.map +1 -0
  129. package/dist/plugin.d.ts +59 -0
  130. package/dist/plugin.d.ts.map +1 -0
  131. package/dist/renewal.d.ts +51 -0
  132. package/dist/renewal.d.ts.map +1 -0
  133. package/dist/report.d.ts +29 -0
  134. package/dist/report.d.ts.map +1 -0
  135. package/dist/sdl.d.ts +12 -0
  136. package/dist/sdl.d.ts.map +1 -0
  137. package/dist/second-factor/index.d.ts +12 -0
  138. package/dist/second-factor/index.d.ts.map +1 -0
  139. package/dist/second-factor/resolvers/deps.d.ts +39 -0
  140. package/dist/second-factor/resolvers/deps.d.ts.map +1 -0
  141. package/dist/second-factor/resolvers/index.d.ts +39 -0
  142. package/dist/second-factor/resolvers/index.d.ts.map +1 -0
  143. package/dist/second-factor/resolvers/sign-in.d.ts +10 -0
  144. package/dist/second-factor/resolvers/sign-in.d.ts.map +1 -0
  145. package/dist/second-factor/resolvers/status.d.ts +10 -0
  146. package/dist/second-factor/resolvers/status.d.ts.map +1 -0
  147. package/dist/second-factor/resolvers/step-up.d.ts +16 -0
  148. package/dist/second-factor/resolvers/step-up.d.ts.map +1 -0
  149. package/dist/second-factor/resolvers/writes.d.ts +19 -0
  150. package/dist/second-factor/resolvers/writes.d.ts.map +1 -0
  151. package/dist/second-factor/sdl.d.ts +14 -0
  152. package/dist/second-factor/sdl.d.ts.map +1 -0
  153. package/dist/second-factor/shape.d.ts +18 -0
  154. package/dist/second-factor/shape.d.ts.map +1 -0
  155. package/dist/second-factor/types/index.d.ts +5 -0
  156. package/dist/second-factor/types/index.d.ts.map +1 -0
  157. package/dist/second-factor/types/options.d.ts +61 -0
  158. package/dist/second-factor/types/options.d.ts.map +1 -0
  159. package/dist/second-factor/types/out.d.ts +84 -0
  160. package/dist/second-factor/types/out.d.ts.map +1 -0
  161. package/dist/second-factor/types/surface.d.ts +89 -0
  162. package/dist/second-factor/types/surface.d.ts.map +1 -0
  163. package/dist/social/index.d.ts +10 -0
  164. package/dist/social/index.d.ts.map +1 -0
  165. package/dist/social/resolvers.d.ts +25 -0
  166. package/dist/social/resolvers.d.ts.map +1 -0
  167. package/dist/social/sdl.d.ts +13 -0
  168. package/dist/social/sdl.d.ts.map +1 -0
  169. package/dist/social/shape.d.ts +11 -0
  170. package/dist/social/shape.d.ts.map +1 -0
  171. package/dist/social/types.d.ts +160 -0
  172. package/dist/social/types.d.ts.map +1 -0
  173. package/dist/surface/api.d.ts +16 -0
  174. package/dist/surface/api.d.ts.map +1 -0
  175. package/dist/surface/request.d.ts +10 -0
  176. package/dist/surface/request.d.ts.map +1 -0
  177. package/dist/surface/signed-in.d.ts +30 -0
  178. package/dist/surface/signed-in.d.ts.map +1 -0
  179. package/dist/types.d.ts +117 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/wiring.d.ts +56 -0
  182. package/dist/wiring.d.ts.map +1 -0
  183. package/docs/README.md +26 -0
  184. package/docs/guide/api-keys.md +365 -0
  185. package/docs/guide/avatars.md +129 -0
  186. package/docs/guide/context.md +371 -0
  187. package/docs/guide/directives.md +371 -0
  188. package/docs/guide/errors.md +318 -0
  189. package/docs/guide/federation.md +71 -0
  190. package/docs/guide/invitations.md +269 -0
  191. package/docs/guide/passkeys.md +207 -0
  192. package/docs/guide/second-factor.md +238 -0
  193. package/docs/guide/social.md +190 -0
  194. package/docs/guide/step-up.md +208 -0
  195. package/docs/guide/subscriptions.md +255 -0
  196. package/docs/guide/telemetry.md +45 -0
  197. package/docs/roadmap.md +124 -0
  198. package/docs/troubleshooting.md +1265 -0
  199. package/graphql/janus-api-keys.graphqls +237 -0
  200. package/graphql/janus-avatar.graphqls +19 -0
  201. package/graphql/janus-invitations.graphqls +280 -0
  202. package/graphql/janus-passkey-sign-in.graphqls +40 -0
  203. package/graphql/janus-passkeys.graphqls +134 -0
  204. package/graphql/janus-second-factor.graphqls +199 -0
  205. package/graphql/janus-social.graphqls +155 -0
  206. package/graphql/janus.graphqls +44 -0
  207. package/package.json +80 -5
@@ -0,0 +1,75 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/api-keys/resolvers/deps.ts", "../src/memo.ts", "../src/context/registry.ts", "../src/context/resolve.ts", "../src/context/create.ts", "../src/errors/denial.ts", "../src/errors/janus-error.ts", "../src/errors/mask.ts", "../src/map-code.ts", "../src/mask-error.ts", "../src/report.ts", "../src/helpers.ts", "../src/api-keys/shape.ts", "../src/bad-input.ts", "../src/api-keys/resolvers/list.ts", "../src/renewal.ts", "../src/api-keys/resolvers/manage.ts", "../src/api-keys/resolvers/index.ts", "../src/api-keys/sdl.ts", "../src/avatar/resolvers.ts", "../src/avatar/sdl.ts", "../src/avatar/index.ts", "../src/options.ts", "../src/connection/credential.ts", "../src/connection/connection.ts", "../src/device.ts", "../src/directives/apply.ts", "../src/fresh.ts", "../src/directives/permission/path.ts", "../src/directives/permission/enforce.ts", "../src/directives/guard.ts", "../src/directives/read.ts", "../src/directives/words.ts", "../src/directives/permission/model.ts", "../src/directives/permission/validate.ts", "../src/directives/validate.ts", "../src/second-factor/shape.ts", "../src/surface/request.ts", "../src/surface/signed-in.ts", "../src/invitations/shape.ts", "../src/invitations/resolvers/anonymous.ts", "../src/invitations/resolvers/deps.ts", "../src/invitations/resolvers/owner.ts", "../src/invitations/resolvers/index.ts", "../src/invitations/sdl/accept.ts", "../src/invitations/sdl/owner.ts", "../src/invitations/sdl/index.ts", "../src/surface/api.ts", "../src/passkeys/deps.ts", "../src/passkeys/shape.ts", "../src/passkeys/sign-in.resolvers.ts", "../src/passkeys/resolvers.ts", "../src/passkeys/sdl.ts", "../src/passkeys/sign-in.sdl.ts", "../src/plugin.ts", "../src/sdl.ts", "../src/second-factor/resolvers/deps.ts", "../src/second-factor/resolvers/sign-in.ts", "../src/second-factor/resolvers/status.ts", "../src/second-factor/resolvers/step-up.ts", "../src/second-factor/resolvers/writes.ts", "../src/second-factor/resolvers/index.ts", "../src/second-factor/sdl.ts", "../src/social/shape.ts", "../src/social/resolvers.ts", "../src/social/sdl.ts"],
4
+ "sourcesContent": [
5
+ "/** What every field's resolver reads, resolved once by `apiKeysResolvers()`, and the steps they share. */\n\nimport type { ApiKeyBound, Principal } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport { answerOf, clockOf, janusOf } from '../../context';\nimport { denial, rethrown } from '../../errors';\nimport { requireUser } from '../../helpers';\nimport { boundToOf, checkedLifetimes } from '../shape';\nimport type {\n\tAnyUser,\n\tApiKeyLifetimes,\n\tApiKeysAuth,\n\tApiKeysAuthorize,\n\tApiKeysResolversOptions,\n\tContext,\n} from '../types';\n\nexport interface Deps {\n\treadonly keys: ApiKeysAuth['apiKeys'];\n\treadonly lifetimes: ApiKeyLifetimes;\n\treadonly authorize: ApiKeysAuthorize;\n\treadonly bound: ApiKeysResolversOptions['bound'];\n}\n\nexport function depsOf(options: ApiKeysResolversOptions): Deps {\n\tconst { auth, authorize } = options;\n\tif ((auth as Partial<ApiKeysAuth> | undefined)?.apiKeys === undefined) {\n\t\tthrow new TypeError(\n\t\t\t'apiKeysResolvers(): auth has no apiKeys — give janus() `apiKeys`',\n\t\t);\n\t}\n\tconst hooks = ['create', 'list', 'revoke'] as const;\n\tif (hooks.some((hook) => typeof authorize?.[hook] !== 'function')) {\n\t\tthrow new TypeError(\n\t\t\t'apiKeysResolvers(): `authorize` needs `create`, `list` and `revoke` — the core authorises nobody, so say who may manage keys',\n\t\t);\n\t}\n\tif (options.bound !== undefined && typeof options.bound !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t'apiKeysResolvers(): `bound` must be a function of the asked id and the context',\n\t\t);\n\t}\n\treturn {\n\t\tkeys: auth.apiKeys,\n\t\tlifetimes: checkedLifetimes(options.lifetimes),\n\t\tauthorize,\n\t\tbound: options.bound,\n\t};\n}\n\n/** Who asks and about which object: the signed-in user, its principal, and the bound object. */\nexport interface Caller {\n\treadonly user: AnyUser;\n\treadonly bound: ApiKeyBound | null;\n\t/** The request's time, from `useJanus({ clock })`: what a key's `status` is read at. */\n\treadonly now: number;\n}\n\n/**\n * The signed-in user (an API key's owner included), then the object `boundTo`\n * names through the `bound` hook. A `boundTo` without the hook, or one the\n * hook answers `null` for, is `NOT_FOUND`.\n */\nexport async function callerOf(\n\tdeps: Deps,\n\tctx: Context,\n\tboundTo: string | null | undefined,\n): Promise<Caller> {\n\tconst asked = boundToOf(boundTo);\n\tconst user = await requireUser<AnyUser>(\n\t\t// `ctx.janus` is what `useJanus()` puts on every context.\n\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t);\n\tconst now = clockOf(janusOf(ctx, 'apiKeysResolvers()')).now().getTime();\n\tif (deps.bound === undefined) {\n\t\tif (asked !== null) throw denial('NOT_FOUND');\n\t\treturn { user, bound: null, now };\n\t}\n\tconst bound = await deps.bound(asked, ctx);\n\tif (bound === null && asked !== null) throw denial('NOT_FOUND');\n\treturn { user, bound, now };\n}\n\n/**\n * What `authenticate` answered for the request: `apiKeys.create` needs the\n * whole principal (its session's freshness), not the user alone.\n */\nexport async function principalOf(ctx: Context): Promise<Principal<AnyUser>> {\n\tconst janus = janusOf(ctx, 'createApiKey');\n\tconst answered =\n\t\tanswerOf(janus) ??\n\t\t(\n\t\t\tjanus as { principal?(): Promise<Principal<AnyUser> | null> }\n\t\t).principal?.();\n\tconst principal = await answered?.then(undefined, rethrown);\n\tif (principal == null) throw denial('UNAUTHENTICATED');\n\treturn principal;\n}\n\n/** Answers `true` or throws `NOT_FOUND`: a hook's `false` hides the object. */\nexport async function allowed(answer: boolean | Promise<boolean>) {\n\tif ((await answer) !== true) throw denial('NOT_FOUND');\n}\n\n/**\n * The refusal of an id that names no key the call may reach: the hook is\n * still asked, without the key, so a known and an unknown id take the same\n * path; only a `GraphQLError` it throws (a step-up) gets through, and the\n * answer is otherwise `NOT_FOUND`.\n */\nexport async function unknownKey(\n\task: () => boolean | Promise<boolean>,\n): Promise<never> {\n\ttry {\n\t\tawait ask();\n\t} catch (error) {\n\t\tif (error instanceof GraphQLError) throw error;\n\t}\n\tthrow denial('NOT_FOUND');\n}\n\nexport const sameBound = (\n\ta: ApiKeyBound | null,\n\tb: ApiKeyBound | null,\n): boolean =>\n\ta === null || b === null ? a === b : a.type === b.type && a.id === b.id;\n",
6
+ "/**\n * The per-request memo of permission checks: the same question asked twice\n * in one request — by two fields, by a directive and a resolver's `can()`,\n * or by two fields at once — is one call to `access.can`.\n */\n\nimport type { Check } from './context';\n\ntype Ref = {\n\treadonly type: string;\n\treadonly id: string;\n\treadonly relation?: unknown;\n};\n\n/**\n * What no id in a key may hold: the notation reads `@` and `#` as its own,\n * so a key built from such an id could be another question's. `can()`\n * refuses or denies such an id anyway; it is asked, not remembered.\n */\nconst NOTATION = /[@#]/;\n\n/**\n * The key of one question, in the notation — `record:r1#view@staff:u1` —\n * or `null` when it is not remembered: an anonymous subject, which `can()`\n * answers `false` with no store call; a condition's `ctx`, which the key\n * does not hold; an id the notation could read two ways.\n */\nfunction keyOf(\n\tsubject: Ref | null,\n\tpermission: string,\n\tobject: Ref,\n\toptions: { readonly ctx?: unknown } | undefined,\n): string | null {\n\tif (subject === null || options?.ctx !== undefined) return null;\n\tif (NOTATION.test(object.id) || NOTATION.test(subject.id)) return null;\n\tconst set =\n\t\ttypeof subject.relation === 'string' ? `#${subject.relation}` : '';\n\treturn `${object.type}:${object.id}#${permission}@${subject.type}:${subject.id}${set}`;\n}\n\n/**\n * `access.can` for one request, remembered: a question asked again answers\n * the first answer's promise, so two asked at once share one call. A\n * failure is not remembered — an outage is no answer, and the next question\n * asks again.\n */\nexport function memoized(access: { readonly can: unknown }): Check {\n\tconst can = access.can as Check;\n\tconst answers = new Map<string, Promise<boolean>>();\n\tconst ask: Check = async (subject, permission, object, options) =>\n\t\tcan.call(access, subject, permission, object, options);\n\treturn (subject, permission, object, options) => {\n\t\tconst key = keyOf(subject, permission, object, options);\n\t\tif (key === null) return ask(subject, permission, object, options);\n\t\tconst known = answers.get(key);\n\t\tif (known !== undefined) return known;\n\t\tconst answer = ask(subject, permission, object, options);\n\t\tanswers.set(key, answer);\n\t\tanswer.then(undefined, () => answers.delete(key));\n\t\treturn answer;\n\t};\n}\n",
7
+ "import { type Clock, type Principal, systemClock } from '@softistx/janus';\nimport type { SessionCookie } from '../renewal';\nimport type { JanusOnContext } from '../types';\n\n/** One check, as `access.can` answers it — loose: the typing is the caller's. */\nexport type Check = (\n\tsubject: { readonly type: string; readonly id: string } | null,\n\tpermission: string,\n\tobject: { readonly type: string; readonly id: string },\n\toptions?: { readonly ctx?: unknown },\n) => Promise<boolean>;\n\n/** A user as this module reads one: the part every user type has. */\nexport type AnyUser = { readonly type: string; readonly id: string };\n\nexport type Built = JanusOnContext<AnyUser, unknown>;\n\n/**\n * The check of each context this module built. A `WeakMap` rather than a\n * property, so the context's own surface stays `user`, `session` and\n * `access`; it is the one place a request's checks pass through, and so the\n * one place a per-request memo of their answers goes.\n */\nexport const checks = new WeakMap<object, { memo: Check; fresh: Check }>();\n\n/** The clock of each context this module built with one: what `@fresh` reads. */\nexport const clocks = new WeakMap<object, Clock>();\n\n/**\n * The answer of `authenticate` for each context this module built — or\n * `undefined` while neither `user()` nor `session()` has been asked, so that\n * reading it never authenticates.\n */\nexport const answers = new WeakMap<\n\tobject,\n\t() => Promise<Principal<AnyUser> | null> | undefined\n>();\n\n/**\n * The session cookie of the instance each context authenticated with — set\n * once a resolver has answered, so a renewed session is sent again with the\n * cookie of the instance that renewed it.\n */\nexport const cookies = new WeakMap<object, SessionCookie | undefined>();\n\n/** The session cookie of the instance `janus` authenticated with, once it did. */\nexport function cookieOfContext(janus: object): SessionCookie | undefined {\n\treturn cookies.get(janus);\n}\n\n/**\n * What `authenticate` answered for `janus`'s request, or `undefined` when it\n * never ran — nothing asked `user()` or `session()`, or the context was not\n * built here. Never runs it.\n */\nexport function answerOf(\n\tjanus: object,\n): Promise<Principal<AnyUser> | null> | undefined {\n\treturn answers.get(janus)?.();\n}\n\n/**\n * The clock `@fresh` and `requireFresh()` read the time from: the one given\n * to `useJanus({ clock })`, or the system's.\n */\nexport function clockOf(janus: object): Clock {\n\treturn clocks.get(janus) ?? systemClock;\n}\n\n/**\n * The check `ctx.janus` answers through: the one its context was built\n * with — `access.can`, memoized for the request (`memo.ts`) — or\n * `access.can` itself for a context built by hand. `null` when it has no\n * `access` at all.\n *\n * `fresh` skips the memo: a subscription is one request whose checks run\n * again on every event, and must see a `revoke()` made since it started.\n */\nexport function checkOf(janus: object, fresh = false): Check | null {\n\tconst built = checks.get(janus);\n\tif (built !== undefined) return fresh ? built.fresh : built.memo;\n\tconst access = (janus as { readonly access?: { readonly can?: unknown } })\n\t\t.access;\n\treturn typeof access?.can === 'function' ? (access.can as Check) : null;\n}\n\n/**\n * `ctx.janus`, or a wiring `TypeError` naming `caller` when nothing put it\n * there: `useJanus()` is missing from the plugins.\n */\nexport function janusOf(ctx: unknown, caller: string): Built {\n\tconst janus = (ctx as { readonly janus?: Built } | null)?.janus;\n\tif (janus === undefined || typeof janus.user !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: ctx.janus is not set — add useJanus({ auth }) to the plugins`,\n\t\t);\n\t}\n\treturn janus;\n}\n",
8
+ "import type { Principal, RequestLike } from '@softistx/janus';\nimport type { SessionCookie } from '../renewal';\nimport { type AnyUser, cookies } from './registry';\n\ntype LooseAuth = {\n\tauthenticate(\n\t\trequest: RequestLike,\n\t\toptions?: { readonly type?: string; readonly apiKey?: boolean },\n\t): Promise<Principal<AnyUser> | null>;\n};\n\n/** `auth` as the options give it: an instance, or a function answering one. */\nexport type AuthOrResolver =\n\t| LooseAuth\n\t| ((\n\t\t\tctx: never,\n\t ) => LooseAuth | null | undefined | Promise<LooseAuth | null | undefined>);\n\n/**\n * The instance that serves a request: `auth` itself, or what the function\n * given as `auth` answers for `context`. A function that answers none, or\n * something that is not what `janus()` answered, is a `TypeError`; one that\n * throws or rejects is its own error, unchanged.\n */\nexport async function resolveAuth(\n\tauth: AuthOrResolver,\n\tcontext: unknown,\n\tcaller: string,\n\twhat: 'request' | 'connection' = 'request',\n): Promise<LooseAuth> {\n\tif (typeof auth !== 'function') return auth;\n\tconst instance = await (auth as (ctx: unknown) => unknown)(context);\n\tif (instance === null || instance === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: the auth resolver answered no janus() instance for this ${what} — return what janus() answered, or ${\n\t\t\t\twhat === 'request'\n\t\t\t\t\t? 'throw to refuse the request'\n\t\t\t\t\t: 'throw to refuse it'\n\t\t\t}`,\n\t\t);\n\t}\n\tif (\n\t\ttypeof (instance as { readonly authenticate?: unknown }).authenticate !==\n\t\t'function'\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: the auth resolver answered something that is not what janus() answered`,\n\t\t);\n\t}\n\treturn instance as LooseAuth;\n}\n\nexport async function instanceOf(\n\tauth: AuthOrResolver,\n\tcontext: unknown,\n\tcaller: string,\n\tjanus: object,\n\twhat: 'request' | 'connection',\n): Promise<LooseAuth> {\n\tconst instance = await resolveAuth(auth, context, caller, what);\n\tcookies.set(janus, (instance as { readonly cookie?: SessionCookie }).cookie);\n\treturn instance;\n}\n",
9
+ "import type { Clock, Principal, RequestLike } from '@softistx/janus';\nimport { memoized } from '../memo';\nimport {\n\ttype AnyUser,\n\tanswers,\n\ttype Built,\n\ttype Check,\n\tchecks,\n\tclocks,\n} from './registry';\nimport { type AuthOrResolver, instanceOf } from './resolve';\n\n/** What `createJanusContext` reads from `useJanus()`'s options. */\nexport interface ContextOptions {\n\treadonly auth: AuthOrResolver;\n\t/** What an `auth` function is called with: the context the request's `ctx` is built from. */\n\treadonly context?: unknown;\n\t/** What the resolver's error names: a `request` (HTTP) or a `connection` (graphql-ws). */\n\treadonly what?: 'request' | 'connection';\n\treadonly access?: { readonly can: unknown } | undefined;\n\treadonly type?: string | undefined;\n\treadonly clock?: Clock | undefined;\n\t/** Accept an API key beside a session: `authenticate(request, { apiKey: true })`. */\n\treadonly apiKey?: boolean | undefined;\n\t/** The call the consumer wrote, named by the no-request `TypeError`. */\n\treadonly caller?: string;\n}\n\n/**\n * `ctx.janus` for one request. `authenticate` runs the first time `user()`\n * or `session()` is asked, once, and its answer — or its failure — is the\n * answer of both from then on.\n *\n * A context with no request — a transport that is not HTTP, or a graphql-ws\n * connection no `janusConnection().onConnect` accepted — answers a\n * `TypeError` from `user()`, not `null`: anonymous is an answer, and nothing\n * here asked.\n */\nexport function createJanusContext(\n\trequest: RequestLike | undefined,\n\toptions: ContextOptions,\n): Built {\n\tconst {\n\t\tauth,\n\t\taccess,\n\t\ttype,\n\t\tclock,\n\t\tapiKey,\n\t\tcaller = 'useJanus()',\n\t\tcontext,\n\t\twhat = 'request',\n\t} = options;\n\tlet answer: Promise<Principal<AnyUser> | null>;\n\tlet asked = false;\n\tconst authenticated = () => {\n\t\tif (!asked) {\n\t\t\tasked = true;\n\t\t\tanswer =\n\t\t\t\trequest === undefined\n\t\t\t\t\t? Promise.reject(\n\t\t\t\t\t\t\tnew TypeError(\n\t\t\t\t\t\t\t\t`${caller}: the GraphQL context has no request to authenticate — build the context from an HTTP request, or accept a graphql-ws connection with janusConnection().onConnect`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: instanceOf(auth, context, caller, janus, what).then((instance) =>\n\t\t\t\t\t\t\tinstance.authenticate(request, {\n\t\t\t\t\t\t\t\t...(type === undefined ? {} : { type }),\n\t\t\t\t\t\t\t\t...(apiKey === true ? { apiKey: true } : {}),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t}\n\t\treturn answer;\n\t};\n\n\tconst janus: object = Object.freeze({\n\t\tuser: () => authenticated().then((current) => current?.user ?? null),\n\t\tsession: () => authenticated().then((current) => current?.session ?? null),\n\t\t// Only when `apiKey: true`: a context without it keeps its three keys.\n\t\t...(apiKey === true\n\t\t\t? {\n\t\t\t\t\tprincipal: () => authenticated(),\n\t\t\t\t\tapiKey: () =>\n\t\t\t\t\t\tauthenticated().then((current) =>\n\t\t\t\t\t\t\tcurrent?.via === 'apiKey' ? current.apiKey : null,\n\t\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(access === undefined ? {} : { access }),\n\t});\n\tif (access !== undefined) {\n\t\tconst can = access.can as Check;\n\t\tchecks.set(janus, {\n\t\t\tmemo: memoized(access),\n\t\t\tfresh: (...args) => can.apply(access, args),\n\t\t});\n\t}\n\tif (clock !== undefined) clocks.set(janus, clock);\n\tanswers.set(janus, () => (asked ? answer : undefined));\n\treturn janus as unknown as Built;\n}\n",
10
+ "import { GraphQLError } from 'graphql';\n\n/** What a guard answers without asking `@softistx/janus`: no user, or not this one. */\nexport type DenialCode = 'UNAUTHENTICATED' | 'FORBIDDEN' | 'NOT_FOUND';\n\n/** A denial: `UNAUTHENTICATED` 401, `FORBIDDEN` 403 or `NOT_FOUND` 404. */\nexport function denial(code: DenialCode, message?: string): GraphQLError {\n\tconst [status, fallback] = denialOf(code);\n\treturn new GraphQLError(message ?? fallback, {\n\t\textensions: { code, http: { status } },\n\t});\n}\n\nfunction denialOf(code: DenialCode): readonly [number, string] {\n\tswitch (code) {\n\t\tcase 'UNAUTHENTICATED':\n\t\t\treturn [401, 'Not signed in'];\n\t\tcase 'FORBIDDEN':\n\t\t\treturn [403, 'Forbidden'];\n\t\tcase 'NOT_FOUND':\n\t\t\treturn [404, 'Not found'];\n\t}\n}\n",
11
+ "import { JanusError, type JanusErrorStatus, statusOf } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\n\n/**\n * A `JanusError` as the client may read it: its code and status, and only\n * what the client can act on — `issues`, `minLength`, `attemptsLeft`,\n * `retryAfter`, `maxActive`, `field`, an invitation code's refusal `reason` (`unknown`, `expired`, `accepted`, `revoked`), and a social flow's `returnTo` and `flowSpent`. Never any other `reason`, `login`, `slot` or a cause: those are for\n * your logs. A throttled sign-in, and a request past its e-mails\n * (`MAIL_THROTTLED`, 429), also carry their `Retry-After` header in\n * `http.headers`, which Yoga answers with.\n *\n * `STORE_FAILED` is `SERVICE_UNAVAILABLE` 503 — **an outage is never a\n * denial** — and no message of the core's reaches the client.\n */\nexport function janusGraphQLError(error: JanusError): GraphQLError {\n\tconst status = statusOf(error.code);\n\tconst code = codeOf(error);\n\treturn new GraphQLError(messageOf(status), {\n\t\toriginalError: error,\n\t\textensions: {\n\t\t\tcode,\n\t\t\thttp: httpOf(error, status),\n\t\t\t...actionable(error),\n\t\t\t...flowOf(error),\n\t\t},\n\t});\n}\n\n/** The client's code: `STORE_FAILED` is an outage, a cursor replayed against another list is the client's bad input. */\nfunction codeOf(error: JanusError): string {\n\tswitch (error.code) {\n\t\tcase 'STORE_FAILED':\n\t\t\treturn 'SERVICE_UNAVAILABLE';\n\t\tcase 'CURSOR_FILTER_MISMATCH':\n\t\t\treturn 'BAD_USER_INPUT';\n\t\tdefault:\n\t\t\treturn error.code;\n\t}\n}\n\n/**\n * A fixed message per status: the core's own message names a hash prefix or\n * a version, which are for your logs. The client reads `extensions.code`.\n */\nfunction messageOf(status: JanusErrorStatus): string {\n\tswitch (status) {\n\t\tcase 400:\n\t\t\treturn 'Invalid request';\n\t\tcase 401:\n\t\t\treturn 'Invalid credentials';\n\t\tcase 403:\n\t\t\treturn 'Forbidden';\n\t\tcase 404:\n\t\t\treturn 'Not found';\n\t\tcase 409:\n\t\t\treturn 'Conflict';\n\t\tcase 429:\n\t\t\treturn 'Too many requests, retry later';\n\t\tcase 502:\n\t\t\treturn 'Bad gateway';\n\t\tcase 503:\n\t\t\treturn 'The service is unavailable, retry later';\n\t\tcase 500:\n\t\tcase 501:\n\t\t\treturn 'Internal server error';\n\t}\n}\n\n/** The status, and the `Retry-After` of a throttled sign-in or request. */\nfunction httpOf(\n\terror: JanusError,\n\tstatus: JanusErrorStatus,\n): Record<string, unknown> {\n\treturn error.retryAfter === undefined\n\t\t? { status }\n\t\t: { status, headers: { 'Retry-After': String(error.retryAfter) } };\n}\n\n/** The fields of a refusal a client can act on, as `@softistx/janus-hono`'s `bodyOf`. */\nfunction actionable(error: JanusError): Record<string, unknown> {\n\tswitch (error.code) {\n\t\tcase 'USER_INVALID':\n\t\t\treturn { issues: error.issues ?? [] };\n\t\tcase 'PASSWORD_TOO_SHORT':\n\t\t\treturn error.minLength === undefined\n\t\t\t\t? {}\n\t\t\t\t: { minLength: error.minLength };\n\t\tcase 'CODE_INVALID':\n\t\t\treturn {\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? {}\n\t\t\t\t: { 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? {}\n\t\t\t\t: { maxActive: error.maxActive };\n\t\tcase 'INVITATION_INVALID':\n\t\t\treturn {\n\t\t\t\t...(error.field === undefined ? {} : { field: error.field }),\n\t\t\t\t...(isInvitationRefusal(error.reason) ? { reason: error.reason } : {}),\n\t\t\t};\n\t\tcase 'API_KEY_INVALID':\n\t\tcase 'PASSKEY_INVALID':\n\t\t\treturn error.field === undefined ? {} : { field: error.field };\n\t\tcase 'INVALID_CURSOR':\n\t\tcase 'CURSOR_FILTER_MISMATCH':\n\t\t\treturn { field: error.field ?? 'after' };\n\t\tdefault:\n\t\t\treturn {};\n\t}\n}\n\nconst INVITATION_REFUSALS: readonly unknown[] = [\n\t'unknown',\n\t'expired',\n\t'accepted',\n\t'revoked',\n];\n\n/** Only `INVITATION_INVALID`'s own reasons reach the client; any other `reason` stays in the logs. */\nfunction isInvitationRefusal(\n\treason: unknown,\n): reason is 'unknown' | 'expired' | 'accepted' | 'revoked' {\n\treturn INVITATION_REFUSALS.includes(reason);\n}\n\n/**\n * What a social refusal tells the BFF: `returnTo`, the path the flow was\n * started with — only when the error carries it, which is after the flow was\n * authenticated — and `flowSpent`: `false` means keep the flow cookie.\n * Neither is for logs; the account id, the e-mail and the cause never get here.\n */\nfunction flowOf(error: JanusError): Record<string, unknown> {\n\treturn {\n\t\t...(error.returnTo === undefined ? {} : { returnTo: error.returnTo }),\n\t\t...(error.flowSpent === undefined ? {} : { flowSpent: error.flowSpent }),\n\t};\n}\n\n/**\n * A rejection handler: a `JanusError` becomes its `GraphQLError`, anything\n * else goes on as it is. `.then(undefined, rethrown)`.\n */\nexport function rethrown(error: unknown): never {\n\tthrow error instanceof JanusError ? janusGraphQLError(error) : error;\n}\n",
12
+ "import type { JanusError } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport { type MappedCode, remapped } from '../map-code';\nimport { maskedError } from '../mask-error';\nimport { janusErrorIn, reporting } from '../report';\nimport { janusGraphQLError } from './janus-error';\n\n/**\n * Yoga's `maskError` signature (and envelop 5's, which has no `context`): what\n * a `fallback` is.\n */\nexport type MaskError = (\n\terror: unknown,\n\tmessage: string,\n\tisDev?: boolean,\n\t// biome-ignore lint/suspicious/noExplicitAny: Yoga types its context parameter; `unknown` would refuse Yoga's own `maskError`.\n\tcontext?: any,\n) => Error;\n\n/**\n * What `janusMaskError()` answers: it fits Yoga's `maskError`, envelop 5's\n * (`isDev` third) and envelop 6's (`context` third) alike, so the third\n * argument is told apart by its type.\n */\nexport type JanusMaskError = (\n\terror: unknown,\n\tmessage: string,\n\tisDevOrContext?: unknown,\n\tcontext?: unknown,\n) => Error;\n\n/** What `janusMaskError()` takes. */\nexport interface JanusMaskErrorOptions {\n\t/**\n\t * Called once with every `JanusError` answered 5xx — `STORE_FAILED`,\n\t * `UNSUPPORTED`, `PERMISSION_DEPTH` — whichever path it took: a\n\t * directive, `requireUser()`, `can()`, or a resolver that let it through.\n\t * Its `slot`, `operation`, `reason` and cause are for your logs; the\n\t * response never carries them.\n\t *\n\t * **It cannot change 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) => unknown;\n\t/**\n\t * Every error that is not a `JanusError`; default: Yoga's `maskError` behaviour, see `janusMaskError()`.\n\t * It has Yoga's signature: `isDev` third, `context` fourth, also under envelop 6, which sends the context third.\n\t */\n\treadonly fallback?: MaskError;\n\t/**\n\t * Answers a code of yours in place of one of the package's. Called with\n\t * the `extensions.code` of every `GraphQLError` the mask is about to\n\t * return — a directive's `UNAUTHENTICATED`, `FORBIDDEN`,\n\t * `STEP_UP_REQUIRED`, a resolver's `NOT_FOUND`, `SERVICE_UNAVAILABLE`… —\n\t * and that error. Return `undefined` to keep the answer as it is.\n\t * Otherwise the error is rebuilt with `code` (and `message`, and\n\t * `extensions.http.status`, when given), keeping its other extensions,\n\t * nodes, source, positions, path and `originalError`.\n\t */\n\treadonly mapCode?: (\n\t\tcode: string,\n\t\terror: GraphQLError,\n\t) => MappedCode | undefined;\n}\n\n/**\n * Yoga's `maskedErrors.maskError`: a `JanusError` a resolver let through is\n * answered with its code and status — `STORE_FAILED` as 503, never masked\n * into a 500 and never a denial — and every other error goes to `fallback`.\n *\n * Without a `fallback`, every other error is masked as Yoga's own `maskError`\n * does: a `GraphQLError` of your own is kept, anything else becomes `message`\n * with `INTERNAL_SERVER_ERROR` and `unexpected: true` (so a failure with no\n * `data`, such as a context factory that throws, is still HTTP 500), keeping\n * `extensions.http`, and showing the original error only in development\n * (`isDev`). Passing Yoga's `maskError` as `fallback` is no longer needed.\n *\n * ```ts\n * import { createYoga } from 'graphql-yoga';\n * createYoga({\n * schema,\n * plugins,\n * maskedErrors: {\n * maskError: janusMaskError({ report: (error) => logger.error(error) }),\n * },\n * });\n * ```\n */\nexport function janusMaskError(\n\toptions: JanusMaskErrorOptions | MaskError = {},\n): JanusMaskError {\n\tconst {\n\t\treport,\n\t\tfallback = maskedError,\n\t\tmapCode,\n\t} = typeof options === 'function' ? { fallback: options } : options;\n\tconst reported = report === undefined ? undefined : reporting(report);\n\tconst mask = masking(fallback, reported);\n\treturn mapCode === undefined\n\t\t? mask\n\t\t: (error, message, isDevOrContext, context) => {\n\t\t\t\tconst masked = mask(error, message, isDevOrContext, context);\n\t\t\t\treturn masked instanceof GraphQLError\n\t\t\t\t\t? remapped(masked, mapCode)\n\t\t\t\t\t: masked;\n\t\t\t};\n}\n\nfunction masking(\n\tfallback: MaskError,\n\treported: ((error: unknown) => void) | undefined,\n): JanusMaskError {\n\treturn (error, message, isDevOrContext, context) => {\n\t\treported?.(error);\n\t\tconst original = janusErrorIn(error);\n\t\tif (original !== null) {\n\t\t\tconst answer = janusGraphQLError(original);\n\t\t\treturn error instanceof GraphQLError\n\t\t\t\t? new GraphQLError(answer.message, {\n\t\t\t\t\t\tnodes: error.nodes ?? null,\n\t\t\t\t\t\tpath: error.path ?? null,\n\t\t\t\t\t\toriginalError: original,\n\t\t\t\t\t\textensions: answer.extensions,\n\t\t\t\t\t})\n\t\t\t\t: answer;\n\t\t}\n\t\t// envelop 6 passes the context third, Yoga and envelop 5 `isDev`.\n\t\treturn typeof isDevOrContext === 'boolean' || isDevOrContext === undefined\n\t\t\t? fallback(error, message, isDevOrContext, context)\n\t\t\t: fallback(error, message, undefined, context ?? isDevOrContext);\n\t};\n}\n",
13
+ "/** `janusMaskError({ mapCode })`: an application's own code on the answer. */\n\nimport { GraphQLError } from 'graphql';\n\n/** What `mapCode` answers: the code of your own, and optionally its message and HTTP status. */\nexport interface MappedCode {\n\treadonly code: string;\n\treadonly message?: string;\n\treadonly status?: number;\n}\n\nexport function remapped(\n\terror: GraphQLError,\n\tmapCode: (code: string, error: GraphQLError) => MappedCode | undefined,\n): GraphQLError {\n\tconst code = error.extensions?.['code'];\n\tconst mapped = typeof code === 'string' ? mapCode(code, error) : undefined;\n\tif (mapped === undefined) return error;\n\tconst extensions: Record<string, unknown> = {\n\t\t...error.extensions,\n\t\tcode: mapped.code,\n\t};\n\tif (mapped.status !== undefined) {\n\t\textensions['http'] = {\n\t\t\t...(error.extensions?.['http'] as object | undefined),\n\t\t\tstatus: mapped.status,\n\t\t};\n\t}\n\treturn new GraphQLError(mapped.message ?? error.message, {\n\t\tnodes: error.nodes,\n\t\tsource: error.source,\n\t\tpositions: error.positions,\n\t\tpath: error.path,\n\t\toriginalError: error.originalError ?? undefined,\n\t\textensions,\n\t});\n}\n",
14
+ "/**\n * The default `fallback` of `janusMaskError()`: what graphql-yoga 5's\n * `maskError` does, without importing it (Yoga is not a peer of this package).\n * It keeps `extensions.unexpected: true`, which Yoga reads to answer a failure\n * with no `data` as HTTP 500.\n *\n * One difference, on purpose: Yoga's `coordinate` is left out, since\n * `getSchemaCoordinate` is not in every `@graphql-tools/utils` the peer range\n * allows. It never reaches the response.\n */\n\nimport { GraphQLError, type GraphQLErrorOptions } from 'graphql';\n\n/** Yoga's `isOriginalGraphQLError`: a `GraphQLError` whose `originalError` chain holds only `GraphQLError`s. */\nfunction isOriginalGraphQLError(error: unknown): error is GraphQLError {\n\tif (error instanceof GraphQLError) {\n\t\treturn (\n\t\t\terror.originalError == null || isOriginalGraphQLError(error.originalError)\n\t\t);\n\t}\n\treturn false;\n}\n\nfunction serialized(error: unknown): unknown {\n\tif (error instanceof GraphQLError) {\n\t\treturn error.toJSON();\n\t}\n\tif (error instanceof Error) {\n\t\treturn { message: error.message, stack: error.stack, cause: error.cause };\n\t}\n\treturn error;\n}\n\n/** `process.env.NODE_ENV === 'development'`, read safely outside Node. */\nfunction inDevelopment(): boolean {\n\treturn globalThis.process?.env?.NODE_ENV === 'development';\n}\n\n/**\n * Yoga 5's `maskError`: a `GraphQLError` of your own is kept, anything else\n * becomes `message` with `{ code: 'INTERNAL_SERVER_ERROR', unexpected: true }`,\n * the position and path of the original, its `extensions.http`, and — only in\n * development — the serialized `originalError`.\n */\nexport function maskedError(\n\terror: unknown,\n\tmessage: string,\n\tisDev: boolean = inDevelopment(),\n): Error {\n\tif (isOriginalGraphQLError(error)) {\n\t\treturn error;\n\t}\n\tconst extensions: Record<string, unknown> = {\n\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\tunexpected: true,\n\t};\n\tconst options: GraphQLErrorOptions = { extensions };\n\tif (error instanceof GraphQLError) {\n\t\tObject.assign(options, {\n\t\t\tnodes: error.nodes,\n\t\t\tsource: error.source,\n\t\t\tpositions: error.positions,\n\t\t\tpath: error.path,\n\t\t});\n\t\tif (isDev && error.originalError) {\n\t\t\textensions['originalError'] = serialized(error.originalError);\n\t\t}\n\t\tif (error.extensions?.['http']) {\n\t\t\textensions['http'] = error.extensions['http'];\n\t\t}\n\t} else if (isDev) {\n\t\textensions['originalError'] = serialized(error);\n\t}\n\treturn new GraphQLError(message, options);\n}\n",
15
+ "/**\n * `janusMaskError({ report })`: every `JanusError` answered 5xx, handed to\n * the application's logger before the response goes — the directives' and\n * the helpers' included, which reach the mask already a `GraphQLError`.\n */\n\nimport { JanusError, statusOf } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\n\n/**\n * The `JanusError` behind `error`: itself, or the one a chain of\n * `GraphQLError`s carries as `originalError` — a directive's refusal,\n * located again by graphql-js. `null` when there is none.\n */\nexport function janusErrorIn(error: unknown): JanusError | null {\n\tlet current = error;\n\twhile (current instanceof GraphQLError) current = current.originalError;\n\treturn current instanceof JanusError ? current : null;\n}\n\n/**\n * A `report` that sees each failure once — a lazy `authenticate` shared by\n * two guarded fields fails both with one error — and only a 5xx: an outage,\n * `UNSUPPORTED`, `PERMISSION_DEPTH`, the ones the server must fix.\n *\n * **It cannot change the answer**: one that throws, or rejects, is a\n * `process.emitWarning`, and the response is sent all the same.\n */\nexport function reporting(\n\treport: (error: JanusError) => unknown,\n): (error: unknown) => void {\n\tconst seen = new WeakSet<JanusError>();\n\treturn (error) => {\n\t\tconst janusError = janusErrorIn(error);\n\t\tif (janusError === null || seen.has(janusError)) return;\n\t\tif (statusOf(janusError.code) < 500) return;\n\t\tseen.add(janusError);\n\t\tconst warn = (failure: unknown) =>\n\t\t\tprocess.emitWarning(\n\t\t\t\t`janusMaskError: report failed on ${janusError.code}: ${failure instanceof Error ? failure.name : typeof failure}`,\n\t\t\t);\n\t\ttry {\n\t\t\t// A thenable of any make, as a native promise: its rejection warns too.\n\t\t\tPromise.resolve(report(janusError)).then(undefined, warn);\n\t\t} catch (failure) {\n\t\t\twarn(failure);\n\t\t}\n\t};\n}\n\n/**\n * The `JanusError` behind any error: itself, or the one a chain of\n * `GraphQLError`s carries as `originalError` — what the package's resolvers\n * and directives throw. `undefined` when there is none; use it to map a\n * resolver's refusal (`INVITATION_NOT_PENDING`, `NOT_FOUND`…) per operation.\n */\nexport function janusErrorOf(error: unknown): JanusError | undefined {\n\treturn janusErrorIn(error) ?? undefined;\n}\n",
16
+ "/**\n * The two calls a resolver makes itself: `requireUser` where a directive\n * would not do, and `can` for a check the schema cannot express.\n */\n\nimport type {\n\tCheckArgs,\n\tCheckableOf,\n\tModelConfig,\n\tObjectRef,\n\tObjectTypeOf,\n\tPermissions,\n} from '@softistx/janus/permissions';\nimport { checkOf, janusOf } from './context';\nimport { denial, rethrown } from './errors';\n\n/** What `requireUser()` takes. */\nexport interface RequireUserOptions<T extends string> {\n\t/**\n\t * Only a user of this type, or of one of these — never an empty list,\n\t * which no user could pass: any other is `FORBIDDEN`.\n\t */\n\treadonly type?: T | readonly [T, ...T[]];\n}\n\n/**\n * The signed-in user, narrowed to `type` when it is given — or a denial:\n * `UNAUTHENTICATED` 401 for an anonymous request, `FORBIDDEN` 403 for a user\n * of another type. A store that cannot answer is `SERVICE_UNAVAILABLE` 503,\n * never either of them.\n *\n * ```ts\n * const staff = await requireUser(ctx, { type: 'staff' });\n * staff.username; // typed: a staff member\n * ```\n */\nexport async function requireUser<\n\tU extends { readonly type: string },\n\tconst T extends U['type'] = U['type'],\n>(\n\tctx: { readonly janus: { user(): Promise<U | null> } },\n\toptions: RequireUserOptions<T> = {},\n): Promise<Extract<U, { readonly type: T }>> {\n\tconst { type } = options;\n\tconst allowed: readonly string[] | undefined =\n\t\ttypeof type === 'string' ? [type] : type;\n\tif (allowed?.length === 0) {\n\t\tthrow new TypeError(\n\t\t\t'requireUser(): type is an empty list, which no user could pass — name at least one user type, or leave type out',\n\t\t);\n\t}\n\tconst user = await janusOf(ctx, 'requireUser()')\n\t\t.user()\n\t\t.then(undefined, rethrown);\n\tif (user === null) throw denial('UNAUTHENTICATED');\n\tif (allowed !== undefined && !allowed.includes(user.type)) {\n\t\tthrow denial('FORBIDDEN');\n\t}\n\treturn user as unknown as Extract<U, { readonly type: T }>;\n}\n\n/**\n * Whether the request's user holds `permission` on `object`, typed as\n * `access.can` is: the permission must be one the object's type declares,\n * the object must carry every field its `fromField`s read, and `{ ctx }` is\n * required exactly when a condition is reachable. Anonymous answers `false`.\n *\n * **A failure throws**: a store that cannot answer is `SERVICE_UNAVAILABLE`\n * 503, never `false`.\n *\n * ```ts\n * if (!(await can(ctx, 'edit', { type: 'record', ...record }))) return null;\n * ```\n */\nexport async function can<\n\tC extends ModelConfig,\n\tconst T extends ObjectTypeOf<C>,\n\tconst P extends CheckableOf<C, T>,\n>(\n\tctx: {\n\t\treadonly janus: {\n\t\t\tuser(): Promise<{ readonly type: string; readonly id: string } | null>;\n\t\t\treadonly access: Pick<Permissions<C>, 'can'>;\n\t\t};\n\t},\n\tpermission: P,\n\tobject: ObjectRef<C, T>,\n\t...options: CheckArgs<C, T, P>\n): Promise<boolean> {\n\tconst janus = janusOf(ctx, 'can()');\n\tconst check = checkOf(janus);\n\tif (check === null) {\n\t\tthrow new TypeError(\n\t\t\t'can(): ctx.janus.access is not set — pass { access } to useJanus()',\n\t\t);\n\t}\n\tconst subject = await janus.user().then(undefined, rethrown);\n\treturn check(subject, permission, object, options[0]).then(\n\t\tundefined,\n\t\trethrown,\n\t);\n}\n",
17
+ "/**\n * The answers of the API key resolvers — a core key as the plain object the\n * schema's fields read — and the arguments checked here, before `authorize`\n * or a store is asked.\n */\n\nimport { type ApiKey, JanusError } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport { badInput } from '../bad-input';\nimport { janusGraphQLError } from '../errors';\nimport type { ApiKeyLifetimes, ApiKeyOut } from './types';\n\nconst iso = (date: Date | null): string | null =>\n\tdate === null ? null : date.toISOString();\n\n/** A key as the schema reads it; `status` from `now`, the request's clock. */\nexport function apiKeyOut(key: ApiKey, now: number): ApiKeyOut {\n\treturn {\n\t\tid: key.id,\n\t\tuserId: key.userId,\n\t\tname: key.name,\n\t\tprefix: key.hint,\n\t\tscopes: key.scopes,\n\t\tbound: key.bound,\n\t\tstatus:\n\t\t\tkey.revokedAt !== null\n\t\t\t\t? 'REVOKED'\n\t\t\t\t: key.expiresAt.getTime() <= now\n\t\t\t\t\t? 'EXPIRED'\n\t\t\t\t\t: 'ACTIVE',\n\t\tcreatedAt: key.createdAt.toISOString(),\n\t\texpiresAt: key.expiresAt.toISOString(),\n\t\tlastUsedAt: iso(key.lastUsedAt),\n\t\trevokedAt: iso(key.revokedAt),\n\t};\n}\n\n/**\n * The longest each argument may be. They mirror `@softistx/janus`'s own\n * bounds — a name of 100 characters once trimmed, 32 scopes of 100\n * characters, a bound id of 200 — held here so an oversized argument is\n * refused before `authorize` or a store is asked; resolvers.create.spec.ts\n * shows the core keeps a key at each maximum.\n */\nexport const API_KEY_LIMITS = {\n\tname: 100,\n\tscopes: 32,\n\tscope: 100,\n\tboundTo: 200,\n} as const;\n\n/** Refuses a `name` over its maximum once trimmed, and `scopes` too many or too long. */\nexport function boundedCreate(\n\tname: string,\n\tscopes: readonly string[] | null | undefined,\n): void {\n\tif (name.trim().length > API_KEY_LIMITS.name) {\n\t\tthrow badInput(\n\t\t\t`name must be at most ${API_KEY_LIMITS.name} characters`,\n\t\t\t'name',\n\t\t);\n\t}\n\tif (scopes == null) return;\n\tif (scopes.length > API_KEY_LIMITS.scopes) {\n\t\tthrow badInput(\n\t\t\t`scopes must hold at most ${API_KEY_LIMITS.scopes} scopes`,\n\t\t\t'scopes',\n\t\t);\n\t}\n\tif (scopes.some((scope) => scope.length > API_KEY_LIMITS.scope)) {\n\t\tthrow badInput(\n\t\t\t`each scope must be at most ${API_KEY_LIMITS.scope} characters`,\n\t\t\t'scopes',\n\t\t);\n\t}\n}\n\n/** The `boundTo` argument: absent (`null`), or 1 to 200 characters. */\nexport function boundToOf(boundTo: string | null | undefined): string | null {\n\tif (boundTo == null) return null;\n\tif (boundTo.length === 0 || boundTo.length > API_KEY_LIMITS.boundTo) {\n\t\tthrow badInput(\n\t\t\t`boundTo must be 1 to ${API_KEY_LIMITS.boundTo} characters`,\n\t\t\t'boundTo',\n\t\t);\n\t}\n\treturn boundTo;\n}\n\n/** The `lifetimeDays` argument: the default when absent, else one of the choices. */\nexport function lifetimeOf(\n\tlifetimes: ApiKeyLifetimes,\n\tlifetimeDays: number | null | undefined,\n): number {\n\tif (lifetimeDays == null) return lifetimes.default;\n\tif (!lifetimes.days.includes(lifetimeDays)) {\n\t\tthrow badInput(\n\t\t\t`lifetimeDays must be one of ${lifetimes.days.join(', ')}`,\n\t\t\t'lifetimeDays',\n\t\t);\n\t}\n\treturn lifetimeDays;\n}\n\n/** Refuses, at wiring, lifetimes that no key could be created with. */\nexport function checkedLifetimes(\n\tlifetimes: ApiKeyLifetimes | undefined,\n): ApiKeyLifetimes {\n\tconst at = 'apiKeysResolvers(): lifetimes';\n\tif (\n\t\tlifetimes === undefined ||\n\t\t!Array.isArray(lifetimes.days) ||\n\t\tlifetimes.days.length === 0\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`${at} must list at least one lifetime in days — for example { days: [30, 90, 365], default: 90 }`,\n\t\t);\n\t}\n\tfor (const days of lifetimes.days) {\n\t\tif (!Number.isSafeInteger(days) || days < 1) {\n\t\t\tthrow new TypeError(`${at}.days must be positive whole numbers of days`);\n\t\t}\n\t}\n\tif (!lifetimes.days.includes(lifetimes.default)) {\n\t\tthrow new TypeError(`${at}.default must be one of lifetimes.days`);\n\t}\n\tconst [first, ...rest] = lifetimes.days;\n\treturn { days: [first, ...rest], default: lifetimes.default };\n}\n\n/**\n * A refusal of `apiKeys.create`, as the schema answers it. The core names the\n * lifetime `lifetime`; the schema's argument is `lifetimeDays`, so a lifetime\n * `lifetimes.days` offers but `janus({ apiKeys: { lifetimes } })` does not\n * points at the argument the caller sent.\n */\nexport function createRefused(error: unknown): never {\n\tif (!(error instanceof JanusError)) throw error;\n\tconst answered = janusGraphQLError(error);\n\tif (error.code !== 'API_KEY_INVALID' || error.field !== 'lifetime') {\n\t\tthrow answered;\n\t}\n\tthrow new GraphQLError(answered.message, {\n\t\textensions: { ...answered.extensions, field: 'lifetimeDays' },\n\t});\n}\n",
18
+ "/**\n * A bad argument, and the page `limit` every list field checks the same way.\n * Shared by the invitation and API key resolvers.\n */\n\nimport { GraphQLError } from 'graphql';\n\n/**\n * `BAD_USER_INPUT` 400 naming the argument in `extensions.field`. Not\n * `denial()`, which speaks of access: this is a bad argument.\n */\nexport function badInput(message: string, field: string): GraphQLError {\n\treturn new GraphQLError(message, {\n\t\textensions: { code: 'BAD_USER_INPUT', http: { status: 400 }, field },\n\t});\n}\n\n/** The `limit`: absent, or a positive integer (the core bounds it at 100). */\nexport function limitOf(limit: number | null | undefined) {\n\tif (limit == null) return {};\n\tif (!Number.isSafeInteger(limit) || limit < 1) {\n\t\tthrow badInput('limit must be a positive integer', 'limit');\n\t}\n\treturn { limit };\n}\n",
19
+ "/** The read fields: `apiKeys`, `boundApiKeys` and `apiKeyLifetimes`. */\n\nimport { limitOf } from '../../bad-input';\nimport { denial, rethrown } from '../../errors';\nimport { requireUser } from '../../helpers';\nimport { apiKeyOut } from '../shape';\nimport type { AnyUser, ApiKeyPageOut, ApiKeysResolvers } from '../types';\nimport { allowed, callerOf, type Deps } from './deps';\n\ntype Queries = ApiKeysResolvers['Query'];\n\n/** The core's page size when the query gives none, and its largest. */\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 100;\n\n/** The page arguments as `authorize` is told them, and the size to read. */\nfunction pageOf(\n\tlimit: number | null | undefined,\n\tafter: string | null | undefined,\n) {\n\tconst asked = {\n\t\t...limitOf(limit),\n\t\t...(after == null ? {} : { after }),\n\t};\n\treturn {\n\t\tasked,\n\t\tsize: Math.min(asked.limit ?? DEFAULT_LIMIT, MAX_LIMIT),\n\t\tafter: after ?? null,\n\t};\n}\n\n/**\n * `Query.apiKeys`: the user's own keys, oldest first — only those bound to\n * the call's object when the application binds keys (unbound ones when the\n * call names none).\n */\nexport function apiKeys(deps: Deps): Queries['apiKeys'] {\n\treturn async (_, { boundTo, limit, after }, ctx): Promise<ApiKeyPageOut> => {\n\t\tconst page = pageOf(limit, after);\n\t\tconst { user, bound, now } = await callerOf(deps, ctx, boundTo);\n\t\tawait allowed(\n\t\t\tdeps.authorize.list({ user, bound, every: false, page: page.asked }, ctx),\n\t\t);\n\t\t// One core call: the keys of the call's object (the unbound ones when\n\t\t// it names none) when the application binds keys, else all of them.\n\t\tconst found = await deps.keys\n\t\t\t.list(user, {\n\t\t\t\tlimit: page.size,\n\t\t\t\tafter: page.after,\n\t\t\t\t...(deps.bound === undefined ? {} : { bound }),\n\t\t\t})\n\t\t\t.then(undefined, rethrown);\n\t\treturn {\n\t\t\titems: found.items.map((key) => apiKeyOut(key, now)),\n\t\t\tnextCursor: found.nextCursor,\n\t\t};\n\t};\n}\n\n/** `Query.boundApiKeys`: every key bound to the call's object, whoever holds it. */\nexport function boundApiKeys(deps: Deps): Queries['boundApiKeys'] {\n\treturn async (_, { boundTo, limit, after }, ctx): Promise<ApiKeyPageOut> => {\n\t\tconst page = pageOf(limit, after);\n\t\tconst { user, bound, now } = await callerOf(deps, ctx, boundTo);\n\t\tif (bound === null) throw denial('NOT_FOUND');\n\t\tawait allowed(\n\t\t\tdeps.authorize.list({ user, bound, every: true, page: page.asked }, ctx),\n\t\t);\n\t\tconst found = await deps.keys\n\t\t\t.listBound(bound, { limit: page.size, after: page.after })\n\t\t\t.then(undefined, rethrown);\n\t\treturn {\n\t\t\titems: found.items.map((key) => apiKeyOut(key, now)),\n\t\t\tnextCursor: found.nextCursor,\n\t\t};\n\t};\n}\n\n/** `Query.apiKeyLifetimes`: what `createApiKey` offers. */\nexport function apiKeyLifetimes(deps: Deps): Queries['apiKeyLifetimes'] {\n\treturn async (_, __, ctx) => {\n\t\tawait requireUser<AnyUser>(\n\t\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t\t);\n\t\treturn deps.lifetimes;\n\t};\n}\n",
20
+ "/**\n * The renewed session cookie: `authenticate` renews a sliding session in\n * passing, and `useJanus()` sends it again on the HTTP response — as\n * `@softistx/janus-hono`'s `session()` does — through Yoga's `onResponse`.\n */\n\nimport type { Session } from '@softistx/janus';\nimport { answerOf, cookieOfContext } from './context';\n\n/** The part of `auth.cookie` a renewal needs. */\nexport interface SessionCookie {\n\treadonly name: string;\n\tserialize(token: string, session: Session): string;\n}\n\n/** What Yoga hands `onResponse`: the part of it read here. */\nexport interface ResponsePayload {\n\treadonly request: Request;\n\treadonly response: Response;\n}\n\n/**\n * The contexts built for each HTTP request: one, or one per operation of a\n * batched request. A `WeakMap`, so an answered request takes its entry with\n * it.\n */\nconst contexts = new WeakMap<object, object[]>();\n\n/** The `Set-Cookie` values a resolver asked for, by request: a completed sign-in. */\nconst pending = new WeakMap<object, string[]>();\n\n/**\n * Asks `resendRenewed` to send `setCookie` on the response of `request`: the\n * session cookie of a sign-in a resolver made. Needs `useJanus()`'s\n * `onResponse` to run, so it is sent over HTTP through Yoga only.\n */\nexport function sendCookie(request: object, setCookie: string): void {\n\tconst known = pending.get(request);\n\tif (known === undefined) pending.set(request, [setCookie]);\n\telse known.push(setCookie);\n}\n\nconst uncached = new WeakSet<object>();\n\n/**\n * Asks `resendRenewed` to answer `Cache-Control: no-store` for `request`: a\n * response that carries a secret (a TOTP secret, recovery codes). Needs\n * `useJanus()`'s `onResponse`, so it holds over HTTP through Yoga only.\n */\nexport function sendNoStore(request: object): void {\n\tuncached.add(request);\n}\n\n/**\n * `sendNoStore` for a resolver that also runs without a request (graphql-ws,\n * a context built by hand): nothing is sent when `ctx` carries none.\n */\nexport function noStoreOf(\n\tctx: { readonly request?: Request } | undefined,\n): void {\n\tif (ctx?.request !== undefined) sendNoStore(ctx.request);\n}\n\n/** Remembers `janus` as a context built for `request`. */\nexport function track(request: object, janus: object): void {\n\tconst known = contexts.get(request);\n\tif (known === undefined) contexts.set(request, [janus]);\n\telse known.push(janus);\n}\n\n/**\n * Sends the session cookie again when a context of `request` renewed it —\n * only when `authenticate` ran for it, so an operation that asked nothing\n * costs nothing here. As `session()` in `@softistx/janus-hono`, only to a\n * request that presented the token as the session cookie — a client that sent\n * `Authorization: Bearer` or `X-Session-Token` is not handed a cookie it never\n * asked for — and never over a session cookie the response already sets.\n *\n * A failed `authenticate` sends nothing: its error is the response's.\n */\nexport async function resendRenewed(\n\t{ request, response }: ResponsePayload,\n\tfixed: SessionCookie | undefined,\n): Promise<void> {\n\tif (uncached.has(request)) response.headers.set('Cache-Control', 'no-store');\n\tfor (const setCookie of pending.get(request) ?? []) {\n\t\tresponse.headers.append('Set-Cookie', setCookie);\n\t}\n\tconst known = contexts.get(request);\n\tif (known === undefined) return;\n\tfor (const janus of known) {\n\t\tconst cookie = fixed ?? cookieOfContext(janus);\n\t\tif (cookie === undefined) continue;\n\t\tconst current = await answerOf(janus)?.then(\n\t\t\t(answer) => answer,\n\t\t\t() => null,\n\t\t);\n\t\tif (\n\t\t\tcurrent?.renewed === true &&\n\t\t\tcookieOf(request, cookie.name) === current.token &&\n\t\t\t!sets(response, cookie.name)\n\t\t) {\n\t\t\tresponse.headers.append(\n\t\t\t\t'Set-Cookie',\n\t\t\t\tcookie.serialize(current.token, current.session),\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** The value of the cookie `name` the request sent, or `null`. */\nexport function cookieOf(request: Request, name: string): string | null {\n\tconst header = request.headers.get('cookie');\n\tif (header === null) return null;\n\tfor (const pair of header.split(';')) {\n\t\tconst at = pair.indexOf('=');\n\t\tif (at !== -1 && pair.slice(0, at).trim() === name) {\n\t\t\treturn pair.slice(at + 1).trim();\n\t\t}\n\t}\n\treturn null;\n}\n\n/** Whether the response already sets the cookie `name`. */\nfunction sets(response: Response, name: string): boolean {\n\treturn response.headers\n\t\t.getSetCookie()\n\t\t.some((value) => value.startsWith(`${name}=`));\n}\n",
21
+ "/** The write fields: `createApiKey` and `revokeApiKey`. */\n\nimport type { ApiKey } from '@softistx/janus';\nimport { rethrown } from '../../errors';\nimport { noStoreOf } from '../../renewal';\nimport { apiKeyOut, boundedCreate, createRefused, lifetimeOf } from '../shape';\nimport type { ApiKeysResolvers } from '../types';\nimport {\n\tallowed,\n\ttype Caller,\n\tcallerOf,\n\ttype Deps,\n\tprincipalOf,\n\tsameBound,\n\tunknownKey,\n} from './deps';\n\ntype Mutations = ApiKeysResolvers['Mutation'];\n\n/**\n * `Mutation.createApiKey`: a key for the signed-in user, bound to the call's\n * object, and its secret once. The step-up is the core's: a session proved\n * within `apiKeys.freshWithin`, never a key.\n */\nexport function createApiKey(deps: Deps): Mutations['createApiKey'] {\n\treturn async (_, args, ctx) => {\n\t\tboundedCreate(args.name, args.scopes);\n\t\tconst lifetimeDays = lifetimeOf(deps.lifetimes, args.lifetimeDays);\n\t\tconst scopes = args.scopes ?? null;\n\t\tconst { user, bound, now } = await callerOf(deps, ctx, args.boundTo);\n\t\tawait allowed(\n\t\t\tdeps.authorize.create(\n\t\t\t\t{ user, bound, input: { name: args.name, lifetimeDays, scopes } },\n\t\t\t\tctx,\n\t\t\t),\n\t\t);\n\t\tconst current = await principalOf(ctx);\n\t\tconst created = await deps.keys\n\t\t\t.create(current, {\n\t\t\t\tname: args.name,\n\t\t\t\tlifetime: `${lifetimeDays}d`,\n\t\t\t\t...(scopes === null ? {} : { scopes }),\n\t\t\t\t...(bound === null ? {} : { bound }),\n\t\t\t})\n\t\t\t.then(undefined, createRefused);\n\t\t// The secret is in the answer: no cache keeps it.\n\t\tnoStoreOf(ctx);\n\t\treturn { apiKey: apiKeyOut(created.apiKey, now), secret: created.token };\n\t};\n}\n\n/**\n * The key `id` names, for the caller: the caller's own, or one bound to the\n * call's object. Read with `get` and no `owner`, so the ownership and the\n * bound object are checked here, and a key of neither kind is no key.\n */\nasync function located(deps: Deps, caller: Caller, id: string) {\n\tconst { user, bound } = caller;\n\tconst key = await deps.keys.get(id).then(undefined, rethrown);\n\tif (key === null) return null;\n\tconst binds = deps.bound !== undefined;\n\tif (key.userId === user.id && (!binds || sameBound(key.bound, bound))) {\n\t\treturn { key, own: true };\n\t}\n\tif (bound !== null && sameBound(key.bound, bound)) return { key, own: false };\n\treturn null;\n}\n\n/**\n * `Mutation.revokeApiKey`: revokes the caller's own key, or — as `authorize`\n * allows — one bound to the call's object, and answers it as stored after.\n */\nexport function revokeApiKey(deps: Deps): Mutations['revokeApiKey'] {\n\treturn async (_, { id, boundTo }, ctx) => {\n\t\tconst caller = await callerOf(deps, ctx, boundTo);\n\t\tconst { user, bound } = caller;\n\t\tconst found = await located(deps, caller, id);\n\t\tif (found === null) {\n\t\t\treturn unknownKey(() => deps.authorize.revoke({ user, bound }, ctx));\n\t\t}\n\t\tconst { key, own } = found;\n\t\tawait allowed(deps.authorize.revoke({ user, bound, key, own }, ctx));\n\t\t// The owner check of the core for one's own key; another's was found\n\t\t// bound to the object, which is what `authorize` allowed.\n\t\tawait deps.keys\n\t\t\t.revoke(key.id, own ? { owner: user } : {})\n\t\t\t.then(undefined, rethrown);\n\t\tconst after: ApiKey = (await deps.keys\n\t\t\t.get(key.id)\n\t\t\t.then(undefined, rethrown)) ?? {\n\t\t\t...key,\n\t\t\trevokedAt: key.revokedAt ?? new Date(caller.now),\n\t\t};\n\t\treturn apiKeyOut(after, caller.now);\n\t};\n}\n",
22
+ "/**\n * The resolvers of the API key SDL: three `Query` fields and two `Mutation`\n * fields over the core's `apiKeys`.\n */\n\nimport type {\n\tApiKeysAuth,\n\tApiKeysResolvers,\n\tApiKeysResolversOptions,\n} from '../types';\nimport { depsOf } from './deps';\nimport { apiKeyLifetimes, apiKeys, boundApiKeys } from './list';\nimport { createApiKey, revokeApiKey } from './manage';\n\n/**\n * The resolvers of the API key SDL. A refusal of the core —\n * `API_KEY_INVALID` (`field`), `API_KEY_LIMIT` (`maxActive`),\n * `STEP_UP_REQUIRED`, `USER_INACTIVE`, `INVALID_CURSOR`… — is rethrown as its\n * `GraphQLError`, so `janusMaskError()` answers its code and status. Needs\n * `useJanus()` for the directives. Throws a `TypeError` at wiring when `auth`\n * has no `apiKeys`, `authorize` lacks a hook, or `lifetimes` lists no\n * lifetime or a default outside it.\n *\n * **`authorize` is the only guard**: say who may create, list and revoke,\n * and which scopes a caller may grant. `bound` names the object a key acts\n * in, for an application that binds keys.\n *\n * ```ts\n * const resolvers = mergeResolvers([\n * apiKeysResolvers({\n * auth,\n * lifetimes: { days: [30, 90, 365], default: 90 },\n * bound: (id) => (id === null ? null : { type: 'workspace', id }),\n * authorize: {\n * create: ({ bound }, ctx) => bound !== null && can(ctx, 'member', bound),\n * list: ({ bound, every }, ctx) => bound !== null && can(ctx, every ? 'own' : 'member', bound),\n * revoke: ({ bound, own }, ctx) => own === true || (bound !== null && can(ctx, 'own', bound)),\n * },\n * }),\n * mine,\n * ]);\n * ```\n *\n * `Query` and `Mutation` are keys of the map: merge it with yours rather than\n * spreading over them.\n */\nexport function apiKeysResolvers<A extends ApiKeysAuth>(\n\toptions: ApiKeysResolversOptions<A>,\n): ApiKeysResolvers {\n\tconst deps = depsOf(options);\n\treturn {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tQuery: {\n\t\t\tapiKeys: apiKeys(deps),\n\t\t\tboundApiKeys: boundApiKeys(deps),\n\t\t\tapiKeyLifetimes: apiKeyLifetimes(deps),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tMutation: {\n\t\t\tcreateApiKey: createApiKey(deps),\n\t\t\trevokeApiKey: revokeApiKey(deps),\n\t\t},\n\t};\n}\n",
23
+ "/**\n * The opt-in API key SDL: put it beside your own type definitions when users\n * create keys for themselves (a CLI, an MCP client, a script). It `extend`s\n * your `Query` and `Mutation`, and needs `janusTypeDefs` for its directives.\n * The same text ships as `graphql/janus-api-keys.graphqls` — `sdl.spec.ts`\n * holds that the two are identical. Timestamps are ISO-8601 `String`s: no\n * scalar to collide with.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, apiKeysTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const apiKeysTypeDefs: string = `\"\"\"\nA personal API key, as its holder and the bound object's owners see it. The\nsecret is never here: \\`createApiKey\\` answers it once.\n\"\"\"\ntype JanusApiKey {\n\t\"\"\"\n\tThe key's id: what \\`revokeApiKey\\` takes. Not the secret.\n\t\"\"\"\n\tid: ID!\n\t\"\"\"\n\tThe id of the user who holds the key.\n\t\"\"\"\n\tuserId: ID!\n\t\"\"\"\n\tThe label its holder chose, 1 to 100 characters.\n\t\"\"\"\n\tname: String!\n\t\"\"\"\n\tThe start of the token: its prefix and the first characters of its id\n\t(\\`sl_0192ab…\\`). Enough to recognise the key, not to use it.\n\t\"\"\"\n\tprefix: String!\n\t\"\"\"\n\tWhat the key may do, as given at creation (\\`mcp:read\\`), or null for a key\n\tthat may do whatever its user may. Janus never enforces them: the\n\tapplication does, where it serves the key's requests.\n\t\"\"\"\n\tscopes: [String!]\n\t\"\"\"\n\tThe one object the key acts in, or null for an unbound key.\n\t\"\"\"\n\tbound: JanusApiKeyBound\n\t\"\"\"\n\t\\`ACTIVE\\`, \\`REVOKED\\` or \\`EXPIRED\\`.\n\t\"\"\"\n\tstatus: JanusApiKeyStatus!\n\t\"\"\"\n\tWhen the key was created, as an ISO-8601 string.\n\t\"\"\"\n\tcreatedAt: String!\n\t\"\"\"\n\tWhen the key stops being usable, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhen the key was last used, as an ISO-8601 string; null while it was never\n\tused. It moves at most once per throttle window.\n\t\"\"\"\n\tlastUsedAt: String\n\t\"\"\"\n\tWhen the key was revoked, as an ISO-8601 string; null while the key stands.\n\t\"\"\"\n\trevokedAt: String\n}\n\n\"\"\"\nThe object a key is bound to: a workspace, an account, a project… as the\napplication names it.\n\"\"\"\ntype JanusApiKeyBound {\n\t\"\"\"\n\tWhat the object is, as the application names its kinds (\\`workspace\\`).\n\t\"\"\"\n\ttype: String!\n\t\"\"\"\n\tThe id of the object.\n\t\"\"\"\n\tid: ID!\n}\n\n\"\"\"\nWhether a key can still be used.\n\"\"\"\nenum JanusApiKeyStatus {\n\t\"\"\"\n\tUsable until \\`expiresAt\\`.\n\t\"\"\"\n\tACTIVE\n\t\"\"\"\n\tRevoked (\\`revokedAt\\`): refused from then on.\n\t\"\"\"\n\tREVOKED\n\t\"\"\"\n\tPast \\`expiresAt\\` without being revoked.\n\t\"\"\"\n\tEXPIRED\n}\n\n\"\"\"\nA key just created: \\`secret\\` is the whole token, answered this once.\n\"\"\"\ntype JanusCreatedApiKey {\n\t\"\"\"\n\tThe key that was created, as \\`apiKeys\\` lists it.\n\t\"\"\"\n\tapiKey: JanusApiKey!\n\t\"\"\"\n\tThe whole token (\\`sl_…\\`). Shown only in this answer and never stored: a\n\tlost secret is a new key. The response is \\`no-store\\`.\n\t\"\"\"\n\tsecret: String!\n}\n\n\"\"\"\nOne page of keys, oldest first. \\`nextCursor\\` is null on the last page; a page\nmay hold fewer than \\`limit\\` keys and still have a next one.\n\"\"\"\ntype JanusApiKeyPage {\n\t\"\"\"\n\tThe keys of this page, oldest first.\n\t\"\"\"\n\titems: [JanusApiKey!]!\n\t\"\"\"\n\tPass it as \\`after\\` to read the next page; null on the last page.\n\t\"\"\"\n\tnextCursor: String\n}\n\n\"\"\"\nThe lifetimes \\`createApiKey\\` offers, in days, and the one it takes when\n\\`lifetimeDays\\` is absent.\n\"\"\"\ntype JanusApiKeyLifetimes {\n\t\"\"\"\n\tThe lifetimes a new key may have, in days.\n\t\"\"\"\n\tdays: [Int!]!\n\t\"\"\"\n\tThe lifetime, in days, taken when \\`lifetimeDays\\` is absent.\n\t\"\"\"\n\tdefault: Int!\n}\n\nextend type Query {\n\t\"\"\"\n\tThe signed-in user's own keys — standing, revoked and expired — oldest\n\tfirst; when the application binds keys, only those bound to the object\n\t\\`boundTo\\` names (or that the request's context names). \\`limit\\` is a\n\tpositive integer, 20 by default and at most 100; \\`after\\` is the previous\n\tpage's \\`nextCursor\\`. NOT_FOUND when the application's \\`authorize\\` refuses,\n\tor \\`boundTo\\` names no object. A \\`boundTo\\` empty or over 200 characters is\n\tBAD_USER_INPUT (\\`field\\`).\n\t\"\"\"\n\tapiKeys(\n\t\t\"\"\"\n\t\tThe object whose keys to list; absent: the one the request's context\n\t\tnames, when the application binds keys.\n\t\t\"\"\"\n\t\tboundTo: ID\n\t\t\"\"\"\n\t\tThe page size: a positive integer, 20 by default, at most 100.\n\t\t\"\"\"\n\t\tlimit: Int\n\t\t\"\"\"\n\t\tThe previous page's \\`nextCursor\\`; absent for the first page.\n\t\t\"\"\"\n\t\tafter: String\n\t): JanusApiKeyPage! @authenticated\n\t\"\"\"\n\tEvery key bound to the object \\`boundTo\\` names (or that the request's\n\tcontext names), whoever holds it: the object owner's view. Paged and\n\trefused as \\`apiKeys\\`, and NOT_FOUND when there is no object.\n\t\"\"\"\n\tboundApiKeys(\n\t\t\"\"\"\n\t\tThe object whose keys to list; absent: the one the request's context names.\n\t\t\"\"\"\n\t\tboundTo: ID\n\t\t\"\"\"\n\t\tThe page size: a positive integer, 20 by default, at most 100.\n\t\t\"\"\"\n\t\tlimit: Int\n\t\t\"\"\"\n\t\tThe previous page's \\`nextCursor\\`; absent for the first page.\n\t\t\"\"\"\n\t\tafter: String\n\t): JanusApiKeyPage! @authenticated\n\t\"\"\"\n\tThe lifetimes a new key may have.\n\t\"\"\"\n\tapiKeyLifetimes: JanusApiKeyLifetimes! @authenticated\n}\n\nextend type Mutation {\n\t\"\"\"\n\tCreates a key for the signed-in user. Needs a recent step-up. The key is\n\tbound to the object \\`boundTo\\` names (or that the request's context names)\n\twhen the application binds keys, and answers its \\`secret\\`, the only time\n\tit is shown. \\`lifetimeDays\\` is one of \\`apiKeyLifetimes.days\\` (its\n\t\\`default\\` when absent; BAD_USER_INPUT otherwise); \\`scopes\\` are what the\n\tkey may do (absent: whatever its user may). STEP_UP_REQUIRED (403) unless\n\tthe session proved who it is recently, and always for a request signed by\n\ta key: a key never creates a key. API_KEY_INVALID (400, \\`field\\`) for a\n\tname or scopes the core cannot keep, API_KEY_LIMIT (409, \\`maxActive\\`) when\n\tthe user holds the most standing keys, NOT_FOUND when \\`authorize\\` refuses.\n\tA \\`name\\` over 100 characters, more than 32 \\`scopes\\` or one over 100\n\tcharacters is BAD_USER_INPUT (400, \\`field\\`) before \\`authorize\\` runs.\n\t\"\"\"\n\tcreateApiKey(\n\t\t\"\"\"\n\t\tThe label for the key, 1 to 100 characters.\n\t\t\"\"\"\n\t\tname: String!\n\t\t\"\"\"\n\t\tOne of \\`apiKeyLifetimes.days\\`; absent: its \\`default\\`.\n\t\t\"\"\"\n\t\tlifetimeDays: Int\n\t\t\"\"\"\n\t\tWhat the key may do, at most 32 of at most 100 characters each; absent:\n\t\twhatever its user may.\n\t\t\"\"\"\n\t\tscopes: [String!]\n\t\t\"\"\"\n\t\tThe object to bind the key to, at most 200 characters; absent: the one\n\t\tthe request's context names, when the application binds keys.\n\t\t\"\"\"\n\t\tboundTo: ID\n\t): JanusCreatedApiKey! @authenticated\n\t\"\"\"\n\tRevokes a key and answers it; revoking a revoked key is not an error. The\n\tkey is the signed-in user's own, or one bound to the object \\`boundTo\\`\n\tnames (or that the request's context names), as \\`authorize\\` allows.\n\tNOT_FOUND for an id that names neither, whatever \\`authorize\\` answers, and\n\twhen \\`authorize\\` refuses.\n\t\"\"\"\n\trevokeApiKey(\n\t\t\"\"\"\n\t\tThe id of the key to revoke.\n\t\t\"\"\"\n\t\tid: ID!\n\t\t\"\"\"\n\t\tThe object the key is bound to; absent: the one the request's context\n\t\tnames, or none for the user's own key.\n\t\t\"\"\"\n\t\tboundTo: ID\n\t): JanusApiKey! @authenticated\n}\n`;\n",
24
+ "/**\n * The resolvers of `JanusAvatar`, keyed as `createSchema` expects: `updatedAt`\n * as an ISO-8601 string, and `url(size:)` from the application's own route.\n */\n\nimport { GraphQLError } from 'graphql';\nimport type { AvatarParent } from './index';\n\n/** What `avatarResolvers()` takes. */\nexport interface AvatarResolversOptions {\n\t/**\n\t * The URL of your own route that streams the image of `avatar.userId` at\n\t * `size` — which checks the session and access first. Put the avatar's id\n\t * in it (`?v=${encodeURIComponent(avatar.id)}`; ids are the application's\n\t * own, so encode them), so a new upload is a new URL for the browser's\n\t * cache. `avatar` is the parent `toJanusAvatar()` made — at least `userId` and `id`\n\t * are what a route needs. `size` is already a positive integer.\n\t */\n\treadonly url: (avatar: AvatarParent, size: number) => string;\n}\n\n/** The resolver map for `JanusAvatar`, keyed as `createSchema` expects. */\nexport interface AvatarResolvers {\n\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\treadonly JanusAvatar: {\n\t\treadonly updatedAt: (avatar: AvatarParent) => string;\n\t\treadonly url: (\n\t\t\tavatar: AvatarParent,\n\t\t\targs: { readonly size: number },\n\t\t) => string;\n\t};\n}\n\n/**\n * The resolvers of `JanusAvatar`: `updatedAt` as an ISO-8601 string, and\n * `url(size:)` from your `url` function. A `size` that is not a positive\n * integer is refused `BAD_USER_INPUT`, 400, before `url` is called; which\n * sizes exist is your route's to decide — it answers 404 for the others.\n *\n * ```ts\n * const resolvers = {\n * ...avatarResolvers({ url: ({ userId, id }, size) => `/avatars/${userId}/${size}?v=${encodeURIComponent(id)}` }),\n * Viewer: { avatar: (user) => toJanusAvatar(user) },\n * };\n * ```\n */\nexport function avatarResolvers(\n\toptions: AvatarResolversOptions,\n): AvatarResolvers {\n\treturn {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tJanusAvatar: {\n\t\t\tupdatedAt: (avatar) => avatar.updatedAt.toISOString(),\n\t\t\turl: (avatar, { size }) => {\n\t\t\t\tif (!Number.isSafeInteger(size) || size < 1) {\n\t\t\t\t\t// Not denial(): that one speaks of access (401/403/404), this is a bad argument.\n\t\t\t\t\tthrow new GraphQLError('size must be a positive integer', {\n\t\t\t\t\t\textensions: { code: 'BAD_USER_INPUT', http: { status: 400 } },\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn options.url(avatar, size);\n\t\t\t},\n\t\t},\n\t};\n}\n",
25
+ "/**\n * The opt-in avatar type as SDL: put it beside your own type definitions when\n * accounts have avatars. The same text ships as\n * `graphql/janus-avatar.graphqls` — `sdl.spec.ts` holds that the two are\n * identical.\n *\n * `updatedAt` is an ISO-8601 `String` rather than a `DateTime`: the package\n * defines no scalar, so it cannot collide with the one your schema already\n * declares, or force you to declare one.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, janusAvatarTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusAvatarTypeDefs: string = `\"\"\"\nThe image of an account, as the application's resolvers hand it out.\n\\`updatedAt\\` is an ISO-8601 string, so the type needs no scalar.\n\"\"\"\ntype JanusAvatar {\n\t\"\"\"\n\tThe id the application stored the image under; changes with every upload.\n\t\"\"\"\n\tid: ID!\n\t\"\"\"\n\tWhen the avatar was set, as an ISO-8601 string.\n\t\"\"\"\n\tupdatedAt: String!\n\t\"\"\"\n\tThe URL of the application's own route that streams the image at this\n\tsize, behind its session and access check. Never a public URL.\n\t\"\"\"\n\turl(size: Int!): String!\n}\n`;\n",
26
+ "/**\n * The avatar surface, opt-in: `JanusAvatar` for a field of your own types,\n * `toJanusAvatar(user)` for the parent that field returns, and\n * `avatarResolvers({ url })` for the type's fields. Janus keeps only the\n * avatar's id; the bytes, and the route that serves them, are the\n * application's.\n */\n\nimport type { UserBase } from '@softistx/janus';\n\n/** What `toJanusAvatar()` reads: the part of a user this needs, as `@softistx/janus` types it. */\nexport type AvatarOwner = Pick<UserBase, 'id' | 'avatar'>;\n\n/** The parent object of a `JanusAvatar` field: the owner's id, and the avatar. */\nexport interface AvatarParent {\n\treadonly userId: string;\n\treadonly id: string;\n\treadonly updatedAt: Date;\n}\n\n/**\n * The parent for an `avatar: JanusAvatar` field of your own type — `null`\n * when the user has none.\n *\n * ```ts\n * Viewer: { avatar: (user) => toJanusAvatar(user) }\n * ```\n *\n * **It checks nothing about who asks**: guard the field (`@permission`, or\n * `can()` in the resolver) before it answers.\n */\nexport function toJanusAvatar(user: AvatarOwner): AvatarParent | null {\n\treturn user.avatar === null\n\t\t? null\n\t\t: { userId: user.id, id: user.avatar.id, updatedAt: user.avatar.updatedAt };\n}\n\nexport type {\n\tAvatarResolvers,\n\tAvatarResolversOptions,\n} from './resolvers';\nexport { avatarResolvers } from './resolvers';\nexport { janusAvatarTypeDefs } from './sdl';\n",
27
+ "/**\n * The wiring checks `useJanus()` and `janusConnection()` share: what each\n * refuses at start-up, with a `TypeError` naming the call that was written.\n */\n\n/** What both calls take and check before anything runs. */\nexport interface Wiring {\n\treadonly auth: unknown;\n\treadonly access?: unknown;\n\treadonly clock?: unknown;\n}\n\n/**\n * Refuses an `auth` that is neither what `janus()` answered nor a function, an `access` that\n * is not what `permissions()` answered, and a `clock` that is not a\n * `Clock` — each a `TypeError` naming `caller`.\n */\nexport function checkWiring(caller: string, { auth, access, clock }: Wiring) {\n\tif (\n\t\ttypeof auth !== 'function' &&\n\t\ttypeof (auth as { readonly authenticate?: unknown } | null)\n\t\t\t?.authenticate !== 'function'\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: auth is not what janus() answered — pass { auth }`,\n\t\t);\n\t}\n\tif (\n\t\taccess !== undefined &&\n\t\ttypeof (access as { readonly can?: unknown } | null)?.can !== 'function'\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: access is not what permissions() answered — pass { auth, access }`,\n\t\t);\n\t}\n\tif (\n\t\tclock !== undefined &&\n\t\ttypeof (clock as { readonly now?: unknown } | null)?.now !== 'function'\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: clock is not a Clock — pass the clock given to janus(), or leave it out for the system clock`,\n\t\t);\n\t}\n}\n",
28
+ "/**\n * The credential a graphql-ws connection presents, and the connections\n * `janusConnection().onConnect` accepted: what each operation on one is\n * authenticated from.\n */\n\nimport type { RequestLike } from '@softistx/janus';\nimport type { ConnectionContext } from './types';\n\n/** Where the upgrade request is, when the transport does not say `extra.request`. */\nexport type Upgrade = (ctx: ConnectionContext) => RequestLike | undefined;\n\n/** The scheme `@softistx/janus` reads a session token from — any case, as it does. */\nconst BEARER = /^\\s*bearer(?:\\s|$)/i;\n\n/**\n * The connection's credential, as `auth.authenticate` reads one:\n *\n * 1. `connectionParams.authorization`, when it is a `Bearer` token — a\n * non-browser client's `'Bearer <token>'`;\n * 2. otherwise the upgrade request itself, read as any request is —\n * `Authorization`, then `X-Session-Token`, then the session cookie a\n * browser sends with it.\n *\n * **The first present wins, not the first valid one**, as in `@softistx/janus`:\n * a lapsed token in `connectionParams` beside a live cookie is refused. An\n * `authorization` of another scheme (`Basic`) is not a session credential,\n * as in `@softistx/janus`, and does not count. `null` when there is nothing to\n * read, or an `authorization` that is not a string — refused, as a\n * client's mistake.\n */\nexport function credentialOf(\n\tctx: ConnectionContext,\n\tupgrade: Upgrade | undefined,\n): RequestLike | null {\n\tconst params = ctx.connectionParams;\n\tif (params !== undefined && Object.hasOwn(params, 'authorization')) {\n\t\tconst { authorization } = params;\n\t\tif (typeof authorization !== 'string') return null;\n\t\t// A record, not `Headers`, which would throw on a value no header may\n\t\t// hold: a client's mistake is a refusal, never a 4500.\n\t\tif (BEARER.test(authorization)) return { authorization };\n\t}\n\tconst request =\n\t\tupgrade === undefined\n\t\t\t? (ctx.extra as { readonly request?: RequestLike } | null)?.request\n\t\t\t: upgrade(ctx);\n\treturn request ?? null;\n}\n\n/**\n * The credential of each connection `onConnect` accepted, by its `extra`:\n * the one object graphql-ws hands every callback of a connection, and that\n * Yoga's recipe spreads into the context it builds. A `WeakMap`, so a\n * closed connection takes its entry with it, and nothing a request carries\n * can name one.\n */\nconst accepted = new WeakMap<object, RequestLike>();\n\n/** Remembers `credential` as the one `ctx`'s connection presented. */\nexport function accept(ctx: ConnectionContext, credential: RequestLike) {\n\tconst { extra } = ctx;\n\tif (typeof extra !== 'object' || extra === null) {\n\t\tthrow new TypeError(\n\t\t\t\"janusConnection(): the connection's extra is not an object — pass the context graphql-ws gave onConnect\",\n\t\t);\n\t}\n\taccepted.set(extra, credential);\n}\n\n/**\n * The credential of the connection a context was built for, or `undefined`\n * for one no `onConnect` accepted — and for every HTTP request.\n */\nexport function acceptedOf(context: unknown): RequestLike | undefined {\n\tconst extra = (context as { readonly extra?: unknown } | null)?.extra;\n\tif (typeof extra !== 'object' || extra === null) return undefined;\n\treturn accepted.get(extra);\n}\n",
29
+ "/**\n * `janusConnection()`: authenticated subscriptions over graphql-ws.\n */\n\nimport { createJanusContext, resolveAuth } from '../context';\nimport { checkWiring } from '../options';\nimport type { Auth, JanusContext, UserOfAuth } from '../types';\nimport { accept, acceptedOf, credentialOf } from './credential';\nimport type { JanusConnection, JanusConnectionOptions } from './types';\n\n/**\n * The pieces of graphql-ws's `useServer()` that authenticate a WebSocket\n * connection, for Yoga's recommended setup:\n *\n * ```ts\n * const connection = janusConnection({ auth });\n * useServer({\n * onConnect: connection.onConnect,\n * execute: (args) => args.rootValue.execute(args),\n * subscribe: (args) => args.rootValue.subscribe(args),\n * onSubscribe: async (ctx, _id, params) => { … yoga.getEnveloped({ ...ctx, … }) … },\n * }, wsServer);\n * ```\n *\n * `onConnect` reads the connection's credential — `connectionParams`'\n * `authorization`, else the upgrade request's headers and cookie — and\n * refuses it unless it authenticates, as a user of `type` when it is given.\n * Each operation on the connection then gets a `ctx.janus` of its own from\n * `useJanus()`, authenticated again from that credential when a field asks:\n * `@authenticated`, `@fresh` and `@permission` hold as over HTTP, and a\n * session revoked since the connection opened is refused at the next\n * subscribe.\n *\n * A server without Yoga passes `context` too, and applies the directives\n * with `applyJanusDirectives()`.\n */\nexport function janusConnection<\n\tA extends Auth<{ readonly type: string; readonly id: string }>,\n\tP extends object | undefined = undefined,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n>(options: JanusConnectionOptions<A, P, T>): JanusConnection<A, P, T> {\n\tconst { auth, access, type, clock } = options;\n\tcheckWiring('janusConnection()', { auth, access, clock });\n\tif (options.upgrade !== undefined && typeof options.upgrade !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t'janusConnection(): upgrade is not a function — pass (ctx) => the upgrade request, or leave it out to read ctx.extra.request',\n\t\t);\n\t}\n\tconst upgrade = options.upgrade?.bind(options);\n\tconst wiring = {\n\t\tauth,\n\t\taccess: access as { readonly can: unknown } | undefined,\n\t\ttype,\n\t\tclock,\n\t\tcaller: 'janusConnection().context',\n\t};\n\n\treturn {\n\t\tonConnect: async (ctx) => {\n\t\t\tconst credential = credentialOf(ctx, upgrade);\n\t\t\tif (credential === null) return false;\n\t\t\t// An outage rejects here, and graphql-ws closes the socket 4500:\n\t\t\t// never `false`, which a client reads as a refusal.\n\t\t\tconst instance = await resolveAuth(\n\t\t\t\tauth,\n\t\t\t\tctx,\n\t\t\t\t'janusConnection()',\n\t\t\t\t'connection',\n\t\t\t);\n\t\t\tconst current = await instance.authenticate(\n\t\t\t\tcredential,\n\t\t\t\ttype === undefined ? undefined : { type },\n\t\t\t);\n\t\t\tif (current === null) return false;\n\t\t\taccept(ctx, credential);\n\t\t\treturn true;\n\t\t},\n\t\t// The one cast at the boundary: the context is built loose, typed here.\n\t\tcontext: (ctx) =>\n\t\t\t({\n\t\t\t\tjanus: createJanusContext(acceptedOf(ctx), {\n\t\t\t\t\t...wiring,\n\t\t\t\t\tcontext: ctx,\n\t\t\t\t\twhat: 'connection',\n\t\t\t\t}),\n\t\t\t}) as unknown as JanusContext<A, P, T>,\n\t};\n}\n",
30
+ "/**\n * The device cookie: the long-lived cookie that holds the device token\n * `@softistx/janus` answers as `deviceToken`, read from the request a\n * sign-in mutation received and set back on the response it will send.\n * The same names, defaults and option shape as `@softistx/janus-hono`.\n */\n\nimport {\n\tDEVICE_COOKIE,\n\ttype DeviceCookieOptions,\n\tdeviceCookie,\n\tdeviceFromCookieHeader,\n} from '@softistx/janus';\nimport { sendCookie } from './renewal';\n\n// The cookie's name, options and wire format belong to `@softistx/janus`.\nexport { DEVICE_COOKIE, type DeviceCookieOptions };\n\n/** The request, or a clear refusal: over graphql-ws a context has none. */\nfunction checked(request: Request | undefined, call: string): Request {\n\tif (typeof request?.headers?.get !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t`${call}(): the GraphQL context has no request — the device cookie is an HTTP matter, so call it from an operation served over HTTP (Yoga), not graphql-ws`,\n\t\t);\n\t}\n\treturn request;\n}\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(args, { device: deviceOf(ctx.request) });\n * ```\n */\nexport function deviceOf(\n\trequest: Request,\n\toptions: DeviceCookieOptions = {},\n): string | null {\n\treturn deviceFromCookieHeader(\n\t\tchecked(request, 'deviceOf').headers.get('cookie'),\n\t\toptions,\n\t);\n}\n\n/**\n * Sets the device cookie, or sets it again so it lasts another `maxAge`:\n * queues its `Set-Cookie` for `useJanus()` to append to Yoga's response,\n * beside any other cookie the response sets.\n *\n * ```ts\n * if (result.deviceToken !== null) sendDevice(ctx.request, result.deviceToken);\n * ```\n */\nexport function sendDevice(\n\trequest: Request,\n\tdeviceToken: string,\n\toptions: DeviceCookieOptions = {},\n): void {\n\tsendCookie(\n\t\tchecked(request, 'sendDevice'),\n\t\tdeviceCookie(deviceToken, options),\n\t);\n}\n",
31
+ "/**\n * The schema transform: every object field a directive guards gets its\n * resolver wrapped, once, when the schema is built.\n */\n\nimport { MapperKind, mapSchema } from '@graphql-tools/utils';\nimport { defaultFieldResolver, type GraphQLSchema } from 'graphql';\nimport { guarded } from './guard';\nimport { readField } from './read';\nimport { type Known, requirementOf } from './validate';\nimport { list, PREFIX } from './words';\n\ntype Entries = {\n\treadonly [type: string]: ((...args: never[]) => unknown) | undefined;\n};\n\n/** What `applyJanusDirectives()` takes. */\nexport interface JanusDirectivesOptions<T extends string = string> {\n\t/**\n\t * What `janus()` answered: its `types` are the names `type:` may take.\n\t * `types: null` (a server whose instance is chosen per request) checks\n\t * none.\n\t */\n\treadonly auth: { readonly types: readonly T[] | null };\n\t/** `useJanus({ type })`'s: the one user type the schema's users can have. */\n\treadonly type?: NoInfer<T>;\n\t/** What `permissions()` answered: its model is what `@permission` may name. Required once a schema uses it. */\n\treadonly access?: { readonly model: unknown } | undefined;\n\t/** `useJanus({ loaders })`'s. */\n\treadonly loaders?: Entries | undefined;\n\t/** `useJanus({ conditions })`'s. */\n\treadonly conditions?: Entries | undefined;\n}\n\n/**\n * The schema with every field guarded by `@authenticated`, `@fresh` or\n * `@permission` — on the field, on its type, or on an interface the type\n * implements — wrapped so its resolver runs only for a signed-in user, of\n * one of the types `type:` names when it names some, on a session that\n * proved who it is less than `maxAge` seconds ago, holding every permission\n * asked. Every directive that applies must hold.\n *\n * `useJanus()` calls it on every schema it is given. Call it yourself to\n * check a schema without a server: the guards it installs read `ctx.janus`,\n * which only `useJanus()` builds.\n *\n * **Refuses when the schema is built**, with a `TypeError` naming the\n * field: a user type `auth` does not know, a `type: []`, restrictions no\n * user type meets together, a `@fresh` whose `maxAge` is not above zero;\n * for `@permission`, an object type or a permission the model does not\n * declare, a malformed `id:`, an argument the field does not take, and a\n * loader or a condition's `ctx` it needs and was not given.\n */\nexport function applyJanusDirectives<const T extends string>(\n\tschema: GraphQLSchema,\n\toptions: JanusDirectivesOptions<T>,\n): GraphQLSchema {\n\tconst known = knownOf(options);\n\treturn mapSchema(schema, {\n\t\t[MapperKind.OBJECT_FIELD]: (field, fieldName, typeName) => {\n\t\t\tconst requirement = requirementOf(\n\t\t\t\t{\n\t\t\t\t\tname: `${typeName}.${fieldName}`,\n\t\t\t\t\targs: Object.keys(field.args ?? {}),\n\t\t\t\t},\n\t\t\t\treadField(schema, field, fieldName, typeName),\n\t\t\t\tknown,\n\t\t\t\toptions,\n\t\t\t);\n\t\t\tif (requirement === null) return field;\n\t\t\tconst resolve = field.resolve ?? defaultFieldResolver;\n\t\t\tif (field.subscribe === undefined) {\n\t\t\t\treturn { ...field, resolve: guarded(resolve, requirement) };\n\t\t\t}\n\t\t\t// A subscription's freshness is checked when it subscribes: its\n\t\t\t// events keep coming past maxAge, as its session keeps standing.\n\t\t\tconst onEvent = { ...requirement, maxAgeMs: null };\n\t\t\treturn {\n\t\t\t\t...field,\n\t\t\t\tsubscribe: guarded(field.subscribe, requirement),\n\t\t\t\tresolve: guarded(resolve, onEvent),\n\t\t\t};\n\t\t},\n\t});\n}\n\n/** The user types a directive may name — `type` alone when it is given, and one of `auth.types`. */\nfunction knownOf({ auth, type }: JanusDirectivesOptions): Known {\n\tif (type === undefined) return { types: auth.types };\n\tif (auth.types !== null && !auth.types.includes(type)) {\n\t\tthrow new TypeError(\n\t\t\t`${PREFIX}: type '${type}' is not a user type of auth — it knows ${list(auth.types)}`,\n\t\t);\n\t}\n\treturn { types: [type] };\n}\n",
32
+ "/**\n * Freshness: whether the request's session proved who it is recently enough\n * — the check `@fresh` runs before a field, and `requireFresh()` in a\n * resolver. Both are `@softistx/janus`'s `assertFresh`, on the clock given to\n * `useJanus({ clock })`.\n */\n\nimport {\n\tassertFresh,\n\ttype Duration,\n\ttype Principal,\n\tparseDuration,\n\ttype Session,\n} from '@softistx/janus';\nimport { clockOf, janusOf } from './context';\nimport { denial, rethrown } from './errors';\n\n/**\n * The request's session, once it proved who it is less than `maxAgeMs` ago\n * — or a denial: `UNAUTHENTICATED` 401 for an anonymous request,\n * `STEP_UP_REQUIRED` 403 for an older session or, under `apiKey: true`, an\n * API key (which has no session and is never fresh). A store that cannot answer is\n * `SERVICE_UNAVAILABLE` 503, never either of them.\n */\nexport async function freshSession(\n\tjanus: {\n\t\tsession(): Promise<Session | null>;\n\t\tprincipal?(): Promise<Principal<{ readonly id: string }> | null>;\n\t},\n\tmaxAgeMs: number,\n): Promise<Session> {\n\t// With `apiKey: true`, ask who the request is: a key has no session, and\n\t// is refused `STEP_UP_REQUIRED` (reason `apiKey`), not called anonymous.\n\tconst subject =\n\t\ttypeof janus.principal === 'function'\n\t\t\t? await janus.principal().then(undefined, rethrown)\n\t\t\t: await janus.session().then(undefined, rethrown);\n\tif (subject === null) throw denial('UNAUTHENTICATED');\n\ttry {\n\t\tassertFresh(\n\t\t\tsubject as Principal<{ readonly id: string }>,\n\t\t\tmaxAgeMs,\n\t\t\tclockOf(janus),\n\t\t);\n\t} catch (error) {\n\t\trethrown(error);\n\t}\n\treturn 'via' in subject ? (subject.session as Session) : subject;\n}\n\n/**\n * The request's session, once it proved who it is less than `maxAge` ago —\n * signed in, or confirmed since by `auth.stepUp.confirm` — or a denial:\n * `UNAUTHENTICATED` 401 for an anonymous request, `STEP_UP_REQUIRED` 403 for\n * an older session, which tells the client to ask for a step-up.\n *\n * ```ts\n * await requireFresh(ctx, '10m'); // before changing the e-mail\n * ```\n *\n * `maxAge` is a duration with its unit — `'10m'`, `'600s'` — never a bare\n * number, which `@softistx/janus` reads as milliseconds where `@fresh` reads\n * seconds: a `TypeError`, as any other malformed duration.\n */\nexport async function requireFresh(\n\tctx: {\n\t\treadonly janus: {\n\t\t\tuser(): Promise<unknown>;\n\t\t\tsession(): Promise<Session | null>;\n\t\t\tprincipal?(): Promise<Principal<{ readonly id: string }> | null>;\n\t\t};\n\t},\n\tmaxAge: Exclude<Duration, number>,\n): Promise<Session> {\n\tif (typeof maxAge !== 'string') {\n\t\tthrow new TypeError(\n\t\t\t\"requireFresh(): maxAge is a duration with its unit, such as '10m' — a bare number would be milliseconds, where @fresh reads seconds\",\n\t\t);\n\t}\n\tconst maxAgeMs = parseDuration(maxAge, 'requireFresh(): maxAge');\n\treturn freshSession(janusOf(ctx, 'requireFresh()'), maxAgeMs);\n}\n",
33
+ "/**\n * `@permission`'s `id:` — `args.<path>` or `parent.<path>` — parsed when the\n * schema is built, and read from a request's arguments or parent value when a\n * field is resolved.\n */\n\n/** A parsed `id:`. */\nexport interface IdPath {\n\t/** As written: `args.id`, `parent.wardId`, `args.input.ids`. */\n\treadonly text: string;\n\treadonly root: 'args' | 'parent';\n\t/** The names after the root, at least one. */\n\treadonly segments: readonly string[];\n}\n\nconst NAME = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\n/** `text` parsed, or `null` when it is not `args.<name>…` or `parent.<name>…`. */\nexport function parsePath(text: string): IdPath | null {\n\tconst [root, ...segments] = text.split('.');\n\tif (root !== 'args' && root !== 'parent') return null;\n\tif (segments.length === 0 || !segments.every((name) => NAME.test(name))) {\n\t\treturn null;\n\t}\n\treturn { text, root, segments };\n}\n\n/** One object a check is about: its id, and the value that holds it when that value is the object. */\nexport interface Target {\n\treadonly id: string;\n\t/** The value the id was read from, when `id` is its `id` field under `parent`. */\n\treadonly holder: object | null;\n}\n\n/**\n * The objects `path` names in this request: one, or one per element where a\n * step reads a list. `null` when a step reads nothing, or an id is not a\n * string or an integer: the request resolved no object id. An empty list\n * under `parent` is `null` too — the object's data names nothing to check,\n * and its fields are not open to everyone for it; under `args` it is the\n * client asking for nothing, and there is nothing to refuse.\n */\nexport function targetsOf(\n\tpath: IdPath,\n\tparent: unknown,\n\targs: unknown,\n): readonly Target[] | null {\n\tconst containers = walk(\n\t\t[path.root === 'args' ? args : parent],\n\t\tpath.segments.slice(0, -1),\n\t);\n\tif (containers === null) return null;\n\tconst last = path.segments[path.segments.length - 1] as string;\n\tconst held = path.root === 'parent' && last === 'id';\n\tconst targets: Target[] = [];\n\tfor (const container of containers) {\n\t\tfor (const value of spread((container as Record<string, unknown>)[last])) {\n\t\t\tconst id = idOf(value);\n\t\t\tif (id === null) return null;\n\t\t\ttargets.push({ id, holder: held ? (container as object) : null });\n\t\t}\n\t}\n\treturn path.root === 'parent' && targets.length === 0 ? null : targets;\n}\n\n/** The values `segments` reach from `values`, a list read as its elements. */\nfunction walk(\n\tvalues: readonly unknown[],\n\tsegments: readonly string[],\n): readonly unknown[] | null {\n\tlet current = values;\n\tfor (const segment of segments) {\n\t\tconst next: unknown[] = [];\n\t\tfor (const value of current) {\n\t\t\tif (typeof value !== 'object' || value === null) return null;\n\t\t\tnext.push(...spread((value as Record<string, unknown>)[segment]));\n\t\t}\n\t\tcurrent = next;\n\t}\n\treturn current.every((value) => typeof value === 'object' && value !== null)\n\t\t? current\n\t\t: null;\n}\n\nfunction spread(value: unknown): readonly unknown[] {\n\treturn Array.isArray(value) ? value.flat(Number.POSITIVE_INFINITY) : [value];\n}\n\n/** An `ID` as graphql-js coerces one: a string, or an integer serialised. */\nfunction idOf(value: unknown): string | null {\n\tif (typeof value === 'string') return value;\n\tif (typeof value === 'number' && Number.isSafeInteger(value)) {\n\t\treturn String(value);\n\t}\n\treturn null;\n}\n",
34
+ "/**\n * One `@permission`, asked at request time: the objects its `id:` names, each\n * checked with the request's check — memoized per request — and a denial\n * unless every one holds. A failure to answer is never a denial.\n */\n\nimport type { Check } from '../../context';\nimport { denial, rethrown } from '../../errors';\nimport { type Target, targetsOf } from './path';\nimport type { PermissionCheck } from './validate';\n\ntype ObjectLike = { readonly type: string; readonly id: string };\ntype Subject = { readonly type: string; readonly id: string };\n\n/** What the guard has in hand when it asks. */\nexport interface Asking {\n\treadonly check: Check;\n\treadonly user: Subject;\n\treadonly parent: unknown;\n\treadonly args: unknown;\n\t/** The GraphQL context, which `loaders` and `conditions` receive. */\n\treadonly ctx: unknown;\n}\n\n/** Refuses the request unless `user` holds `permission` on every object its `id:` names. */\nexport async function enforcePermission(\n\tpermission: PermissionCheck,\n\tasking: Asking,\n): Promise<void> {\n\tconst targets = targetsOf(permission.path, asking.parent, asking.args);\n\tif (targets === null) {\n\t\twarnNoId(permission);\n\t\tthrow denial('NOT_FOUND');\n\t}\n\tconst objects = await Promise.all(\n\t\ttargets.map((target) => objectOf(permission, target, asking.ctx)),\n\t).then(undefined, rethrown);\n\tconst found = objects.filter(\n\t\t(object): object is ObjectLike => object !== null,\n\t);\n\tif (found.length < objects.length) throw denial('NOT_FOUND');\n\tconst answers = await Promise.all(\n\t\tfound.map((object) => ask(permission, object, asking)),\n\t).then(undefined, rethrown);\n\tif (answers.includes(false)) throw denial(permission.onDeny);\n}\n\nasync function ask(\n\tpermission: PermissionCheck,\n\tobject: ObjectLike,\n\t{ check, user, ctx }: Asking,\n): Promise<boolean> {\n\tconst options =\n\t\tpermission.condition === null\n\t\t\t? undefined\n\t\t\t: { ctx: await permission.condition(object, ctx) };\n\treturn check(user, permission.name, object, options);\n}\n\n/**\n * What no object id can hold, as `@softistx/janus` reads the notation: `can()`\n * refuses such an id with a `TypeError`, and one sent by a client is no\n * object's. A copy of the core's `RESERVED`, recorded in AGENTS.md's\n * *Deliberate duplications*.\n */\nconst UNNAMEABLE = /^$|[@#()]/;\n\n/**\n * Whether an id sent by a client can name an object: none of the characters\n * above, no NUL and no lone surrogate — which no store keeps, so `can()`\n * holds them for nobody, and the application's loader must never see them.\n * A copy of the core's `isStorable`, recorded beside `UNNAMEABLE`.\n */\nconst isNameable = (id: string): boolean =>\n\t!UNNAMEABLE.test(id) && !id.includes('\\u0000') && id.isWellFormed();\n\n/**\n * The object `can()` is given for one target: the value that holds the id,\n * the loader's answer, or `{ type, id }`. `null` when there is none: the\n * loader found none, or the id could name no object.\n */\nasync function objectOf(\n\tpermission: PermissionCheck,\n\t{ id, holder }: Target,\n\tctx: unknown,\n): Promise<ObjectLike | null> {\n\tconst { type, load } = permission;\n\tif (!isNameable(id)) return null;\n\tif (holder !== null) return view(holder, type, id);\n\tif (load === null) return { type, id };\n\tconst loaded = await load(id, ctx);\n\tif (loaded === null) return null;\n\tif (typeof loaded !== 'object') {\n\t\tthrow new TypeError(\n\t\t\t`${permission.label}: loaders.${type} answered ${typeof loaded} — answer the object, or null when there is none`,\n\t\t);\n\t}\n\treturn view(loaded, type, id);\n}\n\n/**\n * The object as `can()` reads it: `type` added — and `id`, the string read\n * from the path, so an integer id reads as graphql-js serialises it — every\n * other field read from the object itself, so a getter, a\n * class's `#private` state or an ORM document's accessors answer as they do\n * in the resolver. A spread would copy own enumerable fields only. The\n * proxy's target is an empty object rather than `object`, so a frozen\n * object whose own `type` means something else is read without breaking a\n * proxy invariant.\n */\nfunction view(object: object, type: string, id: string): ObjectLike {\n\treturn new Proxy(Object.create(null) as object, {\n\t\tget: (_, key) =>\n\t\t\tkey === 'type' ? type : key === 'id' ? id : Reflect.get(object, key),\n\t\thas: (_, key) => key === 'type' || Reflect.has(object, key),\n\t}) as ObjectLike;\n}\n\nconst warned = new WeakSet<PermissionCheck>();\n\n/** Says once per directive, on the only channel a library has, why a field answers `NOT_FOUND`. */\nfunction warnNoId(permission: PermissionCheck): void {\n\tif (warned.has(permission)) return;\n\twarned.add(permission);\n\tprocess.emitWarning(\n\t\t`${permission.label} resolved no object id from ${permission.path.text} — answered NOT_FOUND`,\n\t\t{ code: 'JANUS_GRAPHQL_NO_OBJECT_ID' },\n\t);\n}\n",
35
+ "/**\n * What runs before a guarded field's resolver, at request time: the user,\n * then the requirement — its user types, the session's freshness, then each\n * `@permission` in order. A\n * denial is a `GraphQLError`; a failure to answer is `SERVICE_UNAVAILABLE`,\n * never a denial.\n */\n\nimport type { GraphQLFieldResolver } from 'graphql';\nimport { checkOf, janusOf } from '../context';\nimport { denial, rethrown } from '../errors';\nimport { freshSession } from '../fresh';\nimport { enforcePermission } from './permission/enforce';\nimport type { Requirement } from './validate';\n\n/** What the field was asked with. */\nexport interface Resolving {\n\treadonly parent: unknown;\n\treadonly args: unknown;\n\treadonly ctx: unknown;\n\t/** A subscription's: its checks skip the request's memo, and see a revoke. */\n\treadonly fresh: boolean;\n}\n\n/** Refuses the request unless it meets `requirement`. */\nexport async function enforce(\n\trequirement: Requirement,\n\t{ parent, args, ctx, fresh }: Resolving,\n): Promise<void> {\n\tconst janus = janusOf(ctx, requirement.label);\n\tconst user = await janus.user().then(undefined, rethrown);\n\tif (user === null) throw denial('UNAUTHENTICATED');\n\tif (requirement.types !== null && !requirement.types.has(user.type)) {\n\t\tthrow denial('FORBIDDEN');\n\t}\n\tif (requirement.maxAgeMs !== null) {\n\t\tawait freshSession(janus, requirement.maxAgeMs);\n\t}\n\tconst [first] = requirement.permissions;\n\tif (first === undefined) return;\n\tconst check = checkOf(janus, fresh);\n\tif (check === null) {\n\t\tthrow new TypeError(\n\t\t\t`${first.label}: ctx.janus.access is not set — pass { access } to useJanus()`,\n\t\t);\n\t}\n\t// In order, one at a time: the first that denies answers, and the ones\n\t// after it are never asked.\n\tfor (const permission of requirement.permissions) {\n\t\tawait enforcePermission(permission, { check, user, parent, args, ctx });\n\t}\n}\n\n/** `resolve`, run only once `requirement` is met. */\nexport function guarded<S, C, A>(\n\tresolve: GraphQLFieldResolver<S, C, A>,\n\trequirement: Requirement,\n): GraphQLFieldResolver<S, C, A> {\n\treturn async (source, args, ctx, info) => {\n\t\tawait enforce(requirement, {\n\t\t\tparent: source,\n\t\t\targs,\n\t\t\tctx,\n\t\t\tfresh: info.operation.operation === 'subscription',\n\t\t});\n\t\treturn resolve(source, args, ctx, info);\n\t};\n}\n",
36
+ "/**\n * Reads the directives that apply to one object field: its own, its object\n * type's, and those of every interface the type implements — on the\n * interface itself and on the interface's field of the same name. Reads, and\n * decides nothing: `validate.ts` decides what they add up to.\n */\n\nimport { getDirective } from '@graphql-tools/utils';\nimport type {\n\tGraphQLFieldConfig,\n\tGraphQLInterfaceType,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n} from 'graphql';\n\n/** One `@authenticated`, and where it was written. */\nexport interface AuthenticatedUse {\n\t/** `Type.field`, `Type`, `Interface.field` or `Interface`. */\n\treadonly where: string;\n\t/** Its `type:` argument, or `null` when it names none: any signed-in user. */\n\treadonly types: readonly string[] | null;\n}\n\n/** One `@fresh`, and where it was written. */\nexport interface FreshUse {\n\t/** `Type.field`, `Type`, `Interface.field` or `Interface`. */\n\treadonly where: string;\n\t/** Its `maxAge:` argument, in seconds, as written: checked by `validate.ts`. */\n\treadonly maxAge: number;\n}\n\n/** One `@permission`, as written, and where. */\nexport interface PermissionUse {\n\t/** `Type.field`, `Type`, `Interface.field` or `Interface`. */\n\treadonly where: string;\n\t/** Written on a type or an interface, rather than on a field. */\n\treadonly onType: boolean;\n\treadonly name: string;\n\treadonly type: string;\n\t/** Its `id:` argument, or `null` when absent. */\n\treadonly id: string | null;\n\treadonly onDeny: 'NOT_FOUND' | 'FORBIDDEN';\n}\n\n/** Everything written on one field's locations. */\nexport interface FieldDirectives {\n\treadonly authenticated: readonly AuthenticatedUse[];\n\treadonly fresh: readonly FreshUse[];\n\t/** In the order they are checked: the type's and interfaces' first, then the field's. */\n\treadonly permission: readonly PermissionUse[];\n}\n\ntype Located = {\n\treadonly where: string;\n\treadonly onType: boolean;\n\treadonly node: Parameters<typeof getDirective>[1];\n};\n\n/**\n * The locations whose directives apply to `typeName.fieldName`, outermost\n * first: the interfaces, the type, the interfaces' fields, the field. A\n * `@permission` on the object a field belongs to is asked before the one on\n * the field, so a field's `FORBIDDEN` never answers for an object its type\n * would have answered `NOT_FOUND` for.\n */\nfunction locations(\n\tschema: GraphQLSchema,\n\tfield: GraphQLFieldConfig<unknown, unknown>,\n\tfieldName: string,\n\ttypeName: string,\n): Located[] {\n\tconst type = schema.getType(typeName) as GraphQLObjectType;\n\tconst faces = type.getInterfaces() as readonly GraphQLInterfaceType[];\n\tconst fields: Located[] = [];\n\tfor (const face of faces) {\n\t\tconst own = face.getFields()[fieldName];\n\t\tif (own !== undefined) {\n\t\t\tfields.push({\n\t\t\t\twhere: `${face.name}.${fieldName}`,\n\t\t\t\tonType: false,\n\t\t\t\tnode: own,\n\t\t\t});\n\t\t}\n\t}\n\treturn [\n\t\t...faces.map((face) => ({ where: face.name, onType: true, node: face })),\n\t\t{ where: typeName, onType: true, node: type },\n\t\t...fields,\n\t\t{ where: `${typeName}.${fieldName}`, onType: false, node: field },\n\t];\n}\n\n/** Every `@authenticated`, `@fresh` and `@permission` that applies to one object field. */\nexport function readField(\n\tschema: GraphQLSchema,\n\tfield: GraphQLFieldConfig<unknown, unknown>,\n\tfieldName: string,\n\ttypeName: string,\n): FieldDirectives {\n\tconst authenticated: AuthenticatedUse[] = [];\n\tconst fresh: FreshUse[] = [];\n\tconst permission: PermissionUse[] = [];\n\tfor (const { where, onType, node } of locations(\n\t\tschema,\n\t\tfield,\n\t\tfieldName,\n\t\ttypeName,\n\t)) {\n\t\tfor (const args of getDirective(schema, node, 'authenticated') ?? []) {\n\t\t\tconst types = args['type'] as readonly string[] | null | undefined;\n\t\t\tauthenticated.push({ where, types: types ?? null });\n\t\t}\n\t\tfor (const args of getDirective(schema, node, 'fresh') ?? []) {\n\t\t\tfresh.push({ where, maxAge: args['maxAge'] as number });\n\t\t}\n\t\tfor (const args of getDirective(schema, node, 'permission') ?? []) {\n\t\t\tpermission.push({\n\t\t\t\twhere,\n\t\t\t\tonType,\n\t\t\t\tname: args['name'] as string,\n\t\t\t\ttype: args['type'] as string,\n\t\t\t\tid: (args['id'] as string | null | undefined) ?? null,\n\t\t\t\tonDeny: args['onDeny'] === 'FORBIDDEN' ? 'FORBIDDEN' : 'NOT_FOUND',\n\t\t\t});\n\t\t}\n\t}\n\treturn { authenticated, fresh, permission };\n}\n",
37
+ "/** The phrases the schema-time refusals share. */\n\nexport const PREFIX = 'applyJanusDirectives()';\n\n/** `Query.me`, or `Record (read by Record.title)` for a type's directive. */\nexport function on(where: string, field: string): string {\n\treturn where === field ? field : `${where} (read by ${field})`;\n}\n\n/** `'a', 'b'`. */\nexport function list(names: readonly string[]): string {\n\treturn names.map((name) => `'${name}'`).join(', ');\n}\n",
38
+ "/**\n * What `@permission` reads of the permission model when the schema is built:\n * the object types, the names each declares, whether one reads a field of\n * its object (`fromField`), and whether a permission reaches a condition\n * (`when`). Read from `access.model`, as `defineModel()` answered it.\n */\n\n/** `access.model`, as this module reads it. */\nexport interface ModelLike {\n\treadonly types: readonly string[];\n\treadonly definition: {\n\t\treadonly types: {\n\t\t\treadonly [type: string]: {\n\t\t\t\treadonly related?: { readonly [name: string]: unknown };\n\t\t\t\treadonly permits?: { readonly [name: string]: readonly unknown[] };\n\t\t\t};\n\t\t};\n\t};\n}\n\n/** `access.model`, or `null` when `access` is not what `permissions()` answered. */\nexport function modelOf(access: unknown): ModelLike | null {\n\tconst model = (access as { readonly model?: Partial<ModelLike> } | undefined)\n\t\t?.model;\n\tif (!Array.isArray(model?.types) || model.definition?.types === undefined) {\n\t\treturn null;\n\t}\n\treturn model as ModelLike;\n}\n\n/** The relations and permissions `type` declares: what `can()` may be asked. */\nexport function namesOf(model: ModelLike, type: string): readonly string[] {\n\tconst def = model.definition.types[type];\n\treturn [\n\t\t...Object.keys(def?.related ?? {}),\n\t\t...Object.keys(def?.permits ?? {}),\n\t];\n}\n\ntype FromFieldLike = {\n\treadonly kind: 'fromField';\n\treadonly field: string;\n\treadonly subject: string;\n};\n\nfunction isFromField(value: unknown): value is FromFieldLike {\n\treturn (value as { readonly kind?: unknown } | null)?.kind === 'fromField';\n}\n\n/** The fields `type`'s `fromField`s read; empty when it has none. */\nexport function fieldsOf(model: ModelLike, type: string): readonly string[] {\n\tconst related = model.definition.types[type]?.related ?? {};\n\treturn Object.values(related)\n\t\t.filter(isFromField)\n\t\t.map((def) => def.field);\n}\n\n/**\n * Whether `can(…, name, { type })` reaches a `when` — through the\n * permission's rules, the permissions they name, and arrows into other types\n * — and so needs a `ctx`. What `CtxOf` computes in the compiler.\n */\nexport function reachesCondition(\n\tmodel: ModelLike,\n\ttype: string,\n\tname: string,\n\tseen: Set<string> = new Set(),\n): boolean {\n\tconst key = `${type}.${name}`;\n\tif (seen.has(key)) return false;\n\tseen.add(key);\n\tconst def = model.definition.types[type];\n\tfor (const rule of def?.permits?.[name] ?? []) {\n\t\tif (typeof rule !== 'string') return true; // a when()\n\t\tconst [relation, target] = rule.split('->');\n\t\tif (target === undefined) {\n\t\t\tif (reachesCondition(model, type, rule, seen)) return true;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const next of arrowTargets(def?.related?.[relation as string])) {\n\t\t\tif (reachesCondition(model, next, target, seen)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/** The object types an arrow through a relation of this definition reaches. */\nfunction arrowTargets(relation: unknown): readonly string[] {\n\tif (isFromField(relation)) {\n\t\treturn [relation.subject];\n\t}\n\tif (!Array.isArray(relation)) return [];\n\treturn relation\n\t\t.filter((holder): holder is string => typeof holder === 'string')\n\t\t.map((holder) => holder.split('#')[0] as string);\n}\n",
39
+ "/**\n * One `@permission`, checked against the model and the field when the schema\n * is built, and turned into what the guard asks at request time. Everything\n * no request could pass is a `TypeError` naming the field.\n */\n\nimport type { PermissionUse } from '../read';\nimport { list, on, PREFIX } from '../words';\nimport {\n\tfieldsOf,\n\ttype ModelLike,\n\tmodelOf,\n\tnamesOf,\n\treachesCondition,\n} from './model';\nimport { type IdPath, parsePath } from './path';\n\n/** `useJanus({ loaders })`'s entry: the object of a type, by id, or `null`. */\nexport type Loader = (id: string, ctx: unknown) => unknown;\n/** `useJanus({ conditions })`'s entry: the `ctx` a type's conditions test. */\nexport type Condition = (object: unknown, ctx: unknown) => unknown;\n\n/** What `@permission` reads from `useJanus()`'s options. */\nexport interface PermissionWiring {\n\treadonly access?: unknown;\n\treadonly loaders?: { readonly [type: string]: unknown } | undefined;\n\treadonly conditions?: { readonly [type: string]: unknown } | undefined;\n}\n\n/** One `@permission`, as the guard asks it. */\nexport interface PermissionCheck {\n\t/** `@permission on Record (read by Record.title)`, for the messages. */\n\treadonly label: string;\n\treadonly name: string;\n\treadonly type: string;\n\treadonly onDeny: 'NOT_FOUND' | 'FORBIDDEN';\n\treadonly path: IdPath;\n\t/** Loads an object named by id alone; `null` passes `{ type, id }`. */\n\treadonly load: Loader | null;\n\t/** Answers the check's `ctx`; `null` when no condition is reachable. */\n\treadonly condition: Condition | null;\n}\n\n/** The field a directive is read for: `Type.field`, and the arguments it takes. */\nexport interface FieldShape {\n\treadonly name: string;\n\treadonly args: readonly string[];\n}\n\n/** `use`, checked, or a `TypeError` naming the field. */\nexport function permissionCheckOf(\n\tuse: PermissionUse,\n\tfield: FieldShape,\n\twiring: PermissionWiring,\n): PermissionCheck {\n\tconst label = `@permission on ${on(use.where, field.name)}`;\n\tconst refuse = (why: string) => new TypeError(`${PREFIX}: ${label} ${why}`);\n\tconst model = modelOf(wiring.access);\n\tif (model === null) {\n\t\tthrow refuse(\n\t\t\t'needs the permissions() instance — pass useJanus({ auth, access }), with access what permissions() answered',\n\t\t);\n\t}\n\tcheckNames(model, use, refuse);\n\tconst text = use.id ?? (use.onType ? 'parent.id' : 'args.id');\n\tconst path = parsePath(text);\n\tif (path === null) {\n\t\tthrow refuse(\n\t\t\t`reads its id from '${text}', which is not args.<name> or parent.<name>`,\n\t\t);\n\t}\n\tconst [first] = path.segments;\n\tif (path.root === 'args' && !field.args.includes(first as string)) {\n\t\tthrow refuse(\n\t\t\t`reads ${path.root}.${first}, and ${field.name} takes no argument ${first}${\n\t\t\t\tuse.id === null && use.onType === false\n\t\t\t\t\t? ' — name the id with id: \"parent.<field>\" or id: \"args.<name>\"'\n\t\t\t\t\t: ''\n\t\t\t}`,\n\t\t);\n\t}\n\treturn {\n\t\tlabel,\n\t\tname: use.name,\n\t\ttype: use.type,\n\t\tonDeny: use.onDeny,\n\t\tpath,\n\t\tload: loaderOf(model, use.type, path, wiring, refuse),\n\t\tcondition: conditionOf(model, use, wiring, refuse),\n\t};\n}\n\ntype Refuse = (why: string) => TypeError;\n\nfunction checkNames(model: ModelLike, use: PermissionUse, refuse: Refuse) {\n\tif (!model.types.includes(use.type)) {\n\t\tthrow refuse(\n\t\t\t`names the object type '${use.type}', which is not one of ${list(model.types)}`,\n\t\t);\n\t}\n\tconst names = namesOf(model, use.type);\n\tif (!names.includes(use.name)) {\n\t\tthrow refuse(\n\t\t\t`asks '${use.name}', which ${use.type} does not declare — it declares ${list(names)}`,\n\t\t);\n\t}\n}\n\n/** The loader a check needs: its type's, required when the object is named by id alone and reads its own fields. */\nfunction loaderOf(\n\tmodel: ModelLike,\n\ttype: string,\n\tpath: IdPath,\n\twiring: PermissionWiring,\n\trefuse: Refuse,\n): Loader | null {\n\tconst load = wiring.loaders?.[type];\n\tif (load !== undefined && typeof load !== 'function') {\n\t\tthrow refuse(`finds loaders.${type}, which is not a function`);\n\t}\n\tconst held = path.root === 'parent' && path.segments.at(-1) === 'id';\n\tif (held) return null;\n\tif (load !== undefined) return load as Loader;\n\tconst fields = fieldsOf(model, type);\n\tif (fields.length > 0) {\n\t\tthrow refuse(\n\t\t\t`reads the ${type}'s id from ${path.text}, and ${type} reads ${list(fields)} of the object itself (fromField) — pass useJanus({ loaders: { ${type}: (id, ctx) => … } })`,\n\t\t);\n\t}\n\treturn null;\n}\n\n/** The type's `conditions` entry, required when the permission reaches a `when`. */\nfunction conditionOf(\n\tmodel: ModelLike,\n\tuse: PermissionUse,\n\twiring: PermissionWiring,\n\trefuse: Refuse,\n): Condition | null {\n\tif (!reachesCondition(model, use.type, use.name)) return null;\n\tconst condition = wiring.conditions?.[use.type];\n\tif (typeof condition !== 'function') {\n\t\tthrow refuse(\n\t\t\t`asks '${use.name}' of ${use.type}, which reaches a when() — pass useJanus({ conditions: { ${use.type}: (object, ctx) => … } })`,\n\t\t);\n\t}\n\treturn condition as Condition;\n}\n",
40
+ "/**\n * Decides, when the schema is built, what the directives on one field add up\n * to — and refuses with a `TypeError` what no request could ever pass: a user\n * type `auth` does not know, a `type: []`, restrictions that exclude each\n * other, a `@fresh` whose `maxAge` is not above zero, or a `@permission` the\n * model, the field or the wiring cannot answer (`permission/validate.ts`).\n */\n\nimport {\n\ttype FieldShape,\n\ttype PermissionCheck,\n\ttype PermissionWiring,\n\tpermissionCheckOf,\n} from './permission/validate';\nimport type { AuthenticatedUse, FieldDirectives, FreshUse } from './read';\nimport { list, on, PREFIX } from './words';\n\n/** What a field requires before its resolver runs. */\nexport interface Requirement {\n\t/** `Type.field`, for the messages. */\n\treadonly where: string;\n\t/** The directive a missing `ctx.janus` is reported against. */\n\treadonly label: string;\n\t/**\n\t * The user types allowed, every `type:` intersected; `null` when none\n\t * narrows it: any signed-in user.\n\t */\n\treadonly types: ReadonlySet<string> | null;\n\t/**\n\t * How long ago, in milliseconds, the session may have proved who it is at\n\t * most — the smallest `@fresh` that applies; `null` when none does.\n\t */\n\treadonly maxAgeMs: number | null;\n\t/** The permissions asked after that, in order: every one must hold. */\n\treadonly permissions: readonly PermissionCheck[];\n}\n\n/** The user types a schema may name: `auth.types`, or the one `useJanus({ type })` keeps. */\nexport interface Known {\n\t/** `null`: none is known, and no `type:` is checked. */\n\treadonly types: readonly string[] | null;\n}\n\n/**\n * The requirement of one field, or `null` when nothing guards it. Throws a\n * `TypeError` naming the field for a directive no request could pass.\n */\nexport function requirementOf(\n\tfield: FieldShape,\n\tdirectives: FieldDirectives,\n\tknown: Known,\n\twiring: PermissionWiring,\n): Requirement | null {\n\tconst { authenticated, fresh, permission } = directives;\n\tconst [name, first] = firstOf(directives);\n\tif (first === undefined) return null;\n\treturn {\n\t\twhere: field.name,\n\t\tlabel: `${name} on ${on(first.where, field.name)}`,\n\t\ttypes: typesOf(field.name, authenticated, known),\n\t\tmaxAgeMs: maxAgeOf(field.name, fresh),\n\t\tpermissions: permission.map((use) => permissionCheckOf(use, field, wiring)),\n\t};\n}\n\n/** Every `type:` intersected, or `null` when none names any. */\nfunction typesOf(\n\tfield: string,\n\tuses: readonly AuthenticatedUse[],\n\tknown: Known,\n): ReadonlySet<string> | null {\n\tlet types: Set<string> | null = null;\n\tfor (const { where, types: named } of uses) {\n\t\tif (named === null) continue;\n\t\tif (named.length === 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`${PREFIX}: @authenticated on ${on(where, field)} names no user type — leave type: out to admit any signed-in user`,\n\t\t\t);\n\t\t}\n\t\tfor (const name of named) {\n\t\t\tif (known.types !== null && !known.types.includes(name)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`${PREFIX}: @authenticated on ${on(where, field)} names the user type '${name}', which is not one of ${list(known.types)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\ttypes =\n\t\t\ttypes === null\n\t\t\t\t? new Set(named)\n\t\t\t\t: new Set(named.filter((name) => types?.has(name)));\n\t}\n\tif (types !== null && types.size === 0) {\n\t\tthrow new TypeError(\n\t\t\t`${PREFIX}: the @authenticated on ${field} and on its type or interfaces admit no user type in common`,\n\t\t);\n\t}\n\treturn types;\n}\n\n/** The directive a missing `ctx.janus` is reported against: the first checked. */\nfunction firstOf({\n\tauthenticated,\n\tfresh,\n\tpermission,\n}: FieldDirectives): readonly [string, { readonly where: string } | undefined] {\n\tif (authenticated.length > 0) return ['@authenticated', authenticated[0]];\n\tif (fresh.length > 0) return ['@fresh', fresh[0]];\n\treturn ['@permission', permission[0]];\n}\n\n/** The smallest `maxAge`, in milliseconds, or `null` when no `@fresh` applies. */\nfunction maxAgeOf(field: string, uses: readonly FreshUse[]): number | null {\n\tlet seconds: number | null = null;\n\tfor (const { where, maxAge } of uses) {\n\t\tif (!Number.isSafeInteger(maxAge) || maxAge <= 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`${PREFIX}: @fresh on ${on(where, field)} asks maxAge: ${maxAge} — write a number of seconds above zero, such as maxAge: 600 for ten minutes`,\n\t\t\t);\n\t\t}\n\t\tseconds = seconds === null ? maxAge : Math.min(seconds, maxAge);\n\t}\n\treturn seconds === null ? null : seconds * 1000;\n}\n",
41
+ "/**\n * The answers of the second-factor resolvers: a core result as the plain\n * object the schema's fields read, timestamps as ISO-8601 strings.\n */\n\nimport { sendNoStore } from '../renewal';\nimport type { ChallengeIn, ChallengeOut } from './types';\n\n/**\n * The sign-in challenge as `JanusSecondFactorChallenge`, for your own\n * sign-in resolver: pass it the core's `status: 'secondFactor'` answer and the\n * request (`ctx.request`). The challenge is single-use, so the response is sent\n * `Cache-Control: no-store` (through `useJanus()`'s `onResponse`, over HTTP);\n * without the request nothing is sent and the response is yours to mark.\n *\n * ```ts\n * if (result.status === 'secondFactor') return { __typename: 'JanusSecondFactorChallenge', ...secondFactorChallengeOut(result, ctx.request) };\n * ```\n */\nexport function secondFactorChallengeOut(\n\tresult: ChallengeIn,\n\trequest?: Request,\n): ChallengeOut {\n\tif (request !== undefined) sendNoStore(request);\n\treturn {\n\t\tchallenge: result.challenge,\n\t\texpiresAt: result.expiresAt.toISOString(),\n\t\tmethods: result.methods,\n\t\tpasskeyOptions:\n\t\t\tresult.passkeyOptions === undefined\n\t\t\t\t? null\n\t\t\t\t: JSON.stringify(result.passkeyOptions),\n\t};\n}\n",
42
+ "/** The request of a resolver's context, shared by the passkey, social and second-factor modules. */\n\n/**\n * The request: the session and device cookies are HTTP, so a context with none\n * is a wiring mistake. `name` is the caller's, e.g. `socialResolvers`, for the\n * error message.\n */\nexport function requestOf(\n\tctx: { readonly request?: Request } | undefined,\n\tname: string,\n): Request {\n\tif (ctx?.request === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`${name}(): the GraphQL context has no request — build the context from an HTTP request (Yoga does)`,\n\t\t);\n\t}\n\treturn ctx.request;\n}\n",
43
+ "/** The sign-in answer's side effects, shared by the passkey, second-factor and social modules. */\n\nimport type { SignedIn } from '@softistx/janus';\nimport { type DeviceCookieOptions, sendDevice } from '../device';\nimport { sendCookie, sendNoStore } from '../renewal';\n\n/** What the answer reads on the user type's cookie surface and on the options. */\nexport interface SignedInSink {\n\treadonly auth: {\n\t\treadonly cookie: {\n\t\t\tserialize(token: string, session: SignedIn<unknown>['session']): string;\n\t\t};\n\t};\n\treadonly answerToken: boolean;\n\t/** The device cookie's attributes, or `undefined` when devices are not tracked. */\n\treadonly device: DeviceCookieOptions | undefined;\n}\n\n/**\n * A completed sign-in's cookies and fields: the session cookie unless the\n * token is answered (then the response is `no-store`, as it carries a\n * session token), the device cookie when the device is new to track, then\n * the fields every sign-in answer shares.\n */\nexport function signedInAnswer<U extends { readonly id: string }>(\n\t{ auth, answerToken, device }: SignedInSink,\n\trequest: Request,\n\tdone: SignedIn<U>,\n) {\n\tif (answerToken) {\n\t\tsendNoStore(request);\n\t} else {\n\t\tsendCookie(request, auth.cookie.serialize(done.token, done.session));\n\t}\n\tif (device !== undefined && done.deviceToken !== null) {\n\t\tsendDevice(request, done.deviceToken, device);\n\t}\n\treturn {\n\t\tuser: done.user,\n\t\ttoken: answerToken ? done.token : null,\n\t\tuserId: done.user.id,\n\t\texpiresAt: done.session.expiresAt.toISOString(),\n\t\tnewDevice: done.newDevice,\n\t};\n}\n",
44
+ "/**\n * The answers of the invitation resolvers: a core result as the plain object\n * the schema's fields read, timestamps as ISO-8601 strings; and the two\n * arguments that are checked here.\n */\n\nimport type {\n\tInvitation,\n\tInvitationPreview,\n\tInvitationStatus,\n} from '@softistx/janus';\nimport { badInput } from '../bad-input';\nimport type { InvitationOut, PageOut, PreviewOut } from './types';\n\nconst iso = (date: Date | null): string | null =>\n\tdate === null ? null : date.toISOString();\n\nexport const invitationOut = (i: Invitation): InvitationOut => ({\n\tid: i.id,\n\tscope: i.scope,\n\temail: i.email,\n\tname: i.name,\n\trole: i.role,\n\tlocale: i.locale,\n\tref: i.ref,\n\ttype: i.type,\n\tstatus: i.status,\n\tinvitedBy: i.invitedBy,\n\tcreatedAt: i.createdAt.toISOString(),\n\tupdatedAt: i.updatedAt.toISOString(),\n\texpiresAt: i.expiresAt.toISOString(),\n\tacceptedBy: i.acceptedBy,\n\tacceptedAt: iso(i.acceptedAt),\n\trevokedAt: iso(i.revokedAt),\n\trevokedBy: i.revokedBy,\n\tresentBy: i.resentBy,\n});\n\nexport const previewOut = (\n\tp: InvitationPreview,\n\torganization: string | null = null,\n): PreviewOut => ({\n\tid: p.id,\n\tscope: p.scope,\n\temail: p.email,\n\tname: p.name,\n\trole: p.role,\n\tlocale: p.locale,\n\ttype: p.type,\n\torganization,\n\texpiresAt: p.expiresAt.toISOString(),\n\tneedsPassword: p.needsPassword,\n});\n\nexport const pageOut = (\n\tpage: {\n\t\treadonly items: readonly Invitation[];\n\t\treadonly nextCursor: string | null;\n\t},\n\tcounted: PageOut['counted'],\n): PageOut => ({\n\titems: page.items.map(invitationOut),\n\tnextCursor: page.nextCursor,\n\tcounted,\n});\n\n/** The `role` and `ref` filters: each only when given, and non-empty (BAD_USER_INPUT otherwise). */\nexport function textFiltersOf(\n\trole: string | null | undefined,\n\tref: string | null | undefined,\n) {\n\tif (role === '') throw badInput('role must be a non-empty string', 'role');\n\tif (ref === '') throw badInput('ref must be a non-empty string', 'ref');\n\treturn {\n\t\t...(role == null ? {} : { role }),\n\t\t...(ref == null ? {} : { ref }),\n\t};\n}\n\n/** The `order` argument as the core's: `OLDEST` (the default) is `asc`. */\nexport function orderOf(order: 'OLDEST' | 'NEWEST' | null | undefined) {\n\treturn order == null\n\t\t? {}\n\t\t: ({ order: order === 'NEWEST' ? 'desc' : 'asc' } as const);\n}\n\n/** The `lapsed` argument as the core's: `EXCLUDE` is `exclude`, `ONLY` is `only`. */\nexport function lapsedOf(lapsed: 'EXCLUDE' | 'ONLY' | null | undefined) {\n\treturn lapsed == null\n\t\t? {}\n\t\t: ({ lapsed: lapsed === 'ONLY' ? 'only' : 'exclude' } as const);\n}\n\n/**\n * The longest each string argument of the invitation fields may be. The core\n * bounds `scope`, `role`, `name`, `email`, `locale` and `ref` as `issue`\n * keeps them, and a code is 43 characters; these are the same numbers, held\n * here so an oversized argument is refused before `authorize`, a hash or a\n * store is asked. They mirror `SCOPE_MAX`, `ROLE_MAX`, `NAME_MAX`,\n * `EMAIL_MAX`, `LOCALE_MAX` and `REF_MAX` of `@softistx/janus`\n * (`auth/invitations/input.ts`); resolvers.limits.spec.ts fails on a drift\n * downwards. The core has no maximum on a password: 1024 is this\n * layer's.\n */\nexport const INVITATION_LIMITS = {\n\tcode: 43,\n\tpassword: 1024,\n\tscope: 512,\n\trole: 100,\n\tname: 100,\n\temail: 254,\n\tlocale: 35,\n\tref: 100,\n} as const;\n\n/** Arguments whose length the core measures once trimmed. */\nconst TRIMMED: readonly string[] = ['name', 'email'];\n\n/**\n * Refuses (`BAD_USER_INPUT`, 400, `field`) an argument longer than its\n * maximum. Absent arguments pass, and the message never echoes the value.\n */\nexport function boundedArgs(\n\targs: Partial<\n\t\tRecord<keyof typeof INVITATION_LIMITS, string | null | undefined>\n\t>,\n): void {\n\tfor (const [field, value] of Object.entries(args)) {\n\t\tif (typeof value !== 'string') continue;\n\t\tconst max = INVITATION_LIMITS[field as keyof typeof INVITATION_LIMITS];\n\t\tconst length = TRIMMED.includes(field) ? value.trim().length : value.length;\n\t\tif (length > max) {\n\t\t\tthrow badInput(`${field} must be at most ${max} characters`, field);\n\t\t}\n\t}\n}\n\nconst STATUSES: readonly string[] = ['pending', 'accepted', 'revoked'];\n\n/** The `status` filter: absent, or one of the three statuses. */\nexport function statusOf(status: string | null | undefined) {\n\tif (status == null) return {};\n\tif (!STATUSES.includes(status)) {\n\t\tthrow badInput('status must be pending, accepted or revoked', 'status');\n\t}\n\treturn { status: status as InvitationStatus };\n}\n",
45
+ "/** The invitee's fields, open to whoever holds the code: `invitationPreview` and `acceptInvitation`. */\n\nimport type { AcceptedInvitation } from '@softistx/janus';\nimport { deviceOf } from '../../device';\nimport { rethrown } from '../../errors';\nimport { noStoreOf, sendNoStore } from '../../renewal';\nimport { secondFactorChallengeOut } from '../../second-factor/shape';\nimport { requestOf } from '../../surface/request';\nimport { signedInAnswer } from '../../surface/signed-in';\nimport { boundedArgs, previewOut } from '../shape';\nimport type { AcceptedOut, AnyUser, InvitationResolvers } from '../types';\nimport type { Deps } from './deps';\n\ntype Queries = InvitationResolvers['Query'];\ntype Mutations = InvitationResolvers['Mutation'];\n\n/** `Query.invitationPreview`: what the code names, without spending it. */\nexport function invitationPreview(deps: Deps): Queries['invitationPreview'] {\n\treturn async (_, { code }, ctx) => {\n\t\tboundedArgs({ code });\n\t\tconst preview = await deps.invitations\n\t\t\t.preview(code)\n\t\t\t.then(undefined, rethrown);\n\t\t// The code is a secret: no cache keeps its answer.\n\t\tnoStoreOf(ctx);\n\t\tconst organization = await deps.options.describeScope?.(preview.scope, ctx);\n\t\treturn previewOut(preview, organization?.name ?? null);\n\t};\n}\n\n/**\n * The accept's answer as the union's member. The anonymous answer reveals\n * the invitation's id, scope and role, never who invited, and (for `signIn`)\n * nothing of the user but the address the code was sent to.\n */\nfunction acceptedOut(\n\tdeps: Deps,\n\trequest: Request,\n\tdone: AcceptedInvitation,\n): AcceptedOut {\n\tconst { invitation } = done;\n\tif (done.status === 'signedIn') {\n\t\treturn {\n\t\t\tstatus: 'signedIn',\n\t\t\t...signedInAnswer(deps, request, { ...done, user: done.user as AnyUser }),\n\t\t\tinvitationId: invitation.id,\n\t\t\tscope: invitation.scope,\n\t\t\trole: invitation.role,\n\t\t};\n\t}\n\tif (done.status === 'secondFactor') {\n\t\treturn {\n\t\t\tstatus: 'secondFactor',\n\t\t\t...secondFactorChallengeOut(done, request),\n\t\t\tinvitationId: invitation.id,\n\t\t\tscope: invitation.scope,\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'signIn',\n\t\tinvitationId: invitation.id,\n\t\tscope: invitation.scope,\n\t\temail: invitation.email,\n\t};\n}\n\n/** `Mutation.acceptInvitation`: accepts with the code; a new invitee is signed in. */\nexport function acceptInvitation(deps: Deps): Mutations['acceptInvitation'] {\n\treturn async (_, { code, password }, ctx) => {\n\t\tboundedArgs({ code, password });\n\t\tconst request = requestOf(ctx, 'invitationResolvers');\n\t\t// Every answer is no-store: a session token, a challenge, or the proof of an inbox.\n\t\tsendNoStore(request);\n\t\tconst done = await deps.invitations\n\t\t\t.accept({\n\t\t\t\tcode,\n\t\t\t\t...(password == null ? {} : { password }),\n\t\t\t\t...(deps.device === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { device: deviceOf(request, deps.device) }),\n\t\t\t})\n\t\t\t.then(undefined, rethrown);\n\t\treturn acceptedOut(deps, request, done);\n\t};\n}\n",
46
+ "/** What every field's resolver reads, resolved once by `invitationResolvers()`. */\n\nimport type { Invitation } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport type { DeviceCookieOptions } from '../../device';\nimport { denial, rethrown } from '../../errors';\nimport { requireUser } from '../../helpers';\nimport type {\n\tAnyUser,\n\tContext,\n\tInvitationAction,\n\tInvitationAuth,\n\tInvitationResolversOptions,\n\tInvitationSubject,\n} from '../types';\n\nexport interface Deps {\n\treadonly auth: InvitationAuth;\n\treadonly invitations: InvitationAuth['invitations'];\n\treadonly options: InvitationResolversOptions;\n\treadonly answerCode: boolean;\n\treadonly answerToken: boolean;\n\t/** The device cookie's attributes, or `undefined` when devices are not tracked. */\n\treadonly device: DeviceCookieOptions | undefined;\n}\n\nexport function depsOf(options: InvitationResolversOptions): Deps {\n\tconst { auth } = options;\n\tif ((auth as Partial<InvitationAuth>).invitations === undefined) {\n\t\tthrow new TypeError(\n\t\t\t'invitationResolvers(): auth has no invitations — give janus() `invitations`',\n\t\t);\n\t}\n\tif (typeof options.authorize !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t'invitationResolvers(): `authorize` is required — the core authorises nobody, so say who may invite into a scope',\n\t\t);\n\t}\n\tif (options.sendInvitation === undefined && options.answerCode !== true) {\n\t\tthrow new TypeError(\n\t\t\t'invitationResolvers(): give `sendInvitation` (deliver the code) or `answerCode: true` — the code would reach nobody',\n\t\t);\n\t}\n\treturn {\n\t\tauth,\n\t\tinvitations: auth.invitations,\n\t\toptions,\n\t\tanswerCode: options.answerCode ?? false,\n\t\tanswerToken: options.answerToken ?? false,\n\t\tdevice: options.device === true ? {} : options.device,\n\t};\n}\n\n/** What a call is about, beside the user and the scope. */\ntype About = Pick<InvitationSubject, 'input' | 'invitation' | 'page'>;\n\n/**\n * The stored invitation `id` names in `scope`, read with the core's\n * `invitations.get`, or `null` when it names none (an unknown, malformed or\n * other-scope id).\n */\nexport async function stored(\n\t{ invitations }: Deps,\n\tscope: string,\n\tid: string,\n): Promise<Invitation | null> {\n\treturn invitations.get({ id, scope }).then(undefined, rethrown);\n}\n\n/**\n * The inviter of an owner-side call: whatever `ctx.janus.user()` answers (an\n * API key's owner included), of `inviterType` when given, and let through by\n * `authorize`, which also gets `about`: what the call is about (an object, or a\n * function that reads it once the user is known, so an unknown id answers as a\n * refusal and never before the sign-in check). A `false` is `NOT_FOUND`.\n *\n * When that function answers `null` (the id names no invitation), `authorize`\n * is still asked, with no `invitation`, and neither its answer nor an error it\n * throws matters, except a `GraphQLError` (a step-up), which is thrown as for a\n * known id: the call is otherwise `NOT_FOUND`. A known and an unknown id so take\n * the same path and answer the same, whoever the caller is.\n */\nexport async function owner(\n\t{ options }: Deps,\n\taction: InvitationAction,\n\tscope: string,\n\tctx: Context,\n\tabout: About | (() => Promise<About | null>) = {},\n): Promise<AnyUser> {\n\tconst user = await requireUser<AnyUser>(\n\t\t// `ctx.janus` is what `useJanus()` puts on every context.\n\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t\toptions.inviterType === undefined ? {} : { type: options.inviterType },\n\t);\n\tconst known = typeof about === 'function' ? await about() : about;\n\tif (known === null) {\n\t\ttry {\n\t\t\tawait options.authorize(action, { user, scope }, ctx);\n\t\t} catch (error) {\n\t\t\t// A `GraphQLError` (a step-up) is answered as for a known id.\n\t\t\tif (error instanceof GraphQLError) throw error;\n\t\t\t// A callback that reads `subject.invitation` may throw here; the\n\t\t\t// answer is `NOT_FOUND` either way.\n\t\t}\n\t\tthrow denial('NOT_FOUND');\n\t}\n\tif (\n\t\t(await options.authorize(action, { user, scope, ...known }, ctx)) !== true\n\t) {\n\t\tthrow denial('NOT_FOUND');\n\t}\n\treturn user;\n}\n",
47
+ "/** The owner-side fields: `invitations`, `issueInvitation`, `resendInvitation`, `revokeInvitation`. */\n\nimport { limitOf } from '../../bad-input';\nimport { rethrown } from '../../errors';\nimport { noStoreOf } from '../../renewal';\nimport {\n\tboundedArgs,\n\tinvitationOut,\n\tlapsedOf,\n\torderOf,\n\tpageOut,\n\tstatusOf,\n\ttextFiltersOf,\n} from '../shape';\nimport type { Context, InvitationResolvers, IssuedOut } from '../types';\nimport { type Deps, owner, stored } from './deps';\n\ntype Queries = InvitationResolvers['Query'];\ntype Mutations = InvitationResolvers['Mutation'];\n\n/** `Query.invitations`: one scope's invitations, oldest first unless `order` says otherwise. */\nexport function invitations(deps: Deps): Queries['invitations'] {\n\treturn async (\n\t\t_,\n\t\t{ scope, status, role, ref, lapsed, order, limit, after },\n\t\tctx,\n\t) => {\n\t\tconst filter = {\n\t\t\t...statusOf(status),\n\t\t\t...textFiltersOf(role, ref),\n\t\t\t...lapsedOf(lapsed),\n\t\t};\n\t\tconst asked = {\n\t\t\t...filter,\n\t\t\t...orderOf(order),\n\t\t\t...limitOf(limit),\n\t\t\t...(after == null ? {} : { after }),\n\t\t};\n\t\tawait owner(deps, 'list', scope, ctx, { page: asked });\n\t\tconst page = await deps.invitations\n\t\t\t.list(scope, asked)\n\t\t\t.then(undefined, rethrown);\n\t\treturn pageOut(page, { scope, filter });\n\t};\n}\n\n/** `JanusInvitationPage.totalCount`: counted when selected, with the filters the page was listed with. */\nexport function totalCount(\n\tdeps: Deps,\n): InvitationResolvers['JanusInvitationPage']['totalCount'] {\n\treturn async ({ counted }) => {\n\t\tif (counted === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t'totalCount is answered only on pages `invitations` returns',\n\t\t\t);\n\t\t}\n\t\treturn deps.invitations\n\t\t\t.count(counted.scope, counted.filter)\n\t\t\t.then(undefined, rethrown);\n\t};\n}\n\n/**\n * What `issue` and `resend` share once the core answered: the delivery hook,\n * then the response marked `no-store` (the code is a secret), and the code\n * only with `answerCode`.\n */\nasync function delivered(\n\tdeps: Deps,\n\taction: 'issue' | 'resend',\n\tdone: {\n\t\treadonly invitation: Parameters<typeof invitationOut>[0];\n\t\treadonly code: string;\n\t},\n\tctx: Context,\n): Promise<IssuedOut> {\n\tawait deps.options.sendInvitation?.(\n\t\t{ action, invitation: done.invitation, code: done.code },\n\t\tctx,\n\t);\n\tnoStoreOf(ctx);\n\treturn {\n\t\tinvitation: invitationOut(done.invitation),\n\t\tcode: deps.answerCode ? done.code : null,\n\t};\n}\n\n/** `Mutation.issueInvitation`: invites an address; the inviter is the request's user. */\nexport function issueInvitation(deps: Deps): Mutations['issueInvitation'] {\n\treturn async (_, args, ctx) => {\n\t\tboundedArgs({\n\t\t\tscope: args.scope,\n\t\t\temail: args.email,\n\t\t\tname: args.name,\n\t\t\trole: args.role,\n\t\t\tlocale: args.locale,\n\t\t\tref: args.ref,\n\t\t});\n\t\tconst { type: _type, ...rest } = args;\n\t\tconst input = {\n\t\t\tscope: args.scope,\n\t\t\temail: args.email,\n\t\t\tname: args.name,\n\t\t\trole: args.role,\n\t\t\t...(args.locale === undefined ? {} : { locale: args.locale }),\n\t\t\t...(args.ref === undefined ? {} : { ref: args.ref }),\n\t\t\t...(args.type === undefined ? {} : { type: args.type }),\n\t\t};\n\t\tconst user = await owner(deps, 'issue', args.scope, ctx, { input });\n\t\tconst done = await deps.invitations\n\t\t\t.issue({\n\t\t\t\t...rest,\n\t\t\t\t...(args.type == null ? {} : { type: args.type }),\n\t\t\t\tinvitedBy: user,\n\t\t\t})\n\t\t\t.then(undefined, rethrown);\n\t\treturn delivered(deps, 'issue', done, ctx);\n\t};\n}\n\n/** `Mutation.resendInvitation`: a new code and lifetime for a pending invitation. */\nexport function resendInvitation(deps: Deps): Mutations['resendInvitation'] {\n\treturn async (_, { scope, id }, ctx) => {\n\t\tconst user = await owner(deps, 'resend', scope, ctx, async () => {\n\t\t\tconst invitation = await stored(deps, scope, id);\n\t\t\treturn invitation === null ? null : { invitation };\n\t\t});\n\t\tconst done = await deps.invitations\n\t\t\t.resend({ id, scope, by: user.id })\n\t\t\t.then(undefined, rethrown);\n\t\treturn delivered(deps, 'resend', done, ctx);\n\t};\n}\n\n/** `Mutation.revokeInvitation`: takes a pending invitation back. */\nexport function revokeInvitation(deps: Deps): Mutations['revokeInvitation'] {\n\treturn async (_, { scope, id }, ctx) => {\n\t\tconst user = await owner(deps, 'revoke', scope, ctx, async () => {\n\t\t\tconst invitation = await stored(deps, scope, id);\n\t\t\treturn invitation === null ? null : { invitation };\n\t\t});\n\t\tconst revoked = await deps.invitations\n\t\t\t.revoke({ id, scope, by: user.id })\n\t\t\t.then(undefined, rethrown);\n\t\treturn invitationOut(revoked);\n\t};\n}\n",
48
+ "/**\n * The resolvers of the invitation SDL: two `Query` fields, four `Mutation`\n * fields, the page's lazy `totalCount` and the accept union's `__resolveType`. A new invitee's sign-in sets\n * the session cookie (and the device cookie) through `useJanus()`'s\n * `onResponse`, as a renewed session is.\n */\n\nimport type { Auth, UserOfAuth } from '../../types';\nimport type {\n\tAnyUser,\n\tInvitationAuth,\n\tInvitationResolvers,\n\tInvitationResolversOptions,\n} from '../types';\nimport { acceptInvitation, invitationPreview } from './anonymous';\nimport { depsOf } from './deps';\nimport {\n\tinvitations,\n\tissueInvitation,\n\tresendInvitation,\n\trevokeInvitation,\n\ttotalCount,\n} from './owner';\n\n/**\n * The resolvers of the invitation SDL. A refusal of the core —\n * `INVITATION_INVALID` (`field`), `INVITATION_LIMIT` (`maxActive`),\n * `INVITATION_NOT_PENDING`, `INVITATION_REFUSED`, `PASSWORD_REQUIRED`… — is rethrown as its\n * `GraphQLError`, so `janusMaskError()` answers its code and status. Needs\n * `useJanus()` for the directives and for the cookies of an accept. Throws a\n * `TypeError` at wiring when `auth` has no `invitations`, `authorize` is\n * missing, or neither `sendInvitation` nor `answerCode` says where the code\n * goes.\n *\n * **`authorize` is the only guard**, and `invitationPreview` and\n * `acceptInvitation` are open to whoever holds a code: throttle them.\n *\n * ```ts\n * const resolvers = mergeResolvers([\n * invitationResolvers({\n * auth,\n * authorize: (action, { user, scope }, ctx) => can(ctx, 'invite', { type: 'organization', id: scope }),\n * sendInvitation: ({ invitation, code }) => mailer.sendInvitation(invitation, code),\n * }),\n * mine,\n * ]);\n * ```\n *\n * `Query` and `Mutation` are keys of the map: merge it with yours rather than\n * spreading over them.\n */\nexport function invitationResolvers<\n\tA extends InvitationAuth & Auth<AnyUser>,\n\tconst T extends UserOfAuth<A>['type'] = never,\n>(options: InvitationResolversOptions<A, T>): InvitationResolvers {\n\tconst deps = depsOf(options);\n\treturn {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tQuery: {\n\t\t\tinvitations: invitations(deps),\n\t\t\tinvitationPreview: invitationPreview(deps),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tMutation: {\n\t\t\tissueInvitation: issueInvitation(deps),\n\t\t\tresendInvitation: resendInvitation(deps),\n\t\t\trevokeInvitation: revokeInvitation(deps),\n\t\t\tacceptInvitation: acceptInvitation(deps),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tJanusInvitationPage: { totalCount: totalCount(deps) },\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tInvitationAcceptResult: {\n\t\t\t__resolveType: (result) =>\n\t\t\t\tresult.status === 'signedIn'\n\t\t\t\t\t? 'InvitationSignedIn'\n\t\t\t\t\t: result.status === 'secondFactor'\n\t\t\t\t\t\t? 'InvitationSecondFactor'\n\t\t\t\t\t\t: 'InvitationSignIn',\n\t\t},\n\t};\n}\n",
49
+ "/**\n * The accept side of the invitation SDL: the preview and the three answers of\n * `acceptInvitation`. Part of `janusInvitationTypeDefs`, whose text it is\n * spliced into unchanged.\n */\nexport const acceptTypes: string = `\"\"\"\nWhat a code names, for the page the invitee lands on: the content of the\ninvitation, nothing about who sent it or how it stands.\n\"\"\"\ntype JanusInvitationPreview {\n\tid: ID!\n\tscope: String!\n\temail: String!\n\tname: String!\n\trole: String!\n\tlocale: String\n\t\"\"\"\n\tThe user type the invitation is for, so the page can adapt its wording or\n\tflow to it.\n\t\"\"\"\n\ttype: String!\n\t\"\"\"\n\tThe name of the scope's organization (school, clinic, workspace), from the\n\tapplication's describeScope option; null when it names none or is not\n\tgiven.\n\t\"\"\"\n\torganization: String\n\texpiresAt: String!\n\t\"\"\"\n\tWhether the page should ask for a password: false for a user type with no\n\tpassword, or somebody who already has an account with a proved e-mail and a\n\tpassword.\n\t\"\"\"\n\tneedsPassword: Boolean!\n}\n\n\"\"\"\nThe invitation was accepted and a session was opened: a new invitee, an\naccount whose e-mail was never proved, or a proved account with no password\nyet, given one.\n\"\"\"\ntype InvitationSignedIn {\n\t\"\"\"\n\tThe session token, only with \\`answerToken\\`; otherwise the session\n\tcookie is set and this is null.\n\t\"\"\"\n\ttoken: String\n\tuserId: ID!\n\t\"\"\"\n\tWhen the session ends, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\tnewDevice: Boolean!\n\tinvitationId: ID!\n\tscope: String!\n\trole: String!\n}\n\n\"\"\"\nThe invitation was accepted and a second factor is still to prove: confirm\nit with the challenge. No session is open yet. The challenge is a secret:\nnever in a URL or a log.\n\"\"\"\ntype InvitationSecondFactor {\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhat can answer the challenge: \\`totp\\` always, and \\`passkey\\` when the\n\tuser holds one.\n\t\"\"\"\n\tmethods: [String!]!\n\t\"\"\"\n\tThe JSON text for \\`navigator.credentials.get({ publicKey })\\`, present\n\texactly when \\`methods\\` holds \\`passkey\\`.\n\t\"\"\"\n\tpasskeyOptions: String\n\tinvitationId: ID!\n\tscope: String!\n}\n\n\"\"\"\nThe address belongs to a proved user who already has a password (the password\ngiven is ignored), or who has none and gave none. They are NOT signed in: an\ninvitation proves the inbox, not who holds the account. Send them to the\nsign-in page.\n\"\"\"\ntype InvitationSignIn {\n\tinvitationId: ID!\n\tscope: String!\n\temail: String!\n}\n\nunion InvitationAcceptResult =\n\t| InvitationSignedIn\n\t| InvitationSecondFactor\n\t| InvitationSignIn`;\n",
50
+ "/**\n * The owner side of the invitation SDL: the invitation, its issued and page\n * answers, the order, and the fields of `Query` and `Mutation`. Part of\n * `janusInvitationTypeDefs`, whose text they are spliced into unchanged.\n */\nexport const ownerTypes: string = `\"\"\"\nAn invitation into a scope (an organization, a team), as its owners see it.\nThe code is never here: \\`issueInvitation\\` and \\`resendInvitation\\` answer it\nonce.\n\"\"\"\ntype JanusInvitation {\n\tid: ID!\n\t\"\"\"\n\tThe organization (or any grouping) the invitation is into.\n\t\"\"\"\n\tscope: String!\n\temail: String!\n\tname: String!\n\trole: String!\n\tlocale: String\n\t\"\"\"\n\tThe application's opaque reference the invitation was issued with (its own\n\trecord), or null.\n\t\"\"\"\n\tref: String\n\t\"\"\"\n\tThe user type the invitation is for, one of the configured types; an\n\tinvitation stored before types existed reads as the first one.\n\t\"\"\"\n\ttype: String!\n\t\"\"\"\n\t\\`pending\\`, \\`accepted\\` or \\`revoked\\`. A \\`pending\\` invitation past\n\t\\`expiresAt\\` is lapsed: it cannot be previewed or accepted, and\n\t\\`resendInvitation\\` gives it a new code.\n\t\"\"\"\n\tstatus: String!\n\t\"\"\"\n\tThe id of the user who sent it, or null when the system issued it.\n\t\"\"\"\n\tinvitedBy: ID\n\t\"\"\"\n\tTimestamps, as ISO-8601 strings.\n\t\"\"\"\n\tcreatedAt: String!\n\tupdatedAt: String!\n\texpiresAt: String!\n\tacceptedBy: ID\n\tacceptedAt: String\n\trevokedAt: String\n\t\"\"\"\n\tThe id of the user who revoked it, or null.\n\t\"\"\"\n\trevokedBy: ID\n\t\"\"\"\n\tThe id of the user who last sent it again, or null.\n\t\"\"\"\n\tresentBy: ID\n}\n\n\"\"\"\nAn invitation just issued or sent again.\n\"\"\"\ntype JanusIssuedInvitation {\n\tinvitation: JanusInvitation!\n\t\"\"\"\n\tThe code, a secret: null unless \\`answerCode\\` is on. It belongs in the\n\tinvitation e-mail's link, never in a URL you log or a response a cache\n\tkeeps (the response is \\`no-store\\`).\n\t\"\"\"\n\tcode: String\n}\n\n\"\"\"\nOne page of a scope's invitations. \\`nextCursor\\` is null on the last page.\n\"\"\"\ntype JanusInvitationPage {\n\titems: [JanusInvitation!]!\n\tnextCursor: String\n\t\"\"\"\n\tHow many invitations of the scope match the filters (\\`status\\`, \\`role\\`,\n\t\\`ref\\`), whatever the paging. Counted only when selected, and answered only on a page\n\t\\`invitations\\` returned (a page of your own has no count and fails). A \\`pending\\`\n\tinvitation past \\`expiresAt\\` still counts, as it is still listed.\n\t\"\"\"\n\ttotalCount: Int!\n}\n\n\"\"\"\nThe order of a scope's invitations: by creation.\n\"\"\"\nenum JanusInvitationOrder {\n\tOLDEST\n\tNEWEST\n}\n\n\"\"\"\nWhether lapsed invitations (pending, past their expiry) are left out of a\nlist: \\`EXCLUDE\\` drops them and keeps every other invitation, \\`ONLY\\` keeps\nonly them.\n\"\"\"\nenum JanusInvitationLapsed {\n\tEXCLUDE\n\tONLY\n}`;\n\nexport const ownerOperations: string = `extend type Query {\n\t\"\"\"\n\tOne scope's invitations, \\`OLDEST\\` first unless \\`order\\` says \\`NEWEST\\`.\n\t\\`status\\` is \\`pending\\`, \\`accepted\\` or \\`revoked\\` (BAD_USER_INPUT\n\totherwise); \\`role\\` and \\`ref\\` keep the invitations with exactly that role\n\tor reference; \\`lapsed\\` is \\`EXCLUDE\\` to leave out the lapsed (pending,\n\tpast \\`expiresAt\\`) or \\`ONLY\\` to keep just them, and \\`totalCount\\` follows\n\tit; \\`limit\\` is a positive integer, 20 by default and at most\n\t100; \\`after\\` is the previous page's \\`nextCursor\\`, in the same order. An\n\tempty \\`role\\` or \\`ref\\` is BAD_USER_INPUT. Each BAD_USER_INPUT (and\n\tINVALID_CURSOR) names the argument in \\`extensions.field\\`.\n\tNOT_FOUND when the application's \\`authorize\\` refuses the scope.\n\t\"\"\"\n\tinvitations(\n\t\tscope: String!\n\t\tstatus: String\n\t\trole: String\n\t\tref: String\n\t\tlapsed: JanusInvitationLapsed\n\t\torder: JanusInvitationOrder\n\t\tlimit: Int\n\t\tafter: String\n\t): JanusInvitationPage! @authenticated\n\t\"\"\"\n\tWhat \\`code\\` names, without spending it. INVITATION_INVALID (400, \\`extensions.reason\\`: unknown,\n\texpired, accepted or revoked) for any code that names no pending, unlapsed\n\tinvitation. Open to anybody: the\n\tcode is a secret (send it in the variables of a POST, never in a URL), and\n\tthe field is not throttled here. A \\`code\\` longer than 43 characters is\n\tBAD_USER_INPUT (400, \\`field: 'code'\\`).\n\t\"\"\"\n\tinvitationPreview(code: String!): JanusInvitationPreview!\n}\n\nextend type Mutation {\n\t\"\"\"\n\tInvites \\`email\\` into \\`scope\\` with \\`role\\`; the inviter is the signed-in\n\tuser. Issuing again for an address that has a pending invitation revokes\n\tit and makes a new one. INVITATION_INVALID (\\`field\\`) for an input that\n\tcannot be kept, INVITATION_LIMIT (\\`maxActive\\`) when the scope is full,\n\tNOT_FOUND when \\`authorize\\` refuses. \\`ref\\` is an opaque reference to your\n\town record (1 to 100 characters), answered back and usable as a filter of\n\t\\`invitations\\`. An argument over its maximum (\\`scope\\` 512, \\`email\\` 254, \\`name\\`,\n\t\\`role\\` and \\`ref\\` 100, \\`locale\\` 35 characters) is BAD_USER_INPUT (400, \\`field\\`)\n\tbefore \\`authorize\\` runs. \\`type\\` is the user type the invitee becomes: required when\n\tthe instance configures several user types (null or absent means the\n\tinstance's single type), INVITATION_INVALID\n\t(\\`field: 'type'\\`) when absent then, or when it names none of them.\n\t\"\"\"\n\tissueInvitation(\n\t\tscope: String!\n\t\temail: String!\n\t\tname: String!\n\t\trole: String!\n\t\tlocale: String\n\t\tref: String\n\t\ttype: String\n\t): JanusIssuedInvitation! @authenticated\n\t\"\"\"\n\tA new code and lifetime for a pending invitation, lapsed or not; the old\n\tcode stops working. NOT_FOUND for an id of another scope,\n\tINVITATION_NOT_PENDING (409) when it is accepted or revoked.\n\t\"\"\"\n\tresendInvitation(scope: String!, id: ID!): JanusIssuedInvitation!\n\t\t@authenticated\n\t\"\"\"\n\tTakes a pending invitation back. NOT_FOUND as \\`resendInvitation\\`,\n\tINVITATION_NOT_PENDING (409) when it is accepted or already revoked.\n\t\"\"\"\n\trevokeInvitation(scope: String!, id: ID!): JanusInvitation! @authenticated\n\t\"\"\"\n\tAccepts the invitation \\`code\\` names: the code proves the invitee's inbox.\n\tA new invitee, an account whose e-mail was never proved, or a proved account\n\twith no password yet (given one) is signed in (the session cookie, or \\`token\\`\n\twith \\`answerToken\\`); a proved user who already has a password (the password\n\tgiven is ignored), or who has none and gave none, is answered\n\t\\`InvitationSignIn\\` and is not. INVITATION_INVALID (400, \\`extensions.reason\\`: unknown, expired, accepted or revoked) for a code that names no pending\n\tinvitation, PASSWORD_REQUIRED (400) when a password is needed and absent.\n\tINVITATION_REFUSED (403) when the application's \\`beforeAccept\\` refused, with\n\tnothing written. A \\`code\\` over 43 characters or a \\`password\\` over 1024 is\n\tBAD_USER_INPUT (400, \\`field\\`), the code unspent.\n\tOpen to anybody and not throttled here.\n\t\"\"\"\n\tacceptInvitation(code: String!, password: String): InvitationAcceptResult!\n}`;\n",
51
+ "import { acceptTypes } from './accept';\nimport { ownerOperations, ownerTypes } from './owner';\n\n/**\n * The opt-in invitation SDL: put it beside your own type definitions when\n * people are invited into a scope (an organization, a team). It `extend`s your\n * `Query` and `Mutation`, and needs `janusTypeDefs` for its directives. The\n * same text ships as `graphql/janus-invitations.graphqls` — `sdl.spec.ts`\n * holds that the two are identical. Timestamps are ISO-8601 `String`s: no\n * scalar to collide with.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, janusInvitationTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusInvitationTypeDefs: string = `${ownerTypes}\n\n${acceptTypes}\n\n${ownerOperations}\n`;\n",
52
+ "/** The surface of a user type on `auth`, shared by the passkey and second-factor modules. */\n\nexport interface SurfaceSpec<Api extends object> {\n\t/** The caller's name for its error messages, e.g. `passkeyResolvers`. */\n\treadonly name: string;\n\t/** The key that is on `auth` itself when it holds one user type. */\n\treadonly key: keyof Api;\n\t/** Whether the holder has everything the caller needs. */\n\treadonly complete: (holder: Partial<Api> | undefined) => boolean;\n\t/** The message tail when `auth` is the holder, after `<name>(): `. */\n\treadonly missing: string;\n\t/** The message tail when `auth[type]` is the holder, after `<name>(): `. */\n\treadonly missingOf: (type: string) => string;\n}\n\n/** The surface of the user type: the instance itself with one type, `auth[type]` with several. */\nexport function apiOf<Api extends object>(\n\tauth: object,\n\ttype: string | undefined,\n\tspec: SurfaceSpec<Api>,\n): Api {\n\tconst top = auth as Partial<Api>;\n\t// One user type puts the surface on `auth`; several, under the type's name.\n\tconst holder: Partial<Api> | undefined =\n\t\ttype === undefined || top[spec.key] !== undefined\n\t\t\t? top\n\t\t\t: (auth as Record<string, Partial<Api> | undefined>)[type];\n\tif (!spec.complete(holder)) {\n\t\tthrow new TypeError(\n\t\t\t`${spec.name}(): ${type === undefined ? spec.missing : spec.missingOf(type)}`,\n\t\t);\n\t}\n\treturn holder as Api;\n}\n",
53
+ "/** What every passkey field reads: the instance serving the request, bound to the user type and the surfaces it must carry. */\n\nimport type { DeviceCookieOptions } from '../device';\nimport { rethrown } from '../errors';\nimport { requireUser } from '../helpers';\nimport { apiOf, type SurfaceSpec } from '../surface/api';\nimport { requestOf } from '../surface/request';\nimport type { PasskeyFirstFactorTypeApi } from './first-factor.types';\nimport type {\n\tAnyUser,\n\tContext,\n\tCurrent,\n\tPasskeyAuth,\n\tPasskeyTypeApi,\n} from './types';\n\n/** With `firstFactor` an instance needs no `secondFactor`: the management fields only need `passkeys`. */\nconst MANAGE: SurfaceSpec<PasskeyTypeApi> = {\n\tname: 'passkeyResolvers',\n\tkey: 'passkeys',\n\tcomplete: (holder) => holder?.passkeys !== undefined,\n\tmissing:\n\t\t'auth has no passkeys — give janus() `passkeys`; with several user types, name the one with `type`',\n\tmissingOf: (type) =>\n\t\t`auth.${type} has no passkeys — give janus() \\`passkeys\\`, and name a user type that exists`,\n};\n\nconst SURFACE: SurfaceSpec<PasskeyTypeApi> = {\n\tname: 'passkeyResolvers',\n\tkey: 'passkeys',\n\tcomplete: (holder) =>\n\t\tholder?.passkeys !== undefined &&\n\t\tholder.secondFactor?.confirmPasskey !== undefined,\n\tmissing:\n\t\t'auth has no passkeys — give janus() `passkeys` and a `secondFactor`; with several user types, name the one with `type`',\n\tmissingOf: (type) =>\n\t\t`auth.${type} has no passkeys — give janus() \\`passkeys\\` and a \\`secondFactor\\`, and name a user type that exists`,\n};\n\nconst FIRST_FACTOR: SurfaceSpec<PasskeyFirstFactorTypeApi> = {\n\tname: 'passkeyResolvers',\n\tkey: 'passkeys',\n\tcomplete: (holder) =>\n\t\ttypeof holder?.passkeys?.signInOptions === 'function' &&\n\t\ttypeof holder.passkeys.signIn === 'function',\n\tmissing:\n\t\t'firstFactor needs an auth with passkeys.firstFactor — give janus() `passkeys: { firstFactor: true }`',\n\tmissingOf: (type) =>\n\t\t`firstFactor needs auth.${type} with passkeys.firstFactor — give janus() \\`passkeys: { firstFactor: true }\\`, and name a user type that exists`,\n};\n\n/** What `passkeyResolvers()` resolves from one instance: the calls every field makes. */\nexport interface Bound {\n\treadonly auth: PasskeyAuth;\n\treadonly api: PasskeyTypeApi;\n\treadonly first: PasskeyFirstFactorTypeApi | undefined;\n\tsession(ctx: Context): Promise<Current | null>;\n\tuserOf(ctx: Context): Promise<AnyUser>;\n}\n\n/** Binds an instance to the user type and the surfaces it must carry; throws a `TypeError` when one is missing. */\nexport function binder(\n\ttype: string | undefined,\n\tfirstFactor: boolean,\n): (auth: PasskeyAuth) => Bound {\n\tconst only = type === undefined ? {} : { type };\n\treturn (auth) => ({\n\t\tauth,\n\t\tapi: apiOf<PasskeyTypeApi>(auth, type, firstFactor ? MANAGE : SURFACE),\n\t\tfirst: firstFactor\n\t\t\t? apiOf<PasskeyFirstFactorTypeApi>(auth, type, FIRST_FACTOR)\n\t\t\t: undefined,\n\t\tsession: (ctx) =>\n\t\t\tauth\n\t\t\t\t.authenticate(requestOf(ctx, 'passkeyResolvers'), only)\n\t\t\t\t.then(undefined, rethrown),\n\t\t// `ctx.janus` is what `useJanus()` puts on every context.\n\t\tuserOf: (ctx) =>\n\t\t\trequireUser<AnyUser>(\n\t\t\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t\t\t\tonly,\n\t\t\t),\n\t});\n}\n\n/** What every field's resolver reads. */\nexport interface Deps {\n\treadonly answerToken: boolean;\n\t/** The device cookie's attributes, or `undefined` when devices are not tracked. */\n\treadonly device: DeviceCookieOptions | undefined;\n\t/** The instance serving this request, bound. */\n\tbound(ctx: Context): Promise<Bound>;\n}\n",
54
+ "/**\n * The answers of the passkey resolvers: a core result as the plain object the\n * schema's fields read, timestamps as ISO-8601 strings, WebAuthn JSON as text.\n */\n\nimport type { Passkey } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport type { PasskeyOut } from './types';\n\nexport const passkeyOut = (passkey: Passkey): PasskeyOut => ({\n\tcredentialId: passkey.credentialId,\n\tname: passkey.name,\n\ttransports: passkey.transports,\n\taaguid: passkey.aaguid,\n\tbackupEligible: passkey.backupEligible,\n\tbackedUp: passkey.backedUp,\n\tcreatedAt: passkey.createdAt.toISOString(),\n\tlastUsedAt: passkey.lastUsedAt?.toISOString() ?? null,\n});\n\n/**\n * What the browser answered, parsed from the string the client sent. A text\n * that is not JSON is `BAD_USER_INPUT`, 400, before anything is spent; none\n * of it is echoed back.\n */\nexport function jsonOf(text: string, argument: string): unknown {\n\ttry {\n\t\treturn JSON.parse(text);\n\t} catch {\n\t\tthrow new GraphQLError(`${argument} must be a JSON string`, {\n\t\t\textensions: { code: 'BAD_USER_INPUT', http: { status: 400 } },\n\t\t});\n\t}\n}\n",
55
+ "/** The resolvers of the first-factor sign-in SDL, added by `passkeyResolvers({ firstFactor: true })`. */\n\nimport { deviceOf } from '../device';\nimport { rethrown } from '../errors';\nimport { noStoreOf } from '../renewal';\nimport { requestOf } from '../surface/request';\nimport { signedInAnswer } from '../surface/signed-in';\nimport type { Deps } from './deps';\nimport type { PasskeyFirstFactorTypeApi } from './first-factor.types';\nimport { jsonOf } from './shape';\nimport type { PasskeyResolvers } from './types';\n\ntype Queries = PasskeyResolvers['Query'];\ntype Mutations = PasskeyResolvers['Mutation'];\n\n/**\n * `Query.passkeySignInOptions` (with `firstFactor`): the options for\n * `navigator.credentials.get`, with no credential named, and a challenge.\n */\nexport function passkeySignInOptions({\n\tbound,\n}: Deps): NonNullable<Queries['passkeySignInOptions']> {\n\treturn async (_, __, ctx) => {\n\t\t// Present: this resolver exists only with `firstFactor`, which binds it.\n\t\tconst first = (await bound(ctx)).first as PasskeyFirstFactorTypeApi;\n\t\tconst made = await first.passkeys.signInOptions().then(undefined, rethrown);\n\t\t// The challenge is single-use: no cache keeps it.\n\t\tnoStoreOf(ctx);\n\t\treturn {\n\t\t\toptions: JSON.stringify(made.options),\n\t\t\tchallenge: made.challenge,\n\t\t\texpiresAt: made.expiresAt.toISOString(),\n\t\t};\n\t};\n}\n\n/**\n * `Mutation.passkeySignIn` (with `firstFactor`): redeems the challenge with\n * the browser's assertion and opens a session with the passkey alone; sets\n * the session cookie, or answers its token with `answerToken`; with `device`,\n * tracks the device and sets its cookie.\n */\nexport function passkeySignIn({\n\tbound,\n\tanswerToken,\n\tdevice,\n}: Deps): NonNullable<Mutations['passkeySignIn']> {\n\treturn async (_, { challenge, assertion }, ctx) => {\n\t\tconst { auth, first: held } = await bound(ctx);\n\t\tconst first = held as PasskeyFirstFactorTypeApi;\n\t\tconst request = requestOf(ctx, 'passkeyResolvers');\n\t\tconst parsed = jsonOf(assertion, 'assertion');\n\t\tconst done = await first.passkeys\n\t\t\t.signIn(\n\t\t\t\tchallenge,\n\t\t\t\tparsed,\n\t\t\t\tdevice === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { device: deviceOf(request, device) },\n\t\t\t)\n\t\t\t.then(undefined, rethrown);\n\t\treturn signedInAnswer({ auth, answerToken, device }, request, done);\n\t};\n}\n",
56
+ "/**\n * The resolvers of the passkey SDL: two `Query` fields and four `Mutation`\n * fields. A completed passkey sign-in sets the session cookie and the device\n * cookie through `useJanus()`'s `onResponse`, as a renewed session is.\n */\n\nimport { deviceOf } from '../device';\nimport { denial, rethrown } from '../errors';\nimport { noStoreOf } from '../renewal';\nimport { requestOf } from '../surface/request';\nimport { signedInAnswer } from '../surface/signed-in';\nimport { type Bound, binder, type Deps } from './deps';\nimport type { PasskeyAuthSource } from './first-factor.types';\nimport { jsonOf, passkeyOut } from './shape';\nimport { passkeySignIn, passkeySignInOptions } from './sign-in.resolvers';\nimport type {\n\tContext,\n\tPasskeyAuth,\n\tPasskeyResolvers,\n\tPasskeyResolversOptions,\n} from './types';\n\n/**\n * The resolvers of the passkey SDL. A refusal of the core —\n * `PASSKEY_INVALID`, `PASSKEY_TAKEN`, `PASSKEY_LIMIT`, `STEP_UP_REQUIRED`,\n * `CODE_INVALID`, `TOKEN_UNKNOWN`… — is rethrown as its `GraphQLError`, so\n * `janusMaskError()` answers its code and status. Needs `useJanus()` for the\n * directives and to set the cookies of a completed sign-in. Throws a\n * `TypeError` at wiring when `janus()` was given no `passkeys`.\n *\n * ```ts\n * const resolvers = mergeResolvers([passkeyResolvers({ auth }), mine]);\n * ```\n *\n * `Query` and `Mutation` are keys of the map: merge it with yours rather than\n * spreading over them.\n */\nexport function passkeyResolvers<\n\tA extends PasskeyAuth,\n\tconst T extends string = never,\n\tconst F extends boolean = false,\n\tCtx = Context,\n>(options: PasskeyResolversOptions<A, T, F, Ctx>): PasskeyResolvers<F> {\n\tconst { answerToken = false, firstFactor = false } = options;\n\tconst source = options.auth as PasskeyAuthSource<PasskeyAuth, Context>;\n\tconst type: string | undefined = options.type;\n\tconst device = options.device === true ? {} : options.device;\n\tconst bind = binder(type, firstFactor === true);\n\t// An instance is bound once, at wiring; a function is asked on every field.\n\tconst fixed = typeof source === 'function' ? undefined : bind(source);\n\tconst chosenBefore = new WeakMap<object, Bound>();\n\tconst deps: Deps = {\n\t\tanswerToken,\n\t\tdevice,\n\t\tbound: async (ctx) => {\n\t\t\tif (fixed !== undefined) return fixed;\n\t\t\tconst chosen = await (source as (ctx: Context) => unknown)(ctx);\n\t\t\tif (chosen === null || chosen === undefined) {\n\t\t\t\tthrow denial('UNAUTHENTICATED');\n\t\t\t}\n\t\t\tconst instance = chosen as PasskeyAuth;\n\t\t\tconst known = chosenBefore.get(instance);\n\t\t\tif (known !== undefined) return known;\n\t\t\tconst made = bind(instance);\n\t\t\tchosenBefore.set(instance, made);\n\t\t\treturn made;\n\t\t},\n\t};\n\tconst map: PasskeyResolvers = {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tQuery: {\n\t\t\tpasskeys: passkeys(deps),\n\t\t\tpasskeyRegistrationOptions: passkeyRegistrationOptions(deps),\n\t\t\t...(firstFactor === true\n\t\t\t\t? { passkeySignInOptions: passkeySignInOptions(deps) }\n\t\t\t\t: {}),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tMutation: {\n\t\t\tregisterPasskey: registerPasskey(deps),\n\t\t\trenamePasskey: renamePasskey(deps),\n\t\t\tremovePasskey: removePasskey(deps),\n\t\t\tconfirmSecondFactorPasskey: confirmSecondFactorPasskey(deps),\n\t\t\t...(firstFactor === true ? { passkeySignIn: passkeySignIn(deps) } : {}),\n\t\t},\n\t};\n\t// The two sign-in fields are spread exactly when `firstFactor === true`,\n\t// which is what `F` carries; the compiler cannot relate the two.\n\treturn map as PasskeyResolvers<F>;\n}\n\ntype Queries = PasskeyResolvers['Query'];\ntype Mutations = PasskeyResolvers['Mutation'];\n\n/** `Query.passkeys`: the signed-in user's passkeys, oldest first. */\nfunction passkeys({ bound }: Deps): Queries['passkeys'] {\n\treturn async (_, __, ctx) => {\n\t\tconst { api, userOf } = await bound(ctx);\n\t\tconst user = await userOf(ctx);\n\t\tconst held = await api.passkeys.list(user).then(undefined, rethrown);\n\t\treturn held.map(passkeyOut);\n\t};\n}\n\n/** `Query.passkeyRegistrationOptions`: a challenge, and the options the browser needs. */\nfunction passkeyRegistrationOptions({\n\tbound,\n}: Deps): Queries['passkeyRegistrationOptions'] {\n\treturn async (_, __, ctx) => {\n\t\tconst { api, userOf } = await bound(ctx);\n\t\tconst user = await userOf(ctx);\n\t\tconst made = await api.passkeys\n\t\t\t.registrationOptions(user)\n\t\t\t.then(undefined, rethrown);\n\t\t// The challenge is single-use: no cache keeps it.\n\t\tnoStoreOf(ctx);\n\t\treturn {\n\t\t\toptions: JSON.stringify(made.options),\n\t\t\tchallenge: made.challenge,\n\t\t\texpiresAt: made.expiresAt.toISOString(),\n\t\t};\n\t};\n}\n\n/** `Mutation.registerPasskey`: finishes a registration; the core asks for a fresh session. */\nfunction registerPasskey({ bound }: Deps): Mutations['registerPasskey'] {\n\treturn async (_, { challenge, response, name }, ctx) => {\n\t\tconst { api, session } = await bound(ctx);\n\t\tconst current = await session(ctx);\n\t\tif (current === null) throw denial('UNAUTHENTICATED');\n\t\tconst parsed = jsonOf(response, 'response');\n\t\treturn passkeyOut(\n\t\t\tawait api.passkeys\n\t\t\t\t.register(current, { challenge, response: parsed, name })\n\t\t\t\t.then(undefined, rethrown),\n\t\t);\n\t};\n}\n\n/** `Mutation.renamePasskey`: true when one of the user's passkeys was renamed. */\nfunction renamePasskey({ bound }: Deps): Mutations['renamePasskey'] {\n\treturn async (_, { credentialId, name }, ctx) => {\n\t\tconst { api, userOf } = await bound(ctx);\n\t\tconst user = await userOf(ctx);\n\t\treturn api.passkeys\n\t\t\t.rename(user, credentialId, name)\n\t\t\t.then(undefined, rethrown);\n\t};\n}\n\n/** `Mutation.removePasskey`: true when this call removed one; the core asks for a fresh session. */\nfunction removePasskey({ bound }: Deps): Mutations['removePasskey'] {\n\treturn async (_, { credentialId }, ctx) => {\n\t\tconst { api, session } = await bound(ctx);\n\t\tconst current = await session(ctx);\n\t\tif (current === null) throw denial('UNAUTHENTICATED');\n\t\treturn api.passkeys.remove(current, credentialId).then(undefined, rethrown);\n\t};\n}\n\n/**\n * `Mutation.confirmSecondFactorPasskey`: redeems a sign-in's challenge with\n * the browser's assertion; sets the session cookie, or answers its token\n * with `answerToken`; with `device`, tracks the device and sets its cookie.\n */\nfunction confirmSecondFactorPasskey({\n\tbound,\n\tanswerToken,\n\tdevice,\n}: Deps): Mutations['confirmSecondFactorPasskey'] {\n\treturn async (_, { challenge, assertion }, ctx) => {\n\t\tconst { auth, api } = await bound(ctx);\n\t\tconst request = requestOf(ctx, 'passkeyResolvers');\n\t\tconst parsed = jsonOf(assertion, 'assertion');\n\t\t// `firstFactor: true` does not need a `secondFactor`; this field does.\n\t\tif (api.secondFactor?.confirmPasskey === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'passkeyResolvers: confirmSecondFactorPasskey needs janus() `secondFactor`.',\n\t\t\t);\n\t\t}\n\t\tconst done = await api.secondFactor\n\t\t\t.confirmPasskey(\n\t\t\t\tchallenge,\n\t\t\t\tparsed,\n\t\t\t\tdevice === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { device: deviceOf(request, device) },\n\t\t\t)\n\t\t\t.then(undefined, rethrown);\n\t\treturn signedInAnswer({ auth, answerToken, device }, request, done);\n\t};\n}\n",
57
+ "/**\n * The opt-in passkey SDL: put it beside your own type definitions when users\n * hold passkeys as a second factor. It `extend`s your `Query` and `Mutation`,\n * and needs `janusTypeDefs` for `@authenticated`. The same text ships as\n * `graphql/janus-passkeys.graphqls` — `sdl.spec.ts` holds that the two are\n * identical. Timestamps are ISO-8601 `String`s and WebAuthn JSON travels as\n * `String`s too: no scalar to collide with.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, janusPasskeyTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusPasskeyTypeDefs: string = `\"\"\"\nOne passkey a user registered. Never carries the public key or the counter.\n\"\"\"\ntype JanusPasskey {\n\t\"\"\"\n\tThe authenticator's credential id, base64url. Pass it back to\n\t\\`renamePasskey\\` and \\`removePasskey\\`.\n\t\"\"\"\n\tcredentialId: ID!\n\t\"\"\"\n\tThe name the user gave it.\n\t\"\"\"\n\tname: String!\n\t\"\"\"\n\tWhat the authenticator reported at registration (\\`internal\\`, \\`usb\\`).\n\t\"\"\"\n\ttransports: [String!]!\n\t\"\"\"\n\tThe authenticator model, for an icon or a label.\n\t\"\"\"\n\taaguid: String!\n\t\"\"\"\n\tWhether the credential may be synced across the user's devices.\n\t\"\"\"\n\tbackupEligible: Boolean!\n\t\"\"\"\n\tWhether it is synced now.\n\t\"\"\"\n\tbackedUp: Boolean!\n\t\"\"\"\n\tWhen it was registered, as an ISO-8601 string.\n\t\"\"\"\n\tcreatedAt: String!\n\t\"\"\"\n\tWhen it last answered a challenge, as an ISO-8601 string, or null.\n\t\"\"\"\n\tlastUsedAt: String\n}\n\n\"\"\"\nA registration begun: give \\`options\\` to the browser and keep \\`challenge\\`\nuntil \\`registerPasskey\\`.\n\"\"\"\ntype JanusPasskeyRegistration {\n\t\"\"\"\n\tThe JSON text for \\`navigator.credentials.create({ publicKey })\\`, as the\n\tverifier shaped it.\n\t\"\"\"\n\toptions: String!\n\t\"\"\"\n\tThe secret \\`registerPasskey\\` spends, once. Never in a URL or a log.\n\t\"\"\"\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n}\n\n\"\"\"\nA passkey sign-in completed: the session cookie is set on the response, or,\nwith \\`passkeyResolvers({ answerToken: true })\\`, the session token is\nanswered in \\`token\\` and no cookie is set. Extend this type with a \\`user\\`\nfield of your own: its parent carries the signed-in user.\n\"\"\"\ntype PasskeySignedIn {\n\t\"\"\"\n\tThe session token, answered only when \\`passkeyResolvers\\` has\n\t\\`answerToken: true\\`; null otherwise. A secret like a session cookie:\n\tnever in a URL or a log.\n\t\"\"\"\n\ttoken: String\n\t\"\"\"\n\tThe signed-in user's id.\n\t\"\"\"\n\tuserId: ID!\n\t\"\"\"\n\tWhen the session expires, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhether the session was opened from a device the user had not used.\n\t\"\"\"\n\tnewDevice: Boolean!\n}\n\nextend type Query {\n\t\"\"\"\n\tThe signed-in user's passkeys, oldest first.\n\t\"\"\"\n\tpasskeys: [JanusPasskey!]! @authenticated\n\t\"\"\"\n\tMakes a registration challenge and the options the browser needs. Only a\n\tuser with an active TOTP can register a passkey\n\t(SECOND_FACTOR_NOT_ENROLLED otherwise).\n\t\"\"\"\n\tpasskeyRegistrationOptions: JanusPasskeyRegistration! @authenticated\n}\n\nextend type Mutation {\n\t\"\"\"\n\tFinishes a registration with what \\`navigator.credentials.create\\`\n\tanswered, as a JSON string, and a name of 1 to 100 characters. Needs a\n\tsession that proved who it is recently (STEP_UP_REQUIRED). The challenge\n\tis spent even when the response does not verify (PASSKEY_INVALID): ask for\n\tnew options.\n\t\"\"\"\n\tregisterPasskey(\n\t\tchallenge: String!\n\t\tresponse: String!\n\t\tname: String!\n\t): JanusPasskey! @authenticated\n\t\"\"\"\n\tRenames one of the user's passkeys. False when it is not theirs or not\n\tthere.\n\t\"\"\"\n\trenamePasskey(credentialId: ID!, name: String!): Boolean! @authenticated\n\t\"\"\"\n\tRemoves one of the user's passkeys. True when this call removed it. Needs\n\ta session that proved who it is recently (STEP_UP_REQUIRED).\n\t\"\"\"\n\tremovePasskey(credentialId: ID!): Boolean! @authenticated\n\t\"\"\"\n\tRedeems a sign-in's second-factor challenge with what\n\t\\`navigator.credentials.get\\` answered, as a JSON string. Five attempts per\n\tchallenge, shared with the TOTP code (CODE_INVALID with attemptsLeft). Sets\n\tthe session cookie, or answers \\`token\\` with \\`answerToken\\`, and the\n\tdevice cookie.\n\t\"\"\"\n\tconfirmSecondFactorPasskey(\n\t\tchallenge: String!\n\t\tassertion: String!\n\t): PasskeySignedIn!\n}\n`;\n",
58
+ "/**\n * The opt-in first-factor passkey SDL: put it beside `janusPasskeyTypeDefs`\n * (it uses that SDL's `PasskeySignedIn`) when `janus()` has\n * `passkeys: { firstFactor: true }`. It `extend`s your `Query` and `Mutation`.\n * The same text ships as `graphql/janus-passkey-sign-in.graphqls` —\n * `sign-in.sdl.spec.ts` holds that the two are identical.\n *\n * ```ts\n * createSchema({\n * typeDefs: [janusTypeDefs, janusPasskeyTypeDefs, janusPasskeySignInTypeDefs, typeDefs],\n * resolvers: passkeyResolvers({ auth, firstFactor: true }),\n * });\n * ```\n */\nexport const janusPasskeySignInTypeDefs: string = `\"\"\"\nA passkey sign-in begun: give \\`options\\` to the browser and keep \\`challenge\\`\nuntil \\`passkeySignIn\\`.\n\"\"\"\ntype JanusPasskeySignInChallenge {\n\t\"\"\"\n\tThe JSON text for \\`navigator.credentials.get({ publicKey })\\`, with no\n\tcredential named: the browser offers the discoverable passkeys it holds.\n\t\"\"\"\n\toptions: String!\n\t\"\"\"\n\tThe secret \\`passkeySignIn\\` spends, once. Never in a URL or a log.\n\t\"\"\"\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n}\n\nextend type Query {\n\t\"\"\"\n\tMakes a sign-in challenge and the options the browser needs. Anyone may\n\task: rate-limit it where requests enter, as each call stores one\n\tshort-lived token. The response is never cached.\n\t\"\"\"\n\tpasskeySignInOptions: JanusPasskeySignInChallenge!\n}\n\nextend type Mutation {\n\t\"\"\"\n\tSigns in with a passkey alone, with what \\`navigator.credentials.get\\`\n\tanswered, as a JSON string: no password and no code. One attempt per\n\tchallenge: a refusal is CREDENTIALS_INVALID, 401, and asks for new options;\n\ta missing, spent or lapsed challenge is TOKEN_UNKNOWN, TOKEN_SPENT or\n\tTOKEN_EXPIRED. Sets the session cookie, or answers \\`token\\` with\n\t\\`answerToken\\`, and the device cookie.\n\t\"\"\"\n\tpasskeySignIn(challenge: String!, assertion: String!): PasskeySignedIn!\n}\n`;\n",
59
+ "/**\n * `useJanus()`, the envelop plugin — for Yoga, or any server built on\n * envelop.\n */\n\nimport type { Plugin } from '@envelop/core';\nimport type { RequestLike } from '@softistx/janus';\nimport type { GraphQLSchema } from 'graphql';\nimport { acceptedOf } from './connection/credential';\nimport { createJanusContext } from './context';\nimport { applyJanusDirectives } from './directives/apply';\nimport { checkWiring } from './options';\nimport { resendRenewed, track } from './renewal';\nimport type { Auth, JanusContext, JanusOptions, UserOfAuth } from './types';\n\n/**\n * The plugin that wires `@softistx/janus` into a GraphQL server:\n *\n * - every request's context gets `ctx.janus` — `user()` and `session()`,\n * authenticated lazily and once, and `access` when it is given;\n * - every schema the server is given has its directives applied, once, by\n * `applyJanusDirectives()`.\n *\n * ```ts\n * createYoga({\n * schema: createSchema({ typeDefs: [janusTypeDefs, typeDefs], resolvers }),\n * plugins: [useJanus({ auth, access })],\n * maskedErrors: { maskError: janusMaskError() },\n * });\n * ```\n *\n * `type` treats a user of any other type as anonymous, as\n * `auth.authenticate(request, { type })` does. `clock` is what `@fresh` and\n * `requireFresh()` read the time from — the one given to `janus()`.\n * `loaders` and `conditions` are what `@permission` needs beside `access`:\n * the objects it checks by id, and the `ctx` of the conditions it reaches.\n *\n * `apiKey: true` also accepts an API key (`Authorization: Bearer sl_…`):\n * `ctx.janus` gains `principal()` and `apiKey()`, `user()` is the key's user,\n * `session()` is `null` for a key, and `@fresh` refuses one with\n * `STEP_UP_REQUIRED`. Off, a key is anonymous and nothing else changes.\n *\n * A session `authenticate` renewed for a request that presented it as the\n * session cookie is sent again, `Set-Cookie` on Yoga's response\n * (`onResponse`), so a browser keeps the new expiry. Not to a bearer token or\n * `X-Session-Token`, and never when nothing authenticated.\n *\n * `auth` may also be a function of the request's context — `(ctx) =>\n * instance`, `ctx.request` over HTTP — answering the `janus()` instance that\n * serves it, so one server serves several issuers. It runs once per context,\n * the first time `user()` or `session()` asks; `types` then names the user\n * types the directives may use, which no instance can tell at start-up.\n *\n * An operation over graphql-ws has no request: its `ctx.janus`\n * authenticates the credential its connection presented, once\n * `janusConnection().onConnect` accepted it — and has no response to carry a\n * renewed cookie.\n */\nexport function useJanus<\n\tA extends Auth<{ readonly type: string; readonly id: string }>,\n\tP extends object | undefined = undefined,\n\tconst T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'],\n\tconst K extends boolean = false,\n>(\n\toptions: JanusOptions<A, P, T, K>,\n): Plugin<JanusContext<A, P, T, K>> & {\n\treadonly onResponse: (payload: {\n\t\treadonly request: Request;\n\t\treadonly response: Response;\n\t}) => Promise<void>;\n} {\n\tconst { auth, access, type, clock, apiKey, loaders, conditions } = options;\n\tconst types =\n\t\ttypeof auth === 'function' ? (options.types ?? null) : auth.types;\n\tcheckWiring('useJanus()', { auth, access, clock });\n\tconst applied = new WeakSet<GraphQLSchema>();\n\n\treturn {\n\t\tonContextBuilding: ({ context, extendContext }) => {\n\t\t\tconst { request } = context as { readonly request?: RequestLike };\n\t\t\tconst janus = createJanusContext(request ?? acceptedOf(context), {\n\t\t\t\tauth,\n\t\t\t\tcontext,\n\t\t\t\taccess: access as { readonly can: unknown } | undefined,\n\t\t\t\ttype,\n\t\t\t\tclock,\n\t\t\t\tapiKey,\n\t\t\t});\n\t\t\tif (typeof request === 'object' && request !== null) {\n\t\t\t\ttrack(request, janus);\n\t\t\t}\n\t\t\textendContext({ janus } as unknown as Partial<JanusContext<A, P, T, K>>);\n\t\t},\n\t\t// `replaceSchema` calls this hook again with the schema it was given:\n\t\t// the one it made is remembered, or it would transform it for ever.\n\t\tonSchemaChange: ({ schema, replaceSchema }) => {\n\t\t\tif (applied.has(schema)) return;\n\t\t\tconst next = applyJanusDirectives(schema, {\n\t\t\t\tauth: { types },\n\t\t\t\t...(type === undefined ? {} : { type }),\n\t\t\t\taccess: access as { readonly model: unknown } | undefined,\n\t\t\t\tloaders,\n\t\t\t\tconditions,\n\t\t\t});\n\t\t\tapplied.add(next);\n\t\t\treplaceSchema(next);\n\t\t},\n\t\t// Yoga's own hook, which envelop ignores: the HTTP response, once made.\n\t\tonResponse: (payload) =>\n\t\t\tresendRenewed(\n\t\t\t\tpayload,\n\t\t\t\ttypeof auth === 'function' ? undefined : auth.cookie,\n\t\t\t),\n\t};\n}\n",
60
+ "/**\n * The directives and the enum this package reads, as SDL: put it beside your\n * own type definitions. The same text ships as `graphql/janus.graphqls`, for\n * a code generator or an editor that reads files — `sdl.spec.ts` holds that\n * the two are identical.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusTypeDefs: string = `\"\"\"\nOnly a signed-in user reaches this field, or every field of this type or\ninterface. With \\`type\\`, only a user of one of these user types: any other is\nanswered FORBIDDEN.\n\"\"\"\ndirective @authenticated(\n\ttype: [String!]\n) on OBJECT | INTERFACE | FIELD_DEFINITION\n\n\"\"\"\nOnly a session that proved who it is less than \\`maxAge\\` seconds ago reaches\nthis field, or every field of this type or interface: signed in, or confirmed\nsince by a step-up. Anonymous is answered UNAUTHENTICATED, an older session\nSTEP_UP_REQUIRED. Where several apply, the smallest \\`maxAge\\` holds.\n\"\"\"\ndirective @fresh(maxAge: Int!) on OBJECT | INTERFACE | FIELD_DEFINITION\n\n\"\"\"\nWhat a denied \\`@permission\\` answers.\n\"\"\"\nenum JanusPermissionDenial {\n\t\"\"\"\n\t404: the object is not told to exist. The default.\n\t\"\"\"\n\tNOT_FOUND\n\t\"\"\"\n\t403: the object exists, and this user may not do this to it.\n\t\"\"\"\n\tFORBIDDEN\n}\n\n\"\"\"\nOnly a user holding permission \\`name\\` on the object of \\`type\\` whose id \\`id\\`\nreads reaches this field, or every field of this type or interface. \\`id\\` is\n\\`args.<path>\\` or \\`parent.<path>\\`: \\`args.id\\` on a field and \\`parent.id\\` on a\ntype or an interface when absent. A list of ids requires the permission on\nevery one. Repeated, every one must hold, in the order written.\n\"\"\"\ndirective @permission(\n\tname: String!\n\ttype: String!\n\tid: String\n\tonDeny: JanusPermissionDenial! = NOT_FOUND\n) repeatable on OBJECT | INTERFACE | FIELD_DEFINITION\n`;\n",
61
+ "/** What every field's resolver reads, resolved once by `secondFactorResolvers()`. */\n\nimport { type Duration, parseDuration } from '@softistx/janus';\nimport type { DeviceCookieOptions } from '../../device';\nimport { denial, rethrown } from '../../errors';\nimport { requireFresh } from '../../fresh';\nimport { requireUser } from '../../helpers';\nimport { apiOf, type SurfaceSpec } from '../../surface/api';\nimport { requestOf } from '../../surface/request';\nimport type {\n\tAnyUser,\n\tContext,\n\tCurrent,\n\tSecondFactorAction,\n\tSecondFactorAuth,\n\tSecondFactorAuthSource,\n\tSecondFactorResolversOptions,\n\tSecondFactorTypeApi,\n} from '../types';\n\nexport interface Deps {\n\treadonly auth: SecondFactorAuth;\n\treadonly api: SecondFactorTypeApi;\n\treadonly answerToken: boolean;\n\t/** The device cookie's attributes, or `undefined` when devices are not tracked. */\n\treadonly device: DeviceCookieOptions | undefined;\n\treadonly freshWithin: Exclude<Duration, number> | undefined;\n\treadonly freshMs: number | undefined;\n\treadonly options: SecondFactorResolversOptions<\n\t\tSecondFactorAuth,\n\t\tstring,\n\t\tnever\n\t>;\n\t/** The request's session; null for no credential and for an API key, which is no session. */\n\tsession(ctx: Context): Promise<Current | null>;\n\t/** `ctx.janus`'s user: for the reads of the viewer's own status. */\n\tuserOf(ctx: Context): Promise<AnyUser>;\n}\n\n/** What `depsOf()` answers: the bound instance serving this request. */\nexport type DepsSource = (ctx: Context) => Promise<Deps>;\n\n/**\n * The instance of each request, bound. A given instance is bound once, at\n * wiring (a missing surface is a `TypeError` then); a function is asked on\n * every field, and its answer bound once per instance (a missing surface is\n * a `TypeError` on that request).\n */\nexport function depsOf(\n\toptions: SecondFactorResolversOptions<SecondFactorAuth, string, never>,\n): DepsSource {\n\tconst type: string | undefined = options.type;\n\tconst only = type === undefined ? {} : { type };\n\tconst { freshWithin } = options;\n\tif (freshWithin !== undefined && typeof freshWithin !== 'string') {\n\t\tthrow new TypeError(\n\t\t\t\"secondFactorResolvers(): freshWithin is a duration with its unit, such as '10m'\",\n\t\t);\n\t}\n\tconst bind = (auth: SecondFactorAuth): Deps => ({\n\t\tauth,\n\t\tapi: apiOf<SecondFactorTypeApi>(auth, type, SURFACE),\n\t\tanswerToken: options.answerToken ?? false,\n\t\tdevice: options.device === true ? {} : options.device,\n\t\tfreshWithin,\n\t\tfreshMs:\n\t\t\tfreshWithin === undefined\n\t\t\t\t? undefined\n\t\t\t\t: parseDuration(freshWithin, 'secondFactorResolvers(): freshWithin'),\n\t\toptions,\n\t\tsession: (ctx) =>\n\t\t\tauth\n\t\t\t\t.authenticate(requestOf(ctx, 'secondFactorResolvers'), only)\n\t\t\t\t.then(undefined, rethrown),\n\t\t// `ctx.janus` is what `useJanus()` puts on every context.\n\t\tuserOf: (ctx) =>\n\t\t\trequireUser<AnyUser>(\n\t\t\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t\t\t\ttype === undefined ? {} : { type },\n\t\t\t),\n\t});\n\tconst source = options.auth as SecondFactorAuthSource<\n\t\tSecondFactorAuth,\n\t\tContext\n\t>;\n\tconst fixed = typeof source === 'function' ? undefined : bind(source);\n\tconst chosenBefore = new WeakMap<object, Deps>();\n\treturn async (ctx) => {\n\t\tif (fixed !== undefined) return fixed;\n\t\tconst chosen = await (source as (ctx: Context) => unknown)(ctx);\n\t\tif (chosen === null || chosen === undefined) {\n\t\t\tthrow denial('UNAUTHENTICATED');\n\t\t}\n\t\tconst instance = chosen as SecondFactorAuth;\n\t\tconst known = chosenBefore.get(instance);\n\t\tif (known !== undefined) return known;\n\t\tconst made = bind(instance);\n\t\tchosenBefore.set(instance, made);\n\t\treturn made;\n\t};\n}\n\nconst SURFACE: SurfaceSpec<SecondFactorTypeApi> = {\n\tname: 'secondFactorResolvers',\n\tkey: 'secondFactor',\n\tcomplete: (holder) => holder?.secondFactor !== undefined,\n\tmissing:\n\t\t'auth has no secondFactor surface — pass what janus() answered; with several user types, name the one with `type`',\n\tmissingOf: (type) =>\n\t\t`auth.${type} has no secondFactor — give janus() \\`secondFactor\\`, and name a user type that exists`,\n};\n\n/**\n * The request's session, or `UNAUTHENTICATED`: an API key is no session, so\n * under `useJanus({ apiKey: true })` it cannot change its owner's factor or\n * touch their step-ups.\n */\nexport async function sessionOrDeny(\n\tdeps: Deps,\n\tctx: Context,\n): Promise<Current> {\n\tconst current = await deps.session(ctx);\n\tif (current === null) throw denial('UNAUTHENTICATED');\n\treturn current;\n}\n\n/**\n * The user of a write, once the request's session is proved, fresh when\n * `freshWithin` is given, and let through by the `guard` hook.\n */\nexport async function writer(\n\tdeps: Deps,\n\taction: SecondFactorAction,\n\tctx: Context,\n): Promise<AnyUser> {\n\tconst { user } = await sessionOrDeny(deps, ctx);\n\tif (deps.freshWithin !== undefined) {\n\t\tawait requireFresh(\n\t\t\tctx as Parameters<typeof requireFresh>[0],\n\t\t\tdeps.freshWithin,\n\t\t);\n\t}\n\tawait deps.options.guard?.(action, user, ctx);\n\treturn user;\n}\n",
62
+ "/** `confirmSecondFactor` and `recoverSecondFactor`: redeem a sign-in's challenge. */\n\nimport type { SignedIn } from '@softistx/janus';\nimport { deviceOf } from '../../device';\nimport { rethrown } from '../../errors';\nimport { requestOf } from '../../surface/request';\nimport { signedInAnswer } from '../../surface/signed-in';\nimport type { AnyUser, SecondFactorResolvers, SignedInOut } from '../types';\nimport type { Deps, DepsSource } from './deps';\n\ntype Mutations = SecondFactorResolvers['Mutation'];\n\n/** The sign-in answered: cookies set, or the token answered; the shape of `SecondFactorSignedIn`. */\nfunction signedIn(\n\tdeps: Deps,\n\trequest: Request,\n\tdone: SignedIn<AnyUser>,\n\trecoveryCodesLeft: number | null,\n): SignedInOut {\n\treturn { ...signedInAnswer(deps, request, done), recoveryCodesLeft };\n}\n\n/** `confirmSecondFactor`: redeems a sign-in's challenge with the app's code. */\nexport function confirmSecondFactor(\n\tsource: DepsSource,\n): Mutations['confirmSecondFactor'] {\n\treturn async (_, { challenge, code }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst request = requestOf(ctx, 'secondFactorResolvers');\n\t\tconst done = await deps.api.secondFactor\n\t\t\t.confirm(\n\t\t\t\tchallenge,\n\t\t\t\tcode,\n\t\t\t\tdeps.device === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { device: deviceOf(request, deps.device) },\n\t\t\t)\n\t\t\t.then(undefined, rethrown);\n\t\treturn signedIn(deps, request, done, null);\n\t};\n}\n\n/** `recoverSecondFactor`: redeems it with a recovery code. */\nexport function recoverSecondFactor(\n\tsource: DepsSource,\n): Mutations['recoverSecondFactor'] {\n\treturn async (_, { challenge, recoveryCode }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst request = requestOf(ctx, 'secondFactorResolvers');\n\t\tconst done = await deps.api.secondFactor\n\t\t\t.recover(\n\t\t\t\tchallenge,\n\t\t\t\trecoveryCode,\n\t\t\t\tdeps.device === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { device: deviceOf(request, deps.device) },\n\t\t\t)\n\t\t\t.then(undefined, rethrown);\n\t\treturn signedIn(deps, request, done, done.recoveryCodesLeft);\n\t};\n}\n",
63
+ "/** `Query.secondFactor` and `Query.sessionConfirmedUntil`, also the fields of your `Viewer`. */\n\nimport { rethrown } from '../../errors';\nimport type { SecondFactorResolvers } from '../types';\nimport type { DepsSource } from './deps';\n\ntype Queries = SecondFactorResolvers['Query'];\n\n/** `secondFactor`: whether the factor is active, and the recovery codes left. */\nexport function status(source: DepsSource): Queries['secondFactor'] {\n\treturn async (_, __, ctx) => {\n\t\tconst { api, userOf } = await source(ctx);\n\t\tconst user = await userOf(ctx);\n\t\tif (user.hasSecondFactor !== true) {\n\t\t\treturn { enabled: false, recoveryCodesLeft: null };\n\t\t}\n\t\tconst left = await api.secondFactor\n\t\t\t.recoveryCodesLeft(user)\n\t\t\t.then(undefined, rethrown);\n\t\treturn { enabled: true, recoveryCodesLeft: left };\n\t};\n}\n\n/** `sessionConfirmedUntil`: the session's last proof plus `freshWithin`; null without either. */\nexport function sessionConfirmedUntil(\n\tsource: DepsSource,\n): Queries['sessionConfirmedUntil'] {\n\treturn async (_, __, ctx) => {\n\t\tconst { session, freshMs } = await source(ctx);\n\t\tif (freshMs === undefined) return null;\n\t\tconst current = await session(ctx);\n\t\tif (current === null) return null;\n\t\treturn new Date(\n\t\t\tcurrent.session.authenticatedAt.getTime() + freshMs,\n\t\t).toISOString();\n\t};\n}\n",
64
+ "/** `requestStepUp` and `confirmStepUp`, and the guard on a user type that has no step-up. */\n\nimport { rethrown } from '../../errors';\nimport { sendNoStore } from '../../renewal';\nimport { requestOf } from '../../surface/request';\nimport type { SecondFactorResolvers, SecondFactorTypeApi } from '../types';\nimport { type DepsSource, sessionOrDeny } from './deps';\n\ntype Mutations = SecondFactorResolvers['Mutation'];\n\n/** The step-up surface, or a `TypeError`: `stepUp` exists on a user type with an e-mail only. */\nexport function stepUpOf(\n\tapi: SecondFactorTypeApi,\n\tcaller: string,\n): NonNullable<SecondFactorTypeApi['stepUp']> {\n\tif (api.stepUp === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`secondFactorResolvers(): ${caller} needs a step-up — a user type with an e-mail has \\`stepUp\\``,\n\t\t);\n\t}\n\treturn api.stepUp;\n}\n\n/**\n * `requestStepUp`: the app's code for a user with a factor, else an e-mailed\n * one through `sendStepUpCode`. Only a session asks: an API key cannot cancel\n * its owner's step-ups.\n */\nexport function requestStepUp(source: DepsSource): Mutations['requestStepUp'] {\n\treturn async (_, __, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst { user } = await sessionOrDeny(deps, ctx);\n\t\tconst stepUp = stepUpOf(deps.api, 'requestStepUp');\n\t\tconst { sendStepUpCode } = deps.options;\n\t\t// Refused before issuing: an issue cancels the user's live step-up and counts a mail.\n\t\tif (user.hasSecondFactor !== true && sendStepUpCode === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'secondFactorResolvers(): a step-up by e-mail needs `sendStepUpCode` — give it, or require a second factor of every user',\n\t\t\t);\n\t\t}\n\t\tconst issued = await stepUp.request(user).then(undefined, rethrown);\n\t\tif (issued.via === 'email') await sendStepUpCode?.(issued, ctx);\n\t\t// The challenge is single-use: no cache keeps it.\n\t\tsendNoStore(requestOf(ctx, 'secondFactorResolvers'));\n\t\treturn {\n\t\t\tvia: issued.via,\n\t\t\tchallenge: issued.challenge,\n\t\t\texpiresAt: issued.expiresAt.toISOString(),\n\t\t};\n\t};\n}\n\n/** `confirmStepUp`: the code; the request's session is stamped, and answered with its end. */\nexport function confirmStepUp(source: DepsSource): Mutations['confirmStepUp'] {\n\treturn async (_, { challenge, code }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tawait sessionOrDeny(deps, ctx);\n\t\tconst session = await stepUpOf(deps.api, 'confirmStepUp')\n\t\t\t.confirm(requestOf(ctx, 'secondFactorResolvers'), challenge, code)\n\t\t\t.then(undefined, rethrown);\n\t\tconst at = session.authenticatedAt;\n\t\treturn {\n\t\t\tconfirmedAt: at.toISOString(),\n\t\t\tconfirmedUntil:\n\t\t\t\tdeps.freshMs === undefined\n\t\t\t\t\t? null\n\t\t\t\t\t: new Date(at.getTime() + deps.freshMs).toISOString(),\n\t\t};\n\t};\n}\n",
65
+ "/** The four writes of the factor: enroll, activate, regenerate the recovery codes, disable. */\n\nimport { SecondFactorError } from '@softistx/janus';\nimport { janusGraphQLError, rethrown } from '../../errors';\nimport { sendNoStore } from '../../renewal';\nimport { requestOf } from '../../surface/request';\nimport type { SecondFactorResolvers } from '../types';\nimport { type DepsSource, writer } from './deps';\nimport { stepUpOf } from './step-up';\n\ntype Mutations = SecondFactorResolvers['Mutation'];\n\n/** `enrollSecondFactor`: the secret and the URI to show as a QR code; never cached. */\nexport function enrollSecondFactor(\n\tsource: DepsSource,\n): Mutations['enrollSecondFactor'] {\n\treturn async (_, __, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst user = await writer(deps, 'enroll', ctx);\n\t\tsendNoStore(requestOf(ctx, 'secondFactorResolvers'));\n\t\tconst { secret, uri } = await deps.api.secondFactor\n\t\t\t.enroll(user)\n\t\t\t.then(undefined, rethrown);\n\t\treturn { secret, uri };\n\t};\n}\n\n/** `activateSecondFactor`: the first code; answers the ten recovery codes, never cached. */\nexport function activateSecondFactor(\n\tsource: DepsSource,\n): Mutations['activateSecondFactor'] {\n\treturn async (_, { code }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst user = await writer(deps, 'activate', ctx);\n\t\tsendNoStore(requestOf(ctx, 'secondFactorResolvers'));\n\t\tconst { recoveryCodes } = await deps.api.secondFactor\n\t\t\t.activate(user, code)\n\t\t\t.then(undefined, rethrown);\n\t\treturn { recoveryCodes: [...recoveryCodes] };\n\t};\n}\n\n/** `regenerateRecoveryCodes`: ten new codes on a current code of the app, never cached. */\nexport function regenerateRecoveryCodes(\n\tsource: DepsSource,\n): Mutations['regenerateRecoveryCodes'] {\n\treturn async (_, { code }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst user = await writer(deps, 'regenerateRecoveryCodes', ctx);\n\t\tsendNoStore(requestOf(ctx, 'secondFactorResolvers'));\n\t\tconst { recoveryCodes } = await deps.api.secondFactor\n\t\t\t.regenerateRecoveryCodes(user, code)\n\t\t\t.then(undefined, rethrown);\n\t\treturn { recoveryCodes: [...recoveryCodes] };\n\t};\n}\n\nconst notEnrolled = () =>\n\tjanusGraphQLError(\n\t\tnew SecondFactorError(\n\t\t\t'SECOND_FACTOR_NOT_ENROLLED',\n\t\t\t'disableSecondFactor: the user has no active second factor',\n\t\t),\n\t);\n\n/**\n * `disableSecondFactor`: a current code of the app, checked by a step-up of\n * the request's session (five attempts per challenge, counted with the\n * recovery-code tries), then the factor is removed. A user with no active\n * factor is refused before any step-up is issued.\n */\nexport function disableSecondFactor(\n\tsource: DepsSource,\n): Mutations['disableSecondFactor'] {\n\treturn async (_, { code }, ctx) => {\n\t\tconst deps = await source(ctx);\n\t\tconst user = await writer(deps, 'disable', ctx);\n\t\tif (user.hasSecondFactor !== true) throw notEnrolled();\n\t\tconst stepUp = stepUpOf(deps.api, 'disableSecondFactor');\n\t\tconst issued = await stepUp.request(user).then(undefined, rethrown);\n\t\tif (issued.via !== 'secondFactor') throw notEnrolled();\n\t\tawait stepUp\n\t\t\t.confirm(requestOf(ctx, 'secondFactorResolvers'), issued.challenge, code)\n\t\t\t.then(undefined, rethrown);\n\t\tawait deps.api.secondFactor.disable(user).then(undefined, rethrown);\n\t\treturn true;\n\t};\n}\n",
66
+ "/**\n * The resolvers of the second-factor SDL: two `Query` fields and eight\n * `Mutation` fields. A completed sign-in sets the session cookie and the\n * device cookie through `useJanus()`'s `onResponse`, as a renewed session is.\n */\n\nimport type {\n\tContext,\n\tSecondFactorAuth,\n\tSecondFactorResolvers,\n\tSecondFactorResolversOptions,\n\tSecondFactorViewerFields,\n} from '../types';\nimport { depsOf } from './deps';\nimport { confirmSecondFactor, recoverSecondFactor } from './sign-in';\nimport { sessionConfirmedUntil, status } from './status';\nimport { confirmStepUp, requestStepUp } from './step-up';\nimport {\n\tactivateSecondFactor,\n\tdisableSecondFactor,\n\tenrollSecondFactor,\n\tregenerateRecoveryCodes,\n} from './writes';\n\n/**\n * The resolvers of the second-factor SDL. A refusal of the core —\n * `CODE_INVALID`, `TOKEN_UNKNOWN`, `SECOND_FACTOR_ACTIVE`,\n * `SECOND_FACTOR_NOT_ENROLLED`, `STEP_UP_REQUIRED`… — is rethrown as its\n * `GraphQLError`, so `janusMaskError()` answers its code and status. Needs\n * `useJanus()` for the directives and to set the cookies of a completed\n * sign-in. Throws a `TypeError` at wiring when `auth` (or `auth[type]`)\n * carries no `secondFactor` surface (with `auth` a function: on the request\n * that gets such an instance), or `freshWithin` is not a duration\n * string.\n *\n * The writes and `requestStepUp` need a session: an API key (under\n * `useJanus({ apiKey: true })`) is `UNAUTHENTICATED` there.\n *\n * ```ts\n * const resolvers = mergeResolvers([secondFactorResolvers({ auth, freshWithin: '10m' }), mine]);\n * ```\n *\n * `Query` and `Mutation` are keys of the map: merge it with yours rather than\n * spreading over them.\n */\nexport function secondFactorResolvers<\n\tA extends SecondFactorAuth,\n\tconst T extends string = never,\n\tCtx = Context,\n>(options: SecondFactorResolversOptions<A, T, Ctx>): SecondFactorResolvers {\n\tconst source = depsOf(options);\n\treturn {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tQuery: {\n\t\t\tsecondFactor: status(source),\n\t\t\tsessionConfirmedUntil: sessionConfirmedUntil(source),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tMutation: {\n\t\t\tconfirmSecondFactor: confirmSecondFactor(source),\n\t\t\trecoverSecondFactor: recoverSecondFactor(source),\n\t\t\tenrollSecondFactor: enrollSecondFactor(source),\n\t\t\tactivateSecondFactor: activateSecondFactor(source),\n\t\t\tregenerateRecoveryCodes: regenerateRecoveryCodes(source),\n\t\t\tdisableSecondFactor: disableSecondFactor(source),\n\t\t\trequestStepUp: requestStepUp(source),\n\t\t\tconfirmStepUp: confirmStepUp(source),\n\t\t},\n\t};\n}\n\n/**\n * The two fields for your own `Viewer` type — `secondFactor { enabled\n * recoveryCodesLeft }` and `sessionConfirmedUntil` — read from the request's\n * session, with the same options as `secondFactorResolvers`.\n *\n * ```ts\n * resolvers: { Viewer: secondFactorViewerFields({ auth, freshWithin: '10m' }) }\n * ```\n */\nexport function secondFactorViewerFields<\n\tA extends SecondFactorAuth,\n\tconst T extends string = never,\n\tCtx = Context,\n>(options: SecondFactorResolversOptions<A, T, Ctx>): SecondFactorViewerFields {\n\tconst source = depsOf(options);\n\treturn {\n\t\tsecondFactor: status(source),\n\t\tsessionConfirmedUntil: sessionConfirmedUntil(source),\n\t};\n}\n",
67
+ "/**\n * The opt-in TOTP second-factor SDL: put it beside your own type definitions\n * when users may hold an authenticator app (`janus({ secondFactor })`). It\n * `extend`s your `Query` and `Mutation`, and needs `janusTypeDefs` for\n * `@authenticated`. The same text ships as\n * `graphql/janus-second-factor.graphqls` — `sdl.spec.ts` holds that the two\n * are identical. Timestamps are ISO-8601 `String`s: no scalar to collide with.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, janusSecondFactorTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusSecondFactorTypeDefs: string = `\"\"\"\nWhether the signed-in user's TOTP second factor is active.\n\"\"\"\ntype JanusSecondFactorStatus {\n\t\"\"\"\n\tTrue once the factor is active: a sign-in then asks for a code. A factor\n\tthat was started and never activated is not enabled.\n\t\"\"\"\n\tenabled: Boolean!\n\t\"\"\"\n\tThe recovery codes not yet used. Null without an active factor, 0 when\n\tall are spent (regenerate them).\n\t\"\"\"\n\trecoveryCodesLeft: Int\n}\n\n\"\"\"\nA factor started, not yet active: load \\`secret\\` or \\`uri\\` into the\nauthenticator app, then give its first code to \\`activateSecondFactor\\`.\nNever cached, never logged.\n\"\"\"\ntype JanusSecondFactorEnrolment {\n\t\"\"\"\n\tThe TOTP secret in base32, for a user who types it in.\n\t\"\"\"\n\tsecret: String!\n\t\"\"\"\n\tThe \\`otpauth://\\` URI to render as a QR code.\n\t\"\"\"\n\turi: String!\n}\n\n\"\"\"\nTen recovery codes, from \\`activateSecondFactor\\` or\n\\`regenerateRecoveryCodes\\`. Shown once: no call answers them again.\n\"\"\"\ntype JanusRecoveryCodes {\n\trecoveryCodes: [String!]!\n}\n\n\"\"\"\nA sign-in that needs a second factor: no session is open yet. Build it in\nyour own sign-in resolver from the core's \\`secondFactor\\` answer with\n\\`secondFactorChallengeOut\\`, then answer it with \\`confirmSecondFactor\\` or\n\\`recoverSecondFactor\\`. The challenge is a secret like a session token: never\nin a URL or a log.\n\"\"\"\ntype JanusSecondFactorChallenge {\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhat can answer it: \\`totp\\` always, and \\`passkey\\` when the user holds one.\n\t\"\"\"\n\tmethods: [String!]!\n\t\"\"\"\n\tThe JSON text for \\`navigator.credentials.get({ publicKey })\\`, present\n\texactly when \\`methods\\` holds \\`passkey\\`.\n\t\"\"\"\n\tpasskeyOptions: String\n}\n\n\"\"\"\nA second-factor sign-in completed: the session cookie is set on the response,\nor, with \\`secondFactorResolvers({ answerToken: true })\\`, the session token is\nanswered in \\`token\\` and no cookie is set. Extend this type with a \\`user\\`\nfield of your own: its parent carries the signed-in user.\n\"\"\"\ntype SecondFactorSignedIn {\n\t\"\"\"\n\tThe session token, answered only with \\`answerToken: true\\`; null\n\totherwise. A secret like a session cookie: never in a URL or a log.\n\t\"\"\"\n\ttoken: String\n\t\"\"\"\n\tThe signed-in user's id.\n\t\"\"\"\n\tuserId: ID!\n\t\"\"\"\n\tWhen the session expires, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhether the session was opened from a device the user had not used.\n\t\"\"\"\n\tnewDevice: Boolean!\n\t\"\"\"\n\tThe recovery codes left after \\`recoverSecondFactor\\` spent one; null after\n\t\\`confirmSecondFactor\\`.\n\t\"\"\"\n\trecoveryCodesLeft: Int\n}\n\n\"\"\"\nA step-up under way: keep \\`challenge\\` (never in a URL) and give it to\n\\`confirmStepUp\\` with the code.\n\"\"\"\ntype JanusStepUpChallenge {\n\t\"\"\"\n\tHow the code is delivered: \\`email\\` (a code sent to the user's address by\n\tyour \\`sendStepUpCode\\`) or \\`secondFactor\\` (the code of the user's\n\tauthenticator app; nothing is sent).\n\t\"\"\"\n\tvia: String!\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n}\n\n\"\"\"\nA step-up confirmed: the request's session proved who it is just now.\n\"\"\"\ntype JanusStepUpConfirmed {\n\t\"\"\"\n\tWhen the session last proved who it is, as an ISO-8601 string.\n\t\"\"\"\n\tconfirmedAt: String!\n\t\"\"\"\n\tUntil when it counts as fresh (\\`confirmedAt\\` plus \\`freshWithin\\`), as an\n\tISO-8601 string. Null when \\`secondFactorResolvers\\` was given no\n\t\\`freshWithin\\`.\n\t\"\"\"\n\tconfirmedUntil: String\n}\n\nextend type Query {\n\t\"\"\"\n\tThe signed-in user's second factor: whether it is active, and the\n\trecovery codes left. Put the same resolver on your \\`Viewer.secondFactor\\`\n\twith \\`secondFactorViewerFields\\`.\n\t\"\"\"\n\tsecondFactor: JanusSecondFactorStatus! @authenticated\n\t\"\"\"\n\tUntil when the request's session counts as freshly confirmed: its\n\tsign-in or last step-up plus \\`freshWithin\\`. In the past once it no longer\n\tdoes; null without \\`freshWithin\\` or without a session.\n\t\"\"\"\n\tsessionConfirmedUntil: String\n}\n\nextend type Mutation {\n\t\"\"\"\n\tRedeems a sign-in's challenge with the code of the authenticator app.\n\tFive attempts per challenge (CODE_INVALID with attemptsLeft). Sets the\n\tsession cookie, or answers \\`token\\` with \\`answerToken\\`, and the device\n\tcookie.\n\t\"\"\"\n\tconfirmSecondFactor(challenge: String!, code: String!): SecondFactorSignedIn!\n\t\"\"\"\n\tRedeems a sign-in's challenge with a recovery code instead, for a lost\n\tphone. The code is spent and \\`recoveryCodesLeft\\` answers what remains.\n\tRefused as \\`confirmSecondFactor\\`.\n\t\"\"\"\n\trecoverSecondFactor(\n\t\tchallenge: String!\n\t\trecoveryCode: String!\n\t): SecondFactorSignedIn!\n\t\"\"\"\n\tStarts a factor and answers the secret and the URI to show as a QR code.\n\tSECOND_FACTOR_ACTIVE when one is active. With \\`freshWithin\\`, needs a\n\tfresh session (STEP_UP_REQUIRED).\n\t\"\"\"\n\tenrollSecondFactor: JanusSecondFactorEnrolment! @authenticated\n\t\"\"\"\n\tChecks the app's first code and makes the factor active; answers the ten\n\trecovery codes, once. CODE_INVALID, SECOND_FACTOR_NOT_ENROLLED. With\n\t\\`freshWithin\\`, needs a fresh session.\n\t\"\"\"\n\tactivateSecondFactor(code: String!): JanusRecoveryCodes! @authenticated\n\t\"\"\"\n\tReplaces all the recovery codes with ten new ones, on a current code of\n\tthe app. Counted five per user per 15 minutes (CODE_INVALID with\n\tattemptsLeft, or reason \\`throttled\\` and \\`retryAfter\\`). With\n\t\\`freshWithin\\`, needs a fresh session.\n\t\"\"\"\n\tregenerateRecoveryCodes(code: String!): JanusRecoveryCodes! @authenticated\n\t\"\"\"\n\tTurns the factor off, on a current code of the app, checked by a step-up\n\tof the request's session. SECOND_FACTOR_NOT_ENROLLED without an active\n\tfactor. With \\`freshWithin\\`, needs a fresh session.\n\t\"\"\"\n\tdisableSecondFactor(code: String!): Boolean! @authenticated\n\t\"\"\"\n\tStarts a step-up for the request's session: the app's code when the user\n\thas an active second factor, else a code sent by \\`sendStepUpCode\\`.\n\t\"\"\"\n\trequestStepUp: JanusStepUpChallenge! @authenticated\n\t\"\"\"\n\tConfirms the step-up with its challenge and code: the request's session\n\tproved who it is just now. CODE_INVALID with attemptsLeft, TOKEN_UNKNOWN,\n\tTOKEN_SPENT, TOKEN_EXPIRED.\n\t\"\"\"\n\tconfirmStepUp(challenge: String!, code: String!): JanusStepUpConfirmed!\n\t\t@authenticated\n}\n`;\n",
68
+ "/**\n * The answers of the social resolvers: a core result as the plain object the\n * schema's fields read, timestamps as ISO-8601 strings.\n */\n\nimport type { SocialFlowStart, SocialLink } from '@softistx/janus';\nimport { GraphQLError } from 'graphql';\nimport type { FlowOut, LinkOut } from './types';\n\nexport const linkOut = (link: SocialLink): LinkOut => ({\n\tprovider: link.provider,\n\taccountId: link.accountId,\n\temail: link.email,\n\tlinkedAt: link.linkedAt.toISOString(),\n});\n\nexport const flowOut = (start: SocialFlowStart): FlowOut => ({\n\turl: start.url,\n\tflow: start.flow,\n\texpiresAt: start.expiresAt.toISOString(),\n});\n\n/** The query of the provider's callback URL, absolute or relative; nothing of it is echoed back. */\nexport function callbackOf(callbackUrl: string): URLSearchParams {\n\ttry {\n\t\treturn new URL(callbackUrl, 'http://callback.invalid').searchParams;\n\t} catch {\n\t\tthrow new GraphQLError('callbackUrl must be a URL', {\n\t\t\textensions: { code: 'BAD_USER_INPUT', http: { status: 400 } },\n\t\t});\n\t}\n}\n",
69
+ "/**\n * The resolvers of the social SDL: `Query.socialLinks`, the four\n * `Mutation` fields and the result union's `__resolveType`. The flow is the\n * caller's to keep (the BFF's own cookie): nothing here sets a flow cookie.\n * A completed sign-in sets the session cookie through `useJanus()`'s\n * `onResponse`, as a renewed one is.\n */\n\nimport { denial, rethrown } from '../errors';\nimport { requireUser } from '../helpers';\nimport { noStoreOf, sendNoStore } from '../renewal';\nimport { requestOf } from '../surface/request';\nimport { signedInAnswer } from '../surface/signed-in';\nimport { callbackOf, flowOut, linkOut } from './shape';\nimport type {\n\tAnyUser,\n\tCompletedOut,\n\tContext,\n\tSocialAuth,\n\tSocialResolvers,\n\tSocialResolversOptions,\n} from './types';\n\n/**\n * The resolvers of the social SDL. A refusal of the core — `FLOW_EXPIRED`,\n * `PROVIDER_ERROR` (502), `SOCIAL_ACCOUNT_TAKEN`… — is rethrown as its\n * `GraphQLError`, so `janusMaskError()` answers its code and status; a\n * refusal after the flow was authenticated also carries `returnTo` and\n * `flowSpent` in its `extensions`. Needs `useJanus()` for the directives and\n * to set the session cookie of a completed sign-in.\n *\n * ```ts\n * const resolvers = mergeResolvers([socialResolvers({ auth }), mine]);\n * ```\n *\n * `Query` and `Mutation` are keys of the map: merge it with yours rather than\n * spreading over them.\n */\nexport function socialResolvers(\n\toptions: SocialResolversOptions,\n): SocialResolvers {\n\tconst { type, answerToken = false } = options;\n\tconst source = options.auth;\n\tconst only = type === undefined ? {} : { type };\n\tconst bind = (auth: SocialAuth): Bound => ({\n\t\tauth,\n\t\tsession: (ctx) =>\n\t\t\tauth\n\t\t\t\t.authenticate(requestOf(ctx, 'socialResolvers'), only)\n\t\t\t\t.then(undefined, rethrown),\n\t\t// `ctx.janus` is what `useJanus()` puts on every context.\n\t\tuserOf: (ctx) =>\n\t\t\trequireUser<AnyUser>(\n\t\t\t\tctx as { readonly janus: { user(): Promise<AnyUser | null> } },\n\t\t\t\ttype === undefined ? {} : { type },\n\t\t\t),\n\t});\n\t// An instance is bound once, at wiring; a function is asked on every field.\n\tconst fixed = typeof source === 'function' ? undefined : bind(source);\n\tconst chosenBefore = new WeakMap<object, Bound>();\n\tconst deps: Deps = {\n\t\tanswerToken,\n\t\tonly,\n\t\tbound: async (ctx = {}) => {\n\t\t\tif (fixed !== undefined) return fixed;\n\t\t\tconst chosen = await (source as (ctx: Context) => unknown)(ctx);\n\t\t\t// No instance for this request, or one that serves no social sign-in.\n\t\t\tif (\n\t\t\t\tchosen === null ||\n\t\t\t\tchosen === undefined ||\n\t\t\t\t(chosen as Partial<SocialAuth>).social === undefined\n\t\t\t) {\n\t\t\t\tthrow denial('UNAUTHENTICATED');\n\t\t\t}\n\t\t\tconst instance = chosen as SocialAuth;\n\t\t\tconst known = chosenBefore.get(instance);\n\t\t\tif (known !== undefined) return known;\n\t\t\tconst made = bind(instance);\n\t\t\tchosenBefore.set(instance, made);\n\t\t\treturn made;\n\t\t},\n\t};\n\treturn {\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tQuery: { socialLinks: socialLinks(deps) },\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tMutation: {\n\t\t\tsocialSignInStart: socialSignInStart(deps),\n\t\t\tsocialSignInComplete: socialSignInComplete(deps),\n\t\t\tlinkSocial: linkSocial(deps),\n\t\t\tunlinkSocial: unlinkSocial(deps),\n\t\t},\n\t\t// biome-ignore lint/style/useNamingConvention: a resolver map's keys are the schema's type names.\n\t\tSocialSignInResult: {\n\t\t\t__resolveType: (result) =>\n\t\t\t\tresult.status === 'signedIn'\n\t\t\t\t\t? 'SocialSignedIn'\n\t\t\t\t\t: result.status === 'secondFactor'\n\t\t\t\t\t\t? 'SocialSecondFactor'\n\t\t\t\t\t\t: 'SocialLinked',\n\t\t},\n\t};\n}\n\n/** What `socialResolvers()` resolves from one instance: the calls every field makes. */\ninterface Bound {\n\treadonly auth: SocialAuth;\n\tsession(ctx: Context): ReturnType<SocialAuth['authenticate']>;\n\tuserOf(ctx: Context): Promise<AnyUser>;\n}\n\n/** What every field's resolver reads. */\ninterface Deps {\n\t/** Answer the session token instead of setting the cookie. */\n\treadonly answerToken: boolean;\n\t/** `{ type }` when the application named one, else nothing. */\n\treadonly only: { readonly type?: string };\n\t/** The instance serving this request, bound; refuses with `UNAUTHENTICATED` when there is none. */\n\tbound(ctx?: Context): Promise<Bound>;\n}\n\ntype Mutations = SocialResolvers['Mutation'];\n\n/** `Query.socialLinks`: the signed-in user's links. */\nfunction socialLinks({ bound }: Deps): SocialResolvers['Query']['socialLinks'] {\n\treturn async (_, __, ctx) => {\n\t\tconst { auth, userOf } = await bound(ctx);\n\t\tconst user = await userOf(ctx);\n\t\tconst links = await auth.social.list(user).then(undefined, rethrown);\n\t\treturn links.map(linkOut);\n\t};\n}\n\n/** `Mutation.socialSignInStart`: where to send the visitor, and the flow to keep. */\nfunction socialSignInStart({\n\tbound,\n\tonly,\n}: Deps): Mutations['socialSignInStart'] {\n\treturn async (_, { provider, returnTo }, ctx) => {\n\t\tconst { auth } = await bound(ctx);\n\t\tconst start = await auth.social\n\t\t\t.start({\n\t\t\t\tprovider,\n\t\t\t\t...(returnTo == null ? {} : { returnTo }),\n\t\t\t\t...only,\n\t\t\t})\n\t\t\t.then(undefined, rethrown);\n\t\t// `flow` is a single-use secret: no cache keeps it.\n\t\tnoStoreOf(ctx);\n\t\treturn flowOut(start);\n\t};\n}\n\n/** `Mutation.socialSignInComplete`: completes the flow; a sign-in sets the session cookie, or answers its token with `answerToken`. */\nfunction socialSignInComplete({\n\tbound,\n\tanswerToken,\n}: Deps): Mutations['socialSignInComplete'] {\n\treturn async (_, { callbackUrl, flow }, ctx) => {\n\t\tconst { auth, session } = await bound(ctx);\n\t\tconst request = requestOf(ctx, 'socialResolvers');\n\t\tconst callback = callbackOf(callbackUrl);\n\t\tconst current = await session(ctx);\n\t\tconst done = await auth.social\n\t\t\t.complete({ callback, flow, current })\n\t\t\t.then(undefined, rethrown);\n\t\treturn completedOut(done, { auth, answerToken }, request);\n\t};\n}\n\n/** `Mutation.linkSocial`: starts linking an account to the signed-in user. */\nfunction linkSocial({ bound }: Deps): Mutations['linkSocial'] {\n\treturn async (_, { provider, returnTo }, ctx) => {\n\t\tconst { auth, session } = await bound(ctx);\n\t\tconst request = requestOf(ctx, 'socialResolvers');\n\t\tconst current = await session(ctx);\n\t\tif (current === null) throw denial('UNAUTHENTICATED');\n\t\tconst start = await auth.social\n\t\t\t.link(current, {\n\t\t\t\tprovider,\n\t\t\t\t...(returnTo == null ? {} : { returnTo }),\n\t\t\t})\n\t\t\t.then(undefined, rethrown);\n\t\tsendNoStore(request);\n\t\treturn flowOut(start);\n\t};\n}\n\n/** `Mutation.unlinkSocial`: removes one of the signed-in user's links. */\nfunction unlinkSocial({ bound }: Deps): Mutations['unlinkSocial'] {\n\treturn async (_, { provider, accountId }, ctx) => {\n\t\tconst { auth, userOf } = await bound(ctx);\n\t\tconst user = await userOf(ctx);\n\t\treturn auth.social\n\t\t\t.unlink(user, { provider, accountId })\n\t\t\t.then(undefined, rethrown);\n\t};\n}\n\n/** What the core's answer becomes in the schema's union. */\nfunction completedOut(\n\tdone: Awaited<ReturnType<SocialAuth['social']['complete']>>,\n\t{ auth, answerToken }: { auth: SocialAuth; answerToken: boolean },\n\trequest: Request,\n): CompletedOut {\n\tif (done.status === 'signedIn') {\n\t\treturn {\n\t\t\tstatus: 'signedIn',\n\t\t\t// No device cookie: social tracks no device.\n\t\t\t...signedInAnswer(\n\t\t\t\t{ auth, answerToken, device: undefined },\n\t\t\t\trequest,\n\t\t\t\tdone,\n\t\t\t),\n\t\t\tcreated: done.created,\n\t\t\tlinked: done.linked,\n\t\t\treturnTo: done.returnTo,\n\t\t};\n\t}\n\tif (done.status === 'secondFactor') {\n\t\t// The challenge is single-use: no cache keeps it.\n\t\tsendNoStore(request);\n\t\treturn {\n\t\t\tstatus: 'secondFactor',\n\t\t\tchallenge: done.challenge,\n\t\t\texpiresAt: done.expiresAt.toISOString(),\n\t\t\tmethods: done.methods,\n\t\t\tpasskeyOptions:\n\t\t\t\tdone.passkeyOptions === undefined\n\t\t\t\t\t? null\n\t\t\t\t\t: JSON.stringify(done.passkeyOptions),\n\t\t\treturnTo: done.returnTo,\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'linked',\n\t\tlink: linkOut(done.link),\n\t\treturnTo: done.returnTo,\n\t};\n}\n",
70
+ "/**\n * The opt-in social sign-in SDL: put it beside your own type definitions when\n * users sign in with an external provider. It `extend`s your `Query` and\n * `Mutation`, and needs `janusTypeDefs` for its directives. The same text\n * ships as `graphql/janus-social.graphqls` — `sdl.spec.ts` holds that the two\n * are identical. Timestamps are ISO-8601 `String`s: no scalar to collide with.\n *\n * ```ts\n * createSchema({ typeDefs: [janusTypeDefs, janusSocialTypeDefs, typeDefs], resolvers });\n * ```\n */\nexport const janusSocialTypeDefs: string = `\"\"\"\nOne social account linked to a user: the provider's name in the\napplication, and the provider's own identifier of the account.\n\"\"\"\ntype JanusSocialLink {\n\t\"\"\"\n\tThe application's name for the provider (\\`google\\`).\n\t\"\"\"\n\tprovider: String!\n\t\"\"\"\n\tThe provider's identifier of the account. Pass it back to \\`unlinkSocial\\`;\n\tkeep it out of logs and analytics.\n\t\"\"\"\n\taccountId: ID!\n\t\"\"\"\n\tThe e-mail the provider reported when the account was linked, if any.\n\t\"\"\"\n\temail: String\n\t\"\"\"\n\tWhen the account was linked, as an ISO-8601 string.\n\t\"\"\"\n\tlinkedAt: String!\n}\n\n\"\"\"\nA social flow begun: send the visitor to \\`url\\`, and keep \\`flow\\` until the\ncallback.\n\"\"\"\ntype SocialFlowStart {\n\t\"\"\"\n\tThe provider's authorization URL.\n\t\"\"\"\n\turl: String!\n\t\"\"\"\n\tA secret like a session token: the BFF keeps it in its own HttpOnly\n\tSameSite=Lax cookie and hands it back to \\`socialSignInComplete\\`. Never in\n\ta URL or a log.\n\t\"\"\"\n\tflow: String!\n\t\"\"\"\n\tWhen the flow lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n}\n\n\"\"\"\nA social sign-in completed: the session cookie is set on the response, or,\nwith \\`socialResolvers({ answerToken: true })\\`, the session token is answered\nin \\`token\\` and no cookie is set. Extend this type with a \\`user\\` field of\nyour own: its parent carries the signed-in user.\n\"\"\"\ntype SocialSignedIn {\n\t\"\"\"\n\tThe session token, answered only when \\`socialResolvers\\` has \\`answerToken:\n\ttrue\\` (the session cookie is then not set); null otherwise. A secret like\n\ta session cookie: the BFF keeps it in its own HttpOnly cookie and sends\n\tit back as \\`Authorization: Bearer\\`. Never in a URL or a log.\n\t\"\"\"\n\ttoken: String\n\t\"\"\"\n\tThe signed-in user's id.\n\t\"\"\"\n\tuserId: ID!\n\t\"\"\"\n\tWhen the session expires, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhether a user was made for this account.\n\t\"\"\"\n\tcreated: Boolean!\n\t\"\"\"\n\tWhether this call linked the account to an existing user.\n\t\"\"\"\n\tlinked: Boolean!\n\t\"\"\"\n\tWhether the session was opened from a device the user had not used.\n\t\"\"\"\n\tnewDevice: Boolean!\n\t\"\"\"\n\tThe path the flow was started with, or null.\n\t\"\"\"\n\treturnTo: String\n}\n\n\"\"\"\nThe user has an active second factor: confirm it with the challenge. No\nsession is open yet.\n\"\"\"\ntype SocialSecondFactor {\n\tchallenge: String!\n\t\"\"\"\n\tWhen the challenge lapses, as an ISO-8601 string.\n\t\"\"\"\n\texpiresAt: String!\n\t\"\"\"\n\tWhat can answer the challenge: \\`totp\\` always, and \\`passkey\\` when the\n\tuser holds one. Show only these.\n\t\"\"\"\n\tmethods: [String!]!\n\t\"\"\"\n\tThe JSON text for \\`navigator.credentials.get({ publicKey })\\`, present\n\texactly when \\`methods\\` holds \\`passkey\\`. Answer it with\n\t\\`confirmSecondFactorPasskey\\` (\\`janusPasskeyTypeDefs\\`). A \\`totp\\` code\n\tgoes to \\`confirmSecondFactor\\` (\\`janusSecondFactorTypeDefs\\`).\n\t\"\"\"\n\tpasskeyOptions: String\n\treturnTo: String\n}\n\n\"\"\"\nA link flow completed: the signed-in user now has the account. Not a\nsign-in, so no session is set.\n\"\"\"\ntype SocialLinked {\n\tlink: JanusSocialLink!\n\treturnTo: String\n}\n\nunion SocialSignInResult = SocialSignedIn | SocialSecondFactor | SocialLinked\n\nextend type Query {\n\t\"\"\"\n\tThe signed-in user's linked social accounts, oldest first.\n\t\"\"\"\n\tsocialLinks: [JanusSocialLink!]! @authenticated\n}\n\nextend type Mutation {\n\t\"\"\"\n\tBegins a sign-in with \\`provider\\`. \\`returnTo\\` is a path of this site.\n\tAnswers the URL to send the visitor to and the flow to keep until the\n\tcallback.\n\t\"\"\"\n\tsocialSignInStart(provider: String!, returnTo: String): SocialFlowStart!\n\t\"\"\"\n\tCompletes the flow with the provider's callback URL and the \\`flow\\` that\n\t\\`socialSignInStart\\` or \\`linkSocial\\` answered. A sign-in sets the session\n\tcookie, or answers \\`token\\` with \\`answerToken\\`.\n\t\"\"\"\n\tsocialSignInComplete(callbackUrl: String!, flow: String!): SocialSignInResult!\n\t\"\"\"\n\tBegins linking an account to the signed-in user, behind a fresh proof.\n\t\"\"\"\n\tlinkSocial(provider: String!, returnTo: String): SocialFlowStart!\n\t\t@authenticated\n\t\t@fresh(maxAge: 600)\n\t\"\"\"\n\tRemoves one of the user's links. True when this call removed it.\n\tLAST_SIGN_IN_METHOD when it is the user's only way to sign in.\n\t\"\"\"\n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