CI (.gitea/workflows/ci.yaml): lint → typecheck → vitest w/ coverage → OpenNext build → preview smoke → bundle-size budgets; Node 20; npm ci; artifacts; safe env; D1 dry-run scaffold. Budgets: add scripts/budgets.mjs; TOTAL_STATIC_MAX_BYTES and MAX_ASSET_BYTES thresholds; report top offenders; fail on breach; README CI section. Flags: add lib/flags.ts with typed booleans and safe defaults (ADMIN_ENABLED, ARTISTS_MODULE_ENABLED, UPLOADS_ADMIN_ENABLED, BOOKING_ENABLED, PUBLIC_APPOINTMENT_REQUESTS_ENABLED, REFERENCE_UPLOADS_PUBLIC_ENABLED, DEPOSITS_ENABLED, PUBLIC_DB_ARTISTS_ENABLED, ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED, STRICT_CI_GATES_ENABLED, ISR_CACHE_R2_ENABLED); robust parsing; client provider; unit tests. Wiring: gate Admin shell and admin write APIs (503 JSON on uploads and artists writes); disable booking submit and short-circuit booking mutations when off; render static Hero/Artists when advanced animations off; tests for UI and API guards. Ops: expand docs/prd/rollback-strategy.md with “Feature Flags Operations,” Cloudflare Dashboard and wrangler.toml steps, preview simulation, incident playbook, and post-toggle smoke checklist. Release: add docs/releases/2025-09-19-feature-flags-rollout.md with last-good commit, preview/production flag matrices, rollback notes, and smoke results; link from rollback doc. Chore: fix TS issues (gift-cards boolean handling, Lenis options, tailwind darkMode), remove next-on-pages peer conflict, update package.json scripts, configure Gitea act_runner label, open draft PR to trigger CI. Refs: CI-1, FF-1, FF-2, FF-3, OPS-1 Impact: defaults preserve current behavior; no runtime changes unless flags flipped
11 KiB
Wire Flags to Critical Surfaces — Admin/Booking/Public (FF-2)
Story ID: FF-2
Epic: Feature Flags Framework for Controlled Rollbacks — Brownfield Enhancement
Date: 2025-09-18
Owner: Product Manager (John)
Depends On: FF-1 (lib/flags.ts implemented)
Related Docs:
- docs/prd/epic-feature-flags-controlled-rollbacks.md
- docs/prd/rollback-strategy.md
- docs/brownfield-architecture.md
- docs/brownfield-architecture-booking.md
- docs/brownfield-architecture-public.md
Story Title
Wire Flags to Critical Surfaces — Admin/Booking/Public
User Story
As a site operator,
I want key site areas to respect feature flags,
So that I can safely disable Admin, Booking, or heavy Public UX behaviors immediately during incidents.
Story Context
Existing System Integration
- Integrates with:
- Admin UI at app/admin/* (layouts/pages) and admin-related APIs (app/api/admin/*, app/api/artists, app/api/portfolio, app/api/files, app/api/settings, app/api/users)
- Booking UI at components/booking-form.tsx (mounted by app/book/page.tsx)
- Public UX components for heavy scroll/animation (components/hero-section.tsx, components/artists-section.tsx)
- Technology: Next.js 14 App Router, TypeScript, Zod validations, shadcn/ui, Cloudflare Workers (OpenNext)
- Follows pattern: Conditional rendering/early-return guards, user-friendly fallbacks, HTTP 503 JSON for disabled APIs
- Touch points:
- Admin shell/layout and sensitive routes
- Booking form submission path
- Parallax/scroll-heavy public components
Acceptance Criteria
Functional Requirements
-
Admin Gating
- When ADMIN_ENABLED === false, navigating to any /admin route renders a friendly “Admin temporarily unavailable” page (no stacktrace, no redirect loop).
- Admin uploads routes respect UPLOADS_ADMIN_ENABLED:
- POST/DELETE to app/api/files/* return 503 JSON: { error: "Admin uploads disabled" } when false.
- Portfolio bulk operations also respect the flag (e.g., app/api/portfolio/bulk-delete/route.ts).
- If ARTISTS_MODULE_ENABLED === false, POST/PUT/DELETE on app/api/artists return 503 JSON with a clear error; GET remains unaffected.
-
Booking Gating
- When BOOKING_ENABLED === false:
- components/booking-form.tsx disables the final submit action (button disabled and shows inline message “Online booking is temporarily unavailable. Please contact the studio.” with a link to /contact).
- If a submit is invoked programmatically, the handler no-ops on the client (no network call).
- Any server-side booking endpoint that receives a call for booking creation must return 503 JSON: { error: "Booking disabled" } as a safety net (no new endpoint is required; apply to existing ones if reachable).
- PUBLIC_APPOINTMENT_REQUESTS_ENABLED is reserved for future public booking endpoint (no-op in this story).
- When BOOKING_ENABLED === false:
-
Public Advanced Animations Gating
- When ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED === false:
- components/hero-section.tsx and components/artists-section.tsx render without parallax/scroll-linked transforms; no requestAnimationFrame loops or heavy IntersectionObserver effects are active.
- Static rendering must not degrade layout or accessibility (no console errors/warnings).
- When ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED === false:
Integration Requirements 4) Defaults: When no flags are set, existing behavior remains unchanged (baseline preserved). 5) Server/API: Early-return 503 JSON responses include an informative message and do not leak internals; do not throw errors for missing flags. 6) UI: Disabled states are accessible (aria-live or clear text), with obvious call to action (link to /contact for booking).
Quality Requirements 7) Minimal unit tests (or component tests) for:
- Booking form disabled mode (BOOKING_ENABLED=false) ensuring button disabled and message present.
- A representative API route (e.g., app/api/files/route.ts) returning 503 when UPLOADS_ADMIN_ENABLED=false.
- Lint/typecheck/tests pass; preview build succeeds.
- No regression in unaffected surfaces (Admin when ADMIN_ENABLED=true; Booking enabled path unchanged).
Technical Notes
- Integration Approach:
- Import typed flags from lib/flags.ts (FF-1).
- Admin: add gating in app/admin/layout.tsx or app/admin/page.tsx (render an Unavailable component/page when ADMIN_ENABLED=false). For APIs, add top-of-handler guards for UPLOADS_ADMIN_ENABLED and ARTISTS_MODULE_ENABLED.
- Booking: in components/booking-form.tsx, derive a boolean from flags and disable the primary submit. Show a shadcn/ui Alert or inline text with a link Button to /contact.
- Public: add a simple boolean check to skip setting up observers/raf and render static content. Ensure prefers-reduced-motion remains respected independent of flag.
- Existing Pattern Reference:
- Route handler early exits with Zod-validated structured error responses (reuse project patterns for JSON responses).
- UI follows existing shadcn styling and messaging patterns.
- Key Constraints:
- Do not alter middleware routing in this story; scope is view/API-level gating only.
- Keep changes localized; no DB or schema modification.
Suggested Files to Touch (for implementation reference)
- app/admin/layout.tsx or app/admin/page.tsx — render “Unavailable” when ADMIN_ENABLED=false
- app/api/files/route.ts — guard with UPLOADS_ADMIN_ENABLED
- app/api/portfolio/bulk-delete/route.ts — guard with UPLOADS_ADMIN_ENABLED
- app/api/artists/route.ts — guard write methods when ARTISTS_MODULE_ENABLED=false
- components/booking-form.tsx — gate submit on BOOKING_ENABLED
- components/hero-section.tsx — disable parallax on ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED=false
- components/artists-section.tsx — disable parallax on ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED=false
Definition of Done
- Admin shell disabled state rendering implemented and verified.
- Admin uploads/api write routes return 503 when corresponding flags are false.
- Booking form submit disabled with clear message and /contact CTA when flag false; no network call issued on submit in disabled mode.
- Public parallax/scroll animations disabled cleanly when flag false; layout remains intact.
- Minimal tests added and passing; preview build succeeds.
- No changes in default behavior when flags are unset (manual smoke).
Dev Agent Record
Agent Model Used
- Dev agent: James (Full Stack Developer)
Debug Log References
- Added lib/flags.ts and wired flags to Admin layout, API routes, Booking form, and public sections.
- Added minimal tests for booking disabled UI and uploads 503 response.
- Fixed unrelated TypeScript errors to make typecheck pass:
- components/gift-cards-page.tsx: normalized boolean handling for
isGift(removed string comparisons; correct onChange typing). - components/smooth-scroll-provider.tsx: removed invalid Lenis options to satisfy
LenisOptionstyping. - tailwind.config.ts: set
darkModeto "class" (string) instead of tuple to match Tailwind types.
- components/gift-cards-page.tsx: normalized boolean handling for
- Added BOOKING_ENABLED short-circuit for appointment POST/PUT/DELETE plus targeted vitest coverage.
- Added static ArtistsSection fallback when ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED=false and covered with SSR regression test.
- Ran
npm run test:run(fails: existing data migration, flags, and validation suites expect mocked DB/env that are not configured in this branch).
File List
- Added:
lib/flags.ts - Modified:
app/api/appointments/route.ts - Modified:
app/admin/layout.tsx - Modified:
app/api/files/bulk-delete/route.ts - Modified:
app/api/files/folder/route.ts - Modified:
app/api/portfolio/bulk-delete/route.ts - Modified:
app/api/artists/route.ts - Modified:
app/api/artists/[id]/route.ts - Modified:
components/booking-form.tsx - Modified:
components/hero-section.tsx - Modified:
components/artists-section.tsx - Added:
__tests__/flags/booking-form.disabled.test.tsx - Added:
__tests__/flags/api-uploads-disabled.test.ts - Added:
__tests__/flags/api-appointments-booking-disabled.test.ts - Added:
__tests__/flags/artists-section.static.test.tsx
Change Log
- Implemented feature flag gating for Admin, Booking, and Public advanced animations. Added 503 guards to relevant admin write APIs. Added tests.
- Addressed repo TypeScript errors blocking CI typecheck (files above). No behavioral changes intended.
- Added BOOKING_ENABLED guard to appointment mutations and static fallback for ArtistsSection when animations are disabled, with new focused vitest coverage.
QA Results
- Gate Decision: PASS — Booking mutations now short-circuit behind BOOKING_ENABLED and the artists grid renders a static layout when advanced animations are disabled.
- Evidence:
app/api/appointments/route.ts:95adds a sharedbookingDisabledResponse()so POST/PUT/DELETE return{ error: "Booking disabled" }503 responses whenever the flag is false, while GET remains readable for incident forensics.components/artists-section.tsx:32primesvisibleCardswith every index and clears transforms when ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED is false, keeping all cards visible without parallax.
- Acceptance Criteria Coverage:
- AC1 — PASS (unchanged: admin layout renders the maintenance shell when ADMIN_ENABLED=false).
- AC2 — PASS (booking UI disables submit and server mutations return 503 with a clear payload when BOOKING_ENABLED=false).
- AC3 — PASS (hero and artists sections degrade gracefully; artists grid stays fully opaque when animations are off).
- Test Review:
__tests__/flags/api-appointments-booking-disabled.test.tsverifies POST/PUT/DELETE 503 responses and__tests__/flags/artists-section.static.test.tsxensures no hidden cards in the static fallback, alongside the existing booking-form and uploads guards.
Status: Ready for Review
Risk and Compatibility Check
Minimal Risk Assessment
- Primary Risk: Over-gating could hide critical admin functionality unintentionally.
- Mitigation: Defaults preserve behavior; add console.warn in server logs only when a critical flag is explicitly set to false (optional).
- Rollback: Remove or bypass guards; set flags to re-enable surfaces instantly.
Compatibility Verification
- No breaking changes to existing APIs when flags are unset.
- No database changes.
- UI follows existing design system.
- Performance impact negligible (boolean checks).
Validation Checklist
Scope Validation
- Single-session implementable in targeted files.
- Straightforward integration using flags from FF-1.
- Follows existing patterns (conditional UI and API guards).
- No design/architecture work required.
Clarity Check
- Requirements are unambiguous for Admin, Booking, Public.
- Integration points and files specified.
- Success criteria testable via small unit/component tests and manual smoke.
- Rollback approach simple (flip flags).
References
- Epic: docs/prd/epic-feature-flags-controlled-rollbacks.md
- Library from FF-1: lib/flags.ts (pre-req)
- Ops: docs/prd/rollback-strategy.md