Skip to content

feat(api): migrate data layer to SahajCloud PayloadCMS - #11

Merged
Ardnived merged 10 commits into
mainfrom
feat/sahajcloud-data-layer
Jun 30, 2026
Merged

Ardnived merged 10 commits into
mainfrom
feat/sahajcloud-data-layer

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

Migrates the Atlas widget's data layer off the legacy Rails REST API and onto SahajCloud PayloadCMS (Payload v3, REST-only), per #10. Keeps the axios + zod boundary (no Payload SDK, no new runtime SDK dep): repoint at SahajCloud, rewrite the zod schemas to mirror the SahajCloud API, update consuming components, and compute the derived values (eventCount, bounds, distance, region geometry, description HTML) client-side from the GeoJSON feed. payload-types are synced as supplementary compile-time types.

Closes #10. Depends on (and built against) SahajCloud #508 / PR #510.

Corrections to the issue's assumptions

Built against the merged backend + verified against a live SahajCloud, several issue assumptions were corrected:

Issue assumed Reality (verified)
levels country/region/area/venue country / region / **city** / **center** → routed city→area, center→venue (URLs unchanged)
getClient may not have a /me GET /api/clients/me works (Payload auto-/me + self-access bypass)
register POST /api/events/register POST /api/events/{id}/register, body {email, name, startingAt?, questions?}
regions carry geometry lat/lng/radius are null for Mapbox-resolved regions → all bounds/centers derived from the GeoJSON feed
country identity = ISO code identity = slug; ISO code read from legacyData.countryCode for flags + localized names
auth Bearer Authorization: clients API-Key <key>

What changed

  • Type-sync — pnpm types:cms (curl payload-types.ts + the endpoint response-types.ts, strip the declare module 'payload' block) into src/types/payload/. Adds qs + @turf/distance.
  • Pure libs (unit-tested) — src/lib/geo.ts (turf bbox/center/distance) and src/lib/shape/ (geojson→counts/bounds keyed by region breadcrumb ancestry, level→route mapping, a minimal Lexical→HTML/text serializer, shared event derivations).
  • Schemas (src/types/) — mirror SahajCloud internal shapes (eventType, schedule.*, address.*, region+breadcrumbs, registrationQuestions, images url/alt, Lexical description) + derived view-models; raw *DocSchema/FeedEventSchema/GeojsonSchema guard the wire.
  • Data layer — one shared axios client (clients API-Key, qs bracket-notation select/populate, i18next→SahajCloud locale mapping). The GeoJSON feed is the single source of map points + hierarchy counts + geometry (cached via a shared QueryClient so navigation doesn't refetch it). getClient→/clients/me; createRegistration→POST /api/events/:id/register.
  • Components + routing — every event/region consumer updated to the new fields; slug-based routing; Lexical description rendered through the existing DOMPurify path.
  • Docs — CLAUDE.md, .claude/rules/data-layer.md, .claude/docs/{environment,architecture}.md.

Testing

  • pnpm lint (0 errors), pnpm typecheck, pnpm test:run (70 unit specs), pnpm build, pnpm ladle:build — all green locally.
  • New specs: lib/geo, lib/shape/{path,hierarchy,lexical,event}, rewritten schema + api-interceptor specs.
  • /simplify + a correctness and security subagent review were run; findings fixed (notably: constrained CMS URL fields to http(s) to close a javascript:-href XSS vector; fetchQuery for correct feed staleness; Lexical list handling). The geojson endpoint was confirmed (by source) to forward populate[regions].breadcrumbs, which the whole hierarchy aggregation depends on.

Manual / live verification still needed

The node-only lane can't exercise the live API. Against a SahajCloud with a published sahaj-atlas-client key, verify: full hierarchy (country→region→area→venue→event), map clustering + feature-click, events-near-point, event detail (timing/description/images), and an in-app registration round-trip. Env: set VITE_SAHAJCLOUD_URL + VITE_ATLAS_API_KEY in .env.local.

🤖 Generated with Claude Code

Ardnived and others added 7 commits June 19, 2026 16:45
Add `pnpm types:cms` (curl payload-types.ts + the Atlas endpoint
response types from SahajCloud raw, strip the `declare module 'payload'`
augmentation) into src/types/payload/, modeled on WeMeditateWeb. These are
supplementary compile-time types to keep zod schemas and select/populate
objects honest. Add qs (bracket-notation query strings) and @turf/distance
(nearest-event sort) deps. Exclude the generated dir from eslint/prettier.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
SahajCloud regions carry no eventCount/bounds and Mapbox-resolved regions no
lat/lng, so these are derived client-side from the GeoJSON event feed:

- src/lib/geo.ts — turf bbox/center/distance helpers
- src/lib/shape/hierarchy.ts — geojson→counts/bounds keyed by region breadcrumb
  ancestry
- src/lib/shape/path.ts — region level→route mapping (city→area, center→venue)
- src/lib/shape/lexical.ts — minimal Lexical→HTML/text serializer (italic/H3/
  link), avoiding the full richtext-lexical converter in the public bundle

All pure + node-unit-tested (21 specs).

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Rewrite the axios/zod data layer against SahajCloud (Payload v3, REST-only),
replacing the legacy Rails Atlas API. No SDK — plain axios + zod.

- client.ts: one shared instance, `Authorization: clients API-Key`, qs
  bracket-notation select/populate, i18next→SahajCloud locale mapping.
- Schemas mirror SahajCloud internal shapes (eventType, schedule.*, address.*,
  region+breadcrumbs, registrationQuestions, images url/alt, Lexical description)
  plus the client-derived view-models; raw `*DocSchema`/`FeedEventSchema`/
  `GeojsonSchema` guard the wire.
- Fetchers: geojson feed as the single source of map points + counts + geometry;
  region reads compose eventCount/bounds derived client-side; getClient →
  /clients/me; getEvent serializes Lexical→HTML client-side. Query keys kept.
- mutate: createRegistration → POST /api/events/:id/register.
- Env var renamed VITE_API_ENDPOINT → VITE_SAHAJCLOUD_URL (origin + `/api`).

Region taxonomy country/region/city/center routes to country/region/area/venue.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Update every event/region consumer to the new internal field names and
slug-based routing:

- Events: eventType (was online), schedule.{firstDate,firstDate_tz,endTime,
  recurrenceType,upcomingDates} drives EventTime/EventItem/EventSoon, images
  url/alt, languages[0]. EventPanel renders the Lexical description via the
  client-side serializer through the existing DOMPurify path.
- EventDetails + EventRegistration read from `event` directly; registration
  posts {email,name,startingAt,questions} and derives questions from the
  registrationQuestions booleans.
- Routing by slug (/countries|regions|areas|venues/:slug); country flag +
  localized name from legacyData.countryCode; Mapbox feature click navigates by
  event id. Client config bootstrap via /clients/me (locale, allowedDomains,
  home region) with Fathom moved into effects.
- Region/area/venue pages derive bounds/center from the geojson feed.
- events locale: coarse recurrence (daily/weekly/monthly) + new question keys.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Update CLAUDE.md env vars, .claude/rules/data-layer.md (shared client, clients
API-Key, select/populate rules, derived shaping), .claude/docs/environment.md,
and the architecture diagram for the SahajCloud backend.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Cache the geojson feed through a shared QueryClient singleton
  (config/query-client.ts) so hierarchy fetchers reuse the map's already-loaded
  feed instead of re-fetching + re-parsing it on every navigation; single-pass
  the breadcrumb-ancestry computation (indexFeatures).
- Extract shared event derivations (isOnline / nextOccurrence / eventTimeZone)
  into src/lib/shape/event.ts and apply across the event components, replacing
  the duplicated inline logic.
- Fold EventPanel's hasTiming into `next`; dedup the two RegionLevel types
  (path.ts now uses the canonical @/types one).
- Remove dead getAtlasConfig + src/types/config.ts.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- security: constrain onlineUrl/externalRegistrationUrl/webUrl to http(s) URLs
  (they render into NextUI <Link href> outside the DOMPurify path, so a CMS
  `javascript:` value was a stored-XSS vector); drop a hostile value rather than
  failing the event read. Also closes the webUrl JSON-LD sink.
- security: add rel="noopener noreferrer" to the external-registration button.
- fix(lexical): render list/listitem nodes (the DOMPurify allowlist already
  expects ul/ol/li; previously list content ran together unwrapped).
- fix(api): loadGeojson uses fetchQuery, not ensureQueryData, so a feed older
  than the stale window is refetched instead of served from cache forever.
- fix(api): validate legacyData.countryCode shape so a malformed value can't
  throw in Intl.DisplayNames / CircleFlag.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Deploying atlas-legacy with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6928fc9
Status: ✅  Deploy successful!
Preview URL: https://e31b6ca0.syatlas.pages.dev
Branch Preview URL: https://feat-sahajcloud-data-layer.syatlas.pages.dev

View logs

Ardnived and others added 3 commits June 19, 2026 21:29
Add a getCountry spec (mocking /regions + /events/geojson) asserting the
feed-derived eventCount, bounds, ISO countryCode, and event-bearing children —
the riskiest new orchestration, flagged uncovered in PR review. Clear the shared
QueryClient between tests so loadGeojson re-reads the mocked feed.

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Align the dev/standalone client-key env var with the SahajCloud naming
(src/main.tsx + env docs).

Part of #10

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reconcile the design-system refactor on main with the SahajCloud data-layer
migration on this branch:

- App/pages: keep SahajCloud client shape (primaryDomain/allowedDomains,
  region.name/path), adopt main's renamed props (ListItem href, SearchBar
  backHref); drop debug onSelect handlers.
- EventDetails: adopt main's single orchestrator + module-private cards, but
  implement with SahajCloud fields (schedule/address/contactPhone, isOnline,
  nextOccurrence) instead of the structured timing/contact/location sub-objects.
- EventRegistration: keep SahajCloud registrationMode/registrationQuestions
  logic; keep main's exported RegistrationButtonProps; fix online→isOnline.
- EventPanel: render <EventDetails/> orchestrator.
- Stories: rewrite EventShare/EventTime/EventDetails/EventRegistration against
  the SahajCloud mockEvent shape and exported components only; honor main's
  deletion of the head-only EventMetadata story.
- security-scan hook: tighten secret-name patterns to require an assignment so
  documentation mentions (CLAUDE.md MAPBOX_SECRET) no longer false-positive.

Gates green: typecheck, lint (0 warnings), 79 unit tests, build, ladle:build.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 5b96329 into main Jun 30, 2026
3 checks passed
@Ardnived
Ardnived deleted the feat/sahajcloud-data-layer branch June 30, 2026 14:15
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): migrate data layer to SahajCloud PayloadCMS

1 participant