@baseplate-dev/plugin-auth 0.6.16 → 0.6.18

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 (220) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/admin-crud-manage-roles-action.generator.d.ts +12 -0
  3. package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/index.d.ts +12 -0
  4. package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/template-renderers.d.ts +6 -0
  5. package/dist/better-auth/admin/generators/admin-crud-manage-roles-action/generated/typed-templates.d.ts +6 -0
  6. package/dist/better-auth/admin/generators/admin-crud-reset-password-action/admin-crud-reset-password-action.generator.d.ts +12 -0
  7. package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/index.d.ts +12 -0
  8. package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/template-renderers.d.ts +6 -0
  9. package/dist/better-auth/admin/generators/admin-crud-reset-password-action/generated/typed-templates.d.ts +12 -0
  10. package/dist/better-auth/admin/generators/admin-crud-roles-column/admin-crud-roles-column.generator.d.ts +6 -0
  11. package/dist/better-auth/generators/react/better-auth-pages/better-auth-pages.generator.d.ts +6 -0
  12. package/dist/better-auth/generators/react/better-auth-pages/generated/index.d.ts +36 -0
  13. package/dist/better-auth/generators/react/better-auth-pages/generated/template-renderers.d.ts +6 -0
  14. package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.d.ts +60 -0
  15. package/dist/better-auth/generators/react/react-better-auth/generated/index.d.ts +12 -0
  16. package/dist/better-auth/generators/react/react-better-auth/generated/template-renderers.d.ts +6 -0
  17. package/dist/better-auth/generators/react/react-better-auth/generated/typed-templates.d.ts +6 -0
  18. package/dist/better-auth/generators/react/react-better-auth/react-better-auth.generator.d.ts +6 -0
  19. package/dist/local-auth/admin/common.js +6 -0
  20. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/admin-crud-invite-user-action.generator.d.ts +531 -0
  21. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/admin-crud-invite-user-action.generator.js +119 -0
  22. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/index.d.ts +540 -0
  23. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/index.js +11 -0
  24. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-paths.d.ts +12 -0
  25. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-paths.js +24 -0
  26. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-renderers.d.ts +276 -0
  27. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/template-renderers.js +45 -0
  28. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/typed-templates.d.ts +263 -0
  29. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/generated/typed-templates.js +21 -0
  30. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/index.d.ts +2 -0
  31. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/index.js +2 -0
  32. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.d.ts +21 -0
  33. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.js +69 -0
  34. package/dist/local-auth/admin/generators/admin-crud-invite-user-action/templates/routes/-components/invite-user-dialog.tsx +122 -0
  35. package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/admin-crud-manage-roles-action.generator.d.ts +12 -0
  36. package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/index.d.ts +12 -0
  37. package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/template-renderers.d.ts +6 -0
  38. package/dist/local-auth/admin/generators/admin-crud-manage-roles-action/generated/typed-templates.d.ts +6 -0
  39. package/dist/local-auth/admin/generators/admin-crud-reset-password-action/admin-crud-reset-password-action.generator.d.ts +12 -0
  40. package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/index.d.ts +12 -0
  41. package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/template-renderers.d.ts +6 -0
  42. package/dist/local-auth/admin/generators/admin-crud-reset-password-action/generated/typed-templates.d.ts +12 -0
  43. package/dist/local-auth/admin/generators/admin-crud-roles-column/admin-crud-roles-column.generator.d.ts +6 -0
  44. package/dist/local-auth/admin/node.js +13 -0
  45. package/dist/local-auth/admin/schema/invite-user-action.d.ts +12 -0
  46. package/dist/local-auth/admin/schema/invite-user-action.js +6 -0
  47. package/dist/local-auth/admin/web.js +8 -0
  48. package/dist/local-auth/core/common.js +7 -2
  49. package/dist/local-auth/core/components/local-auth-definition-editor.js +2 -1
  50. package/dist/local-auth/core/components/local-auth-web-app-settings-form.d.ts +9 -0
  51. package/dist/local-auth/core/components/local-auth-web-app-settings-form.js +11 -0
  52. package/dist/local-auth/core/generators/auth-apollo/auth-apollo.generator.d.ts +1 -0
  53. package/dist/local-auth/core/generators/auth-email-password/auth-email-password.generator.d.ts +6 -0
  54. package/dist/local-auth/core/generators/auth-email-password/auth-email-password.generator.js +66 -6
  55. package/dist/local-auth/core/generators/auth-email-password/generated/index.d.ts +188 -0
  56. package/dist/local-auth/core/generators/auth-email-password/generated/template-paths.d.ts +5 -0
  57. package/dist/local-auth/core/generators/auth-email-password/generated/template-paths.js +5 -0
  58. package/dist/local-auth/core/generators/auth-email-password/generated/template-renderers.d.ts +18 -0
  59. package/dist/local-auth/core/generators/auth-email-password/generated/template-renderers.js +66 -0
  60. package/dist/local-auth/core/generators/auth-email-password/generated/typed-templates.d.ts +192 -0
  61. package/dist/local-auth/core/generators/auth-email-password/generated/typed-templates.js +82 -1
  62. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.d.ts +19 -0
  63. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.js +20 -0
  64. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/otp.constants.ts +22 -0
  65. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.d.ts +12 -0
  66. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.js +12 -0
  67. package/dist/local-auth/core/generators/auth-email-password/templates/module/constants/password.constants.ts +14 -0
  68. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.d.ts +2 -0
  69. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.js +30 -0
  70. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/email-otp.mutations.ts +38 -0
  71. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.d.ts +2 -0
  72. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.js +42 -0
  73. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/invite.mutations.ts +54 -0
  74. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/user-password.mutations.js +2 -19
  75. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/user-password.mutations.ts +1 -22
  76. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.d.ts +37 -0
  77. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.js +225 -0
  78. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/email-otp.service.ts +333 -0
  79. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.d.ts +39 -0
  80. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.js +138 -0
  81. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/invite.service.ts +209 -0
  82. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.js +3 -3
  83. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.ts +3 -2
  84. package/dist/local-auth/core/generators/auth-email-templates/auth-email-templates.generator.d.ts +3 -1
  85. package/dist/local-auth/core/generators/auth-email-templates/auth-email-templates.generator.js +18 -3
  86. package/dist/local-auth/core/generators/auth-email-templates/generated/index.d.ts +40 -0
  87. package/dist/local-auth/core/generators/auth-email-templates/generated/template-paths.d.ts +2 -0
  88. package/dist/local-auth/core/generators/auth-email-templates/generated/template-paths.js +2 -0
  89. package/dist/local-auth/core/generators/auth-email-templates/generated/template-renderers.d.ts +6 -0
  90. package/dist/local-auth/core/generators/auth-email-templates/generated/template-renderers.js +20 -0
  91. package/dist/local-auth/core/generators/auth-email-templates/generated/typed-templates.d.ts +40 -0
  92. package/dist/local-auth/core/generators/auth-email-templates/generated/typed-templates.js +24 -0
  93. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.d.ts +3 -0
  94. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.js +18 -0
  95. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/email-otp.email.tsx +57 -0
  96. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.d.ts +3 -0
  97. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.js +14 -0
  98. package/dist/local-auth/core/generators/auth-email-templates/templates/src/emails/auth/invite.email.tsx +47 -0
  99. package/dist/local-auth/core/generators/auth-module/auth-module.generator.d.ts +8 -0
  100. package/dist/local-auth/core/generators/auth-module/auth-module.generator.js +5 -1
  101. package/dist/local-auth/core/generators/auth-module/generated/index.d.ts +32 -0
  102. package/dist/local-auth/core/generators/auth-module/generated/template-paths.d.ts +1 -0
  103. package/dist/local-auth/core/generators/auth-module/generated/template-paths.js +1 -0
  104. package/dist/local-auth/core/generators/auth-module/generated/template-renderers.d.ts +7 -0
  105. package/dist/local-auth/core/generators/auth-module/generated/template-renderers.js +13 -0
  106. package/dist/local-auth/core/generators/auth-module/generated/ts-import-providers.d.ts +9 -0
  107. package/dist/local-auth/core/generators/auth-module/generated/ts-import-providers.js +6 -0
  108. package/dist/local-auth/core/generators/auth-module/generated/typed-templates.d.ts +25 -0
  109. package/dist/local-auth/core/generators/auth-module/generated/typed-templates.js +20 -0
  110. package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.d.ts +4 -0
  111. package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.js +1 -1
  112. package/dist/local-auth/core/generators/auth-module/templates/module/services/auth-verification.service.ts +1 -1
  113. package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.d.ts +66 -0
  114. package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.js +134 -0
  115. package/dist/local-auth/core/generators/auth-module/templates/module/services/code-verification.service.ts +184 -0
  116. package/dist/local-auth/core/generators/auth-routes/auth-routes.generator.d.ts +8 -0
  117. package/dist/local-auth/core/generators/auth-routes/auth-routes.generator.js +38 -5
  118. package/dist/local-auth/core/generators/auth-routes/generated/index.d.ts +840 -268
  119. package/dist/local-auth/core/generators/auth-routes/generated/template-paths.d.ts +3 -0
  120. package/dist/local-auth/core/generators/auth-routes/generated/template-paths.js +3 -0
  121. package/dist/local-auth/core/generators/auth-routes/generated/template-renderers.d.ts +18 -0
  122. package/dist/local-auth/core/generators/auth-routes/generated/template-renderers.js +51 -0
  123. package/dist/local-auth/core/generators/auth-routes/generated/typed-templates.d.ts +608 -283
  124. package/dist/local-auth/core/generators/auth-routes/generated/typed-templates.js +69 -23
  125. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.d.ts +9 -0
  126. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.js +10 -0
  127. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/-otp-constants.ts +11 -0
  128. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.d.ts +7 -0
  129. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.js +148 -0
  130. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/accept-invite.tsx +264 -0
  131. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.d.ts +7 -0
  132. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.js +184 -0
  133. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login-otp.tsx +311 -0
  134. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.js +1 -1
  135. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.tsx +2 -9
  136. package/dist/local-auth/core/generators/react-session/generated/index.d.ts +12 -0
  137. package/dist/local-auth/core/generators/react-session/generated/template-renderers.d.ts +6 -0
  138. package/dist/local-auth/core/generators/react-session/generated/typed-templates.d.ts +12 -0
  139. package/dist/local-auth/core/generators/react-session/react-session.generator.d.ts +6 -0
  140. package/dist/local-auth/core/node.js +24 -6
  141. package/dist/local-auth/core/schema/migrations.d.ts +3 -0
  142. package/dist/local-auth/core/schema/migrations.js +36 -0
  143. package/dist/local-auth/core/schema/models.js +8 -0
  144. package/dist/local-auth/core/schema/plugin-definition.d.ts +1 -0
  145. package/dist/local-auth/core/schema/plugin-definition.js +1 -0
  146. package/dist/local-auth/core/schema/web-app-schema.d.ts +15 -0
  147. package/dist/local-auth/core/schema/web-app-schema.js +16 -0
  148. package/dist/local-auth/core/web.js +8 -1
  149. package/dist/web/assets/{_virtual_mf-localSharedImportMap___mfe_internal__plugin_mf_2_auth-04_7KkB1.js → _virtual_mf-localSharedImportMap___mfe_internal__plugin_mf_2_auth__mf_owner__1-CKKmnLep.js} +49 -41
  150. package/dist/web/assets/{dist-BjxypexQ.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib__loadShare__.js-Cx7TvZ_H.js} +16720 -384
  151. package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib_mf_1_web__loadShare__.js-D3Nvasea.js +177 -0
  152. package/dist/web/assets/{_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_ui_mf_2_components__loadShare__.js-CXGct_48.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_baseplate_mf_2_dev_mf_1_ui_mf_2_components__loadShare__.js-C2GDE8Py.js} +3349 -2632
  153. package/dist/web/assets/{_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_tanstack_mf_1_react_mf_2_router__loadShare__.js-Ci5_qYaj.js → _virtual_mf___mfe_internal__plugin_mf_2_auth__mf_owner__1__loadShare___mf_0_tanstack_mf_1_react_mf_2_router__loadShare__.js-CiccpWjh.js} +320 -164
  154. package/dist/web/assets/{arduino-BP2nYunF.js → arduino-BXtgMpyb.js} +2 -2
  155. package/dist/web/assets/auth-CsHp2bQi.js +1 -0
  156. package/dist/web/assets/{c-C7Ey31hW.js → c-6gdx-Hqg.js} +3 -3
  157. package/dist/web/assets/{clike-D9YNFwtw.js → clike-Ds9lUsCq.js} +2 -2
  158. package/dist/web/assets/common-BGTuTgx7.js +43 -0
  159. package/dist/web/assets/common-C8_sC5pp.js +70 -0
  160. package/dist/web/assets/{common-BvU-7KsV.js → common-Co5lW_TK.js} +13 -11
  161. package/dist/web/assets/{common-eFh2vwGb.js → common-CoLuMS7U.js} +6 -6
  162. package/dist/web/assets/common-Dueu_1NG.js +36 -0
  163. package/dist/web/assets/{common-BBriDRRy.js → common-N3skPbzk.js} +10 -10
  164. package/dist/web/assets/{cpp-_RjA_yNA.js → cpp-DRYAY5P6.js} +2 -2
  165. package/dist/web/assets/{csharp-0LZzOc6Q.js → csharp-RJBSoHJ6.js} +2 -2
  166. package/dist/web/assets/{dist-SBfmsOB2.js → dist-DQd1TAJX.js} +274 -133
  167. package/dist/web/assets/{get-auth-plugin-definition-x8oAsN1R.js → get-auth-plugin-definition-DyokUVjX.js} +3 -3
  168. package/dist/web/assets/{go-CzER04EZ.js → go-D9nlw8GJ.js} +2 -2
  169. package/dist/web/assets/{hostInit-Bay0Y9UX.js → hostInit-BCYmw0H5.js} +33 -6
  170. package/dist/web/assets/{java-HAvRESj1.js → java-Asfw0WtJ.js} +2 -2
  171. package/dist/web/assets/{javascript-BVAr0eZH.js → javascript-fpnGEVws.js} +2 -2
  172. package/dist/web/assets/{kotlin-DkCMjTKK.js → kotlin-zNWfDPVY.js} +2 -2
  173. package/dist/web/assets/{markdown-_2_uVr2L.js → markdown-ewV-vLcZ.js} +2 -2
  174. package/dist/web/assets/{markup-BVZ8HhdW.js → markup-D2krQlDZ.js} +2 -2
  175. package/dist/web/assets/{markup-templating-BDIRuVJH.js → markup-templating-c_XBo6vX.js} +2 -2
  176. package/dist/web/assets/mf-entry-bootstrap-0-3ede9334.js +36 -0
  177. package/dist/web/assets/mf-entry-bootstrap-1-3da85eea.js +36 -0
  178. package/dist/web/assets/{mf-entry-bootstrap-0-659c976f.js → mf-entry-bootstrap-2-32e24e11.js} +3 -2
  179. package/dist/web/assets/mf-entry-bootstrap-3-a3cfea9d.js +36 -0
  180. package/dist/web/assets/{models-BpslIbU7.js → models-BcPOQC5p.js} +4 -5
  181. package/dist/web/assets/{models-CKab4MTC.js → models-BcUgOGGn.js} +11 -6
  182. package/dist/web/assets/{objectivec-DPgB68It.js → objectivec-PkUOhxeb.js} +2 -2
  183. package/dist/web/assets/{php-JTON0zp9.js → php-CfWLJZIj.js} +2 -2
  184. package/dist/web/assets/{plugin-definition-8Exesd6T.js → plugin-definition-D1EImXIf.js} +9 -10
  185. package/dist/web/assets/plugin-definition-lw-gB4hU.js +10 -0
  186. package/dist/web/assets/{rolldown-runtime-FZ4Itg2g.js → rolldown-runtime-7_rZTKki.js} +1 -1
  187. package/dist/web/assets/{ruby-BoFHz67P.js → ruby-BlM93DKO.js} +2 -2
  188. package/dist/web/assets/{styles-Cc26Bbxc.css → styles-DIj1cIPB.css} +119 -1
  189. package/dist/web/assets/{styles-Cuq4wgvD.js → styles-EOyEbGA4.js} +9 -10
  190. package/dist/web/assets/{typescript-CDkIWcT8.js → typescript-C5BVqltI.js} +2 -2
  191. package/dist/web/assets/{virtualExposes-BwIds34r.js → virtualExposes-DWORnjyA.js} +1 -1
  192. package/dist/web/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__plugin-auth__remoteEntry_js-t-KnBiUh.js +747 -0
  193. package/dist/web/assets/{virtual_mf-exposes___mfe_internal__plugin-auth__remoteEntry_js-DM6Ir1_S.js → virtual_mf-exposes___mfe_internal__plugin-auth__remoteEntry_js-DZfE3QCR.js} +15 -15
  194. package/dist/web/assets/{vite-preload-helper-iIio8xkS.js → vite-preload-helper-ARKYL6bp.js} +5 -1
  195. package/dist/web/assets/{web-DHv2aVpi.js → web-CBVepebK.js} +24 -24
  196. package/dist/web/assets/{web-CnB-sqCR.js → web-Dgb85jhs.js} +54 -53
  197. package/dist/web/assets/{web-BZd3bM0n.js → web-EDeSquSP.js} +38 -38
  198. package/dist/web/assets/{web-DNrWXjpS.js → web-PqAcfBSy.js} +9 -9
  199. package/dist/web/assets/{web-BgWG7dYl.js → web-RhChfBw_.js} +23 -23
  200. package/dist/web/assets/web-kaD9AzNS.js +59 -0
  201. package/dist/web/assets/web-xJ-GnSkC.js +148 -0
  202. package/dist/web/assets/{workerBundle-GFUata9j.js → workerBundle-BjsY-uXx.js} +2 -2
  203. package/dist/web/index.html +5 -2
  204. package/dist/web/remoteEntry.js +1 -1
  205. package/package.json +36 -39
  206. package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib__loadShare__.js-BfSk5vRC.js +0 -384
  207. package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare___mf_0_baseplate_mf_2_dev_mf_1_project_mf_2_builder_mf_2_lib_mf_1_web__loadShare__.js-DZIcwf2B.js +0 -125
  208. package/dist/web/assets/_virtual_mf___mfe_internal__plugin_mf_2_auth__loadShare__zod__loadShare__.js-Do-7VDVw.js +0 -13567
  209. package/dist/web/assets/auth-8qJtXAgU.js +0 -1
  210. package/dist/web/assets/common-23-wvKrM.js +0 -39
  211. package/dist/web/assets/common-B-NI9TR-.js +0 -37
  212. package/dist/web/assets/common-DBBUvtGu.js +0 -37
  213. package/dist/web/assets/index-qso1IsKy.js +0 -2
  214. package/dist/web/assets/model-utils-dNFTOjqi.js +0 -1599
  215. package/dist/web/assets/plugin-definition-ChBrbazJ.js +0 -11
  216. package/dist/web/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__plugin-auth__remoteEntry_js-BBt5f0I7.js +0 -259
  217. package/dist/web/assets/virtual_mf-exposes-ssr___mfe_internal__plugin-auth__remoteEntry_js-RzPgl37a.js +0 -129
  218. package/dist/web/assets/web-CXHw8SK7.js +0 -118
  219. package/dist/web/assets/web-D_H-MoGI.js +0 -46
  220. package/dist/web/remoteEntry.ssr.js +0 -43
@@ -1,6 +1,7 @@
1
1
  export declare const authModuleGenerator: import("@baseplate-dev/sync").GeneratorBundleCreator<{
2
2
  userAdminRoles?: string[] | undefined;
3
3
  devWebPorts?: number[] | undefined;
4
+ emailOtp?: boolean | undefined;
4
5
  }, {
5
6
  paths: import("@baseplate-dev/sync").GeneratorTask<{
6
7
  localAuthCoreAuthModulePaths: import("@baseplate-dev/sync").ProviderExport<import("./generated/template-paths.js").LocalAuthCoreAuthModulePaths>;
@@ -12,10 +13,13 @@ export declare const authModuleGenerator: import("@baseplate-dev/sync").Generato
12
13
  cleanupAuthVerificationQueue: {};
13
14
  cleanupAuthVerificationWorker: {};
14
15
  cleanupExpiredAuthVerifications: {};
16
+ consumeCodeVerification: {};
15
17
  CookieUserSessionService: {};
16
18
  createAuthVerification: {};
19
+ createCodeVerification: {};
17
20
  userSessionPayload: {};
18
21
  validateAuthVerification: {};
22
+ validateCodeVerification: {};
19
23
  }>>;
20
24
  }, {
21
25
  paths: import("@baseplate-dev/sync").ProviderType<import("./generated/template-paths.js").LocalAuthCoreAuthModulePaths>;
@@ -85,6 +89,10 @@ export declare const authModuleGenerator: import("@baseplate-dev/sync").Generato
85
89
  EnqueueOptions: {
86
90
  isTypeOnly: true;
87
91
  };
92
+ hasFinalAttemptFailureHandler: {};
93
+ QueueFinalAttemptFailureHandler: {
94
+ isTypeOnly: true;
95
+ };
88
96
  QueueHandlerBinding: {
89
97
  isTypeOnly: true;
90
98
  };
@@ -8,12 +8,13 @@ import { LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED as GENERATED_TEMPLATES } from './
8
8
  const descriptorSchema = z.object({
9
9
  userAdminRoles: z.array(z.string()).default([]),
10
10
  devWebPorts: z.array(z.number()).default([]),
11
+ emailOtp: z.boolean().default(false),
11
12
  });
12
13
  export const authModuleGenerator = createGenerator({
13
14
  name: 'local-auth/core/auth-module',
14
15
  generatorFileUrl: import.meta.url,
15
16
  descriptorSchema,
16
- buildTasks: ({ userAdminRoles, devWebPorts }) => ({
17
+ buildTasks: ({ userAdminRoles, devWebPorts, emailOtp }) => ({
17
18
  paths: GENERATED_TEMPLATES.paths.task,
18
19
  imports: GENERATED_TEMPLATES.imports.task,
19
20
  renderers: GENERATED_TEMPLATES.renderers.task,
@@ -70,6 +71,9 @@ export const authModuleGenerator = createGenerator({
70
71
  },
71
72
  }));
72
73
  await builder.apply(renderers.servicesAuthVerification.render({}));
74
+ if (emailOtp) {
75
+ await builder.apply(renderers.servicesCodeVerification.render({}));
76
+ }
73
77
  await builder.apply(renderers.constantsGroup.render({}));
74
78
  await builder.apply(renderers.utilsGroup.render({}));
75
79
  await builder.apply(renderers.moduleGroup.render({
@@ -5,10 +5,13 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED: {
5
5
  cleanupAuthVerificationQueue: {};
6
6
  cleanupAuthVerificationWorker: {};
7
7
  cleanupExpiredAuthVerifications: {};
8
+ consumeCodeVerification: {};
8
9
  CookieUserSessionService: {};
9
10
  createAuthVerification: {};
11
+ createCodeVerification: {};
10
12
  userSessionPayload: {};
11
13
  validateAuthVerification: {};
14
+ validateCodeVerification: {};
12
15
  }>>;
13
16
  }, {
14
17
  paths: import("@baseplate-dev/sync").ProviderType<import("./template-paths.js").LocalAuthCoreAuthModulePaths>;
@@ -89,6 +92,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED: {
89
92
  EnqueueOptions: {
90
93
  isTypeOnly: true;
91
94
  };
95
+ hasFinalAttemptFailureHandler: {};
96
+ QueueFinalAttemptFailureHandler: {
97
+ isTypeOnly: true;
98
+ };
92
99
  QueueHandlerBinding: {
93
100
  isTypeOnly: true;
94
101
  };
@@ -256,6 +263,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED: {
256
263
  EnqueueOptions: {
257
264
  isTypeOnly: true;
258
265
  };
266
+ hasFinalAttemptFailureHandler: {};
267
+ QueueFinalAttemptFailureHandler: {
268
+ isTypeOnly: true;
269
+ };
259
270
  QueueHandlerBinding: {
260
271
  isTypeOnly: true;
261
272
  };
@@ -311,6 +322,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED: {
311
322
  EnqueueOptions: {
312
323
  isTypeOnly: true;
313
324
  };
325
+ hasFinalAttemptFailureHandler: {};
326
+ QueueFinalAttemptFailureHandler: {
327
+ isTypeOnly: true;
328
+ };
314
329
  QueueHandlerBinding: {
315
330
  isTypeOnly: true;
316
331
  };
@@ -372,6 +387,23 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_GENERATED: {
372
387
  prisma: {};
373
388
  }>>;
374
389
  }, Record<never, Record<never, never>>>;
390
+ servicesCodeVerification: import("@baseplate-dev/core-generators").TsTemplateFile<{}, {
391
+ configServiceImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
392
+ getConfig: {};
393
+ isDevelopment: {};
394
+ }>>;
395
+ prismaGeneratedImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
396
+ PrismaClient: {};
397
+ Prisma: {};
398
+ '*': {};
399
+ $Enums: {};
400
+ }>>;
401
+ prismaImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
402
+ prisma: {};
403
+ }>>;
404
+ }, {
405
+ servicesAuthVerification: {};
406
+ }>;
375
407
  userSessionService: import("@baseplate-dev/core-generators").TsTemplateFile<{
376
408
  TPL_PRISMA_USER_SESSION: {};
377
409
  }, {
@@ -7,6 +7,7 @@ export interface LocalAuthCoreAuthModulePaths {
7
7
  schemaUserSessionPayloadObjectType: string;
8
8
  schemaUserSessionQueries: string;
9
9
  servicesAuthVerification: string;
10
+ servicesCodeVerification: string;
10
11
  sessionCookie: string;
11
12
  userRolesMutations: string;
12
13
  userRolesService: string;
@@ -19,6 +19,7 @@ const localAuthCoreAuthModulePathsTask = createGeneratorTask({
19
19
  schemaUserSessionPayloadObjectType: `${moduleRoot}/schema/user-session-payload.object-type.ts`,
20
20
  schemaUserSessionQueries: `${moduleRoot}/schema/user-session.queries.ts`,
21
21
  servicesAuthVerification: `${moduleRoot}/services/auth-verification.service.ts`,
22
+ servicesCodeVerification: `${moduleRoot}/services/code-verification.service.ts`,
22
23
  sessionCookie: `${moduleRoot}/utils/session-cookie.ts`,
23
24
  userRolesMutations: `${moduleRoot}/schema/user-roles.mutations.ts`,
24
25
  userRolesService: `${moduleRoot}/services/user-roles.service.ts`,
@@ -17,6 +17,9 @@ export interface LocalAuthCoreAuthModuleRenderers {
17
17
  servicesAuthVerification: {
18
18
  render: (options: Omit<RenderTsTemplateFileActionInput<typeof LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES.servicesAuthVerification>, 'destination' | 'importMapProviders' | 'template' | 'generatorPaths'>) => BuilderAction;
19
19
  };
20
+ servicesCodeVerification: {
21
+ render: (options: Omit<RenderTsTemplateFileActionInput<typeof LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES.servicesCodeVerification>, 'destination' | 'importMapProviders' | 'template' | 'generatorPaths'>) => BuilderAction;
22
+ };
20
23
  userSessionService: {
21
24
  render: (options: Omit<RenderTsTemplateFileActionInput<typeof LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES.userSessionService>, 'destination' | 'importMapProviders' | 'template' | 'generatorPaths'>) => BuilderAction;
22
25
  };
@@ -91,6 +94,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_RENDERERS: {
91
94
  EnqueueOptions: {
92
95
  isTypeOnly: true;
93
96
  };
97
+ hasFinalAttemptFailureHandler: {};
98
+ QueueFinalAttemptFailureHandler: {
99
+ isTypeOnly: true;
100
+ };
94
101
  QueueHandlerBinding: {
95
102
  isTypeOnly: true;
96
103
  };
@@ -81,6 +81,19 @@ const localAuthCoreAuthModuleRenderersTask = createGeneratorTask({
81
81
  ...options,
82
82
  }),
83
83
  },
84
+ servicesCodeVerification: {
85
+ render: (options) => typescriptFile.renderTemplateFile({
86
+ template: LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES.servicesCodeVerification,
87
+ destination: paths.servicesCodeVerification,
88
+ importMapProviders: {
89
+ configServiceImports,
90
+ prismaGeneratedImports,
91
+ prismaImports,
92
+ },
93
+ generatorPaths: paths,
94
+ ...options,
95
+ }),
96
+ },
84
97
  userSessionService: {
85
98
  render: (options) => typescriptFile.renderTemplateFile({
86
99
  template: LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES.userSessionService,
@@ -3,20 +3,26 @@ export declare const authModuleImportsSchema: {
3
3
  cleanupAuthVerificationQueue: {};
4
4
  cleanupAuthVerificationWorker: {};
5
5
  cleanupExpiredAuthVerifications: {};
6
+ consumeCodeVerification: {};
6
7
  CookieUserSessionService: {};
7
8
  createAuthVerification: {};
9
+ createCodeVerification: {};
8
10
  userSessionPayload: {};
9
11
  validateAuthVerification: {};
12
+ validateCodeVerification: {};
10
13
  };
11
14
  export type AuthModuleImportsProvider = TsImportMapProviderFromSchema<typeof authModuleImportsSchema>;
12
15
  export declare const authModuleImportsProvider: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
13
16
  cleanupAuthVerificationQueue: {};
14
17
  cleanupAuthVerificationWorker: {};
15
18
  cleanupExpiredAuthVerifications: {};
19
+ consumeCodeVerification: {};
16
20
  CookieUserSessionService: {};
17
21
  createAuthVerification: {};
22
+ createCodeVerification: {};
18
23
  userSessionPayload: {};
19
24
  validateAuthVerification: {};
25
+ validateCodeVerification: {};
20
26
  }>>;
21
27
  export declare const LOCAL_AUTH_CORE_AUTH_MODULE_IMPORTS: {
22
28
  task: import("@baseplate-dev/sync").GeneratorTask<{
@@ -24,10 +30,13 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_IMPORTS: {
24
30
  cleanupAuthVerificationQueue: {};
25
31
  cleanupAuthVerificationWorker: {};
26
32
  cleanupExpiredAuthVerifications: {};
33
+ consumeCodeVerification: {};
27
34
  CookieUserSessionService: {};
28
35
  createAuthVerification: {};
36
+ createCodeVerification: {};
29
37
  userSessionPayload: {};
30
38
  validateAuthVerification: {};
39
+ validateCodeVerification: {};
31
40
  }>>;
32
41
  }, {
33
42
  paths: import("@baseplate-dev/sync").ProviderType<import("./template-paths.js").LocalAuthCoreAuthModulePaths>;
@@ -5,10 +5,13 @@ export const authModuleImportsSchema = createTsImportMapSchema({
5
5
  cleanupAuthVerificationQueue: {},
6
6
  cleanupAuthVerificationWorker: {},
7
7
  cleanupExpiredAuthVerifications: {},
8
+ consumeCodeVerification: {},
8
9
  CookieUserSessionService: {},
9
10
  createAuthVerification: {},
11
+ createCodeVerification: {},
10
12
  userSessionPayload: {},
11
13
  validateAuthVerification: {},
14
+ validateCodeVerification: {},
12
15
  });
13
16
  export const authModuleImportsProvider = createReadOnlyProviderType('auth-module-imports');
14
17
  const localAuthCoreAuthModuleImportsTask = createGeneratorTask({
@@ -25,10 +28,13 @@ const localAuthCoreAuthModuleImportsTask = createGeneratorTask({
25
28
  cleanupAuthVerificationQueue: paths.queuesCleanupAuthVerification,
26
29
  cleanupAuthVerificationWorker: paths.queuesCleanupAuthVerificationWorker,
27
30
  cleanupExpiredAuthVerifications: paths.servicesAuthVerification,
31
+ consumeCodeVerification: paths.servicesCodeVerification,
28
32
  CookieUserSessionService: paths.userSessionService,
29
33
  createAuthVerification: paths.servicesAuthVerification,
34
+ createCodeVerification: paths.servicesCodeVerification,
30
35
  userSessionPayload: paths.schemaUserSessionPayloadObjectType,
31
36
  validateAuthVerification: paths.servicesAuthVerification,
37
+ validateCodeVerification: paths.servicesCodeVerification,
32
38
  }),
33
39
  },
34
40
  };
@@ -201,6 +201,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES: {
201
201
  EnqueueOptions: {
202
202
  isTypeOnly: true;
203
203
  };
204
+ hasFinalAttemptFailureHandler: {};
205
+ QueueFinalAttemptFailureHandler: {
206
+ isTypeOnly: true;
207
+ };
204
208
  QueueHandlerBinding: {
205
209
  isTypeOnly: true;
206
210
  };
@@ -256,6 +260,10 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES: {
256
260
  EnqueueOptions: {
257
261
  isTypeOnly: true;
258
262
  };
263
+ hasFinalAttemptFailureHandler: {};
264
+ QueueFinalAttemptFailureHandler: {
265
+ isTypeOnly: true;
266
+ };
259
267
  QueueHandlerBinding: {
260
268
  isTypeOnly: true;
261
269
  };
@@ -317,6 +325,23 @@ export declare const LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES: {
317
325
  prisma: {};
318
326
  }>>;
319
327
  }, Record<never, Record<never, never>>>;
328
+ servicesCodeVerification: import("@baseplate-dev/core-generators").TsTemplateFile<{}, {
329
+ configServiceImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
330
+ getConfig: {};
331
+ isDevelopment: {};
332
+ }>>;
333
+ prismaGeneratedImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
334
+ PrismaClient: {};
335
+ Prisma: {};
336
+ '*': {};
337
+ $Enums: {};
338
+ }>>;
339
+ prismaImports: import("@baseplate-dev/sync").ProviderType<import("@baseplate-dev/core-generators").InferTsImportMapFromSchema<{
340
+ prisma: {};
341
+ }>>;
342
+ }, {
343
+ servicesAuthVerification: {};
344
+ }>;
320
345
  userSessionService: import("@baseplate-dev/core-generators").TsTemplateFile<{
321
346
  TPL_PRISMA_USER_SESSION: {};
322
347
  }, {
@@ -140,6 +140,25 @@ const servicesAuthVerification = createTsTemplateFile({
140
140
  },
141
141
  variables: {},
142
142
  });
143
+ const servicesCodeVerification = createTsTemplateFile({
144
+ fileOptions: { kind: 'singleton' },
145
+ importMapProviders: {
146
+ configServiceImports: configServiceImportsProvider,
147
+ prismaGeneratedImports: prismaGeneratedImportsProvider,
148
+ prismaImports: prismaImportsProvider,
149
+ },
150
+ name: 'services-code-verification',
151
+ projectExports: {
152
+ consumeCodeVerification: { isTypeOnly: false },
153
+ createCodeVerification: { isTypeOnly: false },
154
+ validateCodeVerification: { isTypeOnly: false },
155
+ },
156
+ referencedGeneratorTemplates: { servicesAuthVerification: {} },
157
+ source: {
158
+ path: path.join(import.meta.dirname, '../templates/module/services/code-verification.service.ts'),
159
+ },
160
+ variables: {},
161
+ });
143
162
  const userSessionService = createTsTemplateFile({
144
163
  fileOptions: { kind: 'singleton' },
145
164
  importMapProviders: {
@@ -201,6 +220,7 @@ export const LOCAL_AUTH_CORE_AUTH_MODULE_TEMPLATES = {
201
220
  queuesCleanupAuthVerification,
202
221
  queuesCleanupAuthVerificationWorker,
203
222
  servicesAuthVerification,
223
+ servicesCodeVerification,
204
224
  userSessionService,
205
225
  utilsGroup,
206
226
  };
@@ -1,4 +1,8 @@
1
1
  import type { AuthVerification, Prisma } from '%prismaGeneratedImports';
2
+ /**
3
+ * Constant-time comparison of two hex strings to prevent timing attacks.
4
+ */
5
+ export declare function safeCompare(a: string, b: string): boolean;
2
6
  /**
3
7
  * Creates a new auth verification using the split-token pattern.
4
8
  *
@@ -20,7 +20,7 @@ function hashVerifier(verifier) {
20
20
  /**
21
21
  * Constant-time comparison of two hex strings to prevent timing attacks.
22
22
  */
23
- function safeCompare(a, b) {
23
+ export function safeCompare(a, b) {
24
24
  if (a.length !== b.length)
25
25
  return false;
26
26
  return crypto.timingSafeEqual(Buffer.from(a, 'hex'), Buffer.from(b, 'hex'));
@@ -27,7 +27,7 @@ function hashVerifier(verifier: string): string {
27
27
  /**
28
28
  * Constant-time comparison of two hex strings to prevent timing attacks.
29
29
  */
30
- function safeCompare(a: string, b: string): boolean {
30
+ export function safeCompare(a: string, b: string): boolean {
31
31
  if (a.length !== b.length) return false;
32
32
  return crypto.timingSafeEqual(Buffer.from(a, 'hex'), Buffer.from(b, 'hex'));
33
33
  }
@@ -0,0 +1,66 @@
1
+ import type { AuthVerification, Prisma } from '%prismaGeneratedImports';
2
+ /**
3
+ * Creates or replaces a short code verification (e.g. an emailed OTP).
4
+ *
5
+ * The identifier is caller-supplied (typically an email) rather than a random
6
+ * selector, so the code cannot be folded into a single token the way a
7
+ * split-token flow does. Only one code may be outstanding per
8
+ * `type`/`identifier` pair, so requesting a new one replaces any existing code
9
+ * and resets the attempt counter.
10
+ *
11
+ * The identifier rather than a user reference is the subject here, since a
12
+ * code may be issued for an address that has no account yet.
13
+ *
14
+ * The returned id identifies this particular issuance, so a caller that binds
15
+ * it to the requester (e.g. in a cookie) can tell one request apart from the
16
+ * next. It is regenerated on every call for that reason: reusing it would let
17
+ * whoever requested an earlier code redeem a later one requested by someone
18
+ * else.
19
+ *
20
+ * @param code - The plaintext code sent to the user; only its hash is stored
21
+ */
22
+ export declare function createCodeVerification({ type, identifier, code, expiresInSec, }: {
23
+ type: string;
24
+ identifier: string;
25
+ code: string;
26
+ expiresInSec: number;
27
+ }): Promise<{
28
+ id: string;
29
+ }>;
30
+ /**
31
+ * Validates a short code verification without consuming it, so the caller can
32
+ * gather any further input it needs before committing.
33
+ *
34
+ * Security: a short numeric code has far less entropy than a random token, so
35
+ * each code carries its own attempt counter alongside the endpoint rate limits.
36
+ * The record is deleted when the code has expired or the attempt budget is
37
+ * exhausted. Pass the returned record to {@link consumeCodeVerification} to
38
+ * complete the flow.
39
+ *
40
+ * Both cleanup paths delete by filter rather than by primary key: simultaneous
41
+ * callers can each decide the record should go, and only one of them removes a
42
+ * row. A keyed delete would raise on the others instead of returning null.
43
+ */
44
+ export declare function validateCodeVerification({ type, identifier, code, maxAttempts, }: {
45
+ type: string;
46
+ identifier: string;
47
+ code: string;
48
+ maxAttempts: number;
49
+ }): Promise<AuthVerification | null>;
50
+ /**
51
+ * Consumes a previously validated verification, returning whether this call is
52
+ * the one that claimed it.
53
+ *
54
+ * The conditional delete is the authorization step: concurrent requests
55
+ * carrying the same code race here, and only the request that removes the row
56
+ * may proceed. Reading the row and deleting it in separate statements would
57
+ * let both win.
58
+ *
59
+ * @param client - Transaction client, so consuming the code can be committed
60
+ * together with whatever the code authorized rather than ahead of it
61
+ */
62
+ export declare function consumeCodeVerification({ id, client, }: {
63
+ id: string;
64
+ client?: Prisma.TransactionClient;
65
+ }): Promise<boolean>;
66
+ //# sourceMappingURL=code-verification.service.d.ts.map
@@ -0,0 +1,134 @@
1
+ // @ts-nocheck
2
+ import { safeCompare } from '$servicesAuthVerification';
3
+ import { getConfig } from '%configServiceImports';
4
+ import { prisma } from '%prismaImports';
5
+ import * as crypto from 'node:crypto';
6
+ /**
7
+ * Short code verifications, for flows that email a handful of digits rather
8
+ * than a link.
9
+ *
10
+ * These share the `AuthVerification` table with the split-token flows in
11
+ * {@link ./auth-verification.service.js} but not their security model: the
12
+ * secret is short enough to guess, so it is keyed rather than hashed, carries
13
+ * its own attempt budget, and is addressed by a caller-supplied identifier
14
+ * instead of a random selector.
15
+ */
16
+ /**
17
+ * Derives the stored value for a short code.
18
+ *
19
+ * Short codes occupy a keyspace small enough to invert a plain digest by
20
+ * exhaustive search, so they are keyed with the server secret rather than
21
+ * hashed: an attacker holding only the database cannot recover them. The type
22
+ * and identifier are mixed in so a stored value is valid solely for the flow
23
+ * and address it was issued for.
24
+ */
25
+ function hashCode({ type, identifier, code, }) {
26
+ return crypto
27
+ .createHmac('sha256', getConfig().AUTH_SECRET)
28
+ .update(`${type}:${identifier}:${code}`)
29
+ .digest('hex');
30
+ }
31
+ /**
32
+ * Creates or replaces a short code verification (e.g. an emailed OTP).
33
+ *
34
+ * The identifier is caller-supplied (typically an email) rather than a random
35
+ * selector, so the code cannot be folded into a single token the way a
36
+ * split-token flow does. Only one code may be outstanding per
37
+ * `type`/`identifier` pair, so requesting a new one replaces any existing code
38
+ * and resets the attempt counter.
39
+ *
40
+ * The identifier rather than a user reference is the subject here, since a
41
+ * code may be issued for an address that has no account yet.
42
+ *
43
+ * The returned id identifies this particular issuance, so a caller that binds
44
+ * it to the requester (e.g. in a cookie) can tell one request apart from the
45
+ * next. It is regenerated on every call for that reason: reusing it would let
46
+ * whoever requested an earlier code redeem a later one requested by someone
47
+ * else.
48
+ *
49
+ * @param code - The plaintext code sent to the user; only its hash is stored
50
+ */
51
+ export async function createCodeVerification({ type, identifier, code, expiresInSec, }) {
52
+ const value = hashCode({ type, identifier, code });
53
+ const expiresAt = new Date(Date.now() + expiresInSec * 1000);
54
+ const id = crypto.randomUUID();
55
+ await prisma.authVerification.upsert({
56
+ where: { type_identifier: { type, identifier } },
57
+ create: {
58
+ id,
59
+ type,
60
+ identifier,
61
+ value,
62
+ expiresAt,
63
+ },
64
+ // Resetting `attempts` is what gives the replacement code a fresh budget;
65
+ // without it a reissued code would inherit the old code's failed guesses.
66
+ update: {
67
+ id,
68
+ value,
69
+ attempts: 0,
70
+ expiresAt,
71
+ },
72
+ select: { id: true },
73
+ });
74
+ return { id };
75
+ }
76
+ /**
77
+ * Validates a short code verification without consuming it, so the caller can
78
+ * gather any further input it needs before committing.
79
+ *
80
+ * Security: a short numeric code has far less entropy than a random token, so
81
+ * each code carries its own attempt counter alongside the endpoint rate limits.
82
+ * The record is deleted when the code has expired or the attempt budget is
83
+ * exhausted. Pass the returned record to {@link consumeCodeVerification} to
84
+ * complete the flow.
85
+ *
86
+ * Both cleanup paths delete by filter rather than by primary key: simultaneous
87
+ * callers can each decide the record should go, and only one of them removes a
88
+ * row. A keyed delete would raise on the others instead of returning null.
89
+ */
90
+ export async function validateCodeVerification({ type, identifier, code, maxAttempts, }) {
91
+ const record = await prisma.authVerification.findUnique({
92
+ where: { type_identifier: { type, identifier } },
93
+ });
94
+ if (!record) {
95
+ return null;
96
+ }
97
+ if (record.expiresAt < new Date()) {
98
+ await prisma.authVerification.deleteMany({ where: { id: record.id } });
99
+ return null;
100
+ }
101
+ if (safeCompare(record.value, hashCode({ type, identifier, code }))) {
102
+ return record;
103
+ }
104
+ // Incremented in the database rather than read-modify-written here, so
105
+ // simultaneous guesses each cost a point instead of sharing one.
106
+ const { attempts } = await prisma.authVerification.update({
107
+ where: { id: record.id },
108
+ data: { attempts: { increment: 1 } },
109
+ select: { attempts: true },
110
+ });
111
+ if (attempts >= maxAttempts) {
112
+ await prisma.authVerification.deleteMany({ where: { id: record.id } });
113
+ }
114
+ return null;
115
+ }
116
+ /**
117
+ * Consumes a previously validated verification, returning whether this call is
118
+ * the one that claimed it.
119
+ *
120
+ * The conditional delete is the authorization step: concurrent requests
121
+ * carrying the same code race here, and only the request that removes the row
122
+ * may proceed. Reading the row and deleting it in separate statements would
123
+ * let both win.
124
+ *
125
+ * @param client - Transaction client, so consuming the code can be committed
126
+ * together with whatever the code authorized rather than ahead of it
127
+ */
128
+ export async function consumeCodeVerification({ id, client = prisma, }) {
129
+ const { count } = await client.authVerification.deleteMany({
130
+ where: { id },
131
+ });
132
+ return count === 1;
133
+ }
134
+ //# sourceMappingURL=code-verification.service.js.map