@eifi1/ui-kit 0.28.1 → 0.30.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 (228) hide show
  1. package/README.md +44 -4
  2. package/dist/account/account-parts.d.ts +21 -0
  3. package/dist/account/account-parts.js +40 -0
  4. package/dist/account/account-parts.js.map +1 -0
  5. package/dist/account/data-export-setting.d.ts +73 -0
  6. package/dist/account/data-export-setting.js +113 -0
  7. package/dist/account/data-export-setting.js.map +1 -0
  8. package/dist/account/delete-account-setting.d.ts +91 -0
  9. package/dist/account/delete-account-setting.js +199 -0
  10. package/dist/account/delete-account-setting.js.map +1 -0
  11. package/dist/account/email-change-setting.d.ts +136 -0
  12. package/dist/account/email-change-setting.js +277 -0
  13. package/dist/account/email-change-setting.js.map +1 -0
  14. package/dist/account/sessions-setting.d.ts +110 -0
  15. package/dist/account/sessions-setting.js +146 -0
  16. package/dist/account/sessions-setting.js.map +1 -0
  17. package/dist/admin/admin-action-confirm.d.ts +91 -0
  18. package/dist/admin/admin-action-confirm.js +276 -0
  19. package/dist/admin/admin-action-confirm.js.map +1 -0
  20. package/dist/admin/admin-action-log.d.ts +105 -0
  21. package/dist/admin/admin-action-log.js +153 -0
  22. package/dist/admin/admin-action-log.js.map +1 -0
  23. package/dist/admin/admin-parts.d.ts +40 -0
  24. package/dist/admin/admin-parts.js +45 -0
  25. package/dist/admin/admin-parts.js.map +1 -0
  26. package/dist/admin/invitations-panel.d.ts +91 -0
  27. package/dist/admin/invitations-panel.js +289 -0
  28. package/dist/admin/invitations-panel.js.map +1 -0
  29. package/dist/admin/reviewer-scope-editor.d.ts +91 -0
  30. package/dist/admin/reviewer-scope-editor.js +134 -0
  31. package/dist/admin/reviewer-scope-editor.js.map +1 -0
  32. package/dist/admin/role-select.d.ts +91 -0
  33. package/dist/admin/role-select.js +128 -0
  34. package/dist/admin/role-select.js.map +1 -0
  35. package/dist/admin/transfer-ownership-dialog.d.ts +91 -0
  36. package/dist/admin/transfer-ownership-dialog.js +83 -0
  37. package/dist/admin/transfer-ownership-dialog.js.map +1 -0
  38. package/dist/admin/user-roster.d.ts +91 -0
  39. package/dist/admin/user-roster.js +285 -0
  40. package/dist/admin/user-roster.js.map +1 -0
  41. package/dist/auth/accept-invitation.d.ts +90 -0
  42. package/dist/auth/accept-invitation.js +117 -0
  43. package/dist/auth/accept-invitation.js.map +1 -0
  44. package/dist/auth/auth-errors.d.ts +139 -0
  45. package/dist/auth/auth-errors.js +92 -0
  46. package/dist/auth/auth-errors.js.map +1 -0
  47. package/dist/auth/complete-name-dialog.d.ts +71 -0
  48. package/dist/auth/complete-name-dialog.js +168 -0
  49. package/dist/auth/complete-name-dialog.js.map +1 -0
  50. package/dist/auth/email-tag.d.ts +60 -0
  51. package/dist/auth/email-tag.js +23 -0
  52. package/dist/auth/email-tag.js.map +1 -0
  53. package/dist/auth/forgot-password-form.d.ts +86 -0
  54. package/dist/auth/forgot-password-form.js +123 -0
  55. package/dist/auth/forgot-password-form.js.map +1 -0
  56. package/dist/auth/form-rules.d.ts +27 -0
  57. package/dist/auth/form-rules.js +23 -0
  58. package/dist/auth/form-rules.js.map +1 -0
  59. package/dist/auth/new-password-fields.d.ts +38 -0
  60. package/dist/auth/new-password-fields.js +54 -0
  61. package/dist/auth/new-password-fields.js.map +1 -0
  62. package/dist/auth/not-found-page.d.ts +57 -0
  63. package/dist/auth/not-found-page.js +40 -0
  64. package/dist/auth/not-found-page.js.map +1 -0
  65. package/dist/auth/register-form.d.ts +91 -0
  66. package/dist/auth/register-form.js +270 -0
  67. package/dist/auth/register-form.js.map +1 -0
  68. package/dist/auth/reset-password-form.d.ts +131 -0
  69. package/dist/auth/reset-password-form.js +167 -0
  70. package/dist/auth/reset-password-form.js.map +1 -0
  71. package/dist/auth/sign-in-form.d.ts +295 -0
  72. package/dist/auth/sign-in-form.js +426 -0
  73. package/dist/auth/sign-in-form.js.map +1 -0
  74. package/dist/auth/status-parts.d.ts +78 -0
  75. package/dist/auth/status-parts.js +83 -0
  76. package/dist/auth/status-parts.js.map +1 -0
  77. package/dist/auth/verify-email.d.ts +126 -0
  78. package/dist/auth/verify-email.js +243 -0
  79. package/dist/auth/verify-email.js.map +1 -0
  80. package/dist/chart.d.ts +25 -5
  81. package/dist/components/account-chips.d.ts +47 -7
  82. package/dist/components/account-chips.js +19 -3
  83. package/dist/components/account-chips.js.map +1 -1
  84. package/dist/components/account-settings-labels.d.ts +12 -1
  85. package/dist/components/account-settings-labels.js +4 -1
  86. package/dist/components/account-settings-labels.js.map +1 -1
  87. package/dist/components/account-settings.d.ts +61 -6
  88. package/dist/components/account-settings.js +115 -15
  89. package/dist/components/account-settings.js.map +1 -1
  90. package/dist/components/amount-input.d.ts +26 -5
  91. package/dist/components/button-group.d.ts +26 -5
  92. package/dist/components/calculator.d.ts +26 -5
  93. package/dist/components/confirm-dialog.d.ts +26 -5
  94. package/dist/components/copy-button.d.ts +23 -2
  95. package/dist/components/danger-confirm.d.ts +26 -5
  96. package/dist/components/facing-pair.d.ts +26 -5
  97. package/dist/components/file-button.d.ts +26 -5
  98. package/dist/components/file-dropzone.d.ts +26 -5
  99. package/dist/components/form-actions.d.ts +26 -5
  100. package/dist/components/iban-input.d.ts +26 -5
  101. package/dist/components/language-select.d.ts +26 -12
  102. package/dist/components/legal-page.d.ts +26 -5
  103. package/dist/components/legal.d.ts +26 -5
  104. package/dist/components/money-field.d.ts +26 -5
  105. package/dist/components/number-field.d.ts +26 -5
  106. package/dist/components/number-input.d.ts +26 -5
  107. package/dist/components/numpad-sheet.d.ts +26 -5
  108. package/dist/components/phone-input.d.ts +26 -5
  109. package/dist/components/series-chart.d.ts +26 -5
  110. package/dist/components/settings-fields.d.ts +25 -7
  111. package/dist/components/share-card.d.ts +25 -4
  112. package/dist/components/text-link.d.ts +26 -5
  113. package/dist/components/time-input.d.ts +26 -5
  114. package/dist/components/ui.d.ts +23 -2
  115. package/dist/components/user-avatar.d.ts +16 -2
  116. package/dist/components/user-avatar.js +7 -3
  117. package/dist/components/user-avatar.js.map +1 -1
  118. package/dist/{kit-labels-Du0uHBq4.d.ts → delete-account-setting-CGVMckMw.d.ts} +6654 -5302
  119. package/dist/feedback/feedback-attachment.d.ts +26 -5
  120. package/dist/feedback/feedback-context.d.ts +26 -5
  121. package/dist/feedback/feedback-crash.d.ts +26 -5
  122. package/dist/feedback/feedback-dialog.d.ts +26 -5
  123. package/dist/feedback/feedback-inbox.d.ts +26 -5
  124. package/dist/feedback/feedback-labels.d.ts +26 -5
  125. package/dist/feedback/feedback-menu.d.ts +26 -5
  126. package/dist/feedback/feedback-record.d.ts +26 -5
  127. package/dist/feedback/feedback-row-detail.d.ts +26 -5
  128. package/dist/feedback/feedback-status-undo.d.ts +26 -5
  129. package/dist/feedback/feedback-submit.d.ts +26 -5
  130. package/dist/feedback/feedback-swipe.d.ts +26 -5
  131. package/dist/feedback/feedback-table.d.ts +23 -2
  132. package/dist/feedback/feedback-thread.d.ts +26 -5
  133. package/dist/feedback.d.ts +26 -5
  134. package/dist/hooks/use-anchored-panel.d.ts +6 -2
  135. package/dist/hooks/use-anchored-panel.js +2 -1
  136. package/dist/hooks/use-anchored-panel.js.map +1 -1
  137. package/dist/hooks/use-file-drop.d.ts +26 -5
  138. package/dist/i18n/defaults.d.ts +26 -5
  139. package/dist/i18n/defaults.js +40 -0
  140. package/dist/i18n/defaults.js.map +1 -1
  141. package/dist/i18n/german.d.ts +26 -5
  142. package/dist/i18n/german.js +343 -2
  143. package/dist/i18n/german.js.map +1 -1
  144. package/dist/i18n/kit-labels.d.ts +23 -2
  145. package/dist/i18n/kit-labels.js.map +1 -1
  146. package/dist/i18n/languages.d.ts +21 -204
  147. package/dist/i18n/locales/de-CH.d.ts +26 -5
  148. package/dist/i18n/locales/en.d.ts +26 -5
  149. package/dist/i18n/locales/es.d.ts +26 -5
  150. package/dist/i18n/locales/es.js +337 -3
  151. package/dist/i18n/locales/es.js.map +1 -1
  152. package/dist/i18n/locales/fr.d.ts +26 -5
  153. package/dist/i18n/locales/fr.js +344 -2
  154. package/dist/i18n/locales/fr.js.map +1 -1
  155. package/dist/i18n/locales/hu.d.ts +26 -5
  156. package/dist/i18n/locales/hu.js +337 -3
  157. package/dist/i18n/locales/hu.js.map +1 -1
  158. package/dist/i18n/locales/it.d.ts +26 -5
  159. package/dist/i18n/locales/it.js +342 -2
  160. package/dist/i18n/locales/it.js.map +1 -1
  161. package/dist/i18n/locales/zh.d.ts +26 -5
  162. package/dist/i18n/locales/zh.js +333 -2
  163. package/dist/i18n/locales/zh.js.map +1 -1
  164. package/dist/i18n/review.d.ts +26 -5
  165. package/dist/i18n/review.js +45 -1
  166. package/dist/i18n/review.js.map +1 -1
  167. package/dist/index.d.ts +19 -3
  168. package/dist/index.js +89 -0
  169. package/dist/index.js.map +1 -1
  170. package/dist/lib/person-name.d.ts +69 -0
  171. package/dist/lib/person-name.js +65 -0
  172. package/dist/lib/person-name.js.map +1 -0
  173. package/dist/rhf/fields.d.ts +26 -5
  174. package/dist/rhf/form.d.ts +26 -5
  175. package/dist/rhf.d.ts +26 -5
  176. package/dist/shell/app-shell.d.ts +26 -5
  177. package/dist/shell/company-switcher.d.ts +59 -0
  178. package/dist/shell/company-switcher.js +85 -0
  179. package/dist/shell/company-switcher.js.map +1 -0
  180. package/dist/shell/top-bar-brand.d.ts +26 -5
  181. package/dist/shell/topbar-action-menu.d.ts +1 -0
  182. package/dist/shell.d.ts +20 -5
  183. package/dist/wizard/stepper-nav.d.ts +26 -5
  184. package/dist/wizard.d.ts +26 -5
  185. package/package.json +1 -1
  186. package/src/account/account-parts.ts +67 -0
  187. package/src/account/data-export-setting.tsx +218 -0
  188. package/src/account/delete-account-setting.tsx +362 -0
  189. package/src/account/email-change-setting.tsx +457 -0
  190. package/src/account/sessions-setting.tsx +283 -0
  191. package/src/admin/admin-action-confirm.tsx +495 -0
  192. package/src/admin/admin-action-log.tsx +297 -0
  193. package/src/admin/admin-parts.ts +82 -0
  194. package/src/admin/invitations-panel.tsx +516 -0
  195. package/src/admin/reviewer-scope-editor.tsx +234 -0
  196. package/src/admin/role-select.tsx +286 -0
  197. package/src/admin/transfer-ownership-dialog.tsx +172 -0
  198. package/src/admin/user-roster.tsx +573 -0
  199. package/src/auth/accept-invitation.tsx +227 -0
  200. package/src/auth/auth-errors.ts +262 -0
  201. package/src/auth/complete-name-dialog.tsx +253 -0
  202. package/src/auth/email-tag.ts +75 -0
  203. package/src/auth/forgot-password-form.tsx +229 -0
  204. package/src/auth/form-rules.ts +40 -0
  205. package/src/auth/new-password-fields.tsx +85 -0
  206. package/src/auth/not-found-page.tsx +98 -0
  207. package/src/auth/register-form.tsx +477 -0
  208. package/src/auth/reset-password-form.tsx +351 -0
  209. package/src/auth/sign-in-form.tsx +859 -0
  210. package/src/auth/status-parts.tsx +138 -0
  211. package/src/auth/verify-email.tsx +409 -0
  212. package/src/components/account-chips.tsx +64 -7
  213. package/src/components/account-settings-labels.ts +15 -1
  214. package/src/components/account-settings.tsx +199 -23
  215. package/src/components/user-avatar.tsx +22 -4
  216. package/src/hooks/use-anchored-panel.ts +14 -3
  217. package/src/i18n/defaults.ts +40 -0
  218. package/src/i18n/german.ts +379 -0
  219. package/src/i18n/kit-labels.tsx +60 -0
  220. package/src/i18n/locales/es.ts +371 -1
  221. package/src/i18n/locales/fr.ts +379 -0
  222. package/src/i18n/locales/hu.ts +366 -1
  223. package/src/i18n/locales/it.ts +373 -0
  224. package/src/i18n/locales/zh.ts +343 -0
  225. package/src/i18n/review.ts +44 -0
  226. package/src/index.ts +146 -0
  227. package/src/lib/person-name.ts +157 -0
  228. package/src/shell/company-switcher.tsx +140 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/accept-invitation.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { CheckCircle2, LogIn, TimerOff, XCircle } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { useAnnounce } from \"../hooks/use-announce\";\nimport { LoadingState } from \"../components/loading-state\";\nimport { Button, EmptyState } from \"../components/ui\";\nimport { authErrorCode } from \"./auth-errors\";\nimport { OUTCOME_CLASS, STATUS_HEADING_CLASS, useOncePerKey } from \"./status-parts\";\nimport type { AuthHeadingLevel } from \"./status-parts\";\n\n/* ── Labels ──────────────────────────────────────────────────────────────── */\n\n/** Every string the page renders — the `acceptInvitation` namespace. keksdose's words\n * where its `/join` page has them (`budget_share.join*`). */\nexport interface AcceptInvitationLabels {\n /** The heading. */\n title: string;\n /** While the invitation is accepted. */\n accepting: string;\n /** Accepted, when the app did not say into what. */\n accepted: string;\n /** Accepted, given what it attached the account to — a company, a team, a budget. */\n joined: (name: string) => string;\n /** Into the app, from every outcome but \"sign in first\". */\n continue: string;\n /** The token is unknown, spent, or for another address. */\n invalid: string;\n expired: string;\n /** The page was opened without a `token`. */\n noToken: string;\n /** Under `invalid` and `expired`: an invitation is re-sent as a new one (§4.4). */\n askAgain: string;\n /** Nobody is signed in: an existing account accepts after sign-in (§4.4). */\n signInFirst: string;\n /** Under it. */\n signInHint: string;\n signIn: string;\n /** Beside \"Sign in\", with `registerHref`. */\n register: string;\n}\n\nexport const DEFAULT_ACCEPT_INVITATION_LABELS: AcceptInvitationLabels = {\n title: \"Accept invitation\",\n accepting: \"Joining…\",\n accepted: \"Invitation accepted.\",\n joined: (name) => `You’ve joined ${name}.`,\n continue: \"Continue\",\n invalid: \"Could not join with this link\",\n expired: \"This invitation has expired\",\n noToken: \"This link is missing its invite token.\",\n askAgain: \"Ask the person who invited you to send a new invitation.\",\n signInFirst: \"Sign in to accept this invitation\",\n signInHint: \"Use the account the invitation was sent to.\",\n signIn: \"Sign in\",\n register: \"Create account\",\n};\n\n/* ── Types ───────────────────────────────────────────────────────────────── */\n\n/** What `onAccept` may resolve with. */\nexport interface AcceptInvitationResult {\n /** What the invitation attached the account to, by name — \"Example Property Ltd\",\n * \"Team North\", a budget. Said in the confirmation. */\n name?: string;\n}\n\n/** What became of an invitation that was not accepted. `signIn`: the server wants a\n * session first (a `401`), which `signedIn` did not know about. */\nexport type AcceptInvitationFailure = \"invalid\" | \"expired\" | \"signIn\";\n\ntype Outcome = \"accepted\" | AcceptInvitationFailure;\n\nexport interface AcceptInvitationProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\"> {\n /** The invitation's token — the app's `?invite=` / `?token=`. Empty: the link was cut\n * short, and the page says so without asking anyone. */\n token: string;\n /** Someone is signed in on this device. Until then the page asks for a sign-in and\n * sends nothing: accepting attaches the invitation to the SIGNED-IN account. */\n signedIn: boolean;\n /**\n * Accept it — `POST /auth/invitations/accept {token}`, once per token, as soon as\n * someone is signed in. Resolve (with what it attached the account to, if the app\n * knows); reject with the client's error.\n */\n onAccept: (token: string) => Promise<AcceptInvitationResult | void | undefined>;\n /** Which dead end a rejection is. Default: `invitation_expired` is `expired`,\n * anything else `invalid` (§5.2's codes). Map a `401` to `signIn` here. */\n classifyError?: (error: unknown) => AcceptInvitationFailure;\n /** \"Continue\" — into the app. Default `/`. */\n continueHref?: string;\n /** \"Sign in\" — the app's `/login`, with a way back here (`?next=…`). Default\n * `/login`. */\n signInHref?: string;\n /** \"Create account\" beside \"Sign in\", for an invitation that may lead to a new\n * account — the app's `/register?invite=…`. Left out, none. */\n registerHref?: string;\n /** The heading. Default `labels.title`; `null` draws none, for a page that puts it in\n * `AuthLayout`'s `title` instead. */\n title?: ReactNode;\n /** The heading's level. Default `h2`, under the page's `h1`. */\n headingAs?: AuthHeadingLevel;\n labels?: Partial<AcceptInvitationLabels>;\n}\n\n/**\n * Accept an invitation with an EXISTING account (docs/auth-harmonization.md §4.4): the\n * link leads here, the person signs in if they are not, and the app attaches the\n * invitation — a kastlan user joining a second company, a Kurvenschmiede member a team,\n * a keksdose user a shared budget. A new address never needs this page: its link opens\n * the sign-up form, which spends the invitation itself.\n *\n * keksdose's `JoinSharePage` (features/budgets/join-page.tsx) is the model: it accepts\n * on load, once (the token is single-use, and StrictMode's double effect would send it\n * twice), and shows the outcome where its spinner was. The outcomes: accepted, with the\n * way into the app; not valid; expired (both say to ask for a new invitation, since\n * \"resend\" mints a new token); or \"sign in first\", with nothing sent. \"Continue\" REPLACES\n * this page in the history: the token is spent, so Back must not land here again.\n */\nexport function AcceptInvitation({\n token,\n signedIn,\n onAccept,\n classifyError,\n continueHref = \"/\",\n signInHref = \"/login\",\n registerHref,\n title,\n headingAs: Heading = \"h2\",\n labels: labelsProp,\n className,\n ...rest\n}: AcceptInvitationProps) {\n const labels = useKitLabels(\"acceptInvitation\", DEFAULT_ACCEPT_INVITATION_LABELS, labelsProp);\n const [settled, setSettled] = useState<{ token: string; outcome: Outcome; name?: string } | null>(null);\n const { announce, regionProps } = useAnnounce();\n\n useOncePerKey(token !== \"\" && signedIn ? token : null, onAccept, (key, result) => {\n if (result.ok) {\n const name = result.value?.name?.trim() || undefined;\n setSettled({ token: key, outcome: \"accepted\", name });\n announce(name ? labels.joined(name) : labels.accepted);\n return;\n }\n const failure: AcceptInvitationFailure =\n classifyError?.(result.error) ?? (authErrorCode(result.error) === \"invitation_expired\" ? \"expired\" : \"invalid\");\n setSettled({ token: key, outcome: failure });\n announce(failure === \"signIn\" ? labels.signInFirst : labels[failure]);\n });\n\n const outcome: Outcome | \"accepting\" =\n token === \"\"\n ? \"invalid\"\n : settled?.token === token\n ? settled.outcome\n : signedIn\n ? \"accepting\"\n : \"signIn\";\n\n const continueButton = (variant: \"brand\" | \"secondary\") => (\n <Button href={continueHref} replace variant={variant}>\n {labels.continue}\n </Button>\n );\n\n let body: ReactNode;\n if (outcome === \"accepting\") {\n body = <LoadingState size=\"sm\" label={labels.accepting} />;\n } else if (outcome === \"accepted\") {\n body = (\n <EmptyState\n tone=\"success\"\n icon={<CheckCircle2 />}\n title={settled?.name ? labels.joined(settled.name) : labels.accepted}\n action={continueButton(\"brand\")}\n className={OUTCOME_CLASS}\n />\n );\n } else if (outcome === \"signIn\") {\n body = (\n <EmptyState\n icon={<LogIn />}\n title={labels.signInFirst}\n hint={labels.signInHint}\n action={\n <>\n <Button href={signInHref} variant=\"brand\">\n {labels.signIn}\n </Button>\n {registerHref !== undefined && (\n <Button href={registerHref} variant=\"secondary\">\n {labels.register}\n </Button>\n )}\n </>\n }\n className={OUTCOME_CLASS}\n />\n );\n } else {\n body = (\n <EmptyState\n tone=\"danger\"\n icon={outcome === \"expired\" ? <TimerOff /> : <XCircle />}\n title={token === \"\" ? labels.noToken : labels[outcome]}\n hint={labels.askAgain}\n action={signedIn ? continueButton(\"secondary\") : undefined}\n className={OUTCOME_CLASS}\n />\n );\n }\n\n return (\n <div\n {...rest}\n data-state={outcome}\n aria-busy={outcome === \"accepting\" || undefined}\n className={cn(\"space-y-3\", className)}\n >\n {title === null ? null : <Heading className={STATUS_HEADING_CLASS}>{title ?? labels.title}</Heading>}\n {body}\n {/* Rendered from the start, so the outcome is read when it arrives. */}\n <div {...regionProps} />\n </div>\n );\n}\n"],"mappings":";AAiKI,SAyBM,UAzBN,KAyBM,YAzBN;AAjKJ,SAAS,gBAAgB;AAEzB,SAAS,cAAc,OAAO,UAAU,eAAe;AACvD,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,kBAAkB;AACnC,SAAS,qBAAqB;AAC9B,SAAS,eAAe,sBAAsB,qBAAqB;AAkC5D,MAAM,mCAA2D;AAAA,EACtE,OAAO;AAAA,EACP,WAAW;AAAA,EACX,UAAU;AAAA,EACV,QAAQ,CAAC,SAAS,sBAAiB,IAAI;AAAA,EACvC,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,UAAU;AAAA,EACV,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,UAAU;AACZ;AA+DO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA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;AAAA;AAAA,IACb;AAAA,EAEJ,WAAW,YAAY,UAAU;AAC/B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAM,oBAAC,SAAM;AAAA,QACb,OAAO,OAAO;AAAA,QACd,MAAM,OAAO;AAAA,QACb,QACE,iCACE;AAAA,8BAAC,UAAO,MAAM,YAAY,SAAQ,SAC/B,iBAAO,QACV;AAAA,UACC,iBAAiB,UAChB,oBAAC,UAAO,MAAM,cAAc,SAAQ,aACjC,iBAAO,UACV;AAAA,WAEJ;AAAA,QAEF,WAAW;AAAA;AAAA,IACb;AAAA,EAEJ,OAAO;AACL,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,MAAM,YAAY,YAAY,oBAAC,YAAS,IAAK,oBAAC,WAAQ;AAAA,QACtD,OAAO,UAAU,KAAK,OAAO,UAAU,OAAO,OAAO;AAAA,QACrD,MAAM,OAAO;AAAA,QACb,QAAQ,WAAW,eAAe,WAAW,IAAI;AAAA,QACjD,WAAW;AAAA;AAAA,IACb;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,cAAY;AAAA,MACZ,aAAW,YAAY,eAAe;AAAA,MACtC,WAAW,GAAG,aAAa,SAAS;AAAA,MAEnC;AAAA,kBAAU,OAAO,OAAO,oBAAC,WAAQ,WAAW,sBAAuB,mBAAS,OAAO,OAAM;AAAA,QACzF;AAAA,QAED,oBAAC,SAAK,GAAG,aAAa;AAAA;AAAA;AAAA,EACxB;AAEJ;","names":[]}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The coded refusals of sign-in and sign-up (docs/auth-harmonization.md §5.2): every
