Skip to content

feat(backend): Add billing api and an endpoint for fetching plans #6449

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

Merged

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Jul 31, 2025

Description

Exposes BAPI endpoints related to billing under clerkClient.billing.*.

At this time we only expose clerkClient.billing.getPlanList() that returns a paginated list of an instance's plans.

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

    • Introduced support for commerce subscription plans and features, including new resource types for plans and their associated features.
    • Added the ability to fetch a paginated list of commerce plans via a new billing API client.
  • Refactor

    • Updated and consolidated commerce-related resource types and interfaces for improved consistency and clarity.
    • Adjusted exports to streamline available resource and JSON types.

Copy link

changeset-bot bot commented Jul 31, 2025

🦋 Changeset detected

Latest commit: b5d9a51

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 Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 8:26am

@panteliselef
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @panteliselef - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.1.16-snapshot.v20250731165820
@clerk/astro 2.10.13-snapshot.v20250731165820
@clerk/backend 2.7.0-snapshot.v20250731165820
@clerk/chrome-extension 2.5.15-snapshot.v20250731165820
@clerk/clerk-js 5.79.0-snapshot.v20250731165820
@clerk/elements 0.23.48-snapshot.v20250731165820
@clerk/clerk-expo 2.14.14-snapshot.v20250731165820
@clerk/expo-passkeys 0.3.25-snapshot.v20250731165820
@clerk/express 1.7.15-snapshot.v20250731165820
@clerk/fastify 2.4.15-snapshot.v20250731165820
@clerk/localizations 3.20.6-snapshot.v20250731165820
@clerk/nextjs 6.28.1-snapshot.v20250731165820
@clerk/nuxt 1.8.1-snapshot.v20250731165820
@clerk/clerk-react 5.38.1-snapshot.v20250731165820
@clerk/react-router 1.8.9-snapshot.v20250731165820
@clerk/remix 4.10.9-snapshot.v20250731165820
@clerk/shared 3.17.0-snapshot.v20250731165820
@clerk/tanstack-react-start 0.21.5-snapshot.v20250731165820
@clerk/testing 1.10.9-snapshot.v20250731165820
@clerk/themes 2.4.4-snapshot.v20250731165820
@clerk/types 4.72.0-snapshot.v20250731165820
@clerk/vue 1.9.1-snapshot.v20250731165820

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.1.16-snapshot.v20250731165820 --save-exact

@clerk/astro

npm i @clerk/astro@2.10.13-snapshot.v20250731165820 --save-exact

@clerk/backend

npm i @clerk/backend@2.7.0-snapshot.v20250731165820 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.5.15-snapshot.v20250731165820 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.79.0-snapshot.v20250731165820 --save-exact

@clerk/elements

npm i @clerk/elements@0.23.48-snapshot.v20250731165820 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.14.14-snapshot.v20250731165820 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.3.25-snapshot.v20250731165820 --save-exact

@clerk/express

npm i @clerk/express@1.7.15-snapshot.v20250731165820 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.4.15-snapshot.v20250731165820 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.20.6-snapshot.v20250731165820 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.28.1-snapshot.v20250731165820 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.8.1-snapshot.v20250731165820 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.38.1-snapshot.v20250731165820 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.8.9-snapshot.v20250731165820 --save-exact

@clerk/remix

npm i @clerk/remix@4.10.9-snapshot.v20250731165820 --save-exact

@clerk/shared

npm i @clerk/shared@3.17.0-snapshot.v20250731165820 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@0.21.5-snapshot.v20250731165820 --save-exact

@clerk/testing

npm i @clerk/testing@1.10.9-snapshot.v20250731165820 --save-exact

@clerk/themes

npm i @clerk/themes@2.4.4-snapshot.v20250731165820 --save-exact

@clerk/types

npm i @clerk/types@4.72.0-snapshot.v20250731165820 --save-exact

@clerk/vue

npm i @clerk/vue@1.9.1-snapshot.v20250731165820 --save-exact

@panteliselef panteliselef marked this pull request as ready for review August 4, 2025 14:08
Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

📝 Walkthrough

Walkthrough

This change introduces new commerce-related resource types and API endpoints to the backend package. A new BillingAPI class is added, exposing a getPlanList method to fetch commerce plans. Supporting resource classes CommercePlan and Feature, along with their deserialization logic, are implemented. The JSON schema is updated to include new interfaces and object types for commerce plans and features, with several existing interfaces consolidated or made internal. The API client factory is extended to expose the new billing API. Exports are updated to reflect the new and removed resource types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

  • The review involves new API client logic, new resource classes with deserialization, and substantial changes to type definitions and exports.
  • The most complex aspect is the update to the JSON schema and resource interfaces, which requires careful verification of type integrity and compatibility.
  • The remainder of the changes are straightforward additions or export adjustments.

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f36af2 and b5d9a51.

