@rapidmx/web-client 0.10.0 → 0.11.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 (310) hide show
  1. package/README.md +183 -2
  2. package/apps/admin/_layout.tsx +8 -2
  3. package/apps/admin/index.tsx +7 -1
  4. package/apps/admin/ingest-queue/index.tsx +2 -1
  5. package/apps/admin/mailboxes/[uid].tsx +23 -10
  6. package/apps/admin/quarantine/index.tsx +2 -1
  7. package/apps/admin/signing-certificates/index.tsx +343 -0
  8. package/apps/escrow/_layout.tsx +8 -2
  9. package/apps/shared/appearance/AppearanceForm.tsx +392 -0
  10. package/apps/shared/appearance/AppearanceHead.tsx +49 -0
  11. package/apps/shared/appearance/AppearanceProvider.tsx +470 -0
  12. package/apps/shared/appearance/ColorField.tsx +107 -0
  13. package/apps/shared/appearance/appearanceCache.ts +106 -0
  14. package/apps/shared/appearance/appearanceContext.ts +77 -0
  15. package/apps/shared/appearance/bootScript.ts +35 -0
  16. package/apps/shared/appearance/color.ts +169 -0
  17. package/apps/shared/appearance/photo.ts +88 -0
  18. package/apps/shared/appearance/resolvedTheme.ts +67 -0
  19. package/apps/shared/appearance/theme.ts +355 -0
  20. package/apps/shared/components/admin/layout/AdminShell.tsx +22 -10
  21. package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +107 -60
  22. package/apps/shared/components/admin/settings/BrandingForm.tsx +24 -0
  23. package/apps/shared/components/admin/settings/PluginsManager.tsx +228 -25
  24. package/apps/shared/components/admin/setup/SetupWizard.tsx +2 -1
  25. package/apps/shared/components/calendar/CalendarListSidebar.tsx +4 -5
  26. package/apps/shared/components/contacts/ContactForm.tsx +11 -5
  27. package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -3
  28. package/apps/shared/components/contacts/ContactsToolbar.tsx +25 -52
  29. package/apps/shared/components/contacts/layout/ContactsShell.tsx +10 -5
  30. package/apps/shared/components/escrow/layout/EscrowShell.tsx +13 -6
  31. package/apps/shared/components/layout/AppShell.tsx +98 -32
  32. package/apps/shared/components/layout/BrandingChrome.tsx +200 -13
  33. package/apps/shared/components/layout/RailIcon.tsx +100 -0
  34. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -0
  35. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -0
  36. package/apps/shared/components/layout/UserMenu.tsx +75 -6
  37. package/apps/shared/components/mail/ConversationList.tsx +4 -2
  38. package/apps/shared/components/mail/ConversationThreadPane.tsx +487 -475
  39. package/apps/shared/components/mail/LazyReadingPane.tsx +14 -16
  40. package/apps/shared/components/mail/MailSelectionBar.tsx +2 -10
  41. package/apps/shared/components/mail/MessageDetailPane.tsx +366 -287
  42. package/apps/shared/components/mail/OutboxBadge.tsx +44 -0
  43. package/apps/shared/components/mail/OutboxRowStatus.tsx +31 -0
  44. package/apps/shared/components/mail/compose/ComposeContext.tsx +35 -2
  45. package/apps/shared/components/mail/compose/ComposeWindow.tsx +239 -437
  46. package/apps/shared/components/mail/compose/encryptionRequirement.ts +86 -0
  47. package/apps/shared/components/mail/layout/MailShell.tsx +39 -25
  48. package/apps/shared/components/mail/reading/EncryptedBody.tsx +65 -0
  49. package/apps/shared/components/mail/reading/EncryptedPreview.tsx +35 -0
  50. package/apps/shared/components/mail/reading/MessageBody.tsx +240 -0
  51. package/apps/shared/components/mail/reading/MessageCard.tsx +174 -0
  52. package/apps/shared/components/mail/reading/bodyContent.ts +100 -0
  53. package/apps/shared/components/mail/reading/bodyHtml.ts +298 -0
  54. package/apps/shared/components/mail/reading/color.ts +245 -0
  55. package/apps/shared/components/mail/reading/frameControl.ts +142 -0
  56. package/apps/shared/components/mail/reading/frameDocument.ts +123 -0
  57. package/apps/shared/components/mail/reading/safeDocument.ts +24 -0
  58. package/apps/shared/components/mail/reading/themeAdaptation.ts +221 -0
  59. package/apps/shared/components/mail/reading/themeSurface.ts +90 -0
  60. package/apps/shared/components/mail/reading/viewOriginal.ts +38 -0
  61. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -0
  62. package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
  63. package/apps/shared/components/sharing/PrincipalPicker.tsx +145 -0
  64. package/apps/shared/components/tasks/TasksSidebar.tsx +5 -3
  65. package/apps/shared/components/tasks/layout/TasksShell.tsx +9 -5
  66. package/apps/shared/mail/folderCounts.ts +9 -3
  67. package/apps/shared/mail/folderTree.ts +143 -0
  68. package/apps/shared/mail/outbox/UnlockBridge.tsx +23 -0
  69. package/apps/shared/mail/outbox/composeBridge.ts +69 -0
  70. package/apps/shared/mail/outbox/outboxState.ts +88 -0
  71. package/apps/shared/mail/outbox/pendingSends.ts +146 -0
  72. package/apps/shared/mail/outbox/sendDecision.ts +157 -0
  73. package/apps/shared/mail/outbox/sendJob.ts +427 -0
  74. package/apps/shared/mail/outbox/sendOutcomes.ts +146 -0
  75. package/apps/shared/mail/outbox/sendState.ts +35 -0
  76. package/apps/shared/mail/outbox/useOutboxStatus.ts +61 -0
  77. package/apps/shared/mail/useMailConnection.ts +81 -28
  78. package/apps/shared/mail/useMailLiveUpdates.ts +55 -10
  79. package/apps/shared/mail/useNewMailNotifications.ts +47 -32
  80. package/apps/shared/navigation/AppRouter.tsx +2 -2
  81. package/apps/shared/notifications/NotificationCenter.tsx +215 -0
  82. package/apps/shared/notifications/NotificationHistoryDialog.tsx +90 -0
  83. package/apps/shared/notifications/apiErrors.ts +98 -0
  84. package/apps/shared/notifications/headerOffset.ts +35 -0
  85. package/apps/shared/notifications/pushStatus.ts +56 -0
  86. package/apps/shared/notifications/store.ts +549 -0
  87. package/apps/shared/notifications/systemErrors.ts +63 -0
  88. package/apps/shared/notifications/useNotifications.ts +41 -0
  89. package/apps/shared/signing/enrollmentStorage.ts +33 -0
  90. package/apps/shared/signing/enrollmentTracker.ts +385 -0
  91. package/apps/shared/signing/enrollmentView.ts +251 -0
  92. package/apps/shared/signing/signingInfo.ts +58 -0
  93. package/apps/shared/signing/useNow.ts +19 -0
  94. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -0
  95. package/apps/shared/styles/app.css +80 -0
  96. package/apps/www/_layout.tsx +8 -2
  97. package/apps/www/_routes.ts +1 -0
  98. package/apps/www/calendar/index.tsx +9 -14
  99. package/apps/www/contacts/[uid].tsx +5 -8
  100. package/apps/www/contacts/index.tsx +587 -584
  101. package/apps/www/index.tsx +38 -27
  102. package/apps/www/messages/[uid].tsx +3 -1
  103. package/apps/www/settings/appearance/index.tsx +21 -0
  104. package/apps/www/settings/auto-reply/index.tsx +3 -7
  105. package/apps/www/settings/encryption/index.tsx +151 -116
  106. package/apps/www/settings/filters/[uid].tsx +3 -1
  107. package/apps/www/settings/filters/new/index.tsx +3 -1
  108. package/apps/www/settings/privacy/index.tsx +3 -8
  109. package/apps/www/settings/read-receipts/index.tsx +3 -7
  110. package/apps/www/settings/sharing/index.tsx +44 -65
  111. package/apps/www/settings/signatures/[uid].tsx +3 -1
  112. package/apps/www/settings/signatures/new/index.tsx +3 -2
  113. package/apps/www/tasks/index.tsx +11 -16
  114. package/dist/apps/admin/_layout.d.ts +5 -1
  115. package/dist/apps/admin/_layout.js +3 -2
  116. package/dist/apps/admin/index.js +3 -2
  117. package/dist/apps/admin/ingest-queue/index.js +2 -1
  118. package/dist/apps/admin/mailboxes/[uid].js +9 -6
  119. package/dist/apps/admin/quarantine/index.js +2 -1
  120. package/dist/apps/admin/signing-certificates/index.d.ts +3 -0
  121. package/dist/apps/admin/signing-certificates/index.js +161 -0
  122. package/dist/apps/escrow/_layout.d.ts +5 -1
  123. package/dist/apps/escrow/_layout.js +3 -2
  124. package/dist/apps/shared/appearance/AppearanceForm.d.ts +7 -0
  125. package/dist/apps/shared/appearance/AppearanceForm.js +131 -0
  126. package/dist/apps/shared/appearance/AppearanceHead.d.ts +15 -0
  127. package/dist/apps/shared/appearance/AppearanceHead.js +31 -0
  128. package/dist/apps/shared/appearance/AppearanceProvider.d.ts +32 -0
  129. package/dist/apps/shared/appearance/AppearanceProvider.js +390 -0
  130. package/dist/apps/shared/appearance/ColorField.d.ts +22 -0
  131. package/dist/apps/shared/appearance/ColorField.js +40 -0
  132. package/dist/apps/shared/appearance/appearanceCache.d.ts +45 -0
  133. package/dist/apps/shared/appearance/appearanceCache.js +80 -0
  134. package/dist/apps/shared/appearance/appearanceContext.d.ts +45 -0
  135. package/dist/apps/shared/appearance/appearanceContext.js +29 -0
  136. package/dist/apps/shared/appearance/bootScript.d.ts +16 -0
  137. package/dist/apps/shared/appearance/bootScript.js +33 -0
  138. package/dist/apps/shared/appearance/color.d.ts +65 -0
  139. package/dist/apps/shared/appearance/color.js +132 -0
  140. package/dist/apps/shared/appearance/photo.d.ts +17 -0
  141. package/dist/apps/shared/appearance/photo.js +79 -0
  142. package/dist/apps/shared/appearance/resolvedTheme.d.ts +21 -0
  143. package/dist/apps/shared/appearance/resolvedTheme.js +55 -0
  144. package/dist/apps/shared/appearance/theme.d.ts +111 -0
  145. package/dist/apps/shared/appearance/theme.js +251 -0
  146. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
  147. package/dist/apps/shared/components/admin/layout/AdminShell.js +16 -6
  148. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +10 -5
  149. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +49 -34
  150. package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +2 -0
  151. package/dist/apps/shared/components/admin/settings/BrandingForm.js +7 -1
  152. package/dist/apps/shared/components/admin/settings/PluginsManager.js +106 -20
  153. package/dist/apps/shared/components/admin/setup/SetupWizard.js +2 -1
  154. package/dist/apps/shared/components/calendar/CalendarListSidebar.js +8 -8
  155. package/dist/apps/shared/components/contacts/ContactForm.js +1 -1
  156. package/dist/apps/shared/components/contacts/ContactsSidebar.js +4 -2
  157. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  158. package/dist/apps/shared/components/contacts/ContactsToolbar.js +24 -9
  159. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +4 -1
  160. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +7 -4
  161. package/dist/apps/shared/components/layout/AppShell.d.ts +6 -1
  162. package/dist/apps/shared/components/layout/AppShell.js +59 -13
  163. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +69 -10
  164. package/dist/apps/shared/components/layout/BrandingChrome.js +140 -12
  165. package/dist/apps/shared/components/layout/RailIcon.d.ts +21 -0
  166. package/dist/apps/shared/components/layout/RailIcon.js +85 -0
  167. package/dist/apps/shared/components/layout/ResponsiveToolbar.d.ts +55 -0
  168. package/dist/apps/shared/components/layout/ResponsiveToolbar.js +199 -0
  169. package/dist/apps/shared/components/layout/ThemeSwitch.d.ts +9 -0
  170. package/dist/apps/shared/components/layout/ThemeSwitch.js +54 -0
  171. package/dist/apps/shared/components/layout/UserMenu.d.ts +7 -1
  172. package/dist/apps/shared/components/layout/UserMenu.js +41 -7
  173. package/dist/apps/shared/components/mail/ConversationList.js +3 -2
  174. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +2 -1
  175. package/dist/apps/shared/components/mail/ConversationThreadPane.js +42 -20
  176. package/dist/apps/shared/components/mail/LazyReadingPane.js +9 -8
  177. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +3 -4
  178. package/dist/apps/shared/components/mail/MailSelectionBar.js +2 -3
  179. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +18 -7
  180. package/dist/apps/shared/components/mail/MessageDetailPane.js +86 -41
  181. package/dist/apps/shared/components/mail/OutboxBadge.d.ts +17 -0
  182. package/dist/apps/shared/components/mail/OutboxBadge.js +18 -0
  183. package/dist/apps/shared/components/mail/OutboxRowStatus.d.ts +10 -0
  184. package/dist/apps/shared/components/mail/OutboxRowStatus.js +19 -0
  185. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +8 -0
  186. package/dist/apps/shared/components/mail/compose/ComposeContext.js +28 -3
  187. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +2 -1
  188. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +229 -328
  189. package/dist/apps/shared/components/mail/compose/encryptionRequirement.d.ts +49 -0
  190. package/dist/apps/shared/components/mail/compose/encryptionRequirement.js +35 -0
  191. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +2 -0
  192. package/dist/apps/shared/components/mail/layout/MailShell.js +20 -14
  193. package/dist/apps/shared/components/mail/reading/EncryptedBody.d.ts +21 -0
  194. package/dist/apps/shared/components/mail/reading/EncryptedBody.js +22 -0
  195. package/dist/apps/shared/components/mail/reading/EncryptedPreview.d.ts +18 -0
  196. package/dist/apps/shared/components/mail/reading/EncryptedPreview.js +22 -0
  197. package/dist/apps/shared/components/mail/reading/MessageBody.d.ts +32 -0
  198. package/dist/apps/shared/components/mail/reading/MessageBody.js +136 -0
  199. package/dist/apps/shared/components/mail/reading/MessageCard.d.ts +62 -0
  200. package/dist/apps/shared/components/mail/reading/MessageCard.js +58 -0
  201. package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +38 -0
  202. package/dist/apps/shared/components/mail/reading/bodyContent.js +84 -0
  203. package/dist/apps/shared/components/mail/reading/bodyHtml.d.ts +47 -0
  204. package/dist/apps/shared/components/mail/reading/bodyHtml.js +267 -0
  205. package/dist/apps/shared/components/mail/reading/color.d.ts +63 -0
  206. package/dist/apps/shared/components/mail/reading/color.js +201 -0
  207. package/dist/apps/shared/components/mail/reading/frameControl.d.ts +33 -0
  208. package/dist/apps/shared/components/mail/reading/frameControl.js +120 -0
  209. package/dist/apps/shared/components/mail/reading/frameDocument.d.ts +52 -0
  210. package/dist/apps/shared/components/mail/reading/frameDocument.js +98 -0
  211. package/dist/apps/shared/components/mail/reading/safeDocument.d.ts +3 -0
  212. package/dist/apps/shared/components/mail/reading/safeDocument.js +12 -0
  213. package/dist/apps/shared/components/mail/reading/themeAdaptation.d.ts +56 -0
  214. package/dist/apps/shared/components/mail/reading/themeAdaptation.js +144 -0
  215. package/dist/apps/shared/components/mail/reading/themeSurface.d.ts +17 -0
  216. package/dist/apps/shared/components/mail/reading/themeSurface.js +83 -0
  217. package/dist/apps/shared/components/mail/reading/viewOriginal.d.ts +9 -0
  218. package/dist/apps/shared/components/mail/reading/viewOriginal.js +32 -0
  219. package/dist/apps/shared/components/settings/SigningCertificateCard.d.ts +32 -0
  220. package/dist/apps/shared/components/settings/SigningCertificateCard.js +98 -0
  221. package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
  222. package/dist/apps/shared/components/sharing/PrincipalPicker.d.ts +26 -0
  223. package/dist/apps/shared/components/sharing/PrincipalPicker.js +77 -0
  224. package/dist/apps/shared/components/tasks/TasksSidebar.js +4 -2
  225. package/dist/apps/shared/components/tasks/layout/TasksShell.js +3 -1
  226. package/dist/apps/shared/mail/folderCounts.d.ts +1 -1
  227. package/dist/apps/shared/mail/folderCounts.js +9 -3
  228. package/dist/apps/shared/mail/folderTree.d.ts +55 -0
  229. package/dist/apps/shared/mail/folderTree.js +116 -0
  230. package/dist/apps/shared/mail/outbox/UnlockBridge.d.ts +5 -0
  231. package/dist/apps/shared/mail/outbox/UnlockBridge.js +18 -0
  232. package/dist/apps/shared/mail/outbox/composeBridge.d.ts +34 -0
  233. package/dist/apps/shared/mail/outbox/composeBridge.js +32 -0
  234. package/dist/apps/shared/mail/outbox/outboxState.d.ts +41 -0
  235. package/dist/apps/shared/mail/outbox/outboxState.js +42 -0
  236. package/dist/apps/shared/mail/outbox/pendingSends.d.ts +39 -0
  237. package/dist/apps/shared/mail/outbox/pendingSends.js +109 -0
  238. package/dist/apps/shared/mail/outbox/sendDecision.d.ts +80 -0
  239. package/dist/apps/shared/mail/outbox/sendDecision.js +94 -0
  240. package/dist/apps/shared/mail/outbox/sendJob.d.ts +68 -0
  241. package/dist/apps/shared/mail/outbox/sendJob.js +319 -0
  242. package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +3 -0
  243. package/dist/apps/shared/mail/outbox/sendOutcomes.js +141 -0
  244. package/dist/apps/shared/mail/outbox/sendState.d.ts +25 -0
  245. package/dist/apps/shared/mail/outbox/sendState.js +8 -0
  246. package/dist/apps/shared/mail/outbox/useOutboxStatus.d.ts +11 -0
  247. package/dist/apps/shared/mail/outbox/useOutboxStatus.js +49 -0
  248. package/dist/apps/shared/mail/useMailConnection.d.ts +9 -8
  249. package/dist/apps/shared/mail/useMailConnection.js +64 -22
  250. package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +17 -4
  251. package/dist/apps/shared/mail/useMailLiveUpdates.js +36 -10
  252. package/dist/apps/shared/mail/useNewMailNotifications.d.ts +4 -10
  253. package/dist/apps/shared/mail/useNewMailNotifications.js +43 -23
  254. package/dist/apps/shared/navigation/AppRouter.js +2 -2
  255. package/dist/apps/shared/notifications/NotificationCenter.d.ts +19 -0
  256. package/dist/apps/shared/notifications/NotificationCenter.js +90 -0
  257. package/dist/apps/shared/notifications/NotificationHistoryDialog.d.ts +10 -0
  258. package/dist/apps/shared/notifications/NotificationHistoryDialog.js +36 -0
  259. package/dist/apps/shared/notifications/apiErrors.d.ts +19 -0
  260. package/dist/apps/shared/notifications/apiErrors.js +86 -0
  261. package/dist/apps/shared/notifications/headerOffset.d.ts +8 -0
  262. package/dist/apps/shared/notifications/headerOffset.js +33 -0
  263. package/dist/apps/shared/notifications/pushStatus.d.ts +9 -0
  264. package/dist/apps/shared/notifications/pushStatus.js +54 -0
  265. package/dist/apps/shared/notifications/store.d.ts +136 -0
  266. package/dist/apps/shared/notifications/store.js +416 -0
  267. package/dist/apps/shared/notifications/systemErrors.d.ts +9 -0
  268. package/dist/apps/shared/notifications/systemErrors.js +58 -0
  269. package/dist/apps/shared/notifications/useNotifications.d.ts +17 -0
  270. package/dist/apps/shared/notifications/useNotifications.js +18 -0
  271. package/dist/apps/shared/signing/enrollmentStorage.d.ts +10 -0
  272. package/dist/apps/shared/signing/enrollmentStorage.js +33 -0
  273. package/dist/apps/shared/signing/enrollmentTracker.d.ts +73 -0
  274. package/dist/apps/shared/signing/enrollmentTracker.js +307 -0
  275. package/dist/apps/shared/signing/enrollmentView.d.ts +57 -0
  276. package/dist/apps/shared/signing/enrollmentView.js +214 -0
  277. package/dist/apps/shared/signing/signingInfo.d.ts +11 -0
  278. package/dist/apps/shared/signing/signingInfo.js +48 -0
  279. package/dist/apps/shared/signing/useNow.d.ts +2 -0
  280. package/dist/apps/shared/signing/useNow.js +18 -0
  281. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.d.ts +16 -0
  282. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.js +87 -0
  283. package/dist/apps/shared/styles/app.css +80 -0
  284. package/dist/apps/www/_layout.d.ts +5 -1
  285. package/dist/apps/www/_layout.js +3 -2
  286. package/dist/apps/www/_routes.js +1 -0
  287. package/dist/apps/www/calendar/index.js +3 -4
  288. package/dist/apps/www/contacts/[uid].js +5 -7
  289. package/dist/apps/www/contacts/index.js +14 -21
  290. package/dist/apps/www/index.js +37 -19
  291. package/dist/apps/www/messages/[uid].js +3 -1
  292. package/dist/apps/www/settings/appearance/index.d.ts +4 -0
  293. package/dist/apps/www/settings/appearance/index.js +13 -0
  294. package/dist/apps/www/settings/auto-reply/index.js +3 -6
  295. package/dist/apps/www/settings/encryption/index.js +103 -95
  296. package/dist/apps/www/settings/filters/[uid].js +3 -1
  297. package/dist/apps/www/settings/filters/new/index.js +3 -1
  298. package/dist/apps/www/settings/privacy/index.js +5 -8
  299. package/dist/apps/www/settings/read-receipts/index.js +3 -6
  300. package/dist/apps/www/settings/sharing/index.js +19 -33
  301. package/dist/apps/www/settings/signatures/[uid].js +3 -1
  302. package/dist/apps/www/settings/signatures/new/index.js +3 -2
  303. package/dist/apps/www/tasks/index.js +8 -14
  304. package/package.json +2 -2
  305. package/apps/shared/components/mail/NewMailToasts.tsx +0 -141
  306. package/apps/shared/components/mail/compose/SendFailureAlert.tsx +0 -48
  307. package/dist/apps/shared/components/mail/NewMailToasts.d.ts +0 -19
  308. package/dist/apps/shared/components/mail/NewMailToasts.js +0 -55
  309. package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +0 -14
  310. package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +0 -11
@@ -0,0 +1,385 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { useSyncExternalStore } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import {
8
+ CurrentSignEnrollment,
9
+ EnrollmentResult,
10
+ checkNowRetryAfterSeconds,
11
+ checkSignEnrollmentNow,
12
+ checkSignEnrollmentStatus,
13
+ } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
14
+ import { SIGNING_ENROLLMENT_UNKNOWN } from "@rapidmx/react-shared/crypto/signingProviderApi.js";
15
+ import { storeSignEnrollment } from "./enrollmentStorage.js";
16
+ import { resetSigningInfo } from "./signingInfo.js";
17
+
18
+ /** The code of the 404 the server answers for an enrollment id it does not know (another provider after a configuration change, one long gone).
19
+ * Re-exported from react-shared's `signingProviderApi.js` (R6's) rather than a second copy of the literal. */
20
+ export const UNKNOWN_ENROLLMENT_CODE = SIGNING_ENROLLMENT_UNKNOWN;
21
+
22
+ /**
23
+ * Follows the signing-certificate enrollments this browser knows about, one per mailbox, for everyone who wants to show or react to one:
24
+ * the Settings > Encryption card and the app frame's watcher share it, so an enrollment is asked about once however many look at it.
25
+ *
26
+ * An enrollment is a real e-mail round trip with a public CA (minutes), so it is read - not hammered: after the first answer it asks again
27
+ * after 15 s, then 30 s, then every 60 s, **only while the page is visible** (a hidden tab asks nothing; coming back to the front, or the
28
+ * window taking focus, asks at once and starts the backoff over), and it stops for good when the enrollment is issued or failed.
29
+ * `checkNow()` is the user's "Check status": it asks the server to re-check with the CA, with a cooldown so it can't be spammed.
30
+ *
31
+ * Framework-free apart from the `useSyncExternalStore` hook at the bottom; safe where there is no window (nothing runs until `watch()`).
32
+ */
33
+
34
+ /** The wait before each re-read of a pending enrollment: the last value repeats. */
35
+ export const ENROLLMENT_POLL_DELAYS_MS = [15_000, 30_000, 60_000];
36
+
37
+ /** How long "Check status" stays unavailable after a check (the server refuses one within about ten seconds of the last). */
38
+ export const ENROLLMENT_CHECK_COOLDOWN_MS = 10_000;
39
+
40
+ /** What came of the last manual check. */
41
+ export type CheckOutcome = "changed" | "unchanged" | "limited" | "failed";
42
+
43
+ export interface EnrollmentSnapshot {
44
+ mailboxUid: string;
45
+ enrollmentId: string;
46
+ /** The latest answer. `null` until the server has answered (or when its answers never arrive). */
47
+ result: EnrollmentResult | null;
48
+ /** When this browser last got an answer (its own clock), or `null`. */
49
+ answeredAt: number | null;
50
+ /** A read is in flight. */
51
+ checking: boolean;
52
+ /** A manual check is in flight: the button's busy state. */
53
+ checkingNow: boolean;
54
+ /** "Check status" is unavailable until this time (epoch ms); `0` when it is available. */
55
+ retryAt: number;
56
+ /** The last read did not get an answer (offline, a server error) - what is shown is what was known. */
57
+ offline: boolean;
58
+ /** The server no longer knows this enrollment (404). */
59
+ gone: boolean;
60
+ /** The last manual check, for the words under the button. */
61
+ lastCheck: { at: number; outcome: CheckOutcome } | null;
62
+ }
63
+
64
+ interface Entry {
65
+ snapshot: EnrollmentSnapshot;
66
+ refs: number;
67
+ timer: ReturnType<typeof setTimeout> | undefined;
68
+ /** Reads since the backoff began: picks the next delay. */
69
+ attempt: number;
70
+ /** A timer came due while the page was hidden: nothing is scheduled until it is visible again. */
71
+ paused: boolean;
72
+ /** Ended while this browser was watching a pending enrollment: worth announcing once. */
73
+ expectPending: boolean;
74
+ announced: boolean;
75
+ }
76
+
77
+ const entries = new Map<string, Entry>();
78
+ const listeners = new Set<() => void>();
79
+ const terminalListeners = new Set<(snapshot: EnrollmentSnapshot) => void>();
80
+ let environmentBound = false;
81
+
82
+ function isVisible(): boolean {
83
+ return typeof document === "undefined" || document.visibilityState === "visible";
84
+ }
85
+
86
+ function isTerminal(result: EnrollmentResult | null): boolean {
87
+ return result?.status === "issued" || result?.status === "failed";
88
+ }
89
+
90
+ function emit(): void {
91
+ listeners.forEach((listener) => listener());
92
+ }
93
+
94
+ function update(entry: Entry, patch: Partial<EnrollmentSnapshot>): void {
95
+ entry.snapshot = { ...entry.snapshot, ...patch };
96
+ emit();
97
+ }
98
+
99
+ function isCurrent(entry: Entry): boolean {
100
+ return entries.get(entry.snapshot.mailboxUid) === entry;
101
+ }
102
+
103
+ function stop(entry: Entry): void {
104
+ clearTimeout(entry.timer);
105
+ entry.timer = undefined;
106
+ entry.paused = false;
107
+ }
108
+
109
+ function schedule(entry: Entry): void {
110
+ stop(entry);
111
+ const delay = ENROLLMENT_POLL_DELAYS_MS[Math.min(entry.attempt, ENROLLMENT_POLL_DELAYS_MS.length - 1)];
112
+ entry.attempt += 1;
113
+ entry.timer = setTimeout(() => {
114
+ entry.timer = undefined;
115
+ // (Whatever replaces or ends an entry clears its timer first, so this one is always for the entry as it is.)
116
+ if (!isVisible()) {
117
+ entry.paused = true;
118
+ return;
119
+ }
120
+ void read(entry);
121
+ }, delay);
122
+ }
123
+
124
+ /** Puts an answer on the entry and decides what happens next: keep asking, or end (and tell the watchers once). */
125
+ function apply(entry: Entry, result: EnrollmentResult, patch: Partial<EnrollmentSnapshot> = {}): void {
126
+ if (!isCurrent(entry)) {
127
+ return;
128
+ }
129
+ update(entry, { result, answeredAt: Date.now(), offline: false, gone: false, checking: false, ...patch });
130
+ if (!isTerminal(result)) {
131
+ schedule(entry);
132
+ return;
133
+ }
134
+ stop(entry);
135
+ // The enrollment is over: nothing is pending, so the id is not kept (it is what blocks a rotation across a reload).
136
+ storeSignEnrollment(entry.snapshot.mailboxUid, null);
137
+ if (entry.expectPending && !entry.announced) {
138
+ entry.announced = true;
139
+ terminalListeners.forEach((listener) => listener(entry.snapshot));
140
+ }
141
+ }
142
+
143
+ /** A failed read: the server no longer has the enrollment (nothing is pending), or it could not be reached (assume it is still going). */
144
+ function fail(entry: Entry, err: unknown, patch: Partial<EnrollmentSnapshot> = {}): void {
145
+ if (!isCurrent(entry)) {
146
+ return;
147
+ }
148
+ if (err instanceof ApiRequestError && err.status === 404) {
149
+ stop(entry);
150
+ storeSignEnrollment(entry.snapshot.mailboxUid, null);
151
+ update(entry, { gone: true, offline: false, checking: false, ...patch });
152
+ return;
153
+ }
154
+ update(entry, { offline: true, checking: false, ...patch });
155
+ schedule(entry);
156
+ }
157
+
158
+ async function read(entry: Entry): Promise<void> {
159
+ update(entry, { checking: true });
160
+ try {
161
+ apply(entry, await checkSignEnrollmentStatus(entry.snapshot.mailboxUid, entry.snapshot.enrollmentId));
162
+ } catch (err) {
163
+ fail(entry, err);
164
+ }
165
+ }
166
+
167
+ function resume(): void {
168
+ if (!isVisible()) {
169
+ return;
170
+ }
171
+ entries.forEach((entry) => {
172
+ if (entry.paused && !isTerminal(entry.snapshot.result)) {
173
+ entry.paused = false;
174
+ entry.attempt = 0;
175
+ void read(entry);
176
+ }
177
+ });
178
+ }
179
+
180
+ function bindEnvironment(): void {
181
+ if (!environmentBound && typeof document !== "undefined") {
182
+ environmentBound = true;
183
+ document.addEventListener("visibilitychange", resume);
184
+ window.addEventListener("focus", resume);
185
+ window.addEventListener("online", resume);
186
+ }
187
+ }
188
+
189
+ function unbindEnvironment(): void {
190
+ if (environmentBound && entries.size === 0) {
191
+ environmentBound = false;
192
+ document.removeEventListener("visibilitychange", resume);
193
+ window.removeEventListener("focus", resume);
194
+ window.removeEventListener("online", resume);
195
+ }
196
+ }
197
+
198
+ export interface WatchOptions {
199
+ /** What is already known (a `getCurrentSignEnrollment()` answer): shown at once and not asked again first. */
200
+ initial?: EnrollmentResult;
201
+ /** This enrollment was pending when it was stored, so its ending is news (a stored id, a pending one found on the server). Default `true`. */
202
+ expectPending?: boolean;
203
+ }
204
+
205
+ /**
206
+ * Starts following `enrollmentId` for `mailboxUid` (one enrollment per mailbox; a different id replaces the old one) and returns the
207
+ * function that lets go. Reads it now unless `initial` says what it is, then keeps reading with backoff while it is pending. Following is
208
+ * shared, and a pending enrollment stays followed after everyone has let go (until it ends); an ended one is forgotten.
209
+ */
210
+ export function watchEnrollment(mailboxUid: string, enrollmentId: string, options: WatchOptions = {}): () => void {
211
+ const { initial, expectPending = true } = options;
212
+ let entry = entries.get(mailboxUid);
213
+ if (entry && entry.snapshot.enrollmentId !== enrollmentId) {
214
+ stop(entry);
215
+ entry = undefined;
216
+ }
217
+ if (entry) {
218
+ entry.refs += 1;
219
+ entry.expectPending ||= expectPending && !isTerminal(entry.snapshot.result);
220
+ if (initial && !entry.snapshot.result) {
221
+ apply(entry, initial);
222
+ }
223
+ } else {
224
+ const created: Entry = {
225
+ snapshot: {
226
+ mailboxUid,
227
+ enrollmentId,
228
+ result: null,
229
+ answeredAt: null,
230
+ checking: false,
231
+ checkingNow: false,
232
+ retryAt: 0,
233
+ offline: false,
234
+ gone: false,
235
+ lastCheck: null,
236
+ },
237
+ refs: 1,
238
+ timer: undefined,
239
+ attempt: 0,
240
+ paused: false,
241
+ expectPending,
242
+ announced: false,
243
+ };
244
+ entries.set(mailboxUid, created);
245
+ bindEnvironment();
246
+ emit();
247
+ if (initial) {
248
+ apply(created, initial);
249
+ } else {
250
+ void read(created);
251
+ }
252
+ }
253
+ const held = entries.get(mailboxUid)!;
254
+ let released = false;
255
+ return () => {
256
+ if (released) {
257
+ return;
258
+ }
259
+ released = true;
260
+ held.refs -= 1;
261
+ // A pending enrollment is followed on with nobody looking - that is what lets the frame tell the user it finished wherever they are, and
262
+ // what the next visit to the page shows at once. One that ended (or that the server no longer knows) has nothing left to follow.
263
+ if (held.refs <= 0 && isCurrent(held) && (isTerminal(held.snapshot.result) || held.snapshot.gone)) {
264
+ stop(held);
265
+ entries.delete(mailboxUid);
266
+ unbindEnvironment();
267
+ emit();
268
+ }
269
+ };
270
+ }
271
+
272
+ /** Whether a manual check changed what the user sees: the step, the state or the progress. */
273
+ function differs(before: EnrollmentResult | null, after: EnrollmentResult): boolean {
274
+ return !before || before.status !== after.status || before.stage !== after.stage || before.progress !== after.progress;
275
+ }
276
+
277
+ /** "Check status": asks the server to re-check with the CA now. Does nothing while one is under way or within the cooldown. */
278
+ export async function checkEnrollmentNow(mailboxUid: string): Promise<void> {
279
+ const entry = entries.get(mailboxUid);
280
+ if (!entry || entry.snapshot.checkingNow || entry.snapshot.retryAt > Date.now() || isTerminal(entry.snapshot.result)) {
281
+ return;
282
+ }
283
+ const before = entry.snapshot.result;
284
+ update(entry, { checkingNow: true, checking: true });
285
+ entry.attempt = 0;
286
+ const done = (outcome: CheckOutcome, patch: Partial<EnrollmentSnapshot> = {}) => ({
287
+ checkingNow: false,
288
+ lastCheck: { at: Date.now(), outcome },
289
+ ...patch,
290
+ });
291
+ try {
292
+ const result = await checkSignEnrollmentNow(mailboxUid, entry.snapshot.enrollmentId);
293
+ apply(entry, result, done(differs(before, result) ? "changed" : "unchanged", { retryAt: Date.now() + ENROLLMENT_CHECK_COOLDOWN_MS }));
294
+ return;
295
+ } catch (err) {
296
+ const seconds = checkNowRetryAfterSeconds(err);
297
+ if (seconds !== undefined) {
298
+ update(entry, done("limited", { retryAt: Date.now() + seconds * 1000, checking: false }));
299
+ return;
300
+ }
301
+ if (err instanceof ApiRequestError && err.status === 404 && err.code === UNKNOWN_ENROLLMENT_CODE) {
302
+ // The server says this enrollment does not exist: there is nothing to fall back to.
303
+ fail(entry, err, done("failed"));
304
+ return;
305
+ }
306
+ if (!(err instanceof ApiRequestError && [404, 405, 501].includes(err.status))) {
307
+ if (isCurrent(entry)) {
308
+ update(entry, done("failed", { checking: false }));
309
+ }
310
+ return;
311
+ }
312
+ }
313
+ // A server without the check endpoint: a plain read is the "check" it has - and a 404 there says the enrollment itself is gone.
314
+ try {
315
+ const result = await checkSignEnrollmentStatus(mailboxUid, entry.snapshot.enrollmentId);
316
+ apply(entry, result, done(differs(before, result) ? "changed" : "unchanged", { retryAt: Date.now() + ENROLLMENT_CHECK_COOLDOWN_MS }));
317
+ } catch (err) {
318
+ fail(entry, err, done("failed"));
319
+ }
320
+ }
321
+
322
+ /** Adopts an enrollment the server reported (`getCurrentSignEnrollment()`) - see `watchEnrollment()`. */
323
+ export function watchCurrentEnrollment(mailboxUid: string, current: CurrentSignEnrollment, expectPending = true): () => void {
324
+ const { enrollmentId, ...result } = current;
325
+ return watchEnrollment(mailboxUid, enrollmentId, { initial: result, expectPending });
326
+ }
327
+
328
+ /** Puts an answer the caller got itself (the reply to a cancel that found the certificate already issued) on `mailboxUid`'s enrollment, if it is the one followed. */
329
+ export function recordEnrollmentResult(mailboxUid: string, enrollmentId: string, result: EnrollmentResult): void {
330
+ const entry = entries.get(mailboxUid);
331
+ if (entry && entry.snapshot.enrollmentId === enrollmentId) {
332
+ apply(entry, result);
333
+ }
334
+ }
335
+
336
+ /** Stops following `mailboxUid`'s enrollment altogether (it was cancelled): nothing is kept, whoever else was watching. */
337
+ export function forgetEnrollment(mailboxUid: string): void {
338
+ const entry = entries.get(mailboxUid);
339
+ if (entry) {
340
+ stop(entry);
341
+ entries.delete(mailboxUid);
342
+ unbindEnvironment();
343
+ emit();
344
+ }
345
+ }
346
+
347
+ /** The current state of `mailboxUid`'s followed enrollment, or `undefined` when none is followed. */
348
+ export function getEnrollmentSnapshot(mailboxUid: string): EnrollmentSnapshot | undefined {
349
+ return entries.get(mailboxUid)?.snapshot;
350
+ }
351
+
352
+ export function subscribeToEnrollments(listener: () => void): () => void {
353
+ listeners.add(listener);
354
+ return () => {
355
+ listeners.delete(listener);
356
+ };
357
+ }
358
+
359
+ /** Called once when an enrollment this browser was following ends (issued or failed) - the frame's watcher raises the pop-up. */
360
+ export function onEnrollmentEnded(listener: (snapshot: EnrollmentSnapshot) => void): () => void {
361
+ terminalListeners.add(listener);
362
+ return () => {
363
+ terminalListeners.delete(listener);
364
+ };
365
+ }
366
+
367
+ /** `mailboxUid`'s followed enrollment, kept current (`undefined` when none is followed). */
368
+ export function useEnrollmentSnapshot(mailboxUid: string | undefined): EnrollmentSnapshot | undefined {
369
+ return useSyncExternalStore(
370
+ subscribeToEnrollments,
371
+ () => (mailboxUid ? getEnrollmentSnapshot(mailboxUid) : undefined),
372
+ () => undefined,
373
+ );
374
+ }
375
+
376
+ /** Forgets everything and stops every timer: for tests, which share the module. */
377
+ export function resetEnrollmentTracker(): void {
378
+ resetSigningInfo();
379
+ entries.forEach(stop);
380
+ entries.clear();
381
+ listeners.clear();
382
+ terminalListeners.clear();
383
+ unbindEnvironment();
384
+ environmentBound = false;
385
+ }
@@ -0,0 +1,251 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import type { EnrollmentResult, SignEnrollmentStage, SignEnrollmentStep } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
6
+ import type { SigningEnrollmentInfo } from "./signingInfo.js";
7
+
8
+ /** Warn about an expiring certificate this many days ahead. */
9
+ export const EXPIRY_WARNING_DAYS = 30;
10
+
11
+ const DAY_MS = 86_400_000;
12
+
13
+ /** Epoch ms of a date the server sent, or `undefined` for a missing or unparseable one. */
14
+ export function timeOf(value: string | number | undefined): number | undefined {
15
+ if (value === undefined) {
16
+ return undefined;
17
+ }
18
+ const time = typeof value === "number" ? value : Date.parse(value);
19
+ return Number.isFinite(time) ? time : undefined;
20
+ }
21
+
22
+ /** "just now", "20 s ago", "3 min ago", "2 h ago", "4 days ago" - `undefined` when there is no date. A time slightly in the future (clock skew) is "just now". */
23
+ export function relativeTime(value: string | number | undefined, now: number): string | undefined {
24
+ const time = timeOf(value);
25
+ if (time === undefined) {
26
+ return undefined;
27
+ }
28
+ const seconds = Math.max(0, Math.floor((now - time) / 1000));
29
+ if (seconds < 5) {
30
+ return "just now";
31
+ }
32
+ if (seconds < 60) {
33
+ return `${seconds} s ago`;
34
+ }
35
+ const minutes = Math.floor(seconds / 60);
36
+ if (minutes < 60) {
37
+ return `${minutes} min ago`;
38
+ }
39
+ const hours = Math.floor(minutes / 60);
40
+ if (hours < 24) {
41
+ return `${hours} h ago`;
42
+ }
43
+ const days = Math.floor(hours / 24);
44
+ return `${days} ${days === 1 ? "day" : "days"} ago`;
45
+ }
46
+
47
+ /** A calendar date in the reader's language ("21 Sep 2027"); the raw text if it is not a date. */
48
+ export function formatDate(value: string | number | undefined): string {
49
+ const time = timeOf(value);
50
+ if (time === undefined) {
51
+ return typeof value === "string" ? value : "";
52
+ }
53
+ return new Date(time).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
54
+ }
55
+
56
+ /** A date and time for a step's timestamp. */
57
+ export function formatDateTime(value: string | number | undefined): string {
58
+ const time = timeOf(value);
59
+ if (time === undefined) {
60
+ return typeof value === "string" ? value : "";
61
+ }
62
+ return new Date(time).toLocaleString(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
63
+ }
64
+
65
+ /** A long serial number as `0A1B2C3D...9F8E7D` (the whole value is what gets copied). */
66
+ export function truncateSerial(serial: string, keep = 8): string {
67
+ return serial.length > keep * 2 + 3 ? `${serial.slice(0, keep)}...${serial.slice(-keep)}` : serial;
68
+ }
69
+
70
+ export type ExpiryState = "ok" | "soon" | "expired" | "unknown";
71
+
72
+ /** How long a certificate has left: `soon` inside `EXPIRY_WARNING_DAYS`, `expired` once past. */
73
+ export function expiryOf(notAfter: string | number | undefined, now: number): { state: ExpiryState; daysLeft?: number } {
74
+ const time = timeOf(notAfter);
75
+ if (time === undefined) {
76
+ return { state: "unknown" };
77
+ }
78
+ if (time <= now) {
79
+ return { state: "expired", daysLeft: 0 };
80
+ }
81
+ const daysLeft = Math.ceil((time - now) / DAY_MS);
82
+ return { state: daysLeft <= EXPIRY_WARNING_DAYS ? "soon" : "ok", daysLeft };
83
+ }
84
+
85
+ /** The order the server's steps normally go in, with the words for a server that names a stage but not the steps. */
86
+ const STAGE_STEPS: { stage: SignEnrollmentStage; label: string }[] = [
87
+ { stage: "submitted", label: "Request sent to the certificate authority" },
88
+ { stage: "awaiting-challenge", label: "Verification e-mail from the CA" },
89
+ { stage: "challenge-answered", label: "Verification answered" },
90
+ { stage: "validating", label: "CA validates the answer" },
91
+ { stage: "issuing", label: "Certificate issued and installed" },
92
+ ];
93
+
94
+ /** What each stage means, for the line under the bar. */
95
+ const STAGE_TEXT: Record<SignEnrollmentStage, string> = {
96
+ submitted: "Request sent - waiting for the certificate authority to answer",
97
+ "awaiting-challenge": "Waiting for the CA's verification e-mail",
98
+ "challenge-answered": "Verification answered - waiting for the certificate",
99
+ validating: "The CA is validating the answer",
100
+ issuing: "The certificate is being issued",
101
+ issued: "Issued",
102
+ failed: "Failed",
103
+ };
104
+
105
+ /**
106
+ * The steps to draw: the server's own `stages` when it sent them, else - for a server that only says which `stage` it is at - the usual five
107
+ * with everything before it done and it active, else none (an older server: the card falls back to a plain sentence).
108
+ */
109
+ export function stepsOf(result: EnrollmentResult | null | undefined): SignEnrollmentStep[] {
110
+ if (!result) {
111
+ return [];
112
+ }
113
+ if (result.stages && result.stages.length > 0) {
114
+ return result.stages;
115
+ }
116
+ if (!result.stage) {
117
+ return [];
118
+ }
119
+ const index = STAGE_STEPS.findIndex((step) => step.stage === result.stage);
120
+ const failed = result.stage === "failed" || result.status === "failed";
121
+ const issued = result.stage === "issued" || result.status === "issued";
122
+ // An issued enrollment has done every step; a failed one stopped at an unknown step, so none is claimed done or active.
123
+ return STAGE_STEPS.map((step, position): SignEnrollmentStep => {
124
+ if (issued) {
125
+ return { id: step.stage, label: step.label, state: "done" };
126
+ }
127
+ if (failed || index === -1) {
128
+ return { id: step.stage, label: step.label, state: "pending" };
129
+ }
130
+ return { id: step.stage, label: step.label, state: position < index ? "done" : position === index ? "active" : "pending" };
131
+ });
132
+ }
133
+
134
+ /** The percentage the bar shows: the server's `progress`, else what the steps say (done steps out of all), else `undefined` - unknown. */
135
+ export function progressOf(result: EnrollmentResult | null | undefined): number | undefined {
136
+ if (!result) {
137
+ return undefined;
138
+ }
139
+ if (typeof result.progress === "number") {
140
+ return Math.round(result.progress);
141
+ }
142
+ if (result.status === "issued") {
143
+ return 100;
144
+ }
145
+ const steps = stepsOf(result);
146
+ return steps.length > 0 ? Math.round((steps.filter((step) => step.state === "done").length / steps.length) * 100) : undefined;
147
+ }
148
+
149
+ /** The step doing the work now, if any. */
150
+ export function activeStepOf(result: EnrollmentResult | null | undefined): SignEnrollmentStep | undefined {
151
+ return stepsOf(result).find((step) => step.state === "active");
152
+ }
153
+
154
+ /**
155
+ * A certificate that is issued but not in the mailbox yet: the server installs it with a job a few minutes after the CA issues it, and says when it
156
+ * has (`installedAt`). An older server sends neither date, so its issued certificates are never "installing".
157
+ */
158
+ export function isInstalling(result: EnrollmentResult | null | undefined): boolean {
159
+ return result?.status === "issued" && !!result.issuedAt && !result.installedAt;
160
+ }
161
+
162
+ /** What the server says about a CA it could not reach: still pending, to be retried - not a failure. */
163
+ export const CA_UNREACHABLE_TEXT = "The certificate authority could not be reached just now - it will be asked again.";
164
+
165
+ /** The plain-language line: what the enrollment is waiting for, when it was issued, why it failed. `undefined` when the server said nothing to go on. */
166
+ export function statusLineOf(result: EnrollmentResult | null | undefined): string | undefined {
167
+ if (!result) {
168
+ return undefined;
169
+ }
170
+ if (result.status === "issued") {
171
+ if (isInstalling(result)) {
172
+ return "Issued - installing it on your mailbox (this takes a few minutes)";
173
+ }
174
+ return result.notAfter ? `Issued - valid until ${formatDate(result.notAfter)}` : "Issued";
175
+ }
176
+ if (result.status === "failed") {
177
+ return `Failed: ${result.error ?? "the certificate authority did not issue a certificate."}`;
178
+ }
179
+ return result.stage ? STAGE_TEXT[result.stage] : undefined;
180
+ }
181
+
182
+ /** What a pending request says when the server has not said how it issues certificates (an older server): nothing that is only true of one way of issuing them. */
183
+ export const PENDING_FALLBACK_TEXT = "Requested - waiting for the certificate. Use Check status to see where the request is.";
184
+
185
+ /** A manual deployment: nobody but an administrator can make the certificate. Never "takes effect automatically". */
186
+ export const MANUAL_ISSUE_TEXT = "This server issues signing certificates manually: an administrator has to upload the certificate for your request. Contact your administrator.";
187
+
188
+ /** The enrollment id the browser kept is one the server does not know any more (another provider after a configuration change, a cancelled request). */
189
+ export const STALE_REQUEST_TEXT = "This request is no longer active - request a new certificate.";
190
+
191
+ /** How a request is being turned into a certificate: by a public CA on its own, by an administrator, or not known. The enrollment's own `provider` wins over what the deployment says now. */
192
+ export type IssueMode = "automatic" | "manual" | "unknown";
193
+
194
+ export function issueModeOf(result: EnrollmentResult | null | undefined, info: SigningEnrollmentInfo | null | undefined): IssueMode {
195
+ const provider = result?.provider;
196
+ if (provider === "manual" || (!provider && info?.backend === "manual")) {
197
+ return "manual";
198
+ }
199
+ if (provider === "rfc8823" || (!provider && info?.automatic)) {
200
+ return "automatic";
201
+ }
202
+ return "unknown";
203
+ }
204
+
205
+ function minutes(count: number): string {
206
+ return `${count} ${count === 1 ? "minute" : "minutes"}`;
207
+ }
208
+
209
+ /** "Requested from ca.example. The CA sends a verification e-mail to jane@example.com; this usually takes about 5 minutes." - each part only as far as it is known. */
210
+ export function requestedFromText(info: SigningEnrollmentInfo | null | undefined, address: string | undefined): string {
211
+ const host = info?.ca?.host ? `Requested from ${info.ca.host}.` : "Requested from the certificate authority.";
212
+ const sentence = `The CA sends a verification e-mail to ${address ?? "this mailbox"}`;
213
+ const duration = info?.typicalDurationMinutes ? `; this usually takes about ${minutes(info.typicalDurationMinutes)}` : "";
214
+ return `${host} ${sentence}${duration}.`;
215
+ }
216
+
217
+ /** What to say before anyone has asked for a certificate: how this deployment will issue it (or that it does not). `undefined` when nothing is known. */
218
+ export function beforeRequestText(info: SigningEnrollmentInfo | null | undefined, address: string | undefined): string | undefined {
219
+ if (!info || info.backend === "none") {
220
+ return info ? "This server does not issue signing certificates." : undefined;
221
+ }
222
+ if (info.backend === "manual") {
223
+ return MANUAL_ISSUE_TEXT;
224
+ }
225
+ const from = info.ca?.host ?? "a public certificate authority";
226
+ const duration = info.typicalDurationMinutes ? `, usually within about ${minutes(info.typicalDurationMinutes)}` : "";
227
+ return `A certificate is issued automatically by ${from}: it sends a verification e-mail to ${address ?? "this mailbox"}${duration}.`;
228
+ }
229
+
230
+ /** The warning when the CA has been reporting a problem: what it said and when it last worked. `undefined` when it has not. */
231
+ export function healthWarning(info: SigningEnrollmentInfo | null | undefined): string | undefined {
232
+ const error = info?.health?.lastError;
233
+ if (!error) {
234
+ return undefined;
235
+ }
236
+ const last = info.health!.lastSuccessAt ? formatDateTime(info.health!.lastSuccessAt) : "never";
237
+ return `The certificate authority reported a problem: ${error} (last successful contact ${last})`;
238
+ }
239
+
240
+ /** A pending request is "taking longer than expected" after this long without a change. */
241
+ export const OVERDUE_AFTER_MS = 60 * 60_000;
242
+
243
+ /** Whether a pending request was made more than an hour ago and nothing has changed in the last hour: say so instead of staying silent. */
244
+ export function isOverdue(result: EnrollmentResult | null | undefined, now: number): boolean {
245
+ if (result?.status !== "pending") {
246
+ return false;
247
+ }
248
+ const requested = timeOf(result.requestedAt);
249
+ const changed = timeOf(result.updatedAt) ?? requested;
250
+ return requested !== undefined && changed !== undefined && now - requested > OVERDUE_AFTER_MS && now - changed > OVERDUE_AFTER_MS;
251
+ }