@tinyrack/issuary-server 0.28.0 → 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 (133) hide show
  1. package/dist/entities/oauth-client.entity.d.ts +18 -0
  2. package/dist/entities/oauth-client.entity.d.ts.map +1 -1
  3. package/dist/entities/oauth-client.entity.js +12 -0
  4. package/dist/entities/oauth-client.entity.js.map +1 -1
  5. package/dist/entities/oauth-code.entity.d.ts +18 -0
  6. package/dist/entities/oauth-code.entity.d.ts.map +1 -1
  7. package/dist/entities/oauth-device-code.entity.d.ts +18 -0
  8. package/dist/entities/oauth-device-code.entity.d.ts.map +1 -1
  9. package/dist/entities/revoked-token.entity.d.ts +18 -0
  10. package/dist/entities/revoked-token.entity.d.ts.map +1 -1
  11. package/dist/entities/user-consent.entity.d.ts +18 -0
  12. package/dist/entities/user-consent.entity.d.ts.map +1 -1
  13. package/dist/entrypoints/app.d.ts +124 -30
  14. package/dist/entrypoints/app.d.ts.map +1 -1
  15. package/dist/entrypoints/database/postgres/compiled-functions.d.ts +10 -4
  16. package/dist/entrypoints/database/postgres/compiled-functions.js +111 -24
  17. package/dist/entrypoints/database/postgres/compiled-functions.js.map +1 -1
  18. package/dist/entrypoints/database/sqlite/compiled-functions.d.ts +10 -4
  19. package/dist/entrypoints/database/sqlite/compiled-functions.js +111 -24
  20. package/dist/entrypoints/database/sqlite/compiled-functions.js.map +1 -1
  21. package/dist/lib/config/cleanup.d.ts +8 -0
  22. package/dist/lib/config/cleanup.d.ts.map +1 -1
  23. package/dist/lib/config/cleanup.js +16 -0
  24. package/dist/lib/config/cleanup.js.map +1 -1
  25. package/dist/lib/config/resolved.d.ts +4 -0
  26. package/dist/lib/config/resolved.d.ts.map +1 -1
  27. package/dist/migrations/postgres/Migration20260904090000_add_oauth_client_lifecycle.d.ts +6 -0
  28. package/dist/migrations/postgres/Migration20260904090000_add_oauth_client_lifecycle.d.ts.map +1 -0
  29. package/dist/migrations/postgres/Migration20260904090000_add_oauth_client_lifecycle.js +14 -0
  30. package/dist/migrations/postgres/Migration20260904090000_add_oauth_client_lifecycle.js.map +1 -0
  31. package/dist/migrations/postgres/index.d.ts.map +1 -1
  32. package/dist/migrations/postgres/index.js +2 -0
  33. package/dist/migrations/postgres/index.js.map +1 -1
  34. package/dist/migrations/sqlite/Migration20260904090000_add_oauth_client_lifecycle.d.ts +6 -0
  35. package/dist/migrations/sqlite/Migration20260904090000_add_oauth_client_lifecycle.d.ts.map +1 -0
  36. package/dist/migrations/sqlite/Migration20260904090000_add_oauth_client_lifecycle.js +14 -0
  37. package/dist/migrations/sqlite/Migration20260904090000_add_oauth_client_lifecycle.js.map +1 -0
  38. package/dist/migrations/sqlite/index.d.ts.map +1 -1
  39. package/dist/migrations/sqlite/index.js +2 -0
  40. package/dist/migrations/sqlite/index.js.map +1 -1
  41. package/dist/routes/api/admin/console/index.d.ts +91 -1
  42. package/dist/routes/api/admin/console/index.d.ts.map +1 -1
  43. package/dist/routes/api/admin/console/index.js +10 -2
  44. package/dist/routes/api/admin/console/index.js.map +1 -1
  45. package/dist/routes/api/admin/index.d.ts +91 -1
  46. package/dist/routes/api/admin/index.d.ts.map +1 -1
  47. package/dist/routes/api/auth/accounts/select.post.d.ts +6 -6
  48. package/dist/routes/api/index.d.ts +120 -30
  49. package/dist/routes/api/index.d.ts.map +1 -1
  50. package/dist/routes/api/oauth/_provider/callback/post.d.ts +9 -9
  51. package/dist/routes/index.d.ts +91 -1
  52. package/dist/routes/index.d.ts.map +1 -1
  53. package/dist/schemas/error.d.ts +75 -0
  54. package/dist/schemas/error.d.ts.map +1 -1
  55. package/dist/schemas/error.js +3 -0
  56. package/dist/schemas/error.js.map +1 -1
  57. package/dist/schemas/response.d.ts +1 -0
  58. package/dist/schemas/response.d.ts.map +1 -1
  59. package/dist/schemas/response.js +4 -0
  60. package/dist/schemas/response.js.map +1 -1
  61. package/dist/seeders/config.seeder.js +14 -11
  62. package/dist/seeders/config.seeder.js.map +1 -1
  63. package/dist/services/admin-console.service.d.ts +47 -0
  64. package/dist/services/admin-console.service.d.ts.map +1 -1
  65. package/dist/services/admin-console.service.js +75 -6
  66. package/dist/services/admin-console.service.js.map +1 -1
  67. package/dist/services/cleanup.service.d.ts +2 -0
  68. package/dist/services/cleanup.service.d.ts.map +1 -1
  69. package/dist/services/cleanup.service.js +61 -0
  70. package/dist/services/cleanup.service.js.map +1 -1
  71. package/dist/services/container.d.ts +4 -0
  72. package/dist/services/container.d.ts.map +1 -1
  73. package/dist/services/jwt.service.d.ts +2 -0
  74. package/dist/services/jwt.service.d.ts.map +1 -1
  75. package/dist/services/jwt.service.js +6 -0
  76. package/dist/services/jwt.service.js.map +1 -1
  77. package/dist/services/oauth-client.service.d.ts.map +1 -1
  78. package/dist/services/oauth-client.service.js +9 -5
  79. package/dist/services/oauth-client.service.js.map +1 -1
  80. package/dist/services/oauth-token.service.d.ts.map +1 -1
  81. package/dist/services/oauth-token.service.js +8 -1
  82. package/dist/services/oauth-token.service.js.map +1 -1
  83. package/frontend/client/assets/admin-console-BVGtfvzy.js +1 -0
  84. package/frontend/client/assets/admin-users-notice-DcKE5B43.js +1 -0
  85. package/frontend/client/assets/{auth-layout-BFD6Jwkd.js → auth-layout-CFKu8bHI.js} +1 -1
  86. package/frontend/client/assets/{auth-page-header-DWIuRJtG.js → auth-page-header-D5Z-EA6V.js} +1 -1
  87. package/frontend/client/assets/{authorization-context-banner-WE0b3j97.js → authorization-context-banner-Cqtzj9A1.js} +1 -1
  88. package/frontend/client/assets/i18n-BY3irWek.js +1 -0
  89. package/frontend/client/assets/{language-selector-BZipfWXO.js → language-selector-CGXk9vW_.js} +1 -1
  90. package/frontend/client/assets/{manifest-6d4cda98.js → manifest-4ae87899.js} +1 -1
  91. package/frontend/client/assets/{passkey-DoR9gw8n.js → passkey-C9bzur2Z.js} +1 -1
  92. package/frontend/client/assets/{promise-C4eJsjRN.js → promise-CFWkfv2A.js} +1 -1
  93. package/frontend/client/assets/{root-sdYEeZVs.js → root-DDLeooq1.js} +1 -1
  94. package/frontend/client/assets/{route-BPss6aNC.js → route-48mZ_bkD.js} +1 -1
  95. package/frontend/client/assets/route-9i9rqQdx.js +4 -0
  96. package/frontend/client/assets/{route-CgqKzu4o.js → route-BIhwXFuk.js} +1 -1
  97. package/frontend/client/assets/{route-BA8SLA-y.js → route-Bx9hz_OF.js} +1 -1
  98. package/frontend/client/assets/{route-B4n6iLak.js → route-C5Pe2AZT.js} +1 -1
  99. package/frontend/client/assets/{route-DHyl9fg6.js → route-C9TWgUZf.js} +1 -1
  100. package/frontend/client/assets/{route-DCxEMgcG.js → route-CBjporWj.js} +1 -1
  101. package/frontend/client/assets/{route-BbumhNTg.js → route-CLo3eo-R.js} +1 -1
  102. package/frontend/client/assets/route-CPIXY7eE.js +1 -0
  103. package/frontend/client/assets/{route--ygtU3xf.js → route-Caw4ohFV.js} +1 -1
  104. package/frontend/client/assets/{route-O04gqlmz.js → route-Ceht21dJ.js} +1 -1
  105. package/frontend/client/assets/route-CkS9fAlL.js +1 -0
  106. package/frontend/client/assets/{route-CCs0-fO0.js → route-CsT5EJEh.js} +1 -1
  107. package/frontend/client/assets/{route-DQlEYlRT.js → route-Cvob9_0Q.js} +1 -1
  108. package/frontend/client/assets/{route-OeZDuFSb.js → route-DCfkikii.js} +1 -1
  109. package/frontend/client/assets/{route-B1MD0P12.js → route-DHEnEwHa.js} +1 -1
  110. package/frontend/client/assets/{route-WG7qPhB_.js → route-DHQ_td-S.js} +1 -1
  111. package/frontend/client/assets/{route-BLq7NTd1.js → route-DLNoCW7x.js} +1 -1
  112. package/frontend/client/assets/{route-BUTlt8Ui.js → route-DlKXugZV.js} +1 -1
  113. package/frontend/client/assets/{route-D9cK2_2t.js → route-DokK6Iod.js} +1 -1
  114. package/frontend/client/assets/{route-D98zlsIA.js → route-ID67gqvy.js} +1 -1
  115. package/frontend/client/assets/{route-Cmo_MXuL.js → route-OWWRYmAT.js} +1 -1
  116. package/frontend/client/assets/{route-DitctEyz.js → route-R-BJj3-W.js} +1 -1
  117. package/frontend/client/assets/{route-BukKUAfo.js → route-goGP2kXu.js} +1 -1
  118. package/frontend/client/assets/{route-BI7lRSrf.js → route-uV_qilhG.js} +1 -1
  119. package/frontend/client/assets/{route-DtL-KJ0k.js → route-xuoylbDO.js} +1 -1
  120. package/frontend/client/assets/{shell-header-bar-CtUdWFmD.js → shell-header-bar-C3KYib1D.js} +1 -1
  121. package/frontend/client/assets/{terms-BEja7rHN.js → terms-BReb6uEz.js} +1 -1
  122. package/frontend/client/assets/{use-totp-setup-BwOsP75D.js → use-totp-setup-BOSkSnYG.js} +1 -1
  123. package/frontend/server/assets/{hydration-CzMpuxhN.js → hydration-yaDCGSA8.js} +1 -1
  124. package/frontend/server/assets/{root-loader.server-BjcO3GtR.js → root-loader.server-Cwm-l9OS.js} +3 -3
  125. package/frontend/server/assets/{route-runtime.server-DnkciJ0v.js → route-runtime.server-CjDbp5w6.js} +1 -1
  126. package/frontend/server/assets/{session-CEJThdQg.js → session-CSnQWUgx.js} +30 -0
  127. package/frontend/server/index.js +320 -216
  128. package/package.json +1 -1
  129. package/frontend/client/assets/admin-console-DL8Kf5fu.js +0 -1
  130. package/frontend/client/assets/i18n-wAvPXBC2.js +0 -1
  131. package/frontend/client/assets/route-CEunl4H1.js +0 -1
  132. package/frontend/client/assets/route-CZFY6zgn.js +0 -4
  133. package/frontend/client/assets/route-DUp2lTDn.js +0 -1
@@ -1 +1 @@
1
- import{$ as e,J as t,a as n,f as r,o as i}from"./components-C1SipCbb.js";import{t as a}from"./jsx-runtime-BFZ_fnNJ.js";import{L as o,a as s,i as c,n as l,t as u}from"./api-0SzZx6X7.js";import{n as d,r as f,t as p}from"./text-CGN4ZtUZ.js";import{t as m}from"./useMutation-C4CmK9Sb.js";import{t as h}from"./useQuery-BtUeFnRt.js";import{t as g}from"./mutationOptions-Dfvzj6n2.js";import{V as _}from"./select--ltVnlVl.js";import{a as v,i as y,r as b,t as x}from"./shell-header-bar-CtUdWFmD.js";import{i as S,r as C}from"./NullStore-BxU9yW8l.js";import{t as w}from"./card-CTv8DubK.js";import{t as T}from"./circle-alert-DGTJ9B9k.js";import{a as E,i as D,n as ee,r as O,t as k}from"./use-totp-setup-BwOsP75D.js";import{t as A}from"./auth-field-1EM9pnWe.js";import{t as j}from"./fingerprint-pattern-V_eTEvnZ.js";import{t as M}from"./key-round-DgCbGqQL.js";import{n as N,r as P}from"./language-selector-BZipfWXO.js";import{n as F,t as I}from"./provider-mark-B05f08GZ.js";import{n as te,r as ne,t as re}from"./logout-CBTnIosZ.js";import{t as L}from"./shield-check-93-WFkyJ.js";import{t as R}from"./trash-2-BOsxjkzU.js";import{t as z}from"./triangle-alert-DSSurAZ_.js";import{t as ie}from"./auth-page-header-DWIuRJtG.js";import{t as ae}from"./link-button-qvSTUE1n.js";import{t as B}from"./alert-CFUBsmUN.js";import{n as V,t as H}from"./modal-LoTH9Ttl.js";import{t as oe}from"./initial-avatar-D4aPMV9z.js";import{t as U}from"./route-error-fallback-C2OHu3JW.js";import{r as W,t as G}from"./standard-schema-C8Td_miB.js";import{r as K}from"./FieldItemContext-CPjig163.js";import{a as q,s as J}from"./schemas-Dxi9xZo6.js";import{n as Y,t as se}from"./promise-C4eJsjRN.js";import{n as ce,r as le}from"./totp-BW4BoCpi.js";import{t as ue}from"./badge-BCQspax5.js";import{a as de,i as fe,n as pe,r as me}from"./passkey-DoR9gw8n.js";import{t as he}from"./document-navigation-Cnp3Alf0.js";import{n as ge,t as _e}from"./route-module-Bm4sHkx9.js";var ve=_(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),ye=_(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),be=_(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),xe=_(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),X=e(t(),1),Z=a();function Se({isConfigManaged:e,isDeletionEnabled:t,onDeleteClick:n}){let{t:r}=s();return t?(0,Z.jsxs)(w.Root,{className:`border-tinyrack-danger-border bg-tinyrack-danger-surface`,variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-danger-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[(0,Z.jsx)(z,{"aria-hidden":!0,className:`size-tinyrack-lg text-tinyrack-danger-foreground`}),(0,Z.jsx)(w.Title,{className:`text-tinyrack-danger-foreground`,children:r(`profile.dangerZone.title`)})]}),(0,Z.jsx)(w.Description,{children:r(`profile.dangerZone.description`)})]}),(0,Z.jsx)(w.Content,{className:`px-tinyrack-lg py-tinyrack-md`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(p,{as:`p`,variant:`bodySm`,weight:`medium`,children:r(`profile.deleteAccount.title`)}),(0,Z.jsx)(p,{as:`p`,color:`muted`,variant:`caption`,children:r(e?`profile.deleteAccount.configManaged`:`profile.deleteAccount.description`)})]}),(0,Z.jsxs)(C,{appearance:`outline`,"data-testid":`profile-delete-account`,disabled:e,intent:`danger`,onClick:n,type:`button`,uiSize:`sm`,children:[(0,Z.jsx)(R,{"aria-hidden":!0,className:`size-tinyrack-lg`}),r(`profile.deleteAccount.button`)]})]})})]}):null}function Ce({providerId:e,iconUrl:t,className:n=`size-tinyrack-xl`}){return e===`google`||e===`github`||e===`apple`?(0,Z.jsx)(I,{"aria-hidden":!0,className:n,provider:e}):t?(0,Z.jsx)(`img`,{alt:``,className:n,src:t}):(0,Z.jsx)(F,{"aria-hidden":!0,className:n})}function Q({icon:e,active:t,title:n,status:r,note:i,actions:a}){let o;return o=(0,X.isValidElement)(e)?e:(0,Z.jsx)(e,{"aria-hidden":!0,className:`size-tinyrack-lg ${t?`text-tinyrack-success-foreground`:`text-tinyrack-text-muted`}`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg p-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-tinyrack-md`,children:[(0,Z.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-tinyrack-md ${t?`bg-tinyrack-success-surface`:`bg-tinyrack-surface-muted`}`,children:o}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(p,{variant:`bodySm`,weight:`medium`,children:n}),(0,Z.jsx)(p,{color:`muted`,variant:`caption`,children:r}),i]})]}),a&&(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-tinyrack-xs`,children:a})]})}function we({providers:e,unlinkingProvider:t,getAuthorizeUrl:n,onUnlinkRequest:r}){let{t:i}=s();return e.length===0?null:(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:i(`profile.linkedAccounts.title`)}),(0,Z.jsx)(w.Description,{children:i(`profile.linkedAccounts.description`)})]}),(0,Z.jsx)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:e.map(e=>(0,Z.jsx)(Q,{actions:e.linked?(0,Z.jsx)(C,{appearance:`ghost`,intent:`danger`,loading:t===e.id,loadingLabel:i(`profile.linkedAccounts.unlinking`),onClick:()=>r(e),type:`button`,uiSize:`sm`,children:t===e.id?void 0:i(`profile.linkedAccounts.unlink`)}):(0,Z.jsx)(ae,{appearance:`outline`,intent:`neutral`,render:(0,Z.jsx)(`a`,{href:n(e.id,`link`,`/profile`)}),uiSize:`sm`,children:i(`profile.linkedAccounts.link`)}),active:e.linked,icon:(0,Z.jsx)(Ce,{className:`size-tinyrack-lg`,iconUrl:e.icon_url,providerId:e.id}),status:e.linked?i(`profile.linkedAccounts.connected`):i(`profile.linkedAccounts.notConnected`),title:e.display_name},e.id))})]})}function Te({passkeyCount:e,onOpenModal:t}){let{t:n}=s(),r=e>0;return(0,Z.jsx)(Q,{actions:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:()=>t(r?`manage`:`setup`),type:`button`,uiSize:`sm`,children:n(r?`profile.passkey.manage`:`profile.passkey.add`)}),active:r,icon:j,status:r?n(`profile.passkey.status.enabled`,{count:e}):n(`profile.passkey.status.disabled`),title:n(`profile.passkey.title`)})}function Ee({hasPassword:e,hasLinkedOAuth:t,isConfigManaged:n,hasSecondFactorOnly:r,onOpenModal:i}){let{t:a}=s();return(0,Z.jsx)(Q,{actions:n?void 0:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-change`,intent:`primary`,onClick:()=>i(`change`),type:`button`,uiSize:`sm`,children:a(`profile.password.change`)}),t?(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-remove`,intent:`danger`,onClick:()=>i(`remove`),type:`button`,uiSize:`sm`,children:a(`profile.password.remove`)}):null,!t&&r&&(0,Z.jsxs)(v.Root,{children:[(0,Z.jsx)(v.Trigger,{render:(0,Z.jsx)(C,{appearance:`ghost`,disabled:!0,type:`button`,uiSize:`sm`,children:a(`profile.password.remove`)})}),(0,Z.jsx)(v.Portal,{children:(0,Z.jsx)(v.Positioner,{children:(0,Z.jsx)(v.Popup,{className:`max-w-tinyrack-measure-lg rounded-tinyrack-md border border-tinyrack-border bg-tinyrack-surface p-tinyrack-md text-tinyrack-text text-tinyrack-xs shadow-tinyrack-overlay`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-tinyrack-sm`,children:[(0,Z.jsx)(E,{"aria-hidden":!0,className:`size-tinyrack-lg shrink-0 text-tinyrack-warning-foreground`}),(0,Z.jsx)(p,{variant:`caption`,children:a(`profile.password.removeDisabledReason`)})]})})})})]})]}):(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-set`,intent:`primary`,onClick:()=>i(`set`),type:`button`,uiSize:`sm`,children:a(`profile.password.set`)}),active:e,icon:M,note:n?(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-xs`,children:[(0,Z.jsx)(te,{"aria-hidden":!0,className:`size-tinyrack-md shrink-0`}),(0,Z.jsx)(p,{as:`span`,color:`muted`,variant:`caption`,children:a(`profile.password.configManaged`)})]}):void 0,status:a(e?`profile.password.status.set`:`profile.password.status.notSet`),title:a(`profile.password.title`)})}function De({totpEnabled:e,recoveryCodesMissing:t,onOpenModal:n}){let{t:r}=s();return(0,Z.jsx)(Q,{actions:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-regenerate`,intent:`primary`,onClick:()=>n(`regenerate`),type:`button`,uiSize:`sm`,children:r(`profile.totp.regenerate`)}),(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-disable`,intent:`danger`,onClick:()=>n(`disable`),type:`button`,uiSize:`sm`,children:r(`profile.totp.disable`)})]}):(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-enable`,intent:`primary`,onClick:()=>n(`setup`),type:`button`,uiSize:`sm`,children:r(`profile.totp.enable`)}),active:e,icon:L,status:r(e?t?`profile.totp.status.recoveryCodesMissing`:`profile.totp.status.enabled`:`profile.totp.status.disabled`),title:r(`profile.totp.title`)})}var Oe={error:T,warning:z,info:E};function $({variant:e,children:t}){return(0,Z.jsx)(B,{"data-testid":`alert-banner-${e}`,icon:Oe[e],type:e,children:t})}function ke({isOpen:e,onClose:t,providerName:n,isPending:r,onConfirm:i}){let{t:a}=s(),[o,c]=(0,X.useState)(null),l=()=>{r||(c(null),t())};return(0,Z.jsx)(H,{description:a(`profile.linkedAccounts.unlinkModal.description`,{provider:n}),icon:ye,isOpen:e,onClose:l,preventClose:r,title:a(`profile.linkedAccounts.unlinkModal.title`),variant:`destructive`,children:(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,children:[(0,Z.jsx)($,{variant:`warning`,children:a(`profile.linkedAccounts.unlinkModal.warning`,{provider:n})}),o&&(0,Z.jsx)($,{variant:`error`,children:o}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`unlink-oauth-cancel`,disabled:r,intent:`neutral`,onClick:l,type:`button`,uiSize:`sm`,children:a(`profile.linkedAccounts.unlinkModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`unlink-oauth-unlink`,disabled:r,intent:`danger`,loading:r,loadingLabel:a(`profile.linkedAccounts.unlinking`),onClick:async()=>{c(null);try{await i(),l()}catch{c(a(`profile.linkedAccounts.unlinkError`))}},type:`button`,uiSize:`sm`,children:a(`profile.linkedAccounts.unlink`)})]})]})})}function Ae({label:e,value:t}){return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(p,{className:`shrink-0`,color:`muted`,variant:`caption`,children:e}),(0,Z.jsx)(p,{truncate:!0,variant:`bodySm`,weight:`medium`,children:t})]})}function je({user:e}){let{t}=s();return(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:t(`profile.account.title`)}),(0,Z.jsx)(w.Description,{children:t(`profile.account.description`)})]}),(0,Z.jsxs)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:[(0,Z.jsx)(Ae,{label:t(`profile.id.label`),value:e.sub}),(0,Z.jsx)(Ae,{label:t(`profile.email.label`),value:e.email})]})]})}function Me({children:e,headerActions:t}){return(0,Z.jsxs)(`div`,{className:`flex min-h-dvh flex-col bg-tinyrack-surface`,children:[(0,Z.jsx)(y,{}),(0,Z.jsx)(x,{actions:t,brand:!0}),(0,Z.jsx)(`main`,{className:`flex flex-1 justify-center px-tinyrack-lg py-tinyrack-xl`,children:(0,Z.jsx)(`div`,{className:`auth-enter flex w-full max-w-tinyrack-overlay-width-md flex-col gap-tinyrack-xl`,children:e})}),(0,Z.jsx)(b,{})]})}var Ne=g({mutationFn:async e=>{let t=await u.api.user.password.$post({json:e});return l(t)}}),Pe=g({mutationFn:async e=>{let t=await u.api.user.password.$put({json:e});return l(t)}}),Fe=g({mutationFn:async e=>{let t=await u.api.user.password.$delete({json:e});return l(t)}});function Ie({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),{data:i}=f(N),a=i.auth.password.policy,l=(0,X.useMemo)(()=>q({currentPassword:J().min(1,n(`validation.password.required`)),newPassword:J().min(a.min_length,n(`validation.password.min`,{count:a.min_length})).max(a.max_length,n(`validation.password.max`,{count:a.max_length})),confirmPassword:J()}).refine(e=>e.newPassword===e.confirmPassword,{message:n(`validation.confirmPassword.mismatch`),path:[`confirmPassword`]}),[a.max_length,a.min_length,n]),u=W({resolver:G(l),defaultValues:{currentPassword:``,newPassword:``,confirmPassword:``}}),d=m({...Pe,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),p()}}),p=()=>{u.reset(),t()},h=u.handleSubmit(async e=>{try{await d.mutateAsync({current_password:e.currentPassword,new_password:e.newPassword})}catch(e){e instanceof c&&e.code===`INVALID_CURRENT_PASSWORD`?u.setError(`currentPassword`,{message:n(`profile.password.changeModal.invalidCurrent`)}):u.setError(`root`,{message:n(`profile.password.changeModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.changeModal.description`),icon:M,isOpen:e,onClose:p,title:n(`profile.password.changeModal.title`),children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:h,children:[(0,Z.jsx)(A,{error:u.formState.errors.currentPassword,errorTestId:`change-password-error-currentPassword`,id:`current-password`,label:n(`profile.password.changeModal.currentPassword`),placeholder:n(`profile.password.changeModal.currentPasswordPlaceholder`),...u.register(`currentPassword`),type:`password`}),(0,Z.jsx)(A,{error:u.formState.errors.newPassword,errorTestId:`change-password-error-newPassword`,id:`new-password-change`,label:n(`profile.password.changeModal.newPassword`),placeholder:n(`profile.password.changeModal.newPasswordPlaceholder`),...u.register(`newPassword`),type:`password`}),(0,Z.jsx)(A,{error:u.formState.errors.confirmPassword,errorTestId:`change-password-error-confirmPassword`,id:`confirm-password-change`,label:n(`profile.password.changeModal.confirmPassword`),placeholder:n(`profile.password.changeModal.confirmPasswordPlaceholder`),...u.register(`confirmPassword`),type:`password`}),u.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:u.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`change-password-cancel`,disabled:d.isPending,intent:`neutral`,onClick:p,type:`button`,uiSize:`sm`,children:n(`profile.password.changeModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`change-password-submit`,disabled:d.isPending,intent:`primary`,loading:d.isPending,loadingLabel:n(`profile.password.changeModal.submitting`),type:`submit`,uiSize:`sm`,children:d.isPending?void 0:n(`profile.password.changeModal.submit`)})]})]})})}var Le=g({mutationFn:async()=>{let e=await u.api.user.$delete();return l(e)}});function Re({isOpen:e,onClose:t,retentionDays:n}){let{t:i}=s(),a=r(),c=o(),l=(0,X.useMemo)(()=>q({confirmation:J().refine(e=>e.toLowerCase()===i(`profile.deleteAccount.modal.confirmPlaceholder`).toLowerCase(),{message:i(`validation.confirmText.mismatch`)})}),[i]),u=W({resolver:G(l),defaultValues:{confirmation:``}}),d=m({...Le,onSuccess:async()=>{c.setQueryData(Y.queryKey,{user:null}),await se(),a(`/login`)}}),f=()=>{d.isPending||(u.reset(),t())},h=u.handleSubmit(async()=>{try{await d.mutateAsync()}catch{u.setError(`root`,{message:i(`profile.deleteAccount.error`)})}});return(0,Z.jsx)(H,{icon:R,isOpen:e,onClose:f,preventClose:d.isPending,title:i(`profile.deleteAccount.modal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:h,children:[(0,Z.jsxs)($,{variant:`error`,children:[(0,Z.jsx)(p,{as:`span`,variant:`bodySm`,children:i(`profile.deleteAccount.modal.description`,{days:n})}),(0,Z.jsx)(`br`,{}),(0,Z.jsx)(p,{as:`span`,className:`opacity-tinyrack-hover`,variant:`caption`,children:i(`profile.deleteAccount.modal.warning`)})]}),(0,Z.jsx)(A,{autoComplete:`off`,error:u.formState.errors.confirmation,errorTestId:`delete-account-error`,id:`delete-confirmation`,label:i(`profile.deleteAccount.modal.confirmLabel`),placeholder:i(`profile.deleteAccount.modal.confirmPlaceholder`),...u.register(`confirmation`),type:`text`}),u.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:u.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`delete-account-cancel`,disabled:d.isPending,intent:`neutral`,onClick:f,type:`button`,uiSize:`sm`,children:i(`profile.deleteAccount.modal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`delete-account-submit`,disabled:d.isPending,intent:`danger`,loading:d.isPending,loadingLabel:i(`profile.deleteAccount.modal.confirming`),type:`submit`,uiSize:`sm`,children:d.isPending?void 0:i(`profile.deleteAccount.modal.confirm`)})]})]})})}function ze({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),i=(0,X.useMemo)(()=>q({code:J().length(6,n(`validation.totp.length`)).regex(/^\d{6}$/,n(`validation.totp.digits`))}),[n]),a=W({resolver:G(i),defaultValues:{code:``}}),l=m({...ce,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),u()}}),u=()=>{a.reset(),t()},d=a.handleSubmit(async e=>{try{await l.mutateAsync({code:e.code})}catch(e){if(e instanceof c&&e.code===`CANNOT_REMOVE_LAST_SECOND_FACTOR`){a.setError(`code`,{message:n(`profile.totp.disableModal.cannotRemoveLastSecondFactor`)});return}a.setError(`code`,{message:n(`profile.totp.disableModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.totp.disableModal.description`),icon:L,isOpen:e,onClose:u,title:n(`profile.totp.disableModal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:d,children:[(0,Z.jsx)($,{variant:`warning`,children:n(`profile.totp.disableModal.warning`)}),(0,Z.jsx)(A,{autoComplete:`one-time-code`,error:a.formState.errors.code,errorTestId:`disable-totp-error`,id:`disable-totp-code`,inputMode:`numeric`,label:n(`profile.totp.disableModal.codeLabel`),maxLength:6,pattern:`[0-9]*`,placeholder:`000000`,...a.register(`code`),type:`text`}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`disable-totp-cancel`,disabled:l.isPending,intent:`neutral`,onClick:u,type:`button`,uiSize:`sm`,children:n(`profile.totp.disableModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`disable-totp-submit`,disabled:l.isPending,intent:`danger`,loading:l.isPending,loadingLabel:n(`profile.totp.disableModal.disabling`),type:`submit`,uiSize:`sm`,children:l.isPending?void 0:n(`profile.totp.disableModal.disable`)})]})]})})}function Be({isOpen:e,onClose:t,onAddNew:n}){let{t:r}=s(),i=o(),[a,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),{data:y,isLoading:b}=h({...me,enabled:e}),x=m({...pe,onSuccess:()=>{i.invalidateQueries({queryKey:P.passkeys()}),i.invalidateQueries({queryKey:Y.queryKey})},onSettled:()=>{d(null)}}),w=(0,X.useCallback)(()=>{l(null),d(null),g(null),v(null),t()},[t]),T=e=>{g(e.id),v(null)},E=()=>{g(null),v(null)},D=async e=>{d(e.id),g(null);try{await x.mutateAsync({id:e.id})}catch(e){if(e instanceof c&&e.code===`CANNOT_REMOVE_LAST_SECOND_FACTOR`){v(r(`profile.passkey.manageModal.cannotRemoveLastSecondFactor`));return}v(r(`profile.passkey.manageModal.deleteError`))}},ee=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`}),O=y?.passkeys||[];return(0,Z.jsxs)(H,{icon:j,isOpen:e,onClose:w,size:`lg`,title:r(`profile.passkey.manageModal.title`),children:[(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-sm`,children:[_&&(0,Z.jsx)($,{variant:`error`,children:_}),b&&(0,Z.jsx)(`div`,{className:`flex justify-center py-tinyrack-xl`,children:(0,Z.jsx)(S,{uiSize:`md`})}),!b&&O.length===0&&(0,Z.jsx)(p,{align:`center`,className:`py-tinyrack-xl`,color:`muted`,"data-testid":`passkeys-empty`,variant:`bodySm`,children:r(`profile.passkey.manageModal.noPasskeys`)}),!b&&O.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-col gap-tinyrack-sm`,children:O.map(e=>(0,Z.jsx)(Ve,{formatDate:ee,isConfirmingDelete:f===e.id,isDeleting:u===e.id,isEditing:a?.id===e.id,onCancelDelete:E,onCancelEdit:()=>l(null),onConfirmDelete:()=>D(e),onEdit:()=>l(e),onRequestDelete:()=>T(e),passkey:e},e.id))})]}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`manage-passkeys-close`,intent:`neutral`,onClick:w,type:`button`,uiSize:`sm`,children:r(`profile.passkey.manageModal.close`)}),(0,Z.jsx)(C,{"data-testid":`manage-passkeys-add-new`,intent:`primary`,onClick:()=>{w(),n()},type:`button`,uiSize:`sm`,children:r(`profile.passkey.manageModal.addNew`)})]})]})}function Ve({passkey:e,isDeleting:t,isEditing:n,isConfirmingDelete:r,onEdit:i,onCancelEdit:a,onRequestDelete:c,onConfirmDelete:l,onCancelDelete:u,formatDate:d}){let{t:f}=s(),h=o(),g=(0,X.useMemo)(()=>q({name:J().min(1,f(`validation.passkey.name.required`)).max(100,f(`validation.passkey.name.max`))}),[f]),_=W({resolver:G(g),defaultValues:{name:e.name||``}}),v=m({...de,onSuccess:()=>{h.invalidateQueries({queryKey:P.passkeys()}),a()}}),y=_.handleSubmit(async t=>{try{await v.mutateAsync({id:e.id,name:t.name})}catch{_.setError(`name`,{message:f(`profile.passkey.manageModal.renameError`)})}});return n?(0,Z.jsxs)(K,{className:`flex flex-col gap-tinyrack-xs rounded-tinyrack-md bg-tinyrack-surface-muted p-tinyrack-sm`,onSubmit:y,children:[(0,Z.jsx)(A,{"data-testid":`passkey-rename-input`,error:_.formState.errors.name,errorTestId:`passkey-rename-error`,hideLabel:!0,label:f(`profile.passkey.manageModal.nameLabel`),placeholder:f(`profile.passkey.manageModal.namePlaceholder`),..._.register(`name`),type:`text`}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,disabled:v.isPending,onClick:()=>{_.reset(),a()},type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.cancelEdit`)}),(0,Z.jsx)(C,{disabled:v.isPending,intent:`primary`,type:`submit`,uiSize:`sm`,children:v.isPending?f(`profile.passkey.manageModal.saving`):f(`profile.passkey.manageModal.save`)})]})]}):r?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-tinyrack-md border border-tinyrack-danger-border bg-tinyrack-danger-surface p-tinyrack-sm text-tinyrack-danger-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[(0,Z.jsx)(R,{className:`size-tinyrack-lg`}),(0,Z.jsx)(p,{color:`danger`,variant:`caption`,children:f(`profile.passkey.manageModal.deleteConfirmInline`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,onClick:u,type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.cancelEdit`)}),(0,Z.jsx)(C,{intent:`danger`,onClick:l,type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.delete`)})]})]}):(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-tinyrack-md bg-tinyrack-surface-muted p-tinyrack-sm`,"data-testid":`passkey-item`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[e.device_type===`multiDevice`?(0,Z.jsx)(ve,{className:`size-tinyrack-lg text-tinyrack-primary-foreground`}):(0,Z.jsx)(xe,{className:`size-tinyrack-lg text-tinyrack-primary-foreground`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(p,{variant:`caption`,weight:`medium`,children:e.name||f(`profile.passkey.manageModal.unnamedPasskey`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-xs`,children:[(0,Z.jsx)(p,{color:`muted`,variant:`caption`,children:f(`profile.passkey.manageModal.createdAt`,{date:d(e.created_at)})}),e.backed_up&&(0,Z.jsx)(ue,{uiSize:`md`,variant:`success`,children:f(`profile.passkey.manageModal.backedUp`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":f(`profile.passkey.manageModal.rename`),onClick:i,type:`button`,uiSize:`sm`,children:(0,Z.jsx)(be,{className:`size-tinyrack-lg`})}),(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":f(`profile.passkey.manageModal.delete`),disabled:t,intent:`danger`,loading:t,onClick:c,type:`button`,uiSize:`sm`,children:t?void 0:(0,Z.jsx)(R,{className:`size-tinyrack-lg`})})]})]})}function He({isOpen:e,onClose:t}){let{t:n}=s(),i=r(),a=o(),{data:l}=f(N),[u,d]=(0,X.useState)(`verify`),[p,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),v=m({...le,onSuccess:async e=>{h(e),d(`recovery`),await a.invalidateQueries({queryKey:Y.queryKey})}}),y=(0,X.useCallback)(()=>{d(`verify`),h(null),_(null),v.reset()},[v]),b=(0,X.useCallback)(()=>{y(),t()},[t,y]),x=(0,X.useCallback)(async e=>{_(null);try{await v.mutateAsync({code:e})}catch(e){if(e instanceof c){if(e.code===`INVALID_TOTP_CODE`)throw e;if(e.code===`UNAUTHORIZED`){a.setQueryData(Y.queryKey,{user:null}),await se(),i(`/login`);return}if(e.code===`TOTP_NOT_ENABLED`||e.code===`VALIDATION_ERROR`){await a.invalidateQueries({queryKey:Y.queryKey}),b();return}}_(n(`profile.totp.regenerateModal.unexpectedError`))}},[b,v,i,a,n]);return l.auth.password.totp.enabled?(0,Z.jsx)(H,{description:n(u===`verify`?`profile.totp.regenerateModal.description`:`profile.totp.regenerateModal.recoveryDescription`),icon:L,isOpen:e,onClose:b,preventClose:u===`recovery`,size:`sm`,title:n(u===`verify`?`profile.totp.regenerateModal.title`:`profile.totp.regenerateModal.recoveryTitle`),children:u===`verify`?(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg`,children:[g&&(0,Z.jsx)(`div`,{className:`mb-tinyrack-md`,children:(0,Z.jsx)($,{variant:`error`,children:g})}),(0,Z.jsx)(O,{invalidMessage:n(`profile.totp.regenerateModal.error`),isPending:v.isPending,onSubmit:x,pendingText:n(`profile.totp.regenerateModal.submitting`),submitLabel:n(`profile.totp.regenerateModal.submit`)})]}):(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(D,{onConfirm:b,recoveryCodes:p?.recovery_codes??[]})})}):null}function Ue({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),i=(0,X.useMemo)(()=>q({currentPassword:J().min(1,n(`validation.password.required`))}),[n]),a=W({resolver:G(i),defaultValues:{currentPassword:``}}),l=m({...Fe,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),u()}}),u=()=>{a.reset(),t()},d=a.handleSubmit(async e=>{try{await l.mutateAsync({current_password:e.currentPassword})}catch(e){if(e instanceof c){if(e.code===`INVALID_CURRENT_PASSWORD`){a.setError(`currentPassword`,{message:n(`profile.password.removeModal.invalidCurrent`)});return}if(e.code===`CANNOT_REMOVE_LAST_AUTH_METHOD`){a.setError(`root`,{message:n(`profile.password.removeModal.noOAuth`)});return}if(e.code===`CANNOT_REMOVE_PASSWORD_WITH_SECOND_FACTOR_ONLY`){a.setError(`root`,{message:n(`profile.password.removeModal.noOAuthWith2FA`)});return}}a.setError(`root`,{message:n(`profile.password.removeModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.removeModal.description`),icon:M,isOpen:e,onClose:u,title:n(`profile.password.removeModal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:d,children:[(0,Z.jsx)(A,{error:a.formState.errors.currentPassword,errorTestId:`remove-password-error`,id:`current-password-remove`,label:n(`profile.password.removeModal.currentPassword`),placeholder:n(`profile.password.removeModal.currentPasswordPlaceholder`),...a.register(`currentPassword`),type:`password`}),a.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:a.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`remove-password-cancel`,disabled:l.isPending,intent:`neutral`,onClick:u,type:`button`,uiSize:`sm`,children:n(`profile.password.removeModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`remove-password-submit`,disabled:l.isPending,intent:`danger`,loading:l.isPending,loadingLabel:n(`profile.password.removeModal.submitting`),type:`submit`,uiSize:`sm`,children:l.isPending?void 0:n(`profile.password.removeModal.submit`)})]})]})})}function We({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),{data:i}=f(N),a=i.auth.password.policy,c=(0,X.useMemo)(()=>q({password:J().min(a.min_length,n(`validation.password.min`,{count:a.min_length})).max(a.max_length,n(`validation.password.max`,{count:a.max_length})),confirmPassword:J()}).refine(e=>e.password===e.confirmPassword,{message:n(`validation.confirmPassword.mismatch`),path:[`confirmPassword`]}),[a.max_length,a.min_length,n]),l=W({resolver:G(c),defaultValues:{password:``,confirmPassword:``}}),u=m({...Ne,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),d()}}),d=()=>{l.reset(),t()},p=l.handleSubmit(async e=>{try{await u.mutateAsync({password:e.password})}catch{l.setError(`root`,{message:n(`profile.password.setModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.setModal.description`),icon:M,isOpen:e,onClose:d,title:n(`profile.password.setModal.title`),children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:p,children:[(0,Z.jsx)(A,{error:l.formState.errors.password,errorTestId:`set-password-error-password`,id:`new-password`,label:n(`profile.password.setModal.newPassword`),placeholder:n(`profile.password.setModal.newPasswordPlaceholder`),...l.register(`password`),type:`password`}),(0,Z.jsx)(A,{error:l.formState.errors.confirmPassword,errorTestId:`set-password-error-confirmPassword`,id:`confirm-password`,label:n(`profile.password.setModal.confirmPassword`),placeholder:n(`profile.password.setModal.confirmPasswordPlaceholder`),...l.register(`confirmPassword`),type:`password`}),l.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:l.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`set-password-cancel`,disabled:u.isPending,intent:`neutral`,onClick:d,type:`button`,uiSize:`sm`,children:n(`profile.password.setModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`set-password-submit`,disabled:u.isPending,intent:`primary`,loading:u.isPending,loadingLabel:n(`profile.password.setModal.submitting`),type:`submit`,uiSize:`sm`,children:u.isPending?void 0:n(`profile.password.setModal.submit`)})]})]})})}function Ge({isOpen:e,onClose:t,isRequired:n=!1,canSwitchToTotp:r=!1,onSwitchToTotp:i}){let{t:a}=s(),c=o(),[l,u]=(0,X.useState)(`name`),[d,f]=(0,X.useState)(null),h=(0,X.useMemo)(()=>q({name:J().max(100,a(`validation.passkey.name.max`)).optional().transform(e=>e?.trim()||void 0)}),[a]),g=W({resolver:G(h),defaultValues:{name:``}}),_=m({...fe,onSuccess:()=>{c.invalidateQueries({queryKey:P.passkeys()}),c.invalidateQueries({queryKey:Y.queryKey}),v()},onError:e=>{u(`name`),e.name===`NotAllowedError`?f(a(`profile.passkey.setupModal.cancelled`)):f(a(`profile.passkey.setupModal.error`))}}),v=(0,X.useCallback)(()=>{g.reset(),u(`name`),f(null),t()},[g,t]),y=g.handleSubmit(async e=>{u(`register`),f(null);try{await _.mutateAsync({name:e.name})}catch{}}),b=_.isPending;return(0,Z.jsxs)(H,{description:n?a(`profile.passkey.setupModal.requiredDescription`):void 0,icon:j,isOpen:e,onClose:v,preventClose:n,size:`sm`,title:a(`profile.passkey.setupModal.title`),children:[l===`name`&&(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:y,children:[(0,Z.jsx)(p,{as:`p`,color:`muted`,variant:`caption`,children:a(`profile.passkey.setupModal.description`)}),d&&(0,Z.jsx)($,{variant:`error`,children:d}),(0,Z.jsx)(A,{error:g.formState.errors.name,errorTestId:`setup-passkey-error`,hint:a(`profile.passkey.setupModal.nameHint`),id:`passkey-name`,label:a(`profile.passkey.setupModal.nameLabel`),placeholder:a(`profile.passkey.setupModal.namePlaceholder`),...g.register(`name`),type:`text`}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`setup-passkey-cancel`,intent:`neutral`,onClick:v,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`setup-passkey-continue`,intent:`primary`,type:`submit`,uiSize:`sm`,children:a(`profile.passkey.setupModal.continue`)})]}),r&&i&&(0,Z.jsx)(p,{align:`center`,as:`p`,className:`mt-tinyrack-sm`,variant:`caption`,children:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:i,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.switchToTotp`)})})]}),l===`register`&&(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-tinyrack-md py-tinyrack-xl`,"data-testid":`setup-passkey-loading`,children:[(0,Z.jsx)(S,{uiSize:`md`}),(0,Z.jsx)(p,{align:`center`,as:`p`,color:`muted`,variant:`caption`,children:a(`profile.passkey.setupModal.waitingForDevice`)})]}),(0,Z.jsx)(V,{children:(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`setup-passkey-cancel`,disabled:b,intent:`neutral`,onClick:v,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.cancel`)})})]})]})}function Ke({isOpen:e,onClose:t,isRequired:n=!1,canSwitchToPasskey:r=!1,onSwitchToPasskey:i}){let{t:a}=s(),{step:o,setupData:c,recoveryCodes:l,isSetupPending:u,isVerifyPending:d,isConfirmPending:f,startSetup:m,verify:h,goToVerify:g,goToQr:_,confirmRecoveryCodes:v,reset:y}=k({autoStart:!1,onConfirmSuccess:()=>{y(),t()}}),b=(0,X.useCallback)(()=>{y(),t()},[t,y]),x=(0,X.useCallback)(()=>{!c&&!u&&m()},[c,u,m]);e&&!c&&!u&&o!==`error`&&x();let w=(0,X.useCallback)(async e=>{await h(e)},[h]),T=a(o===`recovery`?`setupTotp.recoveryCodes.title`:`profile.totp.setupModal.title`);return(0,Z.jsxs)(H,{description:n?a(`profile.totp.setupModal.requiredDescription`):void 0,icon:L,isOpen:e,onClose:b,preventClose:n||o===`recovery`,size:`sm`,title:T,children:[u&&(0,Z.jsx)(`div`,{className:`flex justify-center py-tinyrack-xl`,"data-testid":`setup-totp-loading`,children:(0,Z.jsx)(S,{uiSize:`md`})}),o===`error`&&(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,children:[(0,Z.jsx)($,{variant:`error`,children:a(`profile.totp.setupModal.setupError`)}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,intent:`neutral`,onClick:b,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.cancel`)}),(0,Z.jsx)(C,{intent:`primary`,onClick:m,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.retry`)})]})]}),c&&o===`qr`&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(ee,{additionalActions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{children:(0,Z.jsx)(C,{appearance:`outline`,intent:`neutral`,onClick:b,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.cancel`)})}),r&&i&&(0,Z.jsx)(p,{align:`center`,as:`p`,className:`mt-tinyrack-sm`,variant:`caption`,children:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:i,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.switchToPasskey`)})})]}),onNext:g,setupData:c})}),c&&o===`verify`&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(O,{isPending:d,onBack:_,onSubmit:w})}),o===`recovery`&&l.length>0&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(D,{isLoading:f,onConfirm:v,recoveryCodes:l})})]})}var qe=(e=>d({queryKey:P.oauth.accounts(),queryFn:async()=>{let t=await e.api.user[`oauth-accounts`].$get();return l(t)}}))(u),Je=g({mutationFn:async e=>{let t=await u.api.oauth[`:provider`].$delete({param:{provider:e}});return l(t)}});function Ye(e,t=`login`,n){let r=new URLSearchParams({mode:t});return n&&r.set(`return_url`,n),`/api/oauth/${encodeURIComponent(e)}/authorize?${r.toString()}`}var Xe={access_denied:`oauth.error.accessDenied`,temporarily_unavailable:`oauth.error.temporarilyUnavailable`,server_error:`oauth.error.serverError`};function Ze(e){return(0,Z.jsx)(U,{...e,onUnauthorized:()=>{he(`/login`)}})}function Qe({search:e}){let{t}=s(),n=r(),i=o(),a=e.oauth_error,c=a?t(Xe[a]??`oauth.error.failed`):void 0,[l,u]=(0,X.useState)(null),[d,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,E]=(0,X.useState)(!1),{data:D}=f(Y),{data:ee}=f(qe),{data:O}=f(N),k=m({...re,onSuccess:async()=>{i.setQueryData(Y.queryKey,{user:null}),await se(),n(`/login`)},onSettled:()=>{i.invalidateQueries({queryKey:Y.queryKey})}}),A=m({...Je,onSuccess:()=>{i.invalidateQueries({queryKey:qe.queryKey})},onSettled:()=>{u(null)}}),j=async()=>{d&&(u(d.id),await A.mutateAsync(d.id))};if(!D.user)return null;let M=D.user,P=ee.available_providers,F=P.some(e=>e.linked),I=M.managed_by===`config`,te=O.auth.password,L=O.auth.passkey,R=te.totp.enabled,z=L.enabled,ae=O.account_deletion.enabled,V=O.account_deletion.retention,H=(()=>{let e=V.match(/^(\d+)([dmy])$/);if(!e)return 30;let t=parseInt(e[1],10);switch(e[2]){case`d`:return t;case`m`:return t*30;case`y`:return t*365;default:return 30}})(),U=!I&&R,W=!I&&z,G=P.length>0;return(0,Z.jsxs)(Me,{headerActions:(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":t(`profile.logout`),"data-testid":`profile-logout`,disabled:k.isPending,loading:k.isPending,onClick:()=>k.mutate(),type:`button`,uiSize:`sm`,children:k.isPending?void 0:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ne,{"aria-hidden":!0,className:`size-tinyrack-lg`}),(0,Z.jsx)(p,{as:`span`,className:`hidden sm:inline`,variant:`bodySm`,children:t(`profile.logout`)})]})}),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-lg`,children:[(0,Z.jsx)(oe,{email:M.email,size:`lg`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(ie,{title:t(`profile.title`)}),(0,Z.jsx)(p,{as:`p`,color:`muted`,"data-testid":`profile-user-email`,truncate:!0,variant:`bodySm`,children:M.email})]})]}),c&&(0,Z.jsx)(B,{icon:T,type:`error`,children:c}),M&&(0,Z.jsx)(je,{user:M}),(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:t(`profile.security.title`)}),(0,Z.jsx)(w.Description,{children:t(`profile.security.description`)})]}),U&&M.totp_recovery_codes_missing&&(0,Z.jsx)(`div`,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,"data-testid":`profile-totp-recovery-warning`,children:(0,Z.jsx)(B,{icon:T,type:`warning`,children:t(`profile.totp.recoveryCodesMissing`)})}),(0,Z.jsxs)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:[(0,Z.jsx)(Ee,{hasLinkedOAuth:F,hasPassword:M.has_password,hasSecondFactorOnly:M.has_password&&!F&&(M.totp_registered||M.passkey_count>0),isConfigManaged:I,onOpenModal:_}),U&&(0,Z.jsx)(De,{onOpenModal:y,recoveryCodesMissing:M.totp_recovery_codes_missing,totpEnabled:M.totp_registered}),W&&(0,Z.jsx)(Te,{onOpenModal:x,passkeyCount:M.passkey_count})]})]}),G&&(0,Z.jsx)(we,{getAuthorizeUrl:Ye,onUnlinkRequest:e=>h({id:e.id,name:e.display_name}),providers:P,unlinkingProvider:l}),(0,Z.jsx)(Se,{isConfigManaged:I,isDeletionEnabled:ae,onDeleteClick:()=>E(!0)}),(0,Z.jsx)(We,{isOpen:g===`set`,onClose:()=>_(null)}),(0,Z.jsx)(Ie,{isOpen:g===`change`,onClose:()=>_(null)}),(0,Z.jsx)(Ue,{isOpen:g===`remove`,onClose:()=>_(null)}),(0,Z.jsx)(Ke,{isOpen:v===`setup`,onClose:()=>y(null)}),(0,Z.jsx)(ze,{isOpen:v===`disable`,onClose:()=>y(null)}),(0,Z.jsx)(He,{isOpen:v===`regenerate`,onClose:()=>y(null)}),(0,Z.jsx)(Ge,{isOpen:b===`setup`,onClose:()=>x(null)}),(0,Z.jsx)(Be,{isOpen:b===`manage`,onAddNew:()=>x(`setup`),onClose:()=>x(null)}),(0,Z.jsx)(ke,{isOpen:d!==null,isPending:A.isPending,onClose:()=>h(null),onConfirm:j,providerName:d?.name??``}),(0,Z.jsx)(Re,{isOpen:S,onClose:()=>E(!1),retentionDays:H})]})}var $e=i(function({error:e}){return(0,Z.jsx)(_e,{component:Ze,error:e})}),et=n(function({loaderData:e}){return(0,Z.jsx)(ge,{state:e.dehydratedState,children:(0,Z.jsx)(Qe,{search:e.search})})});export{$e as ErrorBoundary,et as default};
1
+ import{$ as e,J as t,a as n,f as r,o as i}from"./components-C1SipCbb.js";import{t as a}from"./jsx-runtime-BFZ_fnNJ.js";import{L as o,a as s,i as c,n as l,t as u}from"./api-0SzZx6X7.js";import{n as d,r as f,t as p}from"./text-CGN4ZtUZ.js";import{t as m}from"./useMutation-C4CmK9Sb.js";import{t as h}from"./useQuery-BtUeFnRt.js";import{t as g}from"./mutationOptions-Dfvzj6n2.js";import{V as _}from"./select--ltVnlVl.js";import{a as v,i as y,r as b,t as x}from"./shell-header-bar-C3KYib1D.js";import{i as S,r as C}from"./NullStore-BxU9yW8l.js";import{t as w}from"./card-CTv8DubK.js";import{t as T}from"./circle-alert-DGTJ9B9k.js";import{a as E,i as D,n as ee,r as O,t as k}from"./use-totp-setup-BOSkSnYG.js";import{t as A}from"./auth-field-1EM9pnWe.js";import{t as j}from"./fingerprint-pattern-V_eTEvnZ.js";import{t as M}from"./key-round-DgCbGqQL.js";import{n as N,r as P}from"./language-selector-CGXk9vW_.js";import{n as F,t as I}from"./provider-mark-B05f08GZ.js";import{n as te,r as ne,t as re}from"./logout-CBTnIosZ.js";import{t as L}from"./shield-check-93-WFkyJ.js";import{t as R}from"./trash-2-BOsxjkzU.js";import{t as z}from"./triangle-alert-DSSurAZ_.js";import{t as ie}from"./auth-page-header-D5Z-EA6V.js";import{t as ae}from"./link-button-qvSTUE1n.js";import{t as B}from"./alert-CFUBsmUN.js";import{n as V,t as H}from"./modal-LoTH9Ttl.js";import{t as oe}from"./initial-avatar-D4aPMV9z.js";import{t as U}from"./route-error-fallback-C2OHu3JW.js";import{r as W,t as G}from"./standard-schema-C8Td_miB.js";import{r as K}from"./FieldItemContext-CPjig163.js";import{a as q,s as J}from"./schemas-Dxi9xZo6.js";import{n as Y,t as se}from"./promise-CFWkfv2A.js";import{n as ce,r as le}from"./totp-BW4BoCpi.js";import{t as ue}from"./badge-BCQspax5.js";import{a as de,i as fe,n as pe,r as me}from"./passkey-C9bzur2Z.js";import{t as he}from"./document-navigation-Cnp3Alf0.js";import{n as ge,t as _e}from"./route-module-Bm4sHkx9.js";var ve=_(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),ye=_(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),be=_(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),xe=_(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),X=e(t(),1),Z=a();function Se({isConfigManaged:e,isDeletionEnabled:t,onDeleteClick:n}){let{t:r}=s();return t?(0,Z.jsxs)(w.Root,{className:`border-tinyrack-danger-border bg-tinyrack-danger-surface`,variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-danger-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[(0,Z.jsx)(z,{"aria-hidden":!0,className:`size-tinyrack-lg text-tinyrack-danger-foreground`}),(0,Z.jsx)(w.Title,{className:`text-tinyrack-danger-foreground`,children:r(`profile.dangerZone.title`)})]}),(0,Z.jsx)(w.Description,{children:r(`profile.dangerZone.description`)})]}),(0,Z.jsx)(w.Content,{className:`px-tinyrack-lg py-tinyrack-md`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(p,{as:`p`,variant:`bodySm`,weight:`medium`,children:r(`profile.deleteAccount.title`)}),(0,Z.jsx)(p,{as:`p`,color:`muted`,variant:`caption`,children:r(e?`profile.deleteAccount.configManaged`:`profile.deleteAccount.description`)})]}),(0,Z.jsxs)(C,{appearance:`outline`,"data-testid":`profile-delete-account`,disabled:e,intent:`danger`,onClick:n,type:`button`,uiSize:`sm`,children:[(0,Z.jsx)(R,{"aria-hidden":!0,className:`size-tinyrack-lg`}),r(`profile.deleteAccount.button`)]})]})})]}):null}function Ce({providerId:e,iconUrl:t,className:n=`size-tinyrack-xl`}){return e===`google`||e===`github`||e===`apple`?(0,Z.jsx)(I,{"aria-hidden":!0,className:n,provider:e}):t?(0,Z.jsx)(`img`,{alt:``,className:n,src:t}):(0,Z.jsx)(F,{"aria-hidden":!0,className:n})}function Q({icon:e,active:t,title:n,status:r,note:i,actions:a}){let o;return o=(0,X.isValidElement)(e)?e:(0,Z.jsx)(e,{"aria-hidden":!0,className:`size-tinyrack-lg ${t?`text-tinyrack-success-foreground`:`text-tinyrack-text-muted`}`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg p-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-tinyrack-md`,children:[(0,Z.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-tinyrack-md ${t?`bg-tinyrack-success-surface`:`bg-tinyrack-surface-muted`}`,children:o}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(p,{variant:`bodySm`,weight:`medium`,children:n}),(0,Z.jsx)(p,{color:`muted`,variant:`caption`,children:r}),i]})]}),a&&(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-tinyrack-xs`,children:a})]})}function we({providers:e,unlinkingProvider:t,getAuthorizeUrl:n,onUnlinkRequest:r}){let{t:i}=s();return e.length===0?null:(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:i(`profile.linkedAccounts.title`)}),(0,Z.jsx)(w.Description,{children:i(`profile.linkedAccounts.description`)})]}),(0,Z.jsx)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:e.map(e=>(0,Z.jsx)(Q,{actions:e.linked?(0,Z.jsx)(C,{appearance:`ghost`,intent:`danger`,loading:t===e.id,loadingLabel:i(`profile.linkedAccounts.unlinking`),onClick:()=>r(e),type:`button`,uiSize:`sm`,children:t===e.id?void 0:i(`profile.linkedAccounts.unlink`)}):(0,Z.jsx)(ae,{appearance:`outline`,intent:`neutral`,render:(0,Z.jsx)(`a`,{href:n(e.id,`link`,`/profile`)}),uiSize:`sm`,children:i(`profile.linkedAccounts.link`)}),active:e.linked,icon:(0,Z.jsx)(Ce,{className:`size-tinyrack-lg`,iconUrl:e.icon_url,providerId:e.id}),status:e.linked?i(`profile.linkedAccounts.connected`):i(`profile.linkedAccounts.notConnected`),title:e.display_name},e.id))})]})}function Te({passkeyCount:e,onOpenModal:t}){let{t:n}=s(),r=e>0;return(0,Z.jsx)(Q,{actions:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:()=>t(r?`manage`:`setup`),type:`button`,uiSize:`sm`,children:n(r?`profile.passkey.manage`:`profile.passkey.add`)}),active:r,icon:j,status:r?n(`profile.passkey.status.enabled`,{count:e}):n(`profile.passkey.status.disabled`),title:n(`profile.passkey.title`)})}function Ee({hasPassword:e,hasLinkedOAuth:t,isConfigManaged:n,hasSecondFactorOnly:r,onOpenModal:i}){let{t:a}=s();return(0,Z.jsx)(Q,{actions:n?void 0:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-change`,intent:`primary`,onClick:()=>i(`change`),type:`button`,uiSize:`sm`,children:a(`profile.password.change`)}),t?(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-remove`,intent:`danger`,onClick:()=>i(`remove`),type:`button`,uiSize:`sm`,children:a(`profile.password.remove`)}):null,!t&&r&&(0,Z.jsxs)(v.Root,{children:[(0,Z.jsx)(v.Trigger,{render:(0,Z.jsx)(C,{appearance:`ghost`,disabled:!0,type:`button`,uiSize:`sm`,children:a(`profile.password.remove`)})}),(0,Z.jsx)(v.Portal,{children:(0,Z.jsx)(v.Positioner,{children:(0,Z.jsx)(v.Popup,{className:`max-w-tinyrack-measure-lg rounded-tinyrack-md border border-tinyrack-border bg-tinyrack-surface p-tinyrack-md text-tinyrack-text text-tinyrack-xs shadow-tinyrack-overlay`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-tinyrack-sm`,children:[(0,Z.jsx)(E,{"aria-hidden":!0,className:`size-tinyrack-lg shrink-0 text-tinyrack-warning-foreground`}),(0,Z.jsx)(p,{variant:`caption`,children:a(`profile.password.removeDisabledReason`)})]})})})})]})]}):(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-password-set`,intent:`primary`,onClick:()=>i(`set`),type:`button`,uiSize:`sm`,children:a(`profile.password.set`)}),active:e,icon:M,note:n?(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-xs`,children:[(0,Z.jsx)(te,{"aria-hidden":!0,className:`size-tinyrack-md shrink-0`}),(0,Z.jsx)(p,{as:`span`,color:`muted`,variant:`caption`,children:a(`profile.password.configManaged`)})]}):void 0,status:a(e?`profile.password.status.set`:`profile.password.status.notSet`),title:a(`profile.password.title`)})}function De({totpEnabled:e,recoveryCodesMissing:t,onOpenModal:n}){let{t:r}=s();return(0,Z.jsx)(Q,{actions:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-regenerate`,intent:`primary`,onClick:()=>n(`regenerate`),type:`button`,uiSize:`sm`,children:r(`profile.totp.regenerate`)}),(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-disable`,intent:`danger`,onClick:()=>n(`disable`),type:`button`,uiSize:`sm`,children:r(`profile.totp.disable`)})]}):(0,Z.jsx)(C,{appearance:`ghost`,"data-testid":`profile-totp-enable`,intent:`primary`,onClick:()=>n(`setup`),type:`button`,uiSize:`sm`,children:r(`profile.totp.enable`)}),active:e,icon:L,status:r(e?t?`profile.totp.status.recoveryCodesMissing`:`profile.totp.status.enabled`:`profile.totp.status.disabled`),title:r(`profile.totp.title`)})}var Oe={error:T,warning:z,info:E};function $({variant:e,children:t}){return(0,Z.jsx)(B,{"data-testid":`alert-banner-${e}`,icon:Oe[e],type:e,children:t})}function ke({isOpen:e,onClose:t,providerName:n,isPending:r,onConfirm:i}){let{t:a}=s(),[o,c]=(0,X.useState)(null),l=()=>{r||(c(null),t())};return(0,Z.jsx)(H,{description:a(`profile.linkedAccounts.unlinkModal.description`,{provider:n}),icon:ye,isOpen:e,onClose:l,preventClose:r,title:a(`profile.linkedAccounts.unlinkModal.title`),variant:`destructive`,children:(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,children:[(0,Z.jsx)($,{variant:`warning`,children:a(`profile.linkedAccounts.unlinkModal.warning`,{provider:n})}),o&&(0,Z.jsx)($,{variant:`error`,children:o}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`unlink-oauth-cancel`,disabled:r,intent:`neutral`,onClick:l,type:`button`,uiSize:`sm`,children:a(`profile.linkedAccounts.unlinkModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`unlink-oauth-unlink`,disabled:r,intent:`danger`,loading:r,loadingLabel:a(`profile.linkedAccounts.unlinking`),onClick:async()=>{c(null);try{await i(),l()}catch{c(a(`profile.linkedAccounts.unlinkError`))}},type:`button`,uiSize:`sm`,children:a(`profile.linkedAccounts.unlink`)})]})]})})}function Ae({label:e,value:t}){return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-tinyrack-lg px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(p,{className:`shrink-0`,color:`muted`,variant:`caption`,children:e}),(0,Z.jsx)(p,{truncate:!0,variant:`bodySm`,weight:`medium`,children:t})]})}function je({user:e}){let{t}=s();return(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:t(`profile.account.title`)}),(0,Z.jsx)(w.Description,{children:t(`profile.account.description`)})]}),(0,Z.jsxs)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:[(0,Z.jsx)(Ae,{label:t(`profile.id.label`),value:e.sub}),(0,Z.jsx)(Ae,{label:t(`profile.email.label`),value:e.email})]})]})}function Me({children:e,headerActions:t}){return(0,Z.jsxs)(`div`,{className:`flex min-h-dvh flex-col bg-tinyrack-surface`,children:[(0,Z.jsx)(y,{}),(0,Z.jsx)(x,{actions:t,brand:!0}),(0,Z.jsx)(`main`,{className:`flex flex-1 justify-center px-tinyrack-lg py-tinyrack-xl`,children:(0,Z.jsx)(`div`,{className:`auth-enter flex w-full max-w-tinyrack-overlay-width-md flex-col gap-tinyrack-xl`,children:e})}),(0,Z.jsx)(b,{})]})}var Ne=g({mutationFn:async e=>{let t=await u.api.user.password.$post({json:e});return l(t)}}),Pe=g({mutationFn:async e=>{let t=await u.api.user.password.$put({json:e});return l(t)}}),Fe=g({mutationFn:async e=>{let t=await u.api.user.password.$delete({json:e});return l(t)}});function Ie({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),{data:i}=f(N),a=i.auth.password.policy,l=(0,X.useMemo)(()=>q({currentPassword:J().min(1,n(`validation.password.required`)),newPassword:J().min(a.min_length,n(`validation.password.min`,{count:a.min_length})).max(a.max_length,n(`validation.password.max`,{count:a.max_length})),confirmPassword:J()}).refine(e=>e.newPassword===e.confirmPassword,{message:n(`validation.confirmPassword.mismatch`),path:[`confirmPassword`]}),[a.max_length,a.min_length,n]),u=W({resolver:G(l),defaultValues:{currentPassword:``,newPassword:``,confirmPassword:``}}),d=m({...Pe,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),p()}}),p=()=>{u.reset(),t()},h=u.handleSubmit(async e=>{try{await d.mutateAsync({current_password:e.currentPassword,new_password:e.newPassword})}catch(e){e instanceof c&&e.code===`INVALID_CURRENT_PASSWORD`?u.setError(`currentPassword`,{message:n(`profile.password.changeModal.invalidCurrent`)}):u.setError(`root`,{message:n(`profile.password.changeModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.changeModal.description`),icon:M,isOpen:e,onClose:p,title:n(`profile.password.changeModal.title`),children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:h,children:[(0,Z.jsx)(A,{error:u.formState.errors.currentPassword,errorTestId:`change-password-error-currentPassword`,id:`current-password`,label:n(`profile.password.changeModal.currentPassword`),placeholder:n(`profile.password.changeModal.currentPasswordPlaceholder`),...u.register(`currentPassword`),type:`password`}),(0,Z.jsx)(A,{error:u.formState.errors.newPassword,errorTestId:`change-password-error-newPassword`,id:`new-password-change`,label:n(`profile.password.changeModal.newPassword`),placeholder:n(`profile.password.changeModal.newPasswordPlaceholder`),...u.register(`newPassword`),type:`password`}),(0,Z.jsx)(A,{error:u.formState.errors.confirmPassword,errorTestId:`change-password-error-confirmPassword`,id:`confirm-password-change`,label:n(`profile.password.changeModal.confirmPassword`),placeholder:n(`profile.password.changeModal.confirmPasswordPlaceholder`),...u.register(`confirmPassword`),type:`password`}),u.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:u.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`change-password-cancel`,disabled:d.isPending,intent:`neutral`,onClick:p,type:`button`,uiSize:`sm`,children:n(`profile.password.changeModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`change-password-submit`,disabled:d.isPending,intent:`primary`,loading:d.isPending,loadingLabel:n(`profile.password.changeModal.submitting`),type:`submit`,uiSize:`sm`,children:d.isPending?void 0:n(`profile.password.changeModal.submit`)})]})]})})}var Le=g({mutationFn:async()=>{let e=await u.api.user.$delete();return l(e)}});function Re({isOpen:e,onClose:t,retentionDays:n}){let{t:i}=s(),a=r(),c=o(),l=(0,X.useMemo)(()=>q({confirmation:J().refine(e=>e.toLowerCase()===i(`profile.deleteAccount.modal.confirmPlaceholder`).toLowerCase(),{message:i(`validation.confirmText.mismatch`)})}),[i]),u=W({resolver:G(l),defaultValues:{confirmation:``}}),d=m({...Le,onSuccess:async()=>{c.setQueryData(Y.queryKey,{user:null}),await se(),a(`/login`)}}),f=()=>{d.isPending||(u.reset(),t())},h=u.handleSubmit(async()=>{try{await d.mutateAsync()}catch{u.setError(`root`,{message:i(`profile.deleteAccount.error`)})}});return(0,Z.jsx)(H,{icon:R,isOpen:e,onClose:f,preventClose:d.isPending,title:i(`profile.deleteAccount.modal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:h,children:[(0,Z.jsxs)($,{variant:`error`,children:[(0,Z.jsx)(p,{as:`span`,variant:`bodySm`,children:i(`profile.deleteAccount.modal.description`,{days:n})}),(0,Z.jsx)(`br`,{}),(0,Z.jsx)(p,{as:`span`,className:`opacity-tinyrack-hover`,variant:`caption`,children:i(`profile.deleteAccount.modal.warning`)})]}),(0,Z.jsx)(A,{autoComplete:`off`,error:u.formState.errors.confirmation,errorTestId:`delete-account-error`,id:`delete-confirmation`,label:i(`profile.deleteAccount.modal.confirmLabel`),placeholder:i(`profile.deleteAccount.modal.confirmPlaceholder`),...u.register(`confirmation`),type:`text`}),u.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:u.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`delete-account-cancel`,disabled:d.isPending,intent:`neutral`,onClick:f,type:`button`,uiSize:`sm`,children:i(`profile.deleteAccount.modal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`delete-account-submit`,disabled:d.isPending,intent:`danger`,loading:d.isPending,loadingLabel:i(`profile.deleteAccount.modal.confirming`),type:`submit`,uiSize:`sm`,children:d.isPending?void 0:i(`profile.deleteAccount.modal.confirm`)})]})]})})}function ze({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),i=(0,X.useMemo)(()=>q({code:J().length(6,n(`validation.totp.length`)).regex(/^\d{6}$/,n(`validation.totp.digits`))}),[n]),a=W({resolver:G(i),defaultValues:{code:``}}),l=m({...ce,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),u()}}),u=()=>{a.reset(),t()},d=a.handleSubmit(async e=>{try{await l.mutateAsync({code:e.code})}catch(e){if(e instanceof c&&e.code===`CANNOT_REMOVE_LAST_SECOND_FACTOR`){a.setError(`code`,{message:n(`profile.totp.disableModal.cannotRemoveLastSecondFactor`)});return}a.setError(`code`,{message:n(`profile.totp.disableModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.totp.disableModal.description`),icon:L,isOpen:e,onClose:u,title:n(`profile.totp.disableModal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:d,children:[(0,Z.jsx)($,{variant:`warning`,children:n(`profile.totp.disableModal.warning`)}),(0,Z.jsx)(A,{autoComplete:`one-time-code`,error:a.formState.errors.code,errorTestId:`disable-totp-error`,id:`disable-totp-code`,inputMode:`numeric`,label:n(`profile.totp.disableModal.codeLabel`),maxLength:6,pattern:`[0-9]*`,placeholder:`000000`,...a.register(`code`),type:`text`}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`disable-totp-cancel`,disabled:l.isPending,intent:`neutral`,onClick:u,type:`button`,uiSize:`sm`,children:n(`profile.totp.disableModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`disable-totp-submit`,disabled:l.isPending,intent:`danger`,loading:l.isPending,loadingLabel:n(`profile.totp.disableModal.disabling`),type:`submit`,uiSize:`sm`,children:l.isPending?void 0:n(`profile.totp.disableModal.disable`)})]})]})})}function Be({isOpen:e,onClose:t,onAddNew:n}){let{t:r}=s(),i=o(),[a,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),{data:y,isLoading:b}=h({...me,enabled:e}),x=m({...pe,onSuccess:()=>{i.invalidateQueries({queryKey:P.passkeys()}),i.invalidateQueries({queryKey:Y.queryKey})},onSettled:()=>{d(null)}}),w=(0,X.useCallback)(()=>{l(null),d(null),g(null),v(null),t()},[t]),T=e=>{g(e.id),v(null)},E=()=>{g(null),v(null)},D=async e=>{d(e.id),g(null);try{await x.mutateAsync({id:e.id})}catch(e){if(e instanceof c&&e.code===`CANNOT_REMOVE_LAST_SECOND_FACTOR`){v(r(`profile.passkey.manageModal.cannotRemoveLastSecondFactor`));return}v(r(`profile.passkey.manageModal.deleteError`))}},ee=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`}),O=y?.passkeys||[];return(0,Z.jsxs)(H,{icon:j,isOpen:e,onClose:w,size:`lg`,title:r(`profile.passkey.manageModal.title`),children:[(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-sm`,children:[_&&(0,Z.jsx)($,{variant:`error`,children:_}),b&&(0,Z.jsx)(`div`,{className:`flex justify-center py-tinyrack-xl`,children:(0,Z.jsx)(S,{uiSize:`md`})}),!b&&O.length===0&&(0,Z.jsx)(p,{align:`center`,className:`py-tinyrack-xl`,color:`muted`,"data-testid":`passkeys-empty`,variant:`bodySm`,children:r(`profile.passkey.manageModal.noPasskeys`)}),!b&&O.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-col gap-tinyrack-sm`,children:O.map(e=>(0,Z.jsx)(Ve,{formatDate:ee,isConfirmingDelete:f===e.id,isDeleting:u===e.id,isEditing:a?.id===e.id,onCancelDelete:E,onCancelEdit:()=>l(null),onConfirmDelete:()=>D(e),onEdit:()=>l(e),onRequestDelete:()=>T(e),passkey:e},e.id))})]}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`manage-passkeys-close`,intent:`neutral`,onClick:w,type:`button`,uiSize:`sm`,children:r(`profile.passkey.manageModal.close`)}),(0,Z.jsx)(C,{"data-testid":`manage-passkeys-add-new`,intent:`primary`,onClick:()=>{w(),n()},type:`button`,uiSize:`sm`,children:r(`profile.passkey.manageModal.addNew`)})]})]})}function Ve({passkey:e,isDeleting:t,isEditing:n,isConfirmingDelete:r,onEdit:i,onCancelEdit:a,onRequestDelete:c,onConfirmDelete:l,onCancelDelete:u,formatDate:d}){let{t:f}=s(),h=o(),g=(0,X.useMemo)(()=>q({name:J().min(1,f(`validation.passkey.name.required`)).max(100,f(`validation.passkey.name.max`))}),[f]),_=W({resolver:G(g),defaultValues:{name:e.name||``}}),v=m({...de,onSuccess:()=>{h.invalidateQueries({queryKey:P.passkeys()}),a()}}),y=_.handleSubmit(async t=>{try{await v.mutateAsync({id:e.id,name:t.name})}catch{_.setError(`name`,{message:f(`profile.passkey.manageModal.renameError`)})}});return n?(0,Z.jsxs)(K,{className:`flex flex-col gap-tinyrack-xs rounded-tinyrack-md bg-tinyrack-surface-muted p-tinyrack-sm`,onSubmit:y,children:[(0,Z.jsx)(A,{"data-testid":`passkey-rename-input`,error:_.formState.errors.name,errorTestId:`passkey-rename-error`,hideLabel:!0,label:f(`profile.passkey.manageModal.nameLabel`),placeholder:f(`profile.passkey.manageModal.namePlaceholder`),..._.register(`name`),type:`text`}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,disabled:v.isPending,onClick:()=>{_.reset(),a()},type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.cancelEdit`)}),(0,Z.jsx)(C,{disabled:v.isPending,intent:`primary`,type:`submit`,uiSize:`sm`,children:v.isPending?f(`profile.passkey.manageModal.saving`):f(`profile.passkey.manageModal.save`)})]})]}):r?(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-tinyrack-md border border-tinyrack-danger-border bg-tinyrack-danger-surface p-tinyrack-sm text-tinyrack-danger-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[(0,Z.jsx)(R,{className:`size-tinyrack-lg`}),(0,Z.jsx)(p,{color:`danger`,variant:`caption`,children:f(`profile.passkey.manageModal.deleteConfirmInline`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,onClick:u,type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.cancelEdit`)}),(0,Z.jsx)(C,{intent:`danger`,onClick:l,type:`button`,uiSize:`sm`,children:f(`profile.passkey.manageModal.delete`)})]})]}):(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-tinyrack-md bg-tinyrack-surface-muted p-tinyrack-sm`,"data-testid":`passkey-item`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-sm`,children:[e.device_type===`multiDevice`?(0,Z.jsx)(ve,{className:`size-tinyrack-lg text-tinyrack-primary-foreground`}):(0,Z.jsx)(xe,{className:`size-tinyrack-lg text-tinyrack-primary-foreground`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(p,{variant:`caption`,weight:`medium`,children:e.name||f(`profile.passkey.manageModal.unnamedPasskey`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-xs`,children:[(0,Z.jsx)(p,{color:`muted`,variant:`caption`,children:f(`profile.passkey.manageModal.createdAt`,{date:d(e.created_at)})}),e.backed_up&&(0,Z.jsx)(ue,{uiSize:`md`,variant:`success`,children:f(`profile.passkey.manageModal.backedUp`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-tinyrack-xs`,children:[(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":f(`profile.passkey.manageModal.rename`),onClick:i,type:`button`,uiSize:`sm`,children:(0,Z.jsx)(be,{className:`size-tinyrack-lg`})}),(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":f(`profile.passkey.manageModal.delete`),disabled:t,intent:`danger`,loading:t,onClick:c,type:`button`,uiSize:`sm`,children:t?void 0:(0,Z.jsx)(R,{className:`size-tinyrack-lg`})})]})]})}function He({isOpen:e,onClose:t}){let{t:n}=s(),i=r(),a=o(),{data:l}=f(N),[u,d]=(0,X.useState)(`verify`),[p,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),v=m({...le,onSuccess:async e=>{h(e),d(`recovery`),await a.invalidateQueries({queryKey:Y.queryKey})}}),y=(0,X.useCallback)(()=>{d(`verify`),h(null),_(null),v.reset()},[v]),b=(0,X.useCallback)(()=>{y(),t()},[t,y]),x=(0,X.useCallback)(async e=>{_(null);try{await v.mutateAsync({code:e})}catch(e){if(e instanceof c){if(e.code===`INVALID_TOTP_CODE`)throw e;if(e.code===`UNAUTHORIZED`){a.setQueryData(Y.queryKey,{user:null}),await se(),i(`/login`);return}if(e.code===`TOTP_NOT_ENABLED`||e.code===`VALIDATION_ERROR`){await a.invalidateQueries({queryKey:Y.queryKey}),b();return}}_(n(`profile.totp.regenerateModal.unexpectedError`))}},[b,v,i,a,n]);return l.auth.password.totp.enabled?(0,Z.jsx)(H,{description:n(u===`verify`?`profile.totp.regenerateModal.description`:`profile.totp.regenerateModal.recoveryDescription`),icon:L,isOpen:e,onClose:b,preventClose:u===`recovery`,size:`sm`,title:n(u===`verify`?`profile.totp.regenerateModal.title`:`profile.totp.regenerateModal.recoveryTitle`),children:u===`verify`?(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg`,children:[g&&(0,Z.jsx)(`div`,{className:`mb-tinyrack-md`,children:(0,Z.jsx)($,{variant:`error`,children:g})}),(0,Z.jsx)(O,{invalidMessage:n(`profile.totp.regenerateModal.error`),isPending:v.isPending,onSubmit:x,pendingText:n(`profile.totp.regenerateModal.submitting`),submitLabel:n(`profile.totp.regenerateModal.submit`)})]}):(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(D,{onConfirm:b,recoveryCodes:p?.recovery_codes??[]})})}):null}function Ue({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),i=(0,X.useMemo)(()=>q({currentPassword:J().min(1,n(`validation.password.required`))}),[n]),a=W({resolver:G(i),defaultValues:{currentPassword:``}}),l=m({...Fe,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),u()}}),u=()=>{a.reset(),t()},d=a.handleSubmit(async e=>{try{await l.mutateAsync({current_password:e.currentPassword})}catch(e){if(e instanceof c){if(e.code===`INVALID_CURRENT_PASSWORD`){a.setError(`currentPassword`,{message:n(`profile.password.removeModal.invalidCurrent`)});return}if(e.code===`CANNOT_REMOVE_LAST_AUTH_METHOD`){a.setError(`root`,{message:n(`profile.password.removeModal.noOAuth`)});return}if(e.code===`CANNOT_REMOVE_PASSWORD_WITH_SECOND_FACTOR_ONLY`){a.setError(`root`,{message:n(`profile.password.removeModal.noOAuthWith2FA`)});return}}a.setError(`root`,{message:n(`profile.password.removeModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.removeModal.description`),icon:M,isOpen:e,onClose:u,title:n(`profile.password.removeModal.title`),variant:`destructive`,children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:d,children:[(0,Z.jsx)(A,{error:a.formState.errors.currentPassword,errorTestId:`remove-password-error`,id:`current-password-remove`,label:n(`profile.password.removeModal.currentPassword`),placeholder:n(`profile.password.removeModal.currentPasswordPlaceholder`),...a.register(`currentPassword`),type:`password`}),a.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:a.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`remove-password-cancel`,disabled:l.isPending,intent:`neutral`,onClick:u,type:`button`,uiSize:`sm`,children:n(`profile.password.removeModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`remove-password-submit`,disabled:l.isPending,intent:`danger`,loading:l.isPending,loadingLabel:n(`profile.password.removeModal.submitting`),type:`submit`,uiSize:`sm`,children:l.isPending?void 0:n(`profile.password.removeModal.submit`)})]})]})})}function We({isOpen:e,onClose:t}){let{t:n}=s(),r=o(),{data:i}=f(N),a=i.auth.password.policy,c=(0,X.useMemo)(()=>q({password:J().min(a.min_length,n(`validation.password.min`,{count:a.min_length})).max(a.max_length,n(`validation.password.max`,{count:a.max_length})),confirmPassword:J()}).refine(e=>e.password===e.confirmPassword,{message:n(`validation.confirmPassword.mismatch`),path:[`confirmPassword`]}),[a.max_length,a.min_length,n]),l=W({resolver:G(c),defaultValues:{password:``,confirmPassword:``}}),u=m({...Ne,onSuccess:()=>{r.invalidateQueries({queryKey:Y.queryKey}),d()}}),d=()=>{l.reset(),t()},p=l.handleSubmit(async e=>{try{await u.mutateAsync({password:e.password})}catch{l.setError(`root`,{message:n(`profile.password.setModal.error`)})}});return(0,Z.jsx)(H,{description:n(`profile.password.setModal.description`),icon:M,isOpen:e,onClose:d,title:n(`profile.password.setModal.title`),children:(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:p,children:[(0,Z.jsx)(A,{error:l.formState.errors.password,errorTestId:`set-password-error-password`,id:`new-password`,label:n(`profile.password.setModal.newPassword`),placeholder:n(`profile.password.setModal.newPasswordPlaceholder`),...l.register(`password`),type:`password`}),(0,Z.jsx)(A,{error:l.formState.errors.confirmPassword,errorTestId:`set-password-error-confirmPassword`,id:`confirm-password`,label:n(`profile.password.setModal.confirmPassword`),placeholder:n(`profile.password.setModal.confirmPasswordPlaceholder`),...l.register(`confirmPassword`),type:`password`}),l.formState.errors.root&&(0,Z.jsx)($,{variant:`error`,children:l.formState.errors.root.message}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`set-password-cancel`,disabled:u.isPending,intent:`neutral`,onClick:d,type:`button`,uiSize:`sm`,children:n(`profile.password.setModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`set-password-submit`,disabled:u.isPending,intent:`primary`,loading:u.isPending,loadingLabel:n(`profile.password.setModal.submitting`),type:`submit`,uiSize:`sm`,children:u.isPending?void 0:n(`profile.password.setModal.submit`)})]})]})})}function Ge({isOpen:e,onClose:t,isRequired:n=!1,canSwitchToTotp:r=!1,onSwitchToTotp:i}){let{t:a}=s(),c=o(),[l,u]=(0,X.useState)(`name`),[d,f]=(0,X.useState)(null),h=(0,X.useMemo)(()=>q({name:J().max(100,a(`validation.passkey.name.max`)).optional().transform(e=>e?.trim()||void 0)}),[a]),g=W({resolver:G(h),defaultValues:{name:``}}),_=m({...fe,onSuccess:()=>{c.invalidateQueries({queryKey:P.passkeys()}),c.invalidateQueries({queryKey:Y.queryKey}),v()},onError:e=>{u(`name`),e.name===`NotAllowedError`?f(a(`profile.passkey.setupModal.cancelled`)):f(a(`profile.passkey.setupModal.error`))}}),v=(0,X.useCallback)(()=>{g.reset(),u(`name`),f(null),t()},[g,t]),y=g.handleSubmit(async e=>{u(`register`),f(null);try{await _.mutateAsync({name:e.name})}catch{}}),b=_.isPending;return(0,Z.jsxs)(H,{description:n?a(`profile.passkey.setupModal.requiredDescription`):void 0,icon:j,isOpen:e,onClose:v,preventClose:n,size:`sm`,title:a(`profile.passkey.setupModal.title`),children:[l===`name`&&(0,Z.jsxs)(K,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,onSubmit:y,children:[(0,Z.jsx)(p,{as:`p`,color:`muted`,variant:`caption`,children:a(`profile.passkey.setupModal.description`)}),d&&(0,Z.jsx)($,{variant:`error`,children:d}),(0,Z.jsx)(A,{error:g.formState.errors.name,errorTestId:`setup-passkey-error`,hint:a(`profile.passkey.setupModal.nameHint`),id:`passkey-name`,label:a(`profile.passkey.setupModal.nameLabel`),placeholder:a(`profile.passkey.setupModal.namePlaceholder`),...g.register(`name`),type:`text`}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`setup-passkey-cancel`,intent:`neutral`,onClick:v,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.cancel`)}),(0,Z.jsx)(C,{"data-testid":`setup-passkey-continue`,intent:`primary`,type:`submit`,uiSize:`sm`,children:a(`profile.passkey.setupModal.continue`)})]}),r&&i&&(0,Z.jsx)(p,{align:`center`,as:`p`,className:`mt-tinyrack-sm`,variant:`caption`,children:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:i,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.switchToTotp`)})})]}),l===`register`&&(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-tinyrack-md py-tinyrack-xl`,"data-testid":`setup-passkey-loading`,children:[(0,Z.jsx)(S,{uiSize:`md`}),(0,Z.jsx)(p,{align:`center`,as:`p`,color:`muted`,variant:`caption`,children:a(`profile.passkey.setupModal.waitingForDevice`)})]}),(0,Z.jsx)(V,{children:(0,Z.jsx)(C,{appearance:`outline`,"data-testid":`setup-passkey-cancel`,disabled:b,intent:`neutral`,onClick:v,type:`button`,uiSize:`sm`,children:a(`profile.passkey.setupModal.cancel`)})})]})]})}function Ke({isOpen:e,onClose:t,isRequired:n=!1,canSwitchToPasskey:r=!1,onSwitchToPasskey:i}){let{t:a}=s(),{step:o,setupData:c,recoveryCodes:l,isSetupPending:u,isVerifyPending:d,isConfirmPending:f,startSetup:m,verify:h,goToVerify:g,goToQr:_,confirmRecoveryCodes:v,reset:y}=k({autoStart:!1,onConfirmSuccess:()=>{y(),t()}}),b=(0,X.useCallback)(()=>{y(),t()},[t,y]),x=(0,X.useCallback)(()=>{!c&&!u&&m()},[c,u,m]);e&&!c&&!u&&o!==`error`&&x();let w=(0,X.useCallback)(async e=>{await h(e)},[h]),T=a(o===`recovery`?`setupTotp.recoveryCodes.title`:`profile.totp.setupModal.title`);return(0,Z.jsxs)(H,{description:n?a(`profile.totp.setupModal.requiredDescription`):void 0,icon:L,isOpen:e,onClose:b,preventClose:n||o===`recovery`,size:`sm`,title:T,children:[u&&(0,Z.jsx)(`div`,{className:`flex justify-center py-tinyrack-xl`,"data-testid":`setup-totp-loading`,children:(0,Z.jsx)(S,{uiSize:`md`})}),o===`error`&&(0,Z.jsxs)(`div`,{className:`mt-tinyrack-lg flex flex-col gap-tinyrack-md`,children:[(0,Z.jsx)($,{variant:`error`,children:a(`profile.totp.setupModal.setupError`)}),(0,Z.jsxs)(V,{children:[(0,Z.jsx)(C,{appearance:`outline`,intent:`neutral`,onClick:b,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.cancel`)}),(0,Z.jsx)(C,{intent:`primary`,onClick:m,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.retry`)})]})]}),c&&o===`qr`&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(ee,{additionalActions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{children:(0,Z.jsx)(C,{appearance:`outline`,intent:`neutral`,onClick:b,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.cancel`)})}),r&&i&&(0,Z.jsx)(p,{align:`center`,as:`p`,className:`mt-tinyrack-sm`,variant:`caption`,children:(0,Z.jsx)(C,{appearance:`ghost`,intent:`primary`,onClick:i,type:`button`,uiSize:`sm`,children:a(`profile.totp.setupModal.switchToPasskey`)})})]}),onNext:g,setupData:c})}),c&&o===`verify`&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(O,{isPending:d,onBack:_,onSubmit:w})}),o===`recovery`&&l.length>0&&(0,Z.jsx)(`div`,{className:`mt-tinyrack-lg`,children:(0,Z.jsx)(D,{isLoading:f,onConfirm:v,recoveryCodes:l})})]})}var qe=(e=>d({queryKey:P.oauth.accounts(),queryFn:async()=>{let t=await e.api.user[`oauth-accounts`].$get();return l(t)}}))(u),Je=g({mutationFn:async e=>{let t=await u.api.oauth[`:provider`].$delete({param:{provider:e}});return l(t)}});function Ye(e,t=`login`,n){let r=new URLSearchParams({mode:t});return n&&r.set(`return_url`,n),`/api/oauth/${encodeURIComponent(e)}/authorize?${r.toString()}`}var Xe={access_denied:`oauth.error.accessDenied`,temporarily_unavailable:`oauth.error.temporarilyUnavailable`,server_error:`oauth.error.serverError`};function Ze(e){return(0,Z.jsx)(U,{...e,onUnauthorized:()=>{he(`/login`)}})}function Qe({search:e}){let{t}=s(),n=r(),i=o(),a=e.oauth_error,c=a?t(Xe[a]??`oauth.error.failed`):void 0,[l,u]=(0,X.useState)(null),[d,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,E]=(0,X.useState)(!1),{data:D}=f(Y),{data:ee}=f(qe),{data:O}=f(N),k=m({...re,onSuccess:async()=>{i.setQueryData(Y.queryKey,{user:null}),await se(),n(`/login`)},onSettled:()=>{i.invalidateQueries({queryKey:Y.queryKey})}}),A=m({...Je,onSuccess:()=>{i.invalidateQueries({queryKey:qe.queryKey})},onSettled:()=>{u(null)}}),j=async()=>{d&&(u(d.id),await A.mutateAsync(d.id))};if(!D.user)return null;let M=D.user,P=ee.available_providers,F=P.some(e=>e.linked),I=M.managed_by===`config`,te=O.auth.password,L=O.auth.passkey,R=te.totp.enabled,z=L.enabled,ae=O.account_deletion.enabled,V=O.account_deletion.retention,H=(()=>{let e=V.match(/^(\d+)([dmy])$/);if(!e)return 30;let t=parseInt(e[1],10);switch(e[2]){case`d`:return t;case`m`:return t*30;case`y`:return t*365;default:return 30}})(),U=!I&&R,W=!I&&z,G=P.length>0;return(0,Z.jsxs)(Me,{headerActions:(0,Z.jsx)(C,{appearance:`ghost`,"aria-label":t(`profile.logout`),"data-testid":`profile-logout`,disabled:k.isPending,loading:k.isPending,onClick:()=>k.mutate(),type:`button`,uiSize:`sm`,children:k.isPending?void 0:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ne,{"aria-hidden":!0,className:`size-tinyrack-lg`}),(0,Z.jsx)(p,{as:`span`,className:`hidden sm:inline`,variant:`bodySm`,children:t(`profile.logout`)})]})}),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-tinyrack-lg`,children:[(0,Z.jsx)(oe,{email:M.email,size:`lg`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-tinyrack-3xs`,children:[(0,Z.jsx)(ie,{title:t(`profile.title`)}),(0,Z.jsx)(p,{as:`p`,color:`muted`,"data-testid":`profile-user-email`,truncate:!0,variant:`bodySm`,children:M.email})]})]}),c&&(0,Z.jsx)(B,{icon:T,type:`error`,children:c}),M&&(0,Z.jsx)(je,{user:M}),(0,Z.jsxs)(w.Root,{variant:`outlined`,children:[(0,Z.jsxs)(w.Header,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,children:[(0,Z.jsx)(w.Title,{children:t(`profile.security.title`)}),(0,Z.jsx)(w.Description,{children:t(`profile.security.description`)})]}),U&&M.totp_recovery_codes_missing&&(0,Z.jsx)(`div`,{className:`border-tinyrack-border border-b-tinyrack-default px-tinyrack-lg py-tinyrack-md`,"data-testid":`profile-totp-recovery-warning`,children:(0,Z.jsx)(B,{icon:T,type:`warning`,children:t(`profile.totp.recoveryCodesMissing`)})}),(0,Z.jsxs)(w.Content,{className:`divide-y divide-tinyrack-border p-0`,children:[(0,Z.jsx)(Ee,{hasLinkedOAuth:F,hasPassword:M.has_password,hasSecondFactorOnly:M.has_password&&!F&&(M.totp_registered||M.passkey_count>0),isConfigManaged:I,onOpenModal:_}),U&&(0,Z.jsx)(De,{onOpenModal:y,recoveryCodesMissing:M.totp_recovery_codes_missing,totpEnabled:M.totp_registered}),W&&(0,Z.jsx)(Te,{onOpenModal:x,passkeyCount:M.passkey_count})]})]}),G&&(0,Z.jsx)(we,{getAuthorizeUrl:Ye,onUnlinkRequest:e=>h({id:e.id,name:e.display_name}),providers:P,unlinkingProvider:l}),(0,Z.jsx)(Se,{isConfigManaged:I,isDeletionEnabled:ae,onDeleteClick:()=>E(!0)}),(0,Z.jsx)(We,{isOpen:g===`set`,onClose:()=>_(null)}),(0,Z.jsx)(Ie,{isOpen:g===`change`,onClose:()=>_(null)}),(0,Z.jsx)(Ue,{isOpen:g===`remove`,onClose:()=>_(null)}),(0,Z.jsx)(Ke,{isOpen:v===`setup`,onClose:()=>y(null)}),(0,Z.jsx)(ze,{isOpen:v===`disable`,onClose:()=>y(null)}),(0,Z.jsx)(He,{isOpen:v===`regenerate`,onClose:()=>y(null)}),(0,Z.jsx)(Ge,{isOpen:b===`setup`,onClose:()=>x(null)}),(0,Z.jsx)(Be,{isOpen:b===`manage`,onAddNew:()=>x(`setup`),onClose:()=>x(null)}),(0,Z.jsx)(ke,{isOpen:d!==null,isPending:A.isPending,onClose:()=>h(null),onConfirm:j,providerName:d?.name??``}),(0,Z.jsx)(Re,{isOpen:S,onClose:()=>E(!1),retentionDays:H})]})}var $e=i(function({error:e}){return(0,Z.jsx)(_e,{component:Ze,error:e})}),et=n(function({loaderData:e}){return(0,Z.jsx)(ge,{state:e.dehydratedState,children:(0,Z.jsx)(Qe,{search:e.search})})});export{$e as ErrorBoundary,et as default};