fix(ENG-4462): send cleared optional fields to the OAuth popup
Summary
When an OAuth account is edited and an optional setup field is emptied, the Hub drops that field from the OAuth popup URL. uc-api then reconnects with the old value. This PR sends the emptied field names as cleared_credential_keys, so uc-api can remove them.
It also makes it a compile error to pass a credentials payload that has already lost its cleared fields to updateAccount, the PATCH path from ENG-902.
Overview: https://claude.ai/artifact/7GtpJfBy66EEzLHg2K4GJT
Linear: ENG-4462
Depends on StackOneHQ/unified-cloud-api#9956, which has to be live on production before the unified-cloud bump that ships this. An older uc-api would store the parameter as a junk credential.
Acceptance criteria
- Editing an OAuth2 (authorization code) account and emptying an optional, non-secret, non-read-only, non-computed field sends its name in
cleared_credential_keys, comma-joined and URL-encoded. - A cleared field is never sent as a value.
- A new link sends no
cleared_credential_keys, and its URL is unchanged. - Fields that still have a value are sent as today.
What changed
buildOAuthPopupUrl(utils/oauthPopupUrl.ts): a new helper that builds the popup URL. It takes the rawCredentialsPayloadand derives both the values (withoutClearedFields) and the cleared names (clearedFieldKeys), so the hook has nothing to get wrong. A characterization test pins the URL from before the change.clearedFieldKeys: new, incredentialsPayload.tsnext towithoutClearedFields.BuiltCredentialsPayload: a type-only brand thatbuildCredentialsPayloadreturns andupdateAccountrequires. A filled-onlyRecord<string, string>can no longer be passed by accident; a@ts-expect-errortest pins this.- The hook: passes
credentialsstraight through, and applieswithoutClearedFieldsinline only on the create path (connectAccount).
Sibling surfaces
| Surface | Decision |
|---|---|
OAuth popup (handleConnect) | changed |
Non-OAuth edit (updateAccount, ENG-902) | type tightened only; behaviour unchanged |
Create (connectAccount) | unchanged: no clears |
| OIDC and non-authorization-code OAuth2 grants | unchanged: they already take the PATCH path |
Other /connect/oauth2 URL builders | none, in hub, unified-cloud or legacy react-hub |
Test plan
oauthPopupUrl.test.ts:- the existing URL is pinned
- the parameter is appended only when there are clears, comma-joined and encoded
- a
nullentry becomes a cleared name, neverkey=null
credentialsPayload.test.ts:clearedFieldKeysreturns only thenullkeys, and none for a create payload- the brand rejects a filled-only payload
- Run locally:
npm run lint(biome and tsc) andnpm test(72 tests), all passing.
Rollout and rollback
- Release order:
- uc-api #9956, live on production.
- This PR, then a release-please release.
- The unified-cloud
@stackone/hubbump, which is what reaches users.
- Rollback: revert the unified-cloud bump. uc-api ignores a missing parameter.
Review notes
This PR went through the same 3 bounded review rounds as #9956.
Deferred: credential keys and token are still interpolated into the popup URL unencoded. That predates this ticket, and the keys come from connector configs written by admins. Only the new parameter is encoded.
Known limit: MCP OAuth connectors are presented to the Hub as oauth2, so the Hub sends clears for them too, but uc-api's MCP flow ignores them, as it already ignores every edited setup value.
🤖 Generated with Claude Code