Skip to content

[haxcms-nodejs] Localization settings parity (PHP): service, routes, createSite default language - #33

Merged
btopro merged 3 commits into
mainfrom
feature/localization-settings-parity
Sep 8, 2026
Merged

[haxcms-nodejs] Localization settings parity (PHP): service, routes, createSite default language#33
btopro merged 3 commits into
mainfrom
feature/localization-settings-parity

Conversation

@btopro

@btopro btopro commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

NodeJS backend parity for the localization settings feature introduced in haxtheweb/haxcms-php (companion PR haxtheweb/haxcms-php#624). Stores the system-wide default language as a localization block on _config/config.json — the single source of truth shared across both backends and the admin Configuration panel.

What's added

  • src/lib/localizationSettings.js — mirrors mediaSettings.js: normalizeDefaultLanguage (BCP-47 validation, en-US default), normalizeLocalizationSettings, getEffectiveLocalizationSettings, hasSupportedLocalizationSettingsPayload, isValidDefaultLanguagePayloadValue, readLocalizationSettings/writeLocalizationSettings (reads full config.json, updates the localization block, writes back preserving sibling keys, syncs haxcms.config.localization in memory).
  • getLocalizationSettings / saveLocalizationSettings route handlers (user-token auth + payload validation), wired into settings.js (getLocalizationSettings / configurationLocalization / saveLocalizationSettings).
  • SystemRoutesMap.js — registered v1/configuration/localization GET/POST/PATCH + added to SystemV1AdminRoutes.
  • HAXCMS.jslocalization config backfill (defaultLanguage: 'en-US').
  • createSite.js — seeds new sites from HAXCMS.config.localization.defaultLanguage (fallback en-US) instead of hardcoding 'en-US'.
  • OpenAPI spec/system/api/v1/configuration/localization path + LocalizationSettings/LocalizationSettingsData schemas.
  • Tests — 16 unit tests in settings.test.cjs, e2e admin-system tests, api-conformance operation path.

Parity / consistency

  • Field name defaultLanguage, storage _config/config.json localization block, route v1/configuration/localization, operation names getLocalizationSettings/saveLocalizationSettings — all match the PHP backend and the webcomponents Configuration panel exactly.
  • No optional chaining (?.); uses globalThis. No build/ubiquity scripts run.

Validation

  • node -c on all 11 modified/new JS + test files: PASS.
  • js-yaml parse of the OpenAPI spec: PASS.
  • node --test test/unit/settings.test.cjs: 91/91 passed (includes the 16 new localizationSettings tests).
  • E2E / api-conformance suites not run (they boot a server); test files mirror existing media test patterns and pass syntax checks.

Refs haxtheweb/issues#2974

Co-Authored-By: Warp agent@warp.dev

…ill, createSite default language

Mirrors the haxtheweb/haxcms-php localization settings implementation for
backend parity. Stores the system-wide default language as a localization
block on _config/config.json (single source of truth), matching the PHP
HAXCMSLocalizationSettingsService shape exactly.

- src/lib/localizationSettings.js: normalize/read/write the localization
  block on config.json (preserving sibling keys), BCP-47 validation, en-US
  default, in-memory config sync on write.
- getLocalizationSettings / saveLocalizationSettings route handlers
  (user-token auth + payload validation), wired into settings.js
  (getLocalizationSettings / configurationLocalization / saveLocalizationSettings).
- SystemRoutesMap: registered v1/configuration/localization GET/POST/PATCH +
  added to SystemV1AdminRoutes.
- HAXCMS.js: localization config backfill (defaultLanguage en-US).
- createSite.js: seeds new sites from HAXCMS.config.localization.defaultLanguage
  (fallback en-US) instead of hardcoding 'en-US'.
- OpenAPI spec: /system/api/v1/configuration/localization path + schemas.
- Tests: 16 unit tests (settings.test.cjs), e2e admin-system tests, api-
  conformance operation path. 91/91 unit tests pass.

Refs haxtheweb/issues#2974

Co-Authored-By: Warp <agent@warp.dev>
Copilot AI lite review requested due to automatic review settings September 8, 2026 15:11
@codesandbox

codesandbox Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The localization endpoint’s request/response contract and normalization behavior are not fully aligned with the OpenAPI schema and with GET-vs-PATCH consistency, risking client/conformance mismatches.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds Node.js backend support for system-level localization settings (default language) to match the PHP backend and the admin Configuration panel, including persistence in _config/config.json, new system API routes, and test coverage.

Changes:

  • Introduces src/lib/localizationSettings.js for reading/writing/normalizing config.json’s localization.defaultLanguage.
  • Adds /system/api/v1/configuration/localization GET/POST (read) + PATCH (write) routes and wires them into the system route map.
  • Updates site creation to seed new sites’ language from HAXCMS.config.localization.defaultLanguage and extends unit/e2e/api-conformance tests plus OpenAPI spec.
File summaries
File Description
test/unit/settings.test.cjs Adds unit tests for localization settings normalization + read/write behavior.
test/e2e/admin-system.e2e.test.cjs Adds e2e coverage for GET/PATCH localization configuration.
test/api-conformance/site-spec.conformance.test.cjs Registers the new system route path in route-group conformance assertions.
src/systemRoutes/v1/settings.js Wires route handlers for localization settings into the v1 settings controller.
src/systemRoutes/v1/routes/saveLocalizationSettings.js Implements authenticated PATCH handler for persisting localization settings.
src/systemRoutes/v1/routes/getLocalizationSettings.js Implements read handler returning effective localization settings.
src/systemRoutes/v1/routes/createSite.js Seeds new site language from system localization config instead of hardcoding en-US.
src/openapi/system-spec.yaml Adds the new endpoint + schemas to the system OpenAPI spec.
src/lib/SystemRoutesMap.js Registers GET/POST/PATCH handlers and marks the route as an admin system route.
src/lib/localizationSettings.js Adds config.json localization read/write + normalization helpers.
src/lib/HAXCMS.js Backfills in-memory config.localization.defaultLanguage to en-US at boot.
Review details

Suppressed comments (1)

src/systemRoutes/v1/routes/saveLocalizationSettings.js:78

  • This PATCH route returns the raw persisted value from writeLocalizationSettings (which can be null when the client clears defaultLanguage), while GET always returns the effective (non-null) default via getEffectiveLocalizationSettings. Returning the effective settings here as well avoids a surprising mismatch between PATCH and a subsequent GET, and better matches the OpenAPI response contract.
    const localizationSettings = await writeLocalizationSettings(HAXCMS, payload);
    return res.json({
      status: 200,
      data: localizationSettings,
    });
  • Files reviewed: 11/11 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +4 to +6
const DEFAULT_LANGUAGE = 'en-US';
const BCP47_LANGUAGE_REGEX = /^[a-zA-Z]{2,3}(-[a-zA-Z]{2,4})?$/;
const DEFAULT_LOCALIZATION_SETTINGS = {
Comment on lines +3088 to +3104
LocalizationSettings:
type: object
description: Localization settings payload (defaultLanguage BCP-47 tag)
properties:
defaultLanguage:
type: string
description: BCP-47 language tag (e.g. en-US, es-ES, fr-FR)
additionalProperties: true
LocalizationSettingsData:
type: object
description: >
Localization settings returned by getLocalizationSettings and
saveLocalizationSettingsPatch. The front-end reads defaultLanguage.
properties:
defaultLanguage:
type: string
additionalProperties: true
Comment thread src/systemRoutes/v1/routes/saveLocalizationSettings.js
Comment thread test/unit/settings.test.cjs Outdated
btopro and others added 2 commits September 8, 2026 11:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@btopro
btopro merged commit 8882acd into main Sep 8, 2026
3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants