Skip to content

Feature flag events return undefined from listEvents - missing deserializer cases #1453

@scottsymm

Description

@scottsymm

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

  1. Create/update a feature flag in the WorkOS dashboard or via API
  2. Call listEvents filtering 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]
  1. 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.created
  • flag.updated
  • flag.deleted
  • flag.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/node version: 7.82.0 (also verified bug exists in v8.0.0)
  • Node.js version: 20.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions