@axium/server 0.25.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/dist/acl.js +1 -1
  2. package/dist/api/admin.js +20 -3
  3. package/dist/api/metadata.js +3 -3
  4. package/dist/api/users.js +4 -1
  5. package/dist/audit.d.ts +1 -0
  6. package/dist/audit.js +3 -3
  7. package/dist/cli.js +511 -541
  8. package/dist/config.d.ts +6 -6
  9. package/dist/config.js +25 -13
  10. package/dist/database.js +7 -6
  11. package/dist/io.d.ts +0 -50
  12. package/dist/io.js +23 -171
  13. package/dist/linking.js +4 -4
  14. package/dist/requests.d.ts +5 -1
  15. package/dist/requests.js +4 -2
  16. package/dist/routes.js +3 -3
  17. package/dist/serve.d.ts +4 -0
  18. package/dist/serve.js +13 -8
  19. package/package.json +5 -6
  20. package/routes/admin/+layout.ts +2 -0
  21. package/routes/admin/audit/+page.svelte +23 -2
  22. package/routes/admin/audit/+page.ts +4 -2
  23. package/routes/login/client/+page.svelte +72 -0
  24. package/routes/login/client/+page.ts +27 -0
  25. package/build/client/_app/immutable/assets/account.dAAx7bby.css +0 -1
  26. package/build/client/_app/immutable/assets/account.dAAx7bby.css.br +0 -0
  27. package/build/client/_app/immutable/assets/account.dAAx7bby.css.gz +0 -0
  28. package/build/client/_app/immutable/assets/list.DVGH0BeP.css +0 -1
  29. package/build/client/_app/immutable/assets/list.DVGH0BeP.css.br +0 -0
  30. package/build/client/_app/immutable/assets/list.DVGH0BeP.css.gz +0 -0
  31. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css +0 -1
  32. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css.br +0 -2
  33. package/build/client/_app/immutable/assets/styles.D8SZ-PeY.css.gz +0 -0
  34. package/build/client/_app/immutable/chunks/1taVrT-y.js +0 -1
  35. package/build/client/_app/immutable/chunks/1taVrT-y.js.br +0 -0
  36. package/build/client/_app/immutable/chunks/1taVrT-y.js.gz +0 -0
  37. package/build/client/_app/immutable/chunks/BSFUgC2l.js +0 -23
  38. package/build/client/_app/immutable/chunks/BSFUgC2l.js.br +0 -0
  39. package/build/client/_app/immutable/chunks/BSFUgC2l.js.gz +0 -0
  40. package/build/client/_app/immutable/chunks/Bbzjahjl.js +0 -2
  41. package/build/client/_app/immutable/chunks/Bbzjahjl.js.br +0 -0
  42. package/build/client/_app/immutable/chunks/Bbzjahjl.js.gz +0 -0
  43. package/build/client/_app/immutable/chunks/BxjargW5.js +0 -1
  44. package/build/client/_app/immutable/chunks/BxjargW5.js.br +0 -0
  45. package/build/client/_app/immutable/chunks/BxjargW5.js.gz +0 -0
  46. package/build/client/_app/immutable/chunks/C2ewTgu8.js +0 -1
  47. package/build/client/_app/immutable/chunks/C2ewTgu8.js.br +0 -0
  48. package/build/client/_app/immutable/chunks/C2ewTgu8.js.gz +0 -0
  49. package/build/client/_app/immutable/chunks/CFWAHLsq.js +0 -1
  50. package/build/client/_app/immutable/chunks/CFWAHLsq.js.br +0 -0
  51. package/build/client/_app/immutable/chunks/CFWAHLsq.js.gz +0 -0
  52. package/build/client/_app/immutable/chunks/CPL43v-I.js +0 -1
  53. package/build/client/_app/immutable/chunks/CPL43v-I.js.br +0 -0
  54. package/build/client/_app/immutable/chunks/CPL43v-I.js.gz +0 -0
  55. package/build/client/_app/immutable/chunks/CTKC36WM.js +0 -1
  56. package/build/client/_app/immutable/chunks/CTKC36WM.js.br +0 -0
  57. package/build/client/_app/immutable/chunks/CTKC36WM.js.gz +0 -0
  58. package/build/client/_app/immutable/chunks/CekH6JMP.js +0 -1
  59. package/build/client/_app/immutable/chunks/CekH6JMP.js.br +0 -0
  60. package/build/client/_app/immutable/chunks/CekH6JMP.js.gz +0 -0
  61. package/build/client/_app/immutable/chunks/Ch16TNvP.js +0 -1
  62. package/build/client/_app/immutable/chunks/Ch16TNvP.js.br +0 -0
  63. package/build/client/_app/immutable/chunks/Ch16TNvP.js.gz +0 -0
  64. package/build/client/_app/immutable/chunks/CqfYW08-.js +0 -1
  65. package/build/client/_app/immutable/chunks/CqfYW08-.js.br +0 -0
  66. package/build/client/_app/immutable/chunks/CqfYW08-.js.gz +0 -0
  67. package/build/client/_app/immutable/chunks/D1v6O410.js +0 -1
  68. package/build/client/_app/immutable/chunks/D1v6O410.js.br +0 -0
  69. package/build/client/_app/immutable/chunks/D1v6O410.js.gz +0 -0
  70. package/build/client/_app/immutable/chunks/DY4fWHx_.js +0 -1
  71. package/build/client/_app/immutable/chunks/DY4fWHx_.js.br +0 -0
  72. package/build/client/_app/immutable/chunks/DY4fWHx_.js.gz +0 -0
  73. package/build/client/_app/immutable/chunks/DdnE6dyJ.js +0 -2
  74. package/build/client/_app/immutable/chunks/DdnE6dyJ.js.br +0 -0
  75. package/build/client/_app/immutable/chunks/DdnE6dyJ.js.gz +0 -0
  76. package/build/client/_app/immutable/chunks/DeieCYM0.js +0 -22
  77. package/build/client/_app/immutable/chunks/DeieCYM0.js.br +0 -0
  78. package/build/client/_app/immutable/chunks/DeieCYM0.js.gz +0 -0
  79. package/build/client/_app/immutable/chunks/DfUzlYF5.js +0 -1
  80. package/build/client/_app/immutable/chunks/DfUzlYF5.js.br +0 -0
  81. package/build/client/_app/immutable/chunks/DfUzlYF5.js.gz +0 -0
  82. package/build/client/_app/immutable/chunks/Dnk28BpG.js +0 -1
  83. package/build/client/_app/immutable/chunks/Dnk28BpG.js.br +0 -0
  84. package/build/client/_app/immutable/chunks/Dnk28BpG.js.gz +0 -0
  85. package/build/client/_app/immutable/chunks/DsnmJJEf.js +0 -1
  86. package/build/client/_app/immutable/chunks/DsnmJJEf.js.br +0 -2
  87. package/build/client/_app/immutable/chunks/DsnmJJEf.js.gz +0 -0
  88. package/build/client/_app/immutable/chunks/KNAS5R2A.js +0 -3
  89. package/build/client/_app/immutable/chunks/KNAS5R2A.js.br +0 -0
  90. package/build/client/_app/immutable/chunks/KNAS5R2A.js.gz +0 -0
  91. package/build/client/_app/immutable/chunks/eyJgPND9.js +0 -1
  92. package/build/client/_app/immutable/chunks/eyJgPND9.js.br +0 -1
  93. package/build/client/_app/immutable/chunks/eyJgPND9.js.gz +0 -0
  94. package/build/client/_app/immutable/entry/app.CPF6A_DV.js +0 -2
  95. package/build/client/_app/immutable/entry/app.CPF6A_DV.js.br +0 -0
  96. package/build/client/_app/immutable/entry/app.CPF6A_DV.js.gz +0 -0
  97. package/build/client/_app/immutable/entry/start.Dos_Ttds.js +0 -1
  98. package/build/client/_app/immutable/entry/start.Dos_Ttds.js.br +0 -2
  99. package/build/client/_app/immutable/entry/start.Dos_Ttds.js.gz +0 -0
  100. package/build/client/_app/immutable/nodes/0.C5HgTRfT.js +0 -1
  101. package/build/client/_app/immutable/nodes/0.C5HgTRfT.js.br +0 -0
  102. package/build/client/_app/immutable/nodes/0.C5HgTRfT.js.gz +0 -0
  103. package/build/client/_app/immutable/nodes/1.CGcgSoA9.js +0 -1
  104. package/build/client/_app/immutable/nodes/1.CGcgSoA9.js.br +0 -0
  105. package/build/client/_app/immutable/nodes/1.CGcgSoA9.js.gz +0 -0
  106. package/build/client/_app/immutable/nodes/10.ukScuXwz.js +0 -1
  107. package/build/client/_app/immutable/nodes/10.ukScuXwz.js.br +0 -5
  108. package/build/client/_app/immutable/nodes/10.ukScuXwz.js.gz +0 -0
  109. package/build/client/_app/immutable/nodes/11.D3RDNx7M.js +0 -1
  110. package/build/client/_app/immutable/nodes/11.D3RDNx7M.js.br +0 -0
  111. package/build/client/_app/immutable/nodes/11.D3RDNx7M.js.gz +0 -0
  112. package/build/client/_app/immutable/nodes/12._vvpCcSG.js +0 -1
  113. package/build/client/_app/immutable/nodes/12._vvpCcSG.js.br +0 -0
  114. package/build/client/_app/immutable/nodes/12._vvpCcSG.js.gz +0 -0
  115. package/build/client/_app/immutable/nodes/13.BWPzZMQ5.js +0 -1
  116. package/build/client/_app/immutable/nodes/13.BWPzZMQ5.js.br +0 -0
  117. package/build/client/_app/immutable/nodes/13.BWPzZMQ5.js.gz +0 -0
  118. package/build/client/_app/immutable/nodes/14.Cr843Lep.js +0 -1
  119. package/build/client/_app/immutable/nodes/14.Cr843Lep.js.br +0 -0
  120. package/build/client/_app/immutable/nodes/14.Cr843Lep.js.gz +0 -0
  121. package/build/client/_app/immutable/nodes/2.DUpwDjw8.js +0 -1
  122. package/build/client/_app/immutable/nodes/2.DUpwDjw8.js.br +0 -0
  123. package/build/client/_app/immutable/nodes/2.DUpwDjw8.js.gz +0 -0
  124. package/build/client/_app/immutable/nodes/3.DPH7xl7M.js +0 -1
  125. package/build/client/_app/immutable/nodes/3.DPH7xl7M.js.br +0 -0
  126. package/build/client/_app/immutable/nodes/3.DPH7xl7M.js.gz +0 -0
  127. package/build/client/_app/immutable/nodes/4.Bk0knTIK.js +0 -1
  128. package/build/client/_app/immutable/nodes/4.Bk0knTIK.js.br +0 -0
  129. package/build/client/_app/immutable/nodes/4.Bk0knTIK.js.gz +0 -0
  130. package/build/client/_app/immutable/nodes/5.DwnZ1Bh8.js +0 -1
  131. package/build/client/_app/immutable/nodes/5.DwnZ1Bh8.js.br +0 -0
  132. package/build/client/_app/immutable/nodes/5.DwnZ1Bh8.js.gz +0 -0
  133. package/build/client/_app/immutable/nodes/6.5U-KxFgt.js +0 -2
  134. package/build/client/_app/immutable/nodes/6.5U-KxFgt.js.br +0 -0
  135. package/build/client/_app/immutable/nodes/6.5U-KxFgt.js.gz +0 -0
  136. package/build/client/_app/immutable/nodes/7.DFc4sJix.js +0 -1
  137. package/build/client/_app/immutable/nodes/7.DFc4sJix.js.br +0 -0
  138. package/build/client/_app/immutable/nodes/7.DFc4sJix.js.gz +0 -0
  139. package/build/client/_app/immutable/nodes/8.BG4bv5P5.js +0 -1
  140. package/build/client/_app/immutable/nodes/8.BG4bv5P5.js.br +0 -0
  141. package/build/client/_app/immutable/nodes/8.BG4bv5P5.js.gz +0 -0
  142. package/build/client/_app/immutable/nodes/9.BKljyhOi.js +0 -1
  143. package/build/client/_app/immutable/nodes/9.BKljyhOi.js.br +0 -0
  144. package/build/client/_app/immutable/nodes/9.BKljyhOi.js.gz +0 -0
  145. package/build/client/_app/version.json +0 -1
  146. package/build/client/_app/version.json.br +0 -0
  147. package/build/client/_app/version.json.gz +0 -0
  148. package/build/client/icons/brands.svg +0 -1493
  149. package/build/client/icons/brands.svg.br +0 -0
  150. package/build/client/icons/brands.svg.gz +0 -0
  151. package/build/client/icons/light.svg +0 -9977
  152. package/build/client/icons/light.svg.br +0 -0
  153. package/build/client/icons/light.svg.gz +0 -0
  154. package/build/client/icons/regular.svg +0 -9977
  155. package/build/client/icons/regular.svg.br +0 -0
  156. package/build/client/icons/regular.svg.gz +0 -0
  157. package/build/client/icons/solid.svg +0 -9977
  158. package/build/client/icons/solid.svg.br +0 -0
  159. package/build/client/icons/solid.svg.gz +0 -0
  160. package/build/client/styles.css +0 -147
  161. package/build/client/styles.css.br +0 -0
  162. package/build/client/styles.css.gz +0 -0
  163. package/build/client/theme.css +0 -42
  164. package/build/client/theme.css.br +0 -0
  165. package/build/client/theme.css.gz +0 -0
  166. package/build/env.js +0 -45
  167. package/build/handler.js +0 -1390
  168. package/build/index.js +0 -334
  169. package/build/server/chunks/0-CZBaNtSI.js +0 -9
  170. package/build/server/chunks/0-CZBaNtSI.js.map +0 -1
  171. package/build/server/chunks/1-D_3BtEbe.js +0 -9
  172. package/build/server/chunks/1-D_3BtEbe.js.map +0 -1
  173. package/build/server/chunks/10-CLkNMKHU.js +0 -13
  174. package/build/server/chunks/10-CLkNMKHU.js.map +0 -1
  175. package/build/server/chunks/11-5xPYR_1w.js +0 -13
  176. package/build/server/chunks/11-5xPYR_1w.js.map +0 -1
  177. package/build/server/chunks/12-N7UaQj7u.js +0 -9
  178. package/build/server/chunks/12-N7UaQj7u.js.map +0 -1
  179. package/build/server/chunks/13-QYVLpXli.js +0 -9
  180. package/build/server/chunks/13-QYVLpXli.js.map +0 -1
  181. package/build/server/chunks/14-CPY578rT.js +0 -9
  182. package/build/server/chunks/14-CPY578rT.js.map +0 -1
  183. package/build/server/chunks/2-_1jFrcvz.js +0 -13
  184. package/build/server/chunks/2-_1jFrcvz.js.map +0 -1
  185. package/build/server/chunks/3-B1CwnVF_.js +0 -9
  186. package/build/server/chunks/3-B1CwnVF_.js.map +0 -1
  187. package/build/server/chunks/4-CcxCcH4F.js +0 -13
  188. package/build/server/chunks/4-CcxCcH4F.js.map +0 -1
  189. package/build/server/chunks/5-CrlH6VoB.js +0 -13
  190. package/build/server/chunks/5-CrlH6VoB.js.map +0 -1
  191. package/build/server/chunks/6-FkP678Uz.js +0 -13
  192. package/build/server/chunks/6-FkP678Uz.js.map +0 -1
  193. package/build/server/chunks/7-B1iCe7VA.js +0 -13
  194. package/build/server/chunks/7-B1iCe7VA.js.map +0 -1
  195. package/build/server/chunks/8-p6n9G-P_.js +0 -13
  196. package/build/server/chunks/8-p6n9G-P_.js.map +0 -1
  197. package/build/server/chunks/9-fc3lKB7X.js +0 -13
  198. package/build/server/chunks/9-fc3lKB7X.js.map +0 -1
  199. package/build/server/chunks/Icon-CG7XnWX5.js +0 -30
  200. package/build/server/chunks/Icon-CG7XnWX5.js.map +0 -1
  201. package/build/server/chunks/Logout-BwzK1P29.js +0 -45
  202. package/build/server/chunks/Logout-BwzK1P29.js.map +0 -1
  203. package/build/server/chunks/_layout.svelte-9KMUotip.js +0 -31
  204. package/build/server/chunks/_layout.svelte-9KMUotip.js.map +0 -1
  205. package/build/server/chunks/_page.svelte-BD3HmLo_.js +0 -28
  206. package/build/server/chunks/_page.svelte-BD3HmLo_.js.map +0 -1
  207. package/build/server/chunks/_page.svelte-BFzPdJ6z.js +0 -105
  208. package/build/server/chunks/_page.svelte-BFzPdJ6z.js.map +0 -1
  209. package/build/server/chunks/_page.svelte-BIxxuzff.js +0 -64
  210. package/build/server/chunks/_page.svelte-BIxxuzff.js.map +0 -1
  211. package/build/server/chunks/_page.svelte-Bou2_u6i.js +0 -13
  212. package/build/server/chunks/_page.svelte-Bou2_u6i.js.map +0 -1
  213. package/build/server/chunks/_page.svelte-C25oQ2NT.js +0 -80
  214. package/build/server/chunks/_page.svelte-C25oQ2NT.js.map +0 -1
  215. package/build/server/chunks/_page.svelte-CAzWL4aq.js +0 -66
  216. package/build/server/chunks/_page.svelte-CAzWL4aq.js.map +0 -1
  217. package/build/server/chunks/_page.svelte-Ci5V-DhL.js +0 -72
  218. package/build/server/chunks/_page.svelte-Ci5V-DhL.js.map +0 -1
  219. package/build/server/chunks/_page.svelte-CnfRSJsl.js +0 -37
  220. package/build/server/chunks/_page.svelte-CnfRSJsl.js.map +0 -1
  221. package/build/server/chunks/_page.svelte-DgyZKeaF.js +0 -231
  222. package/build/server/chunks/_page.svelte-DgyZKeaF.js.map +0 -1
  223. package/build/server/chunks/_page.svelte-VDBvShZ8.js +0 -6
  224. package/build/server/chunks/_page.svelte-VDBvShZ8.js.map +0 -1
  225. package/build/server/chunks/_page.svelte-cAsZlwLs.js +0 -24
  226. package/build/server/chunks/_page.svelte-cAsZlwLs.js.map +0 -1
  227. package/build/server/chunks/_page.svelte-rrN2zFNa.js +0 -66
  228. package/build/server/chunks/_page.svelte-rrN2zFNa.js.map +0 -1
  229. package/build/server/chunks/account-BZSP6KBP.js +0 -445
  230. package/build/server/chunks/account-BZSP6KBP.js.map +0 -1
  231. package/build/server/chunks/color-K_MR7m8s.js +0 -14
  232. package/build/server/chunks/color-K_MR7m8s.js.map +0 -1
  233. package/build/server/chunks/context-R2425nfV.js +0 -64
  234. package/build/server/chunks/context-R2425nfV.js.map +0 -1
  235. package/build/server/chunks/error.svelte-DTrQqomO.js +0 -47
  236. package/build/server/chunks/error.svelte-DTrQqomO.js.map +0 -1
  237. package/build/server/chunks/index-DJrm8BZm.js +0 -844
  238. package/build/server/chunks/index-DJrm8BZm.js.map +0 -1
  239. package/build/server/chunks/index-eKiDBuyI.js +0 -5328
  240. package/build/server/chunks/index-eKiDBuyI.js.map +0 -1
  241. package/build/server/chunks/layout.svelte-UxsTmhKc.js +0 -8
  242. package/build/server/chunks/layout.svelte-UxsTmhKc.js.map +0 -1
  243. package/build/server/chunks/numbers-DL8C9q4W.js +0 -354
  244. package/build/server/chunks/numbers-DL8C9q4W.js.map +0 -1
  245. package/build/server/chunks/user2-Coq3Frtw.js +0 -809
  246. package/build/server/chunks/user2-Coq3Frtw.js.map +0 -1
  247. package/build/server/chunks/utils-DlBYhQz7.js +0 -287
  248. package/build/server/chunks/utils-DlBYhQz7.js.map +0 -1
  249. package/build/server/index.js +0 -7744
  250. package/build/server/index.js.map +0 -1
  251. package/build/server/manifest.js +0 -135
  252. package/build/server/manifest.js.map +0 -1
  253. package/build/shims.js +0 -32
  254. package/dist/apps.d.ts +0 -6
  255. package/dist/apps.js +0 -6
  256. package/dist/plugins.d.ts +0 -14
  257. package/dist/plugins.js +0 -64
  258. /package/{axiumd.service → axium.service} +0 -0
