fix(users): populate connected accounts and serve the spec's verbs - #73
Merged
Conversation
Nothing wrote to the connected_accounts collection, so
GET /user_management/users/{id}/connected_accounts/{slug} answered every
user, in every state, with a 404 — and the shape it would have returned
(provider/provider_id) was not the spec's ConnectedAccount. The path is
also specified with three more verbs the emulator did not serve.
- GET returns the spec shape: user_id, organization_id, scopes,
auth_method, api_key_last_4, state, and data_installation-prefixed ids.
Accounts are keyed by (user, slug, organization scope), with
organization_id validated when passed.
- POST imports an account from OAuth tokens; an omitted state is derived
from the token combination, a duplicate answers 409, and neither state
nor token answers 422.
- PUT updates tokens, scopes, or state; a scopes-only update does not
silently reconnect a needs_reauthorization account.
- DELETE disconnects by removing the account and its stored tokens, so a
later import is a fresh 201. Deleting a user disconnects their accounts.
- A connectedAccounts seed key references users by email and organizations
by name, cross-validated at startup like memberships are.
- State changes emit pipes.connected_account.connected /
reauthorization_needed / disconnected via collection hooks, so seeded
accounts fire the same events; payloads carry the event-only
provider_slug and data_integration_id fields.
Greptile SummaryThe PR adds spec-compatible connected-account CRUD, seed configuration, organization scoping, response formatting, lifecycle events, and user-deletion cleanup.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
|
The support-matrix scanner only resolved literal and template strings, so the connected-account verbs registered through the shared ACCOUNT_PATH const were invisible: SUPPORTED.md read as if this branch removed a Pipes endpoint instead of adding three, and the drift check failed on a table that under-counted the routes. EmulatorSeedConfig also gains the connectedAccounts key the README already documents, so library consumers can pass the seed and the matrix can claim it instead of reporting Pipes as API-only setup.
Deriving from the update DTO alone could not see what the account already holds: an expired replacement token was reported as needs_reauthorization even when a stored refresh token still refreshes it, and an expiry-only update never re-derived at all, leaving an unrefreshable account connected — each emitting (or suppressing) the wrong transition event. A replacement access token sent without an expiry deliberately drops the stored one: that expiry described the token being replaced.
# Conflicts: # README.md # src/workos/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scoped out of #71 as a separate resource; this is that fix. Nothing wrote to the
connected_accountscollection — its only reference outside the store was the one read inuser-features.ts— soGET /user_management/users/{id}/connected_accounts/{slug}answered every user, in every state, with a 404. The shape it would have returned (provider/provider_id) also wasn't the spec'sConnectedAccount, and the spec defines three more verbs on this path that the emulator didn't serve at all.What the endpoint now is
The spec's
ConnectedAccountis the Pipes resource (a data installation):{object, id, user_id, organization_id, scopes, auth_method, api_key_last_4, state, created_at, updated_at}— no provider field (the URL names it), ids prefixeddata_installation_. Accounts are keyed by (user, slug, organization scope): the optionalorganization_idquery parameter on every verb selects an org-scoped account, and an unscoped lookup never resolves a scoped one.Two facts the emulator can be told now create accounts, and both are write paths the spec itself defines — unlike identities in #71, this resource has a write API:
POST(import). Takes the spec'sConnectedAccountDto(OAuth tokens, scopes, state). An omittedstateis derived from the token combination the way the DTO describes: a token that still works — unexpired, or expired but refreshable — isconnected; an expired access token with no refresh token isneeds_reauthorization; neither state nor token is the 422 the spec reserves for an invalid combination. A duplicate for the same (user, provider, scope) answers 409.connectedAccountsseed key. References users by email — the same join key memberships use, since seeded user ids are generated — and organizations by name, both cross-validated at startup. State defaults toconnected: saying a user has a connected account is saying it is connected.PUTupdates tokens, scopes, or state; without an explicit state, only an update carrying tokens re-derives it, so a scopes-only update cannot silently reconnect aneeds_reauthorizationaccount.DELETEdisconnects by removing the account and its stored tokens — the spec's enum valuedisconnectedis observable only in the event a deletion emits, never on a stored row, so a fresh import after a disconnect is a 201 rather than a 409 against a dead link. Deleting a user disconnects their accounts the same way.Events
The spec defines
pipes.connected_account.connected/reauthorization_needed/disconnected, whose payloads carry two fields the REST shape does not (provider_slug,data_integration_id). They're emitted from collection hooks — the repo's pattern, so seeded accounts fire the same events — and only on state transitions. Onedata_integration_id is shared by every account of a provider slug, matching the integration/installation split the id prefixes name.Not covered
The hand-authored
/pipes/connectionsroutes and thedata_providersendpoint (which serves pipe connections where the spec describes a provider catalog) are untouched — they model an adjacent, non-spec surface and deserve their own decision.Verification
bun test(867 pass, 18 new insrc/workos/routes/connected-accounts.spec.ts, including the empty-state 404s, derivation rules, 409/422, org scoping, event payloads, and the user-delete cascade),bun run typecheck,bun run lint,bun run fmt:check.