@alepha/ui 0.32.0 → 0.33.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 (186) hide show
  1. package/dist/account/AccountConnections.js +1 -1
  2. package/dist/account/AccountConnections.js.map +1 -1
  3. package/dist/account/AccountDeleteDialog.d.ts.map +1 -1
  4. package/dist/account/AccountDeleteDialog.js +17 -17
  5. package/dist/account/AccountDeleteDialog.js.map +1 -1
  6. package/dist/account/AccountKeys.js +2 -2
  7. package/dist/account/AccountKeys.js.map +1 -1
  8. package/dist/account/AccountMfaDialog.d.ts.map +1 -1
  9. package/dist/account/AccountMfaDialog.js +19 -25
  10. package/dist/account/AccountMfaDialog.js.map +1 -1
  11. package/dist/account/AccountPasswordDialog.d.ts.map +1 -1
  12. package/dist/account/AccountPasswordDialog.js +25 -24
  13. package/dist/account/AccountPasswordDialog.js.map +1 -1
  14. package/dist/account/AccountProfile.d.ts.map +1 -1
  15. package/dist/account/AccountProfile.js +17 -24
  16. package/dist/account/AccountProfile.js.map +1 -1
  17. package/dist/account/AccountSecurity.d.ts.map +1 -1
  18. package/dist/account/AccountSecurity.js +21 -19
  19. package/dist/account/AccountSecurity.js.map +1 -1
  20. package/dist/account/AccountSessions.js +1 -1
  21. package/dist/account/AccountSessions.js.map +1 -1
  22. package/dist/account/ApiKeyCreateDialog.d.ts.map +1 -1
  23. package/dist/account/ApiKeyCreateDialog.js +8 -12
  24. package/dist/account/ApiKeyCreateDialog.js.map +1 -1
  25. package/dist/admin/AdminFiles.js +1 -1
  26. package/dist/admin/AdminFiles.js.map +1 -1
  27. package/dist/admin/AdminJobs.js +1 -1
  28. package/dist/admin/AdminJobs.js.map +1 -1
  29. package/dist/admin/AdminKeys.js +1 -1
  30. package/dist/admin/AdminKeys.js.map +1 -1
  31. package/dist/admin/AdminParameters.d.ts.map +1 -1
  32. package/dist/admin/AdminParameters.js +7 -5
  33. package/dist/admin/AdminParameters.js.map +1 -1
  34. package/dist/admin/AdminParametersTreeFooterActions.d.ts +2 -2
  35. package/dist/admin/AdminParametersTreeFooterActions.d.ts.map +1 -1
  36. package/dist/admin/AdminParametersTreeFooterActions.js.map +1 -1
  37. package/dist/admin/AdminParametersTreePane.d.ts +2 -2
  38. package/dist/admin/AdminParametersTreePane.d.ts.map +1 -1
  39. package/dist/admin/AdminParametersTreePane.js.map +1 -1
  40. package/dist/admin/AdminRouter.d.ts +1 -3
  41. package/dist/admin/AdminRouter.d.ts.map +1 -1
  42. package/dist/admin/AdminRouter.js +2 -4
  43. package/dist/admin/AdminRouter.js.map +1 -1
  44. package/dist/admin/AdminSessions.js +1 -1
  45. package/dist/admin/AdminSessions.js.map +1 -1
  46. package/dist/admin/AdminUserAvatarControl.d.ts.map +1 -1
  47. package/dist/admin/AdminUserAvatarControl.js +9 -16
  48. package/dist/admin/AdminUserAvatarControl.js.map +1 -1
  49. package/dist/admin/AdminUserDetail.js +4 -4
  50. package/dist/admin/AdminUserDetail.js.map +1 -1
  51. package/dist/admin/AdminUsers.d.ts.map +1 -1
  52. package/dist/admin/AdminUsers.js +10 -12
  53. package/dist/admin/AdminUsers.js.map +1 -1
  54. package/dist/admin/AdminUsersRolesPicker.d.ts +5 -1
  55. package/dist/admin/AdminUsersRolesPicker.d.ts.map +1 -1
  56. package/dist/admin/AdminUsersRolesPicker.js +2 -3
  57. package/dist/admin/AdminUsersRolesPicker.js.map +1 -1
  58. package/dist/admin/analytics/QueryPanel.js +1 -1
  59. package/dist/admin/analytics/QueryPanel.js.map +1 -1
  60. package/dist/admin/useConfirmedAction.d.ts +8 -2
  61. package/dist/admin/useConfirmedAction.d.ts.map +1 -1
  62. package/dist/admin/useConfirmedAction.js +15 -4
  63. package/dist/admin/useConfirmedAction.js.map +1 -1
  64. package/dist/auth/AuthLogin.d.ts.map +1 -1
  65. package/dist/auth/AuthLogin.js +4 -4
  66. package/dist/auth/AuthLogin.js.map +1 -1
  67. package/dist/auth/AuthRegister.js.map +1 -1
  68. package/dist/core/index.js +1 -1
  69. package/dist/form/AutoForm.js +1 -1
  70. package/dist/form/AutoForm.js.map +1 -1
  71. package/dist/form/Control.js +1 -1
  72. package/dist/form/Control.js.map +1 -1
  73. package/dist/form/ControlArray.js +5 -5
  74. package/dist/form/ControlArray.js.map +1 -1
  75. package/dist/form/ControlSelect.js +2 -2
  76. package/dist/form/ControlSelect.js.map +1 -1
  77. package/dist/form/ControlUpload.d.ts +1 -1
  78. package/dist/form/ControlUpload.js.map +1 -1
  79. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  80. package/dist/i18n/fr/uiFr.js +0 -9
  81. package/dist/i18n/fr/uiFr.js.map +1 -1
  82. package/dist/organizations/MyOrganizationInvitations.js +2 -2
  83. package/dist/organizations/MyOrganizationInvitations.js.map +1 -1
  84. package/dist/organizations/OrganizationInviteDialog.js +1 -1
  85. package/dist/organizations/OrganizationInviteDialog.js.map +1 -1
  86. package/dist/organizations/OrganizationMembers.js +1 -1
  87. package/dist/organizations/OrganizationMembers.js.map +1 -1
  88. package/dist/organizations/OrganizationPendingInvitations.js +1 -1
  89. package/dist/organizations/OrganizationPendingInvitations.js.map +1 -1
  90. package/dist/organizations/OrganizationRanks.js +3 -3
  91. package/dist/organizations/OrganizationRanks.js.map +1 -1
  92. package/dist/organizations/useInviteOrganizationMember.d.ts +6 -1
  93. package/dist/organizations/useInviteOrganizationMember.d.ts.map +1 -1
  94. package/dist/organizations/useInviteOrganizationMember.js +13 -13
  95. package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
  96. package/dist/organizations/useRevokeOrganizationInvitation.d.ts +7 -1
  97. package/dist/organizations/useRevokeOrganizationInvitation.d.ts.map +1 -1
  98. package/dist/organizations/useRevokeOrganizationInvitation.js +13 -2
  99. package/dist/organizations/useRevokeOrganizationInvitation.js.map +1 -1
  100. package/dist/shell/ButtonUser.d.ts +1 -2
  101. package/dist/shell/ButtonUser.d.ts.map +1 -1
  102. package/dist/shell/ButtonUser.js +14 -42
  103. package/dist/shell/ButtonUser.js.map +1 -1
  104. package/dist/shell/ButtonUserContent.d.ts +13 -0
  105. package/dist/shell/ButtonUserContent.d.ts.map +1 -0
  106. package/dist/shell/ButtonUserContent.js +52 -0
  107. package/dist/shell/ButtonUserContent.js.map +1 -0
  108. package/dist/shell/ButtonUserPlaceholder.d.ts +14 -0
  109. package/dist/shell/ButtonUserPlaceholder.d.ts.map +1 -0
  110. package/dist/shell/ButtonUserPlaceholder.js +17 -0
  111. package/dist/shell/ButtonUserPlaceholder.js.map +1 -0
  112. package/dist/styles.css +31 -0
  113. package/dist/table/DataTable.js +1 -1
  114. package/dist/table/DataTable.js.map +1 -1
  115. package/dist/table/DataTableFilterBar.js +2 -2
  116. package/dist/table/DataTableFilterBar.js.map +1 -1
  117. package/dist/table/dataTableBaseProps.d.ts +1 -1
  118. package/dist/table/dataTableTypes.d.ts +3 -3
  119. package/dist/table/dataTableTypes.d.ts.map +1 -1
  120. package/dist/table/useDataTableData.d.ts.map +1 -1
  121. package/dist/table/useDataTableData.js +3 -1
  122. package/dist/table/useDataTableData.js.map +1 -1
  123. package/dist/table/useDataTableRefresh.js +2 -2
  124. package/dist/table/useDataTableRefresh.js.map +1 -1
  125. package/dist/table/useDataTableSummary.d.ts.map +1 -1
  126. package/dist/table/useDataTableSummary.js +2 -1
  127. package/dist/table/useDataTableSummary.js.map +1 -1
  128. package/package.json +6 -6
  129. package/src/account/AccountConnections.tsx +1 -1
  130. package/src/account/AccountDeleteDialog.tsx +25 -31
  131. package/src/account/AccountKeys.tsx +2 -2
  132. package/src/account/AccountMfaDialog.tsx +33 -27
  133. package/src/account/AccountPasswordDialog.tsx +36 -39
  134. package/src/account/AccountProfile.tsx +29 -43
  135. package/src/account/AccountSecurity.tsx +57 -64
  136. package/src/account/AccountSessions.tsx +1 -1
  137. package/src/account/ApiKeyCreateDialog.tsx +12 -20
  138. package/src/account/__tests__/AccountRouter.spec.ts +2 -1
  139. package/src/admin/AdminFiles.tsx +1 -1
  140. package/src/admin/AdminJobs.tsx +1 -1
  141. package/src/admin/AdminKeys.tsx +1 -1
  142. package/src/admin/AdminParameters.tsx +7 -5
  143. package/src/admin/AdminParametersTreeFooterActions.tsx +2 -2
  144. package/src/admin/AdminParametersTreePane.tsx +2 -2
  145. package/src/admin/AdminRouter.tsx +2 -4
  146. package/src/admin/AdminSessions.tsx +1 -1
  147. package/src/admin/AdminUserAvatarControl.tsx +17 -22
  148. package/src/admin/AdminUserDetail.tsx +4 -4
  149. package/src/admin/AdminUsers.tsx +10 -12
  150. package/src/admin/AdminUsersRolesPicker.tsx +11 -4
  151. package/src/admin/__tests__/AdminRouter.spec.ts +3 -2
  152. package/src/admin/analytics/QueryPanel.tsx +1 -1
  153. package/src/admin/useConfirmedAction.tsx +24 -10
  154. package/src/auth/AuthLogin.tsx +10 -9
  155. package/src/auth/AuthRegister.tsx +2 -2
  156. package/src/form/AutoForm.tsx +1 -1
  157. package/src/form/Control.tsx +1 -1
  158. package/src/form/ControlArray.tsx +5 -5
  159. package/src/form/ControlSelect.tsx +2 -2
  160. package/src/form/ControlUpload.tsx +1 -1
  161. package/src/form/__tests__/ControlArrayChildChange.browser.spec.tsx +1 -1
  162. package/src/i18n/fr/uiFr.ts +0 -9
  163. package/src/organizations/MyOrganizationInvitations.tsx +2 -2
  164. package/src/organizations/OrganizationInviteDialog.tsx +1 -1
  165. package/src/organizations/OrganizationMembers.tsx +1 -1
  166. package/src/organizations/OrganizationPendingInvitations.tsx +1 -1
  167. package/src/organizations/OrganizationRanks.tsx +3 -3
  168. package/src/organizations/useInviteOrganizationMember.ts +22 -15
  169. package/src/organizations/useRevokeOrganizationInvitation.ts +23 -4
  170. package/src/shell/ButtonUser.tsx +14 -79
  171. package/src/shell/ButtonUserContent.tsx +92 -0
  172. package/src/shell/ButtonUserPlaceholder.tsx +25 -0
  173. package/src/shell/__tests__/ActionErrorToaster.browser.spec.tsx +1 -1
  174. package/src/shell/__tests__/ActionErrorToasterHandled.browser.spec.tsx +1 -2
  175. package/src/shell/__tests__/AppShell.pageCache.spec.tsx +67 -0
  176. package/src/styles.css +31 -0
  177. package/src/table/DataTable.tsx +1 -1
  178. package/src/table/DataTableFilterBar.tsx +2 -2
  179. package/src/table/__tests__/DataTableFilterDateRange.browser.spec.tsx +1 -1
  180. package/src/table/__tests__/DataTableQuerySeed.browser.spec.tsx +1 -1
  181. package/src/table/__tests__/DataTableShareFilters.browser.spec.tsx +1 -1
  182. package/src/table/dataTableBaseProps.ts +1 -1
  183. package/src/table/dataTableTypes.ts +3 -3
  184. package/src/table/useDataTableData.ts +2 -0
  185. package/src/table/useDataTableRefresh.ts +3 -3
  186. package/src/table/useDataTableSummary.ts +2 -1
@@ -28,7 +28,7 @@ const AccountConnections = (props) => {
28
28
  const dialog = useDialog();
29
29
  const { tr } = useI18n();
30
30
  const [connections, setConnections] = useState(props.connections ?? []);
31
- const revoke = useAction({ handler: async (connection) => {
31
+ const revoke = useAction({ handler: async (_ctx, connection) => {
32
32
  if (!await dialog.confirm({
33
33
  title: tr("account.connections.revokeTitle", {
34
34
  default: "Disconnect $1?",
@@ -1 +1 @@
1
- {"version":3,"file":"AccountConnections.js","names":[],"sources":["../../src/account/AccountConnections.tsx"],"sourcesContent":["import type { MyConnection, MyConnectionController } from \"alepha/api/users\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { Plug, Unplug } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport TimeAgo from \"../core/TimeAgo.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { DataTable } from \"../table/DataTable.tsx\";\nimport { AccountPage } from \"./AccountPage.tsx\";\n\nexport interface AccountConnectionsProps {\n connections?: MyConnection[];\n}\n\n/**\n * Applications holding access to this account through OAuth (an MCP client,\n * a CLI, a third-party integration), as a `DataTable` over the list the route\n * loader fetched.\n *\n * `listMyConnections` returns the whole list unpaginated, so the table is\n * handed the array (`data`) and pages it in memory. A disconnect drops the\n * row from the array, which is the table's refresh in this mode.\n *\n * Confirmed on disconnect. A session comes back by signing in again; a\n * connection comes back only by re-running whatever authorization flow\n * created it, which for an MCP client means going to reconnect it from the\n * other side.\n */\nconst AccountConnections = (props: AccountConnectionsProps) => {\n const api = useClient<MyConnectionController>();\n const dialog = useDialog();\n const { tr } = useI18n();\n\n const [connections, setConnections] = useState<MyConnection[]>(\n props.connections ?? [],\n );\n\n const revoke = useAction<[connection: MyConnection], boolean>(\n {\n handler: async (connection) => {\n const ok = await dialog.confirm({\n title: tr(\"account.connections.revokeTitle\", {\n default: \"Disconnect $1?\",\n args: [connection.clientName],\n }),\n description: tr(\"account.connections.revokeDescription\", {\n default:\n \"It loses access immediately and has to be authorized again to come back.\",\n }),\n confirmLabel: tr(\"account.connections.revoke\", {\n default: \"Disconnect\",\n }),\n destructive: true,\n });\n if (!ok) {\n return false;\n }\n await api.revokeMyConnection({ params: { id: connection.id } });\n setConnections((prev) => prev.filter((it) => it.id !== connection.id));\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n return (\n <AccountPage variant=\"table\">\n <DataTable<MyConnection>\n className=\"min-h-0 flex-1\"\n data={connections}\n rowKey={(connection) => connection.id}\n /*\n Today's copy, kept: the page's description and what an empty list\n means. An empty page that drops the description reads as a\n different page, and the sentence is what a reader with nothing on\n screen needs.\n */\n emptyState={{\n icon: Plug,\n title: tr(\"account.connections.empty\", {\n default: \"Nothing is connected\",\n }),\n description: `${tr(\"account.connections.description\", {\n default: \"Applications that can act on your behalf.\",\n })} ${tr(\"account.connections.emptyDescription\", {\n default: \"Applications you authorize will appear here.\",\n })}`,\n }}\n columns={{\n clientName: {\n label: tr(\"account.connections.colApp\", { default: \"App\" }),\n sortable: true,\n cell: (connection) => (\n <span\n className=\"flex items-center gap-2\"\n data-testid=\"account-connection-name\"\n >\n <Plug className=\"text-muted-foreground size-4 shrink-0\" />\n <span className=\"font-medium\">{connection.clientName}</span>\n {connection.current ? (\n <Badge tone=\"success\">\n {tr(\"account.connections.current\", {\n default: \"(this one)\",\n })}\n </Badge>\n ) : null}\n </span>\n ),\n },\n /*\n ⚠️ Said out loud, not hidden. The list groups by client, so one\n row can stand for several authorizations, and a reader deciding\n whether to disconnect should know how many go with it.\n */\n sessionCount: {\n label: tr(\"account.connections.colSessions\", {\n default: \"Sessions\",\n }),\n sortable: true,\n align: \"right\",\n cell: (connection) => (\n <span className=\"text-muted-foreground text-xs tabular-nums\">\n {connection.sessionCount}\n </span>\n ),\n },\n createdAt: {\n label: tr(\"account.connections.colConnected\", {\n default: \"Connected\",\n }),\n sortable: true,\n cell: (connection) => (\n <TimeAgo\n value={connection.createdAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n lastUsedAt: {\n label: tr(\"account.connections.colLastUsed\", {\n default: \"Last used\",\n }),\n sortable: true,\n cell: (connection) =>\n connection.lastUsedAt ? (\n <TimeAgo\n value={connection.lastUsedAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.connections.never\", { default: \"Never\" })}\n </span>\n ),\n },\n expiresAt: {\n label: tr(\"account.connections.colExpires\", {\n default: \"Access ends\",\n }),\n sortable: true,\n cell: (connection) => (\n <TimeAgo\n value={connection.expiresAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n }}\n rowActions={(connection) => [\n {\n label: tr(\"account.connections.revoke\", { default: \"Disconnect\" }),\n icon: Unplug,\n destructive: true,\n disabled: () => revoke.loading,\n onClick: () => void revoke.run(connection),\n },\n ]}\n />\n </AccountPage>\n );\n};\n\nexport default AccountConnections;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,sBAAsB,UAAmC;CAC7D,MAAM,MAAM,UAAkC;CAC9C,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,aAAa,kBAAkB,SACpC,MAAM,eAAe,CAAC,CACxB;CAEA,MAAM,SAAS,UAC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;KACP,OAAO,eACL,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,WAAW;KACR,CAAA;IAEV;IACA,WAAW;KACT,OAAO,GAAG,oCAAoC,EAC5C,SAAS,YACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA;IAEL;IACA,YAAY;KACV,OAAO,GAAG,mCAAmC,EAC3C,SAAS,YACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,WAAW,aACT,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA,IAED,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,GAAG,6BAA6B,EAAE,SAAS,QAAQ,CAAC;KACjD,CAAA;IAEZ;IACA,WAAW;KACT,OAAO,GAAG,kCAAkC,EAC1C,SAAS,cACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA;IAEL;GACF;GACA,aAAa,eAAe,CAC1B;IACE,OAAO,GAAG,8BAA8B,EAAE,SAAS,aAAa,CAAC;IACjE,MAAM;IACN,aAAa;IACb,gBAAgB,OAAO;IACvB,eAAe,KAAK,OAAO,IAAI,UAAU;GAC3C,CACF;EACD,CAAA;CACU,CAAA;AAEjB"}
1
+ {"version":3,"file":"AccountConnections.js","names":[],"sources":["../../src/account/AccountConnections.tsx"],"sourcesContent":["import type { MyConnection, MyConnectionController } from \"alepha/api/users\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { Plug, Unplug } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport TimeAgo from \"../core/TimeAgo.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { DataTable } from \"../table/DataTable.tsx\";\nimport { AccountPage } from \"./AccountPage.tsx\";\n\nexport interface AccountConnectionsProps {\n connections?: MyConnection[];\n}\n\n/**\n * Applications holding access to this account through OAuth (an MCP client,\n * a CLI, a third-party integration), as a `DataTable` over the list the route\n * loader fetched.\n *\n * `listMyConnections` returns the whole list unpaginated, so the table is\n * handed the array (`data`) and pages it in memory. A disconnect drops the\n * row from the array, which is the table's refresh in this mode.\n *\n * Confirmed on disconnect. A session comes back by signing in again; a\n * connection comes back only by re-running whatever authorization flow\n * created it, which for an MCP client means going to reconnect it from the\n * other side.\n */\nconst AccountConnections = (props: AccountConnectionsProps) => {\n const api = useClient<MyConnectionController>();\n const dialog = useDialog();\n const { tr } = useI18n();\n\n const [connections, setConnections] = useState<MyConnection[]>(\n props.connections ?? [],\n );\n\n const revoke = useAction<[connection: MyConnection], boolean>(\n {\n handler: async (_ctx, connection) => {\n const ok = await dialog.confirm({\n title: tr(\"account.connections.revokeTitle\", {\n default: \"Disconnect $1?\",\n args: [connection.clientName],\n }),\n description: tr(\"account.connections.revokeDescription\", {\n default:\n \"It loses access immediately and has to be authorized again to come back.\",\n }),\n confirmLabel: tr(\"account.connections.revoke\", {\n default: \"Disconnect\",\n }),\n destructive: true,\n });\n if (!ok) {\n return false;\n }\n await api.revokeMyConnection({ params: { id: connection.id } });\n setConnections((prev) => prev.filter((it) => it.id !== connection.id));\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n return (\n <AccountPage variant=\"table\">\n <DataTable<MyConnection>\n className=\"min-h-0 flex-1\"\n data={connections}\n rowKey={(connection) => connection.id}\n /*\n Today's copy, kept: the page's description and what an empty list\n means. An empty page that drops the description reads as a\n different page, and the sentence is what a reader with nothing on\n screen needs.\n */\n emptyState={{\n icon: Plug,\n title: tr(\"account.connections.empty\", {\n default: \"Nothing is connected\",\n }),\n description: `${tr(\"account.connections.description\", {\n default: \"Applications that can act on your behalf.\",\n })} ${tr(\"account.connections.emptyDescription\", {\n default: \"Applications you authorize will appear here.\",\n })}`,\n }}\n columns={{\n clientName: {\n label: tr(\"account.connections.colApp\", { default: \"App\" }),\n sortable: true,\n cell: (connection) => (\n <span\n className=\"flex items-center gap-2\"\n data-testid=\"account-connection-name\"\n >\n <Plug className=\"text-muted-foreground size-4 shrink-0\" />\n <span className=\"font-medium\">{connection.clientName}</span>\n {connection.current ? (\n <Badge tone=\"success\">\n {tr(\"account.connections.current\", {\n default: \"(this one)\",\n })}\n </Badge>\n ) : null}\n </span>\n ),\n },\n /*\n ⚠️ Said out loud, not hidden. The list groups by client, so one\n row can stand for several authorizations, and a reader deciding\n whether to disconnect should know how many go with it.\n */\n sessionCount: {\n label: tr(\"account.connections.colSessions\", {\n default: \"Sessions\",\n }),\n sortable: true,\n align: \"right\",\n cell: (connection) => (\n <span className=\"text-muted-foreground text-xs tabular-nums\">\n {connection.sessionCount}\n </span>\n ),\n },\n createdAt: {\n label: tr(\"account.connections.colConnected\", {\n default: \"Connected\",\n }),\n sortable: true,\n cell: (connection) => (\n <TimeAgo\n value={connection.createdAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n lastUsedAt: {\n label: tr(\"account.connections.colLastUsed\", {\n default: \"Last used\",\n }),\n sortable: true,\n cell: (connection) =>\n connection.lastUsedAt ? (\n <TimeAgo\n value={connection.lastUsedAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.connections.never\", { default: \"Never\" })}\n </span>\n ),\n },\n expiresAt: {\n label: tr(\"account.connections.colExpires\", {\n default: \"Access ends\",\n }),\n sortable: true,\n cell: (connection) => (\n <TimeAgo\n value={connection.expiresAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n }}\n rowActions={(connection) => [\n {\n label: tr(\"account.connections.revoke\", { default: \"Disconnect\" }),\n icon: Unplug,\n destructive: true,\n disabled: () => revoke.loading,\n onClick: () => void revoke.run(connection),\n },\n ]}\n />\n </AccountPage>\n );\n};\n\nexport default AccountConnections;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,sBAAsB,UAAmC;CAC7D,MAAM,MAAM,UAAk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GAAG,+BAA+B,EACjC,SAAS,aACX,CAAC;OACI,CAAA,IACL;MACA;;IAEV;IAMA,cAAc;KACZ,OAAO,GAAG,mCAAmC,EAC3C,SAAS,WACX,CAAC;KACD,UAAU;KACV,OAAO;KACP,OAAO,eACL,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,WAAW;KACR,CAAA;IAEV;IACA,WAAW;KACT,OAAO,GAAG,oCAAoC,EAC5C,SAAS,YACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA;IAEL;IACA,YAAY;KACV,OAAO,GAAG,mCAAmC,EAC3C,SAAS,YACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,WAAW,aACT,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA,IAED,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,GAAG,6BAA6B,EAAE,SAAS,QAAQ,CAAC;KACjD,CAAA;IAEZ;IACA,WAAW;KACT,OAAO,GAAG,kCAAkC,EAC1C,SAAS,cACX,CAAC;KACD,UAAU;KACV,OAAO,eACL,oBAAC,SAAD;MACE,OAAO,WAAW;MAClB,WAAU;KACX,CAAA;IAEL;GACF;GACA,aAAa,eAAe,CAC1B;IACE,OAAO,GAAG,8BAA8B,EAAE,SAAS,aAAa,CAAC;IACjE,MAAM;IACN,aAAa;IACb,gBAAgB,OAAO;IACvB,eAAe,KAAK,OAAO,IAAI,UAAU;GAC3C,CACF;EACD,CAAA;CACU,CAAA;AAEjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountDeleteDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountDeleteDialog.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAe5E,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,UAAW,wBAAwB,gCAqIlE,CAAC"}
1
+ {"version":3,"file":"AccountDeleteDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountDeleteDialog.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAc5E,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,UAAW,wBAAwB,gCAgIlE,CAAC"}
@@ -1,13 +1,12 @@
1
1
  import { Button } from "../core/Button.js";
2
2
  import { Input } from "../core/Input.js";
3
- import { useToast } from "../core/useToast.js";
4
3
  import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "../core/Dialog.js";
5
4
  import { Label } from "../core/Label.js";
6
5
  import { ControlPassword } from "../form/ControlPassword.js";
7
6
  import { useI18n } from "alepha/react/i18n";
8
7
  import { useEffect, useState } from "react";
9
8
  import { jsx, jsxs } from "react/jsx-runtime";
10
- import { useClient } from "alepha/react";
9
+ import { useAction, useClient } from "alepha/react";
11
10
  //#region src/account/AccountDeleteDialog.tsx
12
11
  /**
13
12
  * Permanently delete your own account.
@@ -25,12 +24,10 @@ import { useClient } from "alepha/react";
25
24
  const AccountDeleteDialog = (props) => {
26
25
  const accountApi = useClient();
27
26
  const profileApi = useClient();
28
- const toaster = useToast();
29
27
  const { tr } = useI18n();
30
28
  const [expected, setExpected] = useState();
31
29
  const [confirm, setConfirm] = useState("");
32
30
  const [currentPassword, setCurrentPassword] = useState("");
33
- const [submitting, setSubmitting] = useState(false);
34
31
  useEffect(() => {
35
32
  if (!props.open) return;
36
33
  let cancelled = false;
@@ -48,20 +45,23 @@ const AccountDeleteDialog = (props) => {
48
45
  setCurrentPassword("");
49
46
  props.onOpenChange(false);
50
47
  };
51
- const submit = async (event) => {
48
+ const remove = useAction({ handler: async () => {
49
+ await accountApi.deleteMyAccount({ body: {
50
+ confirm,
51
+ currentPassword: props.hasPassword ? currentPassword : void 0
52
+ } });
53
+ await props.onDeleted();
54
+ } }, [
55
+ accountApi,
56
+ confirm,
57
+ currentPassword,
58
+ props.hasPassword,
59
+ props.onDeleted
60
+ ]);
61
+ const submitting = remove.loading;
62
+ const submit = (event) => {
52
63
  event.preventDefault();
53
- setSubmitting(true);
54
- try {
55
- await accountApi.deleteMyAccount({ body: {
56
- confirm,
57
- currentPassword: props.hasPassword ? currentPassword : void 0
58
- } });
59
- await props.onDeleted();
60
- } catch (error) {
61
- toaster.show(error?.message ?? tr("account.delete.error", { default: "Could not delete your account" }), "danger");
62
- } finally {
63
- setSubmitting(false);
64
- }
64
+ remove.run();
65
65
  };
66
66
  const ready = expected !== void 0 && confirm === expected;
67
67
  return /* @__PURE__ */ jsx(Dialog, {
@@ -1 +1 @@
1
- {"version":3,"file":"AccountDeleteDialog.js","names":[],"sources":["../../src/account/AccountDeleteDialog.tsx"],"sourcesContent":["import type {\n MyAccountController,\n MyProfileController,\n} from \"alepha/api/users\";\nimport { useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { type FormEvent, type ReactNode, useEffect, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { Input } from \"../core/Input.tsx\";\nimport { Label } from \"../core/Label.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { ControlPassword } from \"../form/ControlPassword.tsx\";\n\nexport interface AccountDeleteDialogProps {\n open: boolean;\n\n /**\n * Whether the account has a `credentials` identity. An OAuth-only account\n * has no password to prove knowledge of, so the field is not shown — and\n * the server agrees, accepting the confirmation phrase alone.\n */\n hasPassword: boolean;\n\n onOpenChange: (open: boolean) => void;\n\n /**\n * Application-supplied consequences, rendered above the confirmation field.\n *\n * The framework can say what deleting an *account* does; it cannot say what\n * that costs inside your data. An application whose foreign keys cascade —\n * rows the account authored inside other people's projects, say — puts the\n * count here so the person reads it *before* confirming rather than\n * discovering it afterwards.\n *\n * A `ReactNode` rather than a string because the honest version of this is\n * usually a live count, which means a component that fetches one.\n */\n warning?: ReactNode;\n\n /**\n * Called once the account is gone. The caller signs the (now orphaned)\n * session out.\n */\n onDeleted: () => void | Promise<void>;\n}\n\n/**\n * Permanently delete your own account.\n *\n * Asks for two independent things because the two failure modes are different\n * people: the password proves it is *you* (against someone at your unlocked\n * laptop), and typing the confirmation phrase proves you *meant it* (against\n * you, five seconds from now).\n *\n * The phrase is fetched rather than guessed. The server accepts the account's\n * email, falling back to username and then the literal `DELETE`, and this\n * dialog must ask for exactly what the server will accept — a hardcoded\n * \"type DELETE\" would be refused for every account that has an email.\n */\nexport const AccountDeleteDialog = (props: AccountDeleteDialogProps) => {\n const accountApi = useClient<MyAccountController>();\n const profileApi = useClient<MyProfileController>();\n const toaster = useToast();\n const { tr } = useI18n();\n\n const [expected, setExpected] = useState<string | undefined>();\n const [confirm, setConfirm] = useState(\"\");\n const [currentPassword, setCurrentPassword] = useState(\"\");\n const [submitting, setSubmitting] = useState(false);\n\n useEffect(() => {\n if (!props.open) {\n return;\n }\n let cancelled = false;\n profileApi\n .getMyProfile()\n .then((profile) => {\n if (!cancelled) {\n setExpected(profile.email ?? profile.username ?? \"DELETE\");\n }\n })\n .catch(() => {\n if (!cancelled) {\n setExpected(\"DELETE\");\n }\n });\n return () => {\n cancelled = true;\n };\n }, [props.open, profileApi]);\n\n const close = () => {\n setConfirm(\"\");\n setCurrentPassword(\"\");\n props.onOpenChange(false);\n };\n\n const submit = async (event: FormEvent) => {\n event.preventDefault();\n setSubmitting(true);\n try {\n await accountApi.deleteMyAccount({\n body: {\n confirm,\n currentPassword: props.hasPassword ? currentPassword : undefined,\n },\n });\n await props.onDeleted();\n } catch (error: any) {\n /*\n An application's `user:delete:before` hook refuses here — \"You still\n own 3 projects\" — and the framework's fast-path emit delivers that\n message unwrapped. Showing it verbatim is the entire reason the emit\n avoids `{ log: true }`; a generic \"could not delete\" would waste it.\n */\n toaster.show(\n error?.message ??\n tr(\"account.delete.error\", {\n default: \"Could not delete your account\",\n }),\n \"danger\",\n );\n } finally {\n setSubmitting(false);\n }\n };\n\n const ready = expected !== undefined && confirm === expected;\n\n return (\n <Dialog open={props.open} onOpenChange={(next) => !next && close()}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n {tr(\"account.delete.title\", { default: \"Delete your account\" })}\n </DialogTitle>\n </DialogHeader>\n <form onSubmit={submit} className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {tr(\"account.delete.description\", {\n default:\n \"This permanently removes your account, its sign-in methods and every session. It cannot be undone.\",\n })}\n </span>\n\n {props.warning}\n\n {props.hasPassword ? (\n <ControlPassword\n id=\"deleteCurrentPassword\"\n label={tr(\"account.delete.currentPassword\", {\n default: \"Current password\",\n })}\n value={currentPassword}\n onChange={setCurrentPassword}\n autoComplete=\"current-password\"\n required\n />\n ) : null}\n\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor=\"deleteConfirm\">\n {tr(\"account.delete.confirmBefore\", { default: \"Type\" })}{\" \"}\n <span className=\"font-mono\">{expected ?? \"…\"}</span>{\" \"}\n {tr(\"account.delete.confirmAfter\", { default: \"to confirm\" })}\n </Label>\n <Input\n id=\"deleteConfirm\"\n value={confirm}\n onChange={(event) => setConfirm(event.target.value)}\n autoComplete=\"off\"\n required\n />\n </div>\n\n <DialogFooter>\n <Button type=\"button\" variant=\"minimal\" onClick={close}>\n {tr(\"account.delete.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button\n type=\"submit\"\n intent=\"danger\"\n disabled={submitting || !ready}\n >\n {tr(\"account.delete.submit\", { default: \"Delete account\" })}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,uBAAuB,UAAoC;CACtE,MAAM,aAAa,UAA+B;CAClD,MAAM,aAAa,UAA+B;CAClD,MAAM,UAAU,SAAS;CACzB,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,UAAU,eAAe,SAA6B;CAC7D,MAAM,CAAC,SAAS,cAAc,SAAS,EAAE;CACzC,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,EAAE;CACzD,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAElD,gBAAgB;EACd,IAAI,CAAC,MAAM,MACT;EAEF,IAAI,YAAY;EAChB,WACG,aAAa,CAAC,CACd,MAAM,YAAY;GACjB,IAAI,CAAC,WACH,YAAY,QAAQ,SAAS,QAAQ,YAAY,QAAQ;EAE7D,CAAC,CAAC,CACD,YAAY;GACX,IAAI,CAAC,WACH,YAAY,QAAQ;EAExB,CAAC;EACH,aAAa;GACX,YAAY;EACd;CACF,GAAG,CAAC,MAAM,MAAM,UAAU,CAAC;CAE3B,MAAM,cAAc;EAClB,WAAW,EAAE;EACb,mBAAmB,EAAE;EACrB,MAAM,aAAa,KAAK;CAC1B;CAEA,MAAM,SAAS,OAAO,UAAqB;EACzC,MAAM,eAAe;EACrB,cAAc,IAAI;EAClB,IAAI;GACF,MAAM,WAAW,gBAAg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D,EAAA,UAAA,CACE,oBAAC,QAAD;KAAQ,MAAK;KAAS,SAAQ;KAAU,SAAS;KAC9C,UAAA,GAAG,yBAAyB,EAAE,SAAS,SAAS,CAAC;IAC5C,CAAA,GACR,oBAAC,QAAD;KACE,MAAK;KACL,QAAO;KACP,UAAU,cAAc,CAAC;KAExB,UAAA,GAAG,yBAAyB,EAAE,SAAS,iBAAiB,CAAC;IACpD,CAAA,CACI,EAAA,CAAA;GACV;EACO,CAAA,CAAA,EAAA,CAAA;CACT,CAAA;AAEZ"}
1
+ {"version":3,"file":"AccountDeleteDialog.js","names":[],"sources":["../../src/account/AccountDeleteDialog.tsx"],"sourcesContent":["import type {\n MyAccountController,\n MyProfileController,\n} from \"alepha/api/users\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { type FormEvent, type ReactNode, useEffect, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { Input } from \"../core/Input.tsx\";\nimport { Label } from \"../core/Label.tsx\";\nimport { ControlPassword } from \"../form/ControlPassword.tsx\";\n\nexport interface AccountDeleteDialogProps {\n open: boolean;\n\n /**\n * Whether the account has a `credentials` identity. An OAuth-only account\n * has no password to prove knowledge of, so the field is not shown — and\n * the server agrees, accepting the confirmation phrase alone.\n */\n hasPassword: boolean;\n\n onOpenChange: (open: boolean) => void;\n\n /**\n * Application-supplied consequences, rendered above the confirmation field.\n *\n * The framework can say what deleting an *account* does; it cannot say what\n * that costs inside your data. An application whose foreign keys cascade —\n * rows the account authored inside other people's projects, say — puts the\n * count here so the person reads it *before* confirming rather than\n * discovering it afterwards.\n *\n * A `ReactNode` rather than a string because the honest version of this is\n * usually a live count, which means a component that fetches one.\n */\n warning?: ReactNode;\n\n /**\n * Called once the account is gone. The caller signs the (now orphaned)\n * session out.\n */\n onDeleted: () => void | Promise<void>;\n}\n\n/**\n * Permanently delete your own account.\n *\n * Asks for two independent things because the two failure modes are different\n * people: the password proves it is *you* (against someone at your unlocked\n * laptop), and typing the confirmation phrase proves you *meant it* (against\n * you, five seconds from now).\n *\n * The phrase is fetched rather than guessed. The server accepts the account's\n * email, falling back to username and then the literal `DELETE`, and this\n * dialog must ask for exactly what the server will accept — a hardcoded\n * \"type DELETE\" would be refused for every account that has an email.\n */\nexport const AccountDeleteDialog = (props: AccountDeleteDialogProps) => {\n const accountApi = useClient<MyAccountController>();\n const profileApi = useClient<MyProfileController>();\n const { tr } = useI18n();\n\n const [expected, setExpected] = useState<string | undefined>();\n const [confirm, setConfirm] = useState(\"\");\n const [currentPassword, setCurrentPassword] = useState(\"\");\n\n useEffect(() => {\n if (!props.open) {\n return;\n }\n let cancelled = false;\n profileApi\n .getMyProfile()\n .then((profile) => {\n if (!cancelled) {\n setExpected(profile.email ?? profile.username ?? \"DELETE\");\n }\n })\n .catch(() => {\n if (!cancelled) {\n setExpected(\"DELETE\");\n }\n });\n return () => {\n cancelled = true;\n };\n }, [props.open, profileApi]);\n\n const close = () => {\n setConfirm(\"\");\n setCurrentPassword(\"\");\n props.onOpenChange(false);\n };\n\n /*\n An application's `user:delete:before` hook refuses here (\"You still own 3\n projects\") and the framework's fast-path emit delivers that message\n unwrapped. The app's ActionErrorToaster shows it verbatim, which is the\n entire reason the emit avoids `{ log: true }`.\n */\n const remove = useAction<[]>(\n {\n handler: async () => {\n await accountApi.deleteMyAccount({\n body: {\n confirm,\n currentPassword: props.hasPassword ? currentPassword : undefined,\n },\n });\n await props.onDeleted();\n },\n },\n [accountApi, confirm, currentPassword, props.hasPassword, props.onDeleted],\n );\n const submitting = remove.loading;\n\n const submit = (event: FormEvent) => {\n event.preventDefault();\n void remove.run();\n };\n\n const ready = expected !== undefined && confirm === expected;\n\n return (\n <Dialog open={props.open} onOpenChange={(next) => !next && close()}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n {tr(\"account.delete.title\", { default: \"Delete your account\" })}\n </DialogTitle>\n </DialogHeader>\n <form onSubmit={submit} className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {tr(\"account.delete.description\", {\n default:\n \"This permanently removes your account, its sign-in methods and every session. It cannot be undone.\",\n })}\n </span>\n\n {props.warning}\n\n {props.hasPassword ? (\n <ControlPassword\n id=\"deleteCurrentPassword\"\n label={tr(\"account.delete.currentPassword\", {\n default: \"Current password\",\n })}\n value={currentPassword}\n onChange={setCurrentPassword}\n autoComplete=\"current-password\"\n required\n />\n ) : null}\n\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor=\"deleteConfirm\">\n {tr(\"account.delete.confirmBefore\", { default: \"Type\" })}{\" \"}\n <span className=\"font-mono\">{expected ?? \"…\"}</span>{\" \"}\n {tr(\"account.delete.confirmAfter\", { default: \"to confirm\" })}\n </Label>\n <Input\n id=\"deleteConfirm\"\n value={confirm}\n onChange={(event) => setConfirm(event.target.value)}\n autoComplete=\"off\"\n required\n />\n </div>\n\n <DialogFooter>\n <Button type=\"button\" variant=\"minimal\" onClick={close}>\n {tr(\"account.delete.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button\n type=\"submit\"\n intent=\"danger\"\n disabled={submitting || !ready}\n >\n {tr(\"account.delete.submit\", { default: \"Delete account\" })}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,uBAAuB,UAAoC;CACtE,MAAM,aAAa,UAA+B;CAClD,MAAM,aAAa,UAA+B;CAClD,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,UAAU,eAAe,SAA6B;CAC7D,MAAM,CAAC,SAAS,cAAc,SAAS,EAAE;CACzC,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,EAAE;CAEzD,gBAAgB;EACd,IAAI,CAAC,MAAM,MACT;EAEF,IAAI,YAAY;EAChB,WACG,aAAa,CAAC,CACd,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,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,qBAAC,OAAD;MAAO,SAAQ;MAAf,UAAA;OACG,GAAG,gCAAgC,EAAE,SAAS,OAAO,CAAC;OAAG;OAC1D,oBAAC,QAAD;QAAM,WAAU;QAAa,UAAA,YAAY;OAAU,CAAA;OAAE;OACpD,GAAG,+BAA+B,EAAE,SAAS,aAAa,CAAC;MACvD;KACP,CAAA,GAAA,oBAAC,OAAD;MACE,IAAG;MACH,OAAO;MACP,WAAW,UAAU,WAAW,MAAM,OAAO,KAAK;MAClD,cAAa;MACb,UAAA;KACD,CAAA,CACE;;IAEL,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,QAAD;KAAQ,MAAK;KAAS,SAAQ;KAAU,SAAS;KAC9C,UAAA,GAAG,yBAAyB,EAAE,SAAS,SAAS,CAAC;IAC5C,CAAA,GACR,oBAAC,QAAD;KACE,MAAK;KACL,QAAO;KACP,UAAU,cAAc,CAAC;KAExB,UAAA,GAAG,yBAAyB,EAAE,SAAS,iBAAiB,CAAC;IACpD,CAAA,CACI,EAAA,CAAA;GACV;EACO,CAAA,CAAA,EAAA,CAAA;CACT,CAAA;AAEZ"}
@@ -70,7 +70,7 @@ const AccountKeys = (props) => {
70
70
  const reload = async () => {
71
71
  setKeys(await api.listApiKeys());
72
72
  };
73
- const rotate = useAction({ handler: async (key) => {
73
+ const rotate = useAction({ handler: async (_ctx, key) => {
74
74
  if (!await dialog.confirm({
75
75
  title: tr("account.keys.rotateTitle", {
76
76
  default: "Rotate $1?",
@@ -91,7 +91,7 @@ const AccountKeys = (props) => {
91
91
  dialog,
92
92
  tr
93
93
  ]);
94
- const revoke = useAction({ handler: async (key) => {
94
+ const revoke = useAction({ handler: async (_ctx, key) => {
95
95
  if (!await dialog.confirm({
96
96
  title: tr("account.keys.revokeTitle", {
97
97
  default: "Revoke $1?",
@@ -1 +1 @@
1
- {"version":3,"file":"AccountKeys.js","names":[],"sources":["../../src/account/AccountKeys.tsx"],"sourcesContent":["import { z } from \"alepha\";\nimport type {\n ApiKeyController,\n ApiKeyStatus,\n ListApiKeyItem,\n} from \"alepha/api/keys\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport {\n Check,\n CircleDot,\n Clipboard,\n KeyRound,\n Plus,\n RefreshCw,\n Trash2,\n} from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport TimeAgo from \"../core/TimeAgo.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { DataTable } from \"../table/DataTable.tsx\";\nimport type { DataTableFilterFields } from \"../table/dataTableTypes.ts\";\nimport { AccountPage } from \"./AccountPage.tsx\";\nimport { ApiKeyCreateDialog } from \"./ApiKeyCreateDialog.tsx\";\nimport { ApiKeyScopeSummary } from \"./ApiKeyScopeSummary.tsx\";\nimport { ApiKeyStatusBadge } from \"./ApiKeyStatusBadge.tsx\";\n\nexport interface AccountKeysProps {\n /**\n * The rows `GET /api-keys` returns, live and dead: the framework's own\n * response type, so a field added to the endpoint is available here the\n * day it lands.\n */\n apiKeys?: ListApiKeyItem[];\n}\n\n/**\n * The key statuses the filter offers, in order. A local list checked against\n * `ApiKeyStatus` rather than the schema, for the bundle reason `AdminKeys`\n * gives.\n */\nconst API_KEY_STATUSES = [\n \"active\",\n \"expiring\",\n \"expired\",\n \"revoked\",\n] as const satisfies readonly ApiKeyStatus[];\n\n/**\n * Your own API keys: mint, rotate, revoke, and see where each is in its life,\n * as a `DataTable` over the list the route loader fetched.\n *\n * `listApiKeys` returns the whole list unpaginated, so the table is handed\n * the array (`data`) and pages, sorts and filters it in memory. A write\n * re-reads the list, because a revoked key stays listed with its status.\n *\n * The status filter starts on the live keys (active and expiring). Expired\n * and revoked keys are one filter change away: listed because a key that\n * stopped working is the one a user comes looking for, filtered out by\n * default because a table that reads \"14 keys\" when 11 are dead misleads.\n *\n * The freshly created or rotated token is shown **once**, in a dialog that\n * stays open until dismissed, because the server stores only a hash and\n * cannot show it again. That is also why minting and the reveal are separate\n * steps: a token that scrolls out of view behind a re-render is gone.\n */\nconst AccountKeys = (props: AccountKeysProps) => {\n const api = useClient<ApiKeyController>();\n const dialog = useDialog();\n const { tr } = useI18n();\n\n const [keys, setKeys] = useState<ListApiKeyItem[]>(props.apiKeys ?? []);\n const [createOpen, setCreateOpen] = useState(false);\n const [freshToken, setFreshToken] = useState<string | undefined>();\n const [copied, setCopied] = useState(false);\n\n const statusLabel = (status: ApiKeyStatus): string => {\n switch (status) {\n case \"active\":\n return tr(\"account.keys.status.active\", { default: \"Active\" });\n case \"expiring\":\n return tr(\"account.keys.status.expiringLabel\", { default: \"Expiring\" });\n case \"expired\":\n return tr(\"account.keys.status.expired\", { default: \"Expired\" });\n case \"revoked\":\n return tr(\"account.keys.status.revoked\", { default: \"Revoked\" });\n }\n };\n\n const filterFields = {\n status: {\n schema: z.array(z.enum(API_KEY_STATUSES)),\n mode: \"default\",\n label: tr(\"account.keys.colStatus\", { default: \"Status\" }),\n icon: CircleDot,\n optionLabel: statusLabel,\n control: {\n clearLabel: tr(\"account.keys.statusAll\", { default: \"All statuses\" }),\n },\n },\n } satisfies DataTableFilterFields;\n\n const reload = async () => {\n setKeys((await api.listApiKeys()) as ListApiKeyItem[]);\n };\n\n const rotate = useAction<[key: ListApiKeyItem], boolean>(\n {\n handler: async (key) => {\n const ok = await dialog.confirm({\n title: tr(\"account.keys.rotateTitle\", {\n default: \"Rotate $1?\",\n args: [key.name],\n }),\n description: tr(\"account.keys.rotateDescription\", {\n default:\n \"The current secret stops working immediately, and a new one is shown once. Update wherever the key is stored.\",\n }),\n confirmLabel: tr(\"account.keys.rotate\", { default: \"Rotate\" }),\n });\n if (!ok) {\n return false;\n }\n const rotated: any = await api.rotateMyApiKey({\n params: { id: key.id },\n body: {},\n });\n setFreshToken(rotated.token);\n await reload();\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n const revoke = useAction<[key: ListApiKeyItem], boolean>(\n {\n handler: async (key) => {\n const ok = await dialog.confirm({\n title: tr(\"account.keys.revokeTitle\", {\n default: \"Revoke $1?\",\n args: [key.name],\n }),\n description: tr(\"account.keys.revokeDescription\", {\n default:\n \"Anything still using this key stops working immediately. This cannot be undone.\",\n }),\n confirmLabel: tr(\"account.keys.revoke\", { default: \"Revoke\" }),\n destructive: true,\n });\n if (!ok) {\n return false;\n }\n await api.revokeMyApiKey({ params: { id: key.id } });\n // Re-read rather than drop the row: a revoked key stays listed, with\n // its status, until the retention window purges it.\n await reload();\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n const busy = rotate.loading || revoke.loading;\n\n const empty = {\n icon: KeyRound,\n title: tr(\"account.keys.title\", { default: \"API keys\" }),\n description: tr(\"account.keys.description\", {\n default: \"Keys act as you. Revoke any you no longer recognise.\",\n }),\n };\n\n const copy = async () => {\n if (!freshToken) {\n return;\n }\n await navigator.clipboard.writeText(freshToken);\n setCopied(true);\n };\n\n return (\n <AccountPage variant=\"table\">\n <DataTable<ListApiKeyItem, typeof filterFields>\n className=\"min-h-0 flex-1\"\n data={keys}\n rowKey={(key) => key.id}\n filter={(key, filters) =>\n !filters.status?.length || filters.status.includes(key.status)\n }\n filters={{\n fields: filterFields,\n // The live keys first; dead ones are one filter change away.\n initialValues: { status: [\"active\", \"expiring\"] },\n }}\n actions={[\n {\n icon: Plus,\n label: tr(\"account.keys.new\", { default: \"New key\" }),\n primary: true,\n disabled: busy,\n onClick: () => setCreateOpen(true),\n },\n ]}\n emptyState={empty}\n // The status filter is always set (live keys by default), so with no\n // key at all the table would read \"no match, adjust the filters\".\n // Nothing is being filtered out then, so say what is true instead.\n noMatchState={keys.length === 0 ? empty : undefined}\n columns={{\n name: {\n label: tr(\"account.keys.colName\", { default: \"Name\" }),\n sortable: true,\n cell: (key) => (\n <div className=\"flex min-w-0 flex-col\">\n <span className=\"font-medium\" data-testid=\"account-key-name\">\n {key.name}\n </span>\n {key.description ? (\n <span className=\"text-muted-foreground truncate text-xs\">\n {key.description}\n </span>\n ) : null}\n </div>\n ),\n },\n token: {\n label: tr(\"account.keys.colToken\", { default: \"Token\" }),\n cell: (key) => (\n <code className=\"text-xs\">\n {key.tokenPrefix}…{key.tokenSuffix}\n </code>\n ),\n },\n permissions: {\n label: tr(\"account.keys.colScope\", { default: \"Scope\" }),\n cell: (key) => <ApiKeyScopeSummary permissions={key.permissions} />,\n },\n status: {\n label: tr(\"account.keys.colStatus\", { default: \"Status\" }),\n // The Expires column beside it carries the date.\n cell: (key) => <ApiKeyStatusBadge apiKey={key} labelOnly />,\n },\n createdAt: {\n label: tr(\"account.keys.colCreated\", { default: \"Created\" }),\n sortable: true,\n cell: (key) => (\n <TimeAgo\n value={key.createdAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n lastUsedAt: {\n label: tr(\"account.keys.colLastUsed\", { default: \"Last used\" }),\n sortable: true,\n cell: (key) =>\n key.lastUsedAt ? (\n <TimeAgo\n value={key.lastUsedAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.never\", { default: \"Never\" })}\n </span>\n ),\n },\n expiresAt: {\n label: tr(\"account.keys.colExpires\", { default: \"Expires\" }),\n sortable: true,\n cell: (key) =>\n key.expiresAt ? (\n <TimeAgo\n value={key.expiresAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.never\", { default: \"Never\" })}\n </span>\n ),\n },\n /*\n Read-only, set when the key was created through the API: shown so\n a key refusing requests from a new address can be diagnosed here.\n */\n ipAllowlist: {\n label: tr(\"account.keys.colIpAllowlist\", {\n default: \"Allowed from\",\n }),\n defaultHidden: true,\n cell: (key) =>\n key.ipAllowlist.length ? (\n <code className=\"text-xs\">{key.ipAllowlist.join(\", \")}</code>\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.ipAnywhere\", { default: \"Anywhere\" })}\n </span>\n ),\n },\n }}\n /*\n Rotate on a live or an expired key (rotating an expired key is how\n it is renewed), revoke on a live key only, nothing on a revoked\n one: it keeps its row, with its status and usage.\n */\n rowActions={(key) => [\n ...(key.status === \"revoked\"\n ? []\n : [\n {\n label: tr(\"account.keys.rotate\", { default: \"Rotate\" }),\n icon: RefreshCw,\n disabled: () => busy,\n onClick: () => void rotate.run(key),\n },\n ]),\n ...(key.status === \"revoked\" || key.status === \"expired\"\n ? []\n : [\n {\n label: tr(\"account.keys.revoke\", { default: \"Revoke\" }),\n icon: Trash2,\n destructive: true,\n disabled: () => busy,\n onClick: () => void revoke.run(key),\n },\n ]),\n ]}\n />\n\n <ApiKeyCreateDialog\n open={createOpen}\n onOpenChange={setCreateOpen}\n existingKeys={keys}\n onCreated={async (token) => {\n setFreshToken(token);\n await reload();\n }}\n />\n\n {/* Deliberately not auto-dismissed: this is the only time the token\n exists in a readable form. */}\n <Dialog\n open={Boolean(freshToken)}\n onOpenChange={(next) => {\n if (!next) {\n setFreshToken(undefined);\n setCopied(false);\n }\n }}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n {tr(\"account.keys.revealTitle\", { default: \"Copy your key now\" })}\n </DialogTitle>\n </DialogHeader>\n <div className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {tr(\"account.keys.revealDescription\", {\n default:\n \"This is the only time it is shown. Store it somewhere safe before closing this dialog.\",\n })}\n </span>\n <code className=\"bg-muted rounded-md border p-3 font-mono text-xs break-all\">\n {freshToken}\n </code>\n <DialogFooter>\n <Button variant=\"solid\" intent=\"none\" onClick={copy}>\n {copied ? (\n <Check className=\"size-4\" />\n ) : (\n <Clipboard className=\"size-4\" />\n )}\n {copied\n ? tr(\"account.keys.copied\", { default: \"Copied\" })\n : tr(\"account.keys.copy\", { default: \"Copy\" })}\n </Button>\n <Button\n onClick={() => {\n setFreshToken(undefined);\n setCopied(false);\n }}\n >\n {tr(\"account.keys.done\", { default: \"Done\" })}\n </Button>\n </DialogFooter>\n </div>\n </DialogContent>\n </Dialog>\n </AccountPage>\n );\n};\n\nexport default AccountKeys;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,eAAe,UAA4B;CAC/C,MAAM,MAAM,UAA4B;CACxC,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,MAAM,WAAW,SAA2B,MAAM,WAAW,CAAC,CAAC;CACtE,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,YAAY,iBAAiB,SAA6B;CACjE,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;CAE1C,MAAM,eAAe,WAAiC;EACpD,QAAQ,QAAR;GACE,KAAK,UACH,OAAO,GAAG,8BAA8B,EAAE,SAAS,SAAS,CAAC;GAC/D,KAAK,YACH,OAAO,GAAG,qCAAqC,EAAE,SAAS,WAAW,CAAC;GACxE,KAAK,WACH,OAAO,GAAG,+BAA+B,EAAE,SAAS,UAAU,CAAC;GACjE,KAAK,WACH,OAAO,GAAG,+BAA+B,EAAE,SAAS,UAAU,CAAC;EACnE;CACF;CAEA,MAAM,eAAe,EACnB,QAAQ;EACN,QAAQ,EAAE,MAAM,EAAE,KAAK,gBAAgB,CAAC;EACxC,MAAM;EACN,OAAO,GAAG,0BAA0B,EAAE,SAAS,SAAS,CAAC;EACzD,MAAM;EACN,aAAa;EACb,SAAS,EACP,YAAY,GAAG,0BAA0B,EAAE,SAAS,eAAe,CAAC,EACtE;CACF,EACF;CAEA,MAAM,SAAS,YAAY;EACzB,QAAS,MAAM,IAAI,YAAY,CAAsB;CACvD;CAEA,MAAM,SAAS,UACb,EACE,SAAS,OAAO,QAAQ;EAYtB,IAAI,CAAC,MAXY,OAAO,QAA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IACN,cAAc;IACd,cAAc;IACd,WAAW,OAAO,UAAU;KAC1B,cAAc,KAAK;KACnB,MAAM,OAAO;IACf;GACD,CAAA;GAID,oBAAC,QAAD;IACE,MAAM,QAAQ,UAAU;IACxB,eAAe,SAAS;KACtB,IAAI,CAAC,MAAM;MACT,cAAc,KAAA,CAAS;MACvB,UAAU,KAAK;KACjB;IACF;IAEA,UAAA,qBAAC,eAAD,EAAA,UAAA,CACE,oBAAC,cAAD,EAAA,UACE,oBAAC,aAAD,EAAA,UACG,GAAG,4BAA4B,EAAE,SAAS,oBAAoB,CAAC,EACrD,CAAA,EACD,CAAA,GACd,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA;MACE,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA,GAAG,kCAAkC,EACpC,SACE,yFACJ,CAAC;MACG,CAAA;MACN,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;MACN,qBAAC,cAAD,EAAA,UAAA,CACE,qBAAC,QAAD;OAAQ,SAAQ;OAAQ,QAAO;OAAO,SAAS;OAA/C,UAAA,CACG,SACC,oBAAC,OAAD,EAAO,WAAU,SAAU,CAAA,IAE3B,oBAAC,WAAD,EAAW,WAAU,SAAU,CAAA,GAEhC,SACG,GAAG,uBAAuB,EAAE,SAAS,SAAS,CAAC,IAC/C,GAAG,qBAAqB,EAAE,SAAS,OAAO,CAAC,CACzC;MACR,CAAA,GAAA,oBAAC,QAAD;OACE,eAAe;QACb,cAAc,KAAA,CAAS;QACvB,UAAU,KAAK;OACjB;OAEC,UAAA,GAAG,qBAAqB,EAAE,SAAS,OAAO,CAAC;MACtC,CAAA,CACI,EAAA,CAAA;KACX;IACQ,CAAA,CAAA,EAAA,CAAA;GACT,CAAA;EACG;;AAEjB"}
1
+ {"version":3,"file":"AccountKeys.js","names":[],"sources":["../../src/account/AccountKeys.tsx"],"sourcesContent":["import { z } from \"alepha\";\nimport type {\n ApiKeyController,\n ApiKeyStatus,\n ListApiKeyItem,\n} from \"alepha/api/keys\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport {\n Check,\n CircleDot,\n Clipboard,\n KeyRound,\n Plus,\n RefreshCw,\n Trash2,\n} from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport TimeAgo from \"../core/TimeAgo.tsx\";\nimport { useDialog } from \"../core/useDialog.tsx\";\nimport { DataTable } from \"../table/DataTable.tsx\";\nimport type { DataTableFilterFields } from \"../table/dataTableTypes.ts\";\nimport { AccountPage } from \"./AccountPage.tsx\";\nimport { ApiKeyCreateDialog } from \"./ApiKeyCreateDialog.tsx\";\nimport { ApiKeyScopeSummary } from \"./ApiKeyScopeSummary.tsx\";\nimport { ApiKeyStatusBadge } from \"./ApiKeyStatusBadge.tsx\";\n\nexport interface AccountKeysProps {\n /**\n * The rows `GET /api-keys` returns, live and dead: the framework's own\n * response type, so a field added to the endpoint is available here the\n * day it lands.\n */\n apiKeys?: ListApiKeyItem[];\n}\n\n/**\n * The key statuses the filter offers, in order. A local list checked against\n * `ApiKeyStatus` rather than the schema, for the bundle reason `AdminKeys`\n * gives.\n */\nconst API_KEY_STATUSES = [\n \"active\",\n \"expiring\",\n \"expired\",\n \"revoked\",\n] as const satisfies readonly ApiKeyStatus[];\n\n/**\n * Your own API keys: mint, rotate, revoke, and see where each is in its life,\n * as a `DataTable` over the list the route loader fetched.\n *\n * `listApiKeys` returns the whole list unpaginated, so the table is handed\n * the array (`data`) and pages, sorts and filters it in memory. A write\n * re-reads the list, because a revoked key stays listed with its status.\n *\n * The status filter starts on the live keys (active and expiring). Expired\n * and revoked keys are one filter change away: listed because a key that\n * stopped working is the one a user comes looking for, filtered out by\n * default because a table that reads \"14 keys\" when 11 are dead misleads.\n *\n * The freshly created or rotated token is shown **once**, in a dialog that\n * stays open until dismissed, because the server stores only a hash and\n * cannot show it again. That is also why minting and the reveal are separate\n * steps: a token that scrolls out of view behind a re-render is gone.\n */\nconst AccountKeys = (props: AccountKeysProps) => {\n const api = useClient<ApiKeyController>();\n const dialog = useDialog();\n const { tr } = useI18n();\n\n const [keys, setKeys] = useState<ListApiKeyItem[]>(props.apiKeys ?? []);\n const [createOpen, setCreateOpen] = useState(false);\n const [freshToken, setFreshToken] = useState<string | undefined>();\n const [copied, setCopied] = useState(false);\n\n const statusLabel = (status: ApiKeyStatus): string => {\n switch (status) {\n case \"active\":\n return tr(\"account.keys.status.active\", { default: \"Active\" });\n case \"expiring\":\n return tr(\"account.keys.status.expiringLabel\", { default: \"Expiring\" });\n case \"expired\":\n return tr(\"account.keys.status.expired\", { default: \"Expired\" });\n case \"revoked\":\n return tr(\"account.keys.status.revoked\", { default: \"Revoked\" });\n }\n };\n\n const filterFields = {\n status: {\n schema: z.array(z.enum(API_KEY_STATUSES)),\n mode: \"default\",\n label: tr(\"account.keys.colStatus\", { default: \"Status\" }),\n icon: CircleDot,\n optionLabel: statusLabel,\n control: {\n clearLabel: tr(\"account.keys.statusAll\", { default: \"All statuses\" }),\n },\n },\n } satisfies DataTableFilterFields;\n\n const reload = async () => {\n setKeys((await api.listApiKeys()) as ListApiKeyItem[]);\n };\n\n const rotate = useAction<[key: ListApiKeyItem], boolean>(\n {\n handler: async (_ctx, key) => {\n const ok = await dialog.confirm({\n title: tr(\"account.keys.rotateTitle\", {\n default: \"Rotate $1?\",\n args: [key.name],\n }),\n description: tr(\"account.keys.rotateDescription\", {\n default:\n \"The current secret stops working immediately, and a new one is shown once. Update wherever the key is stored.\",\n }),\n confirmLabel: tr(\"account.keys.rotate\", { default: \"Rotate\" }),\n });\n if (!ok) {\n return false;\n }\n const rotated: any = await api.rotateMyApiKey({\n params: { id: key.id },\n body: {},\n });\n setFreshToken(rotated.token);\n await reload();\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n const revoke = useAction<[key: ListApiKeyItem], boolean>(\n {\n handler: async (_ctx, key) => {\n const ok = await dialog.confirm({\n title: tr(\"account.keys.revokeTitle\", {\n default: \"Revoke $1?\",\n args: [key.name],\n }),\n description: tr(\"account.keys.revokeDescription\", {\n default:\n \"Anything still using this key stops working immediately. This cannot be undone.\",\n }),\n confirmLabel: tr(\"account.keys.revoke\", { default: \"Revoke\" }),\n destructive: true,\n });\n if (!ok) {\n return false;\n }\n await api.revokeMyApiKey({ params: { id: key.id } });\n // Re-read rather than drop the row: a revoked key stays listed, with\n // its status, until the retention window purges it.\n await reload();\n return true;\n },\n },\n [api, dialog, tr],\n );\n\n const busy = rotate.loading || revoke.loading;\n\n const empty = {\n icon: KeyRound,\n title: tr(\"account.keys.title\", { default: \"API keys\" }),\n description: tr(\"account.keys.description\", {\n default: \"Keys act as you. Revoke any you no longer recognise.\",\n }),\n };\n\n const copy = async () => {\n if (!freshToken) {\n return;\n }\n await navigator.clipboard.writeText(freshToken);\n setCopied(true);\n };\n\n return (\n <AccountPage variant=\"table\">\n <DataTable<ListApiKeyItem, typeof filterFields>\n className=\"min-h-0 flex-1\"\n data={keys}\n rowKey={(key) => key.id}\n filter={(key, filters) =>\n !filters.status?.length || filters.status.includes(key.status)\n }\n filters={{\n fields: filterFields,\n // The live keys first; dead ones are one filter change away.\n initialValues: { status: [\"active\", \"expiring\"] },\n }}\n actions={[\n {\n icon: Plus,\n label: tr(\"account.keys.new\", { default: \"New key\" }),\n primary: true,\n disabled: busy,\n onClick: () => setCreateOpen(true),\n },\n ]}\n emptyState={empty}\n // The status filter is always set (live keys by default), so with no\n // key at all the table would read \"no match, adjust the filters\".\n // Nothing is being filtered out then, so say what is true instead.\n noMatchState={keys.length === 0 ? empty : undefined}\n columns={{\n name: {\n label: tr(\"account.keys.colName\", { default: \"Name\" }),\n sortable: true,\n cell: (key) => (\n <div className=\"flex min-w-0 flex-col\">\n <span className=\"font-medium\" data-testid=\"account-key-name\">\n {key.name}\n </span>\n {key.description ? (\n <span className=\"text-muted-foreground truncate text-xs\">\n {key.description}\n </span>\n ) : null}\n </div>\n ),\n },\n token: {\n label: tr(\"account.keys.colToken\", { default: \"Token\" }),\n cell: (key) => (\n <code className=\"text-xs\">\n {key.tokenPrefix}…{key.tokenSuffix}\n </code>\n ),\n },\n permissions: {\n label: tr(\"account.keys.colScope\", { default: \"Scope\" }),\n cell: (key) => <ApiKeyScopeSummary permissions={key.permissions} />,\n },\n status: {\n label: tr(\"account.keys.colStatus\", { default: \"Status\" }),\n // The Expires column beside it carries the date.\n cell: (key) => <ApiKeyStatusBadge apiKey={key} labelOnly />,\n },\n createdAt: {\n label: tr(\"account.keys.colCreated\", { default: \"Created\" }),\n sortable: true,\n cell: (key) => (\n <TimeAgo\n value={key.createdAt}\n className=\"text-muted-foreground text-xs\"\n />\n ),\n },\n lastUsedAt: {\n label: tr(\"account.keys.colLastUsed\", { default: \"Last used\" }),\n sortable: true,\n cell: (key) =>\n key.lastUsedAt ? (\n <TimeAgo\n value={key.lastUsedAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.never\", { default: \"Never\" })}\n </span>\n ),\n },\n expiresAt: {\n label: tr(\"account.keys.colExpires\", { default: \"Expires\" }),\n sortable: true,\n cell: (key) =>\n key.expiresAt ? (\n <TimeAgo\n value={key.expiresAt}\n className=\"text-muted-foreground text-xs\"\n />\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.never\", { default: \"Never\" })}\n </span>\n ),\n },\n /*\n Read-only, set when the key was created through the API: shown so\n a key refusing requests from a new address can be diagnosed here.\n */\n ipAllowlist: {\n label: tr(\"account.keys.colIpAllowlist\", {\n default: \"Allowed from\",\n }),\n defaultHidden: true,\n cell: (key) =>\n key.ipAllowlist.length ? (\n <code className=\"text-xs\">{key.ipAllowlist.join(\", \")}</code>\n ) : (\n <span className=\"text-muted-foreground text-xs\">\n {tr(\"account.keys.ipAnywhere\", { default: \"Anywhere\" })}\n </span>\n ),\n },\n }}\n /*\n Rotate on a live or an expired key (rotating an expired key is how\n it is renewed), revoke on a live key only, nothing on a revoked\n one: it keeps its row, with its status and usage.\n */\n rowActions={(key) => [\n ...(key.status === \"revoked\"\n ? []\n : [\n {\n label: tr(\"account.keys.rotate\", { default: \"Rotate\" }),\n icon: RefreshCw,\n disabled: () => busy,\n onClick: () => void rotate.run(key),\n },\n ]),\n ...(key.status === \"revoked\" || key.status === \"expired\"\n ? []\n : [\n {\n label: tr(\"account.keys.revoke\", { default: \"Revoke\" }),\n icon: Trash2,\n destructive: true,\n disabled: () => busy,\n onClick: () => void revoke.run(key),\n },\n ]),\n ]}\n />\n\n <ApiKeyCreateDialog\n open={createOpen}\n onOpenChange={setCreateOpen}\n existingKeys={keys}\n onCreated={async (token) => {\n setFreshToken(token);\n await reload();\n }}\n />\n\n {/* Deliberately not auto-dismissed: this is the only time the token\n exists in a readable form. */}\n <Dialog\n open={Boolean(freshToken)}\n onOpenChange={(next) => {\n if (!next) {\n setFreshToken(undefined);\n setCopied(false);\n }\n }}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n {tr(\"account.keys.revealTitle\", { default: \"Copy your key now\" })}\n </DialogTitle>\n </DialogHeader>\n <div className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {tr(\"account.keys.revealDescription\", {\n default:\n \"This is the only time it is shown. Store it somewhere safe before closing this dialog.\",\n })}\n </span>\n <code className=\"bg-muted rounded-md border p-3 font-mono text-xs break-all\">\n {freshToken}\n </code>\n <DialogFooter>\n <Button variant=\"solid\" intent=\"none\" onClick={copy}>\n {copied ? (\n <Check className=\"size-4\" />\n ) : (\n <Clipboard className=\"size-4\" />\n )}\n {copied\n ? tr(\"account.keys.copied\", { default: \"Copied\" })\n : tr(\"account.keys.copy\", { default: \"Copy\" })}\n </Button>\n <Button\n onClick={() => {\n setFreshToken(undefined);\n setCopied(false);\n }}\n >\n {tr(\"account.keys.done\", { default: \"Done\" })}\n </Button>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B,cAAc,KAAK;KACnB,MAAM,OAAO;IACf;GACD,CAAA;GAID,oBAAC,QAAD;IACE,MAAM,QAAQ,UAAU;IACxB,eAAe,SAAS;KACtB,IAAI,CAAC,MAAM;MACT,cAAc,KAAA,CAAS;MACvB,UAAU,KAAK;KACjB;IACF;IAEA,UAAA,qBAAC,eAAD,EAAA,UAAA,CACE,oBAAC,cAAD,EAAA,UACE,oBAAC,aAAD,EAAA,UACG,GAAG,4BAA4B,EAAE,SAAS,oBAAoB,CAAC,EACrD,CAAA,EACD,CAAA,GACd,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA;MACE,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA,GAAG,kCAAkC,EACpC,SACE,yFACJ,CAAC;MACG,CAAA;MACN,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;MACN,qBAAC,cAAD,EAAA,UAAA,CACE,qBAAC,QAAD;OAAQ,SAAQ;OAAQ,QAAO;OAAO,SAAS;OAA/C,UAAA,CACG,SACC,oBAAC,OAAD,EAAO,WAAU,SAAU,CAAA,IAE3B,oBAAC,WAAD,EAAW,WAAU,SAAU,CAAA,GAEhC,SACG,GAAG,uBAAuB,EAAE,SAAS,SAAS,CAAC,IAC/C,GAAG,qBAAqB,EAAE,SAAS,OAAO,CAAC,CACzC;MACR,CAAA,GAAA,oBAAC,QAAD;OACE,eAAe;QACb,cAAc,KAAA,CAAS;QACvB,UAAU,KAAK;OACjB;OAEC,UAAA,GAAG,qBAAqB,EAAE,SAAS,OAAO,CAAC;MACtC,CAAA,CACI,EAAA,CAAA;KACX;IACQ,CAAA,CAAA,EAAA,CAAA;GACT,CAAA;EACG;;AAEjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountMfaDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountMfaDialog.tsx"],"names":[],"mappings":"AA4BA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gCAmK5D,CAAC"}
1
+ {"version":3,"file":"AccountMfaDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountMfaDialog.tsx"],"names":[],"mappings":"AA2BA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gCA0K5D,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { Button } from "../core/Button.js";
2
- import { useToast } from "../core/useToast.js";
3
2
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../core/Dialog.js";
4
3
  import { Alert, AlertDescription } from "../core/Alert.js";
5
4
  import { InputOTP, InputOTPGroup, InputOTPSlot } from "../otp/InputOTP.js";
@@ -8,7 +7,7 @@ import { useI18n } from "alepha/react/i18n";
8
7
  import { AlertTriangle } from "lucide-react";
9
8
  import { useState } from "react";
10
9
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
- import { useClient, useQuery } from "alepha/react";
10
+ import { useAction, useClient, useQuery } from "alepha/react";
12
11
  //#region src/account/AccountMfaDialog.tsx
13
12
  /**
14
13
  * Enroll an authenticator app: scan, confirm, then write down the recovery
@@ -22,17 +21,17 @@ import { useClient, useQuery } from "alepha/react";
22
21
  */
23
22
  const AccountMfaDialog = (props) => {
24
23
  const api = useClient();
25
- const toaster = useToast();
26
24
  const { tr } = useI18n();
27
25
  const [code, setCode] = useState("");
28
26
  const [recoveryCodes, setRecoveryCodes] = useState();
29
- const [submitting, setSubmitting] = useState(false);
30
27
  /**
31
28
  * A fresh enrollment is started each time the dialog opens, and the
32
29
  * previous pending one is replaced server-side. `enabled` keys it to
33
- * `props.open` so nothing is issued for a dialog nobody asked for.
30
+ * `props.open` so nothing is issued for a dialog nobody asked for. The
31
+ * previous opening's QR is not shown while the new one loads: it names a
32
+ * secret the server has replaced.
34
33
  */
35
- const { data: enrollment, error } = useQuery({
34
+ const { data: enrollment, error, loading: enrolling } = useQuery({
36
35
  enabled: props.open,
37
36
  handler: () => api.enrollTotp()
38
37
  }, [props.open]);
@@ -47,27 +46,22 @@ const AccountMfaDialog = (props) => {
47
46
  }
48
47
  props.onOpenChange(open);
49
48
  };
50
- const activate = async (value) => {
51
- setSubmitting(true);
52
- try {
53
- const result = await api.activateTotp({ body: { code: value } });
54
- setRecoveryCodes(result.recoveryCodes);
55
- await props.onDone?.();
56
- } catch (error) {
57
- setCode("");
58
- toaster.show(error?.message ?? tr("account.mfa.invalidCode", { default: "That code is not valid" }), "danger");
59
- } finally {
60
- setSubmitting(false);
61
- }
49
+ const activate = useAction({ handler: async (_ctx, value) => {
50
+ const result = await api.activateTotp({ body: { code: value } });
51
+ setRecoveryCodes(result.recoveryCodes);
52
+ await props.onDone?.();
53
+ } }, [api, props.onDone]);
54
+ const submit = async (value) => {
55
+ if (!(await activate.run(value)).ok) setCode("");
62
56
  };
63
57
  return /* @__PURE__ */ jsx(Dialog, {
64
58
  open: props.open,
65
59
  onOpenChange: (open) => {
66
- if (!open && recoveryCodes) return;
60
+ if (!open && (recoveryCodes || activate.loading)) return;
67
61
  setOpen(open);
68
62
  },
69
63
  children: /* @__PURE__ */ jsxs(DialogContent, {
70
- showCloseButton: !recoveryCodes,
64
+ showCloseButton: !recoveryCodes && !activate.loading,
71
65
  children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: recoveryCodes ? tr("account.mfa.recoveryTitle", { default: "Save your recovery codes" }) : tr("account.mfa.setupTitle", { default: "Set up two-factor authentication" }) }) }), recoveryCodes ? /* @__PURE__ */ jsx(AccountRecoveryCodes, {
72
66
  codes: recoveryCodes,
73
67
  onSaved: () => setOpen(false)
@@ -82,7 +76,7 @@ const AccountMfaDialog = (props) => {
82
76
  variant: "destructive",
83
77
  children: [/* @__PURE__ */ jsx(AlertTriangle, { className: "size-4" }), /* @__PURE__ */ jsx(AlertDescription, { children: tr("account.mfa.enrollError", { default: "Could not start the enrollment. Close this and try again." }) })]
84
78
  }),
85
- enrollment ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
79
+ enrollment && !enrolling ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
86
80
  /* @__PURE__ */ jsx("div", {
87
81
  className: "mx-auto w-48 rounded-lg bg-white p-3 [&>svg]:w-full",
88
82
  dangerouslySetInnerHTML: { __html: enrollment.qrSvg }
@@ -99,10 +93,10 @@ const AccountMfaDialog = (props) => {
99
93
  children: /* @__PURE__ */ jsx(InputOTP, {
100
94
  maxLength: 6,
101
95
  value: code,
102
- disabled: submitting,
96
+ disabled: activate.loading,
103
97
  onChange: (value) => {
104
98
  setCode(value);
105
- if (value.length === 6) activate(value);
99
+ if (value.length === 6) submit(value);
106
100
  },
107
101
  children: /* @__PURE__ */ jsx(InputOTPGroup, { children: [
108
102
  0,
@@ -115,9 +109,9 @@ const AccountMfaDialog = (props) => {
115
109
  })
116
110
  }),
117
111
  /* @__PURE__ */ jsx(Button, {
118
- loading: submitting,
112
+ loading: activate.loading,
119
113
  disabled: code.length !== 6,
120
- onClick: () => activate(code),
114
+ onClick: () => submit(code),
121
115
  children: tr("account.mfa.turnOn", { default: "Turn on" })
122
116
  })
123
117
  ] }) : /* @__PURE__ */ jsx("p", {
@@ -1 +1 @@
1
- {"version":3,"file":"AccountMfaDialog.js","names":[],"sources":["../../src/account/AccountMfaDialog.tsx"],"sourcesContent":["import type { MyMfaController } from \"alepha/api/users\";\nimport { useClient, useQuery } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { AlertTriangle } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Alert, AlertDescription } from \"../core/Alert.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { InputOTP, InputOTPGroup, InputOTPSlot } from \"../otp/InputOTP.tsx\";\nimport { AccountRecoveryCodes } from \"./AccountRecoveryCodes.tsx\";\n\n/**\n * What `enrollTotp` hands back: the secret in clear, the `otpauth://` URI,\n * and that URI already rendered as an SVG QR code.\n */\ninterface TotpEnrollment {\n secret: string;\n uri: string;\n qrSvg: string;\n}\n\nexport interface AccountMfaDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /**\n * Called after enrollment completes, so the caller can refresh its status.\n */\n onDone?: () => void | Promise<void>;\n}\n\n/**\n * Enroll an authenticator app: scan, confirm, then write down the recovery\n * codes.\n *\n * The recovery-code step is not a formality and is deliberately hard to\n * skip past. The secret is stored encrypted and the codes hashed, so this\n * dialog is the only moment either can ever be displayed; a user who closes\n * it without keeping the codes has no way back in if they lose the phone,\n * short of an administrator resetting the factor for them.\n */\nexport const AccountMfaDialog = (props: AccountMfaDialogProps) => {\n const api = useClient<MyMfaController>();\n const toaster = useToast();\n const { tr } = useI18n();\n\n const [code, setCode] = useState(\"\");\n const [recoveryCodes, setRecoveryCodes] = useState<string[]>();\n const [submitting, setSubmitting] = useState(false);\n\n /**\n * A fresh enrollment is started each time the dialog opens, and the\n * previous pending one is replaced server-side. `enabled` keys it to\n * `props.open` so nothing is issued for a dialog nobody asked for.\n */\n const { data: enrollment, error } = useQuery<TotpEnrollment>(\n {\n enabled: props.open,\n handler: () => api.enrollTotp() as Promise<TotpEnrollment>,\n },\n [props.open],\n );\n\n /**\n * Closing resets the transient state, so reopening does not flash the\n * previous run's recovery codes at whoever is next at the keyboard.\n */\n const setOpen = (open: boolean) => {\n if (!open) {\n setCode(\"\");\n setRecoveryCodes(undefined);\n }\n props.onOpenChange(open);\n };\n\n const activate = async (value: string) => {\n setSubmitting(true);\n try {\n const result = await api.activateTotp({ body: { code: value } });\n setRecoveryCodes(result.recoveryCodes);\n await props.onDone?.();\n } catch (error: any) {\n setCode(\"\");\n toaster.show(\n error?.message ??\n tr(\"account.mfa.invalidCode\", { default: \"That code is not valid\" }),\n \"danger\",\n );\n } finally {\n setSubmitting(false);\n }\n };\n\n return (\n // While the codes are on screen the dialog closes only through \"I have\n // saved them\" (#Q2518): no close button, and Escape or a backdrop click\n // is ignored. Every close path used to clear the codes, which can never\n // be shown again.\n <Dialog\n open={props.open}\n onOpenChange={(open) => {\n if (!open && recoveryCodes) {\n return;\n }\n setOpen(open);\n }}\n >\n <DialogContent showCloseButton={!recoveryCodes}>\n <DialogHeader>\n <DialogTitle>\n {recoveryCodes\n ? tr(\"account.mfa.recoveryTitle\", {\n default: \"Save your recovery codes\",\n })\n : tr(\"account.mfa.setupTitle\", {\n default: \"Set up two-factor authentication\",\n })}\n </DialogTitle>\n </DialogHeader>\n\n {recoveryCodes ? (\n <AccountRecoveryCodes\n codes={recoveryCodes}\n onSaved={() => setOpen(false)}\n />\n ) : (\n <div className=\"flex flex-col gap-4\">\n <p className=\"text-muted-foreground text-sm\">\n {tr(\"account.mfa.setupDescription\", {\n default:\n \"Scan this with your authenticator app, then type the six-digit code it shows.\",\n })}\n </p>\n\n {error && (\n <Alert variant=\"destructive\">\n <AlertTriangle className=\"size-4\" />\n <AlertDescription>\n {tr(\"account.mfa.enrollError\", {\n default:\n \"Could not start the enrollment. Close this and try again.\",\n })}\n </AlertDescription>\n </Alert>\n )}\n\n {enrollment ? (\n <>\n <div\n className=\"mx-auto w-48 rounded-lg bg-white p-3 [&>svg]:w-full\"\n // The QR is generated server-side, from a URI the server\n // built itself. No user input reaches it.\n dangerouslySetInnerHTML={{ __html: enrollment.qrSvg }}\n />\n\n <details className=\"text-muted-foreground text-center text-xs\">\n <summary>\n {tr(\"account.mfa.cannotScan\", {\n default: \"Cannot scan the code?\",\n })}\n </summary>\n <p className=\"mt-2 font-mono break-all\">\n {enrollment.secret}\n </p>\n </details>\n\n <div className=\"flex justify-center\">\n <InputOTP\n maxLength={6}\n value={code}\n disabled={submitting}\n onChange={(value: string) => {\n setCode(value);\n if (value.length === 6) {\n void activate(value);\n }\n }}\n >\n <InputOTPGroup>\n {[0, 1, 2, 3, 4, 5].map((index) => (\n <InputOTPSlot key={index} index={index} />\n ))}\n </InputOTPGroup>\n </InputOTP>\n </div>\n\n <Button\n loading={submitting}\n disabled={code.length !== 6}\n onClick={() => activate(code)}\n >\n {tr(\"account.mfa.turnOn\", { default: \"Turn on\" })}\n </Button>\n </>\n ) : (\n <p className=\"text-muted-foreground text-center text-sm\">\n {tr(\"account.mfa.preparing\", { default: \"Preparing...\" })}\n </p>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,oBAAoB,UAAiC;CAChE,MAAM,MAAM,UAA2B;CACvC,MAAM,UAAU,SAAS;CACzB,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,MAAM,WAAW,SAAS,EAAE;CACnC,MAAM,CAAC,eAAe,oBAAoB,SAAmB;CAC7D,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;;;;;;CAOlD,MAAM,EAAE,MAAM,YAAY,UAAU,SAClC;EACE,SAAS,MAAM;EACf,eAAe,IAAI,WAAW;CAChC,GACA,CAAC,MAAM,IAAI,CACb;;;;;CAMA,MAAM,WAAW,SAAkB;EACjC,IAAI,CAAC,MAAM;GACT,QAAQ,EAAE;GACV,iBAAiB,KAAA,CAAS;EAC5B;EACA,MAAM,aAAa,IAAI;CACzB;CAEA,MAAM,WAAW,OAAO,UAAkB;EACxC,cAAc,IAAI;EAClB,IAAI;GACF,MAAM,SAAS,MAAM,IAA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,KAAD;QAAG,WAAU;QACV,UAAA,WAAW;OACX,CAAA,CACI;;MAET,oBAAC,OAAD;OAAK,WAAU;OACb,UAAA,oBAAC,UAAD;QACE,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW,UAAkB;SAC3B,QAAQ,KAAK;SACb,IAAI,MAAM,WAAW,GACnB,SAAc,KAAK;QAEvB;QAEA,UAAA,oBAAC,eAAD,EAAA,UACG;SAAC;SAAG;SAAG;SAAG;SAAG;SAAG;QAAC,CAAC,CAAC,KAAK,UACvB,oBAAC,cAAD,EAAiC,MAAQ,GAAtB,KAAsB,CAC1C,EACY,CAAA;OACP,CAAA;MACP,CAAA;MAEL,oBAAC,QAAD;OACE,SAAS;OACT,UAAU,KAAK,WAAW;OAC1B,eAAe,SAAS,IAAI;OAE3B,UAAA,GAAG,sBAAsB,EAAE,SAAS,UAAU,CAAC;MAC1C,CAAA;KACR,EAAA,CAAA,IAEF,oBAAC,KAAD;MAAG,WAAU;MACV,UAAA,GAAG,yBAAyB,EAAE,SAAS,eAAe,CAAC;KACvD,CAAA;IAEF;GAEM,CAAA,CAAA;;CACT,CAAA;AAEZ"}
1
+ {"version":3,"file":"AccountMfaDialog.js","names":[],"sources":["../../src/account/AccountMfaDialog.tsx"],"sourcesContent":["import type { MyMfaController } from \"alepha/api/users\";\nimport { useAction, useClient, useQuery } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { AlertTriangle } from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Alert, AlertDescription } from \"../core/Alert.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { InputOTP, InputOTPGroup, InputOTPSlot } from \"../otp/InputOTP.tsx\";\nimport { AccountRecoveryCodes } from \"./AccountRecoveryCodes.tsx\";\n\n/**\n * What `enrollTotp` hands back: the secret in clear, the `otpauth://` URI,\n * and that URI already rendered as an SVG QR code.\n */\ninterface TotpEnrollment {\n secret: string;\n uri: string;\n qrSvg: string;\n}\n\nexport interface AccountMfaDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /**\n * Called after enrollment completes, so the caller can refresh its status.\n */\n onDone?: () => void | Promise<void>;\n}\n\n/**\n * Enroll an authenticator app: scan, confirm, then write down the recovery\n * codes.\n *\n * The recovery-code step is not a formality and is deliberately hard to\n * skip past. The secret is stored encrypted and the codes hashed, so this\n * dialog is the only moment either can ever be displayed; a user who closes\n * it without keeping the codes has no way back in if they lose the phone,\n * short of an administrator resetting the factor for them.\n */\nexport const AccountMfaDialog = (props: AccountMfaDialogProps) => {\n const api = useClient<MyMfaController>();\n const { tr } = useI18n();\n\n const [code, setCode] = useState(\"\");\n const [recoveryCodes, setRecoveryCodes] = useState<string[]>();\n\n /**\n * A fresh enrollment is started each time the dialog opens, and the\n * previous pending one is replaced server-side. `enabled` keys it to\n * `props.open` so nothing is issued for a dialog nobody asked for. The\n * previous opening's QR is not shown while the new one loads: it names a\n * secret the server has replaced.\n */\n const {\n data: enrollment,\n error,\n loading: enrolling,\n } = useQuery<TotpEnrollment>(\n {\n enabled: props.open,\n handler: () => api.enrollTotp() as Promise<TotpEnrollment>,\n },\n [props.open],\n );\n\n /**\n * Closing resets the transient state, so reopening does not flash the\n * previous run's recovery codes at whoever is next at the keyboard.\n */\n const setOpen = (open: boolean) => {\n if (!open) {\n setCode(\"\");\n setRecoveryCodes(undefined);\n }\n props.onOpenChange(open);\n };\n\n // A refused code is toasted by the app's ActionErrorToaster, like any\n // other failed action; the field is cleared for the next attempt.\n const activate = useAction<[code: string]>(\n {\n handler: async (_ctx, value) => {\n const result = await api.activateTotp({ body: { code: value } });\n setRecoveryCodes(result.recoveryCodes);\n await props.onDone?.();\n },\n },\n [api, props.onDone],\n );\n\n const submit = async (value: string) => {\n if (!(await activate.run(value)).ok) {\n setCode(\"\");\n }\n };\n\n return (\n // While the codes are on screen the dialog closes only through \"I have\n // saved them\" (#Q2518): no close button, and Escape or a backdrop click\n // is ignored. Every close path used to clear the codes, which can never\n // be shown again.\n <Dialog\n open={props.open}\n onOpenChange={(open) => {\n // Not while activating either: the codes it is about to return\n // could never be shown again.\n if (!open && (recoveryCodes || activate.loading)) {\n return;\n }\n setOpen(open);\n }}\n >\n <DialogContent showCloseButton={!recoveryCodes && !activate.loading}>\n <DialogHeader>\n <DialogTitle>\n {recoveryCodes\n ? tr(\"account.mfa.recoveryTitle\", {\n default: \"Save your recovery codes\",\n })\n : tr(\"account.mfa.setupTitle\", {\n default: \"Set up two-factor authentication\",\n })}\n </DialogTitle>\n </DialogHeader>\n\n {recoveryCodes ? (\n <AccountRecoveryCodes\n codes={recoveryCodes}\n onSaved={() => setOpen(false)}\n />\n ) : (\n <div className=\"flex flex-col gap-4\">\n <p className=\"text-muted-foreground text-sm\">\n {tr(\"account.mfa.setupDescription\", {\n default:\n \"Scan this with your authenticator app, then type the six-digit code it shows.\",\n })}\n </p>\n\n {error && (\n <Alert variant=\"destructive\">\n <AlertTriangle className=\"size-4\" />\n <AlertDescription>\n {tr(\"account.mfa.enrollError\", {\n default:\n \"Could not start the enrollment. Close this and try again.\",\n })}\n </AlertDescription>\n </Alert>\n )}\n\n {enrollment && !enrolling ? (\n <>\n <div\n className=\"mx-auto w-48 rounded-lg bg-white p-3 [&>svg]:w-full\"\n // The QR is generated server-side, from a URI the server\n // built itself. No user input reaches it.\n dangerouslySetInnerHTML={{ __html: enrollment.qrSvg }}\n />\n\n <details className=\"text-muted-foreground text-center text-xs\">\n <summary>\n {tr(\"account.mfa.cannotScan\", {\n default: \"Cannot scan the code?\",\n })}\n </summary>\n <p className=\"mt-2 font-mono break-all\">\n {enrollment.secret}\n </p>\n </details>\n\n <div className=\"flex justify-center\">\n <InputOTP\n maxLength={6}\n value={code}\n disabled={activate.loading}\n onChange={(value: string) => {\n setCode(value);\n if (value.length === 6) {\n void submit(value);\n }\n }}\n >\n <InputOTPGroup>\n {[0, 1, 2, 3, 4, 5].map((index) => (\n <InputOTPSlot key={index} index={index} />\n ))}\n </InputOTPGroup>\n </InputOTP>\n </div>\n\n <Button\n loading={activate.loading}\n disabled={code.length !== 6}\n onClick={() => submit(code)}\n >\n {tr(\"account.mfa.turnOn\", { default: \"Turn on\" })}\n </Button>\n </>\n ) : (\n <p className=\"text-muted-foreground text-center text-sm\">\n {tr(\"account.mfa.preparing\", { default: \"Preparing...\" })}\n </p>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,oBAAoB,UAAiC;CAChE,MAAM,MAAM,UAA2B;CACvC,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,MAAM,WAAW,SAAS,EAAE;CACnC,MAAM,CAAC,eAAe,oBAAoB,SAAmB;;;;;;;;CAS7D,MAAM,EACJ,MAAM,YACN,OACA,SAAS,cACP,SACF;EACE,SAAS,MAAM;EACf,eAAe,IAAI,WAAW;CAChC,GACA,CAAC,MAAM,IAAI,CACb;;;;;CAMA,MAAM,WAAW,SAAkB;EACjC,IAAI,CAAC,MAAM;GACT,QAAQ,EAAE;GACV,iBAAiB,KAAA,CAAS;EAC5B;EACA,MAAM,aAAa,IAAI;CACzB;CAIA,MAAM,WAAW,UACf,EACE,SAAS,OAAO,MAAM,UAAU;EAC9B,MAAM,SAAS,MAAM,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,CAAC;EAC/D,iBAAiB,OAAO,aAAa;EACrC,MAAM,MAAM,SAAS;CACvB,EACF,GACA,CAAC,KAAK,MAAM,MAAM,CACpB;CAEA,MAAM,SAAS,OAAO,UAAkB;EACtC,IAAI,EAAE,MAAM,SAAS,IAAI,KAAK,EAAA,CAAG,IAC/B,QAAQ,EAAE;CAEd;CAEA,OAKE,oBAAC,QAAD;EACE,MAAM,MAAM;EACZ,eAAe,SAAS;GAGtB,IAAI,CAAC,SAAS,iBAAiB,SAAS,UACtC;GAEF,QAAQ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K,UACvB,oBAAC,cAAD,EAAiC,MAAQ,GAAtB,KAAsB,CAC1C,EACY,CAAA;OACP,CAAA;MACP,CAAA;MAEL,oBAAC,QAAD;OACE,SAAS,SAAS;OAClB,UAAU,KAAK,WAAW;OAC1B,eAAe,OAAO,IAAI;OAEzB,UAAA,GAAG,sBAAsB,EAAE,SAAS,UAAU,CAAC;MAC1C,CAAA;KACR,EAAA,CAAA,IAEF,oBAAC,KAAD;MAAG,WAAU;MACV,UAAA,GAAG,yBAAyB,EAAE,SAAS,eAAe,CAAC;KACvD,CAAA;IAEF;GAEM,CAAA,CAAA;;CACT,CAAA;AAEZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountPasswordDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountPasswordDialog.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,OAAO,CAAC;IAEd;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,UAAW,0BAA0B,gCAmItE,CAAC"}
1
+ {"version":3,"file":"AccountPasswordDialog.d.ts","sourceRoot":"","sources":["../../src/account/AccountPasswordDialog.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,OAAO,CAAC;IAEd;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,UAAW,0BAA0B,gCAgItE,CAAC"}
@@ -5,7 +5,7 @@ import { ControlPassword } from "../form/ControlPassword.js";
5
5
  import { useI18n } from "alepha/react/i18n";
6
6
  import { useState } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
- import { useClient } from "alepha/react";
8
+ import { useAction, useClient } from "alepha/react";
9
9
  //#region src/account/AccountPasswordDialog.tsx
10
10
  /**
11
11
  * Set a first password, or change an existing one.
@@ -30,41 +30,42 @@ const AccountPasswordDialog = (props) => {
30
30
  const [currentPassword, setCurrentPassword] = useState("");
31
31
  const [password, setPassword] = useState("");
32
32
  const [confirmPassword, setConfirmPassword] = useState("");
33
- const [submitting, setSubmitting] = useState(false);
34
33
  const close = () => {
35
34
  setCurrentPassword("");
36
35
  setPassword("");
37
36
  setConfirmPassword("");
38
37
  props.onOpenChange(false);
39
38
  };
39
+ const save = useAction({ handler: async () => {
40
+ if (props.hasPassword) {
41
+ const { otherSessionsRevoked } = await passwordApi.changeMyPassword({ body: {
42
+ currentPassword,
43
+ newPassword: password
44
+ } });
45
+ toaster.show(otherSessionsRevoked > 0 ? tr("account.password.changedWithSessions", {
46
+ default: "Password changed - $1 other session(s) signed out",
47
+ args: [String(otherSessionsRevoked)]
48
+ }) : tr("account.password.changed", { default: "Password changed" }), "success");
49
+ } else {
50
+ await identityApi.setMyFirstPassword({ body: { password } });
51
+ toaster.show(tr("account.password.set", { default: "Password set" }), "success");
52
+ }
53
+ await props.onDone?.();
54
+ close();
55
+ } }, [
56
+ currentPassword,
57
+ password,
58
+ props.hasPassword,
59
+ props.onDone
60
+ ]);
61
+ const submitting = save.loading;
40
62
  const submit = async (event) => {
41
63
  event.preventDefault();
42
64
  if (password !== confirmPassword) {
43
65
  toaster.show(tr("account.password.mismatch", { default: "The two passwords do not match" }), "danger");
44
66
  return;
45
67
  }
46
- setSubmitting(true);
47
- try {
48
- if (props.hasPassword) {
49
- const { otherSessionsRevoked } = await passwordApi.changeMyPassword({ body: {
50
- currentPassword,
51
- newPassword: password
52
- } });
53
- toaster.show(otherSessionsRevoked > 0 ? tr("account.password.changedWithSessions", {
54
- default: "Password changed - $1 other session(s) signed out",
55
- args: [String(otherSessionsRevoked)]
56
- }) : tr("account.password.changed", { default: "Password changed" }), "success");
57
- } else {
58
- await identityApi.setMyFirstPassword({ body: { password } });
59
- toaster.show(tr("account.password.set", { default: "Password set" }), "success");
60
- }
61
- await props.onDone?.();
62
- close();
63
- } catch (error) {
64
- toaster.show(error?.message ?? tr("account.password.error", { default: "Could not save that password" }), "danger");
65
- } finally {
66
- setSubmitting(false);
67
- }
68
+ save.run();
68
69
  };
69
70
  const title = props.hasPassword ? tr("account.password.change", { default: "Change password" }) : tr("account.password.setTitle", { default: "Set a password" });
70
71
  return /* @__PURE__ */ jsx(Dialog, {
@@ -1 +1 @@
1
- {"version":3,"file":"AccountPasswordDialog.js","names":[],"sources":["../../src/account/AccountPasswordDialog.tsx"],"sourcesContent":["import type {\n MyIdentityController,\n MyPasswordController,\n} from \"alepha/api/users\";\nimport { useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { type FormEvent, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { ControlPassword } from \"../form/ControlPassword.tsx\";\n\nexport interface AccountPasswordDialogProps {\n open: boolean;\n\n /**\n * Whether the account already has a `credentials` identity. Decides both\n * the copy and — critically — which endpoint is called.\n */\n hasPassword: boolean;\n\n onOpenChange: (open: boolean) => void;\n\n /**\n * Called after a successful change so the caller can refresh its identity\n * list — setting a first password creates one.\n */\n onDone?: () => void | Promise<void>;\n}\n\n/**\n * Set a first password, or change an existing one.\n *\n * ⚠️ **These are two different endpoints and must stay so.**\n * `setMyFirstPassword` takes only the new password and trusts the session,\n * which is defensible when there is nothing to prove knowledge of. Reusing it\n * to *change* a password would make any unattended signed-in browser a full\n * account takeover.\n *\n * `changeMyPassword` verifies the current password and revokes every other\n * session — the usual reason to change a password is believing someone else\n * has it, and leaving their session alive would accomplish nothing. It\n * reports how many it ended, which is why the toast can say so rather than\n * leave the person wondering about their phone.\n */\nexport const AccountPasswordDialog = (props: AccountPasswordDialogProps) => {\n const passwordApi = useClient<MyPasswordController>();\n const identityApi = useClient<MyIdentityController>();\n const toaster = useToast();\n const { tr } = useI18n();\n\n const [currentPassword, setCurrentPassword] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n const [confirmPassword, setConfirmPassword] = useState(\"\");\n const [submitting, setSubmitting] = useState(false);\n\n const close = () => {\n setCurrentPassword(\"\");\n setPassword(\"\");\n setConfirmPassword(\"\");\n props.onOpenChange(false);\n };\n\n const submit = async (event: FormEvent) => {\n event.preventDefault();\n if (password !== confirmPassword) {\n toaster.show(\n tr(\"account.password.mismatch\", {\n default: \"The two passwords do not match\",\n }),\n \"danger\",\n );\n return;\n }\n setSubmitting(true);\n try {\n if (props.hasPassword) {\n const { otherSessionsRevoked } = await passwordApi.changeMyPassword({\n body: { currentPassword, newPassword: password },\n });\n toaster.show(\n otherSessionsRevoked > 0\n ? tr(\"account.password.changedWithSessions\", {\n default: \"Password changed - $1 other session(s) signed out\",\n args: [String(otherSessionsRevoked)],\n })\n : tr(\"account.password.changed\", { default: \"Password changed\" }),\n \"success\",\n );\n } else {\n await identityApi.setMyFirstPassword({ body: { password } });\n toaster.show(\n tr(\"account.password.set\", { default: \"Password set\" }),\n \"success\",\n );\n }\n await props.onDone?.();\n close();\n } catch (error: any) {\n // The realm's password policy and the wrong-current-password refusal\n // both arrive here with messages worth showing verbatim.\n toaster.show(\n error?.message ??\n tr(\"account.password.error\", {\n default: \"Could not save that password\",\n }),\n \"danger\",\n );\n } finally {\n setSubmitting(false);\n }\n };\n\n const title = props.hasPassword\n ? tr(\"account.password.change\", { default: \"Change password\" })\n : tr(\"account.password.setTitle\", { default: \"Set a password\" });\n\n return (\n <Dialog open={props.open} onOpenChange={(next) => !next && close()}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n </DialogHeader>\n <form onSubmit={submit} className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {props.hasPassword\n ? tr(\"account.password.changeDescription\", {\n default: \"Every other device will be signed out.\",\n })\n : tr(\"account.password.setDescription\", {\n default:\n \"You will be able to sign in with your password as well as your existing method.\",\n })}\n </span>\n {props.hasPassword ? (\n <ControlPassword\n id=\"currentPassword\"\n label={tr(\"account.password.current\", {\n default: \"Current password\",\n })}\n value={currentPassword}\n onChange={setCurrentPassword}\n autoComplete=\"current-password\"\n required\n />\n ) : null}\n <ControlPassword\n id=\"newPassword\"\n label={tr(\"account.password.new\", { default: \"New password\" })}\n value={password}\n onChange={setPassword}\n autoComplete=\"new-password\"\n required\n />\n <ControlPassword\n id=\"confirmPassword\"\n label={tr(\"account.password.confirm\", {\n default: \"Confirm new password\",\n })}\n value={confirmPassword}\n onChange={setConfirmPassword}\n autoComplete=\"new-password\"\n required\n />\n <DialogFooter>\n <Button type=\"button\" variant=\"minimal\" onClick={close}>\n {tr(\"account.password.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button type=\"submit\" disabled={submitting}>\n {title}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAa,yBAAyB,UAAsC;CAC1E,MAAM,cAAc,UAAgC;CACpD,MAAM,cAAc,UAAgC;CACpD,MAAM,UAAU,SAAS;CACzB,MAAM,EAAE,OAAO,QAAQ;CAEvB,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,EAAE;CACzD,MAAM,CAAC,UAAU,eAAe,SAAS,EAAE;CAC3C,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,EAAE;CACzD,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAElD,MAAM,cAAc;EAClB,m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UAAA;IACE,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,MAAM,cACH,GAAG,sCAAsC,EACvC,SAAS,yCACX,CAAC,IACD,GAAG,mCAAmC,EACpC,SACE,kFACJ,CAAC;IACD,CAAA;IACL,MAAM,cACL,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,4BAA4B,EACpC,SAAS,mBACX,CAAC;KACD,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA,IACC;IACJ,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,wBAAwB,EAAE,SAAS,eAAe,CAAC;KAC7D,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA;IACD,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,4BAA4B,EACpC,SAAS,uBACX,CAAC;KACD,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA;IACD,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,QAAD;KAAQ,MAAK;KAAS,SAAQ;KAAU,SAAS;KAC9C,UAAA,GAAG,2BAA2B,EAAE,SAAS,SAAS,CAAC;IAC9C,CAAA,GACR,oBAAC,QAAD;KAAQ,MAAK;KAAS,UAAU;KAC7B,UAAA;IACK,CAAA,CACI,EAAA,CAAA;GACV;EACO,CAAA,CAAA,EAAA,CAAA;CACT,CAAA;AAEZ"}
1
+ {"version":3,"file":"AccountPasswordDialog.js","names":[],"sources":["../../src/account/AccountPasswordDialog.tsx"],"sourcesContent":["import type {\n MyIdentityController,\n MyPasswordController,\n} from \"alepha/api/users\";\nimport { useAction, useClient } from \"alepha/react\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { type FormEvent, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Dialog,\n DialogContent,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"../core/Dialog.tsx\";\nimport { useToast } from \"../core/useToast.tsx\";\nimport { ControlPassword } from \"../form/ControlPassword.tsx\";\n\nexport interface AccountPasswordDialogProps {\n open: boolean;\n\n /**\n * Whether the account already has a `credentials` identity. Decides both\n * the copy and — critically — which endpoint is called.\n */\n hasPassword: boolean;\n\n onOpenChange: (open: boolean) => void;\n\n /**\n * Called after a successful change so the caller can refresh its identity\n * list — setting a first password creates one.\n */\n onDone?: () => void | Promise<void>;\n}\n\n/**\n * Set a first password, or change an existing one.\n *\n * ⚠️ **These are two different endpoints and must stay so.**\n * `setMyFirstPassword` takes only the new password and trusts the session,\n * which is defensible when there is nothing to prove knowledge of. Reusing it\n * to *change* a password would make any unattended signed-in browser a full\n * account takeover.\n *\n * `changeMyPassword` verifies the current password and revokes every other\n * session — the usual reason to change a password is believing someone else\n * has it, and leaving their session alive would accomplish nothing. It\n * reports how many it ended, which is why the toast can say so rather than\n * leave the person wondering about their phone.\n */\nexport const AccountPasswordDialog = (props: AccountPasswordDialogProps) => {\n const passwordApi = useClient<MyPasswordController>();\n const identityApi = useClient<MyIdentityController>();\n const toaster = useToast();\n const { tr } = useI18n();\n\n const [currentPassword, setCurrentPassword] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n const [confirmPassword, setConfirmPassword] = useState(\"\");\n\n const close = () => {\n setCurrentPassword(\"\");\n setPassword(\"\");\n setConfirmPassword(\"\");\n props.onOpenChange(false);\n };\n\n // The realm's password policy and the wrong-current-password refusal both\n // arrive as errors whose message is worth showing verbatim: the app's\n // ActionErrorToaster shows it.\n const save = useAction<[]>(\n {\n handler: async () => {\n if (props.hasPassword) {\n const { otherSessionsRevoked } = await passwordApi.changeMyPassword({\n body: { currentPassword, newPassword: password },\n });\n toaster.show(\n otherSessionsRevoked > 0\n ? tr(\"account.password.changedWithSessions\", {\n default: \"Password changed - $1 other session(s) signed out\",\n args: [String(otherSessionsRevoked)],\n })\n : tr(\"account.password.changed\", { default: \"Password changed\" }),\n \"success\",\n );\n } else {\n await identityApi.setMyFirstPassword({ body: { password } });\n toaster.show(\n tr(\"account.password.set\", { default: \"Password set\" }),\n \"success\",\n );\n }\n await props.onDone?.();\n close();\n },\n },\n [currentPassword, password, props.hasPassword, props.onDone],\n );\n const submitting = save.loading;\n\n const submit = async (event: FormEvent) => {\n event.preventDefault();\n if (password !== confirmPassword) {\n toaster.show(\n tr(\"account.password.mismatch\", {\n default: \"The two passwords do not match\",\n }),\n \"danger\",\n );\n return;\n }\n void save.run();\n };\n\n const title = props.hasPassword\n ? tr(\"account.password.change\", { default: \"Change password\" })\n : tr(\"account.password.setTitle\", { default: \"Set a password\" });\n\n return (\n <Dialog open={props.open} onOpenChange={(next) => !next && close()}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n </DialogHeader>\n <form onSubmit={submit} className=\"flex flex-col gap-4\">\n <span className=\"text-muted-foreground text-sm\">\n {props.hasPassword\n ? tr(\"account.password.changeDescription\", {\n default: \"Every other device will be signed out.\",\n })\n : tr(\"account.password.setDescription\", {\n default:\n \"You will be able to sign in with your password as well as your existing method.\",\n })}\n </span>\n {props.hasPassword ? (\n <ControlPassword\n id=\"currentPassword\"\n label={tr(\"account.password.current\", {\n default: \"Current password\",\n })}\n value={currentPassword}\n onChange={setCurrentPassword}\n autoComplete=\"current-password\"\n required\n />\n ) : null}\n <ControlPassword\n id=\"newPassword\"\n label={tr(\"account.password.new\", { default: \"New password\" })}\n value={password}\n onChange={setPassword}\n autoComplete=\"new-password\"\n required\n />\n <ControlPassword\n id=\"confirmPassword\"\n label={tr(\"account.password.confirm\", {\n default: \"Confirm new password\",\n })}\n value={confirmPassword}\n onChange={setConfirmPassword}\n autoComplete=\"new-password\"\n required\n />\n <DialogFooter>\n <Button type=\"button\" variant=\"minimal\" onClick={close}>\n {tr(\"account.password.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button type=\"submit\" disabled={submitting}>\n {title}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAa,yBAAy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AAS,iBAAiB,CAAC;CAEjE,OACE,oBAAC,QAAD;EAAQ,MAAM,MAAM;EAAM,eAAe,SAAS,CAAC,QAAQ,MAAM;EAC/D,UAAA,qBAAC,eAAD,EAAA,UAAA,CACE,oBAAC,cAAD,EAAA,UACE,oBAAC,aAAD,EAAA,UAAc,MAAmB,CAAA,EACrB,CAAA,GACd,qBAAC,QAAD;GAAM,UAAU;GAAQ,WAAU;GAAlC,UAAA;IACE,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,MAAM,cACH,GAAG,sCAAsC,EACvC,SAAS,yCACX,CAAC,IACD,GAAG,mCAAmC,EACpC,SACE,kFACJ,CAAC;IACD,CAAA;IACL,MAAM,cACL,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,4BAA4B,EACpC,SAAS,mBACX,CAAC;KACD,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA,IACC;IACJ,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,wBAAwB,EAAE,SAAS,eAAe,CAAC;KAC7D,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA;IACD,oBAAC,iBAAD;KACE,IAAG;KACH,OAAO,GAAG,4BAA4B,EACpC,SAAS,uBACX,CAAC;KACD,OAAO;KACP,UAAU;KACV,cAAa;KACb,UAAA;IACD,CAAA;IACD,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,QAAD;KAAQ,MAAK;KAAS,SAAQ;KAAU,SAAS;KAC9C,UAAA,GAAG,2BAA2B,EAAE,SAAS,SAAS,CAAC;IAC9C,CAAA,GACR,oBAAC,QAAD;KAAQ,MAAK;KAAS,UAAU;KAC7B,UAAA;IACK,CAAA,CACI,EAAA,CAAA;GACV;EACO,CAAA,CAAA,EAAA,CAAA;CACT,CAAA;AAEZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountProfile.d.ts","sourceRoot":"","sources":["../../src/account/AccountProfile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAET,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAiB1B,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,QAAA,MAAM,cAAc,UAAW,mBAAmB,uCAuUjD,CAAC;eAEa,cAAc"}
1
+ {"version":3,"file":"AccountProfile.d.ts","sourceRoot":"","sources":["../../src/account/AccountProfile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAET,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAiB1B,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,QAAA,MAAM,cAAc,UAAW,mBAAmB,uCAyTjD,CAAC;eAEa,cAAc"}