@revealui/auth 0.0.1-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (413) hide show
  1. package/LICENSE +202 -0
  2. package/dist/better-auth/adapter/__tests__/transform.test.js +213 -0
  3. package/dist/better-auth/adapter/__tests__/transform.test.js.map +1 -0
  4. package/dist/better-auth/adapter/generate-schema/biome.d.js +2 -0
  5. package/dist/better-auth/adapter/generate-schema/biome.d.js.map +1 -0
  6. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.d.ts +5 -0
  7. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js +482 -0
  8. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js.map +1 -0
  9. package/dist/better-auth/adapter/generate-schema/get-payload-schema.d.ts +1 -0
  10. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js +42 -0
  11. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js.map +1 -0
  12. package/dist/better-auth/adapter/generate-schema/index.d.ts +4 -0
  13. package/dist/better-auth/adapter/generate-schema/index.js +19 -0
  14. package/dist/better-auth/adapter/generate-schema/index.js.map +1 -0
  15. package/dist/better-auth/adapter/generate-schema/utils.d.ts +2 -0
  16. package/dist/better-auth/adapter/generate-schema/utils.js +20 -0
  17. package/dist/better-auth/adapter/generate-schema/utils.js.map +1 -0
  18. package/dist/better-auth/adapter/index.d.ts +15 -0
  19. package/dist/better-auth/adapter/index.js +731 -0
  20. package/dist/better-auth/adapter/index.js.map +1 -0
  21. package/dist/better-auth/adapter/tests/adapter.test.js +174 -0
  22. package/dist/better-auth/adapter/tests/adapter.test.js.map +1 -0
  23. package/dist/better-auth/adapter/tests/base-collections-tests.js +575 -0
  24. package/dist/better-auth/adapter/tests/base-collections-tests.js.map +1 -0
  25. package/dist/better-auth/adapter/tests/dev/index.js +117 -0
  26. package/dist/better-auth/adapter/tests/dev/index.js.map +1 -0
  27. package/dist/better-auth/adapter/tests/dev/migrate.js +26 -0
  28. package/dist/better-auth/adapter/tests/dev/migrate.js.map +1 -0
  29. package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js +218 -0
  30. package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js.map +1 -0
  31. package/dist/better-auth/adapter/tests/dev/schema.js +160 -0
  32. package/dist/better-auth/adapter/tests/dev/schema.js.map +1 -0
  33. package/dist/better-auth/adapter/tests/plugins-tests.js +2 -0
  34. package/dist/better-auth/adapter/tests/plugins-tests.js.map +1 -0
  35. package/dist/better-auth/adapter/transform/index.d.ts +27 -0
  36. package/dist/better-auth/adapter/transform/index.js +664 -0
  37. package/dist/better-auth/adapter/transform/index.js.map +1 -0
  38. package/dist/better-auth/adapter/types.d.ts +10 -0
  39. package/dist/better-auth/adapter/types.js +3 -0
  40. package/dist/better-auth/adapter/types.js.map +1 -0
  41. package/dist/better-auth/generated-types.d.ts +285 -0
  42. package/dist/better-auth/index.d.ts +3 -0
  43. package/dist/better-auth/index.js +5 -0
  44. package/dist/better-auth/index.js.map +1 -0
  45. package/dist/better-auth/plugin/__tests__/plugin.test.js +162 -0
  46. package/dist/better-auth/plugin/__tests__/plugin.test.js.map +1 -0
  47. package/dist/better-auth/plugin/constants.d.ts +220 -0
  48. package/dist/better-auth/plugin/constants.js +249 -0
  49. package/dist/better-auth/plugin/constants.js.map +1 -0
  50. package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts +12 -0
  51. package/dist/better-auth/plugin/helpers/check-plugin-exists.js +14 -0
  52. package/dist/better-auth/plugin/helpers/check-plugin-exists.js.map +1 -0
  53. package/dist/better-auth/plugin/helpers/generate-verify-email-url.d.ts +29 -0
  54. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js +46 -0
  55. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js.map +1 -0
  56. package/dist/better-auth/plugin/helpers/get-admin-access.d.ts +7 -0
  57. package/dist/better-auth/plugin/helpers/get-admin-access.js +22 -0
  58. package/dist/better-auth/plugin/helpers/get-admin-access.js.map +1 -0
  59. package/dist/better-auth/plugin/helpers/get-all-roles.d.ts +5 -0
  60. package/dist/better-auth/plugin/helpers/get-all-roles.js +20 -0
  61. package/dist/better-auth/plugin/helpers/get-all-roles.js.map +1 -0
  62. package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts +18 -0
  63. package/dist/better-auth/plugin/helpers/get-better-auth-schema.js +70 -0
  64. package/dist/better-auth/plugin/helpers/get-better-auth-schema.js.map +1 -0
  65. package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts +5 -0
  66. package/dist/better-auth/plugin/helpers/get-collection-slug.js +20 -0
  67. package/dist/better-auth/plugin/helpers/get-collection-slug.js.map +1 -0
  68. package/dist/better-auth/plugin/helpers/get-collection.d.ts +15 -0
  69. package/dist/better-auth/plugin/helpers/get-collection.js +29 -0
  70. package/dist/better-auth/plugin/helpers/get-collection.js.map +1 -0
  71. package/dist/better-auth/plugin/helpers/get-ip.d.ts +2 -0
  72. package/dist/better-auth/plugin/helpers/get-ip.js +31 -0
  73. package/dist/better-auth/plugin/helpers/get-ip.js.map +1 -0
  74. package/dist/better-auth/plugin/helpers/get-signed-cookie.d.ts +2 -0
  75. package/dist/better-auth/plugin/helpers/get-signed-cookie.js +65 -0
  76. package/dist/better-auth/plugin/helpers/get-signed-cookie.js.map +1 -0
  77. package/dist/better-auth/plugin/helpers/index.d.ts +1 -0
  78. package/dist/better-auth/plugin/helpers/index.js +3 -0
  79. package/dist/better-auth/plugin/helpers/index.js.map +1 -0
  80. package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts +59 -0
  81. package/dist/better-auth/plugin/helpers/prepare-session-data.js +49 -0
  82. package/dist/better-auth/plugin/helpers/prepare-session-data.js.map +1 -0
  83. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.d.ts +20 -0
  84. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js +67 -0
  85. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js.map +1 -0
  86. package/dist/better-auth/plugin/index.d.ts +11 -0
  87. package/dist/better-auth/plugin/index.js +125 -0
  88. package/dist/better-auth/plugin/index.js.map +1 -0
  89. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.d.ts +12 -0
  90. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js +87 -0
  91. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js.map +1 -0
  92. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts +3 -0
  93. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js +60 -0
  94. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js.map +1 -0
  95. package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts +3 -0
  96. package/dist/better-auth/plugin/lib/build-collections/accounts/index.js +154 -0
  97. package/dist/better-auth/plugin/lib/build-collections/accounts/index.js.map +1 -0
  98. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.d.ts +5 -0
  99. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js +11 -0
  100. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js.map +1 -0
  101. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.d.ts +2 -0
  102. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js +8 -0
  103. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js.map +1 -0
  104. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts +6 -0
  105. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js +119 -0
  106. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js.map +1 -0
  107. package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts +3 -0
  108. package/dist/better-auth/plugin/lib/build-collections/api-keys.js +177 -0
  109. package/dist/better-auth/plugin/lib/build-collections/api-keys.js.map +1 -0
  110. package/dist/better-auth/plugin/lib/build-collections/device-code.d.ts +3 -0
  111. package/dist/better-auth/plugin/lib/build-collections/device-code.js +50 -0
  112. package/dist/better-auth/plugin/lib/build-collections/device-code.js.map +1 -0
  113. package/dist/better-auth/plugin/lib/build-collections/index.d.ts +10 -0
  114. package/dist/better-auth/plugin/lib/build-collections/index.js +73 -0
  115. package/dist/better-auth/plugin/lib/build-collections/index.js.map +1 -0
  116. package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts +3 -0
  117. package/dist/better-auth/plugin/lib/build-collections/invitations.js +94 -0
  118. package/dist/better-auth/plugin/lib/build-collections/invitations.js.map +1 -0
  119. package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts +3 -0
  120. package/dist/better-auth/plugin/lib/build-collections/jwks.js +59 -0
  121. package/dist/better-auth/plugin/lib/build-collections/jwks.js.map +1 -0
  122. package/dist/better-auth/plugin/lib/build-collections/members.d.ts +3 -0
  123. package/dist/better-auth/plugin/lib/build-collections/members.js +73 -0
  124. package/dist/better-auth/plugin/lib/build-collections/members.js.map +1 -0
  125. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts +3 -0
  126. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js +107 -0
  127. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js.map +1 -0
  128. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts +3 -0
  129. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js +118 -0
  130. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js.map +1 -0
  131. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts +3 -0
  132. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js +89 -0
  133. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js.map +1 -0
  134. package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts +3 -0
  135. package/dist/better-auth/plugin/lib/build-collections/organizations.js +70 -0
  136. package/dist/better-auth/plugin/lib/build-collections/organizations.js.map +1 -0
  137. package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts +3 -0
  138. package/dist/better-auth/plugin/lib/build-collections/passkeys.js +115 -0
  139. package/dist/better-auth/plugin/lib/build-collections/passkeys.js.map +1 -0
  140. package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts +3 -0
  141. package/dist/better-auth/plugin/lib/build-collections/sessions.js +170 -0
  142. package/dist/better-auth/plugin/lib/build-collections/sessions.js.map +1 -0
  143. package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts +3 -0
  144. package/dist/better-auth/plugin/lib/build-collections/sso-providers.js +81 -0
  145. package/dist/better-auth/plugin/lib/build-collections/sso-providers.js.map +1 -0
  146. package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts +3 -0
  147. package/dist/better-auth/plugin/lib/build-collections/subscriptions.js +111 -0
  148. package/dist/better-auth/plugin/lib/build-collections/subscriptions.js.map +1 -0
  149. package/dist/better-auth/plugin/lib/build-collections/team-members.d.ts +3 -0
  150. package/dist/better-auth/plugin/lib/build-collections/team-members.js +57 -0
  151. package/dist/better-auth/plugin/lib/build-collections/team-members.js.map +1 -0
  152. package/dist/better-auth/plugin/lib/build-collections/teams.d.ts +3 -0
  153. package/dist/better-auth/plugin/lib/build-collections/teams.js +76 -0
  154. package/dist/better-auth/plugin/lib/build-collections/teams.js.map +1 -0
  155. package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts +3 -0
  156. package/dist/better-auth/plugin/lib/build-collections/two-factors.js +67 -0
  157. package/dist/better-auth/plugin/lib/build-collections/two-factors.js.map +1 -0
  158. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.d.ts +7 -0
  159. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js +53 -0
  160. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js.map +1 -0
  161. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.d.ts +11 -0
  162. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js +75 -0
  163. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js.map +1 -0
  164. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts +4 -0
  165. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js +6 -0
  166. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js.map +1 -0
  167. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.d.ts +2 -0
  168. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js +115 -0
  169. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js.map +1 -0
  170. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.d.ts +3 -0
  171. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js +64 -0
  172. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js.map +1 -0
  173. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.d.ts +3 -0
  174. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js +80 -0
  175. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js.map +1 -0
  176. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts +6 -0
  177. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js +79 -0
  178. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js.map +1 -0
  179. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts +2 -0
  180. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js +82 -0
  181. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js.map +1 -0
  182. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts +2 -0
  183. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js +54 -0
  184. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js.map +1 -0
  185. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts +6 -0
  186. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js +15 -0
  187. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js.map +1 -0
  188. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts +6 -0
  189. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js +8 -0
  190. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js.map +1 -0
  191. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts +2 -0
  192. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js +17 -0
  193. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js.map +1 -0
  194. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts +2 -0
  195. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js +91 -0
  196. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js.map +1 -0
  197. package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts +3 -0
  198. package/dist/better-auth/plugin/lib/build-collections/users/index.js +341 -0
  199. package/dist/better-auth/plugin/lib/build-collections/users/index.js.map +1 -0
  200. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts +15 -0
  201. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js +24 -0
  202. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js.map +1 -0
  203. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.d.ts +10 -0
  204. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js +67 -0
  205. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js.map +1 -0
  206. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.d.ts +9 -0
  207. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js +94 -0
  208. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js.map +1 -0
  209. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts +7 -0
  210. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js +35 -0
  211. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js.map +1 -0
  212. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts +12 -0
  213. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js +25 -0
  214. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js.map +1 -0
  215. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.d.ts +14 -0
  216. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js +67 -0
  217. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js.map +1 -0
  218. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts +20 -0
  219. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js +98 -0
  220. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js.map +1 -0
  221. package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts +3 -0
  222. package/dist/better-auth/plugin/lib/build-collections/verifications.js +87 -0
  223. package/dist/better-auth/plugin/lib/build-collections/verifications.js.map +1 -0
  224. package/dist/better-auth/plugin/lib/get-payload-auth.d.ts +5 -0
  225. package/dist/better-auth/plugin/lib/get-payload-auth.js +9 -0
  226. package/dist/better-auth/plugin/lib/get-payload-auth.js.map +1 -0
  227. package/dist/better-auth/plugin/lib/init-better-auth.d.ts +7 -0
  228. package/dist/better-auth/plugin/lib/init-better-auth.js +46 -0
  229. package/dist/better-auth/plugin/lib/init-better-auth.js.map +1 -0
  230. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.d.ts +2 -0
  231. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js +9 -0
  232. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js.map +1 -0
  233. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts +2 -0
  234. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js +10 -0
  235. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js.map +1 -0
  236. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.d.ts +2 -0
  237. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js +8 -0
  238. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js.map +1 -0
  239. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts +10 -0
  240. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js +156 -0
  241. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js.map +1 -0
  242. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts +2 -0
  243. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js +18 -0
  244. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js.map +1 -0
  245. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts +2 -0
  246. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js +34 -0
  247. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js.map +1 -0
  248. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts +2 -0
  249. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js +11 -0
  250. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js.map +1 -0
  251. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts +2 -0
  252. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js +10 -0
  253. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js.map +1 -0
  254. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts +2 -0
  255. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js +11 -0
  256. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js.map +1 -0
  257. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.d.ts +7 -0
  258. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js +23 -0
  259. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js.map +1 -0
  260. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.d.ts +25 -0
  261. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js +62 -0
  262. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js.map +1 -0
  263. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts +9 -0
  264. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js +47 -0
  265. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js.map +1 -0
  266. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts +15 -0
  267. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js +42 -0
  268. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js.map +1 -0
  269. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.d.ts +9 -0
  270. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js +63 -0
  271. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js.map +1 -0
  272. package/dist/better-auth/plugin/lib/set-login-methods.d.ts +4 -0
  273. package/dist/better-auth/plugin/lib/set-login-methods.js +14 -0
  274. package/dist/better-auth/plugin/lib/set-login-methods.js.map +1 -0
  275. package/dist/better-auth/plugin/payload/components/admin-buttons/index.d.ts +9 -0
  276. package/dist/better-auth/plugin/payload/components/admin-buttons/index.js +143 -0
  277. package/dist/better-auth/plugin/payload/components/admin-buttons/index.js.map +1 -0
  278. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.d.ts +10 -0
  279. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js +219 -0
  280. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js.map +1 -0
  281. package/dist/better-auth/plugin/payload/components/logout-button.d.ts +4 -0
  282. package/dist/better-auth/plugin/payload/components/logout-button.js +24 -0
  283. package/dist/better-auth/plugin/payload/components/logout-button.js.map +1 -0
  284. package/dist/better-auth/plugin/payload/components/passkeys/add-button.d.ts +8 -0
  285. package/dist/better-auth/plugin/payload/components/passkeys/add-button.js +117 -0
  286. package/dist/better-auth/plugin/payload/components/passkeys/add-button.js.map +1 -0
  287. package/dist/better-auth/plugin/payload/components/passkeys/client.d.ts +3 -0
  288. package/dist/better-auth/plugin/payload/components/passkeys/client.js +66 -0
  289. package/dist/better-auth/plugin/payload/components/passkeys/client.js.map +1 -0
  290. package/dist/better-auth/plugin/payload/components/passkeys/index.d.ts +4 -0
  291. package/dist/better-auth/plugin/payload/components/passkeys/index.js +52 -0
  292. package/dist/better-auth/plugin/payload/components/passkeys/index.js.map +1 -0
  293. package/dist/better-auth/plugin/payload/components/passkeys/list.d.ts +8 -0
  294. package/dist/better-auth/plugin/payload/components/passkeys/list.js +57 -0
  295. package/dist/better-auth/plugin/payload/components/passkeys/list.js.map +1 -0
  296. package/dist/better-auth/plugin/payload/components/passkeys/types.d.ts +22 -0
  297. package/dist/better-auth/plugin/payload/components/passkeys/types.js +3 -0
  298. package/dist/better-auth/plugin/payload/components/passkeys/types.js.map +1 -0
  299. package/dist/better-auth/plugin/payload/components/rsc-redirect.d.ts +6 -0
  300. package/dist/better-auth/plugin/payload/components/rsc-redirect.js +7 -0
  301. package/dist/better-auth/plugin/payload/components/rsc-redirect.js.map +1 -0
  302. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.d.ts +15 -0
  303. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js +157 -0
  304. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js.map +1 -0
  305. package/dist/better-auth/plugin/payload/components/token-field.d.ts +4 -0
  306. package/dist/better-auth/plugin/payload/components/token-field.js +31 -0
  307. package/dist/better-auth/plugin/payload/components/token-field.js.map +1 -0
  308. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.d.ts +8 -0
  309. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js +300 -0
  310. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js.map +1 -0
  311. package/dist/better-auth/plugin/payload/exports/client.d.ts +6 -0
  312. package/dist/better-auth/plugin/payload/exports/client.js +8 -0
  313. package/dist/better-auth/plugin/payload/exports/client.js.map +1 -0
  314. package/dist/better-auth/plugin/payload/exports/rsc.d.ts +8 -0
  315. package/dist/better-auth/plugin/payload/exports/rsc.js +10 -0
  316. package/dist/better-auth/plugin/payload/exports/rsc.js.map +1 -0
  317. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.d.ts +2 -0
  318. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js +9 -0
  319. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js.map +1 -0
  320. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.d.ts +1 -0
  321. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js +22 -0
  322. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js.map +1 -0
  323. package/dist/better-auth/plugin/payload/views/admin-login/client.d.ts +19 -0
  324. package/dist/better-auth/plugin/payload/views/admin-login/client.js +226 -0
  325. package/dist/better-auth/plugin/payload/views/admin-login/client.js.map +1 -0
  326. package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts +10 -0
  327. package/dist/better-auth/plugin/payload/views/admin-login/index.js +150 -0
  328. package/dist/better-auth/plugin/payload/views/admin-login/index.js.map +1 -0
  329. package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts +16 -0
  330. package/dist/better-auth/plugin/payload/views/admin-signup/client.js +299 -0
  331. package/dist/better-auth/plugin/payload/views/admin-signup/client.js.map +1 -0
  332. package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts +9 -0
  333. package/dist/better-auth/plugin/payload/views/admin-signup/index.js +104 -0
  334. package/dist/better-auth/plugin/payload/views/admin-signup/index.js.map +1 -0
  335. package/dist/better-auth/plugin/payload/views/forgot-password/client.d.ts +7 -0
  336. package/dist/better-auth/plugin/payload/views/forgot-password/client.js +119 -0
  337. package/dist/better-auth/plugin/payload/views/forgot-password/client.js.map +1 -0
  338. package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts +8 -0
  339. package/dist/better-auth/plugin/payload/views/forgot-password/index.js +78 -0
  340. package/dist/better-auth/plugin/payload/views/forgot-password/index.js.map +1 -0
  341. package/dist/better-auth/plugin/payload/views/reset-password/client.d.ts +10 -0
  342. package/dist/better-auth/plugin/payload/views/reset-password/client.js +144 -0
  343. package/dist/better-auth/plugin/payload/views/reset-password/client.js.map +1 -0
  344. package/dist/better-auth/plugin/payload/views/reset-password/index.d.ts +8 -0
  345. package/dist/better-auth/plugin/payload/views/reset-password/index.js +96 -0
  346. package/dist/better-auth/plugin/payload/views/reset-password/index.js.map +1 -0
  347. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.d.ts +6 -0
  348. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js +96 -0
  349. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js.map +1 -0
  350. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts +9 -0
  351. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js +56 -0
  352. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js.map +1 -0
  353. package/dist/better-auth/plugin/types.d.ts +429 -0
  354. package/dist/better-auth/plugin/types.js +3 -0
  355. package/dist/better-auth/plugin/types.js.map +1 -0
  356. package/dist/better-auth/plugin/utils/set.d.ts +39 -0
  357. package/dist/better-auth/plugin/utils/set.js +103 -0
  358. package/dist/better-auth/plugin/utils/set.js.map +1 -0
  359. package/dist/better-auth/scripts/generate-types.d.ts +1 -0
  360. package/dist/better-auth/scripts/generate-types.js +234 -0
  361. package/dist/better-auth/scripts/generate-types.js.map +1 -0
  362. package/dist/better-auth/types.d.ts +2 -0
  363. package/dist/better-auth/types.js +4 -0
  364. package/dist/better-auth/types.js.map +1 -0
  365. package/dist/index.d.ts +1 -0
  366. package/dist/index.js +4 -0
  367. package/dist/index.js.map +1 -0
  368. package/dist/shared/components/icons.d.ts +7 -0
  369. package/dist/shared/components/icons.js +442 -0
  370. package/dist/shared/components/icons.js.map +1 -0
  371. package/dist/shared/components/logo.d.ts +3 -0
  372. package/dist/shared/components/logo.js +24 -0
  373. package/dist/shared/components/logo.js.map +1 -0
  374. package/dist/shared/form/components/submit.d.ts +7 -0
  375. package/dist/shared/form/components/submit.js +16 -0
  376. package/dist/shared/form/components/submit.js.map +1 -0
  377. package/dist/shared/form/fields/text-field.d.ts +8 -0
  378. package/dist/shared/form/fields/text-field.js +37 -0
  379. package/dist/shared/form/fields/text-field.js.map +1 -0
  380. package/dist/shared/form/index.d.ts +4 -0
  381. package/dist/shared/form/index.js +8 -0
  382. package/dist/shared/form/index.js.map +1 -0
  383. package/dist/shared/form/ui/header/index.d.ts +8 -0
  384. package/dist/shared/form/ui/header/index.js +24 -0
  385. package/dist/shared/form/ui/header/index.js.map +1 -0
  386. package/dist/shared/form/ui/index.d.ts +31 -0
  387. package/dist/shared/form/ui/index.js +57 -0
  388. package/dist/shared/form/ui/index.js.map +1 -0
  389. package/dist/shared/form/validation.d.ts +51 -0
  390. package/dist/shared/form/validation.js +127 -0
  391. package/dist/shared/form/validation.js.map +1 -0
  392. package/dist/shared/index.d.ts +2 -0
  393. package/dist/shared/index.js +4 -0
  394. package/dist/shared/index.js.map +1 -0
  395. package/dist/shared/payload/fields/field-copy-button/index.d.ts +3 -0
  396. package/dist/shared/payload/fields/field-copy-button/index.js +38 -0
  397. package/dist/shared/payload/fields/field-copy-button/index.js.map +1 -0
  398. package/dist/shared/payload/fields/generate-uuid-button/index.d.ts +3 -0
  399. package/dist/shared/payload/fields/generate-uuid-button/index.js +26 -0
  400. package/dist/shared/payload/fields/generate-uuid-button/index.js.map +1 -0
  401. package/dist/shared/payload/fields/index.d.ts +2 -0
  402. package/dist/shared/payload/fields/index.js +4 -0
  403. package/dist/shared/payload/fields/index.js.map +1 -0
  404. package/dist/shared/utils/regex.d.ts +2 -0
  405. package/dist/shared/utils/regex.js +4 -0
  406. package/dist/shared/utils/regex.js.map +1 -0
  407. package/dist/shared/utils/try-catch.d.ts +11 -0
  408. package/dist/shared/utils/try-catch.js +17 -0
  409. package/dist/shared/utils/try-catch.js.map +1 -0
  410. package/dist/shared/utils/value-or-default.d.ts +9 -0
  411. package/dist/shared/utils/value-or-default.js +12 -0
  412. package/dist/shared/utils/value-or-default.js.map +1 -0
  413. package/package.json +122 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/better-auth/adapter/transform/index.ts"],"sourcesContent":["import { getAuthTables } from 'better-auth/db';\n\nimport type { BetterAuthOptions, Where } from 'better-auth';\nimport type { DBFieldAttribute } from 'better-auth/db';\nimport type { CollectionSlug, Where as PayloadWhere } from 'payload';\nimport type { ModelKey } from '../../generated-types';\n\nexport const createTransform = (options: BetterAuthOptions, enableDebugLogs: boolean) => {\n const schema = getAuthTables(options);\n\n // Using any[] because debug log messages can contain any types (strings, objects, numbers, etc.)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- debug log messages can contain any types\n function debugLog(message: any[]) {\n if (enableDebugLogs) {\n console.log('[payload-db-adapter]', ...message);\n }\n }\n\n /**\n * Maps a BetterAuth schema model name to its corresponding Payload CMS collection slug.\n *\n * This function resolves the appropriate collection slug by:\n * 1. Looking up the model in the BetterAuth schema to find its configured modelName\n * 2. Falling back to the original model name if no mapping exists\n *\n * Collection slug resolution follows these rules:\n * - For base collections: The sanitizeBetterAuthOptions function ensures the collection slug\n * from plugin options is set as the model name in the schema\n * - For plugins: The betterAuthPluginSlugs constant is used as the modelName\n *\n * @param model - The BetterAuth model name to resolve\n * @returns The corresponding Payload CMS collection slug\n *\n * @example\n * // If schema['user'].modelName is 'users'\n * getCollectionSlug('user') // Returns 'users'\n *\n * @example\n * // If model doesn't exist in schema\n * getCollectionSlug('custom') // Returns 'custom'\n *\n * @warning If a collection is overridden using the collectionOverride option\n * without updating the schema mapping, this function may return incorrect slugs\n */\n function getCollectionSlug(model: ModelKey): CollectionSlug {\n // First try to get the modelName from schema, otherwise fall back to the original model name\n const collection = schema?.[model]?.modelName || model;\n debugLog(['getCollectionSlug:', { model, resolvedSlug: collection }]);\n return collection as CollectionSlug;\n }\n\n /**\n * Maps a BetterAuth schema field to its corresponding Payload CMS field name.\n *\n * This function resolves the appropriate field name by:\n * 1. Preserving 'id' or '_id' fields as-is (special case handling)\n * 2. Looking up the field in the BetterAuth schema to find its configured fieldName\n * 3. Falling back to the original field name if no mapping exists\n *\n * @param model - The BetterAuth model name containing the field\n * @param field - The original field name to resolve\n * @returns The corresponding Payload CMS field name\n *\n * @example\n * // If schema['user'].fields['email'].fieldName is 'emailAddress'\n * getFieldName('user', 'email') // Returns 'emailAddress'\n *\n * @example\n * // Special case for ID fields\n * getFieldName('user', 'id') // Always returns 'id'\n *\n * @example\n * // If field doesn't exist in schema or has no fieldName mapping\n * getFieldName('user', 'custom') // Returns 'custom'\n *\n * @warning If a fieldName is overridden in the payload collection config using the collectionOverride option\n * without updating the schema mapping, this function may return incorrect field names\n */\n function getFieldName(model: ModelKey, field: string): string {\n // Special case: 'id' or '_id' is always preserved as-is\n if (['id', '_id'].includes(field)) {\n return field;\n }\n\n // Look up the field in the schema\n const fieldDefinition = schema[model]?.fields[field];\n\n // Use the configured fieldName if available, otherwise fall back to original\n const fieldName = fieldDefinition?.fieldName || field;\n\n // Log the field resolution for debugging\n debugLog(['getField: ', { fieldName, model, originalField: field }]);\n\n return fieldName;\n }\n\n /**\n * Determines if a field is a relationship field by checking for a references property.\n *\n * Relationship fields in the schema have a 'references' property that points to another model.\n * This function checks if this property exists to identify relationship fields.\n *\n * @param fieldKey - The key of the field to check in the schema\n * @param schemaFields - Object containing all fields from the schema for a specific model\n * @returns True if the field is a relationship field (has references), false otherwise\n *\n * @example\n * // If schema.user.fields.posts has { references: {} }\n * isRelationshipField('posts', schema.user.fields) // Returns true\n *\n * @example\n * // If schema.user.fields.email has no references property\n * isRelationshipField('email', schema.user.fields) // Returns false\n */\n function isRelationshipField(\n fieldKey: string,\n schemaFields: Record<string, DBFieldAttribute>\n ): boolean {\n // A field is a relationship field if it has a 'references' property defined\n return schemaFields[fieldKey]?.references !== undefined;\n }\n /**\n * Extracts a single ID value from a Payload where clause if it represents a simple ID query.\n *\n * This function analyzes a Payload where clause to determine if it's a simple query for a\n * single document by ID. It supports both 'id' and '_id' fields with 'equals' or 'contains'\n * operators. This is useful for optimizing queries when we only need to fetch a single document.\n *\n * @param where - The Payload where clause to analyze\n * @returns The ID value (string or number) if the where clause is a simple ID query, null otherwise\n *\n * @example\n * // Returns '123' for a simple equals query\n * singleIdQuery({ id: { equals: '123' } }) // '123'\n *\n * @example\n * // Returns 456 for a simple equals query with number ID\n * singleIdQuery({ _id: { equals: 456 } }) // 456\n *\n * @example\n * // Returns '789' for a contains query with a single value\n * singleIdQuery({ id: { contains: ['789'] } }) // '789'\n *\n * @example\n * // Returns null for complex queries\n * singleIdQuery({ and: [{ id: { equals: '123' } }] }) // null\n */\n function singleIdQuery(where: PayloadWhere) {\n // Return null for empty where clauses or complex queries with 'and'/'or' operators\n if (!where || 'and' in where || 'or' in where) return null;\n\n // Check if the where clause contains either 'id' or '_id' field\n if (['id', '_id'].some(field => field in where)) {\n // Determine which ID field is being used (support both 'id' and '_id')\n const idField = 'id' in where ? 'id' : '_id';\n const condition = where[idField];\n\n // Process the equals operator case\n if (\n condition &&\n typeof condition === 'object' &&\n !Array.isArray(condition) &&\n 'equals' in condition\n ) {\n const value = condition.equals;\n // Only return string or number ID values\n if (typeof value === 'string' || typeof value === 'number') {\n return value;\n }\n }\n\n // Process the contains operator case with a single value\n if (\n condition &&\n typeof condition === 'object' &&\n !Array.isArray(condition) &&\n 'contains' in condition &&\n Array.isArray(condition.contains) &&\n condition.contains.length === 1\n ) {\n const value = condition.contains[0];\n // Only return string or number ID values\n if (typeof value === 'string' || typeof value === 'number') {\n return value;\n }\n }\n }\n\n // Return null if no valid ID query was found\n return null;\n }\n\n /**\n * Normalizes data values based on field type and required ID type\n *\n * This function handles type conversion for relationship fields to ensure\n * IDs are in the correct format (string or number) based on the configuration.\n *\n * @param key - The field key/name\n * @param value - The value to normalize\n * @param isRelatedField - Whether this field is a relationship field\n * @param idType - The expected ID type ('number' or 'text')\n * @returns The normalized value\n */\n function normalizeData({\n idType,\n isRelatedField,\n key,\n value,\n }: {\n key: string;\n // Using any because data values can be primitives, objects, arrays, or nested structures that vary by field type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- data values can be primitives, objects, arrays, or nested structures\n value: any;\n isRelatedField: boolean;\n idType: 'number' | 'text';\n }) {\n // Skip processing for null/undefined values\n if (value === null || value === undefined) {\n return value;\n }\n\n if (['id', '_id'].includes(key)) {\n if (typeof value === 'string' && idType === 'number') {\n const parsed = parseInt(value, 10);\n if (!Number.isNaN(parsed)) {\n debugLog([\n `ID conversion: ${key} converting string ID to number`,\n { converted: parsed, original: value },\n ]);\n return parsed;\n }\n }\n if (typeof value === 'number' && idType === 'text') {\n const stringId = String(value);\n debugLog([\n `ID conversion: ${key} converting number ID to string`,\n { converted: stringId, original: value },\n ]);\n return stringId;\n }\n }\n\n // Only process relationship fields that need type conversion\n if (isRelatedField) {\n // Handle single ID value conversion\n if (typeof value === 'string' && idType === 'number') {\n const parsed = parseInt(value, 10);\n if (!Number.isNaN(parsed)) {\n debugLog([\n `ID conversion: ${key} converting string ID to number`,\n { converted: parsed, original: value },\n ]);\n return parsed;\n }\n } else if (typeof value === 'number' && idType === 'text') {\n const stringId = String(value);\n debugLog([\n `ID conversion: ${key} converting number ID to string`,\n { converted: stringId, original: value },\n ]);\n return stringId;\n }\n\n // Handle array of IDs - map each value to the correct type\n if (Array.isArray(value)) {\n return value.map(id => {\n // Skip null/undefined values in arrays\n if (id === null || id === undefined) return id;\n\n if (idType === 'number' && typeof id === 'string') {\n const parsed = parseInt(id, 10);\n return !Number.isNaN(parsed) ? parsed : id;\n }\n if (idType === 'text' && typeof id === 'number') {\n return String(id);\n }\n return id;\n });\n }\n }\n\n // Return original value if no conversion was needed or applicable\n return value;\n }\n\n /**\n * Transforms input data from better-auth to Payload CMS format\n *\n * This function handles:\n * 1. Field name mapping according to schema definitions\n * 2. ID type conversion for relationship fields\n * 3. Proper data normalization based on field types\n *\n * @param data - The input data from better-auth\n * @param model - The model name in the schema\n * @param idType - The expected ID type ('number' or 'text')\n * @returns Transformed data compatible with Payload CMS\n */\n function transformInput({\n data,\n idType,\n model,\n }: {\n // Using Record<string, any> because data structure varies by model and field configuration\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- data structure varies by model and field configuration\n data: Record<string, any>;\n model: ModelKey;\n idType: 'number' | 'text';\n // Using Record<string, any> because transformed data structure varies by model and field configuration\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- transformed data structure varies by model and field configuration\n }): Record<string, any> {\n // Using Record<string, any> because transformed data structure varies by model and field configuration\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- transformed data structure varies by model and field configuration\n const transformedData: Record<string, any> = {};\n const schemaFields = schema?.[model]?.fields ?? {};\n\n // Process each field in the input data\n Object.entries(data).forEach(([key, value]) => {\n // Skip null/undefined values\n if (value === null || value === undefined) {\n return;\n }\n\n // Determine if this is a relationship field\n const isRelatedField = isRelationshipField(key, schemaFields);\n\n // Get the mapped field name from schema (if any)\n // Using any because schemaFields[key] may not exist and value type varies by field\n const schemaFieldName = schemaFields[key]?.fieldName;\n\n // Normalize the data value based on field type and ID type\n const normalizedData = normalizeData({\n idType,\n isRelatedField,\n key,\n value,\n });\n\n // Use the schema-defined field name if available, otherwise use original key\n const targetFieldName = schemaFieldName ?? key;\n transformedData[targetFieldName] = normalizedData;\n });\n\n return transformedData;\n }\n\n /**\n * Transforms Payload CMS document output to match BetterAuth schema expectations.\n *\n * This function handles several critical transformations:\n *\n * 1. ID Conversion: Ensures all ID fields are strings as required by BetterAuth\n * (see: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/db/schema.ts#L125)\n *\n * 2. Relationship Field Mapping: Aligns relationship fields with BetterAuth schema naming conventions\n * and ensures proper ID type handling\n *\n * 3. Date Conversion: Transforms date strings from Payload into Date objects for BetterAuth\n *\n * Note: While setting depth: 1 in Payload operations simplifies this process by avoiding\n * deeply nested objects, we maintain comprehensive checks for robustness.\n *\n * @param doc - The document returned from Payload CMS\n * @param model - The model name in the BetterAuth schema\n * @returns The transformed document compatible with BetterAuth\n */\n // Using Record<string, any> because document structure varies by model and field configuration\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- document structure varies by model and field configuration\n function transformOutput<T extends Record<string, any> | null>({\n doc,\n model,\n }: {\n doc: T;\n model: ModelKey;\n }): T {\n if (!doc || typeof doc !== 'object') return doc;\n\n const result = { ...doc };\n const schemaFields = schema?.[model]?.fields ?? {};\n\n // Identify relationship fields with custom field name mappings\n const relationshipFields = Object.fromEntries(\n Object.entries(schemaFields).filter(([key]) => isRelationshipField(key, schemaFields))\n );\n const dateFields = Object.fromEntries(\n Object.entries(schemaFields).filter(([_, value]) => value.type === 'date')\n );\n\n Object.entries(doc).forEach(([key, value]) => {\n if (value === null || value === undefined) return;\n\n // Convert ID fields to strings for BetterAuth compatibility\n if (['id', '_id'].includes(key)) {\n result[key] = String(value);\n return;\n }\n\n // Handle relationship fields with renamed fieldNames\n const originalRelatedFieldKey = Object.keys(relationshipFields).find(\n k => relationshipFields[k]?.fieldName === key\n );\n if (originalRelatedFieldKey) {\n normalizeDocumentIds(result, originalRelatedFieldKey, key, value);\n return;\n }\n\n const originalDateFieldKey = Object.keys(dateFields).find(\n k => dateFields[k]?.fieldName === key\n );\n if (originalDateFieldKey) {\n // Convert ISO date strings to Date objects for BetterAuth\n result[key] = new Date(value);\n }\n });\n\n return result as T;\n }\n\n /**\n * Normalizes ID fields for both primary and relationship documents.\n *\n * This function ensures consistent ID handling between BetterAuth and Payload CMS by:\n * 1. Converting all IDs to strings for BetterAuth (stored in originalKey)\n * 2. Preserving original ID types for Payload CMS (stored in fieldName)\n *\n * The function handles various ID formats:\n * - Primitive values (string/number IDs)\n * - Object references with ID properties\n * - Arrays of either primitive IDs or object references\n *\n * @param result - The result object being transformed\n * @param originalKey - The original field key from BetterAuth schema\n * @param fieldName - The renamed field as used in Payload CMS\n * @param value - The ID value to normalize (primitive, object, or array)\n */\n // Using Record<string, any> because result object structure varies by document type and field configuration\n function normalizeDocumentIds(\n // Using Record<string, any> because result object structure varies by document type and field configuration\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- result object structure varies by document type and field configuration\n result: Record<string, any>,\n originalKey: string,\n fieldName: string,\n // Using any because value can be primitive, object, or array depending on field type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- value can be primitive, object, or array depending on field type\n value: any\n ): void {\n // Case 1: Primitive ID value (string or number)\n if (typeof value === 'string' || typeof value === 'number') {\n // For BetterAuth: Always use string IDs\n result[originalKey] = String(value);\n // For Payload: Keep original type\n result[fieldName] = value;\n return;\n }\n\n // Case 2: Object with ID property\n if (typeof value === 'object' && value !== null && 'id' in value) {\n // For BetterAuth: Extract and stringify the ID\n result[originalKey] = String(value.id);\n // For Payload: Extract ID but preserve type\n result[fieldName] = value.id;\n return;\n }\n\n // Case 3: Array of IDs or references\n if (Array.isArray(value) && value.length > 0) {\n // Check if array contains objects with ID properties\n if (value.every(item => typeof item === 'object' && item !== null && 'id' in item)) {\n // Array of objects with IDs\n result[originalKey] = value.map(item => String(item.id));\n result[fieldName] = value.map(item => item.id);\n } else {\n // Array of primitive IDs\n result[originalKey] = value.map(item => String(item));\n result[fieldName] = value.map(item => item);\n }\n }\n\n // Note: If value doesn't match any expected format, no changes are made\n }\n\n /**\n * Converts a BetterAuth operator to the equivalent Payload CMS query operator\n *\n * This function maps standard query operators from BetterAuth's format to\n * the specific format expected by Payload CMS's query engine.\n *\n * @param operator - The BetterAuth operator string (e.g., 'eq', 'gt', 'contains')\n * @param value - The value to be used with the operator\n * @returns An object with the Payload-compatible operator and value\n *\n * @example\n * // Returns { equals: 'test@example.com' }\n * operatorToPayload('eq', 'test@example.com')\n *\n * @example\n * // Returns { greater_than: 100 }\n * operatorToPayload('gt', 100)\n */\n // Using any for value because query values can be strings, numbers, dates, arrays, or objects depending on operator\n // Using Record<string, any> because PayloadCMS query operators return different structures (equals, greater_than, etc.)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- query values can be strings, numbers, dates, arrays, or objects\n function operatorToPayload(operator: string, value: any): Record<string, any> {\n switch (operator) {\n case 'eq':\n return { equals: value };\n case 'ne':\n return { not_equals: value };\n case 'gt':\n return { greater_than: value };\n case 'gte':\n return { greater_than_equal: value };\n case 'lt':\n return { less_than: value };\n case 'lte':\n return { less_than_equal: value };\n case 'contains':\n return { contains: value };\n case 'in':\n return { in: value };\n case 'starts_with':\n return { like: `${value}%` };\n case 'ends_with':\n return { like: `%${value}` };\n default:\n // Fall back to equals for unrecognized operators\n return { equals: value };\n }\n }\n\n /**\n * Converts a where clause value to the appropriate type based on field name and ID type configuration\n *\n * This function handles two main scenarios:\n * 1. ID field conversion - ensures IDs match the database's expected type (number or string)\n * 2. Object with embedded ID - extracts and converts the ID property from objects\n *\n * @param value - The value to convert (can be primitive, object with ID, or array)\n * @param fieldName - The name of the field being queried\n * @param idType - The expected ID type in the database\n * @returns The converted value appropriate for the database query\n */\n function convertWhereValue({\n fieldName,\n idType,\n value,\n }: {\n // Using any because where clause values can be primitives, objects, arrays, or nested structures\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- where clause values can be primitives, objects, arrays, or nested structures\n value: any;\n fieldName: string;\n idType: 'number' | 'text';\n }) {\n // Check if field is an ID field (supporting both MongoDB-style _id and standard id)\n if (['id', '_id'].includes(fieldName)) {\n // Case 1: Value is an object containing an ID property\n if (typeof value === 'object' && value !== null && 'id' in value) {\n // Extract ID from object\n const id = value.id;\n\n // Use type conversion based on database configuration\n if (idType === 'number' && typeof id === 'string') {\n const numId = Number(id);\n return !Number.isNaN(numId) ? numId : id;\n }\n\n if (idType === 'text' && typeof id === 'number') {\n return String(id);\n }\n\n return id;\n }\n // Case 2: Value is a standalone ID that needs type conversion\n // Convert string ID to number if database expects numeric IDs\n if (idType === 'number' && typeof value === 'string' && !Number.isNaN(Number(value))) {\n return Number(value);\n }\n // Convert numeric ID to string if database expects text IDs\n if (idType === 'text' && typeof value === 'number') {\n return String(value);\n }\n return value;\n }\n\n // For non-ID fields, return the value unchanged\n return value;\n }\n\n /**\n * Converts Better Auth where clauses to Payload CMS compatible where conditions\n *\n * This function transforms the Better Auth query format into Payload's query format,\n * handling field name mapping, value type conversion, and logical operators (AND/OR).\n *\n * The function handles three main cases:\n * 1. Empty or undefined where clause - returns empty object\n * 2. Single condition - converts to a simple field-value pair\n * 3. Multiple conditions - groups by AND/OR connectors and builds a complex query\n *\n * @param idType - The database ID type ('number' or 'text')\n * @param model - The model/collection name to query\n * @param where - Array of Better Auth where conditions\n * @returns A Payload-compatible where clause object\n */\n function convertWhereClause({\n idType,\n model,\n where,\n }: {\n idType: 'number' | 'text';\n model: ModelKey;\n where?: Where[];\n }): PayloadWhere {\n // Handle empty where clause\n if (!where) return {};\n\n // Handle single condition case for optimization\n if (where.length === 1) {\n const w = where[0];\n if (!w) {\n return {};\n }\n\n // Map field name according to schema and convert value to appropriate type\n const fieldName = getFieldName(model, w.field);\n const value = convertWhereValue({\n fieldName,\n idType,\n value: w.value,\n });\n\n // Create the Payload where condition with proper operator\n const res = {\n [fieldName]: operatorToPayload(w.operator ?? '', value),\n };\n\n return res;\n }\n\n // Handle multiple conditions by separating AND/OR clauses\n // Default to AND if no connector is specified\n const and = where.filter(w => w.connector === 'AND' || !w.connector);\n const or = where.filter(w => w.connector === 'OR');\n\n // Process AND conditions\n const andClause = and.map(w => {\n const fieldName = getFieldName(model, w.field);\n const value = convertWhereValue({\n fieldName,\n idType,\n value: w.value,\n });\n return {\n [fieldName]: operatorToPayload(w.operator ?? '', value),\n };\n });\n\n // Process OR conditions\n const orClause = or.map(w => {\n const fieldName = getFieldName(model, w.field);\n const value = convertWhereValue({\n fieldName,\n idType,\n value: w.value,\n });\n return {\n [fieldName]: operatorToPayload(w.operator ?? '', value),\n };\n });\n\n // Combine AND and OR clauses into final Payload where object\n // Only include non-empty clause arrays\n return {\n ...(andClause.length ? { AND: andClause } : {}),\n ...(orClause.length ? { OR: orClause } : {}),\n };\n }\n\n /**\n * Converts a better-auth select array to a Payload select object\n *\n * This function transforms the better-auth select array (which contains field names)\n * into the format expected by Payload CMS's query API (an object with field names as keys\n * and boolean true as values).\n *\n * It also handles field name mapping between better-auth schema and Payload collections\n * by using the getFieldName helper to resolve the correct field names.\n *\n * @param model - The model/collection name to get field mappings from\n * @param select - Optional array of field names to select\n * @returns A Payload-compatible select object or undefined if no fields to select\n * @example\n * // Input: ['email', 'name']\n * // Output: { email: true, name: true }\n */\n function convertSelect(model: ModelKey, select?: string[]) {\n // Return undefined if select is empty or not provided\n if (!select || select.length === 0) return undefined;\n\n // Transform the array of field names into a Payload select object\n // while also mapping any field names that might be different in Payload\n const result: Record<string, boolean> = {};\n for (const field of select) {\n result[getFieldName(model, field)] = true;\n }\n return result;\n }\n\n /**\n * Converts a better-auth sort object to a Payload sort string\n *\n * This function transforms the better-auth sort object (which contains field name and direction)\n * into the format expected by Payload CMS's query API (a string with optional '-' prefix for descending order).\n *\n * It also handles field name mapping between better-auth schema and Payload collections\n * by using the getFieldName helper to resolve the correct field names.\n *\n * @param model - The model/collection name to get field mappings from\n * @param sortBy - Optional object containing field name and sort direction\n * @returns A Payload-compatible sort string or undefined if no sort specified\n * @example\n * // Input: { field: 'email', direction: 'desc' }\n * // Output: '-email'\n * // Input: { field: 'createdAt', direction: 'asc' }\n * // Output: 'createdAt'\n */\n function convertSort(\n model: ModelKey,\n sortBy?: { field: string; direction: 'asc' | 'desc' }\n ): string | undefined {\n if (!sortBy) return undefined;\n const fieldName = getFieldName(model, sortBy.field);\n const prefix = sortBy.direction === 'desc' ? '-' : '';\n return `${prefix}${fieldName}`;\n }\n\n return {\n convertSelect,\n convertSort,\n convertWhereClause,\n getCollectionSlug,\n getFieldName,\n singleIdQuery,\n transformInput,\n transformOutput,\n };\n};\n"],"names":["getAuthTables","createTransform","options","enableDebugLogs","schema","debugLog","message","console","log","getCollectionSlug","model","collection","modelName","resolvedSlug","getFieldName","field","includes","fieldDefinition","fields","fieldName","originalField","isRelationshipField","fieldKey","schemaFields","references","undefined","singleIdQuery","where","some","idField","condition","Array","isArray","value","equals","contains","length","normalizeData","idType","isRelatedField","key","parsed","parseInt","Number","isNaN","converted","original","stringId","String","map","id","transformInput","data","transformedData","Object","entries","forEach","schemaFieldName","normalizedData","targetFieldName","transformOutput","doc","result","relationshipFields","fromEntries","filter","dateFields","_","type","originalRelatedFieldKey","keys","find","k","normalizeDocumentIds","originalDateFieldKey","Date","originalKey","every","item","operatorToPayload","operator","not_equals","greater_than","greater_than_equal","less_than","less_than_equal","in","like","convertWhereValue","numId","convertWhereClause","w","res","and","connector","or","andClause","orClause","AND","OR","convertSelect","select","convertSort","sortBy","prefix","direction"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iBAAiB;AAO/C,OAAO,MAAMC,kBAAkB,CAACC,SAA4BC;IAC1D,MAAMC,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,MAAiB;QACvD,sDAAsD;QACtD,IAAI,CAACA,UAAUA,OAAOjE,MAAM,KAAK,GAAG,OAAOX;QAE3C,kEAAkE;QAClE,wEAAwE;QACxE,MAAMqC,SAAkC,CAAC;QACzC,KAAK,MAAM/C,SAASsF,OAAQ;YAC1BvC,MAAM,CAAChD,aAAaJ,OAAOK,OAAO,GAAG;QACvC;QACA,OAAO+C;IACT;IAEA;;;;;;;;;;;;;;;;;GAiBC,GACD,SAASwC,YACP5F,KAAe,EACf6F,MAAqD;QAErD,IAAI,CAACA,QAAQ,OAAO9E;QACpB,MAAMN,YAAYL,aAAaJ,OAAO6F,OAAOxF,KAAK;QAClD,MAAMyF,SAASD,OAAOE,SAAS,KAAK,SAAS,MAAM;QACnD,OAAO,GAAGD,SAASrF,WAAW;IAChC;IAEA,OAAO;QACLiF;QACAE;QACAZ;QACAjF;QACAK;QACAY;QACAyB;QACAS;IACF;AACF,EAAE"}
@@ -0,0 +1,10 @@
1
+ import type { AdapterInstance } from 'better-auth';
2
+ import type { BasePayload } from 'payload';
3
+ export type PayloadAdapterParams = {
4
+ payloadClient: BasePayload | Promise<BasePayload> | (() => Promise<BasePayload>);
5
+ adapterConfig: {
6
+ enableDebugLogs?: boolean;
7
+ idType: 'number' | 'text';
8
+ };
9
+ };
10
+ export type PayloadAdapter = (options: PayloadAdapterParams) => AdapterInstance;
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/better-auth/adapter/types.ts"],"sourcesContent":["import type { AdapterInstance } from 'better-auth';\nimport type { BasePayload } from 'payload';\n\nexport type PayloadAdapterParams = {\n payloadClient: BasePayload | Promise<BasePayload> | (() => Promise<BasePayload>);\n adapterConfig: {\n enableDebugLogs?: boolean;\n idType: 'number' | 'text';\n };\n // enableDebugLogs?: boolean;\n // idType: 'number' | 'text';\n};\n\nexport type PayloadAdapter = (options: PayloadAdapterParams) => AdapterInstance;\n"],"names":[],"mappings":"AAaA,WAAgF"}
@@ -0,0 +1,285 @@
1
+ export type BaseUserFields = {
2
+ name: string;
3
+ email: string;
4
+ emailVerified: boolean;
5
+ image?: string;
6
+ createdAt: Date;
7
+ updatedAt: Date;
8
+ role?: string;
9
+ };
10
+ export type UserPluginFields = {
11
+ "username": {
12
+ username?: string;
13
+ displayUsername?: string;
14
+ };
15
+ "admin": {
16
+ banned?: boolean;
17
+ banReason?: string;
18
+ banExpires?: Date;
19
+ };
20
+ "phone-number": {
21
+ phoneNumber?: string;
22
+ phoneNumberVerified?: boolean;
23
+ };
24
+ "anonymous": {
25
+ isAnonymous?: boolean;
26
+ };
27
+ "two-factor": {
28
+ twoFactorEnabled?: boolean;
29
+ };
30
+ "last-login-method": {
31
+ lastLoginMethod?: string;
32
+ };
33
+ "stripe": {
34
+ stripeCustomerId?: string;
35
+ };
36
+ };
37
+ export type User = BaseUserFields & UserPluginFields["username"] & UserPluginFields["admin"] & UserPluginFields["phone-number"] & UserPluginFields["anonymous"] & UserPluginFields["two-factor"] & UserPluginFields["last-login-method"] & UserPluginFields["stripe"];
38
+ export type BaseSessionFields = {
39
+ expiresAt: Date;
40
+ token: string;
41
+ createdAt: Date;
42
+ updatedAt: Date;
43
+ ipAddress?: string;
44
+ userAgent?: string;
45
+ userId: string;
46
+ };
47
+ export type SessionPluginFields = {
48
+ "admin": {
49
+ impersonatedBy?: string;
50
+ };
51
+ "organization": {
52
+ activeOrganizationId?: string;
53
+ activeTeamId?: string;
54
+ };
55
+ };
56
+ export type Session = BaseSessionFields & SessionPluginFields["admin"] & SessionPluginFields["organization"];
57
+ export type BaseAccountFields = {
58
+ accountId: string;
59
+ providerId: string;
60
+ userId: string;
61
+ accessToken?: string;
62
+ refreshToken?: string;
63
+ idToken?: string;
64
+ accessTokenExpiresAt?: Date;
65
+ refreshTokenExpiresAt?: Date;
66
+ scope?: string;
67
+ password?: string;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ };
71
+ export type Account = BaseAccountFields;
72
+ export type BaseVerificationFields = {
73
+ identifier: string;
74
+ value: string;
75
+ expiresAt: Date;
76
+ createdAt: Date;
77
+ updatedAt: Date;
78
+ };
79
+ export type Verification = BaseVerificationFields;
80
+ export type ApikeyFields = {
81
+ name?: string;
82
+ start?: string;
83
+ prefix?: string;
84
+ key: string;
85
+ userId: string;
86
+ refillInterval?: number;
87
+ refillAmount?: number;
88
+ lastRefillAt?: Date;
89
+ enabled?: boolean;
90
+ rateLimitEnabled?: boolean;
91
+ rateLimitTimeWindow?: number;
92
+ rateLimitMax?: number;
93
+ requestCount?: number;
94
+ remaining?: number;
95
+ lastRequest?: Date;
96
+ expiresAt?: Date;
97
+ createdAt: Date;
98
+ updatedAt: Date;
99
+ permissions?: string;
100
+ metadata?: string;
101
+ };
102
+ export type Apikey = ApikeyFields;
103
+ export type OauthApplicationPluginFields = {
104
+ "oidc": {
105
+ name?: string;
106
+ icon?: string;
107
+ metadata?: string;
108
+ clientId?: string;
109
+ clientSecret?: string;
110
+ redirectUrls?: string;
111
+ type?: string;
112
+ disabled?: boolean;
113
+ userId?: string;
114
+ createdAt?: Date;
115
+ updatedAt?: Date;
116
+ };
117
+ "mcp": {
118
+ name?: string;
119
+ icon?: string;
120
+ metadata?: string;
121
+ clientId?: string;
122
+ clientSecret?: string;
123
+ redirectUrls?: string;
124
+ type?: string;
125
+ disabled?: boolean;
126
+ userId?: string;
127
+ createdAt?: Date;
128
+ updatedAt?: Date;
129
+ };
130
+ };
131
+ export type OauthApplication = OauthApplicationPluginFields["oidc"] & OauthApplicationPluginFields["mcp"];
132
+ export type OauthAccessTokenPluginFields = {
133
+ "oidc": {
134
+ accessToken?: string;
135
+ refreshToken?: string;
136
+ accessTokenExpiresAt?: Date;
137
+ refreshTokenExpiresAt?: Date;
138
+ clientId?: string;
139
+ userId?: string;
140
+ scopes?: string;
141
+ createdAt?: Date;
142
+ updatedAt?: Date;
143
+ };
144
+ "mcp": {
145
+ accessToken?: string;
146
+ refreshToken?: string;
147
+ accessTokenExpiresAt?: Date;
148
+ refreshTokenExpiresAt?: Date;
149
+ clientId?: string;
150
+ userId?: string;
151
+ scopes?: string;
152
+ createdAt?: Date;
153
+ updatedAt?: Date;
154
+ };
155
+ };
156
+ export type OauthAccessToken = OauthAccessTokenPluginFields["oidc"] & OauthAccessTokenPluginFields["mcp"];
157
+ export type OauthConsentPluginFields = {
158
+ "oidc": {
159
+ clientId?: string;
160
+ userId?: string;
161
+ scopes?: string;
162
+ createdAt?: Date;
163
+ updatedAt?: Date;
164
+ consentGiven?: boolean;
165
+ };
166
+ "mcp": {
167
+ clientId?: string;
168
+ userId?: string;
169
+ scopes?: string;
170
+ createdAt?: Date;
171
+ updatedAt?: Date;
172
+ consentGiven?: boolean;
173
+ };
174
+ };
175
+ export type OauthConsent = OauthConsentPluginFields["oidc"] & OauthConsentPluginFields["mcp"];
176
+ export type SsoProviderFields = {
177
+ issuer: string;
178
+ oidcConfig?: string;
179
+ samlConfig?: string;
180
+ userId?: string;
181
+ providerId: string;
182
+ organizationId?: string;
183
+ domain: string;
184
+ };
185
+ export type SsoProvider = SsoProviderFields;
186
+ export type OrganizationFields = {
187
+ name: string;
188
+ slug: string;
189
+ logo?: string;
190
+ createdAt: Date;
191
+ metadata?: string;
192
+ };
193
+ export type Organization = OrganizationFields;
194
+ export type TeamFields = {
195
+ name: string;
196
+ organizationId: string;
197
+ createdAt: Date;
198
+ updatedAt?: Date;
199
+ };
200
+ export type Team = TeamFields;
201
+ export type TeamMemberFields = {
202
+ teamId: string;
203
+ userId: string;
204
+ createdAt?: Date;
205
+ };
206
+ export type TeamMember = TeamMemberFields;
207
+ export type MemberFields = {
208
+ organizationId: string;
209
+ userId: string;
210
+ role: string;
211
+ createdAt: Date;
212
+ };
213
+ export type Member = MemberFields;
214
+ export type InvitationFields = {
215
+ organizationId: string;
216
+ email: string;
217
+ role?: string;
218
+ teamId?: string;
219
+ status: string;
220
+ expiresAt: Date;
221
+ createdAt: Date;
222
+ inviterId: string;
223
+ };
224
+ export type Invitation = InvitationFields;
225
+ export type JwksFields = {
226
+ publicKey: string;
227
+ privateKey: string;
228
+ createdAt: Date;
229
+ expiresAt?: Date;
230
+ };
231
+ export type Jwks = JwksFields;
232
+ export type TwoFactorFields = {
233
+ secret: string;
234
+ backupCodes: string;
235
+ userId: string;
236
+ };
237
+ export type TwoFactor = TwoFactorFields;
238
+ export type DeviceCodeFields = {
239
+ deviceCode: string;
240
+ userCode: string;
241
+ userId?: string;
242
+ expiresAt: Date;
243
+ status: string;
244
+ lastPolledAt?: Date;
245
+ pollingInterval?: number;
246
+ clientId?: string;
247
+ scope?: string;
248
+ };
249
+ export type DeviceCode = DeviceCodeFields;
250
+ export type SubscriptionFields = {
251
+ plan: string;
252
+ referenceId: string;
253
+ stripeCustomerId?: string;
254
+ stripeSubscriptionId?: string;
255
+ status?: string;
256
+ periodStart?: Date;
257
+ periodEnd?: Date;
258
+ trialStart?: Date;
259
+ trialEnd?: Date;
260
+ cancelAtPeriodEnd?: boolean;
261
+ seats?: number;
262
+ };
263
+ export type Subscription = SubscriptionFields;
264
+ export type PluginId = "username" | "admin" | "api-key" | "passkey" | "bearer" | "email-otp" | "magic-link" | "phone-number" | "one-tap" | "anonymous" | "multi-session" | "one-time-token" | "oidc" | "sso" | "generic-oauth" | "open-api" | "organization" | "jwt" | "two-factor" | "next-cookies" | "custom-session" | "mcp" | "device-authorization" | "last-login-method" | "stripe" | "polar";
265
+ export type BetterAuthFullSchema = {
266
+ "user": User;
267
+ "session": Session;
268
+ "account": Account;
269
+ "verification": Verification;
270
+ "apikey": Apikey;
271
+ "oauthApplication": OauthApplication;
272
+ "oauthAccessToken": OauthAccessToken;
273
+ "oauthConsent": OauthConsent;
274
+ "ssoProvider": SsoProvider;
275
+ "organization": Organization;
276
+ "team": Team;
277
+ "teamMember": TeamMember;
278
+ "member": Member;
279
+ "invitation": Invitation;
280
+ "jwks": Jwks;
281
+ "twoFactor": TwoFactor;
282
+ "deviceCode": DeviceCode;
283
+ "subscription": Subscription;
284
+ };
285
+ export type ModelKey = keyof BetterAuthFullSchema;
@@ -0,0 +1,3 @@
1
+ export * from './adapter';
2
+ export * from './plugin';
3
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ export * from "./adapter";
2
+ export * from "./plugin";
3
+ export * from "./types";
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/better-auth/index.ts"],"sourcesContent":["export * from './adapter';\nexport * from './plugin';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,UAAU"}
@@ -0,0 +1,162 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { betterAuthPlugin } from "../index";
3
+ // Mock Payload CMS
4
+ const mockPayload = {
5
+ collections: {},
6
+ config: {
7
+ custom: {
8
+ hasBetterAuthPlugin: true
9
+ }
10
+ },
11
+ db: {
12
+ defaultIDType: 'string'
13
+ }
14
+ };
15
+ vi.mock('payload', ()=>({
16
+ getPayload: vi.fn().mockResolvedValue(mockPayload),
17
+ buildConfig: vi.fn().mockReturnValue(mockPayload)
18
+ }));
19
+ describe('BetterAuth Plugin', ()=>{
20
+ describe('plugin initialization', ()=>{
21
+ it('should initialize plugin with default options', ()=>{
22
+ const plugin = betterAuthPlugin({
23
+ betterAuthOptions: {
24
+ database: {},
25
+ plugins: []
26
+ }
27
+ });
28
+ expect(plugin).toBeDefined();
29
+ expect(typeof plugin).toBe('function');
30
+ });
31
+ it('should handle disabled plugin', ()=>{
32
+ const plugin = betterAuthPlugin({
33
+ disabled: true,
34
+ betterAuthOptions: {
35
+ database: {},
36
+ plugins: []
37
+ }
38
+ });
39
+ const result = plugin({});
40
+ expect(result).toEqual({});
41
+ });
42
+ it('should add hasBetterAuthPlugin flag to config', ()=>{
43
+ const plugin = betterAuthPlugin({
44
+ betterAuthOptions: {
45
+ database: {},
46
+ plugins: []
47
+ }
48
+ });
49
+ const config = {
50
+ custom: {}
51
+ };
52
+ const result = plugin(config);
53
+ expect(result.custom.hasBetterAuthPlugin).toBe(true);
54
+ });
55
+ });
56
+ describe('collection building', ()=>{
57
+ it('should build collections from schema', ()=>{
58
+ const plugin = betterAuthPlugin({
59
+ betterAuthOptions: {
60
+ database: {},
61
+ plugins: []
62
+ }
63
+ });
64
+ const config = {
65
+ collections: [],
66
+ custom: {}
67
+ };
68
+ const result = plugin(config);
69
+ expect(result.collections).toBeDefined();
70
+ expect(Array.isArray(result.collections)).toBe(true);
71
+ });
72
+ it('should preserve existing collections', ()=>{
73
+ const existingCollection = {
74
+ slug: 'custom-collection',
75
+ fields: []
76
+ };
77
+ const plugin = betterAuthPlugin({
78
+ betterAuthOptions: {
79
+ database: {},
80
+ plugins: []
81
+ }
82
+ });
83
+ const config = {
84
+ collections: [
85
+ existingCollection
86
+ ],
87
+ custom: {}
88
+ };
89
+ const result = plugin(config);
90
+ expect(result.collections).toContain(existingCollection);
91
+ });
92
+ });
93
+ describe('onInit hook', ()=>{
94
+ it('should set up onInit hook', ()=>{
95
+ const plugin = betterAuthPlugin({
96
+ betterAuthOptions: {
97
+ database: {},
98
+ plugins: []
99
+ }
100
+ });
101
+ const config = {
102
+ collections: [],
103
+ custom: {},
104
+ onInit: vi.fn()
105
+ };
106
+ const result = plugin(config);
107
+ expect(result.onInit).toBeDefined();
108
+ expect(typeof result.onInit).toBe('function');
109
+ });
110
+ it('should call existing onInit before setting up BetterAuth', async ()=>{
111
+ const existingOnInit = vi.fn();
112
+ const plugin = betterAuthPlugin({
113
+ betterAuthOptions: {
114
+ database: {},
115
+ plugins: []
116
+ }
117
+ });
118
+ const config = {
119
+ collections: [],
120
+ custom: {},
121
+ onInit: existingOnInit
122
+ };
123
+ const result = plugin(config);
124
+ // Mock the payload instance
125
+ const mockPayloadInstance = {
126
+ betterAuth: undefined
127
+ };
128
+ await result.onInit(mockPayloadInstance);
129
+ expect(existingOnInit).toHaveBeenCalledWith(mockPayloadInstance);
130
+ expect(mockPayloadInstance.betterAuth).toBeDefined();
131
+ });
132
+ });
133
+ describe('error handling', ()=>{
134
+ it('should handle initialization errors gracefully', async ()=>{
135
+ const plugin = betterAuthPlugin({
136
+ betterAuthOptions: {
137
+ database: {},
138
+ plugins: []
139
+ }
140
+ });
141
+ const config = {
142
+ collections: [],
143
+ custom: {},
144
+ onInit: vi.fn()
145
+ };
146
+ const result = plugin(config);
147
+ // Mock payload that will throw an error
148
+ const mockPayloadWithError = {
149
+ db: {
150
+ defaultIDType: 'string'
151
+ }
152
+ };
153
+ // Mock the initBetterAuth to throw an error
154
+ vi.doMock('../lib/init-better-auth', ()=>({
155
+ initBetterAuth: vi.fn().mockRejectedValue(new Error('Init error'))
156
+ }));
157
+ await expect(result.onInit(mockPayloadWithError)).rejects.toThrow('Init error');
158
+ });
159
+ });
160
+ });
161
+
162
+ //# sourceMappingURL=plugin.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/better-auth/plugin/__tests__/plugin.test.ts"],"sourcesContent":["import { beforeEach, describe, expect, it, vi } from 'vitest';\nimport { betterAuthPlugin } from '../index';\n\n// Mock Payload CMS\nconst mockPayload = {\n collections: {},\n config: {\n custom: { hasBetterAuthPlugin: true },\n },\n db: {\n defaultIDType: 'string',\n },\n};\n\nvi.mock('payload', () => ({\n getPayload: vi.fn().mockResolvedValue(mockPayload),\n buildConfig: vi.fn().mockReturnValue(mockPayload),\n}));\n\ndescribe('BetterAuth Plugin', () => {\n describe('plugin initialization', () => {\n it('should initialize plugin with default options', () => {\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n expect(plugin).toBeDefined();\n expect(typeof plugin).toBe('function');\n });\n\n it('should handle disabled plugin', () => {\n const plugin = betterAuthPlugin({\n disabled: true,\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const result = plugin({} as any);\n expect(result).toEqual({});\n });\n\n it('should add hasBetterAuthPlugin flag to config', () => {\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = { custom: {} };\n const result = plugin(config as any);\n\n expect(result.custom.hasBetterAuthPlugin).toBe(true);\n });\n });\n\n describe('collection building', () => {\n it('should build collections from schema', () => {\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = {\n collections: [],\n custom: {},\n };\n\n const result = plugin(config as any);\n\n expect(result.collections).toBeDefined();\n expect(Array.isArray(result.collections)).toBe(true);\n });\n\n it('should preserve existing collections', () => {\n const existingCollection = {\n slug: 'custom-collection',\n fields: [],\n };\n\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = {\n collections: [existingCollection],\n custom: {},\n };\n\n const result = plugin(config as any);\n\n expect(result.collections).toContain(existingCollection);\n });\n });\n\n describe('onInit hook', () => {\n it('should set up onInit hook', () => {\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = {\n collections: [],\n custom: {},\n onInit: vi.fn(),\n };\n\n const result = plugin(config as any);\n\n expect(result.onInit).toBeDefined();\n expect(typeof result.onInit).toBe('function');\n });\n\n it('should call existing onInit before setting up BetterAuth', async () => {\n const existingOnInit = vi.fn();\n\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = {\n collections: [],\n custom: {},\n onInit: existingOnInit,\n };\n\n const result = plugin(config as any);\n\n // Mock the payload instance\n const mockPayloadInstance = {\n betterAuth: undefined,\n };\n\n await result.onInit(mockPayloadInstance as any);\n\n expect(existingOnInit).toHaveBeenCalledWith(mockPayloadInstance);\n expect(mockPayloadInstance.betterAuth).toBeDefined();\n });\n });\n\n describe('error handling', () => {\n it('should handle initialization errors gracefully', async () => {\n const plugin = betterAuthPlugin({\n betterAuthOptions: {\n database: {} as any,\n plugins: [],\n },\n });\n\n const config = {\n collections: [],\n custom: {},\n onInit: vi.fn(),\n };\n\n const result = plugin(config as any);\n\n // Mock payload that will throw an error\n const mockPayloadWithError = {\n db: { defaultIDType: 'string' },\n };\n\n // Mock the initBetterAuth to throw an error\n vi.doMock('../lib/init-better-auth', () => ({\n initBetterAuth: vi.fn().mockRejectedValue(new Error('Init error')),\n }));\n\n await expect(result.onInit(mockPayloadWithError as any)).rejects.toThrow('Init error');\n });\n });\n});\n"],"names":["describe","expect","it","vi","betterAuthPlugin","mockPayload","collections","config","custom","hasBetterAuthPlugin","db","defaultIDType","mock","getPayload","fn","mockResolvedValue","buildConfig","mockReturnValue","plugin","betterAuthOptions","database","plugins","toBeDefined","toBe","disabled","result","toEqual","Array","isArray","existingCollection","slug","fields","toContain","onInit","existingOnInit","mockPayloadInstance","betterAuth","undefined","toHaveBeenCalledWith","mockPayloadWithError","doMock","initBetterAuth","mockRejectedValue","Error","rejects","toThrow"],"mappings":"AAAA,SAAqBA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAS;AAC9D,SAASC,gBAAgB,QAAQ,WAAW;AAE5C,mBAAmB;AACnB,MAAMC,cAAc;IAClBC,aAAa,CAAC;IACdC,QAAQ;QACNC,QAAQ;YAAEC,qBAAqB;QAAK;IACtC;IACAC,IAAI;QACFC,eAAe;IACjB;AACF;AAEAR,GAAGS,IAAI,CAAC,WAAW,IAAO,CAAA;QACxBC,YAAYV,GAAGW,EAAE,GAAGC,iBAAiB,CAACV;QACtCW,aAAab,GAAGW,EAAE,GAAGG,eAAe,CAACZ;IACvC,CAAA;AAEAL,SAAS,qBAAqB;IAC5BA,SAAS,yBAAyB;QAChCE,GAAG,iDAAiD;YAClD,MAAMgB,SAASd,iBAAiB;gBAC9Be,mBAAmB;oBACjBC,UAAU,CAAC;oBACXC,SAAS,EAAE;gBACb;YACF;YAEApB,OAAOiB,QAAQI,WAAW;YAC1BrB,OAAO,OAAOiB,QAAQK,IAAI,CAAC;QAC7B;QAE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