-
Notifications
You must be signed in to change notification settings - Fork 361
chore(clerk-js,types): Convert date properties from number to Date in CommerceSubscriptionResource #6233
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(clerk-js,types): Convert date properties from number to Date in CommerceSubscriptionResource #6233
Conversation
… CommerceSubscriptionResource
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: eb79d11 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis change updates the handling of date-related properties in the commerce subscription resources. Numeric timestamp fields ( Suggested labels
Suggested reviewers
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
.changeset/funny-ducks-boil.md
(1 hunks)packages/clerk-js/src/core/resources/CommerceSubscription.ts
(3 hunks)packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
(2 hunks)packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
(1 hunks)packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
(2 hunks)packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
(1 hunks)packages/clerk-js/src/ui/contexts/components/Plans.tsx
(8 hunks)packages/types/src/commerce.ts
(1 hunks)packages/types/src/json.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
`**/*.{js,jsx,ts,tsx}`: All code must pass ESLint checks with the project's conf...
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Use Prettier for consistent code formatting
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
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Validate all inputs and sanitize outputs
Implement proper logging with different levels
📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)
List of files the instruction was applied to:
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/types/src/commerce.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`packages/**/*.ts`: TypeScript is required for all packages
packages/**/*.ts
: TypeScript is required for all packages
📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)
List of files the instruction was applied to:
packages/types/src/json.ts
packages/types/src/commerce.ts
packages/clerk-js/src/core/resources/CommerceSubscription.ts
`packages/**/*.{ts,tsx,d.ts}`: Packages should export TypeScript types alongside runtime code
packages/**/*.{ts,tsx,d.ts}
: Packages should export TypeScript types alongside runtime code
📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)
List of files the instruction was applied to:
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/types/src/commerce.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`**/*.{ts,tsx}`: Use proper TypeScript error types
**/*.{ts,tsx}
: Use proper TypeScript error types
📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)
List of files the instruction was applied to:
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/types/src/commerce.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`**/*.{ts,tsx}`: Always define explicit return types for functions, especially p...
**/*.{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
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
Document public functions and APIs with JSDoc-style comments including @param, @returns, @throws, and @example
Define custom error classes for domain-specific errors
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining and nullish coalescing for safe property access
Let TypeScript infer types when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use readonly arrays and objects for immutability
Use immutable update patterns (spread, etc.) for objects and arrays
Use lazy loading for large types
Preferunknown
overany
for performance
Use type-only imports:import type { ... }
Use branded types for domain safety
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints in TypeScript generics
No unused type parameters in generics
Proper use of utility types instead of manual type construction
Type-only imports where possible for performance
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)
List of files the instruction was applied to:
packages/types/src/json.ts
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/types/src/commerce.ts
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`**/*.{tsx,jsx}`: Use error boundaries in React components Minimize re-renders in React components
**/*.{tsx,jsx}
: Use error boundaries in React components
Minimize re-renders in React components
📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)
List of files the instruction was applied to:
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`packages/{clerk-js,elements,themes}/**/*`: Visual regression testing should be performed for UI components.
packages/{clerk-js,elements,themes}/**/*
: Visual regression testing should be performed for UI components.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
List of files the instruction was applied to:
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/core/resources/CommerceSubscription.ts
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`**/*.{jsx,tsx}`: Always use functional components with hooks instead of class c...
**/*.{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 state naming
Use proper handler naming
Implement proper component structure
Use proper hook structure
📄 Source: CodeRabbit Inference Engine (.cursor/rules/react.mdc)
List of files the instruction was applied to:
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
`**/*.tsx`: Use proper type definitions for props and state Leverage TypeScript'...
**/*.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
📄 Source: CodeRabbit Inference Engine (.cursor/rules/react.mdc)
List of files the instruction was applied to:
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
packages/clerk-js/src/ui/contexts/components/Plans.tsx
🧠 Learnings (9)
📓 Common learnings
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (6)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type guards for conditional rendering
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/index.tsx:64-83
Timestamp: 2025-06-18T16:33:36.764Z
Learning: In SessionTasks component at packages/clerk-js/src/ui/components/SessionTasks/index.tsx, the useEffect that checks for pending tasks should only run on mount (not react to currentTask/status changes) to handle browser back navigation edge cases without interfering with normal task completion flow managed by nextTask().
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use proper state updates with callbacks
.changeset/funny-ducks-boil.md (3)
Learnt from: dstaley
PR: clerk/javascript#6100
File: packages/clerk-js/src/ui/components/OAuthConsent/OAuthConsent.tsx:121-124
Timestamp: 2025-06-16T17:08:58.414Z
Learning: The @clerk/clerk-js package only supports browsers released in the last two years (since May 8, 2023), so modern CSS features like color-mix() are fully supported across all target browsers without requiring fallbacks.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/@clerk/*/package.json : Framework packages must depend on '@clerk/clerk-js' for core functionality.
packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx (3)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
packages/types/src/commerce.ts (1)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/api/**/*.ts : Document API endpoints with TypeScript interfaces
packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (3)
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use proper button types
packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx (3)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
packages/clerk-js/src/ui/contexts/components/Plans.tsx (1)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
🧬 Code Graph Analysis (1)
packages/clerk-js/src/core/resources/CommerceSubscription.ts (1)
packages/types/src/commerce.ts (1)
CommerceMoney
(181-186)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (18)
packages/types/src/json.ts (1)
704-704
: LGTM! Consistent addition of creation timestamp.The addition of
created_at
property follows the existing pattern in the JSON interface and aligns with the broader migration to enhance date handling in commerce subscription resources.packages/clerk-js/src/ui/components/PricingTable/PricingTable.tsx (1)
27-27
: LGTM! Consistent migration to Date-typed property.The change from
canceledAt
tocanceledAtDate
aligns with the broader migration to use Date-typed properties instead of numeric timestamps for subscription dates.packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (1)
128-128
: LGTM! Consistent migration to Date-typed property.The change from
canceledAt
tocanceledAtDate
maintains the same conditional logic while using the new Date-typed property, consistent with the migration pattern across the codebase.packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (2)
146-146
: LGTM! Consistent migration to Date-typed property.The change from
canceledAt
tocanceledAtDate
maintains the same conditional logic while using the new Date-typed property.
256-256
: LGTM! Consistent migration to Date-typed property.The change from
periodStart
toperiodStartDate
updates the localization parameter to use the new Date-typed property while maintaining the same functionality.packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx (1)
213-213
: LGTM! Consistent migration to Date-typed property.The change from
canceledAt
tocanceledAtDate
maintains the same conditional logic while using the new Date-typed property.packages/clerk-js/src/core/resources/CommerceSubscription.ts (2)
11-11
: LGTM: Clean import of date utilityThe import of
unixEpochToDate
utility function is appropriately placed and will be used for timestamp conversions.
22-26
: LGTM: Well-typed date propertiesThe new date properties are properly typed with appropriate nullability:
createdAt
asDate
(non-null, subscription always has creation time)periodStartDate
asDate
(non-null, subscription always has start time)periodEndDate
andcanceledAtDate
asDate | null
(nullable for ongoing/active subscriptions)This provides better type safety compared to numeric timestamps.
.changeset/funny-ducks-boil.md (1)
1-16
: LGTM: Well-documented changesetThe changeset properly documents:
- Minor version bumps for affected packages (appropriate for deprecation + new features)
- Clear description of the change purpose
- Specific listing of deprecated and new fields
This follows best practices for changeset documentation.
packages/types/src/commerce.ts (2)
158-161
: LGTM: Properly typed date propertiesThe new date properties are correctly typed and align with the implementation in the CommerceSubscription class:
createdAt: Date
- non-nullable for subscription creation timeperiodStartDate: Date
- non-nullable for subscription startperiodEndDate: Date | null
- nullable for ongoing subscriptionscanceledAtDate: Date | null
- nullable for active subscriptions
162-173
: LGTM: Proper deprecation documentationThe JSDoc deprecation comments follow best practices:
- Use standard
@deprecated
tag- Provide clear migration guidance pointing to new field names
- Maintain backwards compatibility while encouraging migration
This allows for a smooth transition period for consumers.
packages/clerk-js/src/ui/contexts/components/Plans.tsx (7)
101-103
: LGTM: Consistent migration to Date propertiesThe subscription checking logic correctly migrates from numeric properties to Date properties:
!subscription.canceledAtDate
(was!subscription.canceledAt
)subscription.canceledAtDate
(wassubscription.canceledAt
)The null-checking logic remains sound with the Date objects.
114-115
: LGTM: Proper Date-to-timestamp conversionUsing
canceledSubscription?.periodEndDate?.getTime()
correctly converts the Date object back to a Unix timestamp for JSON serialization. The optional chaining handles the nullable Date property appropriately.
194-194
: LGTM: Subscription status checking updatedThe logic for determining if the default plan should be implicitly active correctly uses the new
canceledAtDate
property to check for canceled subscriptions.
243-243
: LGTM: Subscription management logic updatedThe
canManageSubscription
function correctly usescanceledAtDate
to determine if a subscription can be managed (non-canceled subscriptions).
286-296
: LGTM: Button props logic updated consistentlyThe localization logic for button states correctly uses
canceledAtDate
for:
- Checking plan period switches on canceled subscriptions
- Determining resubscribe vs manage subscription states
The logic maintains the same behavior with improved type safety.
336-346
: LGTM: Caption generation using Date objectsThe subscription caption logic properly uses the new Date properties:
periodStartDate
for upcoming subscriptionsperiodEndDate
for canceled/active subscription end datescanceledAtDate
for canceled subscription detectionThe TypeScript ignore comment on line 339 is acceptable since the business logic ensures
periodEndDate
exists whencanceledAtDate
is present.
363-363
: LGTM: Plan selection logic updatedThe plan selection logic correctly uses
canceledAtDate
to determine whether to show plan details (for active subscriptions) or checkout flow (for new/canceled subscriptions).
// @ts-expect-error this will always be defined in this case. | ||
date: subscription.periodEndDate, |
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.
💡 Verification agent
🧩 Analysis chain
Verify the TypeScript suppression is justified.
The migration from periodEnd
to periodEndDate
is consistent with the pattern. However, the @ts-expect-error
comment suggests a type issue. Please ensure that the property is indeed always defined in this context or consider updating the type definitions.
🏁 Script executed:
#!/bin/bash
# Description: Check the type definition of periodEndDate in CommerceSubscriptionResource
# Expected: Verify if periodEndDate is optional or required in the type definition
ast-grep --pattern 'interface CommerceSubscriptionResource {
$$$
periodEndDate$_$$$
$$$
}'
# Also search for any type definitions related to subscription period dates
rg -A 3 -B 3 "periodEndDate.*[?:]"
Length of output: 2751
Fix the TypeScript suppression for periodEndDate
The CommerceSubscriptionResource
model declares periodEndDate
as Date | null
, so subscription.periodEndDate
may legitimately be null
. Suppressing the error hides a potential runtime issue. Please remove the @ts-expect-error
and either:
- Add an explicit null check before using it, e.g.
if (!subscription.periodEndDate) { // handle missing date… } else { date: subscription.periodEndDate, }
- Or use a non-null assertion if you’re certain it can’t be null in this context:
- // @ts-expect-error this will always be defined in this case. - date: subscription.periodEndDate, + date: subscription.periodEndDate!,
Locations to update:
- packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx (lines 321–322)
- Note: the type in packages/types/src/commerce.ts is
periodEndDate: Date | null;
🤖 Prompt for AI Agents
In packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx at lines 321-322,
remove the @ts-expect-error comment on subscription.periodEndDate and address
its nullable type properly. Add an explicit null check before using
subscription.periodEndDate to handle the case when it is null, or if you are
certain it cannot be null here, replace the suppression with a non-null
assertion operator to ensure type safety without hiding potential runtime
issues.
this.createdAt = unixEpochToDate(data.created_at); | ||
this.periodStartDate = unixEpochToDate(data.period_start); | ||
this.periodEndDate = data.period_end ? unixEpochToDate(data.period_end) : null; | ||
this.canceledAtDate = data.canceled_at ? unixEpochToDate(data.canceled_at) : 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.
💡 Verification agent
🧩 Analysis chain
Verify the unixEpochToDate utility function
The conversion logic looks correct, but ensure the unixEpochToDate
utility function properly handles edge cases.
🏁 Script executed:
#!/bin/bash
# Description: Verify the unixEpochToDate utility function exists and examine its implementation
# Search for the utility function definition
ast-grep --pattern 'function unixEpochToDate($_) {
$$$
}'
# Also search for arrow function or const declaration
rg -A 10 "unixEpochToDate.*=" src/utils/date
Length of output: 163
I couldn’t locate unixEpochToDate
in the initial paths—let’s do a global search to find its definition and usages.
🏁 Script executed:
#!/bin/bash
# Search for definition and all usages of unixEpochToDate across the repo
rg -n "unixEpochToDate"
Length of output: 10950
Let’s inspect the implementation and its tests:
🏁 Script executed:
#!/bin/bash
# Show the unixEpochToDate implementation
sed -n '1,200p' packages/clerk-js/src/utils/date.ts
# Show tests covering edge cases
sed -n '1,200p' packages/clerk-js/src/utils/__tests__/date.spec.ts
Length of output: 1264
Improve zero-timestamp handling in unixEpochToDate
The current implementation
export function unixEpochToDate(epochInSeconds?: number): Date {
const date = new Date(epochInSeconds || new Date());
return isValidDate(date) ? date : new Date();
}
uses a falsy check (epochInSeconds || …
), so passing 0
(the Unix epoch) falls back to Date.now()
. To correctly support 0
, please:
- In
packages/clerk-js/src/utils/date.ts
, update the guard:export function unixEpochToDate(epochInSeconds?: number): Date {
- const date = new Date(epochInSeconds || new Date());
- const timestamp = epochInSeconds != null ? epochInSeconds : Date.now();
- const date = new Date(timestamp);
return isValidDate(date) ? date : new Date();
}
- In `packages/clerk-js/src/utils/__tests__/date.spec.ts`, add a zero-timestamp test:
```ts
it('correctly handles zero', () => {
const date = unixEpochToDate(0);
expect(date.getTime()).toBe(0);
});
This change ensures unixEpochToDate(0)
returns the Unix epoch rather than “now.”
🤖 Prompt for AI Agents
In packages/clerk-js/src/utils/date.ts, update the unixEpochToDate function to
explicitly check for undefined or null instead of using a falsy check, so that
passing 0 returns the correct Unix epoch date. Then, in
packages/clerk-js/src/utils/__tests__/date.spec.ts, add a test case that calls
unixEpochToDate(0) and asserts that the returned date's time is 0 to verify
correct handling of the zero timestamp.
@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: |
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Bug Fixes
Documentation