-
Notifications
You must be signed in to change notification settings - Fork 371
chore(clerk-js,types): Switch to fees for plan prices #6490
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,types): Switch to fees for plan prices #6490
Conversation
🦋 Changeset detectedLatest commit: 0100be0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 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 Git ↗︎
|
@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: |
📝 WalkthroughWalkthroughThis change refactors the handling of monetary values across commerce-related resources and UI components by replacing the Estimated code review effort🎯 4 (Complex) | ⏱️ ~35 minutes Suggested labels
Suggested reviewers
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 detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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). (22)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 9
🔭 Outside diff range comments (2)
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (1)
193-200
: Localize aria-labelAvoid hard-coded strings; use localization for accessibility labels.
- <SegmentedControl.Root - aria-label='Payment method source' + <SegmentedControl.Root + aria-label={localizationKeys('commerce.checkout.paymentMethodSource')}packages/types/src/json.ts (1)
635-645
: Deprecate legacy flat amount fields in CommercePlanJSONThe
CommercePlanJSON
type now includes a structuredfee: CommerceFeeJSON
object while continuing to expose the old flatamount*
properties. Maintaining both sets without marking the old fields as deprecated increases the risk of inconsistent client usage.Suggested fixes:
- In packages/types/src/json.ts (around lines 635–645), add
@deprecated
JSDoc to these legacy fields:
• amount
• amount_formatted
• annual_amount
• annual_amount_formatted
• annual_monthly_amount
• annual_monthly_amount_formatted
• currency_symbol
• currency- Update your release notes or a migration guide to:
- Inform clients about the preferred
fee
object.- Provide a timeline for removing the deprecated fields.
🧹 Nitpick comments (17)
.changeset/rich-drinks-ring.md (1)
6-6
: Clarify the migration note for easier changelog scanningConsider mentioning key property renames in the message (e.g., “annualMonthlyAmount → annualMonthlyFee.amount”) to help downstream consumers.
packages/clerk-js/src/ui/contexts/components/Plans.tsx (1)
154-163
: Nit: typo in variable name
subscriptionBaseOnPanPeriod
→subscriptionBasedOnPlanPeriod
for clarity.packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (1)
359-363
: Avoid passingundefined
to hidden inputvalue
React can warn on undefined
value
. Default to empty string.- value={selectedPaymentSource?.id} + value={selectedPaymentSource?.id ?? ''}Also applies to: 380-384
packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)
72-76
: Clarify optionalamount
andcredit
semanticsThere’s a TODO about
amount
possibly being undefined. Consider documenting cases when these fields are absent to guide consumers and prevent defensive checks proliferating in UI.Also ensure
data.credit
shape is stable (i.e.,data.credit?.amount
) — your guard is correct.Also applies to: 104-106
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx (1)
240-242
: Inconsistent price formatting – use the sharednormalizeFormatted
helperOther components now strip trailing “.00” via
normalizeFormatted
; this one still renders the rawamountFormatted
, so$10.00
shows up instead of$10
.Import the helper (or centralise it in
utils/formatting.ts
) and render:{planFee.currencySymbol} {normalizeFormatted(planFee.amountFormatted)}to keep pricing display consistent across the UI.
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx (1)
35-53
: Heavy inline fee objects – consider a test builderEvery test now repeats the full
{ amount, amountFormatted, … }
shape. A small helper likemakeFee(1000, '$10.00')
or a factory increateFixtures
would slash ~100 LOC and keep future changes (e.g. new field) to one place.packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx (1)
221-226
: DeduplicatenormalizeFormatted
The same helper appears in multiple components. Move it to a shared utility (e.g.
src/utils/formatting.ts
) and re-use to avoid drift and ensure pricing is formatted uniformly.packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (1)
217-233
: Use the sharednormalizeFormatted
helper for fee displayOther components (e.g.
SubscriptionsList
,PricingTableDefault
) run fee strings throughnormalizeFormatted
to strip trailing “.00”.
For UI consistency, apply the same helper here:- text={`${fee.currencySymbol}${fee.amountFormatted}`} + text={`${fee.currencySymbol}${normalizeFormatted(fee.amountFormatted)}`}…and add the corresponding import.
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (1)
132-137
: DeduplicatenormalizeFormatted
– extract to a shared utilThe same helper exists here and in
PricingTableDefault.tsx
.
Move it toui/utils/formatting.ts
(or similar) and import where needed to keep DRY.packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)
289-294
: Helper duplication – reuse the sharednormalizeFormatted
This is the second definition of the same helper. Centralize it once in a utility module and import it to avoid maintenance drift.
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (2)
327-333
: Make price normalization locale-safe and reusableThe string check only handles ".00". If formatted values use commas (e.g., "10,00") you’ll miss normalization. Prefer a locale-agnostic approach or at least support both separators. Consider centralizing this helper to avoid duplication across UI.
-function normalizeFormatted(formatted: string) { - return formatted.endsWith('.00') ? formatted.slice(0, -3) : formatted; -} +function normalizeFormatted(formatted: string) { + // Strip trailing zero cents regardless of decimal separator + return /([.,]00)$/.test(formatted) ? formatted.slice(0, -3) : formatted; +}
344-346
: Switchability should be symmetric for annual→monthlyCurrent logic checks annualMonthlyFee > 0 only when on a monthly plan. Consider also requiring monthly fee > 0 when on an annual plan to avoid offering a switch to a zero-cost monthly tier unintentionally.
- const isSwitchable = - ((subscription.planPeriod === 'month' && subscription.plan.annualMonthlyFee.amount > 0) || - subscription.planPeriod === 'annual') && - subscription.status !== 'past_due'; + const isSwitchable = + ((subscription.planPeriod === 'month' && subscription.plan.annualMonthlyFee.amount > 0) || + (subscription.planPeriod === 'annual' && subscription.plan.fee.amount > 0)) && + subscription.status !== 'past_due';If product intent is to allow switching even when the destination has no base fee (e.g., free→free), feel free to dismiss.
packages/types/src/commerce.ts (5)
290-309
: Clarify fee fields’ semantics (docs)Document each fee field clearly:
- fee: monthly price when billed monthly
- annualFee: total annual price when billed annually
- annualMonthlyFee: effective monthly price when billed annually
This avoids confusion and reduces misuse across UI/client code.
1034-1034
: Document when subscription item amount is presentamount?: CommerceFee is optional. Add a brief JSDoc describing when it’s set (e.g., non-free items, proration scenarios).
1052-1052
: Currency consistency between credit and planConsider asserting/documenting that credit.amount.currency matches the plan’s currency to prevent mixed-currency totals. Type-level enforcement may be heavy, but documentation helps.
1182-1219
: Mark CommerceFee fields as readonly and specify unitsThese values are data snapshots and should be immutable. Also, clarify whether amount is in major currency units (e.g., 10.50 USD) vs minor units (e.g., 1050 cents).
-export interface CommerceFee { +export interface CommerceFee { - amount: number; - amountFormatted: string; - currency: string; - currencySymbol: string; + readonly amount: number; // Clarify units (major vs minor) in JSDoc + readonly amountFormatted: string; + readonly currency: string; // ISO 4217 code + readonly currencySymbol: string; // Display symbol corresponding to currency }
1238-1284
: Totals currency invariants (optional strong typing)All totals should share the same currency. If you want type-level guarantees, consider parameterizing CommerceFee with a currency generic and threading it through CommerceCheckoutTotals. This is optional and can be deferred if it complicates usage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
.changeset/rich-drinks-ring.md
(1 hunks)packages/clerk-js/src/core/resources/CommercePayment.ts
(3 hunks)packages/clerk-js/src/core/resources/CommercePlan.ts
(2 hunks)packages/clerk-js/src/core/resources/CommerceSubscription.ts
(6 hunks)packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
(4 hunks)packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
(3 hunks)packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
(3 hunks)packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
(8 hunks)packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
(4 hunks)packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
(4 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
(14 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
(5 hunks)packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
(3 hunks)packages/clerk-js/src/ui/contexts/components/Plans.tsx
(2 hunks)packages/clerk-js/src/utils/commerce.ts
(2 hunks)packages/types/src/commerce.ts
(15 hunks)packages/types/src/json.ts
(6 hunks)
🧰 Additional context used
📓 Path-based instructions (15)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/rich-drinks-ring.md
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}
: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.{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/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.{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/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
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/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.{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/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.{jsx,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}
: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}
: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile
,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.{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/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*.tsx
📄 CodeRabbit Inference Engine (.cursor/rules/react.mdc)
**/*.tsx
: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
**/*
⚙️ 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.
Files:
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/core/resources/CommercePayment.ts
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/core/resources/CommercePlan.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/utils/commerce.ts
packages/types/src/commerce.ts
packages/types/src/json.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableMatrix.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Visual regression testing should be performed for UI components.
Files:
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
**/*.test.{jsx,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/react.mdc)
**/*.test.{jsx,tsx}
: Use React Testing Library
Test component behavior, not implementation
Use proper test queries
Implement proper test isolation
Use proper test coverage
Test component interactions
Use proper test data
Implement proper test setup
Use proper test cleanup
Implement proper test assertions
Use proper test structure
Files:
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}
: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
🧬 Code Graph Analysis (3)
packages/clerk-js/src/core/resources/CommerceSubscription.ts (2)
packages/types/src/commerce.ts (1)
CommerceFee
(1182-1219)packages/clerk-js/src/utils/commerce.ts (1)
commerceFeeFromJSON
(10-17)
packages/clerk-js/src/core/resources/CommercePayment.ts (2)
packages/types/src/commerce.ts (2)
CommercePaymentResource
(696-780)CommerceFee
(1182-1219)packages/clerk-js/src/utils/commerce.ts (1)
commerceFeeFromJSON
(10-17)
packages/clerk-js/src/utils/commerce.ts (2)
packages/types/src/json.ts (1)
CommerceFeeJSON
(825-830)packages/types/src/commerce.ts (3)
CommerceFee
(1182-1219)CommerceCheckoutTotals
(1229-1284)CommerceStatementTotals
(1295-1295)
⏰ 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: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (15)
.changeset/rich-drinks-ring.md (1)
1-7
: Changeset present and correct for automated releasePackages and version bumps look valid; message communicates the switch to fee objects.
packages/clerk-js/src/ui/contexts/components/Plans.tsx (1)
302-306
: IgnoreannualMonthlyFee
guard suggestionThe
annualMonthlyFee
property is defined as a requiredCommerceFee
in bothpackages/types/src/commerce.ts
andpackages/clerk-js/src/core/resources/CommercePlan.ts
, so it will always be present at runtime. No additional optional‐chaining or defaulting is needed here—keep the existing logic as is.Likely an incorrect or invalid review comment.
packages/clerk-js/src/core/resources/CommercePayment.ts (1)
2-9
: Type migration toCommerceFee
looks correctImports, property type, and JSON parsing updated to fees; aligns with
@clerk/types
andutils/commerce
.Also applies to: 11-11, 17-17, 41-41
packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (3)
2-2
: Import/type update is consistentSwitch to
CommerceFee
is aligned with the refactor.
59-60
: Price display now uses fee fields — LGTM
${fee.currencySymbol}${fee.amountFormatted}
matches the newCommerceFee
structure.
312-314
: Prop type update toCommerceFee
is correct
ExistingPaymentSourceForm.totalDueNow
now matchestotals.totalDueNow
type.packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)
3-11
: Fee migration in subscription models is consistent
- Replaced
CommerceMoney
withCommerceFee
innextPayment
,amount
, andcredit
.- Switched to
commerceFeeFromJSON
deserializer.No logic changes — deserialization remains straightforward.
Also applies to: 15-16, 26-29, 49-51, 73-77, 104-106
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (1)
58-75
: Fixture realism –annualMonthlyFee.amount
looks off
annualMonthlyFee.amount
is set to8333
($83.33
) while the corresponding annual fee is$100
.
If the intent is “$8.33 / month when billed annually”, this should be833
, not8333
, or the assertions will silently rely on unrelated fields. Double-check the cents values in all test fixtures to prevent false positives.packages/types/src/json.ts (1)
825-830
: 👍 NewCommerceFeeJSON
type looks solidClear, minimal shape; no issues spotted.
packages/clerk-js/src/core/resources/CommercePlan.ts (1)
10-12
: LGTM – fee properties correctly introduced
fee
,annualFee
,annualMonthlyFee
are typed and populated viacommerceFeeFromJSON
.
No functional or typing issues detected.packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)
147-150
: Condition relies onannualMonthlyFee.amount
; confirm zero-price annual plans
plan.annualMonthlyFee.amount > 0
guards the annual–toggle logic.
If an annual plan’s monthly-equivalent is zero (free annual plan), users will never see the annual switch even thoughannualFee.amount
might be non-zero. Double-check the intended behaviour.packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (2)
379-385
: Good: normalized amounts and fee object usage in switch labelsUsing fee.amountFormatted via normalizeFormatted and fee.currencySymbol is consistent with the new CommerceFee model.
379-385
: Ensure translation placeholders match expectations for currency/codeYou pass currencySymbol as the “currency” placeholder. Verify your i18n messages expect a symbol vs a code. If they expect ISO code, pass amount.currency instead.
Also applies to: 511-514
packages/types/src/commerce.ts (2)
706-706
: LGTM: unify payment.amount to CommerceFeeThis enables consistent currency/symbol handling across UI.
1118-1118
: LGTM: nextPayment.amount moved to CommerceFeeMatches UI consumption patterns.
prefix={planPeriod === 'annual' ? 'x12' : undefined} | ||
text={`${plan.currencySymbol}${planPeriod === 'month' ? plan.amountFormatted : plan.annualMonthlyAmountFormatted}`} | ||
text={`${fee.currencySymbol}${fee.amountFormatted}`} | ||
suffix={localizationKeys('commerce.checkout.perMonth')} | ||
/> |
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.
🛠️ Refactor suggestion
Localize hard-coded 'x12' multiplier
All user-facing strings must be localized. Replace 'x12'
with a localization key (e.g., commerce.checkout.x12
) or a parameterized key.
- prefix={planPeriod === 'annual' ? 'x12' : undefined}
+ prefix={planPeriod === 'annual' ? localizationKeys('commerce.checkout.x12') : undefined}
📝 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.
prefix={planPeriod === 'annual' ? 'x12' : undefined} | |
text={`${plan.currencySymbol}${planPeriod === 'month' ? plan.amountFormatted : plan.annualMonthlyAmountFormatted}`} | |
text={`${fee.currencySymbol}${fee.amountFormatted}`} | |
suffix={localizationKeys('commerce.checkout.perMonth')} | |
/> | |
prefix={planPeriod === 'annual' ? localizationKeys('commerce.checkout.x12') : undefined} | |
text={`${fee.currencySymbol}${fee.amountFormatted}`} | |
suffix={localizationKeys('commerce.checkout.perMonth')} | |
/> |
🤖 Prompt for AI Agents
In packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx around lines 58
to 61, the hard-coded string 'x12' used as a prefix should be replaced with a
localized string. Update the code to use a localization key such as
'commerce.checkout.x12' or a parameterized localization key instead of the
literal 'x12' to ensure all user-facing strings are properly localized.
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Tests