-
Notifications
You must be signed in to change notification settings - Fork 390
feat(backend): Add user_id
field to organizationInvitation.accepted
webhook events
#6887
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
feat(backend): Add user_id
field to organizationInvitation.accepted
webhook events
#6887
Conversation
🦋 Changeset detectedLatest commit: 0b2ab7b The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a new OrganizationInvitationAcceptedJSON interface (with required user_id) and updates webhook typings to introduce a distinct organizationInvitation.accepted event type using that interface; organizationInvitation.accepted is removed from the existing OrganizationInvitationWebhookEvent. Changeset metadata updated. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Backend
participant WebhookDispatcher as Dispatcher
participant Consumer
User->>Backend: Accept organization invitation
Backend->>Backend: Build OrganizationInvitationAcceptedJSON (includes user_id)
Backend->>Dispatcher: Emit 'organizationInvitation.accepted' event
Dispatcher-->>Consumer: Deliver Webhook<'organizationInvitation.accepted', OrganizationInvitationAcceptedJSON>
note right of Consumer #DFF2E1: Consumer receives payload\nwith required `user_id`
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
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.
Pull Request Overview
This PR adds a user_id
field to organizationInvitation.accepted
webhook events by creating a specialized interface and webhook type. The change provides more detailed information about accepted organization invitations by including the ID of the user who accepted the invitation.
- Creates a new
OrganizationInvitationAcceptedJSON
interface that extends the base interface with a requireduser_id
field - Separates the
organizationInvitation.accepted
event into its own webhook type to use the enhanced interface - Updates the type system to distinguish between accepted invitations and other invitation events
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/backend/src/api/resources/JSON.ts | Adds new OrganizationInvitationAcceptedJSON interface extending base interface with user_id field |
packages/backend/src/api/resources/Webhooks.ts | Creates separate webhook type for accepted invitations and removes it from generic invitation events |
.changeset/blue-teeth-report.md | Documents the breaking change for version management |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
export type OrganizationInvitationAcceptedWebhookEvent = Webhook< | ||
'organizationInvitation.accepted', | ||
OrganizationInvitationAcceptedJSON | ||
>; |
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.
The new OrganizationInvitationAcceptedWebhookEvent
type should be included in the main webhook union types to ensure it's properly recognized by the webhook handling system. Consider adding it to any existing webhook event unions in this file or related files.
Copilot uses AI. Check for mistakes.
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.
I think this comment is correct?
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.
I did add this to the main webhook union types below :)
…d` webhook events. Creates a new `OrganizationInvitationAcceptedJSON` interface that extends `OrganizationInvitationJSON` with a required `user_id` field, and updates the webhook type system to use this interface specifically for `organizationInvitation`.accepted events. Signed-off-by: Kenton Duprey <kenton@clerk.dev>
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/backend/src/api/resources/Webhooks.ts (1)
98-112
: Accepted webhook event dropped fromWebhookEvent
union
By removing'organizationInvitation.accepted'
fromOrganizationInvitationWebhookEvent
but not adding the newOrganizationInvitationAcceptedWebhookEvent
to the overallWebhookEvent
union, the accepted invitation payload is no longer represented in the exported aggregate type. Any consumers relying onWebhookEvent
to cover all webhook payloads will now fail to type-check or miss accepted events. Please include the new type in the union so accepted events remain covered.export type WebhookEvent = | UserWebhookEvent | SessionWebhookEvent | EmailWebhookEvent | SMSWebhookEvent | OrganizationWebhookEvent | OrganizationDomainWebhookEvent | OrganizationMembershipWebhookEvent | OrganizationInvitationWebhookEvent + | OrganizationInvitationAcceptedWebhookEvent | RoleWebhookEvent | PermissionWebhookEvent | WaitlistEntryWebhookEvent | BillingPaymentAttemptWebhookEvent | BillingSubscriptionWebhookEvent | BillingSubscriptionItemWebhookEvent;
🧹 Nitpick comments (1)
.changeset/blue-teeth-report.md (1)
7-7
: Tighten inline code formatting for the event name
The event name renders asorganizationInvitation`.accepted
because the backticks wrap only the first segment. Consider keeping the entire literal inside the inline code span for clarity.-Creates a new `OrganizationInvitationAcceptedJSON` interface that extends `OrganizationInvitationJSON` with a required `user_id` field, and updates the webhook type system to use this interface specifically for `organizationInvitation`.accepted events. +Creates a new `OrganizationInvitationAcceptedJSON` interface that extends `OrganizationInvitationJSON` with a required `user_id` field, and updates the webhook type system to use this interface specifically for `organizationInvitation.accepted` events.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/blue-teeth-report.md
(1 hunks)packages/backend/src/api/resources/JSON.ts
(1 hunks)packages/backend/src/api/resources/Webhooks.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/backend/src/api/resources/Webhooks.ts
packages/backend/src/api/resources/JSON.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/blue-teeth-report.md
🧬 Code graph analysis (2)
packages/backend/src/api/resources/Webhooks.ts (1)
packages/backend/src/api/resources/JSON.ts (2)
OrganizationInvitationJSON
(380-393)OrganizationInvitationAcceptedJSON
(395-397)
packages/backend/src/api/resources/JSON.ts (1)
packages/types/src/json.ts (1)
OrganizationInvitationJSON
(433-444)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build Packages
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
0ed3485
to
0b2ab7b
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/backend/src/api/resources/JSON.ts (1)
395-397
: Tighten the accepted invitation status typingSince this interface exclusively models the
organizationInvitation.accepted
webhook, we can re-declarestatus
to the'accepted'
literal (or the corresponding enum literal) so consumers get a guaranteed value instead of the inherited optional union. Right now handlers still have to defensively branch on'pending'
/'revoked'
. Consider:export interface OrganizationInvitationAcceptedJSON extends OrganizationInvitationJSON { + status: 'accepted'; user_id: string; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/blue-teeth-report.md
(1 hunks)packages/backend/src/api/resources/JSON.ts
(1 hunks)packages/backend/src/api/resources/Webhooks.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/blue-teeth-report.md
- packages/backend/src/api/resources/Webhooks.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/backend/src/api/resources/JSON.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/backend/src/api/resources/JSON.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/backend/src/api/resources/JSON.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/backend/src/api/resources/JSON.ts
🧬 Code graph analysis (1)
packages/backend/src/api/resources/JSON.ts (1)
packages/types/src/json.ts (1)
OrganizationInvitationJSON
(433-444)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
export interface OrganizationInvitationAcceptedJSON extends OrganizationInvitationJSON { | ||
user_id: string; | ||
} | ||
|
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.
Per the Coderabbit nitpick comment:
export interface OrganizationInvitationAcceptedJSON extends OrganizationInvitationJSON { | |
user_id: string; | |
} | |
export interface OrganizationInvitationAcceptedJSON extends OrganizationInvitationJSON { | |
status: 'accepted'; | |
user_id: string; | |
} | |
export type OrganizationInvitationAcceptedWebhookEvent = Webhook< | ||
'organizationInvitation.accepted', | ||
OrganizationInvitationAcceptedJSON | ||
>; |
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.
I think this comment is correct?
Signed-off-by: Kenton Duprey <kenton@clerk.dev>
Description
Add
user_id
field toorganizationInvitation.accepted
webhook events.Creates a new
OrganizationInvitationAcceptedJSON
interface that extendsOrganizationInvitationJSON
with a requireduser_id
field, and updates the webhook type system to use this interface specifically fororganizationInvitation
.accepted events.USER-3577
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit