fix(typescript): keep only declared response fields in typed error data$
Why
Typed error classes in generated TypeScript SDKs keep the parsed error object in their enumerable data$ field. The inbound schema that produces that object also carries the Request, Response and raw body under request$, response$ and body$, so the transform could build the error's HTTP metadata. The transform passed the whole object to the constructor, so data$.request$ held the authenticated Request. Node's default inspection of a caught error, for example console.error(err), therefore printed the request headers, including Authorization.
data$ is typed and documented as the declared response fields only, so nothing public exposed those keys.
What changed
templates/templates/typescriptv2/includes/zod-error-templating.ts: the inbound transform destructuresrequest$,response$andbody$out of the parsed value and passes only the remaining fields to the constructor. The remap path remaps that stripped object. Empty error types keep passing{}. The HTTP metadata still reaches the error through the existing constructor argument and accessors (rawResponse,headers,statusCode,body, andhttpMetain the envelope format).templates/templates/typescriptv2/tests/primary/errors.test.ts: assertsdata$holds exactly the declared fields (errorplus the envelope'shttpMeta).templates/templates/typescriptv2/tests/secondary/auth_additional.test.ts: new case in the flat-format variant. The SDK is built with basic auth and a random password, the call fails with a typed error, andutil.inspect(err)must contain neither the password nor its Base64Authorizationvalue, whilerawResponseis still set. This is the user-visible contract; it fails onmainbecausedata$.request$.headersprinted the credential.internal/features/tests.go: declares the new test ID;go generateadds it to the other targets' skip lists.- Review TypeScript SDK regenerated: the eight typed error files gain the destructure, plus gen.lock checksums.
- Changeset:
fix, patch bump,errorsfeature,typescriptv2target.
Observable change for SDK users: Object.keys(err.data$) and inspection output no longer include request$, response$ or body$. These keys were absent from the generated XData type and the README, so TypeScript callers could not have read them without a cast.
Testing
- Parsed errors through the rebuilt review SDK's
$inboundSchemafor both a plain and a remapped error type:data$holds only the declared fields andutil.inspect(err)no longer contains the bearer token, whilerawResponseis still populated. make lint,make check-template-typescriptv2,TARGET=review make build-typescriptv2pass.- Ran the secondary
auth_additional.test.tsfile against the regenerated secondary SDK: 5 passed. Temporarily restored the old transform in the generated error class and re-ran: the new case fails on the Base64 credential, the other 4 pass. - Not run locally: the full primary and secondary suites; the primary change is a key-set assertion on an already exercised path and runs in CI.
- Note on scope: in the
envelope-httpformat the documentederr.httpMeta.requeststill carries the request, so an inspect-level assertion can only hold in the flat format; that is why the end-to-end case lives in the secondary variant.
Public-safety check
- This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
- Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (
.claude/skills/public-repo-communication/SKILL.md). - Generated fixtures and review SDK changes are public-safe.
- I reviewed
git diff --check.
Summary by cubic
Stops typed error classes in generated TypeScript SDKs from leaking the authenticated Request—including its Authorization header—when an error is logged.
The inbound transform previously passed the whole parsed object to the error constructor, which stored it as the enumerable data$ field. That object carried the transport keys request$, response$, and body$ alongside the parsed response fields, so console.error(err) or util.inspect(err) printed request headers. The transform now strips those three keys and passes only the declared response fields, while HTTP metadata still reaches the error through rawResponse, headers, statusCode, body, and httpMeta.
Bug Fixes
- Destructures transport keys out of parsed values in the
typescriptv2error template, regenerated SDK error models, and the error schema snapshot. - Asserts
data$holds only the declared fields and that inspecting a basic-auth SDK error reveals neither the password nor its Base64Authorizationvalue. - Adds a patch-bump changeset for the
errorsfeature.
Behavior change for SDK users: Object.keys(err.data$) and inspection output no longer include request$, response$, or body$. The generated XData type never exposed these keys, so TypeScript callers could only reach them via a cast.