fix(sdk-client) #35655: translate UVE_MODE key to backend PageMode value in page.get()#35656
Conversation
…lue in page.get()
The `mode` parameter on `client.page.get()` is typed as `keyof typeof UVE_MODE`
('EDIT' | 'PREVIEW' | 'LIVE' | 'UNKNOWN'), but the value was forwarded as-is to
the GraphQL `pageMode` variable. The backend `PageMode.get(String)` matches on
the enum's `name()` (`EDIT_MODE`, `PREVIEW_MODE`, `LIVE`, ...) and silently
falls back to LIVE for anything else — so `mode: 'EDIT'` and `mode: 'PREVIEW'`
were rendering as LIVE.
Translate the key to the enum value (`UVE_MODE[mode]`) before sending so EDIT
and PREVIEW resolve to `EDIT_MODE` and `PREVIEW_MODE` on the backend.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @zJaaal's task in 2m 6s —— View job Review
VerdictClean. Fix is correctly scoped and well-tested. Nits (non-blocking)
|
Summary
Closes #35655.
The
modeparameter on@dotcms/client'sclient.page.get()is typed askeyof typeof UVE_MODE('EDIT' | 'PREVIEW' | 'LIVE' | 'UNKNOWN'), but the value was being forwarded as-is to the GraphQLpageModevariable. The backendPageMode.get(String)matches against the Java enum'sname()(EDIT_MODE,PREVIEW_MODE,LIVE, ...) and silently falls back toLIVEfor anything else — somode: 'EDIT'andmode: 'PREVIEW'from the SDK were rendering asLIVEon the backend.This change translates the enum key to its value (
UVE_MODE[mode]) right before constructing the GraphQL variables, so'EDIT'is sent as'EDIT_MODE'and'PREVIEW'as'PREVIEW_MODE'. The public type forDotCMSPageRequestParams.modeis unchanged, so this is a non-breaking fix for SDK consumers.modeargument'LIVE'(default)LIVE→ ✅ LIVELIVE→ ✅ LIVE'EDIT'EDIT→ ❌ LIVE (fallback)EDIT_MODE→ ✅ EDIT_MODE'PREVIEW'PREVIEW→ ❌ LIVE (fallback)PREVIEW_MODE→ ✅ PREVIEW_MODE'UNKNOWN'UNKNOWN→ ❌ LIVE (fallback)UNKNOWN→ ❌ LIVE (fallback, unchanged — backend has no UNKNOWN mode)Why only
@dotcms/client?@dotcms/react,@dotcms/angular, and@dotcms/uveuseUVE_MODEonly for runtime UI checks (state.mode === UVE_MODE.EDIT) and route page fetches through@dotcms/clientunderneath — they inherit the fix transitively.Files changed
libs/sdk/client/src/lib/client/page/page-api.ts— importUVE_MODE, translate key → value before sendinglibs/sdk/client/src/lib/client/page/page-api.spec.ts— replaced the existing single-mode test with a parametrizedit.eachcovering all fourUVE_MODEkeys, and updated the older "should pass correct variables" test to use a real keyTest plan
yarn nx test sdk-client --testPathPattern=page-api.spec— 278 tests pass, including new parametrized translation test (EDIT → EDIT_MODE, PREVIEW → PREVIEW_MODE, LIVE → LIVE, UNKNOWN → UNKNOWN)yarn nx lint sdk-client— clean (3 pre-existing warnings in unrelated structured-error block)@dotcms/clientrequests a page withmode: 'PREVIEW'against a live backend and confirms the preview version is returned (not LIVE)🤖 Generated with Claude Code
This PR fixes: #35655