From 4b74ee4c2464c81e212bd0c805b10227a7a33114 Mon Sep 17 00:00:00 2001 From: TheRealToxicDev Date: Mon, 19 Oct 2026 01:35:59 -0600 Subject: [PATCH] fix stuff --- CHANGELOG.md | 11 + .../app/(marketing)/stats/opengraph-image.tsx | 13 ++ apps/web/src/app/(marketing)/stats/page.tsx | 215 ++++++++++++++++++ .../app/(marketing)/stats/twitter-image.tsx | 13 ++ .../src/components/marketing/SiteFooter.tsx | 1 + .../server/service/public-stats-service.ts | 141 ++++++++++++ 6 files changed, 394 insertions(+) create mode 100644 apps/web/src/app/(marketing)/stats/opengraph-image.tsx create mode 100644 apps/web/src/app/(marketing)/stats/page.tsx create mode 100644 apps/web/src/app/(marketing)/stats/twitter-image.tsx create mode 100644 apps/web/src/server/service/public-stats-service.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7933575..6e47534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [0.4.2] - 2026-10-19 + +### Added +- **[Open stats](https://bytesend.cloud/stats)** — a public page (Cloud only) with aggregate emails sent, delivery rate, 30-day daily volume, bounce and complaint rates against AWS limits, active sending regions and uptime from the status page. Numbers are cached for an hour and contain no per-team data +- **Status page component locations** — status components can carry an optional location (e.g. `us-east-1` or "N. Virginia"), shown as a badge on the public status page, component pages and the admin component list + +### Fixed +- Status page Open Graph cards for incidents and maintenance now show times in UTC (previously the server's local time, unlabelled) and use brand colours for the Monitoring, Resolved, Scheduled, In Progress and Completed states + +--- + ## [0.4.1] - 2026-10-19 ### Added diff --git a/apps/web/src/app/(marketing)/stats/opengraph-image.tsx b/apps/web/src/app/(marketing)/stats/opengraph-image.tsx new file mode 100644 index 0000000..c1b29a7 --- /dev/null +++ b/apps/web/src/app/(marketing)/stats/opengraph-image.tsx @@ -0,0 +1,13 @@ +import { OG_SIZE, renderBrandCard } from "~/lib/og/brand-card"; + +export const alt = "ByteSend open stats"; +export const size = OG_SIZE; +export const contentType = "image/png"; + +export default function Image() { + return renderBrandCard({ + eyebrow: "Open stats", + title: "ByteSend, by the numbers", + subtitle: "Emails sent, delivery rate and uptime, live.", + }); +} diff --git a/apps/web/src/app/(marketing)/stats/page.tsx b/apps/web/src/app/(marketing)/stats/page.tsx new file mode 100644 index 0000000..eaba485 --- /dev/null +++ b/apps/web/src/app/(marketing)/stats/page.tsx @@ -0,0 +1,215 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { Reveal } from "~/components/marketing/Reveal"; +import { PublicStatsService, type PublicStatsDay } from "~/server/service/public-stats-service"; +import { isCloud } from "~/utils/common"; + +// Reads the database at request time; the numbers themselves are cached for an hour. +export const dynamic = "force-dynamic"; + +export const metadata: Metadata = { + title: "Open stats – ByteSend", + description: "Live, aggregate numbers from ByteSend: emails sent, delivery rate, deliverability health and uptime.", + alternates: { canonical: "https://bytesend.cloud/stats" }, +}; + +const BOUNCE_THRESHOLD = 0.05; +const COMPLAINT_THRESHOLD = 0.001; + +const compact = new Intl.NumberFormat("en-GB", { notation: "compact", maximumFractionDigits: 1 }); +const full = new Intl.NumberFormat("en-GB"); + +function rate(part: number, total: number) { + return total > 0 ? part / total : null; +} + +function formatPercent(value: number | null, digits = 1) { + return value === null ? "—" : `${(value * 100).toFixed(digits)}%`; +} + +function formatDay(date: string) { + return new Date(`${date}T00:00:00Z`).toLocaleDateString("en-GB", { day: "numeric", month: "short", timeZone: "UTC" }); +} + +function StatTile({ value, label, hint }: { value: string; label: string; hint?: string }) { + return ( +
+
{value}
+
{label}
+ {hint &&
{hint}
} +
+ ); +} + +function VolumeChart({ days }: { days: PublicStatsDay[] }) { + const max = Math.max(1, ...days.map((day) => day.sent)); + const width = 600; + const height = 160; + const gap = 4; + const barWidth = (width - gap * (days.length - 1)) / days.length; + + return ( + + + + + + + + {days.map((day, index) => { + const barHeight = day.sent === 0 ? 2 : Math.max(3, (day.sent / max) * height); + return ( + + {`${formatDay(day.date)}: ${full.format(day.sent)} sent`} + + ); + })} + + ); +} + +function HealthRow({ label, value, threshold, description }: { label: string; value: number | null; threshold: number; description: string }) { + const ratio = value === null ? 0 : Math.min(1, value / threshold); + const healthy = value === null || value < threshold / 2; + + return ( +
+
+
{label}
+
+ {formatPercent(value, 2)} + / {formatPercent(threshold, threshold < 0.01 ? 1 : 0)} AWS limit +
+
+
+
+
+

{description}

+
+ ); +} + +export default async function StatsPage() { + if (!isCloud()) notFound(); + + const stats = await PublicStatsService.get(); + const { window } = stats; + const updated = new Date(stats.generatedAt).toLocaleString("en-GB", { + day: "numeric", + month: "short", + hour: "2-digit", + minute: "2-digit", + timeZone: "UTC", + }); + + return ( +
+
+
+
+ + Updated hourly · last refresh {updated} UTC +
+

Open stats

+

+ Live, aggregate numbers across every team on ByteSend Cloud. No customer data, just how the platform is doing. +

+
+
+ +
+
+ + + + + + + + + + + + +
+ + +
+

Daily volume

+ Emails sent per day, last {window.days} days (UTC) +
+
+ +
+ {formatDay(stats.daily[0]!.date)} + {formatDay(stats.daily[stats.daily.length - 1]!.date)} +
+
+
+ +
+ +

Deliverability health

+

+ Shared sending reputation stays healthy because we keep the whole platform well under AWS SES limits. +

+
+ + +
+
+ + +

Sending regions

+

AWS SES regions your domains can send from.

+
    + {stats.regions.map((region) => ( +
  • + {region.label} + {region.code} +
  • + ))} +
+ + Live region status → + +
+
+ +

+ Figures combine transactional and marketing email across all ByteSend Cloud teams. Self-hosted instances are not + included. Rates are calculated against emails sent in the window; days are in UTC. +

+
+
+ ); +} diff --git a/apps/web/src/app/(marketing)/stats/twitter-image.tsx b/apps/web/src/app/(marketing)/stats/twitter-image.tsx new file mode 100644 index 0000000..c1b29a7 --- /dev/null +++ b/apps/web/src/app/(marketing)/stats/twitter-image.tsx @@ -0,0 +1,13 @@ +import { OG_SIZE, renderBrandCard } from "~/lib/og/brand-card"; + +export const alt = "ByteSend open stats"; +export const size = OG_SIZE; +export const contentType = "image/png"; + +export default function Image() { + return renderBrandCard({ + eyebrow: "Open stats", + title: "ByteSend, by the numbers", + subtitle: "Emails sent, delivery rate and uptime, live.", + }); +} diff --git a/apps/web/src/components/marketing/SiteFooter.tsx b/apps/web/src/components/marketing/SiteFooter.tsx index a3ed640..c8ce6d8 100644 --- a/apps/web/src/components/marketing/SiteFooter.tsx +++ b/apps/web/src/components/marketing/SiteFooter.tsx @@ -20,6 +20,7 @@ export function SiteFooter() { diff --git a/apps/web/src/server/service/public-stats-service.ts b/apps/web/src/server/service/public-stats-service.ts new file mode 100644 index 0000000..56b20b4 --- /dev/null +++ b/apps/web/src/server/service/public-stats-service.ts @@ -0,0 +1,141 @@ +import { db } from "../db"; +import { logger } from "../logger/log"; +import { withCache } from "../redis"; + +const DAY_MS = 24 * 60 * 60 * 1000; +const WINDOW_DAYS = 30; +const CACHE_TTL_SECONDS = 60 * 60; +const STATUS_STATS_URL = "https://status.bytesend.cloud/api/status/stats?range=30d"; + +const REGION_LABELS: Record = { + "us-east-1": "US East (N. Virginia)", + "us-east-2": "US East (Ohio)", + "us-west-1": "US West (N. California)", + "us-west-2": "US West (Oregon)", + "ca-central-1": "Canada (Central)", + "eu-west-1": "Europe (Ireland)", + "eu-west-2": "Europe (London)", + "eu-west-3": "Europe (Paris)", + "eu-central-1": "Europe (Frankfurt)", + "eu-north-1": "Europe (Stockholm)", + "eu-south-1": "Europe (Milan)", + "ap-south-1": "Asia Pacific (Mumbai)", + "ap-northeast-1": "Asia Pacific (Tokyo)", + "ap-northeast-2": "Asia Pacific (Seoul)", + "ap-northeast-3": "Asia Pacific (Osaka)", + "ap-southeast-1": "Asia Pacific (Singapore)", + "ap-southeast-2": "Asia Pacific (Sydney)", + "sa-east-1": "South America (São Paulo)", + "me-south-1": "Middle East (Bahrain)", + "af-south-1": "Africa (Cape Town)", +}; + +export type PublicStatsDay = { date: string; sent: number; delivered: number }; + +export type PublicStats = { + generatedAt: string; + allTime: { sent: number; delivered: number }; + window: { + days: number; + sent: number; + delivered: number; + bounced: number; + complained: number; + }; + daily: PublicStatsDay[]; + regions: { code: string; label: string }[]; + uptime: number | null; +}; + +function toDateKey(date: Date) { + return date.toISOString().slice(0, 10); +} + +async function getAllTimeTotals() { + const [row] = await db.$queryRaw>` + SELECT SUM(d.sent)::float8 AS sent, SUM(d.delivered)::float8 AS delivered + FROM "DailyEmailUsage" d + `; + return { sent: row?.sent ?? 0, delivered: row?.delivered ?? 0 }; +} + +async function getDailyUsage(startKey: string) { + return db.$queryRaw< + Array<{ date: string; sent: number; delivered: number; bounced: number; complained: number }> + >` + SELECT + d."date" AS date, + SUM(d.sent)::float8 AS sent, + SUM(d.delivered)::float8 AS delivered, + SUM(d.bounced)::float8 AS bounced, + SUM(d.complained)::float8 AS complained + FROM "DailyEmailUsage" d + WHERE d."date" >= ${startKey} + GROUP BY d."date" + `; +} + +async function getActiveRegions() { + const settings = await db.sesSetting.findMany({ + where: { isActive: true }, + select: { region: true }, + orderBy: { region: "asc" }, + }); + return settings.map(({ region }) => ({ code: region, label: REGION_LABELS[region] ?? region })); +} + +async function getUptime(): Promise { + try { + const res = await fetch(STATUS_STATS_URL, { signal: AbortSignal.timeout(3000), cache: "no-store" }); + if (!res.ok) return null; + const body = (await res.json()) as { uptime?: unknown }; + return typeof body.uptime === "number" ? body.uptime : null; + } catch (error) { + logger.warn({ err: error }, "[PublicStats] Could not fetch uptime from the status page"); + return null; + } +} + +async function computePublicStats(): Promise { + const today = new Date(); + const start = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate()) - (WINDOW_DAYS - 1) * DAY_MS); + const startKey = toDateKey(start); + + const [allTime, usage, regions, uptime] = await Promise.all([ + getAllTimeTotals(), + getDailyUsage(startKey), + getActiveRegions(), + getUptime(), + ]); + + const byDate = new Map(usage.map((row) => [row.date, row])); + const daily = Array.from({ length: WINDOW_DAYS }, (_, i) => { + const date = toDateKey(new Date(start.getTime() + i * DAY_MS)); + const row = byDate.get(date); + return { date, sent: row?.sent ?? 0, delivered: row?.delivered ?? 0 }; + }); + + const window = usage.reduce( + (acc, row) => { + acc.sent += row.sent; + acc.delivered += row.delivered; + acc.bounced += row.bounced; + acc.complained += row.complained; + return acc; + }, + { days: WINDOW_DAYS, sent: 0, delivered: 0, bounced: 0, complained: 0 }, + ); + + return { generatedAt: new Date().toISOString(), allTime, window, daily, regions, uptime }; +} + +export const PublicStatsService = { + async get(): Promise { + try { + return await withCache("public-stats:v1", computePublicStats, { ttlSeconds: CACHE_TTL_SECONDS }); + } catch (error) { + logger.error({ err: error }, "[PublicStats] Cache unavailable, computing directly"); + return computePublicStats(); + } + }, +};