@better-auth/core 1.5.0-beta.2 → 1.5.0-beta.20

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 (331) hide show
  1. package/LICENSE.md +15 -12
  2. package/README.md +17 -0
  3. package/dist/api/index.d.mts +280 -2
  4. package/dist/api/index.mjs +4 -2
  5. package/dist/api/index.mjs.map +1 -0
  6. package/dist/async_hooks/index.d.mts +2 -1
  7. package/dist/async_hooks/index.mjs +2 -1
  8. package/dist/async_hooks/index.mjs.map +1 -0
  9. package/dist/async_hooks/pure.index.d.mts +2 -1
  10. package/dist/async_hooks/pure.index.mjs +2 -1
  11. package/dist/async_hooks/pure.index.mjs.map +1 -0
  12. package/dist/context/endpoint-context.d.mts +20 -0
  13. package/dist/context/endpoint-context.mjs +32 -0
  14. package/dist/context/endpoint-context.mjs.map +1 -0
  15. package/dist/context/global.d.mts +7 -0
  16. package/dist/context/global.mjs +38 -0
  17. package/dist/context/global.mjs.map +1 -0
  18. package/dist/context/index.d.mts +5 -53
  19. package/dist/context/index.mjs +5 -2
  20. package/dist/context/request-state.d.mts +28 -0
  21. package/dist/context/request-state.mjs +50 -0
  22. package/dist/context/request-state.mjs.map +1 -0
  23. package/dist/context/transaction.d.mts +25 -0
  24. package/dist/context/transaction.mjs +96 -0
  25. package/dist/context/transaction.mjs.map +1 -0
  26. package/dist/db/adapter/factory.d.mts +20 -0
  27. package/dist/db/adapter/factory.mjs +725 -0
  28. package/dist/db/adapter/factory.mjs.map +1 -0
  29. package/dist/db/adapter/get-default-field-name.d.mts +19 -0
  30. package/dist/db/adapter/get-default-field-name.mjs +39 -0
  31. package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
  32. package/dist/db/adapter/get-default-model-name.d.mts +13 -0
  33. package/dist/db/adapter/get-default-model-name.mjs +33 -0
  34. package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
  35. package/dist/db/adapter/get-field-attributes.d.mts +30 -0
  36. package/dist/db/adapter/get-field-attributes.mjs +40 -0
  37. package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
  38. package/dist/db/adapter/get-field-name.d.mts +19 -0
  39. package/dist/db/adapter/get-field-name.mjs +34 -0
  40. package/dist/db/adapter/get-field-name.mjs.map +1 -0
  41. package/dist/db/adapter/get-id-field.d.mts +40 -0
  42. package/dist/db/adapter/get-id-field.mjs +68 -0
  43. package/dist/db/adapter/get-id-field.mjs.map +1 -0
  44. package/dist/db/adapter/get-model-name.d.mts +13 -0
  45. package/dist/db/adapter/get-model-name.mjs +24 -0
  46. package/dist/db/adapter/get-model-name.mjs.map +1 -0
  47. package/dist/db/adapter/index.d.mts +520 -2
  48. package/dist/db/adapter/index.mjs +27 -972
  49. package/dist/db/adapter/index.mjs.map +1 -0
  50. package/dist/db/adapter/types.d.mts +108 -0
  51. package/dist/db/adapter/utils.d.mts +8 -0
  52. package/dist/db/adapter/utils.mjs +39 -0
  53. package/dist/db/adapter/utils.mjs.map +1 -0
  54. package/dist/db/get-tables.d.mts +9 -0
  55. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +52 -39
  56. package/dist/db/get-tables.mjs.map +1 -0
  57. package/dist/db/index.d.mts +10 -2
  58. package/dist/db/index.mjs +7 -60
  59. package/dist/db/plugin.d.mts +13 -0
  60. package/dist/db/schema/account.d.mts +30 -0
  61. package/dist/db/schema/account.mjs +20 -0
  62. package/dist/db/schema/account.mjs.map +1 -0
  63. package/dist/db/schema/rate-limit.d.mts +20 -0
  64. package/dist/db/schema/rate-limit.mjs +12 -0
  65. package/dist/db/schema/rate-limit.mjs.map +1 -0
  66. package/dist/db/schema/session.d.mts +25 -0
  67. package/dist/db/schema/session.mjs +15 -0
  68. package/dist/db/schema/session.mjs.map +1 -0
  69. package/dist/db/schema/shared.d.mts +11 -0
  70. package/dist/db/schema/shared.mjs +12 -0
  71. package/dist/db/schema/shared.mjs.map +1 -0
  72. package/dist/db/schema/user.d.mts +24 -0
  73. package/dist/db/schema/user.mjs +14 -0
  74. package/dist/db/schema/user.mjs.map +1 -0
  75. package/dist/db/schema/verification.d.mts +23 -0
  76. package/dist/db/schema/verification.mjs +13 -0
  77. package/dist/db/schema/verification.mjs.map +1 -0
  78. package/dist/db/type.d.mts +169 -0
  79. package/dist/env/color-depth.d.mts +5 -0
  80. package/dist/env/color-depth.mjs +89 -0
  81. package/dist/env/color-depth.mjs.map +1 -0
  82. package/dist/env/env-impl.d.mts +33 -0
  83. package/dist/env/env-impl.mjs +83 -0
  84. package/dist/env/env-impl.mjs.map +1 -0
  85. package/dist/env/index.d.mts +4 -2
  86. package/dist/env/index.mjs +3 -1
  87. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +2 -35
  88. package/dist/env/logger.mjs +82 -0
  89. package/dist/env/logger.mjs.map +1 -0
  90. package/dist/error/codes.d.mts +69 -0
  91. package/dist/{error-C7mY-p0f.mjs → error/codes.mjs} +7 -30
  92. package/dist/error/codes.mjs.map +1 -0
  93. package/dist/error/index.d.mts +6 -187
  94. package/dist/error/index.mjs +29 -4
  95. package/dist/error/index.mjs.map +1 -0
  96. package/dist/index.d.mts +8 -2
  97. package/dist/oauth2/client-credentials-token.d.mts +58 -0
  98. package/dist/oauth2/client-credentials-token.mjs +67 -0
  99. package/dist/oauth2/client-credentials-token.mjs.map +1 -0
  100. package/dist/oauth2/create-authorization-url.d.mts +48 -0
  101. package/dist/oauth2/create-authorization-url.mjs +44 -0
  102. package/dist/oauth2/create-authorization-url.mjs.map +1 -0
  103. package/dist/oauth2/index.d.mts +8 -2
  104. package/dist/oauth2/index.mjs +7 -3
  105. package/dist/oauth2/oauth-provider.d.mts +195 -0
  106. package/dist/oauth2/refresh-access-token.d.mts +56 -0
  107. package/dist/oauth2/refresh-access-token.mjs +76 -0
  108. package/dist/oauth2/refresh-access-token.mjs.map +1 -0
  109. package/dist/oauth2/utils.d.mts +8 -0
  110. package/dist/oauth2/utils.mjs +28 -0
  111. package/dist/oauth2/utils.mjs.map +1 -0
  112. package/dist/oauth2/validate-authorization-code.d.mts +88 -0
  113. package/dist/oauth2/validate-authorization-code.mjs +83 -0
  114. package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
  115. package/dist/oauth2/verify.d.mts +43 -0
  116. package/dist/oauth2/verify.mjs +96 -0
  117. package/dist/oauth2/verify.mjs.map +1 -0
  118. package/dist/social-providers/apple.d.mts +120 -0
  119. package/dist/social-providers/apple.mjs +105 -0
  120. package/dist/social-providers/apple.mjs.map +1 -0
  121. package/dist/social-providers/atlassian.d.mts +73 -0
  122. package/dist/social-providers/atlassian.mjs +84 -0
  123. package/dist/social-providers/atlassian.mjs.map +1 -0
  124. package/dist/social-providers/cognito.d.mts +88 -0
  125. package/dist/social-providers/cognito.mjs +166 -0
  126. package/dist/social-providers/cognito.mjs.map +1 -0
  127. package/dist/social-providers/discord.d.mts +127 -0
  128. package/dist/social-providers/discord.mjs +65 -0
  129. package/dist/social-providers/discord.mjs.map +1 -0
  130. package/dist/social-providers/dropbox.d.mts +72 -0
  131. package/dist/social-providers/dropbox.mjs +76 -0
  132. package/dist/social-providers/dropbox.mjs.map +1 -0
  133. package/dist/social-providers/facebook.d.mts +82 -0
  134. package/dist/social-providers/facebook.mjs +121 -0
  135. package/dist/social-providers/facebook.mjs.map +1 -0
  136. package/dist/social-providers/figma.d.mts +64 -0
  137. package/dist/social-providers/figma.mjs +87 -0
  138. package/dist/social-providers/figma.mjs.map +1 -0
  139. package/dist/social-providers/github.d.mts +105 -0
  140. package/dist/social-providers/github.mjs +97 -0
  141. package/dist/social-providers/github.mjs.map +1 -0
  142. package/dist/social-providers/gitlab.d.mts +126 -0
  143. package/dist/social-providers/gitlab.mjs +83 -0
  144. package/dist/social-providers/gitlab.mjs.map +1 -0
  145. package/dist/social-providers/google.d.mts +100 -0
  146. package/dist/social-providers/google.mjs +113 -0
  147. package/dist/social-providers/google.mjs.map +1 -0
  148. package/dist/social-providers/huggingface.d.mts +86 -0
  149. package/dist/social-providers/huggingface.mjs +76 -0
  150. package/dist/social-providers/huggingface.mjs.map +1 -0
  151. package/dist/social-providers/index.d.mts +1777 -2
  152. package/dist/social-providers/index.mjs +37 -2570
  153. package/dist/social-providers/index.mjs.map +1 -0
  154. package/dist/social-providers/kakao.d.mts +164 -0
  155. package/dist/social-providers/kakao.mjs +73 -0
  156. package/dist/social-providers/kakao.mjs.map +1 -0
  157. package/dist/social-providers/kick.d.mts +76 -0
  158. package/dist/social-providers/kick.mjs +72 -0
  159. package/dist/social-providers/kick.mjs.map +1 -0
  160. package/dist/social-providers/line.d.mts +108 -0
  161. package/dist/social-providers/line.mjs +114 -0
  162. package/dist/social-providers/line.mjs.map +1 -0
  163. package/dist/social-providers/linear.d.mts +71 -0
  164. package/dist/social-providers/linear.mjs +89 -0
  165. package/dist/social-providers/linear.mjs.map +1 -0
  166. package/dist/social-providers/linkedin.d.mts +70 -0
  167. package/dist/social-providers/linkedin.mjs +77 -0
  168. package/dist/social-providers/linkedin.mjs.map +1 -0
  169. package/dist/social-providers/microsoft-entra-id.d.mts +177 -0
  170. package/dist/social-providers/microsoft-entra-id.mjs +140 -0
  171. package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
  172. package/dist/social-providers/naver.d.mts +95 -0
  173. package/dist/social-providers/naver.mjs +68 -0
  174. package/dist/social-providers/naver.mjs.map +1 -0
  175. package/dist/social-providers/notion.d.mts +67 -0
  176. package/dist/social-providers/notion.mjs +76 -0
  177. package/dist/social-providers/notion.mjs.map +1 -0
  178. package/dist/social-providers/paybin.d.mts +74 -0
  179. package/dist/social-providers/paybin.mjs +86 -0
  180. package/dist/social-providers/paybin.mjs.map +1 -0
  181. package/dist/social-providers/paypal.d.mts +132 -0
  182. package/dist/social-providers/paypal.mjs +145 -0
  183. package/dist/social-providers/paypal.mjs.map +1 -0
  184. package/dist/social-providers/polar.d.mts +77 -0
  185. package/dist/social-providers/polar.mjs +74 -0
  186. package/dist/social-providers/polar.mjs.map +1 -0
  187. package/dist/social-providers/railway.d.mts +68 -0
  188. package/dist/social-providers/railway.mjs +78 -0
  189. package/dist/social-providers/railway.mjs.map +1 -0
  190. package/dist/social-providers/reddit.d.mts +65 -0
  191. package/dist/social-providers/reddit.mjs +84 -0
  192. package/dist/social-providers/reddit.mjs.map +1 -0
  193. package/dist/social-providers/roblox.d.mts +73 -0
  194. package/dist/social-providers/roblox.mjs +60 -0
  195. package/dist/social-providers/roblox.mjs.map +1 -0
  196. package/dist/social-providers/salesforce.d.mts +82 -0
  197. package/dist/social-providers/salesforce.mjs +92 -0
  198. package/dist/social-providers/salesforce.mjs.map +1 -0
  199. package/dist/social-providers/slack.d.mts +86 -0
  200. package/dist/social-providers/slack.mjs +69 -0
  201. package/dist/social-providers/slack.mjs.map +1 -0
  202. package/dist/social-providers/spotify.d.mts +66 -0
  203. package/dist/social-providers/spotify.mjs +72 -0
  204. package/dist/social-providers/spotify.mjs.map +1 -0
  205. package/dist/social-providers/tiktok.d.mts +171 -0
  206. package/dist/social-providers/tiktok.mjs +63 -0
  207. package/dist/social-providers/tiktok.mjs.map +1 -0
  208. package/dist/social-providers/twitch.d.mts +82 -0
  209. package/dist/social-providers/twitch.mjs +79 -0
  210. package/dist/social-providers/twitch.mjs.map +1 -0
  211. package/dist/social-providers/twitter.d.mts +129 -0
  212. package/dist/social-providers/twitter.mjs +88 -0
  213. package/dist/social-providers/twitter.mjs.map +1 -0
  214. package/dist/social-providers/vercel.d.mts +65 -0
  215. package/dist/social-providers/vercel.mjs +62 -0
  216. package/dist/social-providers/vercel.mjs.map +1 -0
  217. package/dist/social-providers/vk.d.mts +73 -0
  218. package/dist/social-providers/vk.mjs +84 -0
  219. package/dist/social-providers/vk.mjs.map +1 -0
  220. package/dist/social-providers/zoom.d.mts +166 -0
  221. package/dist/social-providers/zoom.mjs +73 -0
  222. package/dist/social-providers/zoom.mjs.map +1 -0
  223. package/dist/types/context.d.mts +274 -0
  224. package/dist/types/cookie.d.mts +16 -0
  225. package/dist/types/helper.d.mts +11 -0
  226. package/dist/types/index.d.mts +8 -0
  227. package/dist/types/init-options.d.mts +1298 -0
  228. package/dist/types/plugin-client.d.mts +113 -0
  229. package/dist/types/plugin.d.mts +125 -0
  230. package/dist/utils/db.d.mts +12 -0
  231. package/dist/utils/db.mjs +17 -0
  232. package/dist/utils/db.mjs.map +1 -0
  233. package/dist/utils/deprecate.d.mts +10 -0
  234. package/dist/utils/deprecate.mjs +18 -0
  235. package/dist/utils/deprecate.mjs.map +1 -0
  236. package/dist/utils/{index.d.mts → error-codes.d.mts} +9 -16
  237. package/dist/utils/error-codes.mjs +12 -0
  238. package/dist/utils/error-codes.mjs.map +1 -0
  239. package/dist/utils/id.d.mts +5 -0
  240. package/dist/utils/id.mjs +10 -0
  241. package/dist/utils/id.mjs.map +1 -0
  242. package/dist/utils/ip.d.mts +55 -0
  243. package/dist/utils/ip.mjs +119 -0
  244. package/dist/utils/ip.mjs.map +1 -0
  245. package/dist/utils/json.d.mts +5 -0
  246. package/dist/utils/json.mjs +26 -0
  247. package/dist/utils/json.mjs.map +1 -0
  248. package/dist/utils/string.d.mts +5 -0
  249. package/dist/utils/string.mjs +8 -0
  250. package/dist/utils/string.mjs.map +1 -0
  251. package/dist/utils/url.d.mts +21 -0
  252. package/dist/utils/url.mjs +33 -0
  253. package/dist/utils/url.mjs.map +1 -0
  254. package/package.json +36 -18
  255. package/src/context/endpoint-context.ts +7 -6
  256. package/src/context/global.ts +57 -0
  257. package/src/context/index.ts +2 -0
  258. package/src/context/request-state.ts +7 -6
  259. package/src/context/transaction.ts +77 -14
  260. package/src/db/adapter/factory.ts +54 -86
  261. package/src/db/adapter/get-default-model-name.ts +1 -1
  262. package/src/db/adapter/get-id-field.ts +4 -6
  263. package/src/db/adapter/index.ts +20 -15
  264. package/src/db/adapter/types.ts +2 -41
  265. package/src/db/get-tables.ts +54 -37
  266. package/src/db/index.ts +30 -5
  267. package/src/db/schema/account.ts +16 -3
  268. package/src/db/schema/rate-limit.ts +16 -1
  269. package/src/db/schema/session.ts +15 -3
  270. package/src/db/schema/user.ts +15 -3
  271. package/src/db/schema/verification.ts +16 -3
  272. package/src/db/test/get-tables.test.ts +33 -0
  273. package/src/db/type.ts +154 -1
  274. package/src/env/env-impl.ts +2 -2
  275. package/src/env/logger.ts +1 -1
  276. package/src/error/codes.ts +18 -1
  277. package/src/error/index.ts +2 -3
  278. package/src/oauth2/client-credentials-token.ts +26 -2
  279. package/src/oauth2/create-authorization-url.ts +4 -2
  280. package/src/oauth2/index.ts +3 -0
  281. package/src/oauth2/oauth-provider.ts +7 -1
  282. package/src/oauth2/refresh-access-token.test.ts +90 -0
  283. package/src/oauth2/refresh-access-token.ts +37 -4
  284. package/src/oauth2/validate-authorization-code.ts +55 -29
  285. package/src/oauth2/validate-token.test.ts +229 -0
  286. package/src/social-providers/apple.ts +38 -29
  287. package/src/social-providers/cognito.ts +6 -5
  288. package/src/social-providers/dropbox.ts +1 -1
  289. package/src/social-providers/facebook.ts +3 -3
  290. package/src/social-providers/figma.ts +5 -3
  291. package/src/social-providers/github.ts +26 -4
  292. package/src/social-providers/gitlab.ts +2 -2
  293. package/src/social-providers/google.ts +18 -14
  294. package/src/social-providers/huggingface.ts +1 -1
  295. package/src/social-providers/index.ts +9 -5
  296. package/src/social-providers/kakao.ts +1 -1
  297. package/src/social-providers/line.ts +1 -1
  298. package/src/social-providers/microsoft-entra-id.ts +84 -1
  299. package/src/social-providers/naver.ts +1 -1
  300. package/src/social-providers/notion.ts +1 -1
  301. package/src/social-providers/paybin.ts +1 -5
  302. package/src/social-providers/polar.ts +1 -1
  303. package/src/social-providers/railway.ts +100 -0
  304. package/src/social-providers/tiktok.ts +2 -1
  305. package/src/social-providers/vercel.ts +1 -1
  306. package/src/social-providers/zoom.ts +0 -8
  307. package/src/types/context.ts +241 -132
  308. package/src/types/cookie.ts +6 -4
  309. package/src/types/helper.ts +9 -0
  310. package/src/types/index.ts +19 -2
  311. package/src/types/init-options.ts +301 -186
  312. package/src/types/plugin-client.ts +1 -0
  313. package/src/types/plugin.ts +11 -6
  314. package/src/utils/db.ts +20 -0
  315. package/src/utils/deprecate.test.ts +71 -0
  316. package/src/utils/deprecate.ts +21 -0
  317. package/src/utils/error-codes.ts +12 -9
  318. package/src/utils/ip.test.ts +255 -0
  319. package/src/utils/ip.ts +211 -0
  320. package/src/utils/url.ts +43 -0
  321. package/.turbo/turbo-build.log +0 -43
  322. package/dist/context-DblZrIwO.mjs +0 -114
  323. package/dist/env-DbssmzoK.mjs +0 -245
  324. package/dist/index-BpRqx5_q.d.mts +0 -7833
  325. package/dist/oauth2-BjWM15hm.mjs +0 -326
  326. package/dist/utils/index.mjs +0 -4
  327. package/dist/utils-s65Fz0OM.mjs +0 -47
  328. package/src/utils/index.ts +0 -4
  329. package/tsconfig.json +0 -7
  330. package/tsdown.config.ts +0 -22
  331. package/vitest.config.ts +0 -3
package/LICENSE.md CHANGED
@@ -1,17 +1,20 @@
1
1
  The MIT License (MIT)
2
2
  Copyright (c) 2024 - present, Bereket Engida
3
3
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
- and associated documentation files (the "Software"), to deal in the Software without restriction,
6
- including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
- sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
8
- is furnished to do so, subject to the following conditions:
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the Software), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
9
10
 
10
- The above copyright notice and this permission notice shall be included in all copies or
11
- substantial portions of the Software.
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
12
13
 
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14
- BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ THE SOFTWARE IS PROVIDED AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Better Auth Core
2
+
3
+ Core utilities and types for [Better Auth](https://www.better-auth.com) — the most comprehensive authentication framework for TypeScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @better-auth/core
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ For full documentation, visit [better-auth.com](https://www.better-auth.com).
14
+
15
+ ## License
16
+
17
+ MIT
@@ -1,2 +1,280 @@
1
- import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-BpRqx5_q.mjs";
2
- export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
1
+ import { BetterAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
2
+ import { DBAdapter } from "../db/adapter/index.mjs";
3
+ import { createLogger } from "../env/logger.mjs";
4
+ import "../db/index.mjs";
5
+ import { AuthContext } from "../types/context.mjs";
6
+ import "../types/index.mjs";
7
+ import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
8
+ import "../oauth2/index.mjs";
9
+ import * as better_call0 from "better-call";
10
+ import { EndpointContext, EndpointOptions, StrictEndpoint } from "better-call";
11
+ import * as _better_auth_core0 from "@better-auth/core";
12
+
13
+ //#region src/api/index.d.ts
14
+ declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
15
+ declare const createAuthMiddleware: {
16
+ <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, {
17
+ returned?: unknown | undefined;
18
+ responseHeaders?: Headers | undefined;
19
+ } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
20
+ options: _better_auth_core0.BetterAuthOptions;
21
+ trustedOrigins: string[];
22
+ trustedProviders: string[];
23
+ isTrustedOrigin: (url: string, settings?: {
24
+ allowRelativePaths: boolean;
25
+ }) => boolean;
26
+ oauthConfig: {
27
+ skipStateCookieCheck?: boolean | undefined;
28
+ storeStateStrategy: "database" | "cookie";
29
+ };
30
+ newSession: {
31
+ session: {
32
+ id: string;
33
+ createdAt: Date;
34
+ updatedAt: Date;
35
+ userId: string;
36
+ expiresAt: Date;
37
+ token: string;
38
+ ipAddress?: string | null | undefined;
39
+ userAgent?: string | null | undefined;
40
+ } & Record<string, any>;
41
+ user: {
42
+ id: string;
43
+ createdAt: Date;
44
+ updatedAt: Date;
45
+ email: string;
46
+ emailVerified: boolean;
47
+ name: string;
48
+ image?: string | null | undefined;
49
+ } & Record<string, any>;
50
+ } | null;
51
+ session: {
52
+ session: {
53
+ id: string;
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ userId: string;
57
+ expiresAt: Date;
58
+ token: string;
59
+ ipAddress?: string | null | undefined;
60
+ userAgent?: string | null | undefined;
61
+ } & Record<string, any>;
62
+ user: {
63
+ id: string;
64
+ createdAt: Date;
65
+ updatedAt: Date;
66
+ email: string;
67
+ emailVerified: boolean;
68
+ name: string;
69
+ image?: string | null | undefined;
70
+ } & Record<string, any>;
71
+ } | null;
72
+ setNewSession: (session: {
73
+ session: {
74
+ id: string;
75
+ createdAt: Date;
76
+ updatedAt: Date;
77
+ userId: string;
78
+ expiresAt: Date;
79
+ token: string;
80
+ ipAddress?: string | null | undefined;
81
+ userAgent?: string | null | undefined;
82
+ } & Record<string, any>;
83
+ user: {
84
+ id: string;
85
+ createdAt: Date;
86
+ updatedAt: Date;
87
+ email: string;
88
+ emailVerified: boolean;
89
+ name: string;
90
+ image?: string | null | undefined;
91
+ } & Record<string, any>;
92
+ } | null) => void;
93
+ socialProviders: OAuthProvider[];
94
+ authCookies: _better_auth_core0.BetterAuthCookies;
95
+ logger: ReturnType<typeof createLogger>;
96
+ rateLimit: {
97
+ enabled: boolean;
98
+ window: number;
99
+ max: number;
100
+ storage: "memory" | "database" | "secondary-storage";
101
+ } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
102
+ adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
103
+ internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
104
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
105
+ secret: string;
106
+ sessionConfig: {
107
+ updateAge: number;
108
+ expiresIn: number;
109
+ freshAge: number;
110
+ cookieRefreshCache: false | {
111
+ enabled: true;
112
+ updateAge: number;
113
+ };
114
+ };
115
+ generateId: (options: {
116
+ model: ModelNames;
117
+ size?: number | undefined;
118
+ }) => string | false;
119
+ secondaryStorage: SecondaryStorage | undefined;
120
+ password: {
121
+ hash: (password: string) => Promise<string>;
122
+ verify: (data: {
123
+ password: string;
124
+ hash: string;
125
+ }) => Promise<boolean>;
126
+ config: {
127
+ minPasswordLength: number;
128
+ maxPasswordLength: number;
129
+ };
130
+ checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
131
+ };
132
+ tables: BetterAuthDBSchema;
133
+ runMigrations: () => Promise<void>;
134
+ publishTelemetry: (event: {
135
+ type: string;
136
+ anonymousId?: string | undefined;
137
+ payload: Record<string, any>;
138
+ }) => Promise<void>;
139
+ skipOriginCheck: boolean | string[];
140
+ skipCSRFCheck: boolean;
141
+ runInBackground: (promise: Promise<unknown>) => void;
142
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
143
+ }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
144
+ <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, {
145
+ returned?: unknown | undefined;
146
+ responseHeaders?: Headers | undefined;
147
+ } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
148
+ options: _better_auth_core0.BetterAuthOptions;
149
+ trustedOrigins: string[];
150
+ trustedProviders: string[];
151
+ isTrustedOrigin: (url: string, settings?: {
152
+ allowRelativePaths: boolean;
153
+ }) => boolean;
154
+ oauthConfig: {
155
+ skipStateCookieCheck?: boolean | undefined;
156
+ storeStateStrategy: "database" | "cookie";
157
+ };
158
+ newSession: {
159
+ session: {
160
+ id: string;
161
+ createdAt: Date;
162
+ updatedAt: Date;
163
+ userId: string;
164
+ expiresAt: Date;
165
+ token: string;
166
+ ipAddress?: string | null | undefined;
167
+ userAgent?: string | null | undefined;
168
+ } & Record<string, any>;
169
+ user: {
170
+ id: string;
171
+ createdAt: Date;
172
+ updatedAt: Date;
173
+ email: string;
174
+ emailVerified: boolean;
175
+ name: string;
176
+ image?: string | null | undefined;
177
+ } & Record<string, any>;
178
+ } | null;
179
+ session: {
180
+ session: {
181
+ id: string;
182
+ createdAt: Date;
183
+ updatedAt: Date;
184
+ userId: string;
185
+ expiresAt: Date;
186
+ token: string;
187
+ ipAddress?: string | null | undefined;
188
+ userAgent?: string | null | undefined;
189
+ } & Record<string, any>;
190
+ user: {
191
+ id: string;
192
+ createdAt: Date;
193
+ updatedAt: Date;
194
+ email: string;
195
+ emailVerified: boolean;
196
+ name: string;
197
+ image?: string | null | undefined;
198
+ } & Record<string, any>;
199
+ } | null;
200
+ setNewSession: (session: {
201
+ session: {
202
+ id: string;
203
+ createdAt: Date;
204
+ updatedAt: Date;
205
+ userId: string;
206
+ expiresAt: Date;
207
+ token: string;
208
+ ipAddress?: string | null | undefined;
209
+ userAgent?: string | null | undefined;
210
+ } & Record<string, any>;
211
+ user: {
212
+ id: string;
213
+ createdAt: Date;
214
+ updatedAt: Date;
215
+ email: string;
216
+ emailVerified: boolean;
217
+ name: string;
218
+ image?: string | null | undefined;
219
+ } & Record<string, any>;
220
+ } | null) => void;
221
+ socialProviders: OAuthProvider[];
222
+ authCookies: _better_auth_core0.BetterAuthCookies;
223
+ logger: ReturnType<typeof createLogger>;
224
+ rateLimit: {
225
+ enabled: boolean;
226
+ window: number;
227
+ max: number;
228
+ storage: "memory" | "database" | "secondary-storage";
229
+ } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
230
+ adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
231
+ internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
232
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
233
+ secret: string;
234
+ sessionConfig: {
235
+ updateAge: number;
236
+ expiresIn: number;
237
+ freshAge: number;
238
+ cookieRefreshCache: false | {
239
+ enabled: true;
240
+ updateAge: number;
241
+ };
242
+ };
243
+ generateId: (options: {
244
+ model: ModelNames;
245
+ size?: number | undefined;
246
+ }) => string | false;
247
+ secondaryStorage: SecondaryStorage | undefined;
248
+ password: {
249
+ hash: (password: string) => Promise<string>;
250
+ verify: (data: {
251
+ password: string;
252
+ hash: string;
253
+ }) => Promise<boolean>;
254
+ config: {
255
+ minPasswordLength: number;
256
+ maxPasswordLength: number;
257
+ };
258
+ checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
259
+ };
260
+ tables: BetterAuthDBSchema;
261
+ runMigrations: () => Promise<void>;
262
+ publishTelemetry: (event: {
263
+ type: string;
264
+ anonymousId?: string | undefined;
265
+ payload: Record<string, any>;
266
+ }) => Promise<void>;
267
+ skipOriginCheck: boolean | string[];
268
+ skipCSRFCheck: boolean;
269
+ runInBackground: (promise: Promise<unknown>) => void;
270
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
271
+ }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
272
+ };
273
+ type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
274
+ declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
275
+ declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
276
+ type AuthEndpoint<Path extends string, Opts extends EndpointOptions, R> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
277
+ type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
278
+ //#endregion
279
+ export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
280
+ //# sourceMappingURL=index.d.mts.map
@@ -1,4 +1,5 @@
1
- import { f as runWithEndpointContext } from "../context-DblZrIwO.mjs";
1
+ import { runWithEndpointContext } from "../context/endpoint-context.mjs";
2
+ import "../context/index.mjs";
2
3
  import { createEndpoint, createMiddleware } from "better-call";
3
4
 
4
5
  //#region src/api/index.ts
@@ -29,4 +30,5 @@ function createAuthEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
29
30
  }
30
31
 
31
32
  //#endregion
32
- export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
33
+ export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tEndpointContext,\n\tEndpointOptions,\n\tStrictEndpoint,\n} from \"better-call\";\nimport { createEndpoint, createMiddleware } from \"better-call\";\nimport { runWithEndpointContext } from \"../context\";\nimport type { AuthContext } from \"../types\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddleware.create({\n\tuse: [\n\t\toptionsMiddleware,\n\t\t/**\n\t\t * Only use for post hooks\n\t\t */\n\t\tcreateMiddleware(async () => {\n\t\t\treturn {} as {\n\t\t\t\treturned?: unknown | undefined;\n\t\t\t\tresponseHeaders?: Headers | undefined;\n\t\t\t};\n\t\t}),\n\t],\n});\n\nconst use = [optionsMiddleware];\n\ntype EndpointHandler<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\tpath: Path,\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n\tR,\n>(\n\toptions: Options,\n\thandler: EndpointHandler<Path, Options, R>,\n): StrictEndpoint<Path, Options, R>;\n\nexport function createAuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n>(\n\tpathOrOptions: Path | Opts,\n\thandlerOrOptions: EndpointHandler<Path, Opts, R> | Opts,\n\thandlerOrNever?: any,\n) {\n\tconst path: Path | undefined =\n\t\ttypeof pathOrOptions === \"string\" ? pathOrOptions : undefined;\n\tconst options: Opts =\n\t\ttypeof handlerOrOptions === \"object\"\n\t\t\t? handlerOrOptions\n\t\t\t: (pathOrOptions as Opts);\n\tconst handler: EndpointHandler<Path, Opts, R> =\n\t\ttypeof handlerOrOptions === \"function\" ? handlerOrOptions : handlerOrNever;\n\n\tif (path) {\n\t\treturn createEndpoint(\n\t\t\tpath,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tuse: [...(options?.use || []), ...use],\n\t\t\t},\n\t\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),\n\t\t);\n\t}\n\n\treturn createEndpoint(\n\t\t{\n\t\t\t...options,\n\t\t\tuse: [...(options?.use || []), ...use],\n\t\t},\n\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\tasync (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),\n\t);\n}\n\nexport type AuthEndpoint<\n\tPath extends string,\n\tOpts extends EndpointOptions,\n\tR,\n> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;\nexport type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;\n"],"mappings":";;;;;AASA,MAAa,oBAAoB,iBAAiB,YAAY;;;;;;AAM7D,QAAO,EAAE;EACR;AAEF,MAAa,uBAAuB,iBAAiB,OAAO,EAC3D,KAAK,CACJ,mBAIA,iBAAiB,YAAY;AAC5B,QAAO,EAAE;EAIR,CACF,EACD,CAAC;AAEF,MAAM,MAAM,CAAC,kBAAkB;AA2B/B,SAAgB,mBAKf,eACA,kBACA,gBACC;CACD,MAAM,OACL,OAAO,kBAAkB,WAAW,gBAAgB;CACrD,MAAM,UACL,OAAO,qBAAqB,WACzB,mBACC;CACL,MAAM,UACL,OAAO,qBAAqB,aAAa,mBAAmB;AAE7D,KAAI,KACH,QAAO,eACN,MACA;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE;AAGF,QAAO,eACN;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAQ,uBAAuB,WAAkB,QAAQ,IAAI,CAAC,CACrE"}
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  //#region src/async_hooks/index.d.ts
4
4
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
5
  //#endregion
