@nxgt/janus-graphql 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -10
- package/dist/context.d.ts +7 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/directives/apply.d.ts +10 -9
- package/dist/directives/apply.d.ts.map +1 -1
- package/dist/directives/guard.d.ts +2 -1
- package/dist/directives/guard.d.ts.map +1 -1
- package/dist/directives/read.d.ts +9 -1
- package/dist/directives/read.d.ts.map +1 -1
- package/dist/directives/validate.d.ts +7 -2
- package/dist/directives/validate.d.ts.map +1 -1
- package/dist/fresh.d.ts +37 -0
- package/dist/fresh.d.ts.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -12
- package/dist/index.js.map +11 -10
- package/dist/plugin.d.ts +4 -3
- package/dist/plugin.d.ts.map +1 -1
- package/dist/sdl.d.ts.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +4 -3
- package/docs/guide/context.md +32 -2
- package/docs/guide/directives.md +64 -5
- package/docs/guide/errors.md +2 -1
- package/docs/guide/federation.md +2 -1
- package/docs/guide/step-up.md +182 -0
- package/docs/roadmap.md +11 -3
- package/docs/troubleshooting.md +128 -4
- package/graphql/janus.graphqls +8 -0
- package/package.json +4 -4
package/dist/index.js.map
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/directives/apply.ts", "../src/
|
|
3
|
+
"sources": ["../src/directives/apply.ts", "../src/context.ts", "../src/memo.ts", "../src/errors.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/helpers.ts", "../src/plugin.ts", "../src/sdl.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\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/** What `janus()` answered: its `types` are the names `type:` may take. */\n\treadonly auth: { readonly types: readonly T[] };\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` or `@permission
|
|
5
|
+
"/**\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/** What `janus()` answered: its `types` are the names `type:` may take. */\n\treadonly auth: { readonly types: readonly T[] };\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.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",
|
|
6
|
+
"/**\n * `ctx.janus`, built once per request by `useJanus()`: a lazy\n * authentication, and the per-request check `can()` and the directives ask\n * through.\n */\n\nimport {\n\ttype Authenticated,\n\ttype Clock,\n\ttype RequestLike,\n\tsystemClock,\n} from '@nxgt/janus';\nimport { memoized } from './memo';\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. */\ntype AnyUser = { readonly type: string; readonly id: string };\n\ntype LooseAuth = {\n\tauthenticate(\n\t\trequest: RequestLike,\n\t\toptions?: { readonly type?: string },\n\t): Promise<Authenticated<AnyUser> | null>;\n};\n\ntype 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 */\nconst checks = new WeakMap<object, { memo: Check; fresh: Check }>();\n\n/** The clock of each context this module built with one: what `@fresh` reads. */\nconst clocks = new WeakMap<object, Clock>();\n\n/** What `createJanusContext` reads from `useJanus()`'s options. */\nexport interface ContextOptions {\n\treadonly auth: LooseAuth;\n\treadonly access?: { readonly can: unknown } | undefined;\n\treadonly type?: string | undefined;\n\treadonly clock?: Clock | undefined;\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 — 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 { auth, access, type, clock } = options;\n\tlet answer: Promise<Authenticated<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'useJanus(): the GraphQL context has no request to authenticate — build the context from an HTTP request',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: auth.authenticate(\n\t\t\t\t\t\t\trequest,\n\t\t\t\t\t\t\ttype === undefined ? undefined : { type },\n\t\t\t\t\t\t);\n\t\t}\n\t\treturn answer;\n\t};\n\n\tconst janus = Object.freeze({\n\t\tuser: () => authenticated().then((current) => current?.user ?? null),\n\t\tsession: () => authenticated().then((current) => current?.session ?? null),\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\treturn janus as Built;\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",
|
|
6
7
|
"/**\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
|
-
"/**\n * `ctx.janus`, built once per request by `useJanus()`: a lazy\n * authentication, and the per-request check `can()` and the directives ask\n * through.\n */\n\nimport type { Authenticated, RequestLike } from '@nxgt/janus';\nimport { memoized } from './memo';\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. */\ntype AnyUser = { readonly type: string; readonly id: string };\n\ntype LooseAuth = {\n\tauthenticate(\n\t\trequest: RequestLike,\n\t\toptions?: { readonly type?: string },\n\t): Promise<Authenticated<AnyUser> | null>;\n};\n\ntype 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 */\nconst checks = new WeakMap<object, { memo: Check; fresh: Check }>();\n\n/** What `createJanusContext` reads from `useJanus()`'s options. */\nexport interface ContextOptions {\n\treadonly auth: LooseAuth;\n\treadonly access?: { readonly can: unknown } | undefined;\n\treadonly type?: string | undefined;\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 — 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 { auth, access, type } = options;\n\tlet answer: Promise<Authenticated<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'useJanus(): the GraphQL context has no request to authenticate — build the context from an HTTP request',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: auth.authenticate(\n\t\t\t\t\t\t\trequest,\n\t\t\t\t\t\t\ttype === undefined ? undefined : { type },\n\t\t\t\t\t\t);\n\t\t}\n\t\treturn answer;\n\t};\n\n\tconst janus = Object.freeze({\n\t\tuser: () => authenticated().then((current) => current?.user ?? null),\n\t\tsession: () => authenticated().then((current) => current?.session ?? null),\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\treturn janus as Built;\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
8
|
"/**\n * Every refusal as a `GraphQLError` whose `extensions` carry a `code` and the\n * HTTP status Yoga answers with: `{ code, http: { status } }`. This package\n * defines no error class of its own — a denial is a `GraphQLError`, and what\n * `@nxgt/janus` throws stays its own until `janusMaskError()` reads it.\n */\n\nimport { JanusError, type JanusErrorStatus, statusOf } from '@nxgt/janus';\nimport { GraphQLError } from 'graphql';\n\n/** What a guard answers without asking `@nxgt/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\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`. Never\n * `reason`, `login`, `slot` or a cause: those are for your logs.\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 =\n\t\terror.code === 'STORE_FAILED' ? 'SERVICE_UNAVAILABLE' : error.code;\n\treturn new GraphQLError(messageOf(status), {\n\t\toriginalError: error,\n\t\textensions: { code, http: { status }, ...actionable(error) },\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 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 fields of a refusal a client can act on, as `@nxgt/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 error.attemptsLeft === undefined\n\t\t\t\t? {}\n\t\t\t\t: { attemptsLeft: error.attemptsLeft };\n\t\tdefault:\n\t\t\treturn {};\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\n/** Yoga's and envelop's `maskError` signature. */\nexport type MaskError = (\n\terror: unknown,\n\tmessage: string,\n\tisDev?: boolean,\n) => Error;\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`, a `GraphQLError` is kept and anything else becomes\n * `message`, with no detail. Pass Yoga's own `maskError` to keep its\n * development-mode details:\n *\n * ```ts\n * import { createYoga, maskError } from 'graphql-yoga';\n * createYoga({ schema, plugins, maskedErrors: { maskError: janusMaskError(maskError) } });\n * ```\n */\nexport function janusMaskError(fallback: MaskError = masked): MaskError {\n\treturn (error, message, isDev) => {\n\t\tconst original =\n\t\t\terror instanceof GraphQLError ? error.originalError : error;\n\t\tif (original instanceof JanusError) {\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\treturn fallback(error, message, isDev);\n\t};\n}\n\n/** The default `fallback`: a `GraphQLError` of our own kept, anything else `message`. */\nfunction masked(error: unknown, message: string): Error {\n\tif (error instanceof GraphQLError) {\n\t\tconst original = error.originalError;\n\t\tif (original === undefined || original instanceof GraphQLError) {\n\t\t\treturn error;\n\t\t}\n\t\treturn new GraphQLError(message, {\n\t\t\tnodes: error.nodes ?? null,\n\t\t\tpath: error.path ?? null,\n\t\t\textensions: { code: 'INTERNAL_SERVER_ERROR' },\n\t\t});\n\t}\n\treturn new GraphQLError(message, {\n\t\textensions: { code: 'INTERNAL_SERVER_ERROR' },\n\t});\n}\n",
|
|
9
|
+
"/**\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 `@nxgt/janus`'s `assertFresh`, on the clock given to\n * `useJanus({ clock })`.\n */\n\nimport {\n\tassertFresh,\n\ttype Duration,\n\tparseDuration,\n\ttype Session,\n} from '@nxgt/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. A store that cannot answer is\n * `SERVICE_UNAVAILABLE` 503, never either of them.\n */\nexport async function freshSession(\n\tjanus: { session(): Promise<Session | null> },\n\tmaxAgeMs: number,\n): Promise<Session> {\n\tconst session = await janus.session().then(undefined, rethrown);\n\tif (session === null) throw denial('UNAUTHENTICATED');\n\ttry {\n\t\tassertFresh(session, maxAgeMs, clockOf(janus));\n\t} catch (error) {\n\t\trethrown(error);\n\t}\n\treturn session;\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 `@nxgt/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};\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",
|
|
9
10
|
"/**\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",
|
|
10
11
|
"/**\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 `@nxgt/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",
|
|
11
|
-
"/**\n * What runs before a guarded field's resolver, at request time: the user,\n * then the requirement — its user types, then each `@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 { 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\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",
|
|
12
|
-
"/**\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 `@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\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` 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 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, '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, permission };\n}\n",
|
|
12
|
+
"/**\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",
|
|
13
|
+
"/**\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",
|
|
13
14
|
"/** 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",
|
|
14
15
|
"/**\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",
|
|
15
16
|
"/**\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",
|
|
16
|
-
"/**\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, or a `@permission` the model, the field or the wiring cannot answer
|
|
17
|
+
"/**\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\treadonly types: readonly string[];\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.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",
|
|
17
18
|
"/**\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 '@nxgt/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",
|
|
18
|
-
"/**\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 '@nxgt/janus';\nimport type { GraphQLSchema } from 'graphql';\nimport { createJanusContext } from './context';\nimport { applyJanusDirectives } from './directives/apply';\nimport type { Auth, JanusContext, JanusOptions, UserOfAuth } from './types';\n\n/**\n * The plugin that wires `@nxgt/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. `
|
|
19
|
-
"/**\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\"\"\"\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"
|
|
19
|
+
"/**\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 '@nxgt/janus';\nimport type { GraphQLSchema } from 'graphql';\nimport { createJanusContext } from './context';\nimport { applyJanusDirectives } from './directives/apply';\nimport type { Auth, JanusContext, JanusOptions, UserOfAuth } from './types';\n\n/**\n * The plugin that wires `@nxgt/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 */\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>(options: JanusOptions<A, P, T>): Plugin<JanusContext<A, P, T>> {\n\tconst { auth, access, type, clock, loaders, conditions } = options;\n\tif (typeof auth?.authenticate !== 'function') {\n\t\tthrow new TypeError(\n\t\t\t'useJanus(): 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'useJanus(): 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'useJanus(): 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\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, {\n\t\t\t\tauth,\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});\n\t\t\textendContext({ janus } as unknown as Partial<JanusContext<A, P, T>>);\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,\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};\n}\n",
|
|
20
|
+
"/**\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"
|
|
20
21
|
],
|
|
21
|
-
"mappings": ";AAKA;AACA;;;ACaA,IAAM,WAAW;AAQjB,SAAS,KAAK,CACb,SACA,YACA,Q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MACD,QAAQ,IAAI,IAAI;AAAA,MAChB,cAAc,IAAI;AAAA;AAAA,EAEpB;AAAA;;AC9EM,IAAM,gBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
23
|
+
"debugId": "50FC1B1149A482D964756E2164756E21",
|
|
23
24
|
"names": []
|
|
24
25
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -21,9 +21,10 @@ import type { Auth, JanusContext, JanusOptions, UserOfAuth } from './types';
|
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* `type` treats a user of any other type as anonymous, as
|
|
24
|
-
* `auth.authenticate(request, { type })` does. `
|
|
25
|
-
*
|
|
26
|
-
* and
|
|
24
|
+
* `auth.authenticate(request, { type })` does. `clock` is what `@fresh` and
|
|
25
|
+
* `requireFresh()` read the time from — the one given to `janus()`.
|
|
26
|
+
* `loaders` and `conditions` are what `@permission` needs beside `access`:
|
|
27
|
+
* the objects it checks by id, and the `ctx` of the conditions it reaches.
|
|
27
28
|
*/
|
|
28
29
|
export declare function useJanus<A extends Auth<{
|
|
29
30
|
readonly type: string;
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE5E
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CACvB,CAAC,SAAS,IAAI,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,EAC9D,CAAC,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EACxC,KAAK,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAC5D,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAmD/D"}
|
package/dist/sdl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdl.d.ts","sourceRoot":"","sources":["../src/sdl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"sdl.d.ts","sourceRoot":"","sources":["../src/sdl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,MA4C3B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The public types: what `useJanus()` takes, and what it puts on the
|
|
3
3
|
* GraphQL context. Nothing here runs.
|
|
4
4
|
*/
|
|
5
|
-
import type { Session, SharedApi } from '@nxgt/janus';
|
|
5
|
+
import type { Clock, Session, SharedApi } from '@nxgt/janus';
|
|
6
6
|
import type { PermissionWiringOf } from './wiring';
|
|
7
7
|
/** Anything `janus()` answered: the part of it this package calls. */
|
|
8
8
|
export type Auth<U extends {
|
|
@@ -26,6 +26,11 @@ export type JanusOptions<A, P, T extends string> = {
|
|
|
26
26
|
readonly access?: P;
|
|
27
27
|
/** Only a user of this type is authenticated here; any other is anonymous. */
|
|
28
28
|
readonly type?: T;
|
|
29
|
+
/**
|
|
30
|
+
* The clock `@fresh` and `requireFresh()` read: the one given to
|
|
31
|
+
* `janus()`, when it is not the system's — `fixedClock` in a spec.
|
|
32
|
+
*/
|
|
33
|
+
readonly clock?: Clock;
|
|
29
34
|
} & PermissionWiringOf<P, {
|
|
30
35
|
readonly janus: JanusOnContext<Extract<UserOfAuth<A>, {
|
|
31
36
|
readonly type: T;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,sEAAsE;AACtE,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI,IAAI,CAC3D,SAAS,CAAC,CAAC,CAAC,EACZ,cAAc,GAAG,OAAO,CACxB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,CAA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AE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,EAC5C,CAAC,CACD,CAAC;CACF,CAAC"}
|
package/docs/README.md
CHANGED
|
@@ -5,13 +5,14 @@ give the detail.
|
|
|
5
5
|
|
|
6
6
|
| Page | Read it when |
|
|
7
7
|
| --- | --- |
|
|
8
|
-
| [Directives](guide/directives.md) | You are guarding fields, types or interfaces with `@authenticated` or `@permission`: where the id is read, loaders and conditions, lists, the order, the denials, one check per question, and what is refused at start-up |
|
|
9
|
-
| [The
|
|
8
|
+
| [Directives](guide/directives.md) | You are guarding fields, types or interfaces with `@authenticated`, `@fresh` or `@permission`: where the id is read, loaders and conditions, lists, the order, the denials, one check per question, and what is refused at start-up |
|
|
9
|
+
| [The step-up over GraphQL](guide/step-up.md) | A mutation must run only on a session that proved who it is recently: `@fresh`, `STEP_UP_REQUIRED`, `stepUp.request` and `confirm` as mutations, `requireFresh()`, subscriptions, and testing with a clock |
|
|
10
|
+
| [The context](guide/context.md) | You are reading the user in a resolver, narrowing it to a user type, or checking a permission or freshness yourself with `requireUser()`, `requireFresh()` and `can()` |
|
|
10
11
|
| [Errors](guide/errors.md) | You want to know what a client receives for a denial or an outage, what the status of the response is, and how `janusMaskError()` fits Yoga's masking |
|
|
11
12
|
| [Telemetry](guide/telemetry.md) | You want a span per authentication and per permission check, with `@nxgt/janus-telemetry` |
|
|
12
13
|
| [Federation](guide/federation.md) | The server is a subgraph: where the directives are checked, what the router must forward, and `@composeDirective` |
|
|
13
14
|
| [Troubleshooting](troubleshooting.md) | A query answers something you did not expect, the server refuses to start, or the compiler refuses a resolver |
|
|
14
|
-
| [Roadmap](roadmap.md) | You want to know what is coming — subscriptions over graphql-ws,
|
|
15
|
+
| [Roadmap](roadmap.md) | You want to know what is coming — subscriptions over graphql-ws, the renewed session cookie — and what is deliberately not planned |
|
|
15
16
|
|
|
16
17
|
The words — user, user type, session, subject, permission, failure, denial —
|
|
17
18
|
are [`@nxgt/janus`'s vocabulary](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus/docs/guide/vocabulary.md),
|
package/docs/guide/context.md
CHANGED
|
@@ -29,13 +29,15 @@ export const yoga = createYoga({
|
|
|
29
29
|
calling the hook again with it does not loop.
|
|
30
30
|
|
|
31
31
|
`janusTypeDefs` must be among the type definitions: without it, the schema
|
|
32
|
-
does not build, since `@authenticated` and `@permission` are not
|
|
32
|
+
does not build, since `@authenticated`, `@fresh` and `@permission` are not
|
|
33
|
+
declared.
|
|
33
34
|
|
|
34
35
|
| Option | What it does |
|
|
35
36
|
| --- | --- |
|
|
36
37
|
| `auth` | What `janus()` answered. Required |
|
|
37
38
|
| `access` | What `permissions()` answered: `ctx.janus.access`, what `can()` and `@permission` ask. Optional — and required once the schema uses `@permission` |
|
|
38
39
|
| `type` | A user type: a user of any other type is anonymous on this server, as `auth.authenticate(request, { type })` answers |
|
|
40
|
+
| `clock` | What `@fresh` and `requireFresh()` read the time from: the clock given to `janus()`, when it is not the system's — `fixedClock` in a spec. Absent, the system's |
|
|
39
41
|
| `loaders` | Per object type, `(id, ctx) => object \| null`: the object `@permission` checks when it reads an id alone — from `args`, or a parent field other than `id`. Required for a type with a `fromField` — see [directives](directives.md#reading-the-id) |
|
|
40
42
|
| `conditions` | Per object type, `(object, ctx) => its when()s' ctx`: what `@permission` passes as `{ ctx }` — see [directives](directives.md#conditions) |
|
|
41
43
|
|
|
@@ -92,7 +94,7 @@ then absent from the type, as it is from the context.
|
|
|
92
94
|
|
|
93
95
|
## Directives
|
|
94
96
|
|
|
95
|
-
`@authenticated` and `@permission` guard a field, a type or an interface
|
|
97
|
+
`@authenticated`, `@fresh` and `@permission` guard a field, a type or an interface
|
|
96
98
|
before its resolver runs: see [directives](directives.md). This page covers
|
|
97
99
|
what a resolver checks itself, where a directive does not fit.
|
|
98
100
|
|
|
@@ -121,6 +123,34 @@ time — since no user could pass it.
|
|
|
121
123
|
Use it where a directive does not fit: a mutation that must know the user
|
|
122
124
|
anyway, or a type that depends on the arguments.
|
|
123
125
|
|
|
126
|
+
## `requireFresh(ctx, maxAge)`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { requireFresh } from '@nxgt/janus-graphql';
|
|
130
|
+
|
|
131
|
+
const resolvers = {
|
|
132
|
+
Mutation: {
|
|
133
|
+
transfer: async (_: unknown, { amount }: { amount: number }, ctx: Context) => {
|
|
134
|
+
if (amount > 1_000) await requireFresh(ctx, '5m');
|
|
135
|
+
return payments.transfer(ctx, amount);
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The request's session, once it proved who it is less than `maxAge` ago —
|
|
142
|
+
signed in, or confirmed since by `auth.stepUp.confirm` — or a denial:
|
|
143
|
+
`UNAUTHENTICATED` for an anonymous request, `STEP_UP_REQUIRED`, 403, for an
|
|
144
|
+
older session. A store that cannot answer is `SERVICE_UNAVAILABLE`. It is
|
|
145
|
+
`@fresh` in a resolver, for a rule that depends on the arguments, on
|
|
146
|
+
`useJanus({ clock })`'s clock.
|
|
147
|
+
|
|
148
|
+
`maxAge` is a duration **with its unit** — `'5m'`, `'300s'`, `'1h'` — and
|
|
149
|
+
never a bare number: `@nxgt/janus` reads a number as milliseconds, where
|
|
150
|
+
`@fresh(maxAge: 300)` reads seconds, so the compiler refuses one and the call
|
|
151
|
+
throws a `TypeError` for one built at run time. What the client does next is
|
|
152
|
+
in [the step-up over GraphQL](step-up.md).
|
|
153
|
+
|
|
124
154
|
## `can(ctx, permission, object, options?)`
|
|
125
155
|
|
|
126
156
|
```ts
|
package/docs/guide/directives.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Directives
|
|
2
2
|
|
|
3
3
|
This page is for guarding a schema: `@authenticated`, which asks who the user
|
|
4
|
-
is,
|
|
4
|
+
is, `@fresh`, which asks how recently their session proved it, and
|
|
5
|
+
`@permission`, which asks what the user may do to one object. All three
|
|
5
6
|
are declared in `janusTypeDefs`, applied by `useJanus()` when the server
|
|
6
7
|
builds its schema, and checked before the resolver runs — a refused request
|
|
7
8
|
never reaches it.
|
|
@@ -26,7 +27,7 @@ export const yoga = createYoga({
|
|
|
26
27
|
|
|
27
28
|
## Where a directive applies
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
Every directive goes on a field, an object type or an interface:
|
|
30
31
|
|
|
31
32
|
| Written on | Guards |
|
|
32
33
|
| --- | --- |
|
|
@@ -78,6 +79,57 @@ On `Ward.chart` above, the type's `["staff"]` and the field's
|
|
|
78
79
|
Under `useJanus({ type: 'staff' })`, the only user type a directive may name
|
|
79
80
|
is `'staff'`.
|
|
80
81
|
|
|
82
|
+
## `@fresh(maxAge: Int!)`
|
|
83
|
+
|
|
84
|
+
```graphql
|
|
85
|
+
type Mutation {
|
|
86
|
+
changeEmail(email: String!): User @fresh(maxAge: 600) # signed in, or confirmed, in the last ten minutes
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type PaymentMethods @fresh(maxAge: 600) { # every field of PaymentMethods
|
|
90
|
+
cards: [Card!]!
|
|
91
|
+
add(token: String!): Card @fresh(maxAge: 60) # the smallest maxAge holds: one minute
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Only a session that proved who it is **less than `maxAge` seconds ago**
|
|
96
|
+
reaches the field: signed in, or confirmed since by `auth.stepUp.confirm`,
|
|
97
|
+
which moves the session's `authenticatedAt` to now. Renewing a sliding
|
|
98
|
+
session does not. It is `@nxgt/janus`'s `assertFresh`, and
|
|
99
|
+
`@nxgt/janus-hono`'s `fresh()`, for a schema.
|
|
100
|
+
|
|
101
|
+
**`maxAge` is in seconds**, an `Int`: `600` is ten minutes. Seconds because
|
|
102
|
+
a GraphQL `Int` is 32 bits — about 24 days in milliseconds — and because a
|
|
103
|
+
freshness limit is written in seconds elsewhere, such as OpenID Connect's
|
|
104
|
+
`max_age`. `@nxgt/janus`'s durations read a bare number as milliseconds;
|
|
105
|
+
here there is no unit to write, so it is seconds, always.
|
|
106
|
+
|
|
107
|
+
| The request | Answered |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| anonymous | `UNAUTHENTICATED`, 401 |
|
|
110
|
+
| a user of a type `@authenticated` does not name | `FORBIDDEN`, 403, before freshness is read |
|
|
111
|
+
| a session that proved who it is `maxAge` seconds ago or more | `STEP_UP_REQUIRED`, 403 — the client asks for a step-up |
|
|
112
|
+
| a store that cannot answer | `SERVICE_UNAVAILABLE`, 503, never a denial |
|
|
113
|
+
| a fresh session | every `@permission`, then the resolver |
|
|
114
|
+
|
|
115
|
+
`@fresh` implies a signed-in user, as `@permission` does. **It is checked
|
|
116
|
+
after `@authenticated` and before any `@permission`**, so a stale session
|
|
117
|
+
asks no permission check and loads no object. Where several apply — the
|
|
118
|
+
field's, its type's, its interfaces' — **the smallest `maxAge` holds**. The
|
|
119
|
+
refusal is at `maxAge` exactly: a session `maxAge` seconds old is refused,
|
|
120
|
+
as `assertFresh` refuses it.
|
|
121
|
+
|
|
122
|
+
**A `@fresh` on a subscription field is checked when it subscribes**: a
|
|
123
|
+
fresh one keeps receiving events past `maxAge`. A `@fresh` on the payload's
|
|
124
|
+
type or its fields is checked on every event, as any field. See
|
|
125
|
+
[the step-up over GraphQL](step-up.md#subscriptions).
|
|
126
|
+
|
|
127
|
+
The time is `useJanus({ clock })`'s — give it the clock given to `janus()`
|
|
128
|
+
when that is not the system's, such as `fixedClock` in a spec. The flow a
|
|
129
|
+
client follows on `STEP_UP_REQUIRED`, with `stepUp.request` and `confirm` as
|
|
130
|
+
mutations, is in [the step-up over GraphQL](step-up.md); `requireFresh(ctx,
|
|
131
|
+
maxAge)` is the same check in a resolver.
|
|
132
|
+
|
|
81
133
|
## `@permission(name, type, id, onDeny)`
|
|
82
134
|
|
|
83
135
|
```graphql
|
|
@@ -102,7 +154,8 @@ reads reaches the field. It is `@nxgt/janus-hono`'s
|
|
|
102
154
|
| `onDeny` | What a denial answers: `NOT_FOUND`, 404, by default, or `FORBIDDEN`, 403 |
|
|
103
155
|
|
|
104
156
|
`@permission` implies `@authenticated`: an anonymous request is answered
|
|
105
|
-
`UNAUTHENTICATED`, 401, before any object is loaded or any check asked.
|
|
157
|
+
`UNAUTHENTICATED`, 401, before any object is loaded or any check asked. A
|
|
158
|
+
`@fresh` that applies is checked before it, too.
|
|
106
159
|
|
|
107
160
|
### Reading the id
|
|
108
161
|
|
|
@@ -213,7 +266,9 @@ permission whose rules name both. They are asked **one at a time, in order**,
|
|
|
213
266
|
and the first that denies answers: the ones after it are never asked.
|
|
214
267
|
|
|
215
268
|
The order across locations is outermost first: the interfaces' directives,
|
|
216
|
-
the type's, the interfaces' fields', then the field's own.
|
|
269
|
+
the type's, the interfaces' fields', then the field's own. Across
|
|
270
|
+
directives, every `@authenticated` comes first, then `@fresh`, then the
|
|
271
|
+
`@permission`s. So a type's
|
|
217
272
|
`NOT_FOUND` answers before a field's `FORBIDDEN` could tell that the object
|
|
218
273
|
exists.
|
|
219
274
|
|
|
@@ -235,6 +290,7 @@ type Record @permission(name: "view", type: "record") {
|
|
|
235
290
|
| --- | --- |
|
|
236
291
|
| anonymous | `UNAUTHENTICATED`, 401 |
|
|
237
292
|
| a user of a type `@authenticated` does not name | `FORBIDDEN`, 403, before any check |
|
|
293
|
+
| a session older than a `@fresh` that applies allows | `STEP_UP_REQUIRED`, 403, before any check |
|
|
238
294
|
| no id at the path, an empty list in the parent, or an id no object can hold | `NOT_FOUND`, 404 |
|
|
239
295
|
| a loader answering `null` | `NOT_FOUND`, 404 |
|
|
240
296
|
| a denial | `onDeny`: `NOT_FOUND`, 404, or `FORBIDDEN`, 403 |
|
|
@@ -278,6 +334,7 @@ field — `(read by Ward.name)`:
|
|
|
278
334
|
TypeError: applyJanusDirectives(): @authenticated on Query.me names the user type 'doctor', which is not one of 'patient', 'staff'
|
|
279
335
|
TypeError: applyJanusDirectives(): @authenticated on Query.me names no user type — leave type: out to admit any signed-in user
|
|
280
336
|
TypeError: applyJanusDirectives(): the @authenticated on Ward.chart and on its type or interfaces admit no user type in common
|
|
337
|
+
TypeError: applyJanusDirectives(): @fresh on Mutation.changeEmail asks maxAge: 0 — write a number of seconds above zero, such as maxAge: 600 for ten minutes
|
|
281
338
|
TypeError: applyJanusDirectives(): @permission on Query.ward needs the permissions() instance — pass useJanus({ auth, access }), with access what permissions() answered
|
|
282
339
|
TypeError: applyJanusDirectives(): @permission on Query.invoice names the object type 'invoice', which is not one of 'record', 'ward'
|
|
283
340
|
TypeError: applyJanusDirectives(): @permission on Query.ward asks 'delete', which ward does not declare — it declares 'nurses', 'visitors', 'enter', 'manage'
|
|
@@ -292,7 +349,9 @@ Each is in [troubleshooting](../troubleshooting.md), with its fix. The
|
|
|
292
349
|
compiler refuses the wiring's own mistakes before that: a loader for a type
|
|
293
350
|
the model does not declare, a loader answering an object without a field a
|
|
294
351
|
`fromField` reads, a condition for a type no `when()` is reached on, a `ctx`
|
|
295
|
-
of the wrong shape,
|
|
352
|
+
of the wrong shape, `loaders` or `conditions` without `access`, and a
|
|
353
|
+
`clock` that is not a `Clock`. A `maxAge` that is not an `Int`, or is
|
|
354
|
+
missing, is refused by graphql-js itself, at start-up too.
|
|
296
355
|
|
|
297
356
|
## The transform alone
|
|
298
357
|
|
package/docs/guide/errors.md
CHANGED
|
@@ -30,8 +30,9 @@ Yoga reads `extensions.http.status` to answer the HTTP response, and strips
|
|
|
30
30
|
|
|
31
31
|
| Code | Status | Message | When |
|
|
32
32
|
| --- | --- | --- | --- |
|
|
33
|
-
| `UNAUTHENTICATED` | 401 | `Not signed in` | An anonymous request reached a field
|
|
33
|
+
| `UNAUTHENTICATED` | 401 | `Not signed in` | An anonymous request reached a guarded field, `requireUser()` or `requireFresh()` |
|
|
34
34
|
| `FORBIDDEN` | 403 | `Forbidden` | A user of a type the directive or `requireUser({ type })` does not name, or a `@permission(onDeny: FORBIDDEN)` denied |
|
|
35
|
+
| `STEP_UP_REQUIRED` | 403 | `Forbidden` | A session older than `@fresh(maxAge)` or `requireFresh(ctx, maxAge)` allows: the client asks for a step-up — see [the step-up over GraphQL](step-up.md) |
|
|
35
36
|
| `NOT_FOUND` | 404 | `Not found` | `@permission`'s default denial, a loader answering `null`, an id `@permission` could not read — and `denial('NOT_FOUND')` |
|
|
36
37
|
| `SERVICE_UNAVAILABLE` | 503 | `The service is unavailable, retry later` | A store could not answer: `STORE_FAILED` |
|
|
37
38
|
| any other `JanusErrorCode` | its `statusOf(code)` | fixed per status: `Invalid request` 400, `Invalid credentials` 401 (`CREDENTIALS_INVALID`, `CODE_INVALID`), `Forbidden` 403, `Not found` 404, `Conflict` 409, `Internal server error` 500 and 501 | A `JanusError` a resolver let through — `CREDENTIALS_INVALID` 401, `LOGIN_TAKEN` 409, `TOKEN_EXPIRED` 400, … |
|
package/docs/guide/federation.md
CHANGED
|
@@ -53,8 +53,9 @@ specification URL of your own and compose them:
|
|
|
53
53
|
```graphql
|
|
54
54
|
extend schema
|
|
55
55
|
@link(url: "https://specs.apollo.dev/federation/v2.1", import: ["@key", "@composeDirective"])
|
|
56
|
-
@link(url: "https://example.com/janus/v1.0", import: ["@authenticated", "@permission"])
|
|
56
|
+
@link(url: "https://example.com/janus/v1.0", import: ["@authenticated", "@fresh", "@permission"])
|
|
57
57
|
@composeDirective(name: "@authenticated")
|
|
58
|
+
@composeDirective(name: "@fresh")
|
|
58
59
|
@composeDirective(name: "@permission")
|
|
59
60
|
```
|
|
60
61
|
|