Skip to content

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Aug 29, 2025

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Added ability to retrieve a user’s billing subscription via the Billing API (experimental), enabling user-scoped subscription lookup.
  • Chores

    • Prepared a minor release for @clerk/backend with the above addition.

@panteliselef panteliselef self-assigned this Aug 29, 2025
Copy link

changeset-bot bot commented Aug 29, 2025

🦋 Changeset detected

Latest commit: b0901ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Minor
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

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

Copy link

vercel bot commented Aug 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Aug 29, 2025 5:19pm

Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Release metadata
\.changeset/wild-rice-carry.md
Adds a changeset declaring a minor release for @clerk/backend describing user subscription retrieval via BillingApi.
Backend Billing API
packages/backend/src/api/endpoints/BillingApi.ts
Introduces userBasePath = '/users' and new method getUserBillingSubscription(userId: string) that validates userId, sends GET to /users/{userId}/billing/subscription, and returns CommerceSubscription. Existing endpoints unchanged.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws—new paths to see,
A hop to “/users/…/billing/subscription” with glee.
IDs checked, requests in flight,
A CommerceSubscription nibble—byte!
Minor release, carrots raised high,
Shipping neatly—bun-approved reply. 🥕✨

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch elef/bill-1230-clerkbackend-get-users-subscription

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 summary

Prefer 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 duplication

Both 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 263722e and 14a3174.

📒 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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly 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
Use const assertions for literal types: as const
Use satisfies 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 ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly 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 path

Constant name and value align with existing organizationBasePath usage.

Comment on lines +64 to +74
/**
* @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'),
});
}
Copy link
Contributor

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.

Suggested change
/**
* @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.

Copy link

pkg-pr-new bot commented Aug 29, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6667

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6667

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6667

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6667

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6667

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6667

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6667

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6667

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6667

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6667

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6667

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6667

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6667

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6667

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6667

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6667

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6667

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6667

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6667

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6667

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6667

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6667

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6667

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6667

commit: b0901ec

Copy link
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@panteliselef panteliselef merged commit c19f936 into main Aug 29, 2025
37 checks passed
@panteliselef panteliselef deleted the elef/bill-1230-clerkbackend-get-users-subscription branch August 29, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants