Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Aug 8, 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

  • New Features

    • Improved billing display in the beta feature by introducing structured fee objects for plans, subscriptions, and payments, resulting in clearer and more consistent price formatting across the UI.
  • Refactor

    • Unified all pricing-related fields into fee objects, replacing previous flat amount and currency fields throughout the billing and subscription interfaces.
    • Updated all relevant UI components to use the new fee structure for displaying prices.
    • Modularized subscription and payment attempt UI components for better code organization.
    • Added helper functions to normalize price formatting by removing unnecessary decimal zeros.
    • Refactored subscription list and payment attempt pages to encapsulate row and detail rendering into dedicated components.
    • Adjusted internal contexts and utilities to support the new fee-based pricing model.
  • Bug Fixes

    • Enhanced price formatting to remove unnecessary decimal zeros, ensuring cleaner price displays.
  • Tests

    • Updated test data and assertions to align with the new fee structure and improved price formatting.

@panteliselef panteliselef requested a review from a team August 8, 2025 10:17
@panteliselef panteliselef self-assigned this Aug 8, 2025
Copy link

changeset-bot bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: 0100be0

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

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue 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 Aug 8, 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 3:50pm

Copy link

pkg-pr-new bot commented Aug 8, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 0100be0

Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

📝 Walkthrough

Walkthrough

This change refactors the handling of monetary values across commerce-related resources and UI components by replacing the CommerceMoney type with a new CommerceFee type throughout the codebase. All monetary fields in plan, payment, subscription, and checkout structures are updated to use CommerceFee objects, which encapsulate amount, formatted amount, currency, and currency symbol. JSON interfaces and deserialization utilities are updated accordingly. UI components, context hooks, and tests are refactored to use the new fee objects and their properties, with formatting helpers introduced to standardize price display and remove trailing decimals when unnecessary. Several properties and methods related to the old flat monetary structure are removed. Additionally, some UI components have been modularized by extracting subcomponents to improve code organization.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Suggested labels

types, clerk-js, react

Suggested reviewers

  • aeliox

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 53d1c86 and 69c583c.

⛔ Files ignored due to path filters (1)
  • .typedoc/__tests__/__snapshots__/file-structure.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx (2 hunks)
  • packages/clerk-js/src/utils/commerce.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/clerk-js/src/utils/commerce.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). (22)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • 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/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (1)

193-200: Localize aria-label

Avoid 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 CommercePlanJSON

The CommercePlanJSON type now includes a structured fee: CommerceFeeJSON object while continuing to expose the old flat amount* 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:
    1. Inform clients about the preferred fee object.
    2. 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 scanning

Consider 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

subscriptionBaseOnPanPeriodsubscriptionBasedOnPlanPeriod for clarity.

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx (1)

359-363: Avoid passing undefined to hidden input value

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 optional amount and credit semantics

There’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 shared normalizeFormatted helper

Other components now strip trailing “.00” via normalizeFormatted; this one still renders the raw amountFormatted, 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 builder

Every test now repeats the full { amount, amountFormatted, … } shape. A small helper like makeFee(1000, '$10.00') or a factory in createFixtures 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: Deduplicate normalizeFormatted

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 shared normalizeFormatted helper for fee display

Other components (e.g. SubscriptionsList, PricingTableDefault) run fee strings through normalizeFormatted 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: Deduplicate normalizeFormatted – extract to a shared util

The same helper exists here and in PricingTableDefault.tsx.
Move it to ui/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 shared normalizeFormatted

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 reusable

The 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→monthly

Current 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 present

amount?: 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 plan

Consider 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 units

These 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ff416f and d7daf96.

📒 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
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/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 release

Packages and version bumps look valid; message communicates the switch to fee objects.

packages/clerk-js/src/ui/contexts/components/Plans.tsx (1)

302-306: Ignore annualMonthlyFee guard suggestion

The annualMonthlyFee property is defined as a required CommerceFee in both packages/types/src/commerce.ts and packages/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 to CommerceFee looks correct

Imports, property type, and JSON parsing updated to fees; aligns with @clerk/types and utils/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 consistent

Switch to CommerceFee is aligned with the refactor.


59-60: Price display now uses fee fields — LGTM

${fee.currencySymbol}${fee.amountFormatted} matches the new CommerceFee structure.


312-314: Prop type update to CommerceFee is correct

ExistingPaymentSourceForm.totalDueNow now matches totals.totalDueNow type.

packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)

3-11: Fee migration in subscription models is consistent

  • Replaced CommerceMoney with CommerceFee in nextPayment, amount, and credit.
  • 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 to 8333 ($83.33) while the corresponding annual fee is $100.
If the intent is “$8.33 / month when billed annually”, this should be 833, not 8333, 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: 👍 New CommerceFeeJSON type looks solid

Clear, 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 via commerceFeeFromJSON.
No functional or typing issues detected.

packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)

147-150: Condition relies on annualMonthlyFee.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 though annualFee.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 labels

Using fee.amountFormatted via normalizeFormatted and fee.currencySymbol is consistent with the new CommerceFee model.


379-385: Ensure translation placeholders match expectations for currency/code

You 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 CommerceFee

This enables consistent currency/symbol handling across UI.


1118-1118: LGTM: nextPayment.amount moved to CommerceFee

Matches UI consumption patterns.

Comment on lines 58 to 61
prefix={planPeriod === 'annual' ? 'x12' : undefined}
text={`${plan.currencySymbol}${planPeriod === 'month' ? plan.amountFormatted : plan.annualMonthlyAmountFormatted}`}
text={`${fee.currencySymbol}${fee.amountFormatted}`}
suffix={localizationKeys('commerce.checkout.perMonth')}
/>
Copy link
Contributor

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.

Suggested change
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.

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