Repository navigation
feat(api): migrate data layer to SahajCloud PayloadCMS - #11
Merged
Merged
Conversation
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]>
Deploying atlas-legacy with
|
| Latest commit: |
6928fc9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e31b6ca0.syatlas.pages.dev |
| Branch Preview URL: | https://feat-sahajcloud-data-layer.syatlas.pages.dev |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-typesare 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:
country/region/area/venuecountry / region / **city** / **center**→ routed city→area, center→venue (URLs unchanged)getClientmay not have a/meGET /api/clients/meworks (Payload auto-/me+ self-access bypass)POST /api/events/registerPOST /api/events/{id}/register, body{email, name, startingAt?, questions?}codeslug; ISO code read fromlegacyData.countryCodefor flags + localized namesBearerAuthorization: clients API-Key <key>What changed
pnpm types:cms(curlpayload-types.ts+ the endpointresponse-types.ts, strip thedeclare module 'payload'block) intosrc/types/payload/. Addsqs+@turf/distance.src/lib/geo.ts(turf bbox/center/distance) andsrc/lib/shape/(geojson→counts/bounds keyed by region breadcrumb ancestry, level→route mapping, a minimal Lexical→HTML/text serializer, shared event derivations).src/types/) — mirror SahajCloud internal shapes (eventType,schedule.*,address.*,region+breadcrumbs,registrationQuestions,imagesurl/alt, Lexicaldescription) + derived view-models; raw*DocSchema/FeedEventSchema/GeojsonSchemaguard the wire.clients API-Key, qs bracket-notationselect/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.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.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 ajavascript:-href XSS vector;fetchQueryfor correct feed staleness; Lexical list handling). The geojson endpoint was confirmed (by source) to forwardpopulate[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-clientkey, 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: setVITE_SAHAJCLOUD_URL+VITE_ATLAS_API_KEYin.env.local.🤖 Generated with Claude Code