3
+ * refusal the auth routes answer carries a machine-readable `code`, and the pages
4
+ * recognise the CODE, never the server's sentence.
5
+ *
6
+ * Today each app's pages print the server's `detail` string (keksdose's
7
+ * `extractApiErrorMessage`), which is English on every locale and, on a credential
8
+ * check, would be an account-enumeration oracle if it ever said more than one thing.
9
+ * keksdose already keys one refusal on a code (`features/budgets/plan-limit.ts`,
10
+ * `402 {detail, code: "plan_budget_limit"}`); §5.2 makes that the rule for auth. Each
11
+ * app switches its server and its pages together (§9).
12
+ *
13
+ * - `invalid_credentials` — unknown address, wrong password AND deactivated account:
14
+ * one answer, in the same time (§2.10). `401`.
15
+ * - `registration_closed` — the sign-up gate refused the address. `403`.
16
+ * - `email_taken` — an account with this address exists. `409`.
17
+ * - `invitation_invalid`, `invitation_expired` — the `invite` token of a sign-up or an
18
+ * accept (§4.4).
19
+ * - `token_invalid` — a one-time token (reset, verification, a sign-in challenge) is
20
+ * unknown, spent or expired.
21
+ * - `account_inactive` — **no server answers it.** §2.10 decided that a deactivated
22
+ * account gets `invalid_credentials`, because a separate answer after a correct
23
+ * password would confirm a leaked one. It stays in the union only for a future server
24
+ * step that is past the password (an admin view, a signed-in refresh) and may say so.
25
+ */
26
+ type AuthErrorCode = "invalid_credentials" | "registration_closed" | "email_taken" | "invitation_invalid" | "invitation_expired" | "token_invalid"
27
+ /** 0.29.1: a link that WAS valid and ran out (verification, reset) — keksdose's step-3
28
+ * refusals tell it from `token_invalid`, so a page can say "expired, ask for a new one". */
29
+ | "token_expired" | "account_inactive";
30
+ /**
31
+ * 0.30.0: the coded refusals of user administration and the account's own settings
32
+ * (docs/user-admin-harmonization.md §4, §6) — server-kit 0.4.0's `AccountErrorCode`,
33
+ * value for value. The same family of answer as the sign-in codes (`{detail, code}`,
34
+ * plus `companies` on kastlan's `last_admin`), read by the same {@link authErrorCode}.
35
+ *
36
+ * - `last_admin` — the action would leave no active admin: deactivating, demoting or
37
+ * deleting the last one (in kastlan, of a company; the answer names the `companies`).
38
+ * - `self_action` — an admin acting on their own account where that is never allowed.
39
+ * - `other_companies` — kastlan: the account belongs to other companies too, so a
40
+ * company admin may not deactivate it; "Remove from company" instead (§9.6).
41
+ * - `household_has_members` — keksdose's guard on a deletion request (§6.4).
42
+ * - `confirmation_required`, `confirmation_mismatch` — the action's confirmation level
43
+ * asked for a typed address (or a tick), and the request carried none, or another
44
+ * address (§4.2).
45
+ * - `password_incorrect` — the CURRENT password is wrong on a signed-in route (the email
46
+ * change, the deletion request). `400`, not `401`: an app's client reads a 401 as an
47
+ * ended session and signs the user out, the wrong answer to a typo. Every other one
48
+ * is a `409`.
49
+ */
50
+ type AccountErrorCode = "last_admin" | "self_action" | "other_companies" | "household_has_members" | "confirmation_required" | "confirmation_mismatch" | "password_incorrect";
51
+ /** Every code the kit reads: the sign-in refusals and the account ones (0.30.0). */
52
+ type KitErrorCode = AuthErrorCode | AccountErrorCode;
53
+ /**
54
+ * The code an error carries — an {@link AuthErrorCode}, or since 0.30.0 an
55
+ * {@link AccountErrorCode} — or `undefined` when it carries none.
56
+ *
57
+ * Reads the parsed response body wherever the apps' HTTP clients put it, without
58
+ * depending on any of them:
59
+ *
60
+ * 1. `err.response.data` — axios (keksdose's, kastlan's and Kurvenschmiede's clients;
61
+ * keksdose's `isPlanBudgetLimitRefusal` reads the same path);
62
+ * 2. `err.data` — ofetch's `FetchError`, and most `fetch` wrappers that parse the body;
63
+ * 3. `err.body` — the generated OpenAPI clients' `ApiError`;
64
+ * 4. `err` itself — a body thrown as it came (`throw await res.json()`).
65
+ *
66
+ * In each, `code` or FastAPI's nested `detail.code`. Last, `err.code` — but only when
67
+ * it is one of the codes above: axios writes its OWN codes there (`ERR_NETWORK`,
68
+ * `ECONNABORTED`, `ERR_BAD_REQUEST`), and so does Node, so an unknown value is never
69
+ * read as a refusal. The HTTP status is not checked: the code is the contract, and the
70
+ * status differs per refusal (401, 403, 409, 410).
71
+ */
72
+ declare function authErrorCode(err: unknown): KitErrorCode | undefined;
73
+ /**
74
+ * Whether `err` is a coded auth refusal — any of them, or the one named:
75
+ *
76
+ * ```ts
77
+ * try { await api.register(values) }
78
+ * catch (err) { if (isAuthError(err, "email_taken")) … }
79
+ * ```
80
+ *
81
+ * The kit's `SignInForm` and `RegisterForm` call it on what their callbacks reject
82
+ * with, so an app's `onSubmit` can simply let its client's error through. See
83
+ * {@link authErrorCode} for the shapes it reads. Since 0.30.0 it knows the account codes
84
+ * too: `isAuthError(err, "last_admin")`.
85
+ */
86
+ declare function isAuthError(err: unknown, code?: KitErrorCode): boolean;
87
+ /**
88
+ * Whether `err` is a throttled request — HTTP `429 Too Many Requests` (0.30.0, from the
89
+ * apps' 0.29 adoption: every app answered a throttled sign-in, sign-up or reset through
90
+ * its own `describeError`, with three wordings of one sentence).
91
+ *
92
+ * A throttle carries no `code` in the contract — the STATUS is the answer, set by the
93
+ * apps' limiters (server-kit's `AuthLimiters`, keksdose's per-IP limit) — so this reads
94
+ * the status, wherever the apps' HTTP clients put it, without depending on any of them:
95
+ *
96
+ * 1. `err.response.status` — axios (all three apps' clients);
97
+ * 2. `err.status` — ofetch's `FetchError`, the generated OpenAPI clients' `ApiError`, and
98
+ * a `Response` thrown as it came;
99
+ * 3. `err.statusCode` — ofetch's alias, and Node-style errors.
100
+ *
101
+ * There is no `rate_limited` code: keksdose answers its 429s uncoded, with a
102
+ * `Retry-After` header, and the status is the one signal every limiter gives.
103
+ *
104
+ * The kit's `SignInForm`, `RegisterForm`, `ForgotPasswordForm` and `ResetPasswordForm`
105
+ * call it AFTER the app's `describeError` — an app with words of its own keeps them —
106
+ * and before their generic failure, so "Too many attempts. Try again in 30 s." (with
107
+ * {@link retryAfterSeconds}) or "… Wait a moment and try again." needs no app code.
108
+ */
109
+ declare function isRateLimited(err: unknown): boolean;
110
+ /**
111
+ * How long a throttled request asks to wait, in whole seconds — its `Retry-After`
112
+ * header (0.30.0, keksdose: its 429s carry no code, only the header) — or `undefined`
113
+ * when there is none, or none that parses.
114
+ *
115
+ * Read where the apps' clients keep the response headers, without depending on any of
116
+ * them: `err.response.headers` (axios' `AxiosHeaders` or a plain record; ofetch's
117
+ * `FetchError.response`, a fetch `Headers`), then `err.headers` (a `Response` thrown as
118
+ * it came). The value is delta-seconds, or an HTTP date turned into seconds from `now`
119
+ * (default: the present moment) — never below 0.
120
+ *
121
+ * The forms hand it to their `rateLimited` label when {@link isRateLimited} is true:
122
+ * "Too many attempts. Try again in 30 s." — and, without one, "… Wait a moment and try
123
+ * again." A browser only exposes `Retry-After` to a cross-origin page when the server
124
+ * lists it in `Access-Control-Expose-Headers`.
125
+ */
126
+ declare function retryAfterSeconds(err: unknown, now?: number | Date): number | undefined;
127
+ /**
128
+ * The English of every `rateLimited` label (0.30.0): "Too many attempts. Try again in
129
+ * 30 s." with a wait under a minute, in whole minutes from one minute up (keksdose's
130
+ * reset throttle answers in hours, and "3600 s" is a number nobody reads), and "Wait a
131
+ * moment and try again." without one — or with a `0`.
132
+ *
133
+ * @internal The namespaces' English; not part of the barrel.
134
+ */
135
+ declare function englishRateLimited(seconds?: number): string;
136
+ /** "30 s", "2 min" — a wait in English, rounded up. @internal */
137
+ declare function englishWait(seconds: number): string;
138
+
139
+ export { type AccountErrorCode, type AuthErrorCode, type KitErrorCode, authErrorCode, englishRateLimited, englishWait, isAuthError, isRateLimited, retryAfterSeconds };
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ const CODES = /* @__PURE__ */ new Set([
3
+ "invalid_credentials",
4
+ "registration_closed",
5
+ "email_taken",
6
+ "invitation_invalid",
7
+ "invitation_expired",
8
+ "token_invalid",
9
+ "token_expired",
10
+ "account_inactive",
11
+ "last_admin",
12
+ "self_action",
13
+ "other_companies",
14
+ "household_has_members",
15
+ "confirmation_required",
16
+ "confirmation_mismatch",
17
+ "password_incorrect"
18
+ ]);
19
+ const isBag = (value) => typeof value === "object" && value !== null;
20
+ function known(value) {
21
+ return typeof value === "string" && CODES.has(value) ? value : void 0;
22
+ }
23
+ function codeOfBody(body) {
24
+ if (!isBag(body)) return void 0;
25
+ return known(body.code) ?? (isBag(body.detail) ? known(body.detail.code) : void 0);
26
+ }
27
+ function authErrorCode(err) {
28
+ if (!isBag(err)) return void 0;
29
+ const response = err.response;
30
+ return (isBag(response) ? codeOfBody(response.data) : void 0) ?? codeOfBody(err.data) ?? codeOfBody(err.body) ?? codeOfBody(err);
31
+ }
32
+ function isAuthError(err, code) {
33
+ const found = authErrorCode(err);
34
+ return found !== void 0 && (code === void 0 || found === code);
35
+ }
36
+ function statusOf(value) {
37
+ return typeof value === "number" && Number.isInteger(value) ? value : void 0;
38
+ }
39
+ function isRateLimited(err) {
40
+ if (!isBag(err)) return false;
41
+ const response = err.response;
42
+ const status = (isBag(response) ? statusOf(response.status) : void 0) ?? statusOf(err.status) ?? statusOf(err.statusCode);
43
+ return status === 429;
44
+ }
45
+ function headerOf(headers, name) {
46
+ if (!isBag(headers)) return void 0;
47
+ if (typeof headers.get === "function") {
48
+ try {
49
+ const value = headers.get.call(headers, name);
50
+ if (value !== void 0 && value !== null) return value;
51
+ } catch {
52
+ }
53
+ }
54
+ for (const [key, value] of Object.entries(headers)) {
55
+ if (key.toLowerCase() === name) return value;
56
+ }
57
+ return void 0;
58
+ }
59
+ function parseRetryAfter(value, now) {
60
+ const raw = Array.isArray(value) ? value[0] : value;
61
+ if (typeof raw === "number") return Number.isFinite(raw) && raw >= 0 ? Math.ceil(raw) : void 0;
62
+ if (typeof raw !== "string") return void 0;
63
+ const text = raw.trim();
64
+ if (/^\d+$/.test(text)) return Number(text);
65
+ if (!/[a-z]/i.test(text)) return void 0;
66
+ const at = Date.parse(text);
67
+ if (Number.isNaN(at)) return void 0;
68
+ return Math.max(0, Math.ceil((at - now) / 1e3));
69
+ }
70
+ function retryAfterSeconds(err, now = Date.now()) {
71
+ if (!isBag(err)) return void 0;
72
+ const at = typeof now === "number" ? now : now.getTime();
73
+ const response = err.response;
74
+ const value = (isBag(response) ? headerOf(response.headers, "retry-after") : void 0) ?? headerOf(err.headers, "retry-after");
75
+ return value === void 0 ? void 0 : parseRetryAfter(value, at);
76
+ }
77
+ function englishRateLimited(seconds) {
78
+ if (!seconds || seconds <= 0) return "Too many attempts. Wait a moment and try again.";
79
+ return `Too many attempts. Try again in ${englishWait(seconds)}.`;
80
+ }
81
+ function englishWait(seconds) {
82
+ return seconds < 60 ? `${Math.ceil(seconds)} s` : `${Math.ceil(seconds / 60)} min`;
83
+ }
84
+ export {
85
+ authErrorCode,
86
+ englishRateLimited,
87
+ englishWait,
88
+ isAuthError,
89
+ isRateLimited,
90
+ retryAfterSeconds
91
+ };
92
+ //# sourceMappingURL=auth-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/auth-errors.ts"],"sourcesContent":["/**\n * The coded refusals of sign-in and sign-up (docs/auth-harmonization.md §5.2): every\n * refusal the auth routes answer carries a machine-readable `code`, and the pages\n * recognise the CODE, never the server's sentence.\n *\n * Today each app's pages print the server's `detail` string (keksdose's\n * `extractApiErrorMessage`), which is English on every locale and, on a credential\n * check, would be an account-enumeration oracle if it ever said more than one thing.\n * keksdose already keys one refusal on a code (`features/budgets/plan-limit.ts`,\n * `402 {detail, code: \"plan_budget_limit\"}`); §5.2 makes that the rule for auth. Each\n * app switches its server and its pages together (§9).\n *\n * - `invalid_credentials` — unknown address, wrong password AND deactivated account:\n * one answer, in the same time (§2.10). `401`.\n * - `registration_closed` — the sign-up gate refused the address. `403`.\n * - `email_taken` — an account with this address exists. `409`.\n * - `invitation_invalid`, `invitation_expired` — the `invite` token of a sign-up or an\n * accept (§4.4).\n * - `token_invalid` — a one-time token (reset, verification, a sign-in challenge) is\n * unknown, spent or expired.\n * - `account_inactive` — **no server answers it.** §2.10 decided that a deactivated\n * account gets `invalid_credentials`, because a separate answer after a correct\n * password would confirm a leaked one. It stays in the union only for a future server\n * step that is past the password (an admin view, a signed-in refresh) and may say so.\n */\nexport type AuthErrorCode =\n | \"invalid_credentials\"\n | \"registration_closed\"\n | \"email_taken\"\n | \"invitation_invalid\"\n | \"invitation_expired\"\n | \"token_invalid\"\n /** 0.29.1: a link that WAS valid and ran out (verification, reset) — keksdose's step-3\n * refusals tell it from `token_invalid`, so a page can say \"expired, ask for a new one\". */\n | \"token_expired\"\n | \"account_inactive\";\n\n/**\n * 0.30.0: the coded refusals of user administration and the account's own settings\n * (docs/user-admin-harmonization.md §4, §6) — server-kit 0.4.0's `AccountErrorCode`,\n * value for value. The same family of answer as the sign-in codes (`{detail, code}`,\n * plus `companies` on kastlan's `last_admin`), read by the same {@link authErrorCode}.\n *\n * - `last_admin` — the action would leave no active admin: deactivating, demoting or\n * deleting the last one (in kastlan, of a company; the answer names the `companies`).\n * - `self_action` — an admin acting on their own account where that is never allowed.\n * - `other_companies` — kastlan: the account belongs to other companies too, so a\n * company admin may not deactivate it; \"Remove from company\" instead (§9.6).\n * - `household_has_members` — keksdose's guard on a deletion request (§6.4).\n * - `confirmation_required`, `confirmation_mismatch` — the action's confirmation level\n * asked for a typed address (or a tick), and the request carried none, or another\n * address (§4.2).\n * - `password_incorrect` — the CURRENT password is wrong on a signed-in route (the email\n * change, the deletion request). `400`, not `401`: an app's client reads a 401 as an\n * ended session and signs the user out, the wrong answer to a typo. Every other one\n * is a `409`.\n */\nexport type AccountErrorCode =\n | \"last_admin\"\n | \"self_action\"\n | \"other_companies\"\n | \"household_has_members\"\n | \"confirmation_required\"\n | \"confirmation_mismatch\"\n | \"password_incorrect\";\n\n/** Every code the kit reads: the sign-in refusals and the account ones (0.30.0). */\nexport type KitErrorCode = AuthErrorCode | AccountErrorCode;\n\nconst CODES: ReadonlySet<string> = new Set<KitErrorCode>([\n \"invalid_credentials\",\n \"registration_closed\",\n \"email_taken\",\n \"invitation_invalid\",\n \"invitation_expired\",\n \"token_invalid\",\n \"token_expired\",\n \"account_inactive\",\n \"last_admin\",\n \"self_action\",\n \"other_companies\",\n \"household_has_members\",\n \"confirmation_required\",\n \"confirmation_mismatch\",\n \"password_incorrect\",\n]);\n\ntype Bag = Record<string, unknown>;\n\nconst isBag = (value: unknown): value is Bag => typeof value === \"object\" && value !== null;\n\n/** A known code, or undefined. */\nfunction known(value: unknown): KitErrorCode | undefined {\n return typeof value === \"string\" && CODES.has(value) ? (value as KitErrorCode) : undefined;\n}\n\n/** `{code}` on a parsed body, or FastAPI's `{detail: {code}}` — what an\n * `HTTPException(detail={\"code\": …})` serialises to. */\nfunction codeOfBody(body: unknown): KitErrorCode | undefined {\n if (!isBag(body)) return undefined;\n return known(body.code) ?? (isBag(body.detail) ? known(body.detail.code) : undefined);\n}\n\n/**\n * The code an error carries — an {@link AuthErrorCode}, or since 0.30.0 an\n * {@link AccountErrorCode} — or `undefined` when it carries none.\n *\n * Reads the parsed response body wherever the apps' HTTP clients put it, without\n * depending on any of them:\n *\n * 1. `err.response.data` — axios (keksdose's, kastlan's and Kurvenschmiede's clients;\n * keksdose's `isPlanBudgetLimitRefusal` reads the same path);\n * 2. `err.data` — ofetch's `FetchError`, and most `fetch` wrappers that parse the body;\n * 3. `err.body` — the generated OpenAPI clients' `ApiError`;\n * 4. `err` itself — a body thrown as it came (`throw await res.json()`).\n *\n * In each, `code` or FastAPI's nested `detail.code`. Last, `err.code` — but only when\n * it is one of the codes above: axios writes its OWN codes there (`ERR_NETWORK`,\n * `ECONNABORTED`, `ERR_BAD_REQUEST`), and so does Node, so an unknown value is never\n * read as a refusal. The HTTP status is not checked: the code is the contract, and the\n * status differs per refusal (401, 403, 409, 410).\n */\nexport function authErrorCode(err: unknown): KitErrorCode | undefined {\n if (!isBag(err)) return undefined;\n const response = err.response;\n return (\n (isBag(response) ? codeOfBody(response.data) : undefined) ??\n codeOfBody(err.data) ??\n codeOfBody(err.body) ??\n codeOfBody(err)\n );\n}\n\n/**\n * Whether `err` is a coded auth refusal — any of them, or the one named:\n *\n * ```ts\n * try { await api.register(values) }\n * catch (err) { if (isAuthError(err, \"email_taken\")) … }\n * ```\n *\n * The kit's `SignInForm` and `RegisterForm` call it on what their callbacks reject\n * with, so an app's `onSubmit` can simply let its client's error through. See\n * {@link authErrorCode} for the shapes it reads. Since 0.30.0 it knows the account codes\n * too: `isAuthError(err, \"last_admin\")`.\n */\nexport function isAuthError(err: unknown, code?: KitErrorCode): boolean {\n const found = authErrorCode(err);\n return found !== undefined && (code === undefined || found === code);\n}\n\n/** An HTTP status as a number, or undefined. */\nfunction statusOf(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isInteger(value) ? value : undefined;\n}\n\n/**\n * Whether `err` is a throttled request — HTTP `429 Too Many Requests` (0.30.0, from the\n * apps' 0.29 adoption: every app answered a throttled sign-in, sign-up or reset through\n * its own `describeError`, with three wordings of one sentence).\n *\n * A throttle carries no `code` in the contract — the STATUS is the answer, set by the\n * apps' limiters (server-kit's `AuthLimiters`, keksdose's per-IP limit) — so this reads\n * the status, wherever the apps' HTTP clients put it, without depending on any of them:\n *\n * 1. `err.response.status` — axios (all three apps' clients);\n * 2. `err.status` — ofetch's `FetchError`, the generated OpenAPI clients' `ApiError`, and\n * a `Response` thrown as it came;\n * 3. `err.statusCode` — ofetch's alias, and Node-style errors.\n *\n * There is no `rate_limited` code: keksdose answers its 429s uncoded, with a\n * `Retry-After` header, and the status is the one signal every limiter gives.\n *\n * The kit's `SignInForm`, `RegisterForm`, `ForgotPasswordForm` and `ResetPasswordForm`\n * call it AFTER the app's `describeError` — an app with words of its own keeps them —\n * and before their generic failure, so \"Too many attempts. Try again in 30 s.\" (with\n * {@link retryAfterSeconds}) or \"… Wait a moment and try again.\" needs no app code.\n */\nexport function isRateLimited(err: unknown): boolean {\n if (!isBag(err)) return false;\n const response = err.response;\n const status =\n (isBag(response) ? statusOf(response.status) : undefined) ?? statusOf(err.status) ?? statusOf(err.statusCode);\n return status === 429;\n}\n\n/** A header's value from a `Headers` (fetch, ofetch's `response`), axios' `AxiosHeaders`\n * or a plain record — whose keys may come in any case. */\nfunction headerOf(headers: unknown, name: string): unknown {\n if (!isBag(headers)) return undefined;\n if (typeof headers.get === \"function\") {\n try {\n const value: unknown = (headers.get as (key: string) => unknown).call(headers, name);\n if (value !== undefined && value !== null) return value;\n } catch {\n // A `get` that is not a header lookup; the record below is.\n }\n }\n for (const [key, value] of Object.entries(headers)) {\n if (key.toLowerCase() === name) return value;\n }\n return undefined;\n}\n\n/** `Retry-After` as seconds from `now`: delta-seconds (\"30\"), or an HTTP date\n * (\"Wed, 07 Oct 2026 10:00:00 GMT\") counted from now, never below 0 (RFC 9110 §10.2.3). */\nfunction parseRetryAfter(value: unknown, now: number): number | undefined {\n const raw = Array.isArray(value) ? (value as unknown[])[0] : value;\n if (typeof raw === \"number\") return Number.isFinite(raw) && raw >= 0 ? Math.ceil(raw) : undefined;\n if (typeof raw !== \"string\") return undefined;\n const text = raw.trim();\n if (/^\\d+$/.test(text)) return Number(text);\n // An HTTP date names its day and month (\"Wed, 07 Oct 2026 …\"). Without a letter it is\n // a malformed number (\"-5\", \"1.5\"), which `Date.parse` would happily read as a year.\n if (!/[a-z]/i.test(text)) return undefined;\n const at = Date.parse(text);\n if (Number.isNaN(at)) return undefined;\n return Math.max(0, Math.ceil((at - now) / 1000));\n}\n\n/**\n * How long a throttled request asks to wait, in whole seconds — its `Retry-After`\n * header (0.30.0, keksdose: its 429s carry no code, only the header) — or `undefined`\n * when there is none, or none that parses.\n *\n * Read where the apps' clients keep the response headers, without depending on any of\n * them: `err.response.headers` (axios' `AxiosHeaders` or a plain record; ofetch's\n * `FetchError.response`, a fetch `Headers`), then `err.headers` (a `Response` thrown as\n * it came). The value is delta-seconds, or an HTTP date turned into seconds from `now`\n * (default: the present moment) — never below 0.\n *\n * The forms hand it to their `rateLimited` label when {@link isRateLimited} is true:\n * \"Too many attempts. Try again in 30 s.\" — and, without one, \"… Wait a moment and try\n * again.\" A browser only exposes `Retry-After` to a cross-origin page when the server\n * lists it in `Access-Control-Expose-Headers`.\n */\nexport function retryAfterSeconds(err: unknown, now: number | Date = Date.now()): number | undefined {\n if (!isBag(err)) return undefined;\n const at = typeof now === \"number\" ? now : now.getTime();\n const response = err.response;\n const value =\n (isBag(response) ? headerOf(response.headers, \"retry-after\") : undefined) ?? headerOf(err.headers, \"retry-after\");\n return value === undefined ? undefined : parseRetryAfter(value, at);\n}\n\n/**\n * The English of every `rateLimited` label (0.30.0): \"Too many attempts. Try again in\n * 30 s.\" with a wait under a minute, in whole minutes from one minute up (keksdose's\n * reset throttle answers in hours, and \"3600 s\" is a number nobody reads), and \"Wait a\n * moment and try again.\" without one — or with a `0`.\n *\n * @internal The namespaces' English; not part of the barrel.\n */\nexport function englishRateLimited(seconds?: number): string {\n if (!seconds || seconds <= 0) return \"Too many attempts. Wait a moment and try again.\";\n return `Too many attempts. Try again in ${englishWait(seconds)}.`;\n}\n\n/** \"30 s\", \"2 min\" — a wait in English, rounded up. @internal */\nexport function englishWait(seconds: number): string {\n return seconds < 60 ? `${Math.ceil(seconds)} s` : `${Math.ceil(seconds / 60)} min`;\n}\n"],"mappings":";AAqEA,MAAM,QAA6B,oBAAI,IAAkB;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAID,MAAM,QAAQ,CAAC,UAAiC,OAAO,UAAU,YAAY,UAAU;AAGvF,SAAS,MAAM,OAA0C;AACvD,SAAO,OAAO,UAAU,YAAY,MAAM,IAAI,KAAK,IAAK,QAAyB;AACnF;AAIA,SAAS,WAAW,MAAyC;AAC3D,MAAI,CAAC,MAAM,IAAI,EAAG,QAAO;AACzB,SAAO,MAAM,KAAK,IAAI,MAAM,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAC7E;AAqBO,SAAS,cAAc,KAAwC;AACpE,MAAI,CAAC,MAAM,GAAG,EAAG,QAAO;AACxB,QAAM,WAAW,IAAI;AACrB,UACG,MAAM,QAAQ,IAAI,WAAW,SAAS,IAAI,IAAI,WAC/C,WAAW,IAAI,IAAI,KACnB,WAAW,IAAI,IAAI,KACnB,WAAW,GAAG;AAElB;AAeO,SAAS,YAAY,KAAc,MAA8B;AACtE,QAAM,QAAQ,cAAc,GAAG;AAC/B,SAAO,UAAU,WAAc,SAAS,UAAa,UAAU;AACjE;AAGA,SAAS,SA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AkB,KAAc,MAAqB,KAAK,IAAI,GAAuB;AACnG,MAAI,CAAC,MAAM,GAAG,EAAG,QAAO;AACxB,QAAM,KAAK,OAAO,QAAQ,WAAW,MAAM,IAAI,QAAQ;AACvD,QAAM,WAAW,IAAI;AACrB,QAAM,SACH,MAAM,QAAQ,IAAI,SAAS,SAAS,SAAS,aAAa,IAAI,WAAc,SAAS,IAAI,SAAS,aAAa;AAClH,SAAO,UAAU,SAAY,SAAY,gBAAgB,OAAO,EAAE;AACpE;AAUO,SAAS,mBAAmB,SAA0B;AAC3D,MAAI,CAAC,WAAW,WAAW,EAAG,QAAO;AACrC,SAAO,mCAAmC,YAAY,OAAO,CAAC;AAChE;AAGO,SAAS,YAAY,SAAyB;AACnD,SAAO,UAAU,KAAK,GAAG,KAAK,KAAK,OAAO,CAAC,OAAO,GAAG,KAAK,KAAK,UAAU,EAAE,CAAC;AAC9E;","names":[]}
@@ -0,0 +1,71 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** What `CompleteNameDialog` hands `onSave`: both names, trimmed, 1–120 characters —
5
+ * `PATCH /auth/me {first_name, last_name}` (§6.1). */
6
+ interface CompleteNameValues {
7
+ firstName: string;
8
+ lastName: string;
9
+ }
10
+ /**
11
+ * Every string the dialog renders — the `completeName` namespace of `<UiKitProvider
12
+ * labels>`, overridable per instance through `labels`.
13
+ */
14
+ interface CompleteNameLabels {
15
+ title: string;
16
+ description: string;
17
+ firstName: string;
18
+ lastName: string;
19
+ save: string;
20
+ /** Dismisses the dialog until the next sign-in. */
21
+ later: string;
22
+ /** Under the fields when `onSave` rejected and the app passed no `error`. */
23
+ failed: string;
24
+ }
25
+ declare const DEFAULT_COMPLETE_NAME_LABELS: CompleteNameLabels;
26
+ interface CompleteNameDialogProps {
27
+ /** What the account holds now — after the migration, the old display name (§3.3). */
28
+ firstName?: string;
29
+ /** Usually empty: that is why the dialog is up. */
30
+ lastName?: string;
31
+ /**
32
+ * Save the names (`PATCH /auth/me`). Resolve and the dialog closes (`onClose(true)`);
33
+ * reject and it stays open with the names kept and `error` — or "Your name could not
34
+ * be saved" — under them.
35
+ */
36
+ onSave: (values: CompleteNameValues) => Promise<unknown>;
37
+ /**
38
+ * The dialog has closed: `true` after a resolved `onSave`, `false` for "Later", Escape,
39
+ * the backdrop and Back. `false` only DEFERS it: the app shows it again after the
40
+ * next sign-in while `/auth/me` still answers `name_incomplete: true`.
41
+ */
42
+ onClose: (saved: boolean) => void;
43
+ /** The app's words for the last failed save, instead of `labels.failed`. Hidden again
44
+ * once a name is edited. */
45
+ error?: ReactNode;
46
+ /** Kept-mounted mode, as on `Modal`: left out, the dialog is open while mounted. */
47
+ open?: boolean;
48
+ labels?: Partial<CompleteNameLabels>;
49
+ }
50
+ /**
51
+ * "Complete your name" — asked once after sign-in of a user whose name was migrated
52
+ * (docs/auth-harmonization.md §3.3). keksdose's and Kurvenschmiede's accounts had one
53
+ * `display_name`; it moved whole into `first_name`, `last_name` stayed empty, and
54
+ * nothing was split by guesswork (§2.4). The app shows this while `/auth/me` answers
55
+ * `name_incomplete: true` — never for a demo user.
56
+ *
57
+ * Both names prefilled with what is there; "Save" waits until both have 1–120
58
+ * characters after trimming. **"Later" only defers it**: nothing else waits on a
59
+ * complete name, no page is blocked, and the app asks again at the next sign-in.
60
+ *
61
+ * The promise handling is `ReauthDialog`'s: busy while `onSave` runs (the fields
62
+ * read-only, "Later" disabled, Escape held — a request that has left cannot be called
63
+ * back by closing the dialog), closed on resolve, kept open on reject. Save is a
64
+ * `commit` control, so a `WriteLockProvider` above it locks it with its reason.
65
+ *
66
+ * Focus starts in the first EMPTY field — the last name, as a rule — because filling it
67
+ * in is the whole of what the dialog is for.
68
+ */
69
+ declare function CompleteNameDialog({ firstName: initialFirst, lastName: initialLast, onSave, onClose, error, open, labels: labelsProp, }: CompleteNameDialogProps): react.JSX.Element;
70
+
71
+ export { CompleteNameDialog, type CompleteNameDialogProps, type CompleteNameLabels, type CompleteNameValues, DEFAULT_COMPLETE_NAME_LABELS };
@@ -0,0 +1,168 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useId, useRef, useState } from "react";
4
+ import { useKitLabels } from "../i18n/kit-labels.js";
5
+ import { usePromisePending } from "../components/danger-confirm.js";
6
+ import { DialogFrame } from "../components/dialog-frame.js";
7
+ import { ModalCloseContext } from "../components/modal.js";
8
+ import { Button, Input } from "../components/ui.js";
9
+ import { personNameOk, PERSON_NAME_MAX_LENGTH } from "./form-rules.js";
10
+ const DEFAULT_COMPLETE_NAME_LABELS = {
11
+ title: "Complete your name",
12
+ description: "First and last name are now asked for separately. Check what is filled in and add what is missing.",
13
+ firstName: "First name",
14
+ lastName: "Last name",
15
+ save: "Save",
16
+ later: "Later",
17
+ failed: "Your name could not be saved. Please try again."
18
+ };
19
+ function CompleteNameDialog({
20
+ firstName: initialFirst = "",
21
+ lastName: initialLast = "",
22
+ onSave,
23
+ onClose,
24
+ error,
25
+ open,
26
+ labels: labelsProp
27
+ }) {
28
+ const labels = useKitLabels("completeName", DEFAULT_COMPLETE_NAME_LABELS, labelsProp);
29
+ const [first, setFirst] = useState(initialFirst);
30
+ const [last, setLast] = useState(initialLast);
31
+ const [failed, setFailed] = useState(false);
32
+ const { pending, run } = usePromisePending();
33
+ const [done, setDone] = useState(false);
34
+ const saved = useRef(false);
35
+ const formId = useId();
36
+ const firstRef = useRef(null);
37
+ const lastRef = useRef(null);
38
+ const isOpen = open ?? true;
39
+ const [wasOpen, setWasOpen] = useState(isOpen);
40
+ if (wasOpen !== isOpen) {
41
+ setWasOpen(isOpen);
42
+ if (isOpen) {
43
+ setFirst(initialFirst);
44
+ setLast(initialLast);
45
+ setFailed(false);
46
+ setDone(false);
47
+ }
48
+ }
49
+ useEffect(() => {
50
+ if (!isOpen) return;
51
+ saved.current = false;
52
+ const target = firstRef.current?.value.trim() ? lastRef.current : firstRef.current;
53
+ target?.focus();
54
+ }, [isOpen]);
55
+ const canSave = personNameOk(first) && personNameOk(last);
56
+ const submit = () => {
57
+ if (pending || !canSave) return;
58
+ setFailed(false);
59
+ const values = { firstName: first.trim(), lastName: last.trim() };
60
+ let result;
61
+ try {
62
+ result = Promise.resolve(onSave(values));
63
+ } catch (err) {
64
+ result = Promise.reject(err);
65
+ }
66
+ result.catch(() => setFailed(true));
67
+ run(result, () => {
68
+ saved.current = true;
69
+ setDone(true);
70
+ });
71
+ };
72
+ const edit = (set) => (value) => {
73
+ set(value);
74
+ setFailed(false);
75
+ };
76
+ const message = failed ? error ?? labels.failed : void 0;
77
+ return /* @__PURE__ */ jsx(
78
+ DialogFrame,
79
+ {
80
+ open,
81
+ title: labels.title,
82
+ description: labels.description,
83
+ onClose: () => onClose(saved.current),
84
+ onKeyDown: (e) => {
85
+ if (pending && e.key === "Escape") e.preventDefault();
86
+ },
87
+ "aria-busy": pending || void 0,
88
+ actions: /* @__PURE__ */ jsx(
89
+ CompleteNameActions,
90
+ {
91
+ formId,
92
+ done,
93
+ busy: pending,
94
+ canSave,
95
+ laterLabel: labels.later,
96
+ saveLabel: labels.save
97
+ }
98
+ ),
99
+ children: /* @__PURE__ */ jsxs(
100
+ "form",
101
+ {
102
+ id: formId,
103
+ noValidate: true,
104
+ className: "grid gap-3 @container",
105
+ onSubmit: (e) => {
106
+ e.preventDefault();
107
+ submit();
108
+ },
109
+ children: [
110
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-3 @xs:grid-cols-2", children: [
111
+ /* @__PURE__ */ jsx(
112
+ Input,
113
+ {
114
+ ref: firstRef,
115
+ name: "given-name",
116
+ autoComplete: "given-name",
117
+ label: labels.firstName,
118
+ value: first,
119
+ onChange: (e) => edit(setFirst)(e.target.value),
120
+ maxLength: PERSON_NAME_MAX_LENGTH,
121
+ readOnly: pending,
122
+ required: true
123
+ }
124
+ ),
125
+ /* @__PURE__ */ jsx(
126
+ Input,
127
+ {
128
+ ref: lastRef,
129
+ name: "family-name",
130
+ autoComplete: "family-name",
131
+ label: labels.lastName,
132
+ value: last,
133
+ onChange: (e) => edit(setLast)(e.target.value),
134
+ maxLength: PERSON_NAME_MAX_LENGTH,
135
+ readOnly: pending,
136
+ required: true
137
+ }
138
+ )
139
+ ] }),
140
+ message !== void 0 && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-[var(--danger)]", children: message })
141
+ ]
142
+ }
143
+ )
144
+ }
145
+ );
146
+ }
147
+ function CompleteNameActions({
148
+ formId,
149
+ done,
150
+ busy,
151
+ canSave,
152
+ laterLabel,
153
+ saveLabel
154
+ }) {
155
+ const close = useContext(ModalCloseContext);
156
+ useEffect(() => {
157
+ if (done) close?.();
158
+ }, [done, close]);
159
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
160
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", disabled: busy, onClick: () => close?.(), children: laterLabel }),
161
+ /* @__PURE__ */ jsx(Button, { type: "submit", form: formId, commit: true, disabled: !busy && !canSave, pending: busy, children: saveLabel })
162
+ ] });
163
+ }
164
+ export {
165
+ CompleteNameDialog,
166
+ DEFAULT_COMPLETE_NAME_LABELS
167
+ };
168
+ //# sourceMappingURL=complete-name-dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/complete-name-dialog.tsx"],"sourcesContent":["import { useContext, useEffect, useId, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\n\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { usePromisePending } from \"../components/danger-confirm\";\nimport { DialogFrame } from \"../components/dialog-frame\";\nimport { ModalCloseContext } from \"../components/modal\";\nimport { Button, Input } from \"../components/ui\";\nimport { personNameOk, PERSON_NAME_MAX_LENGTH } from \"./form-rules\";\n\n/** What `CompleteNameDialog` hands `onSave`: both names, trimmed, 1–120 characters —\n * `PATCH /auth/me {first_name, last_name}` (§6.1). */\nexport interface CompleteNameValues {\n firstName: string;\n lastName: string;\n}\n\n/**\n * Every string the dialog renders — the `completeName` namespace of `<UiKitProvider\n * labels>`, overridable per instance through `labels`.\n */\nexport interface CompleteNameLabels {\n title: string;\n description: string;\n firstName: string;\n lastName: string;\n save: string;\n /** Dismisses the dialog until the next sign-in. */\n later: string;\n /** Under the fields when `onSave` rejected and the app passed no `error`. */\n failed: string;\n}\n\nexport const DEFAULT_COMPLETE_NAME_LABELS: CompleteNameLabels = {\n title: \"Complete your name\",\n description: \"First and last name are now asked for separately. Check what is filled in and add what is missing.\",\n firstName: \"First name\",\n lastName: \"Last name\",\n save: \"Save\",\n later: \"Later\",\n failed: \"Your name could not be saved. Please try again.\",\n};\n\nexport interface CompleteNameDialogProps {\n /** What the account holds now — after the migration, the old display name (§3.3). */\n firstName?: string;\n /** Usually empty: that is why the dialog is up. */\n lastName?: string;\n /**\n * Save the names (`PATCH /auth/me`). Resolve and the dialog closes (`onClose(true)`);\n * reject and it stays open with the names kept and `error` — or \"Your name could not\n * be saved\" — under them.\n */\n onSave: (values: CompleteNameValues) => Promise<unknown>;\n /**\n * The dialog has closed: `true` after a resolved `onSave`, `false` for \"Later\", Escape,\n * the backdrop and Back. `false` only DEFERS it: the app shows it again after the\n * next sign-in while `/auth/me` still answers `name_incomplete: true`.\n */\n onClose: (saved: boolean) => void;\n /** The app's words for the last failed save, instead of `labels.failed`. Hidden again\n * once a name is edited. */\n error?: ReactNode;\n /** Kept-mounted mode, as on `Modal`: left out, the dialog is open while mounted. */\n open?: boolean;\n labels?: Partial<CompleteNameLabels>;\n}\n\n/**\n * \"Complete your name\" — asked once after sign-in of a user whose name was migrated\n * (docs/auth-harmonization.md §3.3). keksdose's and Kurvenschmiede's accounts had one\n * `display_name`; it moved whole into `first_name`, `last_name` stayed empty, and\n * nothing was split by guesswork (§2.4). The app shows this while `/auth/me` answers\n * `name_incomplete: true` — never for a demo user.\n *\n * Both names prefilled with what is there; \"Save\" waits until both have 1–120\n * characters after trimming. **\"Later\" only defers it**: nothing else waits on a\n * complete name, no page is blocked, and the app asks again at the next sign-in.\n *\n * The promise handling is `ReauthDialog`'s: busy while `onSave` runs (the fields\n * read-only, \"Later\" disabled, Escape held — a request that has left cannot be called\n * back by closing the dialog), closed on resolve, kept open on reject. Save is a\n * `commit` control, so a `WriteLockProvider` above it locks it with its reason.\n *\n * Focus starts in the first EMPTY field — the last name, as a rule — because filling it\n * in is the whole of what the dialog is for.\n */\nexport function CompleteNameDialog({\n firstName: initialFirst = \"\",\n lastName: initialLast = \"\",\n onSave,\n onClose,\n error,\n open,\n labels: labelsProp,\n}: CompleteNameDialogProps) {\n const labels = useKitLabels(\"completeName\", DEFAULT_COMPLETE_NAME_LABELS, labelsProp);\n const [first, setFirst] = useState(initialFirst);\n const [last, setLast] = useState(initialLast);\n // A failed save describes the names that were sent; an edit makes it stale.\n const [failed, setFailed] = useState(false);\n const { pending, run } = usePromisePending();\n const [done, setDone] = useState(false);\n const saved = useRef(false);\n const formId = useId();\n const firstRef = useRef<HTMLInputElement>(null);\n const lastRef = useRef<HTMLInputElement>(null);\n const isOpen = open ?? true;\n\n // Reopened (kept-mounted): start again from what the account holds. During render,\n // as ReauthDialog wipes its password, so no frame shows the old draft.\n const [wasOpen, setWasOpen] = useState(isOpen);\n if (wasOpen !== isOpen) {\n setWasOpen(isOpen);\n if (isOpen) {\n setFirst(initialFirst);\n setLast(initialLast);\n setFailed(false);\n setDone(false);\n }\n }\n\n // After Modal's own effect, so its trap has recorded the trigger before focus moves.\n useEffect(() => {\n if (!isOpen) return;\n saved.current = false;\n const target = firstRef.current?.value.trim() ? lastRef.current : firstRef.current;\n target?.focus();\n }, [isOpen]);\n\n const canSave = personNameOk(first) && personNameOk(last);\n\n const submit = () => {\n if (pending || !canSave) return;\n setFailed(false);\n const values = { firstName: first.trim(), lastName: last.trim() };\n let result: Promise<unknown>;\n try {\n result = Promise.resolve(onSave(values));\n } catch (err) {\n result = Promise.reject(err);\n }\n // A rejection must not go unhandled; usePromisePending clears `pending` on it.\n result.catch(() => setFailed(true));\n run(result, () => {\n saved.current = true;\n setDone(true);\n });\n };\n\n const edit = (set: (value: string) => void) => (value: string) => {\n set(value);\n setFailed(false);\n };\n\n const message = failed ? (error ?? labels.failed) : undefined;\n\n return (\n <DialogFrame\n open={open}\n title={labels.title}\n description={labels.description}\n onClose={() => onClose(saved.current)}\n onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {\n if (pending && e.key === \"Escape\") e.preventDefault();\n }}\n aria-busy={pending || undefined}\n actions={\n <CompleteNameActions\n formId={formId}\n done={done}\n busy={pending}\n canSave={canSave}\n laterLabel={labels.later}\n saveLabel={labels.save}\n />\n }\n >\n <form\n id={formId}\n noValidate\n className=\"grid gap-3 @container\"\n onSubmit={(e) => {\n e.preventDefault();\n submit();\n }}\n >\n <div className=\"grid gap-3 @xs:grid-cols-2\">\n <Input\n ref={firstRef}\n name=\"given-name\"\n autoComplete=\"given-name\"\n label={labels.firstName}\n value={first}\n onChange={(e) => edit(setFirst)(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={pending}\n required\n />\n <Input\n ref={lastRef}\n name=\"family-name\"\n autoComplete=\"family-name\"\n label={labels.lastName}\n value={last}\n onChange={(e) => edit(setLast)(e.target.value)}\n maxLength={PERSON_NAME_MAX_LENGTH}\n readOnly={pending}\n required\n />\n </div>\n {message !== undefined && (\n <p role=\"alert\" className=\"text-xs text-[var(--danger)]\">\n {message}\n </p>\n )}\n </form>\n </DialogFrame>\n );\n}\n\n/** The actions row, inside the `Modal`, where its animated close is in context: a\n * resolved save lowers the panel through it, as \"Later\" and Escape do. */\nfunction CompleteNameActions({\n formId,\n done,\n busy,\n canSave,\n laterLabel,\n saveLabel,\n}: {\n formId: string;\n done: boolean;\n busy: boolean;\n canSave: boolean;\n laterLabel: string;\n saveLabel: string;\n}) {\n const close = useContext(ModalCloseContext);\n useEffect(() => {\n if (done) close?.();\n }, [done, close]);\n return (\n <>\n <Button type=\"button\" variant=\"ghost\" disabled={busy} onClick={() => close?.()}>\n {laterLabel}\n </Button>\n <Button type=\"subm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E,qBACH;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The address tag: `you@example.com` → `you+kastlan@example.com`, the app's own name as
3
+ * a sub-address of the address a person types for themselves (docs/auth-harmonization.md
4
+ * §4.5, Marcel 2026-10-05). Lifted from keksdose (`features/auth/email-tag.ts`, feedback
5
+ * dev#481), where the tag was the constant `keksdose`; here it is the app's.
6
+ *
7
+ * **Structurally valid is not the same as deliverable.** `+` is an ordinary character in
8
+ * the local part under RFC 5322, and sub-addressing — `user+tag@host` delivered to
9
+ * `user@host` — is specified (RFC 5233). But it is specified as a convention the
10
+ * RECEIVING server may implement: Gmail, Outlook, iCloud, Fastmail and Proton do; many
11
+ * Exchange installs, small hosters and corporate filters do not, and some web forms
12
+ * refuse the character outright.
13
+ *
14
+ * Which is why every caller OFFERS the result and never applies it. Silently registering
15
+ * somebody as `you+kastlan@example.com` would send the verification mail — the one
16
+ * message the account depends on — down a delivery path nobody checked, and make the
17
+ * address they sign in with one they never typed. The tag is a convenience for the
18
+ * person who wants it: one click, with the exact resulting address on the button
19
+ * (`RegisterForm` does this with its `emailTag`).
20
+ *
21
+ * The tagged address is then the identity. The server trims and lower-cases an address
22
+ * at every entry and never strips a tag, so `you@…` and `you+kastlan@…` are two
23
+ * different accounts; sign-in stays exact (§4.5), which is why `SignInForm`'s hint after
24
+ * a failed sign-in names the tagged address rather than trying it.
25
+ *
26
+ * Offer it only where a person types an address FOR THEMSELVES — sign-up, a later email
27
+ * change in the profile — never in a field for someone else's (an invite dialog, a
28
+ * share), where the tag would be a guess about another person's mail server.
29
+ */
30
+ /**
31
+ * `taggedEmail("you@example.com", "kastlan")` → `"you+kastlan@example.com"`, or `null`
32
+ * when there is nothing to offer:
33
+ *
34
+ * - the address is not complete enough to split — no local part, no domain, or a
35
+ * domain without an inner dot (the shape the field's own `type="email"` accepts), so
36
+ * the offer cannot appear before the address is plausible or linger once it stops
37
+ * being one;
38
+ * - the address already carries a `+` — the person's own scheme wins, and stacking a
39
+ * second tag on it would be wrong;
40
+ * - the tag is empty or not a plain name (see `TAG_SHAPE`).
41
+ *
42
+ * The tag is the app's name in lower case (`keksdose`, `kastlan`, `kurvenschmiede`); it
43
+ * is trimmed and lower-cased here, so `"Kastlan"` gives the same answer. The address is
44
+ * trimmed and otherwise kept as typed — normalising it is the server's job (server-kit's
45
+ * `normalise_email`).
46
+ */
47
+ declare function taggedEmail(email: string, tag: string): string | null;
48
+ /**
49
+ * The trimmed address split at its last `@`, or `null` while it is not complete enough
50
+ * to split: no local part, no domain, or a domain without an inner dot — the shape the
51
+ * field's own `type="email"` accepts.
52
+ *
53
+ * @internal `RegisterForm` gates its submit on it; not part of the barrel.
54
+ */
55
+ declare function emailParts(email: string): {
56
+ local: string;
57
+ domain: string;
58
+ } | null;
59
+
60
+ export { emailParts, taggedEmail };
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ const TAG_SHAPE = /^[a-z0-9][a-z0-9._-]*$/;
3
+ function taggedEmail(email, tag) {
4
+ const name = tag.trim().toLowerCase();
5
+ if (!TAG_SHAPE.test(name)) return null;
6
+ const parts = emailParts(email);
7
+ if (!parts || parts.local.includes("+")) return null;
8
+ return `${parts.local}+${name}@${parts.domain}`;
9
+ }
10
+ function emailParts(email) {
11
+ const trimmed = email.trim();
12
+ const at = trimmed.lastIndexOf("@");
13
+ if (at <= 0 || at === trimmed.length - 1) return null;
14
+ const local = trimmed.slice(0, at);
15
+ const domain = trimmed.slice(at + 1);
16
+ if (!domain.includes(".") || domain.startsWith(".") || domain.endsWith(".")) return null;
17
+ return { local, domain };
18
+ }
19
+ export {
20
+ emailParts,
21
+ taggedEmail
22
+ };
23
+ //# sourceMappingURL=email-tag.js.map