-
Notifications
You must be signed in to change notification settings - Fork 381
chore(backend): Get user's subscription via BillingApi #6667
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
chore(backend): Get user's subscription via BillingApi #6667
Conversation
🦋 Changeset detectedLatest commit: b0901ec 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 entry for a minor release of @clerk/backend and introduces a new BillingAPI method to fetch a user’s billing subscription via GET /users/{userId}/billing/subscription, including user ID validation. No other endpoints or public exports are modified. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant BA as BillingAPI
participant HC as HttpClient
participant SVC as Clerk Service
Caller->>BA: getUserBillingSubscription(userId)
BA->>BA: validate userId (requireId)
BA->>HC: GET /users/{userId}/billing/subscription
HC->>SVC: HTTP GET
SVC-->>HC: 200 OK (CommerceSubscription)
HC-->>BA: CommerceSubscription
BA-->>Caller: CommerceSubscription
rect rgba(230,245,255,0.5)
note right of BA: New user-scoped billing retrieval flow
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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: 1
🧹 Nitpick comments (2)
.changeset/wild-rice-carry.md (1)
5-5
: Fix casing and clarify the changeset summaryPrefer consistent casing with the code and a clearer, imperative summary.
-Get user's subscription via BillingApi. +Add BillingAPI.getUserBillingSubscription(userId) to fetch a user's billing subscription.packages/backend/src/api/endpoints/BillingApi.ts (1)
64-74
: Optional: factor shared path-builder to reduce duplicationBoth org- and user-scoped subscription getters differ only by base path and id. A small helper would reduce repetition and guard against future drift.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
.changeset/wild-rice-carry.md
(1 hunks)packages/backend/src/api/endpoints/BillingApi.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/wild-rice-carry.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/BillingApi.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/BillingApi.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/backend/src/api/endpoints/BillingApi.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/BillingApi.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/endpoints/BillingApi.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/BillingApi.ts
🧬 Code graph analysis (1)
packages/backend/src/api/endpoints/BillingApi.ts (2)
packages/backend/src/api/resources/CommerceSubscription.ts (1)
CommerceSubscription
(9-79)packages/backend/src/index.ts (1)
CommerceSubscription
(148-148)
🪛 LanguageTool
.changeset/wild-rice-carry.md
[grammar] ~4-~4: There might be a mistake here.
Context: --- '@clerk/backend': minor --- Get user's subscription via BillingApi.
(QB_NEW_EN)
[grammar] ~5-~5: There might be a mistake here.
Context: ... Get user's subscription via BillingApi.
(QB_NEW_EN)
⏰ 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: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/backend/src/api/endpoints/BillingApi.ts (1)
12-12
: LGTM on adding a user-scoped base pathConstant name and value align with existing
organizationBasePath
usage.
/** | ||
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | ||
* It is advised to pin the SDK version to avoid breaking changes. | ||
*/ | ||
public async getUserBillingSubscription(userId: string) { | ||
this.requireId(userId); | ||
return this.request<CommerceSubscription>({ | ||
method: 'GET', | ||
path: joinPaths(userBasePath, userId, 'billing', 'subscription'), | ||
}); | ||
} |
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.
🛠️ Refactor suggestion
Add explicit return type and enrich JSDoc
Public APIs must declare explicit return types; also document param/returns in JSDoc.
/**
- * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
- * It is advised to pin the SDK version to avoid breaking changes.
+ * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
+ * It is advised to pin the SDK version to avoid breaking changes.
+ *
+ * @param userId - The Clerk user ID.
+ * @returns The user's billing subscription.
*/
- public async getUserBillingSubscription(userId: string) {
+ public async getUserBillingSubscription(userId: string): Promise<CommerceSubscription> {
this.requireId(userId);
return this.request<CommerceSubscription>({
method: 'GET',
path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
});
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
/** | |
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | |
* It is advised to pin the SDK version to avoid breaking changes. | |
*/ | |
public async getUserBillingSubscription(userId: string) { | |
this.requireId(userId); | |
return this.request<CommerceSubscription>({ | |
method: 'GET', | |
path: joinPaths(userBasePath, userId, 'billing', 'subscription'), | |
}); | |
} | |
/** | |
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. | |
* It is advised to pin the SDK version to avoid breaking changes. | |
* | |
* @param userId - The Clerk user ID. | |
* @returns The user's billing subscription. | |
*/ | |
public async getUserBillingSubscription(userId: string): Promise<CommerceSubscription> { | |
this.requireId(userId); | |
return this.request<CommerceSubscription>({ | |
method: 'GET', | |
path: joinPaths(userBasePath, userId, 'billing', 'subscription'), | |
}); | |
} |
🤖 Prompt for AI Agents
In packages/backend/src/api/endpoints/BillingApi.ts around lines 64 to 74, the
public method getUserBillingSubscription lacks an explicit return type and its
JSDoc is minimal; update the method signature to declare an explicit return type
(Promise<CommerceSubscription>) and expand the JSDoc to include @param {string}
userId description and @returns {Promise<CommerceSubscription>} description,
ensuring the docstring mentions experimental status and potential null/undefined
behavior if applicable.
@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: |
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.
looks good
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Chores