@better-auth/core 1.3.26 → 1.3.28

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 (130) hide show
  1. package/.turbo/turbo-build.log +60 -9
  2. package/build.config.ts +7 -0
  3. package/dist/db/adapter/index.cjs +2 -0
  4. package/dist/db/adapter/index.d.cts +14 -0
  5. package/dist/db/adapter/index.d.mts +14 -0
  6. package/dist/db/adapter/index.d.ts +14 -0
  7. package/dist/db/adapter/index.mjs +1 -0
  8. package/dist/db/index.cjs +89 -0
  9. package/dist/db/index.d.cts +16 -107
  10. package/dist/db/index.d.mts +16 -107
  11. package/dist/db/index.d.ts +16 -107
  12. package/dist/db/index.mjs +69 -0
  13. package/dist/env/index.cjs +312 -0
  14. package/dist/env/index.d.cts +36 -0
  15. package/dist/env/index.d.mts +36 -0
  16. package/dist/env/index.d.ts +36 -0
  17. package/dist/env/index.mjs +297 -0
  18. package/dist/error/index.cjs +44 -0
  19. package/dist/error/index.d.cts +33 -0
  20. package/dist/error/index.d.mts +33 -0
  21. package/dist/error/index.d.ts +33 -0
  22. package/dist/error/index.mjs +41 -0
  23. package/dist/index.d.cts +179 -1
  24. package/dist/index.d.mts +179 -1
  25. package/dist/index.d.ts +179 -1
  26. package/dist/middleware/index.cjs +25 -0
  27. package/dist/middleware/index.d.cts +14 -0
  28. package/dist/middleware/index.d.mts +14 -0
  29. package/dist/middleware/index.d.ts +14 -0
  30. package/dist/middleware/index.mjs +21 -0
  31. package/dist/oauth2/index.cjs +368 -0
  32. package/dist/oauth2/index.d.cts +100 -0
  33. package/dist/oauth2/index.d.mts +100 -0
  34. package/dist/oauth2/index.d.ts +100 -0
  35. package/dist/oauth2/index.mjs +357 -0
  36. package/dist/shared/core.BJPBStdk.d.ts +1693 -0
  37. package/dist/shared/core.Bl6TpxyD.d.mts +181 -0
  38. package/dist/shared/core.Bqe5IGAi.d.ts +13 -0
  39. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  40. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  41. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  42. package/dist/shared/core.CajxAutx.d.cts +143 -0
  43. package/dist/shared/core.CajxAutx.d.mts +143 -0
  44. package/dist/shared/core.CajxAutx.d.ts +143 -0
  45. package/dist/shared/core.CkkLHQWc.d.mts +1693 -0
  46. package/dist/shared/core.DkdZ1o38.d.ts +181 -0
  47. package/dist/shared/core.Dl-70uns.d.cts +84 -0
  48. package/dist/shared/core.Dl-70uns.d.mts +84 -0
  49. package/dist/shared/core.Dl-70uns.d.ts +84 -0
  50. package/dist/shared/core.DyEdx0m7.d.cts +181 -0
  51. package/dist/shared/core.E9DfzGLz.d.mts +13 -0
  52. package/dist/shared/core.HqYn20Fi.d.cts +13 -0
  53. package/dist/shared/core.gYIBmdi1.d.cts +1693 -0
  54. package/dist/social-providers/index.cjs +2793 -0
  55. package/dist/social-providers/index.d.cts +3903 -0
  56. package/dist/social-providers/index.d.mts +3903 -0
  57. package/dist/social-providers/index.d.ts +3903 -0
  58. package/dist/social-providers/index.mjs +2743 -0
  59. package/dist/utils/index.cjs +7 -0
  60. package/dist/utils/index.d.cts +10 -0
  61. package/dist/utils/index.d.mts +10 -0
  62. package/dist/utils/index.d.ts +10 -0
  63. package/dist/utils/index.mjs +5 -0
  64. package/package.json +109 -2
  65. package/src/db/adapter/index.ts +448 -0
  66. package/src/db/index.ts +13 -0
  67. package/src/db/plugin.ts +11 -0
  68. package/src/db/schema/account.ts +34 -0
  69. package/src/db/schema/rate-limit.ts +21 -0
  70. package/src/db/schema/session.ts +17 -0
  71. package/src/db/schema/shared.ts +7 -0
  72. package/src/db/schema/user.ts +16 -0
  73. package/src/db/schema/verification.ts +15 -0
  74. package/src/db/type.ts +50 -0
  75. package/src/env/color-depth.ts +172 -0
  76. package/src/env/env-impl.ts +123 -0
  77. package/src/env/index.ts +23 -0
  78. package/src/env/logger.test.ts +33 -0
  79. package/src/env/logger.ts +145 -0
  80. package/src/error/codes.ts +31 -0
  81. package/src/error/index.ts +11 -0
  82. package/src/index.ts +1 -1
  83. package/src/middleware/index.ts +33 -0
  84. package/src/oauth2/client-credentials-token.ts +102 -0
  85. package/src/oauth2/create-authorization-url.ts +85 -0
  86. package/src/oauth2/index.ts +22 -0
  87. package/src/oauth2/oauth-provider.ts +194 -0
  88. package/src/oauth2/refresh-access-token.ts +124 -0
  89. package/src/oauth2/utils.ts +36 -0
  90. package/src/oauth2/validate-authorization-code.ts +156 -0
  91. package/src/social-providers/apple.ts +213 -0
  92. package/src/social-providers/atlassian.ts +130 -0
  93. package/src/social-providers/cognito.ts +269 -0
  94. package/src/social-providers/discord.ts +172 -0
  95. package/src/social-providers/dropbox.ts +112 -0
  96. package/src/social-providers/facebook.ts +204 -0
  97. package/src/social-providers/figma.ts +115 -0
  98. package/src/social-providers/github.ts +154 -0
  99. package/src/social-providers/gitlab.ts +152 -0
  100. package/src/social-providers/google.ts +171 -0
  101. package/src/social-providers/huggingface.ts +116 -0
  102. package/src/social-providers/index.ts +118 -0
  103. package/src/social-providers/kakao.ts +178 -0
  104. package/src/social-providers/kick.ts +95 -0
  105. package/src/social-providers/line.ts +169 -0
  106. package/src/social-providers/linear.ts +120 -0
  107. package/src/social-providers/linkedin.ts +110 -0
  108. package/src/social-providers/microsoft-entra-id.ts +243 -0
  109. package/src/social-providers/naver.ts +112 -0
  110. package/src/social-providers/notion.ts +106 -0
  111. package/src/social-providers/paypal.ts +261 -0
  112. package/src/social-providers/reddit.ts +122 -0
  113. package/src/social-providers/roblox.ts +110 -0
  114. package/src/social-providers/salesforce.ts +157 -0
  115. package/src/social-providers/slack.ts +114 -0
  116. package/src/social-providers/spotify.ts +93 -0
  117. package/src/social-providers/tiktok.ts +211 -0
  118. package/src/social-providers/twitch.ts +111 -0
  119. package/src/social-providers/twitter.ts +194 -0
  120. package/src/social-providers/vk.ts +128 -0
  121. package/src/social-providers/zoom.ts +218 -0
  122. package/src/types/context.ts +313 -0
  123. package/src/types/cookie.ts +7 -0
  124. package/src/types/helper.ts +5 -0
  125. package/src/types/index.ts +20 -1
  126. package/src/types/init-options.ts +1161 -0
  127. package/src/types/plugin-client.ts +69 -0
  128. package/src/types/plugin.ts +134 -0
  129. package/src/utils/error-codes.ts +51 -0
  130. package/src/utils/index.ts +1 -0
@@ -0,0 +1,181 @@
1
+ import { L as LiteralString } from './core.CajxAutx.mjs';
2
+
3
+ interface OAuth2Tokens {
4
+ tokenType?: string;
5
+ accessToken?: string;
6
+ refreshToken?: string;
7
+ accessTokenExpiresAt?: Date;
8
+ refreshTokenExpiresAt?: Date;
9
+ scopes?: string[];
10
+ idToken?: string;
11
+ }
12
+ type OAuth2UserInfo = {
13
+ id: string | number;
14
+ name?: string;
15
+ email?: string | null;
16
+ image?: string;
17
+ emailVerified: boolean;
18
+ };
19
+ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
20
+ id: LiteralString;
21
+ createAuthorizationURL: (data: {
22
+ state: string;
23
+ codeVerifier: string;
24
+ scopes?: string[];
25
+ redirectURI: string;
26
+ display?: string;
27
+ loginHint?: string;
28
+ }) => Promise<URL> | URL;
29
+ name: string;
30
+ validateAuthorizationCode: (data: {
31
+ code: string;
32
+ redirectURI: string;
33
+ codeVerifier?: string;
34
+ deviceId?: string;
35
+ }) => Promise<OAuth2Tokens>;
36
+ getUserInfo: (token: OAuth2Tokens & {
37
+ /**
38
+ * The user object from the provider
39
+ * This is only available for some providers like Apple
40
+ */
41
+ user?: {
42
+ name?: {
43
+ firstName?: string;
44
+ lastName?: string;
45
+ };
46
+ email?: string;
47
+ };
48
+ }) => Promise<{
49
+ user: OAuth2UserInfo;
50
+ data: T;
51
+ } | null>;
52
+ /**
53
+ * Custom function to refresh a token
54
+ */
55
+ refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
56
+ revokeToken?: (token: string) => Promise<void>;
57
+ /**
58
+ * Verify the id token
59
+ * @param token - The id token
60
+ * @param nonce - The nonce
61
+ * @returns True if the id token is valid, false otherwise
62
+ */
63
+ verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
64
+ /**
65
+ * Disable implicit sign up for new users. When set to true for the provider,
66
+ * sign-in need to be called with with requestSignUp as true to create new users.
67
+ */
68
+ disableImplicitSignUp?: boolean;
69
+ /**
70
+ * Disable sign up for new users.
71
+ */
72
+ disableSignUp?: boolean;
73
+ /**
74
+ * Options for the provider
75
+ */
76
+ options?: O;
77
+ }
78
+ type ProviderOptions<Profile extends Record<string, any> = any> = {
79
+ /**
80
+ * The client ID of your application.
81
+ *
82
+ * This is usually a string but can be any type depending on the provider.
83
+ */
84
+ clientId?: unknown;
85
+ /**
86
+ * The client secret of your application
87
+ */
88
+ clientSecret?: string;
89
+ /**
90
+ * The scopes you want to request from the provider
91
+ */
92
+ scope?: string[];
93
+ /**
94
+ * Remove default scopes of the provider
95
+ */
96
+ disableDefaultScope?: boolean;
97
+ /**
98
+ * The redirect URL for your application. This is where the provider will
99
+ * redirect the user after the sign in process. Make sure this URL is
100
+ * whitelisted in the provider's dashboard.
101
+ */
102
+ redirectURI?: string;
103
+ /**
104
+ * The client key of your application
105
+ * Tiktok Social Provider uses this field instead of clientId
106
+ */
107
+ clientKey?: string;
108
+ /**
109
+ * Disable provider from allowing users to sign in
110
+ * with this provider with an id token sent from the
111
+ * client.
112
+ */
113
+ disableIdTokenSignIn?: boolean;
114
+ /**
115
+ * verifyIdToken function to verify the id token
116
+ */
117
+ verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
118
+ /**
119
+ * Custom function to get user info from the provider
120
+ */
121
+ getUserInfo?: (token: OAuth2Tokens) => Promise<{
122
+ user: {
123
+ id: string;
124
+ name?: string;
125
+ email?: string | null;
126
+ image?: string;
127
+ emailVerified: boolean;
128
+ [key: string]: any;
129
+ };
130
+ data: any;
131
+ }>;
132
+ /**
133
+ * Custom function to refresh a token
134
+ */
135
+ refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
136
+ /**
137
+ * Custom function to map the provider profile to a
138
+ * user.
139
+ */
140
+ mapProfileToUser?: (profile: Profile) => {
141
+ id?: string;
142
+ name?: string;
143
+ email?: string | null;
144
+ image?: string;
145
+ emailVerified?: boolean;
146
+ [key: string]: any;
147
+ } | Promise<{
148
+ id?: string;
149
+ name?: string;
150
+ email?: string | null;
151
+ image?: string;
152
+ emailVerified?: boolean;
153
+ [key: string]: any;
154
+ }>;
155
+ /**
156
+ * Disable implicit sign up for new users. When set to true for the provider,
157
+ * sign-in need to be called with with requestSignUp as true to create new users.
158
+ */
159
+ disableImplicitSignUp?: boolean;
160
+ /**
161
+ * Disable sign up for new users.
162
+ */
163
+ disableSignUp?: boolean;
164
+ /**
165
+ * The prompt to use for the authorization code request
166
+ */
167
+ prompt?: "select_account" | "consent" | "login" | "none" | "select_account consent";
168
+ /**
169
+ * The response mode to use for the authorization code request
170
+ */
171
+ responseMode?: "query" | "form_post";
172
+ /**
173
+ * If enabled, the user info will be overridden with the provider user info
174
+ * This is useful if you want to use the provider user info to update the user info
175
+ *
176
+ * @default false
177
+ */
178
+ overrideUserInfoOnSignIn?: boolean;
179
+ };
180
+
181
+ export type { OAuth2Tokens as O, ProviderOptions as P, OAuthProvider as a, OAuth2UserInfo as b };
@@ -0,0 +1,13 @@
1
+ import { D as DBFieldAttribute } from './core.CajxAutx.js';
2
+
3
+ type BetterAuthPluginDBSchema = {
4
+ [table in string]: {
5
+ fields: {
6
+ [field in string]: DBFieldAttribute;
7
+ };
8
+ disableMigration?: boolean;
9
+ modelName?: string;
10
+ };
11
+ };
12
+
13
+ export type { BetterAuthPluginDBSchema as B };
@@ -0,0 +1,53 @@
1
+ declare const TTY_COLORS: {
2
+ readonly reset: "\u001B[0m";
3
+ readonly bright: "\u001B[1m";
4
+ readonly dim: "\u001B[2m";
5
+ readonly undim: "\u001B[22m";
6
+ readonly underscore: "\u001B[4m";
7
+ readonly blink: "\u001B[5m";
8
+ readonly reverse: "\u001B[7m";
9
+ readonly hidden: "\u001B[8m";
10
+ readonly fg: {
11
+ readonly black: "\u001B[30m";
12
+ readonly red: "\u001B[31m";
13
+ readonly green: "\u001B[32m";
14
+ readonly yellow: "\u001B[33m";
15
+ readonly blue: "\u001B[34m";
16
+ readonly magenta: "\u001B[35m";
17
+ readonly cyan: "\u001B[36m";
18
+ readonly white: "\u001B[37m";
19
+ };
20
+ readonly bg: {
21
+ readonly black: "\u001B[40m";
22
+ readonly red: "\u001B[41m";
23
+ readonly green: "\u001B[42m";
24
+ readonly yellow: "\u001B[43m";
25
+ readonly blue: "\u001B[44m";
26
+ readonly magenta: "\u001B[45m";
27
+ readonly cyan: "\u001B[46m";
28
+ readonly white: "\u001B[47m";
29
+ };
30
+ };
31
+ type LogLevel = "info" | "success" | "warn" | "error" | "debug";
32
+ declare const levels: readonly ["info", "success", "warn", "error", "debug"];
33
+ declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
34
+ interface Logger {
35
+ disabled?: boolean;
36
+ disableColors?: boolean;
37
+ level?: Exclude<LogLevel, "success">;
38
+ log?: (level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void;
39
+ }
40
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
41
+ LogLevel,
42
+ ...infer Rest
43
+ ] ? Rest : never;
44
+ type InternalLogger = {
45
+ [K in LogLevel]: (...params: LogHandlerParams) => void;
46
+ } & {
47
+ get level(): LogLevel;
48
+ };
49
+ declare const createLogger: (options?: Logger) => InternalLogger;
50
+ declare const logger: InternalLogger;
51
+
52
+ export { TTY_COLORS as T, levels as a, createLogger as c, logger as l, shouldPublishLog as s };
53
+ export type { InternalLogger as I, Logger as L, LogLevel as b, LogHandlerParams as d };
@@ -0,0 +1,53 @@
1
+ declare const TTY_COLORS: {
2
+ readonly reset: "\u001B[0m";
3
+ readonly bright: "\u001B[1m";
4
+ readonly dim: "\u001B[2m";
5
+ readonly undim: "\u001B[22m";
6
+ readonly underscore: "\u001B[4m";
7
+ readonly blink: "\u001B[5m";
8
+ readonly reverse: "\u001B[7m";
9
+ readonly hidden: "\u001B[8m";
10
+ readonly fg: {
11
+ readonly black: "\u001B[30m";
12
+ readonly red: "\u001B[31m";
13
+ readonly green: "\u001B[32m";
14
+ readonly yellow: "\u001B[33m";
15
+ readonly blue: "\u001B[34m";
16
+ readonly magenta: "\u001B[35m";
17
+ readonly cyan: "\u001B[36m";
18
+ readonly white: "\u001B[37m";
19
+ };
20
+ readonly bg: {
21
+ readonly black: "\u001B[40m";
22
+ readonly red: "\u001B[41m";
23
+ readonly green: "\u001B[42m";
24
+ readonly yellow: "\u001B[43m";
25
+ readonly blue: "\u001B[44m";
26
+ readonly magenta: "\u001B[45m";
27
+ readonly cyan: "\u001B[46m";
28
+ readonly white: "\u001B[47m";
29
+ };
30
+ };
31
+ type LogLevel = "info" | "success" | "warn" | "error" | "debug";
32
+ declare const levels: readonly ["info", "success", "warn", "error", "debug"];
33
+ declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
34
+ interface Logger {
35
+ disabled?: boolean;
36
+ disableColors?: boolean;
37
+ level?: Exclude<LogLevel, "success">;
38
+ log?: (level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void;
39
+ }
40
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
41
+ LogLevel,
42
+ ...infer Rest
43
+ ] ? Rest : never;
44
+ type InternalLogger = {
45
+ [K in LogLevel]: (...params: LogHandlerParams) => void;
46
+ } & {
47
+ get level(): LogLevel;
48
+ };
49
+ declare const createLogger: (options?: Logger) => InternalLogger;
50
+ declare const logger: InternalLogger;
51
+
52
+ export { TTY_COLORS as T, levels as a, createLogger as c, logger as l, shouldPublishLog as s };
53
+ export type { InternalLogger as I, Logger as L, LogLevel as b, LogHandlerParams as d };
@@ -0,0 +1,53 @@
1
+ declare const TTY_COLORS: {
2
+ readonly reset: "\u001B[0m";
3
+ readonly bright: "\u001B[1m";
4
+ readonly dim: "\u001B[2m";
5
+ readonly undim: "\u001B[22m";
6
+ readonly underscore: "\u001B[4m";
7
+ readonly blink: "\u001B[5m";
8
+ readonly reverse: "\u001B[7m";
9
+ readonly hidden: "\u001B[8m";
10
+ readonly fg: {
11
+ readonly black: "\u001B[30m";
12
+ readonly red: "\u001B[31m";
13
+ readonly green: "\u001B[32m";
14
+ readonly yellow: "\u001B[33m";
15
+ readonly blue: "\u001B[34m";
16
+ readonly magenta: "\u001B[35m";
17
+ readonly cyan: "\u001B[36m";
18
+ readonly white: "\u001B[37m";
19
+ };
20
+ readonly bg: {
21
+ readonly black: "\u001B[40m";
22
+ readonly red: "\u001B[41m";
23
+ readonly green: "\u001B[42m";
24
+ readonly yellow: "\u001B[43m";
25
+ readonly blue: "\u001B[44m";
26
+ readonly magenta: "\u001B[45m";
27
+ readonly cyan: "\u001B[46m";
28
+ readonly white: "\u001B[47m";
29
+ };
30
+ };
31
+ type LogLevel = "info" | "success" | "warn" | "error" | "debug";
32
+ declare const levels: readonly ["info", "success", "warn", "error", "debug"];
33
+ declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
34
+ interface Logger {
35
+ disabled?: boolean;
36
+ disableColors?: boolean;
37
+ level?: Exclude<LogLevel, "success">;
38
+ log?: (level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void;
39
+ }
40
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
41
+ LogLevel,
42
+ ...infer Rest
43
+ ] ? Rest : never;
44
+ type InternalLogger = {
45
+ [K in LogLevel]: (...params: LogHandlerParams) => void;
46
+ } & {
47
+ get level(): LogLevel;
48
+ };
49
+ declare const createLogger: (options?: Logger) => InternalLogger;
50
+ declare const logger: InternalLogger;
51
+
52
+ export { TTY_COLORS as T, levels as a, createLogger as c, logger as l, shouldPublishLog as s };
53
+ export type { InternalLogger as I, Logger as L, LogLevel as b, LogHandlerParams as d };
@@ -0,0 +1,143 @@
1
+ import { ZodType } from 'zod';
2
+
3
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
4
+ type LiteralString = "" | (string & Record<never, never>);
5
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
6
+
7
+ declare module "../index" {
8
+ interface BetterAuthMutators<O, C> {
9
+ "better-auth/db": {};
10
+ }
11
+ }
12
+ type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
13
+ type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
14
+ type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
15
+ type DBFieldAttributeConfig = {
16
+ /**
17
+ * If the field should be required on a new record.
18
+ * @default true
19
+ */
20
+ required?: boolean;
21
+ /**
22
+ * If the value should be returned on a response body.
23
+ * @default true
24
+ */
25
+ returned?: boolean;
26
+ /**
27
+ * If a value should be provided when creating a new record.
28
+ * @default true
29
+ */
30
+ input?: boolean;
31
+ /**
32
+ * Default value for the field
33
+ *
34
+ * Note: This will not create a default value on the database level. It will only
35
+ * be used when creating a new record.
36
+ */
37
+ defaultValue?: DBPrimitive | (() => DBPrimitive);
38
+ /**
39
+ * Update value for the field
40
+ *
41
+ * Note: This will create an onUpdate trigger on the database level for supported adapters.
42
+ * It will be called when updating a record.
43
+ */
44
+ onUpdate?: () => DBPrimitive;
45
+ /**
46
+ * transform the value before storing it.
47
+ */
48
+ transform?: {
49
+ input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
50
+ output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
51
+ };
52
+ /**
53
+ * Reference to another model.
54
+ */
55
+ references?: {
56
+ /**
57
+ * The model to reference.
58
+ */
59
+ model: string;
60
+ /**
61
+ * The field on the referenced model.
62
+ */
63
+ field: string;
64
+ /**
65
+ * The action to perform when the reference is deleted.
66
+ * @default "cascade"
67
+ */
68
+ onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
69
+ };
70
+ unique?: boolean;
71
+ /**
72
+ * If the field should be a bigint on the database instead of integer.
73
+ */
74
+ bigint?: boolean;
75
+ /**
76
+ * A zod schema to validate the value.
77
+ */
78
+ validator?: {
79
+ input?: ZodType;
80
+ output?: ZodType;
81
+ };
82
+ /**
83
+ * The name of the field on the database.
84
+ */
85
+ fieldName?: string;
86
+ /**
87
+ * If the field should be sortable.
88
+ *
89
+ * applicable only for `text` type.
90
+ * It's useful to mark fields varchar instead of text.
91
+ */
92
+ sortable?: boolean;
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;
111
+ /**
112
+ * The order of the table
113
+ */
114
+ order?: number;
115
+ }>;
116
+ interface SecondaryStorage {
117
+ /**
118
+ *
119
+ * @param key - Key to get
120
+ * @returns - Value of the key
121
+ */
122
+ get: (key: string) => Promise<unknown> | 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) => Promise<void | null | unknown> | void;
136
+ /**
137
+ *
138
+ * @param key - Key to delete
139
+ */
140
+ delete: (key: string) => Promise<void | null | string> | void;
141
+ }
142
+
143
+ export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralString as L, Models as M, SecondaryStorage as S, LiteralUnion as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
@@ -0,0 +1,143 @@
1
+ import { ZodType } from 'zod';
2
+
3
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
4
+ type LiteralString = "" | (string & Record<never, never>);
5
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
6
+
7
+ declare module "../index" {
8
+ interface BetterAuthMutators<O, C> {
9
+ "better-auth/db": {};
10
+ }
11
+ }
12
+ type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
13
+ type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
14
+ type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
15
+ type DBFieldAttributeConfig = {
16
+ /**
17
+ * If the field should be required on a new record.
18
+ * @default true
19
+ */
20
+ required?: boolean;
21
+ /**
22
+ * If the value should be returned on a response body.
23
+ * @default true
24
+ */
25
+ returned?: boolean;
26
+ /**
27
+ * If a value should be provided when creating a new record.
28
+ * @default true
29
+ */
30
+ input?: boolean;
31
+ /**
32
+ * Default value for the field
33
+ *
34
+ * Note: This will not create a default value on the database level. It will only
35
+ * be used when creating a new record.
36
+ */
37
+ defaultValue?: DBPrimitive | (() => DBPrimitive);
38
+ /**
39
+ * Update value for the field
40
+ *
41
+ * Note: This will create an onUpdate trigger on the database level for supported adapters.
42
+ * It will be called when updating a record.
43
+ */
44
+ onUpdate?: () => DBPrimitive;
45
+ /**
46
+ * transform the value before storing it.
47
+ */
48
+ transform?: {
49
+ input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
50
+ output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
51
+ };
52
+ /**
53
+ * Reference to another model.
54
+ */
55
+ references?: {
56
+ /**
57
+ * The model to reference.
58
+ */
59
+ model: string;
60
+ /**
61
+ * The field on the referenced model.
62
+ */
63
+ field: string;
64
+ /**
65
+ * The action to perform when the reference is deleted.
66
+ * @default "cascade"
67
+ */
68
+ onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
69
+ };
70
+ unique?: boolean;
71
+ /**
72
+ * If the field should be a bigint on the database instead of integer.
73
+ */
74
+ bigint?: boolean;
75
+ /**
76
+ * A zod schema to validate the value.
77
+ */
78
+ validator?: {
79
+ input?: ZodType;
80
+ output?: ZodType;
81
+ };
82
+ /**
83
+ * The name of the field on the database.
84
+ */
85
+ fieldName?: string;
86
+ /**
87
+ * If the field should be sortable.
88
+ *
89
+ * applicable only for `text` type.
90
+ * It's useful to mark fields varchar instead of text.
91
+ */
92
+ sortable?: boolean;
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;
111
+ /**
112
+ * The order of the table
113
+ */
114
+ order?: number;
115
+ }>;
116
+ interface SecondaryStorage {
117
+ /**
118
+ *
119
+ * @param key - Key to get
120
+ * @returns - Value of the key
121
+ */
122
+ get: (key: string) => Promise<unknown> | 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) => Promise<void | null | unknown> | void;
136
+ /**
137
+ *
138
+ * @param key - Key to delete
139
+ */
140
+ delete: (key: string) => Promise<void | null | string> | void;
141
+ }
142
+
143
+ export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralString as L, Models as M, SecondaryStorage as S, LiteralUnion as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };