Skip to content

The public /v1/profiles surface is inconsistent about the {data} envelope, and the SDK declares all of it bare #744

Closed

Description

@thinkclay

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:

  1. 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.
  2. 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.
  3. 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

Activity

  1. added
    bug
    on Sep 10, 2026
  2. thinkclay commented on Sep 11, 2026

    @thinkclay
    ContributorAuthor

    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:

    SDK methods resolving to a real route 301
    envelopes agree 290
    genuinely disagree 11
    undetermined (type not statically resolvable) 44

    /v1/profiles was where I noticed it, not where it lives. The 11 span api-keys, auth, connections, engagement, follows, office-jobs and personality-assessment.

    getUser does not have consumers — I was wrong about that

    I wrote above that "getUser is the one that counts… any of them reading profile.name is reading undefined". That is not true.

    The screens importing a hook named useUserProfile import it from user-profiles-sdk-hooks, which wraps /v1/user-profiles — a different resource that happens to export a same-named hook. The only importer of profiles-sdk-hooks is the barrel. So getUser's mismatch was latent, exactly like getOrganization'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:

    1. "has a top-level data key" is too loose. It flagged PrerequisitesCheckResponse, which carries a data field among a dozen domain fields. A live probe of /v1/prerequisites/check returned a bare body. An envelope is data plus nothing but pagination/metadata keys.
    2. 39 methods unwrap the envelope themselves — 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.
    3. 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:

    1. Unwrap in the client. One change. But 39 methods already unwrap by hand — those would double-unwrap and break. Not viable without auditing all 39 first.
    2. Declare the envelope per method. What fix(profiles): OrganizationProfile described a response the API has never sent sdk#26 and chore: tighten typings across the app #29 did for the two profile routes. Honest and local; leaves the surface inconsistent.
    3. Make the routes consistent. Cleanest contract, breaking for anything consuming current shapes.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions