Skip to content

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

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Jul 1, 2025

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Introduced new date-based properties for subscriptions, including creation date and period start/end/cancellation dates, providing more precise date handling in the user interface.
  • Bug Fixes

    • Updated all subscription-related UI components to use the new date properties, ensuring accurate display and logic for subscription status and periods.
  • Documentation

    • Deprecated older numeric timestamp fields in favor of the new date-based properties, with clear guidance in tooltips and documentation.

@panteliselef panteliselef requested a review from aeliox July 1, 2025 14:51
Copy link

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 2:52pm

Copy link

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: eb79d11

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

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

📝 Walkthrough

Walkthrough

This change updates the handling of date-related properties in the commerce subscription resources. Numeric timestamp fields (periodStart, periodEnd, canceledAt) are deprecated and replaced with new Date-typed fields (periodStartDate, periodEndDate, canceledAtDate) in both type definitions and class implementations. A new createdAt date property is also introduced. All relevant UI components and logic are updated to use the new date properties instead of the deprecated numeric ones, with internal logic and type annotations adjusted accordingly.

Suggested labels

types, clerk-js

Suggested reviewers

  • aeliox

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2a6641 and eb79d11.

📒 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
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
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
Use const assertions for literal types: as const
Use satisfies 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
Prefer unknown over any for performance
Use type-only imports: import type { ... }
Use branded types for domain safety
No any types without justification
Proper error handling with typed errors
Consistent use of readonly 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 to canceledAtDate 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 to canceledAtDate 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 to canceledAtDate 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 to periodStartDate 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 to canceledAtDate 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 utility

The import of unixEpochToDate utility function is appropriately placed and will be used for timestamp conversions.


22-26: LGTM: Well-typed date properties

The new date properties are properly typed with appropriate nullability:

  • createdAt as Date (non-null, subscription always has creation time)
  • periodStartDate as Date (non-null, subscription always has start time)
  • periodEndDate and canceledAtDate as Date | 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 changeset

The 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 properties

The new date properties are correctly typed and align with the implementation in the CommerceSubscription class:

  • createdAt: Date - non-nullable for subscription creation time
  • periodStartDate: Date - non-nullable for subscription start
  • periodEndDate: Date | null - nullable for ongoing subscriptions
  • canceledAtDate: Date | null - nullable for active subscriptions

162-173: LGTM: Proper deprecation documentation

The 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 properties

The subscription checking logic correctly migrates from numeric properties to Date properties:

  • !subscription.canceledAtDate (was !subscription.canceledAt)
  • subscription.canceledAtDate (was subscription.canceledAt)

The null-checking logic remains sound with the Date objects.


114-115: LGTM: Proper Date-to-timestamp conversion

Using 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 updated

The 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 updated

The canManageSubscription function correctly uses canceledAtDate to determine if a subscription can be managed (non-canceled subscriptions).


286-296: LGTM: Button props logic updated consistently

The 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 objects

The subscription caption logic properly uses the new Date properties:

  • periodStartDate for upcoming subscriptions
  • periodEndDate for canceled/active subscription end dates
  • canceledAtDate for canceled subscription detection

The TypeScript ignore comment on line 339 is acceptable since the business logic ensures periodEndDate exists when canceledAtDate is present.


363-363: LGTM: Plan selection logic updated

The plan selection logic correctly uses canceledAtDate to determine whether to show plan details (for active subscriptions) or checkout flow (for new/canceled subscriptions).

Comment on lines +321 to +322
// @ts-expect-error this will always be defined in this case.
date: subscription.periodEndDate,
Copy link
Contributor

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.

Comment on lines +53 to +56
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;
Copy link
Contributor

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.

Copy link

pkg-pr-new bot commented Jul 1, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: eb79d11

@panteliselef panteliselef self-assigned this Jul 1, 2025
@panteliselef panteliselef merged commit 8387a39 into main Jul 2, 2025
64 of 65 checks passed
@panteliselef panteliselef deleted the elef/com-984-fix-clerk-js-subscription-dates branch July 2, 2025 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants