-
Notifications
You must be signed in to change notification settings - Fork 392
chore(backend): Make SubscriptionItem's plan
and planId
nullable
#6839
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
chore(backend): Make SubscriptionItem's plan
and planId
nullable
#6839
Conversation
🦋 Changeset detectedLatest commit: 8e3ac0c The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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.
|
WalkthroughPublic 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
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: 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/omittableplan
/plan_id
.
CommerceSubscriptionItemJSON
still requiresplan
andplan_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
: GuardCommercePlan.fromJSON
to avoid runtime crash whenplan
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 thatplan
/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.
📒 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
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/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‑nullplan
/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.
a9b4347
to
db2486f
Compare
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: 0
🧹 Nitpick comments (2)
packages/backend/src/api/resources/CommerceSubscriptionItem.ts (2)
49-53
: Public API nullability: clarify docs for consumersPlan/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 presentSlightly 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.
📒 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
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/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 — LGTMPassing the computed
plan
andplanId
matches the updated constructor signature.packages/backend/src/api/resources/JSON.ts (2)
885-886
: Correct modeling of omission: optional + null (not undefined) — niceSwitching to
plan?: CommercePlanJSON | null
andplan_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 — LGTMWebhook shapes now match the “omitted or null” contract and align with the resource type.
@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: |
plan
and planId
nullable
Co-authored-by: panteliselef <panteliselef@outlook.com>
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: 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.
📒 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
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/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
plan?: BillingPlanJSON | null; | ||
plan_id?: string | null; | ||
} |
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.
🧩 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.
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.Type of change
Summary by CodeRabbit
New Features
Chores