Skip to content

fix: ApiKey.owner type missing user variant and organizationId#1650

Merged
gjtorikian merged 1 commit into
mainfrom
fix/api-key-owner-user-type
Jul 1, 2026
Merged

fix: ApiKey.owner type missing user variant and organizationId#1650
gjtorikian merged 1 commit into
mainfrom
fix/api-key-owner-user-type

Conversation

@kairadiant

Copy link
Copy Markdown
Contributor

Summary

  • ApiKey.owner was typed as { type: 'organization'; id: string } only, but the API can return a user owner with { type: 'user'; id: string; organization_id: string }
  • Updated ApiKey and SerializedApiKey interfaces to use a discriminated union covering both variants
  • Updated deserializeApiKey to convert organization_idorganizationId for user owners
  • Added fixture and test case for the user owner case

Test plan

  • npx jest src/api-keys/api-keys.spec.ts — all 12 tests pass

Reported by customer in T-9253.

@kairadiant kairadiant requested review from a team as code owners July 1, 2026 18:26
@kairadiant kairadiant requested a review from tribble July 1, 2026 18:26
@kairadiant kairadiant changed the title Fix ApiKey.owner type to include user variant and organizationId fix: ApiKey.owner type missing user variant and organizationId Jul 1, 2026
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates API key owner handling for user-owned keys. The main changes are:

  • Adds a user-owner variant to ApiKey.owner with organizationId.
  • Adds the serialized user-owner shape with organization_id.
  • Converts organization_id to organizationId in deserializeApiKey.
  • Adds a fixture-backed test for validating user-owned API keys.

Confidence Score: 5/5

Safe to merge with minimal risk.

The change is narrow, preserves the existing organization-owner shape, and adds targeted coverage for the new user-owner response.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the before-state test for the API key user-owner serializer/type behavior and observed the TypeScript errors TS2322 for type: 'user' and TS2339 for missing organizationId on the old organization-only owner.
  • Ran the after-state validation for the API key user-owner flow and confirmed TypeScript compilation succeeded, runtime output was produced, and the organization-owner preservation check ran with an attempted Jest output.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/api-keys/interfaces/api-key.interface.ts Updates ApiKey.owner and SerializedApiKey.owner to discriminated unions for organization and user owners.
src/api-keys/serializers/api-key.serializer.ts Maps serialized user owner organization_id to public organizationId while preserving organization owners.
src/api-keys/api-keys.spec.ts Adds coverage for validating an API key whose owner is a user and expects organizationId after deserialization.
src/api-keys/fixtures/validate-api-key-user-owner.json Adds a fixture matching the serialized user-owner API key payload with organization_id.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant API as WorkOS API
participant SDK as ApiKeys.createValidation
participant Serializer as deserializeApiKey
participant User as SDK Consumer

API-->>SDK: "api_key.owner { type: "user", id, organization_id }"
SDK->>Serializer: deserializeApiKey(api_key)
Serializer-->>SDK: "owner { type: "user", id, organizationId }"
SDK-->>User: "{ apiKey }"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant API as WorkOS API
participant SDK as ApiKeys.createValidation
participant Serializer as deserializeApiKey
participant User as SDK Consumer

API-->>SDK: "api_key.owner { type: "user", id, organization_id }"
SDK->>Serializer: deserializeApiKey(api_key)
Serializer-->>SDK: "owner { type: "user", id, organizationId }"
SDK-->>User: "{ apiKey }"
Loading

Reviews (1): Last reviewed commit: "Fix ApiKey.owner type to include user va..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

T-Rex pricing update — T-Rex was free through June 2026. Effective July 1, 2026, T-Rex adds 2 credits on top of the standard 1-credit review (3 total). T-Rex settings

@gjtorikian gjtorikian merged commit f896a1f into main Jul 1, 2026
7 of 8 checks passed
@gjtorikian gjtorikian deleted the fix/api-key-owner-user-type branch July 1, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants