Repository navigation
refactor(server): delete the payload#14495 scaffolding — @payloadcms/sdk throws since 3.88.0 - #87
Merged
Merged
Conversation
`server/payload-client.ts` was built around one upstream bug: `@payloadcms/sdk` resolved `undefined` on an error response instead of throwing. #83 moved this repo to `@payloadcms/[email protected]`, where `PayloadSDK.request` (`dist/index.js:120-137`) checks `!response.ok`, reads the error payload, and throws a `PayloadSDKError` carrying `status` and `errors`. Every collection and global helper routes through that one method, so no read path can resolve `undefined` on a failure any more. Removed: `validateSDKResponse`, its one remaining call site (`getWebConfig`), its unit tests, the `cms-client.test.ts` mock entry, the file-header note, and the step `docs/rules/rest-api.md` wrote into the recipe for every future query function. The guard also rejected `null`. Nothing can reach it: `findGlobal` (`dist/globals/findOne.js`) returns `response.json()` on a 2xx only, and the globals endpoint answers with the document, never a bare `null`. The one SDK path that returns `null` deliberately is `findByID({ disableErrors: true })`, which this repo never calls. Deleting the guard improves error classification rather than weakening it. It threw a bare `Error`, which `detectErrorType` could only read as UNKNOWN; `PayloadSDKError` carries `status`, which `readStatus` reads first, so a 4xx now surfaces the CLIENT copy and a 5xx the SERVER copy. `fetchWithErrorDetails` stays. Its `[PayloadCMS] <method> <url> -> <status>` line is the debugging workflow AGENTS.md documents, and it logs the full error body, where the thrown error carries only `errors[0].message`. Its docblock no longer claims the SDK swallows the status. Tests: two specs pin the upstream contract, stubbing a non-OK response and asserting the throw, the `status` it carries, and the `ErrorType` that follows. Both were confirmed failing first, against a stub returning a 200 with a `null` body — the exact shape of the bug this scaffolding existed for. Closes #85 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiKyVWeb6VXFQom2DDUfHC
The `cms-client.ts` header claimed error-utils classifies an SDK error by matching its message. `detectErrorType` reads `readStatus()` first, and `PayloadSDKError` carries `status`, so the status branch is the rule and message matching the fallback. The claim was already imprecise; deleting the guard made it misleading. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiKyVWeb6VXFQom2DDUfHC
…eter `PayloadClientConfig.previewSecret`'s JSDoc said "passed via URL parameter". `createPayloadClient` sets it as the `x-sahajcloud-preview-secret` header (`payload-client.ts:32`, `:145`). The security pass flagged the mismatch while reviewing this file's other comment fixes. Docs swept for the deleted guard: `docs/rules/rest-api.md` was the only stale surface, corrected in the first commit. `docs/rules/zod-validation.md` still describes `payloadConfigSchema` and `PayloadConfigError` accurately, and `AGENTS.md`'s `[PayloadCMS] GET <url> -> <status>` debugging line still holds. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiKyVWeb6VXFQom2DDUfHC
Deploying wemeditate-design with
|
| Latest commit: |
b64249a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a29bb3cb.wm-design.pages.dev |
| Branch Preview URL: | https://claude-refactor-payload-sdk.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | b64249a | Commit Preview URL Branch Preview URL |
Sep 07 2026, 11:19 PM |
sydevs-bot
marked this pull request as ready for review
September 7, 2026 23:21
Ardnived
added a commit
that referenced
this pull request
Nov 2, 2026
* test: drop leftovers from the KV cache removal and an unused smoke helper - `kv: undefined` in two sahajcloud-context mocks: the context lost its kv field in #107, so the mocks described a shape that no longer exists. - Three retry tests titled "…since the KV layer used to supply that": the KV layer is gone, so the titles now state only the behaviour. - `headTags()` in the smoke preview helper: exported in #28 and never called. The audit found no migration-era test files left; #87, #99 and #107 already removed them with their code. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(server): drop the stale KV binding claim `getSahajCloudContext()` returns `{ apiKey, baseURL }`, and `SahajCloudEnv.Bindings` carries no KV namespace — the binding went with `server/kv-cache.ts` in #98. The docblock still promised a reader that the helper resolves one, which is the same leftover this PR deletes from the file's own test mock. Wording now matches `sitemap-routes.ts`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXde9tn99Z82seiuKd * fix(components): call the related fetch edge-cached Nothing in this Worker holds persistent state (server/CACHING.md). The related endpoints are cached by the Cloudflare zone in front of SahajCloud, which sets `s-maxage` and `Cache-Tag` through `publicReadCacheHeaders`. The KV namespace these docblocks named went away in #98, so "KV-cached" pointed a reader at a cache they could neither inspect nor purge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXde9tn99Z82seiuKd --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
12 tasks
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
validateSDKResponseis gone.@payloadcms/[email protected], installed by chore(deps): clear 3 critical and 65 high advisories via in-range minor/patch bumps #83, throws on a non-OK response instead of resolvingundefined.error-utils.tsclassifies a 4xx as CLIENT and a 5xx as SERVER instead of UNKNOWN.docs/rules/rest-api.mdno longer writes the guard into the recipe for every future query function.Changes
server/payload-client.ts—validateSDKResponsedeleted; the file-header bug note deleted;fetchWithErrorDetailskept, its docblock corrected.server/cms-client.ts— the one remaining call site (getWebConfig), plus two stale header claims.server/payload-client.test.ts— the guard's 11 unit tests replaced by two that pin the upstream contract.docs/rules/rest-api.md— the recipe returnsresult.docs[0] ?? nulland says to let SDK errors propagate.Preview
No rendered output changes, so there is nothing new to look at. Both branch aliases are up, for a sanity check that the Worker still boots and reads the CMS:
getWebConfigread this diff touches — https://claude-refactor-payload-sdk-scaffolding-wemeditate-web.contact-c66.workers.dev/Test results
pnpm lint(0 errors),pnpm typecheck,pnpm test:run— 49 files, 502 testsserver/payload-client.test.ts7 passedb64249a— Lint/Typecheck/Unit, Smoke (web), Smoke (ladle), Workers build, Pages buildBoth new assertions were confirmed failing first, at the site that causes them: the stub was made to answer 200 with a
nullbody — the exact shape of payload#14495 — and both went red (rejects.toBeInstanceOfand.status), then green on restore.Manual verification
Nothing. No rendered output changes, and the one behaviour change (which error copy a CMS failure produces) is asserted in the specs.
Notes for reviewer
nullhalf of the guard, not theundefinedhalf.findGlobalreturnsresponse.json()only on a 2xx, and the globals endpoint answers with the document, never a barenull. The one SDK path that returnsnulldeliberately isfindByID({ disableErrors: true }), which this repo never calls.nullbody,getWebConfigwould now throw a bareTypeErrorfrompartitionPublishedPagesinstead of a named error. Retry behaviour is identical — both classify as UNKNOWN, neither retries — so this is diagnostics, not correctness.fetchWithErrorDetailsstays and is not dead. Its[PayloadCMS] <method> <url> → <status>line is the debugging workflowAGENTS.mddocuments, and it logs the full error body where the thrown error carries onlyerrors[0].message.previewSecretsaid "passed via URL parameter" while the code sends a header.Detail
The evidence for the premise.
PayloadSDK.request(node_modules/@payloadcms/sdk/dist/index.js, the!response.okbranch) reads the error payload and throwsPayloadSDKError({ errors, message, response, status }). Every collection and global helper routes through that one method —dist/globals/findOne.jsanddist/collections/find.jsboth callsdk.request(...)thenresponse.json()— so no read path can resolveundefinedon a failure.Why deleting the guard improves error handling rather than weakening it.
validateSDKResponsethrew a bareErrorwhose message matched none oferror-utils.ts's patterns, sodetectErrorTypecould only return UNKNOWN andwithRetrynever retried it.readStatusreadserror.response?.statusthenerror.status;PayloadSDKErrorsets both. The second new spec asserts exactly that path end to end.Three commits, one behaviour each:
142bd30— the deletion, its call site, its tests, and the docs step.8a820b1—/simplifypass:cms-client.ts's header claimed error-utils classifies an SDK error by matching its message. Status is the rule, message the fallback.b64249a— docs sync: thepreviewSecretJSDoc.Review passes.
/simplifyacross four angles (reuse, simplification, efficiency, altitude): one finding, thecms-client.tsheader, fixed in8a820b1./code-review: no findings, one non-blocking observation, recorded above./security-review(triggered by^server/): no findings at confidence 8+ — it confirmed the logging wrapper never touchesinit.headers, so neither the API key nor the preview secret can reach a log line.Not run:
pnpm types:cms. This change reads no new CMS field, and running it would pull unrelated schema movement from SahajCloudmaininto a refactor PR.Fixture pre-mortem. The new spec mocks
./cms-context, becausecreatePayloadClientcallsgetCmsContext()unconditionally and that throws outside a request. The shape{ apiKey, baseURL, kv }was checked againstserver/cms-context.ts'sCmsContextinterface, and matches whatserver/cms-client.test.tsalready uses. The fetch stub returns a realResponse, not a plain object, becausefetchWithErrorDetailscallsresponse.clone().Closes #85
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01QiKyVWeb6VXFQom2DDUfHC