Skip to content

Add dedicated event types for organisation role deserialisation#1485

Merged
csrbarber merged 2 commits intoworkos:mainfrom
smorimoto:fix-organization-role-event-deserialization
Feb 13, 2026
Merged

Add dedicated event types for organisation role deserialisation#1485
csrbarber merged 2 commits intoworkos:mainfrom
smorimoto:fix-organization-role-event-deserialization

Conversation

@smorimoto
Copy link
Contributor

Summary

  • Introduces OrganizationRoleEvent / OrganizationRoleEventResponse interfaces that match the actual Events API response shape for organization_role.* events
  • Adds deserializeOrganizationRoleEvent serialiser that correctly preserves organization_id and resource_type_slug from the event data
  • Updates event interfaces and the event serialiser to use the new event-specific types instead of reusing REST API types

The Events API returns a different shape for organisation role data compared to the REST API (e.g. object: "organization_role" vs "role", includes organization_id and resource_type_slug). Previously, the shared OrganizationRole / OrganizationRoleResponse types silently dropped these fields during deserialisation.

Closes #1484

Test plan

  • TypeScript type check passes (npx tsc --noEmit)
  • All existing tests pass (npm test)
  • Linter and formatter pass

@smorimoto smorimoto requested a review from a team as a code owner February 13, 2026 17:49
@smorimoto smorimoto requested a review from csrbarber February 13, 2026 17:49
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

Introduced dedicated event types for organization role events to correctly preserve API response fields that were previously dropped during deserialization.

  • Added OrganizationRoleEvent / OrganizationRoleEventResponse interfaces with event-specific fields (organization_id, resource_type_slug, object: "organization_role")
  • Created deserializeOrganizationRoleEvent serializer to handle event data structure
  • Updated event interfaces to use new event-specific types instead of reusing REST API types
  • Maintains backward compatibility for REST API endpoints which continue using deserializeOrganizationRole

The change addresses the mismatch between Events API and REST API response shapes, where the Events API includes additional fields that were being silently dropped.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The changes are well-structured and focused on fixing a data loss issue. The new types correctly represent the Events API response shape, the serializer implementation properly maps all fields, and REST API endpoints remain unaffected. No security concerns, no breaking changes, and the separation of concerns between event and REST API types is a good architectural decision.
  • No files require special attention

Important Files Changed

Filename Overview
src/roles/interfaces/role.interface.ts Added OrganizationRoleEvent and OrganizationRoleEventResponse interfaces to represent event-specific data structure with organization_id and resource_type_slug fields
src/authorization/serializers/organization-role.serializer.ts Added deserializeOrganizationRoleEvent function to correctly deserialize event data with organizationId and resourceTypeSlug fields
src/common/interfaces/event.interface.ts Updated organization role event types to use OrganizationRoleEvent instead of OrganizationRole, correctly matching the Events API response structure
src/common/serializers/event.serializer.ts Updated event deserializer to use deserializeOrganizationRoleEvent for organization role events, preserving all event-specific fields

Sequence Diagram

sequenceDiagram
    participant API as Events API
    participant Deserializer as Event Deserializer
    participant EventTypes as OrganizationRoleEvent Types
    participant RestTypes as OrganizationRole Types (REST API)
    
    Note over API,EventTypes: Event Flow (organization_role.* events)
    API->>Deserializer: organization_role.created/updated/deleted
    Note over API: Response includes:<br/>organization_id, resource_type_slug,<br/>object: "organization_role"
    Deserializer->>EventTypes: deserializeOrganizationRoleEvent()
    EventTypes-->>Deserializer: OrganizationRoleEvent with all fields preserved
    
    Note over Deserializer,RestTypes: REST API Flow (unchanged)
    Note over RestTypes: Response includes:<br/>id, type,<br/>object: "role"
    Note over RestTypes: Uses deserializeOrganizationRole()<br/>for REST endpoints
Loading

Last reviewed commit: 0c5cd84

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

The Events API returns a different shape for organisation role event
data compared to the REST API. The event data includes organisation_id
and resource_type_slug fields that are not present in the REST API
response, and uses a different object type ("organization_role" vs
"role").

Previously, the event serialiser reused OrganizationRole /
OrganizationRoleResponse types from the REST API, which caused
organization_id to be silently dropped during deserialisation. This
made it impossible to determine which organisation a role belongs to
when consuming organisation_role.* events.

Introduces OrganizationRoleEvent / OrganizationRoleEventResponse
interfaces and a deserializeOrganizationRoleEvent serialiser that
correctly preserves all fields from the Events API response.

Closes workos#1484
@smorimoto smorimoto force-pushed the fix-organization-role-event-deserialization branch from 0c5cd84 to 716ce13 Compare February 13, 2026 17:52
Copy link
Contributor

@csrbarber csrbarber left a comment

Choose a reason for hiding this comment

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

Thank you for this @smorimoto! I've added suggestions to include the event id, along with a variable rename.

@csrbarber csrbarber merged commit d709837 into workos:main Feb 13, 2026
7 checks passed
@smorimoto smorimoto deleted the fix-organization-role-event-deserialization branch February 13, 2026 19:07
@csrbarber csrbarber mentioned this pull request Feb 13, 2026
csrbarber added a commit that referenced this pull request Feb 13, 2026
## Description
Includes #1485

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
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.

deserializeOrganizationRole drops organization_id from event data, breaking Events API data sync

2 participants