@better-auth/core 1.4.12-beta.2 → 1.4.13

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 (185) hide show
  1. package/.turbo/turbo-build.log +172 -35
  2. package/dist/api/index.d.mts +178 -1
  3. package/dist/api/index.mjs +2 -1
  4. package/dist/context/endpoint-context.d.mts +19 -0
  5. package/dist/context/endpoint-context.mjs +31 -0
  6. package/dist/context/global.d.mts +7 -0
  7. package/dist/context/global.mjs +37 -0
  8. package/dist/context/index.d.mts +5 -53
  9. package/dist/context/index.mjs +5 -2
  10. package/dist/context/request-state.d.mts +27 -0
  11. package/dist/context/request-state.mjs +49 -0
  12. package/dist/context/transaction.d.mts +16 -0
  13. package/dist/context/transaction.mjs +52 -0
  14. package/dist/db/adapter/factory.d.mts +27 -0
  15. package/dist/db/adapter/factory.mjs +738 -0
  16. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  17. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  18. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  19. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  20. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  21. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  22. package/dist/db/adapter/get-field-name.d.mts +18 -0
  23. package/dist/db/adapter/get-field-name.mjs +33 -0
  24. package/dist/db/adapter/get-id-field.d.mts +39 -0
  25. package/dist/db/adapter/get-id-field.mjs +68 -0
  26. package/dist/db/adapter/get-model-name.d.mts +12 -0
  27. package/dist/db/adapter/get-model-name.mjs +23 -0
  28. package/dist/db/adapter/index.d.mts +513 -1
  29. package/dist/db/adapter/index.mjs +8 -970
  30. package/dist/db/adapter/types.d.mts +139 -0
  31. package/dist/db/adapter/utils.d.mts +7 -0
  32. package/dist/db/adapter/utils.mjs +38 -0
  33. package/dist/db/get-tables.d.mts +8 -0
  34. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  35. package/dist/db/index.d.mts +10 -2
  36. package/dist/db/index.mjs +7 -60
  37. package/dist/db/plugin.d.mts +12 -0
  38. package/dist/db/schema/account.d.mts +26 -0
  39. package/dist/db/schema/account.mjs +19 -0
  40. package/dist/db/schema/rate-limit.d.mts +14 -0
  41. package/dist/db/schema/rate-limit.mjs +11 -0
  42. package/dist/db/schema/session.d.mts +21 -0
  43. package/dist/db/schema/session.mjs +14 -0
  44. package/dist/db/schema/shared.d.mts +10 -0
  45. package/dist/db/schema/shared.mjs +11 -0
  46. package/dist/db/schema/user.d.mts +20 -0
  47. package/dist/db/schema/user.mjs +13 -0
  48. package/dist/db/schema/verification.d.mts +19 -0
  49. package/dist/db/schema/verification.mjs +12 -0
  50. package/dist/db/type.d.mts +143 -0
  51. package/dist/env/color-depth.d.mts +4 -0
  52. package/dist/env/color-depth.mjs +88 -0
  53. package/dist/env/env-impl.d.mts +32 -0
  54. package/dist/env/env-impl.mjs +82 -0
  55. package/dist/env/index.d.mts +4 -2
  56. package/dist/env/index.mjs +3 -1
  57. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  58. package/dist/env/logger.mjs +81 -0
  59. package/dist/error/codes.d.mts +48 -0
  60. package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
  61. package/dist/error/index.d.mts +5 -48
  62. package/dist/error/index.mjs +12 -3
  63. package/dist/index.d.mts +8 -2
  64. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  65. package/dist/oauth2/client-credentials-token.mjs +54 -0
  66. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  67. package/dist/oauth2/create-authorization-url.mjs +42 -0
  68. package/dist/oauth2/index.d.mts +8 -2
  69. package/dist/oauth2/index.mjs +6 -2
  70. package/dist/oauth2/oauth-provider.d.mts +194 -0
  71. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  72. package/dist/oauth2/refresh-access-token.mjs +58 -0
  73. package/dist/oauth2/utils.d.mts +7 -0
  74. package/dist/oauth2/utils.mjs +27 -0
  75. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  76. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  77. package/dist/oauth2/verify.d.mts +49 -0
  78. package/dist/oauth2/verify.mjs +95 -0
  79. package/dist/social-providers/apple.d.mts +119 -0
  80. package/dist/social-providers/apple.mjs +102 -0
  81. package/dist/social-providers/atlassian.d.mts +72 -0
  82. package/dist/social-providers/atlassian.mjs +83 -0
  83. package/dist/social-providers/cognito.d.mts +87 -0
  84. package/dist/social-providers/cognito.mjs +166 -0
  85. package/dist/social-providers/discord.d.mts +126 -0
  86. package/dist/social-providers/discord.mjs +64 -0
  87. package/dist/social-providers/dropbox.d.mts +71 -0
  88. package/dist/social-providers/dropbox.mjs +75 -0
  89. package/dist/social-providers/facebook.d.mts +81 -0
  90. package/dist/social-providers/facebook.mjs +120 -0
  91. package/dist/social-providers/figma.d.mts +63 -0
  92. package/dist/social-providers/figma.mjs +84 -0
  93. package/dist/social-providers/github.d.mts +104 -0
  94. package/dist/social-providers/github.mjs +80 -0
  95. package/dist/social-providers/gitlab.d.mts +125 -0
  96. package/dist/social-providers/gitlab.mjs +82 -0
  97. package/dist/social-providers/google.d.mts +99 -0
  98. package/dist/social-providers/google.mjs +109 -0
  99. package/dist/social-providers/huggingface.d.mts +85 -0
  100. package/dist/social-providers/huggingface.mjs +75 -0
  101. package/dist/social-providers/index.d.mts +1723 -1
  102. package/dist/social-providers/index.mjs +33 -2570
  103. package/dist/social-providers/kakao.d.mts +163 -0
  104. package/dist/social-providers/kakao.mjs +72 -0
  105. package/dist/social-providers/kick.d.mts +75 -0
  106. package/dist/social-providers/kick.mjs +71 -0
  107. package/dist/social-providers/line.d.mts +107 -0
  108. package/dist/social-providers/line.mjs +113 -0
  109. package/dist/social-providers/linear.d.mts +70 -0
  110. package/dist/social-providers/linear.mjs +88 -0
  111. package/dist/social-providers/linkedin.d.mts +69 -0
  112. package/dist/social-providers/linkedin.mjs +76 -0
  113. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  114. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  115. package/dist/social-providers/naver.d.mts +104 -0
  116. package/dist/social-providers/naver.mjs +67 -0
  117. package/dist/social-providers/notion.d.mts +66 -0
  118. package/dist/social-providers/notion.mjs +75 -0
  119. package/dist/social-providers/paybin.d.mts +73 -0
  120. package/dist/social-providers/paybin.mjs +85 -0
  121. package/dist/social-providers/paypal.d.mts +131 -0
  122. package/dist/social-providers/paypal.mjs +144 -0
  123. package/dist/social-providers/polar.d.mts +76 -0
  124. package/dist/social-providers/polar.mjs +73 -0
  125. package/dist/social-providers/reddit.d.mts +64 -0
  126. package/dist/social-providers/reddit.mjs +83 -0
  127. package/dist/social-providers/roblox.d.mts +72 -0
  128. package/dist/social-providers/roblox.mjs +59 -0
  129. package/dist/social-providers/salesforce.d.mts +81 -0
  130. package/dist/social-providers/salesforce.mjs +91 -0
  131. package/dist/social-providers/slack.d.mts +85 -0
  132. package/dist/social-providers/slack.mjs +68 -0
  133. package/dist/social-providers/spotify.d.mts +65 -0
  134. package/dist/social-providers/spotify.mjs +71 -0
  135. package/dist/social-providers/tiktok.d.mts +171 -0
  136. package/dist/social-providers/tiktok.mjs +62 -0
  137. package/dist/social-providers/twitch.d.mts +81 -0
  138. package/dist/social-providers/twitch.mjs +78 -0
  139. package/dist/social-providers/twitter.d.mts +140 -0
  140. package/dist/social-providers/twitter.mjs +87 -0
  141. package/dist/social-providers/vercel.d.mts +64 -0
  142. package/dist/social-providers/vercel.mjs +61 -0
  143. package/dist/social-providers/vk.d.mts +72 -0
  144. package/dist/social-providers/vk.mjs +83 -0
  145. package/dist/social-providers/zoom.d.mts +173 -0
  146. package/dist/social-providers/zoom.mjs +72 -0
  147. package/dist/types/context.d.mts +215 -0
  148. package/dist/types/cookie.d.mts +15 -0
  149. package/dist/types/helper.d.mts +8 -0
  150. package/dist/types/index.d.mts +8 -0
  151. package/dist/types/init-options.d.mts +1266 -0
  152. package/dist/types/plugin-client.d.mts +103 -0
  153. package/dist/types/plugin.d.mts +121 -0
  154. package/dist/utils/deprecate.d.mts +10 -0
  155. package/dist/utils/deprecate.mjs +17 -0
  156. package/dist/utils/error-codes.d.mts +9 -0
  157. package/dist/utils/error-codes.mjs +7 -0
  158. package/dist/utils/id.d.mts +4 -0
  159. package/dist/utils/id.mjs +9 -0
  160. package/dist/utils/index.d.mts +5 -26
  161. package/dist/utils/index.mjs +5 -2
  162. package/dist/utils/json.d.mts +4 -0
  163. package/dist/utils/json.mjs +25 -0
  164. package/dist/utils/string.d.mts +4 -0
  165. package/dist/utils/string.mjs +7 -0
  166. package/package.json +1 -1
  167. package/src/context/endpoint-context.ts +7 -15
  168. package/src/context/global.ts +57 -0
  169. package/src/context/index.ts +1 -0
  170. package/src/context/request-state.ts +7 -12
  171. package/src/context/transaction.ts +7 -16
  172. package/src/db/adapter/factory.ts +13 -13
  173. package/src/db/adapter/get-default-model-name.ts +1 -1
  174. package/src/db/adapter/get-id-field.ts +2 -2
  175. package/src/error/index.ts +2 -3
  176. package/src/social-providers/gitlab.ts +1 -1
  177. package/src/types/context.ts +137 -131
  178. package/src/types/cookie.ts +6 -4
  179. package/src/types/index.ts +2 -1
  180. package/tsdown.config.ts +9 -0
  181. package/dist/context-BGZ8V6DD.mjs +0 -126
  182. package/dist/env-DbssmzoK.mjs +0 -245
  183. package/dist/index-zgYuzZ7O.d.mts +0 -8020
  184. package/dist/oauth2-COJkghlT.mjs +0 -326
  185. package/dist/utils-U2L7n92V.mjs +0 -59
@@ -0,0 +1,139 @@
1
+ import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
2
+ import { Prettify } from "../../types/helper.mjs";
3
+ import { CustomAdapter, DBAdapterFactoryConfig, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
4
+ import { BetterAuthOptions } from "../../types/init-options.mjs";
5
+ import "../../types/index.mjs";
6
+
7
+ //#region src/db/adapter/types.d.ts
8
+ type AdapterFactoryOptions = {
9
+ config: AdapterFactoryConfig;
10
+ adapter: AdapterFactoryCustomizeAdapterCreator;
11
+ };
12
+ interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<BetterAuthOptions>, "transaction"> {
13
+ /**
14
+ * Execute multiple operations in a transaction.
15
+ *
16
+ * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
17
+ *
18
+ * @default false
19
+ */
20
+ transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
21
+ }
22
+ type AdapterFactoryCustomizeAdapterCreator = (config: {
23
+ options: BetterAuthOptions;
24
+ /**
25
+ * The schema of the user's Better-Auth instance.
26
+ */
27
+ schema: BetterAuthDBSchema;
28
+ /**
29
+ * The debug log function.
30
+ *
31
+ * If the config has defined `debugLogs` as `false`, no logs will be shown.
32
+ */
33
+ debugLog: (...args: unknown[]) => void;
34
+ /**
35
+ * Get the model name which is expected to be saved in the database based on the user's schema.
36
+ */
37
+ getModelName: (model: string) => string;
38
+ /**
39
+ * Get the field name which is expected to be saved in the database based on the user's schema.
40
+ */
41
+ getFieldName: ({
42
+ model,
43
+ field
44
+ }: {
45
+ model: string;
46
+ field: string;
47
+ }) => string;
48
+ /**
49
+ * This function helps us get the default model name from the schema defined by devs.
50
+ * Often times, the user will be using the `modelName` which could had been customized by the users.
51
+ * This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
52
+ *
53
+ * If it's still unclear what this does:
54
+ *
55
+ * 1. User can define a custom modelName.
56
+ * 2. When using a custom modelName, doing something like `schema[model]` will not work.
57
+ * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
58
+ * 4. Thus allowing us to use `schema[model]`.
59
+ */
60
+ getDefaultModelName: (model: string) => string;
61
+ /**
62
+ * This function helps us get the default field name from the schema defined by devs.
63
+ * Often times, the user will be using the `fieldName` which could had been customized by the users.
64
+ * This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
65
+ *
66
+ * If it's still unclear what this does:
67
+ *
68
+ * 1. User can define a custom fieldName.
69
+ * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
70
+ *
71
+ */
72
+ getDefaultFieldName: ({
73
+ model,
74
+ field
75
+ }: {
76
+ model: string;
77
+ field: string;
78
+ }) => string;
79
+ /**
80
+ * Get the field attributes for a given model and field.
81
+ *
82
+ * Note: any model name or field name is allowed, whether default to schema or not.
83
+ */
84
+ getFieldAttributes: ({
85
+ model,
86
+ field
87
+ }: {
88
+ model: string;
89
+ field: string;
90
+ }) => DBFieldAttribute;
91
+ transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
92
+ transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
93
+ transformWhereClause: <W extends Where[] | undefined>({
94
+ model,
95
+ where,
96
+ action
97
+ }: {
98
+ where: W;
99
+ model: string;
100
+ action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
101
+ }) => W extends undefined ? undefined : CleanedWhere[];
102
+ }) => CustomAdapter$1;
103
+ /**
104
+ * @deprecated Use `CustomAdapter` from `@better-auth/core/db/adapter` instead.
105
+ */
106
+ interface CustomAdapter$1 extends Omit<CustomAdapter, "createSchema"> {
107
+ createSchema?: ((props: {
108
+ /**
109
+ * The file the user may have passed in to the `generate` command as the expected schema file output path.
110
+ */
111
+ file?: string;
112
+ /**
113
+ * The tables from the user's Better-Auth instance schema.
114
+ */
115
+ tables: BetterAuthDBSchema;
116
+ }) => Promise<DBAdapterSchemaCreation>) | undefined;
117
+ }
118
+ /**
119
+ * @deprecated Use `CleanedWhere` from `@better-auth/core/db/adapter` instead.
120
+ */
121
+ type CleanedWhere = Prettify<Required<Where>>;
122
+ type AdapterTestDebugLogs = {
123
+ resetDebugLogs: () => void;
124
+ printDebugLogs: () => void;
125
+ };
126
+ /**
127
+ * @deprecated Use `AdapterFactoryOptions` instead. This export will be removed in a future version.
128
+ */
129
+ type CreateAdapterOptions = AdapterFactoryOptions;
130
+ /**
131
+ * @deprecated Use `AdapterFactoryConfig` instead. This export will be removed in a future version.
132
+ */
133
+ type AdapterConfig = AdapterFactoryConfig;
134
+ /**
135
+ * @deprecated Use `AdapterFactoryCustomizeAdapterCreator` instead. This export will be removed in a future version.
136
+ */
137
+ type CreateCustomAdapter = AdapterFactoryCustomizeAdapterCreator;
138
+ //#endregion
139
+ export { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter$1 as CustomAdapter };
@@ -0,0 +1,7 @@
1
+ import { DBFieldAttribute } from "../type.mjs";
2
+
3
+ //#region src/db/adapter/utils.d.ts
4
+ declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
5
+ declare function deepmerge<T>(target: T, source: Partial<T>): T;
6
+ //#endregion
7
+ export { deepmerge, withApplyDefault };
@@ -0,0 +1,38 @@
1
+ //#region src/db/adapter/utils.ts
2
+ function withApplyDefault(value, field, action) {
3
+ if (action === "update") {
4
+ if (value === void 0 && field.onUpdate !== void 0) {
5
+ if (typeof field.onUpdate === "function") return field.onUpdate();
6
+ return field.onUpdate;
7
+ }
8
+ return value;
9
+ }
10
+ if (action === "create") {
11
+ if (value === void 0 || field.required === true && value === null) {
12
+ if (field.defaultValue !== void 0) {
13
+ if (typeof field.defaultValue === "function") return field.defaultValue();
14
+ return field.defaultValue;
15
+ }
16
+ }
17
+ }
18
+ return value;
19
+ }
20
+ function isObject(item) {
21
+ return item !== null && typeof item === "object" && !Array.isArray(item);
22
+ }
23
+ function deepmerge(target, source) {
24
+ if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
25
+ else if (isObject(target) && isObject(source)) {
26
+ const result = { ...target };
27
+ for (const [key, value] of Object.entries(source)) {
28
+ if (value === void 0) continue;
29
+ if (key in target) result[key] = deepmerge(target[key], value);
30
+ else result[key] = value;
31
+ }
32
+ return result;
33
+ }
34
+ return source;
35
+ }
36
+
37
+ //#endregion
38
+ export { deepmerge, withApplyDefault };
@@ -0,0 +1,8 @@
1
+ import { BetterAuthDBSchema } from "./type.mjs";
2
+ import { BetterAuthOptions } from "../types/init-options.mjs";
3
+ import "../types/index.mjs";
4
+
5
+ //#region src/db/get-tables.d.ts
6
+ declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
7
+ //#endregion
8
+ export { getAuthTables };
@@ -251,4 +251,4 @@ const getAuthTables = (options) => {
251
251
  };
252
252
 
253
253
  //#endregion
254
- export { getAuthTables as t };
254
+ export { getAuthTables };
@@ -1,2 +1,10 @@
1
- import { Ar as User, Br as getAuthTables, Fr as RateLimit, Gr as DBFieldType, Hr as BetterAuthDBSchema, Ir as rateLimitSchema, Jr as SecondaryStorage, Kr as DBPrimitive, Lr as Account, Mr as coreSchema, Nr as Session, Or as Verification, Pr as sessionSchema, Rr as accountSchema, Ur as DBFieldAttribute, Vr as BaseModelNames, Wr as DBFieldAttributeConfig, jr as userSchema, kr as verificationSchema, qr as ModelNames, zr as BetterAuthPluginDBSchema } from "../index-zgYuzZ7O.mjs";
2
- export { Account, BaseModelNames, BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
1
+ import { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage } from "./type.mjs";
2
+ import { getAuthTables } from "./get-tables.mjs";
3
+ import { BetterAuthPluginDBSchema } from "./plugin.mjs";
4
+ import { Account, accountSchema } from "./schema/account.mjs";
5
+ import { RateLimit, rateLimitSchema } from "./schema/rate-limit.mjs";
6
+ import { Session, sessionSchema } from "./schema/session.mjs";
7
+ import { coreSchema } from "./schema/shared.mjs";
8
+ import { User, userSchema } from "./schema/user.mjs";
9
+ import { Verification, verificationSchema } from "./schema/verification.mjs";
10
+ export { type Account, type BaseModelNames, type BetterAuthDBSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute, type DBFieldAttributeConfig, type DBFieldType, type DBPrimitive, type ModelNames, type RateLimit, type SecondaryStorage, type Session, type User, type Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
package/dist/db/index.mjs CHANGED
@@ -1,62 +1,9 @@
1
- import { t as getAuthTables } from "../get-tables-CMc_Emww.mjs";
2
- import * as z from "zod";
1
+ import { getAuthTables } from "./get-tables.mjs";
2
+ import { coreSchema } from "./schema/shared.mjs";
3
+ import { accountSchema } from "./schema/account.mjs";
4
+ import { rateLimitSchema } from "./schema/rate-limit.mjs";
5
+ import { sessionSchema } from "./schema/session.mjs";
6
+ import { userSchema } from "./schema/user.mjs";
7
+ import { verificationSchema } from "./schema/verification.mjs";
3
8
 
4
- //#region src/db/schema/shared.ts
5
- const coreSchema = z.object({
6
- id: z.string(),
7
- createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
8
- updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
9
- });
10
-
11
- //#endregion
12
- //#region src/db/schema/account.ts
13
- const accountSchema = coreSchema.extend({
14
- providerId: z.string(),
15
- accountId: z.string(),
16
- userId: z.coerce.string(),
17
- accessToken: z.string().nullish(),
18
- refreshToken: z.string().nullish(),
19
- idToken: z.string().nullish(),
20
- accessTokenExpiresAt: z.date().nullish(),
21
- refreshTokenExpiresAt: z.date().nullish(),
22
- scope: z.string().nullish(),
23
- password: z.string().nullish()
24
- });
25
-
26
- //#endregion
27
- //#region src/db/schema/rate-limit.ts
28
- const rateLimitSchema = z.object({
29
- key: z.string(),
30
- count: z.number(),
31
- lastRequest: z.number()
32
- });
33
-
34
- //#endregion
35
- //#region src/db/schema/session.ts
36
- const sessionSchema = coreSchema.extend({
37
- userId: z.coerce.string(),
38
- expiresAt: z.date(),
39
- token: z.string(),
40
- ipAddress: z.string().nullish(),
41
- userAgent: z.string().nullish()
42
- });
43
-
44
- //#endregion
45
- //#region src/db/schema/user.ts
46
- const userSchema = coreSchema.extend({
47
- email: z.string().transform((val) => val.toLowerCase()),
48
- emailVerified: z.boolean().default(false),
49
- name: z.string(),
50
- image: z.string().nullish()
51
- });
52
-
53
- //#endregion
54
- //#region src/db/schema/verification.ts
55
- const verificationSchema = coreSchema.extend({
56
- value: z.string(),
57
- expiresAt: z.date(),
58
- identifier: z.string()
59
- });
60
-
61
- //#endregion
62
9
  export { accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -0,0 +1,12 @@
1
+ import { DBFieldAttribute } from "./type.mjs";
2
+
3
+ //#region src/db/plugin.d.ts
4
+ type BetterAuthPluginDBSchema = { [table in string]: {
5
+ fields: {
6
+ [field: string]: DBFieldAttribute;
7
+ };
8
+ disableMigration?: boolean | undefined;
9
+ modelName?: string | undefined;
10
+ } };
11
+ //#endregion
12
+ export { BetterAuthPluginDBSchema };
@@ -0,0 +1,26 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/account.d.ts
4
+ declare const accountSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ createdAt: z.ZodDefault<z.ZodDate>;
7
+ updatedAt: z.ZodDefault<z.ZodDate>;
8
+ providerId: z.ZodString;
9
+ accountId: z.ZodString;
10
+ userId: z.ZodCoercedString<unknown>;
11
+ accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
+ idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
+ accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
15
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
16
+ scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
18
+ }, z.core.$strip>;
19
+ /**
20
+ * Account schema type used by better-auth, note that it's possible that account could have additional fields
21
+ *
22
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
23
+ */
24
+ type Account = z.infer<typeof accountSchema>;
25
+ //#endregion
26
+ export { Account, accountSchema };
@@ -0,0 +1,19 @@
1
+ import { coreSchema } from "./shared.mjs";
2
+ import * as z from "zod";
3
+
4
+ //#region src/db/schema/account.ts
5
+ const accountSchema = coreSchema.extend({
6
+ providerId: z.string(),
7
+ accountId: z.string(),
8
+ userId: z.coerce.string(),
9
+ accessToken: z.string().nullish(),
10
+ refreshToken: z.string().nullish(),
11
+ idToken: z.string().nullish(),
12
+ accessTokenExpiresAt: z.date().nullish(),
13
+ refreshTokenExpiresAt: z.date().nullish(),
14
+ scope: z.string().nullish(),
15
+ password: z.string().nullish()
16
+ });
17
+
18
+ //#endregion
19
+ export { accountSchema };
@@ -0,0 +1,14 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/rate-limit.d.ts
4
+ declare const rateLimitSchema: z.ZodObject<{
5
+ key: z.ZodString;
6
+ count: z.ZodNumber;
7
+ lastRequest: z.ZodNumber;
8
+ }, z.core.$strip>;
9
+ /**
10
+ * Rate limit schema type used by better-auth for rate limiting
11
+ */
12
+ type RateLimit = z.infer<typeof rateLimitSchema>;
13
+ //#endregion
14
+ export { RateLimit, rateLimitSchema };
@@ -0,0 +1,11 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/rate-limit.ts
4
+ const rateLimitSchema = z.object({
5
+ key: z.string(),
6
+ count: z.number(),
7
+ lastRequest: z.number()
8
+ });
9
+
10
+ //#endregion
11
+ export { rateLimitSchema };
@@ -0,0 +1,21 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/session.d.ts
4
+ declare const sessionSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ createdAt: z.ZodDefault<z.ZodDate>;
7
+ updatedAt: z.ZodDefault<z.ZodDate>;
8
+ userId: z.ZodCoercedString<unknown>;
9
+ expiresAt: z.ZodDate;
10
+ token: z.ZodString;
11
+ ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
+ }, z.core.$strip>;
14
+ /**
15
+ * Session schema type used by better-auth, note that it's possible that session could have additional fields
16
+ *
17
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
18
+ */
19
+ type Session = z.infer<typeof sessionSchema>;
20
+ //#endregion
21
+ export { Session, sessionSchema };
@@ -0,0 +1,14 @@
1
+ import { coreSchema } from "./shared.mjs";
2
+ import * as z from "zod";
3
+
4
+ //#region src/db/schema/session.ts
5
+ const sessionSchema = coreSchema.extend({
6
+ userId: z.coerce.string(),
7
+ expiresAt: z.date(),
8
+ token: z.string(),
9
+ ipAddress: z.string().nullish(),
10
+ userAgent: z.string().nullish()
11
+ });
12
+
13
+ //#endregion
14
+ export { sessionSchema };
@@ -0,0 +1,10 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/shared.d.ts
4
+ declare const coreSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ createdAt: z.ZodDefault<z.ZodDate>;
7
+ updatedAt: z.ZodDefault<z.ZodDate>;
8
+ }, z.core.$strip>;
9
+ //#endregion
10
+ export { coreSchema };
@@ -0,0 +1,11 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/shared.ts
4
+ const coreSchema = z.object({
5
+ id: z.string(),
6
+ createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
7
+ updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
8
+ });
9
+
10
+ //#endregion
11
+ export { coreSchema };
@@ -0,0 +1,20 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/user.d.ts
4
+ declare const userSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ createdAt: z.ZodDefault<z.ZodDate>;
7
+ updatedAt: z.ZodDefault<z.ZodDate>;
8
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
9
+ emailVerified: z.ZodDefault<z.ZodBoolean>;
10
+ name: z.ZodString;
11
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ }, z.core.$strip>;
13
+ /**
14
+ * User schema type used by better-auth, note that it's possible that user could have additional fields
15
+ *
16
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
17
+ */
18
+ type User = z.infer<typeof userSchema>;
19
+ //#endregion
20
+ export { User, userSchema };
@@ -0,0 +1,13 @@
1
+ import { coreSchema } from "./shared.mjs";
2
+ import * as z from "zod";
3
+
4
+ //#region src/db/schema/user.ts
5
+ const userSchema = coreSchema.extend({
6
+ email: z.string().transform((val) => val.toLowerCase()),
7
+ emailVerified: z.boolean().default(false),
8
+ name: z.string(),
9
+ image: z.string().nullish()
10
+ });
11
+
12
+ //#endregion
13
+ export { userSchema };
@@ -0,0 +1,19 @@
1
+ import * as z from "zod";
2
+
3
+ //#region src/db/schema/verification.d.ts
4
+ declare const verificationSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ createdAt: z.ZodDefault<z.ZodDate>;
7
+ updatedAt: z.ZodDefault<z.ZodDate>;
8
+ value: z.ZodString;
9
+ expiresAt: z.ZodDate;
10
+ identifier: z.ZodString;
11
+ }, z.core.$strip>;
12
+ /**
13
+ * Verification schema type used by better-auth, note that it's possible that verification could have additional fields
14
+ *
15
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
16
+ */
17
+ type Verification = z.infer<typeof verificationSchema>;
18
+ //#endregion
19
+ export { Verification, verificationSchema };
@@ -0,0 +1,12 @@
1
+ import { coreSchema } from "./shared.mjs";
2
+ import * as z from "zod";
3
+
4
+ //#region src/db/schema/verification.ts
5
+ const verificationSchema = coreSchema.extend({
6
+ value: z.string(),
7
+ expiresAt: z.date(),
8
+ identifier: z.string()
9
+ });
10
+
11
+ //#endregion
12
+ export { verificationSchema };
@@ -0,0 +1,143 @@
1
+ import { Awaitable, LiteralString } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+
5
+ //#region src/db/type.d.ts
6
+ type BaseModelNames = "user" | "account" | "session" | "verification";
7
+ type ModelNames<T extends string = LiteralString> = BaseModelNames | T | "rate-limit";
8
+ type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
9
+ type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[] | (Record<string, unknown> | unknown[]);
10
+ type DBFieldAttributeConfig = {
11
+ /**
12
+ * If the field should be required on a new record.
13
+ * @default true
14
+ */
15
+ required?: boolean | undefined;
16
+ /**
17
+ * If the value should be returned on a response body.
18
+ * @default true
19
+ */
20
+ returned?: boolean | undefined;
21
+ /**
22
+ * If a value should be provided when creating a new record.
23
+ * @default true
24
+ */
25
+ input?: boolean | undefined;
26
+ /**
27
+ * Default value for the field
28
+ *
29
+ * Note: This will not create a default value on the database level. It will only
30
+ * be used when creating a new record.
31
+ */
32
+ defaultValue?: (DBPrimitive | (() => DBPrimitive)) | undefined;
33
+ /**
34
+ * Update value for the field
35
+ *
36
+ * Note: This will create an onUpdate trigger on the database level for supported adapters.
37
+ * It will be called when updating a record.
38
+ */
39
+ onUpdate?: (() => DBPrimitive) | undefined;
40
+ /**
41
+ * transform the value before storing it.
42
+ */
43
+ transform?: {
44
+ input?: (value: DBPrimitive) => Awaitable<DBPrimitive>;
45
+ output?: (value: DBPrimitive) => Awaitable<DBPrimitive>;
46
+ } | undefined;
47
+ /**
48
+ * Reference to another model.
49
+ */
50
+ references?: {
51
+ /**
52
+ * The model to reference.
53
+ */
54
+ model: string;
55
+ /**
56
+ * The field on the referenced model.
57
+ */
58
+ field: string;
59
+ /**
60
+ * The action to perform when the reference is deleted.
61
+ * @default "cascade"
62
+ */
63
+ onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
64
+ } | undefined;
65
+ unique?: boolean | undefined;
66
+ /**
67
+ * If the field should be a bigint on the database instead of integer.
68
+ */
69
+ bigint?: boolean | undefined;
70
+ /**
71
+ * A zod schema to validate the value.
72
+ */
73
+ validator?: {
74
+ input?: StandardSchemaV1;
75
+ output?: StandardSchemaV1;
76
+ } | undefined;
77
+ /**
78
+ * The name of the field on the database.
79
+ */
80
+ fieldName?: string | undefined;
81
+ /**
82
+ * If the field should be sortable.
83
+ *
84
+ * applicable only for `text` type.
85
+ * It's useful to mark fields varchar instead of text.
86
+ */
87
+ sortable?: boolean | undefined;
88
+ /**
89
+ * If the field should be indexed.
90
+ * @default false
91
+ */
92
+ index?: boolean | undefined;
93
+ };
94
+ type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
95
+ type: T;
96
+ } & DBFieldAttributeConfig;
97
+ type BetterAuthDBSchema = Record<string, {
98
+ /**
99
+ * The name of the table in the database
100
+ */
101
+ modelName: string;
102
+ /**
103
+ * The fields of the table
104
+ */
105
+ fields: Record<string, DBFieldAttribute>;
106
+ /**
107
+ * Whether to disable migrations for this table
108
+ * @default false
109
+ */
110
+ disableMigrations?: boolean | undefined;
111
+ /**
112
+ * The order of the table
113
+ */
114
+ order?: number | undefined;
115
+ }>;
116
+ interface SecondaryStorage {
117
+ /**
118
+ *
119
+ * @param key - Key to get
120
+ * @returns - Value of the key
121
+ */
122
+ get: (key: string) => Awaitable<unknown>;
123
+ set: (
124
+ /**
125
+ * Key to store
126
+ */
127
+ key: string,
128
+ /**
129
+ * Value to store
130
+ */
131
+ value: string,
132
+ /**
133
+ * Time to live in seconds
134
+ */
135
+ ttl?: number | undefined) => Awaitable<void | null | unknown>;
136
+ /**
137
+ *
138
+ * @param key - Key to delete
139
+ */
140
+ delete: (key: string) => Awaitable<void | null | string>;
141
+ }
142
+ //#endregion
143
+ export { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage };
@@ -0,0 +1,4 @@
1
+ //#region src/env/color-depth.d.ts
2
+ declare function getColorDepth(): number;
3
+ //#endregion
4
+ export { getColorDepth };