Skip to content

Conversation

paddycarver
Copy link
Contributor

@paddycarver paddycarver commented Sep 22, 2025

Description

We're introducing changes in future API versions that will either not send plan/plan_id at all on some subscription items, or may send null instead. Which hasn't been determined yet. Updating the client and webhooks to accept either, though.

C1s must take an explicit action before any subscription item will return a null or omitted plan/plan_id, so we'll have the opportunity to warn them.

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

    • Subscription items now allow missing plan details — plan and plan_id can be null or omitted.
    • Webhook payloads for subscription items now permit plan and plan_id to be null or omitted, improving integration flexibility and robustness.
    • Improves compatibility across integrations by tolerating absent plan information in API responses and webhooks.
  • Chores

    • Added a minor changeset documenting this update.

Copy link

changeset-bot bot commented Sep 22, 2025

🦋 Changeset detected

Latest commit: 8e3ac0c

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

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Minor
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing 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 Sep 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 22, 2025 6:51pm

Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

Walkthrough

Public types for BillingSubscriptionItem.plan and planId were changed to allow null. Corresponding JSON/webhook typings (plan and plan_id) were made optional and nullable, and the fromJSON path now conditionally constructs BillingPlan only when plan data exists.

Changes

Cohort / File(s) Summary of changes
Subscription item resource
packages/backend/src/api/resources/CommerceSubscriptionItem.ts
plan type changed from BillingPlanBillingPlan | null; planId changed from stringstring | null. fromJSON now conditionally constructs plan (use BillingPlan.fromJSON only if data.plan is present) and sets planId via data.plan_id ?? null.
Webhook & JSON typings
packages/backend/src/api/resources/JSON.ts
BillingSubscriptionItemJSON.plan changed to plan?: BillingPlanJSON | null; plan_id changed to plan_id?: string | null. BillingSubscriptionItemWebhookEventJSON similarly makes plan and plan_id optional and nullable.
Changeset
.changeset/silly-rooms-sleep.md
Added changeset noting subscription item plan and planId can be null/undefined; marked as a minor release note.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Source as Webhook / API payload
  participant Parser as JSON.fromJSON
  participant Resource as BillingSubscriptionItem

  Note over Source,Parser: incoming payload may include `plan` / `plan_id`
  Source->>Parser: payload
  alt plan present and non-null
    Parser->>Parser: plan = BillingPlan.fromJSON(data.plan)
    Parser->>Parser: planId = data.plan_id
  else plan absent or null
    Parser->>Parser: plan = null
    Parser->>Parser: planId = null
  end
  Parser->>Resource: new BillingSubscriptionItem(..., plan, planId, ...)
  Resource-->>Source: constructed instance
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble fields both small and grand,
If plans appear, I'll give a hand.
If plans are gone, I softly hum —
null's okay, so hop-hip-hooray! 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly states the primary change—making SubscriptionItem's plan and planId nullable in the backend—and aligns with the file changes shown in CommerceSubscriptionItem.ts and JSON.ts and the PR objectives. It is specific, clear, and free of extraneous details, so a teammate scanning history will understand the main intent. The phrasing and length are appropriate for a single-line PR title.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch paddy/bill-1248/make-plan-and-plan-id-nullable

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/backend/src/api/resources/JSON.ts (1)

885-887: Align resource JSON with nullable/omittable plan/plan_id.

CommerceSubscriptionItemJSON still requires plan and plan_id. If the API can return them as null or omit them, this type will be wrong and downstream code (e.g., fromJSON) can crash.

Apply this diff:

   amount: CommerceMoneyAmountJSON | null;
-  plan: CommercePlanJSON;
-  plan_id: string;
+  plan?: CommercePlanJSON | null;
+  plan_id?: string | null;
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1)

115-116: Guard CommercePlan.fromJSON to avoid runtime crash when plan is null/omitted.

With the new contract, data.plan can be null/undefined. The current call will throw.

Apply this diff:

-      CommercePlan.fromJSON(data.plan),
+      data.plan ? CommercePlan.fromJSON(data.plan) : data.plan,
🧹 Nitpick comments (2)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (2)

93-99: Use a nullish check instead of truthiness for amount.

Be explicit for null | undefined and avoid surprising behavior if an empty object ever appears.

-      if (!amount) {
+      if (amount == null) {
         return amount;
       }

47-54: Clarify JSDoc that plan/planId may be null or omitted.

Docs should reflect the breaking change for consumers.

   /**
-   * The plan associated with this subscription item.
+   * The plan associated with this subscription item.
+   * May be null or omitted if the instance has opted into planless items.
    */
   readonly plan: CommercePlan | null | undefined,
   /**
-   * The plan ID.
+   * The plan ID. May be null or omitted.
    */
   readonly planId: string | null | undefined,
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 034e6a3 and b136591.

📒 Files selected for processing (2)
  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1 hunks)
  • packages/backend/src/api/resources/JSON.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{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/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
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/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
🧬 Code graph analysis (1)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1)
packages/backend/src/api/resources/CommercePlan.ts (1)
  • CommercePlan (11-97)
⏰ 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). (3)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1)

92-126: Verify downstream usages don’t assume non‑null plan / planId

I couldn't run the previous scan here (rg errors). Run the script below in your environment and fix any direct property accesses or non-null assertions on plan/planId (use optional chaining or explicit null checks).

#!/bin/bash
set -euo pipefail
tmpfile=$(mktemp)
rg -n -l '\bCommerceSubscriptionItem\b' -g '**/*.ts' -g '**/*.tsx' -g '**/*.js' -g '**/*.jsx' > "$tmpfile" || true

if [ ! -s "$tmpfile" ]; then
  echo "No files found referencing CommerceSubscriptionItem"
  rm -f "$tmpfile"
  exit 0
fi

while IFS= read -r f; do
  echo "== $f =="
  rg -n -C1 '\bplan\.(id|name|slug|is_|has_|fee|annual|public|features)\b' "$f" || true
  rg -n -C1 '\bplan!\.' "$f" || true
  rg -n -C1 '\b(planId|plan_id)\.' "$f" || true
done < "$tmpfile"

rm -f "$tmpfile"

We're introducing changes in future API versions that will either not
send plan/plan_id at all on some subscription items, or may send null
instead. Which hasn't been determined yet. Updating the client and
webhooks to accept either, though.

C1s must take an explicit action before any subscription item will
return a null or omitted plan/plan_id, so we'll have the opportunity to
warn them.
@paddycarver paddycarver force-pushed the paddy/bill-1248/make-plan-and-plan-id-nullable branch from a9b4347 to db2486f Compare September 22, 2025 18:36
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: 0

🧹 Nitpick comments (2)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (2)

49-53: Public API nullability: clarify docs for consumers

Plan/planId are now nullable. Please reflect this in the JSDoc so integrators know when to expect nulls (opt‑in behavior, webhooks vs resources) and suggested guards.

Apply this doc tweak:

   /**
-   * The plan associated with this subscription item.
+   * The plan associated with this subscription item.
+   * May be null when the API omits the plan or explicitly returns null (after customer opt‑in).
    */
   readonly plan: CommercePlan | null,
   /**
-   * The plan ID.
+   * The plan ID.
+   * May be null; prefer `plan?.id` when `plan` is present.
    */
   readonly planId: string | null,

108-115: Normalize parsing and derive planId when plan is present

Slightly simplify the null checks and populate planId from plan.id if plan_id is omitted. This makes the model more resilient without changing external types.

-    let plan = null;
-    if (data.plan !== undefined && data.plan !== null) {
-      plan = CommercePlan.fromJSON(data.plan);
-    }
-    let planId = null;
-    if (data.plan_id !== undefined) {
-      planId = data.plan_id;
-    }
+    const plan = data.plan != null ? CommercePlan.fromJSON(data.plan) : null;
+    const planId = data.plan_id ?? (data.plan != null ? data.plan.id : null);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c144c9 and a9b4347.

📒 Files selected for processing (2)
  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts (2 hunks)
  • packages/backend/src/api/resources/JSON.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{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/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
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/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
  • packages/backend/src/api/resources/JSON.ts
🧬 Code graph analysis (2)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1)
packages/backend/src/api/resources/CommercePlan.ts (1)
  • CommercePlan (11-97)
packages/backend/src/api/resources/JSON.ts (1)
packages/types/src/json.ts (1)
  • CommercePlanJSON (653-679)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (1)

124-125: Constructor arg order and values — LGTM

Passing the computed plan and planId matches the updated constructor signature.

packages/backend/src/api/resources/JSON.ts (2)

885-886: Correct modeling of omission: optional + null (not undefined) — nice

Switching to plan?: CommercePlanJSON | null and plan_id?: string | null properly represents “omitted or null” per the PR intent.

Run to spot unsafe assumptions in consumers (non‑null assertions or direct member access):

#!/bin/bash
# Find risky uses of plan/planId across TS/TSX files
rg -nP --type=ts --type=tsx -C2 '\.planId\s*!|\bplanId!\b'
rg -nP --type=ts --type=tsx -C2 '\.plan\s*!|\bplan!\b'
# Direct property access on plan without optional chaining (heuristic)
rg -nP --type=ts --type=tsx -C2 '\.plan\.(?!\?)'

911-929: Webhook JSON: optional + nullable plan/plan_id — LGTM

Webhook shapes now match the “omitted or null” contract and align with the resource type.

Copy link

pkg-pr-new bot commented Sep 22, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 8e3ac0c

@panteliselef panteliselef changed the title feat: Make SubscriptionItem's plan and planId optional and nullable chore(backend): Make SubscriptionItem's plan and planId nullable Sep 22, 2025
paddycarver and others added 3 commits September 22, 2025 11:48
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: 1

🧹 Nitpick comments (1)
packages/backend/src/api/resources/JSON.ts (1)

909-927: Webhook: good nullability; consider extracting a reusable interface and add docs.

Inline shape is large and differs from BillingPlanJSON. Extracting a dedicated webhook plan interface improves reuse and discoverability; add brief docs on omission/null.

@@
 export interface BillingSubscriptionItemWebhookEventJSON extends ClerkResourceJSON {
@@
-  amount: BillingMoneyAmountJSON;
-  plan?: {
-    id: string;
-    instance_id: string;
-    product_id: string;
-    name: string;
-    slug: string;
-    description?: string;
-    is_default: boolean;
-    is_recurring: boolean;
-    amount: number;
-    period: 'month' | 'annual';
-    interval: number;
-    has_base_fee: boolean;
-    currency: string;
-    annual_monthly_amount: number;
-    publicly_visible: boolean;
-  } | null;
-  plan_id?: string | null;
+  amount: BillingMoneyAmountJSON;
+  /**
+   * May be omitted or null when the instance is configured to allow planless items.
+   */
+  plan?: WebhookBillingPlanJSON | null;
+  /**
+   * May be omitted or null.
+   */
+  plan_id?: string | null;
// Add near other billing JSON types
export interface WebhookBillingPlanJSON {
  id: string;
  instance_id: string;
  product_id: string;
  name: string;
  slug: string;
  description?: string;
  is_default: boolean;
  is_recurring: boolean;
  amount: number;
  period: 'month' | 'annual';
  interval: number;
  has_base_fee: boolean;
  currency: string;
  annual_monthly_amount: number;
  publicly_visible: boolean;
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 070be0f and 8e3ac0c.

📒 Files selected for processing (3)
  • .changeset/silly-rooms-sleep.md (1 hunks)
  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts (2 hunks)
  • packages/backend/src/api/resources/JSON.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/silly-rooms-sleep.md
  • packages/backend/src/api/resources/CommerceSubscriptionItem.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{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/backend/src/api/resources/JSON.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/api/resources/JSON.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/api/resources/JSON.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
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/backend/src/api/resources/JSON.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/api/resources/JSON.ts
🧬 Code graph analysis (1)
packages/backend/src/api/resources/JSON.ts (1)
packages/types/src/json.ts (1)
  • BillingPlanJSON (643-669)
⏰ 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). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment on lines +883 to 885
plan?: BillingPlanJSON | null;
plan_id?: string | null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Correct optional+nullable modeling for “omitted or null”; add brief field docs.

Types now reflect the API contract. Please document the semantics so SDK users know these may be absent or explicitly null.

   amount: BillingMoneyAmountJSON | null;
-  plan?: BillingPlanJSON | null;
-  plan_id?: string | null;
+  /**
+   * May be omitted or null when the instance is configured to allow planless items.
+   */
+  plan?: BillingPlanJSON | null;
+  /**
+   * May be omitted or null. Can be null even when `plan` is omitted.
+   */
+  plan_id?: string | null;

To catch lingering unsafe accesses, run:


🏁 Script executed:

#!/bin/bash
# Find places that still assume `plan` is always present.
rg -nP --type=ts -C2 '\b(plan|plan_id)\b(?!\s*\?:)' packages | sed -n '1,120p'
rg -nP --type=ts -C2 '\bplan\.(id|name|slug)\b' packages | sed -n '1,120p'

Length of output: 12199


Guard direct accesses to plan / plan_id (now optional|null)

JSDoc additions are fine; there are many direct property accesses that will throw when plan is omitted/null — fix these call sites:

  • packages/shared/src/react/commerce.tsx:258 — checkout.plan.name
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx:145,153 — subscription.plan.id (find/filter)
  • packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx:182 — subscription.plan.name
  • packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx:263,280,283,293,301,421,433,510,526 — multiple selectedSubscription/subscription.plan.name/id/avatarUrl usages
  • packages/clerk-js/src/ui/components/Statements/StatementPage.tsx:108,119 — item.subscriptionItem.plan.name
  • packages/clerk-js/src/ui/components/SubscriptionDetails/tests/SubscriptionDetails.test.tsx:925 — test expects subscription.plan.id (update mocks)

Replace direct member access with optional chaining or explicit null checks (e.g., subscription.plan?.name or guard early), update affected tests/mocks, then re-run the grep to confirm no remaining unsafe accesses.

🤖 Prompt for AI Agents
packages/backend/src/api/resources/JSON.ts around lines 883-885: the properties
plan and plan_id are now optional|null, so any direct member access will throw
when absent; update all listed call sites to guard against null by using
optional chaining or explicit null checks (e.g., subscription.plan?.name or if
(!subscription.plan) handle early), update tests/mocks that expect plan.id
(e.g., SubscriptionDetails.test.tsx) to include nullable cases or adjust
assertions, and re-run a grep across the repo for "plan." and "plan_id" to
ensure no remaining unsafe direct accesses remain.

@paddycarver paddycarver merged commit b8fbadd into main Sep 23, 2025
40 checks passed
@paddycarver paddycarver deleted the paddy/bill-1248/make-plan-and-plan-id-nullable branch September 23, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants