Skip to content

fix(site-features): wire site features to the backend AppSettings API - #106

Merged
geourjoa merged 1 commit into
mainfrom
fix/wire-site-features-to-backend
Aug 5, 2026
Merged

fix(site-features): wire site features to the backend AppSettings API#106
geourjoa merged 1 commit into
mainfrom
fix/wire-site-features-to-backend

Conversation

@geourjoa

@geourjoa geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Cross-repo dependency: requires backend PR archetype-pal/backend#149 (adds GET/PUT /api/v1/site-features/, superuser-gated write, backed by the new AppSettings model) to actually work end-to-end — this PR alone is safe to merge first (it degrades to getDefaultConfig() on any fetch failure) but won't reflect real backend data until #149 is also merged.

  • config/site-features.json was being read/written directly from the Next.js server's local filesystem — unsafe across replicas/deploys. Follows the exact same pattern already used for model labels (see fix/wire-model-labels-to-backend, commit 63f557c).
  • lib/site-features-server.ts: readSiteFeatures/writeSiteFeatures now call the backend via apiFetch/authFetch instead of readJsonConfig/writeJsonConfig. All existing defensive merge/normalize logic (missing features key, malformed sections, etc.) is preserved, just re-pointed at the backend response instead of file contents.
  • app/api/site-features/route.ts: PUT now forwards the superuser token to writeSiteFeatures and returns 502 on backend write failure.
  • config/site-features.json is intentionally not deleted — same caution as config/model-labels.json (don't remove until every environment has migrated).

No downstream changes needed: contexts/site-features-context.tsx and the backoffice UI consume the internal /api/site-features route, whose contract to its own callers is unchanged.

Test plan

  • vitest run — full suite 114 files / 1155 tests passed
  • tsc --noEmit clean
  • eslint / prettier --check clean
  • Smoke test against the real backend once #149 is merged

No new dependencies.

site-features-server.ts read/wrote a local config/site-features.json
file, which isn't safely shared or persisted across replicas/deploys.
Point readSiteFeatures/writeSiteFeatures at the backend's
/api/v1/site-features/ endpoint instead (GET public, PUT
superuser-only), following the same pattern already used for
model-labels -> SiteLabel. writeSiteFeatures now takes the caller's
token and throws on a failed write; the PUT route handler catches
that and returns a 502 instead of crashing.

config/site-features.json is left in place, unused, until all
environments have migrated (same caution as config/model-labels.json).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@geourjoa
geourjoa merged commit 387ac61 into main Aug 5, 2026
5 checks passed
@geourjoa
geourjoa deleted the fix/wire-site-features-to-backend branch August 5, 2026 07:40
@geourjoa

geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged by error, I revert sorry.
I reopen here.

@geourjoa
geourjoa restored the fix/wire-site-features-to-backend branch August 5, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant