-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Feature flag events return undefined from listEvents - missing deserializer cases
Description
When using workos.events.listEvents() to fetch feature flag events (e.g., flag.rule_updated, flag.created, flag.updated, flag.deleted), the SDK returns an array of null values instead of the actual event objects.
Steps to Reproduce
- Create/update a feature flag in the WorkOS dashboard or via API
- Call
listEventsfiltering for feature flag events:
const result = await workos.events.listEvents({
events: ['flag.rule_updated'],
limit: 10,
});
console.log(result.data); // [null, null, null, null, null, null, null, null]- Calling the REST API directly returns valid data:
curl -H "Authorization: Bearer sk_..." "https://api.workos.com/events?events[]=flag.rule_updated"Returns properly structured events with id, event, data, created_at, and context fields.
Expected Behavior
result.data should contain deserialized event objects with id, event, data, createdAt, and context properties.
Actual Behavior
result.data contains [null, null, null, null, ...] - one null for each event that should have been returned.
Root Cause
The deserializeEvent function uses a switch statement without a default case and has no handling for feature flag event types:
flag.createdflag.updatedflag.deletedflag.rule_updated
When an unrecognized event type is encountered, the switch statement falls through and the function implicitly returns undefined, which becomes null in the resulting array.
The listEvents function calls this deserializer.
Proposed Solution
Add cases for feature flag events in src/common/serializers/event.serializer.ts:
case 'flag.created':
case 'flag.updated':
case 'flag.deleted':
case 'flag.rule_updated':
return {
...eventBase,
event: event.event,
data: deserializeFeatureFlag(event.data),
};Additionally, consider adding a default case to handle unknown event types gracefully (perhaps returning a generic event object with the raw data) rather than silently returning undefined.
Environment
@workos-inc/nodeversion: 7.82.0 (also verified bug exists in v8.0.0)- Node.js version: 20.x