Skip to content

fix(ENG-4462): send cleared optional fields to the OAuth popup - #258

Open
jpmiguel wants to merge 5 commits into
mainfrom
joao/eng-4462-cleared-optional-field-values-are-retained-on
Open

jpmiguel wants to merge 5 commits into
mainfrom
joao/eng-4462-cleared-optional-field-values-are-retained-on

Conversation

@jpmiguel

Copy link
Copy Markdown
Contributor

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 raw CredentialsPayload and 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, in credentialsPayload.ts next to withoutClearedFields.
  • BuiltCredentialsPayload: a type-only brand that buildCredentialsPayload returns and updateAccount requires. A filled-only Record<string, string> can no longer be passed by accident; a @ts-expect-error test pins this.
  • The hook: passes credentials straight through, and applies withoutClearedFields inline 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 null entry becomes a cleared name, never key=null
  • credentialsPayload.test.ts:
    • clearedFieldKeys returns only the null keys, and none for a create payload
    • the brand rejects a filled-only payload
  • Run locally: npm run lint (biome and tsc) and npm test (72 tests), all passing.

Rollout and rollback

  • Release order:
    1. uc-api #9956, live on production.
    2. This PR, then a release-please release.
    3. The unified-cloud @stackone/hub bump, 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

jpmiguel and others added 5 commits November 30, 2026 14:02
`buildOAuthPopupUrl` returns the same URL the hook built inline: the redirect
URI encoded, the token and attempt id as they are, then each filled credential
in form order with its value encoded. The hook now calls it. No behaviour
change; the new test pins the current string.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When editing an OAuth2 authorization-code account, the popup URL now names the
optional fields the user emptied in `cleared_credential_keys`
(comma-separated, encoded), so the API removes them instead of keeping the
stored values. The parameter is left out when nothing was cleared, which is
always the case for a new account.

Needs the unified-cloud-api change that reads the parameter to be live first:
an older API would store it as a credential.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…helper

`buildOAuthPopupUrl` now takes the raw credentials payload and splits it
itself: filled fields become query values and `null` ones become
`cleared_credential_keys`. The hook passes its payload straight through, so
the derivation the hook did untested is now covered, including that a
cleared field is never sent as a value (R1-20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… branch

`withoutClearedFields` is now computed only where the create path sends it,
so the OAuth branch can no longer pass a payload with the clears already
dropped to `buildOAuthPopupUrl` (R2-04). A narrower parameter type can't
express this: a payload without nulls is still a `CredentialsPayload`.

Also drops the "never sends a cleared field as a value" test: the exact-URL
assertion already covers it, and `not.toContain('region=')` would trip on a
field like `subregion` (R2-14).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… error

`updateAccount` took `Record<string, unknown>`, and narrowing it to
`CredentialsPayload` would not help: a filled-only `Record<string, string>`
from `withoutClearedFields` still assigns to `Record<string, string | null>`.
`buildCredentialsPayload` now returns a `BuiltCredentialsPayload`, branded
with a type-only unique symbol, and `updateAccount` requires one. Passing
`withoutClearedFields(credentials)` to the PATCH is then a type error, which
was checked by making that change in the hook. A `@ts-expect-error` spec pins
it (R3-09).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Requires human review: Fixes OAuth edits not clearing emptied optional fields by adding cleared_credential_keys to the popup URL; requires human sign-off because the new parameter depends on uc-api #9956 being deployed first, or older uc-api stores it as junk.

View guided diff | Turn on auto-fix | Re-trigger cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant