@rapidmx/web-client 0.20.0 → 0.21.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 (118) hide show
  1. package/README.md +381 -381
  2. package/apps/admin/branding/index.tsx +39 -39
  3. package/apps/admin/data-requests/index.tsx +482 -482
  4. package/apps/admin/domains/[uid].tsx +166 -166
  5. package/apps/admin/escrow-scopes/[uid].tsx +350 -350
  6. package/apps/admin/index.tsx +129 -129
  7. package/apps/admin/mailboxes/[uid].tsx +271 -271
  8. package/apps/admin/mailboxes/new/index.tsx +30 -30
  9. package/apps/admin/plugins/index.tsx +15 -15
  10. package/apps/admin/retention-policy/index.tsx +39 -39
  11. package/apps/admin/signing-certificates/index.tsx +343 -343
  12. package/apps/escrow/audit-log/index.tsx +196 -196
  13. package/apps/escrow/matters/[uid].tsx +621 -621
  14. package/apps/shared/auth/adminAccess.ts +99 -99
  15. package/apps/shared/components/admin/layout/AdminShell.tsx +384 -384
  16. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -238
  17. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  18. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -194
  19. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  20. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  21. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  22. package/apps/shared/components/admin/settings/PluginsManager.tsx +2093 -2093
  23. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  24. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  25. package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -446
  26. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  27. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  28. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  29. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  30. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  31. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  32. package/apps/shared/components/calendar/allDay.ts +124 -124
  33. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  34. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -103
  35. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  36. package/apps/shared/components/layout/AppShell.tsx +463 -461
  37. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  38. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  39. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  40. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  41. package/apps/shared/components/layout/UserMenu.tsx +439 -439
  42. package/apps/shared/components/mail/ConversationList.tsx +332 -332
  43. package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -613
  44. package/apps/shared/components/mail/MailSelectionBar.tsx +240 -240
  45. package/apps/shared/components/mail/MenuButton.tsx +404 -404
  46. package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1757
  47. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  48. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  49. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1705 -1681
  50. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  51. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  52. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  53. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -258
  54. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -79
  55. package/apps/shared/components/mail/reading/messageExport.ts +59 -59
  56. package/apps/shared/components/mail/reading/printMessage.ts +99 -99
  57. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -443
  58. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  59. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  60. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  61. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  62. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  63. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  64. package/apps/shared/keyboard/dispatch.ts +124 -124
  65. package/apps/shared/keyboard/format.ts +89 -89
  66. package/apps/shared/keyboard/keymap.ts +114 -114
  67. package/apps/shared/keyboard/registry.ts +65 -65
  68. package/apps/shared/keyboard/targets.ts +79 -79
  69. package/apps/shared/mail/folderOfType.ts +49 -49
  70. package/apps/shared/mail/folderTree.ts +143 -143
  71. package/apps/shared/mail/listAllPages.ts +39 -39
  72. package/apps/shared/mail/newMailNotifications.ts +171 -171
  73. package/apps/shared/mail/outbox/sendJob.ts +445 -445
  74. package/apps/shared/mail/outbox/sendOutcomes.ts +155 -155
  75. package/apps/shared/mail/reportNotices.ts +66 -66
  76. package/apps/shared/mail/senderBlocking.ts +141 -141
  77. package/apps/shared/mail/useMailConnection.ts +205 -205
  78. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  79. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -60
  80. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  81. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  82. package/apps/shared/notifications/store.ts +560 -560
  83. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  84. package/apps/shared/search/localIndexBuilder.ts +481 -481
  85. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  86. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  87. package/apps/shared/signing/enrollmentView.ts +251 -251
  88. package/apps/shared/signing/useNow.ts +19 -19
  89. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  90. package/apps/shared/styles/app.css +396 -396
  91. package/apps/www/calendar/index.tsx +581 -581
  92. package/apps/www/contacts/[uid].tsx +112 -112
  93. package/apps/www/index.tsx +3012 -3012
  94. package/apps/www/messages/[uid].tsx +139 -139
  95. package/apps/www/settings/auto-reply/index.tsx +136 -136
  96. package/apps/www/settings/blocked-senders/index.tsx +303 -303
  97. package/apps/www/settings/encryption/index.tsx +1290 -1290
  98. package/apps/www/settings/filters/[uid].tsx +179 -179
  99. package/apps/www/settings/filters/index.tsx +105 -105
  100. package/apps/www/settings/filters/new/index.tsx +165 -165
  101. package/apps/www/settings/labels/index.tsx +207 -207
  102. package/apps/www/settings/privacy/index.tsx +495 -495
  103. package/apps/www/settings/profile/index.tsx +251 -251
  104. package/apps/www/settings/read-receipts/index.tsx +150 -150
  105. package/apps/www/settings/sharing/index.tsx +259 -259
  106. package/apps/www/settings/signatures/[uid].tsx +175 -175
  107. package/apps/www/settings/signatures/index.tsx +91 -91
  108. package/apps/www/settings/signatures/new/index.tsx +138 -138
  109. package/apps/www/tasks/index.tsx +654 -654
  110. package/dist/apps/shared/components/admin/layout/AdminShell.js +2 -2
  111. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  112. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +2 -2
  113. package/dist/apps/shared/components/layout/AppShell.js +4 -2
  114. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +7 -1
  115. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +20 -1
  116. package/dist/apps/shared/components/mail/reading/printMessage.js +11 -11
  117. package/dist/apps/shared/styles/app.css +396 -396
  118. package/package.json +2 -2
@@ -1,384 +1,384 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import "../../../styles/app.css";
6
- import React, { PropsWithChildren, ReactNode, useEffect, useState } from "react";
7
- import { useRouter } from "@rapidrest/react/client";
8
- import {
9
- HiOutlineClipboardDocumentList,
10
- HiOutlineClock,
11
- HiOutlineCpuChip,
12
- HiOutlineDocumentArrowDown,
13
- HiOutlineDocumentCheck,
14
- HiOutlineGlobeAlt,
15
- HiOutlineInboxStack,
16
- HiOutlineKey,
17
- HiOutlineLockClosed,
18
- HiOutlinePaintBrush,
19
- HiOutlinePuzzlePiece,
20
- HiOutlineQueueList,
21
- HiOutlineRocketLaunch,
22
- HiOutlineShieldCheck,
23
- HiOutlineShieldExclamation,
24
- HiOutlineUserGroup,
25
- HiOutlineWrenchScrewdriver,
26
- HiOutlineBars3,
27
- } from "react-icons/hi2";
28
- import { apiFetch, ApiRequestError } from "@rapidmx/react-shared/util/api.js";
29
- import { getSetupStatus } from "@rapidmx/react-shared/admin/setupApi.js";
30
- import { useRedirectIfUnauthenticated } from "@rapidmx/react-shared/auth/session.js";
31
- import useBranding from "@rapidmx/react-shared/branding/useBranding.js";
32
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
33
- import Button from "@rapidmx/react-shared/components/buttons/Button.js";
34
- import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
35
- import type { NavItem } from "@rapidmx/react-shared/components/navigation/BottomTabBar.js";
36
- import { FrameBrandingFooter, useBrandingHtml } from "../../layout/BrandingChrome.js";
37
- import RailIcon from "../../layout/RailIcon.js";
38
- import AppearanceProvider from "../../../appearance/AppearanceProvider.js";
39
- import UserMenu from "../../layout/UserMenu.js";
40
- import {
41
- clearElevationAttempt,
42
- elevationAttemptedRecently,
43
- elevationUrl,
44
- isElevationRequired,
45
- recordElevationAttempt,
46
- } from "../elevation.js";
47
- import { signOutOfConsole } from "../signOut.js";
48
- import { mergePluginNavItems, PluginNav, PluginNavProps } from "../../../plugins/pluginNav.js";
49
-
50
- export type AdminSection =
51
- | "mailboxes"
52
- | "quarantine"
53
- | "ingestQueue"
54
- | "domains"
55
- | "auditLog"
56
- | "distributionLists"
57
- | "transportRules"
58
- | "escrowScopes"
59
- | "retentionPolicy"
60
- | "encryptionPolicy"
61
- | "mailboxPolicy"
62
- | "setup"
63
- | "dataRequests"
64
- | "plugins"
65
- | "diagnostics"
66
- | "branding"
67
- | "signingCertificates";
68
-
69
- /** A core `AdminSection`, or a plugin's `adminNav` item id (see `PluginNav`). */
70
- export type AdminShellActive = AdminSection | (string & {});
71
-
72
- export interface AdminShellProps extends PluginNavProps {
73
- /** Which icon in the rail is highlighted as the current section - a plugin admin page passes its own
74
- * `adminNav` item id. */
75
- active: AdminShellActive;
76
- /** Populated automatically by the framework from an authenticated request (e.g. a valid `jwt` cookie). */
77
- userUid?: string;
78
- /** auth-server's base URL, injected via the route's `fetchProps` — see `src/mongo/routes/AdminConsoleRoute.ts`. */
79
- authServerUrl?: string;
80
- /**
81
- * Where `mailApi.ts`'s `impersonateUser()`/`stopImpersonating()` should call: the real auth-server in
82
- * production, or `""` under `yarn dev` to call this app's own local dev-only impersonation endpoint
83
- * instead — see `AdminConsoleRoute`'s `fetchProps` and `src/dev/DevImpersonationRoute.ts`.
84
- */
85
- impersonationBaseUrl?: string;
86
- }
87
-
88
- /** `elevating`: the browser is being sent to auth-server to confirm the user's identity. `elevationFailed`: it was
89
- * sent a moment ago and the console still isn't elevated - see `elevation.ts`. */
90
- type Status = "checking" | "denied" | "elevating" | "elevationFailed" | "error" | "authorized";
91
-
92
- /** Sections shown in the persistent icon rail / mobile tab bar — every admin area reachable from
93
- * anywhere in the console. Deliberately excludes `quarantine`/`ingestQueue`: those are scoped to a
94
- * single mailbox and only ever reached via links on that mailbox's own detail page (see
95
- * `apps/admin/mailboxes/[uid].tsx`), not global navigation destinations. */
96
- const NAV_ITEMS: NavItem[] = [
97
- { id: "mailboxes", href: "/admin", label: "Mailboxes", icon: HiOutlineInboxStack },
98
- { id: "domains", href: "/admin/domains", label: "Domains", icon: HiOutlineGlobeAlt },
99
- { id: "auditLog", href: "/admin/audit-log", label: "Audit Log", icon: HiOutlineClipboardDocumentList },
100
- {
101
- id: "distributionLists",
102
- href: "/admin/distribution-lists",
103
- label: "Distribution Lists",
104
- icon: HiOutlineUserGroup,
105
- },
106
- {
107
- id: "transportRules",
108
- href: "/admin/transport-rules",
109
- label: "Transport Rules",
110
- icon: HiOutlineShieldCheck,
111
- },
112
- {
113
- id: "escrowScopes",
114
- href: "/admin/escrow-scopes",
115
- label: "Escrow Scopes",
116
- icon: HiOutlineKey,
117
- },
118
- {
119
- id: "encryptionPolicy",
120
- href: "/admin/encryption-policy",
121
- label: "Encryption Policy",
122
- icon: HiOutlineLockClosed,
123
- },
124
- {
125
- id: "mailboxPolicy",
126
- href: "/admin/mailbox-policy",
127
- label: "Mailbox Policy",
128
- icon: HiOutlineWrenchScrewdriver,
129
- },
130
- {
131
- id: "retentionPolicy",
132
- href: "/admin/retention-policy",
133
- label: "Retention Policy",
134
- icon: HiOutlineClock,
135
- },
136
- {
137
- id: "dataRequests",
138
- href: "/admin/data-requests",
139
- label: "Data Requests",
140
- icon: HiOutlineDocumentArrowDown,
141
- },
142
- {
143
- id: "signingCertificates",
144
- href: "/admin/signing-certificates",
145
- label: "Signing Certificates",
146
- icon: HiOutlineDocumentCheck,
147
- },
148
- { id: "plugins", href: "/admin/plugins", label: "Plugins", icon: HiOutlinePuzzlePiece },
149
- { id: "diagnostics", href: "/admin/diagnostics", label: "Diagnostics", icon: HiOutlineCpuChip },
150
- { id: "branding", href: "/admin/branding", label: "Branding", icon: HiOutlinePaintBrush },
151
- ];
152
-
153
- /** Mailbox-scoped sections — not part of the global nav rail/tab bar (see `NAV_ITEMS` above), but
154
- * still need an entry here so the header can resolve a label for them when they're the active page. */
155
- const MAILBOX_SCOPED_ITEMS: NavItem[] = [
156
- { id: "quarantine", href: "/admin/quarantine", label: "Quarantine", icon: HiOutlineShieldExclamation },
157
- { id: "ingestQueue", href: "/admin/ingest-queue", label: "Ingest Queue", icon: HiOutlineQueueList },
158
- ];
159
-
160
- /** The setup wizard - reached by redirect or from the Mailboxes page, not from the rail. */
161
- const SETUP_ITEM: NavItem = { id: "setup", href: "/admin/setup", label: "Setup", icon: HiOutlineRocketLaunch };
162
-
163
- const OFF_RAIL_ITEMS: NavItem[] = [...MAILBOX_SCOPED_ITEMS, SETUP_ITEM];
164
-
165
- /** `NAV_ITEMS` followed by the plugins' `adminNav` items (generic icon). Core ids win, including the
166
- * off-rail sections' - see `mergePluginNavItems`. */
167
- export function adminNavItems(pluginNav?: PluginNav): NavItem[] {
168
- return mergePluginNavItems<NavItem>(
169
- NAV_ITEMS,
170
- pluginNav?.adminNav,
171
- ({ id, href, label }) => ({ id, href, label, icon: HiOutlinePuzzlePiece }),
172
- OFF_RAIL_ITEMS.map((item) => item.id),
173
- );
174
- }
175
-
176
- /**
177
- * Gates every `apps/admin` page behind the `admin` trusted role, and behind an elevated session. Uses
178
- * `GET /api/admin/release-notes` (any `BaseAdminRoute` endpoint works — this one is side-effect-free) purely as a
179
- * canary. The endpoint is class-level `@RequiresElevation()`, checked *before* the trusted-role check, so a 200 means the
180
- * caller's JWT is elevated and carries a trusted role: show the console. Otherwise:
181
- *
182
- * 403 `api-104` means the JWT isn't elevated (an administrator's normal sign-in). There is no local step-up form; the
183
- * browser is sent to auth-server's `/auth/elevate?return_to=<this page>`, which returns it here once the user has
184
- * confirmed their identity (or to its own account page if they cancel). Sent at most once per
185
- * `ELEVATION_RETRY_WINDOW_MS`, so an elevated cookie that never reaches this origin can't bounce the browser back
186
- * and forth - see `elevation.ts`, and the "didn't take effect" alert with its own "Try again" below.
187
- *
188
- * 403 `api-103` (elevated, but not an administrator), any other 403, and 401 mean "no administrator access".
189
- */
190
- export default function AdminShell({ active, userUid, authServerUrl, pluginNav, children }: PropsWithChildren<AdminShellProps>) {
191
- const { navigate } = useRouter();
192
- const [status, setStatus] = useState<Status>("checking");
193
- const [error, setError] = useState<string | null>(null);
194
- const [menuOpen, setMenuOpen] = useState(false);
195
- // `branding` only feeds the footer below: the admin-configured header is for the webmail and public pages, not the
196
- // console. `useBranding()` is still what injects the custom stylesheet and supplies the rail's icon.
197
- const { branding, iconSrc } = useBranding();
198
- const footer = useBrandingHtml(branding?.footerHtml);
199
-
200
- useRedirectIfUnauthenticated(userUid, authServerUrl);
201
-
202
- useEffect(() => {
203
- if (!userUid) {
204
- return;
205
- }
206
- apiFetch("/admin/release-notes")
207
- .then(async () => {
208
- // Elevated (or elevation isn't needed): a later expiry of the elevation may send the user round again.
209
- clearElevationAttempt();
210
- // Until first-run setup is finished, every other admin page sends the admin to the wizard. A failed
211
- // check never blocks the console - the admin can still reach setup from the Mailboxes page.
212
- if (active !== "setup") {
213
- try {
214
- if ((await getSetupStatus()).required) {
215
- // Replacing this page in the history, which would otherwise send the back button round again.
216
- void navigate(SETUP_ITEM.href, { replace: true });
217
- return;
218
- }
219
- } catch {
220
- // Fall through to the page.
221
- }
222
- }
223
- setStatus("authorized");
224
- })
225
- .catch((err) => {
226
- if (isElevationRequired(err)) {
227
- // Without auth-server's URL there is nowhere to send the browser to elevate.
228
- if (!authServerUrl) {
229
- setStatus("denied");
230
- } else if (elevationAttemptedRecently()) {
231
- setStatus("elevationFailed");
232
- } else {
233
- startElevation(authServerUrl);
234
- }
235
- return;
236
- }
237
- if (err instanceof ApiRequestError && (err.status === 403 || err.status === 401)) {
238
- setStatus("denied");
239
- return;
240
- }
241
- setError(err instanceof ApiRequestError ? err.message : "Could not verify administrator access.");
242
- setStatus("error");
243
- });
244
- }, [userUid]);
245
-
246
- /** Remembers the attempt, then sends the browser to auth-server to confirm the user's identity. */
247
- function startElevation(authServer: string) {
248
- recordElevationAttempt();
249
- setStatus("elevating");
250
- window.location.href = elevationUrl(authServer, window.location.href);
251
- }
252
-
253
- function handleRetryElevation() {
254
- clearElevationAttempt();
255
- startElevation(authServerUrl!);
256
- }
257
-
258
- function handleSignOut() {
259
- // Ends the auth-server session and tells other tabs, not just navigates - see `signOutOfConsole()`.
260
- void signOutOfConsole(authServerUrl);
261
- }
262
-
263
- let content: ReactNode;
264
- if (!userUid || status === "checking") {
265
- content = <div className="min-h-screen" />;
266
- } else if (status === "elevating") {
267
- content = (
268
- <div className="min-h-screen flex items-center justify-center p-8">
269
- <p role="status" className="text-sm text-text-muted">
270
- Redirecting to confirm your identity&hellip;
271
- </p>
272
- </div>
273
- );
274
- } else if (status === "elevationFailed") {
275
- content = (
276
- <div className="min-h-screen flex items-center justify-center p-8">
277
- <div className="w-full max-w-md flex flex-col items-start">
278
- <Alert>
279
- Confirming your identity didn&rsquo;t take effect, so the administrator console is still locked. Try again,
280
- and if this keeps happening, sign out and sign back in.
281
- </Alert>
282
- <Button type="button" className="!w-auto" onClick={handleRetryElevation}>
283
- Try again
284
- </Button>
285
- </div>
286
- </div>
287
- );
288
- } else if (status === "denied") {
289
- content = (
290
- <div className="min-h-screen flex items-center justify-center p-8">
291
- <div className="w-full max-w-md">
292
- <Alert>You do not have administrator access.</Alert>
293
- </div>
294
- </div>
295
- );
296
- } else if (status === "error") {
297
- content = (
298
- <div className="min-h-screen flex items-center justify-center p-8">
299
- <div className="w-full max-w-md">
300
- <Alert>{error}</Alert>
301
- </div>
302
- </div>
303
- );
304
- } else {
305
- const navItems = adminNavItems(pluginNav);
306
- const activeItem = [...navItems, ...OFF_RAIL_ITEMS].find((item) => item.id === active);
307
- content = (
308
- <div className="rr-frame-bg min-h-screen flex flex-col">
309
- <div className="flex-1 flex min-h-0">
310
- <nav
311
- aria-label="Admin sections"
312
- className="hidden md:flex w-16 shrink-0 bg-surface border-r border-border flex-col items-center pb-3 gap-1"
313
- >
314
- <RailIcon src={iconSrc} />
315
- {navItems.map(({ id, href, label, icon: Icon }) => (
316
- <a
317
- key={id}
318
- href={href}
319
- aria-label={label}
320
- aria-current={id === active ? "page" : undefined}
321
- title={label}
322
- className={[
323
- "w-10 h-10 flex items-center justify-center rounded-sm",
324
- id === active
325
- ? "bg-primary/10 text-primary-dark"
326
- : "text-text-muted hover:bg-surface-alt hover:text-text",
327
- ].join(" ")}
328
- >
329
- <Icon size={20} aria-hidden="true" />
330
- </a>
331
- ))}
332
- </nav>
333
- {/* Below `md` the sections are a menu that slides in from the left: ten or so of them don't fit a bar along the bottom. */}
334
- <Drawer open={menuOpen} onClose={() => setMenuOpen(false)} title="Admin" fullScreen>
335
- <nav aria-label="Admin menu" className="flex flex-col gap-1 -mx-2">
336
- {navItems.map(({ id, href, label, icon: Icon }) => (
337
- <a
338
- key={id}
339
- href={href}
340
- aria-current={id === active ? "page" : undefined}
341
- onClick={() => setMenuOpen(false)}
342
- className={[
343
- "flex items-center gap-3 px-3 py-2.5 rounded-sm text-sm font-medium",
344
- id === active ? "bg-primary/10 text-primary-dark" : "text-text hover:bg-surface-alt",
345
- ].join(" ")}
346
- >
347
- <Icon size={20} aria-hidden="true" />
348
- {label}
349
- </a>
350
- ))}
351
- </nav>
352
- </Drawer>
353
- <div className="flex-1 flex flex-col min-w-0">
354
- <header className="rr-solid sticky top-0 z-30 h-16 shrink-0 bg-surface border-b border-border flex items-center justify-between gap-4 px-4 md:px-6">
355
- <div className="flex items-center gap-2 min-w-0">
356
- <button
357
- type="button"
358
- className="md:hidden shrink-0 w-9 h-9 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text"
359
- aria-label="Open menu"
360
- onClick={() => setMenuOpen(true)}
361
- >
362
- <HiOutlineBars3 size={20} aria-hidden="true" />
363
- </button>
364
- <span className="font-display font-bold text-lg uppercase tracking-wide truncate">{activeItem?.label}</span>
365
- </div>
366
- <UserMenu userUid={userUid} authServerUrl={authServerUrl} onSignOut={handleSignOut} showMailLink />
367
- </header>
368
- <div id="app-content" className="flex-1">
369
- <main className="max-w-6xl mx-auto px-6 py-8">{children}</main>
370
- </div>
371
- </div>
372
- </div>
373
- </div>
374
- );
375
- }
376
-
377
- // The user's own colours and background (`AppearanceProvider`), from what the last webmail page cached in this browser: the console never asks the server.
378
- return (
379
- <AppearanceProvider userUid={userUid} lookUp={false}>
380
- {content}
381
- <FrameBrandingFooter parsed={footer} appTitle={[...adminNavItems(pluginNav), ...OFF_RAIL_ITEMS].find((item) => item.id === active)?.label} />
382
- </AppearanceProvider>
383
- );
384
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import "../../../styles/app.css";
6
+ import React, { PropsWithChildren, ReactNode, useEffect, useState } from "react";
7
+ import { useRouter } from "@rapidrest/react/client";
8
+ import {
9
+ HiOutlineClipboardDocumentList,
10
+ HiOutlineClock,
11
+ HiOutlineCpuChip,
12
+ HiOutlineDocumentArrowDown,
13
+ HiOutlineDocumentCheck,
14
+ HiOutlineGlobeAlt,
15
+ HiOutlineInboxStack,
16
+ HiOutlineKey,
17
+ HiOutlineLockClosed,
18
+ HiOutlinePaintBrush,
19
+ HiOutlinePuzzlePiece,
20
+ HiOutlineQueueList,
21
+ HiOutlineRocketLaunch,
22
+ HiOutlineShieldCheck,
23
+ HiOutlineShieldExclamation,
24
+ HiOutlineUserGroup,
25
+ HiOutlineWrenchScrewdriver,
26
+ HiOutlineBars3,
27
+ } from "react-icons/hi2";
28
+ import { apiFetch, ApiRequestError } from "@rapidmx/react-shared/util/api.js";
29
+ import { getSetupStatus } from "@rapidmx/react-shared/admin/setupApi.js";
30
+ import { useSessionRefresh } from "@rapidmx/react-shared/auth/session.js";
31
+ import useBranding from "@rapidmx/react-shared/branding/useBranding.js";
32
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
33
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
34
+ import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
35
+ import type { NavItem } from "@rapidmx/react-shared/components/navigation/BottomTabBar.js";
36
+ import { FrameBrandingFooter, useBrandingHtml } from "../../layout/BrandingChrome.js";
37
+ import RailIcon from "../../layout/RailIcon.js";
38
+ import AppearanceProvider from "../../../appearance/AppearanceProvider.js";
39
+ import UserMenu from "../../layout/UserMenu.js";
40
+ import {
41
+ clearElevationAttempt,
42
+ elevationAttemptedRecently,
43
+ elevationUrl,
44
+ isElevationRequired,
45
+ recordElevationAttempt,
46
+ } from "../elevation.js";
47
+ import { signOutOfConsole } from "../signOut.js";
48
+ import { mergePluginNavItems, PluginNav, PluginNavProps } from "../../../plugins/pluginNav.js";
49
+
50
+ export type AdminSection =
51
+ | "mailboxes"
52
+ | "quarantine"
53
+ | "ingestQueue"
54
+ | "domains"
55
+ | "auditLog"
56
+ | "distributionLists"
57
+ | "transportRules"
58
+ | "escrowScopes"
59
+ | "retentionPolicy"
60
+ | "encryptionPolicy"
61
+ | "mailboxPolicy"
62
+ | "setup"
63
+ | "dataRequests"
64
+ | "plugins"
65
+ | "diagnostics"
66
+ | "branding"
67
+ | "signingCertificates";
68
+
69
+ /** A core `AdminSection`, or a plugin's `adminNav` item id (see `PluginNav`). */
70
+ export type AdminShellActive = AdminSection | (string & {});
71
+
72
+ export interface AdminShellProps extends PluginNavProps {
73
+ /** Which icon in the rail is highlighted as the current section - a plugin admin page passes its own
74
+ * `adminNav` item id. */
75
+ active: AdminShellActive;
76
+ /** Populated automatically by the framework from an authenticated request (e.g. a valid `jwt` cookie). */
77
+ userUid?: string;
78
+ /** auth-server's base URL, injected via the route's `fetchProps` — see `src/mongo/routes/AdminConsoleRoute.ts`. */
79
+ authServerUrl?: string;
80
+ /**
81
+ * Where `mailApi.ts`'s `impersonateUser()`/`stopImpersonating()` should call: the real auth-server in
82
+ * production, or `""` under `yarn dev` to call this app's own local dev-only impersonation endpoint
83
+ * instead — see `AdminConsoleRoute`'s `fetchProps` and `src/dev/DevImpersonationRoute.ts`.
84
+ */
85
+ impersonationBaseUrl?: string;
86
+ }
87
+
88
+ /** `elevating`: the browser is being sent to auth-server to confirm the user's identity. `elevationFailed`: it was
89
+ * sent a moment ago and the console still isn't elevated - see `elevation.ts`. */
90
+ type Status = "checking" | "denied" | "elevating" | "elevationFailed" | "error" | "authorized";
91
+
92
+ /** Sections shown in the persistent icon rail / mobile tab bar — every admin area reachable from
93
+ * anywhere in the console. Deliberately excludes `quarantine`/`ingestQueue`: those are scoped to a
94
+ * single mailbox and only ever reached via links on that mailbox's own detail page (see
95
+ * `apps/admin/mailboxes/[uid].tsx`), not global navigation destinations. */
96
+ const NAV_ITEMS: NavItem[] = [
97
+ { id: "mailboxes", href: "/admin", label: "Mailboxes", icon: HiOutlineInboxStack },
98
+ { id: "domains", href: "/admin/domains", label: "Domains", icon: HiOutlineGlobeAlt },
99
+ { id: "auditLog", href: "/admin/audit-log", label: "Audit Log", icon: HiOutlineClipboardDocumentList },
100
+ {
101
+ id: "distributionLists",
102
+ href: "/admin/distribution-lists",
103
+ label: "Distribution Lists",
104
+ icon: HiOutlineUserGroup,
105
+ },
106
+ {
107
+ id: "transportRules",
108
+ href: "/admin/transport-rules",
109
+ label: "Transport Rules",
110
+ icon: HiOutlineShieldCheck,
111
+ },
112
+ {
113
+ id: "escrowScopes",
114
+ href: "/admin/escrow-scopes",
115
+ label: "Escrow Scopes",
116
+ icon: HiOutlineKey,
117
+ },
118
+ {
119
+ id: "encryptionPolicy",
120
+ href: "/admin/encryption-policy",
121
+ label: "Encryption Policy",
122
+ icon: HiOutlineLockClosed,
123
+ },
124
+ {
125
+ id: "mailboxPolicy",
126
+ href: "/admin/mailbox-policy",
127
+ label: "Mailbox Policy",
128
+ icon: HiOutlineWrenchScrewdriver,
129
+ },
130
+ {
131
+ id: "retentionPolicy",
132
+ href: "/admin/retention-policy",
133
+ label: "Retention Policy",
134
+ icon: HiOutlineClock,
135
+ },
136
+ {
137
+ id: "dataRequests",
138
+ href: "/admin/data-requests",
139
+ label: "Data Requests",
140
+ icon: HiOutlineDocumentArrowDown,
141
+ },
142
+ {
143
+ id: "signingCertificates",
144
+ href: "/admin/signing-certificates",
145
+ label: "Signing Certificates",
146
+ icon: HiOutlineDocumentCheck,
147
+ },
148
+ { id: "plugins", href: "/admin/plugins", label: "Plugins", icon: HiOutlinePuzzlePiece },
149
+ { id: "diagnostics", href: "/admin/diagnostics", label: "Diagnostics", icon: HiOutlineCpuChip },
150
+ { id: "branding", href: "/admin/branding", label: "Branding", icon: HiOutlinePaintBrush },
151
+ ];
152
+
153
+ /** Mailbox-scoped sections — not part of the global nav rail/tab bar (see `NAV_ITEMS` above), but
154
+ * still need an entry here so the header can resolve a label for them when they're the active page. */
155
+ const MAILBOX_SCOPED_ITEMS: NavItem[] = [
156
+ { id: "quarantine", href: "/admin/quarantine", label: "Quarantine", icon: HiOutlineShieldExclamation },
157
+ { id: "ingestQueue", href: "/admin/ingest-queue", label: "Ingest Queue", icon: HiOutlineQueueList },
158
+ ];
159
+
160
+ /** The setup wizard - reached by redirect or from the Mailboxes page, not from the rail. */
161
+ const SETUP_ITEM: NavItem = { id: "setup", href: "/admin/setup", label: "Setup", icon: HiOutlineRocketLaunch };
162
+
163
+ const OFF_RAIL_ITEMS: NavItem[] = [...MAILBOX_SCOPED_ITEMS, SETUP_ITEM];
164
+
165
+ /** `NAV_ITEMS` followed by the plugins' `adminNav` items (generic icon). Core ids win, including the
166
+ * off-rail sections' - see `mergePluginNavItems`. */
167
+ export function adminNavItems(pluginNav?: PluginNav): NavItem[] {
168
+ return mergePluginNavItems<NavItem>(
169
+ NAV_ITEMS,
170
+ pluginNav?.adminNav,
171
+ ({ id, href, label }) => ({ id, href, label, icon: HiOutlinePuzzlePiece }),
172
+ OFF_RAIL_ITEMS.map((item) => item.id),
173
+ );
174
+ }
175
+
176
+ /**
177
+ * Gates every `apps/admin` page behind the `admin` trusted role, and behind an elevated session. Uses
178
+ * `GET /api/admin/release-notes` (any `BaseAdminRoute` endpoint works — this one is side-effect-free) purely as a
179
+ * canary. The endpoint is class-level `@RequiresElevation()`, checked *before* the trusted-role check, so a 200 means the
180
+ * caller's JWT is elevated and carries a trusted role: show the console. Otherwise:
181
+ *
182
+ * 403 `api-104` means the JWT isn't elevated (an administrator's normal sign-in). There is no local step-up form; the
183
+ * browser is sent to auth-server's `/auth/elevate?return_to=<this page>`, which returns it here once the user has
184
+ * confirmed their identity (or to its own account page if they cancel). Sent at most once per
185
+ * `ELEVATION_RETRY_WINDOW_MS`, so an elevated cookie that never reaches this origin can't bounce the browser back
186
+ * and forth - see `elevation.ts`, and the "didn't take effect" alert with its own "Try again" below.
187
+ *
188
+ * 403 `api-103` (elevated, but not an administrator), any other 403, and 401 mean "no administrator access".
189
+ */
190
+ export default function AdminShell({ active, userUid, authServerUrl, pluginNav, children }: PropsWithChildren<AdminShellProps>) {
191
+ const { navigate } = useRouter();
192
+ const [status, setStatus] = useState<Status>("checking");
193
+ const [error, setError] = useState<string | null>(null);
194
+ const [menuOpen, setMenuOpen] = useState(false);
195
+ // `branding` only feeds the footer below: the admin-configured header is for the webmail and public pages, not the
196
+ // console. `useBranding()` is still what injects the custom stylesheet and supplies the rail's icon.
197
+ const { branding, iconSrc } = useBranding();
198
+ const footer = useBrandingHtml(branding?.footerHtml);
199
+
200
+ useSessionRefresh(userUid, authServerUrl);
201
+
202
+ useEffect(() => {
203
+ if (!userUid) {
204
+ return;
205
+ }
206
+ apiFetch("/admin/release-notes")
207
+ .then(async () => {
208
+ // Elevated (or elevation isn't needed): a later expiry of the elevation may send the user round again.
209
+ clearElevationAttempt();
210
+ // Until first-run setup is finished, every other admin page sends the admin to the wizard. A failed
211
+ // check never blocks the console - the admin can still reach setup from the Mailboxes page.
212
+ if (active !== "setup") {
213
+ try {
214
+ if ((await getSetupStatus()).required) {
215
+ // Replacing this page in the history, which would otherwise send the back button round again.
216
+ void navigate(SETUP_ITEM.href, { replace: true });
217
+ return;
218
+ }
219
+ } catch {
220
+ // Fall through to the page.
221
+ }
222
+ }
223
+ setStatus("authorized");
224
+ })
225
+ .catch((err) => {
226
+ if (isElevationRequired(err)) {
227
+ // Without auth-server's URL there is nowhere to send the browser to elevate.
228
+ if (!authServerUrl) {
229
+ setStatus("denied");
230
+ } else if (elevationAttemptedRecently()) {
231
+ setStatus("elevationFailed");
232
+ } else {
233
+ startElevation(authServerUrl);
234
+ }
235
+ return;
236
+ }
237
+ if (err instanceof ApiRequestError && (err.status === 403 || err.status === 401)) {
238
+ setStatus("denied");
239
+ return;
240
+ }
241
+ setError(err instanceof ApiRequestError ? err.message : "Could not verify administrator access.");
242
+ setStatus("error");
243
+ });
244
+ }, [userUid]);
245
+
246
+ /** Remembers the attempt, then sends the browser to auth-server to confirm the user's identity. */
247
+ function startElevation(authServer: string) {
248
+ recordElevationAttempt();
249
+ setStatus("elevating");
250
+ window.location.href = elevationUrl(authServer, window.location.href);
251
+ }
252
+
253
+ function handleRetryElevation() {
254
+ clearElevationAttempt();
255
+ startElevation(authServerUrl!);
256
+ }
257
+
258
+ function handleSignOut() {
259
+ // Ends the auth-server session and tells other tabs, not just navigates - see `signOutOfConsole()`.
260
+ void signOutOfConsole(authServerUrl);
261
+ }
262
+
263
+ let content: ReactNode;
264
+ if (!userUid || status === "checking") {
265
+ content = <div className="min-h-screen" />;
266
+ } else if (status === "elevating") {
267
+ content = (
268
+ <div className="min-h-screen flex items-center justify-center p-8">
269
+ <p role="status" className="text-sm text-text-muted">
270
+ Redirecting to confirm your identity&hellip;
271
+ </p>
272
+ </div>
273
+ );
274
+ } else if (status === "elevationFailed") {
275
+ content = (
276
+ <div className="min-h-screen flex items-center justify-center p-8">
277
+ <div className="w-full max-w-md flex flex-col items-start">
278
+ <Alert>
279
+ Confirming your identity didn&rsquo;t take effect, so the administrator console is still locked. Try again,
280
+ and if this keeps happening, sign out and sign back in.
281
+ </Alert>
282
+ <Button type="button" className="!w-auto" onClick={handleRetryElevation}>
283
+ Try again
284
+ </Button>
285
+ </div>
286
+ </div>
287
+ );
288
+ } else if (status === "denied") {
289
+ content = (
290
+ <div className="min-h-screen flex items-center justify-center p-8">
291
+ <div className="w-full max-w-md">
292
+ <Alert>You do not have administrator access.</Alert>
293
+ </div>
294
+ </div>
295
+ );
296
+ } else if (status === "error") {
297
+ content = (
298
+ <div className="min-h-screen flex items-center justify-center p-8">
299
+ <div className="w-full max-w-md">
300
+ <Alert>{error}</Alert>
301
+ </div>
302
+ </div>
303
+ );
304
+ } else {
305
+ const navItems = adminNavItems(pluginNav);
306
+ const activeItem = [...navItems, ...OFF_RAIL_ITEMS].find((item) => item.id === active);
307
+ content = (
308
+ <div className="rr-frame-bg min-h-screen flex flex-col">
309
+ <div className="flex-1 flex min-h-0">
310
+ <nav
311
+ aria-label="Admin sections"
312
+ className="hidden md:flex w-16 shrink-0 bg-surface border-r border-border flex-col items-center pb-3 gap-1"
313
+ >
314
+ <RailIcon src={iconSrc} />
315
+ {navItems.map(({ id, href, label, icon: Icon }) => (
316
+ <a
317
+ key={id}
318
+ href={href}
319
+ aria-label={label}
320
+ aria-current={id === active ? "page" : undefined}
321
+ title={label}
322
+ className={[
323
+ "w-10 h-10 flex items-center justify-center rounded-sm",
324
+ id === active
325
+ ? "bg-primary/10 text-primary-dark"
326
+ : "text-text-muted hover:bg-surface-alt hover:text-text",
327
+ ].join(" ")}
328
+ >
329
+ <Icon size={20} aria-hidden="true" />
330
+ </a>
331
+ ))}
332
+ </nav>
333
+ {/* Below `md` the sections are a menu that slides in from the left: ten or so of them don't fit a bar along the bottom. */}
334
+ <Drawer open={menuOpen} onClose={() => setMenuOpen(false)} title="Admin" fullScreen>
335
+ <nav aria-label="Admin menu" className="flex flex-col gap-1 -mx-2">
336
+ {navItems.map(({ id, href, label, icon: Icon }) => (
337
+ <a
338
+ key={id}
339
+ href={href}
340
+ aria-current={id === active ? "page" : undefined}
341
+ onClick={() => setMenuOpen(false)}
342
+ className={[
343
+ "flex items-center gap-3 px-3 py-2.5 rounded-sm text-sm font-medium",
344
+ id === active ? "bg-primary/10 text-primary-dark" : "text-text hover:bg-surface-alt",
345
+ ].join(" ")}
346
+ >
347
+ <Icon size={20} aria-hidden="true" />
348
+ {label}
349
+ </a>
350
+ ))}
351
+ </nav>
352
+ </Drawer>
353
+ <div className="flex-1 flex flex-col min-w-0">
354
+ <header className="rr-solid sticky top-0 z-30 h-16 shrink-0 bg-surface border-b border-border flex items-center justify-between gap-4 px-4 md:px-6">
355
+ <div className="flex items-center gap-2 min-w-0">
356
+ <button
357
+ type="button"
358
+ className="md:hidden shrink-0 w-9 h-9 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text"
359
+ aria-label="Open menu"
360
+ onClick={() => setMenuOpen(true)}
361
+ >
362
+ <HiOutlineBars3 size={20} aria-hidden="true" />
363
+ </button>
364
+ <span className="font-display font-bold text-lg uppercase tracking-wide truncate">{activeItem?.label}</span>
365
+ </div>
366
+ <UserMenu userUid={userUid} authServerUrl={authServerUrl} onSignOut={handleSignOut} showMailLink />
367
+ </header>
368
+ <div id="app-content" className="flex-1">
369
+ <main className="max-w-6xl mx-auto px-6 py-8">{children}</main>
370
+ </div>
371
+ </div>
372
+ </div>
373
+ </div>
374
+ );
375
+ }
376
+
377
+ // The user's own colours and background (`AppearanceProvider`), from what the last webmail page cached in this browser: the console never asks the server.
378
+ return (
379
+ <AppearanceProvider userUid={userUid} lookUp={false}>
380
+ {content}
381
+ <FrameBrandingFooter parsed={footer} appTitle={[...adminNavItems(pluginNav), ...OFF_RAIL_ITEMS].find((item) => item.id === active)?.label} />
382
+ </AppearanceProvider>
383
+ );
384
+ }