@softistx/janus-graphql 0.0.0-stage → 0.30.2

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,160 @@
1
+ /**
2
+ * The types of the social resolvers: the part of `janus()`'s answer they
3
+ * call, their options, and the resolver map they return.
4
+ */
5
+ import type { Session, SocialCompleted, SocialFlowStart, SocialLink } from '@softistx/janus';
6
+ /** The user as these resolvers read one. */
7
+ export type AnyUser = {
8
+ readonly type: string;
9
+ readonly id: string;
10
+ };
11
+ /**
12
+ * The part of `janus()`'s answer these resolvers call: `social`, the session
13
+ * `cookie` and `authenticate`. Loosely typed on purpose: the providers and
14
+ * types of your instance narrow its own calls.
15
+ */
16
+ export interface SocialAuth {
17
+ authenticate(request: Request, options?: {
18
+ readonly type?: string;
19
+ }): Promise<{
20
+ readonly via: 'session';
21
+ readonly user: AnyUser;
22
+ readonly session: Session;
23
+ readonly token: string;
24
+ readonly renewed: boolean;
25
+ } | null>;
26
+ readonly cookie: {
27
+ serialize(token: string, session: Session): string;
28
+ };
29
+ readonly social: {
30
+ start(options: {
31
+ readonly provider: string;
32
+ readonly returnTo?: string;
33
+ readonly type?: string;
34
+ }): Promise<SocialFlowStart>;
35
+ link(current: {
36
+ readonly via: 'session';
37
+ readonly user: AnyUser;
38
+ readonly session: Session;
39
+ readonly token: string;
40
+ readonly renewed: boolean;
41
+ }, options: {
42
+ readonly provider: string;
43
+ readonly returnTo?: string;
44
+ }): Promise<SocialFlowStart>;
45
+ complete(input: {
46
+ readonly callback: URLSearchParams;
47
+ readonly flow: string;
48
+ readonly current?: {
49
+ readonly user: {
50
+ readonly id: string;
51
+ };
52
+ } | null;
53
+ }): Promise<SocialCompleted<AnyUser>>;
54
+ unlink(user: {
55
+ readonly id: string;
56
+ }, link: {
57
+ readonly provider: string;
58
+ readonly accountId: string;
59
+ }): Promise<boolean>;
60
+ list(user: {
61
+ readonly id: string;
62
+ }): Promise<readonly SocialLink[]>;
63
+ };
64
+ }
65
+ /**
66
+ * `auth` as `socialResolvers()` takes it: the instance, or a function of the
67
+ * GraphQL context answering the instance that serves the request (`null` or
68
+ * `undefined` for none), as {@link PasskeyAuthSource} does.
69
+ */
70
+ export type SocialAuthSource<A = SocialAuth, Ctx = Context> = A | ((ctx: Ctx) => A | null | undefined | Promise<A | null | undefined>);
71
+ /** What `socialResolvers()` takes. */
72
+ export interface SocialResolversOptions {
73
+ /**
74
+ * What `janus()` answered (the `social` surface needs a user type with
75
+ * `social`), or a function of the GraphQL context answering the instance
76
+ * that serves the request. `null`, `undefined` or an instance with no
77
+ * `social` is refused with `UNAUTHENTICATED`.
78
+ */
79
+ readonly auth: SocialAuthSource;
80
+ /**
81
+ * The user type that signs in, links and lists. Needed when several user
82
+ * types configure `social`; it also limits `socialLinks`, `linkSocial` and
83
+ * `unlinkSocial` to that type's users.
84
+ */
85
+ readonly type?: string;
86
+ /**
87
+ * Answer the session token in `SocialSignedIn.token` instead of setting
88
+ * the session cookie, for a backend-for-frontend that keeps the token in
89
+ * its own cookie and forwards it as `Authorization: Bearer`. Off by
90
+ * default: the cookie is set and `token` is null.
91
+ */
92
+ readonly answerToken?: boolean;
93
+ }
94
+ /** A GraphQL context as these resolvers read it. */
95
+ export interface Context {
96
+ readonly request?: Request;
97
+ }
98
+ /** The resolver map, keyed as `createSchema` expects. */
99
+ export interface SocialResolvers {
100
+ readonly Query: {
101
+ readonly socialLinks: (parent: unknown, args: unknown, ctx: Context) => Promise<readonly LinkOut[]>;
102
+ };
103
+ readonly Mutation: {
104
+ readonly socialSignInStart: (parent: unknown, args: {
105
+ readonly provider: string;
106
+ readonly returnTo?: string | null;
107
+ }, ctx?: Context) => Promise<FlowOut>;
108
+ readonly socialSignInComplete: (parent: unknown, args: {
109
+ readonly callbackUrl: string;
110
+ readonly flow: string;
111
+ }, ctx: Context) => Promise<CompletedOut>;
112
+ readonly linkSocial: (parent: unknown, args: {
113
+ readonly provider: string;
114
+ readonly returnTo?: string | null;
115
+ }, ctx: Context) => Promise<FlowOut>;
116
+ readonly unlinkSocial: (parent: unknown, args: {
117
+ readonly provider: string;
118
+ readonly accountId: string;
119
+ }, ctx: Context) => Promise<boolean>;
120
+ };
121
+ readonly SocialSignInResult: {
122
+ readonly __resolveType: (result: CompletedOut) => string;
123
+ };
124
+ }
125
+ export interface LinkOut {
126
+ readonly provider: string;
127
+ readonly accountId: string;
128
+ readonly email: string | null;
129
+ readonly linkedAt: string;
130
+ }
131
+ export interface FlowOut {
132
+ readonly url: string;
133
+ readonly flow: string;
134
+ readonly expiresAt: string;
135
+ }
136
+ export type CompletedOut = {
137
+ readonly status: 'signedIn';
138
+ /** For a `user` field of your own on `SocialSignedIn`. */
139
+ readonly user: AnyUser;
140
+ /** The session token with `answerToken`, else null. */
141
+ readonly token: string | null;
142
+ readonly userId: string;
143
+ readonly expiresAt: string;
144
+ readonly created: boolean;
145
+ readonly linked: boolean;
146
+ readonly newDevice: boolean;
147
+ readonly returnTo: string | null;
148
+ } | {
149
+ readonly status: 'secondFactor';
150
+ readonly challenge: string;
151
+ readonly expiresAt: string;
152
+ readonly methods: readonly string[];
153
+ readonly passkeyOptions: string | null;
154
+ readonly returnTo: string | null;
155
+ } | {
156
+ readonly status: 'linked';
157
+ readonly link: LinkOut;
158
+ readonly returnTo: string | null;
159
+ };
160
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources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EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GACD;IACA,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GACD;IACA,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** The surface of a user type on `auth`, shared by the passkey and second-factor modules. */
2
+ export interface SurfaceSpec<Api extends object> {
3
+ /** The caller's name for its error messages, e.g. `passkeyResolvers`. */
4
+ readonly name: string;
5
+ /** The key that is on `auth` itself when it holds one user type. */
6
+ readonly key: keyof Api;
7
+ /** Whether the holder has everything the caller needs. */
8
+ readonly complete: (holder: Partial<Api> | undefined) => boolean;
9
+ /** The message tail when `auth` is the holder, after `<name>(): `. */
10
+ readonly missing: string;
11
+ /** The message tail when `auth[type]` is the holder, after `<name>(): `. */
12
+ readonly missingOf: (type: string) => string;
13
+ }
14
+ /** The surface of the user type: the instance itself with one type, `auth[type]` with several. */
15
+ export declare function apiOf<Api extends object>(auth: object, type: string | undefined, spec: SurfaceSpec<Api>): Api;
16
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/surface/api.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAE7F,MAAM,WAAW,WAAW,CAAC,GAAG,SAAS,MAAM;IAC9C,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,KAAK,OAAO,CAAC;IACjE,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7C;AAED,kGAAkG;AAClG,wBAAgB,KAAK,CAAC,GAAG,SAAS,MAAM,EACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,GACpB,GAAG,CAaL"}
@@ -0,0 +1,10 @@
1
+ /** The request of a resolver's context, shared by the passkey, social and second-factor modules. */
2
+ /**
3
+ * The request: the session and device cookies are HTTP, so a context with none
4
+ * is a wiring mistake. `name` is the caller's, e.g. `socialResolvers`, for the
5
+ * error message.
6
+ */
7
+ export declare function requestOf(ctx: {
8
+ readonly request?: Request;
9
+ } | undefined, name: string): Request;
10
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/surface/request.ts"],"names":[],"mappings":"AAAA,oGAAoG;AAEpG;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,GAAG,EAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,EAC/C,IAAI,EAAE,MAAM,GACV,OAAO,CAOT"}
@@ -0,0 +1,30 @@
1
+ /** The sign-in answer's side effects, shared by the passkey, second-factor and social modules. */
2
+ import type { SignedIn } from '@softistx/janus';
3
+ import { type DeviceCookieOptions } from '../device';
4
+ /** What the answer reads on the user type's cookie surface and on the options. */
5
+ export interface SignedInSink {
6
+ readonly auth: {
7
+ readonly cookie: {
8
+ serialize(token: string, session: SignedIn<unknown>['session']): string;
9
+ };
10
+ };
11
+ readonly answerToken: boolean;
12
+ /** The device cookie's attributes, or `undefined` when devices are not tracked. */
13
+ readonly device: DeviceCookieOptions | undefined;
14
+ }
15
+ /**
16
+ * A completed sign-in's cookies and fields: the session cookie unless the
17
+ * token is answered (then the response is `no-store`, as it carries a
18
+ * session token), the device cookie when the device is new to track, then
19
+ * the fields every sign-in answer shares.
20
+ */
21
+ export declare function signedInAnswer<U extends {
22
+ readonly id: string;
23
+ }>({ auth, answerToken, device }: SignedInSink, request: Request, done: SignedIn<U>): {
24
+ user: U;
25
+ token: string | null;
26
+ userId: string;
27
+ expiresAt: string;
28
+ newDevice: boolean;
29
+ };
30
+ //# sourceMappingURL=signed-in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-in.d.ts","sourceRoot":"","sources":["../../src/surface/signed-in.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAElG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,mBAAmB,EAAc,MAAM,WAAW,CAAC;AAGjE,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,IAAI,EAAE;QACd,QAAQ,CAAC,MAAM,EAAE;YAChB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;SACxE,CAAC;KACF,CAAC;IACF,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACjD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAC/D,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,YAAY,EAC3C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAWhB,IAAI;IACJ,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;EAEV"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The public types: what `useJanus()` takes, and what it puts on the
3
+ * GraphQL context. Nothing here runs.
4
+ */
5
+ import type { ApiKey, Clock, Principal, Session, SharedApi } from '@softistx/janus';
6
+ import type { PermissionWiringOf } from './wiring';
7
+ /**
8
+ * Anything `janus()` answered: the part of it this package calls. `cookie`
9
+ * is what `useJanus()` sends a renewed session again with; an `auth` without
10
+ * one — a wrapper of your own — sends none.
11
+ */
12
+ export type Auth<U extends {
13
+ readonly type: string;
14
+ }> = Pick<SharedApi<U>, 'authenticate' | 'types'> & Partial<Pick<SharedApi<U>, 'cookie'>>;
15
+ /** The users an `auth` instance knows, as a union narrowed by `user.type`. */
16
+ export type UserOfAuth<A> = A extends Auth<infer U> ? U : never;
17
+ /**
18
+ * What a resolver given as `useJanus({ auth })` is called with: the context
19
+ * the request's `ctx` is built from — `request` over HTTP, `extra` and
20
+ * `connectionParams` over graphql-ws.
21
+ */
22
+ export type AuthContext = {
23
+ readonly request?: Request;
24
+ } & Readonly<Record<string, unknown>>;
25
+ /**
26
+ * `auth` as `useJanus()` and `janusConnection()` take it: what `janus()`
27
+ * answered, or a function of the request's context (`Ctx`) answering the
28
+ * instance that serves it — `null` for none. Called once per context, the
29
+ * first time `user()` or `session()` asks.
30
+ */
31
+ export type AuthSource<A, Ctx = AuthContext> = A | ((ctx: Ctx) => A | null | undefined | Promise<A | null | undefined>);
32
+ /**
33
+ * What `useJanus()` takes. `loaders` and `conditions` are what `@permission`
34
+ * needs beside `access`, typed from its model — see `Loaders` and
35
+ * `Conditions`.
36
+ */
37
+ export type JanusOptions<A, P, T extends string, K extends boolean = false> = {
38
+ /**
39
+ * What `janus()` answered — or a function of the request's context
40
+ * answering the instance that serves it, to serve several issuers from one
41
+ * server. See {@link AuthSource}.
42
+ */
43
+ readonly auth: AuthSource<A>;
44
+ /**
45
+ * The user types the schema's directives may name, when `auth` is a
46
+ * function (there is no instance to read `types` from at start-up). Left
47
+ * out, a `type:` of a directive is not checked against any. Ignored
48
+ * with an instance, whose own `types` are used.
49
+ */
50
+ readonly types?: readonly UserOfAuth<A>['type'][];
51
+ /**
52
+ * What `permissions()` answered: `ctx.janus.access`, what `can()` and
53
+ * `@permission` ask. Absent, the context has no `access`, and `can()` does
54
+ * not compile.
55
+ */
56
+ readonly access?: P;
57
+ /** Only a user of this type is authenticated here; any other is anonymous. */
58
+ readonly type?: T;
59
+ /**
60
+ * The clock `@fresh` and `requireFresh()` read: the one given to
61
+ * `janus()`, when it is not the system's — `fixedClock` in a spec.
62
+ */
63
+ readonly clock?: Clock;
64
+ /**
65
+ * Accept an API key beside a session (`authenticate(request, { apiKey:
66
+ * true })`; needs `janus({ apiKeys })`). `ctx.janus` then also has
67
+ * `principal()` and `apiKey()`. Off by default: a request that presented a
68
+ * key is anonymous, and `session()` is never `null` for a signed-in user.
69
+ *
70
+ * With it on, `session()` is `null` for a key, so a resolver that reads
71
+ * `session()` must expect it; `@fresh` refuses a key.
72
+ */
73
+ readonly apiKey?: K;
74
+ } & PermissionWiringOf<P, {
75
+ readonly janus: JanusOnContext<Extract<UserOfAuth<A>, {
76
+ readonly type: T;
77
+ }>, P, K>;
78
+ }>;
79
+ /**
80
+ * `ctx.janus`, one per request.
81
+ *
82
+ * `user()` and `session()` call `auth.authenticate` on the request the first
83
+ * time either is asked, and never when neither is: a query that reads no
84
+ * guarded field costs no store call. Both share that one answer.
85
+ */
86
+ export type JanusOnContext<U, P, K extends boolean = false> = {
87
+ /**
88
+ * Who the request belongs to, or `null` for an anonymous one. **An outage
89
+ * is not anonymous**: a store that cannot answer rejects with
90
+ * `STORE_FAILED`, answered 503.
91
+ */
92
+ user(): Promise<U | null>;
93
+ /** The session the request presented, or `null` for an anonymous one. */
94
+ session(): Promise<Session | null>;
95
+ } & ([K] extends [true] ? {
96
+ /**
97
+ * Whoever the request belongs to — a session or an API key, narrowed
98
+ * on `via` — or `null` for an anonymous one. Shares `user()`'s answer.
99
+ */
100
+ principal(): Promise<Principal<U> | null>;
101
+ /** The key the request presented, or `null` for a session or no one. */
102
+ apiKey(): Promise<ApiKey | null>;
103
+ } : unknown) & ([P] extends [undefined] ? unknown : {
104
+ readonly access: P;
105
+ });
106
+ /**
107
+ * The context `useJanus()` adds to, for your resolvers:
108
+ * `YogaInitialContext & JanusContext<typeof auth, typeof access>`.
109
+ *
110
+ * `T` narrows the user to the types `useJanus({ type })` was given.
111
+ */
112
+ export type JanusContext<A, P = undefined, T extends UserOfAuth<A>['type'] = UserOfAuth<A>['type'], K extends boolean = false> = {
113
+ readonly janus: JanusOnContext<Extract<UserOfAuth<A>, {
114
+ readonly type: T;
115
+ }>, P, K>;
116
+ };
117
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,MAAM,EACN,KAAK,EACL,SAAS,EACT,OAAO,EACP,SAAS,EACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;GAIG;AACH,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,GACA,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEvC,8EAA8E;AAC9E,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC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;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,IAAI;IAC7D;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,yEAAyE;IACzE,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACnC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GACpB;IACA;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,wEAAwE;IACxE,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,GACV,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CACvB,CAAC,EACD,CAAC,GAAG,SAAS,EACb,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EACvD,CAAC,SAAS,OAAO,GAAG,KAAK,IACtB;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,CAC7B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,EAC5C,CAAC,EACD,CAAC,CACD,CAAC;CACF,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The types of what `@permission` takes from `useJanus()` beside `access`:
3
+ * `loaders`, the objects it checks by id, and `conditions`, the `ctx` a
4
+ * condition tests. Typed from the model `access` was built on. Nothing here
5
+ * runs.
6
+ */
7
+ import type { CheckableOf, CtxOf, FieldsOf, ModelConfig, ObjectRef, ObjectTypeOf, PermissionModel } from '@softistx/janus/permissions';
8
+ type Awaitable<V> = V | Promise<V>;
9
+ /** The model configuration of a `permissions()` instance; `never` for anything else. */
10
+ export type ModelConfigOf<P> = P extends {
11
+ readonly model: PermissionModel<infer C>;
12
+ } ? C : never;
13
+ /**
14
+ * An object of type `T` as a loader answers it: its id, **every field a
15
+ * `fromField` of its type reads**, and whatever else it carries.
16
+ */
17
+ export type LoadedObject<C extends ModelConfig, T extends ObjectTypeOf<C>> = {
18
+ readonly id: string;
19
+ } & {
20
+ readonly [F in FieldsOf<C, T>]: string | null;
21
+ };
22
+ /** Every condition any permission of `T` reaches, as one `ctx`; `never` when none does. */
23
+ export type ConditionCtxOf<C extends ModelConfig, T extends ObjectTypeOf<C>> = CtxOf<C, T, CheckableOf<C, T>>;
24
+ type Loader<C extends ModelConfig, T extends ObjectTypeOf<C>, Ctx> = {
25
+ load(id: string, ctx: Ctx): Awaitable<LoadedObject<C, T> | null>;
26
+ }['load'];
27
+ type Condition<C extends ModelConfig, T extends ObjectTypeOf<C>, Ctx> = {
28
+ condition(object: ObjectRef<C, T>, ctx: Ctx): Awaitable<ConditionCtxOf<C, T>>;
29
+ }['condition'];
30
+ /**
31
+ * `useJanus({ loaders })`: per object type, the object whose id a request
32
+ * names, or `null` when there is none — answered `NOT_FOUND`. Required for a
33
+ * type with a `fromField` whose id `@permission` reads from `args`.
34
+ */
35
+ export type Loaders<C extends ModelConfig, Ctx> = {
36
+ readonly [T in ObjectTypeOf<C>]?: Loader<C, T, Ctx>;
37
+ };
38
+ /**
39
+ * `useJanus({ conditions })`: per object type whose permissions reach a
40
+ * `when()`, the `ctx` it tests, from the object and the request's context.
41
+ */
42
+ export type Conditions<C extends ModelConfig, Ctx> = {
43
+ readonly [T in ObjectTypeOf<C> as [ConditionCtxOf<C, T>] extends [never] ? never : T]?: Condition<C, T, Ctx>;
44
+ };
45
+ /** The options `@permission` reads, typed from `access`; absent without it. */
46
+ export type PermissionWiringOf<P, Ctx> = [ModelConfigOf<P>] extends [never] ? {
47
+ readonly loaders?: never;
48
+ readonly conditions?: never;
49
+ } : {
50
+ /** The objects `@permission` checks by id — see {@link Loaders}. */
51
+ readonly loaders?: Loaders<ModelConfigOf<P>, Ctx>;
52
+ /** The `ctx` of the conditions `@permission` reaches — see {@link Conditions}. */
53
+ readonly conditions?: Conditions<ModelConfigOf<P>, Ctx>;
54
+ };
55
+ export {};
56
+ //# sourceMappingURL=wiring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wiring.d.ts","sourceRoot":"","sources":["../src/wiring.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,KAAK,EACL,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,EACf,MAAM,6BAA6B,CAAC;AAErC,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEnC,wFAAwF;AACxF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IACxC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;CACzC,GACE,CAAC,GACD,KAAK,CAAC;AAET;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,IAAI;IAC5E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACpB,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI;CAAE,CAAC;AAEtD,2FAA2F;AAC3F,MAAM,MAAM,cAAc,CACzB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,IACtB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC,EAA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AAC,KAAK,CAAC,GACxE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GACzD;IACA,oEAAoE;IACpE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAClD,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;CACxD,CAAC"}
package/docs/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @softistx/janus-graphql — documentation
2
+
3
+ The [README](../README.md) shows the whole wiring in one example; these pages
4
+ give the detail.
5
+
6
+ | Page | Read it when |
7
+ | --- | --- |
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
+ | [Subscriptions over graphql-ws](guide/subscriptions.md) | You serve subscriptions over a WebSocket: `janusConnection()`, the cookie or `connectionParams`, the close codes, a session revoked mid-stream, Bun, and a server without Yoga |
11
+ | [The context](guide/context.md) | You are reading the user in a resolver, narrowing it to a user type, checking a permission or freshness yourself with `requireUser()`, `requireFresh()` and `can()`, wondering when the renewed session cookie is sent, passing the device cookie from a sign-in mutation, accepting API keys with `useJanus({ apiKey: true })`, or serving several issuers from one server with `auth: (ctx) => instance` |
12
+ | [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, how `janusMaskError()` fits Yoga's masking, how `report` logs every outage, how `mapCode` puts your own codes on the answers, and `janusErrorOf` |
13
+ | [Telemetry](guide/telemetry.md) | You want a span per authentication and per permission check, with `@softistx/janus-telemetry` |
14
+ | [Account avatars](guide/avatars.md) | Accounts have an avatar: `JanusAvatar`, `toJanusAvatar()`, `avatarResolvers({ url })`, the `url(size:)` that points at your own authenticated route, and guarding the field |
15
+ | [Social sign-in](guide/social.md) | Users sign in, sign up or link accounts with a provider: `janusSocialTypeDefs`, `socialResolvers()`, the flow the BFF keeps, the session cookie of a completed sign-in, an auth instance per request, and the errors with `returnTo` and `flowSpent` |
16
+ | [Passkeys](guide/passkeys.md) | Users hold passkeys as a second factor: `janusPasskeyTypeDefs`, `passkeyResolvers()`, the browser's JSON as strings, `confirmSecondFactorPasskey` and its cookies, passkey as the first factor (`janusPasskeySignInTypeDefs`, `firstFactor: true`), an auth instance chosen per request, the step-up, and the errors |
17
+ | [Second factor (TOTP)](guide/second-factor.md) | Users hold an authenticator app: `janusSecondFactorTypeDefs`, `secondFactorResolvers()`, the sign-in challenge, `confirmSecondFactor` and `recoverSecondFactor`, enroll, activate, regenerate and disable, `Viewer.secondFactor`, an auth instance chosen per request, the step-up and the policy hooks |
18
+ | [Invitations](guide/invitations.md) | People are invited into a scope: `janusInvitationTypeDefs`, `invitationResolvers()`, `authorize` as the only guard, where the code goes (`sendInvitation`, `answerCode`), the preview and the accept that signs a new invitee in, and the errors |
19
+ | [API keys](guide/api-keys.md) | Users hold personal API keys, maybe bound to a workspace: `apiKeysTypeDefs`, `apiKeysResolvers()`, the lifetimes, `authorize` and `bound` as the guards, the secret answered once, the step-up and the verified e-mail, paging, the limits, and the errors |
20
+ | [Federation](guide/federation.md) | The server is a subgraph: where the directives are checked, what the router must forward, and `@composeDirective` |
21
+ | [Troubleshooting](troubleshooting.md) | A query answers something you did not expect, the server refuses to start, or the compiler refuses a resolver |
22
+ | [Roadmap](roadmap.md) | You want to know what is coming — anonymous graphql-ws connections — and what is deliberately not planned |
23
+
24
+ The words — user, user type, session, subject, permission, failure, denial —
25
+ are [`@softistx/janus`'s vocabulary](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus/docs/guide/vocabulary.md),
26
+ and mean the same here.