@better-auth/core 1.4.0-beta.9 → 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 (151) hide show
  1. package/.turbo/turbo-build.log +41 -76
  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 -14
  11. package/dist/db/adapter/index.mjs +1 -1
  12. package/dist/db/index.d.mts +3 -39
  13. package/dist/db/index.mjs +46 -55
  14. package/dist/env/index.d.mts +2 -36
  15. package/dist/env/index.mjs +2 -299
  16. package/dist/env-DwlNAN_D.mjs +245 -0
  17. package/dist/error/index.d.mts +31 -29
  18. package/dist/error/index.mjs +3 -40
  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 -180
  24. package/dist/index.mjs +1 -1
  25. package/dist/oauth2/index.d.mts +3 -99
  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 -3903
  29. package/dist/social-providers/index.mjs +2434 -2654
  30. package/dist/utils/index.d.mts +5 -6
  31. package/dist/utils/index.mjs +2 -4
  32. package/dist/utils-C5EN75oV.mjs +7 -0
  33. package/package.json +70 -111
  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 +215 -129
  42. package/src/db/index.ts +12 -13
  43. package/src/db/plugin.ts +3 -3
  44. package/src/db/type.ts +54 -42
  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 +1 -1
  51. package/src/error/index.ts +1 -1
  52. package/src/oauth2/client-credentials-token.ts +9 -9
  53. package/src/oauth2/create-authorization-url.ts +12 -12
  54. package/src/oauth2/index.ts +10 -11
  55. package/src/oauth2/oauth-provider.ts +96 -74
  56. package/src/oauth2/refresh-access-token.ts +12 -12
  57. package/src/oauth2/utils.ts +2 -0
  58. package/src/oauth2/validate-authorization-code.ts +13 -15
  59. package/src/social-providers/apple.ts +8 -8
  60. package/src/social-providers/atlassian.ts +21 -19
  61. package/src/social-providers/cognito.ts +15 -15
  62. package/src/social-providers/discord.ts +8 -11
  63. package/src/social-providers/dropbox.ts +5 -5
  64. package/src/social-providers/facebook.ts +12 -10
  65. package/src/social-providers/figma.ts +6 -6
  66. package/src/social-providers/github.ts +4 -4
  67. package/src/social-providers/gitlab.ts +13 -10
  68. package/src/social-providers/google.ts +13 -13
  69. package/src/social-providers/huggingface.ts +27 -25
  70. package/src/social-providers/index.ts +30 -24
  71. package/src/social-providers/kakao.ts +41 -41
  72. package/src/social-providers/kick.ts +7 -9
  73. package/src/social-providers/line.ts +12 -12
  74. package/src/social-providers/linear.ts +9 -8
  75. package/src/social-providers/linkedin.ts +5 -5
  76. package/src/social-providers/microsoft-entra-id.ts +31 -15
  77. package/src/social-providers/naver.ts +5 -5
  78. package/src/social-providers/notion.ts +11 -9
  79. package/src/social-providers/paybin.ts +122 -0
  80. package/src/social-providers/paypal.ts +31 -29
  81. package/src/social-providers/polar.ts +110 -0
  82. package/src/social-providers/reddit.ts +6 -6
  83. package/src/social-providers/roblox.ts +15 -14
  84. package/src/social-providers/salesforce.ts +20 -18
  85. package/src/social-providers/slack.ts +4 -7
  86. package/src/social-providers/spotify.ts +5 -5
  87. package/src/social-providers/tiktok.ts +32 -33
  88. package/src/social-providers/twitch.ts +8 -8
  89. package/src/social-providers/twitter.ts +49 -45
  90. package/src/social-providers/vk.ts +14 -17
  91. package/src/social-providers/zoom.ts +29 -14
  92. package/src/types/context.ts +67 -67
  93. package/src/types/cookie.ts +1 -0
  94. package/src/types/index.ts +13 -11
  95. package/src/types/init-options.ts +1134 -911
  96. package/src/types/plugin-client.ts +61 -13
  97. package/src/types/plugin.ts +81 -57
  98. package/tsconfig.json +2 -5
  99. package/{build.config.ts → tsdown.config.ts} +8 -11
  100. package/vitest.config.ts +3 -0
  101. package/dist/async_hooks/index.cjs +0 -27
  102. package/dist/async_hooks/index.d.cts +0 -10
  103. package/dist/async_hooks/index.d.ts +0 -10
  104. package/dist/db/adapter/index.cjs +0 -2
  105. package/dist/db/adapter/index.d.cts +0 -14
  106. package/dist/db/adapter/index.d.ts +0 -14
  107. package/dist/db/index.cjs +0 -91
  108. package/dist/db/index.d.cts +0 -39
  109. package/dist/db/index.d.ts +0 -39
  110. package/dist/env/index.cjs +0 -315
  111. package/dist/env/index.d.cts +0 -36
  112. package/dist/env/index.d.ts +0 -36
  113. package/dist/error/index.cjs +0 -44
  114. package/dist/error/index.d.cts +0 -33
  115. package/dist/error/index.d.ts +0 -33
  116. package/dist/index.cjs +0 -2
  117. package/dist/index.d.cts +0 -180
  118. package/dist/index.d.ts +0 -180
  119. package/dist/middleware/index.cjs +0 -25
  120. package/dist/middleware/index.d.cts +0 -14
  121. package/dist/middleware/index.d.mts +0 -14
  122. package/dist/middleware/index.d.ts +0 -14
  123. package/dist/middleware/index.mjs +0 -21
  124. package/dist/oauth2/index.cjs +0 -368
  125. package/dist/oauth2/index.d.cts +0 -99
  126. package/dist/oauth2/index.d.ts +0 -99
  127. package/dist/shared/core.2rWMW9q9.d.ts +0 -13
  128. package/dist/shared/core.40VTWh-p.d.cts +0 -217
  129. package/dist/shared/core.BfcVdsSf.d.cts +0 -181
  130. package/dist/shared/core.Bisb2Bdk.d.mts +0 -181
  131. package/dist/shared/core.BwoNUcJQ.d.cts +0 -53
  132. package/dist/shared/core.BwoNUcJQ.d.mts +0 -53
  133. package/dist/shared/core.BwoNUcJQ.d.ts +0 -53
  134. package/dist/shared/core.CErFRCOZ.d.mts +0 -1684
  135. package/dist/shared/core.CGN6D-Mh.d.ts +0 -181
  136. package/dist/shared/core.CPuIItYE.d.ts +0 -217
  137. package/dist/shared/core.CftpHMDz.d.cts +0 -13
  138. package/dist/shared/core.Db7zJyxf.d.ts +0 -1684
  139. package/dist/shared/core.DqaxObkf.d.cts +0 -1684
  140. package/dist/shared/core.MjcDoj7R.d.cts +0 -5
  141. package/dist/shared/core.MjcDoj7R.d.mts +0 -5
  142. package/dist/shared/core.MjcDoj7R.d.ts +0 -5
  143. package/dist/shared/core.g2ZbxAEV.d.mts +0 -217
  144. package/dist/shared/core.g9ACQ8v2.d.mts +0 -13
  145. package/dist/social-providers/index.cjs +0 -2793
  146. package/dist/social-providers/index.d.cts +0 -3903
  147. package/dist/social-providers/index.d.ts +0 -3903
  148. package/dist/utils/index.cjs +0 -7
  149. package/dist/utils/index.d.cts +0 -10
  150. package/dist/utils/index.d.ts +0 -10
  151. package/src/middleware/index.ts +0 -33
@@ -1,77 +1,42 @@
1
1
 
2
- > @better-auth/core@1.4.0-beta.9 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
- "node:sqlite" is imported by "src/types/init-options.ts", but could not be resolved – treating it as an external dependency.
12
- "bun:sqlite" is imported by "src/types/init-options.ts", but could not be resolved – treating it as an external dependency.
13
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
14
- Either change the import in "src/oauth2/create-authorization-url.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
15
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
16
- Either change the import in "src/oauth2/validate-authorization-code.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
17
- Export "OAuthProvider" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
18
- Either change the import in "src/types/context.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
19
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
20
- Either change the import in "src/oauth2/create-authorization-url.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
21
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
22
- Either change the import in "src/oauth2/validate-authorization-code.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
23
- Export "OAuthProvider" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
24
- Either change the import in "src/types/context.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
25
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
26
- Either change the import in "src/oauth2/create-authorization-url.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
27
- Export "ProviderOptions" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
28
- Either change the import in "src/oauth2/validate-authorization-code.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
29
- Export "OAuthProvider" of module "src/oauth2/oauth-provider.ts" was reexported through module "src/oauth2/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
30
- Either change the import in "src/types/context.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
31
- [success] Build succeeded for core
32
- [log] dist/index.cjs (total size: 15 B, chunk size: 15 B)
33
-
34
- [log] dist/async_hooks/index.cjs (total size: 922 B, chunk size: 922 B, exports: getAsyncLocalStorage)
35
-
36
- [log] dist/middleware/index.cjs (total size: 610 B, chunk size: 610 B, exports: createAuthEndpoint, createAuthMiddleware, optionsMiddleware)
37
-
38
- [log] dist/utils/index.cjs (total size: 114 B, chunk size: 114 B, exports: defineErrorCodes)
39
-
40
- [log] dist/error/index.cjs (total size: 1.75 kB, chunk size: 1.75 kB, exports: BASE_ERROR_CODES, BetterAuthError)
41
-
42
- [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)
43
-
44
- [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)
45
-
46
- [log] dist/db/index.cjs (total size: 2.43 kB, chunk size: 2.43 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
47
-
48
- [log] dist/social-providers/index.cjs (total size: 87.9 kB, chunk size: 86.1 kB, exports: SocialProviderListEnum, apple, atlassian, cognito, discord, dropbox, facebook, figma, getApplePublicKey, getCognitoPublicKey, github, gitlab, google, huggingface, kakao, kick, line, linear, linkedin, microsoft, naver, notion, paypal, reddit, roblox, salesforce, slack, socialProviderList, socialProviders, spotify, tiktok, twitch, twitter, vk, zoom)
49
- └─ dist/error/index.cjs (1.75 kB)
50
-
51
- [log] dist/db/adapter/index.cjs (total size: 15 B, chunk size: 15 B)
52
- [log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
53
-
54
- [log] dist/async_hooks/index.mjs (total size: 887 B, chunk size: 887 B, exports: getAsyncLocalStorage)
55
-
56
- [log] dist/middleware/index.mjs (total size: 495 B, chunk size: 495 B, exports: createAuthEndpoint, createAuthMiddleware, optionsMiddleware)
57
-
58
- [log] dist/utils/index.mjs (total size: 83 B, chunk size: 83 B, exports: defineErrorCodes)
59
-
60
- [log] dist/error/index.mjs (total size: 1.7 kB, chunk size: 1.7 kB, exports: BASE_ERROR_CODES, BetterAuthError)
61
-
62
- [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)
63
-
64
- [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)
65
-
66
- [log] dist/db/index.mjs (total size: 1.67 kB, chunk size: 1.67 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
67
-
68
- [log] dist/social-providers/index.mjs (total size: 85.8 kB, chunk size: 84.1 kB, exports: SocialProviderListEnum, apple, atlassian, cognito, discord, dropbox, facebook, figma, getApplePublicKey, getCognitoPublicKey, github, gitlab, google, huggingface, kakao, kick, line, linear, linkedin, microsoft, naver, notion, paypal, reddit, roblox, salesforce, slack, socialProviderList, socialProviders, spotify, tiktok, twitch, twitter, vk, zoom)
69
- └─ dist/error/index.mjs (1.7 kB)
70
-
71
- [log] dist/db/adapter/index.mjs (total size: 1 B, chunk size: 1 B)
72
- Σ Total dist size (byte size): 859 kB
73
- [log]
74
- [warn] Build is done with some warnings:
75
-
76
- - Implicitly bundling "bun:sqlite"
77
- - Implicitly bundling "node:sqlite"
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,14 +1,3 @@
1
- import '../../shared/core.g2ZbxAEV.mjs';
2
- export { C as CleanedWhere, j as CustomAdapter, i as DBAdapter, D as DBAdapterDebugLogOption, g as DBAdapterFactoryConfig, k as DBAdapterInstance, f as DBAdapterSchemaCreation, h as DBTransactionAdapter, W as Where } from '../../shared/core.CErFRCOZ.mjs';
3
- import 'zod';
4
- import '../../shared/core.MjcDoj7R.mjs';
5
- import 'kysely';
6
- import 'better-sqlite3';
7
- import 'better-call';
8
- import 'bun:sqlite';
9
- import 'node:sqlite';
10
- import '../../social-providers/index.mjs';
11
- import '@better-auth/core/oauth2';
12
- import '../../shared/core.Bisb2Bdk.mjs';
13
- import '../../shared/core.BwoNUcJQ.mjs';
14
- import '@better-auth/core';
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,39 +1,3 @@
1
- import { D as DBFieldAttribute, a as DBFieldAttributeConfig, b as DBFieldType, c as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.g2ZbxAEV.mjs';
2
- export { A as Account, d as DBPreservedModels, R as RateLimit, S as SecondaryStorage, f as Session, U as User, V as Verification, e as accountSchema, r as rateLimitSchema, s as sessionSchema, u as userSchema, v as verificationSchema } from '../shared/core.g2ZbxAEV.mjs';
3
- import { B as BetterAuthPluginDBSchema } from '../shared/core.g9ACQ8v2.mjs';
4
- import * as z from 'zod';
5
- import '../shared/core.MjcDoj7R.mjs';
6
-
7
- declare const coreSchema: z.ZodObject<{
8
- id: z.ZodString;
9
- createdAt: z.ZodDefault<z.ZodDate>;
10
- updatedAt: z.ZodDefault<z.ZodDate>;
11
- }, z.core.$strip>;
12
-
13
- /**
14
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
15
- */
16
- type AuthPluginSchema = BetterAuthPluginDBSchema;
17
- /**
18
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
19
- */
20
- type FieldAttribute = DBFieldAttribute;
21
- /**
22
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
23
- */
24
- type FieldAttributeConfig = DBFieldAttributeConfig;
25
- /**
26
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
27
- */
28
- type FieldType = DBFieldType;
29
- /**
30
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
31
- */
32
- type Primitive = DBPrimitive;
33
- /**
34
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
35
- */
36
- type BetterAuthDbSchema = BetterAuthDBSchema;
37
-
38
- export { BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, coreSchema };
39
- export type { AuthPluginSchema, BetterAuthDbSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
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 };
@@ -1,36 +1,2 @@
1
- export { I as InternalLogger, d as LogHandlerParams, b as LogLevel, L as Logger, T as TTY_COLORS, c as createLogger, a as levels, l as logger, s as shouldPublishLog } from '../shared/core.BwoNUcJQ.mjs';
2
-
3
- type EnvObject = Record<string, string | undefined>;
4
- declare const env: EnvObject;
5
- declare const nodeENV: string;
6
- /** Detect if `NODE_ENV` environment variable is `production` */
7
- declare const isProduction: boolean;
8
- /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
9
- declare const isDevelopment: boolean;
10
- /** Detect if `NODE_ENV` environment variable is `test` */
11
- declare const isTest: () => boolean;
12
- /**
13
- * Get environment variable with fallback
14
- */
15
- declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
16
- /**
17
- * Get boolean environment variable
18
- */
19
- declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
20
- /**
21
- * Common environment variables used in Better Auth
22
- */
23
- declare const ENV: Readonly<{
24
- readonly BETTER_AUTH_SECRET: string;
25
- readonly AUTH_SECRET: string;
26
- readonly BETTER_AUTH_TELEMETRY: string;
27
- readonly BETTER_AUTH_TELEMETRY_ID: string;
28
- readonly NODE_ENV: string;
29
- readonly PACKAGE_VERSION: string;
30
- readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
31
- }>;
32
-
33
- declare function getColorDepth(): number;
34
-
35
- export { ENV, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
36
- export type { EnvObject };
1
+ import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-CdubV7uy.mjs";
2
+ export { ENV, EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };