@better-auth/core 1.4.0-beta.8 → 1.4.0

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 (125) hide show
  1. package/.turbo/turbo-build.log +41 -34
  2. package/dist/api/index.d.mts +3 -0
  3. package/dist/api/index.mjs +26 -0
  4. package/dist/async_hooks/index.d.mts +2 -10
  5. package/dist/async_hooks/index.mjs +2 -24
  6. package/dist/async_hooks-BfRfbd1J.mjs +18 -0
  7. package/dist/context/index.d.mts +54 -0
  8. package/dist/context/index.mjs +4 -0
  9. package/dist/context-DgQ9XGBl.mjs +114 -0
  10. package/dist/db/adapter/index.d.mts +3 -23
  11. package/dist/db/adapter/index.mjs +1 -1
  12. package/dist/db/index.d.mts +3 -127
  13. package/dist/db/index.mjs +46 -55
  14. package/dist/env/index.d.mts +2 -85
  15. package/dist/env/index.mjs +2 -299
  16. package/dist/env-DwlNAN_D.mjs +245 -0
  17. package/dist/error/index.d.mts +35 -0
  18. package/dist/error/index.mjs +4 -0
  19. package/dist/error-BhAKg8LX.mjs +45 -0
  20. package/dist/index-CdubV7uy.d.mts +82 -0
  21. package/dist/index-CkAWdKH8.d.mts +7352 -0
  22. package/dist/index-DgwIISs7.d.mts +7 -0
  23. package/dist/index.d.mts +3 -115
  24. package/dist/index.mjs +1 -1
  25. package/dist/oauth2/index.d.mts +3 -277
  26. package/dist/oauth2/index.mjs +2 -356
  27. package/dist/oauth2-DmgZmPEg.mjs +236 -0
  28. package/dist/social-providers/index.d.mts +3 -0
  29. package/dist/social-providers/index.mjs +2523 -0
  30. package/dist/utils/index.d.mts +9 -0
  31. package/dist/utils/index.mjs +3 -0
  32. package/dist/utils-C5EN75oV.mjs +7 -0
  33. package/package.json +90 -62
  34. package/src/api/index.ts +53 -0
  35. package/src/async_hooks/index.ts +1 -9
  36. package/src/context/endpoint-context.ts +49 -0
  37. package/src/context/index.ts +21 -0
  38. package/src/context/request-state.test.ts +94 -0
  39. package/src/context/request-state.ts +90 -0
  40. package/src/context/transaction.ts +73 -0
  41. package/src/db/adapter/index.ts +518 -8
  42. package/src/db/index.ts +12 -11
  43. package/src/db/plugin.ts +3 -3
  44. package/src/db/type.ts +55 -52
  45. package/src/env/color-depth.ts +5 -4
  46. package/src/env/env-impl.ts +2 -1
  47. package/src/env/index.ts +9 -9
  48. package/src/env/logger.test.ts +3 -2
  49. package/src/env/logger.ts +11 -9
  50. package/src/error/codes.ts +31 -0
  51. package/src/error/index.ts +11 -0
  52. package/src/index.ts +0 -2
  53. package/src/oauth2/client-credentials-token.ts +9 -9
  54. package/src/oauth2/create-authorization-url.ts +12 -12
  55. package/src/oauth2/index.ts +10 -11
  56. package/src/oauth2/oauth-provider.ts +96 -74
  57. package/src/oauth2/refresh-access-token.ts +12 -12
  58. package/src/oauth2/utils.ts +2 -0
  59. package/src/oauth2/validate-authorization-code.ts +13 -15
  60. package/src/social-providers/apple.ts +213 -0
  61. package/src/social-providers/atlassian.ts +132 -0
  62. package/src/social-providers/cognito.ts +269 -0
  63. package/src/social-providers/discord.ts +169 -0
  64. package/src/social-providers/dropbox.ts +112 -0
  65. package/src/social-providers/facebook.ts +206 -0
  66. package/src/social-providers/figma.ts +115 -0
  67. package/src/social-providers/github.ts +154 -0
  68. package/src/social-providers/gitlab.ts +155 -0
  69. package/src/social-providers/google.ts +171 -0
  70. package/src/social-providers/huggingface.ts +118 -0
  71. package/src/social-providers/index.ts +124 -0
  72. package/src/social-providers/kakao.ts +178 -0
  73. package/src/social-providers/kick.ts +93 -0
  74. package/src/social-providers/line.ts +169 -0
  75. package/src/social-providers/linear.ts +121 -0
  76. package/src/social-providers/linkedin.ts +110 -0
  77. package/src/social-providers/microsoft-entra-id.ts +259 -0
  78. package/src/social-providers/naver.ts +112 -0
  79. package/src/social-providers/notion.ts +108 -0
  80. package/src/social-providers/paybin.ts +122 -0
  81. package/src/social-providers/paypal.ts +263 -0
  82. package/src/social-providers/polar.ts +110 -0
  83. package/src/social-providers/reddit.ts +122 -0
  84. package/src/social-providers/roblox.ts +111 -0
  85. package/src/social-providers/salesforce.ts +159 -0
  86. package/src/social-providers/slack.ts +111 -0
  87. package/src/social-providers/spotify.ts +93 -0
  88. package/src/social-providers/tiktok.ts +210 -0
  89. package/src/social-providers/twitch.ts +111 -0
  90. package/src/social-providers/twitter.ts +198 -0
  91. package/src/social-providers/vk.ts +125 -0
  92. package/src/social-providers/zoom.ts +233 -0
  93. package/src/types/context.ts +270 -0
  94. package/src/types/cookie.ts +8 -0
  95. package/src/types/index.ts +21 -1
  96. package/src/types/init-options.ts +1328 -68
  97. package/src/types/plugin-client.ts +117 -0
  98. package/src/types/plugin.ts +158 -0
  99. package/src/utils/error-codes.ts +51 -0
  100. package/src/utils/index.ts +1 -0
  101. package/tsconfig.json +2 -5
  102. package/tsdown.config.ts +20 -0
  103. package/vitest.config.ts +3 -0
  104. package/build.config.ts +0 -19
  105. package/dist/async_hooks/index.cjs +0 -27
  106. package/dist/async_hooks/index.d.cts +0 -10
  107. package/dist/async_hooks/index.d.ts +0 -10
  108. package/dist/db/adapter/index.cjs +0 -2
  109. package/dist/db/adapter/index.d.cts +0 -23
  110. package/dist/db/adapter/index.d.ts +0 -23
  111. package/dist/db/index.cjs +0 -91
  112. package/dist/db/index.d.cts +0 -127
  113. package/dist/db/index.d.ts +0 -127
  114. package/dist/env/index.cjs +0 -315
  115. package/dist/env/index.d.cts +0 -85
  116. package/dist/env/index.d.ts +0 -85
  117. package/dist/index.cjs +0 -2
  118. package/dist/index.d.cts +0 -115
  119. package/dist/index.d.ts +0 -115
  120. package/dist/oauth2/index.cjs +0 -368
  121. package/dist/oauth2/index.d.cts +0 -277
  122. package/dist/oauth2/index.d.ts +0 -277
  123. package/dist/shared/core.DeNN5HMO.d.cts +0 -143
  124. package/dist/shared/core.DeNN5HMO.d.mts +0 -143
  125. package/dist/shared/core.DeNN5HMO.d.ts +0 -143
