Skip to content

Update seats on stripe when sharing premium#488

Merged
elie222 merged 3 commits intomainfrom
share-premium-stripe
Jun 5, 2025
Merged

Update seats on stripe when sharing premium#488
elie222 merged 3 commits intomainfrom
share-premium-stripe

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Jun 5, 2025

Summary by CodeRabbit

  • New Features
    • Improved management of premium account subscription seats, now supporting both Stripe and Lemon Squeezy subscriptions.
  • Chores
    • Updated version to v1.3.20.
  • Bug Fixes
    • Standardized error handling across multiple actions by replacing error return objects with exception throwing for clearer failure signaling.

@vercel
Copy link

vercel bot commented Jun 5, 2025

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

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Jun 5, 2025 6:21pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

The update refactors premium account seat management by introducing a new helper function, updateAccountSeatsForPremium, which centralizes logic for updating subscription quantities based on Stripe or Lemon Squeezy IDs. The premium action now calculates total seats using user accounts and pending invites, then updates the subscription accordingly. Additionally, error handling across multiple action functions was standardized by replacing returned error objects with thrown SafeError exceptions. The version number was incremented.

Changes

File(s) Change Summary
apps/web/utils/actions/premium.ts Updated updateMultiAccountPremiumAction to include Stripe subscription logic and new seat calculation; removed Lemon Squeezy-specific call; now calls updateAccountSeatsForPremium. Replaced early returns with thrown SafeError exceptions for error handling.
apps/web/utils/premium/server.ts Refactored seat update logic into new exported function updateAccountSeatsForPremium; updateAccountSeats now delegates to this helper.
apps/web/utils/actions/admin.ts Changed error handling in adminDeleteAccountAction to throw SafeError instead of returning error objects.
apps/web/utils/actions/ai-rule.ts Replaced returned error objects with thrown SafeError exceptions in multiple AI rule-related actions.
apps/web/utils/actions/categorize.ts Changed duplicate category name error handling in upsertCategory to throw SafeError instead of returning error.
apps/web/utils/actions/generate-reply.ts Replaced returned error objects with thrown SafeError exceptions in generateNudgeReplyAction.
apps/web/utils/actions/group.ts Changed error handling in group-related actions to throw SafeError instead of returning error objects.
apps/web/utils/actions/mail.ts Standardized Gmail-related action error handling by throwing SafeError exceptions instead of returning error objects.
apps/web/utils/actions/permissions.ts Replaced returned error objects with thrown SafeError exceptions in permission check actions.
apps/web/utils/actions/rule.ts Changed error handling in rule-related actions to throw SafeError exceptions instead of returning error objects.
apps/web/utils/actions/stats.ts Replaced returned error object with thrown SafeError in loadEmailStatsAction when access token is missing.
version.txt Version updated from v1.3.18 to v1.3.20.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant updateMultiAccountPremiumAction
    participant DB
    participant updateAccountSeatsForPremium
    participant StripeOrLemonSqueezy

    User->>updateMultiAccountPremiumAction: Trigger premium seat update
    updateMultiAccountPremiumAction->>DB: Fetch premium record (with user accounts & pending invites)
    updateMultiAccountPremiumAction->>updateAccountSeatsForPremium: Call with premium record & total seats
    updateAccountSeatsForPremium->>StripeOrLemonSqueezy: Update subscription item quantity
Loading

Poem

The seats are counted, invites too,
Stripe and Lemon Squeezy—handled anew!
A helper now manages the premium flow,
Keeping our numbers in tidy tow.
With errors caught by SafeError’s might,
Our code hops forward, error-free and bright!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/utils/actions/ai-rule.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/utils/actions/group.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/web/utils/actions/admin.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

  • 7 others
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 docstrings to generate docstrings for this 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.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ BugBot reviewed your changes and found no bugs!


BugBot free trial expires on June 9, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31fefbb and 481c391.

📒 Files selected for processing (10)
  • apps/web/utils/actions/admin.ts (2 hunks)
  • apps/web/utils/actions/ai-rule.ts (4 hunks)
  • apps/web/utils/actions/categorize.ts (1 hunks)
  • apps/web/utils/actions/generate-reply.ts (2 hunks)
  • apps/web/utils/actions/group.ts (3 hunks)
  • apps/web/utils/actions/mail.ts (10 hunks)
  • apps/web/utils/actions/permissions.ts (4 hunks)
  • apps/web/utils/actions/premium.ts (7 hunks)
  • apps/web/utils/actions/rule.ts (8 hunks)
  • apps/web/utils/actions/stats.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/utils/actions/premium.ts
🧰 Additional context used
🧬 Code Graph Analysis (9)
apps/web/utils/actions/stats.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/categorize.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/generate-reply.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/permissions.ts (3)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/gmail/permissions.ts (1)
  • handleGmailPermissionsCheck (71-106)
apps/web/utils/account.ts (1)
  • getGmailAndAccessTokenForEmail (25-39)
apps/web/utils/actions/mail.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/rule.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/ai-rule.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/group.ts (1)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/actions/admin.ts (2)
apps/web/utils/error.ts (1)
  • SafeError (83-91)
apps/web/utils/user/delete.ts (1)
  • deleteUser (14-74)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Jit Security
