@softistx/janus-graphql 0.32.1 → 0.34.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 CHANGED
@@ -81,13 +81,13 @@ that reads files — `node_modules/@softistx/janus-graphql/graphql/janus.graphql
81
81
 
82
82
  | Export | What it is |
83
83
  | --- | --- |
84
- | `useJanus({ auth, types?, access?, type?, clock?, apiKey?, loaders?, conditions? })` | The envelop plugin. `auth` is what `janus()` answered, or a function `(ctx) => instance` that picks the instance per request ([several issuers](#one-server-several-issuers)); `types` names the user types the directives may use when it is a function. Adds `ctx.janus` to every request's context, and applies the directives to every schema the server is given, once. `type` treats a user of any other type as anonymous. `clock` is what `@fresh` and `requireFresh()` read — the one given to `janus()`, when it is not the system's. `loaders` and `conditions` are what `@permission` needs beside `access`. `apiKey: true` also accepts an API key: `ctx.janus` gains `principal()` and `apiKey()`, `session()` is `null` for a key, `@fresh` refuses one (`STEP_UP_REQUIRED`); off, a key is anonymous. Under Yoga, a session `authenticate` renewed is sent again as `Set-Cookie` on the response, to a request that presented it as the cookie |
84
+ | `useJanus({ auth, types?, access?, type?, clock?, apiKey?, loaders?, conditions? })` | The envelop plugin. `auth` is what `janus()` answered, or a function `(ctx) => instance` that picks the instance per request ([several issuers](#one-server-several-issuers)); `types` names the user types the directives may use when it is a function. Adds `ctx.janus` to every request's context, and applies the directives to every schema the server is given, once. `type` treats a user of any other type as anonymous. `clock` is what `@fresh` and `requireFresh()` read — the one given to `janus()`, when it is not the system's. `loaders` and `conditions` are what `@permission` needs beside `access`. `apiKey: true` also accepts an API key: `ctx.janus` gains `principal()` and `apiKey()`, `session()` is `null` for a key, `@fresh` refuses one (`STEP_UP_REQUIRED`); off, a key is anonymous. `apiKey: 'service'` does the same and also accepts an object's service key (`janus({ apiKeys: { service } })`): `principal()` may answer `via: 'serviceKey'` (`user()` is `null`, the owner is `bound`), `@fresh` refuses it too. Under Yoga, a session `authenticate` renewed is sent again as `Set-Cookie` on the response, to a request that presented it as the cookie |
85
85
  | `ctx.janus.user()`, `ctx.janus.session()` | Who the request belongs to, and the session it presented — `null` for an anonymous request. `auth.authenticate(request)` runs the first time either is asked, once per request, and never when neither is |
86
86
  | `ctx.janus.principal()`, `ctx.janus.apiKey()` | With `useJanus({ apiKey: true })` only: the session or API key principal (narrow on `via`), and the key. See [the context guide](docs/guide/context.md) |
87
87
  | `ctx.janus.access` | The `permissions()` instance given to `useJanus()`. Absent from the type — and from the context — without one |
88
88
  | `janusTypeDefs` | The SDL: `@authenticated`, `@fresh`, `@permission` and the `JanusPermissionDenial` enum — prefixed, so it never collides with a type of your schema. The same text as `graphql/janus.graphqls` |
89
89
  | `@authenticated(type: [String!])` | On a field, a type or an interface. A signed-in user, of one of the `type`s when it names some. Anonymous: `UNAUTHENTICATED`. Another type: `FORBIDDEN`. Every one that applies — the field's, its type's, its interfaces' — must hold |
90
- | `@fresh(maxAge: Int!)` | On a field, a type or an interface. A session that proved who it is less than `maxAge` **seconds** ago — signed in, or confirmed since by `auth.stepUp.confirm`. Anonymous: `UNAUTHENTICATED`. Older, or an API key under `apiKey: true`: `STEP_UP_REQUIRED`, 403. Checked after `@authenticated`, before `@permission`; the smallest `maxAge` that applies holds; on a subscription field, checked when it subscribes |
90
+ | `@fresh(maxAge: Int!)` | On a field, a type or an interface. A session that proved who it is less than `maxAge` **seconds** ago — signed in, or confirmed since by `auth.stepUp.confirm`. Anonymous: `UNAUTHENTICATED`. Older, or an API key under `apiKey: true`: `STEP_UP_REQUIRED`, 403. A service key (`apiKey: 'service'`): `FORBIDDEN`, 403, `extensions.reason: "serviceKey"`. Checked after `@authenticated`, before `@permission`; the smallest `maxAge` that applies holds; on a subscription field, checked when it subscribes |
91
91
  | `@permission(name, type, id, onDeny)` | On a field, a type or an interface. A user holding permission `name` on the object of `type` whose id `id` reads — `args.<path>` or `parent.<path>`; `args.id` on a field, `parent.id` on a type. A list requires it on every id. Repeated, every one must hold, in order. Denied: `NOT_FOUND`, or `FORBIDDEN` with `onDeny: FORBIDDEN` |
92
92
  | `loaders: { [type]: (id, ctx) => object \| null }` | The object `@permission` checks for an id alone — from `args`, or a parent field other than `id` — required for a type with a `fromField`, whose fields `access.can` reads. `null` answers `NOT_FOUND` |
93
93
  | `conditions: { [type]: (object, ctx) => ctx }` | The `ctx` `@permission` passes to `access.can` for a permission that reaches a `when()` |
@@ -658,6 +658,13 @@ createYoga({
658
658
  - **A denial of a list field's item fails the whole list** where the item is
659
659
  non-null (`[Doctor!]!`), as GraphQL's null propagation always does. Guard
660
660
  the list field, or make the item nullable.
661
+ - **A service key never passes a user guard.** Under
662
+ `useJanus({ apiKey: 'service' })`, `@authenticated`, `@fresh` and
663
+ `@permission` answer a service key `FORBIDDEN` (403,
664
+ `extensions.reason: "serviceKey"`): it has no user, and `UNAUTHENTICATED`
665
+ would send a client to sign in again. Read `ctx.janus.principal()` in its
666
+ resolvers. `useJanus({ type, apiKey: 'service' })` leaves service keys
667
+ anonymous, since `type` narrows the server to users of that type.
661
668
 
662
669
  ## Documentation
663
670
 
@@ -667,7 +674,7 @@ createYoga({
667
674
 
668
675
  ## Type safety, counted
669
676
 
670
- Eighty-seven plausible mistakes are refused by the compiler, each with a
677
+ Eighty-eight plausible mistakes are refused by the compiler, each with a
671
678
  `@ts-expect-error` case in `test/types/`:
672
679
 
673
680
  - seven in `context.ts`: reading the user or the session where either may be
@@ -1 +1 @@
1
- {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/deps.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAE1G,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM9D,OAAO,KAAK,EACX,OAAO,EACP,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EACP,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,IAAI;IACpB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,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.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/list.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAMxE,OAAO,KAAK,EAA0B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtD,KAAK,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAsBzC;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBtD;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CAgBhE;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOtE"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/list.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAMxE,OAAO,KAAK,EAA0B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtD,KAAK,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAsBzC;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBtD;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CAmBhE;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOtE"}
@@ -1 +1 @@
1
- {"version":3,"file":"manage.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/manage.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAM3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAIN,KAAK,IAAI,EAIT,MAAM,QAAQ,CAAC;AAEhB,KAAK,SAAS,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAyBlE;AAmBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAuBlE"}
1
+ {"version":3,"file":"manage.d.ts","sourceRoot":"","sources":["../../../src/api-keys/resolvers/manage.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAM3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAIN,KAAK,IAAI,EAIT,MAAM,QAAQ,CAAC;AAEhB,KAAK,SAAS,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAyBlE;AAoBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAuBlE"}
@@ -1 +1 @@
1
- {"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/api-keys/shape.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAK1D,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAmB7D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;aAC1B,IAAI,EAAE,GAAG;aACT,MAAM,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AAuE;AACvE,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAS3E;AAED,qFAAqF;AACrF,wBAAgB,UAAU,CACzB,SAAS,EAAE,eAAe,EAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,MAAM,CASR;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,eAAe,GAAG,SAAS,GACpC,eAAe,CAqBjB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CASnD"}
@@ -14,7 +14,7 @@ export interface ContextOptions {
14
14
  readonly type?: string | undefined;
15
15
  readonly clock?: Clock | undefined;
16
16
  /** Accept an API key beside a session: `authenticate(request, { apiKey: true })`. */
17
- readonly apiKey?: boolean | undefined;
17
+ readonly apiKey?: boolean | 'service' | undefined;
18
18
  /** The call the consumer wrote, named by the no-request `TypeError`. */
19
19
  readonly caller?: string;
20
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/context/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAa,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAGN,KAAK,KAAK,EAIV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,cAAc,EAAc,MAAM,WAAW,CAAC;AAE5D,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,6FAA6F;IAC7F,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;KAAE,GAAG,S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AAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,WAAW,GAAG,SAAS,EAChC,OAAO,EAAE,cAAc,GACrB,KAAK,CA+DP"}
@@ -1,4 +1,4 @@
1
- import { type Clock, type Principal } from '@softistx/janus';
1
+ import { type Clock, type Principal, type ServiceKeyAuthenticated } from '@softistx/janus';
2
2
  import type { SessionCookie } from '../renewal';
3
3
  import type { JanusOnContext } from '../types';
4
4
  /** One check, as `access.can` answers it — loose: the typing is the caller's. */
@@ -34,7 +34,7 @@ export declare const clocks: WeakMap<object, Clock>;
34
34
  * `undefined` while neither `user()` nor `session()` has been asked, so that
35
35
  * reading it never authenticates.
36
36
  */
37
- export declare const answers: WeakMap<object, () => Promise<Principal<AnyUser> | null> | undefined>;
37
+ export declare const answers: WeakMap<object, () => Promise<Principal<AnyUser> | ServiceKeyAuthenticated | null> | undefined>;
38
38
  /**
39
39
  * The session cookie of the instance each context authenticated with — set
40
40
  * once a resolver has answered, so a renewed session is sent again with the
@@ -48,7 +48,7 @@ export declare function cookieOfContext(janus: object): SessionCookie | undefine
48
48
  * never ran — nothing asked `user()` or `session()`, or the context was not
49
49
  * built here. Never runs it.
50
50
  */
51
- export declare function answerOf(janus: object): Promise<Principal<AnyUser> | null> | undefined;
51
+ export declare function answerOf(janus: object): Promise<Principal<AnyUser> | ServiceKeyAuthenticated | null> | undefined;
52
52
  /**
53
53
  * The clock `@fresh` and `requireFresh()` read the time from: the one given
54
54
  * to `useJanus({ clock })`, or the system's.
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/context/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,C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FAAiF;AACjF,eAAO,MAAM,MAAM,wBAA+B,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,OAAO,wBAEb,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,uBAAuB,GAAG,IAAI,CAAC,GAAG,SAAS,CAC5E,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,OAAO,4CAAmD,CAAC;AAExE,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAExE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACvB,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,uBAAuB,GAAG,IAAI,CAAC,GAAG,SAAS,CAE1E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,KAAK,GAAG,IAAI,CAMlE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAQ3D"}
@@ -1,10 +1,11 @@
1
- import type { Principal, RequestLike } from '@softistx/janus';
1
+ import type { Principal, RequestLike, ServiceKeyAuthenticated } from '@softistx/janus';
2
2
  import { type AnyUser } from './registry';
3
3
  type LooseAuth = {
4
4
  authenticate(request: RequestLike, options?: {
5
5
  readonly type?: string;
6
6
  readonly apiKey?: boolean;
7
- }): Promise<Principal<AnyUser> | null>;
7
+ readonly service?: boolean;
8
+ }): Promise<Principal<AnyUser> | ServiceKeyAuthenticated | null>;
8
9
  };
9
10
  /** `auth` as the options give it: an instance, or a function answering one. */
10
11
  export type AuthOrResolver = LooseAuth | ((ctx: never) => LooseAuth | null | undefined | Promise<LooseAuth | null | undefined>);
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/context/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,YAAY,CAAC;AAEnD,KAAK,SAAS,GAAG;IAChB,YAAY,CACX,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAC7D,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;CACtC,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,cAAc,GACvB,SAAS,GACT,CAAC,CACD,GAAG,EAAE,KAAK,KACL,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC;AAE9E;;;;;GAKG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,SAAS,GAAG,YAAwB,GACxC,OAAO,CAAC,SAAS,CAAC,CAqBpB;AAED,wBAAsB,UAAU,CAC/B,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS,GAAG,YAAY,GAC5B,OAAO,CAAC,SAAS,CAAC,CAIpB"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/context/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,uBAAuB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,YAAY,CAAC;AAEnD,KAAK,S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AAC,CAAC,EACtC,WAAW,EAAE,WAAW,GACtB,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAU/B"}
@@ -2,5 +2,5 @@ import { GraphQLError } from 'graphql';
2
2
  /** What a guard answers without asking `@softistx/janus`: no user, or not this one. */
3
3
  export type DenialCode = 'UNAUTHENTICATED' | 'FORBIDDEN' | 'NOT_FOUND';
4
4
  /** A denial: `UNAUTHENTICATED` 401, `FORBIDDEN` 403 or `NOT_FOUND` 404. */
5
- export declare function denial(code: DenialCode, message?: string): GraphQLError;
5
+ export declare function denial(code: DenialCode, message?: string, extensions?: Readonly<Record<string, unknown>>): GraphQLError;
6
6
  //# sourceMappingURL=denial.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"denial.d.ts","sourceRoot":"","sources":["../../src/errors/denial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,uFAAuF;AACvF,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;AAEvE,2EAA2E;AAC3E,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAKvE"}
1
+ {"version":3,"file":"denial.d.ts","sourceRoot":"","sources":["../../src/errors/denial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,uFAAuF;AACvF,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;AAEvE,2EAA2E;AAC3E,wBAAgB,MAAM,CACrB,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAChD,YAAY,CAKd"}
package/dist/fresh.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * resolver. Both are `@softistx/janus`'s `assertFresh`, on the clock given to
5
5
  * `useJanus({ clock })`.
6
6
  */
7
- import { type Duration, type Principal, type Session } from '@softistx/janus';
7
+ import { type Duration, type Principal, type ServiceKeyAuthenticated, type Session } from '@softistx/janus';
8
8
  /**
9
9
  * The request's session, once it proved who it is less than `maxAgeMs` ago
10
10
  * — or a denial: `UNAUTHENTICATED` 401 for an anonymous request,
@@ -16,7 +16,7 @@ export declare function freshSession(janus: {
16
16
  session(): Promise<Session | null>;
17
17
  principal?(): Promise<Principal<{
18
18
  readonly id: string;
19
- }> | null>;
19
+ }> | ServiceKeyAuthenticated | null>;
20
20
  }, maxAgeMs: number): Promise<Session>;
21
21
  /**
22
22
  * The request's session, once it proved who it is less than `maxAge` ago —
@@ -38,7 +38,7 @@ export declare function requireFresh(ctx: {
38
38
  session(): Promise<Session | null>;
39
39
  principal?(): Promise<Principal<{
40
40
  readonly id: string;
41
- }> | null>;
41
+ }> | ServiceKeyAuthenticated | null>;
42
42
  };
43
43
  }, maxAge: Exclude<Duration, number>): Promise<Session>;
44
44
  //# sourceMappingURL=fresh.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fresh.d.ts","sourceRoot":"","sources":["../src/fresh.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEN,KAAK,QAAQ,EACb,KAAK,SAAS,EAEd,KAAK,OAAO,EACZ,MAAM,iBAAiB,CAAC;AAIzB;;;;;;GAMG;AACH,wBAAsB,YAAY,CACjC,KAAK,EAAE;IACN,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IACnC,SAAS,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC,CAAC;CACjE,EACD,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,CAkBlB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,YAAY,CACj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uB,GAAG,IAAI,CACnE,CAAC;KACF,CAAC;CACF,EACD,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC,CAQlB"}
package/dist/index.js CHANGED
@@ -30,7 +30,9 @@ function memoized(access) {
30
30
  }
31
31
 
32
32
  // src/context/registry.ts
33
- import { systemClock } from "@softistx/janus";
33
+ import {
34
+ systemClock
35
+ } from "@softistx/janus";
34
36
  var checks = new WeakMap;
35
37
  var clocks = new WeakMap;
36
38
  var answers = new WeakMap;
@@ -97,7 +99,8 @@ function createJanusContext(request, options) {
97
99
  asked = true;
98
100
  answer = request === undefined ? Promise.reject(new TypeError(`${caller}: the GraphQL context has no request to authenticate — build the context from an HTTP request, or accept a graphql-ws connection with janusConnection().onConnect`)) : instanceOf(auth, context, caller, janus, what).then((instance) => instance.authenticate(request, {
99
101
  ...type === undefined ? {} : { type },
100
- ...apiKey === true ? { apiKey: true } : {}
102
+ ...apiKey === true || apiKey === "service" ? { apiKey: true } : {},
103
+ ...apiKey === "service" ? { service: true } : {}
101
104
  }));
102
105
  }
103
106
  return answer;
@@ -105,9 +108,9 @@ function createJanusContext(request, options) {
105
108
  const janus = Object.freeze({
106
109
  user: () => authenticated().then((current) => current?.user ?? null),
107
110
  session: () => authenticated().then((current) => current?.session ?? null),
108
- ...apiKey === true ? {
111
+ ...apiKey === true || apiKey === "service" ? {
109
112
  principal: () => authenticated(),
110
- apiKey: () => authenticated().then((current) => current?.via === "apiKey" ? current.apiKey : null)
113
+ apiKey: () => authenticated().then((current) => current?.via === "apiKey" || current?.via === "serviceKey" ? current.apiKey : null)
111
114
  } : {},
112
115
  ...access === undefined ? {} : { access }
113
116
  });
@@ -125,10 +128,10 @@ function createJanusContext(request, options) {
125
128
  }
126
129
  // src/errors/denial.ts
127
130
  import { GraphQLError } from "graphql";
128
- function denial(code, message) {
131
+ function denial(code, message, extensions = {}) {
129
132
  const [status, fallback] = denialOf(code);
130
133
  return new GraphQLError(message ?? fallback, {
131
- extensions: { code, http: { status } }
134
+ extensions: { ...extensions, code, http: { status } }
132
135
  });
133
136
  }
134
137
  function denialOf(code) {
@@ -430,16 +433,20 @@ function limitOf(limit) {
430
433
  // src/api-keys/shape.ts
431
434
  var iso = (date) => date === null ? null : date.toISOString();
432
435
  function apiKeyOut(key, now) {
436
+ const { userId, expiresAt } = key;
437
+ if (userId === null || expiresAt === null) {
438
+ throw new TypeError("apiKeyOut: a service key is not a user key");
439
+ }
433
440
  return {
434
441
  id: key.id,
435
- userId: key.userId,
442
+ userId,
436
443
  name: key.name,
437
444
  prefix: key.hint,
438
445
  scopes: key.scopes,
439
446
  bound: key.bound,
440
- status: key.revokedAt !== null ? "REVOKED" : key.expiresAt.getTime() <= now ? "EXPIRED" : "ACTIVE",
447
+ status: key.revokedAt !== null ? "REVOKED" : expiresAt.getTime() <= now ? "EXPIRED" : "ACTIVE",
441
448
  createdAt: key.createdAt.toISOString(),
442
- expiresAt: key.expiresAt.toISOString(),
449
+ expiresAt: expiresAt.toISOString(),
443
450
  lastUsedAt: iso(key.lastUsedAt),
444
451
  revokedAt: iso(key.revokedAt)
445
452
  };
@@ -547,6 +554,9 @@ async function principalOf(ctx) {
547
554
  const principal = await answered?.then(undefined, rethrown);
548
555
  if (principal == null)
549
556
  throw denial("UNAUTHENTICATED");
557
+ if (principal.via === "serviceKey") {
558
+ throw denial("FORBIDDEN", undefined, { reason: "serviceKey" });
559
+ }
550
560
  return principal;
551
561
  }
552
562
  async function allowed(answer) {
@@ -603,7 +613,7 @@ function boundApiKeys(deps) {
603
613
  await allowed(deps.authorize.list({ user, bound, every: true, page: page.asked }, ctx));
604
614
  const found = await deps.keys.listBound(bound, { limit: page.size, after: page.after }).then(undefined, rethrown);
605
615
  return {
606
- items: found.items.map((key) => apiKeyOut(key, now)),
616
+ items: found.items.filter((key) => key.userId !== null).map((key) => apiKeyOut(key, now)),
607
617
  nextCursor: found.nextCursor
608
618
  };
609
619
  };
@@ -697,7 +707,7 @@ function createApiKey(deps) {
697
707
  async function located(deps, caller, id) {
698
708
  const { user, bound } = caller;
699
709
  const key = await deps.keys.get(id).then(undefined, rethrown);
700
- if (key === null)
710
+ if (key === null || key.userId === null)
701
711
  return null;
702
712
  const binds = deps.bound !== undefined;
703
713
  if (key.userId === user.id && (!binds || sameBound(key.bound, bound))) {
@@ -1252,11 +1262,21 @@ function warnNoId(permission) {
1252
1262
  }
1253
1263
 
1254
1264
  // src/directives/guard.ts
1265
+ async function refuseServiceKey(janus) {
1266
+ if (typeof janus.principal !== "function")
1267
+ return;
1268
+ const principal = await janus.principal().then(undefined, rethrown);
1269
+ if (principal?.via === "serviceKey") {
1270
+ throw denial("FORBIDDEN", undefined, { reason: "serviceKey" });
1271
+ }
1272
+ }
1255
1273
  async function enforce(requirement, { parent, args, ctx, fresh }) {
1256
1274
  const janus = janusOf(ctx, requirement.label);
1257
1275
  const user = await janus.user().then(undefined, rethrown);
1258
- if (user === null)
1276
+ if (user === null) {
1277
+ await refuseServiceKey(janus);
1259
1278
  throw denial("UNAUTHENTICATED");
1279
+ }
1260
1280
  if (requirement.types !== null && !requirement.types.has(user.type)) {
1261
1281
  throw denial("FORBIDDEN");
1262
1282
  }
@@ -3209,6 +3229,7 @@ function completedOut(done, { auth, answerToken }, request) {
3209
3229
  ...signedInAnswer({ auth, answerToken, device: undefined }, request, done),
3210
3230
  created: done.created,
3211
3231
  linked: done.linked,
3232
+ replaced: done.replaced,
3212
3233
  returnTo: done.returnTo
3213
3234
  };
3214
3235
  }
@@ -3306,6 +3327,10 @@ type SocialSignedIn {
3306
3327
  """
3307
3328
  linked: Boolean!
3308
3329
  """
3330
+ Whether this call took over a user who held the e-mail and never proved it.
3331
+ """
3332
+ replaced: Boolean!
3333
+ """
3309
3334
  Whether the session was opened from a device the user had not used.
3310
3335
  """
3311
3336
  newDevice: Boolean!
@@ -3419,5 +3444,5 @@ export {
3419
3444
  useJanus
3420
3445
  };
3421
3446
 
3422
- //# debugId=2FB1478B92324A1E64756E2164756E21
3447
+ //# debugId=B2E92D24AF56A16064756E2164756E21
3423
3448
  //# sourceMappingURL=index.js.map