Skip to content

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Sep 2, 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
    • Added support for the subscriptionItem.freeTrialEnding webhook event, enabling notifications when a free trial is nearing its end.
  • Documentation
    • Documented availability of the subscriptionItem.freeTrialEnding event in commerce subscription item webhooks.
  • Chores
    • Updated backend dependency to the latest minor version.

Copy link

changeset-bot bot commented Sep 2, 2025

🦋 Changeset detected

Latest commit: 4acaf16

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

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Minor
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

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

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

Copy link

vercel bot commented Sep 2, 2025

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

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 2, 2025 1:49pm

Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds a new webhook event type 'subscriptionItem.freeTrialEnding' to CommerceSubscriptionItemWebhookEvent in the backend. Updates the changeset to note a minor bump of '@clerk/backend' and document inclusion of the new event. No other exported/public declarations changed.

Changes

Cohort / File(s) Summary
Release notes / changeset
\.changeset/short-ravens-sell.md
Documents minor version bump of '@clerk/backend' and inclusion of subscriptionItem.freeTrialEnding in CommerceSubscriptionItemWebhookEvent.
Backend Webhooks types
packages/backend/src/api/resources/Webhooks.ts
Extends CommerceSubscriptionItemWebhookEvent union to include 'subscriptionItem.freeTrialEnding'; adjusts trailing comma/ordering in the union. No other API surface changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Billing as Billing/Commerce System
  participant WH as Webhook Emitter
  participant App as App Webhook Handler

  Billing->>WH: Generate subscription item event
  alt Existing events
    WH-->>App: subscriptionItem.created/updated/.../past_due
    App->>App: Route to existing handlers
  else New event
    rect rgba(198,235,255,0.25)
    note right of WH: New in this change
    WH-->>App: subscriptionItem.freeTrialEnding
    end
    App->>App: Route to freeTrialEnding handler
    opt If unhandled
      App-->>WH: 2xx with no-op or 4xx per app policy
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A whisker-twitch, a gentle ping—
New notes in webhooks’ subtle ring.
“Free trial’s ending!” drums the breeze,
I hop and file my types with ease.
Minor bumps, yet tidy art—
Carrots logged, events that start.
Ship it! Thump-thump—rabbit heart.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch elef/add-trials-webhook

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

pkg-pr-new bot commented Sep 2, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 4acaf16

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
.changeset/short-ravens-sell.md (2)

5-5: Polish the release note phrasing.

Drop the inner quotes and add the article for clarity.

-Include `'subscriptionItem.freeTrialEnding'` event in `CommerceSubscriptionItemWebhookEvent`.
+Include the `subscriptionItem.freeTrialEnding` event in `CommerceSubscriptionItemWebhookEvent`.

5-5: Add one-line context for integrators.

Briefly state when the event fires and what payload to expect (e.g., includes subscription item id, trial end timestamp). This improves changelog usefulness.

Happy to draft a concise sentence if you share the trigger semantics.

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

87-89: Document the new event in JSDoc.

Public API types should mention all members and intended trigger. Add a short JSDoc above the type.

Apply near the type declaration:

+/**
+ * CommerceSubscriptionItem webhooks.
+ * Includes:
+ * - 'subscriptionItem.freeTrialEnding' — emitted when a subscription item's free trial is about to end.
+ */
 export type CommerceSubscriptionItemWebhookEvent = Webhook<

87-89: Optional: add a compile-time guard in tests/examples.

A minimal type-level test helps ensure the new literal is part of WebhookEventType.

I can add a tiny tsd/type-test asserting:

type _Expect = Extract<WebhookEventType, 'subscriptionItem.freeTrialEnding'>;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e9f538a and 4acaf16.

📒 Files selected for processing (2)
  • .changeset/short-ravens-sell.md (1 hunks)
  • packages/backend/src/api/resources/Webhooks.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/short-ravens-sell.md
**/*.{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/Webhooks.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/Webhooks.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/backend/src/api/resources/Webhooks.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/Webhooks.ts
**/*.{ts,tsx}

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

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/backend/src/api/resources/Webhooks.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/Webhooks.ts
🪛 LanguageTool
.changeset/short-ravens-sell.md

[grammar] ~5-~5: There might be a mistake here.
Context: ... CommerceSubscriptionItemWebhookEvent.

(QB_NEW_EN)

⏰ 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: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
.changeset/short-ravens-sell.md (1)

1-3: Changeset scope and bump look correct.

Minor bump for @clerk/backend is appropriate for adding a new event to a public union type.

packages/backend/src/api/resources/Webhooks.ts (1)

87-89: Event added to union — LGTM.

The new subscriptionItem.freeTrialEnding literal is correctly included and type-imports remain intact.

Comment on lines +87 to 89
| 'subscriptionItem.past_due'
| 'subscriptionItem.freeTrialEnding',
CommerceSubscriptionItemWebhookEventJSON
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

Confirm naming convention before release.

Existing multi-word suffix uses underscore (past_due), while this one is camelCase (freeTrialEnding). If conventions favor snake_case for statuses/special phases, consider free_trial_ending. Changing later would be breaking.

Run to check for existing precedents and external references:


🏁 Script executed:

#!/bin/bash
# Inspect existing event naming patterns
rg -nP --type=ts -C2 $'subscription(Item)?\\.(past_due|free[_-]?trial[_-]?ending|trial[_-]?ending|freeTrialEnding)'

# Find usages that may need updates (handlers, docs, examples)
rg -n --type=ts --type=md -C2 "subscriptionItem\\." 

Length of output: 10879


Use snake_case for multi-word webhook events

In packages/backend/src/api/resources/Webhooks.ts:88, rename subscriptionItem.freeTrialEnding to subscriptionItem.free_trial_ending to align with the existing subscriptionItem.past_due. Changing this later would be breaking.

🤖 Prompt for AI Agents
In packages/backend/src/api/resources/Webhooks.ts around lines 87 to 89, the
multi-word webhook event key uses camelCase; rename
subscriptionItem.freeTrialEnding to subscriptionItem.free_trial_ending to match
the snake_case style used by subscriptionItem.past_due and avoid a breaking
change; update the string literal (and any corresponding type/enum references in
this file) to the snake_case variant and run tests or search the repo for other
uses to ensure consistency.

@@ -84,7 +84,8 @@ export type CommerceSubscriptionItemWebhookEvent = Webhook<
| 'subscriptionItem.ended'
| 'subscriptionItem.abandoned'
| 'subscriptionItem.incomplete'
| 'subscriptionItem.past_due',
| 'subscriptionItem.past_due'
| 'subscriptionItem.freeTrialEnding',

Choose a reason for hiding this comment

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

Do we have a separate task ticketed for addressing the case inconsistencies?

Copy link
Member Author

Choose a reason for hiding this comment

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

past_due is correct as-is. We need to double check for freeTrialEnding

@panteliselef panteliselef merged commit 5e94f0a into main Sep 2, 2025
40 checks passed
@panteliselef panteliselef deleted the elef/add-trials-webhook branch September 2, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants