Skip to content

feat(api): serve SEO metadata for an atlas route (C3) - #646

Merged
Ardnived merged 15 commits into
mainfrom
feat/atlas-seo-endpoint
Aug 25, 2026
Merged

Ardnived merged 15 commits into
mainfrom
feat/atlas-seo-endpoint

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds GET /api/atlas/seo?route=/gb/london&locale=fr — one call gives a host page an atlas route's <head> metadata and the content it renders as children of <sahaj-atlas>.
  • Keyed by route, not by id, per the ticket's proposal — a consumer holds ?atlas=/gb/london, not an id, and the route is parsed with the same rule the widget applies to the same string.
  • Makes the hreflang language set operator-owned on the Sahaj Atlas config global, replacing a constant that was duplicated in sydevs/SahajAtlasWeb.
  • Unblocks C4 (WeMeditateWeb SSR) and C5 (the WordPress plugin, 13 of 29 client domains).

The two open questions in the ticket

Both were confirmed before implementing:

  • Route-keyed, and only route-keyed. No internal caller holds an id and wants SEO, so the id-keyed shape isn't kept. One endpoint, one round trip, no path→id logic duplicated in PHP and TypeScript.
  • Yes, the response carries body content. A region also carries a listing of the classes beneath it — a region page with only a name is thin content, and the class list is what makes it worth indexing.

What it returns, and the parts a consumer must not guess at

Each of these is documented on the handler, in the OpenAPI description, and asserted in the guard spec:

  • canonical is the document's own webUrl, read and never recomputed, so it is byte-identical to what feat(api): resolve canonical webUrl per owning client region #640 publishes everywhere else. Each breadcrumb rung resolves its own canonical too, because ownership is per-subtree — /gb and /gb/greater-london can legitimately be different domains.
  • canonical is locale-free, and so is the x-default alternate. Nothing in the atlas is localized (verified: no localized: true on Events or Regions), so locales differ only in the widget's UI language, which alternates carry as ?locale=.
  • jsonLd is already serialized and escaped for a <script type="application/ld+json"> — emit it verbatim.
  • No HTML crosses the wire. A description arrives as content.paragraphs, plain text, one entry per block. C5's plugin echoes this into a template that never passes through wp_kses, so markup we emit is markup nothing downstream sanitizes.
  • A region gets description: null. It has no description field in the CMS, and since nothing here is translated, an invented English sentence would land in a Dutch or Czech site's <head>. The host writes that line in its own language. og:site_name is omitted for the same reason.
  • An unresolvable route is a 404 — the atlas root and bare view routes included. The host owns its own landing page's metadata.

jsonLdEscape()

<, >, & and the two Unicode line separators are escaped once, here, so a CMS-authored </script> or <!-- can't break out of the block on somebody else's page. Every replacement is a valid JSON escape for the same character, so the output still parses back to the input — asserted as a round-trip, and checked by flipping the escape off to confirm the tests go red rather than passing vacuously.

Operator-owned languages

The hreflang set was a constant here duplicating supportedLanguages in sydevs/SahajAtlasWeb — two lists that could disagree, neither of which an operator could change. It now lives on sy-atlas-config and is read per request (memoized, so a route still costs one read). Filed sydevs/SahajAtlasWeb#167 for the widget half; until that lands the global governs hreflang but not the widget's own picker, which is the safe direction (we stop advertising a language rather than start).

⚠ The field is named languages, not locales, and that is load-bearing. A global's sub-table is <global_table>_<field>, and Payload reserves the _locales suffix for a localized document's value table — so a field named locales generates sy_atlas_config_locales, collides, and makes every read of the global 500 with Cannot read properties of undefined (reading 'referencedTable') from Drizzle's relation builder. Reproduced with select+hasMany, with an array, and with the array localized, on both the dev DB and a fresh test schema; the fix is the field name, not its shape. Written up in .claude/rules/globals.md because the failure looks nothing like a naming problem.

No data migration is needed, deliberately. Production's global row already exists and a defaultValue doesn't backfill it — so ATLAS_DEFAULT_LOCALES serves as both the field default and the unconfigured-column fallback, one definition that can't drift. Without that, this deploy would have collapsed every atlas page's hreflang from ten languages to one.

One correction to what the ticket and the programme record assume

Both state that where[breadcrumbs.url][equals]='/nl/amsterdam' resolves a region path in one query, which #640 shipped generateURL to enable. It does not resolve one region. breadcrumbs is an array, and Payload's equals on an array sub-field matches when any element matches — so /gb/london matches every descendant of London as well as London itself, and which row comes back is whatever the database returned first. The integration spec caught it resolving a city route to a venue two levels down.

