-
Notifications
You must be signed in to change notification settings - Fork 388
chore(clerk-js,backend): Replace /commerce
endpoints with /billing
endpoints
#6854
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
base: main
Are you sure you want to change the base?
chore(clerk-js,backend): Replace /commerce
endpoints with /billing
endpoints
#6854
Conversation
🦋 Changeset detectedLatest commit: c362b20 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 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.
|
WalkthroughUpdates the billing API base path from /commerce to /billing. Adds a centralized Billing.path helper in clerk-js and refactors billing-related client calls to use it. Adjusts multiple clerk-js resources to route through the helper. Includes a changeset patching @clerk/clerk-js and @clerk/backend. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant App as App (Client)
participant ClerkJS as clerk-js Billing
participant Fetch as BaseResource._fetch
participant API as Backend /billing API
User->>App: Initiates billing action
App->>ClerkJS: call Billing.* method
note over ClerkJS: Build URL via Billing.path("/...",{ orgId? })<br/>Path root: "/me/billing"
ClerkJS->>Fetch: _fetch(constructed URL, options)
Fetch->>API: HTTP request to /billing/... (server base)
API-->>Fetch: Response
Fetch-->>ClerkJS: Parsed result
ClerkJS-->>App: Return data
App-->>User: Render result
note right of ClerkJS: New/changed: centralized URL construction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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: |
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: 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
: FixBilling.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 whenorgId
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
whenorgId
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 baseEvery 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.
📒 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
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/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.
static readonly #pathRoot = '/billing'; | ||
static path(subPath: string, param?: { orgId?: string }): string { | ||
const { orgId } = param || {}; | ||
let prefix = ''; | ||
if (orgId) { | ||
prefix = `/organizations/${orgId}`; | ||
} | ||
prefix = '/me'; | ||
return `${prefix}${Billing.#pathRoot}${subPath}`; | ||
} |
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.
Org-specific billing routes are now broken.
Billing.path
always resets the prefix to /me
, so every caller—including those that pass orgId
—now hits /me/billing/...
. This regresses all organization-scoped billing operations (statements, payment sources, subscription items, checkout confirmation, etc.), which will 404 or operate on the wrong tenant. Please restore the conditional prefix so that orgId-backed requests keep using /organizations/{orgId}/billing/...
.
- let prefix = '';
- if (orgId) {
- prefix = `/organizations/${orgId}`;
- }
- prefix = '/me';
- return `${prefix}${Billing.#pathRoot}${subPath}`;
+ 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.
static readonly #pathRoot = '/billing'; | |
static path(subPath: string, param?: { orgId?: string }): string { | |
const { orgId } = param || {}; | |
let prefix = ''; | |
if (orgId) { | |
prefix = `/organizations/${orgId}`; | |
} | |
prefix = '/me'; | |
return `${prefix}${Billing.#pathRoot}${subPath}`; | |
} | |
static readonly #pathRoot = '/billing'; | |
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/modules/billing/namespace.ts around lines 31 to
40, the prefix is unconditionally reset to '/me' which ignores orgId and breaks
organization-scoped billing routes; restore the conditional so when param.orgId
is provided the prefix remains `/organizations/${orgId}` and only use '/me' when
no orgId is present, then return `${prefix}${Billing.#pathRoot}${subPath}` as
before; ensure no other code overrides prefix after the orgId check.
path: Billing.path(`/checkouts/${this.id}/confirm`, { orgId: this.payer.organizationId }), | ||
body: params as any, | ||
}), |
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.
Confirm checkout fails for organization payers
Line 64 relies on Billing.path
, which currently ignores orgId
and always returns the /me/billing/...
path. As a result, confirming an organization checkout will call the wrong endpoint. Please fix Billing.path
to respect the organization prefix before merging.
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/BillingCheckout.ts around lines 64 to
66, the call to Billing.path(..., { orgId: this.payer.organizationId }) fails
because Billing.path currently ignores orgId and always returns a
/me/billing/... path; update Billing.path to prepend the organization prefix
when an orgId is provided (i.e., return /organizations/{orgId}/billing/...
instead of /me/billing/...), keep the existing behavior when orgId is undefined,
and ensure the path builder is used consistently by other callers (adjust or add
tests to cover both org and me paths).
path: Billing.path(`/subscription_items/${this.id}`, { orgId }), | ||
method: 'DELETE', | ||
}) |
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.
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.
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.
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
No functional behavior changes beyond the new billing endpoint paths.