⛔ Files ignored due to path filters (1)
  • .typedoc/__tests__/__snapshots__/file-structure.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • packages/backend/src/api/factory.ts (2 hunks)
  • packages/backend/src/api/resources/Deserializer.ts (2 hunks)
  • packages/backend/src/api/resources/JSON.ts (4 hunks)
  • packages/backend/src/api/resources/index.ts (1 hunks)
  • packages/backend/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/factory.ts
  • packages/backend/src/index.ts
  • packages/backend/src/api/resources/JSON.ts
⏰ 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: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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: 9

🔭 Outside diff range comments (2)
packages/backend/src/api/resources/JSON.ts (2)

825-847: Add JSDoc documentation for CommercePlanJSON interface

The interface should have JSDoc documentation describing its purpose and clarifying fields like interval.

+/**
+ * JSON representation of a commerce subscription plan
+ */
 export interface CommercePlanJSON extends ClerkResourceJSON {

1-936: Security review and tests needed

Please address two critical areas before merging:

  • Security Review
    Tag @clerk/security for a dedicated review of all new commerce/payment logic.

  • Add Missing Tests
    No tests cover the new billing endpoints or model deserialization. At a minimum, add unit tests for:
    BillingAPI.getPlanList in packages/backend/src/api/endpoints/BillingApi.ts
    CommercePlan.fromJSON in packages/backend/src/api/resources/CommercePlan.ts
    Feature.fromJSON integration with CommercePlan.fromJSON
    • Error/edge-case handling (e.g. empty plan list, malformed JSON)

🧹 Nitpick comments (3)
packages/backend/src/api/resources/index.ts (1)

60-60: Consider alphabetical ordering of exports.

While the export is correct, consider placing it in alphabetical order with other resource exports (around line 7-8 after Client exports) for better maintainability.

export * from './Client';
export * from './CnameTarget';
+export * from './CommercePlan';
export * from './Cookies';

And remove from the current location:

export * from './WaitlistEntry';
export * from './Web3Wallet';
-export * from './CommercePlan';
packages/backend/src/api/resources/Feature.ts (1)

12-14: Consider input validation for the fromJSON method.

The method assumes all required properties exist in the JSON data. Consider adding validation to provide better error messages for malformed data.

   static fromJSON(data: FeatureJSON): Feature {
+    if (!data.id || !data.name || !data.slug) {
+      throw new Error('Invalid feature data: missing required fields');
+    }
     return new Feature(data.id, data.name, data.description, data.slug, data.avatar_url);
   }
packages/backend/src/api/resources/CommercePlan.ts (1)

71-79: Extract formatAmountJSON for better modularity

The formatAmountJSON function could be useful elsewhere and should be extracted as a private static method or utility function.

+  private static formatAmountJSON(fee: CommercePlanJSON['fee']): CommerceFee {
+    return {
+      amount: fee.amount,
+      amountFormatted: fee.amount_formatted,
+      currency: fee.currency,
+      currencySymbol: fee.currency_symbol,
+    };
+  }
+
   static fromJSON(data: CommercePlanJSON): CommercePlan {
-    const formatAmountJSON = (fee: CommercePlanJSON['fee']) => {
-      return {
-        amount: fee.amount,
-        amountFormatted: fee.amount_formatted,
-        currency: fee.currency,
-        currencySymbol: fee.currency_symbol,
-      };
-    };
     return new CommercePlan(

And update the usage:

-      formatAmountJSON(data.fee),
-      formatAmountJSON(data.annual_fee),
-      formatAmountJSON(data.annual_monthly_fee),
+      CommercePlan.formatAmountJSON(data.fee),
+      CommercePlan.formatAmountJSON(data.annual_fee),
+      CommercePlan.formatAmountJSON(data.annual_monthly_fee),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d30d566 and fbaffb2.

📒 Files selected for processing (9)
  • .changeset/early-bats-shout.md (1 hunks)
  • packages/backend/src/api/endpoints/BillingApi.ts (1 hunks)
  • packages/backend/src/api/factory.ts (2 hunks)
  • packages/backend/src/api/resources/CommercePlan.ts (1 hunks)
  • packages/backend/src/api/resources/Deserializer.ts (2 hunks)
  • packages/backend/src/api/resources/Feature.ts (1 hunks)
  • packages/backend/src/api/resources/JSON.ts (5 hunks)
  • packages/backend/src/api/resources/index.ts (1 hunks)
  • packages/backend/src/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/early-bats-shout.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
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.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/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.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/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.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
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.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
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.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
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.ts
**/*

⚙️ CodeRabbit Configuration File

**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag @clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag @clerk/security.

Any time that you tag @clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Feature.ts
  • packages/backend/src/api/resources/CommercePlan.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/index.ts
packages/**/index.{js,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use tree-shaking friendly exports

Files:

  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/index.ts
**/index.ts

📄 CodeRabbit Inference Engine (.cursor/rules/react.mdc)

Use index.ts files for clean imports but avoid deep barrel exports

Avoid barrel files (index.ts re-exports) as they can cause circular dependencies

Files:

  • packages/backend/src/api/resources/index.ts
  • packages/backend/src/index.ts
🔇 Additional comments (5)
packages/backend/src/api/resources/Deserializer.ts (2)

40-41: LGTM! Imports are properly added.

The new resource imports follow the established pattern and are correctly positioned alphabetically.


184-187: LGTM! Deserialization cases are correctly implemented.

The new switch cases for CommercePlan and Feature follow the established pattern and properly call the fromJSON static methods.

packages/backend/src/api/factory.ts (2)

32-32: LGTM! Import is properly positioned.

The BillingAPI import follows the established alphabetical ordering pattern.


56-56: LGTM! Billing API integration follows established pattern.

The billing API is correctly instantiated and positioned alphabetically in the returned client object.

Note: Since this introduces billing/commerce functionality that handles financial data, please ensure appropriate security reviews are conducted. @clerk/security should review these billing-related changes.

packages/backend/src/index.ts (1)

147-147: Export addition looks good

The addition of CommercePlan to the exported types is correct and follows the existing pattern.

Copy link

pkg-pr-new bot commented Aug 4, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: b5d9a51

@@ -846,17 +833,28 @@ export interface CommercePlanJSON {
is_recurring: boolean;
amount: number;
period: 'month' | 'annual';

Choose a reason for hiding this comment

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

I'm working on removing period and interval from plans now and also the "top level amounts", so this may need a refactor soon if merged before my change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Handled here. This PR will get merged only after BAPI changes are in effect.

Choose a reason for hiding this comment

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

I was also referring to the plans.period and plans.interval thats being added here

Copy link
Member Author

Choose a reason for hiding this comment

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

Those should be persisted, as they affect the webhooks that can be already consumed by our customers.

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: 0

♻️ Duplicate comments (1)
packages/backend/src/api/resources/JSON.ts (1)

817-823: Add JSDoc documentation for FeatureJSON interface.

The new interface should have JSDoc documentation to follow the coding guidelines requiring comprehensive JSDoc comments for public APIs.

+/**
+ * JSON representation of a plan feature
+ */
 export interface FeatureJSON extends ClerkResourceJSON {
🧹 Nitpick comments (1)
packages/backend/src/api/resources/JSON.ts (1)

862-878: Consider consistency between inline plan object and CommercePlanJSON.

The inline plan object structure differs from CommercePlanJSON interface:

  • Uses primitive amount: number instead of CommerceFeeJSON structure
  • Includes period and interval fields not present in CommercePlanJSON
  • Missing features array and other fields from CommercePlanJSON

Consider whether this inconsistency is intentional or if alignment would improve maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b43d14 and ae89b78.

📒 Files selected for processing (1)
  • packages/backend/src/api/resources/JSON.ts (4 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/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
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/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
**/*

⚙️ CodeRabbit Configuration File

**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag @clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag @clerk/security.

Any time that you tag @clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/backend/src/api/resources/JSON.ts
🧬 Code Graph Analysis (1)
packages/backend/src/api/resources/JSON.ts (2)
packages/backend/src/index.ts (4)
  • ClerkResourceJSON (59-59)
  • CommercePlanJSON (104-104)
  • CommerceSubscriptionItemJSON (105-105)
  • CommercePayerJSON (103-103)
packages/types/src/json.ts (3)
  • ClerkResourceJSON (36-40)
  • CommercePlanJSON (631-652)
  • CommerceSubscriptionItemJSON (767-783)
⏰ 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). (5)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/backend/src/api/resources/JSON.ts (4)

72-73: LGTM! Object type additions are correctly implemented.

The new entries for CommercePlan and Feature follow the established naming conventions and align with the billing API functionality being introduced.


797-815: Well-structured internal interfaces for commerce data.

The new internal interfaces follow TypeScript best practices:

  • CommercePayeeJSON properly defines gateway information with appropriate literal types
  • CommerceFeeJSON replacement for CommerceAmountJSON is more semantically clear
  • CommerceTotalsJSON correctly composes the fee structure

825-841: Excellent refactoring of CommercePlanJSON interface.

The interface improvements are well-designed:

  • Consistent use of CommerceFeeJSON for financial data
  • Proper literal union type for for_payer_type
  • Clean integration of the new features array
  • Removal of instance_id aligns with the architectural changes

893-911: Improved structured data for payment attempt details.

The enhanced inline objects provide better typed information:

  • failed_reason now includes both code and decline_code for better error handling
  • payment_source provides comprehensive payment method details with proper typing

These changes improve API usability and type safety.

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 enabled auto-merge (squash) August 8, 2025 08:44
@panteliselef panteliselef merged commit 6ff416f into main Aug 8, 2025
82 of 84 checks passed
@panteliselef panteliselef deleted the elef/com-1028-expose-bapi-endpoints-from-clerkbackend branch August 8, 2025 09:07
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.

5 participants