You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(backend): Add directory group webhook event types - #10378
Directory Sync sends directoryGroup.created, .updated, .deleted and directoryGroupMembership.created, .deleted, but WebhookEvent has no members for them, so verifyWebhook() cannot narrow them and handlers have to cast the payload.
Adds DirectoryGroupWebhookEvent and DirectoryGroupMembershipWebhookEvent to the union, with their payload types. The deleted membership carries cause (group_deleted or member_removed). The membership payload has no id, so it declares id?: never to keep event.data.id typed as string | undefined across the union, which an existing type test guards.
Checklist
pnpm test runs as expected.
pnpm build runs as expected.
(If applicable) JSDoc comments have been added or updated for any package exports
The backend adds payload interfaces and webhook event types for directory groups and directory group memberships. The event types join the WebhookEvent union, and the new payload and event types are exported from the package. Type-level tests check event membership and payload fields, including deletion causes and nullable user IDs.
No concrete merge-blocking defect remains established for this type-only webhook addition.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title names the primary change: adding directory group webhook event types to the backend package. The changeset adds DirectoryGroupWebhookEvent and DirectoryGroupMembershipWebhookEvent to the Web…
Description check
The description states the problem (Directory Sync sends directory group and membership events that WebhookEvent does not cover, so verifyWebhook() cannot narrow them). It then lists the added union m…
Docstring Coverage
Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the primary change: adding directory group webhook event types to the backend package. The changeset adds DirectoryGroupWebhookEvent and DirectoryGroupMembershipWebhookEvent to the WebhookEvent union, along with their payload types, so the title matches the main change. It omits the membership events and the synced event, but that level of detail is not required.
Full details: Description check
Explanation
The description states the problem (Directory Sync sends directory group and membership events that WebhookEvent does not cover, so verifyWebhook() cannot narrow them). It then lists the added union members, the payload types, the cause field on deleted membership events, and the id?: never choice. All of this matches the changeset files. The description is related to the changeset in substance.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Linked repositories: Some configured repositories could not be included in this review. Cross-repository analysis may be incomplete. Please check linked-repository access and settings.
CodeRabbit Verify
Run CodeRabbit Verify to test the changes in this pull request.
The directoryGroup.* and directoryGroupMembership.* events Directory Sync sends are now in the public webhook reference, but verifyWebhook() could not narrow them because WebhookEvent had no members for them. The membership payload declares an optional id it never sets, so event.data.id keeps its type across the union.
Static analyzer: Breaking change in type alias WebhookEvent: Type changed: import("@clerk/backend").BillingPaymentAttemptWebhookEvent|import("@clerk/backend").BillingSubscriptionItemWebhookEvent… → import("@clerk/backend").BillingPaymentAttemptWebhookEvent|import("@clerk/backend").BillingSubscriptionItemWebhookEvent…
🤖 AI review (reclassified as non-breaking) (95%): WebhookEvent is an output type (returned by verifyWebhook as Promise); adding new union variants DirectoryGroupWebhookEvent and DirectoryGroupMembershipWebhookEvent only widens the return type, which is safe for consumers who switch/narrow on 'type' — existing exhaustive checks may need updating, but existing well-typed code continues to compile.
Static analyzer: Breaking change in type alias WebhookEvent: Type changed: import("@clerk/backend").BillingPaymentAttemptWebhookEvent|import("@clerk/backend").BillingSubscriptionItemWebhookEvent… → import("@clerk/backend").BillingPaymentAttemptWebhookEvent|import("@clerk/backend").BillingSubscriptionItemWebhookEvent…
🤖 AI review (reclassified as non-breaking) (95%): WebhookEvent is only used as the return type of verifyWebhook (output/Promise result) and as the source of WebhookEventType; adding new union members DirectoryGroupWebhookEvent and DirectoryGroupMembershipWebhookEvent to an output type widens what callers receive but does not break any existing well-typed consumer code — exhaustive switches would need updating but are not a compile error unless the consumer uses noUncheckedIndexedAccess/strict exhaustiveness helpers outside the type system.
🟢 Additions (2)
Added: DirectoryGroupMembershipWebhookEvent
+ export type DirectoryGroupMembershipWebhookEvent = Webhook<'directoryGroupMembership.created', DirectoryGroupMembershipWebhookEventJSON> | Webhook<'directoryGroupMembership.deleted', DeletedDirectoryGroupMembershipWebhookEventJSON>;
Added type alias DirectoryGroupMembershipWebhookEvent
The reason will be displayed to describe this comment to others. Learn more.
directoryGroup.synced is also a current Directory Sync webhook and uses this same DirectoryGroupEventPayload in the canonical webhook spec; clerk_go registers and emits it. Because it is absent here, verifyWebhook() still cannot narrow that event, and evt.type === 'directoryGroup.synced' remains a type error. Please include it in this union and in the type test/changeset so the directory-group event family is complete.
A cast-free verifyWebhook handler for all five directory events fails to compile before and compiles after; cause is only on the deleted membership and limited to its two values.
Merge-base
This PR 31566d2e
Also checked · 1 match
event.data.id stays string | undefined
Proof on 31566d2e · Did Proof get it right? Yes · No
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Represent each group event as a union member.
Extract<WebhookEvent, { type: 'directoryGroup.synced' }> resolves to never because this member contains four event names. (typescriptlang.org) Event-specific handlers using Extract therefore cannot accept synced events. The membership tests use this extraction pattern at Lines 32–33.
Use a separate Webhook union member for each group event and add an extraction test.
Included review availability: This review used your included allowance. 7 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Directory Sync sends
directoryGroup.created,.updated,.deletedanddirectoryGroupMembership.created,.deleted, butWebhookEventhas no members for them, soverifyWebhook()cannot narrow them and handlers have to cast the payload.Adds
DirectoryGroupWebhookEventandDirectoryGroupMembershipWebhookEventto the union, with their payload types. The deleted membership carriescause(group_deletedormember_removed). The membership payload has noid, so it declaresid?: neverto keepevent.data.idtyped asstring | undefinedacross the union, which an existing type test guards.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change