-
Notifications
You must be signed in to change notification settings - Fork 381
feat(backend): Add subscriptionItem.freeTrialEnding
event
#6684
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
Conversation
🦋 Changeset detectedLatest commit: 4acaf16 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.
|
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
@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: |
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 (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.
📒 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
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/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.
| 'subscriptionItem.past_due' | ||
| 'subscriptionItem.freeTrialEnding', | ||
CommerceSubscriptionItemWebhookEventJSON |
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
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', |
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.
Do we have a separate task ticketed for addressing the case inconsistencies?
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.
past_due
is correct as-is. We need to double check for freeTrialEnding
Description
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit