@hammadj/better-auth 1.5.0-beta.9

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 (688) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +33 -0
  3. package/dist/_virtual/rolldown_runtime.mjs +36 -0
  4. package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
  5. package/dist/adapters/drizzle-adapter/index.mjs +3 -0
  6. package/dist/adapters/index.d.mts +23 -0
  7. package/dist/adapters/index.mjs +13 -0
  8. package/dist/adapters/index.mjs.map +1 -0
  9. package/dist/adapters/kysely-adapter/index.d.mts +1 -0
  10. package/dist/adapters/kysely-adapter/index.mjs +3 -0
  11. package/dist/adapters/memory-adapter/index.d.mts +1 -0
  12. package/dist/adapters/memory-adapter/index.mjs +3 -0
  13. package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
  14. package/dist/adapters/mongodb-adapter/index.mjs +3 -0
  15. package/dist/adapters/prisma-adapter/index.d.mts +1 -0
  16. package/dist/adapters/prisma-adapter/index.mjs +3 -0
  17. package/dist/api/index.d.mts +40 -0
  18. package/dist/api/index.mjs +205 -0
  19. package/dist/api/index.mjs.map +1 -0
  20. package/dist/api/middlewares/index.d.mts +1 -0
  21. package/dist/api/middlewares/index.mjs +3 -0
  22. package/dist/api/middlewares/origin-check.d.mts +17 -0
  23. package/dist/api/middlewares/origin-check.mjs +140 -0
  24. package/dist/api/middlewares/origin-check.mjs.map +1 -0
  25. package/dist/api/rate-limiter/index.mjs +177 -0
  26. package/dist/api/rate-limiter/index.mjs.map +1 -0
  27. package/dist/api/routes/account.d.mts +10 -0
  28. package/dist/api/routes/account.mjs +493 -0
  29. package/dist/api/routes/account.mjs.map +1 -0
  30. package/dist/api/routes/callback.d.mts +5 -0
  31. package/dist/api/routes/callback.mjs +178 -0
  32. package/dist/api/routes/callback.mjs.map +1 -0
  33. package/dist/api/routes/email-verification.d.mts +29 -0
  34. package/dist/api/routes/email-verification.mjs +301 -0
  35. package/dist/api/routes/email-verification.mjs.map +1 -0
  36. package/dist/api/routes/error.d.mts +5 -0
  37. package/dist/api/routes/error.mjs +386 -0
  38. package/dist/api/routes/error.mjs.map +1 -0
  39. package/dist/api/routes/index.d.mts +11 -0
  40. package/dist/api/routes/index.mjs +13 -0
  41. package/dist/api/routes/ok.d.mts +5 -0
  42. package/dist/api/routes/ok.mjs +30 -0
  43. package/dist/api/routes/ok.mjs.map +1 -0
  44. package/dist/api/routes/password.d.mts +8 -0
  45. package/dist/api/routes/password.mjs +198 -0
  46. package/dist/api/routes/password.mjs.map +1 -0
  47. package/dist/api/routes/session.d.mts +52 -0
  48. package/dist/api/routes/session.mjs +478 -0
  49. package/dist/api/routes/session.mjs.map +1 -0
  50. package/dist/api/routes/sign-in.d.mts +8 -0
  51. package/dist/api/routes/sign-in.mjs +262 -0
  52. package/dist/api/routes/sign-in.mjs.map +1 -0
  53. package/dist/api/routes/sign-out.d.mts +5 -0
  54. package/dist/api/routes/sign-out.mjs +33 -0
  55. package/dist/api/routes/sign-out.mjs.map +1 -0
  56. package/dist/api/routes/sign-up.d.mts +7 -0
  57. package/dist/api/routes/sign-up.mjs +227 -0
  58. package/dist/api/routes/sign-up.mjs.map +1 -0
  59. package/dist/api/routes/update-user.d.mts +12 -0
  60. package/dist/api/routes/update-user.mjs +493 -0
  61. package/dist/api/routes/update-user.mjs.map +1 -0
  62. package/dist/api/state/oauth.d.mts +5 -0
  63. package/dist/api/state/oauth.mjs +8 -0
  64. package/dist/api/state/oauth.mjs.map +1 -0
  65. package/dist/api/state/should-session-refresh.d.mts +13 -0
  66. package/dist/api/state/should-session-refresh.mjs +16 -0
  67. package/dist/api/state/should-session-refresh.mjs.map +1 -0
  68. package/dist/api/to-auth-endpoints.mjs +197 -0
  69. package/dist/api/to-auth-endpoints.mjs.map +1 -0
  70. package/dist/auth/base.mjs +44 -0
  71. package/dist/auth/base.mjs.map +1 -0
  72. package/dist/auth/full.d.mts +30 -0
  73. package/dist/auth/full.mjs +32 -0
  74. package/dist/auth/full.mjs.map +1 -0
  75. package/dist/auth/minimal.d.mts +12 -0
  76. package/dist/auth/minimal.mjs +14 -0
  77. package/dist/auth/minimal.mjs.map +1 -0
  78. package/dist/auth/trusted-origins.mjs +31 -0
  79. package/dist/auth/trusted-origins.mjs.map +1 -0
  80. package/dist/client/broadcast-channel.d.mts +20 -0
  81. package/dist/client/broadcast-channel.mjs +46 -0
  82. package/dist/client/broadcast-channel.mjs.map +1 -0
  83. package/dist/client/config.mjs +90 -0
  84. package/dist/client/config.mjs.map +1 -0
  85. package/dist/client/fetch-plugins.mjs +18 -0
  86. package/dist/client/fetch-plugins.mjs.map +1 -0
  87. package/dist/client/focus-manager.d.mts +11 -0
  88. package/dist/client/focus-manager.mjs +32 -0
  89. package/dist/client/focus-manager.mjs.map +1 -0
  90. package/dist/client/index.d.mts +30 -0
  91. package/dist/client/index.mjs +21 -0
  92. package/dist/client/index.mjs.map +1 -0
  93. package/dist/client/lynx/index.d.mts +62 -0
  94. package/dist/client/lynx/index.mjs +24 -0
  95. package/dist/client/lynx/index.mjs.map +1 -0
  96. package/dist/client/lynx/lynx-store.d.mts +47 -0
  97. package/dist/client/lynx/lynx-store.mjs +47 -0
  98. package/dist/client/lynx/lynx-store.mjs.map +1 -0
  99. package/dist/client/online-manager.d.mts +12 -0
  100. package/dist/client/online-manager.mjs +35 -0
  101. package/dist/client/online-manager.mjs.map +1 -0
  102. package/dist/client/parser.mjs +73 -0
  103. package/dist/client/parser.mjs.map +1 -0
  104. package/dist/client/path-to-object.d.mts +57 -0
  105. package/dist/client/plugins/index.d.mts +58 -0
  106. package/dist/client/plugins/index.mjs +33 -0
  107. package/dist/client/plugins/infer-plugin.d.mts +9 -0
  108. package/dist/client/plugins/infer-plugin.mjs +11 -0
  109. package/dist/client/plugins/infer-plugin.mjs.map +1 -0
  110. package/dist/client/proxy.mjs +79 -0
  111. package/dist/client/proxy.mjs.map +1 -0
  112. package/dist/client/query.d.mts +23 -0
  113. package/dist/client/query.mjs +98 -0
  114. package/dist/client/query.mjs.map +1 -0
  115. package/dist/client/react/index.d.mts +63 -0
  116. package/dist/client/react/index.mjs +24 -0
  117. package/dist/client/react/index.mjs.map +1 -0
  118. package/dist/client/react/react-store.d.mts +47 -0
  119. package/dist/client/react/react-store.mjs +47 -0
  120. package/dist/client/react/react-store.mjs.map +1 -0
  121. package/dist/client/session-atom.mjs +29 -0
  122. package/dist/client/session-atom.mjs.map +1 -0
  123. package/dist/client/session-refresh.d.mts +28 -0
  124. package/dist/client/session-refresh.mjs +140 -0
  125. package/dist/client/session-refresh.mjs.map +1 -0
  126. package/dist/client/solid/index.d.mts +57 -0
  127. package/dist/client/solid/index.mjs +22 -0
  128. package/dist/client/solid/index.mjs.map +1 -0
  129. package/dist/client/solid/solid-store.mjs +24 -0
  130. package/dist/client/solid/solid-store.mjs.map +1 -0
  131. package/dist/client/svelte/index.d.mts +63 -0
  132. package/dist/client/svelte/index.mjs +20 -0
  133. package/dist/client/svelte/index.mjs.map +1 -0
  134. package/dist/client/types.d.mts +58 -0
  135. package/dist/client/vanilla.d.mts +62 -0
  136. package/dist/client/vanilla.mjs +20 -0
  137. package/dist/client/vanilla.mjs.map +1 -0
  138. package/dist/client/vue/index.d.mts +86 -0
  139. package/dist/client/vue/index.mjs +38 -0
  140. package/dist/client/vue/index.mjs.map +1 -0
  141. package/dist/client/vue/vue-store.mjs +26 -0
  142. package/dist/client/vue/vue-store.mjs.map +1 -0
  143. package/dist/context/create-context.mjs +211 -0
  144. package/dist/context/create-context.mjs.map +1 -0
  145. package/dist/context/helpers.mjs +62 -0
  146. package/dist/context/helpers.mjs.map +1 -0
  147. package/dist/context/init-minimal.mjs +20 -0
  148. package/dist/context/init-minimal.mjs.map +1 -0
  149. package/dist/context/init.mjs +22 -0
  150. package/dist/context/init.mjs.map +1 -0
  151. package/dist/cookies/cookie-utils.d.mts +29 -0
  152. package/dist/cookies/cookie-utils.mjs +105 -0
  153. package/dist/cookies/cookie-utils.mjs.map +1 -0
  154. package/dist/cookies/index.d.mts +67 -0
  155. package/dist/cookies/index.mjs +264 -0
  156. package/dist/cookies/index.mjs.map +1 -0
  157. package/dist/cookies/session-store.d.mts +36 -0
  158. package/dist/cookies/session-store.mjs +200 -0
  159. package/dist/cookies/session-store.mjs.map +1 -0
  160. package/dist/crypto/buffer.d.mts +8 -0
  161. package/dist/crypto/buffer.mjs +18 -0
  162. package/dist/crypto/buffer.mjs.map +1 -0
  163. package/dist/crypto/index.d.mts +27 -0
  164. package/dist/crypto/index.mjs +38 -0
  165. package/dist/crypto/index.mjs.map +1 -0
  166. package/dist/crypto/jwt.d.mts +8 -0
  167. package/dist/crypto/jwt.mjs +95 -0
  168. package/dist/crypto/jwt.mjs.map +1 -0
  169. package/dist/crypto/password.d.mts +12 -0
  170. package/dist/crypto/password.mjs +36 -0
  171. package/dist/crypto/password.mjs.map +1 -0
  172. package/dist/crypto/random.d.mts +5 -0
  173. package/dist/crypto/random.mjs +8 -0
  174. package/dist/crypto/random.mjs.map +1 -0
  175. package/dist/db/adapter-base.d.mts +8 -0
  176. package/dist/db/adapter-base.mjs +28 -0
  177. package/dist/db/adapter-base.mjs.map +1 -0
  178. package/dist/db/adapter-kysely.d.mts +8 -0
  179. package/dist/db/adapter-kysely.mjs +21 -0
  180. package/dist/db/adapter-kysely.mjs.map +1 -0
  181. package/dist/db/field-converter.d.mts +8 -0
  182. package/dist/db/field-converter.mjs +21 -0
  183. package/dist/db/field-converter.mjs.map +1 -0
  184. package/dist/db/field.d.mts +55 -0
  185. package/dist/db/field.mjs +11 -0
  186. package/dist/db/field.mjs.map +1 -0
  187. package/dist/db/get-migration.d.mts +23 -0
  188. package/dist/db/get-migration.mjs +339 -0
  189. package/dist/db/get-migration.mjs.map +1 -0
  190. package/dist/db/get-schema.d.mts +11 -0
  191. package/dist/db/get-schema.mjs +39 -0
  192. package/dist/db/get-schema.mjs.map +1 -0
  193. package/dist/db/index.d.mts +9 -0
  194. package/dist/db/index.mjs +36 -0
  195. package/dist/db/index.mjs.map +1 -0
  196. package/dist/db/internal-adapter.d.mts +14 -0
  197. package/dist/db/internal-adapter.mjs +616 -0
  198. package/dist/db/internal-adapter.mjs.map +1 -0
  199. package/dist/db/schema.d.mts +26 -0
  200. package/dist/db/schema.mjs +118 -0
  201. package/dist/db/schema.mjs.map +1 -0
  202. package/dist/db/to-zod.d.mts +36 -0
  203. package/dist/db/to-zod.mjs +26 -0
  204. package/dist/db/to-zod.mjs.map +1 -0
  205. package/dist/db/verification-token-storage.mjs +28 -0
  206. package/dist/db/verification-token-storage.mjs.map +1 -0
  207. package/dist/db/with-hooks.d.mts +33 -0
  208. package/dist/db/with-hooks.mjs +159 -0
  209. package/dist/db/with-hooks.mjs.map +1 -0
  210. package/dist/index.d.mts +52 -0
  211. package/dist/index.mjs +26 -0
  212. package/dist/integrations/next-js.d.mts +14 -0
  213. package/dist/integrations/next-js.mjs +78 -0
  214. package/dist/integrations/next-js.mjs.map +1 -0
  215. package/dist/integrations/node.d.mts +13 -0
  216. package/dist/integrations/node.mjs +16 -0
  217. package/dist/integrations/node.mjs.map +1 -0
  218. package/dist/integrations/solid-start.d.mts +23 -0
  219. package/dist/integrations/solid-start.mjs +17 -0
  220. package/dist/integrations/solid-start.mjs.map +1 -0
  221. package/dist/integrations/svelte-kit.d.mts +29 -0
  222. package/dist/integrations/svelte-kit.mjs +57 -0
  223. package/dist/integrations/svelte-kit.mjs.map +1 -0
  224. package/dist/integrations/tanstack-start-solid.d.mts +22 -0
  225. package/dist/integrations/tanstack-start-solid.mjs +61 -0
  226. package/dist/integrations/tanstack-start-solid.mjs.map +1 -0
  227. package/dist/integrations/tanstack-start.d.mts +22 -0
  228. package/dist/integrations/tanstack-start.mjs +61 -0
  229. package/dist/integrations/tanstack-start.mjs.map +1 -0
  230. package/dist/oauth2/index.d.mts +5 -0
  231. package/dist/oauth2/index.mjs +7 -0
  232. package/dist/oauth2/link-account.d.mts +31 -0
  233. package/dist/oauth2/link-account.mjs +144 -0
  234. package/dist/oauth2/link-account.mjs.map +1 -0
  235. package/dist/oauth2/state.d.mts +26 -0
  236. package/dist/oauth2/state.mjs +51 -0
  237. package/dist/oauth2/state.mjs.map +1 -0
  238. package/dist/oauth2/utils.d.mts +8 -0
  239. package/dist/oauth2/utils.mjs +31 -0
  240. package/dist/oauth2/utils.mjs.map +1 -0
  241. package/dist/plugins/access/access.d.mts +30 -0
  242. package/dist/plugins/access/access.mjs +46 -0
  243. package/dist/plugins/access/access.mjs.map +1 -0
  244. package/dist/plugins/access/index.d.mts +3 -0
  245. package/dist/plugins/access/index.mjs +3 -0
  246. package/dist/plugins/access/types.d.mts +17 -0
  247. package/dist/plugins/additional-fields/client.d.mts +14 -0
  248. package/dist/plugins/additional-fields/client.mjs +11 -0
  249. package/dist/plugins/additional-fields/client.mjs.map +1 -0
  250. package/dist/plugins/admin/access/index.d.mts +2 -0
  251. package/dist/plugins/admin/access/index.mjs +3 -0
  252. package/dist/plugins/admin/access/statement.d.mts +118 -0
  253. package/dist/plugins/admin/access/statement.mjs +53 -0
  254. package/dist/plugins/admin/access/statement.mjs.map +1 -0
  255. package/dist/plugins/admin/admin.d.mts +14 -0
  256. package/dist/plugins/admin/admin.mjs +95 -0
  257. package/dist/plugins/admin/admin.mjs.map +1 -0
  258. package/dist/plugins/admin/client.d.mts +14 -0
  259. package/dist/plugins/admin/client.mjs +36 -0
  260. package/dist/plugins/admin/client.mjs.map +1 -0
  261. package/dist/plugins/admin/error-codes.d.mts +5 -0
  262. package/dist/plugins/admin/error-codes.mjs +30 -0
  263. package/dist/plugins/admin/error-codes.mjs.map +1 -0
  264. package/dist/plugins/admin/has-permission.mjs +16 -0
  265. package/dist/plugins/admin/has-permission.mjs.map +1 -0
  266. package/dist/plugins/admin/index.d.mts +3 -0
  267. package/dist/plugins/admin/index.mjs +3 -0
  268. package/dist/plugins/admin/routes.mjs +855 -0
  269. package/dist/plugins/admin/routes.mjs.map +1 -0
  270. package/dist/plugins/admin/schema.d.mts +6 -0
  271. package/dist/plugins/admin/schema.mjs +34 -0
  272. package/dist/plugins/admin/schema.mjs.map +1 -0
  273. package/dist/plugins/admin/types.d.mts +89 -0
  274. package/dist/plugins/anonymous/client.d.mts +9 -0
  275. package/dist/plugins/anonymous/client.mjs +22 -0
  276. package/dist/plugins/anonymous/client.mjs.map +1 -0
  277. package/dist/plugins/anonymous/error-codes.d.mts +5 -0
  278. package/dist/plugins/anonymous/error-codes.mjs +16 -0
  279. package/dist/plugins/anonymous/error-codes.mjs.map +1 -0
  280. package/dist/plugins/anonymous/index.d.mts +14 -0
  281. package/dist/plugins/anonymous/index.mjs +163 -0
  282. package/dist/plugins/anonymous/index.mjs.map +1 -0
  283. package/dist/plugins/anonymous/schema.d.mts +5 -0
  284. package/dist/plugins/anonymous/schema.mjs +11 -0
  285. package/dist/plugins/anonymous/schema.mjs.map +1 -0
  286. package/dist/plugins/anonymous/types.d.mts +68 -0
  287. package/dist/plugins/api-key/adapter.mjs +468 -0
  288. package/dist/plugins/api-key/adapter.mjs.map +1 -0
  289. package/dist/plugins/api-key/client.d.mts +9 -0
  290. package/dist/plugins/api-key/client.mjs +19 -0
  291. package/dist/plugins/api-key/client.mjs.map +1 -0
  292. package/dist/plugins/api-key/error-codes.d.mts +5 -0
  293. package/dist/plugins/api-key/error-codes.mjs +34 -0
  294. package/dist/plugins/api-key/error-codes.mjs.map +1 -0
  295. package/dist/plugins/api-key/index.d.mts +17 -0
  296. package/dist/plugins/api-key/index.mjs +134 -0
  297. package/dist/plugins/api-key/index.mjs.map +1 -0
  298. package/dist/plugins/api-key/rate-limit.mjs +74 -0
  299. package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
  300. package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
  301. package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
  302. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
  303. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
  304. package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
  305. package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
  306. package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
  307. package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
  308. package/dist/plugins/api-key/routes/index.mjs +71 -0
  309. package/dist/plugins/api-key/routes/index.mjs.map +1 -0
  310. package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
  311. package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
  312. package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
  313. package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
  314. package/dist/plugins/api-key/routes/verify-api-key.mjs +223 -0
  315. package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
  316. package/dist/plugins/api-key/schema.d.mts +11 -0
  317. package/dist/plugins/api-key/schema.mjs +130 -0
  318. package/dist/plugins/api-key/schema.mjs.map +1 -0
  319. package/dist/plugins/api-key/types.d.mts +346 -0
  320. package/dist/plugins/bearer/index.d.mts +25 -0
  321. package/dist/plugins/bearer/index.mjs +66 -0
  322. package/dist/plugins/bearer/index.mjs.map +1 -0
  323. package/dist/plugins/captcha/constants.d.mts +10 -0
  324. package/dist/plugins/captcha/constants.mjs +22 -0
  325. package/dist/plugins/captcha/constants.mjs.map +1 -0
  326. package/dist/plugins/captcha/error-codes.mjs +16 -0
  327. package/dist/plugins/captcha/error-codes.mjs.map +1 -0
  328. package/dist/plugins/captcha/index.d.mts +14 -0
  329. package/dist/plugins/captcha/index.mjs +60 -0
  330. package/dist/plugins/captcha/index.mjs.map +1 -0
  331. package/dist/plugins/captcha/types.d.mts +28 -0
  332. package/dist/plugins/captcha/utils.mjs +11 -0
  333. package/dist/plugins/captcha/utils.mjs.map +1 -0
  334. package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
  335. package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
  336. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +25 -0
  337. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
  338. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +29 -0
  339. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
  340. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
  341. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
  342. package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
  343. package/dist/plugins/custom-session/client.d.mts +10 -0
  344. package/dist/plugins/custom-session/client.mjs +11 -0
  345. package/dist/plugins/custom-session/client.mjs.map +1 -0
  346. package/dist/plugins/custom-session/index.d.mts +26 -0
  347. package/dist/plugins/custom-session/index.mjs +70 -0
  348. package/dist/plugins/custom-session/index.mjs.map +1 -0
  349. package/dist/plugins/device-authorization/client.d.mts +5 -0
  350. package/dist/plugins/device-authorization/client.mjs +18 -0
  351. package/dist/plugins/device-authorization/client.mjs.map +1 -0
  352. package/dist/plugins/device-authorization/error-codes.mjs +21 -0
  353. package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
  354. package/dist/plugins/device-authorization/index.d.mts +28 -0
  355. package/dist/plugins/device-authorization/index.mjs +50 -0
  356. package/dist/plugins/device-authorization/index.mjs.map +1 -0
  357. package/dist/plugins/device-authorization/routes.mjs +510 -0
  358. package/dist/plugins/device-authorization/routes.mjs.map +1 -0
  359. package/dist/plugins/device-authorization/schema.mjs +57 -0
  360. package/dist/plugins/device-authorization/schema.mjs.map +1 -0
  361. package/dist/plugins/email-otp/client.d.mts +7 -0
  362. package/dist/plugins/email-otp/client.mjs +18 -0
  363. package/dist/plugins/email-otp/client.mjs.map +1 -0
  364. package/dist/plugins/email-otp/error-codes.d.mts +5 -0
  365. package/dist/plugins/email-otp/error-codes.mjs +12 -0
  366. package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
  367. package/dist/plugins/email-otp/index.d.mts +14 -0
  368. package/dist/plugins/email-otp/index.mjs +108 -0
  369. package/dist/plugins/email-otp/index.mjs.map +1 -0
  370. package/dist/plugins/email-otp/otp-token.mjs +29 -0
  371. package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
  372. package/dist/plugins/email-otp/routes.mjs +564 -0
  373. package/dist/plugins/email-otp/routes.mjs.map +1 -0
  374. package/dist/plugins/email-otp/types.d.mts +74 -0
  375. package/dist/plugins/email-otp/utils.mjs +17 -0
  376. package/dist/plugins/email-otp/utils.mjs.map +1 -0
  377. package/dist/plugins/generic-oauth/client.d.mts +19 -0
  378. package/dist/plugins/generic-oauth/client.mjs +14 -0
  379. package/dist/plugins/generic-oauth/client.mjs.map +1 -0
  380. package/dist/plugins/generic-oauth/error-codes.d.mts +5 -0
  381. package/dist/plugins/generic-oauth/error-codes.mjs +15 -0
  382. package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
  383. package/dist/plugins/generic-oauth/index.d.mts +34 -0
  384. package/dist/plugins/generic-oauth/index.mjs +137 -0
  385. package/dist/plugins/generic-oauth/index.mjs.map +1 -0
  386. package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
  387. package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
  388. package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
  389. package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
  390. package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
  391. package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
  392. package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
  393. package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
  394. package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
  395. package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
  396. package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
  397. package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
  398. package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
  399. package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
  400. package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
  401. package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
  402. package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
  403. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
  404. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
  405. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
  406. package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
  407. package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
  408. package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
  409. package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
  410. package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
  411. package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
  412. package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
  413. package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
  414. package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
  415. package/dist/plugins/generic-oauth/routes.mjs +394 -0
  416. package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
  417. package/dist/plugins/generic-oauth/types.d.mts +145 -0
  418. package/dist/plugins/haveibeenpwned/index.d.mts +21 -0
  419. package/dist/plugins/haveibeenpwned/index.mjs +56 -0
  420. package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
  421. package/dist/plugins/index.d.mts +68 -0
  422. package/dist/plugins/index.mjs +51 -0
  423. package/dist/plugins/jwt/adapter.mjs +27 -0
  424. package/dist/plugins/jwt/adapter.mjs.map +1 -0
  425. package/dist/plugins/jwt/client.d.mts +18 -0
  426. package/dist/plugins/jwt/client.mjs +19 -0
  427. package/dist/plugins/jwt/client.mjs.map +1 -0
  428. package/dist/plugins/jwt/index.d.mts +17 -0
  429. package/dist/plugins/jwt/index.mjs +202 -0
  430. package/dist/plugins/jwt/index.mjs.map +1 -0
  431. package/dist/plugins/jwt/schema.d.mts +5 -0
  432. package/dist/plugins/jwt/schema.mjs +23 -0
  433. package/dist/plugins/jwt/schema.mjs.map +1 -0
  434. package/dist/plugins/jwt/sign.d.mts +57 -0
  435. package/dist/plugins/jwt/sign.mjs +66 -0
  436. package/dist/plugins/jwt/sign.mjs.map +1 -0
  437. package/dist/plugins/jwt/types.d.mts +194 -0
  438. package/dist/plugins/jwt/utils.d.mts +42 -0
  439. package/dist/plugins/jwt/utils.mjs +64 -0
  440. package/dist/plugins/jwt/utils.mjs.map +1 -0
  441. package/dist/plugins/jwt/verify.d.mts +12 -0
  442. package/dist/plugins/jwt/verify.mjs +46 -0
  443. package/dist/plugins/jwt/verify.mjs.map +1 -0
  444. package/dist/plugins/last-login-method/client.d.mts +18 -0
  445. package/dist/plugins/last-login-method/client.mjs +32 -0
  446. package/dist/plugins/last-login-method/client.mjs.map +1 -0
  447. package/dist/plugins/last-login-method/index.d.mts +52 -0
  448. package/dist/plugins/last-login-method/index.mjs +77 -0
  449. package/dist/plugins/last-login-method/index.mjs.map +1 -0
  450. package/dist/plugins/magic-link/client.d.mts +5 -0
  451. package/dist/plugins/magic-link/client.mjs +11 -0
  452. package/dist/plugins/magic-link/client.mjs.map +1 -0
  453. package/dist/plugins/magic-link/index.d.mts +61 -0
  454. package/dist/plugins/magic-link/index.mjs +167 -0
  455. package/dist/plugins/magic-link/index.mjs.map +1 -0
  456. package/dist/plugins/magic-link/utils.mjs +12 -0
  457. package/dist/plugins/magic-link/utils.mjs.map +1 -0
  458. package/dist/plugins/mcp/authorize.mjs +133 -0
  459. package/dist/plugins/mcp/authorize.mjs.map +1 -0
  460. package/dist/plugins/mcp/index.d.mts +46 -0
  461. package/dist/plugins/mcp/index.mjs +717 -0
  462. package/dist/plugins/mcp/index.mjs.map +1 -0
  463. package/dist/plugins/multi-session/client.d.mts +8 -0
  464. package/dist/plugins/multi-session/client.mjs +20 -0
  465. package/dist/plugins/multi-session/client.mjs.map +1 -0
  466. package/dist/plugins/multi-session/error-codes.d.mts +5 -0
  467. package/dist/plugins/multi-session/error-codes.mjs +8 -0
  468. package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
  469. package/dist/plugins/multi-session/index.d.mts +22 -0
  470. package/dist/plugins/multi-session/index.mjs +172 -0
  471. package/dist/plugins/multi-session/index.mjs.map +1 -0
  472. package/dist/plugins/oauth-proxy/index.d.mts +39 -0
  473. package/dist/plugins/oauth-proxy/index.mjs +305 -0
  474. package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
  475. package/dist/plugins/oauth-proxy/utils.mjs +44 -0
  476. package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
  477. package/dist/plugins/oidc-provider/authorize.mjs +194 -0
  478. package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
  479. package/dist/plugins/oidc-provider/client.d.mts +8 -0
  480. package/dist/plugins/oidc-provider/client.mjs +11 -0
  481. package/dist/plugins/oidc-provider/client.mjs.map +1 -0
  482. package/dist/plugins/oidc-provider/error.mjs +17 -0
  483. package/dist/plugins/oidc-provider/error.mjs.map +1 -0
  484. package/dist/plugins/oidc-provider/index.d.mts +32 -0
  485. package/dist/plugins/oidc-provider/index.mjs +1093 -0
  486. package/dist/plugins/oidc-provider/index.mjs.map +1 -0
  487. package/dist/plugins/oidc-provider/schema.d.mts +26 -0
  488. package/dist/plugins/oidc-provider/schema.mjs +132 -0
  489. package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
  490. package/dist/plugins/oidc-provider/types.d.mts +517 -0
  491. package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
  492. package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
  493. package/dist/plugins/oidc-provider/utils.mjs +15 -0
  494. package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
  495. package/dist/plugins/one-tap/client.d.mts +159 -0
  496. package/dist/plugins/one-tap/client.mjs +214 -0
  497. package/dist/plugins/one-tap/client.mjs.map +1 -0
  498. package/dist/plugins/one-tap/index.d.mts +27 -0
  499. package/dist/plugins/one-tap/index.mjs +96 -0
  500. package/dist/plugins/one-tap/index.mjs.map +1 -0
  501. package/dist/plugins/one-time-token/client.d.mts +7 -0
  502. package/dist/plugins/one-time-token/client.mjs +11 -0
  503. package/dist/plugins/one-time-token/client.mjs.map +1 -0
  504. package/dist/plugins/one-time-token/index.d.mts +53 -0
  505. package/dist/plugins/one-time-token/index.mjs +82 -0
  506. package/dist/plugins/one-time-token/index.mjs.map +1 -0
  507. package/dist/plugins/one-time-token/utils.mjs +12 -0
  508. package/dist/plugins/one-time-token/utils.mjs.map +1 -0
  509. package/dist/plugins/open-api/generator.d.mts +115 -0
  510. package/dist/plugins/open-api/generator.mjs +315 -0
  511. package/dist/plugins/open-api/generator.mjs.map +1 -0
  512. package/dist/plugins/open-api/index.d.mts +45 -0
  513. package/dist/plugins/open-api/index.mjs +67 -0
  514. package/dist/plugins/open-api/index.mjs.map +1 -0
  515. package/dist/plugins/open-api/logo.mjs +15 -0
  516. package/dist/plugins/open-api/logo.mjs.map +1 -0
  517. package/dist/plugins/organization/access/index.d.mts +2 -0
  518. package/dist/plugins/organization/access/index.mjs +3 -0
  519. package/dist/plugins/organization/access/statement.d.mts +249 -0
  520. package/dist/plugins/organization/access/statement.mjs +81 -0
  521. package/dist/plugins/organization/access/statement.mjs.map +1 -0
  522. package/dist/plugins/organization/adapter.d.mts +205 -0
  523. package/dist/plugins/organization/adapter.mjs +624 -0
  524. package/dist/plugins/organization/adapter.mjs.map +1 -0
  525. package/dist/plugins/organization/call.mjs +19 -0
  526. package/dist/plugins/organization/call.mjs.map +1 -0
  527. package/dist/plugins/organization/client.d.mts +151 -0
  528. package/dist/plugins/organization/client.mjs +107 -0
  529. package/dist/plugins/organization/client.mjs.map +1 -0
  530. package/dist/plugins/organization/error-codes.d.mts +5 -0
  531. package/dist/plugins/organization/error-codes.mjs +65 -0
  532. package/dist/plugins/organization/error-codes.mjs.map +1 -0
  533. package/dist/plugins/organization/has-permission.mjs +35 -0
  534. package/dist/plugins/organization/has-permission.mjs.map +1 -0
  535. package/dist/plugins/organization/index.d.mts +5 -0
  536. package/dist/plugins/organization/index.mjs +4 -0
  537. package/dist/plugins/organization/organization.d.mts +252 -0
  538. package/dist/plugins/organization/organization.mjs +428 -0
  539. package/dist/plugins/organization/organization.mjs.map +1 -0
  540. package/dist/plugins/organization/permission.d.mts +26 -0
  541. package/dist/plugins/organization/permission.mjs +16 -0
  542. package/dist/plugins/organization/permission.mjs.map +1 -0
  543. package/dist/plugins/organization/routes/crud-access-control.d.mts +11 -0
  544. package/dist/plugins/organization/routes/crud-access-control.mjs +656 -0
  545. package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
  546. package/dist/plugins/organization/routes/crud-invites.d.mts +16 -0
  547. package/dist/plugins/organization/routes/crud-invites.mjs +555 -0
  548. package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
  549. package/dist/plugins/organization/routes/crud-members.d.mts +13 -0
  550. package/dist/plugins/organization/routes/crud-members.mjs +473 -0
  551. package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
  552. package/dist/plugins/organization/routes/crud-org.d.mts +13 -0
  553. package/dist/plugins/organization/routes/crud-org.mjs +447 -0
  554. package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
  555. package/dist/plugins/organization/routes/crud-team.d.mts +15 -0
  556. package/dist/plugins/organization/routes/crud-team.mjs +676 -0
  557. package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
  558. package/dist/plugins/organization/schema.d.mts +376 -0
  559. package/dist/plugins/organization/schema.mjs +68 -0
  560. package/dist/plugins/organization/schema.mjs.map +1 -0
  561. package/dist/plugins/organization/types.d.mts +733 -0
  562. package/dist/plugins/phone-number/client.d.mts +8 -0
  563. package/dist/plugins/phone-number/client.mjs +20 -0
  564. package/dist/plugins/phone-number/client.mjs.map +1 -0
  565. package/dist/plugins/phone-number/error-codes.d.mts +5 -0
  566. package/dist/plugins/phone-number/error-codes.mjs +21 -0
  567. package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
  568. package/dist/plugins/phone-number/index.d.mts +14 -0
  569. package/dist/plugins/phone-number/index.mjs +49 -0
  570. package/dist/plugins/phone-number/index.mjs.map +1 -0
  571. package/dist/plugins/phone-number/routes.mjs +459 -0
  572. package/dist/plugins/phone-number/routes.mjs.map +1 -0
  573. package/dist/plugins/phone-number/schema.d.mts +5 -0
  574. package/dist/plugins/phone-number/schema.mjs +20 -0
  575. package/dist/plugins/phone-number/schema.mjs.map +1 -0
  576. package/dist/plugins/phone-number/types.d.mts +118 -0
  577. package/dist/plugins/siwe/client.d.mts +5 -0
  578. package/dist/plugins/siwe/client.mjs +11 -0
  579. package/dist/plugins/siwe/client.mjs.map +1 -0
  580. package/dist/plugins/siwe/error-codes.mjs +13 -0
  581. package/dist/plugins/siwe/error-codes.mjs.map +1 -0
  582. package/dist/plugins/siwe/index.d.mts +26 -0
  583. package/dist/plugins/siwe/index.mjs +261 -0
  584. package/dist/plugins/siwe/index.mjs.map +1 -0
  585. package/dist/plugins/siwe/schema.d.mts +5 -0
  586. package/dist/plugins/siwe/schema.mjs +32 -0
  587. package/dist/plugins/siwe/schema.mjs.map +1 -0
  588. package/dist/plugins/siwe/types.d.mts +44 -0
  589. package/dist/plugins/two-factor/backup-codes/index.d.mts +91 -0
  590. package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
  591. package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
  592. package/dist/plugins/two-factor/client.d.mts +17 -0
  593. package/dist/plugins/two-factor/client.mjs +37 -0
  594. package/dist/plugins/two-factor/client.mjs.map +1 -0
  595. package/dist/plugins/two-factor/constant.mjs +8 -0
  596. package/dist/plugins/two-factor/constant.mjs.map +1 -0
  597. package/dist/plugins/two-factor/error-code.d.mts +5 -0
  598. package/dist/plugins/two-factor/error-code.mjs +18 -0
  599. package/dist/plugins/two-factor/error-code.mjs.map +1 -0
  600. package/dist/plugins/two-factor/index.d.mts +19 -0
  601. package/dist/plugins/two-factor/index.mjs +207 -0
  602. package/dist/plugins/two-factor/index.mjs.map +1 -0
  603. package/dist/plugins/two-factor/otp/index.d.mts +96 -0
  604. package/dist/plugins/two-factor/otp/index.mjs +199 -0
  605. package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
  606. package/dist/plugins/two-factor/schema.d.mts +5 -0
  607. package/dist/plugins/two-factor/schema.mjs +36 -0
  608. package/dist/plugins/two-factor/schema.mjs.map +1 -0
  609. package/dist/plugins/two-factor/totp/index.d.mts +81 -0
  610. package/dist/plugins/two-factor/totp/index.mjs +157 -0
  611. package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
  612. package/dist/plugins/two-factor/types.d.mts +65 -0
  613. package/dist/plugins/two-factor/utils.mjs +12 -0
  614. package/dist/plugins/two-factor/utils.mjs.map +1 -0
  615. package/dist/plugins/two-factor/verify-two-factor.mjs +76 -0
  616. package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
  617. package/dist/plugins/username/client.d.mts +7 -0
  618. package/dist/plugins/username/client.mjs +18 -0
  619. package/dist/plugins/username/client.mjs.map +1 -0
  620. package/dist/plugins/username/error-codes.d.mts +5 -0
  621. package/dist/plugins/username/error-codes.mjs +17 -0
  622. package/dist/plugins/username/error-codes.mjs.map +1 -0
  623. package/dist/plugins/username/index.d.mts +74 -0
  624. package/dist/plugins/username/index.mjs +237 -0
  625. package/dist/plugins/username/index.mjs.map +1 -0
  626. package/dist/plugins/username/schema.d.mts +9 -0
  627. package/dist/plugins/username/schema.mjs +26 -0
  628. package/dist/plugins/username/schema.mjs.map +1 -0
  629. package/dist/social-providers/index.d.mts +1 -0
  630. package/dist/social-providers/index.mjs +3 -0
  631. package/dist/state.d.mts +42 -0
  632. package/dist/state.mjs +107 -0
  633. package/dist/state.mjs.map +1 -0
  634. package/dist/test-utils/headers.d.mts +9 -0
  635. package/dist/test-utils/headers.mjs +24 -0
  636. package/dist/test-utils/headers.mjs.map +1 -0
  637. package/dist/test-utils/index.d.mts +3 -0
  638. package/dist/test-utils/index.mjs +4 -0
  639. package/dist/test-utils/test-instance.d.mts +181 -0
  640. package/dist/test-utils/test-instance.mjs +210 -0
  641. package/dist/test-utils/test-instance.mjs.map +1 -0
  642. package/dist/types/adapter.d.mts +24 -0
  643. package/dist/types/api.d.mts +29 -0
  644. package/dist/types/auth.d.mts +30 -0
  645. package/dist/types/helper.d.mts +21 -0
  646. package/dist/types/index.d.mts +11 -0
  647. package/dist/types/index.mjs +1 -0
  648. package/dist/types/models.d.mts +17 -0
  649. package/dist/types/plugins.d.mts +16 -0
  650. package/dist/utils/boolean.mjs +8 -0
  651. package/dist/utils/boolean.mjs.map +1 -0
  652. package/dist/utils/constants.mjs +6 -0
  653. package/dist/utils/constants.mjs.map +1 -0
  654. package/dist/utils/date.mjs +8 -0
  655. package/dist/utils/date.mjs.map +1 -0
  656. package/dist/utils/get-request-ip.d.mts +7 -0
  657. package/dist/utils/get-request-ip.mjs +23 -0
  658. package/dist/utils/get-request-ip.mjs.map +1 -0
  659. package/dist/utils/hashing.mjs +21 -0
  660. package/dist/utils/hashing.mjs.map +1 -0
  661. package/dist/utils/hide-metadata.d.mts +7 -0
  662. package/dist/utils/hide-metadata.mjs +6 -0
  663. package/dist/utils/hide-metadata.mjs.map +1 -0
  664. package/dist/utils/index.d.mts +3 -0
  665. package/dist/utils/index.mjs +5 -0
  666. package/dist/utils/is-api-error.d.mts +7 -0
  667. package/dist/utils/is-api-error.mjs +11 -0
  668. package/dist/utils/is-api-error.mjs.map +1 -0
  669. package/dist/utils/is-atom.mjs +8 -0
  670. package/dist/utils/is-atom.mjs.map +1 -0
  671. package/dist/utils/is-promise.mjs +8 -0
  672. package/dist/utils/is-promise.mjs.map +1 -0
  673. package/dist/utils/middleware-response.mjs +6 -0
  674. package/dist/utils/middleware-response.mjs.map +1 -0
  675. package/dist/utils/password.mjs +26 -0
  676. package/dist/utils/password.mjs.map +1 -0
  677. package/dist/utils/plugin-helper.mjs +17 -0
  678. package/dist/utils/plugin-helper.mjs.map +1 -0
  679. package/dist/utils/shim.mjs +24 -0
  680. package/dist/utils/shim.mjs.map +1 -0
  681. package/dist/utils/time.d.mts +49 -0
  682. package/dist/utils/time.mjs +100 -0
  683. package/dist/utils/time.mjs.map +1 -0
  684. package/dist/utils/url.mjs +92 -0
  685. package/dist/utils/url.mjs.map +1 -0
  686. package/dist/utils/wildcard.mjs +108 -0
  687. package/dist/utils/wildcard.mjs.map +1 -0
  688. package/package.json +601 -0
@@ -0,0 +1,68 @@
1
+ import { Session, User } from "../../types/models.mjs";
2
+ import { InferOptionSchema } from "../../types/plugins.mjs";
3
+ import "../../types/index.mjs";
4
+ import { schema } from "./schema.mjs";
5
+ import { AuthContext, Awaitable, GenericEndpointContext } from "@better-auth/core";
6
+ import { EndpointContext } from "better-call";
7
+
8
+ //#region src/plugins/anonymous/types.d.ts
9
+ type AnonymousSession = {
10
+ session: Session;
11
+ user: User;
12
+ } & {
13
+ user: {
14
+ isAnonymous: boolean | null;
15
+ };
16
+ } & Record<string, any>;
17
+ interface UserWithAnonymous extends User {
18
+ isAnonymous: boolean;
19
+ }
20
+ interface AnonymousOptions {
21
+ /**
22
+ * Configure the domain name of the temporary email
23
+ * address for anonymous users in the database.
24
+ * @default "baseURL"
25
+ */
26
+ emailDomainName?: string | undefined;
27
+ /**
28
+ * A useful hook to run after an anonymous user
29
+ * is about to link their account.
30
+ */
31
+ onLinkAccount?: ((data: {
32
+ anonymousUser: {
33
+ user: UserWithAnonymous & Record<string, any>;
34
+ session: Session & Record<string, any>;
35
+ };
36
+ newUser: {
37
+ user: User & Record<string, any>;
38
+ session: Session & Record<string, any>;
39
+ };
40
+ ctx: GenericEndpointContext;
41
+ }) => Awaitable<void>) | undefined;
42
+ /**
43
+ * Disable deleting the anonymous user
44
+ */
45
+ disableDeleteAnonymousUser?: boolean | undefined;
46
+ /**
47
+ * A hook to generate a name for the anonymous user.
48
+ * Useful if you want to have random names for anonymous users, or if `name` is unique in your database.
49
+ * @returns The name for the anonymous user.
50
+ */
51
+ generateName?: ((ctx: EndpointContext<"/sign-in/anonymous", {
52
+ method: "POST";
53
+ }, AuthContext>) => Awaitable<string>) | undefined;
54
+ /**
55
+ * A custom random email generation function.
56
+ * Useful when you want to specify a temporary email in a different format from the default.
57
+ * You are responsible for ensuring the email is unique to avoid conflicts.
58
+ * @returns The email address for the anonymous user.
59
+ */
60
+ generateRandomEmail?: (() => Awaitable<string>) | undefined;
61
+ /**
62
+ * Custom schema for the anonymous plugin
63
+ */
64
+ schema?: InferOptionSchema<typeof schema> | undefined;
65
+ }
66
+ //#endregion
67
+ export { AnonymousOptions, AnonymousSession, UserWithAnonymous };
68
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1,468 @@
1
+ import { safeJSONParse } from "@better-auth/core/utils/json";
2
+
3
+ //#region src/plugins/api-key/adapter.ts
4
+ /**
5
+ * Parses double-stringified metadata synchronously without updating the database.
6
+ * Use this for reading metadata, then call migrateLegacyMetadataInBackground for DB updates.
7
+ *
8
+ * @returns The properly parsed metadata object, or the original if already an object
9
+ */
10
+ function parseDoubleStringifiedMetadata(metadata) {
11
+ if (metadata == null) return null;
12
+ if (typeof metadata === "object") return metadata;
13
+ return safeJSONParse(metadata);
14
+ }
15
+ /**
16
+ * Checks if metadata needs migration (is a string instead of object)
17
+ */
18
+ function needsMetadataMigration(metadata) {
19
+ return metadata != null && typeof metadata === "string";
20
+ }
21
+ /**
22
+ * Batch migrates double-stringified metadata for multiple API keys.
23
+ * Runs all updates in parallel to avoid N sequential database calls.
24
+ */
25
+ async function batchMigrateLegacyMetadata(ctx, apiKeys, opts) {
26
+ if (opts.storage !== "database" && !opts.fallbackToDatabase) return;
27
+ const keysToMigrate = apiKeys.filter((key) => needsMetadataMigration(key.metadata));
28
+ if (keysToMigrate.length === 0) return;
29
+ const migrationPromises = keysToMigrate.map(async (apiKey) => {
30
+ const parsed = parseDoubleStringifiedMetadata(apiKey.metadata);
31
+ try {
32
+ await ctx.context.adapter.update({
33
+ model: "apikey",
34
+ where: [{
35
+ field: "id",
36
+ value: apiKey.id
37
+ }],
38
+ update: { metadata: parsed }
39
+ });
40
+ } catch (error) {
41
+ ctx.context.logger.warn(`Failed to migrate double-stringified metadata for API key ${apiKey.id}:`, error);
42
+ }
43
+ });
44
+ await Promise.all(migrationPromises);
45
+ }
46
+ /**
47
+ * Migrates double-stringified metadata to properly parsed object.
48
+ *
49
+ * This handles legacy data where metadata was incorrectly double-stringified.
50
+ * If metadata is a string (should be object after adapter's transform.output),
51
+ * it parses it and optionally updates the database.
52
+ *
53
+ * @returns The properly parsed metadata object
54
+ */
55
+ async function migrateDoubleStringifiedMetadata(ctx, apiKey, opts) {
56
+ const parsed = parseDoubleStringifiedMetadata(apiKey.metadata);
57
+ if (needsMetadataMigration(apiKey.metadata) && (opts.storage === "database" || opts.fallbackToDatabase)) try {
58
+ await ctx.context.adapter.update({
59
+ model: "apikey",
60
+ where: [{
61
+ field: "id",
62
+ value: apiKey.id
63
+ }],
64
+ update: { metadata: parsed }
65
+ });
66
+ } catch (error) {
67
+ ctx.context.logger.warn(`Failed to migrate double-stringified metadata for API key ${apiKey.id}:`, error);
68
+ }
69
+ return parsed;
70
+ }
71
+ /**
72
+ * Generate storage key for API key by hashed key
73
+ */
74
+ function getStorageKeyByHashedKey(hashedKey) {
75
+ return `api-key:${hashedKey}`;
76
+ }
77
+ /**
78
+ * Generate storage key for API key by ID
79
+ */
80
+ function getStorageKeyById(id) {
81
+ return `api-key:by-id:${id}`;
82
+ }
83
+ /**
84
+ * Generate storage key for user's API key list
85
+ */
86
+ function getStorageKeyByUserId(userId) {
87
+ return `api-key:by-user:${userId}`;
88
+ }
89
+ /**
90
+ * Serialize API key for storage
91
+ */
92
+ function serializeApiKey(apiKey) {
93
+ return JSON.stringify({
94
+ ...apiKey,
95
+ createdAt: apiKey.createdAt.toISOString(),
96
+ updatedAt: apiKey.updatedAt.toISOString(),
97
+ expiresAt: apiKey.expiresAt?.toISOString() ?? null,
98
+ lastRefillAt: apiKey.lastRefillAt?.toISOString() ?? null,
99
+ lastRequest: apiKey.lastRequest?.toISOString() ?? null
100
+ });
101
+ }
102
+ /**
103
+ * Deserialize API key from storage
104
+ */
105
+ function deserializeApiKey(data) {
106
+ if (!data || typeof data !== "string") return null;
107
+ try {
108
+ const parsed = JSON.parse(data);
109
+ return {
110
+ ...parsed,
111
+ createdAt: new Date(parsed.createdAt),
112
+ updatedAt: new Date(parsed.updatedAt),
113
+ expiresAt: parsed.expiresAt ? new Date(parsed.expiresAt) : null,
114
+ lastRefillAt: parsed.lastRefillAt ? new Date(parsed.lastRefillAt) : null,
115
+ lastRequest: parsed.lastRequest ? new Date(parsed.lastRequest) : null
116
+ };
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+ /**
122
+ * Get the storage instance to use (custom methods take precedence)
123
+ */
124
+ function getStorageInstance(ctx, opts) {
125
+ if (opts.customStorage) return opts.customStorage;
126
+ return ctx.context.secondaryStorage || null;
127
+ }
128
+ /**
129
+ * Calculate TTL in seconds for an API key
130
+ */
131
+ function calculateTTL(apiKey) {
132
+ if (apiKey.expiresAt) {
133
+ const now = Date.now();
134
+ const expiresAt = new Date(apiKey.expiresAt).getTime();
135
+ const ttlSeconds = Math.floor((expiresAt - now) / 1e3);
136
+ if (ttlSeconds > 0) return ttlSeconds;
137
+ }
138
+ }
139
+ /**
140
+ * Get API key from secondary storage by hashed key
141
+ */
142
+ async function getApiKeyFromStorage(ctx, hashedKey, storage) {
143
+ const key = getStorageKeyByHashedKey(hashedKey);
144
+ return deserializeApiKey(await storage.get(key));
145
+ }
146
+ /**
147
+ * Get API key from secondary storage by ID
148
+ */
149
+ async function getApiKeyByIdFromStorage(ctx, id, storage) {
150
+ const key = getStorageKeyById(id);
151
+ return deserializeApiKey(await storage.get(key));
152
+ }
153
+ /**
154
+ * Store API key in secondary storage
155
+ */
156
+ async function setApiKeyInStorage(ctx, apiKey, storage, ttl) {
157
+ const serialized = serializeApiKey(apiKey);
158
+ const hashedKey = apiKey.key;
159
+ const id = apiKey.id;
160
+ await storage.set(getStorageKeyByHashedKey(hashedKey), serialized, ttl);
161
+ await storage.set(getStorageKeyById(id), serialized, ttl);
162
+ const userKey = getStorageKeyByUserId(apiKey.userId);
163
+ const userListData = await storage.get(userKey);
164
+ let userIds = [];
165
+ if (userListData && typeof userListData === "string") try {
166
+ userIds = JSON.parse(userListData);
167
+ } catch {
168
+ userIds = [];
169
+ }
170
+ else if (Array.isArray(userListData)) userIds = userListData;
171
+ if (!userIds.includes(id)) {
172
+ userIds.push(id);
173
+ await storage.set(userKey, JSON.stringify(userIds));
174
+ }
175
+ }
176
+ /**
177
+ * Delete API key from secondary storage
178
+ */
179
+ async function deleteApiKeyFromStorage(ctx, apiKey, storage) {
180
+ const hashedKey = apiKey.key;
181
+ const id = apiKey.id;
182
+ const userId = apiKey.userId;
183
+ await storage.delete(getStorageKeyByHashedKey(hashedKey));
184
+ await storage.delete(getStorageKeyById(id));
185
+ const userKey = getStorageKeyByUserId(userId);
186
+ const userListData = await storage.get(userKey);
187
+ let userIds = [];
188
+ if (userListData && typeof userListData === "string") try {
189
+ userIds = JSON.parse(userListData);
190
+ } catch {
191
+ userIds = [];
192
+ }
193
+ else if (Array.isArray(userListData)) userIds = userListData;
194
+ const filteredIds = userIds.filter((keyId) => keyId !== id);
195
+ if (filteredIds.length === 0) await storage.delete(userKey);
196
+ else await storage.set(userKey, JSON.stringify(filteredIds));
197
+ }
198
+ /**
199
+ * Unified getter for API keys with support for all storage modes
200
+ */
201
+ async function getApiKey(ctx, hashedKey, opts) {
202
+ const storage = getStorageInstance(ctx, opts);
203
+ if (opts.storage === "database") return await ctx.context.adapter.findOne({
204
+ model: "apikey",
205
+ where: [{
206
+ field: "key",
207
+ value: hashedKey
208
+ }]
209
+ });
210
+ if (opts.storage === "secondary-storage" && opts.fallbackToDatabase) {
211
+ if (storage) {
212
+ const cached = await getApiKeyFromStorage(ctx, hashedKey, storage);
213
+ if (cached) return cached;
214
+ }
215
+ const dbKey = await ctx.context.adapter.findOne({
216
+ model: "apikey",
217
+ where: [{
218
+ field: "key",
219
+ value: hashedKey
220
+ }]
221
+ });
222
+ if (dbKey && storage) await setApiKeyInStorage(ctx, dbKey, storage, calculateTTL(dbKey));
223
+ return dbKey;
224
+ }
225
+ if (opts.storage === "secondary-storage") {
226
+ if (!storage) return null;
227
+ return await getApiKeyFromStorage(ctx, hashedKey, storage);
228
+ }
229
+ return await ctx.context.adapter.findOne({
230
+ model: "apikey",
231
+ where: [{
232
+ field: "key",
233
+ value: hashedKey
234
+ }]
235
+ });
236
+ }
237
+ /**
238
+ * Unified getter for API keys by ID
239
+ */
240
+ async function getApiKeyById(ctx, id, opts) {
241
+ const storage = getStorageInstance(ctx, opts);
242
+ if (opts.storage === "database") return await ctx.context.adapter.findOne({
243
+ model: "apikey",
244
+ where: [{
245
+ field: "id",
246
+ value: id
247
+ }]
248
+ });
249
+ if (opts.storage === "secondary-storage" && opts.fallbackToDatabase) {
250
+ if (storage) {
251
+ const cached = await getApiKeyByIdFromStorage(ctx, id, storage);
252
+ if (cached) return cached;
253
+ }
254
+ const dbKey = await ctx.context.adapter.findOne({
255
+ model: "apikey",
256
+ where: [{
257
+ field: "id",
258
+ value: id
259
+ }]
260
+ });
261
+ if (dbKey && storage) await setApiKeyInStorage(ctx, dbKey, storage, calculateTTL(dbKey));
262
+ return dbKey;
263
+ }
264
+ if (opts.storage === "secondary-storage") {
265
+ if (!storage) return null;
266
+ return await getApiKeyByIdFromStorage(ctx, id, storage);
267
+ }
268
+ return await ctx.context.adapter.findOne({
269
+ model: "apikey",
270
+ where: [{
271
+ field: "id",
272
+ value: id
273
+ }]
274
+ });
275
+ }
276
+ /**
277
+ * Unified setter for API keys with support for all storage modes
278
+ */
279
+ async function setApiKey(ctx, apiKey, opts) {
280
+ const storage = getStorageInstance(ctx, opts);
281
+ const ttl = calculateTTL(apiKey);
282
+ if (opts.storage === "database") return;
283
+ if (opts.storage === "secondary-storage") {
284
+ if (!storage) throw new Error("Secondary storage is required when storage mode is 'secondary-storage'");
285
+ await setApiKeyInStorage(ctx, apiKey, storage, ttl);
286
+ return;
287
+ }
288
+ }
289
+ /**
290
+ * Unified deleter for API keys with support for all storage modes
291
+ */
292
+ async function deleteApiKey(ctx, apiKey, opts) {
293
+ const storage = getStorageInstance(ctx, opts);
294
+ if (opts.storage === "database") return;
295
+ if (opts.storage === "secondary-storage") {
296
+ if (!storage) throw new Error("Secondary storage is required when storage mode is 'secondary-storage'");
297
+ await deleteApiKeyFromStorage(ctx, apiKey, storage);
298
+ return;
299
+ }
300
+ }
301
+ /**
302
+ * Apply sorting and pagination to an array of API keys in memory
303
+ * Used for secondary storage mode where we can't rely on database operations
304
+ */
305
+ function applySortingAndPagination(apiKeys, sortBy, sortDirection, limit, offset) {
306
+ let result = [...apiKeys];
307
+ if (sortBy) {
308
+ const direction = sortDirection || "asc";
309
+ result.sort((a, b) => {
310
+ const aValue = a[sortBy];
311
+ const bValue = b[sortBy];
312
+ if (aValue == null && bValue == null) return 0;
313
+ if (aValue == null) return direction === "asc" ? -1 : 1;
314
+ if (bValue == null) return direction === "asc" ? 1 : -1;
315
+ if (aValue < bValue) return direction === "asc" ? -1 : 1;
316
+ if (aValue > bValue) return direction === "asc" ? 1 : -1;
317
+ return 0;
318
+ });
319
+ }
320
+ if (offset !== void 0) result = result.slice(offset);
321
+ if (limit !== void 0) result = result.slice(0, limit);
322
+ return result;
323
+ }
324
+ /**
325
+ * List API keys for a user with support for all storage modes
326
+ */
327
+ async function listApiKeys(ctx, userId, opts, paginationOpts) {
328
+ const storage = getStorageInstance(ctx, opts);
329
+ const { limit, offset, sortBy, sortDirection } = paginationOpts || {};
330
+ if (opts.storage === "database") {
331
+ const [apiKeys, total] = await Promise.all([ctx.context.adapter.findMany({
332
+ model: "apikey",
333
+ where: [{
334
+ field: "userId",
335
+ value: userId
336
+ }],
337
+ limit,
338
+ offset,
339
+ sortBy: sortBy ? {
340
+ field: sortBy,
341
+ direction: sortDirection || "asc"
342
+ } : void 0
343
+ }), ctx.context.adapter.count({
344
+ model: "apikey",
345
+ where: [{
346
+ field: "userId",
347
+ value: userId
348
+ }]
349
+ })]);
350
+ return {
351
+ apiKeys,
352
+ total
353
+ };
354
+ }
355
+ if (opts.storage === "secondary-storage" && opts.fallbackToDatabase) {
356
+ const userKey = getStorageKeyByUserId(userId);
357
+ if (storage) {
358
+ const userListData = await storage.get(userKey);
359
+ let userIds = [];
360
+ if (userListData && typeof userListData === "string") try {
361
+ userIds = JSON.parse(userListData);
362
+ } catch {
363
+ userIds = [];
364
+ }
365
+ else if (Array.isArray(userListData)) userIds = userListData;
366
+ if (userIds.length > 0) {
367
+ const apiKeys = [];
368
+ for (const id of userIds) {
369
+ const apiKey = await getApiKeyByIdFromStorage(ctx, id, storage);
370
+ if (apiKey) apiKeys.push(apiKey);
371
+ }
372
+ return {
373
+ apiKeys: applySortingAndPagination(apiKeys, sortBy, sortDirection, limit, offset),
374
+ total: apiKeys.length
375
+ };
376
+ }
377
+ }
378
+ const [dbKeys, total] = await Promise.all([ctx.context.adapter.findMany({
379
+ model: "apikey",
380
+ where: [{
381
+ field: "userId",
382
+ value: userId
383
+ }],
384
+ limit,
385
+ offset,
386
+ sortBy: sortBy ? {
387
+ field: sortBy,
388
+ direction: sortDirection || "asc"
389
+ } : void 0
390
+ }), ctx.context.adapter.count({
391
+ model: "apikey",
392
+ where: [{
393
+ field: "userId",
394
+ value: userId
395
+ }]
396
+ })]);
397
+ if (storage && dbKeys.length > 0) {
398
+ const userIds = [];
399
+ for (const apiKey of dbKeys) {
400
+ await setApiKeyInStorage(ctx, apiKey, storage, calculateTTL(apiKey));
401
+ userIds.push(apiKey.id);
402
+ }
403
+ await storage.set(userKey, JSON.stringify(userIds));
404
+ }
405
+ return {
406
+ apiKeys: dbKeys,
407
+ total
408
+ };
409
+ }
410
+ if (opts.storage === "secondary-storage") {
411
+ if (!storage) return {
412
+ apiKeys: [],
413
+ total: 0
414
+ };
415
+ const userKey = getStorageKeyByUserId(userId);
416
+ const userListData = await storage.get(userKey);
417
+ let userIds = [];
418
+ if (userListData && typeof userListData === "string") try {
419
+ userIds = JSON.parse(userListData);
420
+ } catch {
421
+ return {
422
+ apiKeys: [],
423
+ total: 0
424
+ };
425
+ }
426
+ else if (Array.isArray(userListData)) userIds = userListData;
427
+ else return {
428
+ apiKeys: [],
429
+ total: 0
430
+ };
431
+ const apiKeys = [];
432
+ for (const id of userIds) {
433
+ const apiKey = await getApiKeyByIdFromStorage(ctx, id, storage);
434
+ if (apiKey) apiKeys.push(apiKey);
435
+ }
436
+ return {
437
+ apiKeys: applySortingAndPagination(apiKeys, sortBy, sortDirection, limit, offset),
438
+ total: apiKeys.length
439
+ };
440
+ }
441
+ const [apiKeys, total] = await Promise.all([ctx.context.adapter.findMany({
442
+ model: "apikey",
443
+ where: [{
444
+ field: "userId",
445
+ value: userId
446
+ }],
447
+ limit,
448
+ offset,
449
+ sortBy: sortBy ? {
450
+ field: sortBy,
451
+ direction: sortDirection || "asc"
452
+ } : void 0
453
+ }), ctx.context.adapter.count({
454
+ model: "apikey",
455
+ where: [{
456
+ field: "userId",
457
+ value: userId
458
+ }]
459
+ })]);
460
+ return {
461
+ apiKeys,
462
+ total
463
+ };
464
+ }
465
+
466
+ //#endregion
467
+ export { batchMigrateLegacyMetadata, deleteApiKey, getApiKey, getApiKeyById, listApiKeys, migrateDoubleStringifiedMetadata, parseDoubleStringifiedMetadata, setApiKey };
468
+ //# sourceMappingURL=adapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.mjs","names":[],"sources":["../../../src/plugins/api-key/adapter.ts"],"sourcesContent":["import type { GenericEndpointContext } from \"@better-auth/core\";\nimport type { SecondaryStorage } from \"@better-auth/core/db\";\nimport { safeJSONParse } from \"@better-auth/core/utils/json\";\nimport type { PredefinedApiKeyOptions } from \"./routes\";\nimport type { ApiKey } from \"./types\";\n\n/**\n * Parses double-stringified metadata synchronously without updating the database.\n * Use this for reading metadata, then call migrateLegacyMetadataInBackground for DB updates.\n *\n * @returns The properly parsed metadata object, or the original if already an object\n */\nexport function parseDoubleStringifiedMetadata(\n\tmetadata: ApiKey[\"metadata\"],\n): Record<string, any> | null {\n\t// If metadata is null/undefined, return null\n\tif (metadata == null) {\n\t\treturn null;\n\t}\n\n\t// If metadata is already an object, no migration needed\n\tif (typeof metadata === \"object\") {\n\t\treturn metadata;\n\t}\n\n\t// Metadata is a string - this is legacy double-stringified data\n\t// Parse it to get the actual object\n\treturn safeJSONParse<Record<string, any>>(metadata);\n}\n\n/**\n * Checks if metadata needs migration (is a string instead of object)\n */\nfunction needsMetadataMigration(metadata: ApiKey[\"metadata\"]): boolean {\n\treturn metadata != null && typeof metadata === \"string\";\n}\n\n/**\n * Batch migrates double-stringified metadata for multiple API keys.\n * Runs all updates in parallel to avoid N sequential database calls.\n */\nexport async function batchMigrateLegacyMetadata(\n\tctx: GenericEndpointContext,\n\tapiKeys: ApiKey[],\n\topts: PredefinedApiKeyOptions,\n): Promise<void> {\n\t// Only migrate for database storage\n\tif (opts.storage !== \"database\" && !opts.fallbackToDatabase) {\n\t\treturn;\n\t}\n\n\t// Filter keys that need migration\n\tconst keysToMigrate = apiKeys.filter((key) =>\n\t\tneedsMetadataMigration(key.metadata),\n\t);\n\n\tif (keysToMigrate.length === 0) {\n\t\treturn;\n\t}\n\n\t// Run migrations in parallel (not sequentially)\n\tconst migrationPromises = keysToMigrate.map(async (apiKey) => {\n\t\tconst parsed = parseDoubleStringifiedMetadata(apiKey.metadata);\n\t\ttry {\n\t\t\tawait ctx.context.adapter.update({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [{ field: \"id\", value: apiKey.id }],\n\t\t\t\tupdate: { metadata: parsed },\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tctx.context.logger.warn(\n\t\t\t\t`Failed to migrate double-stringified metadata for API key ${apiKey.id}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t});\n\n\tawait Promise.all(migrationPromises);\n}\n\n/**\n * Migrates double-stringified metadata to properly parsed object.\n *\n * This handles legacy data where metadata was incorrectly double-stringified.\n * If metadata is a string (should be object after adapter's transform.output),\n * it parses it and optionally updates the database.\n *\n * @returns The properly parsed metadata object\n */\nexport async function migrateDoubleStringifiedMetadata(\n\tctx: GenericEndpointContext,\n\tapiKey: ApiKey,\n\topts: PredefinedApiKeyOptions,\n): Promise<Record<string, any> | null> {\n\tconst parsed = parseDoubleStringifiedMetadata(apiKey.metadata);\n\n\t// Update the database to fix the legacy data (only for database storage)\n\tif (\n\t\tneedsMetadataMigration(apiKey.metadata) &&\n\t\t(opts.storage === \"database\" || opts.fallbackToDatabase)\n\t) {\n\t\ttry {\n\t\t\tawait ctx.context.adapter.update({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [{ field: \"id\", value: apiKey.id }],\n\t\t\t\tupdate: { metadata: parsed },\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t// Log but don't fail the request if migration update fails\n\t\t\tctx.context.logger.warn(\n\t\t\t\t`Failed to migrate double-stringified metadata for API key ${apiKey.id}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn parsed;\n}\n\n/**\n * Generate storage key for API key by hashed key\n */\nfunction getStorageKeyByHashedKey(hashedKey: string): string {\n\treturn `api-key:${hashedKey}`;\n}\n\n/**\n * Generate storage key for API key by ID\n */\nfunction getStorageKeyById(id: string): string {\n\treturn `api-key:by-id:${id}`;\n}\n\n/**\n * Generate storage key for user's API key list\n */\nfunction getStorageKeyByUserId(userId: string): string {\n\treturn `api-key:by-user:${userId}`;\n}\n\n/**\n * Serialize API key for storage\n */\nfunction serializeApiKey(apiKey: ApiKey): string {\n\treturn JSON.stringify({\n\t\t...apiKey,\n\t\tcreatedAt: apiKey.createdAt.toISOString(),\n\t\tupdatedAt: apiKey.updatedAt.toISOString(),\n\t\texpiresAt: apiKey.expiresAt?.toISOString() ?? null,\n\t\tlastRefillAt: apiKey.lastRefillAt?.toISOString() ?? null,\n\t\tlastRequest: apiKey.lastRequest?.toISOString() ?? null,\n\t});\n}\n\n/**\n * Deserialize API key from storage\n */\nfunction deserializeApiKey(data: unknown): ApiKey | null {\n\tif (!data || typeof data !== \"string\") {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst parsed = JSON.parse(data);\n\t\treturn {\n\t\t\t...parsed,\n\t\t\tcreatedAt: new Date(parsed.createdAt),\n\t\t\tupdatedAt: new Date(parsed.updatedAt),\n\t\t\texpiresAt: parsed.expiresAt ? new Date(parsed.expiresAt) : null,\n\t\t\tlastRefillAt: parsed.lastRefillAt ? new Date(parsed.lastRefillAt) : null,\n\t\t\tlastRequest: parsed.lastRequest ? new Date(parsed.lastRequest) : null,\n\t\t} as ApiKey;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Get the storage instance to use (custom methods take precedence)\n */\nfunction getStorageInstance(\n\tctx: GenericEndpointContext,\n\topts: PredefinedApiKeyOptions,\n): SecondaryStorage | null {\n\tif (opts.customStorage) {\n\t\treturn opts.customStorage as SecondaryStorage;\n\t}\n\treturn ctx.context.secondaryStorage || null;\n}\n\n/**\n * Calculate TTL in seconds for an API key\n */\nfunction calculateTTL(apiKey: ApiKey): number | undefined {\n\tif (apiKey.expiresAt) {\n\t\tconst now = Date.now();\n\t\tconst expiresAt = new Date(apiKey.expiresAt).getTime();\n\t\tconst ttlSeconds = Math.floor((expiresAt - now) / 1000);\n\t\t// Only set TTL if expiration is in the future\n\t\tif (ttlSeconds > 0) {\n\t\t\treturn ttlSeconds;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Get API key from secondary storage by hashed key\n */\nasync function getApiKeyFromStorage(\n\tctx: GenericEndpointContext,\n\thashedKey: string,\n\tstorage: SecondaryStorage,\n): Promise<ApiKey | null> {\n\tconst key = getStorageKeyByHashedKey(hashedKey);\n\tconst data = await storage.get(key);\n\treturn deserializeApiKey(data);\n}\n\n/**\n * Get API key from secondary storage by ID\n */\nasync function getApiKeyByIdFromStorage(\n\tctx: GenericEndpointContext,\n\tid: string,\n\tstorage: SecondaryStorage,\n): Promise<ApiKey | null> {\n\tconst key = getStorageKeyById(id);\n\tconst data = await storage.get(key);\n\treturn deserializeApiKey(data);\n}\n\n/**\n * Store API key in secondary storage\n */\nasync function setApiKeyInStorage(\n\tctx: GenericEndpointContext,\n\tapiKey: ApiKey,\n\tstorage: SecondaryStorage,\n\tttl?: number | undefined,\n): Promise<void> {\n\tconst serialized = serializeApiKey(apiKey);\n\tconst hashedKey = apiKey.key;\n\tconst id = apiKey.id;\n\n\t// Store by hashed key (primary lookup)\n\tawait storage.set(getStorageKeyByHashedKey(hashedKey), serialized, ttl);\n\n\t// Store by ID (for ID-based lookups)\n\tawait storage.set(getStorageKeyById(id), serialized, ttl);\n\n\t// Update user's API key list\n\tconst userKey = getStorageKeyByUserId(apiKey.userId);\n\tconst userListData = await storage.get(userKey);\n\tlet userIds: string[] = [];\n\n\tif (userListData && typeof userListData === \"string\") {\n\t\ttry {\n\t\t\tuserIds = JSON.parse(userListData);\n\t\t} catch {\n\t\t\tuserIds = [];\n\t\t}\n\t} else if (Array.isArray(userListData)) {\n\t\tuserIds = userListData;\n\t}\n\n\tif (!userIds.includes(id)) {\n\t\tuserIds.push(id);\n\t\tawait storage.set(userKey, JSON.stringify(userIds));\n\t}\n}\n\n/**\n * Delete API key from secondary storage\n */\nasync function deleteApiKeyFromStorage(\n\tctx: GenericEndpointContext,\n\tapiKey: ApiKey,\n\tstorage: SecondaryStorage,\n): Promise<void> {\n\tconst hashedKey = apiKey.key;\n\tconst id = apiKey.id;\n\tconst userId = apiKey.userId;\n\n\t// Delete by hashed key\n\tawait storage.delete(getStorageKeyByHashedKey(hashedKey));\n\n\t// Delete by ID\n\tawait storage.delete(getStorageKeyById(id));\n\n\t// Update user's API key list\n\tconst userKey = getStorageKeyByUserId(userId);\n\tconst userListData = await storage.get(userKey);\n\tlet userIds: string[] = [];\n\n\tif (userListData && typeof userListData === \"string\") {\n\t\ttry {\n\t\t\tuserIds = JSON.parse(userListData);\n\t\t} catch {\n\t\t\tuserIds = [];\n\t\t}\n\t} else if (Array.isArray(userListData)) {\n\t\tuserIds = userListData;\n\t}\n\n\tconst filteredIds = userIds.filter((keyId) => keyId !== id);\n\tif (filteredIds.length === 0) {\n\t\tawait storage.delete(userKey);\n\t} else {\n\t\tawait storage.set(userKey, JSON.stringify(filteredIds));\n\t}\n}\n\n/**\n * Unified getter for API keys with support for all storage modes\n */\nexport async function getApiKey(\n\tctx: GenericEndpointContext,\n\thashedKey: string,\n\topts: PredefinedApiKeyOptions,\n): Promise<ApiKey | null> {\n\tconst storage = getStorageInstance(ctx, opts);\n\n\t// Database mode only\n\tif (opts.storage === \"database\") {\n\t\treturn await ctx.context.adapter.findOne<ApiKey>({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"key\",\n\t\t\t\t\tvalue: hashedKey,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\t// Secondary storage mode with fallback\n\tif (opts.storage === \"secondary-storage\" && opts.fallbackToDatabase) {\n\t\tif (storage) {\n\t\t\tconst cached = await getApiKeyFromStorage(ctx, hashedKey, storage);\n\t\t\tif (cached) {\n\t\t\t\treturn cached;\n\t\t\t}\n\t\t}\n\t\tconst dbKey = await ctx.context.adapter.findOne<ApiKey>({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"key\",\n\t\t\t\t\tvalue: hashedKey,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tif (dbKey && storage) {\n\t\t\t// Populate secondary storage for future reads\n\t\t\tconst ttl = calculateTTL(dbKey);\n\t\t\tawait setApiKeyInStorage(ctx, dbKey, storage, ttl);\n\t\t}\n\n\t\treturn dbKey;\n\t}\n\n\t// Secondary storage mode only\n\tif (opts.storage === \"secondary-storage\") {\n\t\tif (!storage) {\n\t\t\treturn null;\n\t\t}\n\t\treturn await getApiKeyFromStorage(ctx, hashedKey, storage);\n\t}\n\n\t// Default fallback\n\treturn await ctx.context.adapter.findOne<ApiKey>({\n\t\tmodel: \"apikey\",\n\t\twhere: [\n\t\t\t{\n\t\t\t\tfield: \"key\",\n\t\t\t\tvalue: hashedKey,\n\t\t\t},\n\t\t],\n\t});\n}\n\n/**\n * Unified getter for API keys by ID\n */\nexport async function getApiKeyById(\n\tctx: GenericEndpointContext,\n\tid: string,\n\topts: PredefinedApiKeyOptions,\n): Promise<ApiKey | null> {\n\tconst storage = getStorageInstance(ctx, opts);\n\n\t// Database mode only\n\tif (opts.storage === \"database\") {\n\t\treturn await ctx.context.adapter.findOne<ApiKey>({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: id,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\t// Secondary storage mode with fallback\n\tif (opts.storage === \"secondary-storage\" && opts.fallbackToDatabase) {\n\t\tif (storage) {\n\t\t\tconst cached = await getApiKeyByIdFromStorage(ctx, id, storage);\n\t\t\tif (cached) {\n\t\t\t\treturn cached;\n\t\t\t}\n\t\t}\n\t\tconst dbKey = await ctx.context.adapter.findOne<ApiKey>({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: id,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tif (dbKey && storage) {\n\t\t\t// Populate secondary storage for future reads\n\t\t\tconst ttl = calculateTTL(dbKey);\n\t\t\tawait setApiKeyInStorage(ctx, dbKey, storage, ttl);\n\t\t}\n\n\t\treturn dbKey;\n\t}\n\n\t// Secondary storage mode only\n\tif (opts.storage === \"secondary-storage\") {\n\t\tif (!storage) {\n\t\t\treturn null;\n\t\t}\n\t\treturn await getApiKeyByIdFromStorage(ctx, id, storage);\n\t}\n\n\t// Default fallback\n\treturn await ctx.context.adapter.findOne<ApiKey>({\n\t\tmodel: \"apikey\",\n\t\twhere: [\n\t\t\t{\n\t\t\t\tfield: \"id\",\n\t\t\t\tvalue: id,\n\t\t\t},\n\t\t],\n\t});\n}\n\n/**\n * Unified setter for API keys with support for all storage modes\n */\nexport async function setApiKey(\n\tctx: GenericEndpointContext,\n\tapiKey: ApiKey,\n\topts: PredefinedApiKeyOptions,\n): Promise<void> {\n\tconst storage = getStorageInstance(ctx, opts);\n\tconst ttl = calculateTTL(apiKey);\n\n\t// Database mode only - handled by adapter in route handlers\n\tif (opts.storage === \"database\") {\n\t\treturn;\n\t}\n\n\t// Secondary storage mode (with or without fallback)\n\tif (opts.storage === \"secondary-storage\") {\n\t\tif (!storage) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Secondary storage is required when storage mode is 'secondary-storage'\",\n\t\t\t);\n\t\t}\n\t\tawait setApiKeyInStorage(ctx, apiKey, storage, ttl);\n\t\treturn;\n\t}\n}\n\n/**\n * Unified deleter for API keys with support for all storage modes\n */\nexport async function deleteApiKey(\n\tctx: GenericEndpointContext,\n\tapiKey: ApiKey,\n\topts: PredefinedApiKeyOptions,\n): Promise<void> {\n\tconst storage = getStorageInstance(ctx, opts);\n\n\t// Database mode only - handled by adapter in route handlers\n\tif (opts.storage === \"database\") {\n\t\treturn;\n\t}\n\n\t// Secondary storage mode (with or without fallback)\n\tif (opts.storage === \"secondary-storage\") {\n\t\tif (!storage) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Secondary storage is required when storage mode is 'secondary-storage'\",\n\t\t\t);\n\t\t}\n\t\tawait deleteApiKeyFromStorage(ctx, apiKey, storage);\n\t\treturn;\n\t}\n}\n\nexport interface ListApiKeysOptions {\n\tlimit?: number;\n\toffset?: number;\n\tsortBy?: string;\n\tsortDirection?: \"asc\" | \"desc\";\n}\n\nexport interface ListApiKeysResult {\n\tapiKeys: ApiKey[];\n\ttotal: number;\n}\n\n/**\n * Apply sorting and pagination to an array of API keys in memory\n * Used for secondary storage mode where we can't rely on database operations\n */\nfunction applySortingAndPagination(\n\tapiKeys: ApiKey[],\n\tsortBy?: string,\n\tsortDirection?: \"asc\" | \"desc\",\n\tlimit?: number,\n\toffset?: number,\n): ApiKey[] {\n\tlet result = [...apiKeys];\n\n\t// Apply sorting if sortBy is specified\n\tif (sortBy) {\n\t\tconst direction = sortDirection || \"asc\";\n\t\tresult.sort((a, b) => {\n\t\t\tconst aValue = a[sortBy as keyof ApiKey];\n\t\t\tconst bValue = b[sortBy as keyof ApiKey];\n\n\t\t\t// Handle null/undefined values\n\t\t\tif (aValue == null && bValue == null) return 0;\n\t\t\tif (aValue == null) return direction === \"asc\" ? -1 : 1;\n\t\t\tif (bValue == null) return direction === \"asc\" ? 1 : -1;\n\n\t\t\t// Compare values\n\t\t\tif (aValue < bValue) return direction === \"asc\" ? -1 : 1;\n\t\t\tif (aValue > bValue) return direction === \"asc\" ? 1 : -1;\n\t\t\treturn 0;\n\t\t});\n\t}\n\n\t// Apply pagination\n\tif (offset !== undefined) {\n\t\tresult = result.slice(offset);\n\t}\n\tif (limit !== undefined) {\n\t\tresult = result.slice(0, limit);\n\t}\n\n\treturn result;\n}\n\n/**\n * List API keys for a user with support for all storage modes\n */\nexport async function listApiKeys(\n\tctx: GenericEndpointContext,\n\tuserId: string,\n\topts: PredefinedApiKeyOptions,\n\tpaginationOpts?: ListApiKeysOptions,\n): Promise<ListApiKeysResult> {\n\tconst storage = getStorageInstance(ctx, opts);\n\tconst { limit, offset, sortBy, sortDirection } = paginationOpts || {};\n\n\t// Database mode only\n\tif (opts.storage === \"database\") {\n\t\tconst [apiKeys, total] = await Promise.all([\n\t\t\tctx.context.adapter.findMany<ApiKey>({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\tsortBy: sortBy\n\t\t\t\t\t? { field: sortBy, direction: sortDirection || \"asc\" }\n\t\t\t\t\t: undefined,\n\t\t\t}),\n\t\t\tctx.context.adapter.count({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}),\n\t\t]);\n\t\treturn { apiKeys, total };\n\t}\n\n\t// Secondary storage mode with fallback\n\tif (opts.storage === \"secondary-storage\" && opts.fallbackToDatabase) {\n\t\tconst userKey = getStorageKeyByUserId(userId);\n\n\t\tif (storage) {\n\t\t\tconst userListData = await storage.get(userKey);\n\t\t\tlet userIds: string[] = [];\n\n\t\t\tif (userListData && typeof userListData === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\tuserIds = JSON.parse(userListData);\n\t\t\t\t} catch {\n\t\t\t\t\tuserIds = [];\n\t\t\t\t}\n\t\t\t} else if (Array.isArray(userListData)) {\n\t\t\t\tuserIds = userListData;\n\t\t\t}\n\n\t\t\tif (userIds.length > 0) {\n\t\t\t\tconst apiKeys: ApiKey[] = [];\n\t\t\t\tfor (const id of userIds) {\n\t\t\t\t\tconst apiKey = await getApiKeyByIdFromStorage(ctx, id, storage);\n\t\t\t\t\tif (apiKey) {\n\t\t\t\t\t\tapiKeys.push(apiKey);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Apply sorting and pagination in memory for secondary storage\n\t\t\t\tconst sortedKeys = applySortingAndPagination(\n\t\t\t\t\tapiKeys,\n\t\t\t\t\tsortBy,\n\t\t\t\t\tsortDirection,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t);\n\t\t\t\treturn { apiKeys: sortedKeys, total: apiKeys.length };\n\t\t\t}\n\t\t}\n\t\t// Fallback to database\n\t\tconst [dbKeys, total] = await Promise.all([\n\t\t\tctx.context.adapter.findMany<ApiKey>({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\tsortBy: sortBy\n\t\t\t\t\t? { field: sortBy, direction: sortDirection || \"asc\" }\n\t\t\t\t\t: undefined,\n\t\t\t}),\n\t\t\tctx.context.adapter.count({\n\t\t\t\tmodel: \"apikey\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}),\n\t\t]);\n\n\t\t// Populate secondary storage with fetched keys\n\t\tif (storage && dbKeys.length > 0) {\n\t\t\tconst userIds: string[] = [];\n\t\t\tfor (const apiKey of dbKeys) {\n\t\t\t\t// Store each key in secondary storage\n\t\t\t\tconst ttl = calculateTTL(apiKey);\n\t\t\t\tawait setApiKeyInStorage(ctx, apiKey, storage, ttl);\n\t\t\t\tuserIds.push(apiKey.id);\n\t\t\t}\n\t\t\t// Update user's key list in secondary storage\n\t\t\tawait storage.set(userKey, JSON.stringify(userIds));\n\t\t}\n\n\t\treturn { apiKeys: dbKeys, total };\n\t}\n\n\t// Secondary storage mode only\n\tif (opts.storage === \"secondary-storage\") {\n\t\tif (!storage) {\n\t\t\treturn { apiKeys: [], total: 0 };\n\t\t}\n\n\t\tconst userKey = getStorageKeyByUserId(userId);\n\t\tconst userListData = await storage.get(userKey);\n\t\tlet userIds: string[] = [];\n\n\t\tif (userListData && typeof userListData === \"string\") {\n\t\t\ttry {\n\t\t\t\tuserIds = JSON.parse(userListData);\n\t\t\t} catch {\n\t\t\t\treturn { apiKeys: [], total: 0 };\n\t\t\t}\n\t\t} else if (Array.isArray(userListData)) {\n\t\t\tuserIds = userListData;\n\t\t} else {\n\t\t\treturn { apiKeys: [], total: 0 };\n\t\t}\n\n\t\tconst apiKeys: ApiKey[] = [];\n\t\tfor (const id of userIds) {\n\t\t\tconst apiKey = await getApiKeyByIdFromStorage(ctx, id, storage);\n\t\t\tif (apiKey) {\n\t\t\t\tapiKeys.push(apiKey);\n\t\t\t}\n\t\t}\n\n\t\t// Apply sorting and pagination in memory for secondary storage\n\t\tconst sortedKeys = applySortingAndPagination(\n\t\t\tapiKeys,\n\t\t\tsortBy,\n\t\t\tsortDirection,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t);\n\t\treturn { apiKeys: sortedKeys, total: apiKeys.length };\n\t}\n\n\t// Default fallback\n\tconst [apiKeys, total] = await Promise.all([\n\t\tctx.context.adapter.findMany<ApiKey>({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\tvalue: userId,\n\t\t\t\t},\n\t\t\t],\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tsortBy: sortBy\n\t\t\t\t? { field: sortBy, direction: sortDirection || \"asc\" }\n\t\t\t\t: undefined,\n\t\t}),\n\t\tctx.context.adapter.count({\n\t\t\tmodel: \"apikey\",\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\tvalue: userId,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t]);\n\treturn { apiKeys, total };\n}\n"],"mappings":";;;;;;;;;AAYA,SAAgB,+BACf,UAC6B;AAE7B,KAAI,YAAY,KACf,QAAO;AAIR,KAAI,OAAO,aAAa,SACvB,QAAO;AAKR,QAAO,cAAmC,SAAS;;;;;AAMpD,SAAS,uBAAuB,UAAuC;AACtE,QAAO,YAAY,QAAQ,OAAO,aAAa;;;;;;AAOhD,eAAsB,2BACrB,KACA,SACA,MACgB;AAEhB,KAAI,KAAK,YAAY,cAAc,CAAC,KAAK,mBACxC;CAID,MAAM,gBAAgB,QAAQ,QA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C,IAAI,QAAQ,QAAQ,SAAiB;EACpC,OAAO;EACP,OAAO,CACN;GACC,OAAO;GACP,OAAO;GACP,CACD;EACD;EACA;EACA,QAAQ,SACL;GAAE,OAAO;GAAQ,WAAW,iBAAiB;GAAO,GACpD;EACH,CAAC,EACF,IAAI,QAAQ,QAAQ,MAAM;EACzB,OAAO;EACP,OAAO,CACN;GACC,OAAO;GACP,OAAO;GACP,CACD;EACD,CAAC,CACF,CAAC;AACF,QAAO;EAAE;EAAS;EAAO"}
@@ -0,0 +1,9 @@
1
+ import { API_KEY_ERROR_CODES } from "./error-codes.mjs";
2
+ import { ApiKey, ApiKeyOptions } from "./types.mjs";
3
+
4
+ //#region src/plugins/api-key/client.d.ts
5
+ declare const apiKeyClient: () => BetterAuthClientPlugin;
6
+ type ApiKeyClientPlugin = ReturnType<typeof apiKeyClient>;
7
+ //#endregion
8
+ export { ApiKeyClientPlugin, apiKeyClient };
9
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1,19 @@
1
+ import { API_KEY_ERROR_CODES } from "./error-codes.mjs";
2
+
3
+ //#region src/plugins/api-key/client.ts
4
+ const apiKeyClient = () => {
5
+ return {
6
+ id: "api-key",
7
+ $InferServerPlugin: {},
8
+ pathMethods: {
9
+ "/api-key/create": "POST",
10
+ "/api-key/delete": "POST",
11
+ "/api-key/delete-all-expired-api-keys": "POST"
12
+ },
13
+ $ERROR_CODES: API_KEY_ERROR_CODES
14
+ };
15
+ };
16
+
17
+ //#endregion
18
+ export { apiKeyClient };
19
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/api-key/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { apiKey } from \".\";\nimport { API_KEY_ERROR_CODES } from \"./error-codes\";\n\nexport * from \"./error-codes\";\n\nexport const apiKeyClient = () => {\n\treturn {\n\t\tid: \"api-key\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof apiKey>,\n\t\tpathMethods: {\n\t\t\t\"/api-key/create\": \"POST\",\n\t\t\t\"/api-key/delete\": \"POST\",\n\t\t\t\"/api-key/delete-all-expired-api-keys\": \"POST\",\n\t\t},\n\t\t$ERROR_CODES: API_KEY_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n\nexport type ApiKeyClientPlugin = ReturnType<typeof apiKeyClient>;\n\nexport type * from \"./types\";\n"],"mappings":";;;AAMA,MAAa,qBAAqB;AACjC,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,aAAa;GACZ,mBAAmB;GACnB,mBAAmB;GACnB,wCAAwC;GACxC;EACD,cAAc;EACd"}
@@ -0,0 +1,5 @@
1
+ //#region src/plugins/api-key/error-codes.d.ts
2
+ declare const API_KEY_ERROR_CODES: any;
3
+ //#endregion
4
+ export { API_KEY_ERROR_CODES };
5
+ //# sourceMappingURL=error-codes.d.mts.map
@@ -0,0 +1,34 @@
1
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
+
3
+ //#region src/plugins/api-key/error-codes.ts
4
+ const API_KEY_ERROR_CODES = defineErrorCodes({
5
+ INVALID_METADATA_TYPE: "metadata must be an object or undefined",
6
+ REFILL_AMOUNT_AND_INTERVAL_REQUIRED: "refillAmount is required when refillInterval is provided",
7
+ REFILL_INTERVAL_AND_AMOUNT_REQUIRED: "refillInterval is required when refillAmount is provided",
8
+ USER_BANNED: "User is banned",
9
+ UNAUTHORIZED_SESSION: "Unauthorized or invalid session",
10
+ KEY_NOT_FOUND: "API Key not found",
11
+ KEY_DISABLED: "API Key is disabled",
12
+ KEY_EXPIRED: "API Key has expired",
13
+ USAGE_EXCEEDED: "API Key has reached its usage limit",
14
+ KEY_NOT_RECOVERABLE: "API Key is not recoverable",
15
+ EXPIRES_IN_IS_TOO_SMALL: "The expiresIn is smaller than the predefined minimum value.",
16
+ EXPIRES_IN_IS_TOO_LARGE: "The expiresIn is larger than the predefined maximum value.",
17
+ INVALID_REMAINING: "The remaining count is either too large or too small.",
18
+ INVALID_PREFIX_LENGTH: "The prefix length is either too large or too small.",
19
+ INVALID_NAME_LENGTH: "The name length is either too large or too small.",
20
+ METADATA_DISABLED: "Metadata is disabled.",
21
+ RATE_LIMIT_EXCEEDED: "Rate limit exceeded.",
22
+ NO_VALUES_TO_UPDATE: "No values to update.",
23
+ KEY_DISABLED_EXPIRATION: "Custom key expiration values are disabled.",
24
+ INVALID_API_KEY: "Invalid API key.",
25
+ INVALID_USER_ID_FROM_API_KEY: "The user id from the API key is invalid.",
26
+ INVALID_API_KEY_GETTER_RETURN_TYPE: "API Key getter returned an invalid key type. Expected string.",
27
+ SERVER_ONLY_PROPERTY: "The property you're trying to set can only be set from the server auth instance only.",
28
+ FAILED_TO_UPDATE_API_KEY: "Failed to update API key",
29
+ NAME_REQUIRED: "API Key name is required."
30
+ });
31
+
32
+ //#endregion
33
+ export { API_KEY_ERROR_CODES };
34
+ //# sourceMappingURL=error-codes.mjs.map