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