-
Notifications
You must be signed in to change notification settings - Fork 411
fix(backend): Inconsistent create params for Invite & Org Invite #6750
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
fix(backend): Inconsistent create params for Invite & Org Invite #6750
Conversation
🦋 Changeset detectedLatest commit: 22f2fcf 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.
|
WalkthroughAdds a changeset for a patch release and updates backend SDK invitation-related type definitions to align with the backend API. Invitation creation gains a required templateSlug and optional fields; organization invitation types add optional expiresInDays, inviterUserId, and privateMetadata. No runtime logic or endpoints change. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer Code
participant SDK as Backend SDK (Invitations)
participant BAPI as Backend API
Note over Dev,SDK: Create Invitation (aligned params)
Dev->>SDK: createInvitation({ emailAddress, templateSlug, expiresInDays?, notify?, redirectUrl?, publicMetadata?, ignoreExisting? })
SDK->>BAPI: POST /invitations with payload
BAPI-->>SDK: 201 Created (invitation)
SDK-->>Dev: Invitation object
rect rgba(230,245,255,0.4)
Note right of SDK: Organization Invitations (single/bulk)
Dev->>SDK: createOrganizationInvitation({ emailAddress, role, expiresInDays?, inviterUserId?, privateMetadata?, publicMetadata?, redirectUrl? })
SDK->>BAPI: POST /organizations/:id/invitations
BAPI-->>SDK: 201 Created
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (4 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing Touches
🧪 Generate unit tests
Comment |
@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: |
wobsoriano
left a 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.
🧹
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
.changeset/all-hats-float.md (1)
5-6: Changeset likely understates a breaking type change
templateSlugappears to be newly required in InvitationAPI CreateParams (see InvitationApi.ts). If so, this is a breaking change for TS consumers and should not be a patch. Either keep it optional (preferred for patch) or bump to a minor with a clear migration note.Apply one of:
-Align create params for Invitation and OrganizationInvitation with backend API +Align create params for Invitation and OrganizationInvitation with backend API. + +Note: `templateSlug` remains optional in the SDK for backward compatibility; the backend default is used when omitted.or reclassify the release as minor if keeping
templateSlugrequired.packages/backend/src/api/endpoints/InvitationApi.ts (1)
1-8: Missing import forUserPublicMetadata
UserPublicMetadatais referenced but not imported; TS will error if it’s not globally available.-import type { ClerkPaginationRequest } from '@clerk/types'; +import type { ClerkPaginationRequest, UserPublicMetadata } from '@clerk/types';packages/backend/src/api/endpoints/OrganizationApi.ts (1)
1-1: Import missing metadata types used below
OrganizationInvitationPrivateMetadata/OrganizationInvitationPublicMetadataare referenced but not imported.-import type { ClerkPaginationRequest, OrganizationEnrollmentMode } from '@clerk/types'; +import type { + ClerkPaginationRequest, + OrganizationEnrollmentMode, + OrganizationInvitationPrivateMetadata, + OrganizationInvitationPublicMetadata, +} from '@clerk/types';
🧹 Nitpick comments (4)
packages/backend/src/api/endpoints/InvitationApi.ts (2)
11-12: Export param types for DX and to satisfy package guidelinesThese types shape a public API surface; exporting them helps consumers and aligns with “packages should export TypeScript types”.
-type TemplateSlug = 'invitation' | 'waitlist_invitation'; +export type TemplateSlug = 'invitation' | 'waitlist_invitation';Optionally also:
- type CreateParams = { ... } + export type CreateInvitationParams = CreateParams;
13-21: Add concise JSDoc for newly exposed fieldsPublic API additions should be documented (notify defaults, redirect behavior, TTL semantics).
type CreateParams = { - emailAddress: string; - expiresInDays?: number; + /** Recipient email for the invitation. */ + emailAddress: string; + /** Invitation validity in days. If omitted, backend default applies. */ + expiresInDays?: number; ignoreExisting?: boolean; - notify?: boolean; - publicMetadata?: UserPublicMetadata; - redirectUrl?: string; - templateSlug?: TemplateSlug; + /** Whether to trigger email notification. Defaults to true on backend unless specified. */ + notify?: boolean; + /** Public metadata to attach to the invited user. */ + publicMetadata?: UserPublicMetadata; + /** URL to redirect the user after accepting the invitation. */ + redirectUrl?: string; + /** Invitation email template to use. */ + templateSlug?: TemplateSlug; };packages/backend/src/api/endpoints/OrganizationApi.ts (2)
165-174: Document new invitation fields and export the params typeAdd JSDoc for the new fields and export the type for consumers.
-type CreateOrganizationInvitationParams = { +export type CreateOrganizationInvitationParams = { organizationId: string; emailAddress: string; role: OrganizationMembershipRole; - expiresInDays?: number; - inviterUserId?: string; - privateMetadata?: OrganizationInvitationPrivateMetadata; - publicMetadata?: OrganizationInvitationPublicMetadata; - redirectUrl?: string; + /** Invitation validity in days. If omitted, backend default applies. */ + expiresInDays?: number; + /** Explicit inviter user id. If omitted, the caller is used. */ + inviterUserId?: string; + /** Private metadata attached to the invitation. */ + privateMetadata?: OrganizationInvitationPrivateMetadata; + /** Public metadata attached to the invitation. */ + publicMetadata?: OrganizationInvitationPublicMetadata; + /** Redirect URL after invitation acceptance. */ + redirectUrl?: string; };
379-388: Add JSDoc to bulk endpoint and clarify accepted shapesClarify whether the endpoint accepts an array of items or an object with
emailAddresses. This avoids ambiguity between backends and@clerk/types.Proposed JSDoc:
public async createOrganizationInvitationBulk( organizationId: string, params: CreateOrganizationInvitationBulkItem[], ) { + /** + * Creates multiple invitations for the given organization. + * Accepts an array of invitation item objects. If the backend also accepts + * `{ emailAddresses: string[]; role: ... }`, document and accept that shape too + * (with runtime normalization) to ease migration. + */If both shapes are allowed by BAPI, consider overloading the signature and normalizing at runtime.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/all-hats-float.md(1 hunks)packages/backend/src/api/endpoints/InvitationApi.ts(1 hunks)packages/backend/src/api/endpoints/OrganizationApi.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/all-hats-float.md
**/*.{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/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.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/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/backend/src/api/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.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/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.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/endpoints/InvitationApi.tspackages/backend/src/api/endpoints/OrganizationApi.ts
🧬 Code graph analysis (1)
packages/backend/src/api/endpoints/OrganizationApi.ts (1)
packages/types/src/clerk.ts (1)
CreateBulkOrganizationInvitationParams(2145-2148)
⏰ 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: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/backend/src/api/endpoints/InvitationApi.ts (1)
59-65: BodyParams are automatically snake_cased by the shared request util (viasnakecase-keys); enabledeepSnakecaseBodyParamKeys: trueonly if you need nested-object key transforms.packages/backend/src/api/endpoints/OrganizationApi.ts (1)
165-185: No manual mapping needed: The request builder usessnakecaseKeysfor allbodyParams, soexpiresInDays,inviterUserId, metadata andredirectUrlare automatically serialized to the expected snake_case keys.
Description
Updates inconsistent create params for Invites & Organization Invites (including bulk).
Fixes USER-3259
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Chores