better-auth 1.2.6-beta.7 → 1.2.7-beta.1

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 (273) hide show
  1. package/dist/adapters/drizzle-adapter/index.cjs +186 -249
  2. package/dist/adapters/drizzle-adapter/index.d.cts +11 -49
  3. package/dist/adapters/drizzle-adapter/index.d.mts +11 -49
  4. package/dist/adapters/drizzle-adapter/index.d.ts +11 -49
  5. package/dist/adapters/drizzle-adapter/index.mjs +186 -249
  6. package/dist/adapters/index.cjs +26 -0
  7. package/dist/adapters/index.d.cts +17 -0
  8. package/dist/adapters/index.d.mts +17 -0
  9. package/dist/adapters/index.d.ts +17 -0
  10. package/dist/adapters/index.mjs +20 -0
  11. package/dist/adapters/kysely-adapter/index.cjs +7 -7
  12. package/dist/adapters/kysely-adapter/index.d.cts +17 -49
  13. package/dist/adapters/kysely-adapter/index.d.mts +17 -49
  14. package/dist/adapters/kysely-adapter/index.d.ts +17 -49
  15. package/dist/adapters/kysely-adapter/index.mjs +8 -8
  16. package/dist/adapters/memory-adapter/index.cjs +7 -8
  17. package/dist/adapters/memory-adapter/index.d.cts +9 -49
  18. package/dist/adapters/memory-adapter/index.d.mts +9 -49
  19. package/dist/adapters/memory-adapter/index.d.ts +9 -49
  20. package/dist/adapters/memory-adapter/index.mjs +8 -9
  21. package/dist/adapters/mongodb-adapter/index.cjs +2 -2
  22. package/dist/adapters/mongodb-adapter/index.d.cts +4 -4
  23. package/dist/adapters/mongodb-adapter/index.d.mts +4 -4
  24. package/dist/adapters/mongodb-adapter/index.d.ts +4 -4
  25. package/dist/adapters/mongodb-adapter/index.mjs +3 -3
  26. package/dist/adapters/prisma-adapter/index.cjs +130 -203
  27. package/dist/adapters/prisma-adapter/index.d.cts +17 -49
  28. package/dist/adapters/prisma-adapter/index.d.mts +17 -49
  29. package/dist/adapters/prisma-adapter/index.d.ts +17 -49
  30. package/dist/adapters/prisma-adapter/index.mjs +131 -204
  31. package/dist/adapters/test.cjs +710 -377
  32. package/dist/adapters/test.d.cts +64 -5
  33. package/dist/adapters/test.d.mts +64 -5
  34. package/dist/adapters/test.d.ts +64 -5
  35. package/dist/adapters/test.mjs +712 -380
  36. package/dist/api/index.cjs +61 -25
  37. package/dist/api/index.d.cts +3 -3
  38. package/dist/api/index.d.mts +3 -3
  39. package/dist/api/index.d.ts +3 -3
  40. package/dist/api/index.mjs +63 -27
  41. package/dist/client/index.d.cts +3 -3
  42. package/dist/client/index.d.mts +3 -3
  43. package/dist/client/index.d.ts +3 -3
  44. package/dist/client/plugins/index.cjs +13 -15
  45. package/dist/client/plugins/index.d.cts +80 -19
  46. package/dist/client/plugins/index.d.mts +80 -19
  47. package/dist/client/plugins/index.d.ts +80 -19
  48. package/dist/client/plugins/index.mjs +13 -16
  49. package/dist/client/react/index.cjs +4 -4
  50. package/dist/client/react/index.d.cts +3 -3
  51. package/dist/client/react/index.d.mts +3 -3
  52. package/dist/client/react/index.d.ts +3 -3
  53. package/dist/client/solid/index.d.cts +3 -3
  54. package/dist/client/solid/index.d.mts +3 -3
  55. package/dist/client/solid/index.d.ts +3 -3
  56. package/dist/client/svelte/index.d.cts +3 -3
  57. package/dist/client/svelte/index.d.mts +3 -3
  58. package/dist/client/svelte/index.d.ts +3 -3
  59. package/dist/client/vue/index.d.cts +3 -3
  60. package/dist/client/vue/index.d.mts +3 -3
  61. package/dist/client/vue/index.d.ts +3 -3
  62. package/dist/cookies/index.cjs +13 -2
  63. package/dist/cookies/index.d.cts +3 -3
  64. package/dist/cookies/index.d.mts +3 -3
  65. package/dist/cookies/index.d.ts +3 -3
  66. package/dist/cookies/index.mjs +13 -2
  67. package/dist/db/index.cjs +6 -5
  68. package/dist/db/index.d.cts +4 -4
  69. package/dist/db/index.d.mts +4 -4
  70. package/dist/db/index.d.ts +4 -4
  71. package/dist/db/index.mjs +7 -6
  72. package/dist/index.cjs +11 -7
  73. package/dist/index.d.cts +4 -4
  74. package/dist/index.d.mts +4 -4
  75. package/dist/index.d.ts +4 -4
  76. package/dist/index.mjs +14 -10
  77. package/dist/integrations/next-js.cjs +4 -5
  78. package/dist/integrations/next-js.d.cts +3 -3
  79. package/dist/integrations/next-js.d.mts +3 -3
  80. package/dist/integrations/next-js.d.ts +3 -3
  81. package/dist/integrations/next-js.mjs +5 -6
  82. package/dist/integrations/node.d.cts +3 -3
  83. package/dist/integrations/node.d.mts +3 -3
  84. package/dist/integrations/node.d.ts +3 -3
  85. package/dist/integrations/react-start.cjs +5 -6
  86. package/dist/integrations/react-start.d.cts +3 -3
  87. package/dist/integrations/react-start.d.mts +3 -3
  88. package/dist/integrations/react-start.d.ts +3 -3
  89. package/dist/integrations/react-start.mjs +6 -7
  90. package/dist/integrations/svelte-kit.d.cts +3 -3
  91. package/dist/integrations/svelte-kit.d.mts +3 -3
  92. package/dist/integrations/svelte-kit.d.ts +3 -3
  93. package/dist/oauth2/index.d.cts +5 -5
  94. package/dist/oauth2/index.d.mts +5 -5
  95. package/dist/oauth2/index.d.ts +5 -5
  96. package/dist/plugins/access/index.d.cts +1 -1
  97. package/dist/plugins/access/index.d.mts +1 -1
  98. package/dist/plugins/access/index.d.ts +1 -1
  99. package/dist/plugins/admin/access/index.d.cts +1 -1
  100. package/dist/plugins/admin/access/index.d.mts +1 -1
  101. package/dist/plugins/admin/access/index.d.ts +1 -1
  102. package/dist/plugins/admin/index.cjs +4 -4
  103. package/dist/plugins/admin/index.d.cts +74 -14
  104. package/dist/plugins/admin/index.d.mts +74 -14
  105. package/dist/plugins/admin/index.d.ts +74 -14
  106. package/dist/plugins/admin/index.mjs +5 -5
  107. package/dist/plugins/anonymous/index.cjs +4 -5
  108. package/dist/plugins/anonymous/index.d.cts +3 -3
  109. package/dist/plugins/anonymous/index.d.mts +3 -3
  110. package/dist/plugins/anonymous/index.d.ts +3 -3
  111. package/dist/plugins/anonymous/index.mjs +5 -6
  112. package/dist/plugins/bearer/index.cjs +2 -2
  113. package/dist/plugins/bearer/index.d.cts +3 -3
  114. package/dist/plugins/bearer/index.d.mts +3 -3
  115. package/dist/plugins/bearer/index.d.ts +3 -3
  116. package/dist/plugins/bearer/index.mjs +3 -3
  117. package/dist/plugins/captcha/index.cjs +110 -45
  118. package/dist/plugins/captcha/index.d.cts +26 -6
  119. package/dist/plugins/captcha/index.d.mts +26 -6
  120. package/dist/plugins/captcha/index.d.ts +26 -6
  121. package/dist/plugins/captcha/index.mjs +110 -45
  122. package/dist/plugins/custom-session/index.cjs +24 -5
  123. package/dist/plugins/custom-session/index.d.cts +25 -6
  124. package/dist/plugins/custom-session/index.d.mts +25 -6
  125. package/dist/plugins/custom-session/index.d.ts +25 -6
  126. package/dist/plugins/custom-session/index.mjs +25 -6
  127. package/dist/plugins/email-otp/index.cjs +96 -30
  128. package/dist/plugins/email-otp/index.d.cts +33 -10
  129. package/dist/plugins/email-otp/index.d.mts +33 -10
  130. package/dist/plugins/email-otp/index.d.ts +33 -10
  131. package/dist/plugins/email-otp/index.mjs +97 -31
  132. package/dist/plugins/generic-oauth/index.cjs +81 -20
  133. package/dist/plugins/generic-oauth/index.d.cts +46 -3
  134. package/dist/plugins/generic-oauth/index.d.mts +46 -3
  135. package/dist/plugins/generic-oauth/index.d.ts +46 -3
  136. package/dist/plugins/generic-oauth/index.mjs +82 -21
  137. package/dist/plugins/haveibeenpwned/index.cjs +98 -0
  138. package/dist/plugins/haveibeenpwned/index.d.cts +36 -0
  139. package/dist/plugins/haveibeenpwned/index.d.mts +36 -0
  140. package/dist/plugins/haveibeenpwned/index.d.ts +36 -0
  141. package/dist/plugins/haveibeenpwned/index.mjs +96 -0
  142. package/dist/plugins/index.cjs +583 -19
  143. package/dist/plugins/index.d.cts +7 -5
  144. package/dist/plugins/index.d.mts +7 -5
  145. package/dist/plugins/index.d.ts +7 -5
  146. package/dist/plugins/index.mjs +583 -21
  147. package/dist/plugins/jwt/index.cjs +45 -21
  148. package/dist/plugins/jwt/index.d.cts +52 -6
  149. package/dist/plugins/jwt/index.d.mts +52 -6
  150. package/dist/plugins/jwt/index.d.ts +52 -6
  151. package/dist/plugins/jwt/index.mjs +46 -22
  152. package/dist/plugins/magic-link/index.cjs +3 -3
  153. package/dist/plugins/magic-link/index.mjs +4 -4
  154. package/dist/plugins/multi-session/index.cjs +3 -3
  155. package/dist/plugins/multi-session/index.d.cts +3 -3
  156. package/dist/plugins/multi-session/index.d.mts +3 -3
  157. package/dist/plugins/multi-session/index.d.ts +3 -3
  158. package/dist/plugins/multi-session/index.mjs +4 -4
  159. package/dist/plugins/oauth-proxy/index.cjs +4 -4
  160. package/dist/plugins/oauth-proxy/index.d.cts +3 -3
  161. package/dist/plugins/oauth-proxy/index.d.mts +3 -3
  162. package/dist/plugins/oauth-proxy/index.d.ts +3 -3
  163. package/dist/plugins/oauth-proxy/index.mjs +5 -5
  164. package/dist/plugins/oidc-provider/index.cjs +227 -8
  165. package/dist/plugins/oidc-provider/index.d.cts +215 -3
  166. package/dist/plugins/oidc-provider/index.d.mts +215 -3
  167. package/dist/plugins/oidc-provider/index.d.ts +215 -3
  168. package/dist/plugins/oidc-provider/index.mjs +228 -9
  169. package/dist/plugins/one-tap/index.cjs +5 -5
  170. package/dist/plugins/one-tap/index.mjs +6 -6
  171. package/dist/plugins/one-time-token/index.cjs +119 -0
  172. package/dist/plugins/one-time-token/index.d.cts +134 -0
  173. package/dist/plugins/one-time-token/index.d.mts +134 -0
  174. package/dist/plugins/one-time-token/index.d.ts +134 -0
  175. package/dist/plugins/one-time-token/index.mjs +117 -0
  176. package/dist/plugins/open-api/index.cjs +3 -3
  177. package/dist/plugins/open-api/index.d.cts +3 -3
  178. package/dist/plugins/open-api/index.d.mts +3 -3
  179. package/dist/plugins/open-api/index.d.ts +3 -3
  180. package/dist/plugins/open-api/index.mjs +4 -4
  181. package/dist/plugins/organization/access/index.d.cts +1 -1
  182. package/dist/plugins/organization/access/index.d.mts +1 -1
  183. package/dist/plugins/organization/access/index.d.ts +1 -1
  184. package/dist/plugins/organization/index.cjs +4 -4
  185. package/dist/plugins/organization/index.d.cts +708 -55
  186. package/dist/plugins/organization/index.d.mts +708 -55
  187. package/dist/plugins/organization/index.d.ts +708 -55
  188. package/dist/plugins/organization/index.mjs +5 -5
  189. package/dist/plugins/passkey/index.cjs +82 -8
  190. package/dist/plugins/passkey/index.d.cts +72 -3
  191. package/dist/plugins/passkey/index.d.mts +72 -3
  192. package/dist/plugins/passkey/index.d.ts +72 -3
  193. package/dist/plugins/passkey/index.mjs +83 -9
  194. package/dist/plugins/phone-number/index.cjs +194 -26
  195. package/dist/plugins/phone-number/index.d.cts +132 -8
  196. package/dist/plugins/phone-number/index.d.mts +132 -8
  197. package/dist/plugins/phone-number/index.d.ts +132 -8
  198. package/dist/plugins/phone-number/index.mjs +195 -27
  199. package/dist/plugins/sso/index.cjs +190 -7
  200. package/dist/plugins/sso/index.d.cts +181 -15
  201. package/dist/plugins/sso/index.d.mts +181 -15
  202. package/dist/plugins/sso/index.d.ts +181 -15
  203. package/dist/plugins/sso/index.mjs +191 -8
  204. package/dist/plugins/two-factor/index.cjs +443 -92
  205. package/dist/plugins/two-factor/index.d.cts +230 -396
  206. package/dist/plugins/two-factor/index.d.mts +230 -396
  207. package/dist/plugins/two-factor/index.d.ts +230 -396
  208. package/dist/plugins/two-factor/index.mjs +431 -80
  209. package/dist/plugins/username/index.cjs +34 -31
  210. package/dist/plugins/username/index.d.cts +15 -12
  211. package/dist/plugins/username/index.d.mts +15 -12
  212. package/dist/plugins/username/index.d.ts +15 -12
  213. package/dist/plugins/username/index.mjs +35 -32
  214. package/dist/shared/better-auth.1DR6suCQ.mjs +307 -0
  215. package/dist/shared/{better-auth.BSsp73pg.cjs → better-auth.B7cZ2juS.cjs} +15 -14
  216. package/dist/shared/{better-auth.bKwabe3I.d.mts → better-auth.B88xucNq.d.mts} +529 -39
  217. package/dist/shared/{better-auth.CApEjVDP.cjs → better-auth.BW8BpneG.cjs} +4 -1
  218. package/dist/shared/{better-auth.BiQsvaIP.d.cts → better-auth.BcU1Kjyq.d.cts} +2051 -518
  219. package/dist/shared/better-auth.BfG24BjZ.cjs +118 -0
  220. package/dist/shared/{better-auth.A3TjrU8G.mjs → better-auth.Bk5IMdhM.mjs} +32 -12
  221. package/dist/shared/{better-auth.D9VnBkRI.mjs → better-auth.Bm9HxIzE.mjs} +47 -24
  222. package/dist/shared/{better-auth.BRf6Iynu.d.ts → better-auth.Bwc-6kOr.d.ts} +1 -1
  223. package/dist/shared/{better-auth.D-oLmHIj.d.mts → better-auth.CA2hFK4N.d.ts} +2051 -518
  224. package/dist/shared/{better-auth.Dmhe30iW.d.mts → better-auth.CGukGrxT.d.cts} +1 -1
  225. package/dist/shared/{better-auth.CsSpq0zL.cjs → better-auth.CHUzBidy.cjs} +46 -23
  226. package/dist/shared/{better-auth.DWRligF8.d.cts → better-auth.CT9J6rD-.d.cts} +539 -7
  227. package/dist/shared/better-auth.CVCo5Z2T.cjs +310 -0
  228. package/dist/shared/{better-auth.D4jH-sJA.mjs → better-auth.CWwVo_61.mjs} +458 -118
  229. package/dist/shared/{better-auth.Bi8FQwDD.d.cts → better-auth.CYegVoq1.d.cts} +1 -1
  230. package/dist/shared/{better-auth.Bi8FQwDD.d.mts → better-auth.CYegVoq1.d.mts} +1 -1
  231. package/dist/shared/{better-auth.Bi8FQwDD.d.ts → better-auth.CYegVoq1.d.ts} +1 -1
  232. package/dist/shared/{better-auth.CepcSj5H.mjs → better-auth.Cc72UxUH.mjs} +1 -2
  233. package/dist/shared/{better-auth.BWp5dztg.d.ts → better-auth.CmN4mlPh.d.ts} +539 -7
  234. package/dist/shared/{better-auth.DH3YjMQH.mjs → better-auth.Cqykj82J.mjs} +1 -1
  235. package/dist/shared/{better-auth.wcdMj2cT.d.mts → better-auth.DIt2e3lu.d.mts} +539 -7
  236. package/dist/shared/{better-auth.BANAxdkL.d.ts → better-auth.DNTAFSt1.d.ts} +529 -39
  237. package/dist/shared/{better-auth.DU2QNVc_.d.ts → better-auth.DQ7OSJbI.d.mts} +2051 -518
  238. package/dist/shared/{better-auth.DLTzKoOS.cjs → better-auth.DSVbLSt7.cjs} +4 -1
  239. package/dist/shared/{better-auth.B2Fw1vhH.d.cts → better-auth.DTiSPWEk.d.cts} +529 -39
  240. package/dist/shared/better-auth.DURsStt9.mjs +116 -0
  241. package/dist/shared/{better-auth.BIjcZ_vt.cjs → better-auth.DYoLD99C.cjs} +31 -11
  242. package/dist/shared/{better-auth.CV1L7TPV.cjs → better-auth.D_ZIX1O8.cjs} +317 -47
  243. package/dist/shared/{better-auth.C5H9XEzZ.cjs → better-auth.DcWKCjjf.cjs} +1 -2
  244. package/dist/shared/{better-auth.BDYXUcLv.cjs → better-auth.Dg0siV5C.cjs} +457 -117
  245. package/dist/shared/better-auth.DjryM8pE.cjs +760 -0
  246. package/dist/shared/{better-auth.DPBQN9Fs.mjs → better-auth.Dn_Ms1Uf.mjs} +318 -48
  247. package/dist/shared/{better-auth.DiG4KL2x.mjs → better-auth.OuYYTHC7.mjs} +4 -1
  248. package/dist/shared/{better-auth.DtC8i3pf.d.cts → better-auth.S1jimRbX.d.mts} +1 -1
  249. package/dist/shared/better-auth.SPmq4a4z.d.mts +344 -0
  250. package/dist/shared/{better-auth.cOCrlspr.mjs → better-auth.bkwPl2G4.mjs} +4 -1
  251. package/dist/shared/better-auth.cp2rC2iM.d.ts +344 -0
  252. package/dist/shared/better-auth.eVy4DZvP.d.cts +344 -0
  253. package/dist/shared/{better-auth.BrOpzmqo.mjs → better-auth.iKoUsdFE.mjs} +15 -14
  254. package/dist/shared/better-auth.rSYJCd3o.mjs +758 -0
  255. package/dist/social-providers/index.cjs +75 -3
  256. package/dist/social-providers/index.d.cts +2 -2
  257. package/dist/social-providers/index.d.mts +2 -2
  258. package/dist/social-providers/index.d.ts +2 -2
  259. package/dist/social-providers/index.mjs +77 -6
  260. package/dist/types/index.d.cts +4 -4
  261. package/dist/types/index.d.mts +4 -4
  262. package/dist/types/index.d.ts +4 -4
  263. package/package.json +42 -5
  264. package/dist/chunks/server.cjs +0 -905
  265. package/dist/chunks/server.mjs +0 -895
  266. package/dist/shared/better-auth.BcoSd9tC.mjs +0 -10
  267. package/dist/shared/better-auth.BnRFp-t0.mjs +0 -405
  268. package/dist/shared/better-auth.C1-vpKly.cjs +0 -12
  269. package/dist/shared/better-auth.ClTSOgiD.mjs +0 -140
  270. package/dist/shared/better-auth.DC8JQbiE.mjs +0 -173
  271. package/dist/shared/better-auth.DWHWPllD.cjs +0 -175
  272. package/dist/shared/better-auth.DqLjzBlO.cjs +0 -408
  273. package/dist/shared/better-auth.m575EIBC.cjs +0 -144
@@ -1,408 +0,0 @@
1
- 'use strict';
2
-
3
- const kysely = require('kysely');
4
- require('./better-auth.C5H9XEzZ.cjs');
5
- require('./better-auth.DiSjtgs9.cjs');
6
- const id = require('./better-auth.Bg6iw3ig.cjs');
7
- require('zod');
8
- require('better-call');
9
- require('@better-auth/utils/hash');
10
- require('@noble/ciphers/chacha');
11
- require('@noble/ciphers/utils');
12
- require('@noble/ciphers/webcrypto');
13
- require('@better-auth/utils/base64');
14
- require('jose');
15
- require('@noble/hashes/scrypt');
16
- require('@better-auth/utils');
17
- require('@better-auth/utils/hex');
18
- require('@noble/hashes/utils');
19
- require('./better-auth.CYeOI8C-.cjs');
20
- require('./better-auth.GpOOav9x.cjs');
21
- const getTables = require('./better-auth.BEphVDyL.cjs');
22
- const utils = require('./better-auth.CUdxApHl.cjs');
23
-
24
- function getDatabaseType(db) {
25
- if (!db) {
26
- return null;
27
- }
28
- if ("dialect" in db) {
29
- return getDatabaseType(db.dialect);
30
- }
31
- if ("createDriver" in db) {
32
- if (db instanceof kysely.SqliteDialect) {
33
- return "sqlite";
34
- }
35
- if (db instanceof kysely.MysqlDialect) {
36
- return "mysql";
37
- }
38
- if (db instanceof kysely.PostgresDialect) {
39
- return "postgres";
40
- }
41
- if (db instanceof kysely.MssqlDialect) {
42
- return "mssql";
43
- }
44
- }
45
- if ("aggregate" in db) {
46
- return "sqlite";
47
- }
48
- if ("getConnection" in db) {
49
- return "mysql";
50
- }
51
- if ("connect" in db) {
52
- return "postgres";
53
- }
54
- return null;
55
- }
56
- const createKyselyAdapter = async (config) => {
57
- const db = config.database;
58
- if (!db) {
59
- return {
60
- kysely: null,
61
- databaseType: null
62
- };
63
- }
64
- if ("db" in db) {
65
- return {
66
- kysely: db.db,
67
- databaseType: db.type
68
- };
69
- }
70
- if ("dialect" in db) {
71
- return {
72
- kysely: new kysely.Kysely({ dialect: db.dialect }),
73
- databaseType: db.type
74
- };
75
- }
76
- let dialect = void 0;
77
- const databaseType = getDatabaseType(db);
78
- if ("createDriver" in db) {
79
- dialect = db;
80
- }
81
- if ("aggregate" in db) {
82
- dialect = new kysely.SqliteDialect({
83
- database: db
84
- });
85
- }
86
- if ("getConnection" in db) {
87
- dialect = new kysely.MysqlDialect(db);
88
- }
89
- if ("connect" in db) {
90
- dialect = new kysely.PostgresDialect({
91
- pool: db
92
- });
93
- }
94
- return {
95
- kysely: dialect ? new kysely.Kysely({ dialect }) : null,
96
- databaseType
97
- };
98
- };
99
-
100
- const createTransform = (db, options, config) => {
101
- const schema = getTables.getAuthTables(options);
102
- function getField(model, field) {
103
- if (field === "id") {
104
- return field;
105
- }
106
- const f = schema[model].fields[field];
107
- if (!f) {
108
- console.log("Field not found", model, field);
109
- }
110
- return f.fieldName || field;
111
- }
112
- function transformValueToDB(value, model, field) {
113
- if (field === "id") {
114
- return value;
115
- }
116
- const { type = "sqlite" } = config || {};
117
- const f = schema[model].fields[field];
118
- if (f.type === "boolean" && (type === "sqlite" || type === "mssql") && value !== null && value !== void 0) {
119
- return value ? 1 : 0;
120
- }
121
- if (f.type === "date" && value && value instanceof Date) {
122
- return type === "sqlite" ? value.toISOString() : value;
123
- }
124
- return value;
125
- }
126
- function transformValueFromDB(value, model, field) {
127
- const { type = "sqlite" } = config || {};
128
- const f = schema[model].fields[field];
129
- if (f.type === "boolean" && (type === "sqlite" || type === "mssql") && value !== null) {
130
- return value === 1;
131
- }
132
- if (f.type === "date" && value) {
133
- return new Date(value);
134
- }
135
- return value;
136
- }
137
- function getModelName(model) {
138
- return schema[model].modelName;
139
- }
140
- const useDatabaseGeneratedId = options?.advanced?.generateId === false;
141
- return {
142
- transformInput(data, model, action) {
143
- const transformedData = useDatabaseGeneratedId || action === "update" ? {} : {
144
- id: options.advanced?.generateId ? options.advanced.generateId({
145
- model
146
- }) : data.id || id.generateId()
147
- };
148
- const fields = schema[model].fields;
149
- for (const field in fields) {
150
- const value = data[field];
151
- transformedData[fields[field].fieldName || field] = utils.withApplyDefault(
152
- transformValueToDB(value, model, field),
153
- fields[field],
154
- action
155
- );
156
- }
157
- return transformedData;
158
- },
159
- transformOutput(data, model, select = []) {
160
- if (!data) return null;
161
- const transformedData = data.id ? select.length === 0 || select.includes("id") ? {
162
- id: data.id
163
- } : {} : {};
164
- const tableSchema = schema[model].fields;
165
- for (const key in tableSchema) {
166
- if (select.length && !select.includes(key)) {
167
- continue;
168
- }
169
- const field = tableSchema[key];
170
- if (field) {
171
- transformedData[key] = transformValueFromDB(
172
- data[field.fieldName || key],
173
- model,
174
- key
175
- );
176
- }
177
- }
178
- return transformedData;
179
- },
180
- convertWhereClause(model, w) {
181
- if (!w)
182
- return {
183
- and: null,
184
- or: null
185
- };
186
- const conditions = {
187
- and: [],
188
- or: []
189
- };
190
- w.forEach((condition) => {
191
- let {
192
- field: _field,
193
- value,
194
- operator = "=",
195
- connector = "AND"
196
- } = condition;
197
- const field = getField(model, _field);
198
- value = transformValueToDB(value, model, _field);
199
- const expr = (eb) => {
200
- if (operator.toLowerCase() === "in") {
201
- return eb(field, "in", Array.isArray(value) ? value : [value]);
202
- }
203
- if (operator === "contains") {
204
- return eb(field, "like", `%${value}%`);
205
- }
206
- if (operator === "starts_with") {
207
- return eb(field, "like", `${value}%`);
208
- }
209
- if (operator === "ends_with") {
210
- return eb(field, "like", `%${value}`);
211
- }
212
- if (operator === "eq") {
213
- return eb(field, "=", value);
214
- }
215
- if (operator === "ne") {
216
- return eb(field, "<>", value);
217
- }
218
- if (operator === "gt") {
219
- return eb(field, ">", value);
220
- }
221
- if (operator === "gte") {
222
- return eb(field, ">=", value);
223
- }
224
- if (operator === "lt") {
225
- return eb(field, "<", value);
226
- }
227
- if (operator === "lte") {
228
- return eb(field, "<=", value);
229
- }
230
- return eb(field, operator, value);
231
- };
232
- if (connector === "OR") {
233
- conditions.or.push(expr);
234
- } else {
235
- conditions.and.push(expr);
236
- }
237
- });
238
- return {
239
- and: conditions.and.length ? conditions.and : null,
240
- or: conditions.or.length ? conditions.or : null
241
- };
242
- },
243
- async withReturning(values, builder, model, where) {
244
- let res;
245
- if (config?.type === "mysql") {
246
- await builder.execute();
247
- const field = values.id ? "id" : where[0].field ? where[0].field : "id";
248
- const value = values[field] || where[0].value;
249
- res = await db.selectFrom(getModelName(model)).selectAll().where(getField(model, field), "=", value).executeTakeFirst();
250
- return res;
251
- }
252
- if (config?.type === "mssql") {
253
- res = await builder.outputAll("inserted").executeTakeFirst();
254
- return res;
255
- }
256
- res = await builder.returningAll().executeTakeFirst();
257
- return res;
258
- },
259
- getModelName,
260
- getField
261
- };
262
- };
263
- const kyselyAdapter = (db, config) => (opts) => {
264
- const {
265
- transformInput,
266
- withReturning,
267
- transformOutput,
268
- convertWhereClause,
269
- getModelName,
270
- getField
271
- } = createTransform(db, opts, config);
272
- return {
273
- id: "kysely",
274
- async create(data) {
275
- const { model, data: values, select } = data;
276
- const transformed = transformInput(values, model, "create");
277
- const builder = db.insertInto(getModelName(model)).values(transformed);
278
- return transformOutput(
279
- await withReturning(transformed, builder, model, []),
280
- model,
281
- select
282
- );
283
- },
284
- async findOne(data) {
285
- const { model, where, select } = data;
286
- const { and, or } = convertWhereClause(model, where);
287
- let query = db.selectFrom(getModelName(model)).selectAll();
288
- if (and) {
289
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
290
- }
291
- if (or) {
292
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
293
- }
294
- const res = await query.executeTakeFirst();
295
- if (!res) return null;
296
- return transformOutput(res, model, select);
297
- },
298
- async findMany(data) {
299
- const { model, where, limit, offset, sortBy } = data;
300
- const { and, or } = convertWhereClause(model, where);
301
- let query = db.selectFrom(getModelName(model));
302
- if (and) {
303
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
304
- }
305
- if (or) {
306
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
307
- }
308
- if (config?.type === "mssql") {
309
- if (!offset) {
310
- query = query.top(limit || 100);
311
- }
312
- } else {
313
- query = query.limit(limit || 100);
314
- }
315
- if (sortBy) {
316
- query = query.orderBy(
317
- getField(model, sortBy.field),
318
- sortBy.direction
319
- );
320
- }
321
- if (offset) {
322
- if (config?.type === "mssql") {
323
- if (!sortBy) {
324
- query = query.orderBy(getField(model, "id"));
325
- }
326
- query = query.offset(offset).fetch(limit || 100);
327
- } else {
328
- query = query.offset(offset);
329
- }
330
- }
331
- const res = await query.selectAll().execute();
332
- if (!res) return [];
333
- return res.map((r) => transformOutput(r, model));
334
- },
335
- async update(data) {
336
- const { model, where, update: values } = data;
337
- const { and, or } = convertWhereClause(model, where);
338
- const transformedData = transformInput(values, model, "update");
339
- let query = db.updateTable(getModelName(model)).set(transformedData);
340
- if (and) {
341
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
342
- }
343
- if (or) {
344
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
345
- }
346
- const res = await transformOutput(
347
- await withReturning(transformedData, query, model, where),
348
- model
349
- );
350
- return res;
351
- },
352
- async updateMany(data) {
353
- const { model, where, update: values } = data;
354
- const { and, or } = convertWhereClause(model, where);
355
- const transformedData = transformInput(values, model, "update");
356
- let query = db.updateTable(getModelName(model)).set(transformedData);
357
- if (and) {
358
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
359
- }
360
- if (or) {
361
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
362
- }
363
- const res = await query.execute();
364
- return res.length;
365
- },
366
- async count(data) {
367
- const { model, where } = data;
368
- const { and, or } = convertWhereClause(model, where);
369
- let query = db.selectFrom(getModelName(model)).select(db.fn.count("id").as("count"));
370
- if (and) {
371
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
372
- }
373
- if (or) {
374
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
375
- }
376
- const res = await query.execute();
377
- return res[0].count;
378
- },
379
- async delete(data) {
380
- const { model, where } = data;
381
- const { and, or } = convertWhereClause(model, where);
382
- let query = db.deleteFrom(getModelName(model));
383
- if (and) {
384
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
385
- }
386
- if (or) {
387
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
388
- }
389
- await query.execute();
390
- },
391
- async deleteMany(data) {
392
- const { model, where } = data;
393
- const { and, or } = convertWhereClause(model, where);
394
- let query = db.deleteFrom(getModelName(model));
395
- if (and) {
396
- query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
397
- }
398
- if (or) {
399
- query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
400
- }
401
- return (await query.execute()).length;
402
- },
403
- options: config
404
- };
405
- };
406
-
407
- exports.createKyselyAdapter = createKyselyAdapter;
408
- exports.kyselyAdapter = kyselyAdapter;
@@ -1,144 +0,0 @@
1
- 'use strict';
2
-
3
- const betterCall = require('better-call');
4
- const refreshToken = require('./better-auth.BDYXUcLv.cjs');
5
- const cookies_index = require('../cookies/index.cjs');
6
- const zod = require('zod');
7
- require('./better-auth.C5H9XEzZ.cjs');
8
- require('./better-auth.DiSjtgs9.cjs');
9
- require('./better-auth.GpOOav9x.cjs');
10
- require('defu');
11
- const hmac = require('@better-auth/utils/hmac');
12
-
13
- const TWO_FACTOR_COOKIE_NAME = "two_factor";
14
- const TRUST_DEVICE_COOKIE_NAME = "trust_device";
15
-
16
- const verifyTwoFactorMiddleware = refreshToken.createAuthMiddleware(
17
- {
18
- body: zod.z.object({
19
- /**
20
- * if true, the device will be trusted
21
- * for 30 days. It'll be refreshed on
22
- * every sign in request within this time.
23
- */
24
- trustDevice: zod.z.boolean().optional()
25
- })
26
- },
27
- async (ctx) => {
28
- const session = await refreshToken.getSessionFromCtx(ctx);
29
- if (!session) {
30
- const cookieName = ctx.context.createAuthCookie(TWO_FACTOR_COOKIE_NAME);
31
- const userId = await ctx.getSignedCookie(
32
- cookieName.name,
33
- ctx.context.secret
34
- );
35
- if (!userId) {
36
- throw new betterCall.APIError("UNAUTHORIZED", {
37
- message: "invalid two factor cookie"
38
- });
39
- }
40
- const user = await ctx.context.internalAdapter.findUserById(
41
- userId
42
- );
43
- if (!user) {
44
- throw new betterCall.APIError("UNAUTHORIZED", {
45
- message: "invalid two factor cookie"
46
- });
47
- }
48
- const dontRememberMe = await ctx.getSignedCookie(
49
- ctx.context.authCookies.dontRememberToken.name,
50
- ctx.context.secret
51
- );
52
- const session2 = await ctx.context.internalAdapter.createSession(
53
- userId,
54
- ctx.request,
55
- !!dontRememberMe
56
- );
57
- if (!session2) {
58
- throw new betterCall.APIError("INTERNAL_SERVER_ERROR", {
59
- message: "failed to create session"
60
- });
61
- }
62
- return {
63
- valid: async (ctx2) => {
64
- await cookies_index.setSessionCookie(ctx2, {
65
- session: session2,
66
- user
67
- });
68
- if (ctx2.body.trustDevice) {
69
- const trustDeviceCookie = ctx2.context.createAuthCookie(
70
- TRUST_DEVICE_COOKIE_NAME,
71
- {
72
- maxAge: 30 * 24 * 60 * 60
73
- // 30 days, it'll be refreshed on sign in requests
74
- }
75
- );
76
- const token = await hmac.createHMAC("SHA-256", "base64urlnopad").sign(
77
- ctx2.context.secret,
78
- `${user.id}!${session2.token}`
79
- );
80
- await ctx2.setSignedCookie(
81
- trustDeviceCookie.name,
82
- `${token}!${session2.token}`,
83
- ctx2.context.secret,
84
- trustDeviceCookie.attributes
85
- );
86
- ctx2.setCookie(ctx2.context.authCookies.dontRememberToken.name, "", {
87
- maxAge: 0
88
- });
89
- ctx2.setCookie(cookieName.name, "", {
90
- maxAge: 0
91
- });
92
- }
93
- return ctx2.json({
94
- token: session2.token,
95
- user: {
96
- id: user.id,
97
- email: user.email,
98
- emailVerified: user.emailVerified,
99
- name: user.name,
100
- image: user.image,
101
- createdAt: user.createdAt,
102
- updatedAt: user.updatedAt
103
- }
104
- });
105
- },
106
- invalid: async () => {
107
- throw new betterCall.APIError("UNAUTHORIZED", {
108
- message: "invalid two factor authentication"
109
- });
110
- },
111
- session: {
112
- session: session2,
113
- user
114
- }
115
- };
116
- }
117
- return {
118
- valid: async (ctx2) => {
119
- return ctx2.json({
120
- token: session.session.token,
121
- user: {
122
- id: session.user.id,
123
- email: session.user.email,
124
- emailVerified: session.user.emailVerified,
125
- name: session.user.name,
126
- image: session.user.image,
127
- createdAt: session.user.createdAt,
128
- updatedAt: session.user.updatedAt
129
- }
130
- });
131
- },
132
- invalid: async () => {
133
- throw new betterCall.APIError("UNAUTHORIZED", {
134
- message: "invalid two factor authentication"
135
- });
136
- },
137
- session
138
- };
139
- }
140
- );
141
-
142
- exports.TRUST_DEVICE_COOKIE_NAME = TRUST_DEVICE_COOKIE_NAME;
143
- exports.TWO_FACTOR_COOKIE_NAME = TWO_FACTOR_COOKIE_NAME;
144
- exports.verifyTwoFactorMiddleware = verifyTwoFactorMiddleware;