@axium/server 0.13.0 → 0.13.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 (160) hide show
  1. package/build/client/_app/immutable/assets/4.C58W2qGZ.css +1 -0
  2. package/build/client/_app/immutable/assets/4.C58W2qGZ.css.br +0 -0
  3. package/build/client/_app/immutable/assets/4.C58W2qGZ.css.gz +0 -0
  4. package/build/client/_app/immutable/assets/_page.C58W2qGZ.css +1 -0
  5. package/build/client/_app/immutable/assets/_page.C58W2qGZ.css.br +0 -0
  6. package/build/client/_app/immutable/assets/_page.C58W2qGZ.css.gz +0 -0
  7. package/build/client/_app/immutable/chunks/{CVa83dr8.js → 1J1OrtJW.js} +1 -1
  8. package/build/client/_app/immutable/chunks/1J1OrtJW.js.br +0 -0
  9. package/build/client/_app/immutable/chunks/1J1OrtJW.js.gz +0 -0
  10. package/build/client/_app/immutable/chunks/BStPPX1X.js +33 -0
  11. package/build/client/_app/immutable/chunks/BStPPX1X.js.br +0 -0
  12. package/build/client/_app/immutable/chunks/BStPPX1X.js.gz +0 -0
  13. package/build/client/_app/immutable/chunks/{hjeMeV6C.js → BmyAb9RG.js} +1 -1
  14. package/build/client/_app/immutable/chunks/BmyAb9RG.js.br +2 -0
  15. package/build/client/_app/immutable/chunks/BmyAb9RG.js.gz +0 -0
  16. package/build/client/_app/immutable/chunks/{Bb1FLBYy.js → BylUy_Y5.js} +1 -1
  17. package/build/client/_app/immutable/chunks/BylUy_Y5.js.br +0 -0
  18. package/build/client/_app/immutable/chunks/BylUy_Y5.js.gz +0 -0
  19. package/build/client/_app/immutable/chunks/{D1Bh_mwl.js → CeESZvTN.js} +1 -1
  20. package/build/client/_app/immutable/chunks/CeESZvTN.js.br +0 -0
  21. package/build/client/_app/immutable/chunks/{D1Bh_mwl.js.gz → CeESZvTN.js.gz} +0 -0
  22. package/build/client/_app/immutable/chunks/{DsTLXD2g.js → CtXEx3cs.js} +1 -1
  23. package/build/client/_app/immutable/chunks/CtXEx3cs.js.br +0 -0
  24. package/build/client/_app/immutable/chunks/CtXEx3cs.js.gz +0 -0
  25. package/build/client/_app/immutable/chunks/{DiwI9kUA.js → _m3Oacli.js} +2 -2
  26. package/build/client/_app/immutable/chunks/_m3Oacli.js.br +0 -0
  27. package/build/client/_app/immutable/chunks/_m3Oacli.js.gz +0 -0
  28. package/build/client/_app/immutable/entry/{app.Bj9AgMfp.js → app.BUuJx2IM.js} +2 -2
  29. package/build/client/_app/immutable/entry/app.BUuJx2IM.js.br +0 -0
  30. package/build/client/_app/immutable/entry/app.BUuJx2IM.js.gz +0 -0
  31. package/build/client/_app/immutable/entry/start.iGYwuSbX.js +1 -0
  32. package/build/client/_app/immutable/entry/start.iGYwuSbX.js.br +2 -0
  33. package/build/client/_app/immutable/entry/start.iGYwuSbX.js.gz +0 -0
  34. package/build/client/_app/immutable/nodes/{0.B5tIZ8Ux.js → 0.C8tUtue5.js} +1 -1
  35. package/build/client/_app/immutable/nodes/0.C8tUtue5.js.br +0 -0
  36. package/build/client/_app/immutable/nodes/0.C8tUtue5.js.gz +0 -0
  37. package/build/client/_app/immutable/nodes/{1.CgvMyPD2.js → 1.DjF4CgFu.js} +1 -1
  38. package/build/client/_app/immutable/nodes/1.DjF4CgFu.js.br +0 -0
  39. package/build/client/_app/immutable/nodes/1.DjF4CgFu.js.gz +0 -0
  40. package/build/client/_app/immutable/nodes/{2.CxWCdWnk.js → 2.B9G2lbYt.js} +1 -1
  41. package/build/client/_app/immutable/nodes/2.B9G2lbYt.js.br +0 -0
  42. package/build/client/_app/immutable/nodes/2.B9G2lbYt.js.gz +0 -0
  43. package/build/client/_app/immutable/nodes/3.8VcoGzOR.js +1 -0
  44. package/build/client/_app/immutable/nodes/3.8VcoGzOR.js.br +0 -0
  45. package/build/client/_app/immutable/nodes/3.8VcoGzOR.js.gz +0 -0
  46. package/build/client/_app/immutable/nodes/4.BMtEyD0W.js +1 -0
  47. package/build/client/_app/immutable/nodes/4.BMtEyD0W.js.br +0 -0
  48. package/build/client/_app/immutable/nodes/4.BMtEyD0W.js.gz +0 -0
  49. package/build/client/_app/immutable/nodes/5.DieY10_D.js +1 -0
  50. package/build/client/_app/immutable/nodes/5.DieY10_D.js.br +0 -0
  51. package/build/client/_app/immutable/nodes/5.DieY10_D.js.gz +0 -0
  52. package/build/client/_app/immutable/nodes/6.CKg5IGgw.js +1 -0
  53. package/build/client/_app/immutable/nodes/6.CKg5IGgw.js.br +0 -0
  54. package/build/client/_app/immutable/nodes/6.CKg5IGgw.js.gz +0 -0
  55. package/build/client/_app/version.json +1 -1
  56. package/build/client/_app/version.json.br +0 -0
  57. package/build/client/_app/version.json.gz +0 -0
  58. package/build/server/chunks/{0-DoFQPg1a.js → 0-7meuaxFL.js} +2 -2
  59. package/build/server/chunks/{0-DoFQPg1a.js.map → 0-7meuaxFL.js.map} +1 -1
  60. package/build/server/chunks/1-D6sNqsBB.js +9 -0
  61. package/build/server/chunks/{1-BWAH9TGW.js.map → 1-D6sNqsBB.js.map} +1 -1
  62. package/build/server/chunks/{2-D6Jxv35X.js → 2-D6R7j0yL.js} +2 -2
  63. package/build/server/chunks/{2-D6Jxv35X.js.map → 2-D6R7j0yL.js.map} +1 -1
  64. package/build/server/chunks/3-BNC7Q4g9.js +9 -0
  65. package/build/server/chunks/3-BNC7Q4g9.js.map +1 -0
  66. package/build/server/chunks/4-BNHaP8Im.js +9 -0
  67. package/build/server/chunks/4-BNHaP8Im.js.map +1 -0
  68. package/build/server/chunks/5-BB5f8Gql.js +9 -0
  69. package/build/server/chunks/5-BB5f8Gql.js.map +1 -0
  70. package/build/server/chunks/6-DxBM08_q.js +9 -0
  71. package/build/server/chunks/6-DxBM08_q.js.map +1 -0
  72. package/build/server/chunks/_page.svelte-BAUPxESW.js +63 -0
  73. package/build/server/chunks/_page.svelte-BAUPxESW.js.map +1 -0
  74. package/build/server/chunks/{_page.svelte-BWZAX8uM.js → _page.svelte-DMz-kLOp.js} +3 -5
  75. package/build/server/chunks/_page.svelte-DMz-kLOp.js.map +1 -0
  76. package/build/server/chunks/_page.svelte-DTZhNKFJ.js +49 -0
  77. package/build/server/chunks/_page.svelte-DTZhNKFJ.js.map +1 -0
  78. package/build/server/chunks/_page.svelte-Dcb0jVNv.js +57 -0
  79. package/build/server/chunks/_page.svelte-Dcb0jVNv.js.map +1 -0
  80. package/build/server/chunks/{client2-CDtZFfLJ.js → client-BwGZz7hC.js} +5 -2
  81. package/build/server/chunks/client-BwGZz7hC.js.map +1 -0
  82. package/build/server/chunks/{error.svelte-xp9OLkmb.js → error.svelte-Cp6qBRXj.js} +2 -3
  83. package/build/server/chunks/{error.svelte-xp9OLkmb.js.map → error.svelte-Cp6qBRXj.js.map} +1 -1
  84. package/build/server/chunks/{user2-D249re2A.js → user-BM1CPpSk.js} +818 -2
  85. package/build/server/chunks/user-BM1CPpSk.js.map +1 -0
  86. package/build/server/index.js +1 -1
  87. package/build/server/index.js.map +1 -1
  88. package/build/server/manifest.js +8 -8
  89. package/build/server/manifest.js.map +1 -1
  90. package/package.json +1 -1
  91. package/routes/logout/+page.svelte +2 -10
  92. package/web/lib/FormDialog.svelte +6 -0
  93. package/web/lib/Login.svelte +16 -1
  94. package/web/lib/Logout.svelte +20 -0
  95. package/web/lib/Register.svelte +16 -1
  96. package/build/client/_app/immutable/assets/FormDialog.Cbakz6hh.css +0 -1
  97. package/build/client/_app/immutable/assets/FormDialog.Cbakz6hh.css.br +0 -0
  98. package/build/client/_app/immutable/assets/FormDialog.Cbakz6hh.css.gz +0 -0
  99. package/build/client/_app/immutable/chunks/BTL0bUBR.js +0 -2
  100. package/build/client/_app/immutable/chunks/BTL0bUBR.js.br +0 -0
  101. package/build/client/_app/immutable/chunks/BTL0bUBR.js.gz +0 -0
  102. package/build/client/_app/immutable/chunks/Bb1FLBYy.js.br +0 -0
  103. package/build/client/_app/immutable/chunks/Bb1FLBYy.js.gz +0 -0
  104. package/build/client/_app/immutable/chunks/CVa83dr8.js.br +0 -0
  105. package/build/client/_app/immutable/chunks/CVa83dr8.js.gz +0 -0
  106. package/build/client/_app/immutable/chunks/D1Bh_mwl.js.br +0 -0
  107. package/build/client/_app/immutable/chunks/DiwI9kUA.js.br +0 -0
  108. package/build/client/_app/immutable/chunks/DiwI9kUA.js.gz +0 -0
  109. package/build/client/_app/immutable/chunks/DsTLXD2g.js.br +0 -0
  110. package/build/client/_app/immutable/chunks/DsTLXD2g.js.gz +0 -0
  111. package/build/client/_app/immutable/chunks/e8wRVKCT.js +0 -32
  112. package/build/client/_app/immutable/chunks/e8wRVKCT.js.br +0 -0
  113. package/build/client/_app/immutable/chunks/e8wRVKCT.js.gz +0 -0
  114. package/build/client/_app/immutable/chunks/hjeMeV6C.js.br +0 -4
  115. package/build/client/_app/immutable/chunks/hjeMeV6C.js.gz +0 -0
  116. package/build/client/_app/immutable/entry/app.Bj9AgMfp.js.br +0 -0
  117. package/build/client/_app/immutable/entry/app.Bj9AgMfp.js.gz +0 -0
  118. package/build/client/_app/immutable/entry/start.D3D0blII.js +0 -1
  119. package/build/client/_app/immutable/entry/start.D3D0blII.js.br +0 -2
  120. package/build/client/_app/immutable/entry/start.D3D0blII.js.gz +0 -0
  121. package/build/client/_app/immutable/nodes/0.B5tIZ8Ux.js.br +0 -0
  122. package/build/client/_app/immutable/nodes/0.B5tIZ8Ux.js.gz +0 -0
  123. package/build/client/_app/immutable/nodes/1.CgvMyPD2.js.br +0 -0
  124. package/build/client/_app/immutable/nodes/1.CgvMyPD2.js.gz +0 -0
  125. package/build/client/_app/immutable/nodes/2.CxWCdWnk.js.br +0 -0
  126. package/build/client/_app/immutable/nodes/2.CxWCdWnk.js.gz +0 -0
  127. package/build/client/_app/immutable/nodes/3.Cxnd1eBj.js +0 -1
  128. package/build/client/_app/immutable/nodes/3.Cxnd1eBj.js.br +0 -0
  129. package/build/client/_app/immutable/nodes/3.Cxnd1eBj.js.gz +0 -0
  130. package/build/client/_app/immutable/nodes/4.BBmDy2XN.js +0 -1
  131. package/build/client/_app/immutable/nodes/4.BBmDy2XN.js.br +0 -0
  132. package/build/client/_app/immutable/nodes/4.BBmDy2XN.js.gz +0 -0
  133. package/build/client/_app/immutable/nodes/5.Dji23mCj.js +0 -1
  134. package/build/client/_app/immutable/nodes/5.Dji23mCj.js.br +0 -0
  135. package/build/client/_app/immutable/nodes/5.Dji23mCj.js.gz +0 -0
  136. package/build/client/_app/immutable/nodes/6.C0l7G2Ig.js +0 -1
  137. package/build/client/_app/immutable/nodes/6.C0l7G2Ig.js.br +0 -0
  138. package/build/client/_app/immutable/nodes/6.C0l7G2Ig.js.gz +0 -0
  139. package/build/server/chunks/1-BWAH9TGW.js +0 -9
  140. package/build/server/chunks/3-Cgt_tntw.js +0 -9
  141. package/build/server/chunks/3-Cgt_tntw.js.map +0 -1
  142. package/build/server/chunks/4-jkxSmP_D.js +0 -9
  143. package/build/server/chunks/4-jkxSmP_D.js.map +0 -1
  144. package/build/server/chunks/5-D2gy-tmt.js +0 -9
  145. package/build/server/chunks/5-D2gy-tmt.js.map +0 -1
  146. package/build/server/chunks/6-CN2cq92f.js +0 -9
  147. package/build/server/chunks/6-CN2cq92f.js.map +0 -1
  148. package/build/server/chunks/_page.svelte-BWZAX8uM.js.map +0 -1
  149. package/build/server/chunks/_page.svelte-CDrMZ0qp.js +0 -47
  150. package/build/server/chunks/_page.svelte-CDrMZ0qp.js.map +0 -1
  151. package/build/server/chunks/_page.svelte-DNN9oylU.js +0 -53
  152. package/build/server/chunks/_page.svelte-DNN9oylU.js.map +0 -1
  153. package/build/server/chunks/_page.svelte-DRiG-AM0.js +0 -15
  154. package/build/server/chunks/_page.svelte-DRiG-AM0.js.map +0 -1
  155. package/build/server/chunks/client-Bm0tawqd.js +0 -6
  156. package/build/server/chunks/client-Bm0tawqd.js.map +0 -1
  157. package/build/server/chunks/client2-CDtZFfLJ.js.map +0 -1
  158. package/build/server/chunks/user-Bf_pHH7Y.js +0 -813
  159. package/build/server/chunks/user-Bf_pHH7Y.js.map +0 -1
  160. package/build/server/chunks/user2-D249re2A.js.map +0 -1
@@ -1,3 +1,594 @@
1
+ import { P as push, a7 as copy_payload, a8 as assign_payload, ag as bind_props, T as pop, ah as spread_props, ai as spread_attributes, aj as attr_class, a5 as escape_html, ak as clsx } from './exports-Bdi6Ec6W.js';
2
+ import './client-BwGZz7hC.js';
3
+
4
+ /**
5
+ * Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
6
+ * credential response ArrayBuffers to string for sending back to the server as JSON.
7
+ *
8
+ * Helper method to compliment `base64URLStringToBuffer`
9
+ */
10
+ function bufferToBase64URLString(buffer) {
11
+ const bytes = new Uint8Array(buffer);
12
+ let str = '';
13
+ for (const charCode of bytes) {
14
+ str += String.fromCharCode(charCode);
15
+ }
16
+ const base64String = btoa(str);
17
+ return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
18
+ }
19
+
20
+ /**
21
+ * Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
22
+ * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
23
+ * excludeCredentials
24
+ *
25
+ * Helper method to compliment `bufferToBase64URLString`
26
+ */
27
+ function base64URLStringToBuffer(base64URLString) {
28
+ // Convert from Base64URL to Base64
29
+ const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
30
+ /**
31
+ * Pad with '=' until it's a multiple of four
32
+ * (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
33
+ * (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
34
+ * (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
35
+ * (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
36
+ */
37
+ const padLength = (4 - (base64.length % 4)) % 4;
38
+ const padded = base64.padEnd(base64.length + padLength, '=');
39
+ // Convert to a binary string
40
+ const binary = atob(padded);
41
+ // Convert binary string to buffer
42
+ const buffer = new ArrayBuffer(binary.length);
43
+ const bytes = new Uint8Array(buffer);
44
+ for (let i = 0; i < binary.length; i++) {
45
+ bytes[i] = binary.charCodeAt(i);
46
+ }
47
+ return buffer;
48
+ }
49
+
50
+ /**
51
+ * Determine if the browser is capable of Webauthn
52
+ */
53
+ function browserSupportsWebAuthn() {
54
+ return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
55
+ typeof globalThis.PublicKeyCredential === 'function');
56
+ }
57
+ /**
58
+ * Make it possible to stub the return value during testing
59
+ * @ignore Don't include this in docs output
60
+ */
61
+ const _browserSupportsWebAuthnInternals = {
62
+ stubThis: (value) => value,
63
+ };
64
+
65
+ function toPublicKeyCredentialDescriptor(descriptor) {
66
+ const { id } = descriptor;
67
+ return {
68
+ ...descriptor,
69
+ id: base64URLStringToBuffer(id),
70
+ /**
71
+ * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer
72
+ * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
73
+ * are fine to pass to WebAuthn since browsers will recognize the new value.
74
+ */
75
+ transports: descriptor.transports,
76
+ };
77
+ }
78
+
79
+ /**
80
+ * A simple test to determine if a hostname is a properly-formatted domain name
81
+ *
82
+ * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain
83
+ *
84
+ * Regex sourced from here:
85
+ * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html
86
+ */
87
+ function isValidDomain(hostname) {
88
+ return (
89
+ // Consider localhost valid as well since it's okay wrt Secure Contexts
90
+ hostname === 'localhost' ||
91
+ /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
92
+ }
93
+
94
+ /**
95
+ * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
96
+ * errors in the spec was raised after calling `navigator.credentials.create()` or
97
+ * `navigator.credentials.get()`:
98
+ *
99
+ * - `AbortError`
100
+ * - `ConstraintError`
101
+ * - `InvalidStateError`
102
+ * - `NotAllowedError`
103
+ * - `NotSupportedError`
104
+ * - `SecurityError`
105
+ * - `TypeError`
106
+ * - `UnknownError`
107
+ *
108
+ * Error messages were determined through investigation of the spec to determine under which
109
+ * scenarios a given error would be raised.
110
+ */
111
+ class WebAuthnError extends Error {
112
+ constructor({ message, code, cause, name, }) {
113
+ // @ts-ignore: help Rollup understand that `cause` is okay to set
114
+ super(message, { cause });
115
+ Object.defineProperty(this, "code", {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ this.name = name ?? cause.name;
122
+ this.code = code;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
128
+ */
129
+ function identifyRegistrationError({ error, options, }) {
130
+ const { publicKey } = options;
131
+ if (!publicKey) {
132
+ throw Error('options was missing required publicKey property');
133
+ }
134
+ if (error.name === 'AbortError') {
135
+ if (options.signal instanceof AbortSignal) {
136
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
137
+ return new WebAuthnError({
138
+ message: 'Registration ceremony was sent an abort signal',
139
+ code: 'ERROR_CEREMONY_ABORTED',
140
+ cause: error,
141
+ });
142
+ }
143
+ }
144
+ else if (error.name === 'ConstraintError') {
145
+ if (publicKey.authenticatorSelection?.requireResidentKey === true) {
146
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
147
+ return new WebAuthnError({
148
+ message: 'Discoverable credentials were required but no available authenticator supported it',
149
+ code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
150
+ cause: error,
151
+ });
152
+ }
153
+ else if (
154
+ // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
155
+ options.mediation === 'conditional' &&
156
+ publicKey.authenticatorSelection?.userVerification === 'required') {
157
+ // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
158
+ return new WebAuthnError({
159
+ message: 'User verification was required during automatic registration but it could not be performed',
160
+ code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
161
+ cause: error,
162
+ });
163
+ }
164
+ else if (publicKey.authenticatorSelection?.userVerification === 'required') {
165
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
166
+ return new WebAuthnError({
167
+ message: 'User verification was required but no available authenticator supported it',
168
+ code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
169
+ cause: error,
170
+ });
171
+ }
172
+ }
173
+ else if (error.name === 'InvalidStateError') {
174
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
175
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
176
+ return new WebAuthnError({
177
+ message: 'The authenticator was previously registered',
178
+ code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
179
+ cause: error,
180
+ });
181
+ }
182
+ else if (error.name === 'NotAllowedError') {
183
+ /**
184
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
185
+ * defines and we don't want to overwrite potentially useful error messages.
186
+ */
187
+ return new WebAuthnError({
188
+ message: error.message,
189
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
190
+ cause: error,
191
+ });
192
+ }
193
+ else if (error.name === 'NotSupportedError') {
194
+ const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
195
+ if (validPubKeyCredParams.length === 0) {
196
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
197
+ return new WebAuthnError({
198
+ message: 'No entry in pubKeyCredParams was of type "public-key"',
199
+ code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
200
+ cause: error,
201
+ });
202
+ }
203
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
204
+ return new WebAuthnError({
205
+ message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
206
+ code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
207
+ cause: error,
208
+ });
209
+ }
210
+ else if (error.name === 'SecurityError') {
211
+ const effectiveDomain = globalThis.location.hostname;
212
+ if (!isValidDomain(effectiveDomain)) {
213
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
214
+ return new WebAuthnError({
215
+ message: `${globalThis.location.hostname} is an invalid domain`,
216
+ code: 'ERROR_INVALID_DOMAIN',
217
+ cause: error,
218
+ });
219
+ }
220
+ else if (publicKey.rp.id !== effectiveDomain) {
221
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
222
+ return new WebAuthnError({
223
+ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
224
+ code: 'ERROR_INVALID_RP_ID',
225
+ cause: error,
226
+ });
227
+ }
228
+ }
229
+ else if (error.name === 'TypeError') {
230
+ if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
231
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
232
+ return new WebAuthnError({
233
+ message: 'User ID was not between 1 and 64 characters',
234
+ code: 'ERROR_INVALID_USER_ID_LENGTH',
235
+ cause: error,
236
+ });
237
+ }
238
+ }
239
+ else if (error.name === 'UnknownError') {
240
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
241
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
242
+ return new WebAuthnError({
243
+ message: 'The authenticator was unable to process the specified options, or could not create a new credential',
244
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
245
+ cause: error,
246
+ });
247
+ }
248
+ return error;
249
+ }
250
+
251
+ class BaseWebAuthnAbortService {
252
+ constructor() {
253
+ Object.defineProperty(this, "controller", {
254
+ enumerable: true,
255
+ configurable: true,
256
+ writable: true,
257
+ value: void 0
258
+ });
259
+ }
260
+ createNewAbortSignal() {
261
+ // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
262
+ if (this.controller) {
263
+ const abortError = new Error('Cancelling existing WebAuthn API call for new one');
264
+ abortError.name = 'AbortError';
265
+ this.controller.abort(abortError);
266
+ }
267
+ const newController = new AbortController();
268
+ this.controller = newController;
269
+ return newController.signal;
270
+ }
271
+ cancelCeremony() {
272
+ if (this.controller) {
273
+ const abortError = new Error('Manually cancelling existing WebAuthn API call');
274
+ abortError.name = 'AbortError';
275
+ this.controller.abort(abortError);
276
+ this.controller = undefined;
277
+ }
278
+ }
279
+ }
280
+ /**
281
+ * A service singleton to help ensure that only a single WebAuthn ceremony is active at a time.
282
+ *
283
+ * Users of **@simplewebauthn/browser** shouldn't typically need to use this, but it can help e.g.
284
+ * developers building projects that use client-side routing to better control the behavior of
285
+ * their UX in response to router navigation events.
286
+ */
287
+ const WebAuthnAbortService = new BaseWebAuthnAbortService();
288
+
289
+ const attachments = ['cross-platform', 'platform'];
290
+ /**
291
+ * If possible coerce a `string` value into a known `AuthenticatorAttachment`
292
+ */
293
+ function toAuthenticatorAttachment(attachment) {
294
+ if (!attachment) {
295
+ return;
296
+ }
297
+ if (attachments.indexOf(attachment) < 0) {
298
+ return;
299
+ }
300
+ return attachment;
301
+ }
302
+
303
+ /**
304
+ * Begin authenticator "registration" via WebAuthn attestation
305
+ *
306
+ * @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
307
+ * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
308
+ */
309
+ async function startRegistration(options) {
310
+ // @ts-ignore: Intentionally check for old call structure to warn about improper API call
311
+ if (!options.optionsJSON && options.challenge) {
312
+ 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.');
313
+ // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
314
+ options = { optionsJSON: options };
315
+ }
316
+ const { optionsJSON, useAutoRegister = false } = options;
317
+ if (!browserSupportsWebAuthn()) {
318
+ throw new Error('WebAuthn is not supported in this browser');
319
+ }
320
+ // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
321
+ const publicKey = {
322
+ ...optionsJSON,
323
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
324
+ user: {
325
+ ...optionsJSON.user,
326
+ id: base64URLStringToBuffer(optionsJSON.user.id),
327
+ },
328
+ excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
329
+ };
330
+ // Prepare options for `.create()`
331
+ const createOptions = {};
332
+ /**
333
+ * Try to use conditional create to register a passkey for the user with the password manager
334
+ * the user just used to authenticate with. The user won't be shown any prominent UI by the
335
+ * browser.
336
+ */
337
+ if (useAutoRegister) {
338
+ // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
339
+ createOptions.mediation = 'conditional';
340
+ }
341
+ // Finalize options
342
+ createOptions.publicKey = publicKey;
343
+ // Set up the ability to cancel this request if the user attempts another
344
+ createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
345
+ // Wait for the user to complete attestation
346
+ let credential;
347
+ try {
348
+ credential = (await navigator.credentials.create(createOptions));
349
+ }
350
+ catch (err) {
351
+ throw identifyRegistrationError({ error: err, options: createOptions });
352
+ }
353
+ if (!credential) {
354
+ throw new Error('Registration was not completed');
355
+ }
356
+ const { id, rawId, response, type } = credential;
357
+ // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
358
+ let transports = undefined;
359
+ if (typeof response.getTransports === 'function') {
360
+ transports = response.getTransports();
361
+ }
362
+ // L3 says this is required, but browser and webview support are still not guaranteed.
363
+ let responsePublicKeyAlgorithm = undefined;
364
+ if (typeof response.getPublicKeyAlgorithm === 'function') {
365
+ try {
366
+ responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
367
+ }
368
+ catch (error) {
369
+ warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
370
+ }
371
+ }
372
+ let responsePublicKey = undefined;
373
+ if (typeof response.getPublicKey === 'function') {
374
+ try {
375
+ const _publicKey = response.getPublicKey();
376
+ if (_publicKey !== null) {
377
+ responsePublicKey = bufferToBase64URLString(_publicKey);
378
+ }
379
+ }
380
+ catch (error) {
381
+ warnOnBrokenImplementation('getPublicKey()', error);
382
+ }
383
+ }
384
+ // L3 says this is required, but browser and webview support are still not guaranteed.
385
+ let responseAuthenticatorData;
386
+ if (typeof response.getAuthenticatorData === 'function') {
387
+ try {
388
+ responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
389
+ }
390
+ catch (error) {
391
+ warnOnBrokenImplementation('getAuthenticatorData()', error);
392
+ }
393
+ }
394
+ return {
395
+ id,
396
+ rawId: bufferToBase64URLString(rawId),
397
+ response: {
398
+ attestationObject: bufferToBase64URLString(response.attestationObject),
399
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
400
+ transports,
401
+ publicKeyAlgorithm: responsePublicKeyAlgorithm,
402
+ publicKey: responsePublicKey,
403
+ authenticatorData: responseAuthenticatorData,
404
+ },
405
+ type,
406
+ clientExtensionResults: credential.getClientExtensionResults(),
407
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
408
+ };
409
+ }
410
+ /**
411
+ * Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
412
+ * calls
413
+ */
414
+ function warnOnBrokenImplementation(methodName, cause) {
415
+ console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
416
+ }
417
+
418
+ /**
419
+ * Determine if the browser supports conditional UI, so that WebAuthn credentials can
420
+ * be shown to the user in the browser's typical password autofill popup.
421
+ */
422
+ function browserSupportsWebAuthnAutofill() {
423
+ if (!browserSupportsWebAuthn()) {
424
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
425
+ }
426
+ /**
427
+ * I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
428
+ * TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
429
+ * want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
430
+ * have a chance to catch up.
431
+ */
432
+ const globalPublicKeyCredential = globalThis
433
+ .PublicKeyCredential;
434
+ if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
435
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
436
+ }
437
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
438
+ }
439
+ // Make it possible to stub the return value during testing
440
+ const _browserSupportsWebAuthnAutofillInternals = {
441
+ stubThis: (value) => value,
442
+ };
443
+
444
+ /**
445
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
446
+ */
447
+ function identifyAuthenticationError({ error, options, }) {
448
+ const { publicKey } = options;
449
+ if (!publicKey) {
450
+ throw Error('options was missing required publicKey property');
451
+ }
452
+ if (error.name === 'AbortError') {
453
+ if (options.signal instanceof AbortSignal) {
454
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
455
+ return new WebAuthnError({
456
+ message: 'Authentication ceremony was sent an abort signal',
457
+ code: 'ERROR_CEREMONY_ABORTED',
458
+ cause: error,
459
+ });
460
+ }
461
+ }
462
+ else if (error.name === 'NotAllowedError') {
463
+ /**
464
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
465
+ * defines and we don't want to overwrite potentially useful error messages.
466
+ */
467
+ return new WebAuthnError({
468
+ message: error.message,
469
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
470
+ cause: error,
471
+ });
472
+ }
473
+ else if (error.name === 'SecurityError') {
474
+ const effectiveDomain = globalThis.location.hostname;
475
+ if (!isValidDomain(effectiveDomain)) {
476
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
477
+ return new WebAuthnError({
478
+ message: `${globalThis.location.hostname} is an invalid domain`,
479
+ code: 'ERROR_INVALID_DOMAIN',
480
+ cause: error,
481
+ });
482
+ }
483
+ else if (publicKey.rpId !== effectiveDomain) {
484
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
485
+ return new WebAuthnError({
486
+ message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
487
+ code: 'ERROR_INVALID_RP_ID',
488
+ cause: error,
489
+ });
490
+ }
491
+ }
492
+ else if (error.name === 'UnknownError') {
493
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
494
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
495
+ return new WebAuthnError({
496
+ message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
497
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
498
+ cause: error,
499
+ });
500
+ }
501
+ return error;
502
+ }
503
+
504
+ /**
505
+ * Begin authenticator "login" via WebAuthn assertion
506
+ *
507
+ * @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
508
+ * @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
509
+ * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
510
+ */
511
+ async function startAuthentication(options) {
512
+ // @ts-ignore: Intentionally check for old call structure to warn about improper API call
513
+ if (!options.optionsJSON && options.challenge) {
514
+ 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.');
515
+ // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
516
+ options = { optionsJSON: options };
517
+ }
518
+ const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
519
+ if (!browserSupportsWebAuthn()) {
520
+ throw new Error('WebAuthn is not supported in this browser');
521
+ }
522
+ // We need to avoid passing empty array to avoid blocking retrieval
523
+ // of public key
524
+ let allowCredentials;
525
+ if (optionsJSON.allowCredentials?.length !== 0) {
526
+ allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
527
+ }
528
+ // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
529
+ const publicKey = {
530
+ ...optionsJSON,
531
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
532
+ allowCredentials,
533
+ };
534
+ // Prepare options for `.get()`
535
+ const getOptions = {};
536
+ /**
537
+ * Set up the page to prompt the user to select a credential for authentication via the browser's
538
+ * input autofill mechanism.
539
+ */
540
+ if (useBrowserAutofill) {
541
+ if (!(await browserSupportsWebAuthnAutofill())) {
542
+ throw Error('Browser does not support WebAuthn autofill');
543
+ }
544
+ // Check for an <input> with "webauthn" in its `autocomplete` attribute
545
+ const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
546
+ // WebAuthn autofill requires at least one valid input
547
+ if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
548
+ throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
549
+ }
550
+ // `CredentialMediationRequirement` doesn't know about "conditional" yet as of
551
+ // typescript@4.6.3
552
+ getOptions.mediation = 'conditional';
553
+ // Conditional UI requires an empty allow list
554
+ publicKey.allowCredentials = [];
555
+ }
556
+ // Finalize options
557
+ getOptions.publicKey = publicKey;
558
+ // Set up the ability to cancel this request if the user attempts another
559
+ getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
560
+ // Wait for the user to complete assertion
561
+ let credential;
562
+ try {
563
+ credential = (await navigator.credentials.get(getOptions));
564
+ }
565
+ catch (err) {
566
+ throw identifyAuthenticationError({ error: err, options: getOptions });
567
+ }
568
+ if (!credential) {
569
+ throw new Error('Authentication was not completed');
570
+ }
571
+ const { id, rawId, response, type } = credential;
572
+ let userHandle = undefined;
573
+ if (response.userHandle) {
574
+ userHandle = bufferToBase64URLString(response.userHandle);
575
+ }
576
+ // Convert values to base64 to make it easier to send back to the server
577
+ return {
578
+ id,
579
+ rawId: bufferToBase64URLString(rawId),
580
+ response: {
581
+ authenticatorData: bufferToBase64URLString(response.authenticatorData),
582
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
583
+ signature: bufferToBase64URLString(response.signature),
584
+ userHandle,
585
+ },
586
+ type,
587
+ clientExtensionResults: credential.getClientExtensionResults(),
588
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
589
+ };
590
+ }
591
+
1
592
  /** A special constant with type `never` */
2
593
  const NEVER = Object.freeze({
3
594
  status: "aborted",
@@ -11481,6 +12072,119 @@ var z = /*#__PURE__*/Object.freeze({
11481
12072
  xid: xid
11482
12073
  });
11483
12074
 
12075
+ function Dialog($$payload, $$props) {
12076
+ push();
12077
+ let { children, dialog = void 0, $$slots, $$events, ...rest } = $$props;
12078
+ $$payload.out += `<dialog${spread_attributes({ ...rest }, "svelte-1yuzruq")}>`;
12079
+ children($$payload);
12080
+ $$payload.out += `<!----></dialog>`;
12081
+ bind_props($$props, { dialog });
12082
+ pop();
12083
+ }
12084
+ function FormDialog($$payload, $$props) {
12085
+ push();
12086
+ let {
12087
+ children,
12088
+ dialog = void 0,
12089
+ submitText = "Submit",
12090
+ cancel = () => {
12091
+ },
12092
+ submit = (data) => Promise.resolve(),
12093
+ pageMode = false,
12094
+ submitDanger = false,
12095
+ header,
12096
+ footer,
12097
+ $$slots,
12098
+ $$events,
12099
+ ...rest
12100
+ } = $$props;
12101
+ function onclose(e) {
12102
+ e.preventDefault();
12103
+ cancel();
12104
+ }
12105
+ function submitButton($$payload2) {
12106
+ $$payload2.out += `<button type="submit"${attr_class(clsx(["submit", submitDanger && "danger"]))}>${escape_html(submitText)}</button>`;
12107
+ }
12108
+ let $$settled = true;
12109
+ let $$inner_payload;
12110
+ function $$render_inner($$payload2) {
12111
+ Dialog($$payload2, spread_props([
12112
+ { onclose },
12113
+ rest,
12114
+ {
12115
+ get dialog() {
12116
+ return dialog;
12117
+ },
12118
+ set dialog($$value) {
12119
+ dialog = $$value;
12120
+ $$settled = false;
12121
+ },
12122
+ children: ($$payload3) => {
12123
+ header?.($$payload3);
12124
+ $$payload3.out += `<!----> <form class="main" method="dialog">`;
12125
+ {
12126
+ $$payload3.out += "<!--[!-->";
12127
+ }
12128
+ $$payload3.out += `<!--]--> `;
12129
+ children($$payload3);
12130
+ $$payload3.out += `<!----> `;
12131
+ if (pageMode) {
12132
+ $$payload3.out += "<!--[-->";
12133
+ submitButton($$payload3);
12134
+ } else {
12135
+ $$payload3.out += "<!--[!-->";
12136
+ $$payload3.out += `<div class="actions svelte-p6pltw"><button type="button">Cancel</button> `;
12137
+ submitButton($$payload3);
12138
+ $$payload3.out += `<!----></div>`;
12139
+ }
12140
+ $$payload3.out += `<!--]--></form> `;
12141
+ footer?.($$payload3);
12142
+ $$payload3.out += `<!---->`;
12143
+ },
12144
+ $$slots: { default: true }
12145
+ }
12146
+ ]));
12147
+ }
12148
+ do {
12149
+ $$settled = true;
12150
+ $$inner_payload = copy_payload($$payload);
12151
+ $$render_inner($$inner_payload);
12152
+ } while (!$$settled);
12153
+ assign_payload($$payload, $$inner_payload);
12154
+ bind_props($$props, { dialog });
12155
+ pop();
12156
+ }
12157
+ let prefix = "/api/";
12158
+ async function fetchAPI(method, endpoint, data, ...params) {
12159
+ const options = {
12160
+ method,
12161
+ headers: {
12162
+ "Content-Type": "application/json",
12163
+ Accept: "application/json"
12164
+ }
12165
+ };
12166
+ if (method !== "GET" && method !== "HEAD")
12167
+ options.body = JSON.stringify(data);
12168
+ const parts = [];
12169
+ for (const part of endpoint.split("/")) {
12170
+ if (!part.startsWith(":")) {
12171
+ parts.push(part);
12172
+ continue;
12173
+ }
12174
+ const value = params.shift();
12175
+ if (!value)
12176
+ throw new Error(`Missing parameter "${part.slice(1)}"`);
12177
+ parts.push(value);
12178
+ }
12179
+ const response = await fetch(prefix + parts.join("/"), options);
12180
+ if (!response.headers.get("Content-Type")?.includes("application/json")) {
12181
+ throw new Error(`Unexpected response type: ${response.headers.get("Content-Type")}`);
12182
+ }
12183
+ const json = await response.json().catch(() => ({ message: "Unknown server error (invalid JSON response)" }));
12184
+ if (!response.ok)
12185
+ throw new Error(json.message);
12186
+ return json;
12187
+ }
11484
12188
  const transports = ["ble", "cable", "hybrid", "internal", "nfc", "smart-card", "usb"];
11485
12189
  const authenticatorAttachment = z.literal(["platform", "cross-platform"]).optional();
11486
12190
  const PasskeyRegistration = z.object({
@@ -11555,6 +12259,118 @@ function getUserImage(user) {
11555
12259
  <text x="23" y="28" style="font-family:sans-serif;font-weight:bold;" fill="white">${user.name.replaceAll(/\W/g, "")[0]}</text>
11556
12260
  </svg>`.replaceAll(/[\t\n]/g, "");
11557
12261
  }
12262
+ async function login(userId) {
12263
+ const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "login" }, userId);
12264
+ const response = await startAuthentication({ optionsJSON: options });
12265
+ return await fetchAPI("POST", "users/:id/auth", response, userId);
12266
+ }
12267
+ async function elevate(userId) {
12268
+ const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
12269
+ const response = await startAuthentication({ optionsJSON: options });
12270
+ await fetchAPI("POST", "users/:id/auth", response, userId);
12271
+ }
12272
+ async function loginByEmail(email) {
12273
+ const { id: userId } = await fetchAPI("POST", "user_id", {
12274
+ using: "email",
12275
+ value: email
12276
+ });
12277
+ return await login(userId);
12278
+ }
12279
+ async function getCurrentSession() {
12280
+ const result = await fetchAPI("GET", "session");
12281
+ result.created = new Date(result.created);
12282
+ result.expires = new Date(result.expires);
12283
+ return result;
12284
+ }
12285
+ async function getSessions(userId) {
12286
+ _checkId(userId);
12287
+ const result = await fetchAPI("GET", "users/:id/sessions", {}, userId);
12288
+ for (const session of result) {
12289
+ session.created = new Date(session.created);
12290
+ session.expires = new Date(session.expires);
12291
+ }
12292
+ return result;
12293
+ }
12294
+ async function logout(userId, ...sessionId) {
12295
+ _checkId(userId);
12296
+ const result = await fetchAPI("DELETE", "users/:id/sessions", { id: sessionId }, userId);
12297
+ for (const session of result) {
12298
+ session.created = new Date(session.created);
12299
+ session.expires = new Date(session.expires);
12300
+ }
12301
+ return result;
12302
+ }
12303
+ async function logoutAll(userId) {
12304
+ _checkId(userId);
12305
+ await elevate(userId);
12306
+ const result = await fetchAPI("DELETE", "users/:id/sessions", { confirm_all: true }, userId);
12307
+ for (const session of result) {
12308
+ session.created = new Date(session.created);
12309
+ session.expires = new Date(session.expires);
12310
+ }
12311
+ return result;
12312
+ }
12313
+ async function logoutCurrentSession() {
12314
+ return await fetchAPI("DELETE", "session");
12315
+ }
12316
+ async function register(_data) {
12317
+ const data = z.object({ name: z.string(), email: z.email() }).parse(_data);
12318
+ const { options, userId } = await fetchAPI("OPTIONS", "register", data);
12319
+ const response = await startRegistration({ optionsJSON: options });
12320
+ await fetchAPI("POST", "register", {
12321
+ userId,
12322
+ name: data.name,
12323
+ email: data.email,
12324
+ response
12325
+ });
12326
+ }
12327
+ function _checkId(userId) {
12328
+ try {
12329
+ z.uuid().parse(userId);
12330
+ } catch (e) {
12331
+ throw z.prettifyError(e);
12332
+ }
12333
+ }
12334
+ async function updateUser(userId, data) {
12335
+ _checkId(userId);
12336
+ const body = await UserChangeable.parseAsync(data).catch((e) => {
12337
+ throw z.prettifyError(e);
12338
+ });
12339
+ const result = await fetchAPI("PATCH", "users/:id", body, userId);
12340
+ result.registeredAt = new Date(result.registeredAt);
12341
+ if (result.emailVerified)
12342
+ result.emailVerified = new Date(result.emailVerified);
12343
+ return result;
12344
+ }
12345
+ async function deleteUser(userId) {
12346
+ _checkId(userId);
12347
+ const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "action" }, userId);
12348
+ const response = await startAuthentication({ optionsJSON: options });
12349
+ await fetchAPI("POST", "users/:id/auth", response, userId);
12350
+ const result = await fetchAPI("DELETE", "users/:id", response, userId);
12351
+ result.registeredAt = new Date(result.registeredAt);
12352
+ result.emailVerified = new Date(result.emailVerified);
12353
+ return result;
12354
+ }
12355
+ async function emailVerificationEnabled(userId) {
12356
+ _checkId(userId);
12357
+ const { enabled } = await fetchAPI("OPTIONS", "users/:id/verify_email", {}, userId);
12358
+ return enabled;
12359
+ }
12360
+ async function getPasskeys(userId) {
12361
+ _checkId(userId);
12362
+ const result = await fetchAPI("GET", "users/:id/passkeys", {}, userId);
12363
+ for (const passkey of result) {
12364
+ passkey.createdAt = new Date(passkey.createdAt);
12365
+ }
12366
+ return result;
12367
+ }
12368
+ async function updatePasskey(passkeyId, data) {
12369
+ return await fetchAPI("PATCH", "passkeys/:id", data, passkeyId);
12370
+ }
12371
+ async function deletePasskey(passkeyId) {
12372
+ return await fetchAPI("DELETE", "passkeys/:id", {}, passkeyId);
12373
+ }
11558
12374
 
11559
- export { UserChangeable as U, getUserImage as g, z };
11560
- //# sourceMappingURL=user2-D249re2A.js.map
12375
+ export { FormDialog as F, getPasskeys as a, getSessions as b, getUserImage as c, deleteUser as d, emailVerificationEnabled as e, deletePasskey as f, getCurrentSession as g, logoutAll as h, updateUser as i, loginByEmail as j, logoutCurrentSession as k, logout as l, register as r, updatePasskey as u };
12376
+ //# sourceMappingURL=user-BM1CPpSk.js.map