@entro314labs/entro-auth-core 0.0.0-stage → 1.8.0-beta.12

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 (379) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +16 -2
  3. package/dist/api/index.d.mts +298 -0
  4. package/dist/api/index.mjs +108 -0
  5. package/dist/async_hooks/builtin.mjs +9 -0
  6. package/dist/async_hooks/index.d.mts +3 -0
  7. package/dist/async_hooks/index.mjs +36 -0
  8. package/dist/async_hooks/pure.index.d.mts +2 -0
  9. package/dist/async_hooks/pure.index.mjs +57 -0
  10. package/dist/context/endpoint-context.d.mts +30 -0
  11. package/dist/context/endpoint-context.mjs +47 -0
  12. package/dist/context/global.d.mts +2 -0
  13. package/dist/context/global.mjs +38 -0
  14. package/dist/context/index.d.mts +5 -0
  15. package/dist/context/index.mjs +5 -0
  16. package/dist/context/request-state.d.mts +23 -0
  17. package/dist/context/request-state.mjs +46 -0
  18. package/dist/context/transaction.d.mts +55 -0
  19. package/dist/context/transaction.mjs +161 -0
  20. package/dist/db/adapter/atomic-fallback.mjs +136 -0
  21. package/dist/db/adapter/factory.d.mts +13 -0
  22. package/dist/db/adapter/factory.mjs +882 -0
  23. package/dist/db/adapter/get-default-field-name.d.mts +8 -0
  24. package/dist/db/adapter/get-default-field-name.mjs +35 -0
  25. package/dist/db/adapter/get-default-model-name.d.mts +5 -0
  26. package/dist/db/adapter/get-default-model-name.mjs +30 -0
  27. package/dist/db/adapter/get-field-attributes.d.mts +16 -0
  28. package/dist/db/adapter/get-field-attributes.mjs +36 -0
  29. package/dist/db/adapter/get-field-name.d.mts +8 -0
  30. package/dist/db/adapter/get-field-name.mjs +30 -0
  31. package/dist/db/adapter/get-id-field.d.mts +54 -0
  32. package/dist/db/adapter/get-id-field.mjs +106 -0
  33. package/dist/db/adapter/get-model-name.d.mts +5 -0
  34. package/dist/db/adapter/get-model-name.mjs +20 -0
  35. package/dist/db/adapter/index.d.mts +594 -0
  36. package/dist/db/adapter/index.mjs +23 -0
  37. package/dist/db/adapter/types.d.mts +90 -0
  38. package/dist/db/adapter/utils.d.mts +3 -0
  39. package/dist/db/adapter/utils.mjs +36 -0
  40. package/dist/db/database-index.d.mts +41 -0
  41. package/dist/db/database-index.mjs +167 -0
  42. package/dist/db/errors.d.mts +2 -0
  43. package/dist/db/errors.mjs +31 -0
  44. package/dist/db/get-tables.d.mts +9 -0
  45. package/dist/db/get-tables.mjs +298 -0
  46. package/dist/db/index.d.mts +10 -0
  47. package/dist/db/index.mjs +8 -0
  48. package/dist/db/internal.d.mts +7 -0
  49. package/dist/db/internal.mjs +7 -0
  50. package/dist/db/plugin.d.mts +10 -0
  51. package/dist/db/schema/account.d.mts +27 -0
  52. package/dist/db/schema/account.mjs +31 -0
  53. package/dist/db/schema/rate-limit.d.mts +15 -0
  54. package/dist/db/schema/rate-limit.mjs +17 -0
  55. package/dist/db/schema/session.d.mts +20 -0
  56. package/dist/db/schema/session.mjs +11 -0
  57. package/dist/db/schema/shared.d.mts +6 -0
  58. package/dist/db/schema/shared.mjs +8 -0
  59. package/dist/db/schema/user.d.mts +19 -0
  60. package/dist/db/schema/user.mjs +10 -0
  61. package/dist/db/schema/verification.d.mts +18 -0
  62. package/dist/db/schema/verification.mjs +9 -0
  63. package/dist/db/schema-check.d.mts +59 -0
  64. package/dist/db/schema-check.mjs +127 -0
  65. package/dist/db/schema-diff.d.mts +100 -0
  66. package/dist/db/schema-diff.mjs +154 -0
  67. package/dist/db/type.d.mts +190 -0
  68. package/dist/env/color-depth.d.mts +1 -0
  69. package/dist/env/color-depth.mjs +85 -0
  70. package/dist/env/env-impl.d.mts +26 -0
  71. package/dist/env/env-impl.mjs +72 -0
  72. package/dist/env/index.d.mts +5 -0
  73. package/dist/env/index.mjs +5 -0
  74. package/dist/env/logger.d.mts +45 -0
  75. package/dist/env/logger.mjs +93 -0
  76. package/dist/env/runtime.d.mts +23 -0
  77. package/dist/env/runtime.mjs +23 -0
  78. package/dist/error/codes.d.mts +68 -0
  79. package/dist/error/codes.mjs +57 -0
  80. package/dist/error/index.d.mts +21 -0
  81. package/dist/error/index.mjs +32 -0
  82. package/dist/index.d.mts +10 -0
  83. package/dist/index.mjs +1 -0
  84. package/dist/instrumentation/api.mjs +14 -0
  85. package/dist/instrumentation/attributes.d.mts +14 -0
  86. package/dist/instrumentation/attributes.mjs +16 -0
  87. package/dist/instrumentation/index.d.mts +3 -0
  88. package/dist/instrumentation/index.mjs +3 -0
  89. package/dist/instrumentation/noop.d.mts +5 -0
  90. package/dist/instrumentation/noop.mjs +44 -0
  91. package/dist/instrumentation/pure.index.d.mts +9 -0
  92. package/dist/instrumentation/pure.index.mjs +10 -0
  93. package/dist/instrumentation/tracer.d.mts +16 -0
  94. package/dist/instrumentation/tracer.mjs +59 -0
  95. package/dist/oauth2/authorization-params.d.mts +8 -0
  96. package/dist/oauth2/authorization-params.mjs +11 -0
  97. package/dist/oauth2/basic-credentials.d.mts +27 -0
  98. package/dist/oauth2/basic-credentials.mjs +63 -0
  99. package/dist/oauth2/client-assertion.d.mts +95 -0
  100. package/dist/oauth2/client-assertion.mjs +111 -0
  101. package/dist/oauth2/client-credentials-token.d.mts +35 -0
  102. package/dist/oauth2/client-credentials-token.mjs +68 -0
  103. package/dist/oauth2/create-authorization-url.d.mts +33 -0
  104. package/dist/oauth2/create-authorization-url.mjs +79 -0
  105. package/dist/oauth2/dpop-client.d.mts +137 -0
  106. package/dist/oauth2/dpop-client.mjs +291 -0
  107. package/dist/oauth2/dpop-protocol.d.mts +22 -0
  108. package/dist/oauth2/dpop-protocol.mjs +65 -0
  109. package/dist/oauth2/dpop.d.mts +194 -0
  110. package/dist/oauth2/dpop.mjs +329 -0
  111. package/dist/oauth2/index.d.mts +16 -0
  112. package/dist/oauth2/index.mjs +14 -0
  113. package/dist/oauth2/internal.d.mts +4 -0
  114. package/dist/oauth2/internal.mjs +4 -0
  115. package/dist/oauth2/oauth-provider.d.mts +440 -0
  116. package/dist/oauth2/pushed-authorization-request.d.mts +54 -0
  117. package/dist/oauth2/pushed-authorization-request.mjs +52 -0
  118. package/dist/oauth2/refresh-access-token.d.mts +41 -0
  119. package/dist/oauth2/refresh-access-token.mjs +91 -0
  120. package/dist/oauth2/reject-redirects.mjs +48 -0
  121. package/dist/oauth2/resolve-host.d.mts +90 -0
  122. package/dist/oauth2/resolve-host.mjs +141 -0
  123. package/dist/oauth2/token-endpoint-auth.d.mts +54 -0
  124. package/dist/oauth2/token-endpoint-auth.mjs +131 -0
  125. package/dist/oauth2/utils.d.mts +32 -0
  126. package/dist/oauth2/utils.mjs +79 -0
  127. package/dist/oauth2/validate-authorization-code.d.mts +65 -0
  128. package/dist/oauth2/validate-authorization-code.mjs +99 -0
  129. package/dist/oauth2/verify-id-token.d.mts +36 -0
  130. package/dist/oauth2/verify-id-token.mjs +100 -0
  131. package/dist/oauth2/verify.d.mts +174 -0
  132. package/dist/oauth2/verify.mjs +449 -0
  133. package/dist/social-providers/apple.d.mts +111 -0
  134. package/dist/social-providers/apple.mjs +95 -0
  135. package/dist/social-providers/atlassian.d.mts +70 -0
  136. package/dist/social-providers/atlassian.mjs +82 -0
  137. package/dist/social-providers/cloudflare.d.mts +132 -0
  138. package/dist/social-providers/cloudflare.mjs +83 -0
  139. package/dist/social-providers/cognito.d.mts +122 -0
  140. package/dist/social-providers/cognito.mjs +156 -0
  141. package/dist/social-providers/discord.d.mts +141 -0
  142. package/dist/social-providers/discord.mjs +74 -0
  143. package/dist/social-providers/dropbox.d.mts +115 -0
  144. package/dist/social-providers/dropbox.mjs +72 -0
  145. package/dist/social-providers/facebook.d.mts +86 -0
  146. package/dist/social-providers/facebook.mjs +158 -0
  147. package/dist/social-providers/figma.d.mts +47 -0
  148. package/dist/social-providers/figma.mjs +83 -0
  149. package/dist/social-providers/github.d.mts +91 -0
  150. package/dist/social-providers/github.mjs +106 -0
  151. package/dist/social-providers/gitlab.d.mts +88 -0
  152. package/dist/social-providers/gitlab.mjs +79 -0
  153. package/dist/social-providers/google.d.mts +125 -0
  154. package/dist/social-providers/google.mjs +153 -0
  155. package/dist/social-providers/huggingface.d.mts +77 -0
  156. package/dist/social-providers/huggingface.mjs +73 -0
  157. package/dist/social-providers/index.d.mts +1531 -0
  158. package/dist/social-providers/index.mjs +79 -0
  159. package/dist/social-providers/kakao.d.mts +168 -0
  160. package/dist/social-providers/kakao.mjs +98 -0
  161. package/dist/social-providers/kick.d.mts +59 -0
  162. package/dist/social-providers/kick.mjs +68 -0
  163. package/dist/social-providers/line.d.mts +71 -0
  164. package/dist/social-providers/line.mjs +106 -0
  165. package/dist/social-providers/linear.d.mts +58 -0
  166. package/dist/social-providers/linear.mjs +86 -0
  167. package/dist/social-providers/linkedin.d.mts +51 -0
  168. package/dist/social-providers/linkedin.mjs +73 -0
  169. package/dist/social-providers/microsoft-entra-id.d.mts +195 -0
  170. package/dist/social-providers/microsoft-entra-id.mjs +164 -0
  171. package/dist/social-providers/naver.d.mts +78 -0
  172. package/dist/social-providers/naver.mjs +65 -0
  173. package/dist/social-providers/notion.d.mts +52 -0
  174. package/dist/social-providers/notion.mjs +74 -0
  175. package/dist/social-providers/paybin.d.mts +56 -0
  176. package/dist/social-providers/paybin.mjs +90 -0
  177. package/dist/social-providers/paypal.d.mts +96 -0
  178. package/dist/social-providers/paypal.mjs +118 -0
  179. package/dist/social-providers/polar.d.mts +48 -0
  180. package/dist/social-providers/polar.mjs +70 -0
  181. package/dist/social-providers/railway.d.mts +57 -0
  182. package/dist/social-providers/railway.mjs +74 -0
  183. package/dist/social-providers/reddit.d.mts +50 -0
  184. package/dist/social-providers/reddit.mjs +80 -0
  185. package/dist/social-providers/roblox.d.mts +58 -0
  186. package/dist/social-providers/roblox.mjs +70 -0
  187. package/dist/social-providers/salesforce.d.mts +65 -0
  188. package/dist/social-providers/salesforce.mjs +87 -0
  189. package/dist/social-providers/slack.d.mts +71 -0
  190. package/dist/social-providers/slack.mjs +72 -0
  191. package/dist/social-providers/spotify.d.mts +54 -0
  192. package/dist/social-providers/spotify.mjs +69 -0
  193. package/dist/social-providers/tiktok.d.mts +157 -0
  194. package/dist/social-providers/tiktok.mjs +81 -0
  195. package/dist/social-providers/twitch.d.mts +67 -0
  196. package/dist/social-providers/twitch.mjs +88 -0
  197. package/dist/social-providers/twitter.d.mts +146 -0
  198. package/dist/social-providers/twitter.mjs +91 -0
  199. package/dist/social-providers/vercel.d.mts +56 -0
  200. package/dist/social-providers/vercel.mjs +62 -0
  201. package/dist/social-providers/vk.d.mts +55 -0
  202. package/dist/social-providers/vk.mjs +82 -0
  203. package/dist/social-providers/wechat.d.mts +107 -0
  204. package/dist/social-providers/wechat.mjs +101 -0
  205. package/dist/social-providers/zoom.d.mts +177 -0
  206. package/dist/social-providers/zoom.mjs +63 -0
  207. package/dist/types/context.d.mts +369 -0
  208. package/dist/types/cookie.d.mts +25 -0
  209. package/dist/types/database.d.mts +20 -0
  210. package/dist/types/helper.d.mts +7 -0
  211. package/dist/types/index.d.mts +10 -0
  212. package/dist/types/init-options.d.mts +1579 -0
  213. package/dist/types/plugin-client.d.mts +119 -0
  214. package/dist/types/plugin.d.mts +137 -0
  215. package/dist/types/secret.d.mts +8 -0
  216. package/dist/utils/async.d.mts +18 -0
  217. package/dist/utils/async.mjs +31 -0
  218. package/dist/utils/auth-completion.d.mts +25 -0
  219. package/dist/utils/auth-completion.mjs +32 -0
  220. package/dist/utils/db.d.mts +7 -0
  221. package/dist/utils/db.mjs +14 -0
  222. package/dist/utils/deprecate.d.mts +5 -0
  223. package/dist/utils/deprecate.mjs +15 -0
  224. package/dist/utils/email.d.mts +16 -0
  225. package/dist/utils/email.mjs +17 -0
  226. package/dist/utils/error-codes.d.mts +11 -0
  227. package/dist/utils/error-codes.mjs +9 -0
  228. package/dist/utils/fetch-metadata.d.mts +1 -0
  229. package/dist/utils/fetch-metadata.mjs +5 -0
  230. package/dist/utils/host.d.mts +170 -0
  231. package/dist/utils/host.mjs +306 -0
  232. package/dist/utils/id.d.mts +1 -0
  233. package/dist/utils/id.mjs +6 -0
  234. package/dist/utils/ip.d.mts +76 -0
  235. package/dist/utils/ip.mjs +245 -0
  236. package/dist/utils/is-api-error.d.mts +2 -0
  237. package/dist/utils/is-api-error.mjs +7 -0
  238. package/dist/utils/json.d.mts +1 -0
  239. package/dist/utils/json.mjs +40 -0
  240. package/dist/utils/redirect-uri.d.mts +33 -0
  241. package/dist/utils/redirect-uri.mjs +109 -0
  242. package/dist/utils/state.d.mts +4 -0
  243. package/dist/utils/state.mjs +6 -0
  244. package/dist/utils/string.d.mts +5 -0
  245. package/dist/utils/string.mjs +24 -0
  246. package/dist/utils/url.d.mts +43 -0
  247. package/dist/utils/url.mjs +80 -0
  248. package/package.json +211 -3
  249. package/src/api/index.ts +227 -0
  250. package/src/async_hooks/builtin.ts +8 -0
  251. package/src/async_hooks/index.ts +55 -0
  252. package/src/async_hooks/pure.index.ts +86 -0
  253. package/src/context/endpoint-context.ts +77 -0
  254. package/src/context/global.ts +77 -0
  255. package/src/context/index.ts +25 -0
  256. package/src/context/request-state.ts +93 -0
  257. package/src/context/transaction.ts +255 -0
  258. package/src/db/adapter/atomic-fallback.ts +247 -0
  259. package/src/db/adapter/factory.ts +1679 -0
  260. package/src/db/adapter/get-default-field-name.ts +59 -0
  261. package/src/db/adapter/get-default-model-name.ts +60 -0
  262. package/src/db/adapter/get-field-attributes.ts +62 -0
  263. package/src/db/adapter/get-field-name.ts +43 -0
  264. package/src/db/adapter/get-id-field.ts +212 -0
  265. package/src/db/adapter/get-model-name.ts +36 -0
  266. package/src/db/adapter/index.ts +671 -0
  267. package/src/db/adapter/types.ts +134 -0
  268. package/src/db/adapter/utils.ts +61 -0
  269. package/src/db/database-index.ts +351 -0
  270. package/src/db/errors.ts +45 -0
  271. package/src/db/get-tables.ts +366 -0
  272. package/src/db/index.ts +45 -0
  273. package/src/db/internal.ts +34 -0
  274. package/src/db/plugin.ts +13 -0
  275. package/src/db/schema/account.ts +55 -0
  276. package/src/db/schema/rate-limit.ts +36 -0
  277. package/src/db/schema/session.ts +29 -0
  278. package/src/db/schema/shared.ts +7 -0
  279. package/src/db/schema/user.ts +31 -0
  280. package/src/db/schema/verification.ts +28 -0
  281. package/src/db/schema-check.ts +197 -0
  282. package/src/db/schema-diff.ts +271 -0
  283. package/src/db/type.ts +363 -0
  284. package/src/env/color-depth.ts +172 -0
  285. package/src/env/env-impl.ts +112 -0
  286. package/src/env/index.ts +31 -0
  287. package/src/env/logger.ts +166 -0
  288. package/src/env/runtime.ts +36 -0
  289. package/src/error/codes.ts +77 -0
  290. package/src/error/index.ts +54 -0
  291. package/src/index.ts +1 -0
  292. package/src/instrumentation/api.ts +21 -0
  293. package/src/instrumentation/attributes.ts +24 -0
  294. package/src/instrumentation/index.ts +2 -0
  295. package/src/instrumentation/noop.ts +95 -0
  296. package/src/instrumentation/pure.index.ts +23 -0
  297. package/src/instrumentation/tracer.ts +106 -0
  298. package/src/oauth2/authorization-params.ts +28 -0
  299. package/src/oauth2/basic-credentials.ts +87 -0
  300. package/src/oauth2/client-assertion.ts +267 -0
  301. package/src/oauth2/client-credentials-token.ts +158 -0
  302. package/src/oauth2/create-authorization-url.ts +144 -0
  303. package/src/oauth2/dpop-client.ts +457 -0
  304. package/src/oauth2/dpop-protocol.ts +89 -0
  305. package/src/oauth2/dpop.ts +819 -0
  306. package/src/oauth2/index.ts +123 -0
  307. package/src/oauth2/internal.ts +8 -0
  308. package/src/oauth2/oauth-provider.ts +496 -0
  309. package/src/oauth2/pushed-authorization-request.ts +129 -0
  310. package/src/oauth2/refresh-access-token.ts +220 -0
  311. package/src/oauth2/reject-redirects.ts +54 -0
  312. package/src/oauth2/resolve-host.ts +190 -0
  313. package/src/oauth2/token-endpoint-auth.ts +323 -0
  314. package/src/oauth2/utils.ts +117 -0
  315. package/src/oauth2/validate-authorization-code.ts +228 -0
  316. package/src/oauth2/verify-id-token.ts +176 -0
  317. package/src/oauth2/verify.ts +923 -0
  318. package/src/social-providers/apple.ts +213 -0
  319. package/src/social-providers/atlassian.ts +140 -0
  320. package/src/social-providers/cloudflare.ts +234 -0
  321. package/src/social-providers/cognito.ts +306 -0
  322. package/src/social-providers/discord.ts +200 -0
  323. package/src/social-providers/dropbox.ts +183 -0
  324. package/src/social-providers/facebook.ts +293 -0
  325. package/src/social-providers/figma.ts +125 -0
  326. package/src/social-providers/github.ts +213 -0
  327. package/src/social-providers/gitlab.ts +158 -0
  328. package/src/social-providers/google.ts +322 -0
  329. package/src/social-providers/huggingface.ts +134 -0
  330. package/src/social-providers/index.ts +135 -0
  331. package/src/social-providers/kakao.ts +244 -0
  332. package/src/social-providers/kick.ts +118 -0
  333. package/src/social-providers/line.ts +164 -0
  334. package/src/social-providers/linear.ts +132 -0
  335. package/src/social-providers/linkedin.ts +109 -0
  336. package/src/social-providers/microsoft-entra-id.ts +406 -0
  337. package/src/social-providers/naver.ts +114 -0
  338. package/src/social-providers/notion.ts +116 -0
  339. package/src/social-providers/paybin.ts +141 -0
  340. package/src/social-providers/paypal.ts +237 -0
  341. package/src/social-providers/polar.ts +103 -0
  342. package/src/social-providers/railway.ts +113 -0
  343. package/src/social-providers/reddit.ts +125 -0
  344. package/src/social-providers/roblox.ts +119 -0
  345. package/src/social-providers/salesforce.ts +166 -0
  346. package/src/social-providers/slack.ts +121 -0
  347. package/src/social-providers/spotify.ts +108 -0
  348. package/src/social-providers/tiktok.ts +247 -0
  349. package/src/social-providers/twitch.ts +150 -0
  350. package/src/social-providers/twitter.ts +231 -0
  351. package/src/social-providers/vercel.ts +127 -0
  352. package/src/social-providers/vk.ts +134 -0
  353. package/src/social-providers/wechat.ts +247 -0
  354. package/src/social-providers/zoom.ts +233 -0
  355. package/src/types/context.ts +524 -0
  356. package/src/types/cookie.ts +23 -0
  357. package/src/types/database.ts +21 -0
  358. package/src/types/helper.ts +27 -0
  359. package/src/types/index.ts +50 -0
  360. package/src/types/init-options.ts +1849 -0
  361. package/src/types/plugin-client.ts +143 -0
  362. package/src/types/plugin.ts +180 -0
  363. package/src/types/secret.ts +8 -0
  364. package/src/utils/async.ts +53 -0
  365. package/src/utils/auth-completion.ts +66 -0
  366. package/src/utils/db.ts +20 -0
  367. package/src/utils/deprecate.ts +21 -0
  368. package/src/utils/email.ts +36 -0
  369. package/src/utils/error-codes.ts +68 -0
  370. package/src/utils/fetch-metadata.ts +3 -0
  371. package/src/utils/host.ts +428 -0
  372. package/src/utils/id.ts +5 -0
  373. package/src/utils/ip.ts +416 -0
  374. package/src/utils/is-api-error.ts +10 -0
  375. package/src/utils/json.ts +56 -0
  376. package/src/utils/redirect-uri.ts +139 -0
  377. package/src/utils/state.ts +5 -0
  378. package/src/utils/string.ts +40 -0
  379. package/src/utils/url.ts +120 -0
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2024 - present, Bereket Engida
3
+
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:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
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 CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # Entro Auth Core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Core utilities and types for [Entro Auth](https://www.better-auth.com) — the most comprehensive authentication framework for TypeScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @entro314labs/entro-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
@@ -0,0 +1,298 @@
1
+ import { EntroAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
2
+ import "../oauth2/index.mjs";
3
+ import { createLogger } from "../env/logger.mjs";
4
+ import { DBAdapter } from "../db/adapter/index.mjs";
5
+ import { SchemaCheck } from "../db/schema-check.mjs";
6
+ import { AuthContext } from "../types/context.mjs";
7
+ import "../db/index.mjs";
8
+ import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
9
+ import "../types/index.mjs";
10
+ import { EndpointHandler, EndpointOptions, MiddlewareHandler, StrictEndpoint } from "better-call";
11
+ /**
12
+ * Response headers that forbid any intermediary (proxy, CDN, browser) from
13
+ * caching a response body. Credential-bearing responses (access/refresh tokens,
14
+ * ID tokens, client secrets, device codes) must carry them.
15
+ *
16
+ * Set `metadata: { noStore: true }` on an endpoint and {@link createAuthEndpoint}
17
+ * applies these to the responses its handler produces: the success body and any
18
+ * error the handler throws. A request rejected by schema or media-type
19
+ * validation before the handler runs is not covered, and carries no credentials
20
+ * to protect. Spread them into a hand-built `Response` or `APIError`'s headers
21
+ * for the rare endpoint that constructs its own response.
22
+ *
23
+ * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
24
+ */
25
+ export declare const NO_STORE_HEADERS: {
26
+ readonly "Cache-Control": "no-store";
27
+ readonly Pragma: "no-cache";
28
+ };
29
+ export declare const HIDE_METADATA: {
30
+ readonly scope: "server";
31
+ };
32
+ export declare const optionsMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, <InputCtx extends import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>>;
33
+ export declare const createAuthMiddleware: {
34
+ <Options extends import("better-call").MiddlewareOptions, R>(options: Options, handler: (ctx: import("better-call").MiddlewareContext<Options, import("@entro314labs/entro-auth-core").PluginContext<import("@entro314labs/entro-auth-core").EntroAuthOptions> & import("@entro314labs/entro-auth-core").InfoContext & {
35
+ options: import("@entro314labs/entro-auth-core").EntroAuthOptions;
36
+ trustedOrigins: string[];
37
+ trustedProviders: string[];
38
+ isTrustedOrigin: (url: string, settings?: {
39
+ allowRelativePaths: boolean;
40
+ }) => boolean;
41
+ oauthConfig: {
42
+ skipStateCookieCheck?: boolean | undefined;
43
+ storeStateStrategy: "database" | "cookie";
44
+ };
45
+ newSession: {
46
+ session: {
47
+ id: string;
48
+ createdAt: Date;
49
+ updatedAt: Date;
50
+ userId: string;
51
+ expiresAt: Date;
52
+ token: string;
53
+ ipAddress?: string | null | undefined;
54
+ userAgent?: string | null | undefined;
55
+ } & Record<string, any>;
56
+ user: {
57
+ id: string;
58
+ createdAt: Date;
59
+ updatedAt: Date;
60
+ email: string;
61
+ emailVerified: boolean;
62
+ name: string;
63
+ image?: string | null | undefined;
64
+ } & Record<string, any>;
65
+ } | null;
66
+ session: {
67
+ session: {
68
+ id: string;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ userId: string;
72
+ expiresAt: Date;
73
+ token: string;
74
+ ipAddress?: string | null | undefined;
75
+ userAgent?: string | null | undefined;
76
+ } & Record<string, any>;
77
+ user: {
78
+ id: string;
79
+ createdAt: Date;
80
+ updatedAt: Date;
81
+ email: string;
82
+ emailVerified: boolean;
83
+ name: string;
84
+ image?: string | null | undefined;
85
+ } & Record<string, any>;
86
+ } | null;
87
+ setNewSession: (session: {
88
+ session: {
89
+ id: string;
90
+ createdAt: Date;
91
+ updatedAt: Date;
92
+ userId: string;
93
+ expiresAt: Date;
94
+ token: string;
95
+ ipAddress?: string | null | undefined;
96
+ userAgent?: string | null | undefined;
97
+ } & Record<string, any>;
98
+ user: {
99
+ id: string;
100
+ createdAt: Date;
101
+ updatedAt: Date;
102
+ email: string;
103
+ emailVerified: boolean;
104
+ name: string;
105
+ image?: string | null | undefined;
106
+ } & Record<string, any>;
107
+ } | null) => void;
108
+ socialProviders: OAuthProvider[];
109
+ authCookies: import("@entro314labs/entro-auth-core").EntroAuthCookies;
110
+ logger: ReturnType<typeof createLogger>;
111
+ rateLimit: {
112
+ enabled: boolean;
113
+ window: number;
114
+ max: number;
115
+ storage: "memory" | "database" | "secondary-storage";
116
+ } & Omit<import("@entro314labs/entro-auth-core").EntroAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
117
+ adapter: DBAdapter<import("@entro314labs/entro-auth-core").EntroAuthOptions>;
118
+ checkSchema?: SchemaCheck | undefined;
119
+ explicitSchemaCheck?: SchemaCheck | undefined;
120
+ internalAdapter: import("@entro314labs/entro-auth-core").InternalAdapter<import("@entro314labs/entro-auth-core").EntroAuthOptions>;
121
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@entro314labs/entro-auth-core").EntroAuthCookie;
122
+ secret: string;
123
+ secretConfig: string | import("@entro314labs/entro-auth-core").SecretConfig;
124
+ sessionConfig: {
125
+ updateAge: number;
126
+ expiresIn: number;
127
+ freshAge: number;
128
+ cookieCacheSigner?: import("@entro314labs/entro-auth-core").CookieCacheSigner | undefined;
129
+ cookieRefreshCache: false | {
130
+ enabled: true;
131
+ updateAge: number;
132
+ };
133
+ };
134
+ generateId: (options: {
135
+ model: ModelNames;
136
+ size?: number | undefined;
137
+ }) => string | false;
138
+ secondaryStorage: SecondaryStorage | undefined;
139
+ password: {
140
+ hash: (password: string) => Promise<string>;
141
+ verify: (data: {
142
+ password: string;
143
+ hash: string;
144
+ }) => Promise<boolean>;
145
+ config: {
146
+ minPasswordLength: number;
147
+ maxPasswordLength: number;
148
+ };
149
+ checkPassword: (userId: string, ctx: import("@entro314labs/entro-auth-core").GenericEndpointContext<import("@entro314labs/entro-auth-core").EntroAuthOptions>) => Promise<boolean>;
150
+ };
151
+ tables: EntroAuthDBSchema;
152
+ runMigrations: () => Promise<void>;
153
+ skipOriginCheck: boolean | string[];
154
+ skipCSRFCheck: boolean;
155
+ runInBackground: (promise: Promise<unknown>) => void;
156
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@entro314labs/entro-auth-core").Awaitable<unknown>;
157
+ } & {
158
+ returned?: unknown | undefined;
159
+ responseHeaders?: Headers | undefined;
160
+ }>) => Promise<R>): import("better-call").Middleware<Options, (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R>>;
161
+ <Options extends import("better-call").MiddlewareOptions, R_1>(handler: (ctx: import("better-call").MiddlewareContext<Options, import("@entro314labs/entro-auth-core").PluginContext<import("@entro314labs/entro-auth-core").EntroAuthOptions> & import("@entro314labs/entro-auth-core").InfoContext & {
162
+ options: import("@entro314labs/entro-auth-core").EntroAuthOptions;
163
+ trustedOrigins: string[];
164
+ trustedProviders: string[];
165
+ isTrustedOrigin: (url: string, settings?: {
166
+ allowRelativePaths: boolean;
167
+ }) => boolean;
168
+ oauthConfig: {
169
+ skipStateCookieCheck?: boolean | undefined;
170
+ storeStateStrategy: "database" | "cookie";
171
+ };
172
+ newSession: {
173
+ session: {
174
+ id: string;
175
+ createdAt: Date;
176
+ updatedAt: Date;
177
+ userId: string;
178
+ expiresAt: Date;
179
+ token: string;
180
+ ipAddress?: string | null | undefined;
181
+ userAgent?: string | null | undefined;
182
+ } & Record<string, any>;
183
+ user: {
184
+ id: string;
185
+ createdAt: Date;
186
+ updatedAt: Date;
187
+ email: string;
188
+ emailVerified: boolean;
189
+ name: string;
190
+ image?: string | null | undefined;
191
+ } & Record<string, any>;
192
+ } | null;
193
+ session: {
194
+ session: {
195
+ id: string;
196
+ createdAt: Date;
197
+ updatedAt: Date;
198
+ userId: string;
199
+ expiresAt: Date;
200
+ token: string;
201
+ ipAddress?: string | null | undefined;
202
+ userAgent?: string | null | undefined;
203
+ } & Record<string, any>;
204
+ user: {
205
+ id: string;
206
+ createdAt: Date;
207
+ updatedAt: Date;
208
+ email: string;
209
+ emailVerified: boolean;
210
+ name: string;
211
+ image?: string | null | undefined;
212
+ } & Record<string, any>;
213
+ } | null;
214
+ setNewSession: (session: {
215
+ session: {
216
+ id: string;
217
+ createdAt: Date;
218
+ updatedAt: Date;
219
+ userId: string;
220
+ expiresAt: Date;
221
+ token: string;
222
+ ipAddress?: string | null | undefined;
223
+ userAgent?: string | null | undefined;
224
+ } & Record<string, any>;
225
+ user: {
226
+ id: string;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+ email: string;
230
+ emailVerified: boolean;
231
+ name: string;
232
+ image?: string | null | undefined;
233
+ } & Record<string, any>;
234
+ } | null) => void;
235
+ socialProviders: OAuthProvider[];
236
+ authCookies: import("@entro314labs/entro-auth-core").EntroAuthCookies;
237
+ logger: ReturnType<typeof createLogger>;
238
+ rateLimit: {
239
+ enabled: boolean;
240
+ window: number;
241
+ max: number;
242
+ storage: "memory" | "database" | "secondary-storage";
243
+ } & Omit<import("@entro314labs/entro-auth-core").EntroAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
244
+ adapter: DBAdapter<import("@entro314labs/entro-auth-core").EntroAuthOptions>;
245
+ checkSchema?: SchemaCheck | undefined;
246
+ explicitSchemaCheck?: SchemaCheck | undefined;
247
+ internalAdapter: import("@entro314labs/entro-auth-core").InternalAdapter<import("@entro314labs/entro-auth-core").EntroAuthOptions>;
248
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@entro314labs/entro-auth-core").EntroAuthCookie;
249
+ secret: string;
250
+ secretConfig: string | import("@entro314labs/entro-auth-core").SecretConfig;
251
+ sessionConfig: {
252
+ updateAge: number;
253
+ expiresIn: number;
254
+ freshAge: number;
255
+ cookieCacheSigner?: import("@entro314labs/entro-auth-core").CookieCacheSigner | undefined;
256
+ cookieRefreshCache: false | {
257
+ enabled: true;
258
+ updateAge: number;
259
+ };
260
+ };
261
+ generateId: (options: {
262
+ model: ModelNames;
263
+ size?: number | undefined;
264
+ }) => string | false;
265
+ secondaryStorage: SecondaryStorage | undefined;
266
+ password: {
267
+ hash: (password: string) => Promise<string>;
268
+ verify: (data: {
269
+ password: string;
270
+ hash: string;
271
+ }) => Promise<boolean>;
272
+ config: {
273
+ minPasswordLength: number;
274
+ maxPasswordLength: number;
275
+ };
276
+ checkPassword: (userId: string, ctx: import("@entro314labs/entro-auth-core").GenericEndpointContext<import("@entro314labs/entro-auth-core").EntroAuthOptions>) => Promise<boolean>;
277
+ };
278
+ tables: EntroAuthDBSchema;
279
+ runMigrations: () => Promise<void>;
280
+ skipOriginCheck: boolean | string[];
281
+ skipCSRFCheck: boolean;
282
+ runInBackground: (promise: Promise<unknown>) => void;
283
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@entro314labs/entro-auth-core").Awaitable<unknown>;
284
+ } & {
285
+ returned?: unknown | undefined;
286
+ responseHeaders?: Headers | undefined;
287
+ }>) => Promise<R_1>): import("better-call").Middleware<Options, (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R_1>>;
288
+ };
289
+ type AuthEndpointHandler<Path extends string, Options extends EndpointOptions, R> = EndpointHandler<Path, Options, R, AuthContext>;
290
+ type PathlessAuthEndpointHandler<Options extends EndpointOptions, R> = AuthEndpointHandler<string, Options, R>;
291
+ export declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: AuthEndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
292
+ export declare function createAuthEndpoint<InferredPath extends string, Options extends EndpointOptions, R>(options: Options, handler: PathlessAuthEndpointHandler<Options, R>): StrictEndpoint<InferredPath, Options, R>;
293
+ export declare namespace createAuthEndpoint {
294
+ var serverOnly: <InferredPath extends string, Options extends EndpointOptions, R>(options: Options, handler: PathlessAuthEndpointHandler<Options, R>) => StrictEndpoint<InferredPath, Options, R>;
295
+ }
296
+ export type AuthEndpoint<Path extends string, Opts extends EndpointOptions, R> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
297
+ export type AuthMiddleware = MiddlewareHandler;
298
+ export {};
@@ -0,0 +1,108 @@
1
+ import { runWithEndpointContext } from "../context/endpoint-context.mjs";
2
+ import { isAPIError } from "../utils/is-api-error.mjs";
3
+ import { createEndpoint, createMiddleware, kAPIErrorHeaderSymbol } from "better-call";
4
+ // src/api/index.ts
5
+ /**
6
+ * Response headers that forbid any intermediary (proxy, CDN, browser) from
7
+ * caching a response body. Credential-bearing responses (access/refresh tokens,
8
+ * ID tokens, client secrets, device codes) must carry them.
9
+ *
10
+ * Set `metadata: { noStore: true }` on an endpoint and {@link createAuthEndpoint}
11
+ * applies these to the responses its handler produces: the success body and any
12
+ * error the handler throws. A request rejected by schema or media-type
13
+ * validation before the handler runs is not covered, and carries no credentials
14
+ * to protect. Spread them into a hand-built `Response` or `APIError`'s headers
15
+ * for the rare endpoint that constructs its own response.
16
+ *
17
+ * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
18
+ */
19
+ const NO_STORE_HEADERS = {
20
+ "Cache-Control": "no-store",
21
+ Pragma: "no-cache"
22
+ };
23
+ const HIDE_METADATA = { scope: "server" };
24
+ /**
25
+ * Better-call's createEndpoint re-throws APIError without exposing the headers
26
+ * accumulated on ctx.responseHeaders (e.g. Set-Cookie from deleteSessionCookie
27
+ * before throw). Attach them to the error via kAPIErrorHeaderSymbol — matching
28
+ * better-call's createMiddleware contract so the outer pipeline can merge them
29
+ * into the response.
30
+ */
31
+ function attachResponseHeadersToAPIError(responseHeaders, e) {
32
+ if (!isAPIError(e) || !responseHeaders) return;
33
+ Object.defineProperty(e, kAPIErrorHeaderSymbol, {
34
+ enumerable: false,
35
+ configurable: true,
36
+ value: responseHeaders,
37
+ writable: false
38
+ });
39
+ }
40
+ const optionsMiddleware = createMiddleware(async () => {
41
+ /**
42
+ * This will be passed on the instance of
43
+ * the context. Used to infer the type
44
+ * here.
45
+ */
46
+ return {};
47
+ });
48
+ const createAuthMiddleware = createMiddleware.create({ use: [optionsMiddleware, createMiddleware(async () => {
49
+ return {};
50
+ })] });
51
+ const createEndpointWithAuthContext = createEndpoint.create({ use: [optionsMiddleware] });
52
+ function wrapEndpointHandler(handler, options) {
53
+ const noStore = options.metadata?.noStore === true;
54
+ return async (context) => {
55
+ if (noStore) for (const [name, value] of Object.entries(NO_STORE_HEADERS)) context.setHeader(name, value);
56
+ try {
57
+ return await runWithEndpointContext(context, () => handler(context));
58
+ } catch (error) {
59
+ attachResponseHeadersToAPIError(context.responseHeaders, error);
60
+ throw error;
61
+ }
62
+ };
63
+ }
64
+ function createAuthEndpoint(...args) {
65
+ if (args.length === 3) {
66
+ const [path, options, handler] = args;
67
+ return createEndpointWithAuthContext(path, options, wrapEndpointHandler(handler, options));
68
+ }
69
+ const [options, handler] = args;
70
+ return createEndpointWithAuthContext(options, wrapEndpointHandler(handler, options));
71
+ }
72
+ /**
73
+ * Set `metadata.SERVER_ONLY` while preserving any existing metadata
74
+ * (`$Infer`, `openapi`, ...).
75
+ */
76
+ function withServerOnly(options) {
77
+ return {
78
+ ...options,
79
+ metadata: {
80
+ ...options.metadata,
81
+ SERVER_ONLY: true
82
+ }
83
+ };
84
+ }
85
+ /**
86
+ * Declare a **server-only** endpoint.
87
+ *
88
+ * The endpoint is callable through `auth.api.*` from trusted server code but is
89
+ * never registered on the HTTP router and never emitted into the OpenAPI
90
+ * schema. It takes no path because it has no URL to be reached at.
91
+ *
92
+ * Prefer this over the path-less `createAuthEndpoint({ ... }, handler)` form.
93
+ * Setting `metadata.SERVER_ONLY` makes the intent explicit at the call site and
94
+ * keeps the endpoint off the HTTP surface even if a path is later added by
95
+ * mistake: better-call's router skips an endpoint when its path is missing *or*
96
+ * when `SERVER_ONLY` is set, so the two together are defense in depth. Relying
97
+ * on path omission alone is invisible and one keystroke away from exposure.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * viewBackupCodes: createAuthEndpoint.serverOnly(
102
+ * { method: "POST", body: schema },
103
+ * async (ctx) => { ... },
104
+ * )
105
+ * ```
106
+ */
107
+ createAuthEndpoint.serverOnly = (options, handler) => createAuthEndpoint(withServerOnly(options), handler);
108
+ export { HIDE_METADATA, NO_STORE_HEADERS, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -0,0 +1,9 @@
1
+ // src/async_hooks/builtin.ts
2
+ function getBuiltinAsyncLocalStorage() {
3
+ try {
4
+ return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage;
5
+ } catch {
6
+ return;
7
+ }
8
+ }
9
+ export { getBuiltinAsyncLocalStorage };
@@ -0,0 +1,3 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
3
+ export type { AsyncLocalStorage };
@@ -0,0 +1,36 @@
1
+ import { getBuiltinAsyncLocalStorage } from "./builtin.mjs";
2
+ // src/async_hooks/index.ts
3
+ let cachedAsyncLocalStorageConstructor;
4
+ let availabilityWarningLogged = false;
5
+ async function getAsyncLocalStorage() {
6
+ if (cachedAsyncLocalStorageConstructor) return cachedAsyncLocalStorageConstructor;
7
+ const builtinConstructor = getBuiltinAsyncLocalStorage();
8
+ if (builtinConstructor) {
9
+ cachedAsyncLocalStorageConstructor ??= builtinConstructor;
10
+ return cachedAsyncLocalStorageConstructor;
11
+ }
12
+ try {
13
+ const { AsyncLocalStorage: constructor } = await import(
14
+ /* @vite-ignore */
15
+ /* webpackIgnore: true */
16
+ "node:async_hooks"
17
+ );
18
+ cachedAsyncLocalStorageConstructor ??= constructor;
19
+ return cachedAsyncLocalStorageConstructor;
20
+ } catch (err) {
21
+ const constructor = globalThis.AsyncLocalStorage;
22
+ if (typeof constructor === "function") {
23
+ cachedAsyncLocalStorageConstructor ??= constructor;
24
+ return cachedAsyncLocalStorageConstructor;
25
+ }
26
+ if (typeof window !== "undefined") throw new Error("getAsyncLocalStorage is only available in server code");
27
+ if (!availabilityWarningLogged) {
28
+ availabilityWarningLogged = true;
29
+ console.warn("[entro-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.");
30
+ console.warn("[entro-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler");
31
+ console.warn("[entro-auth] If you are using Cloudflare Workers, please see: https://better-auth.com/docs/guides/cloudflare#nodejs-compatibility");
32
+ }
33
+ throw err;
34
+ }
35
+ }
36
+ export { getAsyncLocalStorage };
@@ -0,0 +1,2 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
@@ -0,0 +1,57 @@
1
+ import { getBuiltinAsyncLocalStorage } from "./builtin.mjs";
2
+ // src/async_hooks/pure.index.ts
3
+ /**
4
+ * Due to the lack of AsyncLocalStorage in some environments (like Convex),
5
+ *
6
+ * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.
7
+ */
8
+ var AsyncLocalStoragePolyfill = class {
9
+ #current;
10
+ run(store, fn) {
11
+ const frame = {
12
+ store,
13
+ parent: this.#current
14
+ };
15
+ if (this.#current) this.#current.child = frame;
16
+ this.#current = frame;
17
+ const leave = () => {
18
+ const { parent, child } = frame;
19
+ if (parent) parent.child = child;
20
+ if (child) {
21
+ child.parent = parent;
22
+ return;
23
+ }
24
+ this.#current = parent;
25
+ };
26
+ try {
27
+ const result = fn();
28
+ if (result instanceof Promise) return result.finally(leave);
29
+ leave();
30
+ return result;
31
+ } catch (error) {
32
+ leave();
33
+ throw error;
34
+ }
35
+ }
36
+ getStore() {
37
+ return this.#current?.store;
38
+ }
39
+ };
40
+ let cachedAsyncLocalStorageConstructor;
41
+ async function getAsyncLocalStorage() {
42
+ if (cachedAsyncLocalStorageConstructor) return cachedAsyncLocalStorageConstructor;
43
+ if ("AsyncLocalStorage" in globalThis) {
44
+ const constructor = globalThis.AsyncLocalStorage;
45
+ if (typeof constructor !== "function") throw new Error(`Invalid globalThis.AsyncLocalStorage: expected a function, received ${typeof constructor}.`);
46
+ cachedAsyncLocalStorageConstructor ??= constructor;
47
+ return cachedAsyncLocalStorageConstructor;
48
+ }
49
+ const builtinConstructor = getBuiltinAsyncLocalStorage();
50
+ if (builtinConstructor) {
51
+ cachedAsyncLocalStorageConstructor ??= builtinConstructor;
52
+ return cachedAsyncLocalStorageConstructor;
53
+ }
54
+ cachedAsyncLocalStorageConstructor ??= AsyncLocalStoragePolyfill;
55
+ return cachedAsyncLocalStorageConstructor;
56
+ }
57
+ export { getAsyncLocalStorage };
@@ -0,0 +1,30 @@
1
+ import { AuthContext } from "../types/context.mjs";
2
+ import "../types/index.mjs";
3
+ import { EndpointContext, InputContext } from "better-call";
4
+ import { AsyncLocalStorage } from "@entro314labs/entro-auth-core/async_hooks";
5
+ export type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
6
+ context: AuthContext;
7
+ };
8
+ type AuthEndpointContextStorage = AsyncLocalStorage<AuthEndpointContext>;
9
+ /**
10
+ * @deprecated Use `getCurrentAuthEndpointContext`,
11
+ * `tryGetCurrentAuthEndpointContext`, or `runWithEndpointContext` instead.
12
+ */
13
+ export declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AuthEndpointContextStorage>;
14
+ /**
15
+ * Returns the current auth endpoint context, or `undefined` when called outside
16
+ * of `runWithEndpointContext`.
17
+ */
18
+ export declare function tryGetCurrentAuthEndpointContext(): AuthEndpointContext | undefined;
19
+ /**
20
+ * Returns the current auth endpoint context.
21
+ *
22
+ * @throws When called outside of `runWithEndpointContext`.
23
+ */
24
+ export declare function getCurrentAuthEndpointContext(): AuthEndpointContext;
25
+ /**
26
+ * @deprecated Use `getCurrentAuthEndpointContext` instead.
27
+ */
28
+ export declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
29
+ export declare function runWithEndpointContext<T>(authEndpointContext: AuthEndpointContext, fn: () => T): Promise<T>;
30
+ export {};
@@ -0,0 +1,47 @@
1
+ import { __getCurrentEndpointContext, __getEntroAuthGlobal } from "./global.mjs";
2
+ import { getAsyncLocalStorage } from "@entro314labs/entro-auth-core/async_hooks";
3
+ // src/context/endpoint-context.ts
4
+ const getExistingEndpointContextStorage = () => {
5
+ return __getEntroAuthGlobal().context.endpointContextAsyncStorage;
6
+ };
7
+ const getOrCreateEndpointContextStorage = async () => {
8
+ const existing = getExistingEndpointContextStorage();
9
+ if (existing) return existing;
10
+ const AsyncLocalStorage = await getAsyncLocalStorage();
11
+ const globalContext = __getEntroAuthGlobal().context;
12
+ return globalContext.endpointContextAsyncStorage ??= new AsyncLocalStorage();
13
+ };
14
+ /**
15
+ * @deprecated Use `getCurrentAuthEndpointContext`,
16
+ * `tryGetCurrentAuthEndpointContext`, or `runWithEndpointContext` instead.
17
+ */
18
+ async function getCurrentAuthContextAsyncLocalStorage() {
19
+ return getOrCreateEndpointContextStorage();
20
+ }
21
+ /**
22
+ * Returns the current auth endpoint context, or `undefined` when called outside
23
+ * of `runWithEndpointContext`.
24
+ */
25
+ function tryGetCurrentAuthEndpointContext() {
26
+ return __getCurrentEndpointContext();
27
+ }
28
+ /**
29
+ * Returns the current auth endpoint context.
30
+ *
31
+ * @throws When called outside of `runWithEndpointContext`.
32
+ */
33
+ function getCurrentAuthEndpointContext() {
34
+ const authEndpointContext = tryGetCurrentAuthEndpointContext();
35
+ if (!authEndpointContext) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
36
+ return authEndpointContext;
37
+ }
38
+ /**
39
+ * @deprecated Use `getCurrentAuthEndpointContext` instead.
40
+ */
41
+ async function getCurrentAuthContext() {
42
+ return getCurrentAuthEndpointContext();
43
+ }
44
+ async function runWithEndpointContext(authEndpointContext, fn) {
45
+ return (await getOrCreateEndpointContextStorage()).run(authEndpointContext, fn);
46
+ }
47
+ export { getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentAuthEndpointContext, runWithEndpointContext, tryGetCurrentAuthEndpointContext };
@@ -0,0 +1,2 @@
1
+ import { AsyncLocalStorage } from "@entro314labs/entro-auth-core/async_hooks";
2
+ export declare function getEntroAuthVersion(): string;