-
Notifications
You must be signed in to change notification settings - Fork 392
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: c509060 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.
|
WalkthroughRenames the billing API base path from Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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.
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.
c362b20
to
3aa3a07
Compare
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
Refactor
Chores