img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function CardAction({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function CardContent({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+export {
+ Card,
+ CardHeader,
+ CardFooter,
+ CardTitle,
+ CardAction,
+ CardDescription,
+ CardContent,
+}
diff --git a/admin/src/components/ui/dialog.tsx b/admin/src/components/ui/dialog.tsx
new file mode 100644
index 0000000..9ddd059
--- /dev/null
+++ b/admin/src/components/ui/dialog.tsx
@@ -0,0 +1,160 @@
+"use client"
+
+import * as React from "react"
+import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
+import { cn } from "@/lib/utils"
+
+import { Button } from "@/components/ui/button"
+import { XIcon } from "lucide-react"
+
+function Dialog({ ...props }: DialogPrimitive.Root.Props) {
+ return
+}
+
+function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
+ return
+}
+
+function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
+ return
+}
+
+function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
+ return
+}
+
+function DialogOverlay({
+ className,
+ ...props
+}: DialogPrimitive.Backdrop.Props) {
+ return (
+
+ )
+}
+
+function DialogContent({
+ className,
+ children,
+ showCloseButton = true,
+ ...props
+}: DialogPrimitive.Popup.Props & {
+ showCloseButton?: boolean
+}) {
+ return (
+
+
+
+ {children}
+ {showCloseButton && (
+
+ }
+ >
+
+ Close
+
+ )}
+
+
+ )
+}
+
+function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+
+ )
+}
+
+function DialogFooter({
+ className,
+ showCloseButton = false,
+ children,
+ ...props
+}: React.ComponentProps<"div"> & {
+ showCloseButton?: boolean
+}) {
+ return (
+
+ {children}
+ {showCloseButton && (
+ }>
+ Close
+
+ )}
+
+ )
+}
+
+function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
+ return (
+
+ )
+}
+
+function DialogDescription({
+ className,
+ ...props
+}: DialogPrimitive.Description.Props) {
+ return (
+
+ )
+}
+
+export {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogOverlay,
+ DialogPortal,
+ DialogTitle,
+ DialogTrigger,
+}
diff --git a/admin/src/components/ui/input.tsx b/admin/src/components/ui/input.tsx
new file mode 100644
index 0000000..1158fea
--- /dev/null
+++ b/admin/src/components/ui/input.tsx
@@ -0,0 +1,19 @@
+import * as React from "react"
+import { Input as InputPrimitive } from "@base-ui/react/input"
+import { cn } from "@/lib/utils"
+
+function Input({ className, type, ...props }: React.ComponentProps<"input">) {
+ return (
+
+ )
+}
+
+export { Input }
diff --git a/admin/src/components/ui/label.tsx b/admin/src/components/ui/label.tsx
new file mode 100644
index 0000000..c9e74c0
--- /dev/null
+++ b/admin/src/components/ui/label.tsx
@@ -0,0 +1,17 @@
+import * as React from "react"
+import { cn } from "@/lib/utils"
+
+function Label({ className, ...props }: React.ComponentProps<"label">) {
+ return (
+
+ )
+}
+
+export { Label }
diff --git a/admin/src/components/ui/select.tsx b/admin/src/components/ui/select.tsx
new file mode 100644
index 0000000..1dee7e4
--- /dev/null
+++ b/admin/src/components/ui/select.tsx
@@ -0,0 +1,200 @@
+"use client"
+
+import * as React from "react"
+import { Select as SelectPrimitive } from "@base-ui/react/select"
+import { cn } from "@/lib/utils"
+import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react"
+
+const Select = SelectPrimitive.Root
+
+function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
+ return (
+
+ )
+}
+
+function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
+ return (
+
+ )
+}
+
+function SelectTrigger({
+ className,
+ size = "default",
+ children,
+ ...props
+}: SelectPrimitive.Trigger.Props & {
+ size?: "sm" | "default"
+}) {
+ return (
+
+ {children}
+
+ }
+ />
+
+ )
+}
+
+function SelectContent({
+ className,
+ children,
+ side = "bottom",
+ sideOffset = 4,
+ align = "center",
+ alignOffset = 0,
+ alignItemWithTrigger = true,
+ ...props
+}: SelectPrimitive.Popup.Props &
+ Pick<
+ SelectPrimitive.Positioner.Props,
+ "align" | "alignOffset" | "side" | "sideOffset" | "alignItemWithTrigger"
+ >) {
+ return (
+
+
+
+
+ {children}
+
+
+
+
+ )
+}
+
+function SelectLabel({
+ className,
+ ...props
+}: SelectPrimitive.GroupLabel.Props) {
+ return (
+
+ )
+}
+
+function SelectItem({
+ className,
+ children,
+ ...props
+}: SelectPrimitive.Item.Props) {
+ return (
+
+
+ {children}
+
+
+ }
+ >
+
+
+
+ )
+}
+
+function SelectSeparator({
+ className,
+ ...props
+}: SelectPrimitive.Separator.Props) {
+ return (
+
+ )
+}
+
+function SelectScrollUpButton({
+ className,
+ ...props
+}: React.ComponentProps
) {
+ return (
+
+
+
+ )
+}
+
+function SelectScrollDownButton({
+ className,
+ ...props
+}: React.ComponentProps) {
+ return (
+
+
+
+ )
+}
+
+export {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectLabel,
+ SelectScrollDownButton,
+ SelectScrollUpButton,
+ SelectSeparator,
+ SelectTrigger,
+ SelectValue,
+}
diff --git a/admin/src/components/ui/separator.tsx b/admin/src/components/ui/separator.tsx
new file mode 100644
index 0000000..ed5bcef
--- /dev/null
+++ b/admin/src/components/ui/separator.tsx
@@ -0,0 +1,22 @@
+import { Separator as SeparatorPrimitive } from "@base-ui/react/separator"
+import { cn } from "@/lib/utils"
+
+function Separator({
+ className,
+ orientation = "horizontal",
+ ...props
+}: SeparatorPrimitive.Props) {
+ return (
+
+ )
+}
+
+export { Separator }
diff --git a/admin/src/components/ui/sonner.tsx b/admin/src/components/ui/sonner.tsx
new file mode 100644
index 0000000..9280ee5
--- /dev/null
+++ b/admin/src/components/ui/sonner.tsx
@@ -0,0 +1,49 @@
+"use client"
+
+import { useTheme } from "next-themes"
+import { Toaster as Sonner, type ToasterProps } from "sonner"
+import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
+
+const Toaster = ({ ...props }: ToasterProps) => {
+ const { theme = "system" } = useTheme()
+
+ return (
+
+ ),
+ info: (
+
+ ),
+ warning: (
+
+ ),
+ error: (
+
+ ),
+ loading: (
+
+ ),
+ }}
+ style={
+ {
+ "--normal-bg": "var(--popover)",
+ "--normal-text": "var(--popover-foreground)",
+ "--normal-border": "var(--border)",
+ "--border-radius": "var(--radius)",
+ } as React.CSSProperties
+ }
+ toastOptions={{
+ classNames: {
+ toast: "cn-toast",
+ },
+ }}
+ {...props}
+ />
+ )
+}
+
+export { Toaster }
diff --git a/admin/src/components/ui/switch.tsx b/admin/src/components/ui/switch.tsx
new file mode 100644
index 0000000..57c7c26
--- /dev/null
+++ b/admin/src/components/ui/switch.tsx
@@ -0,0 +1,29 @@
+import { Switch as SwitchPrimitive } from "@base-ui/react/switch"
+import { cn } from "@/lib/utils"
+
+function Switch({
+ className,
+ size = "default",
+ ...props
+}: SwitchPrimitive.Root.Props & {
+ size?: "sm" | "default"
+}) {
+ return (
+
+
+
+ )
+}
+
+export { Switch }
diff --git a/admin/src/components/ui/table.tsx b/admin/src/components/ui/table.tsx
new file mode 100644
index 0000000..c02e2af
--- /dev/null
+++ b/admin/src/components/ui/table.tsx
@@ -0,0 +1,115 @@
+"use client"
+
+import * as React from "react"
+import { cn } from "@/lib/utils"
+
+function Table({ className, ...props }: React.ComponentProps<"table">) {
+ return (
+
+ )
+}
+
+function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
+ return (
+
+ )
+}
+
+function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
+ return (
+
+ )
+}
+
+function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
+ return (
+ tr]:last:border-b-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
+ return (
+
+ )
+}
+
+function TableHead({ className, ...props }: React.ComponentProps<"th">) {
+ return (
+ |
+ )
+}
+
+function TableCell({ className, ...props }: React.ComponentProps<"td">) {
+ return (
+ |
+ )
+}
+
+function TableCaption({
+ className,
+ ...props
+}: React.ComponentProps<"caption">) {
+ return (
+
+ )
+}
+
+export {
+ Table,
+ TableHeader,
+ TableBody,
+ TableFooter,
+ TableHead,
+ TableRow,
+ TableCell,
+ TableCaption,
+}
diff --git a/admin/src/components/ui/tabs.tsx b/admin/src/components/ui/tabs.tsx
new file mode 100644
index 0000000..841883a
--- /dev/null
+++ b/admin/src/components/ui/tabs.tsx
@@ -0,0 +1,79 @@
+import { Tabs as TabsPrimitive } from "@base-ui/react/tabs"
+import { cva, type VariantProps } from "class-variance-authority"
+import { cn } from "@/lib/utils"
+
+function Tabs({
+ className,
+ orientation = "horizontal",
+ ...props
+}: TabsPrimitive.Root.Props) {
+ return (
+
+ )
+}
+
+const tabsListVariants = cva(
+ "group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",
+ {
+ variants: {
+ variant: {
+ default: "bg-muted",
+ line: "gap-1 bg-transparent",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ }
+)
+
+function TabsList({
+ className,
+ variant = "default",
+ ...props
+}: TabsPrimitive.List.Props & VariantProps) {
+ return (
+
+ )
+}
+
+function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
+ return (
+
+ )
+}
+
+function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
+ return (
+
+ )
+}
+
+export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }
diff --git a/admin/src/components/ui/textarea.tsx b/admin/src/components/ui/textarea.tsx
new file mode 100644
index 0000000..9662e56
--- /dev/null
+++ b/admin/src/components/ui/textarea.tsx
@@ -0,0 +1,17 @@
+import * as React from "react"
+import { cn } from "@/lib/utils"
+
+function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
+ return (
+
+ )
+}
+
+export { Textarea }
diff --git a/admin/src/index.css b/admin/src/index.css
new file mode 100644
index 0000000..fb3c7e9
--- /dev/null
+++ b/admin/src/index.css
@@ -0,0 +1,130 @@
+@import "tailwindcss";
+@import "tw-animate-css";
+@import "shadcn/tailwind.css";
+@import "@fontsource-variable/geist";
+
+@custom-variant dark (&:is(.dark *));
+
+@theme inline {
+ --font-heading: var(--font-sans);
+ --font-sans: 'Geist Variable', sans-serif;
+ --color-sidebar-ring: var(--sidebar-ring);
+ --color-sidebar-border: var(--sidebar-border);
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
+ --color-sidebar-accent: var(--sidebar-accent);
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
+ --color-sidebar-primary: var(--sidebar-primary);
+ --color-sidebar-foreground: var(--sidebar-foreground);
+ --color-sidebar: var(--sidebar);
+ --color-chart-5: var(--chart-5);
+ --color-chart-4: var(--chart-4);
+ --color-chart-3: var(--chart-3);
+ --color-chart-2: var(--chart-2);
+ --color-chart-1: var(--chart-1);
+ --color-ring: var(--ring);
+ --color-input: var(--input);
+ --color-border: var(--border);
+ --color-destructive: var(--destructive);
+ --color-accent-foreground: var(--accent-foreground);
+ --color-accent: var(--accent);
+ --color-muted-foreground: var(--muted-foreground);
+ --color-muted: var(--muted);
+ --color-secondary-foreground: var(--secondary-foreground);
+ --color-secondary: var(--secondary);
+ --color-primary-foreground: var(--primary-foreground);
+ --color-primary: var(--primary);
+ --color-popover-foreground: var(--popover-foreground);
+ --color-popover: var(--popover);
+ --color-card-foreground: var(--card-foreground);
+ --color-card: var(--card);
+ --color-foreground: var(--foreground);
+ --color-background: var(--background);
+ --radius-sm: calc(var(--radius) * 0.6);
+ --radius-md: calc(var(--radius) * 0.8);
+ --radius-lg: var(--radius);
+ --radius-xl: calc(var(--radius) * 1.4);
+ --radius-2xl: calc(var(--radius) * 1.8);
+ --radius-3xl: calc(var(--radius) * 2.2);
+ --radius-4xl: calc(var(--radius) * 2.6);
+}
+
+:root {
+ --background: oklch(1 0 0);
+ --foreground: oklch(0.145 0 0);
+ --card: oklch(1 0 0);
+ --card-foreground: oklch(0.145 0 0);
+ --popover: oklch(1 0 0);
+ --popover-foreground: oklch(0.145 0 0);
+ --primary: oklch(0.205 0 0);
+ --primary-foreground: oklch(0.985 0 0);
+ --secondary: oklch(0.97 0 0);
+ --secondary-foreground: oklch(0.205 0 0);
+ --muted: oklch(0.97 0 0);
+ --muted-foreground: oklch(0.556 0 0);
+ --accent: oklch(0.97 0 0);
+ --accent-foreground: oklch(0.205 0 0);
+ --destructive: oklch(0.577 0.245 27.325);
+ --border: oklch(0.922 0 0);
+ --input: oklch(0.922 0 0);
+ --ring: oklch(0.708 0 0);
+ --chart-1: oklch(0.87 0 0);
+ --chart-2: oklch(0.556 0 0);
+ --chart-3: oklch(0.439 0 0);
+ --chart-4: oklch(0.371 0 0);
+ --chart-5: oklch(0.269 0 0);
+ --radius: 0.625rem;
+ --sidebar: oklch(0.985 0 0);
+ --sidebar-foreground: oklch(0.145 0 0);
+ --sidebar-primary: oklch(0.205 0 0);
+ --sidebar-primary-foreground: oklch(0.985 0 0);
+ --sidebar-accent: oklch(0.97 0 0);
+ --sidebar-accent-foreground: oklch(0.205 0 0);
+ --sidebar-border: oklch(0.922 0 0);
+ --sidebar-ring: oklch(0.708 0 0);
+}
+
+.dark {
+ --background: oklch(0.145 0 0);
+ --foreground: oklch(0.985 0 0);
+ --card: oklch(0.205 0 0);
+ --card-foreground: oklch(0.985 0 0);
+ --popover: oklch(0.205 0 0);
+ --popover-foreground: oklch(0.985 0 0);
+ --primary: oklch(0.922 0 0);
+ --primary-foreground: oklch(0.205 0 0);
+ --secondary: oklch(0.269 0 0);
+ --secondary-foreground: oklch(0.985 0 0);
+ --muted: oklch(0.269 0 0);
+ --muted-foreground: oklch(0.708 0 0);
+ --accent: oklch(0.269 0 0);
+ --accent-foreground: oklch(0.985 0 0);
+ --destructive: oklch(0.704 0.191 22.216);
+ --border: oklch(1 0 0 / 10%);
+ --input: oklch(1 0 0 / 15%);
+ --ring: oklch(0.556 0 0);
+ --chart-1: oklch(0.87 0 0);
+ --chart-2: oklch(0.556 0 0);
+ --chart-3: oklch(0.439 0 0);
+ --chart-4: oklch(0.371 0 0);
+ --chart-5: oklch(0.269 0 0);
+ --sidebar: oklch(0.205 0 0);
+ --sidebar-foreground: oklch(0.985 0 0);
+ --sidebar-primary: oklch(0.488 0.243 264.376);
+ --sidebar-primary-foreground: oklch(0.985 0 0);
+ --sidebar-accent: oklch(0.269 0 0);
+ --sidebar-accent-foreground: oklch(0.985 0 0);
+ --sidebar-border: oklch(1 0 0 / 10%);
+ --sidebar-ring: oklch(0.556 0 0);
+}
+
+@layer base {
+ * {
+ @apply border-border outline-ring/50;
+ }
+ body {
+ @apply bg-background text-foreground;
+ }
+ html {
+ @apply font-sans;
+ }
+}
\ No newline at end of file
diff --git a/admin/src/lib/api.test.ts b/admin/src/lib/api.test.ts
new file mode 100644
index 0000000..28cfc5f
--- /dev/null
+++ b/admin/src/lib/api.test.ts
@@ -0,0 +1,152 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { api, ApiError, session } from './api'
+
+type Call = { url: string; init: RequestInit }
+let calls: Call[]
+
+function respond(status: number, body?: unknown) {
+ return () =>
+ Promise.resolve(
+ new Response(body === undefined ? null : JSON.stringify(body), {
+ status,
+ headers: body === undefined ? {} : { 'Content-Type': 'application/json' },
+ }),
+ )
+}
+
+function mockFetch(handler: (c: Call) => Promise) {
+ calls = []
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn((url: string, init: RequestInit = {}) => {
+ const c = { url, init }
+ calls.push(c)
+ return handler(c)
+ }),
+ )
+}
+
+beforeEach(() => session.set('secret-token'))
+afterEach(() => {
+ vi.unstubAllGlobals()
+ session.onUnauthorized(null)
+})
+
+describe('session', () => {
+ it('keeps the token in sessionStorage only', () => {
+ session.set('abc')
+ expect(sessionStorage.getItem('parsimony.token')).toBe('abc')
+ expect(localStorage.getItem('parsimony.token')).toBeNull()
+ expect(session.get()).toBe('abc')
+ session.clear()
+ expect(session.get()).toBeNull()
+ })
+})
+
+describe('request', () => {
+ it('sends the bearer token and parses JSON', async () => {
+ mockFetch(respond(200, [{ id: 1 }]))
+ const lists = await api.lists.list()
+ expect(lists).toEqual([{ id: 1 }])
+ expect(calls[0].url).toBe('/api/v1/lists')
+ expect((calls[0].init.headers as Record).Authorization).toBe('Bearer secret-token')
+ })
+
+ it('sends JSON bodies with a content type', async () => {
+ mockFetch(respond(201, { id: 2 }))
+ await api.lists.create({ name: 'dev', domain: 'example.org', title: 'Dev' })
+ expect(calls[0].init.method).toBe('POST')
+ expect(JSON.parse(calls[0].init.body as string)).toEqual({ name: 'dev', domain: 'example.org', title: 'Dev' })
+ expect((calls[0].init.headers as Record)['Content-Type']).toBe('application/json')
+ })
+
+ it('returns undefined for 204', async () => {
+ mockFetch(respond(204))
+ await expect(api.lists.remove(3)).resolves.toBeUndefined()
+ expect(calls[0].init.method).toBe('DELETE')
+ expect(calls[0].url).toBe('/api/v1/lists/3')
+ })
+
+ it('throws ApiError with the server message', async () => {
+ mockFetch(respond(409, { error: 'already exists' }))
+ const err = await api.lists.create({ name: 'a', domain: 'b', title: 'c' }).catch((e) => e)
+ expect(err).toBeInstanceOf(ApiError)
+ expect(err.status).toBe(409)
+ expect(err.message).toBe('already exists')
+ })
+
+ it('falls back to a generic message when the body is not JSON', async () => {
+ mockFetch(() => Promise.resolve(new Response('bad gateway', { status: 502 })))
+ const err = await api.lists.list().catch((e) => e)
+ expect(err).toBeInstanceOf(ApiError)
+ expect(err.status).toBe(502)
+ expect(err.message).toMatch(/502/)
+ })
+
+ it('clears the token and notifies on 401', async () => {
+ const onUnauthorized = vi.fn()
+ session.onUnauthorized(onUnauthorized)
+ mockFetch(respond(401, { error: 'invalid or missing token' }))
+ await expect(api.lists.list()).rejects.toMatchObject({ status: 401 })
+ expect(session.get()).toBeNull()
+ expect(onUnauthorized).toHaveBeenCalledTimes(1)
+ })
+
+ it('turns network failures into ApiError', async () => {
+ mockFetch(() => Promise.reject(new TypeError('Failed to fetch')))
+ const err = await api.lists.list().catch((e) => e)
+ expect(err).toBeInstanceOf(ApiError)
+ expect(err.status).toBe(0)
+ expect(err.message).toMatch(/reach the server/i)
+ })
+})
+
+describe('endpoints', () => {
+ it('patches a list with only the given fields', async () => {
+ mockFetch(respond(200, { id: 1 }))
+ await api.lists.update(1, { post_policy: 'moderated' })
+ expect(calls[0].init.method).toBe('PATCH')
+ expect(JSON.parse(calls[0].init.body as string)).toEqual({ post_policy: 'moderated' })
+ })
+
+ it('encodes member addresses in the path', async () => {
+ mockFetch(respond(204))
+ await api.members.remove(1, 'a+b@example.com')
+ expect(calls[0].url).toBe('/api/v1/lists/1/members/a%2Bb%40example.com')
+ })
+
+ it('adds members', async () => {
+ mockFetch(respond(201, { address: 'a@x.com' }))
+ await api.members.add(7, { address: 'a@x.com', display_name: 'A' })
+ expect(calls[0].url).toBe('/api/v1/lists/7/members')
+ expect(JSON.parse(calls[0].init.body as string)).toEqual({ address: 'a@x.com', display_name: 'A' })
+ })
+
+ it('approves and discards held messages', async () => {
+ mockFetch(respond(204))
+ await api.held.approve(5)
+ await api.held.discard(5)
+ expect(calls.map((c) => [c.init.method, c.url])).toEqual([
+ ['POST', '/api/v1/held/5/approve'],
+ ['DELETE', '/api/v1/held/5'],
+ ])
+ })
+
+ it('builds the archive query string and skips empty values', async () => {
+ mockFetch(respond(200, { total: 0, messages: [] }))
+ await api.archive.list(2, { q: 'deploy & go', limit: 25, offset: 50 })
+ await api.archive.list(2, { q: '', limit: 25, offset: 0 })
+ expect(calls[0].url).toBe('/api/v1/lists/2/archive?q=deploy+%26+go&limit=25&offset=50')
+ expect(calls[1].url).toBe('/api/v1/lists/2/archive?limit=25&offset=0')
+ })
+
+ it('reads and deletes archived messages', async () => {
+ mockFetch(respond(204))
+ await api.archive.remove(9)
+ await api.archive.get(9).catch(() => undefined)
+ expect(calls.map((c) => [c.init.method, c.url])).toEqual([
+ ['DELETE', '/api/v1/archive/9'],
+ ['GET', '/api/v1/archive/9'],
+ ])
+ })
+})
diff --git a/admin/src/lib/api.ts b/admin/src/lib/api.ts
new file mode 100644
index 0000000..1686a7a
--- /dev/null
+++ b/admin/src/lib/api.ts
@@ -0,0 +1,145 @@
+// Typed client for the Parsimony admin REST API (/api/v1).
+
+export type PostPolicy = 'members' | 'moderated'
+export type JoinPolicy = 'open' | 'closed'
+export type ArchivePolicy = 'public' | 'private' | 'off'
+
+export interface List {
+ id: number
+ name: string
+ domain: string
+ title: string
+ address: string
+ post_policy: PostPolicy
+ join_policy: JoinPolicy
+ archive_policy: ArchivePolicy
+}
+
+export interface Member {
+ address: string
+ display_name: string
+ disabled: boolean
+ bounce_count: number
+}
+
+export interface Held {
+ id: number
+ sender: string
+ subject: string
+ size: number
+ created_at: string
+}
+
+export interface Message {
+ id: number
+ thread_id: number
+ message_id: string
+ in_reply_to?: string
+ subject: string
+ sender: string
+ date: string
+ size: number
+ body?: string
+}
+
+export interface ArchivePage {
+ total: number
+ messages: Message[]
+}
+
+export class ApiError extends Error {
+ readonly status: number
+ constructor(status: number, message: string) {
+ super(message)
+ this.name = 'ApiError'
+ this.status = status
+ }
+}
+
+const TOKEN_KEY = 'parsimony.token'
+let unauthorizedHandler: (() => void) | null = null
+
+/** The bearer token lives in sessionStorage: it dies with the tab. */
+export const session = {
+ get: (): string | null => sessionStorage.getItem(TOKEN_KEY),
+ set: (token: string) => sessionStorage.setItem(TOKEN_KEY, token),
+ clear: () => sessionStorage.removeItem(TOKEN_KEY),
+ /** Called after any 401, once the token has been cleared. */
+ onUnauthorized: (fn: (() => void) | null) => {
+ unauthorizedHandler = fn
+ },
+}
+
+async function request(method: string, path: string, body?: unknown): Promise {
+ const headers: Record = {}
+ const token = session.get()
+ if (token) headers.Authorization = `Bearer ${token}`
+ if (body !== undefined) headers['Content-Type'] = 'application/json'
+
+ let res: Response
+ try {
+ res = await fetch(`/api/v1${path}`, {
+ method,
+ headers,
+ body: body === undefined ? undefined : JSON.stringify(body),
+ })
+ } catch {
+ throw new ApiError(0, 'Cannot reach the server')
+ }
+
+ if (res.status === 401) {
+ session.clear()
+ unauthorizedHandler?.()
+ }
+ if (!res.ok) {
+ let message = `Request failed (${res.status})`
+ try {
+ const data = await res.json()
+ if (typeof data?.error === 'string') message = data.error
+ } catch {
+ // not JSON: keep the generic message
+ }
+ throw new ApiError(res.status, message)
+ }
+ if (res.status === 204) return undefined as T
+ return (await res.json()) as T
+}
+
+const enc = encodeURIComponent
+
+export const api = {
+ lists: {
+ list: () => request('GET', '/lists'),
+ get: (id: number) => request('GET', `/lists/${id}`),
+ create: (b: { name: string; domain: string; title?: string }) => request('POST', '/lists', b),
+ update: (
+ id: number,
+ b: Partial>,
+ ) => request('PATCH', `/lists/${id}`, b),
+ remove: (id: number) => request('DELETE', `/lists/${id}`),
+ },
+ members: {
+ list: (listId: number) => request('GET', `/lists/${listId}/members`),
+ add: (listId: number, b: { address: string; display_name?: string }) =>
+ request('POST', `/lists/${listId}/members`, b),
+ remove: (listId: number, address: string) =>
+ request('DELETE', `/lists/${listId}/members/${enc(address)}`),
+ },
+ held: {
+ list: (listId: number) => request('GET', `/lists/${listId}/held`),
+ approve: (id: number) => request('POST', `/held/${id}/approve`),
+ discard: (id: number) => request('DELETE', `/held/${id}`),
+ },
+ archive: {
+ list: (listId: number, p: { q?: string; limit?: number; offset?: number } = {}) => {
+ const qs = new URLSearchParams()
+ if (p.q) qs.set('q', p.q)
+ if (p.limit !== undefined) qs.set('limit', String(p.limit))
+ if (p.offset !== undefined) qs.set('offset', String(p.offset))
+ const s = qs.toString()
+ return request('GET', `/lists/${listId}/archive${s ? `?${s}` : ''}`)
+ },
+ get: (id: number) => request('GET', `/archive/${id}`),
+ remove: (id: number) => request('DELETE', `/archive/${id}`),
+ },
+}
diff --git a/admin/src/lib/auth.tsx b/admin/src/lib/auth.tsx
new file mode 100644
index 0000000..9202167
--- /dev/null
+++ b/admin/src/lib/auth.tsx
@@ -0,0 +1,52 @@
+import { useQueryClient } from '@tanstack/react-query'
+import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
+import { api, session } from '@/lib/api'
+
+interface AuthState {
+ authed: boolean
+ /** Verifies the token against the API and keeps it for this tab. Throws ApiError on failure. */
+ login: (token: string) => Promise
+ logout: () => void
+}
+
+const AuthContext = createContext(null)
+
+export function AuthProvider({ children }: { children: ReactNode }) {
+ const queryClient = useQueryClient()
+ const [authed, setAuthed] = useState(() => session.get() !== null)
+
+ // Any 401 from the API ends the session.
+ useEffect(() => {
+ session.onUnauthorized(() => {
+ setAuthed(false)
+ queryClient.clear()
+ })
+ return () => session.onUnauthorized(null)
+ }, [queryClient])
+
+ const login = useCallback(async (token: string) => {
+ session.set(token)
+ try {
+ await api.lists.list()
+ } catch (e) {
+ session.clear()
+ throw e
+ }
+ setAuthed(true)
+ }, [])
+
+ const logout = useCallback(() => {
+ session.clear()
+ queryClient.clear()
+ setAuthed(false)
+ }, [queryClient])
+
+ const value = useMemo(() => ({ authed, login, logout }), [authed, login, logout])
+ return {children}
+}
+
+export function useAuth(): AuthState {
+ const ctx = useContext(AuthContext)
+ if (!ctx) throw new Error('useAuth must be used inside AuthProvider')
+ return ctx
+}
diff --git a/admin/src/lib/format.test.ts b/admin/src/lib/format.test.ts
new file mode 100644
index 0000000..0d310c0
--- /dev/null
+++ b/admin/src/lib/format.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest'
+import { formatBytes, formatDate } from './format'
+
+describe('formatBytes', () => {
+ it.each([
+ [0, '0 B'],
+ [512, '512 B'],
+ [1023, '1023 B'],
+ [1024, '1.0 KB'],
+ [1536, '1.5 KB'],
+ [10 * 1024, '10 KB'],
+ [1024 * 1024, '1.0 MB'],
+ [25 * 1024 * 1024, '25 MB'],
+ ])('%d -> %s', (n, want) => expect(formatBytes(n)).toBe(want))
+})
+
+describe('formatDate', () => {
+ it('formats ISO dates in UTC, minute precision', () => {
+ expect(formatDate('2030-01-02T03:04:05Z')).toBe('2030-01-02 03:04 UTC')
+ expect(formatDate('2030-01-02T23:59:59+02:00')).toBe('2030-01-02 21:59 UTC')
+ })
+ it('returns the input for something that is not a date', () => {
+ expect(formatDate('garbage')).toBe('garbage')
+ })
+})
diff --git a/admin/src/lib/format.ts b/admin/src/lib/format.ts
new file mode 100644
index 0000000..7b69c59
--- /dev/null
+++ b/admin/src/lib/format.ts
@@ -0,0 +1,16 @@
+const KB = 1024
+const MB = 1024 * KB
+
+/** 1536 -> "1.5 KB". One decimal below 10, none above. */
+export function formatBytes(n: number): string {
+ if (n < KB) return `${n} B`
+ const [value, unit] = n < MB ? [n / KB, 'KB'] : [n / MB, 'MB']
+ return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${unit}`
+}
+
+/** ISO timestamp -> "2030-01-02 03:04 UTC". Unparseable input is returned as is. */
+export function formatDate(iso: string): string {
+ const d = new Date(iso)
+ if (Number.isNaN(d.getTime())) return iso
+ return `${d.toISOString().slice(0, 16).replace('T', ' ')} UTC`
+}
diff --git a/admin/src/lib/utils.ts b/admin/src/lib/utils.ts
new file mode 100644
index 0000000..fed2fe9
--- /dev/null
+++ b/admin/src/lib/utils.ts
@@ -0,0 +1,6 @@
+import { clsx, type ClassValue } from 'clsx'
+import { twMerge } from 'tailwind-merge'
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs))
+}
diff --git a/admin/src/main.tsx b/admin/src/main.tsx
new file mode 100644
index 0000000..e1f8a89
--- /dev/null
+++ b/admin/src/main.tsx
@@ -0,0 +1,23 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { StrictMode } from 'react'
+import { createRoot } from 'react-dom/client'
+import { BrowserRouter } from 'react-router'
+import { App } from './App'
+import { AuthProvider } from './lib/auth'
+import './index.css'
+
+const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } },
+})
+
+createRoot(document.getElementById('root')!).render(
+
+
+
+
+
+
+
+
+ ,
+)
diff --git a/admin/src/pages/ListPage.test.tsx b/admin/src/pages/ListPage.test.tsx
new file mode 100644
index 0000000..4449a7a
--- /dev/null
+++ b/admin/src/pages/ListPage.test.tsx
@@ -0,0 +1,162 @@
+import { screen, waitFor, within } from '@testing-library/react'
+import { describe, expect, it } from 'vitest'
+import { aList, installFakeApi, newState } from '@/test/fakeApi'
+import { renderApp } from '@/test/render'
+
+const dev = () => aList({ id: 1, name: 'dev', title: 'Developers' })
+
+describe('list page', () => {
+ it('shows the list header and the tabs', async () => {
+ installFakeApi(newState({ lists: [dev()] }))
+ renderApp('/lists/1', { token: 'good' })
+ expect(await screen.findByRole('heading', { name: 'dev@example.org' })).toBeInTheDocument()
+ expect(screen.getByText('Developers')).toBeInTheDocument()
+ for (const name of ['Settings', 'Members', 'Held', 'Archive']) {
+ expect(screen.getByRole('tab', { name: new RegExp(`^${name}`) })).toBeInTheDocument()
+ }
+ expect(screen.getByRole('link', { name: /all lists/i })).toHaveAttribute('href', '/')
+ })
+
+ it('says so when the list does not exist', async () => {
+ installFakeApi(newState())
+ renderApp('/lists/42', { token: 'good' })
+ expect(await screen.findByText(/list not found/i)).toBeInTheDocument()
+ })
+
+ it('treats a non-numeric id as not found without calling the API', async () => {
+ const state = installFakeApi(newState())
+ renderApp('/lists/abc', { token: 'good' })
+ expect(await screen.findByText(/list not found/i)).toBeInTheDocument()
+ expect(state.calls).toEqual([])
+ })
+
+ it('moves between tabs', async () => {
+ installFakeApi(newState({ lists: [dev()] }))
+ const { user } = renderApp('/lists/1', { token: 'good' })
+ await user.click(await screen.findByRole('tab', { name: /^members/i }))
+ expect(await screen.findByRole('heading', { name: /members/i, level: 2 })).toBeInTheDocument()
+ expect(screen.getByRole('tab', { name: /^members/i })).toHaveAttribute('aria-selected', 'true')
+ await user.click(screen.getByRole('tab', { name: /^settings/i }))
+ expect(await screen.findByLabelText(/^title$/i)).toBeInTheDocument()
+ })
+
+ it('opens the tab named in the URL', async () => {
+ installFakeApi(newState({ lists: [dev()] }))
+ renderApp('/lists/1/archive', { token: 'good' })
+ expect(await screen.findByRole('tab', { name: /^archive/i })).toHaveAttribute('aria-selected', 'true')
+ })
+
+ it('shows how many messages wait in the held queue', async () => {
+ installFakeApi(
+ newState({
+ lists: [dev()],
+ held: { 1: [{ id: 5, sender: 'a@x.com', subject: 's', size: 10, created_at: '2030-01-01T00:00:00Z' }] },
+ }),
+ )
+ renderApp('/lists/1', { token: 'good' })
+ expect(await screen.findByRole('tab', { name: /^held\s*1$/i })).toBeInTheDocument()
+ })
+})
+
+describe('settings tab', () => {
+ async function setup(list = dev()) {
+ const state = installFakeApi(newState({ lists: [list] }))
+ const ctx = renderApp('/lists/1', { token: 'good' })
+ await screen.findByLabelText(/^title$/i)
+ return { ...ctx, state }
+ }
+
+ it('shows the current settings', async () => {
+ await setup(aList({ id: 1, title: 'Developers', post_policy: 'moderated', join_policy: 'closed', archive_policy: 'public' }))
+ expect(screen.getByLabelText(/^title$/i)).toHaveValue('Developers')
+ expect(screen.getByRole('combobox', { name: /posting/i })).toHaveTextContent(/moderated/i)
+ expect(screen.getByRole('combobox', { name: /joining/i })).toHaveTextContent(/closed/i)
+ expect(screen.getByRole('combobox', { name: /archive/i })).toHaveTextContent(/public/i)
+ })
+
+ it('cannot be saved until something changes', async () => {
+ await setup()
+ expect(screen.getByRole('button', { name: /save changes/i })).toBeDisabled()
+ })
+
+ it('saves only the fields that changed', async () => {
+ const { user, state } = await setup()
+ await user.clear(screen.getByLabelText(/^title$/i))
+ await user.type(screen.getByLabelText(/^title$/i), 'Core developers')
+ await user.click(screen.getByRole('combobox', { name: /posting/i }))
+ await user.click(await screen.findByRole('option', { name: /moderated/i }))
+ await user.click(screen.getByRole('button', { name: /save changes/i }))
+
+ await waitFor(() => expect(state.lists[0].title).toBe('Core developers'))
+ expect(state.lists[0].post_policy).toBe('moderated')
+ expect(state.lists[0].join_policy).toBe('open')
+ expect(state.calls).toContain('PATCH /lists/1')
+ expect(await screen.findByText(/settings saved/i)).toBeInTheDocument()
+ await waitFor(() => expect(screen.getByRole('button', { name: /save changes/i })).toBeDisabled())
+ })
+
+ it('changes the archive policy', async () => {
+ const { user, state } = await setup()
+ await user.click(screen.getByRole('combobox', { name: /archive/i }))
+ await user.click(await screen.findByRole('option', { name: /public/i }))
+ await user.click(screen.getByRole('button', { name: /save changes/i }))
+ await waitFor(() => expect(state.lists[0].archive_policy).toBe('public'))
+ expect(state.lists[0].title).toBe('Developers')
+ })
+
+ it('refuses an empty title', async () => {
+ const { user, state } = await setup()
+ await user.clear(screen.getByLabelText(/^title$/i))
+ await user.click(screen.getByRole('button', { name: /save changes/i }))
+ expect(await screen.findByText(/title is required/i)).toBeInTheDocument()
+ expect(state.calls).not.toContain('PATCH /lists/1')
+ })
+
+ it('shows a server error and keeps the edits', async () => {
+ const { user, state } = await setup()
+ state.fail['PATCH /lists/1'] = { status: 500, error: 'disk full' }
+ await user.type(screen.getByLabelText(/^title$/i), '!')
+ await user.click(screen.getByRole('button', { name: /save changes/i }))
+ expect(await screen.findByRole('alert')).toHaveTextContent('disk full')
+ expect(screen.getByLabelText(/^title$/i)).toHaveValue('Developers!')
+ })
+})
+
+describe('deleting a list', () => {
+ async function setup() {
+ const state = installFakeApi(newState({ lists: [dev(), aList({ id: 2, name: 'news' })] }))
+ const ctx = renderApp('/lists/1', { token: 'good' })
+ await ctx.user.click(await screen.findByRole('button', { name: /delete list/i }))
+ const dialog = await screen.findByRole('alertdialog')
+ return { ...ctx, state, dialog }
+ }
+
+ it('asks for confirmation naming the list, and cancelling deletes nothing', async () => {
+ const { user, state, dialog } = await setup()
+ expect(dialog).toHaveTextContent('dev@example.org')
+ await user.click(within(dialog).getByRole('button', { name: /cancel/i }))
+ await waitFor(() => expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument())
+ expect(state.calls).not.toContain('DELETE /lists/1')
+ expect(state.lists).toHaveLength(2)
+ })
+
+ it('deletes the list and goes back to the overview', async () => {
+ const { user, state, dialog } = await setup()
+ await user.click(within(dialog).getByRole('button', { name: /^delete$/i }))
+ expect(await screen.findByRole('heading', { name: /^lists$/i })).toBeInTheDocument()
+ expect(state.lists.map((l) => l.id)).toEqual([2])
+ // The overview refetches and the modal's aria-hidden is cleaned up asynchronously: wait for both.
+ expect(await screen.findByRole('link', { name: 'news@example.org' })).toBeInTheDocument()
+ await waitFor(() => expect(screen.queryByRole('link', { name: 'dev@example.org' })).not.toBeInTheDocument())
+ })
+
+ it('shows a server error and stays on the page', async () => {
+ const { user, state, dialog } = await setup()
+ state.fail['DELETE /lists/1'] = { status: 500, error: 'locked' }
+ await user.click(within(dialog).getByRole('button', { name: /^delete$/i }))
+ expect(await within(dialog).findByRole('alert')).toHaveTextContent('locked')
+ expect(screen.getByRole('alertdialog')).toBeInTheDocument() // still open: the user can retry
+ expect(screen.getByRole('heading', { name: 'dev@example.org', hidden: true })).toBeInTheDocument()
+ expect(state.lists).toHaveLength(2)
+ })
+})
diff --git a/admin/src/pages/ListPage.tsx b/admin/src/pages/ListPage.tsx
new file mode 100644
index 0000000..4d65251
--- /dev/null
+++ b/admin/src/pages/ListPage.tsx
@@ -0,0 +1,61 @@
+import { useQuery } from '@tanstack/react-query'
+import { Link, Outlet, useLocation, useNavigate, useParams } from 'react-router'
+import { Badge } from '@/components/ui/badge'
+import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
+import { api } from '@/lib/api'
+
+const tabs = ['settings', 'members', 'held', 'archive'] as const
+
+export function ListPage() {
+ const params = useParams()
+ const id = /^\d+$/.test(params.id ?? '') ? Number(params.id) : null
+ const navigate = useNavigate()
+ const { pathname } = useLocation()
+
+ const list = useQuery({ queryKey: ['list', id], queryFn: () => api.lists.get(id!), enabled: id !== null })
+ const held = useQuery({ queryKey: ['held', id], queryFn: () => api.held.list(id!), enabled: id !== null })
+
+ if (id === null || (list.isError && list.error.message === 'not found')) {
+ return
+ }
+ if (list.isPending) return Loading…
+ if (list.isError) return {list.error.message}
+
+ const current = tabs.find((t) => pathname.endsWith(`/${t}`)) ?? 'settings'
+ const heldCount = held.data?.length ?? 0
+
+ return (
+
+
+
+ All lists
+
+
{list.data.address}
+
{list.data.title}
+
+
navigate(t === 'settings' ? `/lists/${id}` : `/lists/${id}/${t}`)}>
+
+ Settings
+ Members
+
+ Held
+ {heldCount > 0 && {heldCount}}
+
+ Archive
+
+
+
+
+ )
+}
+
+function NotFound() {
+ return (
+
+
List not found
+
+ Back to lists
+
+
+ )
+}
diff --git a/admin/src/pages/ListsPage.test.tsx b/admin/src/pages/ListsPage.test.tsx
new file mode 100644
index 0000000..0e8be5c
--- /dev/null
+++ b/admin/src/pages/ListsPage.test.tsx
@@ -0,0 +1,95 @@
+import { screen, waitFor, within } from '@testing-library/react'
+import { describe, expect, it } from 'vitest'
+import { aList, installFakeApi, newState } from '@/test/fakeApi'
+import { renderApp } from '@/test/render'
+
+describe('lists overview', () => {
+ it('shows every list with its policies and links to the detail page', async () => {
+ installFakeApi(
+ newState({
+ lists: [
+ aList({ id: 1, name: 'dev', title: 'Developers', post_policy: 'moderated', archive_policy: 'public' }),
+ aList({ id: 2, name: 'news', title: 'News', join_policy: 'closed' }),
+ ],
+ }),
+ )
+ renderApp('/', { token: 'good' })
+ const dev = await screen.findByRole('link', { name: 'dev@example.org' })
+ expect(dev).toHaveAttribute('href', '/lists/1')
+ expect(screen.getByRole('link', { name: 'news@example.org' })).toHaveAttribute('href', '/lists/2')
+ const row = dev.closest('tr')!
+ expect(within(row).getByText('Developers')).toBeInTheDocument()
+ expect(within(row).getByText('moderated')).toBeInTheDocument()
+ expect(within(row).getByText('public')).toBeInTheDocument()
+ })
+
+ it('has an empty state', async () => {
+ installFakeApi(newState())
+ renderApp('/', { token: 'good' })
+ expect(await screen.findByText(/no lists yet/i)).toBeInTheDocument()
+ })
+
+ it('shows a loading error from the server', async () => {
+ installFakeApi(newState({ fail: { 'GET /lists': { status: 500, error: 'database is locked' } } }))
+ renderApp('/', { token: 'good' })
+ expect(await screen.findByRole('alert')).toHaveTextContent('database is locked')
+ })
+})
+
+describe('creating a list', () => {
+ async function openDialog() {
+ const state = installFakeApi(newState({ lists: [aList()] }))
+ const ctx = renderApp('/', { token: 'good' })
+ await screen.findByText('dev@example.org')
+ await ctx.user.click(screen.getByRole('button', { name: /new list/i }))
+ const dialog = await screen.findByRole('dialog')
+ return { ...ctx, state, dialog }
+ }
+
+ it('creates a list and shows it in the table', async () => {
+ const { user, state, dialog } = await openDialog()
+ await user.type(within(dialog).getByLabelText(/^name$/i), 'ops')
+ await user.type(within(dialog).getByLabelText(/domain/i), 'example.org')
+ await user.type(within(dialog).getByLabelText(/title/i), 'Operations')
+ await user.click(within(dialog).getByRole('button', { name: /create list/i }))
+
+ expect(await screen.findByRole('link', { name: 'ops@example.org' })).toBeInTheDocument()
+ expect(screen.getByText('Operations')).toBeInTheDocument()
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
+ expect(state.calls).toContain('POST /lists')
+ })
+
+ it('needs a name and a domain before calling the API', async () => {
+ const { user, state, dialog } = await openDialog()
+ await user.click(within(dialog).getByRole('button', { name: /create list/i }))
+ expect(await within(dialog).findByText(/name and domain are required/i)).toBeInTheDocument()
+ expect(state.calls).not.toContain('POST /lists')
+ })
+
+ it('rejects names with @ or + before calling the API', async () => {
+ const { user, state, dialog } = await openDialog()
+ await user.type(within(dialog).getByLabelText(/^name$/i), 'a+b')
+ await user.type(within(dialog).getByLabelText(/domain/i), 'example.org')
+ await user.click(within(dialog).getByRole('button', { name: /create list/i }))
+ expect(await within(dialog).findByText(/must not contain/i)).toBeInTheDocument()
+ expect(state.calls).not.toContain('POST /lists')
+ })
+
+ it('shows a duplicate error and keeps the dialog open', async () => {
+ const { user, dialog } = await openDialog()
+ await user.type(within(dialog).getByLabelText(/^name$/i), 'dev')
+ await user.type(within(dialog).getByLabelText(/domain/i), 'example.org')
+ await user.click(within(dialog).getByRole('button', { name: /create list/i }))
+ expect(await within(dialog).findByRole('alert')).toHaveTextContent('already exists')
+ expect(screen.getByRole('dialog')).toBeInTheDocument()
+ })
+
+ it('starts empty each time it opens', async () => {
+ const { user, dialog } = await openDialog()
+ await user.type(within(dialog).getByLabelText(/^name$/i), 'leftover')
+ await user.keyboard('{Escape}')
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
+ await user.click(screen.getByRole('button', { name: /new list/i }))
+ expect(await within(await screen.findByRole('dialog')).findByLabelText(/^name$/i)).toHaveValue('')
+ })
+})
diff --git a/admin/src/pages/ListsPage.tsx b/admin/src/pages/ListsPage.tsx
new file mode 100644
index 0000000..228dd00
--- /dev/null
+++ b/admin/src/pages/ListsPage.tsx
@@ -0,0 +1,53 @@
+import { useQuery } from '@tanstack/react-query'
+import { useState } from 'react'
+import { Link } from 'react-router'
+import { CreateListDialog } from '@/components/CreateListDialog'
+import { Badge } from '@/components/ui/badge'
+import { Button } from '@/components/ui/button'
+import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
+import { api } from '@/lib/api'
+
+export function ListsPage() {
+ const lists = useQuery({ queryKey: ['lists'], queryFn: api.lists.list })
+ const [creating, setCreating] = useState(false)
+ return (
+
+
+
Lists
+
+
+
+ {lists.isPending &&
Loading…
}
+ {lists.isError &&
{lists.error.message}
}
+ {lists.data && lists.data.length === 0 &&
No lists yet.
}
+ {lists.data && lists.data.length > 0 && (
+
+
+
+ Address
+ Title
+ Posting
+ Joining
+ Archive
+
+
+
+ {lists.data.map((l) => (
+
+
+
+ {l.address}
+
+
+ {l.title}
+ {l.post_policy}
+ {l.join_policy}
+ {l.archive_policy}
+
+ ))}
+
+
+ )}
+
+ )
+}
diff --git a/admin/src/pages/LoginPage.tsx b/admin/src/pages/LoginPage.tsx
new file mode 100644
index 0000000..6b1c4c1
--- /dev/null
+++ b/admin/src/pages/LoginPage.tsx
@@ -0,0 +1,63 @@
+import { useState, type FormEvent } from 'react'
+import { Navigate, useLocation } from 'react-router'
+import { Button } from '@/components/ui/button'
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
+import { Input } from '@/components/ui/input'
+import { Label } from '@/components/ui/label'
+import { useAuth } from '@/lib/auth'
+
+export function LoginPage() {
+ const { authed, login } = useAuth()
+ const location = useLocation()
+ const [token, setToken] = useState('')
+ const [error, setError] = useState(null)
+ const [busy, setBusy] = useState(false)
+
+ if (authed) return
+
+ async function submit(e: FormEvent) {
+ e.preventDefault()
+ if (token.trim() === '') {
+ setError('Enter the API token')
+ return
+ }
+ setBusy(true)
+ setError(null)
+ try {
+ await login(token.trim())
+ } catch (err) {
+ setError(err instanceof Error ? err.message : 'Sign in failed')
+ } finally {
+ setBusy(false)
+ }
+ }
+
+ return (
+
+
+
+
+ Sign in
+
+ Use the bearer token of this Parsimony server.
+
+
+
+
+
+
+ )
+}
diff --git a/admin/src/pages/NotFoundPage.tsx b/admin/src/pages/NotFoundPage.tsx
new file mode 100644
index 0000000..8dd0660
--- /dev/null
+++ b/admin/src/pages/NotFoundPage.tsx
@@ -0,0 +1,12 @@
+import { Link } from 'react-router'
+
+export function NotFoundPage() {
+ return (
+
+
Not found
+
+ Back to lists
+
+
+ )
+}
diff --git a/admin/src/tabs/ArchiveTab.test.tsx b/admin/src/tabs/ArchiveTab.test.tsx
new file mode 100644
index 0000000..b255286
--- /dev/null
+++ b/admin/src/tabs/ArchiveTab.test.tsx
@@ -0,0 +1,174 @@
+import { screen, waitFor, within } from '@testing-library/react'
+import { describe, expect, it } from 'vitest'
+import type { Message } from '@/lib/api'
+import { aList, installFakeApi, newState } from '@/test/fakeApi'
+import { renderApp } from '@/test/render'
+
+const msg = (id: number, over: Partial = {}): Message => ({
+ id,
+ thread_id: id,
+ message_id: `<${id}@x>`,
+ subject: `Subject ${id}`,
+ sender: `Sender ${id}`,
+ date: '2030-01-02T03:04:05Z',
+ size: 2048,
+ body: `Body of message ${id}`,
+ ...over,
+})
+
+async function setup(messages: Message[], list = aList({ id: 1, archive_policy: 'private' })) {
+ const state = installFakeApi(newState({ lists: [list], archive: { [list.id]: messages } }))
+ const ctx = renderApp(`/lists/${list.id}/archive`, { token: 'good' })
+ await screen.findByRole('heading', { name: /^archive/i, level: 2 })
+ return { ...ctx, state }
+}
+
+describe('archive tab', () => {
+ it('lists messages with sender, date and size', async () => {
+ await setup([msg(1), msg(2)])
+ const row = (await screen.findByRole('button', { name: 'Subject 1' })).closest('tr')!
+ expect(within(row).getByText('Sender 1')).toBeInTheDocument()
+ expect(within(row).getByText('2030-01-02 03:04 UTC')).toBeInTheDocument()
+ expect(within(row).getByText('2.0 KB')).toBeInTheDocument()
+ expect(screen.getByRole('heading', { name: 'Archive (2)', level: 2 })).toBeInTheDocument()
+ })
+
+ it('has an empty state', async () => {
+ await setup([])
+ expect(await screen.findByText(/no messages archived yet/i)).toBeInTheDocument()
+ })
+
+ it('warns when archiving is off', async () => {
+ await setup([], aList({ id: 1, archive_policy: 'off' }))
+ expect(await screen.findByText(/archiving is off/i)).toBeInTheDocument()
+ })
+
+ it('does not warn when archiving is on', async () => {
+ await setup([msg(1)])
+ await screen.findByRole('button', { name: 'Subject 1' })
+ expect(screen.queryByText(/archiving is off/i)).not.toBeInTheDocument()
+ })
+
+ describe('searching', () => {
+ it('shows only matches and how many', async () => {
+ const { user } = await setup([msg(1, { subject: 'Deploy failed' }), msg(2, { subject: 'Lunch' })])
+ await screen.findByRole('button', { name: 'Lunch' })
+ await user.type(screen.getByRole('searchbox', { name: /search archive/i }), 'deploy')
+ await user.click(screen.getByRole('button', { name: /^search$/i }))
+ expect(await screen.findByText(/1 result for “deploy”/i)).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Deploy failed' })).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Lunch' })).not.toBeInTheDocument()
+ })
+
+ it('submits with Enter and says when nothing matches', async () => {
+ const { user } = await setup([msg(1)])
+ await screen.findByRole('button', { name: 'Subject 1' })
+ await user.type(screen.getByRole('searchbox', { name: /search archive/i }), 'zzz{Enter}')
+ expect(await screen.findByText(/no messages found/i)).toBeInTheDocument()
+ })
+
+ it('clears the search to show everything again', async () => {
+ const { user } = await setup([msg(1, { subject: 'Alpha' }), msg(2, { subject: 'Beta' })])
+ await screen.findByRole('button', { name: 'Beta' })
+ await user.type(screen.getByRole('searchbox', { name: /search archive/i }), 'alpha{Enter}')
+ await waitFor(() => expect(screen.queryByRole('button', { name: 'Beta' })).not.toBeInTheDocument())
+ await user.click(screen.getByRole('button', { name: /clear/i }))
+ expect(await screen.findByRole('button', { name: 'Beta' })).toBeInTheDocument()
+ expect(screen.getByRole('searchbox', { name: /search archive/i })).toHaveValue('')
+ })
+ })
+
+ describe('paging', () => {
+ const many = Array.from({ length: 60 }, (_, i) => msg(i + 1))
+
+ it('shows 25 at a time and moves through the pages', async () => {
+ const { user, state } = await setup(many)
+ await screen.findByRole('button', { name: 'Subject 1' })
+ expect(screen.getAllByRole('button', { name: /^Subject \d+$/ })).toHaveLength(25)
+ expect(screen.getByText('1–25 of 60')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /previous/i })).toBeDisabled()
+
+ await user.click(screen.getByRole('button', { name: /next/i }))
+ expect(await screen.findByText('26–50 of 60')).toBeInTheDocument()
+ // The rows really are the second page, not just the label.
+ expect(await screen.findByRole('button', { name: 'Subject 26' })).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Subject 1' })).not.toBeInTheDocument()
+ expect(state.calls).toContain('GET /lists/1/archive')
+ await user.click(screen.getByRole('button', { name: /next/i }))
+ expect(await screen.findByText('51–60 of 60')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /next/i })).toBeDisabled()
+ await user.click(screen.getByRole('button', { name: /previous/i }))
+ expect(await screen.findByText('26–50 of 60')).toBeInTheDocument()
+ })
+
+ it('goes back to the first page on a new search', async () => {
+ const { user } = await setup(many)
+ await screen.findByText('1–25 of 60')
+ await user.click(screen.getByRole('button', { name: /next/i }))
+ await screen.findByText('26–50 of 60')
+ await user.type(screen.getByRole('searchbox', { name: /search archive/i }), 'subject{Enter}')
+ expect(await screen.findByText('1–25 of 60')).toBeInTheDocument()
+ })
+
+ it('hides the pager when everything fits on one page', async () => {
+ await setup([msg(1)])
+ await screen.findByRole('button', { name: 'Subject 1' })
+ expect(screen.queryByRole('button', { name: /next/i })).not.toBeInTheDocument()
+ })
+ })
+
+ describe('reading a message', () => {
+ async function open(messages = [msg(1, { body: 'Hello world' }), msg(2)]) {
+ const ctx = await setup(messages)
+ await ctx.user.click(await screen.findByRole('button', { name: 'Subject 1' }))
+ return { ...ctx, dialog: await screen.findByRole('dialog') }
+ }
+
+ it('shows the full text as plain text', async () => {
+ const { dialog } = await open()
+ expect(await within(dialog).findByText(/Hello