@robelest/convex-auth 0.0.2-preview.1 → 0.0.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 (145) hide show
  1. package/dist/bin.cjs +466 -63
  2. package/dist/client/index.d.ts +211 -30
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +673 -59
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/component/_generated/api.d.ts +56 -1
  7. package/dist/component/_generated/api.d.ts.map +1 -1
  8. package/dist/component/_generated/api.js.map +1 -1
  9. package/dist/component/_generated/component.d.ts +93 -3
  10. package/dist/component/_generated/component.d.ts.map +1 -1
  11. package/dist/component/convex.config.d.ts.map +1 -1
  12. package/dist/component/convex.config.js +2 -0
  13. package/dist/component/convex.config.js.map +1 -1
  14. package/dist/component/index.d.ts +5 -3
  15. package/dist/component/index.d.ts.map +1 -1
  16. package/dist/component/index.js +5 -3
  17. package/dist/component/index.js.map +1 -1
  18. package/dist/component/portalBridge.d.ts +80 -0
  19. package/dist/component/portalBridge.d.ts.map +1 -0
  20. package/dist/component/portalBridge.js +102 -0
  21. package/dist/component/portalBridge.js.map +1 -0
  22. package/dist/component/public.d.ts +193 -9
  23. package/dist/component/public.d.ts.map +1 -1
  24. package/dist/component/public.js +204 -33
  25. package/dist/component/public.js.map +1 -1
  26. package/dist/component/schema.d.ts +89 -9
  27. package/dist/component/schema.d.ts.map +1 -1
  28. package/dist/component/schema.js +68 -7
  29. package/dist/component/schema.js.map +1 -1
  30. package/dist/providers/{Anonymous.d.ts → anonymous.d.ts} +8 -8
  31. package/dist/providers/{Anonymous.d.ts.map → anonymous.d.ts.map} +1 -1
  32. package/dist/providers/{Anonymous.js → anonymous.js} +9 -10
  33. package/dist/providers/anonymous.js.map +1 -0
  34. package/dist/providers/{ConvexCredentials.d.ts → credentials.d.ts} +11 -11
  35. package/dist/providers/credentials.d.ts.map +1 -0
  36. package/dist/providers/{ConvexCredentials.js → credentials.js} +8 -8
  37. package/dist/providers/credentials.js.map +1 -0
  38. package/dist/providers/{Email.d.ts → email.d.ts} +6 -6
  39. package/dist/providers/email.d.ts.map +1 -0
  40. package/dist/providers/{Email.js → email.js} +6 -6
  41. package/dist/providers/email.js.map +1 -0
  42. package/dist/providers/passkey.d.ts +20 -0
  43. package/dist/providers/passkey.d.ts.map +1 -0
  44. package/dist/providers/passkey.js +32 -0
  45. package/dist/providers/passkey.js.map +1 -0
  46. package/dist/providers/{Password.d.ts → password.d.ts} +10 -10
  47. package/dist/providers/{Password.d.ts.map → password.d.ts.map} +1 -1
  48. package/dist/providers/{Password.js → password.js} +19 -20
  49. package/dist/providers/password.js.map +1 -0
  50. package/dist/providers/{Phone.d.ts → phone.d.ts} +3 -3
  51. package/dist/providers/{Phone.d.ts.map → phone.d.ts.map} +1 -1
  52. package/dist/providers/{Phone.js → phone.js} +3 -3
  53. package/dist/providers/{Phone.js.map → phone.js.map} +1 -1
  54. package/dist/providers/totp.d.ts +14 -0
  55. package/dist/providers/totp.d.ts.map +1 -0
  56. package/dist/providers/totp.js +23 -0
  57. package/dist/providers/totp.js.map +1 -0
  58. package/dist/server/convex-auth.d.ts +243 -0
  59. package/dist/server/convex-auth.d.ts.map +1 -0
  60. package/dist/server/convex-auth.js +365 -0
  61. package/dist/server/convex-auth.js.map +1 -0
  62. package/dist/server/implementation/index.d.ts +153 -166
  63. package/dist/server/implementation/index.d.ts.map +1 -1
  64. package/dist/server/implementation/index.js +162 -105
  65. package/dist/server/implementation/index.js.map +1 -1
  66. package/dist/server/implementation/passkey.d.ts +33 -0
  67. package/dist/server/implementation/passkey.d.ts.map +1 -0
  68. package/dist/server/implementation/passkey.js +450 -0
  69. package/dist/server/implementation/passkey.js.map +1 -0
  70. package/dist/server/implementation/redirects.d.ts.map +1 -1
  71. package/dist/server/implementation/redirects.js +4 -9
  72. package/dist/server/implementation/redirects.js.map +1 -1
  73. package/dist/server/implementation/sessions.d.ts +2 -20
  74. package/dist/server/implementation/sessions.d.ts.map +1 -1
  75. package/dist/server/implementation/sessions.js +2 -20
  76. package/dist/server/implementation/sessions.js.map +1 -1
  77. package/dist/server/implementation/signIn.d.ts +13 -0
  78. package/dist/server/implementation/signIn.d.ts.map +1 -1
  79. package/dist/server/implementation/signIn.js +26 -1
  80. package/dist/server/implementation/signIn.js.map +1 -1
  81. package/dist/server/implementation/totp.d.ts +40 -0
  82. package/dist/server/implementation/totp.d.ts.map +1 -0
  83. package/dist/server/implementation/totp.js +211 -0
  84. package/dist/server/implementation/totp.js.map +1 -0
  85. package/dist/server/index.d.ts +18 -0
  86. package/dist/server/index.d.ts.map +1 -1
  87. package/dist/server/index.js +255 -0
  88. package/dist/server/index.js.map +1 -1
  89. package/dist/server/portal-email.d.ts +19 -0
  90. package/dist/server/portal-email.d.ts.map +1 -0
  91. package/dist/server/portal-email.js +89 -0
  92. package/dist/server/portal-email.js.map +1 -0
  93. package/dist/server/portal.d.ts +116 -0
  94. package/dist/server/portal.d.ts.map +1 -0
  95. package/dist/server/portal.js +294 -0
  96. package/dist/server/portal.js.map +1 -0
  97. package/dist/server/provider_utils.d.ts +1 -1
  98. package/dist/server/provider_utils.d.ts.map +1 -1
  99. package/dist/server/provider_utils.js +39 -1
  100. package/dist/server/provider_utils.js.map +1 -1
  101. package/dist/server/types.d.ts +128 -11
  102. package/dist/server/types.d.ts.map +1 -1
  103. package/package.json +7 -7
  104. package/src/cli/index.ts +48 -6
  105. package/src/cli/portal-link.ts +112 -0
  106. package/src/cli/portal-upload.ts +411 -0
  107. package/src/client/index.ts +823 -109
  108. package/src/component/_generated/api.ts +72 -1
  109. package/src/component/_generated/component.ts +180 -4
  110. package/src/component/convex.config.ts +3 -0
  111. package/src/component/index.ts +5 -10
  112. package/src/component/portalBridge.ts +116 -0
  113. package/src/component/public.ts +231 -37
  114. package/src/component/schema.ts +70 -7
  115. package/src/providers/{Anonymous.ts → anonymous.ts} +10 -11
  116. package/src/providers/{ConvexCredentials.ts → credentials.ts} +11 -11
  117. package/src/providers/{Email.ts → email.ts} +5 -5
  118. package/src/providers/passkey.ts +35 -0
  119. package/src/providers/{Password.ts → password.ts} +22 -27
  120. package/src/providers/{Phone.ts → phone.ts} +2 -2
  121. package/src/providers/totp.ts +26 -0
  122. package/src/server/convex-auth.ts +470 -0
  123. package/src/server/implementation/index.ts +228 -239
  124. package/src/server/implementation/passkey.ts +650 -0
  125. package/src/server/implementation/redirects.ts +4 -11
  126. package/src/server/implementation/sessions.ts +2 -20
  127. package/src/server/implementation/signIn.ts +39 -1
  128. package/src/server/implementation/totp.ts +366 -0
  129. package/src/server/index.ts +373 -0
  130. package/src/server/portal-email.ts +95 -0
  131. package/src/server/portal.ts +375 -0
  132. package/src/server/provider_utils.ts +42 -1
  133. package/src/server/types.ts +161 -10
  134. package/dist/providers/Anonymous.js.map +0 -1
  135. package/dist/providers/ConvexCredentials.d.ts.map +0 -1
  136. package/dist/providers/ConvexCredentials.js.map +0 -1
  137. package/dist/providers/Email.d.ts.map +0 -1
  138. package/dist/providers/Email.js.map +0 -1
  139. package/dist/providers/Password.js.map +0 -1
  140. package/providers/Anonymous/package.json +0 -6
  141. package/providers/ConvexCredentials/package.json +0 -6
  142. package/providers/Email/package.json +0 -6
  143. package/providers/Password/package.json +0 -6
  144. package/providers/Phone/package.json +0 -6
  145. package/server/package.json +0 -6
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import type * as index from "../index.js";
12
+ import type * as portalBridge from "../portalBridge.js";
12
13
  import type * as public_ from "../public.js";
13
14
 
14
15
  import type {
@@ -20,6 +21,7 @@ import { anyApi, componentsGeneric } from "convex/server";
20
21
 
21
22
  const fullApi: ApiFromModules<{
22
23
  index: typeof index;
24
+ portalBridge: typeof portalBridge;
23
25
  public: typeof public_;
24
26
  }> = anyApi as any;
25
27
 
@@ -49,4 +51,73 @@ export const internal: FilterApi<
49
51
  FunctionReference<any, "internal">
50
52
  > = anyApi as any;
51
53
 
52
- export const components = componentsGeneric() as unknown as {};
54
+ export const components = componentsGeneric() as unknown as {
55
+ selfHosting: {
56
+ lib: {
57
+ gcOldAssets: FunctionReference<
58
+ "mutation",
59
+ "internal",
60
+ { currentDeploymentId: string },
61
+ { blobIds: Array<string>; storageIds: Array<string> }
62
+ >;
63
+ generateUploadUrl: FunctionReference<"mutation", "internal", {}, string>;
64
+ getByPath: FunctionReference<
65
+ "query",
66
+ "internal",
67
+ { path: string },
68
+ {
69
+ _creationTime: number;
70
+ _id: string;
71
+ blobId?: string;
72
+ contentType: string;
73
+ deploymentId: string;
74
+ path: string;
75
+ storageId?: string;
76
+ } | null
77
+ >;
78
+ getCurrentDeployment: FunctionReference<
79
+ "query",
80
+ "internal",
81
+ {},
82
+ {
83
+ _creationTime: number;
84
+ _id: string;
85
+ currentDeploymentId: string;
86
+ deployedAt: number;
87
+ } | null
88
+ >;
89
+ listAssets: FunctionReference<
90
+ "query",
91
+ "internal",
92
+ { limit?: number },
93
+ Array<{
94
+ _creationTime: number;
95
+ _id: string;
96
+ blobId?: string;
97
+ contentType: string;
98
+ deploymentId: string;
99
+ path: string;
100
+ storageId?: string;
101
+ }>
102
+ >;
103
+ recordAsset: FunctionReference<
104
+ "mutation",
105
+ "internal",
106
+ {
107
+ blobId?: string;
108
+ contentType: string;
109
+ deploymentId: string;
110
+ path: string;
111
+ storageId?: string;
112
+ },
113
+ { oldBlobId: string | null; oldStorageId: string | null }
114
+ >;
115
+ setCurrentDeployment: FunctionReference<
116
+ "mutation",
117
+ "internal",
118
+ { deploymentId: string },
119
+ null
120
+ >;
121
+ };
122
+ };
123
+ };
@@ -23,6 +23,56 @@ import type { FunctionReference } from "convex/server";
23
23
  */
24
24
  export type ComponentApi<Name extends string | undefined = string | undefined> =
25
25
  {
26
+ portalBridge: {
27
+ gcOldAssets: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { currentDeploymentId: string },
31
+ any,
32
+ Name
33
+ >;
34
+ getByPath: FunctionReference<
35
+ "query",
36
+ "internal",
37
+ { path: string },
38
+ any,
39
+ Name
40
+ >;
41
+ getCurrentDeployment: FunctionReference<
42
+ "query",
43
+ "internal",
44
+ {},
45
+ any,
46
+ Name
47
+ >;
48
+ listAssets: FunctionReference<
49
+ "query",
50
+ "internal",
51
+ { limit?: number },
52
+ any,
53
+ Name
54
+ >;
55
+ recordAsset: FunctionReference<
56
+ "mutation",
57
+ "internal",
58
+ {
59
+ blobId?: string;
60
+ contentType: string;
61
+ deploymentId: string;
62
+ path: string;
63
+ storageId?: string;
64
+ },
65
+ any,
66
+ Name
67
+ >;
68
+ setCurrentDeployment: FunctionReference<
69
+ "mutation",
70
+ "internal",
71
+ { deploymentId: string },
72
+ null,
73
+ Name
74
+ >;
75
+ };
26
76
  public: {
27
77
  accountDelete: FunctionReference<
28
78
  "mutation",
@@ -57,6 +107,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
57
107
  any,
58
108
  Name
59
109
  >;
110
+ accountListByUser: FunctionReference<
111
+ "query",
112
+ "internal",
113
+ { userId: string },
114
+ any,
115
+ Name
116
+ >;
60
117
  accountPatch: FunctionReference<
61
118
  "mutation",
62
119
  "internal",
@@ -102,7 +159,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
102
159
  inviteAccept: FunctionReference<
103
160
  "mutation",
104
161
  "internal",
105
- { inviteId: string },
162
+ { acceptedByUserId?: string; inviteId: string },
106
163
  any,
107
164
  Name
108
165
  >;
@@ -110,11 +167,11 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
110
167
  "mutation",
111
168
  "internal",
112
169
  {
113
- email: string;
114
- expiresTime: number;
170
+ email?: string;
171
+ expiresTime?: number;
115
172
  extend?: any;
116
173
  groupId?: string;
117
- invitedByUserId: string;
174
+ invitedByUserId?: string;
118
175
  role?: string;
119
176
  status: "pending" | "accepted" | "revoked" | "expired";
120
177
  tokenHash: string;
@@ -129,6 +186,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
129
186
  any,
130
187
  Name
131
188
  >;
189
+ inviteGetByTokenHash: FunctionReference<
190
+ "query",
191
+ "internal",
192
+ { tokenHash: string },
193
+ any,
194
+ Name
195
+ >;
132
196
  inviteList: FunctionReference<
133
197
  "query",
134
198
  "internal",
@@ -201,6 +265,59 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
201
265
  any,
202
266
  Name
203
267
  >;
268
+ passkeyDelete: FunctionReference<
269
+ "mutation",
270
+ "internal",
271
+ { passkeyId: string },
272
+ any,
273
+ Name
274
+ >;
275
+ passkeyGetByCredentialId: FunctionReference<
276
+ "query",
277
+ "internal",
278
+ { credentialId: string },
279
+ any,
280
+ Name
281
+ >;
282
+ passkeyInsert: FunctionReference<
283
+ "mutation",
284
+ "internal",
285
+ {
286
+ algorithm: number;
287
+ backedUp: boolean;
288
+ counter: number;
289
+ createdAt: number;
290
+ credentialId: string;
291
+ deviceType: string;
292
+ name?: string;
293
+ publicKey: ArrayBuffer;
294
+ transports?: Array<string>;
295
+ userId: string;
296
+ },
297
+ any,
298
+ Name
299
+ >;
300
+ passkeyListByUserId: FunctionReference<
301
+ "query",
302
+ "internal",
303
+ { userId: string },
304
+ any,
305
+ Name
306
+ >;
307
+ passkeyUpdateCounter: FunctionReference<
308
+ "mutation",
309
+ "internal",
310
+ { counter: number; lastUsedAt: number; passkeyId: string },
311
+ any,
312
+ Name
313
+ >;
314
+ passkeyUpdateMeta: FunctionReference<
315
+ "mutation",
316
+ "internal",
317
+ { data: any; passkeyId: string },
318
+ any,
319
+ Name
320
+ >;
204
321
  rateLimitCreate: FunctionReference<
205
322
  "mutation",
206
323
  "internal",
@@ -303,6 +420,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
303
420
  any,
304
421
  Name
305
422
  >;
423
+ sessionList: FunctionReference<"query", "internal", {}, any, Name>;
306
424
  sessionListByUser: FunctionReference<
307
425
  "query",
308
426
  "internal",
@@ -310,6 +428,63 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
310
428
  any,
311
429
  Name
312
430
  >;
431
+ totpDelete: FunctionReference<
432
+ "mutation",
433
+ "internal",
434
+ { totpId: string },
435
+ any,
436
+ Name
437
+ >;
438
+ totpGetById: FunctionReference<
439
+ "query",
440
+ "internal",
441
+ { totpId: string },
442
+ any,
443
+ Name
444
+ >;
445
+ totpGetVerifiedByUserId: FunctionReference<
446
+ "query",
447
+ "internal",
448
+ { userId: string },
449
+ any,
450
+ Name
451
+ >;
452
+ totpInsert: FunctionReference<
453
+ "mutation",
454
+ "internal",
455
+ {
456
+ createdAt: number;
457
+ digits: number;
458
+ name?: string;
459
+ period: number;
460
+ secret: ArrayBuffer;
461
+ userId: string;
462
+ verified: boolean;
463
+ },
464
+ any,
465
+ Name
466
+ >;
467
+ totpListByUserId: FunctionReference<
468
+ "query",
469
+ "internal",
470
+ { userId: string },
471
+ any,
472
+ Name
473
+ >;
474
+ totpMarkVerified: FunctionReference<
475
+ "mutation",
476
+ "internal",
477
+ { lastUsedAt: number; totpId: string },
478
+ any,
479
+ Name
480
+ >;
481
+ totpUpdateLastUsed: FunctionReference<
482
+ "mutation",
483
+ "internal",
484
+ { lastUsedAt: number; totpId: string },
485
+ any,
486
+ Name
487
+ >;
313
488
  userFindByVerifiedEmail: FunctionReference<
314
489
  "query",
315
490
  "internal",
@@ -338,6 +513,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
338
513
  any,
339
514
  Name
340
515
  >;
516
+ userList: FunctionReference<"query", "internal", {}, any, Name>;
341
517
  userPatch: FunctionReference<
342
518
  "mutation",
343
519
  "internal",
@@ -1,5 +1,8 @@
1
1
  import { defineComponent } from "convex/server";
2
+ import selfHosting from "@convex-dev/self-hosting/convex.config";
2
3
 
3
4
  const component = defineComponent("auth");
4
5
 
6
+ component.use(selfHosting);
7
+
5
8
  export default component;
@@ -2,26 +2,21 @@
2
2
  * Configuration and helpers for using Convex Auth on your Convex
3
3
  * backend.
4
4
  *
5
- * Call {@link convexAuth} to configure your authentication methods
6
- * and use the helpers it returns.
5
+ * Use `new Auth(components.auth, config)` to configure authentication
6
+ * and `Portal(auth)` to create portal admin exports.
7
7
  *
8
8
  * @module
9
9
  */
10
10
 
11
11
  export {
12
- Auth,
13
- getAuthUserId,
14
- getAuthSessionId,
15
- createAccount,
16
- retrieveAccount,
17
- signInViaProvider,
18
- invalidateSessions,
19
- modifyAccountCredentials,
12
+ Auth as AuthFactory,
20
13
  Tokens,
21
14
  Doc,
22
15
  SignInAction,
23
16
  SignOutAction,
24
17
  } from "../server/implementation/index.js";
18
+ export { Portal as PortalFactory } from "../server/portal.js";
19
+ export { Auth, Portal } from "../server/convex-auth.js";
25
20
  export type {
26
21
  ConvexAuthConfig,
27
22
  AuthProviderConfig,
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Bridge functions that delegate to the self-hosting sub-component.
3
+ *
4
+ * The auth component uses self-hosting as a sub-component for serving
5
+ * portal static assets. These functions expose the self-hosting API
6
+ * as internal queries/mutations within the auth component, so the
7
+ * app layer can call them via `ctx.runQuery(components.auth.portalBridge.getByPath, ...)`.
8
+ */
9
+
10
+ import { v } from "convex/values";
11
+ import { query, mutation, internalMutation } from "./_generated/server.js";
12
+ import { components } from "./_generated/api.js";
13
+
14
+ // ============================================================================
15
+ // Queries — delegate to selfHosting.lib.*
16
+ // ============================================================================
17
+
18
+ /**
19
+ * Look up a static asset by URL path.
20
+ * Delegates to selfHosting.lib.getByPath.
21
+ */
22
+ export const getByPath = query({
23
+ args: { path: v.string() },
24
+ returns: v.any(),
25
+ handler: async (ctx, args) => {
26
+ return await ctx.runQuery(components.selfHosting.lib.getByPath, {
27
+ path: args.path,
28
+ });
29
+ },
30
+ });
31
+
32
+ /**
33
+ * Get the current deployment info.
34
+ * Delegates to selfHosting.lib.getCurrentDeployment.
35
+ */
36
+ export const getCurrentDeployment = query({
37
+ args: {},
38
+ returns: v.any(),
39
+ handler: async (ctx) => {
40
+ return await ctx.runQuery(
41
+ components.selfHosting.lib.getCurrentDeployment,
42
+ {},
43
+ );
44
+ },
45
+ });
46
+
47
+ /**
48
+ * List all static assets.
49
+ * Delegates to selfHosting.lib.listAssets.
50
+ */
51
+ export const listAssets = query({
52
+ args: { limit: v.optional(v.number()) },
53
+ returns: v.any(),
54
+ handler: async (ctx, args) => {
55
+ return await ctx.runQuery(components.selfHosting.lib.listAssets, {
56
+ limit: args.limit,
57
+ });
58
+ },
59
+ });
60
+
61
+ // ============================================================================
62
+ // Mutations — delegate to selfHosting.lib.*
63
+ // ============================================================================
64
+
65
+ /**
66
+ * Record an asset after upload.
67
+ * Delegates to selfHosting.lib.recordAsset.
68
+ */
69
+ export const recordAsset = mutation({
70
+ args: {
71
+ path: v.string(),
72
+ storageId: v.optional(v.string()),
73
+ blobId: v.optional(v.string()),
74
+ contentType: v.string(),
75
+ deploymentId: v.string(),
76
+ },
77
+ returns: v.any(),
78
+ handler: async (ctx, args) => {
79
+ return await ctx.runMutation(components.selfHosting.lib.recordAsset, {
80
+ path: args.path,
81
+ ...(args.storageId ? { storageId: args.storageId } : {}),
82
+ ...(args.blobId ? { blobId: args.blobId } : {}),
83
+ contentType: args.contentType,
84
+ deploymentId: args.deploymentId,
85
+ });
86
+ },
87
+ });
88
+
89
+ /**
90
+ * Garbage collect assets from old deployments.
91
+ * Delegates to selfHosting.lib.gcOldAssets.
92
+ */
93
+ export const gcOldAssets = mutation({
94
+ args: { currentDeploymentId: v.string() },
95
+ returns: v.any(),
96
+ handler: async (ctx, args) => {
97
+ return await ctx.runMutation(components.selfHosting.lib.gcOldAssets, {
98
+ currentDeploymentId: args.currentDeploymentId,
99
+ });
100
+ },
101
+ });
102
+
103
+ /**
104
+ * Update the current deployment ID.
105
+ * Delegates to selfHosting.lib.setCurrentDeployment.
106
+ */
107
+ export const setCurrentDeployment = mutation({
108
+ args: { deploymentId: v.string() },
109
+ returns: v.null(),
110
+ handler: async (ctx, args) => {
111
+ return await ctx.runMutation(
112
+ components.selfHosting.lib.setCurrentDeployment,
113
+ { deploymentId: args.deploymentId },
114
+ );
115
+ },
116
+ });