Repository navigation
Description
Phase 5 of epic #158, the last one. Adds /admin/notices plus site-wide banner rendering.
Backend contract (already live)
nemar-cli backend/src/routes/admin/notices.ts behind authMiddleware + adminMiddleware:
GET /admin/notices->{ notices }, all notices including expired,created_at DESCPOST /admin/notices-> 201 + the created notice.message(1-1000),level(info|warning|critical, defaultinfo),scope(all|admins|members, defaultall),expires_at(optional, RFC3339 with offset perz.string().datetime({ offset: true }))DELETE /admin/notices/:id->{ message }, or 404
Plus the public read path, backend/src/index.ts:125:
GET /noticeswithoptionalAuthMiddleware->{ notices }, active only, filtered by role: anonymous seesscope: all; members also seemembers; admins/owners also seeadmins. Fails soft to{ notices: [] }.
Notice = { id, message, level, scope, created_at, expires_at } (migration 0016; expires_at is the only nullable field).
Scope
-
src/lib/notices-api.ts— admin CRUD + public fetch, deadline-bounded like the other admin clients -
src/pages/admin/notices.astro— list, create form, delete with confirmation -
src/pages/api/notices.ts— same-originno-storeJSON endpoint for the banner -
src/components/SiteNotices.astro— stacking banners inBase.astro, one visual tone per level, per-notice dismissal - Enable the Notices tab in
ADMIN_TABS, completing the epic - Unit tests including the real hung-fetch abort path
Rendering decision: client-side fetch, not SSR
The banner must NOT be server-rendered into page HTML. index.astro, discover.astro, and dataset/[id].astro all set real edge-cache headers with long stale-while-revalidate windows (12h on the landing page, 24h on dataset detail). An SSR'd banner would be baked into cached HTML: a new outage notice would not appear for up to s-maxage, and a resolved one would linger for up to the SWR window.
Fetching client-side from a no-store same-origin endpoint keeps page HTML cacheable and the banner always current. On the marketing host the request is anonymous (the session cookie is Domain=app.nemar.org), so the backend returns scope: all only, which is exactly the desired behaviour.
Expiry is computed client-side, deliberately
Per nemar-cli#1024, the backend's active-notice filter compares an ISO-8601 expires_at against SQLite's datetime('now') as strings, so a notice expiring later today is still served as active until the next UTC day. Until that lands, both the banner and the admin list compute expiry themselves. The CLI already does the same (src/commands/admin.ts:5334), so this matches existing behaviour rather than inventing a workaround.
Level vocabulary
level is constrained to info | warning | critical by both the zod enum and migration 0016's CHECK. The three get distinct visual tones (info reads as a tip, warning amber, critical as an outage/maintenance banner). A separate maintenance level would need an upstream migration and is not attempted here.
Activity