@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,664 @@
1
+ import { getAuthTables } from "better-auth/db";
2
+ export const createTransform = (options, enableDebugLogs)=>{
3
+ const schema = getAuthTables(options);
4
+ // Using any[] because debug log messages can contain any types (strings, objects, numbers, etc.)
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- debug log messages can contain any types
6
+ function debugLog(message) {
7
+ if (enableDebugLogs) {
8
+ console.log('[payload-db-adapter]', ...message);
9
+ }
10
+ }
11
+ /**
12
+ * Maps a BetterAuth schema model name to its corresponding Payload CMS collection slug.
13
+ *
14
+ * This function resolves the appropriate collection slug by:
15
+ * 1. Looking up the model in the BetterAuth schema to find its configured modelName
16
+ * 2. Falling back to the original model name if no mapping exists
17
+ *
18
+ * Collection slug resolution follows these rules:
19
+ * - For base collections: The sanitizeBetterAuthOptions function ensures the collection slug
20
+ * from plugin options is set as the model name in the schema
21
+ * - For plugins: The betterAuthPluginSlugs constant is used as the modelName
22
+ *
23
+ * @param model - The BetterAuth model name to resolve
24
+ * @returns The corresponding Payload CMS collection slug
25
+ *
26
+ * @example
27
+ * // If schema['user'].modelName is 'users'
28
+ * getCollectionSlug('user') // Returns 'users'
29
+ *
30
+ * @example
31
+ * // If model doesn't exist in schema
32
+ * getCollectionSlug('custom') // Returns 'custom'
33
+ *
34
+ * @warning If a collection is overridden using the collectionOverride option
35
+ * without updating the schema mapping, this function may return incorrect slugs
36
+ */ function getCollectionSlug(model) {
37
+ // First try to get the modelName from schema, otherwise fall back to the original model name
38
+ const collection = schema?.[model]?.modelName || model;
39
+ debugLog([
40
+ 'getCollectionSlug:',
41
+ {
42
+ model,
43
+ resolvedSlug: collection
44
+ }
45
+ ]);
46
+ return collection;
47
+ }
48
+ /**
49
+ * Maps a BetterAuth schema field to its corresponding Payload CMS field name.
50
+ *
51
+ * This function resolves the appropriate field name by:
52
+ * 1. Preserving 'id' or '_id' fields as-is (special case handling)
53
+ * 2. Looking up the field in the BetterAuth schema to find its configured fieldName
54
+ * 3. Falling back to the original field name if no mapping exists
55
+ *
56
+ * @param model - The BetterAuth model name containing the field
57
+ * @param field - The original field name to resolve
58
+ * @returns The corresponding Payload CMS field name
59
+ *
60
+ * @example
61
+ * // If schema['user'].fields['email'].fieldName is 'emailAddress'
62
+ * getFieldName('user', 'email') // Returns 'emailAddress'
63
+ *
64
+ * @example
65
+ * // Special case for ID fields
66
+ * getFieldName('user', 'id') // Always returns 'id'
67
+ *
68
+ * @example
69
+ * // If field doesn't exist in schema or has no fieldName mapping
70
+ * getFieldName('user', 'custom') // Returns 'custom'
71
+ *
72
+ * @warning If a fieldName is overridden in the payload collection config using the collectionOverride option
73
+ * without updating the schema mapping, this function may return incorrect field names
74
+ */ function getFieldName(model, field) {
75
+ // Special case: 'id' or '_id' is always preserved as-is
76
+ if ([
77
+ 'id',
78
+ '_id'
79
+ ].includes(field)) {
80
+ return field;
81
+ }
82
+ // Look up the field in the schema
83
+ const fieldDefinition = schema[model]?.fields[field];
84
+ // Use the configured fieldName if available, otherwise fall back to original
85
+ const fieldName = fieldDefinition?.fieldName || field;
86
+ // Log the field resolution for debugging
87
+ debugLog([
88
+ 'getField: ',
89
+ {
90
+ fieldName,
91
+ model,
92
+ originalField: field
93
+ }
94
+ ]);
95
+ return fieldName;
96
+ }
97
+ /**
98
+ * Determines if a field is a relationship field by checking for a references property.
99
+ *
100
+ * Relationship fields in the schema have a 'references' property that points to another model.
101
+ * This function checks if this property exists to identify relationship fields.
102
+ *
103
+ * @param fieldKey - The key of the field to check in the schema
104
+ * @param schemaFields - Object containing all fields from the schema for a specific model
105
+ * @returns True if the field is a relationship field (has references), false otherwise
106
+ *
107
+ * @example
108
+ * // If schema.user.fields.posts has { references: {} }
109
+ * isRelationshipField('posts', schema.user.fields) // Returns true
110
+ *
111
+ * @example
112
+ * // If schema.user.fields.email has no references property
113
+ * isRelationshipField('email', schema.user.fields) // Returns false
114
+ */ function isRelationshipField(fieldKey, schemaFields) {
115
+ // A field is a relationship field if it has a 'references' property defined
116
+ return schemaFields[fieldKey]?.references !== undefined;
117
+ }
118
+ /**
119
+ * Extracts a single ID value from a Payload where clause if it represents a simple ID query.
120
+ *
121
+ * This function analyzes a Payload where clause to determine if it's a simple query for a
122
+ * single document by ID. It supports both 'id' and '_id' fields with 'equals' or 'contains'
123
+ * operators. This is useful for optimizing queries when we only need to fetch a single document.
124
+ *
125
+ * @param where - The Payload where clause to analyze
126
+ * @returns The ID value (string or number) if the where clause is a simple ID query, null otherwise
127
+ *
128
+ * @example
129
+ * // Returns '123' for a simple equals query
130
+ * singleIdQuery({ id: { equals: '123' } }) // '123'
131
+ *
132
+ * @example
133
+ * // Returns 456 for a simple equals query with number ID
134
+ * singleIdQuery({ _id: { equals: 456 } }) // 456
135
+ *
136
+ * @example
137
+ * // Returns '789' for a contains query with a single value
138
+ * singleIdQuery({ id: { contains: ['789'] } }) // '789'
139
+ *
140
+ * @example
141
+ * // Returns null for complex queries
142
+ * singleIdQuery({ and: [{ id: { equals: '123' } }] }) // null
143
+ */ function singleIdQuery(where) {
144
+ // Return null for empty where clauses or complex queries with 'and'/'or' operators
145
+ if (!where || 'and' in where || 'or' in where) return null;
146
+ // Check if the where clause contains either 'id' or '_id' field
147
+ if ([
148
+ 'id',
149
+ '_id'
150
+ ].some((field)=>field in where)) {
151
+ // Determine which ID field is being used (support both 'id' and '_id')
152
+ const idField = 'id' in where ? 'id' : '_id';
153
+ const condition = where[idField];
154
+ // Process the equals operator case
155
+ if (condition && typeof condition === 'object' && !Array.isArray(condition) && 'equals' in condition) {
156
+ const value = condition.equals;
157
+ // Only return string or number ID values
158
+ if (typeof value === 'string' || typeof value === 'number') {
159
+ return value;
160
+ }
161
+ }
162
+ // Process the contains operator case with a single value
163
+ if (condition && typeof condition === 'object' && !Array.isArray(condition) && 'contains' in condition && Array.isArray(condition.contains) && condition.contains.length === 1) {
164
+ const value = condition.contains[0];
165
+ // Only return string or number ID values
166
+ if (typeof value === 'string' || typeof value === 'number') {
167
+ return value;
168
+ }
169
+ }
170
+ }
171
+ // Return null if no valid ID query was found
172
+ return null;
173
+ }
174
+ /**
175
+ * Normalizes data values based on field type and required ID type
176
+ *
177
+ * This function handles type conversion for relationship fields to ensure
178
+ * IDs are in the correct format (string or number) based on the configuration.
179
+ *
180
+ * @param key - The field key/name
181
+ * @param value - The value to normalize
182
+ * @param isRelatedField - Whether this field is a relationship field
183
+ * @param idType - The expected ID type ('number' or 'text')
184
+ * @returns The normalized value
185
+ */ function normalizeData({ idType, isRelatedField, key, value }) {
186
+ // Skip processing for null/undefined values
187
+ if (value === null || value === undefined) {
188
+ return value;
189
+ }
190
+ if ([
191
+ 'id',
192
+ '_id'
193
+ ].includes(key)) {
194
+ if (typeof value === 'string' && idType === 'number') {
195
+ const parsed = parseInt(value, 10);
196
+ if (!Number.isNaN(parsed)) {
197
+ debugLog([
198
+ `ID conversion: ${key} converting string ID to number`,
199
+ {
200
+ converted: parsed,
201
+ original: value
202
+ }
203
+ ]);
204
+ return parsed;
205
+ }
206
+ }
207
+ if (typeof value === 'number' && idType === 'text') {
208
+ const stringId = String(value);
209
+ debugLog([
210
+ `ID conversion: ${key} converting number ID to string`,
211
+ {
212
+ converted: stringId,
213
+ original: value
214
+ }
215
+ ]);
216
+ return stringId;
217
+ }
218
+ }
219
+ // Only process relationship fields that need type conversion
220
+ if (isRelatedField) {
221
+ // Handle single ID value conversion
222
+ if (typeof value === 'string' && idType === 'number') {
223
+ const parsed = parseInt(value, 10);
224
+ if (!Number.isNaN(parsed)) {
225
+ debugLog([
226
+ `ID conversion: ${key} converting string ID to number`,
227
+ {
228
+ converted: parsed,
229
+ original: value
230
+ }
231
+ ]);
232
+ return parsed;
233
+ }
234
+ } else if (typeof value === 'number' && idType === 'text') {
235
+ const stringId = String(value);
236
+ debugLog([
237
+ `ID conversion: ${key} converting number ID to string`,
238
+ {
239
+ converted: stringId,
240
+ original: value
241
+ }
242
+ ]);
243
+ return stringId;
244
+ }
245
+ // Handle array of IDs - map each value to the correct type
246
+ if (Array.isArray(value)) {
247
+ return value.map((id)=>{
248
+ // Skip null/undefined values in arrays
249
+ if (id === null || id === undefined) return id;
250
+ if (idType === 'number' && typeof id === 'string') {
251
+ const parsed = parseInt(id, 10);
252
+ return !Number.isNaN(parsed) ? parsed : id;
253
+ }
254
+ if (idType === 'text' && typeof id === 'number') {
255
+ return String(id);
256
+ }
257
+ return id;
258
+ });
259
+ }
260
+ }
261
+ // Return original value if no conversion was needed or applicable
262
+ return value;
263
+ }
264
+ /**
265
+ * Transforms input data from better-auth to Payload CMS format
266
+ *
267
+ * This function handles:
268
+ * 1. Field name mapping according to schema definitions
269
+ * 2. ID type conversion for relationship fields
270
+ * 3. Proper data normalization based on field types
271
+ *
272
+ * @param data - The input data from better-auth
273
+ * @param model - The model name in the schema
274
+ * @param idType - The expected ID type ('number' or 'text')
275
+ * @returns Transformed data compatible with Payload CMS
276
+ */ function transformInput({ data, idType, model }) {
277
+ // Using Record<string, any> because transformed data structure varies by model and field configuration
278
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- transformed data structure varies by model and field configuration
279
+ const transformedData = {};
280
+ const schemaFields = schema?.[model]?.fields ?? {};
281
+ // Process each field in the input data
282
+ Object.entries(data).forEach(([key, value])=>{
283
+ // Skip null/undefined values
284
+ if (value === null || value === undefined) {
285
+ return;
286
+ }
287
+ // Determine if this is a relationship field
288
+ const isRelatedField = isRelationshipField(key, schemaFields);
289
+ // Get the mapped field name from schema (if any)
290
+ // Using any because schemaFields[key] may not exist and value type varies by field
291
+ const schemaFieldName = schemaFields[key]?.fieldName;
292
+ // Normalize the data value based on field type and ID type
293
+ const normalizedData = normalizeData({
294
+ idType,
295
+ isRelatedField,
296
+ key,
297
+ value
298
+ });
299
+ // Use the schema-defined field name if available, otherwise use original key
300
+ const targetFieldName = schemaFieldName ?? key;
301
+ transformedData[targetFieldName] = normalizedData;
302
+ });
303
+ return transformedData;
304
+ }
305
+ /**
306
+ * Transforms Payload CMS document output to match BetterAuth schema expectations.
307
+ *
308
+ * This function handles several critical transformations:
309
+ *
310
+ * 1. ID Conversion: Ensures all ID fields are strings as required by BetterAuth
311
+ * (see: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/db/schema.ts#L125)
312
+ *
313
+ * 2. Relationship Field Mapping: Aligns relationship fields with BetterAuth schema naming conventions
314
+ * and ensures proper ID type handling
315
+ *
316
+ * 3. Date Conversion: Transforms date strings from Payload into Date objects for BetterAuth
317
+ *
318
+ * Note: While setting depth: 1 in Payload operations simplifies this process by avoiding
319
+ * deeply nested objects, we maintain comprehensive checks for robustness.
320
+ *
321
+ * @param doc - The document returned from Payload CMS
322
+ * @param model - The model name in the BetterAuth schema
323
+ * @returns The transformed document compatible with BetterAuth
324
+ */ // Using Record<string, any> because document structure varies by model and field configuration
325
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- document structure varies by model and field configuration
326
+ function transformOutput({ doc, model }) {
327
+ if (!doc || typeof doc !== 'object') return doc;
328
+ const result = {
329
+ ...doc
330
+ };
331
+ const schemaFields = schema?.[model]?.fields ?? {};
332
+ // Identify relationship fields with custom field name mappings
333
+ const relationshipFields = Object.fromEntries(Object.entries(schemaFields).filter(([key])=>isRelationshipField(key, schemaFields)));
334
+ const dateFields = Object.fromEntries(Object.entries(schemaFields).filter(([_, value])=>value.type === 'date'));
335
+ Object.entries(doc).forEach(([key, value])=>{
336
+ if (value === null || value === undefined) return;
337
+ // Convert ID fields to strings for BetterAuth compatibility
338
+ if ([
339
+ 'id',
340
+ '_id'
341
+ ].includes(key)) {
342
+ result[key] = String(value);
343
+ return;
344
+ }
345
+ // Handle relationship fields with renamed fieldNames
346
+ const originalRelatedFieldKey = Object.keys(relationshipFields).find((k)=>relationshipFields[k]?.fieldName === key);
347
+ if (originalRelatedFieldKey) {
348
+ normalizeDocumentIds(result, originalRelatedFieldKey, key, value);
349
+ return;
350
+ }
351
+ const originalDateFieldKey = Object.keys(dateFields).find((k)=>dateFields[k]?.fieldName === key);
352
+ if (originalDateFieldKey) {
353
+ // Convert ISO date strings to Date objects for BetterAuth
354
+ result[key] = new Date(value);
355
+ }
356
+ });
357
+ return result;
358
+ }
359
+ /**
360
+ * Normalizes ID fields for both primary and relationship documents.
361
+ *
362
+ * This function ensures consistent ID handling between BetterAuth and Payload CMS by:
363
+ * 1. Converting all IDs to strings for BetterAuth (stored in originalKey)
364
+ * 2. Preserving original ID types for Payload CMS (stored in fieldName)
365
+ *
366
+ * The function handles various ID formats:
367
+ * - Primitive values (string/number IDs)
368
+ * - Object references with ID properties
369
+ * - Arrays of either primitive IDs or object references
370
+ *
371
+ * @param result - The result object being transformed
372
+ * @param originalKey - The original field key from BetterAuth schema
373
+ * @param fieldName - The renamed field as used in Payload CMS
374
+ * @param value - The ID value to normalize (primitive, object, or array)
375
+ */ // Using Record<string, any> because result object structure varies by document type and field configuration
376
+ function normalizeDocumentIds(// Using Record<string, any> because result object structure varies by document type and field configuration
377
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- result object structure varies by document type and field configuration
378
+ result, originalKey, fieldName, // Using any because value can be primitive, object, or array depending on field type
379
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- value can be primitive, object, or array depending on field type
380
+ value) {
381
+ // Case 1: Primitive ID value (string or number)
382
+ if (typeof value === 'string' || typeof value === 'number') {
383
+ // For BetterAuth: Always use string IDs
384
+ result[originalKey] = String(value);
385
+ // For Payload: Keep original type
386
+ result[fieldName] = value;
387
+ return;
388
+ }
389
+ // Case 2: Object with ID property
390
+ if (typeof value === 'object' && value !== null && 'id' in value) {
391
+ // For BetterAuth: Extract and stringify the ID
392
+ result[originalKey] = String(value.id);
393
+ // For Payload: Extract ID but preserve type
394
+ result[fieldName] = value.id;
395
+ return;
396
+ }
397
+ // Case 3: Array of IDs or references
398
+ if (Array.isArray(value) && value.length > 0) {
399
+ // Check if array contains objects with ID properties
400
+ if (value.every((item)=>typeof item === 'object' && item !== null && 'id' in item)) {
401
+ // Array of objects with IDs
402
+ result[originalKey] = value.map((item)=>String(item.id));
403
+ result[fieldName] = value.map((item)=>item.id);
404
+ } else {
405
+ // Array of primitive IDs
406
+ result[originalKey] = value.map((item)=>String(item));
407
+ result[fieldName] = value.map((item)=>item);
408
+ }
409
+ }
410
+ // Note: If value doesn't match any expected format, no changes are made
411
+ }
412
+ /**
413
+ * Converts a BetterAuth operator to the equivalent Payload CMS query operator
414
+ *
415
+ * This function maps standard query operators from BetterAuth's format to
416
+ * the specific format expected by Payload CMS's query engine.
417
+ *
418
+ * @param operator - The BetterAuth operator string (e.g., 'eq', 'gt', 'contains')
419
+ * @param value - The value to be used with the operator
420
+ * @returns An object with the Payload-compatible operator and value
421
+ *
422
+ * @example
423
+ * // Returns { equals: 'test@example.com' }
424
+ * operatorToPayload('eq', 'test@example.com')
425
+ *
426
+ * @example
427
+ * // Returns { greater_than: 100 }
428
+ * operatorToPayload('gt', 100)
429
+ */ // Using any for value because query values can be strings, numbers, dates, arrays, or objects depending on operator
430
+ // Using Record<string, any> because PayloadCMS query operators return different structures (equals, greater_than, etc.)
431
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- query values can be strings, numbers, dates, arrays, or objects
432
+ function operatorToPayload(operator, value) {
433
+ switch(operator){
434
+ case 'eq':
435
+ return {
436
+ equals: value
437
+ };
438
+ case 'ne':
439
+ return {
440
+ not_equals: value
441
+ };
442
+ case 'gt':
443
+ return {
444
+ greater_than: value
445
+ };
446
+ case 'gte':
447
+ return {
448
+ greater_than_equal: value
449
+ };
450
+ case 'lt':
451
+ return {
452
+ less_than: value
453
+ };
454
+ case 'lte':
455
+ return {
456
+ less_than_equal: value
457
+ };
458
+ case 'contains':
459
+ return {
460
+ contains: value
461
+ };
462
+ case 'in':
463
+ return {
464
+ in: value
465
+ };
466
+ case 'starts_with':
467
+ return {
468
+ like: `${value}%`
469
+ };
470
+ case 'ends_with':
471
+ return {
472
+ like: `%${value}`
473
+ };
474
+ default:
475
+ // Fall back to equals for unrecognized operators
476
+ return {
477
+ equals: value
478
+ };
479
+ }
480
+ }
481
+ /**
482
+ * Converts a where clause value to the appropriate type based on field name and ID type configuration
483
+ *
484
+ * This function handles two main scenarios:
485
+ * 1. ID field conversion - ensures IDs match the database's expected type (number or string)
486
+ * 2. Object with embedded ID - extracts and converts the ID property from objects
487
+ *
488
+ * @param value - The value to convert (can be primitive, object with ID, or array)
489
+ * @param fieldName - The name of the field being queried
490
+ * @param idType - The expected ID type in the database
491
+ * @returns The converted value appropriate for the database query
492
+ */ function convertWhereValue({ fieldName, idType, value }) {
493
+ // Check if field is an ID field (supporting both MongoDB-style _id and standard id)
494
+ if ([
495
+ 'id',
496
+ '_id'
497
+ ].includes(fieldName)) {
498
+ // Case 1: Value is an object containing an ID property
499
+ if (typeof value === 'object' && value !== null && 'id' in value) {
500
+ // Extract ID from object
501
+ const id = value.id;
502
+ // Use type conversion based on database configuration
503
+ if (idType === 'number' && typeof id === 'string') {
504
+ const numId = Number(id);
505
+ return !Number.isNaN(numId) ? numId : id;
506
+ }
507
+ if (idType === 'text' && typeof id === 'number') {
508
+ return String(id);
509
+ }
510
+ return id;
511
+ }
512
+ // Case 2: Value is a standalone ID that needs type conversion
513
+ // Convert string ID to number if database expects numeric IDs
514
+ if (idType === 'number' && typeof value === 'string' && !Number.isNaN(Number(value))) {
515
+ return Number(value);
516
+ }
517
+ // Convert numeric ID to string if database expects text IDs
518
+ if (idType === 'text' && typeof value === 'number') {
519
+ return String(value);
520
+ }
521
+ return value;
522
+ }
523
+ // For non-ID fields, return the value unchanged
524
+ return value;
525
+ }
526
+ /**
527
+ * Converts Better Auth where clauses to Payload CMS compatible where conditions
528
+ *
529
+ * This function transforms the Better Auth query format into Payload's query format,
530
+ * handling field name mapping, value type conversion, and logical operators (AND/OR).
531
+ *
532
+ * The function handles three main cases:
533
+ * 1. Empty or undefined where clause - returns empty object
534
+ * 2. Single condition - converts to a simple field-value pair
535
+ * 3. Multiple conditions - groups by AND/OR connectors and builds a complex query
536
+ *
537
+ * @param idType - The database ID type ('number' or 'text')
538
+ * @param model - The model/collection name to query
539
+ * @param where - Array of Better Auth where conditions
540
+ * @returns A Payload-compatible where clause object
541
+ */ function convertWhereClause({ idType, model, where }) {
542
+ // Handle empty where clause
543
+ if (!where) return {};
544
+ // Handle single condition case for optimization
545
+ if (where.length === 1) {
546
+ const w = where[0];
547
+ if (!w) {
548
+ return {};
549
+ }
550
+ // Map field name according to schema and convert value to appropriate type
551
+ const fieldName = getFieldName(model, w.field);
552
+ const value = convertWhereValue({
553
+ fieldName,
554
+ idType,
555
+ value: w.value
556
+ });
557
+ // Create the Payload where condition with proper operator
558
+ const res = {
559
+ [fieldName]: operatorToPayload(w.operator ?? '', value)
560
+ };
561
+ return res;
562
+ }
563
+ // Handle multiple conditions by separating AND/OR clauses
564
+ // Default to AND if no connector is specified
565
+ const and = where.filter((w)=>w.connector === 'AND' || !w.connector);
566
+ const or = where.filter((w)=>w.connector === 'OR');
567
+ // Process AND conditions
568
+ const andClause = and.map((w)=>{
569
+ const fieldName = getFieldName(model, w.field);
570
+ const value = convertWhereValue({
571
+ fieldName,
572
+ idType,
573
+ value: w.value
574
+ });
575
+ return {
576
+ [fieldName]: operatorToPayload(w.operator ?? '', value)
577
+ };
578
+ });
579
+ // Process OR conditions
580
+ const orClause = or.map((w)=>{
581
+ const fieldName = getFieldName(model, w.field);
582
+ const value = convertWhereValue({
583
+ fieldName,
584
+ idType,
585
+ value: w.value
586
+ });
587
+ return {
588
+ [fieldName]: operatorToPayload(w.operator ?? '', value)
589
+ };
590
+ });
591
+ // Combine AND and OR clauses into final Payload where object
592
+ // Only include non-empty clause arrays
593
+ return {
594
+ ...andClause.length ? {
595
+ AND: andClause
596
+ } : {},
597
+ ...orClause.length ? {
598
+ OR: orClause
599
+ } : {}
600
+ };
601
+ }
602
+ /**
603
+ * Converts a better-auth select array to a Payload select object
604
+ *
605
+ * This function transforms the better-auth select array (which contains field names)
606
+ * into the format expected by Payload CMS's query API (an object with field names as keys
607
+ * and boolean true as values).
608
+ *
609
+ * It also handles field name mapping between better-auth schema and Payload collections
610
+ * by using the getFieldName helper to resolve the correct field names.
611
+ *
612
+ * @param model - The model/collection name to get field mappings from
613
+ * @param select - Optional array of field names to select
614
+ * @returns A Payload-compatible select object or undefined if no fields to select
615
+ * @example
616
+ * // Input: ['email', 'name']
617
+ * // Output: { email: true, name: true }
618
+ */ function convertSelect(model, select) {
619
+ // Return undefined if select is empty or not provided
620
+ if (!select || select.length === 0) return undefined;
621
+ // Transform the array of field names into a Payload select object
622
+ // while also mapping any field names that might be different in Payload
623
+ const result = {};
624
+ for (const field of select){
625
+ result[getFieldName(model, field)] = true;
626
+ }
627
+ return result;
628
+ }
629
+ /**
630
+ * Converts a better-auth sort object to a Payload sort string
631
+ *
632
+ * This function transforms the better-auth sort object (which contains field name and direction)
633
+ * into the format expected by Payload CMS's query API (a string with optional '-' prefix for descending order).
634
+ *
635
+ * It also handles field name mapping between better-auth schema and Payload collections
636
+ * by using the getFieldName helper to resolve the correct field names.
637
+ *
638
+ * @param model - The model/collection name to get field mappings from
639
+ * @param sortBy - Optional object containing field name and sort direction
640
+ * @returns A Payload-compatible sort string or undefined if no sort specified
641
+ * @example
642
+ * // Input: { field: 'email', direction: 'desc' }
643
+ * // Output: '-email'
644
+ * // Input: { field: 'createdAt', direction: 'asc' }
645
+ * // Output: 'createdAt'
646
+ */ function convertSort(model, sortBy) {
647
+ if (!sortBy) return undefined;
648
+ const fieldName = getFieldName(model, sortBy.field);
649
+ const prefix = sortBy.direction === 'desc' ? '-' : '';
650
+ return `${prefix}${fieldName}`;
651
+ }
652
+ return {
653
+ convertSelect,
654
+ convertSort,
655
+ convertWhereClause,
656
+ getCollectionSlug,
657
+ getFieldName,
658
+ singleIdQuery,
659
+ transformInput,
660
+ transformOutput
661
+ };
662
+ };
663
+
664
+ //# sourceMappingURL=index.js.map