-
Notifications
You must be signed in to change notification settings - Fork 44
Add context field to Event interface #1442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The listEvents API returns a context field with metadata like client_id, but the deserializer was dropping it. Add optional context field to EventBase and EventResponseBase interfaces, and pass it through in the deserializer. Fixes #1415
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds support for the context field in Event interfaces, which was previously being dropped by the deserializer despite being returned by the WorkOS API.
Changes Made
- Added optional
context?: Record<string, string>field toEventBaseandEventResponseBaseinterfaces - Updated
deserializeEventserializer to pass through thecontextfield from API responses - Added test coverage with a sample context containing
client_id
Implementation
The change is minimal and follows the existing pattern for optional fields on events. The context field is properly typed as an optional Record<string, string>, which matches the test fixture showing client_id as the primary use case. The deserializer correctly spreads event.context into the eventBase object, ensuring it's included in all event types that extend EventBase.
Testing
Test fixtures include context data in both the API response format (EventResponse) and the deserialized format (Event), validating that the field is properly preserved through the serialization pipeline.
Confidence Score: 5/5
- This PR is safe to merge - it adds a missing field without breaking existing functionality.
- The changes are minimal, well-tested, and follow existing patterns. The optional field addition is backward compatible, the serializer correctly passes through the data, and test coverage validates the functionality. No breaking changes or logic errors detected.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/common/interfaces/event.interface.ts | 5/5 | Added optional context field to EventBase and EventResponseBase interfaces with Record<string, string> type |
| src/common/serializers/event.serializer.ts | 5/5 | Updated deserializeEvent to pass through context field from API response to Event object |
| src/events/events.spec.ts | 5/5 | Added context test data with client_id to both Event and EventResponse fixtures |
Sequence Diagram
sequenceDiagram
participant API as WorkOS API
participant Deserializer as deserializeEvent
participant EventBase as EventBase Interface
participant Client as SDK Client
API->>Deserializer: EventResponse (with context)
Note over Deserializer: Extract base fields
Deserializer->>EventBase: Create EventBase object
Note over EventBase: id, createdAt, context
Deserializer->>Deserializer: Switch on event type
Deserializer->>Deserializer: Deserialize event data
Deserializer->>Client: Return Event (with context)
Note over Client: Context now preserved
More flexible type since WorkOS doesn't document the exact schema of the context object values.
EventBase (deserialized) uses `context: T | undefined` since the serializer always assigns it. EventResponseBase keeps `context?:` since the API may omit it entirely.
## Description - #1442 ## 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.
Summary
contextfield toEventBaseandEventResponseBaseinterfacescontextindeserializeEventserializerThe
listEventsAPI returns acontextobject containing metadata likeclient_id, but the deserializer was dropping it.Test plan
Manual verification script
Save as
scripts/verify-context-field.tsand run withnpx tsx scripts/verify-context-field.ts:Fixes #1415