@@ -1,809 +0,0 @@
1
- import { N as bind_props, Q as spread_props, P as attributes, y as attr_class, z as clsx } from './index-DJrm8BZm.js';
2
- import { e as escape_html } from './context-R2425nfV.js';
3
- import { o as object, e as email, d as string, u as uuid, f as prettifyError, $ as $ZodError, U as UserChangeable } from './index-eKiDBuyI.js';
4
-
5
- /**
6
- * Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
7
- * credential response ArrayBuffers to string for sending back to the server as JSON.
8
- *
9
- * Helper method to compliment `base64URLStringToBuffer`
10
- */
11
- function bufferToBase64URLString(buffer) {
12
- const bytes = new Uint8Array(buffer);
13
- let str = '';
14
- for (const charCode of bytes) {
15
- str += String.fromCharCode(charCode);
16
- }
17
- const base64String = btoa(str);
18
- return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
19
- }
20
-
21
- /**
22
- * Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
23
- * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
24
- * excludeCredentials
25
- *
26
- * Helper method to compliment `bufferToBase64URLString`
27
- */
28
- function base64URLStringToBuffer(base64URLString) {
29
- // Convert from Base64URL to Base64
30
- const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
31
- /**
32
- * Pad with '=' until it's a multiple of four
33
- * (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
34
- * (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
35
- * (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
36
- * (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
37
- */
38
- const padLength = (4 - (base64.length % 4)) % 4;
39
- const padded = base64.padEnd(base64.length + padLength, '=');
40
- // Convert to a binary string
41
- const binary = atob(padded);
42
- // Convert binary string to buffer
43
- const buffer = new ArrayBuffer(binary.length);
44
- const bytes = new Uint8Array(buffer);
45
- for (let i = 0; i < binary.length; i++) {
46
- bytes[i] = binary.charCodeAt(i);
47
- }
48
- return buffer;
49
- }
50
-
51
- /**
52
- * Determine if the browser is capable of Webauthn
53
- */
54
- function browserSupportsWebAuthn() {
55
- return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
56
- typeof globalThis.PublicKeyCredential === 'function');
57
- }
58
- /**
59
- * Make it possible to stub the return value during testing
60
- * @ignore Don't include this in docs output
61
- */
62
- const _browserSupportsWebAuthnInternals = {
63
- stubThis: (value) => value,
64
- };
65
-
66
- function toPublicKeyCredentialDescriptor(descriptor) {
67
- const { id } = descriptor;
68
- return {
69
- ...descriptor,
70
- id: base64URLStringToBuffer(id),
71
- /**
72
- * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer
73
- * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
74
- * are fine to pass to WebAuthn since browsers will recognize the new value.
75
- */
76
- transports: descriptor.transports,
77
- };
78
- }
79
-
80
- /**
81
- * A simple test to determine if a hostname is a properly-formatted domain name
82
- *
83
- * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain
84
- *
85
- * Regex sourced from here:
86
- * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html
87
- */
88
- function isValidDomain(hostname) {
89
- return (
90
- // Consider localhost valid as well since it's okay wrt Secure Contexts
91
- hostname === 'localhost' ||
92
- /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
93
- }
94
-
95
- /**
96
- * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
97
- * errors in the spec was raised after calling `navigator.credentials.create()` or
98
- * `navigator.credentials.get()`:
99
- *
100
- * - `AbortError`
101
- * - `ConstraintError`
102
- * - `InvalidStateError`
103
- * - `NotAllowedError`
104
- * - `NotSupportedError`
105
- * - `SecurityError`
106
- * - `TypeError`
107
- * - `UnknownError`
108
- *
109
- * Error messages were determined through investigation of the spec to determine under which
110
- * scenarios a given error would be raised.
111
- */
112
- class WebAuthnError extends Error {
113
- constructor({ message, code, cause, name, }) {
114
- // @ts-ignore: help Rollup understand that `cause` is okay to set
115
- super(message, { cause });
116
- Object.defineProperty(this, "code", {
117
- enumerable: true,
118
- configurable: true,
119
- writable: true,
120
- value: void 0
121
- });
122
- this.name = name ?? cause.name;
123
- this.code = code;
124
- }
125
- }
126
-
127
- /**
128
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
129
- */
130
- function identifyRegistrationError({ error, options, }) {
131
- const { publicKey } = options;
132
- if (!publicKey) {
133
- throw Error('options was missing required publicKey property');
134
- }
135
- if (error.name === 'AbortError') {
136
- if (options.signal instanceof AbortSignal) {
137
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
138
- return new WebAuthnError({
139
- message: 'Registration ceremony was sent an abort signal',
140
- code: 'ERROR_CEREMONY_ABORTED',
141
- cause: error,
142
- });
143
- }
144
- }
145
- else if (error.name === 'ConstraintError') {
146
- if (publicKey.authenticatorSelection?.requireResidentKey === true) {
147
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
148
- return new WebAuthnError({
149
- message: 'Discoverable credentials were required but no available authenticator supported it',
150
- code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
151
- cause: error,
152
- });
153
- }
154
- else if (
155
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
156
- options.mediation === 'conditional' &&
157
- publicKey.authenticatorSelection?.userVerification === 'required') {
158
- // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
159
- return new WebAuthnError({
160
- message: 'User verification was required during automatic registration but it could not be performed',
161
- code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
162
- cause: error,
163
- });
164
- }
165
- else if (publicKey.authenticatorSelection?.userVerification === 'required') {
166
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
167
- return new WebAuthnError({
168
- message: 'User verification was required but no available authenticator supported it',
169
- code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
170
- cause: error,
171
- });
172
- }
173
- }
174
- else if (error.name === 'InvalidStateError') {
175
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
176
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
177
- return new WebAuthnError({
178
- message: 'The authenticator was previously registered',
179
- code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
180
- cause: error,
181
- });
182
- }
183
- else if (error.name === 'NotAllowedError') {
184
- /**
185
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
186
- * defines and we don't want to overwrite potentially useful error messages.
187
- */
188
- return new WebAuthnError({
189
- message: error.message,
190
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
191
- cause: error,
192
- });
193
- }
194
- else if (error.name === 'NotSupportedError') {
195
- const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
196
- if (validPubKeyCredParams.length === 0) {
197
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
198
- return new WebAuthnError({
199
- message: 'No entry in pubKeyCredParams was of type "public-key"',
200
- code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
201
- cause: error,
202
- });
203
- }
204
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
205
- return new WebAuthnError({
206
- message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
207
- code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
208
- cause: error,
209
- });
210
- }
211
- else if (error.name === 'SecurityError') {
212
- const effectiveDomain = globalThis.location.hostname;
213
- if (!isValidDomain(effectiveDomain)) {
214
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
215
- return new WebAuthnError({
216
- message: `${globalThis.location.hostname} is an invalid domain`,
217
- code: 'ERROR_INVALID_DOMAIN',
218
- cause: error,
219
- });
220
- }
221
- else if (publicKey.rp.id !== effectiveDomain) {
222
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
223
- return new WebAuthnError({
224
- message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
225
- code: 'ERROR_INVALID_RP_ID',
226
- cause: error,
227
- });
228
- }
229
- }
230
- else if (error.name === 'TypeError') {
231
- if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
232
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
233
- return new WebAuthnError({
234
- message: 'User ID was not between 1 and 64 characters',
235
- code: 'ERROR_INVALID_USER_ID_LENGTH',
236
- cause: error,
237
- });
238
- }
239
- }
240
- else if (error.name === 'UnknownError') {
241
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
242
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
243
- return new WebAuthnError({
244
- message: 'The authenticator was unable to process the specified options, or could not create a new credential',
245
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
246
- cause: error,
247
- });
248
- }
249
- return error;
250
- }
251
-
252
- class BaseWebAuthnAbortService {
253
- constructor() {
254
- Object.defineProperty(this, "controller", {
255
- enumerable: true,
256
- configurable: true,
257
- writable: true,
258
- value: void 0
259
- });
260
- }
261
- createNewAbortSignal() {
262
- // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
263
- if (this.controller) {
264
- const abortError = new Error('Cancelling existing WebAuthn API call for new one');
265
- abortError.name = 'AbortError';
266
- this.controller.abort(abortError);
267
- }
268
- const newController = new AbortController();
269
- this.controller = newController;
270
- return newController.signal;
271
- }
272
- cancelCeremony() {
273
- if (this.controller) {
274
- const abortError = new Error('Manually cancelling existing WebAuthn API call');
275
- abortError.name = 'AbortError';
276
- this.controller.abort(abortError);
277
- this.controller = undefined;
278
- }
279
- }
280
- }
281
- /**
282
- * A service singleton to help ensure that only a single WebAuthn ceremony is active at a time.
283
- *
284
- * Users of **@simplewebauthn/browser** shouldn't typically need to use this, but it can help e.g.
285
- * developers building projects that use client-side routing to better control the behavior of
286
- * their UX in response to router navigation events.
287
- */
288
- const WebAuthnAbortService = new BaseWebAuthnAbortService();
289
-
290
- const attachments = ['cross-platform', 'platform'];
291
- /**
292
- * If possible coerce a `string` value into a known `AuthenticatorAttachment`
293
- */
294
- function toAuthenticatorAttachment(attachment) {
295
- if (!attachment) {
296
- return;
297
- }
298
- if (attachments.indexOf(attachment) < 0) {
299
- return;
300
- }
301
- return attachment;
302
- }
303
-
304
- /**
305
- * Begin authenticator "registration" via WebAuthn attestation
306
- *
307
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
308
- * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
309
- */
310
- async function startRegistration(options) {
311
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
312
- if (!options.optionsJSON && options.challenge) {
313
- 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.');
314
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
315
- options = { optionsJSON: options };
316
- }
317
- const { optionsJSON, useAutoRegister = false } = options;
318
- if (!browserSupportsWebAuthn()) {
319
- throw new Error('WebAuthn is not supported in this browser');
320
- }
321
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
322
- const publicKey = {
323
- ...optionsJSON,
324
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
325
- user: {
326
- ...optionsJSON.user,
327
- id: base64URLStringToBuffer(optionsJSON.user.id),
328
- },
329
- excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
330
- };
331
- // Prepare options for `.create()`
332
- const createOptions = {};
333
- /**
334
- * Try to use conditional create to register a passkey for the user with the password manager
335
- * the user just used to authenticate with. The user won't be shown any prominent UI by the
336
- * browser.
337
- */
338
- if (useAutoRegister) {
339
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
340
- createOptions.mediation = 'conditional';
341
- }
342
- // Finalize options
343
- createOptions.publicKey = publicKey;
344
- // Set up the ability to cancel this request if the user attempts another
345
- createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
346
- // Wait for the user to complete attestation
347
- let credential;
348
- try {
349
- credential = (await navigator.credentials.create(createOptions));
350
- }
351
- catch (err) {
352
- throw identifyRegistrationError({ error: err, options: createOptions });
353
- }
354
- if (!credential) {
355
- throw new Error('Registration was not completed');
356
- }
357
- const { id, rawId, response, type } = credential;
358
- // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
359
- let transports = undefined;
360
- if (typeof response.getTransports === 'function') {
361
- transports = response.getTransports();
362
- }
363
- // L3 says this is required, but browser and webview support are still not guaranteed.
364
- let responsePublicKeyAlgorithm = undefined;
365
- if (typeof response.getPublicKeyAlgorithm === 'function') {
366
- try {
367
- responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
368
- }
369
- catch (error) {
370
- warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
371
- }
372
- }
373
- let responsePublicKey = undefined;
374
- if (typeof response.getPublicKey === 'function') {
375
- try {
376
- const _publicKey = response.getPublicKey();
377
- if (_publicKey !== null) {
378
- responsePublicKey = bufferToBase64URLString(_publicKey);
379
- }
380
- }
381
- catch (error) {
382
- warnOnBrokenImplementation('getPublicKey()', error);
383
- }
384
- }
385
- // L3 says this is required, but browser and webview support are still not guaranteed.
386
- let responseAuthenticatorData;
387
- if (typeof response.getAuthenticatorData === 'function') {
388
- try {
389
- responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
390
- }
391
- catch (error) {
392
- warnOnBrokenImplementation('getAuthenticatorData()', error);
393
- }
394
- }
395
- return {
396
- id,
397
- rawId: bufferToBase64URLString(rawId),
398
- response: {
399
- attestationObject: bufferToBase64URLString(response.attestationObject),
400
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
401
- transports,
402
- publicKeyAlgorithm: responsePublicKeyAlgorithm,
403
- publicKey: responsePublicKey,
404
- authenticatorData: responseAuthenticatorData,
405
- },
406
- type,
407
- clientExtensionResults: credential.getClientExtensionResults(),
408
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
409
- };
410
- }
411
- /**
412
- * Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
413
- * calls
414
- */
415
- function warnOnBrokenImplementation(methodName, cause) {
416
- console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
417
- }
418
-
419
- /**
420
- * Determine if the browser supports conditional UI, so that WebAuthn credentials can
421
- * be shown to the user in the browser's typical password autofill popup.
422
- */
423
- function browserSupportsWebAuthnAutofill() {
424
- if (!browserSupportsWebAuthn()) {
425
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
426
- }
427
- /**
428
- * I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
429
- * TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
430
- * want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
431
- * have a chance to catch up.
432
- */
433
- const globalPublicKeyCredential = globalThis
434
- .PublicKeyCredential;
435
- if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
436
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
437
- }
438
- return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
439
- }
440
- // Make it possible to stub the return value during testing
441
- const _browserSupportsWebAuthnAutofillInternals = {
442
- stubThis: (value) => value,
443
- };
444
-
445
- /**
446
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
447
- */
448
- function identifyAuthenticationError({ error, options, }) {
449
- const { publicKey } = options;
450
- if (!publicKey) {
451
- throw Error('options was missing required publicKey property');
452
- }
453
- if (error.name === 'AbortError') {
454
- if (options.signal instanceof AbortSignal) {
455
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
456
- return new WebAuthnError({
457
- message: 'Authentication ceremony was sent an abort signal',
458
- code: 'ERROR_CEREMONY_ABORTED',
459
- cause: error,
460
- });
461
- }
462
- }
463
- else if (error.name === 'NotAllowedError') {
464
- /**
465
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
466
- * defines and we don't want to overwrite potentially useful error messages.
467
- */
468
- return new WebAuthnError({
469
- message: error.message,
470
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
471
- cause: error,
472
- });
473
- }
474
- else if (error.name === 'SecurityError') {
475
- const effectiveDomain = globalThis.location.hostname;
476
- if (!isValidDomain(effectiveDomain)) {
477
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
478
- return new WebAuthnError({
479
- message: `${globalThis.location.hostname} is an invalid domain`,
480
- code: 'ERROR_INVALID_DOMAIN',
481
- cause: error,
482
- });
483
- }
484
- else if (publicKey.rpId !== effectiveDomain) {
485
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
486
- return new WebAuthnError({
487
- message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
488
- code: 'ERROR_INVALID_RP_ID',
489
- cause: error,
490
- });
491
- }
492
- }
493
- else if (error.name === 'UnknownError') {
494
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
495
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
496
- return new WebAuthnError({
497
- message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
498
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
499
- cause: error,
500
- });
501
- }
502
- return error;
503
- }
504
-
505
- /**
506
- * Begin authenticator "login" via WebAuthn assertion
507
- *
508
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
509
- * @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
510
- * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
511
- */
512
- async function startAuthentication(options) {
513
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
514
- if (!options.optionsJSON && options.challenge) {
515
- 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.');
516
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
517
- options = { optionsJSON: options };
518
- }
519
- const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
520
- if (!browserSupportsWebAuthn()) {
521
- throw new Error('WebAuthn is not supported in this browser');
522
- }
523
- // We need to avoid passing empty array to avoid blocking retrieval
524
- // of public key
525
- let allowCredentials;
526
- if (optionsJSON.allowCredentials?.length !== 0) {
527
- allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
528
- }
529
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
530
- const publicKey = {
531
- ...optionsJSON,
532
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
533
- allowCredentials,
534
- };
535
- // Prepare options for `.get()`
536
- const getOptions = {};
537
- /**
538
- * Set up the page to prompt the user to select a credential for authentication via the browser's
539
- * input autofill mechanism.
540
- */
541
- if (useBrowserAutofill) {
542
- if (!(await browserSupportsWebAuthnAutofill())) {
543
- throw Error('Browser does not support WebAuthn autofill');
544
- }
545
- // Check for an <input> with "webauthn" in its `autocomplete` attribute
546
- const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
547
- // WebAuthn autofill requires at least one valid input
548
- if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
549
- throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
550
- }
551
- // `CredentialMediationRequirement` doesn't know about "conditional" yet as of
552
- // typescript@4.6.3
553
- getOptions.mediation = 'conditional';
554
- // Conditional UI requires an empty allow list
555
- publicKey.allowCredentials = [];
556
- }
557
- // Finalize options
558
- getOptions.publicKey = publicKey;
559
- // Set up the ability to cancel this request if the user attempts another
560
- getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
561
- // Wait for the user to complete assertion
562
- let credential;
563
- try {
564
- credential = (await navigator.credentials.get(getOptions));
565
- }
566
- catch (err) {
567
- throw identifyAuthenticationError({ error: err, options: getOptions });
568
- }
569
- if (!credential) {
570
- throw new Error('Authentication was not completed');
571
- }
572
- const { id, rawId, response, type } = credential;
573
- let userHandle = undefined;
574
- if (response.userHandle) {
575
- userHandle = bufferToBase64URLString(response.userHandle);
576
- }
577
- // Convert values to base64 to make it easier to send back to the server
578
- return {
579
- id,
580
- rawId: bufferToBase64URLString(rawId),
581
- response: {
582
- authenticatorData: bufferToBase64URLString(response.authenticatorData),
583
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
584
- signature: bufferToBase64URLString(response.signature),
585
- userHandle,
586
- },
587
- type,
588
- clientExtensionResults: credential.getClientExtensionResults(),
589
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
590
- };
591
- }
592
-
593
- const $$css$1 = {
594
- hash: "svelte-1bkt9ng",
595
- code: "dialog.svelte-1bkt9ng {border-radius:1em;background:var(--bg-menu);border:1px solid #8888;padding:1em;}dialog.svelte-1bkt9ng::backdrop {background:#0003;}dialog[open].svelte-1bkt9ng {\n animation: svelte-1bkt9ng-zoom 0.25s cubic-bezier(0.35, 1.55, 0.65, 1);}\n\n @keyframes svelte-1bkt9ng-zoom {\n from {\n transform: scale(0.95);\n }\n to {\n transform: scale(1);\n }\n }dialog[open].svelte-1bkt9ng::backdrop {\n animation: svelte-1bkt9ng-fade 0.25s ease-out;}\n\n @keyframes svelte-1bkt9ng-fade {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n }"
596
- };
597
- function Dialog($$renderer, $$props) {
598
- $$renderer.global.css.add($$css$1);
599
- $$renderer.component(($$renderer2) => {
600
- let { children, dialog = void 0, $$slots, $$events, ...rest } = $$props;
601
- $$renderer2.push(`<dialog${attributes({ ...rest }, "svelte-1bkt9ng")}>`);
602
- children($$renderer2);
603
- $$renderer2.push(`<!----></dialog>`);
604
- bind_props($$props, { dialog });
605
- });
606
- }
607
- const $$css = {
608
- hash: "svelte-m5w2se",
609
- code: ".actions.svelte-m5w2se {display:flex;gap:1em;flex-direction:row;justify-content:space-between;}"
610
- };
611
- function FormDialog($$renderer, $$props) {
612
- $$renderer.global.css.add($$css);
613
- $$renderer.component(($$renderer2) => {
614
- let {
615
- children,
616
- dialog = void 0,
617
- submitText = "Submit",
618
- cancel = () => {
619
- },
620
- submit = (data) => Promise.resolve(),
621
- pageMode = false,
622
- submitDanger = false,
623
- header,
624
- footer,
625
- $$slots,
626
- $$events,
627
- ...rest
628
- /** Change the text displayed for the submit button */
629
- /** Basically a callback for when the dialog is canceled */
630
- /** Called on submission, this should do the actual submission */
631
- /** Whether to display the dialog as a full-page form */
632
- } = $$props;
633
- function onclose(e) {
634
- e.preventDefault();
635
- cancel();
636
- }
637
- function submitButton($$renderer3) {
638
- $$renderer3.push(`<button type="submit"${attr_class(clsx(["submit", submitDanger && "danger"]))}>${escape_html(submitText)}</button>`);
639
- }
640
- let $$settled = true;
641
- let $$inner_renderer;
642
- function $$render_inner($$renderer3) {
643
- Dialog($$renderer3, spread_props([
644
- { onclose },
645
- rest,
646
- {
647
- get dialog() {
648
- return dialog;
649
- },
650
- set dialog($$value) {
651
- dialog = $$value;
652
- $$settled = false;
653
- },
654
- children: ($$renderer4) => {
655
- header?.($$renderer4);
656
- $$renderer4.push(`<!----> <form class="main" method="dialog">`);
657
- {
658
- $$renderer4.push("<!--[!-->");
659
- }
660
- $$renderer4.push(`<!--]--> `);
661
- children($$renderer4);
662
- $$renderer4.push(`<!----> `);
663
- if (pageMode) {
664
- $$renderer4.push("<!--[-->");
665
- submitButton($$renderer4);
666
- } else {
667
- $$renderer4.push("<!--[!-->");
668
- $$renderer4.push(`<div class="actions svelte-m5w2se"><button type="button">Cancel</button> `);
669
- submitButton($$renderer4);
670
- $$renderer4.push(`<!----></div>`);
671
- }
672
- $$renderer4.push(`<!--]--></form> `);
673
- footer?.($$renderer4);
674
- $$renderer4.push(`<!---->`);
675
- },
676
- $$slots: { default: true }
677
- }
678
- ]));
679
- }
680
- do {
681
- $$settled = true;
682
- $$inner_renderer = $$renderer2.copy();
683
- $$render_inner($$inner_renderer);
684
- } while (!$$settled);
685
- $$renderer2.subsume($$inner_renderer);
686
- bind_props($$props, { dialog });
687
- });
688
- }
689
-
690
- let prefix = "/api/";
691
- async function fetchAPI(method, endpoint, data, ...params) {
692
- const options = {
693
- method,
694
- headers: {
695
- "Content-Type": "application/json",
696
- Accept: "application/json"
697
- }
698
- };
699
- if (method !== "GET" && method !== "HEAD")
700
- options.body = JSON.stringify(data);
701
- const search = method != "GET" || typeof data != "object" || data == null || !Object.keys(data).length ? "" : "?" + new URLSearchParams(data).toString();
702
- const parts = [];
703
- for (const part of endpoint.split("/")) {
704
- if (!part.startsWith(":")) {
705
- parts.push(part);
706
- continue;
707
- }
708
- const value = params.shift();
709
- if (!value)
710
- throw new Error(`Missing parameter "${part.slice(1)}"`);
711
- parts.push(value);
712
- }
713
- const response = await fetch(prefix + parts.join("/") + search, options);
714
- if (!response.headers.get("Content-Type")?.includes("application/json")) {
715
- throw new Error(`Unexpected response type: ${response.headers.get("Content-Type")}`);
716
- }
717
- const json = await response.json().catch(() => ({ message: "Unknown server error (invalid JSON response)" }));
718
- if (!response.ok)
719
- throw new Error(json.message);
720
- return json;
721
- }
722
-
723
- async function login(userId) {
724
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "login" }, userId);
725
- const response = await startAuthentication({ optionsJSON: options });
726
- return await fetchAPI("POST", "users/:id/auth", response, userId);
727
- }
728
- async function elevate(userId) {
729
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
730
- const response = await startAuthentication({ optionsJSON: options });
731
- await fetchAPI("POST", "users/:id/auth", response, userId);
732
- }
733
- async function loginByEmail(email) {
734
- const { id: userId } = await fetchAPI("POST", "user_id", {
735
- using: "email",
736
- value: email
737
- });
738
- return await login(userId);
739
- }
740
- async function logout(userId, ...sessionId) {
741
- _checkId(userId);
742
- const result = await fetchAPI("DELETE", "users/:id/sessions", { id: sessionId }, userId);
743
- for (const session of result) {
744
- session.created = new Date(session.created);
745
- session.expires = new Date(session.expires);
746
- }
747
- return result;
748
- }
749
- async function logoutAll(userId) {
750
- _checkId(userId);
751
- await elevate(userId);
752
- const result = await fetchAPI("DELETE", "users/:id/sessions", { confirm_all: true }, userId);
753
- for (const session of result) {
754
- session.created = new Date(session.created);
755
- session.expires = new Date(session.expires);
756
- }
757
- return result;
758
- }
759
- async function logoutCurrentSession() {
760
- return await fetchAPI("DELETE", "session");
761
- }
762
- async function register(_data) {
763
- const data = object({ name: string(), email: email() }).parse(_data);
764
- const { options, userId } = await fetchAPI("OPTIONS", "register", data);
765
- const response = await startRegistration({ optionsJSON: options });
766
- await fetchAPI("POST", "register", {
767
- userId,
768
- name: data.name,
769
- email: data.email,
770
- response
771
- });
772
- }
773
- function _checkId(userId) {
774
- try {
775
- uuid().parse(userId);
776
- } catch (e) {
777
- throw e instanceof $ZodError ? prettifyError(e) : e;
778
- }
779
- }
780
- async function updateUser(userId, data) {
781
- _checkId(userId);
782
- const body = await UserChangeable.parseAsync(data).catch((e) => {
783
- throw e instanceof $ZodError ? prettifyError(e) : e;
784
- });
785
- const result = await fetchAPI("PATCH", "users/:id", body, userId);
786
- result.registeredAt = new Date(result.registeredAt);
787
- if (result.emailVerified)
788
- result.emailVerified = new Date(result.emailVerified);
789
- return result;
790
- }
791
- async function deleteUser(userId) {
792
- _checkId(userId);
793
- const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
794
- const response = await startAuthentication({ optionsJSON: options });
795
- await fetchAPI("POST", "users/:id/auth", response, userId);
796
- const result = await fetchAPI("DELETE", "users/:id", response, userId);
797
- result.registeredAt = new Date(result.registeredAt);
798
- result.emailVerified = new Date(result.emailVerified);
799
- return result;
800
- }
801
- async function updatePasskey(passkeyId, data) {
802
- return await fetchAPI("PATCH", "passkeys/:id", data, passkeyId);
803
- }
804
- async function deletePasskey(passkeyId) {
805
- return await fetchAPI("DELETE", "passkeys/:id", {}, passkeyId);
806
- }
807
-
808
- export { FormDialog as F, deletePasskey as a, updateUser as b, logoutAll as c, deleteUser as d, loginByEmail as e, logoutCurrentSession as f, logout as l, register as r, updatePasskey as u };
809
- //# sourceMappingURL=user2-Coq3Frtw.js.map