6
- export { type AsyncLocalStorage, getAsyncLocalStorage };
6
+ export { type AsyncLocalStorage, getAsyncLocalStorage };
7
+ //# sourceMappingURL=index.d.mts.map
@@ -18,4 +18,5 @@ async function getAsyncLocalStorage() {
18
18
  }
19
19
 
20
20
  //#endregion
21
- export { getAsyncLocalStorage };
21
+ export { getAsyncLocalStorage };
22
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/async_hooks/index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type { AsyncLocalStorage };\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\timport(\n\t\t/* @vite-ignore */\n\t\t/* webpackIgnore: true */\n\t\t\"node:async_hooks\"\n\t)\n\t\t.then((mod) => mod.AsyncLocalStorage)\n\t\t.catch((err) => {\n\t\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t\t}\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag\",\n\t\t\t);\n\t\t\tthrow err;\n\t\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";AAIA,MAAM,2BACL;;;CAGC;EAEC,MAAM,QAAQ,IAAI,kBAAkB,CACpC,OAAO,QAAQ;AACf,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,KAAI,OAAO,WAAW,YACrB,QAAO;AAER,SAAQ,KACP,yHACA;AACD,SAAQ,KACP,+GACA;AACD,SAAQ,KACP,wKACA;AACD,OAAM;EACL;AAEJ,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
@@ -3,4 +3,5 @@ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  //#region src/async_hooks/pure.index.d.ts
4
4
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
5
  //#endregion
6
- export { getAsyncLocalStorage };
6
+ export { getAsyncLocalStorage };
7
+ //# sourceMappingURL=pure.index.d.mts.map
@@ -31,4 +31,5 @@ async function getAsyncLocalStorage() {
31
31
  }
32
32
 
33
33
  //#endregion
34
- export { getAsyncLocalStorage };
34
+ export { getAsyncLocalStorage };
35
+ //# sourceMappingURL=pure.index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure.index.mjs","names":["#current"],"sources":["../../src/async_hooks/pure.index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Due to the lack of AsyncLocalStorage in some environments (like Convex),\n *\n * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.\n */\nclass AsyncLocalStoragePolyfill<T> {\n\t#current: T | undefined = undefined;\n\n\trun(store: T, fn: () => unknown): unknown {\n\t\tconst prev = this.#current;\n\t\tthis.#current = store;\n\t\tconst result = fn();\n\t\tif (result instanceof Promise) {\n\t\t\treturn result.finally(() => {\n\t\t\t\tthis.#current = prev;\n\t\t\t});\n\t\t}\n\t\tthis.#current = prev;\n\t\treturn result;\n\t}\n\n\tgetStore(): T | undefined {\n\t\treturn this.#current;\n\t}\n}\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\tPromise.resolve().then(() => {\n\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t}\n\t\treturn AsyncLocalStoragePolyfill;\n\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";;;;;;AAOA,IAAM,4BAAN,MAAmC;CAClC,WAA0B;CAE1B,IAAI,OAAU,IAA4B;EACzC,MAAM,OAAO,MAAKA;AAClB,QAAKA,UAAW;EAChB,MAAM,SAAS,IAAI;AACnB,MAAI,kBAAkB,QACrB,QAAO,OAAO,cAAc;AAC3B,SAAKA,UAAW;IACf;AAEH,QAAKA,UAAW;AAChB,SAAO;;CAGR,WAA0B;AACzB,SAAO,MAAKA;;;AAId,MAAM,2BACL,QAAQ,SAAS,CAAC,WAAW;AAC5B,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,QAAO;EACN;AAEH,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
@@ -0,0 +1,20 @@
1
+ import { AuthContext } from "../types/context.mjs";
2
+ import "../types/index.mjs";
3
+ import { EndpointContext, InputContext } from "better-call";
4
+ import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
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
+ export { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
20
+ //# sourceMappingURL=endpoint-context.d.mts.map
@@ -0,0 +1,32 @@
1
+ import { __getBetterAuthGlobal } from "./global.mjs";
2
+ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
+
4
+ //#region src/context/endpoint-context.ts
5
+ const ensureAsyncStorage = async () => {
6
+ const betterAuthGlobal = __getBetterAuthGlobal();
7
+ if (!betterAuthGlobal.context.endpointContextAsyncStorage) {
8
+ const AsyncLocalStorage = await getAsyncLocalStorage();
9
+ betterAuthGlobal.context.endpointContextAsyncStorage = new AsyncLocalStorage();
10
+ }
11
+ return betterAuthGlobal.context.endpointContextAsyncStorage;
12
+ };
13
+ /**
14
+ * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
15
+ *
16
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
17
+ */
18
+ async function getCurrentAuthContextAsyncLocalStorage() {
19
+ return ensureAsyncStorage();
20
+ }
21
+ async function getCurrentAuthContext() {
22
+ const context = (await ensureAsyncStorage()).getStore();
23
+ if (!context) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
24
+ return context;
25
+ }
26
+ async function runWithEndpointContext(context, fn) {
27
+ return (await ensureAsyncStorage()).run(context, fn);
28
+ }
29
+
30
+ //#endregion
31
+ export { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext };
32
+ //# sourceMappingURL=endpoint-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-context.mjs","names":[],"sources":["../../src/context/endpoint-context.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { EndpointContext, InputContext } from \"better-call\";\nimport type { AuthContext } from \"../types\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type AuthEndpointContext = Partial<\n\tInputContext<string, any> & EndpointContext<string, any>\n> & {\n\tcontext: AuthContext;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.endpointContextAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.endpointContextAsyncStorage =\n\t\t\tnew AsyncLocalStorage<AuthEndpointContext>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.endpointContextAsyncStorage as AsyncLocalStorage<AuthEndpointContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAuthContext` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport async function getCurrentAuthContextAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function getCurrentAuthContext(): Promise<AuthEndpointContext> {\n\tconst als = await ensureAsyncStorage();\n\tconst context = als.getStore();\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.\",\n\t\t);\n\t}\n\treturn context;\n}\n\nexport async function runWithEndpointContext<T>(\n\tcontext: AuthEndpointContext,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(context, fn);\n}\n"],"mappings":";;;;AAYA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,6BAA6B;EAC1D,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,8BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;;;;;;AAQH,eAAsB,yCAAyC;AAC9D,QAAO,oBAAoB;;AAG5B,eAAsB,wBAAsD;CAE3E,MAAM,WADM,MAAM,oBAAoB,EAClB,UAAU;AAC9B,KAAI,CAAC,QACJ,OAAM,IAAI,MACT,oHACA;AAEF,QAAO;;AAGR,eAAsB,uBACrB,SACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,SAAS,GAAG"}
@@ -0,0 +1,7 @@
1
+ import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
+
3
+ //#region src/context/global.d.ts
4
+ declare function getBetterAuthVersion(): string;
5
+ //#endregion
6
+ export { getBetterAuthVersion };
7
+ //# sourceMappingURL=global.d.mts.map
@@ -0,0 +1,38 @@
1
+ //#region src/context/global.ts
2
+ const symbol = Symbol.for("better-auth:global");
3
+ let bind = null;
4
+ const __context = {};
5
+ const __betterAuthVersion = "1.5.0-beta.20";
6
+ /**
7
+ * We store context instance in the globalThis.
8
+ *
9
+ * The reason we do this is that some bundlers, web framework, or package managers might
10
+ * create multiple copies of BetterAuth in the same process intentionally or unintentionally.
11
+ *
12
+ * For example, yarn v1, Next.js, SSR, Vite...
13
+ *
14
+ * @internal
15
+ */
16
+ function __getBetterAuthGlobal() {
17
+ if (!globalThis[symbol]) {
18
+ globalThis[symbol] = {
19
+ version: __betterAuthVersion,
20
+ epoch: 1,
21
+ context: __context
22
+ };
23
+ bind = globalThis[symbol];
24
+ }
25
+ bind = globalThis[symbol];
26
+ if (bind.version !== __betterAuthVersion) {
27
+ bind.version = __betterAuthVersion;
28
+ bind.epoch++;
29
+ }
30
+ return globalThis[symbol];
31
+ }
32
+ function getBetterAuthVersion() {
33
+ return __getBetterAuthGlobal().version;
34
+ }
35
+
36
+ //#endregion
37
+ export { __getBetterAuthGlobal, getBetterAuthVersion };
38
+ //# sourceMappingURL=global.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.mjs","names":[],"sources":["../../src/context/global.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\n\ninterface BetterAuthGlobal {\n\t/**\n\t * The version of BetterAuth.\n\t */\n\tversion: string;\n\t/**\n\t * Used to track the number of BetterAuth instances in the same process.\n\t *\n\t * Debugging purposes only.\n\t */\n\tepoch: number;\n\t/**\n\t * Stores the AsyncLocalStorage instances for each context.\n\t */\n\tcontext: Record<string, AsyncLocalStorage<unknown>>;\n}\n\nconst symbol = Symbol.for(\"better-auth:global\");\nlet bind: BetterAuthGlobal | null = null;\n\nconst __context: Record<string, AsyncLocalStorage<unknown>> = {};\nconst __betterAuthVersion: string = import.meta.env\n\t.BETTER_AUTH_VERSION as string;\n\n/**\n * We store context instance in the globalThis.\n *\n * The reason we do this is that some bundlers, web framework, or package managers might\n * create multiple copies of BetterAuth in the same process intentionally or unintentionally.\n *\n * For example, yarn v1, Next.js, SSR, Vite...\n *\n * @internal\n */\nexport function __getBetterAuthGlobal(): BetterAuthGlobal {\n\tif (!(globalThis as any)[symbol]) {\n\t\t(globalThis as any)[symbol] = {\n\t\t\tversion: __betterAuthVersion,\n\t\t\tepoch: 1,\n\t\t\tcontext: __context,\n\t\t};\n\t\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\t}\n\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\tif (bind.version !== __betterAuthVersion) {\n\t\tbind.version = __betterAuthVersion;\n\t\t// Different versions of BetterAuth are loaded in the same process.\n\t\tbind.epoch++;\n\t}\n\treturn (globalThis as any)[symbol] as BetterAuthGlobal;\n}\n\nexport function getBetterAuthVersion(): string {\n\treturn __getBetterAuthGlobal().version;\n}\n"],"mappings":";AAmBA,MAAM,SAAS,OAAO,IAAI,qBAAqB;AAC/C,IAAI,OAAgC;AAEpC,MAAM,YAAwD,EAAE;AAChE,MAAM;;;;;;;;;;;AAaN,SAAgB,wBAA0C;AACzD,KAAI,CAAE,WAAmB,SAAS;AACjC,EAAC,WAAmB,UAAU;GAC7B,SAAS;GACT,OAAO;GACP,SAAS;GACT;AACD,SAAQ,WAAmB;;AAE5B,QAAQ,WAAmB;AAC3B,KAAI,KAAK,YAAY,qBAAqB;AACzC,OAAK,UAAU;AAEf,OAAK;;AAEN,QAAQ,WAAmB;;AAG5B,SAAgB,uBAA+B;AAC9C,QAAO,uBAAuB,CAAC"}
@@ -1,53 +1,5 @@
1
- import { Yn as DBAdapter, er as DBTransactionAdapter, f as AuthContext } from "../index-BpRqx5_q.mjs";
2
- import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
3
- import { EndpointContext, InputContext } from "better-call";
4
-
5
- //#region src/context/endpoint-context.d.ts
6
- type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
7
- context: AuthContext;
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
- declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalStorage<AuthEndpointContext>>;
15
- declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
16
- declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
17
- //#endregion
18
- //#region src/context/request-state.d.ts
19
- type RequestStateWeakMap = WeakMap<object, any>;
20
- declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
21
- declare function hasRequestState(): Promise<boolean>;
22
- declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
23
- declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
24
- interface RequestState<T> {
25
- get(): Promise<T>;
26
- set(value: T): Promise<void>;
27
- readonly ref: Readonly<object>;
28
- }
29
- /**
30
- * Defines a request-scoped state with lazy initialization.
31
- *
32
- * @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.
33
- * @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.
34
- *
35
- * @example
36
- * const userState = defineRequestState(() => ({ id: '', name: '' }));
37
- * // Later, within a request context:
38
- * const user = await userState.get();
39
- */
40
- declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
41
- //#endregion
42
- //#region src/context/transaction.d.ts
43
- /**
44
- * This is for internal use only. Most users should use `getCurrentAdapter` instead.
45
- *
46
- * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
47
- */
48
- declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<DBTransactionAdapter>>;
49
- declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBTransactionAdapter>;
50
- declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
51
- declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
52
- //#endregion
53
- export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
1
+ import { AuthEndpointContext, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext } from "./endpoint-context.mjs";
2
+ import { getBetterAuthVersion } from "./global.mjs";
3
+ import { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState } from "./request-state.mjs";
4
+ import { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction } from "./transaction.mjs";
5
+ export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getBetterAuthVersion, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, queueAfterTransactionHook, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -1,3 +1,6 @@
1
- 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-DblZrIwO.mjs";
1
+ import { getBetterAuthVersion } from "./global.mjs";
2
+ import { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, runWithEndpointContext } from "./endpoint-context.mjs";
3
+ import { defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState } from "./request-state.mjs";
4
+ import { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction } from "./transaction.mjs";
2
5
 
3
- export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
6
+ export { defineRequestState, getBetterAuthVersion, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, queueAfterTransactionHook, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -0,0 +1,28 @@
1
+ import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
+
3
+ //#region src/context/request-state.d.ts
4
+ type RequestStateWeakMap = WeakMap<object, any>;
5
+ declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
6
+ declare function hasRequestState(): Promise<boolean>;
7
+ declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
8
+ declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
9
+ interface RequestState<T> {
10
+ get(): Promise<T>;
11
+ set(value: T): Promise<void>;
12
+ readonly ref: Readonly<object>;
13
+ }
14
+ /**
15
+ * Defines a request-scoped state with lazy initialization.
16
+ *
17
+ * @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.
18
+ * @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.
19
+ *
20
+ * @example
21
+ * const userState = defineRequestState(() => ({ id: '', name: '' }));
22
+ * // Later, within a request context:
23
+ * const user = await userState.get();
24
+ */
25
+ declare function defineRequestState<T>(initFn: () => T | Promise<T>): RequestState<T>;
26
+ //#endregion
27
+ export { RequestState, RequestStateWeakMap, defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
28
+ //# sourceMappingURL=request-state.d.mts.map