@axium/server 0.26.0 → 0.26.2

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 (258) hide show
  1. package/dist/api/acl.js +2 -4
  2. package/dist/cli.js +1 -1
  3. package/dist/config.d.ts +2 -0
  4. package/dist/config.js +5 -1
  5. package/dist/internal_requests.js +1 -1
  6. package/package.json +2 -3
  7. package/build/client/_app/immutable/assets/account.dAAx7bby.css +0 -1
  8. package/build/client/_app/immutable/assets/account.dAAx7bby.css.br +0 -0
  9. package/build/client/_app/immutable/assets/account.dAAx7bby.css.gz +0 -0
  10. package/build/client/_app/immutable/assets/list.DVGH0BeP.css +0 -1
  11. package/build/client/_app/immutable/assets/list.DVGH0BeP.css.br +0 -0
  12. package/build/client/_app/immutable/assets/list.DVGH0BeP.css.gz +0 -0
  13. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css +0 -1
  14. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css.br +0 -2
  15. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css.gz +0 -0
  16. package/build/client/_app/immutable/chunks/46qGscyh.js +0 -2
  17. package/build/client/_app/immutable/chunks/46qGscyh.js.br +0 -0
  18. package/build/client/_app/immutable/chunks/46qGscyh.js.gz +0 -0
  19. package/build/client/_app/immutable/chunks/B2Vkpbkw.js +0 -2
  20. package/build/client/_app/immutable/chunks/B2Vkpbkw.js.br +0 -0
  21. package/build/client/_app/immutable/chunks/B2Vkpbkw.js.gz +0 -0
  22. package/build/client/_app/immutable/chunks/BKixenYx.js +0 -1
  23. package/build/client/_app/immutable/chunks/BKixenYx.js.br +0 -0
  24. package/build/client/_app/immutable/chunks/BKixenYx.js.gz +0 -0
  25. package/build/client/_app/immutable/chunks/BLtAtlP3.js +0 -1
  26. package/build/client/_app/immutable/chunks/BLtAtlP3.js.br +0 -2
  27. package/build/client/_app/immutable/chunks/BLtAtlP3.js.gz +0 -0
  28. package/build/client/_app/immutable/chunks/BNTlty5m.js +0 -1
  29. package/build/client/_app/immutable/chunks/BNTlty5m.js.br +0 -0
  30. package/build/client/_app/immutable/chunks/BNTlty5m.js.gz +0 -0
  31. package/build/client/_app/immutable/chunks/Beh6Ec8J.js +0 -1
  32. package/build/client/_app/immutable/chunks/Beh6Ec8J.js.br +0 -0
  33. package/build/client/_app/immutable/chunks/Beh6Ec8J.js.gz +0 -0
  34. package/build/client/_app/immutable/chunks/BrUe-Qen.js +0 -1
  35. package/build/client/_app/immutable/chunks/BrUe-Qen.js.br +0 -0
  36. package/build/client/_app/immutable/chunks/BrUe-Qen.js.gz +0 -0
  37. package/build/client/_app/immutable/chunks/Bs4cD_pX.js +0 -1
  38. package/build/client/_app/immutable/chunks/Bs4cD_pX.js.br +0 -0
  39. package/build/client/_app/immutable/chunks/Bs4cD_pX.js.gz +0 -0
  40. package/build/client/_app/immutable/chunks/C62F-tXu.js +0 -1
  41. package/build/client/_app/immutable/chunks/C62F-tXu.js.br +0 -1
  42. package/build/client/_app/immutable/chunks/C62F-tXu.js.gz +0 -0
  43. package/build/client/_app/immutable/chunks/CUBtP2L9.js +0 -23
  44. package/build/client/_app/immutable/chunks/CUBtP2L9.js.br +0 -0
  45. package/build/client/_app/immutable/chunks/CUBtP2L9.js.gz +0 -0
  46. package/build/client/_app/immutable/chunks/Ch16TNvP.js +0 -1
  47. package/build/client/_app/immutable/chunks/Ch16TNvP.js.br +0 -0
  48. package/build/client/_app/immutable/chunks/Ch16TNvP.js.gz +0 -0
  49. package/build/client/_app/immutable/chunks/CoYD6HNm.js +0 -1
  50. package/build/client/_app/immutable/chunks/CoYD6HNm.js.br +0 -0
  51. package/build/client/_app/immutable/chunks/CoYD6HNm.js.gz +0 -0
  52. package/build/client/_app/immutable/chunks/D40Zn55h.js +0 -1
  53. package/build/client/_app/immutable/chunks/D40Zn55h.js.br +0 -0
  54. package/build/client/_app/immutable/chunks/D40Zn55h.js.gz +0 -0
  55. package/build/client/_app/immutable/chunks/DW7-1esk.js +0 -21
  56. package/build/client/_app/immutable/chunks/DW7-1esk.js.br +0 -0
  57. package/build/client/_app/immutable/chunks/DW7-1esk.js.gz +0 -0
  58. package/build/client/_app/immutable/chunks/DY4fWHx_.js +0 -1
  59. package/build/client/_app/immutable/chunks/DY4fWHx_.js.br +0 -0
  60. package/build/client/_app/immutable/chunks/DY4fWHx_.js.gz +0 -0
  61. package/build/client/_app/immutable/chunks/DvOBbqVY.js +0 -1
  62. package/build/client/_app/immutable/chunks/DvOBbqVY.js.br +0 -0
  63. package/build/client/_app/immutable/chunks/DvOBbqVY.js.gz +0 -0
  64. package/build/client/_app/immutable/chunks/DwZYWemd.js +0 -1
  65. package/build/client/_app/immutable/chunks/DwZYWemd.js.br +0 -0
  66. package/build/client/_app/immutable/chunks/DwZYWemd.js.gz +0 -0
  67. package/build/client/_app/immutable/chunks/Dy2Ho0cF.js +0 -1
  68. package/build/client/_app/immutable/chunks/Dy2Ho0cF.js.br +0 -0
  69. package/build/client/_app/immutable/chunks/Dy2Ho0cF.js.gz +0 -0
  70. package/build/client/_app/immutable/chunks/FTv0qR3w.js +0 -1
  71. package/build/client/_app/immutable/chunks/FTv0qR3w.js.br +0 -0
  72. package/build/client/_app/immutable/chunks/FTv0qR3w.js.gz +0 -0
  73. package/build/client/_app/immutable/chunks/NeK0YGoY.js +0 -1
  74. package/build/client/_app/immutable/chunks/NeK0YGoY.js.br +0 -0
  75. package/build/client/_app/immutable/chunks/NeK0YGoY.js.gz +0 -0
  76. package/build/client/_app/immutable/chunks/aArGsq9c.js +0 -1
  77. package/build/client/_app/immutable/chunks/aArGsq9c.js.br +0 -0
  78. package/build/client/_app/immutable/chunks/aArGsq9c.js.gz +0 -0
  79. package/build/client/_app/immutable/chunks/lH47zGKU.js +0 -1
  80. package/build/client/_app/immutable/chunks/lH47zGKU.js.br +0 -0
  81. package/build/client/_app/immutable/chunks/lH47zGKU.js.gz +0 -0
  82. package/build/client/_app/immutable/chunks/sMHjBQqw.js +0 -1
  83. package/build/client/_app/immutable/chunks/sMHjBQqw.js.br +0 -0
  84. package/build/client/_app/immutable/chunks/sMHjBQqw.js.gz +0 -0
  85. package/build/client/_app/immutable/chunks/vQfHcJV6.js +0 -2
  86. package/build/client/_app/immutable/chunks/vQfHcJV6.js.br +0 -0
  87. package/build/client/_app/immutable/chunks/vQfHcJV6.js.gz +0 -0
  88. package/build/client/_app/immutable/entry/app.pLVZKpSD.js +0 -2
  89. package/build/client/_app/immutable/entry/app.pLVZKpSD.js.br +0 -0
  90. package/build/client/_app/immutable/entry/app.pLVZKpSD.js.gz +0 -0
  91. package/build/client/_app/immutable/entry/start.CUaVsIrY.js +0 -1
  92. package/build/client/_app/immutable/entry/start.CUaVsIrY.js.br +0 -2
  93. package/build/client/_app/immutable/entry/start.CUaVsIrY.js.gz +0 -0
  94. package/build/client/_app/immutable/nodes/0.D7hET-Bq.js +0 -1
  95. package/build/client/_app/immutable/nodes/0.D7hET-Bq.js.br +0 -0
  96. package/build/client/_app/immutable/nodes/0.D7hET-Bq.js.gz +0 -0
  97. package/build/client/_app/immutable/nodes/1.BWU-JJm_.js +0 -1
  98. package/build/client/_app/immutable/nodes/1.BWU-JJm_.js.br +0 -2
  99. package/build/client/_app/immutable/nodes/1.BWU-JJm_.js.gz +0 -0
  100. package/build/client/_app/immutable/nodes/10.C5N2XBee.js +0 -1
  101. package/build/client/_app/immutable/nodes/10.C5N2XBee.js.br +0 -0
  102. package/build/client/_app/immutable/nodes/10.C5N2XBee.js.gz +0 -0
  103. package/build/client/_app/immutable/nodes/11.CerbuSAv.js +0 -1
  104. package/build/client/_app/immutable/nodes/11.CerbuSAv.js.br +0 -0
  105. package/build/client/_app/immutable/nodes/11.CerbuSAv.js.gz +0 -0
  106. package/build/client/_app/immutable/nodes/12.Z4B9zS78.js +0 -1
  107. package/build/client/_app/immutable/nodes/12.Z4B9zS78.js.br +0 -0
  108. package/build/client/_app/immutable/nodes/12.Z4B9zS78.js.gz +0 -0
  109. package/build/client/_app/immutable/nodes/13.CuICShck.js +0 -1
  110. package/build/client/_app/immutable/nodes/13.CuICShck.js.br +0 -0
  111. package/build/client/_app/immutable/nodes/13.CuICShck.js.gz +0 -0
  112. package/build/client/_app/immutable/nodes/14.BSEF5oaF.js +0 -1
  113. package/build/client/_app/immutable/nodes/14.BSEF5oaF.js.br +0 -0
  114. package/build/client/_app/immutable/nodes/14.BSEF5oaF.js.gz +0 -0
  115. package/build/client/_app/immutable/nodes/15.D1nsmo6j.js +0 -1
  116. package/build/client/_app/immutable/nodes/15.D1nsmo6j.js.br +0 -0
  117. package/build/client/_app/immutable/nodes/15.D1nsmo6j.js.gz +0 -0
  118. package/build/client/_app/immutable/nodes/2.DQ1JcYgz.js +0 -1
  119. package/build/client/_app/immutable/nodes/2.DQ1JcYgz.js.br +0 -0
  120. package/build/client/_app/immutable/nodes/2.DQ1JcYgz.js.gz +0 -0
  121. package/build/client/_app/immutable/nodes/3.BJp2JEtW.js +0 -1
  122. package/build/client/_app/immutable/nodes/3.BJp2JEtW.js.br +0 -0
  123. package/build/client/_app/immutable/nodes/3.BJp2JEtW.js.gz +0 -0
  124. package/build/client/_app/immutable/nodes/4.Cvn_QsIx.js +0 -1
  125. package/build/client/_app/immutable/nodes/4.Cvn_QsIx.js.br +0 -0
  126. package/build/client/_app/immutable/nodes/4.Cvn_QsIx.js.gz +0 -0
  127. package/build/client/_app/immutable/nodes/5.DgPP9GX3.js +0 -1
  128. package/build/client/_app/immutable/nodes/5.DgPP9GX3.js.br +0 -0
  129. package/build/client/_app/immutable/nodes/5.DgPP9GX3.js.gz +0 -0
  130. package/build/client/_app/immutable/nodes/6.DKIzms8i.js +0 -2
  131. package/build/client/_app/immutable/nodes/6.DKIzms8i.js.br +0 -0
  132. package/build/client/_app/immutable/nodes/6.DKIzms8i.js.gz +0 -0
  133. package/build/client/_app/immutable/nodes/7.3UigVXV4.js +0 -1
  134. package/build/client/_app/immutable/nodes/7.3UigVXV4.js.br +0 -0
  135. package/build/client/_app/immutable/nodes/7.3UigVXV4.js.gz +0 -0
  136. package/build/client/_app/immutable/nodes/8.B8s2TdNQ.js +0 -1
  137. package/build/client/_app/immutable/nodes/8.B8s2TdNQ.js.br +0 -0
  138. package/build/client/_app/immutable/nodes/8.B8s2TdNQ.js.gz +0 -0
  139. package/build/client/_app/immutable/nodes/9.LBMMe2kc.js +0 -1
  140. package/build/client/_app/immutable/nodes/9.LBMMe2kc.js.br +0 -0
  141. package/build/client/_app/immutable/nodes/9.LBMMe2kc.js.gz +0 -0
  142. package/build/client/_app/version.json +0 -1
  143. package/build/client/_app/version.json.br +0 -0
  144. package/build/client/_app/version.json.gz +0 -0
  145. package/build/client/icons/brands.svg +0 -1493
  146. package/build/client/icons/brands.svg.br +0 -0
  147. package/build/client/icons/brands.svg.gz +0 -0
  148. package/build/client/icons/light.svg +0 -9977
  149. package/build/client/icons/light.svg.br +0 -0
  150. package/build/client/icons/light.svg.gz +0 -0
  151. package/build/client/icons/regular.svg +0 -9977
  152. package/build/client/icons/regular.svg.br +0 -0
  153. package/build/client/icons/regular.svg.gz +0 -0
  154. package/build/client/icons/solid.svg +0 -9977
  155. package/build/client/icons/solid.svg.br +0 -0
  156. package/build/client/icons/solid.svg.gz +0 -0
  157. package/build/client/styles.css +0 -168
  158. package/build/client/styles.css.br +0 -0
  159. package/build/client/styles.css.gz +0 -0
  160. package/build/client/theme.css +0 -42
  161. package/build/client/theme.css.br +0 -0
  162. package/build/client/theme.css.gz +0 -0
  163. package/build/env.js +0 -45
  164. package/build/handler.js +0 -1390
  165. package/build/index.js +0 -334
  166. package/build/server/chunks/0-CNbALTKz.js +0 -9
  167. package/build/server/chunks/0-CNbALTKz.js.map +0 -1
  168. package/build/server/chunks/1-Dgxy393u.js +0 -9
  169. package/build/server/chunks/1-Dgxy393u.js.map +0 -1
  170. package/build/server/chunks/10-DovmbqKa.js +0 -14
  171. package/build/server/chunks/10-DovmbqKa.js.map +0 -1
  172. package/build/server/chunks/11-CRK_ubcl.js +0 -14
  173. package/build/server/chunks/11-CRK_ubcl.js.map +0 -1
  174. package/build/server/chunks/12-SbQlwMfe.js +0 -9
  175. package/build/server/chunks/12-SbQlwMfe.js.map +0 -1
  176. package/build/server/chunks/13-CbniIW7F.js +0 -14
  177. package/build/server/chunks/13-CbniIW7F.js.map +0 -1
  178. package/build/server/chunks/14-D9Vb_8Yx.js +0 -9
  179. package/build/server/chunks/14-D9Vb_8Yx.js.map +0 -1
  180. package/build/server/chunks/15-D-75Hdef.js +0 -9
  181. package/build/server/chunks/15-D-75Hdef.js.map +0 -1
  182. package/build/server/chunks/2-57exN8ae.js +0 -14
  183. package/build/server/chunks/2-57exN8ae.js.map +0 -1
  184. package/build/server/chunks/3-DNQft-pY.js +0 -9
  185. package/build/server/chunks/3-DNQft-pY.js.map +0 -1
  186. package/build/server/chunks/4-D9Bwp-f8.js +0 -14
  187. package/build/server/chunks/4-D9Bwp-f8.js.map +0 -1
  188. package/build/server/chunks/5-COEQwZNP.js +0 -14
  189. package/build/server/chunks/5-COEQwZNP.js.map +0 -1
  190. package/build/server/chunks/6-RT4yiDcP.js +0 -14
  191. package/build/server/chunks/6-RT4yiDcP.js.map +0 -1
  192. package/build/server/chunks/7-CVqF_r5D.js +0 -14
  193. package/build/server/chunks/7-CVqF_r5D.js.map +0 -1
  194. package/build/server/chunks/8-C5SO-sVH.js +0 -14
  195. package/build/server/chunks/8-C5SO-sVH.js.map +0 -1
  196. package/build/server/chunks/9-DoCOKtY-.js +0 -14
  197. package/build/server/chunks/9-DoCOKtY-.js.map +0 -1
  198. package/build/server/chunks/FormDialog-ZCY0chY1.js +0 -102
  199. package/build/server/chunks/FormDialog-ZCY0chY1.js.map +0 -1
  200. package/build/server/chunks/Icon-BVo9qbDf.js +0 -30
  201. package/build/server/chunks/Icon-BVo9qbDf.js.map +0 -1
  202. package/build/server/chunks/Logout-CmBZgu0j.js +0 -46
  203. package/build/server/chunks/Logout-CmBZgu0j.js.map +0 -1
  204. package/build/server/chunks/_layout.svelte-DuS006VZ.js +0 -33
  205. package/build/server/chunks/_layout.svelte-DuS006VZ.js.map +0 -1
  206. package/build/server/chunks/_page.svelte-BFVobcI7.js +0 -14
  207. package/build/server/chunks/_page.svelte-BFVobcI7.js.map +0 -1
  208. package/build/server/chunks/_page.svelte-B_cvhWJS.js +0 -66
  209. package/build/server/chunks/_page.svelte-B_cvhWJS.js.map +0 -1
  210. package/build/server/chunks/_page.svelte-BriaBR9l.js +0 -28
  211. package/build/server/chunks/_page.svelte-BriaBR9l.js.map +0 -1
  212. package/build/server/chunks/_page.svelte-BtQQzT7H.js +0 -72
  213. package/build/server/chunks/_page.svelte-BtQQzT7H.js.map +0 -1
  214. package/build/server/chunks/_page.svelte-C8D3c3yB.js +0 -64
  215. package/build/server/chunks/_page.svelte-C8D3c3yB.js.map +0 -1
  216. package/build/server/chunks/_page.svelte-CVSb9eHQ.js +0 -24
  217. package/build/server/chunks/_page.svelte-CVSb9eHQ.js.map +0 -1
  218. package/build/server/chunks/_page.svelte-CwRjZqL7.js +0 -107
  219. package/build/server/chunks/_page.svelte-CwRjZqL7.js.map +0 -1
  220. package/build/server/chunks/_page.svelte-D9A9RYjx.js +0 -233
  221. package/build/server/chunks/_page.svelte-D9A9RYjx.js.map +0 -1
  222. package/build/server/chunks/_page.svelte-DGhwqWMM.js +0 -34
  223. package/build/server/chunks/_page.svelte-DGhwqWMM.js.map +0 -1
  224. package/build/server/chunks/_page.svelte-DTvnX95_.js +0 -75
  225. package/build/server/chunks/_page.svelte-DTvnX95_.js.map +0 -1
  226. package/build/server/chunks/_page.svelte-DUfwpXfC.js +0 -122
  227. package/build/server/chunks/_page.svelte-DUfwpXfC.js.map +0 -1
  228. package/build/server/chunks/_page.svelte-DxDoD3rZ.js +0 -37
  229. package/build/server/chunks/_page.svelte-DxDoD3rZ.js.map +0 -1
  230. package/build/server/chunks/_page.svelte-VDBvShZ8.js +0 -6
  231. package/build/server/chunks/_page.svelte-VDBvShZ8.js.map +0 -1
  232. package/build/server/chunks/account-Bf_llRe2.js +0 -446
  233. package/build/server/chunks/account-Bf_llRe2.js.map +0 -1
  234. package/build/server/chunks/auth_redirect-olBYiIF2.js +0 -24
  235. package/build/server/chunks/auth_redirect-olBYiIF2.js.map +0 -1
  236. package/build/server/chunks/color-K_MR7m8s.js +0 -14
  237. package/build/server/chunks/color-K_MR7m8s.js.map +0 -1
  238. package/build/server/chunks/context-R2425nfV.js +0 -64
  239. package/build/server/chunks/context-R2425nfV.js.map +0 -1
  240. package/build/server/chunks/error.svelte-CkSCwrMJ.js +0 -47
  241. package/build/server/chunks/error.svelte-CkSCwrMJ.js.map +0 -1
  242. package/build/server/chunks/index-CIEcmmdN.js +0 -890
  243. package/build/server/chunks/index-CIEcmmdN.js.map +0 -1
  244. package/build/server/chunks/index-Tt4zVDIZ.js +0 -5345
  245. package/build/server/chunks/index-Tt4zVDIZ.js.map +0 -1
  246. package/build/server/chunks/layout.svelte-UxsTmhKc.js +0 -8
  247. package/build/server/chunks/layout.svelte-UxsTmhKc.js.map +0 -1
  248. package/build/server/chunks/numbers-DL8C9q4W.js +0 -354
  249. package/build/server/chunks/numbers-DL8C9q4W.js.map +0 -1
  250. package/build/server/chunks/user2-CRfK67II.js +0 -716
  251. package/build/server/chunks/user2-CRfK67II.js.map +0 -1
  252. package/build/server/chunks/utils-h74ns7K6.js +0 -286
  253. package/build/server/chunks/utils-h74ns7K6.js.map +0 -1
  254. package/build/server/index.js +0 -8115
  255. package/build/server/index.js.map +0 -1
  256. package/build/server/manifest.js +0 -143
  257. package/build/server/manifest.js.map +0 -1
  258. package/build/shims.js +0 -32
@@ -1,716 +0,0 @@
1
- import { o as object, e as email, d as string, u as uuid, f as prettifyError, $ as $ZodError, U as UserChangeable } from './index-Tt4zVDIZ.js';
2
-
3
- /**
4
- * Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
5
- * credential response ArrayBuffers to string for sending back to the server as JSON.
6
- *
7
- * Helper method to compliment `base64URLStringToBuffer`
8
- */
9
- function bufferToBase64URLString(buffer) {
10
- const bytes = new Uint8Array(buffer);
11
- let str = '';
12
- for (const charCode of bytes) {
13
- str += String.fromCharCode(charCode);
14
- }
15
- const base64String = btoa(str);
16
- return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
17
- }
18
-
19
- /**
20
- * Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
21
- * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
22
- * excludeCredentials
23
- *
24
- * Helper method to compliment `bufferToBase64URLString`
25
- */
26
- function base64URLStringToBuffer(base64URLString) {
27
- // Convert from Base64URL to Base64
28
- const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
29
- /**
30
- * Pad with '=' until it's a multiple of four
31
- * (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
32
- * (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
33
- * (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
34
- * (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
35
- */
36
- const padLength = (4 - (base64.length % 4)) % 4;
37
- const padded = base64.padEnd(base64.length + padLength, '=');
38
- // Convert to a binary string
39
- const binary = atob(padded);
40
- // Convert binary string to buffer
41
- const buffer = new ArrayBuffer(binary.length);
42
- const bytes = new Uint8Array(buffer);
43
- for (let i = 0; i < binary.length; i++) {
44
- bytes[i] = binary.charCodeAt(i);
45
- }
46
- return buffer;
47
- }
48
-
49
- /**
50
- * Determine if the browser is capable of Webauthn
51
- */
52
- function browserSupportsWebAuthn() {
53
- return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
54
- typeof globalThis.PublicKeyCredential === 'function');
55
- }
56
- /**
57
- * Make it possible to stub the return value during testing
58
- * @ignore Don't include this in docs output
59
- */
60
- const _browserSupportsWebAuthnInternals = {
61
- stubThis: (value) => value,
62
- };
63
-
64
- function toPublicKeyCredentialDescriptor(descriptor) {
65
- const { id } = descriptor;
66
- return {
67
- ...descriptor,
68
- id: base64URLStringToBuffer(id),
69
- /**
70
- * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer
71
- * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
72
- * are fine to pass to WebAuthn since browsers will recognize the new value.
73
- */
74
- transports: descriptor.transports,
75
- };
76
- }
77
-
78
- /**
79
- * A simple test to determine if a hostname is a properly-formatted domain name
80
- *
81
- * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain
82
- *
83
- * Regex sourced from here:
84
- * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html
85
- */
86
- function isValidDomain(hostname) {
87
- return (
88
- // Consider localhost valid as well since it's okay wrt Secure Contexts
89
- hostname === 'localhost' ||
90
- /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
91
- }
92
-
93
- /**
94
- * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
95
- * errors in the spec was raised after calling `navigator.credentials.create()` or
96
- * `navigator.credentials.get()`:
97
- *
98
- * - `AbortError`
99
- * - `ConstraintError`
100
- * - `InvalidStateError`
101
- * - `NotAllowedError`
102
- * - `NotSupportedError`
103
- * - `SecurityError`
104
- * - `TypeError`
105
- * - `UnknownError`
106
- *
107
- * Error messages were determined through investigation of the spec to determine under which
108
- * scenarios a given error would be raised.
109
- */
110
- class WebAuthnError extends Error {
111
- constructor({ message, code, cause, name, }) {
112
- // @ts-ignore: help Rollup understand that `cause` is okay to set
113
- super(message, { cause });
114
- Object.defineProperty(this, "code", {
115
- enumerable: true,
116
- configurable: true,
117
- writable: true,
118
- value: void 0
119
- });
120
- this.name = name ?? cause.name;
121
- this.code = code;
122
- }
123
- }
124
-
125
- /**
126
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
127
- */
128
- function identifyRegistrationError({ error, options, }) {
129
- const { publicKey } = options;
130
- if (!publicKey) {
131
- throw Error('options was missing required publicKey property');
132
- }
133
- if (error.name === 'AbortError') {
134
- if (options.signal instanceof AbortSignal) {
135
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
136
- return new WebAuthnError({
137
- message: 'Registration ceremony was sent an abort signal',
138
- code: 'ERROR_CEREMONY_ABORTED',
139
- cause: error,
140
- });
141
- }
142
- }
143
- else if (error.name === 'ConstraintError') {
144
- if (publicKey.authenticatorSelection?.requireResidentKey === true) {
145
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
146
- return new WebAuthnError({
147
- message: 'Discoverable credentials were required but no available authenticator supported it',
148
- code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
149
- cause: error,
150
- });
151
- }
152
- else if (
153
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
154
- options.mediation === 'conditional' &&
155
- publicKey.authenticatorSelection?.userVerification === 'required') {
156
- // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
157
- return new WebAuthnError({
158
- message: 'User verification was required during automatic registration but it could not be performed',
159
- code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
160
- cause: error,
161
- });
162
- }
163
- else if (publicKey.authenticatorSelection?.userVerification === 'required') {
164
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
165
- return new WebAuthnError({
166
- message: 'User verification was required but no available authenticator supported it',
167
- code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
168
- cause: error,
169
- });
170
- }
171
- }
172
- else if (error.name === 'InvalidStateError') {
173
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
174
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
175
- return new WebAuthnError({
176
- message: 'The authenticator was previously registered',
177
- code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
178
- cause: error,
179
- });
180
- }
181
- else if (error.name === 'NotAllowedError') {
182
- /**
183
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
184
- * defines and we don't want to overwrite potentially useful error messages.
185
- */
186
- return new WebAuthnError({
187
- message: error.message,
188
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
189
- cause: error,
190
- });
191
- }
192
- else if (error.name === 'NotSupportedError') {
193
- const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
194
- if (validPubKeyCredParams.length === 0) {
195
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
196
- return new WebAuthnError({
197
- message: 'No entry in pubKeyCredParams was of type "public-key"',
198
- code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
199
- cause: error,
200
- });
201
- }
202
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
203
- return new WebAuthnError({
204
- message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
205
- code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
206
- cause: error,
207
- });
208
- }
209
- else if (error.name === 'SecurityError') {
210
- const effectiveDomain = globalThis.location.hostname;
211
- if (!isValidDomain(effectiveDomain)) {
212
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
213
- return new WebAuthnError({
214
- message: `${globalThis.location.hostname} is an invalid domain`,
215
- code: 'ERROR_INVALID_DOMAIN',
216
- cause: error,
217
- });
218
- }
219
- else if (publicKey.rp.id !== effectiveDomain) {
220
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
221
- return new WebAuthnError({
222
- message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
223
- code: 'ERROR_INVALID_RP_ID',
224
- cause: error,
225
- });
226
- }
227
- }
228
- else if (error.name === 'TypeError') {
229
- if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
230
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
231
- return new WebAuthnError({
232
- message: 'User ID was not between 1 and 64 characters',
233
- code: 'ERROR_INVALID_USER_ID_LENGTH',
234
- cause: error,
235
- });
236
- }
237
- }
238
- else if (error.name === 'UnknownError') {
239
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
240
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
241
- return new WebAuthnError({
242
- message: 'The authenticator was unable to process the specified options, or could not create a new credential',
243
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
244
- cause: error,
245
- });
246
- }
247
- return error;
248
- }
249
-
250
- class BaseWebAuthnAbortService {
251
- constructor() {
252
- Object.defineProperty(this, "controller", {
253
- enumerable: true,
254
- configurable: true,
255
- writable: true,
256
- value: void 0
257
- });
258
- }
259
- createNewAbortSignal() {
260
- // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
261
- if (this.controller) {
262
- const abortError = new Error('Cancelling existing WebAuthn API call for new one');
263
- abortError.name = 'AbortError';
264
- this.controller.abort(abortError);
265
- }
266
- const newController = new AbortController();
267
- this.controller = newController;
268
- return newController.signal;
269
- }
270
- cancelCeremony() {
271
- if (this.controller) {
272
- const abortError = new Error('Manually cancelling existing WebAuthn API call');
273
- abortError.name = 'AbortError';
274
- this.controller.abort(abortError);
275
- this.controller = undefined;
276
- }
277
- }
278
- }
279
- /**
280
- * A service singleton to help ensure that only a single WebAuthn ceremony is active at a time.
281
- *
282
- * Users of **@simplewebauthn/browser** shouldn't typically need to use this, but it can help e.g.
283
- * developers building projects that use client-side routing to better control the behavior of
284
- * their UX in response to router navigation events.
285
- */
286
- const WebAuthnAbortService = new BaseWebAuthnAbortService();
287
-
288
- const attachments = ['cross-platform', 'platform'];
289
- /**
290
- * If possible coerce a `string` value into a known `AuthenticatorAttachment`
291
- */
292
- function toAuthenticatorAttachment(attachment) {
293
- if (!attachment) {
294
- return;
295
- }
296
- if (attachments.indexOf(attachment) < 0) {
297
- return;
298
- }
299
- return attachment;
300
- }
301
-
302
- /**
303
- * Begin authenticator "registration" via WebAuthn attestation
304
- *
305
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
306
- * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
307
- */
308
- async function startRegistration(options) {
309
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
310
- if (!options.optionsJSON && options.challenge) {
311
- console.warn('startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
312
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
313
- options = { optionsJSON: options };
314
- }
315
- const { optionsJSON, useAutoRegister = false } = options;
316
- if (!browserSupportsWebAuthn()) {
317
- throw new Error('WebAuthn is not supported in this browser');
318
- }
319
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
320
- const publicKey = {
321
- ...optionsJSON,
322
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
323
- user: {
324
- ...optionsJSON.user,
325
- id: base64URLStringToBuffer(optionsJSON.user.id),
326
- },
327
- excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
328
- };
329
- // Prepare options for `.create()`
330
- const createOptions = {};
331
- /**
332
- * Try to use conditional create to register a passkey for the user with the password manager
333
- * the user just used to authenticate with. The user won't be shown any prominent UI by the
334
- * browser.
335
- */
336
- if (useAutoRegister) {
337
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
338
- createOptions.mediation = 'conditional';
339
- }
340
- // Finalize options
341
- createOptions.publicKey = publicKey;
342
- // Set up the ability to cancel this request if the user attempts another
343
- createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
344
- // Wait for the user to complete attestation
345
- let credential;
346
- try {
347
- credential = (await navigator.credentials.create(createOptions));
348
- }
349
- catch (err) {
350
- throw identifyRegistrationError({ error: err, options: createOptions });
351
- }
352
- if (!credential) {
353
- throw new Error('Registration was not completed');
354
- }
355
- const { id, rawId, response, type } = credential;
356
- // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
357
- let transports = undefined;
358
- if (typeof response.getTransports === 'function') {
359
- transports = response.getTransports();
360
- }
361
- // L3 says this is required, but browser and webview support are still not guaranteed.
362
- let responsePublicKeyAlgorithm = undefined;
363
- if (typeof response.getPublicKeyAlgorithm === 'function') {
364
- try {
365
- responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
366
- }
367
- catch (error) {
368
- warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
369
- }
370
- }
371
- let responsePublicKey = undefined;
372
- if (typeof response.getPublicKey === 'function') {
373
- try {
374
- const _publicKey = response.getPublicKey();
375
- if (_publicKey !== null) {
376
- responsePublicKey = bufferToBase64URLString(_publicKey);
377
- }
378
- }
379
- catch (error) {
380
- warnOnBrokenImplementation('getPublicKey()', error);
381
- }
382
- }
383
- // L3 says this is required, but browser and webview support are still not guaranteed.
384
- let responseAuthenticatorData;
385
- if (typeof response.getAuthenticatorData === 'function') {
386
- try {
387
- responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
388
- }
389
- catch (error) {
390
- warnOnBrokenImplementation('getAuthenticatorData()', error);
391
- }
392
- }
393
- return {
394
- id,
395
- rawId: bufferToBase64URLString(rawId),
396
- response: {
397
- attestationObject: bufferToBase64URLString(response.attestationObject),
398
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
399
- transports,
400
- publicKeyAlgorithm: responsePublicKeyAlgorithm,
401
- publicKey: responsePublicKey,
402
- authenticatorData: responseAuthenticatorData,
403
- },
404
- type,
405
- clientExtensionResults: credential.getClientExtensionResults(),
406
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
407
- };
408
- }
409
- /**
410
- * Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
411
- * calls
412
- */
413
- function warnOnBrokenImplementation(methodName, cause) {
414
- console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
415
- }
416
-
417
- /**
418
- * Determine if the browser supports conditional UI, so that WebAuthn credentials can
419
- * be shown to the user in the browser's typical password autofill popup.
420
- */
421
- function browserSupportsWebAuthnAutofill() {
422
- if (!browserSupportsWebAuthn()) {
423
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
424
- }
425
- /**
426
- * I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
427
- * TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
428
- * want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
429
- * have a chance to catch up.
430
- */
431
- const globalPublicKeyCredential = globalThis
432
- .PublicKeyCredential;
433
- if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
434
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
435
- }
436
- return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
437
- }
438
- // Make it possible to stub the return value during testing
439
- const _browserSupportsWebAuthnAutofillInternals = {
440
- stubThis: (value) => value,
441
- };
442
-
443
- /**
444
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
445
- */
446
- function identifyAuthenticationError({ error, options, }) {
447
- const { publicKey } = options;
448
- if (!publicKey) {
449
- throw Error('options was missing required publicKey property');
450
- }
451
- if (error.name === 'AbortError') {
452
- if (options.signal instanceof AbortSignal) {
453
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
454
- return new WebAuthnError({
455
- message: 'Authentication ceremony was sent an abort signal',
456
- code: 'ERROR_CEREMONY_ABORTED',
457
- cause: error,
458
- });
459
- }
460
- }
461
- else if (error.name === 'NotAllowedError') {
462
- /**
463
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
464
- * defines and we don't want to overwrite potentially useful error messages.
465
- */
466
- return new WebAuthnError({
467
- message: error.message,
468
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
469
- cause: error,
470
- });
471
- }
472
- else if (error.name === 'SecurityError') {
473
- const effectiveDomain = globalThis.location.hostname;
474
- if (!isValidDomain(effectiveDomain)) {
475
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
476
- return new WebAuthnError({
477
- message: `${globalThis.location.hostname} is an invalid domain`,
478
- code: 'ERROR_INVALID_DOMAIN',
479
- cause: error,
480
- });
481
- }
482
- else if (publicKey.rpId !== effectiveDomain) {
483
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
484
- return new WebAuthnError({
485
- message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
486
- code: 'ERROR_INVALID_RP_ID',
487
- cause: error,
488
- });
489
- }
490
- }
491
- else if (error.name === 'UnknownError') {
492
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
493
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
494
- return new WebAuthnError({
495
- message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
496
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
497
- cause: error,
498
- });
499
- }
500
- return error;
501
- }
502
-
503
- /**
504
- * Begin authenticator "login" via WebAuthn assertion
505
- *
506
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
507
- * @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
508
- * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
509
- */
510
- async function startAuthentication(options) {
511
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
512
- if (!options.optionsJSON && options.challenge) {
513
- console.warn('startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
514
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
515
- options = { optionsJSON: options };
516
- }
517
- const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
518
- if (!browserSupportsWebAuthn()) {
519
- throw new Error('WebAuthn is not supported in this browser');
520
- }
521
- // We need to avoid passing empty array to avoid blocking retrieval
522
- // of public key
523
- let allowCredentials;
524
- if (optionsJSON.allowCredentials?.length !== 0) {
525
- allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
526
- }
527
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
528
- const publicKey = {
529
- ...optionsJSON,
530
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
531
- allowCredentials,
532
- };
533
- // Prepare options for `.get()`
534
- const getOptions = {};
535
- /**
536
- * Set up the page to prompt the user to select a credential for authentication via the browser's
537
- * input autofill mechanism.
538
- */
539
- if (useBrowserAutofill) {
540
- if (!(await browserSupportsWebAuthnAutofill())) {
541
- throw Error('Browser does not support WebAuthn autofill');
542
- }
543
- // Check for an <input> with "webauthn" in its `autocomplete` attribute
544
- const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
545
- // WebAuthn autofill requires at least one valid input
546
- if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
547
- throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
548
- }
549
- // `CredentialMediationRequirement` doesn't know about "conditional" yet as of
550
- // typescript@4.6.3
551
- getOptions.mediation = 'conditional';
552
- // Conditional UI requires an empty allow list
553
- publicKey.allowCredentials = [];
554
- }
555
- // Finalize options
556
- getOptions.publicKey = publicKey;
557
- // Set up the ability to cancel this request if the user attempts another
558
- getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
559
- // Wait for the user to complete assertion
560
- let credential;
561
- try {
562
- credential = (await navigator.credentials.get(getOptions));
563
- }
564
- catch (err) {
565
- throw identifyAuthenticationError({ error: err, options: getOptions });
566
- }
567
- if (!credential) {
568
- throw new Error('Authentication was not completed');
569
- }
570
- const { id, rawId, response, type } = credential;
571
- let userHandle = undefined;
572
- if (response.userHandle) {
573
- userHandle = bufferToBase64URLString(response.userHandle);
574
- }
575
- // Convert values to base64 to make it easier to send back to the server
576
- return {
577
- id,
578
- rawId: bufferToBase64URLString(rawId),
579
- response: {
580
- authenticatorData: bufferToBase64URLString(response.authenticatorData),
581
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
582
- signature: bufferToBase64URLString(response.signature),
583
- userHandle,
584
- },
585
- type,
586
- clientExtensionResults: credential.getClientExtensionResults(),
587
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
588
- };
589
- }
590
-
591
- let prefix = "/api/";
592
- async function fetchAPI(method, endpoint, data, ...params) {
593
- const options = {
594
- method,
595
- headers: {
596
- "Content-Type": "application/json",
597
- Accept: "application/json"
598
- }
599
- };
600
- if (method !== "GET" && method !== "HEAD")
601
- options.body = JSON.stringify(data);
602
- const search = method != "GET" || typeof data != "object" || data == null || !Object.keys(data).length ? "" : "?" + new URLSearchParams(data).toString();
603
- const parts = [];
604
- for (const part of endpoint.split("/")) {
605
- if (!part.startsWith(":")) {
606
- parts.push(part);
607
- continue;
608
- }
609
- const value = params.shift();
610
- if (!value)
611
- throw new Error(`Missing parameter "${part.slice(1)}"`);
612
- parts.push(value);
613
- }
614
- const response = await fetch(prefix + parts.join("/") + search, options);
615
- if (!response.headers.get("Content-Type")?.includes("application/json")) {
616
- throw new Error(`Unexpected response type: ${response.headers.get("Content-Type")}`);
617
- }
618
- const json = await response.json().catch(() => ({ message: "Unknown server error (invalid JSON response)" }));
619
- if (!response.ok)
620
- throw new Error(json.message);
621
- return json;
622
- }
623
-
624
- async function login(userId) {
625
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "login" }, userId);
626
- const response = await startAuthentication({ optionsJSON: options });
627
- return await fetchAPI("POST", "users/:id/auth", response, userId);
628
- }
629
- async function elevate(userId) {
630
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
631
- const response = await startAuthentication({ optionsJSON: options });
632
- await fetchAPI("POST", "users/:id/auth", response, userId);
633
- }
634
- async function loginByEmail(email) {
635
- const { id: userId } = await fetchAPI("POST", "user_id", {
636
- using: "email",
637
- value: email
638
- });
639
- return await login(userId);
640
- }
641
- async function getCurrentSession() {
642
- const result = await fetchAPI("GET", "session");
643
- result.created = new Date(result.created);
644
- result.expires = new Date(result.expires);
645
- return result;
646
- }
647
- async function logout(userId, ...sessionId) {
648
- _checkId(userId);
649
- const result = await fetchAPI("DELETE", "users/:id/sessions", { id: sessionId }, userId);
650
- for (const session of result) {
651
- session.created = new Date(session.created);
652
- session.expires = new Date(session.expires);
653
- }
654
- return result;
655
- }
656
- async function logoutAll(userId) {
657
- _checkId(userId);
658
- await elevate(userId);
659
- const result = await fetchAPI("DELETE", "users/:id/sessions", { confirm_all: true }, userId);
660
- for (const session of result) {
661
- session.created = new Date(session.created);
662
- session.expires = new Date(session.expires);
663
- }
664
- return result;
665
- }
666
- async function logoutCurrentSession() {
667
- return await fetchAPI("DELETE", "session");
668
- }
669
- async function register(_data) {
670
- const data = object({ name: string(), email: email() }).parse(_data);
671
- const { options, userId } = await fetchAPI("OPTIONS", "register", data);
672
- const response = await startRegistration({ optionsJSON: options });
673
- await fetchAPI("POST", "register", {
674
- userId,
675
- name: data.name,
676
- email: data.email,
677
- response
678
- });
679
- }
680
- function _checkId(userId) {
681
- try {
682
- uuid().parse(userId);
683
- } catch (e) {
684
- throw e instanceof $ZodError ? prettifyError(e) : e;
685
- }
686
- }
687
- async function updateUser(userId, data) {
688
- _checkId(userId);
689
- const body = await UserChangeable.parseAsync(data).catch((e) => {
690
- throw e instanceof $ZodError ? prettifyError(e) : e;
691
- });
692
- const result = await fetchAPI("PATCH", "users/:id", body, userId);
693
- result.registeredAt = new Date(result.registeredAt);
694
- if (result.emailVerified)
695
- result.emailVerified = new Date(result.emailVerified);
696
- return result;
697
- }
698
- async function deleteUser(userId) {
699
- _checkId(userId);
700
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
701
- const response = await startAuthentication({ optionsJSON: options });
702
- await fetchAPI("POST", "users/:id/auth", response, userId);
703
- const result = await fetchAPI("DELETE", "users/:id", response, userId);
704
- result.registeredAt = new Date(result.registeredAt);
705
- result.emailVerified = new Date(result.emailVerified);
706
- return result;
707
- }
708
- async function updatePasskey(passkeyId, data) {
709
- return await fetchAPI("PATCH", "passkeys/:id", data, passkeyId);
710
- }
711
- async function deletePasskey(passkeyId) {
712
- return await fetchAPI("DELETE", "passkeys/:id", {}, passkeyId);
713
- }
714
-
715
- export { deletePasskey as a, updateUser as b, logoutAll as c, deleteUser as d, loginByEmail as e, logoutCurrentSession as f, getCurrentSession as g, logout as l, register as r, updatePasskey as u };
716
- //# sourceMappingURL=user2-CRfK67II.js.map