@@ -1,35 +1,42 @@
1
1
 
2
- > @better-auth/core@1.4.0-beta.8 build /home/runner/work/better-auth/better-auth/packages/core
3
- > unbuild --clean
4
-
5
- [info] Building core
6
- [info] Cleaning dist directory: `./dist`
7
- Generated an empty chunk: "index".
8
- Generated an empty chunk: "db/adapter/index".
9
- Generated an empty chunk: "index".
10
- Generated an empty chunk: "db/adapter/index".
11
- [success] Build succeeded for core
12
- [log] dist/index.cjs (total size: 15 B, chunk size: 15 B)
13
-
14
- [log] dist/async_hooks/index.cjs (total size: 922 B, chunk size: 922 B, exports: getAsyncLocalStorage)
15
-
16
- [log] dist/env/index.cjs (total size: 8.71 kB, chunk size: 8.71 kB, exports: ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog)
17
-
18
- [log] dist/oauth2/index.cjs (total size: 10.3 kB, chunk size: 10.3 kB, exports: clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken)
19
-
20
- [log] dist/db/index.cjs (total size: 2.43 kB, chunk size: 2.43 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
21
-
22
- [log] dist/db/adapter/index.cjs (total size: 15 B, chunk size: 15 B)
23
- [log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
24
-
25
- [log] dist/async_hooks/index.mjs (total size: 887 B, chunk size: 887 B, exports: getAsyncLocalStorage)
26
-
27
- [log] dist/env/index.mjs (total size: 8.42 kB, chunk size: 8.42 kB, exports: ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog)
28
-
29
- [log] dist/oauth2/index.mjs (total size: 9.88 kB, chunk size: 9.88 kB, exports: clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken)
30
-
31
- [log] dist/db/index.mjs (total size: 1.67 kB, chunk size: 1.67 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
32
-
33
- [log] dist/db/adapter/index.mjs (total size: 1 B, chunk size: 1 B)
34
- Σ Total dist size (byte size): 119 kB
35
- [log]
2
+ > @better-auth/core@1.4.0 build /home/runner/work/better-auth/better-auth/packages/core
3
+ > tsdown
4
+
5
+ ℹ tsdown v0.16.5 powered by rolldown v1.0.0-beta.50
6
+ ℹ Using tsdown config: /home/runner/work/better-auth/better-auth/packages/core/tsdown.config.ts
7
+ ℹ entry: src/index.ts, src/db/index.ts, src/db/adapter/index.ts, src/async_hooks/index.ts, src/context/index.ts, src/env/index.ts, src/oauth2/index.ts, src/api/index.ts, src/social-providers/index.ts, src/utils/index.ts, src/error/index.ts
8
+ ℹ tsconfig: tsconfig.json
9
+ ℹ Build start
10
+ ℹ dist/social-providers/index.mjs  78.21 kB │ gzip: 10.17 kB
11
+ ℹ dist/db/index.mjs  1.58 kB │ gzip: 0.49 kB
12
+ ℹ dist/api/index.mjs  0.83 kB │ gzip: 0.40 kB
13
+ ℹ dist/context/index.mjs  0.74 kB │ gzip: 0.27 kB
14
+ ℹ dist/oauth2/index.mjs  0.61 kB │ gzip: 0.24 kB
15
+ ℹ dist/env/index.mjs  0.44 kB │ gzip: 0.25 kB
16
+ ℹ dist/error/index.mjs  0.16 kB │ gzip: 0.13 kB
17
+ ℹ dist/async_hooks/index.mjs  0.11 kB │ gzip: 0.10 kB
18
+ ℹ dist/utils/index.mjs  0.09 kB │ gzip: 0.09 kB
19
+ ℹ dist/db/adapter/index.mjs  0.01 kB │ gzip: 0.03 kB
20
+ ℹ dist/index.mjs  0.01 kB │ gzip: 0.03 kB
21
+ ℹ dist/oauth2-DmgZmPEg.mjs  9.17 kB │ gzip: 2.13 kB
22
+ ℹ dist/env-DwlNAN_D.mjs  7.67 kB │ gzip: 2.54 kB
23
+ ℹ dist/context-DgQ9XGBl.mjs  3.89 kB │ gzip: 1.00 kB
24
+ ℹ dist/error-BhAKg8LX.mjs  1.77 kB │ gzip: 0.79 kB
25
+ ℹ dist/async_hooks-BfRfbd1J.mjs  0.87 kB │ gzip: 0.46 kB
26
+ ℹ dist/utils-C5EN75oV.mjs  0.13 kB │ gzip: 0.12 kB
27
+ ℹ dist/social-providers/index.d.mts  3.78 kB │ gzip: 1.16 kB
28
+ ℹ dist/context/index.d.mts  3.05 kB │ gzip: 0.96 kB
29
+ ℹ dist/error/index.d.mts  1.84 kB │ gzip: 0.72 kB
30
+ ℹ dist/db/index.d.mts  1.01 kB │ gzip: 0.38 kB
31
+ ℹ dist/index.d.mts  0.87 kB │ gzip: 0.34 kB
32
+ ℹ dist/utils/index.d.mts  0.84 kB │ gzip: 0.43 kB
33
+ ℹ dist/oauth2/index.d.mts  0.79 kB │ gzip: 0.30 kB
34
+ ℹ dist/env/index.d.mts  0.59 kB │ gzip: 0.30 kB
35
+ ℹ dist/db/adapter/index.d.mts  0.53 kB │ gzip: 0.24 kB
36
+ ℹ dist/api/index.d.mts  0.29 kB │ gzip: 0.16 kB
37
+ ℹ dist/async_hooks/index.d.mts  0.14 kB │ gzip: 0.10 kB
38
+ ℹ dist/index-CkAWdKH8.d.mts 205.84 kB │ gzip: 32.50 kB
39
+ ℹ dist/index-CdubV7uy.d.mts  3.31 kB │ gzip: 1.11 kB
40
+ ℹ dist/index-DgwIISs7.d.mts  0.24 kB │ gzip: 0.16 kB
41
+ ℹ 31 files, total: 329.43 kB
42
+ ✔ Build complete in 4482ms
@@ -0,0 +1,3 @@
1
+ import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-CkAWdKH8.mjs";
2
+ import "../index-CdubV7uy.mjs";
3
+ export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -0,0 +1,26 @@
1
+ import "../async_hooks-BfRfbd1J.mjs";
2
+ import { f as runWithEndpointContext } from "../context-DgQ9XGBl.mjs";
3
+ import { createEndpoint, createMiddleware } from "better-call";
4
+
5
+ //#region src/api/index.ts
6
+ const optionsMiddleware = createMiddleware(async () => {
7
+ /**
8
+ * This will be passed on the instance of
9
+ * the context. Used to infer the type
10
+ * here.
11
+ */
12
+ return {};
13
+ });
14
+ const createAuthMiddleware = createMiddleware.create({ use: [optionsMiddleware, createMiddleware(async () => {
15
+ return {};
16
+ })] });
17
+ const use = [optionsMiddleware];
18
+ const createAuthEndpoint = (path, options, handler) => {
19
+ return createEndpoint(path, {
20
+ ...options,
21
+ use: [...options?.use || [], ...use]
22
+ }, async (ctx) => runWithEndpointContext(ctx, () => handler(ctx)));
23
+ };
24
+
25
+ //#endregion
26
+ export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -1,10 +1,2 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- export { AsyncLocalStorage } from 'node:async_hooks';
3
-
4
- /**
5
- * AsyncLocalStorage will be import directly in 1.5.x
6
- */
7
-
8
- declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
9
-
10
- export { getAsyncLocalStorage };
1
+ import { n as getAsyncLocalStorage, t as AsyncLocalStorage } from "../index-DgwIISs7.mjs";
2
+ export { AsyncLocalStorage, getAsyncLocalStorage };
@@ -1,25 +1,3 @@
1
- let moduleName = "node:async_hooks";
2
- const AsyncLocalStoragePromise = import(
3
- /* @vite-ignore */
4
- /* webpackIgnore: true */
5
- moduleName
6
- ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
- if ("AsyncLocalStorage" in globalThis) {
8
- return globalThis.AsyncLocalStorage;
9
- }
10
- console.warn(
11
- "[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected."
12
- );
13
- console.warn(
14
- "[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler"
15
- );
16
- console.warn(
17
- "[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag"
18
- );
19
- throw err;
20
- });
21
- async function getAsyncLocalStorage() {
22
- return AsyncLocalStoragePromise;
23
- }
1
+ import { t as getAsyncLocalStorage } from "../async_hooks-BfRfbd1J.mjs";
24
2
 
25
- export { getAsyncLocalStorage };
3
+ export { getAsyncLocalStorage };
@@ -0,0 +1,18 @@
1
+ //#region src/async_hooks/index.ts
2
+ const AsyncLocalStoragePromise = import(
3
+ /* @vite-ignore */
4
+ /* webpackIgnore: true */
5
+ "node:async_hooks"
6
+ ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
+ if ("AsyncLocalStorage" in globalThis) return globalThis.AsyncLocalStorage;
8
+ console.warn("[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.");
9
+ console.warn("[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler");
10
+ console.warn("[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag");
11
+ throw err;
12
+ });
13
+ async function getAsyncLocalStorage() {
14
+ return AsyncLocalStoragePromise;
15
+ }
16
+
17
+ //#endregion
18
+ export { getAsyncLocalStorage as t };
@@ -0,0 +1,54 @@
1
+ import { Wn as DBAdapter, Yn as DBTransactionAdapter, f as AuthContext } from "../index-CkAWdKH8.mjs";
2
+ import "../index-CdubV7uy.mjs";
3
+ import { t as AsyncLocalStorage } from "../index-DgwIISs7.mjs";
4
+ import { EndpointContext, InputContext } from "better-call";
5
+
6
+ //#region src/context/endpoint-context.d.ts
7
+ type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
8
+ context: AuthContext;
9
+ };
10
+ /**
11
+ * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
12
+ *
13
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
14
+ */
15
+ declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalStorage<AuthEndpointContext>>;
16
+ declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
17
+ declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
18
+ //#endregion
19
+ //#region src/context/request-state.d.ts
20
+ type RequestStateWeakMap = WeakMap<object, any>;
21
+ declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
22
+ declare function hasRequestState(): Promise<boolean>;
23
+ declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
24
+ declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
25
+ interface RequestState<T> {
26
+ get(): Promise<T>;
27
+ set(value: T): Promise<void>;
28
+ readonly ref: Readonly<object>;
29
+ }
30
+ /**
31
+ * Defines a request-scoped state with lazy initialization.
32
+ *
33
+ * @param initFn - A function that initializes the state. It is called the first time `get()` is invoked within each request context, and only once per context.
34
+ * @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.
35
+ *
36
+ * @example
37
+ * const userState = defineRequestState(() => ({ id: '', name: '' }));
38
+ * // Later, within a request context:
39
+ * const user = await userState.get();
40
+ */
41
+ declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
42
+ //#endregion
43
+ //#region src/context/transaction.d.ts
44
+ /**
45
+ * This is for internal use only. Most users should use `getCurrentAdapter` instead.
46
+ *
47
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
48
+ */
49
+ declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<DBTransactionAdapter>>;
50
+ declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBTransactionAdapter>;
51
+ declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
52
+ declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
53
+ //#endregion
54
+ export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -0,0 +1,4 @@
1
+ import "../async_hooks-BfRfbd1J.mjs";
2
+ import { a as defineRequestState, c as hasRequestState, d as getCurrentAuthContextAsyncLocalStorage, f as runWithEndpointContext, i as runWithTransaction, l as runWithRequestState, n as getCurrentDBAdapterAsyncLocalStorage, o as getCurrentRequestState, r as runWithAdapter, s as getRequestStateAsyncLocalStorage, t as getCurrentAdapter, u as getCurrentAuthContext } from "../context-DgQ9XGBl.mjs";
3
+
4
+ export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -0,0 +1,114 @@
1
+ import { t as getAsyncLocalStorage } from "./async_hooks-BfRfbd1J.mjs";
2
+
3
+ //#region src/context/endpoint-context.ts
4
+ let currentContextAsyncStorage = null;
5
+ const ensureAsyncStorage$2 = async () => {
6
+ if (!currentContextAsyncStorage) currentContextAsyncStorage = new (await (getAsyncLocalStorage()))();
7
+ return currentContextAsyncStorage;
8
+ };
9
+ /**
10
+ * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
11
+ *
12
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
13
+ */
14
+ async function getCurrentAuthContextAsyncLocalStorage() {
15
+ return ensureAsyncStorage$2();
16
+ }
17
+ async function getCurrentAuthContext() {
18
+ const context = (await ensureAsyncStorage$2()).getStore();
19
+ if (!context) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
20
+ return context;
21
+ }
22
+ async function runWithEndpointContext(context, fn) {
23
+ return (await ensureAsyncStorage$2()).run(context, fn);
24
+ }
25
+
26
+ //#endregion
27
+ //#region src/context/request-state.ts
28
+ let requestStateAsyncStorage = null;
29
+ const ensureAsyncStorage$1 = async () => {
30
+ if (!requestStateAsyncStorage) requestStateAsyncStorage = new (await (getAsyncLocalStorage()))();
31
+ return requestStateAsyncStorage;
32
+ };
33
+ async function getRequestStateAsyncLocalStorage() {
34
+ return ensureAsyncStorage$1();
35
+ }
36
+ async function hasRequestState() {
37
+ return (await ensureAsyncStorage$1()).getStore() !== void 0;
38
+ }
39
+ async function getCurrentRequestState() {
40
+ const store = (await ensureAsyncStorage$1()).getStore();
41
+ if (!store) throw new Error("No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.");
42
+ return store;
43
+ }
44
+ async function runWithRequestState(store, fn) {
45
+ return (await ensureAsyncStorage$1()).run(store, fn);
46
+ }
47
+ function defineRequestState(initFn) {
48
+ const ref = Object.freeze({});
49
+ return {
50
+ get ref() {
51
+ return ref;
52
+ },
53
+ async get() {
54
+ const store = await getCurrentRequestState();
55
+ if (!store.has(ref)) {
56
+ const initialValue = await initFn();
57
+ store.set(ref, initialValue);
58
+ return initialValue;
59
+ }
60
+ return store.get(ref);
61
+ },
62
+ async set(value) {
63
+ (await getCurrentRequestState()).set(ref, value);
64
+ }
65
+ };
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/context/transaction.ts
70
+ let currentAdapterAsyncStorage = null;
71
+ const ensureAsyncStorage = async () => {
72
+ if (!currentAdapterAsyncStorage) currentAdapterAsyncStorage = new (await (getAsyncLocalStorage()))();
73
+ return currentAdapterAsyncStorage;
74
+ };
75
+ /**
76
+ * This is for internal use only. Most users should use `getCurrentAdapter` instead.
77
+ *
78
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
79
+ */
80
+ const getCurrentDBAdapterAsyncLocalStorage = async () => {
81
+ return ensureAsyncStorage();
82
+ };
83
+ const getCurrentAdapter = async (fallback) => {
84
+ return ensureAsyncStorage().then((als) => {
85
+ return als.getStore() || fallback;
86
+ }).catch(() => {
87
+ return fallback;
88
+ });
89
+ };
90
+ const runWithAdapter = async (adapter, fn) => {
91
+ let called = true;
92
+ return ensureAsyncStorage().then((als) => {
93
+ called = true;
94
+ return als.run(adapter, fn);
95
+ }).catch((err) => {
96
+ if (!called) return fn();
97
+ throw err;
98
+ });
99
+ };
100
+ const runWithTransaction = async (adapter, fn) => {
101
+ let called = true;
102
+ return ensureAsyncStorage().then((als) => {
103
+ called = true;
104
+ return adapter.transaction(async (trx) => {
105
+ return als.run(trx, fn);
106
+ });
107
+ }).catch((err) => {
108
+ if (!called) return fn();
109
+ throw err;
110
+ });
111
+ };
112
+
113
+ //#endregion
114
+ export { defineRequestState as a, hasRequestState as c, getCurrentAuthContextAsyncLocalStorage as d, runWithEndpointContext as f, runWithTransaction as i, runWithRequestState as l, getCurrentDBAdapterAsyncLocalStorage as n, getCurrentRequestState as o, runWithAdapter as r, getRequestStateAsyncLocalStorage as s, getCurrentAdapter as t, getCurrentAuthContext as u };
@@ -1,23 +1,3 @@
1
- type DBAdapterDebugLogOption = boolean | {
2
- /**
3
- * Useful when you want to log only certain conditions.
4
- */
5
- logCondition?: (() => boolean) | undefined;
6
- create?: boolean;
7
- update?: boolean;
8
- updateMany?: boolean;
9
- findOne?: boolean;
10
- findMany?: boolean;
11
- delete?: boolean;
12
- deleteMany?: boolean;
13
- count?: boolean;
14
- } | {
15
- /**
16
- * Only used for adapter tests to show debug logs if a test fails.
17
- *
18
- * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
19
- */
20
- isRunningAdapterTests: boolean;
21
- };
22
-
23
- export type { DBAdapterDebugLogOption };
1
+ import { Gn as DBAdapterDebugLogOption, Hn as CleanedWhere, Jn as DBAdapterSchemaCreation, Kn as DBAdapterFactoryConfig, Qn as Where, Un as CustomAdapter, Wn as DBAdapter, Xn as JoinConfig, Yn as DBTransactionAdapter, Zn as JoinOption, qn as DBAdapterInstance } from "../../index-CkAWdKH8.mjs";
2
+ import "../../index-CdubV7uy.mjs";
3
+ export { CleanedWhere, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where };
@@ -1 +1 @@
1
-
1
+ export { };
@@ -1,127 +1,3 @@
1
- import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.DeNN5HMO.mjs';
2
- export { S as SecondaryStorage } from '../shared/core.DeNN5HMO.mjs';
3
- import * as z from 'zod';
4
-
5
- type BetterAuthPluginDBSchema = {
6
- [table in string]: {
7
- fields: {
8
- [field in string]: DBFieldAttribute;
9
- };
10
- disableMigration?: boolean;
11
- modelName?: string;
12
- };
13
- };
14
-
15
- declare const coreSchema: z.ZodObject<{
16
- id: z.ZodString;
17
- createdAt: z.ZodDefault<z.ZodDate>;
18
- updatedAt: z.ZodDefault<z.ZodDate>;
19
- }, z.core.$strip>;
20
-
21
- declare const userSchema: z.ZodObject<{
22
- id: z.ZodString;
23
- createdAt: z.ZodDefault<z.ZodDate>;
24
- updatedAt: z.ZodDefault<z.ZodDate>;
25
- email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
26
- emailVerified: z.ZodDefault<z.ZodBoolean>;
27
- name: z.ZodString;
28
- image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
- }, z.core.$strip>;
30
- /**
31
- * User schema type used by better-auth, note that it's possible that user could have additional fields
32
- *
33
- * todo: we should use generics to extend this type with additional fields from plugins and options in the future
34
- */
35
- type User = z.infer<typeof userSchema>;
36
-
37
- declare const accountSchema: z.ZodObject<{
38
- id: z.ZodString;
39
- createdAt: z.ZodDefault<z.ZodDate>;
40
- updatedAt: z.ZodDefault<z.ZodDate>;
41
- providerId: z.ZodString;
42
- accountId: z.ZodString;
43
- userId: z.ZodCoercedString<unknown>;
44
- accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
- refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
- idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
- accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
48
- refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
49
- scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
- password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
- }, z.core.$strip>;
52
- /**
53
- * Account schema type used by better-auth, note that it's possible that account could have additional fields
54
- *
55
- * todo: we should use generics to extend this type with additional fields from plugins and options in the future
56
- */
57
- type Account = z.infer<typeof accountSchema>;
58
-
59
- declare const sessionSchema: z.ZodObject<{
60
- id: z.ZodString;
61
- createdAt: z.ZodDefault<z.ZodDate>;
62
- updatedAt: z.ZodDefault<z.ZodDate>;
63
- userId: z.ZodCoercedString<unknown>;
64
- expiresAt: z.ZodDate;
65
- token: z.ZodString;
66
- ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
67
- userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
- }, z.core.$strip>;
69
- /**
70
- * Session schema type used by better-auth, note that it's possible that session could have additional fields
71
- *
72
- * todo: we should use generics to extend this type with additional fields from plugins and options in the future
73
- */
74
- type Session = z.infer<typeof sessionSchema>;
75
-
76
- declare const verificationSchema: z.ZodObject<{
77
- id: z.ZodString;
78
- createdAt: z.ZodDefault<z.ZodDate>;
79
- updatedAt: z.ZodDefault<z.ZodDate>;
80
- value: z.ZodString;
81
- expiresAt: z.ZodDate;
82
- identifier: z.ZodString;
83
- }, z.core.$strip>;
84
- /**
85
- * Verification schema type used by better-auth, note that it's possible that verification could have additional fields
86
- *
87
- * todo: we should use generics to extend this type with additional fields from plugins and options in the future
88
- */
89
- type Verification = z.infer<typeof verificationSchema>;
90
-
91
- declare const rateLimitSchema: z.ZodObject<{
92
- key: z.ZodString;
93
- count: z.ZodNumber;
94
- lastRequest: z.ZodNumber;
95
- }, z.core.$strip>;
96
- /**
97
- * Rate limit schema type used by better-auth for rate limiting
98
- */
99
- type RateLimit = z.infer<typeof rateLimitSchema>;
100
-
101
- /**
102
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
103
- */
104
- type AuthPluginSchema = BetterAuthPluginDBSchema;
105
- /**
106
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
107
- */
108
- type FieldAttribute = DBFieldAttribute;
109
- /**
110
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
111
- */
112
- type FieldAttributeConfig = DBFieldAttributeConfig;
113
- /**
114
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
115
- */
116
- type FieldType = DBFieldType;
117
- /**
118
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
119
- */
120
- type Primitive = DBPrimitive;
121
- /**
122
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
123
- */
124
- type BetterAuthDbSchema = BetterAuthDBSchema;
125
-
126
- export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
127
- export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, RateLimit, Session, User, Verification };
1
+ import { $n as AuthPluginSchema, Cr as SecondaryStorage, Sr as DBPrimitive, _r as BetterAuthDBSchema, ar as Verification, br as DBFieldType, cr as userSchema, dr as sessionSchema, er as BetterAuthDbSchema, fr as RateLimit, gr as BetterAuthPluginDBSchema, hr as accountSchema, ir as Primitive, lr as coreSchema, mr as Account, nr as FieldAttributeConfig, or as verificationSchema, pr as rateLimitSchema, rr as FieldType, sr as User, tr as FieldAttribute, ur as Session, vr as DBFieldAttribute, xr as DBPreservedModels, yr as DBFieldAttributeConfig } from "../index-CkAWdKH8.mjs";
2
+ import "../index-CdubV7uy.mjs";
3
+ export { Account, AuthPluginSchema, BetterAuthDBSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPreservedModels, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
package/dist/db/index.mjs CHANGED
@@ -1,70 +1,61 @@
1
- import * as z from 'zod';
1
+ import * as z from "zod";
2
2
 
3
+ //#region src/db/schema/shared.ts
3
4
  const coreSchema = z.object({
4
- id: z.string(),
5
- createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
6
- updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
5
+ id: z.string(),
6
+ createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
7
+ updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
7
8
  });
8
9
 
9
- const userSchema = coreSchema.extend({
10
- email: z.string().transform((val) => val.toLowerCase()),
11
- emailVerified: z.boolean().default(false),
12
- name: z.string(),
13
- image: z.string().nullish()
10
+ //#endregion
11
+ //#region src/db/schema/account.ts
12
+ const accountSchema = coreSchema.extend({
13
+ providerId: z.string(),
14
+ accountId: z.string(),
15
+ userId: z.coerce.string(),
16
+ accessToken: z.string().nullish(),
17
+ refreshToken: z.string().nullish(),
18
+ idToken: z.string().nullish(),
19
+ accessTokenExpiresAt: z.date().nullish(),
20
+ refreshTokenExpiresAt: z.date().nullish(),
21
+ scope: z.string().nullish(),
22
+ password: z.string().nullish()
14
23
  });
15
24
 
16
- const accountSchema = coreSchema.extend({
17
- providerId: z.string(),
18
- accountId: z.string(),
19
- userId: z.coerce.string(),
20
- accessToken: z.string().nullish(),
21
- refreshToken: z.string().nullish(),
22
- idToken: z.string().nullish(),
23
- /**
24
- * Access token expires at
25
- */
26
- accessTokenExpiresAt: z.date().nullish(),
27
- /**
28
- * Refresh token expires at
29
- */
30
- refreshTokenExpiresAt: z.date().nullish(),
31
- /**
32
- * The scopes that the user has authorized
33
- */
34
- scope: z.string().nullish(),
35
- /**
36
- * Password is only stored in the credential provider
37
- */
38
- password: z.string().nullish()
25
+ //#endregion
26
+ //#region src/db/schema/rate-limit.ts
27
+ const rateLimitSchema = z.object({
28
+ key: z.string(),
29
+ count: z.number(),
30
+ lastRequest: z.number()
39
31
  });
40
32
 
33
+ //#endregion
34
+ //#region src/db/schema/session.ts
41
35
  const sessionSchema = coreSchema.extend({
42
- userId: z.coerce.string(),
43
- expiresAt: z.date(),
44
- token: z.string(),
45
- ipAddress: z.string().nullish(),
46
- userAgent: z.string().nullish()
36
+ userId: z.coerce.string(),
37
+ expiresAt: z.date(),
38
+ token: z.string(),
39
+ ipAddress: z.string().nullish(),
40
+ userAgent: z.string().nullish()
47
41
  });
48
42
 
49
- const verificationSchema = coreSchema.extend({
50
- value: z.string(),
51
- expiresAt: z.date(),
52
- identifier: z.string()
43
+ //#endregion
44
+ //#region src/db/schema/user.ts
45
+ const userSchema = coreSchema.extend({
46
+ email: z.string().transform((val) => val.toLowerCase()),
47
+ emailVerified: z.boolean().default(false),
48
+ name: z.string(),
49
+ image: z.string().nullish()
53
50
  });
54
51
 
55
- const rateLimitSchema = z.object({
56
- /**
57
- * The key to use for rate limiting
58
- */
59
- key: z.string(),
60
- /**
61
- * The number of requests made
62
- */
63
- count: z.number(),
64
- /**
65
- * The last request time in milliseconds
66
- */
67
- lastRequest: z.number()
52
+ //#endregion
53
+ //#region src/db/schema/verification.ts
54
+ const verificationSchema = coreSchema.extend({
55
+ value: z.string(),
56
+ expiresAt: z.date(),
57
+ identifier: z.string()
68
58
  });
69
59
 
70
- export { accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
60
+ //#endregion
61
+ export { accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };