@eifi1/ui-kit 0.28.1 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +21 -3
  2. package/dist/auth/accept-invitation.d.ts +90 -0
  3. package/dist/auth/accept-invitation.js +117 -0
  4. package/dist/auth/accept-invitation.js.map +1 -0
  5. package/dist/auth/auth-errors.d.ts +60 -0
  6. package/dist/auth/auth-errors.js +32 -0
  7. package/dist/auth/auth-errors.js.map +1 -0
  8. package/dist/auth/complete-name-dialog.d.ts +71 -0
  9. package/dist/auth/complete-name-dialog.js +168 -0
  10. package/dist/auth/complete-name-dialog.js.map +1 -0
  11. package/dist/auth/email-tag.d.ts +60 -0
  12. package/dist/auth/email-tag.js +23 -0
  13. package/dist/auth/email-tag.js.map +1 -0
  14. package/dist/auth/forgot-password-form.d.ts +79 -0
  15. package/dist/auth/forgot-password-form.js +120 -0
  16. package/dist/auth/forgot-password-form.js.map +1 -0
  17. package/dist/auth/form-rules.d.ts +27 -0
  18. package/dist/auth/form-rules.js +23 -0
  19. package/dist/auth/form-rules.js.map +1 -0
  20. package/dist/auth/new-password-fields.d.ts +38 -0
  21. package/dist/auth/new-password-fields.js +54 -0
  22. package/dist/auth/new-password-fields.js.map +1 -0
  23. package/dist/auth/not-found-page.d.ts +57 -0
  24. package/dist/auth/not-found-page.js +40 -0
  25. package/dist/auth/not-found-page.js.map +1 -0
  26. package/dist/auth/register-form.d.ts +86 -0
  27. package/dist/auth/register-form.js +268 -0
  28. package/dist/auth/register-form.js.map +1 -0
  29. package/dist/auth/reset-password-form.d.ts +124 -0
  30. package/dist/auth/reset-password-form.js +164 -0
  31. package/dist/auth/reset-password-form.js.map +1 -0
  32. package/dist/auth/sign-in-form.d.ts +243 -0
  33. package/dist/auth/sign-in-form.js +345 -0
  34. package/dist/auth/sign-in-form.js.map +1 -0
  35. package/dist/auth/status-parts.d.ts +78 -0
  36. package/dist/auth/status-parts.js +83 -0
  37. package/dist/auth/status-parts.js.map +1 -0
  38. package/dist/auth/verify-email.d.ts +121 -0
  39. package/dist/auth/verify-email.js +207 -0
  40. package/dist/auth/verify-email.js.map +1 -0
  41. package/dist/chart.d.ts +17 -2
  42. package/dist/components/amount-input.d.ts +18 -2
  43. package/dist/components/button-group.d.ts +18 -2
  44. package/dist/components/calculator.d.ts +18 -2
  45. package/dist/components/confirm-dialog.d.ts +18 -2
  46. package/dist/components/copy-button.d.ts +18 -2
  47. package/dist/components/danger-confirm.d.ts +18 -2
  48. package/dist/components/facing-pair.d.ts +18 -2
  49. package/dist/components/file-button.d.ts +18 -2
  50. package/dist/components/file-dropzone.d.ts +18 -2
  51. package/dist/components/form-actions.d.ts +18 -2
  52. package/dist/components/iban-input.d.ts +18 -2
  53. package/dist/components/language-select.d.ts +18 -9
  54. package/dist/components/legal-page.d.ts +18 -2
  55. package/dist/components/legal.d.ts +18 -2
  56. package/dist/components/money-field.d.ts +18 -2
  57. package/dist/components/number-field.d.ts +18 -2
  58. package/dist/components/number-input.d.ts +18 -2
  59. package/dist/components/numpad-sheet.d.ts +18 -2
  60. package/dist/components/phone-input.d.ts +18 -2
  61. package/dist/components/series-chart.d.ts +18 -2
  62. package/dist/components/settings-fields.d.ts +15 -2
  63. package/dist/components/share-card.d.ts +18 -2
  64. package/dist/components/text-link.d.ts +18 -2
  65. package/dist/components/time-input.d.ts +18 -2
  66. package/dist/components/ui.d.ts +17 -1
  67. package/dist/components/user-avatar.d.ts +16 -2
  68. package/dist/components/user-avatar.js +7 -3
  69. package/dist/components/user-avatar.js.map +1 -1
  70. package/dist/feedback/feedback-attachment.d.ts +18 -2
  71. package/dist/feedback/feedback-context.d.ts +18 -2
  72. package/dist/feedback/feedback-crash.d.ts +18 -2
  73. package/dist/feedback/feedback-dialog.d.ts +18 -2
  74. package/dist/feedback/feedback-inbox.d.ts +18 -2
  75. package/dist/feedback/feedback-labels.d.ts +18 -2
  76. package/dist/feedback/feedback-menu.d.ts +18 -2
  77. package/dist/feedback/feedback-record.d.ts +18 -2
  78. package/dist/feedback/feedback-row-detail.d.ts +18 -2
  79. package/dist/feedback/feedback-status-undo.d.ts +18 -2
  80. package/dist/feedback/feedback-submit.d.ts +18 -2
  81. package/dist/feedback/feedback-swipe.d.ts +18 -2
  82. package/dist/feedback/feedback-table.d.ts +18 -2
  83. package/dist/feedback/feedback-thread.d.ts +18 -2
  84. package/dist/feedback.d.ts +18 -2
  85. package/dist/hooks/use-file-drop.d.ts +18 -2
  86. package/dist/i18n/defaults.d.ts +18 -2
  87. package/dist/i18n/defaults.js +18 -0
  88. package/dist/i18n/defaults.js.map +1 -1
  89. package/dist/i18n/german.d.ts +18 -2
  90. package/dist/i18n/german.js +137 -0
  91. package/dist/i18n/german.js.map +1 -1
  92. package/dist/i18n/kit-labels.d.ts +18 -2
  93. package/dist/i18n/kit-labels.js.map +1 -1
  94. package/dist/i18n/languages.d.ts +13 -201
  95. package/dist/i18n/locales/de-CH.d.ts +18 -2
  96. package/dist/i18n/locales/en.d.ts +18 -2
  97. package/dist/i18n/locales/es.d.ts +18 -2
  98. package/dist/i18n/locales/es.js +137 -1
  99. package/dist/i18n/locales/es.js.map +1 -1
  100. package/dist/i18n/locales/fr.d.ts +18 -2
  101. package/dist/i18n/locales/fr.js +139 -0
  102. package/dist/i18n/locales/fr.js.map +1 -1
  103. package/dist/i18n/locales/hu.d.ts +18 -2
  104. package/dist/i18n/locales/hu.js +139 -1
  105. package/dist/i18n/locales/hu.js.map +1 -1
  106. package/dist/i18n/locales/it.d.ts +18 -2
  107. package/dist/i18n/locales/it.js +137 -0
  108. package/dist/i18n/locales/it.js.map +1 -1
  109. package/dist/i18n/locales/zh.d.ts +18 -2
  110. package/dist/i18n/locales/zh.js +137 -0
  111. package/dist/i18n/locales/zh.js.map +1 -1
  112. package/dist/i18n/review.d.ts +18 -2
  113. package/dist/i18n/review.js +9 -1
  114. package/dist/i18n/review.js.map +1 -1
  115. package/dist/index.d.ts +13 -2
  116. package/dist/index.js +36 -0
  117. package/dist/index.js.map +1 -1
  118. package/dist/lib/person-name.d.ts +69 -0
  119. package/dist/lib/person-name.js +65 -0
  120. package/dist/lib/person-name.js.map +1 -0
  121. package/dist/{kit-labels-Du0uHBq4.d.ts → register-form-V1OeNlMr.d.ts} +383 -2
  122. package/dist/rhf/fields.d.ts +18 -2
  123. package/dist/rhf/form.d.ts +18 -2
  124. package/dist/rhf.d.ts +18 -2
  125. package/dist/shell/app-shell.d.ts +18 -2
  126. package/dist/shell/company-switcher.d.ts +59 -0
  127. package/dist/shell/company-switcher.js +85 -0
  128. package/dist/shell/company-switcher.js.map +1 -0
  129. package/dist/shell/top-bar-brand.d.ts +18 -2
  130. package/dist/shell/topbar-action-menu.d.ts +1 -0
  131. package/dist/shell.d.ts +12 -2
  132. package/dist/wizard/stepper-nav.d.ts +18 -2
  133. package/dist/wizard.d.ts +18 -2
  134. package/package.json +1 -1
  135. package/src/auth/accept-invitation.tsx +227 -0
  136. package/src/auth/auth-errors.ts +105 -0
  137. package/src/auth/complete-name-dialog.tsx +253 -0
  138. package/src/auth/email-tag.ts +75 -0
  139. package/src/auth/forgot-password-form.tsx +213 -0
  140. package/src/auth/form-rules.ts +40 -0
  141. package/src/auth/new-password-fields.tsx +85 -0
  142. package/src/auth/not-found-page.tsx +98 -0
  143. package/src/auth/register-form.tsx +459 -0
  144. package/src/auth/reset-password-form.tsx +337 -0
  145. package/src/auth/sign-in-form.tsx +687 -0
  146. package/src/auth/status-parts.tsx +138 -0
  147. package/src/auth/verify-email.tsx +358 -0
  148. package/src/components/user-avatar.tsx +22 -4
  149. package/src/i18n/defaults.ts +18 -0
  150. package/src/i18n/german.ts +143 -0
  151. package/src/i18n/kit-labels.tsx +27 -0
  152. package/src/i18n/locales/es.ts +144 -1
  153. package/src/i18n/locales/fr.ts +147 -0
  154. package/src/i18n/locales/hu.ts +147 -1
  155. package/src/i18n/locales/it.ts +143 -0
  156. package/src/i18n/locales/zh.ts +138 -0
  157. package/src/i18n/review.ts +8 -0
  158. package/src/index.ts +53 -0
  159. package/src/lib/person-name.ts +157 -0
  160. package/src/shell/company-switcher.tsx +140 -0
@@ -0,0 +1,345 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useEffectEvent, useId, useRef, useState } from "react";
4
+ import { KeyRound } from "lucide-react";
5
+ import { useKitLabels } from "../i18n/kit-labels.js";
6
+ import { cn } from "../lib/cn.js";
7
+ import { AlertBanner } from "../components/alert-banner.js";
8
+ import { hasMessage } from "../components/choice-parts.js";
9
+ import { CurrentPasswordInput } from "../components/danger-confirm.js";
10
+ import { OneTimeCodeInput } from "../components/one-time-code-input.js";
11
+ import { TextLink } from "../components/text-link.js";
12
+ import { Button, Input } from "../components/ui.js";
13
+ import { authErrorCode } from "./auth-errors.js";
14
+ import { taggedEmail } from "./email-tag.js";
15
+ import { newPasswordProblem } from "./form-rules.js";
16
+ import { NewPasswordFields } from "./new-password-fields.js";
17
+ const DEFAULT_SIGN_IN_LABELS = {
18
+ email: "Email",
19
+ password: "Password",
20
+ submit: "Sign in",
21
+ passkey: "Sign in with a passkey",
22
+ forgotPassword: "Forgot your password?",
23
+ noAccount: "No account yet?",
24
+ register: "Create account",
25
+ invalidCredentials: "The email or password is incorrect.",
26
+ failed: "Sign-in failed. Please try again.",
27
+ passkeyFailed: "Passkey sign-in failed.",
28
+ deactivatedHint: "Account deactivated? Write to {contact}.",
29
+ tagHint: (taggedAddress) => `Signed up with ${taggedAddress}? Use that address.`,
30
+ twoFactorTitle: "Two-factor authentication",
31
+ twoFactorIntro: "Enter the code your authenticator app shows.",
32
+ code: "2FA code",
33
+ verify: "Verify",
34
+ codeInvalid: "Invalid 2FA code.",
35
+ setPasswordTitle: "Choose a new password",
36
+ setPasswordIntro: "A new password was requested for this account. Choose one and you are straight back in.",
37
+ newPassword: "New password",
38
+ confirmPassword: "Repeat new password",
39
+ passwordMismatch: "The passwords don't match.",
40
+ setPasswordSubmit: "Set password and sign in",
41
+ setPasswordFailed: "The password could not be set.",
42
+ expired: "This sign-in has expired. Please sign in again.",
43
+ backToSignIn: "Back to sign in"
44
+ };
45
+ function withContact(template, contact) {
46
+ const node = typeof contact === "string" && contact.includes("@") ? /* @__PURE__ */ jsx(TextLink, { href: `mailto:${contact}`, tone: "secondary", children: contact }, "contact") : /* @__PURE__ */ jsx("span", { children: contact }, "contact");
47
+ if (!template.includes("{contact}")) return [template, " ", node];
48
+ return template.split(/(\{contact\})/).filter((part) => part !== "").map((part) => part === "{contact}" ? node : part);
49
+ }
50
+ const HINT_CLASS = "text-xs text-[var(--text-secondary)]";
51
+ const INTRO_CLASS = "text-sm text-[var(--text-secondary)]";
52
+ function SignInForm({
53
+ onSubmit,
54
+ onCode,
55
+ onSetPassword,
56
+ onPasskey,
57
+ passkeyAutofill,
58
+ forgotHref,
59
+ registerHref,
60
+ defaultEmail = "",
61
+ emailTag,
62
+ deactivatedContact,
63
+ codeLength = 6,
64
+ credentialsContent,
65
+ twoFactorContent,
66
+ passwordChangeContent,
67
+ describeError,
68
+ onStepChange,
69
+ headingAs: Heading = "h2",
70
+ labels: labelsProp,
71
+ className,
72
+ ...rest
73
+ }) {
74
+ const labels = useKitLabels("signIn", DEFAULT_SIGN_IN_LABELS, labelsProp);
75
+ const [step, setStep] = useState("credentials");
76
+ const [email, setEmail] = useState(defaultEmail);
77
+ const [password, setPassword] = useState("");
78
+ const [code, setCode] = useState("");
79
+ const [newPassword, setNewPassword] = useState("");
80
+ const [confirm, setConfirm] = useState("");
81
+ const [challenge, setChallenge] = useState(
82
+ null
83
+ );
84
+ const [busy, setBusy] = useState(null);
85
+ const [failure, setFailure] = useState(null);
86
+ const headingId = useId();
87
+ const emailRef = useRef(null);
88
+ const passwordRef = useRef(null);
89
+ const codeRef = useRef(null);
90
+ const newPasswordRef = useRef(null);
91
+ const mounted = useRef(true);
92
+ useEffect(() => {
93
+ mounted.current = true;
94
+ return () => {
95
+ mounted.current = false;
96
+ };
97
+ }, []);
98
+ const goTo = (next) => {
99
+ setStep(next);
100
+ onStepChange?.(next);
101
+ };
102
+ const present = (answer) => {
103
+ setFailure(null);
104
+ if (answer.kind === "signed-in") {
105
+ setBusy("done");
106
+ return;
107
+ }
108
+ setBusy(null);
109
+ setPassword("");
110
+ setCode("");
111
+ setNewPassword("");
112
+ setConfirm("");
113
+ if (answer.kind === "2fa") {
114
+ setChallenge({ token: answer.challengeToken });
115
+ goTo("2fa");
116
+ } else if (answer.kind === "password-change") {
117
+ setChallenge({ token: answer.challengeToken, extra: answer.extra });
118
+ goTo("password-change");
119
+ }
120
+ };
121
+ const messageFor = (error, action, code2) => {
122
+ const own = describeError?.(error, action);
123
+ if (hasMessage(own)) return own;
124
+ if (action === "password") return code2 === "invalid_credentials" ? labels.invalidCredentials : labels.failed;
125
+ if (action === "passkey") return labels.passkeyFailed;
126
+ if (action === "code") return code2 === "token_invalid" ? labels.expired : labels.codeInvalid;
127
+ return code2 === "token_invalid" ? labels.expired : labels.setPasswordFailed;
128
+ };
129
+ const fail = (error, action, sentEmail) => {
130
+ setBusy(null);
131
+ if (error?.name === "AbortError") return;
132
+ const code2 = authErrorCode(error);
133
+ const message = messageFor(error, action, code2);
134
+ if ((action === "code" || action === "set-password") && code2 === "token_invalid") {
135
+ setChallenge(null);
136
+ setCode("");
137
+ setNewPassword("");
138
+ setConfirm("");
139
+ goTo("credentials");
140
+ }
141
+ setFailure({ action, code: code2, message, email: sentEmail });
142
+ };
143
+ const attempt = (action, call, sentEmail) => {
144
+ if (busy) return;
145
+ setBusy(action);
146
+ setFailure(null);
147
+ let result;
148
+ try {
149
+ result = Promise.resolve(call());
150
+ } catch (error) {
151
+ result = Promise.reject(error);
152
+ }
153
+ result.then(
154
+ (answer) => {
155
+ if (mounted.current) present(answer);
156
+ },
157
+ (error) => {
158
+ if (mounted.current) fail(error, action, sentEmail);
159
+ }
160
+ );
161
+ };
162
+ const armAutofill = useEffectEvent((signal) => passkeyAutofill?.(signal));
163
+ const autofillAnswered = useEffectEvent((answer) => {
164
+ if (busy === null) present(answer);
165
+ });
166
+ useEffect(() => {
167
+ const controller = new AbortController();
168
+ let pending;
169
+ try {
170
+ pending = Promise.resolve(armAutofill(controller.signal));
171
+ } catch (error) {
172
+ pending = Promise.reject(error);
173
+ }
174
+ pending.then(
175
+ (answer) => {
176
+ if (answer && !controller.signal.aborted && mounted.current) autofillAnswered(answer);
177
+ },
178
+ () => {
179
+ }
180
+ );
181
+ return () => controller.abort();
182
+ }, []);
183
+ const shownStep = useRef(step);
184
+ useEffect(() => {
185
+ if (shownStep.current === step) return;
186
+ shownStep.current = step;
187
+ if (step === "2fa") codeRef.current?.focus();
188
+ else if (step === "password-change") newPasswordRef.current?.focus();
189
+ else if (emailRef.current?.value) passwordRef.current?.focus();
190
+ else emailRef.current?.focus();
191
+ }, [step]);
192
+ const backToCredentials = () => {
193
+ if (busy) return;
194
+ setChallenge(null);
195
+ setFailure(null);
196
+ setCode("");
197
+ setNewPassword("");
198
+ setConfirm("");
199
+ goTo("credentials");
200
+ };
201
+ const working = busy !== null;
202
+ const rootClass = cn("space-y-3", className);
203
+ if (step === "2fa" && challenge) {
204
+ const submitCode = (e) => {
205
+ e.preventDefault();
206
+ if (code.length !== codeLength) return;
207
+ attempt("code", () => onCode({ challengeToken: challenge.token, code }));
208
+ };
209
+ const codeError = failure?.action === "code" ? failure.message : void 0;
210
+ return /* @__PURE__ */ jsxs("div", { ...rest, "data-step": "2fa", className: rootClass, children: [
211
+ /* @__PURE__ */ jsxs("form", { className: "space-y-3", "aria-labelledby": headingId, onSubmit: submitCode, children: [
212
+ /* @__PURE__ */ jsx(Heading, { id: headingId, className: "text-base font-semibold text-[var(--text-primary)]", children: labels.twoFactorTitle }),
213
+ /* @__PURE__ */ jsx("p", { className: INTRO_CLASS, children: labels.twoFactorIntro }),
214
+ twoFactorContent,
215
+ /* @__PURE__ */ jsx(
216
+ OneTimeCodeInput,
217
+ {
218
+ ref: codeRef,
219
+ label: labels.code,
220
+ name: "code",
221
+ value: code,
222
+ length: codeLength,
223
+ onChange: (next) => {
224
+ setCode(next);
225
+ if (failure) setFailure(null);
226
+ },
227
+ readOnly: working,
228
+ error: codeError,
229
+ required: true
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsx(Button, { type: "submit", className: "w-full", disabled: !working && code.length !== codeLength, pending: working, children: labels.verify })
233
+ ] }),
234
+ /* @__PURE__ */ jsx(BackLink, { label: labels.backToSignIn, onClick: backToCredentials, disabled: working })
235
+ ] });
236
+ }
237
+ if (step === "password-change" && challenge) {
238
+ const problem = newPasswordProblem(newPassword, confirm);
239
+ const submitPassword = (e) => {
240
+ e.preventDefault();
241
+ if (problem) return;
242
+ attempt("set-password", () => onSetPassword({ challengeToken: challenge.token, password: newPassword }));
243
+ };
244
+ const content = typeof passwordChangeContent === "function" ? passwordChangeContent(challenge.extra) : passwordChangeContent;
245
+ return /* @__PURE__ */ jsxs("div", { ...rest, "data-step": "password-change", className: rootClass, children: [
246
+ /* @__PURE__ */ jsxs("form", { className: "space-y-3", "aria-labelledby": headingId, onSubmit: submitPassword, children: [
247
+ /* @__PURE__ */ jsx(Heading, { id: headingId, className: "text-base font-semibold text-[var(--text-primary)]", children: labels.setPasswordTitle }),
248
+ /* @__PURE__ */ jsx("p", { className: INTRO_CLASS, children: labels.setPasswordIntro }),
249
+ content,
250
+ email !== "" && /* @__PURE__ */ jsx("input", { type: "email", name: "username", autoComplete: "username", value: email, readOnly: true, hidden: true }),
251
+ /* @__PURE__ */ jsx(
252
+ NewPasswordFields,
253
+ {
254
+ password: newPassword,
255
+ confirm,
256
+ onPasswordChange: setNewPassword,
257
+ onConfirmChange: setConfirm,
258
+ busy: working,
259
+ passwordRef: newPasswordRef,
260
+ text: { password: labels.newPassword, confirm: labels.confirmPassword, mismatch: labels.passwordMismatch }
261
+ }
262
+ ),
263
+ failure?.action === "set-password" && /* @__PURE__ */ jsx(AlertBanner, { tone: "danger", size: "sm", role: "alert", children: failure.message }),
264
+ /* @__PURE__ */ jsx(Button, { type: "submit", className: "w-full", disabled: !working && problem !== null, pending: working, children: labels.setPasswordSubmit })
265
+ ] }),
266
+ /* @__PURE__ */ jsx(BackLink, { label: labels.backToSignIn, onClick: backToCredentials, disabled: working })
267
+ ] });
268
+ }
269
+ const submitCredentials = (e) => {
270
+ e.preventDefault();
271
+ const sent = email.trim();
272
+ if (sent === "" || password === "") return;
273
+ attempt("password", () => onSubmit({ email: sent, password }), sent);
274
+ };
275
+ const refused = failure?.code === "invalid_credentials";
276
+ const tagged = refused && failure?.action === "password" && emailTag && failure.email ? taggedEmail(failure.email, emailTag) : null;
277
+ const showDeactivated = refused && hasMessage(deactivatedContact);
278
+ return /* @__PURE__ */ jsxs("div", { ...rest, "data-step": "credentials", className: rootClass, children: [
279
+ /* @__PURE__ */ jsxs("form", { className: "space-y-3", onSubmit: submitCredentials, children: [
280
+ credentialsContent,
281
+ /* @__PURE__ */ jsx(
282
+ Input,
283
+ {
284
+ ref: emailRef,
285
+ type: "email",
286
+ name: "email",
287
+ autoComplete: "username webauthn",
288
+ label: labels.email,
289
+ value: email,
290
+ onChange: (e) => setEmail(e.target.value),
291
+ readOnly: working,
292
+ required: true
293
+ }
294
+ ),
295
+ /* @__PURE__ */ jsx(
296
+ CurrentPasswordInput,
297
+ {
298
+ ref: passwordRef,
299
+ name: "password",
300
+ label: labels.password,
301
+ value: password,
302
+ onValueChange: setPassword,
303
+ busy: working,
304
+ required: true
305
+ }
306
+ ),
307
+ failure && // One live region for the sentence and its hints: they are one answer.
308
+ /* @__PURE__ */ jsxs("div", { role: "alert", className: "space-y-1.5", children: [
309
+ /* @__PURE__ */ jsx(AlertBanner, { tone: "danger", size: "sm", children: failure.message }),
310
+ showDeactivated && /* @__PURE__ */ jsx("p", { className: HINT_CLASS, children: withContact(labels.deactivatedHint, deactivatedContact) }),
311
+ tagged && /* @__PURE__ */ jsx("p", { className: HINT_CLASS, children: labels.tagHint(tagged) })
312
+ ] }),
313
+ /* @__PURE__ */ jsx(Button, { type: "submit", className: "w-full", pending: busy === "password" || busy === "done", disabled: busy === "passkey", children: labels.submit }),
314
+ onPasskey && /* @__PURE__ */ jsxs(
315
+ Button,
316
+ {
317
+ type: "button",
318
+ variant: "secondary",
319
+ className: "w-full",
320
+ pending: busy === "passkey",
321
+ disabled: busy === "password" || busy === "done",
322
+ onClick: () => attempt("passkey", onPasskey),
323
+ children: [
324
+ /* @__PURE__ */ jsx(KeyRound, { "aria-hidden": true, className: "size-4" }),
325
+ labels.passkey
326
+ ]
327
+ }
328
+ )
329
+ ] }),
330
+ forgotHref !== void 0 && /* @__PURE__ */ jsx("p", { className: "text-center text-sm", children: /* @__PURE__ */ jsx(TextLink, { href: forgotHref, tone: "secondary", children: labels.forgotPassword }) }),
331
+ registerHref !== void 0 && /* @__PURE__ */ jsxs("p", { className: "text-center text-sm text-[var(--text-secondary)]", children: [
332
+ labels.noAccount,
333
+ " ",
334
+ /* @__PURE__ */ jsx(TextLink, { href: registerHref, tone: "primary", children: labels.register })
335
+ ] })
336
+ ] });
337
+ }
338
+ function BackLink({ label, onClick, disabled }) {
339
+ return /* @__PURE__ */ jsx("p", { className: "text-center text-sm", children: /* @__PURE__ */ jsx(Button, { type: "button", variant: "link", tone: "muted", size: "sm", disabled, onClick, children: label }) });
340
+ }
341
+ export {
342
+ DEFAULT_SIGN_IN_LABELS,
343
+ SignInForm
344
+ };
345
+ //# sourceMappingURL=sign-in-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/sign-in-form.tsx"],"sourcesContent":["import { useEffect, useEffectEvent, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { KeyRound } from \"lucide-react\";\n\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { cn } from \"../lib/cn\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { hasMessage } from \"../components/choice-parts\";\nimport { CurrentPasswordInput } from \"../components/danger-confirm\";\nimport { OneTimeCodeInput } from \"../components/one-time-code-input\";\nimport { TextLink } from \"../components/text-link\";\nimport { Button, Input } from \"../components/ui\";\nimport { authErrorCode } from \"./auth-errors\";\nimport type { AuthErrorCode } from \"./auth-errors\";\nimport { taggedEmail } from \"./email-tag\";\nimport { newPasswordProblem } from \"./form-rules\";\nimport { NewPasswordFields } from \"./new-password-fields\";\n\n/* ── The answers (§5.1) ──────────────────────────────────────────────────── */\n\n/**\n * What a sign-in call answers, in the kit's words — docs/auth-harmonization.md §5.1,\n * keksdose's three shapes. The app maps its own HTTP answer to one of these and resolves\n * with it; a refusal REJECTS (with whatever its client throws — {@link authErrorCode}\n * reads the code out of it).\n *\n * | the server answers (keksdose) | resolve with |\n * |---|---|\n * | `TokenResponse` `{access_token, refresh_token, token_type, user}` | `{ kind: \"signed-in\" }`, after the app has stored the session |\n * | `{requires_2fa: true, challenge_token}` | `{ kind: \"2fa\", challengeToken: challenge_token }` |\n * | `{requires_password_change: true, challenge_token, encrypted}` | `{ kind: \"password-change\", challengeToken: challenge_token, extra: { encrypted } }` |\n * | `401 {code: \"invalid_credentials\"}` | reject — let the client's error through |\n *\n * ```ts\n * async function toAnswer(res: TokenResponse | TwoFactorChallenge | PasswordChangeChallenge): Promise<SignInAnswer> {\n * if (\"requires_2fa\" in res) return { kind: \"2fa\", challengeToken: res.challenge_token };\n * if (\"requires_password_change\" in res)\n * return { kind: \"password-change\", challengeToken: res.challenge_token, extra: { encrypted: res.encrypted } };\n * await onLoginSuccess(res); // store tokens, load /auth/me, switch language\n * return { kind: \"signed-in\" };\n * }\n * <SignInForm onSubmit={async (v) => toAnswer(await authApi.login(v))} … />\n * ```\n *\n * The same mapping serves `/auth/login/2fa`, `/auth/login/set-password` and the passkey\n * finish, which answer the same union.\n */\nexport type SignInAnswer =\n | { kind: \"signed-in\" }\n | { kind: \"2fa\"; challengeToken: string }\n | {\n kind: \"password-change\";\n challengeToken: string;\n /** The challenge's app fields, passed through untouched — keksdose's `encrypted`,\n * which its note on this step reads (`passwordChangeContent`). */\n extra?: Readonly<Record<string, unknown>>;\n };\n\n/** The step on screen: the credentials, the second factor, or a new password. */\nexport type SignInStep = \"credentials\" | \"2fa\" | \"password-change\";\n\n/** What the person did when a call failed — {@link SignInFormProps.describeError}'s\n * second argument. */\nexport type SignInAction = \"password\" | \"passkey\" | \"code\" | \"set-password\";\n\nexport interface SignInCredentials {\n /** Trimmed. Lower-casing is the server's (§3.1). */\n email: string;\n /** As typed, never trimmed. */\n password: string;\n}\n\nexport interface SignInCodeValues {\n challengeToken: string;\n /** Digits only — {@link OneTimeCodeInput} drops the spaces of \"123 456\". */\n code: string;\n}\n\nexport interface SignInNewPasswordValues {\n challengeToken: string;\n password: string;\n}\n\n/* ── Labels ──────────────────────────────────────────────────────────────── */\n\n/**\n * Every string `SignInForm` renders — the `signIn` namespace of `<UiKitProvider\n * labels>`, overridable per instance through `labels`. keksdose's words where it has\n * them (`auth.*` in its catalogue).\n */\nexport interface SignInLabels {\n email: string;\n password: string;\n /** The submit button. */\n submit: string;\n /** The passkey button (`onPasskey`). */\n passkey: string;\n /** The link to `forgotHref`. */\n forgotPassword: string;\n /** Before the link to `registerHref`. */\n noAccount: string;\n /** The link to `registerHref`. */\n register: string;\n /** The ONE answer to an unknown address, a wrong password and a deactivated account\n * (`invalid_credentials`, §5.2). */\n invalidCredentials: string;\n /** Any other failed sign-in (the network, a 500). */\n failed: string;\n /** A failed or refused passkey sign-in. */\n passkeyFailed: string;\n /**\n * The hint under `invalidCredentials` (§2.10), shown when `deactivatedContact` is\n * given. A TEMPLATE: `{contact}` is replaced by the contact — a `mailto:` link for an\n * address — so a language puts it where its grammar needs it.\n */\n deactivatedHint: string;\n /** The hint under `invalidCredentials` when `emailTag` is given (§4.5), given the\n * typed address with the app's tag: \"Signed up with ada+kastlan@example.com?\". */\n tagHint: (taggedAddress: string) => string;\n /** The second-factor step's heading. */\n twoFactorTitle: string;\n twoFactorIntro: string;\n /** The code field's label. */\n code: string;\n /** The code step's submit button. */\n verify: string;\n /** The code was refused. */\n codeInvalid: string;\n /** The set-a-new-password step's heading. */\n setPasswordTitle: string;\n setPasswordIntro: string;\n newPassword: string;\n confirmPassword: string;\n passwordMismatch: string;\n /** The set-a-new-password step's submit button. */\n setPasswordSubmit: string;\n setPasswordFailed: string;\n /** A challenge was refused as `token_invalid` — it expired between the steps; the\n * form is back on the credentials. */\n expired: string;\n /** From the second and third step back to the credentials. */\n backToSignIn: string;\n}\n\nexport const DEFAULT_SIGN_IN_LABELS: SignInLabels = {\n email: \"Email\",\n password: \"Password\",\n submit: \"Sign in\",\n passkey: \"Sign in with a passkey\",\n forgotPassword: \"Forgot your password?\",\n noAccount: \"No account yet?\",\n register: \"Create account\",\n invalidCredentials: \"The email or password is incorrect.\",\n failed: \"Sign-in failed. Please try again.\",\n passkeyFailed: \"Passkey sign-in failed.\",\n deactivatedHint: \"Account deactivated? Write to {contact}.\",\n tagHint: (taggedAddress) => `Signed up with ${taggedAddress}? Use that address.`,\n twoFactorTitle: \"Two-factor authentication\",\n twoFactorIntro: \"Enter the code your authenticator app shows.\",\n code: \"2FA code\",\n verify: \"Verify\",\n codeInvalid: \"Invalid 2FA code.\",\n setPasswordTitle: \"Choose a new password\",\n setPasswordIntro: \"A new password was requested for this account. Choose one and you are straight back in.\",\n newPassword: \"New password\",\n confirmPassword: \"Repeat new password\",\n passwordMismatch: \"The passwords don't match.\",\n setPasswordSubmit: \"Set password and sign in\",\n setPasswordFailed: \"The password could not be set.\",\n expired: \"This sign-in has expired. Please sign in again.\",\n backToSignIn: \"Back to sign in\",\n};\n\n/* ── Props ───────────────────────────────────────────────────────────────── */\n\nexport interface SignInFormProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSubmit\" | \"children\"> {\n /**\n * The credentials step was submitted. Send them, and resolve with the answer\n * ({@link SignInAnswer}) or reject with the client's error. The form never sends a\n * request itself (§8): keksdose must see the password on its way, to refuse the same\n * string as an encryption passphrase later.\n *\n * On `signed-in` the form's job is over — it stays busy while the app navigates.\n */\n onSubmit: (credentials: SignInCredentials) => Promise<SignInAnswer>;\n /** The second factor was submitted (`/auth/login/2fa`). Resolves with the next answer\n * — keksdose may still require a new password after the code. */\n onCode: (values: SignInCodeValues) => Promise<SignInAnswer>;\n /** The new password was submitted (`/auth/login/set-password`). Resolves with the\n * answer, `signed-in` in practice; keksdose's `key_wrap_unchanged` note is the app's\n * to show from here. */\n onSetPassword: (values: SignInNewPasswordValues) => Promise<SignInAnswer>;\n /**\n * The passkey button was pressed: run the ceremony (`/auth/passkey/login/begin|finish`)\n * and resolve with its answer. It asks for NO email — a passkey is bound to the site,\n * and the browser offers every one it holds (keksdose #126). Left out, no button: pass\n * it only where `PublicKeyCredential` exists.\n */\n onPasskey?: () => Promise<SignInAnswer>;\n /**\n * Passkey autofill (conditional mediation). The email field is\n * `autoComplete=\"username webauthn\"`, so a pending `navigator.credentials.get({\n * mediation: \"conditional\" })` lists the site's passkeys in its dropdown. The form\n * calls this ONCE on mount; arm the request there and resolve with its answer when the\n * person picks a passkey, or with `null` when nothing happens. The signal aborts on\n * unmount — cancel the pending request then (keksdose: `armPasskeyAutofill(onDone,\n * signal)` + `cancelPasskeyAutofill()`). A rejection is silent: the button stays the\n * reliable path.\n */\n passkeyAutofill?: (signal: AbortSignal) => Promise<SignInAnswer | null | undefined>;\n /** \"Forgot your password?\" goes here — the app's `/forgot-password`. Left out, no\n * link. */\n forgotHref?: string;\n /** \"No account yet? Create account\" goes here — `/register`. Left out, no line. */\n registerHref?: string;\n /** The email field's start value — the reset page ends on \"Sign in\" with the address\n * filled in (§6.3). */\n defaultEmail?: string;\n /**\n * The app's address tag (`\"kastlan\"`, §4.5). After `invalid_credentials` the form also\n * says \"Signed up with you+kastlan@example.com? Use that address.\" — sign-in stays\n * exact, and the server looks nothing up.\n */\n emailTag?: string;\n /**\n * Who a deactivated user writes to (§2.10): an address (drawn as a `mailto:` link) or\n * the app's own node. Shown after `invalid_credentials` as \"Account deactivated? Write\n * to …\". Left out, no hint.\n */\n deactivatedContact?: ReactNode;\n /** Digits of the second factor. Default 6 (TOTP). */\n codeLength?: number;\n /** App content at the top of the credentials step — a notice, a demo button. */\n credentialsContent?: ReactNode;\n /** App content on the second-factor step, under its intro. */\n twoFactorContent?: ReactNode;\n /**\n * App content on the set-a-new-password step, under its intro — keksdose's\n * private-mode note (\"Your encrypted data is untouched …\"), which depends on the\n * challenge: pass a function and it gets the challenge's `extra`.\n */\n passwordChangeContent?: ReactNode | ((extra: Readonly<Record<string, unknown>> | undefined) => ReactNode);\n /**\n * The app's own words for a failure, or `undefined` for the kit's: a throttled\n * attempt (`429`), the device being offline. Asked first, for every failure; what it\n * returns replaces the message, and the `invalid_credentials` hints still follow.\n */\n describeError?: (error: unknown, action: SignInAction) => ReactNode | undefined;\n /** The step changed — retitle the page (`AuthLayout`'s `title`) if the app wants. */\n onStepChange?: (step: SignInStep) => void;\n /** The level of the second and third step's heading. Default `h2`, under the page's\n * `h1`; one level under `AuthLayout`'s `headingAs` where that is embedded lower. */\n headingAs?: \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n labels?: Partial<SignInLabels>;\n}\n\n/* ── Parts ───────────────────────────────────────────────────────────────── */\n\ninterface Failure {\n action: SignInAction;\n code: AuthErrorCode | undefined;\n message: ReactNode;\n /** The address the failed credentials carried — the tag hint names its tagged form. */\n email?: string;\n}\n\n/** `{contact}` in the template, replaced by the contact (a `mailto:` link for an\n * address). Split, not interpolated, so the link is an element. A template that lost\n * its placeholder still shows the contact, after it. */\nfunction withContact(template: string, contact: ReactNode): ReactNode[] {\n const node =\n typeof contact === \"string\" && contact.includes(\"@\") ? (\n <TextLink key=\"contact\" href={`mailto:${contact}`} tone=\"secondary\">\n {contact}\n </TextLink>\n ) : (\n <span key=\"contact\">{contact}</span>\n );\n if (!template.includes(\"{contact}\")) return [template, \" \", node];\n return template\n .split(/(\\{contact\\})/)\n .filter((part) => part !== \"\")\n .map((part) => (part === \"{contact}\" ? node : part));\n}\n\nconst HINT_CLASS = \"text-xs text-[var(--text-secondary)]\";\nconst INTRO_CLASS = \"text-sm text-[var(--text-secondary)]\";\n\n/* ── The form ────────────────────────────────────────────────────────────── */\n\n/**\n * Sign-in for every app (docs/auth-harmonization.md §5, §8): email and password, or a\n * passkey; then the second factor when it is on; then a new password when an admin\n * required one. keksdose's `LoginPage` and `ForcedPasswordChangeStep`\n * (features/auth/login-page.tsx, forced-password-change.tsx), as one component.\n *\n * **It never sends a request.** Each step hands its input to a callback and renders the\n * {@link SignInAnswer} it resolves with; a rejection is shown in the step it came from.\n * The challenge token lives in this component's state only, as in keksdose, so a reload\n * costs a fresh sign-in — no route, no storage.\n *\n * **One error for every wrong credential** (§2.10, §5.2): `invalid_credentials` shows one\n * sentence, whatever was wrong, plus two hints UNDER it — \"Account deactivated? Write to\n * …\" (`deactivatedContact`) and \"Signed up with you+kastlan@…? Use that address.\"\n * (`emailTag`). Any other failure says \"Sign-in failed\" and no hint: the hints answer a\n * refused credential, not a network that is down. `describeError` puts the app's words\n * on a failure the kit cannot know (a throttled attempt).\n *\n * **The steps.**\n * - Credentials: the email field is `username webauthn` (passkey autofill, see\n * `passkeyAutofill`), the password a `CurrentPasswordInput` (a password manager fills\n * it and never offers a new one). The submit is not disabled while the fields are\n * empty: a browser that autofills on load withholds the values until the first\n * interaction, and a disabled button would swallow that first click. The fields'\n * own `required` answers an empty submit instead. \"Forgot your password?\" sits under\n * the buttons, where someone whose password just failed is already looking\n * (keksdose #198).\n * - Second factor: {@link OneTimeCodeInput}, focused on arrival. \"Verify\" waits for the\n * whole code. A refused code stays here with its error; `token_invalid` (the\n * challenge expired) goes back to the credentials and says why. Kurvenschmiede has\n * no 2FA yet, and the step is here from the start, so adding it is backend work only\n * (§10.5).\n * - New password: new + confirm with the strength meter, the 8-character / 72-byte\n * rules and nothing else (§8). It reads as explained, not blocked (keksdose): the\n * person did nothing wrong.\n *\n * The password is dropped from state once the credentials are answered; \"Back to sign in\"\n * returns to an empty password field.\n */\nexport function SignInForm({\n onSubmit,\n onCode,\n onSetPassword,\n onPasskey,\n passkeyAutofill,\n forgotHref,\n registerHref,\n defaultEmail = \"\",\n emailTag,\n deactivatedContact,\n codeLength = 6,\n credentialsContent,\n twoFactorContent,\n passwordChangeContent,\n describeError,\n onStepChange,\n headingAs: Heading = \"h2\",\n labels: labelsProp,\n className,\n ...rest\n}: SignInFormProps) {\n const labels = useKitLabels(\"signIn\", DEFAULT_SIGN_IN_LABELS, labelsProp);\n const [step, setStep] = useState<SignInStep>(\"credentials\");\n const [email, setEmail] = useState(defaultEmail);\n const [password, setPassword] = useState(\"\");\n const [code, setCode] = useState(\"\");\n const [newPassword, setNewPassword] = useState(\"\");\n const [confirm, setConfirm] = useState(\"\");\n const [challenge, setChallenge] = useState<{ token: string; extra?: Readonly<Record<string, unknown>> } | null>(\n null,\n );\n // What is running: one call at a time. \"done\" after `signed-in` — the app has the\n // session and is leaving; the buttons stay busy so nothing is sent twice meanwhile.\n const [busy, setBusy] = useState<SignInAction | \"done\" | null>(null);\n const [failure, setFailure] = useState<Failure | null>(null);\n const headingId = useId();\n\n const emailRef = useRef<HTMLInputElement>(null);\n const passwordRef = useRef<HTMLInputElement>(null);\n const codeRef = useRef<HTMLInputElement>(null);\n const newPasswordRef = useRef<HTMLInputElement>(null);\n\n // A late answer after unmount (the app navigated away) must not set state.\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const goTo = (next: SignInStep) => {\n setStep(next);\n onStepChange?.(next);\n };\n\n const present = (answer: SignInAnswer) => {\n setFailure(null);\n if (answer.kind === \"signed-in\") {\n setBusy(\"done\");\n return;\n }\n setBusy(null);\n // The password has done its work; it does not stay in state for the next steps.\n setPassword(\"\");\n setCode(\"\");\n setNewPassword(\"\");\n setConfirm(\"\");\n if (answer.kind === \"2fa\") {\n setChallenge({ token: answer.challengeToken });\n goTo(\"2fa\");\n } else if (answer.kind === \"password-change\") {\n setChallenge({ token: answer.challengeToken, extra: answer.extra });\n goTo(\"password-change\");\n }\n };\n\n const messageFor = (error: unknown, action: SignInAction, code: AuthErrorCode | undefined): ReactNode => {\n const own = describeError?.(error, action);\n if (hasMessage(own)) return own;\n if (action === \"password\") return code === \"invalid_credentials\" ? labels.invalidCredentials : labels.failed;\n if (action === \"passkey\") return labels.passkeyFailed;\n if (action === \"code\") return code === \"token_invalid\" ? labels.expired : labels.codeInvalid;\n return code === \"token_invalid\" ? labels.expired : labels.setPasswordFailed;\n };\n\n const fail = (error: unknown, action: SignInAction, sentEmail?: string) => {\n setBusy(null);\n // Our own abort (a passkey ceremony cancelled by the unmount) is no failure.\n if ((error as { name?: unknown } | null)?.name === \"AbortError\") return;\n const code = authErrorCode(error);\n const message = messageFor(error, action, code);\n // The challenge expired between the steps: only a fresh sign-in helps.\n if ((action === \"code\" || action === \"set-password\") && code === \"token_invalid\") {\n setChallenge(null);\n setCode(\"\");\n setNewPassword(\"\");\n setConfirm(\"\");\n goTo(\"credentials\");\n }\n setFailure({ action, code, message, email: sentEmail });\n };\n\n const attempt = (action: SignInAction, call: () => Promise<SignInAnswer>, sentEmail?: string) => {\n if (busy) return;\n setBusy(action);\n setFailure(null);\n let result: Promise<SignInAnswer>;\n try {\n result = Promise.resolve(call());\n } catch (error) {\n result = Promise.reject(error);\n }\n result.then(\n (answer) => {\n if (mounted.current) present(answer);\n },\n (error: unknown) => {\n if (mounted.current) fail(error, action, sentEmail);\n },\n );\n };\n\n // Passkey autofill: armed once, on mount; the signal aborts on unmount. Its answer\n // arrives whenever the person picks a passkey from the email field's dropdown — and\n // is dropped if they have meanwhile started a sign-in of their own.\n const armAutofill = useEffectEvent((signal: AbortSignal) => passkeyAutofill?.(signal));\n const autofillAnswered = useEffectEvent((answer: SignInAnswer) => {\n if (busy === null) present(answer);\n });\n useEffect(() => {\n const controller = new AbortController();\n let pending: Promise<SignInAnswer | null | undefined>;\n try {\n pending = Promise.resolve(armAutofill(controller.signal));\n } catch (error) {\n pending = Promise.reject(error);\n }\n pending.then(\n (answer) => {\n if (answer && !controller.signal.aborted && mounted.current) autofillAnswered(answer);\n },\n () => {\n /* silent — unsupported, declined or aborted; the button stays the way in */\n },\n );\n return () => controller.abort();\n }, []);\n\n // Focus follows the step — not on mount (where it would pop a phone's keyboard over\n // the page), only once the person moved to another step.\n const shownStep = useRef(step);\n useEffect(() => {\n if (shownStep.current === step) return;\n shownStep.current = step;\n if (step === \"2fa\") codeRef.current?.focus();\n else if (step === \"password-change\") newPasswordRef.current?.focus();\n else if (emailRef.current?.value) passwordRef.current?.focus();\n else emailRef.current?.focus();\n }, [step]);\n\n const backToCredentials = () => {\n if (busy) return;\n setChallenge(null);\n setFailure(null);\n setCode(\"\");\n setNewPassword(\"\");\n setConfirm(\"\");\n goTo(\"credentials\");\n };\n\n const working = busy !== null;\n const rootClass = cn(\"space-y-3\", className);\n\n /* ── Step 2: the second factor ── */\n if (step === \"2fa\" && challenge) {\n const submitCode = (e: FormEvent) => {\n e.preventDefault();\n if (code.length !== codeLength) return;\n attempt(\"code\", () => onCode({ challengeToken: challenge.token, code }));\n };\n const codeError = failure?.action === \"code\" ? failure.message : undefined;\n return (\n <div {...rest} data-step=\"2fa\" className={rootClass}>\n <form className=\"space-y-3\" aria-labelledby={headingId} onSubmit={submitCode}>\n <Heading id={headingId} className=\"text-base font-semibold text-[var(--text-primary)]\">\n {labels.twoFactorTitle}\n </Heading>\n <p className={INTRO_CLASS}>{labels.twoFactorIntro}</p>\n {twoFactorContent}\n <OneTimeCodeInput\n ref={codeRef}\n label={labels.code}\n name=\"code\"\n value={code}\n length={codeLength}\n onChange={(next) => {\n setCode(next);\n if (failure) setFailure(null);\n }}\n readOnly={working}\n error={codeError}\n required\n />\n <Button type=\"submit\" className=\"w-full\" disabled={!working && code.length !== codeLength} pending={working}>\n {labels.verify}\n </Button>\n </form>\n <BackLink label={labels.backToSignIn} onClick={backToCredentials} disabled={working} />\n </div>\n );\n }\n\n /* ── Step 3: a new password ── */\n if (step === \"password-change\" && challenge) {\n const problem = newPasswordProblem(newPassword, confirm);\n const submitPassword = (e: FormEvent) => {\n e.preventDefault();\n if (problem) return;\n attempt(\"set-password\", () => onSetPassword({ challengeToken: challenge.token, password: newPassword }));\n };\n const content =\n typeof passwordChangeContent === \"function\" ? passwordChangeContent(challenge.extra) : passwordChangeContent;\n return (\n <div {...rest} data-step=\"password-change\" className={rootClass}>\n <form className=\"space-y-3\" aria-labelledby={headingId} onSubmit={submitPassword}>\n <Heading id={headingId} className=\"text-base font-semibold text-[var(--text-primary)]\">\n {labels.setPasswordTitle}\n </Heading>\n <p className={INTRO_CLASS}>{labels.setPasswordIntro}</p>\n {content}\n {/* Which account the new password is for, for the password manager: it files\n the new password under this username instead of guessing. */}\n {email !== \"\" && (\n <input type=\"email\" name=\"username\" autoComplete=\"username\" value={email} readOnly hidden />\n )}\n <NewPasswordFields\n password={newPassword}\n confirm={confirm}\n onPasswordChange={setNewPassword}\n onConfirmChange={setConfirm}\n busy={working}\n passwordRef={newPasswordRef}\n text={{ password: labels.newPassword, confirm: labels.confirmPassword, mismatch: labels.passwordMismatch }}\n />\n {failure?.action === \"set-password\" && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure.message}\n </AlertBanner>\n )}\n <Button type=\"submit\" className=\"w-full\" disabled={!working && problem !== null} pending={working}>\n {labels.setPasswordSubmit}\n </Button>\n </form>\n <BackLink label={labels.backToSignIn} onClick={backToCredentials} disabled={working} />\n </div>\n );\n }\n\n /* ── Step 1: the credentials ── */\n const submitCredentials = (e: FormEvent) => {\n e.preventDefault();\n const sent = email.trim();\n if (sent === \"\" || password === \"\") return;\n attempt(\"password\", () => onSubmit({ email: sent, password }), sent);\n };\n\n const refused = failure?.code === \"invalid_credentials\";\n const tagged =\n refused && failure?.action === \"password\" && emailTag && failure.email ? taggedEmail(failure.email, emailTag) : null;\n const showDeactivated = refused && hasMessage(deactivatedContact);\n\n return (\n <div {...rest} data-step=\"credentials\" className={rootClass}>\n <form className=\"space-y-3\" onSubmit={submitCredentials}>\n {credentialsContent}\n <Input\n ref={emailRef}\n type=\"email\"\n name=\"email\"\n // \"webauthn\" lets the browser list passkeys in this field's dropdown, paired\n // with the conditional request `passkeyAutofill` arms.\n autoComplete=\"username webauthn\"\n label={labels.email}\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n readOnly={working}\n required\n />\n <CurrentPasswordInput\n ref={passwordRef}\n name=\"password\"\n label={labels.password}\n value={password}\n onValueChange={setPassword}\n busy={working}\n required\n />\n {failure && (\n // One live region for the sentence and its hints: they are one answer.\n <div role=\"alert\" className=\"space-y-1.5\">\n <AlertBanner tone=\"danger\" size=\"sm\">\n {failure.message}\n </AlertBanner>\n {showDeactivated && (\n <p className={HINT_CLASS}>{withContact(labels.deactivatedHint, deactivatedContact)}</p>\n )}\n {tagged && <p className={HINT_CLASS}>{labels.tagHint(tagged)}</p>}\n </div>\n )}\n <Button type=\"submit\" className=\"w-full\" pending={busy === \"password\" || busy === \"done\"} disabled={busy === \"passkey\"}>\n {labels.submit}\n </Button>\n {onPasskey && (\n <Button\n type=\"button\"\n variant=\"secondary\"\n className=\"w-full\"\n pending={busy === \"passkey\"}\n disabled={busy === \"password\" || busy === \"done\"}\n onClick={() => attempt(\"passkey\", onPasskey)}\n >\n <KeyRound aria-hidden className=\"size-4\" />\n {labels.passkey}\n </Button>\n )}\n </form>\n {forgotHref !== undefined && (\n <p className=\"text-center text-sm\">\n <TextLink href={forgotHref} tone=\"secondary\">\n {labels.forgotPassword}\n </TextLink>\n </p>\n )}\n {registerHref !== undefined && (\n <p className=\"text-center text-sm text-[var(--text-secondary)]\">\n {labels.noAccount}{\" \"}\n <TextLink href={registerHref} tone=\"primary\">\n {labels.register}\n </TextLink>\n </p>\n )}\n </div>\n );\n}\n\n/** \"Back to sign in\" under the second and third step: a button, since it changes the\n * step in place rather than going anywhere. */\nfunction BackLink({ label, onClick, disabled }: { label: string; onClick: () => void; disabled: boolean }) {\n return (\n <p className=\"text-center text-sm\">\n <Button type=\"button\" variant=\"link\" tone=\"muted\" size=\"sm\" disabled={disabled} onClick={onClick}>\n {label}\n </Button>\n </p>\n );\n}\n"],"mappings":";AAgRM,cAkPE,YAlPF;AAhRN,SAAS,WAAW,gBAAgB,OAAO,QAAQ,gBAAgB;AAEnE,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AACzB,SAAS,QAAQ,aAAa;AAC9B,SAAS,qBAAqB;AAE9B,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAgI3B,MAAM,yBAAuC;AAAA,EAClD,OAAO;AAAA,EACP,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,SAAS,CAAC,kBAAkB,kBAAkB,aAAa;AAAA,EAC3D,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,cAAc;AAChB;AAkGA,SAAS,YAAY,UAAkB,SAAiC;AACtE,QAAM,OACJ,OAAO,YAAY,YAAY,QAAQ,SAAS,GAAG,IACjD,oBAAC,YAAuB,MAAM,UAAU,OAAO,IAAI,MAAK,aACrD,qBADW,SAEd,IAEA,oBAAC,UAAoB,qBAAX,SAAmB;AAEjC,MAAI,CAAC,SAAS,SAAS,WAAW,EA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,MAAM,GAAE;AAAA,SAC/D;AAAA,MAEF,oBAAC,UAAO,MAAK,UAAS,WAAU,UAAS,SAAS,SAAS,cAAc,SAAS,QAAQ,UAAU,SAAS,WAC1G,iBAAO,QACV;AAAA,MACC,aACC;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,SAAQ;AAAA,UACR,WAAU;AAAA,UACV,SAAS,SAAS;AAAA,UAClB,UAAU,SAAS,cAAc,SAAS;AAAA,UAC1C,SAAS,MAAM,QAAQ,WAAW,SAAS;AAAA,UAE3C;AAAA,gCAAC,YAAS,eAAW,MAAC,WAAU,UAAS;AAAA,YACxC,OAAO;AAAA;AAAA;AAAA,MACV;AAAA,OAEJ;AAAA,IACC,eAAe,UACd,oBAAC,OAAE,WAAU,uBACX,8BAAC,YAAS,MAAM,YAAY,MAAK,aAC9B,iBAAO,gBACV,GACF;AAAA,IAED,iBAAiB,UAChB,qBAAC,OAAE,WAAU,oDACV;AAAA,aAAO;AAAA,MAAW;AAAA,MACnB,oBAAC,YAAS,MAAM,cAAc,MAAK,WAChC,iBAAO,UACV;AAAA,OACF;AAAA,KAEJ;AAEJ;AAIA,SAAS,SAAS,EAAE,OAAO,SAAS,SAAS,GAA8D;AACzG,SACE,oBAAC,OAAE,WAAU,uBACX,8BAAC,UAAO,MAAK,UAAS,SAAQ,QAAO,MAAK,SAAQ,MAAK,MAAK,UAAoB,SAC7E,iBACH,GACF;AAEJ;","names":["code"]}
@@ -0,0 +1,78 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * The pieces the signed-out status pages share — {@link ForgotPasswordForm},
6
+ * {@link ResetPasswordForm}, {@link VerifyEmailStatus}, {@link AcceptInvitation} and
7
+ * {@link NotFoundPage} (docs/auth-harmonization.md §7).
8
+ *
9
+ * @internal Not part of the barrel; the pages are.
10
+ */
11
+ /** A heading level a page part may take. Default `h2`, under the page's `h1`
12
+ * (`AuthLayout`'s `title`, the app's name), as on `SignInForm`'s steps; deeper for a
13
+ * page embedded in another (a preview, the docs). */
14
+ type AuthHeadingLevel = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
15
+ /** The form pages' heading: start-aligned, the size of `SignInForm`'s step headings. */
16
+ declare const FORM_HEADING_CLASS = "text-base font-semibold text-[var(--text-primary)]";
17
+ /** The status pages' heading: centred over the centred outcome below it. */
18
+ declare const STATUS_HEADING_CLASS = "text-center text-base font-semibold text-[var(--text-primary)]";
19
+ declare const INTRO_CLASS = "text-sm text-[var(--text-secondary)]";
20
+ /**
21
+ * kastlan's outcome block (verify-email-page, reset-password-page): the kit's
22
+ * `EmptyState` without its dashed box, because it already sits in `AuthLayout`'s card —
23
+ * a box in a box. The icon and the title carry the tone.
24
+ */
25
+ declare const OUTCOME_CLASS = "border-0 bg-transparent px-0 py-3";
26
+ /** `href` with `key=value` added to its query, before any `#fragment`: the reset page's
27
+ * "Sign in" carries the address (`/login?email=ada%40example.com`). */
28
+ declare function withQuery(href: string, key: string, value: string): string;
29
+ /** What a callback's promise came to. */
30
+ type Settled<T> = {
31
+ ok: true;
32
+ value: T;
33
+ } | {
34
+ ok: false;
35
+ error: unknown;
36
+ };
37
+ /**
38
+ * Run `start(key)` ONCE per key, and hand what it settles to into `settle` — unless the
39
+ * key moved on in the meantime, when the stale answer is dropped.
40
+ *
41
+ * keksdose's verify-email and join pages fire their request from an effect behind a
42
+ * `useRef` guard, and say why: the token is single-use, and StrictMode's
43
+ * mount → unmount → remount would send it twice and turn a success into "invalid" on
44
+ * the second answer. The guard is the same here; there is deliberately no "unmounted"
45
+ * flag set in the cleanup, because StrictMode's simulated unmount would set it and the
46
+ * remount would never clear the guard — the page would hang on its spinner (the bug
47
+ * keksdose hit on /join with a react-query observer). A state update after a real
48
+ * unmount is a no-op in React 18 and later.
49
+ *
50
+ * `key === null` runs nothing (no token, not signed in yet) and forgets the last key, so
51
+ * the same token runs again once it is back.
52
+ */
53
+ declare function useOncePerKey<T>(key: string | null, start: (key: string) => T | Promise<T>, settle: (key: string, result: Settled<T>) => void): void;
54
+ /** Whether a callback's return is a promise to wait for. A callback that returns
55
+ * nothing is done when it returns. */
56
+ declare function isThenable(value: unknown): value is PromiseLike<unknown>;
57
+ /**
58
+ * Move focus to `ref` when `active` turns true — the outcome a person's own submit led
59
+ * to ("If an account exists … the link is on its way", "Your password has been
60
+ * changed"). The submit button they pressed is gone with the form, which drops focus to
61
+ * `<body>`; a screen reader then hears nothing at all. Focusing the message (a
62
+ * `tabIndex={-1}` box) reads it out and leaves the next Tab where the page continues.
63
+ */
64
+ declare function useFocusWhen(active: boolean, ref: {
65
+ current: HTMLElement | null;
66
+ }): void;
67
+ /** The box {@link useFocusWhen} focuses: centred, no focus ring of its own (it is not a
68
+ * control; the ring would read as one). */
69
+ declare function OutcomeMessage({ icon, children, focusRef, className, }: {
70
+ icon: ReactNode;
71
+ children: ReactNode;
72
+ focusRef?: {
73
+ current: HTMLDivElement | null;
74
+ };
75
+ className?: string;
76
+ }): react.JSX.Element;
77
+
78
+ export { type AuthHeadingLevel, FORM_HEADING_CLASS, INTRO_CLASS, OUTCOME_CLASS, OutcomeMessage, STATUS_HEADING_CLASS, type Settled, isThenable, useFocusWhen, useOncePerKey, withQuery };
@@ -0,0 +1,83 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from "react";
4
+ import { cn } from "../lib/cn.js";
5
+ const FORM_HEADING_CLASS = "text-base font-semibold text-[var(--text-primary)]";
6
+ const STATUS_HEADING_CLASS = "text-center text-base font-semibold text-[var(--text-primary)]";
7
+ const INTRO_CLASS = "text-sm text-[var(--text-secondary)]";
8
+ const OUTCOME_CLASS = "border-0 bg-transparent px-0 py-3";
9
+ function withQuery(href, key, value) {
10
+ const hash = href.indexOf("#");
11
+ const base = hash === -1 ? href : href.slice(0, hash);
12
+ const fragment = hash === -1 ? "" : href.slice(hash);
13
+ const separator = base.includes("?") ? base.endsWith("?") || base.endsWith("&") ? "" : "&" : "?";
14
+ return `${base}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}${fragment}`;
15
+ }
16
+ function useOncePerKey(key, start, settle) {
17
+ const latest = useRef({ start, settle });
18
+ useEffect(() => {
19
+ latest.current = { start, settle };
20
+ });
21
+ const current = useRef(null);
22
+ useEffect(() => {
23
+ if (key === null) {
24
+ current.current = null;
25
+ return;
26
+ }
27
+ if (current.current === key) return;
28
+ current.current = key;
29
+ const report = (result) => {
30
+ if (current.current === key) latest.current.settle(key, result);
31
+ };
32
+ let started;
33
+ try {
34
+ started = latest.current.start(key);
35
+ } catch (error) {
36
+ report({ ok: false, error });
37
+ return;
38
+ }
39
+ Promise.resolve(started).then(
40
+ (value) => report({ ok: true, value }),
41
+ (error) => report({ ok: false, error })
42
+ );
43
+ }, [key]);
44
+ }
45
+ function isThenable(value) {
46
+ return typeof value?.then === "function";
47
+ }
48
+ function useFocusWhen(active, ref) {
49
+ useEffect(() => {
50
+ if (active) ref.current?.focus();
51
+ }, [active, ref]);
52
+ }
53
+ function OutcomeMessage({
54
+ icon,
55
+ children,
56
+ focusRef,
57
+ className
58
+ }) {
59
+ return /* @__PURE__ */ jsxs(
60
+ "div",
61
+ {
62
+ ref: focusRef,
63
+ tabIndex: -1,
64
+ className: cn("flex flex-col items-center gap-2 py-2 text-center outline-none", className),
65
+ children: [
66
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "[&_svg]:size-10", children: icon }),
67
+ children
68
+ ]
69
+ }
70
+ );
71
+ }
72
+ export {
73
+ FORM_HEADING_CLASS,
74
+ INTRO_CLASS,
75
+ OUTCOME_CLASS,
76
+ OutcomeMessage,
77
+ STATUS_HEADING_CLASS,
78
+ isThenable,
79
+ useFocusWhen,
80
+ useOncePerKey,
81
+ withQuery
82
+ };
83
+ //# sourceMappingURL=status-parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/status-parts.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\n\n/**\n * The pieces the signed-out status pages share — {@link ForgotPasswordForm},\n * {@link ResetPasswordForm}, {@link VerifyEmailStatus}, {@link AcceptInvitation} and\n * {@link NotFoundPage} (docs/auth-harmonization.md §7).\n *\n * @internal Not part of the barrel; the pages are.\n */\n\n/** A heading level a page part may take. Default `h2`, under the page's `h1`\n * (`AuthLayout`'s `title`, the app's name), as on `SignInForm`'s steps; deeper for a\n * page embedded in another (a preview, the docs). */\nexport type AuthHeadingLevel = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n\n/** The form pages' heading: start-aligned, the size of `SignInForm`'s step headings. */\nexport const FORM_HEADING_CLASS = \"text-base font-semibold text-[var(--text-primary)]\";\n/** The status pages' heading: centred over the centred outcome below it. */\nexport const STATUS_HEADING_CLASS = \"text-center text-base font-semibold text-[var(--text-primary)]\";\nexport const INTRO_CLASS = \"text-sm text-[var(--text-secondary)]\";\n\n/**\n * kastlan's outcome block (verify-email-page, reset-password-page): the kit's\n * `EmptyState` without its dashed box, because it already sits in `AuthLayout`'s card —\n * a box in a box. The icon and the title carry the tone.\n */\nexport const OUTCOME_CLASS = \"border-0 bg-transparent px-0 py-3\";\n\n/** `href` with `key=value` added to its query, before any `#fragment`: the reset page's\n * \"Sign in\" carries the address (`/login?email=ada%40example.com`). */\nexport function withQuery(href: string, key: string, value: string): string {\n const hash = href.indexOf(\"#\");\n const base = hash === -1 ? href : href.slice(0, hash);\n const fragment = hash === -1 ? \"\" : href.slice(hash);\n const separator = base.includes(\"?\") ? (base.endsWith(\"?\") || base.endsWith(\"&\") ? \"\" : \"&\") : \"?\";\n return `${base}${separator}${encodeURIComponent(key)}=${encodeURIComponent(value)}${fragment}`;\n}\n\n/** What a callback's promise came to. */\nexport type Settled<T> = { ok: true; value: T } | { ok: false; error: unknown };\n\n/**\n * Run `start(key)` ONCE per key, and hand what it settles to into `settle` — unless the\n * key moved on in the meantime, when the stale answer is dropped.\n *\n * keksdose's verify-email and join pages fire their request from an effect behind a\n * `useRef` guard, and say why: the token is single-use, and StrictMode's\n * mount → unmount → remount would send it twice and turn a success into \"invalid\" on\n * the second answer. The guard is the same here; there is deliberately no \"unmounted\"\n * flag set in the cleanup, because StrictMode's simulated unmount would set it and the\n * remount would never clear the guard — the page would hang on its spinner (the bug\n * keksdose hit on /join with a react-query observer). A state update after a real\n * unmount is a no-op in React 18 and later.\n *\n * `key === null` runs nothing (no token, not signed in yet) and forgets the last key, so\n * the same token runs again once it is back.\n */\nexport function useOncePerKey<T>(\n key: string | null,\n start: (key: string) => T | Promise<T>,\n settle: (key: string, result: Settled<T>) => void,\n): void {\n const latest = useRef({ start, settle });\n useEffect(() => {\n latest.current = { start, settle };\n });\n const current = useRef<string | null>(null);\n useEffect(() => {\n if (key === null) {\n current.current = null;\n return;\n }\n if (current.current === key) return;\n current.current = key;\n const report = (result: Settled<T>) => {\n if (current.current === key) latest.current.settle(key, result);\n };\n let started: T | Promise<T>;\n try {\n started = latest.current.start(key);\n } catch (error) {\n report({ ok: false, error });\n return;\n }\n Promise.resolve(started).then(\n (value) => report({ ok: true, value }),\n (error: unknown) => report({ ok: false, error }),\n );\n }, [key]);\n}\n\n/** Whether a callback's return is a promise to wait for. A callback that returns\n * nothing is done when it returns. */\nexport function isThenable(value: unknown): value is PromiseLike<unknown> {\n return typeof (value as PromiseLike<unknown> | null)?.then === \"function\";\n}\n\n/**\n * Move focus to `ref` when `active` turns true — the outcome a person's own submit led\n * to (\"If an account exists … the link is on its way\", \"Your password has been\n * changed\"). The submit button they pressed is gone with the form, which drops focus to\n * `<body>`; a screen reader then hears nothing at all. Focusing the message (a\n * `tabIndex={-1}` box) reads it out and leaves the next Tab where the page continues.\n */\nexport function useFocusWhen(active: boolean, ref: { current: HTMLElement | null }): void {\n useEffect(() => {\n if (active) ref.current?.focus();\n }, [active, ref]);\n}\n\n/** The box {@link useFocusWhen} focuses: centred, no focus ring of its own (it is not a\n * control; the ring would read as one). */\nexport function OutcomeMessage({\n icon,\n children,\n focusRef,\n className,\n}: {\n icon: ReactNode;\n children: ReactNode;\n focusRef?: { current: HTMLDivElement | null };\n className?: string;\n}) {\n return (\n <div\n ref={focusRef}\n tabIndex={-1}\n className={cn(\"flex flex-col items-center gap-2 py-2 text-center outline-none\", className)}\n >\n <span aria-hidden className=\"[&_svg]:size-10\">\n {icon}\n </span>\n {children}\n </div>\n );\n}\n"],"mappings":";AA8HI,SAKE,KALF;AA9HJ,SAAS,WAAW,cAAc;AAElC,SAAS,UAAU;AAgBZ,MAAM,qBAAqB;AAE3B,MAAM,uBAAuB;AAC7B,MAAM,cAAc;AAOpB,MAAM,gBAAgB;AAItB,SAAS,UAAU,MAAc,KAAa,OAAuB;AAC1E,QAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,QAAM,OAAO,SAAS,KAAK,OAAO,KAAK,MAAM,GAAG,IAAI;AACpD,QAAM,WAAW,SAAS,KAAK,KAAK,KAAK,MAAM,IAAI;AACnD,QAAM,YAAY,KAAK,SAAS,GAAG,IAAK,KAAK,SAAS,GAAG,KAAK,KAAK,SAAS,GAAG,IAAI,KAAK,MAAO;AAC/F,SAAO,GAAG,IAAI,GAAG,SAAS,GAAG,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,KAAK,CAAC,GAAG,QAAQ;AAC9F;AAqBO,SAAS,cACd,KACA,OACA,QACM;AACN,QAAM,SAAS,OAAO,EAAE,OAAO,OAAO,CAAC;AACvC,YAAU,MAAM;AACd,WAAO,UAAU,EAAE,OAAO,OAAO;AAAA,EACnC,CAAC;AACD,QAAM,UAAU,OAAsB,IAAI;AAC1C,YAAU,MAAM;AACd,QAAI,QAAQ,MAAM;AAChB,cAAQ,UAAU;AAClB;AAAA,IACF;AACA,QAAI,QAAQ,YAAY,IAAK;AAC7B,YAAQ,UAAU;AAClB,UAAM,SAAS,CAAC,WAAuB;AACrC,UAAI,QAAQ,YAAY,IAAK,QAAO,QAAQ,OAAO,KAAK,MAAM;AAAA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