feat(clerk-js,localizations,shared,ui): Add support for discounts/promo codes - #9316
feat(clerk-js,localizations,shared,ui): Add support for discounts/promo codes#9316dstaley wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 4e89c8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 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.
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-google-signin
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
@clerk/sharedCurrent version: 4.26.0 Subpath
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdded billing discount contracts and JSON conversion. Subscription items now expose applied discount redemptions. The subscription overview, payment attempts, and statements render discount details with localized amounts. Billing localization keys were added across supported resources. Tests cover fixed discounts, percentage discounts, and redemption mapping. Patch changesets and a bundle size limit update were added. Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/shared/src/types/billing.ts (1)
1032-1069: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd per-field JSDoc to the new discount interfaces.
BillingAppliedDiscountandBillingDiscountRedemptiononly carry an interface-level@experimentalcomment. Every other interface in this file, includingBillingSubscriptionItemResourceandBillingDiscounts, documents each property individually. Add a short doc comment to each field (amount,discountId,effect,percentOff,amountOff,promoCode,cyclesRemaining,source,status,redeemedAt,redeemedBy, etc.) so consumers of this new public, experimental API understand the field semantics without cross-referencing the JSON layer.As per coding guidelines, "All public APIs must be documented with JSDoc" and "TypeScript is required for all packages... Maintain comprehensive JSDoc comments for public APIs."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/shared/src/types/billing.ts` around lines 1032 - 1069, Add individual JSDoc comments for every property in the public interfaces BillingAppliedDiscount and BillingDiscountRedemption, including identifiers, monetary fields, discount effects, cycle counters, source/status values, redemption timestamps, and redeemer information. Keep the existing interface-level experimental documentation and ensure each comment clearly describes the field’s semantics without relying on JSON-layer definitions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/localizations/src/en-US.ts`:
- Around line 125-126: Update the discount localization usage associated with
SubscriptionDiscountRow so a single cycle uses the singular billing.month or
billing.year label, while multiple cycles retain billing.months or
billing.years. Ensure both discountCyclesRemaining and discountDuration render
grammatically correct singular and plural wording.
In `@packages/ui/src/components/Subscriptions/SubscriptionsList.tsx`:
- Around line 258-302: Update the period-label logic near discountTitle so
singular keys are selected when each relevant cycle count equals 1, reusing the
existing billing.month/year keys and plural keys otherwise. Replace the shared
period value in discountDuration with a label based on totalCycles and in
discountCyclesRemaining with a label based on appliedDiscount.cyclesRemaining,
using the existing getPeriodLabel helper if available.
---
Nitpick comments:
In `@packages/shared/src/types/billing.ts`:
- Around line 1032-1069: Add individual JSDoc comments for every property in the
public interfaces BillingAppliedDiscount and BillingDiscountRedemption,
including identifiers, monetary fields, discount effects, cycle counters,
source/status values, redemption timestamps, and redeemer information. Keep the
existing interface-level experimental documentation and ensure each comment
clearly describes the field’s semantics without relying on JSON-layer
definitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 6b94bfa3-1098-4c76-ae70-37dedd04e586
📒 Files selected for processing (57)
.changeset/green-dolphins-discount.mdpackages/clerk-js/src/core/resources/BillingSubscription.tspackages/clerk-js/src/utils/__tests__/billing.test.tspackages/clerk-js/src/utils/billing.tspackages/localizations/src/ar-SA.tspackages/localizations/src/be-BY.tspackages/localizations/src/bg-BG.tspackages/localizations/src/bn-IN.tspackages/localizations/src/ca-ES.tspackages/localizations/src/cs-CZ.tspackages/localizations/src/da-DK.tspackages/localizations/src/de-DE.tspackages/localizations/src/el-GR.tspackages/localizations/src/en-GB.tspackages/localizations/src/en-US.tspackages/localizations/src/es-CR.tspackages/localizations/src/es-ES.tspackages/localizations/src/es-MX.tspackages/localizations/src/es-UY.tspackages/localizations/src/fa-IR.tspackages/localizations/src/fi-FI.tspackages/localizations/src/fr-FR.tspackages/localizations/src/he-IL.tspackages/localizations/src/hi-IN.tspackages/localizations/src/hr-HR.tspackages/localizations/src/hu-HU.tspackages/localizations/src/id-ID.tspackages/localizations/src/is-IS.tspackages/localizations/src/it-IT.tspackages/localizations/src/ja-JP.tspackages/localizations/src/kk-KZ.tspackages/localizations/src/ko-KR.tspackages/localizations/src/mn-MN.tspackages/localizations/src/ms-MY.tspackages/localizations/src/nb-NO.tspackages/localizations/src/nl-BE.tspackages/localizations/src/nl-NL.tspackages/localizations/src/pl-PL.tspackages/localizations/src/pt-BR.tspackages/localizations/src/pt-PT.tspackages/localizations/src/ro-RO.tspackages/localizations/src/ru-RU.tspackages/localizations/src/sk-SK.tspackages/localizations/src/sr-RS.tspackages/localizations/src/sv-SE.tspackages/localizations/src/ta-IN.tspackages/localizations/src/te-IN.tspackages/localizations/src/th-TH.tspackages/localizations/src/tr-TR.tspackages/localizations/src/uk-UA.tspackages/localizations/src/vi-VN.tspackages/localizations/src/zh-CN.tspackages/localizations/src/zh-TW.tspackages/shared/src/types/billing.tspackages/shared/src/types/json.tspackages/shared/src/types/localization.tspackages/ui/src/components/Subscriptions/SubscriptionsList.tsx
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)clerk/clerk-ios(auto-detected)clerk/clerk-android(auto-detected)clerk/cli(auto-detected)
53e7936 to
6af04e8
Compare
6af04e8 to
73f5daf
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/ui/src/utils/billing.ts (1)
14-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd explicit
stringreturn types.
getDiscountDescriptionandgetBillingPeriodLabelare exported TypeScript functions. Declare their return type asstring.Proposed fix
export function getDiscountDescription( discount: Discount, cycles: number | null, planPeriod: BillingSubscriptionPlanPeriod, { $, t }: Localizations, -) { +): string { @@ export function getBillingPeriodLabel( planPeriod: BillingSubscriptionPlanPeriod, cycles: number, t: Localizations['t'], -) { +): string {Based on learnings and coding guidelines: exported TypeScript functions require explicit return types.
Also applies to: 35-39
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ui/src/utils/billing.ts` around lines 14 - 19, Update the exported functions getDiscountDescription and getBillingPeriodLabel to explicitly declare string return types in their signatures, without changing their existing behavior or implementation.Sources: Coding guidelines, Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/ui/src/utils/billing.ts`:
- Around line 14-19: Update the exported functions getDiscountDescription and
getBillingPeriodLabel to explicitly declare string return types in their
signatures, without changing their existing behavior or implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 098eb993-20bb-45ac-9216-e11d156c5681
📒 Files selected for processing (5)
.changeset/render-discounts-payment-statement.mdpackages/backend/src/util/billing.tspackages/ui/src/components/PaymentAttempts/PaymentAttemptPage.tsxpackages/ui/src/components/Statements/StatementPage.tsxpackages/ui/src/utils/billing.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)clerk/clerk-ios(auto-detected)clerk/clerk-android(auto-detected)clerk/cli(auto-detected)
73f5daf to
a574667
Compare
…counts on subscription items
a574667 to
34d2072
Compare
Description
This PR adds support for rendering discounts on subscription items. It also adds support for promo codes at checkout.
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change