🔇 Additional comments (27)
apps/web/utils/actions/stats.ts (1)

15-15: LGTM: Standardized error handling with SafeError.

The addition of SafeError import and the change from returning an error object to throwing a SafeError exception properly standardizes error handling across the codebase. This improves control flow by using exceptions for error signaling.

Also applies to: 31-31

apps/web/utils/actions/categorize.ts (1)

256-256: LGTM: Consistent error handling for duplicate category names.

The change from returning an error object to throwing a SafeError exception aligns with the broader error handling standardization across the codebase. The error message remains clear and appropriate.

apps/web/utils/actions/rule.ts (1)

156-156: LGTM: Comprehensive error handling standardization.

All error cases have been consistently updated from returning error objects to throwing SafeError exceptions. This improves control flow and aligns with proper exception-based error handling patterns. The error messages remain clear and appropriate for each scenario.

Also applies to: 256-256, 259-261, 279-279, 304-304, 331-331, 360-360, 389-389, 448-448

apps/web/utils/actions/generate-reply.ts (1)

9-9: LGTM: Proper error handling standardization.

The addition of SafeError import and the conversion of error returns to exception throwing is consistent with the broader error handling refactoring. Both error cases are handled appropriately with clear error messages.

Also applies to: 21-21, 25-25

apps/web/utils/actions/admin.ts (3)

9-9: LGTM: SafeError import added appropriately.

The import is correctly placed and aligns with the error handling standardization across the codebase.


44-44: LGTM: Consistent error handling with SafeError.

The change from returning an error object to throwing a SafeError exception improves consistency and follows the standardized error handling pattern.


49-51: LGTM: Proper error wrapping and logging.

The error handling correctly wraps the original error message in a SafeError while maintaining the logging for debugging purposes. This is appropriate for admin functionality.

apps/web/utils/actions/group.ts (3)

11-11: LGTM: SafeError import correctly added.

The import is properly placed and supports the error handling standardization.


22-22: LGTM: Consistent error throwing for missing rule.

The change from returning an error object to throwing SafeError improves error handling consistency and provides clear feedback.


48-52: LGTM: Proper validation and permission checking.

Both error conditions (missing group and permission validation) are handled consistently with clear, user-friendly error messages using SafeError.

apps/web/utils/actions/permissions.ts (3)

9-9: LGTM: SafeError import added for standardization.

The import supports the consistent error handling pattern being implemented across the codebase.


21-21: LGTM: Consistent error handling in checkPermissionsAction.

All error conditions are now handled uniformly by throwing SafeError exceptions instead of returning error objects, improving consistency and error propagation.

Also applies to: 27-27, 40-40


55-55: LGTM: Standardized error handling in adminCheckPermissionsAction.

The error handling follows the same consistent pattern as the regular permissions action, with appropriate error messages for admin context.

Also applies to: 61-61, 67-67, 71-71

apps/web/utils/actions/ai-rule.ts (5)

214-214: LGTM: Clear error handling for missing execution plan.

The change from returning an error object to throwing SafeError("Plan not found") provides clear feedback and follows the standardized error handling pattern.


278-278: LGTM: Consistent error handling for missing email account.

The error handling is standardized and provides appropriate feedback when the email account cannot be found.


510-510: LGTM: Duplicate pattern for email account validation.

The error handling is consistent with the previous instance and follows the standardized SafeError pattern.


567-567: LGTM: Appropriate error handling for AI generation failure.

The SafeError provides clear feedback when the AI fails to generate a rules prompt, maintaining consistency with the standardized error handling.


1-583: Flag inconsistency between AI summary and actual changes.

The AI-generated summary mentions premium account seat management and a new helper function updateAccountSeatsForPremium, but the actual changes in this file are only related to error handling standardization. The summary appears to be inconsistent with the actual code changes.

Likely an incorrect or invalid review comment.

apps/web/utils/actions/mail.ts (9)

22-22: LGTM: SafeError import added correctly.

The import aligns with the standardized error handling refactoring.


67-68: Consistent error handling pattern applied.

The change from returning error objects to throwing SafeError exceptions follows the same pattern as other functions in this refactoring.


80-80: Good maintenance: Updated commented code.

Even though this code is commented out, updating it to follow the new error handling pattern shows good attention to detail and maintains consistency.


93-93: Consistent error handling pattern applied.

The standardized error handling approach is correctly implemented.


110-110: Consistent error handling pattern applied.

The error message is clear and follows the established pattern.


123-123: Consistent error handling pattern applied.

The standardized error handling approach is correctly implemented.


139-139: Consistent error handling pattern applied.

The error message accurately describes the failure scenario.


159-160: Consistent error handling pattern applied.

The change maintains the same error handling pattern while preserving the return statement for successful responses.


174-174: Consistent error handling pattern applied.

The one-line format is clean and follows the established pattern.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

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

❌ The following Jit checks failed to run:

  • secret-detection
  • static-code-analysis-js

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

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

❌ The following Jit checks failed to run:

  • secret-detection
  • static-code-analysis-js

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

@elie222 elie222 merged commit 3d960b2 into main Jun 5, 2025
3 of 9 checks passed
@elie222 elie222 deleted the share-premium-stripe branch June 5, 2025 18:30
@coderabbitai coderabbitai bot mentioned this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments