@better-auth/core 1.7.0-rc.1 → 1.7.0-rc.2

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 (208) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +0 -1
  3. package/dist/async_hooks/pure.index.d.mts +0 -1
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/global.d.mts +0 -1
  6. package/dist/context/global.mjs +1 -1
  7. package/dist/context/request-state.d.mts +0 -1
  8. package/dist/context/request-state.mjs +8 -5
  9. package/dist/context/transaction.d.mts +8 -3
  10. package/dist/context/transaction.mjs +27 -10
  11. package/dist/db/adapter/factory.d.mts +3 -5
  12. package/dist/db/adapter/factory.mjs +7 -5
  13. package/dist/db/adapter/get-default-field-name.d.mts +2 -9
  14. package/dist/db/adapter/get-default-model-name.d.mts +1 -5
  15. package/dist/db/adapter/get-default-model-name.mjs +6 -5
  16. package/dist/db/adapter/get-field-attributes.d.mts +4 -11
  17. package/dist/db/adapter/get-field-name.d.mts +2 -9
  18. package/dist/db/adapter/get-id-field.d.mts +4 -12
  19. package/dist/db/adapter/get-model-name.d.mts +1 -5
  20. package/dist/db/adapter/index.d.mts +7 -32
  21. package/dist/db/adapter/types.d.mts +5 -17
  22. package/dist/db/adapter/utils.d.mts +0 -1
  23. package/dist/db/database-index.d.mts +44 -0
  24. package/dist/db/database-index.mjs +168 -0
  25. package/dist/db/get-tables.d.mts +7 -1
  26. package/dist/db/get-tables.mjs +47 -6
  27. package/dist/db/index.d.mts +3 -3
  28. package/dist/db/index.mjs +2 -2
  29. package/dist/db/internal.d.mts +3 -0
  30. package/dist/db/internal.mjs +3 -0
  31. package/dist/db/plugin.d.mts +4 -3
  32. package/dist/db/schema/account.d.mts +16 -3
  33. package/dist/db/schema/account.mjs +35 -2
  34. package/dist/db/schema/rate-limit.d.mts +1 -1
  35. package/dist/db/schema/rate-limit.mjs +9 -0
  36. package/dist/db/schema/session.d.mts +1 -1
  37. package/dist/db/schema/shared.d.mts +0 -1
  38. package/dist/db/schema/user.d.mts +1 -1
  39. package/dist/db/schema/verification.d.mts +1 -1
  40. package/dist/db/type.d.mts +17 -9
  41. package/dist/env/logger.d.mts +25 -25
  42. package/dist/error/codes.d.mts +0 -1
  43. package/dist/error/index.d.mts +0 -1
  44. package/dist/index.d.mts +1 -1
  45. package/dist/instrumentation/attributes.d.mts +0 -1
  46. package/dist/instrumentation/pure.index.d.mts +0 -1
  47. package/dist/instrumentation/tracer.mjs +1 -1
  48. package/dist/oauth2/authorization-params.d.mts +0 -1
  49. package/dist/oauth2/client-assertion.d.mts +3 -13
  50. package/dist/oauth2/client-credentials-token.d.mts +3 -17
  51. package/dist/oauth2/client-credentials-token.mjs +1 -4
  52. package/dist/oauth2/create-authorization-url.d.mts +3 -21
  53. package/dist/oauth2/dpop.d.mts +2 -23
  54. package/dist/oauth2/dpop.mjs +1 -1
  55. package/dist/oauth2/index.d.mts +2 -2
  56. package/dist/oauth2/oauth-provider.d.mts +85 -36
  57. package/dist/oauth2/refresh-access-token.d.mts +3 -19
  58. package/dist/oauth2/refresh-access-token.mjs +3 -9
  59. package/dist/oauth2/reject-redirects.mjs +1 -1
  60. package/dist/oauth2/token-endpoint-auth.d.mts +0 -1
  61. package/dist/oauth2/utils.d.mts +0 -1
  62. package/dist/oauth2/utils.mjs +2 -3
  63. package/dist/oauth2/validate-authorization-code.d.mts +5 -29
  64. package/dist/oauth2/verify-id-token.d.mts +3 -2
  65. package/dist/oauth2/verify-id-token.mjs +3 -3
  66. package/dist/oauth2/verify.d.mts +5 -7
  67. package/dist/oauth2/verify.mjs +2 -2
  68. package/dist/social-providers/apple.d.mts +9 -24
  69. package/dist/social-providers/apple.mjs +2 -1
  70. package/dist/social-providers/atlassian.d.mts +18 -19
  71. package/dist/social-providers/atlassian.mjs +1 -1
  72. package/dist/social-providers/cognito.d.mts +33 -22
  73. package/dist/social-providers/cognito.mjs +2 -2
  74. package/dist/social-providers/discord.d.mts +7 -20
  75. package/dist/social-providers/discord.mjs +1 -1
  76. package/dist/social-providers/dropbox.d.mts +7 -22
  77. package/dist/social-providers/dropbox.mjs +1 -1
  78. package/dist/social-providers/facebook.d.mts +19 -27
  79. package/dist/social-providers/facebook.mjs +6 -17
  80. package/dist/social-providers/figma.d.mts +7 -22
  81. package/dist/social-providers/figma.mjs +1 -1
  82. package/dist/social-providers/github.d.mts +7 -23
  83. package/dist/social-providers/github.mjs +1 -1
  84. package/dist/social-providers/gitlab.d.mts +6 -43
  85. package/dist/social-providers/gitlab.mjs +1 -1
  86. package/dist/social-providers/google.d.mts +10 -32
  87. package/dist/social-providers/google.mjs +2 -1
  88. package/dist/social-providers/huggingface.d.mts +7 -22
  89. package/dist/social-providers/huggingface.mjs +1 -1
  90. package/dist/social-providers/index.d.mts +229 -787
  91. package/dist/social-providers/kakao.d.mts +8 -33
  92. package/dist/social-providers/kakao.mjs +1 -1
  93. package/dist/social-providers/kick.d.mts +7 -22
  94. package/dist/social-providers/kick.mjs +1 -1
  95. package/dist/social-providers/line.d.mts +8 -44
  96. package/dist/social-providers/line.mjs +4 -6
  97. package/dist/social-providers/linear.d.mts +7 -21
  98. package/dist/social-providers/linear.mjs +1 -1
  99. package/dist/social-providers/linkedin.d.mts +7 -21
  100. package/dist/social-providers/linkedin.mjs +1 -1
  101. package/dist/social-providers/microsoft-entra-id.d.mts +8 -18
  102. package/dist/social-providers/microsoft-entra-id.mjs +18 -2
  103. package/dist/social-providers/naver.d.mts +27 -42
  104. package/dist/social-providers/naver.mjs +1 -1
  105. package/dist/social-providers/notion.d.mts +7 -21
  106. package/dist/social-providers/notion.mjs +1 -1
  107. package/dist/social-providers/paybin.d.mts +8 -23
  108. package/dist/social-providers/paybin.mjs +2 -1
  109. package/dist/social-providers/paypal.d.mts +8 -33
  110. package/dist/social-providers/paypal.mjs +1 -1
  111. package/dist/social-providers/polar.d.mts +7 -22
  112. package/dist/social-providers/polar.mjs +1 -1
  113. package/dist/social-providers/railway.d.mts +7 -22
  114. package/dist/social-providers/railway.mjs +1 -1
  115. package/dist/social-providers/reddit.d.mts +7 -20
  116. package/dist/social-providers/reddit.mjs +1 -1
  117. package/dist/social-providers/roblox.d.mts +7 -20
  118. package/dist/social-providers/roblox.mjs +1 -1
  119. package/dist/social-providers/salesforce.d.mts +7 -22
  120. package/dist/social-providers/salesforce.mjs +1 -1
  121. package/dist/social-providers/slack.d.mts +7 -20
  122. package/dist/social-providers/slack.mjs +1 -1
  123. package/dist/social-providers/spotify.d.mts +7 -22
  124. package/dist/social-providers/spotify.mjs +1 -1
  125. package/dist/social-providers/tiktok.d.mts +10 -22
  126. package/dist/social-providers/tiktok.mjs +1 -1
  127. package/dist/social-providers/twitch.d.mts +7 -20
  128. package/dist/social-providers/twitch.mjs +1 -1
  129. package/dist/social-providers/twitter.d.mts +29 -26
  130. package/dist/social-providers/twitter.mjs +1 -1
  131. package/dist/social-providers/vercel.d.mts +7 -22
  132. package/dist/social-providers/vercel.mjs +1 -1
  133. package/dist/social-providers/vk.d.mts +8 -24
  134. package/dist/social-providers/vk.mjs +5 -6
  135. package/dist/social-providers/wechat.d.mts +7 -19
  136. package/dist/social-providers/wechat.mjs +1 -1
  137. package/dist/social-providers/zoom.d.mts +9 -25
  138. package/dist/social-providers/zoom.mjs +1 -1
  139. package/dist/types/context.d.mts +16 -9
  140. package/dist/types/cookie.d.mts +0 -1
  141. package/dist/types/helper.d.mts +1 -1
  142. package/dist/types/index.d.mts +1 -1
  143. package/dist/types/init-options.d.mts +37 -26
  144. package/dist/types/plugin-client.d.mts +1 -3
  145. package/dist/types/plugin.d.mts +2 -2
  146. package/dist/utils/async.d.mts +0 -1
  147. package/dist/utils/db.d.mts +1 -0
  148. package/dist/utils/deprecate.d.mts +0 -1
  149. package/dist/utils/error-codes.d.mts +2 -2
  150. package/dist/utils/host.d.mts +27 -1
  151. package/dist/utils/host.mjs +1 -1
  152. package/dist/utils/ip.d.mts +1 -0
  153. package/dist/utils/ip.mjs +1 -1
  154. package/dist/utils/is-api-error.d.mts +0 -1
  155. package/dist/utils/redirect-uri.d.mts +0 -1
  156. package/package.json +10 -2
  157. package/src/context/request-state.ts +26 -6
  158. package/src/context/transaction.ts +37 -18
  159. package/src/db/adapter/factory.ts +24 -18
  160. package/src/db/adapter/get-default-model-name.ts +23 -14
  161. package/src/db/database-index.ts +351 -0
  162. package/src/db/get-tables.ts +89 -9
  163. package/src/db/index.ts +4 -0
  164. package/src/db/internal.ts +12 -0
  165. package/src/db/plugin.ts +3 -1
  166. package/src/db/schema/account.ts +27 -1
  167. package/src/db/schema/user.ts +1 -1
  168. package/src/db/type.ts +12 -0
  169. package/src/oauth2/index.ts +3 -0
  170. package/src/oauth2/oauth-provider.ts +94 -36
  171. package/src/oauth2/verify-id-token.ts +4 -2
  172. package/src/social-providers/apple.ts +2 -1
  173. package/src/social-providers/atlassian.ts +1 -1
  174. package/src/social-providers/cognito.ts +2 -2
  175. package/src/social-providers/discord.ts +1 -1
  176. package/src/social-providers/dropbox.ts +1 -1
  177. package/src/social-providers/facebook.ts +21 -28
  178. package/src/social-providers/figma.ts +1 -1
  179. package/src/social-providers/github.ts +1 -1
  180. package/src/social-providers/gitlab.ts +1 -1
  181. package/src/social-providers/google.ts +2 -1
  182. package/src/social-providers/huggingface.ts +1 -1
  183. package/src/social-providers/kakao.ts +1 -1
  184. package/src/social-providers/kick.ts +1 -1
  185. package/src/social-providers/line.ts +7 -12
  186. package/src/social-providers/linear.ts +1 -1
  187. package/src/social-providers/linkedin.ts +1 -1
  188. package/src/social-providers/microsoft-entra-id.ts +3 -2
  189. package/src/social-providers/naver.ts +1 -1
  190. package/src/social-providers/notion.ts +1 -1
  191. package/src/social-providers/paybin.ts +2 -1
  192. package/src/social-providers/paypal.ts +1 -1
  193. package/src/social-providers/polar.ts +1 -1
  194. package/src/social-providers/railway.ts +1 -1
  195. package/src/social-providers/reddit.ts +1 -1
  196. package/src/social-providers/roblox.ts +1 -1
  197. package/src/social-providers/salesforce.ts +1 -1
  198. package/src/social-providers/slack.ts +1 -1
  199. package/src/social-providers/spotify.ts +1 -1
  200. package/src/social-providers/tiktok.ts +2 -2
  201. package/src/social-providers/twitch.ts +1 -1
  202. package/src/social-providers/twitter.ts +1 -1
  203. package/src/social-providers/vercel.ts +1 -1
  204. package/src/social-providers/vk.ts +2 -2
  205. package/src/social-providers/wechat.ts +1 -1
  206. package/src/social-providers/zoom.ts +1 -1
  207. package/src/types/context.ts +21 -14
  208. package/src/types/init-options.ts +15 -14
@@ -1,12 +1,12 @@
1
1
  import { BetterAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
2
2
  import { DBAdapter } from "../db/adapter/index.mjs";
3
3
  import { createLogger } from "../env/logger.mjs";
4
+ import "../db/index.mjs";
4
5
  import { AuthContext } from "../types/context.mjs";
6
+ import "../types/index.mjs";
5
7
  import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
6
- import * as better_call0 from "better-call";
8
+ import "../oauth2/index.mjs";
7
9
  import { EndpointContext, EndpointOptions, StrictEndpoint } from "better-call";
8
- import * as _better_auth_core0 from "@better-auth/core";
9
-
10
10
  //#region src/api/index.d.ts
11
11
  /**
12
12
  * Response headers that forbid any intermediary (proxy, CDN, browser) from
@@ -26,13 +26,13 @@ declare const NO_STORE_HEADERS: {
26
26
  readonly "Cache-Control": "no-store";
27
27
  readonly Pragma: "no-cache";
28
28
  };
29
- declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
29
+ declare const optionsMiddleware: <InputCtx extends import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
30
30
  declare const createAuthMiddleware: {
31
- <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, {
31
+ <Options extends import("better-call").MiddlewareOptions, R>(options: Options, handler: (ctx: import("better-call").MiddlewareContext<Options, {
32
32
  returned?: unknown | undefined;
33
33
  responseHeaders?: Headers | undefined;
34
- } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
35
- options: _better_auth_core0.BetterAuthOptions;
34
+ } & import("@better-auth/core").PluginContext<import("@better-auth/core").BetterAuthOptions> & import("@better-auth/core").InfoContext & {
35
+ options: import("@better-auth/core").BetterAuthOptions;
36
36
  trustedOrigins: string[];
37
37
  trustedProviders: string[];
38
38
  isTrustedOrigin: (url: string, settings?: {
@@ -106,19 +106,19 @@ declare const createAuthMiddleware: {
106
106
  } & Record<string, any>;
107
107
  } | null) => void;
108
108
  socialProviders: OAuthProvider[];
109
- authCookies: _better_auth_core0.BetterAuthCookies;
109
+ authCookies: import("@better-auth/core").BetterAuthCookies;
110
110
  logger: ReturnType<typeof createLogger>;
111
111
  rateLimit: {
112
112
  enabled: boolean;
113
113
  window: number;
114
114
  max: number;
115
115
  storage: "memory" | "database" | "secondary-storage";
116
- } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
117
- adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
118
- internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
119
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
116
+ } & Omit<import("@better-auth/core").BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
117
+ adapter: DBAdapter<import("@better-auth/core").BetterAuthOptions>;
118
+ internalAdapter: import("@better-auth/core").InternalAdapter<import("@better-auth/core").BetterAuthOptions>;
119
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@better-auth/core").BetterAuthCookie;
120
120
  secret: string;
121
- secretConfig: string | _better_auth_core0.SecretConfig;
121
+ secretConfig: string | import("@better-auth/core").SecretConfig;
122
122
  sessionConfig: {
123
123
  updateAge: number;
124
124
  expiresIn: number;
@@ -143,7 +143,7 @@ declare const createAuthMiddleware: {
143
143
  minPasswordLength: number;
144
144
  maxPasswordLength: number;
145
145
  };
146
- checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
146
+ checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
147
147
  };
148
148
  tables: BetterAuthDBSchema;
149
149
  runMigrations: () => Promise<void>;
@@ -155,13 +155,13 @@ declare const createAuthMiddleware: {
155
155
  skipOriginCheck: boolean | string[];
156
156
  skipCSRFCheck: boolean;
157
157
  runInBackground: (promise: Promise<unknown>) => void;
158
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
159
- }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
160
- <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, {
158
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@better-auth/core").Awaitable<unknown>;
159
+ }>) => Promise<R>): (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R>;
160
+ <Options extends import("better-call").MiddlewareOptions, R_1>(handler: (ctx: import("better-call").MiddlewareContext<Options, {
161
161
  returned?: unknown | undefined;
162
162
  responseHeaders?: Headers | undefined;
163
- } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
164
- options: _better_auth_core0.BetterAuthOptions;
163
+ } & import("@better-auth/core").PluginContext<import("@better-auth/core").BetterAuthOptions> & import("@better-auth/core").InfoContext & {
164
+ options: import("@better-auth/core").BetterAuthOptions;
165
165
  trustedOrigins: string[];
166
166
  trustedProviders: string[];
167
167
  isTrustedOrigin: (url: string, settings?: {
@@ -235,19 +235,19 @@ declare const createAuthMiddleware: {
235
235
  } & Record<string, any>;
236
236
  } | null) => void;
237
237
  socialProviders: OAuthProvider[];
238
- authCookies: _better_auth_core0.BetterAuthCookies;
238
+ authCookies: import("@better-auth/core").BetterAuthCookies;
239
239
  logger: ReturnType<typeof createLogger>;
240
240
  rateLimit: {
241
241
  enabled: boolean;
242
242
  window: number;
243
243
  max: number;
244
244
  storage: "memory" | "database" | "secondary-storage";
245
- } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
246
- adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
247
- internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
248
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
245
+ } & Omit<import("@better-auth/core").BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
246
+ adapter: DBAdapter<import("@better-auth/core").BetterAuthOptions>;
247
+ internalAdapter: import("@better-auth/core").InternalAdapter<import("@better-auth/core").BetterAuthOptions>;
248
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@better-auth/core").BetterAuthCookie;
249
249
  secret: string;
250
- secretConfig: string | _better_auth_core0.SecretConfig;
250
+ secretConfig: string | import("@better-auth/core").SecretConfig;
251
251
  sessionConfig: {
252
252
  updateAge: number;
253
253
  expiresIn: number;
@@ -272,7 +272,7 @@ declare const createAuthMiddleware: {
272
272
  minPasswordLength: number;
273
273
  maxPasswordLength: number;
274
274
  };
275
- checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
275
+ checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
276
276
  };
277
277
  tables: BetterAuthDBSchema;
278
278
  runMigrations: () => Promise<void>;
@@ -284,8 +284,8 @@ declare const createAuthMiddleware: {
284
284
  skipOriginCheck: boolean | string[];
285
285
  skipCSRFCheck: boolean;
286
286
  runInBackground: (promise: Promise<unknown>) => void;
287
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
288
- }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
287
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@better-auth/core").Awaitable<unknown>;
288
+ }>) => Promise<R_1>): (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R_1>;
289
289
  };
290
290
  type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
291
291
  declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
2
  //#region src/async_hooks/index.d.ts
4
3
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
4
  //#endregion
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
2
  //#region src/async_hooks/pure.index.d.ts
4
3
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
4
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { AuthContext } from "../types/context.mjs";
2
+ import "../types/index.mjs";
2
3
  import { EndpointContext, InputContext } from "better-call";
3
4
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
4
-
5
5
  //#region src/context/endpoint-context.d.ts
6
6
  type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
7
7
  context: AuthContext;
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
-
3
2
  //#region src/context/global.d.ts
4
3
  declare function getBetterAuthVersion(): string;
5
4
  //#endregion
@@ -2,7 +2,7 @@
2
2
  const symbol = Symbol.for("better-auth:global");
3
3
  let bind = null;
4
4
  const __context = {};
5
- const __betterAuthVersion = "1.7.0-rc.1";
5
+ const __betterAuthVersion = "1.7.0-rc.2";
6
6
  /**
7
7
  * We store context instance in the globalThis.
8
8
  *
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
-
3
2
  //#region src/context/request-state.d.ts
4
3
  type RequestStateWeakMap = WeakMap<object, any>;
5
4
  declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
@@ -1,13 +1,16 @@
1
1
  import { __getBetterAuthGlobal } from "./global.mjs";
2
2
  import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  //#region src/context/request-state.ts
4
+ let asyncStorageInit = null;
4
5
  const ensureAsyncStorage = async () => {
5
6
  const betterAuthGlobal = __getBetterAuthGlobal();
6
- if (!betterAuthGlobal.context.requestStateAsyncStorage) {
7
- const AsyncLocalStorage = await getAsyncLocalStorage();
8
- betterAuthGlobal.context.requestStateAsyncStorage = new AsyncLocalStorage();
9
- }
10
- return betterAuthGlobal.context.requestStateAsyncStorage;
7
+ const existing = betterAuthGlobal.context.requestStateAsyncStorage;
8
+ if (existing) return existing;
9
+ if (!asyncStorageInit) asyncStorageInit = getAsyncLocalStorage().then((AsyncLocalStorage) => {
10
+ betterAuthGlobal.context.requestStateAsyncStorage ??= new AsyncLocalStorage();
11
+ return betterAuthGlobal.context.requestStateAsyncStorage;
12
+ });
13
+ return asyncStorageInit;
11
14
  };
12
15
  async function getRequestStateAsyncLocalStorage() {
13
16
  return ensureAsyncStorage();
@@ -1,7 +1,7 @@
1
1
  import { DBAdapter, DBTransactionAdapter } from "../db/adapter/index.mjs";
2
2
  import { BetterAuthOptions } from "../types/init-options.mjs";
3
+ import "../types/index.mjs";
3
4
  import { AsyncLocalStorage } from "node:async_hooks";
4
-
5
5
  //#region src/context/transaction.d.ts
6
6
  type StoredAdapter = DBTransactionAdapter<BetterAuthOptions>;
7
7
  type HookContext = {
@@ -17,11 +17,16 @@ type HookContext = {
17
17
  declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<HookContext>>;
18
18
  declare const getCurrentAdapter: <Options extends BetterAuthOptions = BetterAuthOptions>(fallback: DBTransactionAdapter<Options>) => Promise<DBTransactionAdapter<Options>>;
19
19
  declare const runWithAdapter: <R, Options extends BetterAuthOptions = BetterAuthOptions>(adapter: DBAdapter<Options>, fn: () => R) => Promise<R>;
20
- declare const runWithTransaction: <R, Options extends BetterAuthOptions = BetterAuthOptions>(adapter: DBAdapter<Options>, fn: () => R) => Promise<R>;
20
+ declare const runWithTransaction: <R, Options extends BetterAuthOptions = BetterAuthOptions>(adapter: DBAdapter<Options>, fn: () => R, options?: {
21
+ onAfterCommitHookError?: (error: unknown) => void | Promise<void>;
22
+ }) => Promise<R>;
21
23
  /**
22
24
  * Queue a hook to be executed after the current transaction commits.
23
25
  * If not in a transaction, the hook will execute immediately.
24
26
  */
25
- declare const queueAfterTransactionHook: (hook: () => Promise<void>) => Promise<void>;
27
+ declare const queueAfterTransactionHook: (hook: () => Promise<void>, options?: {
28
+ /** Handles a queued hook failure after the surrounding work has committed. */
29
+ onError?: (error: unknown) => void | Promise<void>;
30
+ }) => Promise<void>;
26
31
  //#endregion
27
32
  export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction };
@@ -50,7 +50,7 @@ const runWithAdapter = async (adapter, fn) => {
50
50
  throw err;
51
51
  });
52
52
  };
53
- const runWithTransaction = async (adapter, fn) => {
53
+ const runWithTransaction = async (adapter, fn, options) => {
54
54
  let called = false;
55
55
  return ensureAsyncStorage().then(async (als) => {
56
56
  called = true;
@@ -71,8 +71,15 @@ const runWithTransaction = async (adapter, fn) => {
71
71
  hasError = true;
72
72
  error = e;
73
73
  }
74
- for (const hook of pendingHooks) await hook();
75
74
  if (hasError) throw error;
75
+ for (const hook of pendingHooks) try {
76
+ await hook();
77
+ } catch (error) {
78
+ if (!options?.onAfterCommitHookError) throw error;
79
+ try {
80
+ await options.onAfterCommitHookError(error);
81
+ } catch {}
82
+ }
76
83
  return result;
77
84
  }).catch((err) => {
78
85
  if (!called) return fn();
@@ -83,14 +90,24 @@ const runWithTransaction = async (adapter, fn) => {
83
90
  * Queue a hook to be executed after the current transaction commits.
84
91
  * If not in a transaction, the hook will execute immediately.
85
92
  */
86
- const queueAfterTransactionHook = async (hook) => {
87
- return ensureAsyncStorage().then((als) => {
88
- const store = als.getStore();
89
- if (store) store.pendingHooks.push(hook);
90
- else return hook();
91
- }).catch(() => {
92
- return hook();
93
- });
93
+ const queueAfterTransactionHook = async (hook, options) => {
94
+ const executeHook = async () => {
95
+ try {
96
+ await hook();
97
+ } catch (error) {
98
+ if (!options?.onError) throw error;
99
+ await options.onError(error);
100
+ }
101
+ };
102
+ let storage;
103
+ try {
104
+ storage = await ensureAsyncStorage();
105
+ } catch {
106
+ return executeHook();
107
+ }
108
+ const store = storage.getStore();
109
+ if (!store?.isTransactionActive) return executeHook();
110
+ store.pendingHooks.push(executeHook);
94
111
  };
95
112
  //#endregion
96
113
  export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction };
@@ -7,11 +7,9 @@ import { initGetModelName } from "./get-model-name.mjs";
7
7
  import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs } from "./types.mjs";
8
8
  import { DBAdapter } from "./index.mjs";
9
9
  import { BetterAuthOptions } from "../../types/init-options.mjs";
10
+ import "../../types/index.mjs";
10
11
  //#region src/db/adapter/factory.d.ts
11
12
  type AdapterFactory<Options extends BetterAuthOptions> = (options: Options) => DBAdapter<Options>;
12
- declare const createAdapterFactory: <Options extends BetterAuthOptions>({
13
- adapter: customAdapter,
14
- config: cfg
15
- }: AdapterFactoryOptions) => AdapterFactory<Options>;
13
+ declare const createAdapterFactory: <Options extends BetterAuthOptions>({ adapter: customAdapter, config: cfg }: AdapterFactoryOptions) => AdapterFactory<Options>;
16
14
  //#endregion
17
- export { AdapterFactory, createAdapterFactory };
15
+ export { AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, createAdapterFactory, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName };
@@ -187,8 +187,10 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
187
187
  if (!data) return null;
188
188
  for (const { modelName, defaultModelName, joinConfig } of requiredModels) {
189
189
  let joinedData = await (async () => {
190
- if (options.experimental?.joins) return data[modelName];
191
- else return await handleFallbackJoin({
190
+ if (options.advanced?.database?.joins) {
191
+ if (modelName in data) return data[modelName];
192
+ }
193
+ return await handleFallbackJoin({
192
194
  baseModel: unsafe_model,
193
195
  baseData: transformedData,
194
196
  joinModel: modelName,
@@ -546,7 +548,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
546
548
  join = result.join;
547
549
  select = result.select;
548
550
  }
549
- if (!options.experimental?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
551
+ if (!options.advanced?.database?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
550
552
  } else join = unsafeJoin;
551
553
  debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findOne")}:`, {
552
554
  model,
@@ -594,7 +596,7 @@ const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (optio
594
596
  join = result.join;
595
597
  select = result.select;
596
598
  }
597
- if (!options.experimental?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
599
+ if (!options.advanced?.database?.joins && join && Object.keys(join).length > 0) passJoinToAdapter = false;
598
600
  } else join = unsafeJoin;
599
601
  debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findMany")}:`, {
600
602
  model,
@@ -839,4 +841,4 @@ function formatAction(action) {
839
841
  return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
840
842
  }
841
843
  //#endregion
842
- export { createAdapterFactory };
844
+ export { createAdapterFactory, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName };
@@ -1,16 +1,9 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-default-field-name.d.ts
4
- declare const initGetDefaultFieldName: ({
5
- schema,
6
- usePlural
7
- }: {
3
+ declare const initGetDefaultFieldName: ({ schema, usePlural }: {
8
4
  schema: BetterAuthDBSchema;
9
5
  usePlural: boolean | undefined;
10
- }) => ({
11
- field,
12
- model: unsafeModel
13
- }: {
6
+ }) => ({ field, model: unsafeModel }: {
14
7
  model: string;
15
8
  field: string;
16
9
  }) => string;
@@ -1,10 +1,6 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-default-model-name.d.ts
4
- declare const initGetDefaultModelName: ({
5
- usePlural,
6
- schema
7
- }: {
3
+ declare const initGetDefaultModelName: ({ usePlural, schema }: {
8
4
  usePlural: boolean | undefined;
9
5
  schema: BetterAuthDBSchema;
10
6
  }) => (model: string) => string;
@@ -13,14 +13,15 @@ const initGetDefaultModelName = ({ usePlural, schema }) => {
13
13
  * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
14
14
  */
15
15
  const getDefaultModelName = (model) => {
16
+ const resolve = (candidate) => {
17
+ if (schema[candidate]) return candidate;
18
+ return Object.entries(schema).find(([_, f]) => f.modelName === candidate)?.[0];
19
+ };
16
20
  if (usePlural && model.charAt(model.length - 1) === "s") {
17
- const pluralessModel = model.slice(0, -1);
18
- let m = schema[pluralessModel] ? pluralessModel : void 0;
19
- if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
21
+ const m = resolve(model.slice(0, -1));
20
22
  if (m) return m;
21
23
  }
22
- let m = schema[model] ? model : void 0;
23
- if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
24
+ const m = resolve(model);
24
25
  if (!m) throw new BetterAuthError(`Model "${model}" not found in schema`);
25
26
  return m;
26
27
  };
@@ -1,13 +1,9 @@
1
1
  import { BetterAuthDBSchema, DBFieldAttribute, DBFieldType } from "../type.mjs";
2
2
  import { BetterAuthOptions } from "../../types/init-options.mjs";
3
+ import "../index.mjs";
4
+ import "../../types/index.mjs";
3
5
  //#region src/db/adapter/get-field-attributes.d.ts
4
- declare const initGetFieldAttributes: ({
5
- usePlural,
6
- schema,
7
- options,
8
- customIdGenerator,
9
- disableIdGeneration
10
- }: {
6
+ declare const initGetFieldAttributes: ({ usePlural, schema, options, customIdGenerator, disableIdGeneration }: {
11
7
  usePlural?: boolean;
12
8
  schema: BetterAuthDBSchema;
13
9
  options: BetterAuthOptions;
@@ -15,10 +11,7 @@ declare const initGetFieldAttributes: ({
15
11
  customIdGenerator?: ((props: {
16
12
  model: string;
17
13
  }) => string) | undefined;
18
- }) => ({
19
- model,
20
- field
21
- }: {
14
+ }) => ({ model, field }: {
22
15
  model: string;
23
16
  field: string;
24
17
  }) => DBFieldAttribute<DBFieldType>;
@@ -1,16 +1,9 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-field-name.d.ts
4
- declare const initGetFieldName: ({
5
- schema,
6
- usePlural
7
- }: {
3
+ declare const initGetFieldName: ({ schema, usePlural }: {
8
4
  schema: BetterAuthDBSchema;
9
5
  usePlural: boolean | undefined;
10
- }) => ({
11
- model: modelName,
12
- field: fieldName
13
- }: {
6
+ }) => ({ model: modelName, field: fieldName }: {
14
7
  model: string;
15
8
  field: string;
16
9
  }) => string;
@@ -1,14 +1,9 @@
1
1
  import { BetterAuthDBSchema, DBPrimitive } from "../type.mjs";
2
2
  import { BetterAuthOptions } from "../../types/init-options.mjs";
3
+ import "../index.mjs";
4
+ import "../../types/index.mjs";
3
5
  //#region src/db/adapter/get-id-field.d.ts
4
- declare const initGetIdField: ({
5
- usePlural,
6
- schema,
7
- disableIdGeneration,
8
- options,
9
- customIdGenerator,
10
- supportsUUIDs
11
- }: {
6
+ declare const initGetIdField: ({ usePlural, schema, disableIdGeneration, options, customIdGenerator, supportsUUIDs }: {
12
7
  usePlural?: boolean;
13
8
  schema: BetterAuthDBSchema;
14
9
  options: BetterAuthOptions;
@@ -17,10 +12,7 @@ declare const initGetIdField: ({
17
12
  model: string;
18
13
  }) => string) | undefined;
19
14
  supportsUUIDs?: boolean;
20
- }) => ({
21
- customModelName,
22
- forceAllowId
23
- }: {
15
+ }) => ({ customModelName, forceAllowId }: {
24
16
  customModelName?: string;
25
17
  forceAllowId?: boolean;
26
18
  }) => {
@@ -1,10 +1,6 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-model-name.d.ts
4
- declare const initGetModelName: ({
5
- usePlural,
6
- schema
7
- }: {
3
+ declare const initGetModelName: ({ usePlural, schema }: {
8
4
  usePlural: boolean | undefined;
9
5
  schema: BetterAuthDBSchema;
10
6
  }) => (model: string) => string;
@@ -9,6 +9,7 @@ import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFac
9
9
  import { AdapterFactory, createAdapterFactory } from "./factory.mjs";
10
10
  import { deepmerge, withApplyDefault } from "./utils.mjs";
11
11
  import { BetterAuthOptions } from "../../types/init-options.mjs";
12
+ import "../../types/index.mjs";
12
13
  //#region src/db/adapter/index.d.ts
13
14
  type DBAdapterDebugLogOption = boolean | {
14
15
  /**
@@ -488,11 +489,7 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
488
489
  };
489
490
  type CleanedWhere = Required<Where>;
490
491
  interface CustomAdapter {
491
- create: <T extends Record<string, any>>({
492
- data,
493
- model,
494
- select
495
- }: {
492
+ create: <T extends Record<string, any>>({ data, model, select }: {
496
493
  model: string;
497
494
  data: T;
498
495
  select?: string[] | undefined;
@@ -507,26 +504,13 @@ interface CustomAdapter {
507
504
  where: CleanedWhere[];
508
505
  update: Record<string, any>;
509
506
  }) => Promise<number>;
510
- findOne: <T>({
511
- model,
512
- where,
513
- select,
514
- join
515
- }: {
507
+ findOne: <T>({ model, where, select, join }: {
516
508
  model: string;
517
509
  where: CleanedWhere[];
518
510
  select?: string[] | undefined;
519
511
  join?: JoinConfig | undefined;
520
512
  }) => Promise<T | null>;
521
- findMany: <T>({
522
- model,
523
- where,
524
- limit,
525
- select,
526
- sortBy,
527
- offset,
528
- join
529
- }: {
513
+ findMany: <T>({ model, where, limit, select, sortBy, offset, join }: {
530
514
  model: string;
531
515
  where?: CleanedWhere[] | undefined;
532
516
  limit: number;
@@ -538,17 +522,11 @@ interface CustomAdapter {
538
522
  offset?: number | undefined;
539
523
  join?: JoinConfig | undefined;
540
524
  }) => Promise<T[]>;
541
- delete: ({
542
- model,
543
- where
544
- }: {
525
+ delete: ({ model, where }: {
545
526
  model: string;
546
527
  where: CleanedWhere[];
547
528
  }) => Promise<void>;
548
- deleteMany: ({
549
- model,
550
- where
551
- }: {
529
+ deleteMany: ({ model, where }: {
552
530
  model: string;
553
531
  where: CleanedWhere[];
554
532
  }) => Promise<number>;
@@ -580,10 +558,7 @@ interface CustomAdapter {
580
558
  increment: Record<string, number>;
581
559
  set?: Record<string, unknown> | undefined;
582
560
  }) => Promise<T | null>;
583
- count: ({
584
- model,
585
- where
586
- }: {
561
+ count: ({ model, where }: {
587
562
  model: string;
588
563
  where?: CleanedWhere[] | undefined;
589
564
  }) => Promise<number>;
@@ -1,6 +1,7 @@
1
1
  import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
2
2
  import { CleanedWhere, CustomAdapter, DBAdapterFactoryConfig, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
3
3
  import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
4
5
  //#region src/db/adapter/types.d.ts
5
6
  type AdapterFactoryOptions = {
6
7
  config: AdapterFactoryConfig;
@@ -35,10 +36,7 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
35
36
  /**
36
37
  * Get the field name which is expected to be saved in the database based on the user's schema.
37
38
  */
38
- getFieldName: ({
39
- model,
40
- field
41
- }: {
39
+ getFieldName: ({ model, field }: {
42
40
  model: string;
43
41
  field: string;
44
42
  }) => string;
@@ -66,10 +64,7 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
66
64
  * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
67
65
  *
68
66
  */
69
- getDefaultFieldName: ({
70
- model,
71
- field
72
- }: {
67
+ getDefaultFieldName: ({ model, field }: {
73
68
  model: string;
74
69
  field: string;
75
70
  }) => string;
@@ -78,20 +73,13 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
78
73
  *
79
74
  * Note: any model name or field name is allowed, whether default to schema or not.
80
75
  */
81
- getFieldAttributes: ({
82
- model,
83
- field
84
- }: {
76
+ getFieldAttributes: ({ model, field }: {
85
77
  model: string;
86
78
  field: string;
87
79
  }) => DBFieldAttribute;
88
80
  transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
89
81
  transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
90
- transformWhereClause: <W extends Where[] | undefined>({
91
- model,
92
- where,
93
- action
94
- }: {
82
+ transformWhereClause: <W extends Where[] | undefined>({ model, where, action }: {
95
83
  where: W;
96
84
  model: string;
97
85
  action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "consumeOne" | "incrementOne" | "count";
@@ -1,5 +1,4 @@
1
1
  import { DBFieldAttribute } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/utils.d.ts
4
3
  declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
5
4
  declare function deepmerge<T>(target: T, source: Partial<T>): T;