@better-auth/core 1.4.6-beta.2 → 1.4.6-beta.4

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 (59) hide show
  1. package/.turbo/turbo-build.log +31 -30
  2. package/dist/api/index.d.mts +1 -2
  3. package/dist/api/index.mjs +3 -2
  4. package/dist/async_hooks/index.d.mts +1 -1
  5. package/dist/async_hooks/index.mjs +2 -1
  6. package/dist/async_hooks-CrTStdt6.mjs +45 -0
  7. package/dist/context/index.d.mts +2 -3
  8. package/dist/context/index.mjs +3 -2
  9. package/dist/{context-DgQ9XGBl.mjs → context-su4uu82y.mjs} +1 -1
  10. package/dist/db/adapter/index.d.mts +2 -3
  11. package/dist/db/adapter/index.mjs +955 -1
  12. package/dist/db/index.d.mts +2 -3
  13. package/dist/db/index.mjs +2 -1
  14. package/dist/env/index.d.mts +1 -1
  15. package/dist/env/index.mjs +1 -1
  16. package/dist/error/index.mjs +3 -2
  17. package/dist/{error-BhAKg8LX.mjs → error-CMXuwPsa.mjs} +1 -1
  18. package/dist/get-tables-BGfrxIVZ.mjs +252 -0
  19. package/dist/{index-D_XSRX55.d.mts → index-Bp1Bfmzt.d.mts} +307 -32
  20. package/dist/{index-DgwIISs7.d.mts → index-Da4Ujjef.d.mts} +0 -1
  21. package/dist/index.d.mts +2 -3
  22. package/dist/oauth2/index.d.mts +1 -2
  23. package/dist/oauth2/index.mjs +1 -1
  24. package/dist/social-providers/index.d.mts +2 -3
  25. package/dist/social-providers/index.mjs +22 -8
  26. package/dist/utils/index.d.mts +10 -1
  27. package/dist/utils/index.mjs +3 -2
  28. package/dist/utils-BqQC77zO.mjs +43 -0
  29. package/package.json +8 -6
  30. package/src/async_hooks/convex.spec.ts +12 -0
  31. package/src/async_hooks/index.ts +60 -25
  32. package/src/db/adapter/factory.ts +1368 -0
  33. package/src/db/adapter/get-default-field-name.ts +59 -0
  34. package/src/db/adapter/get-default-model-name.ts +51 -0
  35. package/src/db/adapter/get-field-attributes.ts +62 -0
  36. package/src/db/adapter/get-field-name.ts +43 -0
  37. package/src/db/adapter/get-id-field.ts +141 -0
  38. package/src/db/adapter/get-model-name.ts +36 -0
  39. package/src/db/adapter/index.ts +12 -0
  40. package/src/db/adapter/types.ts +161 -0
  41. package/src/db/adapter/utils.ts +61 -0
  42. package/src/db/get-tables.ts +276 -0
  43. package/src/db/index.ts +2 -0
  44. package/src/db/test/get-tables.test.ts +62 -0
  45. package/src/env/logger.ts +4 -6
  46. package/src/oauth2/oauth-provider.ts +1 -1
  47. package/src/social-providers/google.ts +46 -17
  48. package/src/types/context.ts +10 -0
  49. package/src/types/helper.ts +4 -0
  50. package/src/types/init-options.ts +24 -24
  51. package/src/utils/id.ts +5 -0
  52. package/src/utils/index.ts +3 -0
  53. package/src/utils/json.ts +25 -0
  54. package/src/utils/string.ts +3 -0
  55. package/dist/async_hooks-BfRfbd1J.mjs +0 -18
  56. package/dist/utils-C5EN75oV.mjs +0 -7
  57. /package/dist/{env-8yWFh7b8.mjs → env-D6s-lvJz.mjs} +0 -0
  58. /package/dist/{index-X1Fs3IbM.d.mts → index-D4vfN5ui.d.mts} +0 -0
  59. /package/dist/{oauth2-B2XPHgx5.mjs → oauth2-7k48hhcV.mjs} +0 -0
@@ -1,3 +1,2 @@
1
- import { Cr as DBFieldAttributeConfig, Dr as SecondaryStorage, Er as ModelNames, Sr as DBFieldAttribute, Tr as DBPrimitive, _r as Account, ar as FieldAttributeConfig, br as BaseModelNames, cr as Verification, dr as userSchema, fr as coreSchema, gr as rateLimitSchema, hr as RateLimit, ir as FieldAttribute, lr as verificationSchema, mr as sessionSchema, nr as AuthPluginSchema, or as FieldType, pr as Session, rr as BetterAuthDbSchema, sr as Primitive, ur as User, vr as accountSchema, wr as DBFieldType, xr as BetterAuthDBSchema, yr as BetterAuthPluginDBSchema } from "../index-D_XSRX55.mjs";
2
- import "../index-X1Fs3IbM.mjs";
3
- export { Account, AuthPluginSchema, BaseModelNames, BetterAuthDBSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, ModelNames, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
1
+ import { Ar as verificationSchema, Br as BetterAuthPluginDBSchema, Cr as BetterAuthDbSchema, Dr as Primitive, Er as FieldType, Fr as sessionSchema, Gr as DBFieldType, Hr as BetterAuthDBSchema, Ir as RateLimit, Jr as SecondaryStorage, Kr as DBPrimitive, Lr as rateLimitSchema, Mr as userSchema, Nr as coreSchema, Or as getAuthTables, Pr as Session, Rr as Account, Sr as AuthPluginSchema, Tr as FieldAttributeConfig, Ur as DBFieldAttribute, Vr as BaseModelNames, Wr as DBFieldAttributeConfig, jr as User, kr as Verification, qr as ModelNames, wr as FieldAttribute, zr as accountSchema } from "../index-Bp1Bfmzt.mjs";
2
+ export { Account, AuthPluginSchema, BaseModelNames, BetterAuthDBSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, ModelNames, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
package/dist/db/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as getAuthTables } from "../get-tables-BGfrxIVZ.mjs";
1
2
  import * as z from "zod";
2
3
 
3
4
  //#region src/db/schema/shared.ts
@@ -58,4 +59,4 @@ const verificationSchema = coreSchema.extend({
58
59
  });
59
60
 
60
61
  //#endregion
61
- export { accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
62
+ export { accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -1,2 +1,2 @@
1
- import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-X1Fs3IbM.mjs";
1
+ import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-D4vfN5ui.mjs";
2
2
  export { ENV, EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,3 +1,3 @@
1
- import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-8yWFh7b8.mjs";
1
+ import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-D6s-lvJz.mjs";
2
2
 
3
3
  export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,4 +1,5 @@
1
- import "../utils-C5EN75oV.mjs";
2
- import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-BhAKg8LX.mjs";
1
+ import "../env-D6s-lvJz.mjs";
2
+ import "../utils-BqQC77zO.mjs";
3
+ import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-CMXuwPsa.mjs";
3
4
 
4
5
  export { BASE_ERROR_CODES, BetterAuthError };
@@ -1,4 +1,4 @@
1
- import { t as defineErrorCodes } from "./utils-C5EN75oV.mjs";
1
+ import { i as defineErrorCodes } from "./utils-BqQC77zO.mjs";
2
2
 
3
3
  //#region src/error/codes.ts
4
4
  const BASE_ERROR_CODES = defineErrorCodes({
@@ -0,0 +1,252 @@
1
+ //#region src/db/get-tables.ts
2
+ const getAuthTables = (options) => {
3
+ const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
4
+ const schema = plugin.schema;
5
+ if (!schema) return acc;
6
+ for (const [key, value] of Object.entries(schema)) acc[key] = {
7
+ fields: {
8
+ ...acc[key]?.fields,
9
+ ...value.fields
10
+ },
11
+ modelName: value.modelName || key
12
+ };
13
+ return acc;
14
+ }, {});
15
+ const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
16
+ const rateLimitTable = { rateLimit: {
17
+ modelName: options.rateLimit?.modelName || "rateLimit",
18
+ fields: {
19
+ key: {
20
+ type: "string",
21
+ fieldName: options.rateLimit?.fields?.key || "key"
22
+ },
23
+ count: {
24
+ type: "number",
25
+ fieldName: options.rateLimit?.fields?.count || "count"
26
+ },
27
+ lastRequest: {
28
+ type: "number",
29
+ bigint: true,
30
+ fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest"
31
+ }
32
+ }
33
+ } };
34
+ const { user, session, account, ...pluginTables } = pluginSchema;
35
+ const sessionTable = { session: {
36
+ modelName: options.session?.modelName || "session",
37
+ fields: {
38
+ expiresAt: {
39
+ type: "date",
40
+ required: true,
41
+ fieldName: options.session?.fields?.expiresAt || "expiresAt"
42
+ },
43
+ token: {
44
+ type: "string",
45
+ required: true,
46
+ fieldName: options.session?.fields?.token || "token",
47
+ unique: true
48
+ },
49
+ createdAt: {
50
+ type: "date",
51
+ required: true,
52
+ fieldName: options.session?.fields?.createdAt || "createdAt",
53
+ defaultValue: () => /* @__PURE__ */ new Date()
54
+ },
55
+ updatedAt: {
56
+ type: "date",
57
+ required: true,
58
+ fieldName: options.session?.fields?.updatedAt || "updatedAt",
59
+ onUpdate: () => /* @__PURE__ */ new Date()
60
+ },
61
+ ipAddress: {
62
+ type: "string",
63
+ required: false,
64
+ fieldName: options.session?.fields?.ipAddress || "ipAddress"
65
+ },
66
+ userAgent: {
67
+ type: "string",
68
+ required: false,
69
+ fieldName: options.session?.fields?.userAgent || "userAgent"
70
+ },
71
+ userId: {
72
+ type: "string",
73
+ fieldName: options.session?.fields?.userId || "userId",
74
+ references: {
75
+ model: options.user?.modelName || "user",
76
+ field: "id",
77
+ onDelete: "cascade"
78
+ },
79
+ required: true,
80
+ index: true
81
+ },
82
+ ...session?.fields,
83
+ ...options.session?.additionalFields
84
+ },
85
+ order: 2
86
+ } };
87
+ return {
88
+ user: {
89
+ modelName: options.user?.modelName || "user",
90
+ fields: {
91
+ name: {
92
+ type: "string",
93
+ required: true,
94
+ fieldName: options.user?.fields?.name || "name",
95
+ sortable: true
96
+ },
97
+ email: {
98
+ type: "string",
99
+ unique: true,
100
+ required: true,
101
+ fieldName: options.user?.fields?.email || "email",
102
+ sortable: true
103
+ },
104
+ emailVerified: {
105
+ type: "boolean",
106
+ defaultValue: false,
107
+ required: true,
108
+ fieldName: options.user?.fields?.emailVerified || "emailVerified",
109
+ input: false
110
+ },
111
+ image: {
112
+ type: "string",
113
+ required: false,
114
+ fieldName: options.user?.fields?.image || "image"
115
+ },
116
+ createdAt: {
117
+ type: "date",
118
+ defaultValue: () => /* @__PURE__ */ new Date(),
119
+ required: true,
120
+ fieldName: options.user?.fields?.createdAt || "createdAt"
121
+ },
122
+ updatedAt: {
123
+ type: "date",
124
+ defaultValue: () => /* @__PURE__ */ new Date(),
125
+ onUpdate: () => /* @__PURE__ */ new Date(),
126
+ required: true,
127
+ fieldName: options.user?.fields?.updatedAt || "updatedAt"
128
+ },
129
+ ...user?.fields,
130
+ ...options.user?.additionalFields
131
+ },
132
+ order: 1
133
+ },
134
+ ...!options.secondaryStorage || options.session?.storeSessionInDatabase ? sessionTable : {},
135
+ account: {
136
+ modelName: options.account?.modelName || "account",
137
+ fields: {
138
+ accountId: {
139
+ type: "string",
140
+ required: true,
141
+ fieldName: options.account?.fields?.accountId || "accountId"
142
+ },
143
+ providerId: {
144
+ type: "string",
145
+ required: true,
146
+ fieldName: options.account?.fields?.providerId || "providerId"
147
+ },
148
+ userId: {
149
+ type: "string",
150
+ references: {
151
+ model: options.user?.modelName || "user",
152
+ field: "id",
153
+ onDelete: "cascade"
154
+ },
155
+ required: true,
156
+ fieldName: options.account?.fields?.userId || "userId",
157
+ index: true
158
+ },
159
+ accessToken: {
160
+ type: "string",
161
+ required: false,
162
+ fieldName: options.account?.fields?.accessToken || "accessToken"
163
+ },
164
+ refreshToken: {
165
+ type: "string",
166
+ required: false,
167
+ fieldName: options.account?.fields?.refreshToken || "refreshToken"
168
+ },
169
+ idToken: {
170
+ type: "string",
171
+ required: false,
172
+ fieldName: options.account?.fields?.idToken || "idToken"
173
+ },
174
+ accessTokenExpiresAt: {
175
+ type: "date",
176
+ required: false,
177
+ fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
178
+ },
179
+ refreshTokenExpiresAt: {
180
+ type: "date",
181
+ required: false,
182
+ fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
183
+ },
184
+ scope: {
185
+ type: "string",
186
+ required: false,
187
+ fieldName: options.account?.fields?.scope || "scope"
188
+ },
189
+ password: {
190
+ type: "string",
191
+ required: false,
192
+ fieldName: options.account?.fields?.password || "password"
193
+ },
194
+ createdAt: {
195
+ type: "date",
196
+ required: true,
197
+ fieldName: options.account?.fields?.createdAt || "createdAt",
198
+ defaultValue: () => /* @__PURE__ */ new Date()
199
+ },
200
+ updatedAt: {
201
+ type: "date",
202
+ required: true,
203
+ fieldName: options.account?.fields?.updatedAt || "updatedAt",
204
+ onUpdate: () => /* @__PURE__ */ new Date()
205
+ },
206
+ ...account?.fields,
207
+ ...options.account?.additionalFields
208
+ },
209
+ order: 3
210
+ },
211
+ verification: {
212
+ modelName: options.verification?.modelName || "verification",
213
+ fields: {
214
+ identifier: {
215
+ type: "string",
216
+ required: true,
217
+ fieldName: options.verification?.fields?.identifier || "identifier",
218
+ index: true
219
+ },
220
+ value: {
221
+ type: "string",
222
+ required: true,
223
+ fieldName: options.verification?.fields?.value || "value"
224
+ },
225
+ expiresAt: {
226
+ type: "date",
227
+ required: true,
228
+ fieldName: options.verification?.fields?.expiresAt || "expiresAt"
229
+ },
230
+ createdAt: {
231
+ type: "date",
232
+ required: true,
233
+ defaultValue: () => /* @__PURE__ */ new Date(),
234
+ fieldName: options.verification?.fields?.createdAt || "createdAt"
235
+ },
236
+ updatedAt: {
237
+ type: "date",
238
+ required: true,
239
+ defaultValue: () => /* @__PURE__ */ new Date(),
240
+ onUpdate: () => /* @__PURE__ */ new Date(),
241
+ fieldName: options.verification?.fields?.updatedAt || "updatedAt"
242
+ }
243
+ },
244
+ order: 4
245
+ },
246
+ ...pluginTables,
247
+ ...shouldAddRateLimitTable ? rateLimitTable : {}
248
+ };
249
+ };
250
+
251
+ //#endregion
252
+ export { getAuthTables as t };