Skip to content

feat(webhooks): Parse feature_flags.* events into typed models - #580

Open
stanleyphu wants to merge 1 commit into
mainfrom
feat/feature-flags-webhook-event-models
Open

stanleyphu wants to merge 1 commit into
mainfrom
feat/feature-flags-webhook-event-models

Conversation

@stanleyphu

Copy link
Copy Markdown
Contributor

Description

Why

Ruby is the only typed WorkOS SDK that still hands back the eight new feature_flags.* webhook events as plain Hashes. Node, Python, Go, .NET and Kotlin already parse them into typed models. WorkOS is deprecating the flag.* events and asking customers to move to feature_flags.*, so Ruby customers who migrate lose the typed event.data they had on the legacy events.

The events are already in the subscription enum and the generated event classes exist, but WebhookEvent::EVENT_DATA_MODELS (hand-maintained, @oagen-ignore-file) never got entries for them. This adds the eight mappings next to the legacy flag.* entries, which stay as they are. Each event uses the data model its generated event class already declares, which is also what the Node serializer uses:

  • feature_flags.flag.{created,updated,deleted} → FeatureFlagsFlag{Created,Updated,Deleted}Data. All three are aliases of FeatureFlagsFlagCreatedData, so .class prints that name.
  • feature_flags.flag_rule.{created,updated,deleted} → FlagRule
  • feature_flags.flag_target.{created,deleted} → FlagTarget

Unknown events still fall back to a Hash. WebhookEvent still doesn't expose context for any event, including previous_attributes on the update events. It's available on event.raw["context"], the same as before.

Proof

I ran the same signed payload through client.webhooks.construct_event and printed event.data.class, before and after:

== before (origin/main 6acba86)
feature_flags.flag.created         Hash
feature_flags.flag.updated         Hash
feature_flags.flag.deleted         Hash
feature_flags.flag_rule.created    Hash
feature_flags.flag_rule.updated    Hash
feature_flags.flag_rule.deleted    Hash
feature_flags.flag_target.created  Hash
feature_flags.flag_target.deleted  Hash
flag.rule_updated                  WorkOS::FeatureFlagsFlagCreatedData
== after (this branch)
feature_flags.flag.created         WorkOS::FeatureFlagsFlagCreatedData
feature_flags.flag.updated         WorkOS::FeatureFlagsFlagCreatedData
feature_flags.flag.deleted         WorkOS::FeatureFlagsFlagCreatedData
feature_flags.flag_rule.created    WorkOS::FlagRule
feature_flags.flag_rule.updated    WorkOS::FlagRule
feature_flags.flag_rule.deleted    WorkOS::FlagRule
feature_flags.flag_target.created  WorkOS::FlagTarget
feature_flags.flag_target.deleted  WorkOS::FlagTarget
flag.rule_updated                  WorkOS::FeatureFlagsFlagCreatedData

The new test/workos/test_webhook_event.rb sends spec-shaped payloads (the same ones the Python SDK uses as fixtures) through construct_event. Before this change, every feature_flags.* case fails because the data is a Hash, for example:

Expected {"object" => "flag_rule", "id" => "flag_rule_01EHZNVPK3SFK441A1RGBFSHRT", ...} to be an instance of WorkOS::FlagRule, not Hash.
NoMethodError: undefined method 'target_id' for an instance of Hash
16 runs, 33 assertions, 8 failures, 3 errors, 0 skips

The four legacy flag.* cases and the unknown-event case passed on main too. With this change, all 16 pass, and the field checks pass as well: rule.position == 0, target.rule_id, and flag.owner.email parsed into a typed owner.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

No. This only changes the SDK's parsed type for events that are already documented.

🤖 Generated with Claude Code

construct_event returned the eight feature_flags.* events' data as a
plain Hash because EVENT_DATA_MODELS had no entries for them. Map them
to the generated models the event classes already use
(FeatureFlagsFlag*Data, FlagRule, FlagTarget), alongside the legacy
flag.* entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stanleyphu
stanleyphu marked this pull request as ready for review November 17, 2026 18:57
@stanleyphu
stanleyphu requested a review from a team as a code owner November 17, 2026 18:57
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Adds typed event.data for all eight feature_flags.* webhook events.

  • Feature-flag webhooks now return typed flag, rule, and target data.

No actionable issues found. Tests were reviewed but not run.

Acknowledged scope: stanleyphu explicitly notes that typed context, including previous_attributes, remains unsupported; callers can still use event.raw["context"].

Reviews (1) · Last reviewed commit: "feat(webhooks): Parse feature_flags.* ev..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

1 participant