From da856184b48ccaf4597a4ccfd21c32ae057097e5 Mon Sep 17 00:00:00 2001 From: Alejandro Aspinwall Date: Wed, 18 Nov 2026 14:22:50 -0500 Subject: [PATCH 01/11] Resolve the Accounts downtime banner URL from the webmail hostname. (#261) --- .env.local.example | 4 ++++ src/defines.ts | 7 +++++++ src/env.d.ts | 1 + 3 files changed, 12 insertions(+) diff --git a/.env.local.example b/.env.local.example index 56763be8..fe76c8b2 100644 --- a/.env.local.example +++ b/.env.local.example @@ -19,3 +19,7 @@ # WS auth proxy (run: npm run stack:ws-proxy) # UPSTREAM_BASE=http://127.0.0.1:8081 + +# Downtime banner from the local Accounts stack; it shows while +# LOGIN_BANNER_JSON is set on the stack's accounts service: +# VITE_BANNER_URL=http://localhost:8087/api/v1/status/banner/ diff --git a/src/defines.ts b/src/defines.ts index 397ade90..8e0a9734 100644 --- a/src/defines.ts +++ b/src/defines.ts @@ -54,6 +54,13 @@ export function accountsUrlForHostname(hostname = globalThis.location?.hostname) return "https://accounts.stage-thundermail.com"; } +export function defaultBannerUrl(hostname = globalThis.location?.hostname): string { + if (isProdWebmailHostname(hostname)) { + return "https://accounts.tb.pro/api/v1/status/banner/"; + } + return import.meta.env.VITE_BANNER_URL ?? ""; +} + export function appointmentUrlForHostname(hostname = globalThis.location?.hostname): string { if (isProdWebmailHostname(hostname)) { return "https://appointment.tb.pro"; diff --git a/src/env.d.ts b/src/env.d.ts index d72e9062..c5886814 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -20,6 +20,7 @@ interface ImportMetaEnv { readonly VITE_LOCAL_STACK?: string; readonly VITE_SENDER_AVATAR_PROXY_URL?: string; readonly VITE_STAFF_APP_URL?: string; + readonly VITE_BANNER_URL?: string; } interface ImportMeta { From beeb029cabaab8843ba62086dbcd02e0b8230d8c Mon Sep 17 00:00:00 2001 From: Alejandro Aspinwall Date: Wed, 18 Nov 2026 14:23:20 -0500 Subject: [PATCH 02/11] Add a composable that loads the Accounts downtime banner once on mount. (#261) --- src/composables/useDowntimeBanner.ts | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/composables/useDowntimeBanner.ts diff --git a/src/composables/useDowntimeBanner.ts b/src/composables/useDowntimeBanner.ts new file mode 100644 index 00000000..ccd1d7ad --- /dev/null +++ b/src/composables/useDowntimeBanner.ts @@ -0,0 +1,65 @@ +// Port of the Accounts login theme's banner check (thunderbird-accounts#1490); the app never waits on it. +import { onMounted, ref, type Ref } from 'vue'; + +type BannerType = 'info' | 'warning' | 'critical'; + +export interface Banner { + type: BannerType; + message: string; + link: { text: string; href: string } | null; +} + +const BANNER_TYPES: readonly BannerType[] = ['info', 'warning', 'critical']; +const MAX_MESSAGE_LENGTH = 300; + +const isRecord = (value: unknown): value is Record => + typeof value === 'object' && value !== null && !Array.isArray(value); + +function parseTimestamp(value: unknown, field: string): number | null { + if (value === undefined || value === null) return null; + const time = typeof value === 'string' ? Date.parse(value) : NaN; + if (Number.isNaN(time)) throw new Error(`${field} is not a date`); + return time; +} + +function parseLink(value: unknown): Banner['link'] { + if (!isRecord(value) || typeof value.text !== 'string' || !value.text || typeof value.href !== 'string') return null; + try { + const { protocol } = new URL(value.href); + return protocol === 'http:' || protocol === 'https:' ? { text: value.text, href: value.href } : null; + } catch { + return null; + } +} + +function parseBanner(data: unknown, now: number): Banner | null { + if (!isRecord(data)) throw new Error('not an object'); + if (data.enabled !== true) return null; + const { type, message } = data; + if (!BANNER_TYPES.includes(type as BannerType)) throw new Error('unknown type'); + // Code points, matching the server's max_length; String.length counts emoji twice. + if (typeof message !== 'string' || !message.trim() || [...message].length > MAX_MESSAGE_LENGTH) { + throw new Error('invalid message'); + } + const starts = parseTimestamp(data.starts, 'starts'); + const ends = parseTimestamp(data.ends, 'ends'); + if ((starts !== null && now < starts) || (ends !== null && now >= ends)) throw new Error('outside its starts/ends window'); + return { type: type as BannerType, message, link: parseLink(data.link) }; +} + +export function useDowntimeBanner(url: string): { banner: Ref } { + const banner = ref(null); + + onMounted(async () => { + if (!url) return; + try { + const response = await fetch(url, { signal: AbortSignal.timeout(2000), cache: 'no-store', credentials: 'omit' }); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + banner.value = parseBanner(await response.json(), Date.now()); + } catch (error) { + console.warn('[banner] Not showing the downtime banner:', error instanceof Error ? error.message : error); + } + }); + + return { banner }; +} From e1896ed333be1f58e374e8b8eb22e240d832f34c Mon Sep 17 00:00:00 2001 From: Alejandro Aspinwall Date: Wed, 18 Nov 2026 14:28:58 -0500 Subject: [PATCH 03/11] Add a DowntimeBanner component that shows the banner in a services-ui NoticeBar. (#261) --- src/components/DowntimeBanner.vue | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/components/DowntimeBanner.vue diff --git a/src/components/DowntimeBanner.vue b/src/components/DowntimeBanner.vue new file mode 100644 index 00000000..5433d717 --- /dev/null +++ b/src/components/DowntimeBanner.vue @@ -0,0 +1,28 @@ + + + + + From 54d441c77f699dc415edf4cae6183f8533729aa5 Mon Sep 17 00:00:00 2001 From: Alejandro Aspinwall Date: Wed, 18 Nov 2026 14:41:56 -0500 Subject: [PATCH 04/11] Show the downtime banner at the top of both login gate views. (#261) --- src/components/LoginGate.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/LoginGate.vue b/src/components/LoginGate.vue index 8413c192..e0be491d 100644 --- a/src/components/LoginGate.vue +++ b/src/components/LoginGate.vue @@ -4,9 +4,11 @@ import { useOnline } from '@vueuse/core'; import { Loader2 } from '@lucide/vue'; import { NoticeWarningIcon } from '@thunderbirdops/services-ui'; import AppButton from './AppButton.vue'; +import DowntimeBanner from './DowntimeBanner.vue'; import { useAuthStore } from '../stores/auth-store'; import { AUTH_STATE } from '../constants/states'; +import { defaultBannerUrl } from '../defines'; import { hasAutoLoginFlag, withoutAutoLoginFlag } from '../utils/staff-redirect'; import ThundermailLogo from './ThundermailLogo.vue'; @@ -14,6 +16,7 @@ const authStore = useAuthStore(); const username = ref(''); const password = ref(''); const isOnline = useOnline(); +const bannerUrl = defaultBannerUrl(); if (typeof window !== 'undefined' && hasAutoLoginFlag(window.location.search)) { window.history.replaceState(window.history.state, '', withoutAutoLoginFlag(window.location.href)); @@ -50,6 +53,7 @@ onBeforeUnmount(() => window.removeEventListener('pageshow', onPageShow));