The stored breadcrumbs.url is still a fine denormalization; it just isn't a unique key. The region slug already is one, so a route is keyed by its terminal segment for both variants — which is also what the widget's own resolvePath does. That makes stale ancestry resolve rather than 404: a region moved in the tree, or a country re-slugged to its ISO code (#556), still lands on the right document, and the answer's route/canonical name the URL to redirect to.

Changes

  • src/endpoints/atlas/seo/ — the endpoint, route parser, JSON-LD builders, response shaper, and the locale resolver. The folder path mirrors the URL; the modules are single-owner code, which is why they aren't in src/lib/.
  • src/globals/SahajAtlasConfig/ — the languages field, plus a migration.
  • src/lib/atlas/regionTree.ts — nameById for breadcrumb labels (read fresh, so a rename doesn't go stale in descendants' trails), and descendantRegionIds so a city's page includes classes at its shared venues.
  • src/lib/atlas/regionOwners.ts — getCanonicalUrlForRegion, the composition hoisted so a breadcrumb ancestor named only by id doesn't re-derive it.
  • src/plugins/openapi/customEndpoints.ts — the path plus nine hand-authored schemas.

Query budget

Pinned by test, because the endpoint leans on per-request memoization and losing it would be slower, still correct, and invisible everywhere else:

  • Event route: 1 regions + 1 clients read, plus 1 images read only when the class has photos (most don't).
  • Region route: 2 regions + 1 clients + 1 events.

Edge caching — already live

The Cloudflare Cache Rule enumerates cacheable paths by collection slug, and atlas is not one, so /api/atlas/seo would have stayed DYNAMIC despite emitting s-maxage=300. The rule has been updated (ruleset v8 → v9) with http.request.uri.path eq "/api/atlas/seo" added to the existing rule's path group — inside that rule, not as a new one, because only it carries the Authorization-present conjunct that stops an unauthenticated request being served the cached authed body. Verified after: unauth GET is DYNAMIC on both the new path and the existing ones. DEPLOYMENT.md records it, including the rule for the next root endpoint.

Migration

  • New migration: src/migrations/20260825_212133_atlas_config_languages.ts
  • Impact: creates sy_atlas_config_languages (join table) + its enum. No existing data touched.
  • Reversible: yes — down drops both. The validator's one WARN is that DROP TABLE, which is correct for a reversible create.

Test Results

  • Unit: whole lane green, including 30 route-parsing, 35 shaping, and 8 language-normalization cases
  • Integration: atlas-seo 36 passed; region-canonical-url, regions, events-geojson, region-breadcrumb-url-backfill, atlas-collections 74 passed
  • Lint ✓ · typecheck ✓ · typecheck:tests ✓ · migration validator ✓

Also verified live against a dev server that /api/atlas/seo actually routes — a two-segment root endpoint path is something tests calling the handler directly can't check. It returns 403 from the auth gate, while /api/atlas/nope returns Payload's "Route not found".

Manual verification

  1. With a published client key: curl -g -H "Authorization: <scheme> <key>" "$URL/api/atlas/seo?route=/india/pune" and confirm canonical matches that region's webUrl from GET /api/regions?where[slug][equals]=pune&select[webUrl]=true.
  2. Paste the jsonLd string into the Rich Results Test to confirm real Atlas data validates as Event / BreadcrumbList / ItemList.
  3. In the admin, open Sahaj Atlas → Configuration and confirm the Languages list renders and saves.
  4. After deploy, confirm the endpoint edge-caches: an authed GET should go MISS → HIT, and an unauth GET must stay 403/DYNAMIC.

Notes for reviewer

  • The route echoed back is always the document's own webPath, never the caller's string, so a consumer can use it as a redirect target.
  • og:image resolution goes relationship → virtual url → filename and preserves the editor's ordering — a bug found and fixed mid-review, since a where id in (…) read returns rows in database order and the lead photo is what unfurls.
  • We Meditate Web (client id 1) has been given the sahaj-atlas-client role in production, so C4 can call this endpoint; regions/events belong only to the sahaj-atlas project and it would otherwise 403.

Closes #645

🤖 Generated with Claude Code

Ardnived and others added 10 commits August 25, 2026 11:35
Adds `GET /api/atlas/seo?route=/gb/london&locale=fr` — one route-keyed root
endpoint that resolves a region or an event and answers with everything a host
page needs to render it: title, meta description, canonical, hreflang,
Open Graph, escaped JSON-LD, and the body content it renders as children of
`<sahaj-atlas>`.

Keyed by route rather than by id because a route is what a consumer holds. An
id-keyed shape would make WeMeditateWeb and the WordPress plugin each resolve
path -> id first, which is two round trips and the same logic written twice.
The route is parsed with the same rule the widget applies to the same string,
so a server-rendered page and the widget that upgrades over it cannot disagree
about which document a URL names.

Notable contract choices, all documented on the handler:

- `canonical` is the document's own `webUrl`, read and never recomputed, so it
  is byte-identical to what #640 publishes everywhere else.
- No HTML crosses the wire: a description arrives as plain-text paragraphs. The
  WordPress plugin echoes this into a template that never passes through
  `wp_kses`.
- `jsonLdEscape()` escapes `<`, `>`, `&` and the two Unicode separators, so a
  CMS-authored string containing `</script>` or `<!--` cannot break out of the
  block it is embedded in.
- A region has no description in the CMS, so it gets `description: null` rather
  than an untranslatable English sentence in somebody else's `<head>`.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…erage

The shim entry is where a consumer learns the parts of this contract it cannot
infer — that the canonical is locale-free, that jsonLd is already escaped, that
no HTML crosses the wire, that a region's list is capped while eventCount is
not, and that an unresolvable route is a 404. Each of those is asserted in the
guard spec, because a silent omission there is a consumer guessing wrong.

The unit specs cover the two halves that need no database: route parsing (the
widget's own rule, including view segments and legacy prefixes) and shaping
(escaping, hreflang, JSON-LD nodes, the region/event variants). The escaping
assertions were checked by flipping the escape off and confirming they go red.

Moves the endpoint's private modules from src/lib/atlas/ into
src/endpoints/atlasSeo/, which is where lib-boundary.spec.ts says single-owner
code belongs — they had exactly one consumer each. `widgetLocales.ts` stays in
lib, since the OpenAPI shim reads it too.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…rail

The integration spec caught the region lookup resolving a city route to a venue
two levels beneath it. `where['breadcrumbs.url'][equals]` looks like an exact
path match but `breadcrumbs` is an array, and Payload's `equals` on an array
sub-field matches when ANY element matches — so `/gb/london` matches every
descendant of London as well as London itself, and which row comes back is
whatever the database returned first.

#640 shipped `generateURL` specifically to enable that lookup, and both the
ticket and the programme record assert it works, so this is worth stating
plainly: the stored `breadcrumbs.url` is a fine denormalization, it is just not
a unique key. The region slug already is one — globally unique and indexed, and
the importer disambiguates the handful of colliding names.

So a route is now keyed by its terminal segment for both variants, which is also
what the widget's own `resolvePath` does. That makes stale ancestry resolve
rather than 404: a region moved in the tree, or a country re-slugged to its ISO
code (#556), still lands on the right document, and the `route` and `canonical`
in the answer name the URL the host should redirect to. 404-ing every inbound
link into a restructured subtree is the opposite of what this endpoint is for.

Adds tests/int/atlas-seo.int.spec.ts (29 cases) over a two-owner tree with a
venue under a city: the canonical matching each document's own `webUrl`, each
breadcrumb rung matching its own ancestor's, the descendant-inclusive listing,
the 404 matrix, and an end-to-end check that a class titled `</script>...`
leaves nothing for an HTML parser to act on.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Also records the breadcrumb-trail finding on the regions row, since that is
where the next person will look before reaching for `breadcrumbs.url` as a
lookup key.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three things a reader would otherwise have to derive from source: that a route
is keyed by its terminal segment, that `breadcrumbs.url` equality matches any
trail element rather than one region, and that nothing in the atlas is localized
(which is why the canonical is locale-free and why the endpoint composes no
prose).

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`images` is a relationship whose `url` is itself a virtual field, populated
under the caller's own access — so an absent `og:image` would have been a silent
failure rather than an error. One case now asserts the whole chain.

The two cases that create their own class now put it in a sandbox city under
France, so the UK listing counts don't depend on which cases have already run.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three findings applied from the cleanup agents:

- Read an event at `depth: 0` and fetch its images only when it has some. The
  `depth: 1` read existed for `images`, but it also populated the event's
  `region` — a whole extra `regions` query, running that region's own webPath /
  webUrl afterRead hooks, for a document reduced to an id one line later. Most
  classes have no photos, so they now pay nothing at all for the image read.
  Pinned by a query-budget test: an event route costs exactly one `regions` and
  one `clients` read, and touches `images` only when there are any.
- Extract `locationNode()` out of the triple-nested ternary in the JSON-LD
  event builder.
- `images` now arrives on `EventSeoInput` rather than being read off the event,
  which keeps the shaper's "endpoint does the I/O" contract honest.

Two findings rejected. `descendantRegionIds` and `getCanonicalUrlForRegion`
were reported as lib-boundary violations that would fail CI; they are not — the
check counts consumers per module, and both live in modules with several
(`lib-boundary.spec.ts` passes). They are also at the right layer: the first
sits beside `resolveOwnersByRegion`, the other pure function over the same
`chainById`, and the second beside `getCanonicalUrlBase`, so canonical URLs
stay composed in one place. And the per-ancestor re-await of the memoized tree
in `regionBreadcrumbs` is a handful of microtasks on already-resolved promises;
inlining it would create a second place that builds a canonical URL, which is
the one thing this endpoint is careful not to do.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two statements the endpoint made stale: contact-admin was the only root endpoint
calling `assertClientOriginAllowed` itself, and the finished-events table listed
every client-facing read.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`GET /api/atlas/seo` emits the same cache headers as any client read, but the
Cache Rule enumerates paths by collection slug and `atlas` is not one — so it
stays DYNAMIC and every SSR page render reaches the origin. Nothing breaks (same
fail-safe as an absent rule), but the caching never activates, and this endpoint
is called once per host page render by two consumers. Records the one-line fix.

The gap had not come up because the only prior root endpoint is a POST.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reading a class's photos with `id in (…)` returns rows in database order, which
is descending — so an event whose editor arranged its images ascending got them
back reversed, and `og:image` unfurled the LAST photo instead of the first. The
ordering was free while the event was read at `depth: 1` (Payload's own populate
preserves a hasMany field's order); fetching the images separately, which is
what makes a photo-less class cost nothing, is what dropped it.

Re-applies the id order after the read, and drops ids with no surviving row
rather than leaving a hole.

The first version of the regression test asserted one fixed ordering and stayed
green with the fix deleted — the database order happened to match it. It now
asserts both directions, so whichever way the database sorts, one case must
disagree with it. Verified by deleting the reordering and watching the ascending
case go red.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@railway-app

railway-app Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-646 environment in sahajcloud

Service Status Web Updated (UTC)
SahajCloud ✅ Success (View Logs) Web Aug 25, 2026 at 10:17 pm

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-646 August 25, 2026 19:14 Destroyed
Ardnived and others added 5 commits August 25, 2026 13:04
The rule was edited on the live zone (ruleset v8 -> v9), so the previous note —
which said the endpoint stays DYNAMIC and told the reader how to enable it — was
stale the moment it shipped.

Keeps the reason the term had to go inside the existing rule rather than into a
new one: only that rule carries the Authorization-present conjunct, and without
it an unauthenticated request is served the cached authed body.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The folder path now mirrors the URL it serves: src/endpoints/atlas/seo/ ->
GET /api/atlas/seo, handler in index.ts. A reader looking for what answers a
route no longer has to know that `atlasSeo` is the camelCase of a two-segment
path.

Records the convention in the endpoints and project-structure rules, including
why the supporting modules stay in the folder rather than moving to src/lib/
(single-owner code — lib-boundary.spec.ts fails a lib module with one consumer
outside lib). `responseTypes.ts` stays at src/endpoints/ since both root
endpoints share it.

Pure move: no behaviour change, and the exported symbol is still `atlasSeo`.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The hreflang list was a hardcoded constant duplicating `supportedLanguages` in
sydevs/SahajAtlasWeb — two lists that could disagree, neither of which an
operator could change. It now lives on the Sahaj Atlas configuration global and
the SEO endpoint reads it per request (memoized, so a route still costs one
read), which makes enabling a language a content decision rather than a deploy
in two repos.

⚠ The field is named `languages`, not `locales`, and that is load-bearing. A
sub-table on a global is named `<global_table>_<field>`, and Payload already
uses the `_locales` suffix for a localized document's value table — so a field
called `locales` generates `sy_atlas_config_locales`, collides with that
convention, and every read of the global then dies in Drizzle's relation builder
with `Cannot read properties of undefined (reading 'referencedTable')`.
Reproduced with select+hasMany, with an array, and with the array localized, on
both the dev database and a fresh test schema; renaming the field is what fixes
it. The comment on the field says so, because the next person to add a field
here will not guess it.

The constant survives as `ATLAS_DEFAULT_LOCALES`, serving as both the field's
defaultValue and the fallback for an unconfigured column — one definition, so
they cannot drift. That fallback is not cosmetic: production's global row
already exists, a defaultValue does not backfill it, and without a matching
fallback this deploy would collapse every atlas page's hreflang cluster from ten
languages to one. It also means no data migration is needed.

The OpenAPI enum stays the CMS locale superset, because the spec is built
statically and the effective set is now runtime data — the description says so
and points readers at `alternates`.

Coverage splits along the same seam: the wiring (global changes -> hreflang
changes, live) is an integration case, while the states the API cannot produce
are unit-tested against the pure normalizer. An empty set is one of those: the
field is `required` with `minRows: 1`, so Payload rejects it outright.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… trap

The globals rule described the Atlas config field-by-field and no longer
matched it. It now covers `languages`, and carries the warning that cost real
debugging time: a global's sub-table is `<global_table>_<field>`, Payload
reserves the `_locales` suffix for a localized document's value table, and a
field named `locales` therefore makes every read of that global 500 in Drizzle's
relation builder. The fix is the field NAME, not its shape — worth stating
plainly, because the failure looks nothing like a naming problem.

Also notes the operator-owned hreflang set in the architecture doc, and the new
coverage in the test map.

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
- Overlap the independent reads. An event route resolved images, ancestry and
  the language set one after another; a region route awaited the language set
  after its other reads had already returned. All now ride in one Promise.all.
  The risk that introduces — concurrent first-callers racing the per-request
  memo — is exactly what the query-budget test pins, and it still reports one
  `regions` and one `clients` read.
- Breadcrumb `route` is `null`, not `''`, when a blank slug in the chain means
  no path can be built. It now goes null in the same cases `url` does, instead
  of an empty string that a host would render as a link to the current page.
  The published type said "Always present", which was false.
- Simplify the recurrence interval to `Math.max(…, 1)` (same result for every
  input, including 0, negatives and undefined), hoist the schema's locale list,
  and drop an `isValidLocale` re-check that Zod's own refine already narrowed.

That last one was checked rather than trusted: `.refine()` does not usually
narrow, so a type probe was used to confirm `parsed.data.locale` really does
infer as `LocaleCode | undefined` before the guard was removed.

Rejected: the reported `weekdays` "double check" (the guard is on `firstDate`,
not `recurrenceType`), an `og:image` "undefined" leak (guarded by `if
(args.image)`), a region slug shadowing a reserved word (slugs are lowercase and
the shadow is the documented guard), case-insensitive slug lookup (would diverge
from the widget's own rule), `descendantRegionIds` being O(n·m) (~2400 checks on
already-loaded maps, once per request), and the import-order reports (eslint
enforces that rule and passes).

Refs #645

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-646 August 25, 2026 22:15 Destroyed
@Ardnived
Ardnived merged commit 2961a73 into main Aug 25, 2026
2 checks passed
@Ardnived
Ardnived deleted the feat/atlas-seo-endpoint branch August 25, 2026 22:38
sydevs-bot added a commit that referenced this pull request Sep 12, 2026
…es (#769)

* feat(translations): add a Seo group holding the atlas landing page's copy

The atlas root — `/`, and every bare view route — names no document, so it
has no name of its own to borrow. Every other route `GET /api/atlas/seo`
answers describes a row: a region's name, an event's title and description.
The landing page needs copy an operator writes.

`sy-atlas-translations` over `sy-atlas-config`, per Ardnived on #739. It is
already localized, already seeded in ten locales, and already the place a
translator visits — and page metadata written once per locale is exactly
what that global is for.

Two keys, both bounded to what a result page shows: `root_title` at 60 and
`root_description` at 160. Both advisory rather than `strict`, matching
every other limit in this schema — an over-long title is untidy, not broken.

The migration is additive: one `jsonb` column on the locales table and its
versions twin, reversible, with no backfill. The endpoint reading these
lands in the next commit.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K4kjAuZiiLpicAZkxMefjx

* feat(api): answer the atlas root and bare view routes from /api/atlas/seo

`GET /api/atlas/seo?route=/` 404'd, and so did `/search`, `/calendar`,
`/filters`, `/online` and `/share`. Those are the routes most hosts mount,
so the one page a host links from its own nav was the only page with no
metadata of its own: it inherited the site's global title and description
and emitted no canonical, which reads to a crawler as a duplicate of the
site's homepage (sydevs/SahajAtlasWeb#173).

`parseAtlasRoute` gains a third variant, `{ kind: 'root' }`, for a route
that reduces to no segments — a view of the root is still the root. The
response is a third union member: `type: 'root'`, `id: null`, `route: '/'`,
empty `breadcrumbs`, and a `WebSite` JSON-LD node rather than `Place` or
`Event`.

**"Names nothing" and "is not a route" stay different answers.** A string
carrying a query, fragment or whitespace, or past the segment cap, is still
a 404 — and the cap is now measured *before* reserved words are dropped, so
twenty `/search` rungs cannot reduce to a landing page. Past the length
ceiling is a 400, on the query schema, before the parser sees it; the spec
pins which refusals live on which side of that line. The 404 message no
longer claims the route "does not name a region or an event", which was
about to become misleading for a string we simply refuse to read.

**`description` never falls back to English; `title` does.** A locale with
no description gets `null`, exactly as a region does, and the host writes
its own line in its own language (#646's rule). `<title>` is mandatory
markup and typed as a string, so it falls back to English and then to a
constant — a page a crawler cannot name is worse than one named in the
wrong language, and the constant is also what makes the endpoint answer the
root on the day it deploys, before an operator has typed anything. That is
the role `EMAIL_STRING_DEFAULTS` already plays for this same global.

Holding that asymmetry means reading the global **around**
`clientEnglishFallback`: the hook fills blank keys from English for every
`clients` read, which is right for widget chrome and would silently defeat
the rule above. `rootStrings.ts` reads with `fallbackLocale: false` and a
user-less copy of the request, and decides for itself what an absence
means. Reintroducing the merge turns the French case red with the English
sentence in it.

**The canonical is the caller's own verified embed page**, with no route
appended — read from its `clients` row, from
`canonical.verification.verified` and never from the declaration, since
only the verification job writes what it loaded itself (#633's trust
boundary). Read rather than taken off `req.user`: what auth attaches is not
this endpoint's contract to depend on, and a missing `canonical` group
would downgrade every host's root canonical to the We Meditate fallback
with nothing failing. `canonicalMountUrl` has no routing branch, because
`path` and `query` differ only in how a route *below* the root is
expressed, and there is none. A caller owning no canonical falls through to
the We Meditate surface, exactly as an unclaimed region does.

Every new assertion was watched fail at the site that would cause it:
returning `null` for an empty segment list (9 unit + 13 integration cases),
filtering before the cap, branching the mount URL on routing mode, emitting
a `Place` node with breadcrumbs, and restoring the English merge.

Closes #739

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K4kjAuZiiLpicAZkxMefjx

* refactor(atlas): reuse the canonical-owner rule and make the English opt-out explicit

Findings from the /simplify pass, all applied.

**Reuse / altitude — the endpoint was re-deriving "may this client publish a
canonical".** `rootCanonical` carried its own `clients` row shape, its own
`select`, its own flattener and its own eligibility test, all of which
`regionOwners.ts` already owns — and the copy was already a *different* rule:
it checked `typeof verified.domain === 'string'` where `canonicalOwnerFrom`
checks `isValidCanonicalDomain`, and it dropped the `_status: published` half
of `CANONICAL_ELIGIBLE` entirely. That file's own comment warns that a third
condition added to one caller silently leaves the other on the old rule; this
was that third caller, outside the file that made the promise.

`loadCanonicalFallbackOwner` is now `canonicalOwnerForClient(req, id)`, exported
and shared, and `rootCanonical` is two lines. The endpoint carries no client
row shape, no select, no eligibility test and no try/catch.

That also corrected a claim: the root does **not** fall through to the #652
fallback client the way a region does. That client speaks for regions nobody
claims, and somebody else's landing page is not one of those — a host with no
canonical of its own gets the We Meditate surface, never another client's page.

**Altitude — the English-merge bypass said the wrong thing.** Passing a
user-less request defeated `clientEnglishFallback` by making it believe nobody
was asking. The intent is "do not merge English into this read"; identity is
only the hook's proxy for it, so any future hook keyed on `req.user` would have
changed this read's behaviour silently. `withoutEnglishFallback(req)` now sits
beside the hook it disables, the hook documents its own exception where it is
enforced, and the read keeps its real user for access control. The ⚠ in
`src/globals/AGENTS.md` describes a seam the code now has rather than a rule
only prose carried.

**Reuse — one publishability guard.** `canonicalMountUrl` had copy-pasted
`canonicalUrlBase`'s origin and mount prologue, and the two had already
drifted: the new one refused whitespace in a mount, the old one accepted it.
`canonicalUrlBase` now builds on `canonicalMountUrl`, so there is one
definition. That deliberately tightens `canonicalUrlBase` by one case —
whitespace in a mount is now `null` rather than a URL nobody chose, which is
what the origin half of the same function has always done. No contract fixture
case carries one.

**Efficiency.** The translations read now carries `select: { seo: true }` —
it was materializing all seven localized groups (52 leaf keys) to read two
strings. A failed read is kept distinct from a blank locale, so an unreadable
global no longer costs a second read that will fail identically.

**Simplification.** Dropped a `memoizeOnRequest` wrapper that could never hit
(one caller, one call per request, and the English repeat is already branched
away). Extracted the fallback chain as the pure `resolveRootStrings`, which
makes the asymmetry unit-testable and reaches the last-resort constant that no
integration case could. Spread the resolved strings instead of copying two
fields by name, folded a redundant destructure, and cut two comments that
restated prose already on screen.

`canonicalMountUrl` now takes `Omit<CanonicalTarget, 'routing'>`, so "routing
does not enter into it" is in the signature rather than only the docblock.

Both behaviours re-verified after the refactor: dropping the opt-out puts the
English sentence back in the French `<head>`, and resolving the caller as
`undefined` publishes the We Meditate URL for a host that owns its own.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K4kjAuZiiLpicAZkxMefjx

* fix(api): close the root content shape and stop truncating its body copy

Three findings from the review pass.

**The `content` oneOf was ambiguous.** `AtlasSeoRootContent` shipped without
`additionalProperties: false`, which both sibling content schemas carry. An
event's `content` also has a `paragraphs` array, so an event response matched
two branches of the union — a strict validator would reject a correct response,
and codegen would produce an ambiguous type. The spec now asserts all three
shapes are closed, since the trap is that an open one fails somewhere else.

**`content.paragraphs` was being truncated.** `buildEventSeo` puts the full
text there and bounds only the `<meta>` value; the root did both from the
truncated string. `root_description`'s 160-character limit is advisory, not
`strict`, so a longer operator-written description would have rendered as
visibly cut-off body copy on the host's page.

**The 404 documentation was wrong about one case.** An over-length route is a
400 — `querySchema.route.max(512)` refuses it before the parser runs, which the
integration spec already asserted. The handler docblock and both OpenAPI
descriptions said 404. Corrected rather than changed: a length ceiling belongs
to request validation, not to "there is no such page".

Both new assertions watched fail first: dropping `additionalProperties`, and
building `paragraphs` from the truncated value.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K4kjAuZiiLpicAZkxMefjx

* docs(tests): list the root-strings unit spec in the coverage map

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K4kjAuZiiLpicAZkxMefjx

* fix(translations): build the English opt-out on localeIsolatedReq

`withoutEnglishFallback` spread the request itself, re-deriving what
`localeIsolatedReq` already owns at eleven call sites — including the one
three lines below it in this file. Both callers pass an explicit `locale`,
which is exactly the `createLocalReq` hazard that helper documents, so the
reasoning for copying at all now lives in one place.

No behaviour change: the helper is that same shallow copy.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014BYwdHjK7hdWv1NeyRjgd5

* fix(api): declare the root select without a cast

`SEO_GROUP_SELECT` carried `as never`, which its four siblings in
`seo/index.ts` do not: `REGION_SELECT`, `EVENT_SELECT`, `IMAGE_SELECT` and
`EVENT_CARD_SELECT` all declare `: SelectType` plainly. `{ seo: true }` is a
valid `SelectIncludeType`, so the cast silenced nothing — `pnpm typecheck`
and `pnpm typecheck:tests` both pass without it.

A cast that buys nothing is worse than none: the next reader has to work out
which mismatch it was hiding.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014BYwdHjK7hdWv1NeyRjgd5

* docs(api): state the root rule, not five view routes

The OpenAPI description and `docs/architecture.md` both named five bare view
routes as what answers the root. `RESERVED_SEGMENTS` holds eleven, so
`/register`, `/preview`, `/events`, `/areas`, `/regions`, `/venues` and any
combination of them answer as the root too — `atlas-seo-route.spec.ts`
already pins `/events/areas` doing it.

A list a reader can check against the code, and lose to, is worse than the
rule: a route left empty once reserved segments are dropped is the root.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014BYwdHjK7hdWv1NeyRjgd5

* fix(api): name the atlas root in the caller's own locale

The root's `<title>` fell back from `seo.root_title` straight to English.
`seo` ships empty in all ten locales, so every locale got the English
constant on day one, and a host adopting the root lost its own localized
title to it. Reviewer's call on #769: default to the localized
`common.free_meditation_classes` instead.

The chain now exhausts the locale before it leaves it — the operator's
`seo.root_title`, then that locale's own `common.free_meditation_classes`,
which is seeded in ten locales where `seo` is empty. English, and then
`ROOT_TITLE_FALLBACK`, are reached only by a locale carrying neither
string, so the constant is now a brand-new-database case rather than the
live one. `description` is untouched: it still never falls back.

Both groups come from one read, so an untranslated locale costs no extra
query. The English read still fires only when the locale names the atlas
nowhere.

The integration fixture pins `seo: {}` for German deliberately.
`publishSpecificLocale` publishes the draft as that locale reads it, and a
draft read falls back to English — so omitting `seo` wrote the English
landing copy into the German column and the fixture stopped representing
an untranslated locale at all. That cost one debugging round.

Both new assertions were watched fail against the old chain, unit and
integration, before the fix went back in.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018P23ua27dChRxb1g9frwBb

* docs(api): state that the root title stays in the locale

`docs/architecture.md` and the OpenAPI `title` description both said the
root title falls back to English. It now falls back within the locale
first, so both stated the opposite of what ships.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018P23ua27dChRxb1g9frwBb

---------

Co-authored-by: Claude <[email protected]>
sydevs-bot pushed a commit that referenced this pull request Sep 14, 2026
The reviewer's call on #781, open question 2: every locale carries a
`root_description`, not English alone. The endpoint still never falls
back — an eleventh locale gets `null`, not our sentence — so this changes
the data, not the rule #646 set.

Each description recombines strings that locale's translator already
wrote: `countries.title`, `compact.open`, `online.title`,
`common.chrome.all_classes_free`, and the rendering of "Sahaja Yoga
meditation" in `registration.questions.experience` — Сахаджа-йога in ru
and uk, Sahadža jóga in cs. Register follows each locale's own
`compact.open`: du in de, jij in nl, tú in es, vous in fr, ön in hu,
vykání in cs. Lengths 119–156 against the schema's advisory 160.

⚠ Written here, not by a native speaker. That is the same debt the open
thread names for the nine titles, now doubled — nine more `<head>`
strings on up to 29 domains that nobody fluent has read.

Three claims this falsifies, swept: the admin field description said
English only, `docs/architecture.md` counted titles alone, and
`index.ts:421` still said an operator writes the copy — a survivor of
cf2145d's sweep.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tG8ZaLunkn1bEkDRrGDoi
sydevs-bot added a commit that referenced this pull request Sep 14, 2026
…781)

* feat(translations): seed atlas landing-page SEO copy in ten locales

`GET /api/atlas/seo` answers the atlas root from the `seo` group of
`sy-atlas-translations`, and no seed carried that group. Every locale's
root title fell back to its own `common.chrome.widget_label` — the
widget's name for itself, not a page title — and `description` was
`null` everywhere.

Ten titles, one description.

Each title is built from that locale's OWN already-translated strings:
`countries.title` / `common.chrome.widget_label` ("free meditation
classes") plus `compact.open` ("near you"). So a title is a
recombination of copy a translator already wrote, never a sentence this
run invented — "Kostenlose Meditationskurse in deiner Nähe" is both
halves of the German seed, joined.

A description is not. It is new prose, and `resolveRootStrings` refuses
to serve English into another locale's `<head>` on purpose (#646), so
the nine non-English descriptions are left for a translator and the
endpoint keeps sending `null` for them — exactly today's behaviour,
never a half-state. English carries both keys.

`atlas-translations-schema.spec.ts` no longer exempts `seo.` from the
English coverage check, so both keys are guarded from here. Verified
the assertion bites: with `seo` removed from `data.en.json` it fails
and names `seo.root_title` and `seo.root_description`.

Every value is inside the schema's advisory `maxLength` — titles 32-46
of 60, the description 121 of 160. Neither field sets `strict`, so the
limits do not block a save; they are the widths a result page truncates
at.

Verified against a seeded local database: `pnpm seed translations
--dry-run` reports `<locale>:seo — created` for all ten, and
`getRootSeoStrings` then returns each locale's own title with
`description` non-null for `en` and `null` for the other nine.

Refs #778

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BR7nsviQCZzQF2s9JfZ9Pt

* docs(atlas): correct the root title fallback in the endpoint docblock

The endpoint's own summary said the root `title` "falls back to English
and then to a constant". It has not since #739: `resolveRootStrings`
exhausts the locale first, taking `common.chrome.widget_label` before it
looks at English, so an unwritten locale is named in its own language
rather than in ours. That asymmetry is the module's whole point, and the
summary a reader meets first contradicted it.

Refs #778

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BR7nsviQCZzQF2s9JfZ9Pt

* docs(atlas): say who owns the landing copy, and where the order is written

Review of the branch found three claims this branch falsifies or
duplicates, and one contradiction it introduced.

Falsified. `atlas-seo-root-strings.spec.ts` and `docs/architecture.md`
both said `common.chrome.widget_label` is the live root title "where
`seo` is empty" — true while no seed carried the group, false from the
commit before this one. The hop is not dead: it still answers for a
locale outside the ten, and for one an operator has blanked. Both now
say that instead.

Duplicated. The endpoint docblock enumerated all four fallback hops,
which `rootStrings.ts` already does twice at greater length. Enumerating
it a third time is what let it go stale in the first place, so it now
states the contract a consumer needs — `title` is never blank, and never
another language's while the locale has words of its own — and names
`./rootStrings` as the one place the order lives.

Contradicted. `atlas-translations-schema.spec.ts` calls `seo` not
widget-facing in one test and, since the exemption came off, required it
under a test titled "covers every widget-facing key". Renamed to what it
now checks — every key the seed owns — with the reason stated: English
is the one locale where a blank landing description is an omission
rather than the `null` the endpoint answers with on purpose.

Not taken: seeding `root_title` for English alone and letting each
locale's `widget_label` answer the rest. It is the cheaper change and it
keeps one copy of the phrase per locale, but a widget's self-label is
not a page title — that gap is the defect #778 opens with, and "near
you" is the search intent the landing page is for.

Refs #778

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BR7nsviQCZzQF2s9JfZ9Pt

* fix(atlas): the seo group is no longer empty everywhere

`rootStrings.ts:71` still called the group blank until someone writes it.
Ten seeds in this branch make that false, and the endpoint docblock names
this file as the one place the chain is written down — so the survivor of
the stale-claim sweep sat in the file the sweep pointed at.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RCPWTjvtu2VS5uNukAeuiE

* fix(atlas): say the landing copy is seed-owned, everywhere it is described

Seeding `seo` in ten locales makes the seed its owner: the importer
replaces the whole group on every run, so a description typed into the
admin is gone on the next `pnpm seed translations`. Nine strings still
told an operator or a host the opposite, and the decision lived only in
the PR body.

The three that make a promise now name the seed file instead — the field
description an operator reads in the admin, the OpenAPI schema a host
reads, and `rootStrings.ts`'s own header, which adds the `fillBlanks`
condition for handing the group back. The other six said
"operator-written" where they meant "lives on sy-atlas-translations".

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RCPWTjvtu2VS5uNukAeuiE

* fix(test): name the coverage check after what it asserts

"covers every key the seed owns" claimed more than the filter checks:
the seed does own English `emails` and `event.title`, through the
defaults `fillBlanks` merges in, and the two lines below exempt both.
What the assertion actually covers is the keys this file carries.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RCPWTjvtu2VS5uNukAeuiE

* feat(translations): seed the landing description in nine more locales

The reviewer's call on #781, open question 2: every locale carries a
`root_description`, not English alone. The endpoint still never falls
back — an eleventh locale gets `null`, not our sentence — so this changes
the data, not the rule #646 set.

Each description recombines strings that locale's translator already
wrote: `countries.title`, `compact.open`, `online.title`,
`common.chrome.all_classes_free`, and the rendering of "Sahaja Yoga
meditation" in `registration.questions.experience` — Сахаджа-йога in ru
and uk, Sahadža jóga in cs. Register follows each locale's own
`compact.open`: du in de, jij in nl, tú in es, vous in fr, ön in hu,
vykání in cs. Lengths 119–156 against the schema's advisory 160.

⚠ Written here, not by a native speaker. That is the same debt the open
thread names for the nine titles, now doubled — nine more `<head>`
strings on up to 29 domains that nobody fluent has read.

Three claims this falsifies, swept: the admin field description said
English only, `docs/architecture.md` counted titles alone, and
`index.ts:421` still said an operator writes the copy — a survivor of
cf2145d's sweep.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tG8ZaLunkn1bEkDRrGDoi

* chore(types): regenerate payload-types after the seo description edit

cf2145d rewrote `root_description`'s field description in
`translationsSchema.json` without running `pnpm generate:types`, so the
generated docblock still carried main's wording. Regenerated, and it now
matches this branch's text.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012tG8ZaLunkn1bEkDRrGDoi

---------

Co-authored-by: Claude <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-646 — 38eaba32 Deployed Aug 25, 2026 by railway-app[bot]
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.

feat(api): serve SEO metadata for an atlas route (C3) — blocks the WordPress plugin and WeMeditateWeb SSR

1 participant