Repository navigation
Description
Found while closing #482. Two of the three public profile routes wrap their payload in { data }; one does not. The SDK declares all three as the bare object.
| route | wraps in { data } |
SDK declares |
|---|---|---|
GET /v1/profiles/{username} |
yes | Promise<UserProfile> — wrong |
GET /v1/profiles/organizations/{slug} |
yes | fixed in Scaffald/sdk#26 |
GET /v1/profiles/slug/{slug} |
no | Promise<ProfileBySlug> — correct |
Why it is silent
HttpClient.request returns the parsed body verbatim:
if (response.ok) {
if (response.status === 204) return undefined as T
const data = await response.json()
return data // no unwrapping
}So a wrapped route resolves to { data: T } while the method's signature promises T. TypeScript is satisfied because the generic is asserted, not inferred from the wire — this.get<UserProfile>(...) tells the compiler what to believe.
The msw mocks then hide it: each handler returns whatever shape the type claims, so the suite agrees with the type and neither is checked against the API. This is the third time that pattern has produced a wrong contract that tests certified — Scaffald/sdk#21 (employers), Scaffald/sdk#26 (organizations), and now this.
Why it matters
getUser is the one that counts. Unlike the organization profile, it has consumers, and any of them reading profile.name is reading undefined — the name is at profile.data.name. Worth checking whether that is currently masked by optional chaining somewhere.
The decision this needs
Not mechanical, which is why it is an issue rather than a PR:
- Unwrap in the client.
if (body && typeof body === 'object' && 'data' in body) return body.data. One change, fixes every wrapped route at once — and silently changes the resolved value of every method that already declares the envelope correctly. Would need an audit of which those are. - Declare the envelope per method, as fix(profiles): OrganizationProfile described a response the API has never sent sdk#26 did for
getOrganization. Honest and local, but leaves callers unwrapping by hand and the surface still inconsistent. - Make the routes consistent — pick wrapped or bare for the whole public surface and change the ones that disagree. Cleanest contract, breaking for anything already consuming the current shapes.
My inclination is (3) for the routes plus (2) for the SDK in the interim, but that is a public API decision.
Acceptance
- Every
/v1/profiles/*route agrees on the envelope, or the SDK reflects each route's actual shape -
getUser's declared return matches what it resolves to, and its consumers are checked - The msw handlers mirror real responses rather than the declared types — a mock written from the type can never catch this class
Related
- fix(profiles): OrganizationProfile described a response the API has never sent sdk#26 — the organizations half, with the live-response comparison
- The envelope convention itself: SDK-facing routes are meant to be bare, public REST routes wrap in
{ data }. Worth writing down somewhere, because nothing currently enforces or documents which a given route is.
Activity
fix(profiles): getUser declared a bare body for a route that wraps, and
fix(profiles): getUser declared a bare body for a route that wraps, and
thinkclay commentedon Sep 11, 2026
Guard landed in #746. Two corrections to this issue, both mine, and the second changes the headline number.
The scope is wider than "the profiles surface"
A census of every mounted route against every SDK method:
/v1/profileswas where I noticed it, not where it lives. The 11 span api-keys, auth, connections, engagement, follows, office-jobs and personality-assessment.getUserdoes not have consumers — I was wrong about thatI wrote above that "
getUseris the one that counts… any of them readingprofile.nameis readingundefined". That is not true.The screens importing a hook named
useUserProfileimport it fromuser-profiles-sdk-hooks, which wraps/v1/user-profiles— a different resource that happens to export a same-named hook. The only importer ofprofiles-sdk-hooksis the barrel. SogetUser's mismatch was latent, exactly likegetOrganization's. It is fixed in Scaffald/sdk#29 regardless.Three things I got wrong while counting, worth recording
The first pass said 25 mismatches. It was wrong three ways, and each correction is now encoded in the guard:
datakey" is too loose. It flaggedPrerequisitesCheckResponse, which carries adatafield among a dozen domain fields. A live probe of/v1/prerequisites/checkreturned a bare body. An envelope isdataplus nothing but pagination/metadata keys.const res = await this.get<X>(p); return res.data. Their declared type describes the inner payload and is right because the route wraps. This alone accounted for 11 false positives.return c.json({ data }, 200)is shorthand. Requiring a colon to read a key called two correct routes bare.I would treat any number produced by a first-pass static sweep of this kind with suspicion, including this one — the 11 are the ones that survived three rounds of being wrong and a live probe.
The decision this issue exists for is unchanged
Still three options, and the census makes them concrete rather than hypothetical:
The census shifts my recommendation toward (2) as the mechanical fix for the remaining 11, because (1) is now known to be unsafe and (3) is a far larger change than the 11 mismatches justify on its own. Whether the surface should later be normalised is a separate, bigger question.
The guard means neither answer is urgent: the list can only shrink, and a new mismatch fails the build.
test(api): guard the response envelope, which no mock written from a …
test(api): guard the response envelope, which no mock written from a …
fix: make nine methods agree with their route about the envelope (#30)
fix(profiles): the last 11 envelope mismatches, and one live bug amon…