@softistx/janus-graphql 0.0.0-stage → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +716 -2
  3. package/dist/api-keys/index.d.ts +11 -0
  4. package/dist/api-keys/index.d.ts.map +1 -0
  5. package/dist/api-keys/resolvers/deps.d.ts +39 -0
  6. package/dist/api-keys/resolvers/deps.d.ts.map +1 -0
  7. package/dist/api-keys/resolvers/index.d.ts +39 -0
  8. package/dist/api-keys/resolvers/index.d.ts.map +1 -0
  9. package/dist/api-keys/resolvers/list.d.ts +16 -0
  10. package/dist/api-keys/resolvers/list.d.ts.map +1 -0
  11. package/dist/api-keys/resolvers/manage.d.ts +17 -0
  12. package/dist/api-keys/resolvers/manage.d.ts.map +1 -0
  13. package/dist/api-keys/sdl.d.ts +14 -0
  14. package/dist/api-keys/sdl.d.ts.map +1 -0
  15. package/dist/api-keys/shape.d.ts +38 -0
  16. package/dist/api-keys/shape.d.ts.map +1 -0
  17. package/dist/api-keys/types.d.ts +149 -0
  18. package/dist/api-keys/types.d.ts.map +1 -0
  19. package/dist/avatar/index.d.ts +32 -0
  20. package/dist/avatar/index.d.ts.map +1 -0
  21. package/dist/avatar/resolvers.d.ts +41 -0
  22. package/dist/avatar/resolvers.d.ts.map +1 -0
  23. package/dist/avatar/sdl.d.ts +16 -0
  24. package/dist/avatar/sdl.d.ts.map +1 -0
  25. package/dist/bad-input.d.ts +17 -0
  26. package/dist/bad-input.d.ts.map +1 -0
  27. package/dist/connection/connection.d.ts +36 -0
  28. package/dist/connection/connection.d.ts.map +1 -0
  29. package/dist/connection/credential.d.ts +34 -0
  30. package/dist/connection/credential.d.ts.map +1 -0
  31. package/dist/connection/types.d.ts +61 -0
  32. package/dist/connection/types.d.ts.map +1 -0
  33. package/dist/context/create.d.ts +32 -0
  34. package/dist/context/create.d.ts.map +1 -0
  35. package/dist/context/index.d.ts +9 -0
  36. package/dist/context/index.d.ts.map +1 -0
  37. package/dist/context/registry.d.ts +72 -0
  38. package/dist/context/registry.d.ts.map +1 -0
  39. package/dist/context/resolve.d.ts +20 -0
  40. package/dist/context/resolve.d.ts.map +1 -0
  41. package/dist/device.d.ts +28 -0
  42. package/dist/device.d.ts.map +1 -0
  43. package/dist/directives/apply.d.ts +51 -0
  44. package/dist/directives/apply.d.ts.map +1 -0
  45. package/dist/directives/guard.d.ts +22 -0
  46. package/dist/directives/guard.d.ts.map +1 -0
  47. package/dist/directives/permission/enforce.d.ts +24 -0
  48. package/dist/directives/permission/enforce.d.ts.map +1 -0
  49. package/dist/directives/permission/model.d.ts +35 -0
  50. package/dist/directives/permission/model.d.ts.map +1 -0
  51. package/dist/directives/permission/path.d.ts +31 -0
  52. package/dist/directives/permission/path.d.ts.map +1 -0
  53. package/dist/directives/permission/validate.d.ts +42 -0
  54. package/dist/directives/permission/validate.d.ts.map +1 -0
  55. package/dist/directives/read.d.ts +43 -0
  56. package/dist/directives/read.d.ts.map +1 -0
  57. package/dist/directives/validate.d.ts +39 -0
  58. package/dist/directives/validate.d.ts.map +1 -0
  59. package/dist/directives/words.d.ts +7 -0
  60. package/dist/directives/words.d.ts.map +1 -0
  61. package/dist/errors/denial.d.ts +6 -0
  62. package/dist/errors/denial.d.ts.map +1 -0
  63. package/dist/errors/index.d.ts +12 -0
  64. package/dist/errors/index.d.ts.map +1 -0
  65. package/dist/errors/janus-error.d.ts +20 -0
  66. package/dist/errors/janus-error.d.ts.map +1 -0
  67. package/dist/errors/mask.d.ts +69 -0
  68. package/dist/errors/mask.d.ts.map +1 -0
  69. package/dist/fresh.d.ts +44 -0
  70. package/dist/fresh.d.ts.map +1 -0
  71. package/dist/helpers.d.ts +56 -0
  72. package/dist/helpers.d.ts.map +1 -0
  73. package/dist/index.d.ts +86 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +3393 -0
  76. package/dist/index.js.map +75 -0
  77. package/dist/invitations/index.d.ts +12 -0
  78. package/dist/invitations/index.d.ts.map +1 -0
  79. package/dist/invitations/resolvers/anonymous.d.ts +11 -0
  80. package/dist/invitations/resolvers/anonymous.d.ts.map +1 -0
  81. package/dist/invitations/resolvers/deps.d.ts +38 -0
  82. package/dist/invitations/resolvers/deps.d.ts.map +1 -0
  83. package/dist/invitations/resolvers/index.d.ts +37 -0
  84. package/dist/invitations/resolvers/index.d.ts.map +1 -0
  85. package/dist/invitations/resolvers/owner.d.ts +17 -0
  86. package/dist/invitations/resolvers/owner.d.ts.map +1 -0
  87. package/dist/invitations/sdl/accept.d.ts +7 -0
  88. package/dist/invitations/sdl/accept.d.ts.map +1 -0
  89. package/dist/invitations/sdl/index.d.ts +14 -0
  90. package/dist/invitations/sdl/index.d.ts.map +1 -0
  91. package/dist/invitations/sdl/owner.d.ts +8 -0
  92. package/dist/invitations/sdl/owner.d.ts.map +1 -0
  93. package/dist/invitations/shape.d.ts +63 -0
  94. package/dist/invitations/shape.d.ts.map +1 -0
  95. package/dist/invitations/types/index.d.ts +5 -0
  96. package/dist/invitations/types/index.d.ts.map +1 -0
  97. package/dist/invitations/types/options.d.ts +104 -0
  98. package/dist/invitations/types/options.d.ts.map +1 -0
  99. package/dist/invitations/types/out.d.ts +136 -0
  100. package/dist/invitations/types/out.d.ts.map +1 -0
  101. package/dist/invitations/types/surface.d.ts +18 -0
  102. package/dist/invitations/types/surface.d.ts.map +1 -0
  103. package/dist/map-code.d.ts +10 -0
  104. package/dist/map-code.d.ts.map +1 -0
  105. package/dist/mask-error.d.ts +18 -0
  106. package/dist/mask-error.d.ts.map +1 -0
  107. package/dist/memo.d.ts +16 -0
  108. package/dist/memo.d.ts.map +1 -0
  109. package/dist/options.d.ts +17 -0
  110. package/dist/options.d.ts.map +1 -0
  111. package/dist/passkeys/deps.d.ts +23 -0
  112. package/dist/passkeys/deps.d.ts.map +1 -0
  113. package/dist/passkeys/first-factor.types.d.ts +38 -0
  114. package/dist/passkeys/first-factor.types.d.ts.map +1 -0
  115. package/dist/passkeys/index.d.ts +14 -0
  116. package/dist/passkeys/index.d.ts.map +1 -0
  117. package/dist/passkeys/resolvers.d.ts +23 -0
  118. package/dist/passkeys/resolvers.d.ts.map +1 -0
  119. package/dist/passkeys/sdl.d.ts +14 -0
  120. package/dist/passkeys/sdl.d.ts.map +1 -0
  121. package/dist/passkeys/shape.d.ts +14 -0
  122. package/dist/passkeys/shape.d.ts.map +1 -0
  123. package/dist/passkeys/sign-in.resolvers.d.ts +19 -0
  124. package/dist/passkeys/sign-in.resolvers.d.ts.map +1 -0
  125. package/dist/passkeys/sign-in.sdl.d.ts +16 -0
  126. package/dist/passkeys/sign-in.sdl.d.ts.map +1 -0
  127. package/dist/passkeys/types.d.ts +193 -0
  128. package/dist/passkeys/types.d.ts.map +1 -0
  129. package/dist/plugin.d.ts +59 -0
  130. package/dist/plugin.d.ts.map +1 -0
  131. package/dist/renewal.d.ts +51 -0
  132. package/dist/renewal.d.ts.map +1 -0
  133. package/dist/report.d.ts +29 -0
  134. package/dist/report.d.ts.map +1 -0
  135. package/dist/sdl.d.ts +12 -0
  136. package/dist/sdl.d.ts.map +1 -0
  137. package/dist/second-factor/index.d.ts +12 -0
  138. package/dist/second-factor/index.d.ts.map +1 -0
  139. package/dist/second-factor/resolvers/deps.d.ts +39 -0
  140. package/dist/second-factor/resolvers/deps.d.ts.map +1 -0
  141. package/dist/second-factor/resolvers/index.d.ts +39 -0
  142. package/dist/second-factor/resolvers/index.d.ts.map +1 -0
  143. package/dist/second-factor/resolvers/sign-in.d.ts +10 -0
  144. package/dist/second-factor/resolvers/sign-in.d.ts.map +1 -0
  145. package/dist/second-factor/resolvers/status.d.ts +10 -0
  146. package/dist/second-factor/resolvers/status.d.ts.map +1 -0
  147. package/dist/second-factor/resolvers/step-up.d.ts +16 -0
  148. package/dist/second-factor/resolvers/step-up.d.ts.map +1 -0
  149. package/dist/second-factor/resolvers/writes.d.ts +19 -0
  150. package/dist/second-factor/resolvers/writes.d.ts.map +1 -0
  151. package/dist/second-factor/sdl.d.ts +14 -0
  152. package/dist/second-factor/sdl.d.ts.map +1 -0
  153. package/dist/second-factor/shape.d.ts +18 -0
  154. package/dist/second-factor/shape.d.ts.map +1 -0
  155. package/dist/second-factor/types/index.d.ts +5 -0
  156. package/dist/second-factor/types/index.d.ts.map +1 -0
  157. package/dist/second-factor/types/options.d.ts +61 -0
  158. package/dist/second-factor/types/options.d.ts.map +1 -0
  159. package/dist/second-factor/types/out.d.ts +84 -0
  160. package/dist/second-factor/types/out.d.ts.map +1 -0
  161. package/dist/second-factor/types/surface.d.ts +89 -0
  162. package/dist/second-factor/types/surface.d.ts.map +1 -0
  163. package/dist/social/index.d.ts +10 -0
  164. package/dist/social/index.d.ts.map +1 -0
  165. package/dist/social/resolvers.d.ts +25 -0
  166. package/dist/social/resolvers.d.ts.map +1 -0
  167. package/dist/social/sdl.d.ts +13 -0
  168. package/dist/social/sdl.d.ts.map +1 -0
  169. package/dist/social/shape.d.ts +11 -0
  170. package/dist/social/shape.d.ts.map +1 -0
  171. package/dist/social/types.d.ts +160 -0
  172. package/dist/social/types.d.ts.map +1 -0
  173. package/dist/surface/api.d.ts +16 -0
  174. package/dist/surface/api.d.ts.map +1 -0
  175. package/dist/surface/request.d.ts +10 -0
  176. package/dist/surface/request.d.ts.map +1 -0
  177. package/dist/surface/signed-in.d.ts +30 -0
  178. package/dist/surface/signed-in.d.ts.map +1 -0
  179. package/dist/types.d.ts +117 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/wiring.d.ts +56 -0
  182. package/dist/wiring.d.ts.map +1 -0
  183. package/docs/README.md +26 -0
  184. package/docs/guide/api-keys.md +365 -0
  185. package/docs/guide/avatars.md +129 -0
  186. package/docs/guide/context.md +371 -0
  187. package/docs/guide/directives.md +371 -0
  188. package/docs/guide/errors.md +318 -0
  189. package/docs/guide/federation.md +71 -0
  190. package/docs/guide/invitations.md +269 -0
  191. package/docs/guide/passkeys.md +207 -0
  192. package/docs/guide/second-factor.md +238 -0
  193. package/docs/guide/social.md +190 -0
  194. package/docs/guide/step-up.md +208 -0
  195. package/docs/guide/subscriptions.md +255 -0
  196. package/docs/guide/telemetry.md +45 -0
  197. package/docs/roadmap.md +124 -0
  198. package/docs/troubleshooting.md +1265 -0
  199. package/graphql/janus-api-keys.graphqls +237 -0
  200. package/graphql/janus-avatar.graphqls +19 -0
  201. package/graphql/janus-invitations.graphqls +280 -0
  202. package/graphql/janus-passkey-sign-in.graphqls +40 -0
  203. package/graphql/janus-passkeys.graphqls +134 -0
  204. package/graphql/janus-second-factor.graphqls +199 -0
  205. package/graphql/janus-social.graphqls +155 -0
  206. package/graphql/janus.graphqls +44 -0
  207. package/package.json +80 -5
@@ -0,0 +1,69 @@
1
+ import type { JanusError } from '@softistx/janus';
2
+ import { GraphQLError } from 'graphql';
3
+ import { type MappedCode } from '../map-code';
4
+ /**
5
+ * Yoga's `maskError` signature (and envelop 5's, which has no `context`): what
6
+ * a `fallback` is.
7
+ */
8
+ export type MaskError = (error: unknown, message: string, isDev?: boolean, context?: any) => Error;
9
+ /**
10
+ * What `janusMaskError()` answers: it fits Yoga's `maskError`, envelop 5's
11
+ * (`isDev` third) and envelop 6's (`context` third) alike, so the third
12
+ * argument is told apart by its type.
13
+ */
14
+ export type JanusMaskError = (error: unknown, message: string, isDevOrContext?: unknown, context?: unknown) => Error;
15
+ /** What `janusMaskError()` takes. */
16
+ export interface JanusMaskErrorOptions {
17
+ /**
18
+ * Called once with every `JanusError` answered 5xx — `STORE_FAILED`,
19
+ * `UNSUPPORTED`, `PERMISSION_DEPTH` — whichever path it took: a
20
+ * directive, `requireUser()`, `can()`, or a resolver that let it through.
21
+ * Its `slot`, `operation`, `reason` and cause are for your logs; the
22
+ * response never carries them.
23
+ *
24
+ * **It cannot change the answer**: one that throws, or rejects, is a
25
+ * `process.emitWarning`, and the 503 is sent all the same.
26
+ */
27
+ readonly report?: (error: JanusError) => unknown;
28
+ /**
29
+ * Every error that is not a `JanusError`; default: Yoga's `maskError` behaviour, see `janusMaskError()`.
30
+ * It has Yoga's signature: `isDev` third, `context` fourth, also under envelop 6, which sends the context third.
31
+ */
32
+ readonly fallback?: MaskError;
33
+ /**
34
+ * Answers a code of yours in place of one of the package's. Called with
35
+ * the `extensions.code` of every `GraphQLError` the mask is about to
36
+ * return — a directive's `UNAUTHENTICATED`, `FORBIDDEN`,
37
+ * `STEP_UP_REQUIRED`, a resolver's `NOT_FOUND`, `SERVICE_UNAVAILABLE`… —
38
+ * and that error. Return `undefined` to keep the answer as it is.
39
+ * Otherwise the error is rebuilt with `code` (and `message`, and
40
+ * `extensions.http.status`, when given), keeping its other extensions,
41
+ * nodes, source, positions, path and `originalError`.
42
+ */
43
+ readonly mapCode?: (code: string, error: GraphQLError) => MappedCode | undefined;
44
+ }
45
+ /**
46
+ * Yoga's `maskedErrors.maskError`: a `JanusError` a resolver let through is
47
+ * answered with its code and status — `STORE_FAILED` as 503, never masked
48
+ * into a 500 and never a denial — and every other error goes to `fallback`.
49
+ *
50
+ * Without a `fallback`, every other error is masked as Yoga's own `maskError`
51
+ * does: a `GraphQLError` of your own is kept, anything else becomes `message`
52
+ * with `INTERNAL_SERVER_ERROR` and `unexpected: true` (so a failure with no
53
+ * `data`, such as a context factory that throws, is still HTTP 500), keeping
54
+ * `extensions.http`, and showing the original error only in development
55
+ * (`isDev`). Passing Yoga's `maskError` as `fallback` is no longer needed.
56
+ *
57
+ * ```ts
58
+ * import { createYoga } from 'graphql-yoga';
59
+ * createYoga({
60
+ * schema,
61
+ * plugins,
62
+ * maskedErrors: {
63
+ * maskError: janusMaskError({ report: (error) => logger.error(error) }),
64
+ * },
65
+ * });
66
+ * ```
67
+ */
68
+ export declare function janusMaskError(options?: JanusMaskErrorOptions | MaskError): JanusMaskError;
69
+ //# sourceMappingURL=mask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../../src/errors/mask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;AAKxD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,EAEf,OAAO,CAAC,EAAE,GAAG,KACT,KAAK,CAAC;AAEX;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,CAC5B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,OAAO,EACxB,OAAO,CAAC,EAAE,OAAO,KACb,KAAK,CAAC;AAEX,qCAAqC;AACrC,MAAM,WAAW,qBAAqB;IACrC;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IACjD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,YAAY,KACf,UAAU,GAAG,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAC7B,OAAO,GAAE,qBAAqB,GAAG,SAAc,GAC7C,cAAc,CAgBhB"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Freshness: whether the request's session proved who it is recently enough
3
+ * — the check `@fresh` runs before a field, and `requireFresh()` in a
4
+ * resolver. Both are `@softistx/janus`'s `assertFresh`, on the clock given to
5
+ * `useJanus({ clock })`.
6
+ */
7
+ import { type Duration, type Principal, type Session } from '@softistx/janus';
8
+ /**
9
+ * The request's session, once it proved who it is less than `maxAgeMs` ago
10
+ * — or a denial: `UNAUTHENTICATED` 401 for an anonymous request,
11
+ * `STEP_UP_REQUIRED` 403 for an older session or, under `apiKey: true`, an
12
+ * API key (which has no session and is never fresh). A store that cannot answer is
13
+ * `SERVICE_UNAVAILABLE` 503, never either of them.
14
+ */
15
+ export declare function freshSession(janus: {
16
+ session(): Promise<Session | null>;
17
+ principal?(): Promise<Principal<{
18
+ readonly id: string;
19
+ }> | null>;
20
+ }, maxAgeMs: number): Promise<Session>;
21
+ /**
22
+ * The request's session, once it proved who it is less than `maxAge` ago —
23
+ * signed in, or confirmed since by `auth.stepUp.confirm` — or a denial:
24
+ * `UNAUTHENTICATED` 401 for an anonymous request, `STEP_UP_REQUIRED` 403 for
25
+ * an older session, which tells the client to ask for a step-up.
26
+ *
27
+ * ```ts
28
+ * await requireFresh(ctx, '10m'); // before changing the e-mail
29
+ * ```
30
+ *
31
+ * `maxAge` is a duration with its unit — `'10m'`, `'600s'` — never a bare
32
+ * number, which `@softistx/janus` reads as milliseconds where `@fresh` reads
33
+ * seconds: a `TypeError`, as any other malformed duration.
34
+ */
35
+ export declare function requireFresh(ctx: {
36
+ readonly janus: {
37
+ user(): Promise<unknown>;
38
+ session(): Promise<Session | null>;
39
+ principal?(): Promise<Principal<{
40
+ readonly id: string;
41
+ }> | null>;
42
+ };
43
+ }, maxAge: Exclude<Duration, number>): Promise<Session>;
44
+ //# sourceMappingURL=fresh.d.ts.map
@@ -0,0 +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,CACjC,GAAG,EAAE;IACJ,QAAQ,CAAC,KAAK,EAAE;QACf,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACnC,SAAS,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC;YAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,GAAG,IAAI,CAAC,CAAC;KACjE,CAAC;CACF,EACD,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC,CAQlB"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The two calls a resolver makes itself: `requireUser` where a directive
3
+ * would not do, and `can` for a check the schema cannot express.
4
+ */
5
+ import type { CheckArgs, CheckableOf, ModelConfig, ObjectRef, ObjectTypeOf, Permissions } from '@softistx/janus/permissions';
6
+ /** What `requireUser()` takes. */
7
+ export interface RequireUserOptions<T extends string> {
8
+ /**
9
+ * Only a user of this type, or of one of these — never an empty list,
10
+ * which no user could pass: any other is `FORBIDDEN`.
11
+ */
12
+ readonly type?: T | readonly [T, ...T[]];
13
+ }
14
+ /**
15
+ * The signed-in user, narrowed to `type` when it is given — or a denial:
16
+ * `UNAUTHENTICATED` 401 for an anonymous request, `FORBIDDEN` 403 for a user
17
+ * of another type. A store that cannot answer is `SERVICE_UNAVAILABLE` 503,
18
+ * never either of them.
19
+ *
20
+ * ```ts
21
+ * const staff = await requireUser(ctx, { type: 'staff' });
22
+ * staff.username; // typed: a staff member
23
+ * ```
24
+ */
25
+ export declare function requireUser<U extends {
26
+ readonly type: string;
27
+ }, const T extends U['type'] = U['type']>(ctx: {
28
+ readonly janus: {
29
+ user(): Promise<U | null>;
30
+ };
31
+ }, options?: RequireUserOptions<T>): Promise<Extract<U, {
32
+ readonly type: T;
33
+ }>>;
34
+ /**
35
+ * Whether the request's user holds `permission` on `object`, typed as
36
+ * `access.can` is: the permission must be one the object's type declares,
37
+ * the object must carry every field its `fromField`s read, and `{ ctx }` is
38
+ * required exactly when a condition is reachable. Anonymous answers `false`.
39
+ *
40
+ * **A failure throws**: a store that cannot answer is `SERVICE_UNAVAILABLE`
41
+ * 503, never `false`.
42
+ *
43
+ * ```ts
44
+ * if (!(await can(ctx, 'edit', { type: 'record', ...record }))) return null;
45
+ * ```
46
+ */
47
+ export declare function can<C extends ModelConfig, const T extends ObjectTypeOf<C>, const P extends CheckableOf<C, T>>(ctx: {
48
+ readonly janus: {
49
+ user(): Promise<{
50
+ readonly type: string;
51
+ readonly id: string;
52
+ } | null>;
53
+ readonly access: Pick<Permissions<C>, 'can'>;
54
+ };
55
+ }, permission: P, object: ObjectRef<C, T>, ...options: CheckArgs<C, T, P>): Promise<boolean>;
56
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,6BAA6B,CAAC;AAIrC,kCAAkC;AAClC,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM;IACnD;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;CACzC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAChC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACnC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAErC,GAAG,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE;QAAE,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;KAAE,CAAA;CAAE,EACtD,OAAO,GAAE,kBAAkB,CAAC,CAAC,CAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,CAiB3C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,GAAG,CACxB,CAAC,SAAS,WAAW,EACrB,KAAK,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAC/B,KAAK,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAEjC,GAAG,EAAE;IACJ,QAAQ,CAAC,KAAK,EAAE;QACf,IAAI,IAAI,OAAO,CAAC;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAC,CAAC;QACvE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;KAC7C,CAAC;CACF,EACD,UAAU,EAAE,CAAC,EACb,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,GAAG,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAalB"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * `@softistx/janus-graphql` — `@softistx/janus` in a GraphQL server.
3
+ *
4
+ * - `useJanus({ auth, types?, access?, type?, clock?, loaders?, conditions? })` —
5
+ * the envelop plugin: `ctx.janus` on every request, and the directives —
6
+ * `@authenticated`, `@fresh`, `@permission` — applied to the schema;
7
+ * - `janusTypeDefs` — the directives' SDL, also shipped as
8
+ * `graphql/janus.graphqls`;
9
+ * - `applyJanusDirectives(schema, { auth })` — the schema transform alone;
10
+ * - `requireUser(ctx, { type? })`, `requireFresh(ctx, maxAge)` and
11
+ * `can(ctx, permission, object)` — the calls a resolver makes itself;
12
+ * - `janusMaskError({ report?, fallback?, mapCode? })` — Yoga's `maskError`: a
13
+ * `JanusError` as its code and status, `STORE_FAILED` as 503 and never as
14
+ * 401 or 403, and every 5xx handed to `report`; `mapCode` answers your
15
+ * own codes. `janusErrorOf(error)` finds the `JanusError` under a
16
+ * resolver's error.
17
+ * - `janusGraphQLError(error)` — a `JanusError` as the `GraphQLError` the
18
+ * client reads, and `denial(code, message?)` — a denial of your own.
19
+ * - `janusConnection({ auth, access?, type?, clock?, upgrade? })` —
20
+ * subscriptions over graphql-ws: `onConnect` and `context` for its
21
+ * `useServer()`, a connection authenticated from its `connectionParams`
22
+ * or its upgrade request.
23
+ *
24
+ * - `janusAvatarTypeDefs`, `toJanusAvatar(user)` and `avatarResolvers({ url })`
25
+ * — the opt-in `JanusAvatar` type, its `url(size:)` pointing at your own
26
+ * authenticated route (`graphql/janus-avatar.graphqls`).
27
+ *
28
+ * - `janusSocialTypeDefs` and `socialResolvers({ auth, type? })` — the opt-in
29
+ * social sign-in fields: `socialSignInStart`, `socialSignInComplete`,
30
+ * `linkSocial`, `unlinkSocial` and `socialLinks`
31
+ * (`graphql/janus-social.graphqls`).
32
+ *
33
+ * - `janusSecondFactorTypeDefs` and `secondFactorResolvers({ auth, type?, answerToken?,
34
+ * device?, freshWithin?, guard?, sendStepUpCode? })` — the opt-in TOTP fields: the
35
+ * sign-in challenge, `confirmSecondFactor`, `recoverSecondFactor`, `enrollSecondFactor`,
36
+ * `activateSecondFactor`, `regenerateRecoveryCodes`, `disableSecondFactor`, `secondFactor`,
37
+ * `requestStepUp`, `confirmStepUp` and `sessionConfirmedUntil`
38
+ * (`graphql/janus-second-factor.graphqls`); `secondFactorViewerFields` puts two of them
39
+ * on your `Viewer`.
40
+ * - `janusPasskeyTypeDefs` and `passkeyResolvers({ auth, type?, answerToken?, device? })`
41
+ * — the opt-in passkey fields: `passkeys`, `passkeyRegistrationOptions`,
42
+ * `registerPasskey`, `renamePasskey`, `removePasskey` and
43
+ * `confirmSecondFactorPasskey` (`graphql/janus-passkeys.graphqls`);
44
+ * `janusPasskeySignInTypeDefs` and `passkeyResolvers({ auth, firstFactor: true })`
45
+ * add `passkeySignInOptions` and `passkeySignIn`
46
+ * (`graphql/janus-passkey-sign-in.graphqls`), and `auth` may be a function
47
+ * of the context.
48
+ *
49
+ * - `janusInvitationTypeDefs` and `invitationResolvers({ auth, authorize, sendInvitation?,
50
+ * answerCode?, answerToken?, device?, inviterType? })` — the opt-in invitation fields:
51
+ * `invitations`, `issueInvitation`, `resendInvitation`, `revokeInvitation`,
52
+ * `invitationPreview` and `acceptInvitation` (`graphql/janus-invitations.graphqls`).
53
+ *
54
+ * - `apiKeysTypeDefs` and `apiKeysResolvers({ auth, lifetimes, authorize: { create, list,
55
+ * revoke }, bound? })` — the opt-in API key fields: `apiKeys`, `boundApiKeys`,
56
+ * `apiKeyLifetimes`, `createApiKey` (the secret answered once) and `revokeApiKey`
57
+ * (`graphql/janus-api-keys.graphqls`).
58
+ *
59
+ * - `deviceOf(request, options?)`, `sendDevice(request, deviceToken, options?)`,
60
+ * `DEVICE_COOKIE` and `DeviceCookieOptions` — the device cookie a sign-in
61
+ * mutation reads and sets.
62
+ *
63
+ * It defines no error class: every denial goes through `denial()` and is a
64
+ * `GraphQLError` (the one other error is `avatarResolvers`' bad-size
65
+ * `BAD_USER_INPUT`), and what it lets through is `@softistx/janus`'s own.
66
+ */
67
+ export { type ApiKeyCreateSubject, type ApiKeyLifetimes, type ApiKeyListSubject, type ApiKeyRevokeSubject, type ApiKeySubjectBase, type ApiKeysAuth, type ApiKeysAuthorize, type ApiKeysResolvers, type ApiKeysResolversOptions, apiKeysResolvers, apiKeysTypeDefs, } from './api-keys';
68
+ export { type AvatarOwner, type AvatarParent, type AvatarResolvers, type AvatarResolversOptions, avatarResolvers, janusAvatarTypeDefs, toJanusAvatar, } from './avatar';
69
+ export { janusConnection } from './connection/connection';
70
+ export type { ConnectionContext, JanusConnection, JanusConnectionOptions, } from './connection/types';
71
+ export { DEVICE_COOKIE, type DeviceCookieOptions, deviceOf, sendDevice, } from './device';
72
+ export { applyJanusDirectives, type JanusDirectivesOptions, } from './directives/apply';
73
+ export { type DenialCode, denial, type JanusMaskError, type JanusMaskErrorOptions, janusGraphQLError, janusMaskError, type MaskError, } from './errors';
74
+ export { requireFresh } from './fresh';
75
+ export { can, type RequireUserOptions, requireUser } from './helpers';
76
+ export { type InvitationAction, type InvitationAuth, type InvitationResolvers, type InvitationResolversOptions, type InvitationSubject, invitationResolvers, janusInvitationTypeDefs, } from './invitations';
77
+ export type { MappedCode } from './map-code';
78
+ export { janusPasskeySignInTypeDefs, janusPasskeyTypeDefs, type PasskeyAuth, type PasskeyAuthSource, type PasskeyFirstFactorSurface, type PasskeyFirstFactorTypeApi, type PasskeyManageSurface, type PasskeyManageTypeApi, type PasskeyResolvers, type PasskeyResolversOptions, type PasskeySurface, type PasskeyTypeApi, passkeyResolvers, } from './passkeys';
79
+ export { useJanus } from './plugin';
80
+ export { janusErrorOf } from './report';
81
+ export { janusTypeDefs } from './sdl';
82
+ export { type ChallengeIn, type ChallengeOut, janusSecondFactorTypeDefs, type SecondFactorAction, type SecondFactorAuth, type SecondFactorAuthSource, type SecondFactorResolvers, type SecondFactorResolversOptions, type SecondFactorSurface, type SecondFactorTypeApi, type SecondFactorViewerFields, secondFactorChallengeOut, secondFactorResolvers, secondFactorViewerFields, } from './second-factor';
83
+ export { janusSocialTypeDefs, type SocialAuth, type SocialAuthSource, type SocialResolvers, type SocialResolversOptions, socialResolvers, } from './social';
84
+ export type { Auth, AuthContext, AuthSource, JanusContext, JanusOnContext, JanusOptions, UserOfAuth, } from './types';
85
+ export type { Conditions, LoadedObject, Loaders } from './wiring';
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}