@convex-dev/better-auth 0.6.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.
Files changed (181) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +44 -0
  3. package/dist/commonjs/client/adapter.d.ts +4 -0
  4. package/dist/commonjs/client/adapter.d.ts.map +1 -0
  5. package/dist/commonjs/client/adapter.js +189 -0
  6. package/dist/commonjs/client/adapter.js.map +1 -0
  7. package/dist/commonjs/client/cors.d.ts +72 -0
  8. package/dist/commonjs/client/cors.d.ts.map +1 -0
  9. package/dist/commonjs/client/cors.js +281 -0
  10. package/dist/commonjs/client/cors.js.map +1 -0
  11. package/dist/commonjs/client/index.d.ts +302 -0
  12. package/dist/commonjs/client/index.d.ts.map +1 -0
  13. package/dist/commonjs/client/index.js +232 -0
  14. package/dist/commonjs/client/index.js.map +1 -0
  15. package/dist/commonjs/client/plugins/index.d.ts +3 -0
  16. package/dist/commonjs/client/plugins/index.d.ts.map +1 -0
  17. package/dist/commonjs/client/plugins/index.js +3 -0
  18. package/dist/commonjs/client/plugins/index.js.map +1 -0
  19. package/dist/commonjs/component/_generated/api.d.ts +12 -0
  20. package/dist/commonjs/component/_generated/api.d.ts.map +1 -0
  21. package/dist/commonjs/component/_generated/api.js +22 -0
  22. package/dist/commonjs/component/_generated/api.js.map +1 -0
  23. package/dist/commonjs/component/_generated/server.d.ts +64 -0
  24. package/dist/commonjs/component/_generated/server.d.ts.map +1 -0
  25. package/dist/commonjs/component/_generated/server.js +74 -0
  26. package/dist/commonjs/component/_generated/server.js.map +1 -0
  27. package/dist/commonjs/component/convex.config.d.ts +3 -0
  28. package/dist/commonjs/component/convex.config.d.ts.map +1 -0
  29. package/dist/commonjs/component/convex.config.js +4 -0
  30. package/dist/commonjs/component/convex.config.js.map +1 -0
  31. package/dist/commonjs/component/lib.d.ts +584 -0
  32. package/dist/commonjs/component/lib.d.ts.map +1 -0
  33. package/dist/commonjs/component/lib.js +323 -0
  34. package/dist/commonjs/component/lib.js.map +1 -0
  35. package/dist/commonjs/component/schema.d.ts +116 -0
  36. package/dist/commonjs/component/schema.d.ts.map +1 -0
  37. package/dist/commonjs/component/schema.js +68 -0
  38. package/dist/commonjs/component/schema.js.map +1 -0
  39. package/dist/commonjs/component/util.d.ts +394 -0
  40. package/dist/commonjs/component/util.d.ts.map +1 -0
  41. package/dist/commonjs/component/util.js +4 -0
  42. package/dist/commonjs/component/util.js.map +1 -0
  43. package/dist/commonjs/nextjs/index.d.ts +10 -0
  44. package/dist/commonjs/nextjs/index.d.ts.map +1 -0
  45. package/dist/commonjs/nextjs/index.js +23 -0
  46. package/dist/commonjs/nextjs/index.js.map +1 -0
  47. package/dist/commonjs/package.json +3 -0
  48. package/dist/commonjs/plugins/convex/client.d.ts +6 -0
  49. package/dist/commonjs/plugins/convex/client.d.ts.map +1 -0
  50. package/dist/commonjs/plugins/convex/client.js +7 -0
  51. package/dist/commonjs/plugins/convex/client.js.map +1 -0
  52. package/dist/commonjs/plugins/convex/index.d.ts +280 -0
  53. package/dist/commonjs/plugins/convex/index.d.ts.map +1 -0
  54. package/dist/commonjs/plugins/convex/index.js +253 -0
  55. package/dist/commonjs/plugins/convex/index.js.map +1 -0
  56. package/dist/commonjs/plugins/cross-domain/client.d.ts +123 -0
  57. package/dist/commonjs/plugins/cross-domain/client.d.ts.map +1 -0
  58. package/dist/commonjs/plugins/cross-domain/client.js +164 -0
  59. package/dist/commonjs/plugins/cross-domain/client.js.map +1 -0
  60. package/dist/commonjs/plugins/cross-domain/index.d.ts +81 -0
  61. package/dist/commonjs/plugins/cross-domain/index.d.ts.map +1 -0
  62. package/dist/commonjs/plugins/cross-domain/index.js +135 -0
  63. package/dist/commonjs/plugins/cross-domain/index.js.map +1 -0
  64. package/dist/commonjs/plugins/index.d.ts +3 -0
  65. package/dist/commonjs/plugins/index.d.ts.map +1 -0
  66. package/dist/commonjs/plugins/index.js +3 -0
  67. package/dist/commonjs/plugins/index.js.map +1 -0
  68. package/dist/commonjs/react/client.d.ts +31 -0
  69. package/dist/commonjs/react/client.d.ts.map +1 -0
  70. package/dist/commonjs/react/client.js +102 -0
  71. package/dist/commonjs/react/client.js.map +1 -0
  72. package/dist/commonjs/react/index.d.ts +9 -0
  73. package/dist/commonjs/react/index.d.ts.map +1 -0
  74. package/dist/commonjs/react/index.js +15 -0
  75. package/dist/commonjs/react/index.js.map +1 -0
  76. package/dist/commonjs/react-start/index.d.ts +10 -0
  77. package/dist/commonjs/react-start/index.d.ts.map +1 -0
  78. package/dist/commonjs/react-start/index.js +32 -0
  79. package/dist/commonjs/react-start/index.js.map +1 -0
  80. package/dist/esm/client/adapter.d.ts +4 -0
  81. package/dist/esm/client/adapter.d.ts.map +1 -0
  82. package/dist/esm/client/adapter.js +189 -0
  83. package/dist/esm/client/adapter.js.map +1 -0
  84. package/dist/esm/client/cors.d.ts +72 -0
  85. package/dist/esm/client/cors.d.ts.map +1 -0
  86. package/dist/esm/client/cors.js +281 -0
  87. package/dist/esm/client/cors.js.map +1 -0
  88. package/dist/esm/client/index.d.ts +302 -0
  89. package/dist/esm/client/index.d.ts.map +1 -0
  90. package/dist/esm/client/index.js +232 -0
  91. package/dist/esm/client/index.js.map +1 -0
  92. package/dist/esm/client/plugins/index.d.ts +3 -0
  93. package/dist/esm/client/plugins/index.d.ts.map +1 -0
  94. package/dist/esm/client/plugins/index.js +3 -0
  95. package/dist/esm/client/plugins/index.js.map +1 -0
  96. package/dist/esm/component/_generated/api.d.ts +12 -0
  97. package/dist/esm/component/_generated/api.d.ts.map +1 -0
  98. package/dist/esm/component/_generated/api.js +22 -0
  99. package/dist/esm/component/_generated/api.js.map +1 -0
  100. package/dist/esm/component/_generated/server.d.ts +64 -0
  101. package/dist/esm/component/_generated/server.d.ts.map +1 -0
  102. package/dist/esm/component/_generated/server.js +74 -0
  103. package/dist/esm/component/_generated/server.js.map +1 -0
  104. package/dist/esm/component/convex.config.d.ts +3 -0
  105. package/dist/esm/component/convex.config.d.ts.map +1 -0
  106. package/dist/esm/component/convex.config.js +4 -0
  107. package/dist/esm/component/convex.config.js.map +1 -0
  108. package/dist/esm/component/lib.d.ts +584 -0
  109. package/dist/esm/component/lib.d.ts.map +1 -0
  110. package/dist/esm/component/lib.js +323 -0
  111. package/dist/esm/component/lib.js.map +1 -0
  112. package/dist/esm/component/schema.d.ts +116 -0
  113. package/dist/esm/component/schema.d.ts.map +1 -0
  114. package/dist/esm/component/schema.js +68 -0
  115. package/dist/esm/component/schema.js.map +1 -0
  116. package/dist/esm/component/util.d.ts +394 -0
  117. package/dist/esm/component/util.d.ts.map +1 -0
  118. package/dist/esm/component/util.js +4 -0
  119. package/dist/esm/component/util.js.map +1 -0
  120. package/dist/esm/nextjs/index.d.ts +10 -0
  121. package/dist/esm/nextjs/index.d.ts.map +1 -0
  122. package/dist/esm/nextjs/index.js +23 -0
  123. package/dist/esm/nextjs/index.js.map +1 -0
  124. package/dist/esm/package.json +3 -0
  125. package/dist/esm/plugins/convex/client.d.ts +6 -0
  126. package/dist/esm/plugins/convex/client.d.ts.map +1 -0
  127. package/dist/esm/plugins/convex/client.js +7 -0
  128. package/dist/esm/plugins/convex/client.js.map +1 -0
  129. package/dist/esm/plugins/convex/index.d.ts +280 -0
  130. package/dist/esm/plugins/convex/index.d.ts.map +1 -0
  131. package/dist/esm/plugins/convex/index.js +253 -0
  132. package/dist/esm/plugins/convex/index.js.map +1 -0
  133. package/dist/esm/plugins/cross-domain/client.d.ts +123 -0
  134. package/dist/esm/plugins/cross-domain/client.d.ts.map +1 -0
  135. package/dist/esm/plugins/cross-domain/client.js +164 -0
  136. package/dist/esm/plugins/cross-domain/client.js.map +1 -0
  137. package/dist/esm/plugins/cross-domain/index.d.ts +81 -0
  138. package/dist/esm/plugins/cross-domain/index.d.ts.map +1 -0
  139. package/dist/esm/plugins/cross-domain/index.js +135 -0
  140. package/dist/esm/plugins/cross-domain/index.js.map +1 -0
  141. package/dist/esm/plugins/index.d.ts +3 -0
  142. package/dist/esm/plugins/index.d.ts.map +1 -0
  143. package/dist/esm/plugins/index.js +3 -0
  144. package/dist/esm/plugins/index.js.map +1 -0
  145. package/dist/esm/react/client.d.ts +31 -0
  146. package/dist/esm/react/client.d.ts.map +1 -0
  147. package/dist/esm/react/client.js +102 -0
  148. package/dist/esm/react/client.js.map +1 -0
  149. package/dist/esm/react/index.d.ts +9 -0
  150. package/dist/esm/react/index.d.ts.map +1 -0
  151. package/dist/esm/react/index.js +15 -0
  152. package/dist/esm/react/index.js.map +1 -0
  153. package/dist/esm/react-start/index.d.ts +10 -0
  154. package/dist/esm/react-start/index.d.ts.map +1 -0
  155. package/dist/esm/react-start/index.js +32 -0
  156. package/dist/esm/react-start/index.js.map +1 -0
  157. package/package.json +161 -0
  158. package/plugins/package.json +5 -0
  159. package/react/package.json +5 -0
  160. package/src/client/adapter.ts +236 -0
  161. package/src/client/cors.ts +403 -0
  162. package/src/client/index.ts +381 -0
  163. package/src/client/plugins/index.ts +2 -0
  164. package/src/component/_generated/api.d.ts +313 -0
  165. package/src/component/_generated/api.js +23 -0
  166. package/src/component/_generated/dataModel.d.ts +60 -0
  167. package/src/component/_generated/server.d.ts +149 -0
  168. package/src/component/_generated/server.js +90 -0
  169. package/src/component/convex.config.ts +5 -0
  170. package/src/component/lib.ts +391 -0
  171. package/src/component/schema.ts +74 -0
  172. package/src/component/util.ts +4 -0
  173. package/src/nextjs/index.ts +30 -0
  174. package/src/plugins/convex/client.ts +9 -0
  175. package/src/plugins/convex/index.ts +296 -0
  176. package/src/plugins/cross-domain/client.ts +209 -0
  177. package/src/plugins/cross-domain/index.ts +156 -0
  178. package/src/plugins/index.ts +2 -0
  179. package/src/react/client.tsx +184 -0
  180. package/src/react/index.tsx +38 -0
  181. package/src/react-start/index.ts +51 -0
@@ -0,0 +1,381 @@
1
+ import {
2
+ type Auth as ConvexAuth,
3
+ type DefaultFunctionArgs,
4
+ type Expand,
5
+ type FunctionReference,
6
+ GenericActionCtx,
7
+ type GenericDataModel,
8
+ GenericMutationCtx,
9
+ type GenericQueryCtx,
10
+ type HttpRouter,
11
+ httpActionGeneric,
12
+ internalMutationGeneric,
13
+ queryGeneric,
14
+ } from "convex/server";
15
+ import { type GenericId, Infer, v } from "convex/values";
16
+ import type { api } from "../component/_generated/api";
17
+ import schema from "../component/schema";
18
+ import { convexAdapter } from "./adapter";
19
+ import corsRouter from "./cors";
20
+ import { getByArgsValidator, updateArgsInputValidator } from "../component/lib";
21
+ import { betterAuth } from "better-auth";
22
+ import { omit } from "convex-helpers";
23
+ import { createCookieGetter } from "better-auth/cookies";
24
+ import { fetchQuery } from "convex/nextjs";
25
+ export { convexAdapter };
26
+
27
+ const createUserFields = omit(schema.tables.user.validator.fields, ["userId"]);
28
+ const createUserValidator = v.object(createUserFields);
29
+ const createUserArgsValidator = v.object({
30
+ input: v.object({
31
+ ...createUserFields,
32
+ table: v.literal("user"),
33
+ }),
34
+ });
35
+ const updateUserArgsValidator = v.object({
36
+ input: updateArgsInputValidator("user"),
37
+ });
38
+ const deleteUserArgsValidator = v.object(getByArgsValidator);
39
+
40
+ const createSessionArgsValidator = v.object({
41
+ input: v.object({
42
+ table: v.literal("session"),
43
+ ...schema.tables.session.validator.fields,
44
+ }),
45
+ });
46
+
47
+ export type EventFunction<T extends DefaultFunctionArgs> = FunctionReference<
48
+ "mutation",
49
+ "internal" | "public",
50
+ T
51
+ >;
52
+
53
+ export type AuthFunctions = {
54
+ createUser: FunctionReference<
55
+ "mutation",
56
+ "internal",
57
+ Infer<typeof createUserArgsValidator>
58
+ >;
59
+ deleteUser: FunctionReference<
60
+ "mutation",
61
+ "internal",
62
+ Infer<typeof deleteUserArgsValidator>
63
+ >;
64
+ updateUser: FunctionReference<
65
+ "mutation",
66
+ "internal",
67
+ Infer<typeof updateUserArgsValidator>
68
+ >;
69
+ createSession: FunctionReference<
70
+ "mutation",
71
+ "internal",
72
+ Infer<typeof createSessionArgsValidator>
73
+ >;
74
+ };
75
+
76
+ export type PublicAuthFunctions = {
77
+ isAuthenticated: FunctionReference<"query", "public">;
78
+ };
79
+
80
+ export class BetterAuth<UserId extends string = string> {
81
+ constructor(
82
+ public component: UseApi<typeof api>,
83
+ public config: {
84
+ authFunctions: AuthFunctions;
85
+ publicAuthFunctions?: PublicAuthFunctions;
86
+ verbose?: boolean;
87
+ }
88
+ ) {}
89
+
90
+ async isAuthenticated(token?: string | null) {
91
+ if (!this.config.publicAuthFunctions?.isAuthenticated) {
92
+ throw new Error(
93
+ "isAuthenticated function not found. It must be a named export in convex/auth.ts"
94
+ );
95
+ }
96
+ return fetchQuery(
97
+ this.config.publicAuthFunctions.isAuthenticated,
98
+ {},
99
+ { token: token ?? undefined }
100
+ );
101
+ }
102
+
103
+ async getHeaders(ctx: RunQueryCtx & { auth: ConvexAuth }) {
104
+ const identity = await ctx.auth.getUserIdentity();
105
+ if (!identity) {
106
+ return new Headers();
107
+ }
108
+ const session = await ctx.runQuery(this.component.lib.getCurrentSession);
109
+ return new Headers({
110
+ authorization: `Bearer ${session?.token}`,
111
+ });
112
+ }
113
+
114
+ // TODO: use the proper id type for auth functions
115
+ async getAuthUserId(ctx: RunQueryCtx & { auth: ConvexAuth }) {
116
+ const identity = await ctx.auth.getUserIdentity();
117
+ if (!identity) {
118
+ return null;
119
+ }
120
+ return identity.subject as UserId;
121
+ }
122
+
123
+ // Convenience function for getting the Better Auth user
124
+ async getAuthUser(ctx: RunQueryCtx & { auth: ConvexAuth }) {
125
+ const identity = await ctx.auth.getUserIdentity();
126
+ if (!identity) {
127
+ return null;
128
+ }
129
+ const doc = await ctx.runQuery(this.component.lib.getBy, {
130
+ table: "user",
131
+ field: "userId",
132
+ value: identity.subject,
133
+ });
134
+ if (!doc) {
135
+ return null;
136
+ }
137
+ // Type narrowing
138
+ if (!("emailVerified" in doc)) {
139
+ throw new Error("invalid user");
140
+ }
141
+ const { id: _id, ...user } = doc;
142
+ return user;
143
+ }
144
+
145
+ async getIdTokenCookieName(
146
+ createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
147
+ ) {
148
+ const auth = createAuth({} as any);
149
+ const createCookie = createCookieGetter(auth.options);
150
+ const cookie = createCookie("convex_jwt");
151
+ return cookie.name;
152
+ }
153
+
154
+ createAuthFunctions<DataModel extends GenericDataModel>(opts: {
155
+ onCreateUser: (
156
+ ctx: GenericMutationCtx<DataModel>,
157
+ user: Infer<typeof createUserValidator>
158
+ ) => Promise<UserId>;
159
+ onDeleteUser?: (
160
+ ctx: GenericMutationCtx<DataModel>,
161
+ id: UserId
162
+ ) => void | Promise<void>;
163
+ onUpdateUser?: (
164
+ ctx: GenericMutationCtx<DataModel>,
165
+ user: Infer<typeof schema.tables.user.validator>
166
+ ) => void | Promise<void>;
167
+ onCreateSession?: (
168
+ ctx: GenericMutationCtx<DataModel>,
169
+ session: Infer<typeof schema.tables.session.validator>
170
+ ) => void | Promise<void>;
171
+ }) {
172
+ return {
173
+ isAuthenticated: queryGeneric({
174
+ args: v.object({}),
175
+ handler: async (ctx) => {
176
+ const identity = await ctx.auth.getUserIdentity();
177
+ return identity !== null;
178
+ },
179
+ }),
180
+ createUser: internalMutationGeneric({
181
+ args: createUserArgsValidator,
182
+ handler: async (ctx, args) => {
183
+ const userId = await opts.onCreateUser(ctx, args.input);
184
+ const input = { ...args.input, table: "user", userId };
185
+ return ctx.runMutation(this.component.lib.create, {
186
+ input,
187
+ });
188
+ },
189
+ }),
190
+ deleteUser: internalMutationGeneric({
191
+ args: deleteUserArgsValidator,
192
+ handler: async (ctx, args) => {
193
+ const doc = await ctx.runMutation(this.component.lib.deleteBy, args);
194
+ if (opts.onDeleteUser) {
195
+ await opts.onDeleteUser(ctx, doc.userId as UserId);
196
+ }
197
+ },
198
+ }),
199
+ updateUser: internalMutationGeneric({
200
+ args: updateUserArgsValidator,
201
+ handler: async (ctx, args) => {
202
+ const updatedUser = await ctx.runMutation(
203
+ this.component.lib.update,
204
+ args
205
+ );
206
+ // Type narrowing
207
+ if (!("emailVerified" in updatedUser)) {
208
+ throw new Error("invalid user");
209
+ }
210
+ if (opts.onUpdateUser) {
211
+ await opts.onUpdateUser(ctx, omit(updatedUser, ["id"]));
212
+ }
213
+ return updatedUser;
214
+ },
215
+ }),
216
+ createSession: internalMutationGeneric({
217
+ args: createSessionArgsValidator,
218
+ handler: async (ctx, args) => {
219
+ const session = await ctx.runMutation(
220
+ this.component.lib.create,
221
+ args
222
+ );
223
+ // Type narrowing
224
+ if (!("ipAddress" in session)) {
225
+ throw new Error("invalid session");
226
+ }
227
+ await opts.onCreateSession?.(ctx, session);
228
+ return session;
229
+ },
230
+ }),
231
+ };
232
+ }
233
+
234
+ registerRoutes(
235
+ http: HttpRouter,
236
+ createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>,
237
+ opts?: {
238
+ path?: string;
239
+ allowedOrigins?: string[];
240
+ }
241
+ ) {
242
+ const path = opts?.path ?? "/api/auth";
243
+ const options = createAuth({} as any).options;
244
+ const trustedOriginsOption: string[] = Array.isArray(options.trustedOrigins)
245
+ ? options.trustedOrigins
246
+ : [];
247
+
248
+ const trustedOrigins = createAuth({} as any).options.plugins?.reduce(
249
+ (acc, plugin) => {
250
+ if (plugin.options?.trustedOrigins) {
251
+ acc.push(...plugin.options.trustedOrigins);
252
+ }
253
+ return acc;
254
+ },
255
+ [...trustedOriginsOption, options.baseURL].filter(Boolean) as string[]
256
+ );
257
+ // Reuse trustedOrigins as default for allowedOrigins
258
+ const allowedOrigins =
259
+ opts?.allowedOrigins ??
260
+ trustedOrigins?.map((origin) =>
261
+ // Strip trailing wildcards, unsupported for allowedOrigins
262
+ origin.endsWith("*") && origin.length > 1 ? origin.slice(0, -1) : origin
263
+ );
264
+ const requireEnv = (name: string) => {
265
+ const value = process.env[name];
266
+ if (value === undefined) {
267
+ throw new Error(`Missing environment variable \`${name}\``);
268
+ }
269
+ return value;
270
+ };
271
+
272
+ const authRequestHandler = httpActionGeneric(async (ctx, request) => {
273
+ const auth = createAuth(ctx);
274
+ const response = await auth.handler(request);
275
+ if (this.config?.verbose) {
276
+ console.log("response headers", response.headers);
277
+ }
278
+ return response;
279
+ });
280
+
281
+ const cors = corsRouter(http, {
282
+ allowedOrigins,
283
+ allowCredentials: true,
284
+ allowedHeaders: ["Authorization", "Content-Type", "Better-Auth-Cookie"],
285
+ verbose: this.config?.verbose,
286
+ exposedHeaders: ["Set-Better-Auth-Cookie"],
287
+ });
288
+
289
+ http.route({
290
+ path: "/.well-known/openid-configuration",
291
+ method: "GET",
292
+ handler: httpActionGeneric(async () => {
293
+ const url = `${requireEnv("CONVEX_SITE_URL")}/api/auth/convex/.well-known/openid-configuration`;
294
+ return Response.redirect(url);
295
+ }),
296
+ });
297
+
298
+ http.route({
299
+ path: `${path}/convex/.well-known/openid-configuration`,
300
+ method: "GET",
301
+ handler: authRequestHandler,
302
+ });
303
+
304
+ http.route({
305
+ path: `${path}/convex/jwks`,
306
+ method: "GET",
307
+ handler: authRequestHandler,
308
+ });
309
+
310
+ http.route({
311
+ pathPrefix: `${path}/callback/`,
312
+ method: "GET",
313
+ handler: authRequestHandler,
314
+ });
315
+
316
+ http.route({
317
+ path: `${path}/magic-link/verify`,
318
+ method: "GET",
319
+ handler: authRequestHandler,
320
+ });
321
+
322
+ http.route({
323
+ path: `${path}/verify-email`,
324
+ method: "GET",
325
+ handler: authRequestHandler,
326
+ });
327
+
328
+ http.route({
329
+ pathPrefix: `${path}/reset-password/`,
330
+ method: "GET",
331
+ handler: authRequestHandler,
332
+ });
333
+
334
+ cors.route({
335
+ pathPrefix: `${path}/`,
336
+ method: "GET",
337
+ handler: authRequestHandler,
338
+ });
339
+
340
+ cors.route({
341
+ pathPrefix: `${path}/`,
342
+ method: "POST",
343
+ handler: authRequestHandler,
344
+ });
345
+ }
346
+ }
347
+
348
+ /* Type utils follow */
349
+
350
+ type RunQueryCtx = {
351
+ runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
352
+ };
353
+
354
+ export type OpaqueIds<T> =
355
+ T extends GenericId<infer _T>
356
+ ? string
357
+ : T extends (infer U)[]
358
+ ? OpaqueIds<U>[]
359
+ : T extends ArrayBuffer
360
+ ? ArrayBuffer
361
+ : T extends object
362
+ ? { [K in keyof T]: OpaqueIds<T[K]> }
363
+ : T;
364
+
365
+ export type UseApi<API> = Expand<{
366
+ [mod in keyof API]: API[mod] extends FunctionReference<
367
+ infer FType,
368
+ "public",
369
+ infer FArgs,
370
+ infer FReturnType,
371
+ infer FComponentPath
372
+ >
373
+ ? FunctionReference<
374
+ FType,
375
+ "internal",
376
+ OpaqueIds<FArgs>,
377
+ OpaqueIds<FReturnType>,
378
+ FComponentPath
379
+ >
380
+ : UseApi<API[mod]>;
381
+ }>;
@@ -0,0 +1,2 @@
1
+ export * from "../../plugins/convex/client";
2
+ export * from "../../plugins/cross-domain/client";
@@ -0,0 +1,313 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as lib from "../lib.js";
12
+ import type * as util from "../util.js";
13
+
14
+ import type {
15
+ ApiFromModules,
16
+ FilterApi,
17
+ FunctionReference,
18
+ } from "convex/server";
19
+
20
+ /**
21
+ * A utility for referencing Convex functions in your app's API.
22
+ *
23
+ * Usage:
24
+ * ```js
25
+ * const myFunctionReference = api.myModule.myFunction;
26
+ * ```
27
+ */
28
+ declare const fullApi: ApiFromModules<{
29
+ lib: typeof lib;
30
+ util: typeof util;
31
+ }>;
32
+ export type Mounts = {
33
+ lib: {
34
+ create: FunctionReference<
35
+ "mutation",
36
+ "public",
37
+ {
38
+ input:
39
+ | {
40
+ createdAt: number;
41
+ email: string;
42
+ emailVerified: boolean;
43
+ image?: string;
44
+ name: string;
45
+ table: string;
46
+ twoFactorEnabled?: boolean;
47
+ updatedAt: number;
48
+ userId: string;
49
+ }
50
+ | {
51
+ createdAt: number;
52
+ expiresAt: number;
53
+ ipAddress?: string;
54
+ table: string;
55
+ token: string;
56
+ updatedAt: number;
57
+ userAgent?: string;
58
+ userId: string;
59
+ }
60
+ | {
61
+ accessToken?: string;
62
+ accessTokenExpiresAt?: number;
63
+ accountId: string;
64
+ createdAt: number;
65
+ idToken?: string;
66
+ password?: string;
67
+ providerId: string;
68
+ refreshToken?: string;
69
+ refreshTokenExpiresAt?: number;
70
+ scope?: string;
71
+ table: string;
72
+ updatedAt: number;
73
+ userId: string;
74
+ }
75
+ | {
76
+ backupCodes: string;
77
+ secret: string;
78
+ table: string;
79
+ userId: string;
80
+ }
81
+ | {
82
+ createdAt?: number;
83
+ expiresAt: number;
84
+ identifier: string;
85
+ table: string;
86
+ updatedAt?: number;
87
+ value: string;
88
+ }
89
+ | {
90
+ createdAt: number;
91
+ id?: string;
92
+ privateKey: string;
93
+ publicKey: string;
94
+ table: string;
95
+ };
96
+ },
97
+ any
98
+ >;
99
+ deleteAllForUser: FunctionReference<
100
+ "action",
101
+ "public",
102
+ { table: string; userId: string },
103
+ any
104
+ >;
105
+ deleteAllForUserPage: FunctionReference<
106
+ "mutation",
107
+ "public",
108
+ {
109
+ paginationOpts?: {
110
+ cursor: string | null;
111
+ endCursor?: string | null;
112
+ id?: number;
113
+ maximumBytesRead?: number;
114
+ maximumRowsRead?: number;
115
+ numItems: number;
116
+ };
117
+ table: string;
118
+ userId: string;
119
+ },
120
+ any
121
+ >;
122
+ deleteBy: FunctionReference<
123
+ "mutation",
124
+ "public",
125
+ {
126
+ field: string;
127
+ table: string;
128
+ unique?: boolean;
129
+ value: string | number | boolean | Array<string> | Array<number> | null;
130
+ },
131
+ any
132
+ >;
133
+ deleteOldVerifications: FunctionReference<
134
+ "action",
135
+ "public",
136
+ { currentTimestamp: number },
137
+ any
138
+ >;
139
+ deleteOldVerificationsPage: FunctionReference<
140
+ "mutation",
141
+ "public",
142
+ {
143
+ currentTimestamp: number;
144
+ paginationOpts?: {
145
+ cursor: string | null;
146
+ endCursor?: string | null;
147
+ id?: number;
148
+ maximumBytesRead?: number;
149
+ maximumRowsRead?: number;
150
+ numItems: number;
151
+ };
152
+ },
153
+ any
154
+ >;
155
+ getAccountByAccountIdAndProviderId: FunctionReference<
156
+ "query",
157
+ "public",
158
+ { accountId: string; providerId: string },
159
+ any
160
+ >;
161
+ getAccountsByUserId: FunctionReference<
162
+ "query",
163
+ "public",
164
+ { limit?: number; userId: string },
165
+ any
166
+ >;
167
+ getBy: FunctionReference<
168
+ "query",
169
+ "public",
170
+ {
171
+ field: string;
172
+ table: string;
173
+ unique?: boolean;
174
+ value: string | number | boolean | Array<string> | Array<number> | null;
175
+ },
176
+ any
177
+ >;
178
+ getByQuery: FunctionReference<
179
+ "query",
180
+ "public",
181
+ {
182
+ field: string;
183
+ table: string;
184
+ unique?: boolean;
185
+ value: string | number | boolean | Array<string> | Array<number> | null;
186
+ },
187
+ any
188
+ >;
189
+ getCurrentSession: FunctionReference<"query", "public", {}, any>;
190
+ getJwks: FunctionReference<"query", "public", { limit?: number }, any>;
191
+ listVerificationsByIdentifier: FunctionReference<
192
+ "query",
193
+ "public",
194
+ {
195
+ identifier: string;
196
+ limit?: number;
197
+ sortBy?: { direction: "asc" | "desc"; field: string };
198
+ },
199
+ any
200
+ >;
201
+ update: FunctionReference<
202
+ "mutation",
203
+ "public",
204
+ {
205
+ input:
206
+ | {
207
+ table: "account";
208
+ value: Record<string, any>;
209
+ where: {
210
+ field: string;
211
+ value:
212
+ | string
213
+ | number
214
+ | boolean
215
+ | Array<string>
216
+ | Array<number>
217
+ | null;
218
+ };
219
+ }
220
+ | {
221
+ table: "session";
222
+ value: Record<string, any>;
223
+ where: {
224
+ field: string;
225
+ value:
226
+ | string
227
+ | number
228
+ | boolean
229
+ | Array<string>
230
+ | Array<number>
231
+ | null;
232
+ };
233
+ }
234
+ | {
235
+ table: "verification";
236
+ value: Record<string, any>;
237
+ where: {
238
+ field: string;
239
+ value:
240
+ | string
241
+ | number
242
+ | boolean
243
+ | Array<string>
244
+ | Array<number>
245
+ | null;
246
+ };
247
+ }
248
+ | {
249
+ table: "user";
250
+ value: Record<string, any>;
251
+ where: {
252
+ field: string;
253
+ value:
254
+ | string
255
+ | number
256
+ | boolean
257
+ | Array<string>
258
+ | Array<number>
259
+ | null;
260
+ };
261
+ };
262
+ },
263
+ any
264
+ >;
265
+ updateTwoFactor: FunctionReference<
266
+ "mutation",
267
+ "public",
268
+ {
269
+ update: { backupCodes?: string; secret?: string; userId?: string };
270
+ userId: string;
271
+ },
272
+ any
273
+ >;
274
+ updateUserProviderAccounts: FunctionReference<
275
+ "mutation",
276
+ "public",
277
+ {
278
+ providerId: string;
279
+ update: {
280
+ accessToken?: string;
281
+ accessTokenExpiresAt?: number;
282
+ accountId?: string;
283
+ createdAt?: number;
284
+ idToken?: string;
285
+ password?: string;
286
+ providerId?: string;
287
+ refreshToken?: string;
288
+ refreshTokenExpiresAt?: number;
289
+ scope?: string;
290
+ updatedAt?: number;
291
+ userId?: string;
292
+ };
293
+ userId: string;
294
+ },
295
+ any
296
+ >;
297
+ };
298
+ };
299
+ // For now fullApiWithMounts is only fullApi which provides
300
+ // jump-to-definition in component client code.
301
+ // Use Mounts for the same type without the inference.
302
+ declare const fullApiWithMounts: typeof fullApi;
303
+
304
+ export declare const api: FilterApi<
305
+ typeof fullApiWithMounts,
306
+ FunctionReference<any, "public">
307
+ >;
308
+ export declare const internal: FilterApi<
309
+ typeof fullApiWithMounts,
310
+ FunctionReference<any, "internal">
311
+ >;
312
+
313
+ export declare const components: {};
@@ -0,0 +1,23 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import { anyApi, componentsGeneric } from "convex/server";
12
+
13
+ /**
14
+ * A utility for referencing Convex functions in your app's API.
15
+ *
16
+ * Usage:
17
+ * ```js
18
+ * const myFunctionReference = api.myModule.myFunction;
19
+ * ```
20
+ */
21
+ export const api = anyApi;
22
+ export const internal = anyApi;
23
+ export const components = componentsGeneric();