Repository navigation
Description
Summary
Migrate the Atlas widget's data layer off the legacy Rails REST API (https://atlas.sydevelopers.com/api) and onto SahajCloud PayloadCMS (Payload v3, REST-only). The widget runs entirely in the browser as a public, third-party-embedded bundle, so we keep axios + zod (the zod boundary is a runtime-resilience feature; no Payload SDK, no new bundle deps), repoint at SahajCloud, rewrite the zod schemas to mirror the SahajCloud API, update consuming components to the new shapes, and compute the few derived values (eventCount, bounds, distance) client-side from the GeoJSON feed. payload-types are synced as supplementary compile-time types.
Note: there is no GraphQL in Atlas today — this is a REST → PayloadCMS-REST migration.
Depends on the SahajCloud backend epic: sydevs/SahajCloud#508 (region slug, GeoJSON feed, /register endpoint, reseeded data, exported response types). Develop against a local SahajCloud (http://localhost:3000/api) with a published dev sahaj-atlas-client key.
Proposed changes
Type-sync utility
- Add a
pnpm types:cmsscript (model: WeMeditateWebpackage.jsontypes:cms+scripts/strip-payload-augmentation.mjs) that curls SahajCloud'spayload-types.ts+ the geojson/register response types from GitHub raw intosrc/types/payload/, stripping thedeclare module 'payload'augmentation. - Use the synced types to type
select/populateobjects (satisfies) and to align the zod schemas.
Rewrite zod schemas + update components
- Rewrite the schemas in
src/types/to mirror SahajCloud response shapes using internal field names (eventType,region,breadcrumbs,recurrenceType: DAILY|WEEKLY|MONTHLY,upcomingDates,registrationQuestions, imagesurl/alt, etc.), cross-checked against the syncedpayload-types. - Update consuming components to the new fields:
EventTime/EventItem/EventSoon/EventDetails, the event pages,EventPanel(description rendering), and Mapbox feature-property access insrc/components/organisms/Mapbox/(currently readspath/ cluster props off features) — adapt to the GeoJSON feed's internal-name properties.
Axios layer (src/config/api/fetch.ts, src/config/api/auth.ts)
- Base URL → SahajCloud
/api. - Interceptor header
Authorization: Bearer→clients API-Key <key>. - Build bracket-notation
select/populateparams (addqsor Payload's query stringify) — SahajCloud rejects client reads withoutselect, anddepth>1withoutpopulate. - Map the
localeparam to SahajCloud locale codes. getClient→GET /api/clients/me(API-key self-read).
Fetchers → raw reads + minimal derived shaping (keep query keys + zod .parse())
getGeojson→ the custom GeoJSON endpoint (withselect/populate).getCountries/getCountry(slug)/getRegion/getArea/getVenue→ raw/api/regions(where[level]+where[slug],breadcrumbsfor path, a children query); deriveeventCount+boundsfrom the GeoJSON feed via a newsrc/lib/geo.ts(@turf).getEvents(lat, lng, onlineOnly)→ pick nearest from the GeoJSON feed (add@turf/distance), hydrate details via raw/api/events?where[id][in]=….getEvent(id)→ raw/api/events/:id?depth=2&select&populate&locale; the response maps almost 1:1 to the rewrittenEventSchema. Remaining client work:descriptionHtmlvia a minimal client-side Lexical serializer (italic / H3 / link only), rendered through the existing dompurify path insrc/components/organisms/EventPanel/EventPanel.tsx.
Derived-only shaping module
src/lib/shape/(pure, unit-tested): geojson→counts/bounds, breadcrumb→path, the small Lexical→HTML serializer. No recurrence engine —upcomingDatescomes pre-computed from SahajCloud's virtual field.
Mutation (src/config/api/mutate.ts)
createRegistration→POST /api/events/:id/register.
Routing
- Country route param ISO
code→slug; entity identity viaslug/id; update<Link>/useNavigateandpages/{country,region,area,venue,event}.tsx.
Tests
- Update
src/config/api/fetch.test.ts(header / paths /selectparams / shapes) and the schema-typed mocks insrc/mocks/. - Add specs for
src/lib/shape/+src/lib/geo.ts.
Docs
- Update
CLAUDE.md(data-layer section),.claude/rules/data-layer.md,.claude/docs/environment.md, andSTORYBOOK.md/DESIGN_SYSTEM.mdwhere schema shapes are referenced.
Deps
- Add
qs(or Payload query helper) +@turf/distance. No SDK.
Acceptance criteria
-
pnpm types:cmssyncs types intosrc/types/payload/;pnpm typecheckpasses. - zod schemas mirror the SahajCloud API; consuming components updated; derived values (eventCount, bounds, distance) computed client-side from the GeoJSON feed.
- Every fetcher hits SahajCloud (raw reads + geojson), sends a valid
select/populate, parses through its zod schema, and keeps its existing query key. - Full hierarchy (country → region → area → venue → event), map clustering, events-near-point, event detail (timing / description / images), and in-app registration all work.
- Auth via
clients API-Key; routing byslug. - Atlas docs updated;
pnpm lint,pnpm typecheck,pnpm test:run,pnpm build,pnpm ladle:buildall pass; no new runtime SDK dependency.
Files affected
package.json,scripts/strip-payload-augmentation.mjs(new),src/types/payload/(new, synced)src/types/*.ts(schemas),src/config/api/{fetch,mutate,auth}.tssrc/lib/geo.ts(new),src/lib/shape/(new)src/components/molecules/{EventTime,EventItem,EventSoon},src/components/organisms/{EventDetails,EventPanel,Mapbox}src/pages/{country,region,area,venue,event}.tsxsrc/config/api/fetch.test.ts,src/mocks/.env,.env.local,CLAUDE.md,.claude/rules/data-layer.md,.claude/docs/environment.md
References
- Backend companion epic (dependency): feat(atlas): add region slug, geojson feed, and event registration endpoint SahajCloud#508
- WeMeditateWeb type-sync pattern:
package.jsontypes:cms+scripts/strip-payload-augmentation.mjs - SahajCloud query-param enforcement:
src/plugins/usage/hooks.ts(validateClientQueryParamsHook)
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
test(api): cover the geojson-derived hierarchy fetcher
chore(env): rename VITE_ATLAS_API_KEY → VITE_SAHAJCLOUD_API_KEY