@convex-dev/better-auth 0.9.11 → 0.10.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 (102) hide show
  1. package/dist/auth-config.d.ts +43 -0
  2. package/dist/auth-config.d.ts.map +1 -0
  3. package/dist/auth-config.js +45 -0
  4. package/dist/auth-config.js.map +1 -0
  5. package/dist/auth-options.d.ts +3 -0
  6. package/dist/auth-options.d.ts.map +1 -0
  7. package/dist/auth-options.js +41 -0
  8. package/dist/auth-options.js.map +1 -0
  9. package/dist/auth.d.ts +1 -3
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/auth.js +2 -42
  12. package/dist/auth.js.map +1 -1
  13. package/dist/client/{adapterUtils.d.ts → adapter-utils.d.ts} +15 -15
  14. package/dist/client/adapter-utils.d.ts.map +1 -0
  15. package/dist/client/{adapterUtils.js → adapter-utils.js} +1 -1
  16. package/dist/client/adapter-utils.js.map +1 -0
  17. package/dist/client/adapter.d.ts +1 -2
  18. package/dist/client/adapter.d.ts.map +1 -1
  19. package/dist/client/adapter.js +4 -4
  20. package/dist/client/adapter.js.map +1 -1
  21. package/dist/client/create-api.d.ts +139 -0
  22. package/dist/client/create-api.d.ts.map +1 -0
  23. package/dist/client/create-api.js +204 -0
  24. package/dist/client/create-api.js.map +1 -0
  25. package/dist/client/create-client.d.ts +183 -0
  26. package/dist/client/create-client.d.ts.map +1 -0
  27. package/dist/client/create-client.js +311 -0
  28. package/dist/client/create-client.js.map +1 -0
  29. package/dist/client/{createSchema.d.ts → create-schema.d.ts} +1 -1
  30. package/dist/client/create-schema.d.ts.map +1 -0
  31. package/dist/client/{createSchema.js → create-schema.js} +11 -5
  32. package/dist/client/create-schema.js.map +1 -0
  33. package/dist/client/index.d.ts +4 -279
  34. package/dist/client/index.d.ts.map +1 -1
  35. package/dist/client/index.js +6 -463
  36. package/dist/client/index.js.map +1 -1
  37. package/dist/component/_generated/component.d.ts +0 -3
  38. package/dist/component/_generated/component.d.ts.map +1 -1
  39. package/dist/component/adapter.d.ts +19 -21
  40. package/dist/component/adapter.d.ts.map +1 -1
  41. package/dist/component/adapter.js +2 -2
  42. package/dist/component/adapter.js.map +1 -1
  43. package/dist/component/schema.d.ts +50 -50
  44. package/dist/nextjs/client.d.ts +4 -0
  45. package/dist/nextjs/client.d.ts.map +1 -0
  46. package/dist/nextjs/client.js +37 -0
  47. package/dist/nextjs/client.js.map +1 -0
  48. package/dist/nextjs/index.d.ts +19 -7
  49. package/dist/nextjs/index.d.ts.map +1 -1
  50. package/dist/nextjs/index.js +90 -36
  51. package/dist/nextjs/index.js.map +1 -1
  52. package/dist/plugins/convex/client.d.ts +1 -1
  53. package/dist/plugins/convex/client.d.ts.map +1 -1
  54. package/dist/plugins/convex/client.js +0 -1
  55. package/dist/plugins/convex/client.js.map +1 -1
  56. package/dist/plugins/convex/index.d.ts +239 -227
  57. package/dist/plugins/convex/index.d.ts.map +1 -1
  58. package/dist/plugins/convex/index.js +191 -37
  59. package/dist/plugins/convex/index.js.map +1 -1
  60. package/dist/plugins/cross-domain/client.d.ts +3 -3
  61. package/dist/plugins/cross-domain/client.d.ts.map +1 -1
  62. package/dist/plugins/cross-domain/index.d.ts +15 -70
  63. package/dist/plugins/cross-domain/index.d.ts.map +1 -1
  64. package/dist/plugins/cross-domain/index.js +8 -0
  65. package/dist/plugins/cross-domain/index.js.map +1 -1
  66. package/dist/react/index.d.ts +52 -2
  67. package/dist/react/index.d.ts.map +1 -1
  68. package/dist/react/index.js +133 -9
  69. package/dist/react/index.js.map +1 -1
  70. package/dist/react-start/index.d.ts +11 -41
  71. package/dist/react-start/index.d.ts.map +1 -1
  72. package/dist/react-start/index.js +82 -106
  73. package/dist/react-start/index.js.map +1 -1
  74. package/dist/utils/index.d.ts +20 -2
  75. package/dist/utils/index.d.ts.map +1 -1
  76. package/dist/utils/index.js +54 -1
  77. package/dist/utils/index.js.map +1 -1
  78. package/package.json +20 -13
  79. package/src/auth-config.ts +82 -0
  80. package/src/auth-options.ts +54 -0
  81. package/src/auth.ts +3 -56
  82. package/src/client/adapter.ts +5 -5
  83. package/src/client/create-api.ts +337 -0
  84. package/src/client/create-client.ts +446 -0
  85. package/src/client/{createSchema.ts → create-schema.ts} +10 -4
  86. package/src/client/index.ts +22 -771
  87. package/src/component/_generated/component.ts +0 -7
  88. package/src/component/adapter.ts +2 -3
  89. package/src/nextjs/client.tsx +52 -0
  90. package/src/nextjs/index.ts +138 -45
  91. package/src/plugins/convex/client.ts +1 -1
  92. package/src/plugins/convex/index.ts +337 -51
  93. package/src/plugins/cross-domain/index.ts +10 -2
  94. package/src/react/index.tsx +195 -9
  95. package/src/react-start/index.ts +126 -171
  96. package/src/test.ts +1 -1
  97. package/src/utils/index.ts +96 -1
  98. package/dist/client/adapterUtils.d.ts.map +0 -1
  99. package/dist/client/adapterUtils.js.map +0 -1
  100. package/dist/client/createSchema.d.ts.map +0 -1
  101. package/dist/client/createSchema.js.map +0 -1
  102. /package/src/client/{adapterUtils.ts → adapter-utils.ts} +0 -0
@@ -0,0 +1,311 @@
1
+ import { httpActionGeneric, internalMutationGeneric, queryGeneric, } from "convex/server";
2
+ import { ConvexError, v } from "convex/values";
3
+ import { convexAdapter } from "./adapter.js";
4
+ import { corsRouter } from "convex-helpers/server/cors";
5
+ import defaultSchema from "../component/schema.js";
6
+ import {} from "../component/_generated/component.js";
7
+ import {} from "./index.js";
8
+ /**
9
+ * Backend API for the Better Auth component.
10
+ * Responsible for exposing the `client` and `triggers` APIs to the client, http
11
+ * route registration, and having convenience methods for interacting with the
12
+ * component from the backend.
13
+ *
14
+ * @param component - Generally `components.betterAuth` from
15
+ * `./_generated/api` once you've configured it in `convex.config.ts`.
16
+ * @param config - Configuration options for the component.
17
+ * @param config.local - Local schema configuration.
18
+ * @param config.verbose - Whether to enable verbose logging.
19
+ * @param config.triggers - Triggers configuration.
20
+ * @param config.authFunctions - Authentication functions configuration.
21
+ */
22
+ export const createClient = (component, config) => {
23
+ const safeGetAuthUser = async (ctx) => {
24
+ const identity = await ctx.auth.getUserIdentity();
25
+ if (!identity) {
26
+ return;
27
+ }
28
+ const session = (await ctx.runQuery(component.adapter.findOne, {
29
+ model: "session",
30
+ where: [
31
+ {
32
+ field: "_id",
33
+ value: identity.sessionId,
34
+ },
35
+ {
36
+ field: "expiresAt",
37
+ operator: "gt",
38
+ value: new Date().getTime(),
39
+ },
40
+ ],
41
+ }));
42
+ if (!session) {
43
+ return;
44
+ }
45
+ const doc = (await ctx.runQuery(component.adapter.findOne, {
46
+ model: "user",
47
+ where: [
48
+ {
49
+ field: "_id",
50
+ value: identity.subject,
51
+ },
52
+ ],
53
+ }));
54
+ if (!doc) {
55
+ return;
56
+ }
57
+ return doc;
58
+ };
59
+ const getAuthUser = async (ctx) => {
60
+ const user = await safeGetAuthUser(ctx);
61
+ if (!user) {
62
+ throw new ConvexError("Unauthenticated");
63
+ }
64
+ return user;
65
+ };
66
+ const getHeaders = async (ctx) => {
67
+ const identity = await ctx.auth.getUserIdentity();
68
+ if (!identity) {
69
+ return new Headers();
70
+ }
71
+ // Don't validate the session here, let Better Auth handle that
72
+ const session = await ctx.runQuery(component.adapter.findOne, {
73
+ model: "session",
74
+ where: [
75
+ {
76
+ field: "_id",
77
+ value: identity.sessionId,
78
+ },
79
+ ],
80
+ });
81
+ return new Headers({
82
+ ...(session?.token ? { authorization: `Bearer ${session.token}` } : {}),
83
+ ...(session?.ipAddress
84
+ ? { "x-forwarded-for": session.ipAddress }
85
+ : {}),
86
+ });
87
+ };
88
+ return {
89
+ /**
90
+ * Returns the Convex database adapter for use in Better Auth options.
91
+ * @param ctx - The Convex context
92
+ * @returns The Convex database adapter
93
+ */
94
+ adapter: (ctx) => convexAdapter(ctx, component, {
95
+ ...config,
96
+ debugLogs: config?.verbose,
97
+ }),
98
+ /**
99
+ * Returns the Better Auth auth object and headers for using Better Auth API
100
+ * methods directly in a Convex mutation or query. Convex functions don't
101
+ * have access to request headers, so the headers object is created at
102
+ * runtime with the token for the current session as a Bearer token.
103
+ *
104
+ * @param createAuth - The createAuth function
105
+ * @param ctx - The Convex context
106
+ * @returns A promise that resolves to the Better Auth `auth` API object and
107
+ * headers.
108
+ */
109
+ getAuth: async (createAuth, ctx) => ({
110
+ auth: createAuth(ctx),
111
+ headers: await getHeaders(ctx),
112
+ }),
113
+ /**
114
+ * Returns a Headers object for the current session using the session id
115
+ * from the current user identity via `ctx.auth.getUserIdentity()`. This is
116
+ * used to pass the headers to the Better Auth API methods when using the
117
+ * `getAuth` method.
118
+ *
119
+ * @param ctx - The Convex context
120
+ * @returns The headers
121
+ */
122
+ getHeaders,
123
+ /**
124
+ * Returns the current user or null if the user is not found
125
+ * @param ctx - The Convex context
126
+ * @returns The user or null if the user is not found
127
+ */
128
+ safeGetAuthUser,
129
+ /**
130
+ * Returns the current user or throws an error if the user is not found
131
+ *
132
+ * @param ctx - The Convex context
133
+ * @returns The user or throws an error if the user is not found
134
+ */
135
+ getAuthUser,
136
+ /**
137
+ * Returns a user by their Better Auth user id.
138
+ * @param ctx - The Convex context
139
+ * @param id - The Better Auth user id
140
+ * @returns The user or null if the user is not found
141
+ */
142
+ getAnyUserById: async (ctx, id) => {
143
+ return (await ctx.runQuery(component.adapter.findOne, {
144
+ model: "user",
145
+ where: [{ field: "_id", value: id }],
146
+ }));
147
+ },
148
+ /**
149
+ * Replaces 0.7 behavior of returning a new user id from
150
+ * onCreateUser
151
+ * @param ctx - The Convex context
152
+ * @param authId - The Better Auth user id
153
+ * @param userId - The app user id
154
+ * @deprecated in 0.9
155
+ */
156
+ setUserId: async (ctx, authId, userId) => {
157
+ await ctx.runMutation(component.adapter.updateOne, {
158
+ input: {
159
+ model: "user",
160
+ where: [{ field: "_id", value: authId }],
161
+ update: { userId },
162
+ },
163
+ });
164
+ },
165
+ /**
166
+ * Exposes functions for use with the ClientAuthBoundary component. Currently
167
+ * only contains getAuthUser.
168
+ * @returns Functions to pass to the ClientAuthBoundary component.
169
+ */
170
+ clientApi: () => ({
171
+ /**
172
+ * Convex query to get the current user. For use with the ClientAuthBoundary component.
173
+ *
174
+ * ```ts title="convex/auth.ts"
175
+ * export const { getAuthUser } = authComponent.clientApi();
176
+ * ```
177
+ *
178
+ * @returns The user or throws an error if the user is not found
179
+ */
180
+ getAuthUser: queryGeneric({
181
+ args: {},
182
+ handler: async (ctx) => {
183
+ return await getAuthUser(ctx);
184
+ },
185
+ }),
186
+ }),
187
+ /**
188
+ * Exposes functions for executing trigger callbacks in the app context.
189
+ *
190
+ * Callbacks are defined in the `triggers` option to the component client config.
191
+ *
192
+ * See {@link createClient} for more information.
193
+ *
194
+ * @returns Functions to execute trigger callbacks in the app context.
195
+ */
196
+ triggersApi: () => ({
197
+ onCreate: internalMutationGeneric({
198
+ args: {
199
+ doc: v.any(),
200
+ model: v.string(),
201
+ },
202
+ handler: async (ctx, args) => {
203
+ await config?.triggers?.[args.model]?.onCreate?.(ctx, args.doc);
204
+ },
205
+ }),
206
+ onUpdate: internalMutationGeneric({
207
+ args: {
208
+ oldDoc: v.any(),
209
+ newDoc: v.any(),
210
+ model: v.string(),
211
+ },
212
+ handler: async (ctx, args) => {
213
+ await config?.triggers?.[args.model]?.onUpdate?.(ctx, args.newDoc, args.oldDoc);
214
+ },
215
+ }),
216
+ onDelete: internalMutationGeneric({
217
+ args: {
218
+ doc: v.any(),
219
+ model: v.string(),
220
+ },
221
+ handler: async (ctx, args) => {
222
+ await config?.triggers?.[args.model]?.onDelete?.(ctx, args.doc);
223
+ },
224
+ }),
225
+ }),
226
+ registerRoutes: (http, createAuth, opts = {}) => {
227
+ const staticAuth = createAuth({});
228
+ const path = staticAuth.options.basePath ?? "/api/auth";
229
+ const authRequestHandler = httpActionGeneric(async (ctx, request) => {
230
+ if (config?.verbose) {
231
+ console.log("options.baseURL", staticAuth.options.baseURL);
232
+ console.log("request headers", request.headers);
233
+ }
234
+ const auth = createAuth(ctx);
235
+ const response = await auth.handler(request);
236
+ if (config?.verbose) {
237
+ console.log("response headers", response.headers);
238
+ }
239
+ return response;
240
+ });
241
+ const wellKnown = http.lookup("/.well-known/openid-configuration", "GET");
242
+ // If registerRoutes is used multiple times, this may already be defined
243
+ if (!wellKnown) {
244
+ // Redirect root well-known to api well-known
245
+ http.route({
246
+ path: "/.well-known/openid-configuration",
247
+ method: "GET",
248
+ handler: httpActionGeneric(async () => {
249
+ const url = `${process.env.CONVEX_SITE_URL}${path}/convex/.well-known/openid-configuration`;
250
+ return Response.redirect(url);
251
+ }),
252
+ });
253
+ }
254
+ if (!opts.cors) {
255
+ http.route({
256
+ pathPrefix: `${path}/`,
257
+ method: "GET",
258
+ handler: authRequestHandler,
259
+ });
260
+ http.route({
261
+ pathPrefix: `${path}/`,
262
+ method: "POST",
263
+ handler: authRequestHandler,
264
+ });
265
+ return;
266
+ }
267
+ const corsOpts = typeof opts.cors === "boolean"
268
+ ? { allowedOrigins: [], allowedHeaders: [], exposedHeaders: [] }
269
+ : opts.cors;
270
+ let trustedOriginsOption;
271
+ const cors = corsRouter(http, {
272
+ allowedOrigins: async (request) => {
273
+ trustedOriginsOption =
274
+ trustedOriginsOption ??
275
+ (await staticAuth.$context).options.trustedOrigins ??
276
+ [];
277
+ const trustedOrigins = Array.isArray(trustedOriginsOption)
278
+ ? trustedOriginsOption
279
+ : await trustedOriginsOption(request);
280
+ return trustedOrigins
281
+ .map((origin) =>
282
+ // Strip trailing wildcards, unsupported for allowedOrigins
283
+ origin.endsWith("*") && origin.length > 1
284
+ ? origin.slice(0, -1)
285
+ : origin)
286
+ .concat(corsOpts.allowedOrigins ?? []);
287
+ },
288
+ allowCredentials: true,
289
+ allowedHeaders: [
290
+ "Content-Type",
291
+ "Better-Auth-Cookie",
292
+ "Authorization",
293
+ ].concat(corsOpts.allowedHeaders ?? []),
294
+ exposedHeaders: ["Set-Better-Auth-Cookie"].concat(corsOpts.exposedHeaders ?? []),
295
+ debug: config?.verbose,
296
+ enforceAllowOrigins: false,
297
+ });
298
+ cors.route({
299
+ pathPrefix: `${path}/`,
300
+ method: "GET",
301
+ handler: authRequestHandler,
302
+ });
303
+ cors.route({
304
+ pathPrefix: `${path}/`,
305
+ method: "POST",
306
+ handler: authRequestHandler,
307
+ });
308
+ },
309
+ };
310
+ };
311
+ //# sourceMappingURL=create-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../src/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAc,CAAC,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAqB,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAoC,MAAM,YAAY,CAAC;AAsD9D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAK1B,SAAc,EACd,MAWC,EACD,EAAE;IAGF,MAAM,eAAe,GAAG,KAAK,EAAE,GAA0B,EAAE,EAAE;QAC3D,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;YAC7D,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE;gBACL;oBACE,KAAK,EAAE,KAAK;oBACZ,KAAK,EAAE,QAAQ,CAAC,SAAmB;iBACpC;gBACD;oBACE,KAAK,EAAE,WAAW;oBAClB,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;iBAC5B;aACF;S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
18
18
  }>;
19
- //# sourceMappingURL=createSchema.d.ts.map
19
+ //# sourceMappingURL=create-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-schema.d.ts","sourceRoot":"","sources":["../../src/client/create-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,gBAAgB,CAAC;AAI3E,eAAO,MAAM,WAAW;;;;;;;;CAQvB,CAAC;AAkDF,eAAO,MAAM,YAAY,GAAU,mBAGhC;IACD,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;;;;EAiGA,CAAC"}
@@ -28,7 +28,7 @@ const specialFields = (tables) => Object.fromEntries(Object.entries(tables)
28
28
  const mergedIndexFields = (tables) => Object.fromEntries(Object.entries(tables).map(([key, table]) => {
29
29
  const manualIndexes = indexFields[key]?.map((index) => {
30
30
  return typeof index === "string"
31
- ? table.fields[index]?.fieldName ?? index
31
+ ? (table.fields[index]?.fieldName ?? index)
32
32
  : index.map((i) => table.fields[i]?.fieldName ?? i);
33
33
  }) || [];
34
34
  const specialFieldIndexes = Object.keys(specialFields(tables)[key] ||
@@ -47,9 +47,15 @@ export const createSchema = async ({ file, tables, }) => {
47
47
  if (baseName === "convex") {
48
48
  throw new Error("Better Auth schema must be generated in the Better Auth component directory.");
49
49
  }
50
- let code = `// This file is auto-generated. Do not edit this file manually.
51
- // To regenerate the schema, run:
52
- // \`npx @better-auth/cli generate --output ${file} -y\`
50
+ let code = `/**
51
+ * This file is auto-generated. Do not edit this file manually.
52
+ * To regenerate the schema, run:
53
+ * \`npx @better-auth/cli generate --output ${file} -y\`
54
+ *
55
+ * To customize the schema, generate to an alternate file and import
56
+ * the table definitions to your schema file. See
57
+ * https://convex-better-auth.netlify.app/features/local-install#adding-custom-indexes.
58
+ */
53
59
 
54
60
  import { defineSchema, defineTable } from "convex/server";
55
61
  import { v } from "convex/values";
@@ -105,4 +111,4 @@ export default schema;
105
111
  overwrite: true,
106
112
  };
107
113
  };
108
- //# sourceMappingURL=createSchema.js.map
114
+ //# sourceMappingURL=create-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-schema.js","sourceRoot":"","sources":["../../src/client/create-schema.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,mEAAmE;AACnE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7E,SAAS,EAAE,CAAC,KAAK,CAAC;IAClB,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/C,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC;IAC3C,OAAO,EAAE,CAAC,cAAc,CAAC;IACzB,YAAY,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;CACvC,CAAC;AAEF,uDAAuD;AACvD,MAAM,aAAa,GAAG,CAAC,MAA0B,EAAE,EAAE,CACnD,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;KACnB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACpB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC1B,KAAK,CAAC,SAAS,IAAI,QAAQ;QAC3B;YACE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;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AAM,CAAC,KAAK,CAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,IAAwB,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,CAAC,WAAmB,EAAE,EAAE,CACvC,IAAI,CAAC,QAAQ;gBACX,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,gCAAgC,WAAW,IAAI,CAAC;YACtD,OAAO,OAAO,IAAI,CAAC,SAAS,IAAI,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAC9D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC;MACP,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QACnE,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;;;;;CAKT,CAAC;IAEA,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,IAAI,IAAI,aAAa;QAC3B,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC,CAAC"}
@@ -1,281 +1,6 @@
1
- import { type DataModelFromSchemaDefinition, type DefaultFunctionArgs, type FunctionReference, type GenericActionCtx, type GenericDataModel, type GenericMutationCtx, type GenericQueryCtx, type GenericSchema, type HttpRouter, type SchemaDefinition } from "convex/server";
2
- import { type Infer } from "convex/values";
3
1
  import { convexAdapter } from "./adapter.js";
4
- import { type Auth, betterAuth } from "better-auth";
5
- import type { DBAdapterInstance } from "better-auth/adapters";
6
- import defaultSchema from "../component/schema.js";
7
- import type { ComponentApi } from "../component/_generated/component.js";
8
- import type { TableNames } from "../component/_generated/dataModel.js";
9
- export { convexAdapter };
10
- export type CreateAdapter = <Ctx extends GenericCtx<GenericDataModel>>(ctx: Ctx) => DBAdapterInstance;
11
- export type CreateAuth<DataModel extends GenericDataModel, A extends ReturnType<typeof betterAuth> = Auth> = ((ctx: GenericCtx<DataModel>) => A) | ((ctx: GenericCtx<DataModel>, opts?: {
12
- optionsOnly?: boolean;
13
- }) => A);
14
- export declare const getStaticAuth: <DataModel extends GenericDataModel, Auth extends ReturnType<typeof betterAuth>>(createAuth: CreateAuth<DataModel, Auth>) => Auth;
15
- export type EventFunction<T extends DefaultFunctionArgs> = FunctionReference<"mutation", "internal" | "public", T>;
16
- export type GenericCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericQueryCtx<DataModel> | GenericMutationCtx<DataModel> | GenericActionCtx<DataModel>;
17
- export type AuthFunctions = {
18
- onCreate?: FunctionReference<"mutation", "internal", {
19
- [key: string]: any;
20
- }>;
21
- onUpdate?: FunctionReference<"mutation", "internal", {
22
- [key: string]: any;
23
- }>;
24
- onDelete?: FunctionReference<"mutation", "internal", {
25
- [key: string]: any;
26
- }>;
27
- };
28
- export declare const createApi: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>>(schema: Schema, createAuth: CreateAuth<DataModel>) => {
29
- migrationRemoveUserId: import("convex/server").RegisteredMutation<"public", {
30
- userId: string;
31
- }, Promise<void>>;
32
- create: import("convex/server").RegisteredMutation<"public", {
33
- select?: string[] | undefined;
34
- onCreateHandle?: string | undefined;
35
- input: {
36
- model: string;
37
- data: {
38
- [x: string]: any;
39
- [x: number]: any;
40
- [x: symbol]: any;
41
- };
42
- };
43
- }, Promise<any>>;
44
- findOne: import("convex/server").RegisteredQuery<"public", {
45
- where?: {
46
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
47
- connector?: "AND" | "OR" | undefined;
48
- value: string | number | boolean | string[] | number[] | null;
49
- field: string;
50
- }[] | undefined;
51
- select?: string[] | undefined;
52
- model: string;
53
- }, Promise<import("convex/server").GenericDocument | null>>;
54
- findMany: import("convex/server").RegisteredQuery<"public", {
55
- where?: {
56
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
57
- connector?: "AND" | "OR" | undefined;
58
- value: string | number | boolean | string[] | number[] | null;
59
- field: string;
60
- }[] | undefined;
61
- sortBy?: {
62
- field: string;
63
- direction: "asc" | "desc";
64
- } | undefined;
65
- limit?: number | undefined;
66
- offset?: number | undefined;
67
- model: string;
68
- paginationOpts: {
69
- id?: number;
70
- endCursor?: string | null;
71
- maximumRowsRead?: number;
72
- maximumBytesRead?: number;
73
- numItems: number;
74
- cursor: string | null;
75
- };
76
- }, Promise<import("convex/server").PaginationResult<import("convex/server").GenericDocument>>>;
77
- updateOne: import("convex/server").RegisteredMutation<"public", {
78
- onUpdateHandle?: string | undefined;
79
- input: {
80
- where?: {
81
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
82
- connector?: "AND" | "OR" | undefined;
83
- value: string | number | boolean | string[] | number[] | null;
84
- field: string;
85
- }[] | undefined;
86
- update: {
87
- [x: string]: unknown;
88
- [x: number]: unknown;
89
- [x: symbol]: unknown;
90
- };
91
- model: TableNames;
92
- };
93
- }, Promise<any>>;
94
- updateMany: import("convex/server").RegisteredMutation<"public", {
95
- onUpdateHandle?: string | undefined;
96
- input: {
97
- where?: {
98
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
99
- connector?: "AND" | "OR" | undefined;
100
- value: string | number | boolean | string[] | number[] | null;
101
- field: string;
102
- }[] | undefined;
103
- update: {
104
- [x: string]: unknown;
105
- [x: number]: unknown;
106
- [x: symbol]: unknown;
107
- };
108
- model: TableNames;
109
- };
110
- paginationOpts: {
111
- id?: number;
112
- endCursor?: string | null;
113
- maximumRowsRead?: number;
114
- maximumBytesRead?: number;
115
- numItems: number;
116
- cursor: string | null;
117
- };
118
- }, Promise<{
119
- count: number;
120
- ids: import("convex/values").Value[];
121
- isDone: boolean;
122
- continueCursor: import("convex/server").Cursor;
123
- splitCursor?: import("convex/server").Cursor | null;
124
- pageStatus?: "SplitRecommended" | "SplitRequired" | null;
125
- }>>;
126
- deleteOne: import("convex/server").RegisteredMutation<"public", {
127
- onDeleteHandle?: string | undefined;
128
- input: {
129
- where?: {
130
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
131
- connector?: "AND" | "OR" | undefined;
132
- value: string | number | boolean | string[] | number[] | null;
133
- field: string;
134
- }[] | undefined;
135
- model: TableNames;
136
- };
137
- }, Promise<import("convex/server").GenericDocument | undefined>>;
138
- deleteMany: import("convex/server").RegisteredMutation<"public", {
139
- onDeleteHandle?: string | undefined;
140
- input: {
141
- where?: {
142
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
143
- connector?: "AND" | "OR" | undefined;
144
- value: string | number | boolean | string[] | number[] | null;
145
- field: string;
146
- }[] | undefined;
147
- model: TableNames;
148
- };
149
- paginationOpts: {
150
- id?: number;
151
- endCursor?: string | null;
152
- maximumRowsRead?: number;
153
- maximumBytesRead?: number;
154
- numItems: number;
155
- cursor: string | null;
156
- };
157
- }, Promise<{
158
- count: number;
159
- ids: import("convex/values").Value[];
160
- isDone: boolean;
161
- continueCursor: import("convex/server").Cursor;
162
- splitCursor?: import("convex/server").Cursor | null;
163
- pageStatus?: "SplitRecommended" | "SplitRequired" | null;
164
- }>>;
165
- };
166
- export type Triggers<DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>> = {
167
- [K in keyof Schema["tables"]]?: {
168
- onCreate?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, doc: Infer<Schema["tables"][K]["validator"]> & {
169
- _id: string;
170
- _creationTime: number;
171
- }) => Promise<void>;
172
- onUpdate?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, newDoc: Infer<Schema["tables"][K]["validator"]> & {
173
- _id: string;
174
- _creationTime: number;
175
- }, oldDoc: Infer<Schema["tables"][K]["validator"]> & {
176
- _id: string;
177
- _creationTime: number;
178
- }) => Promise<void>;
179
- onDelete?: <Ctx extends GenericMutationCtx<DataModel>>(ctx: Ctx, doc: Infer<Schema["tables"][K]["validator"]> & {
180
- _id: string;
181
- _creationTime: number;
182
- }) => Promise<void>;
183
- };
184
- };
185
- type SlimComponentApi = {
186
- adapter: {
187
- create: FunctionReference<"mutation", "internal">;
188
- findOne: FunctionReference<"query", "internal">;
189
- findMany: FunctionReference<"query", "internal">;
190
- updateOne: FunctionReference<"mutation", "internal">;
191
- updateMany: FunctionReference<"mutation", "internal">;
192
- deleteOne: FunctionReference<"mutation", "internal">;
193
- deleteMany: FunctionReference<"mutation", "internal">;
194
- migrationRemoveUserId?: FunctionReference<"mutation", "internal">;
195
- };
196
- adapterTest?: ComponentApi["adapterTest"];
197
- };
198
- export declare const createClient: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<GenericSchema, true> = typeof defaultSchema, Api extends SlimComponentApi = SlimComponentApi>(component: Api, config?: {
199
- local?: {
200
- schema?: Schema;
201
- };
202
- verbose?: boolean;
203
- } & ({
204
- triggers: Triggers<DataModel, Schema>;
205
- authFunctions: AuthFunctions;
206
- } | {
207
- triggers?: undefined;
208
- })) => {
209
- component: Api;
210
- adapter: (ctx: GenericCtx<DataModel>) => import("better-auth/adapters").AdapterFactory;
211
- getAuth: <T extends CreateAuth<DataModel>>(createAuth: T, ctx: GenericCtx<DataModel>) => Promise<{
212
- auth: ReturnType<T>;
213
- headers: Headers;
214
- }>;
215
- getHeaders: (ctx: GenericCtx<DataModel>) => Promise<Headers>;
216
- /**
217
- * Returns the current user or null if the user is not found
218
- * @param ctx - The Convex context
219
- * @returns The user or null if the user is not found
220
- */
221
- safeGetAuthUser: (ctx: GenericCtx<DataModel>) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"] | undefined>;
222
- /**
223
- * Returns the current user.
224
- * @param ctx - The Convex context
225
- * @returns The user or throws an error if the user is not found
226
- */
227
- getAuthUser: (ctx: GenericCtx<DataModel>) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"]>;
228
- /**
229
- * Returns a user by their Better Auth user id.
230
- * @param ctx - The Convex context
231
- * @param id - The Better Auth user id
232
- * @returns The user or null if the user is not found
233
- */
234
- getAnyUserById: (ctx: GenericCtx<DataModel>, id: string) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"] | null>;
235
- /**
236
- * Replaces 0.7 behavior of returning a new user id from
237
- * onCreateUser
238
- * @param ctx - The Convex context
239
- * @param authId - The Better Auth user id
240
- * @param userId - The app user id
241
- * @deprecated in 0.9
242
- */
243
- setUserId: (ctx: GenericMutationCtx<DataModel>, authId: string, userId: string) => Promise<void>;
244
- /**
245
- * Temporary method to simplify 0.9 migration, gets a user by `userId` field
246
- * @param ctx - The Convex context
247
- * @param userId - The app user id
248
- * @returns The user or null if the user is not found
249
- */
250
- migrationGetUser: (ctx: GenericMutationCtx<DataModel>, userId: string) => Promise<DataModelFromSchemaDefinition<Schema>["user"]["document"] | null>;
251
- /**
252
- * Temporary method to simplify 0.9 migration, removes the `userId` field
253
- * from the Better Auth user record
254
- * @param ctx - The Convex context
255
- * @param userId - The app user id
256
- */
257
- migrationRemoveUserId: (ctx: GenericMutationCtx<DataModel>, userId: string) => Promise<void>;
258
- triggersApi: () => {
259
- onCreate: import("convex/server").RegisteredMutation<"internal", {
260
- model: string;
261
- doc: any;
262
- }, Promise<void>>;
263
- onUpdate: import("convex/server").RegisteredMutation<"internal", {
264
- model: string;
265
- newDoc: any;
266
- oldDoc: any;
267
- }, Promise<void>>;
268
- onDelete: import("convex/server").RegisteredMutation<"internal", {
269
- model: string;
270
- doc: any;
271
- }, Promise<void>>;
272
- };
273
- registerRoutes: (http: HttpRouter, createAuth: CreateAuth<DataModel>, opts?: {
274
- cors?: boolean | {
275
- allowedOrigins?: string[];
276
- allowedHeaders?: string[];
277
- exposedHeaders?: string[];
278
- };
279
- }) => void;
280
- };
2
+ import { type AuthFunctions, createClient, type Triggers } from "./create-client.js";
3
+ import { createApi } from "./create-api.js";
4
+ import { type CreateAuth, type EventFunction, type GenericCtx } from "../utils/index.js";
5
+ export { convexAdapter, createClient, createApi, type CreateAuth, type EventFunction, type GenericCtx, type Triggers, type AuthFunctions, };
281
6
  //# sourceMappingURL=index.d.ts.map