Skip to content

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Sep 25, 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

  • Refactor

    • Public billing API routes renamed from /commerce to /billing.
    • Billing features (plans, subscriptions, statements, payment attempts, payment sources, checkouts) now operate under /billing with no behavioral or interface changes.
  • Chores

    • Standardized URL construction for billing requests to ensure consistent handling across personal and organization contexts.

Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: c509060

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

This PR includes changesets to release 14 packages
Name Type
@clerk/clerk-js Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@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 Sep 25, 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 Oct 10, 2025 9:35pm

Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Renames the billing API base path from /commerce to /billing across backend and Clerk JS, centralizes URL construction via a Billing.path helper, updates multiple resource methods and adds a changeset for patch releases. No public API signatures or method semantics changed.

Changes

Cohort / File(s) Summary
Release metadata
./.changeset/young-nails-matter.md
Adds a changeset for patch releases of @clerk/clerk-js and @clerk/backend; documents endpoint path rename from /commerce to /billing.
Backend billing base path
packages/backend/src/api/endpoints/BillingApi.ts
Changes basePath from '/commerce' to '/billing'; path construction updated accordingly; no interface changes.
Clerk JS billing namespace
packages/clerk-js/src/core/modules/billing/namespace.ts
Introduces/updates Billing.#pathRoot to '/billing' and centralizes endpoint URL construction via Billing.path, replacing hardcoded /commerce/... usages.
Clerk JS billing resources
packages/clerk-js/src/core/resources/BillingCheckout.ts, packages/clerk-js/src/core/resources/BillingPaymentSource.ts, packages/clerk-js/src/core/resources/BillingSubscription.ts
Refactors endpoint URL construction to use Billing.path(..., { orgId }) for confirm, payment source remove/makeDefault, and subscription item delete; no signature or behavior changes beyond URL formation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as App/UI
  participant CJ as Clerk JS (Billing)
  participant BE as Backend Billing API

  rect rgb(240,248,255)
    Note over CJ,BE: Base path unified to /billing via Billing.path
  end

  UI->>CJ: getPlans() / getSubscription({orgId?})
  CJ->>CJ: Build URL with Billing.path(endpoint, { orgId? })
  CJ->>BE: HTTP GET /billing/...
  BE-->>CJ: 200 OK (data)
  CJ-->>UI: Return data

  UI->>CJ: startCheckout()/confirm()/payment source ops
  CJ->>CJ: Build URL with Billing.path(..., { orgId? })
  CJ->>BE: HTTP POST/DELETE /billing/...
  BE-->>CJ: Success / Error
  CJ-->>UI: Result / Error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibbled paths from commerce’s vine,
Hopped to billing—short and fine.
One helper trail for every call,
Org or me, it guides them all.
Patch released, the routes now sing—🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely summarizes the primary change by indicating that the /commerce endpoints are replaced with /billing endpoints across the clerk-js and backend packages and follows conventional commit style.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch elef/bill-1279-js-sdks-to-use-billing-path-instead-of-commerce

📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 3aa3a07 and c509060.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/modules/billing/namespace.ts (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/modules/billing/namespace.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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

pkg-pr-new bot commented Sep 25, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c509060

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/clerk-js/src/core/resources/BillingPaymentSource.ts (1)

47-53: Fix Billing.path so org routes don’t collapse to /me

The new helper currently does:

let prefix = '';
if (orgId) {
  prefix = `/organizations/${orgId}`;
}
prefix = '/me';

That final assignment overwrites the organization prefix, so every call you switched over—including this DELETE—now goes to /me/billing/... even when orgId is provided. Organization payment-source operations will 404/regress.

Please fix the helper in packages/clerk-js/src/core/modules/billing/namespace.ts so it only falls back to /me when orgId is absent:

-    let prefix = '';
-    if (orgId) {
-      prefix = `/organizations/${orgId}`;
-    }
-    prefix = '/me';
+    const prefix = orgId ? `/organizations/${orgId}` : '/me';
packages/clerk-js/src/core/modules/billing/payment-source-methods.ts (1)

18-34: Organization billing endpoints currently resolve to the wrong base

Every call you switched to Billing.path (Line 18, 31, 43) now inherits the helper bug where /me is always selected, so organization payment-source operations will target /me/billing/... instead of /organizations/${orgId}/billing/... and 404/403. Once the helper is corrected as noted in the other comment, these requests will route properly.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4d8cb and c362b20.

📒 Files selected for processing (7)
  • .changeset/young-nails-matter.md (1 hunks)
  • packages/backend/src/api/endpoints/BillingApi.ts (1 hunks)
  • packages/clerk-js/src/core/modules/billing/namespace.ts (7 hunks)
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.ts (3 hunks)
  • packages/clerk-js/src/core/resources/BillingCheckout.ts (2 hunks)
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts (3 hunks)
  • packages/clerk-js/src/core/resources/BillingSubscription.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/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.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/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.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/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.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/clerk-js/src/core/resources/BillingSubscription.ts
  • packages/clerk-js/src/core/resources/BillingPaymentSource.ts
  • packages/clerk-js/src/core/resources/BillingCheckout.ts
  • packages/backend/src/api/endpoints/BillingApi.ts
  • packages/clerk-js/src/core/modules/billing/namespace.ts
  • packages/clerk-js/src/core/modules/billing/payment-source-methods.ts
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/young-nails-matter.md
🧬 Code graph analysis (5)
packages/clerk-js/src/core/resources/BillingSubscription.ts (1)
packages/clerk-js/src/core/modules/billing/namespace.ts (1)
  • Billing (30-142)
packages/clerk-js/src/core/resources/BillingPaymentSource.ts (1)
packages/clerk-js/src/core/modules/billing/namespace.ts (1)
  • Billing (30-142)
packages/clerk-js/src/core/resources/BillingCheckout.ts (1)
packages/clerk-js/src/core/modules/billing/namespace.ts (1)
  • Billing (30-142)
packages/clerk-js/src/core/modules/billing/namespace.ts (4)
packages/types/src/billing.ts (3)
  • GetPlansParams (110-115)
  • BillingPlanResource (122-189)
  • GetSubscriptionParams (472-474)
packages/types/src/pagination.ts (1)
  • ClerkPaginatedResponse (22-31)
packages/types/src/json.ts (1)
  • BillingPlanJSON (643-669)
packages/clerk-js/src/core/resources/BillingPlan.ts (1)
  • BillingPlan (7-54)
packages/clerk-js/src/core/modules/billing/payment-source-methods.ts (2)
packages/types/src/billing.ts (1)
  • InitializePaymentSourceParams (240-245)
packages/clerk-js/src/core/modules/billing/namespace.ts (1)
  • Billing (30-142)
⏰ 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: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/backend/src/api/endpoints/BillingApi.ts (1)

10-10: Base path update aligns with new billing routes.

The switch to /billing keeps the backend in step with the frontend refactor.

.changeset/young-nails-matter.md (1)

1-6: Changeset looks good.

Package bumps and summary read clean—no issues from my side.

Comment on lines +114 to 116
path: Billing.path(`/subscription_items/${this.id}`, { orgId }),
method: 'DELETE',
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Restore organization billing routes before merging

Line 114: Billing.path currently disregards orgId because the helper always overwrites the prefix with /me after the conditional assignment. As soon as this method is called for an organization subscription item, we’ll hit /me/billing/subscription_items/... instead of /organizations/${orgId}/billing/..., causing the cancel call to fail. Please fix the helper so it preserves the organization prefix.

 static path(subPath: string, param?: { orgId?: string }): string {
   const { orgId } = param || {};
-  let prefix = '';
-  if (orgId) {
-    prefix = `/organizations/${orgId}`;
-  }
-  prefix = '/me';
+  const prefix = orgId ? `/organizations/${orgId}` : '/me';
   return `${prefix}${Billing.#pathRoot}${subPath}`;
 }
📝 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
path: Billing.path(`/subscription_items/${this.id}`, { orgId }),
method: 'DELETE',
})
static path(subPath: string, param?: { orgId?: string }): string {
const { orgId } = param || {};
const prefix = orgId ? `/organizations/${orgId}` : '/me';
return `${prefix}${Billing.#pathRoot}${subPath}`;
}
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/BillingSubscription.ts around lines
114-116, the call uses Billing.path(..., { orgId }) but the Billing.path helper
currently overwrites the computed prefix with "/me" unconditionally; change the
helper so it only uses "/me" when orgId is absent and when orgId is present it
sets and preserves the prefix to "/organizations/{orgId}" (do not overwrite it
later), update any conditional assignment/order so orgId wins, and add/adjust
unit tests to verify paths produce "/organizations/{orgId}/billing/..." when
orgId is provided.

@panteliselef panteliselef force-pushed the elef/bill-1279-js-sdks-to-use-billing-path-instead-of-commerce branch from c362b20 to 3aa3a07 Compare October 10, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants