Skip to content

Comments

Digest clean up#521

Merged
elie222 merged 6 commits intomainfrom
feat/digest-screen
Jun 23, 2025
Merged

Digest clean up#521
elie222 merged 6 commits intomainfrom
feat/digest-screen

Conversation

@elie222
Copy link
Owner

@elie222 elie222 commented Jun 23, 2025

Summary by CodeRabbit

  • Refactor

    • Improved how email account information is accessed during onboarding setup, streamlining internal data handling.
    • Simplified loading and error display for onboarding categories setup, providing a more consistent user experience.
    • Updated internal naming for categorization preferences, with no impact on user-facing features.
    • Enhanced consistency checks for supported system types in digest settings.
    • Refined digest processing to improve reliability and maintainability behind the scenes.
  • Chores

    • Updated version to v1.7.5.

@vercel
Copy link

vercel bot commented Jun 23, 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 23, 2025 2:58pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes refactor how email account IDs are accessed in the onboarding category setup, update API endpoints and response types, and improve loading state handling in the onboarding page. Digest upsertion logic is moved from a utility file into the API route, with related database code removed from the utility. Type naming is clarified, and digest settings logic is made more robust. The version is incremented.

Changes

File(s) Change Summary
.../CategoriesSetup.tsx Refactored to obtain emailAccountId internally via hook; prop removed from component signature.
.../onboarding/page.tsx Updated to use new API endpoint and response type; improved loading/error handling; stopped passing prop.
.../api/ai/digest/route.ts Inlined and rewrote upsertDigest logic; removed external import; added atomic find-or-create/update-or-create.
.../api/user/categorization-preferences/route.ts Renamed exported type alias for response from onboarding to categorization preferences.
.../api/user/digest-settings/route.ts Introduced supported system types constant; added mapping consistency check.
.../utils/digest/index.ts Removed all Prisma/database-related digest functions and types; retained only queue-publishing logic.
version.txt Version updated from v1.7.4 to v1.7.5.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CategoriesSetup
    participant EmailAccountProvider

    User->>CategoriesSetup: Render component
    CategoriesSetup->>EmailAccountProvider: useAccount()
    EmailAccountProvider-->>CategoriesSetup: Returns emailAccountId
    CategoriesSetup->>CategoriesSetup: Uses emailAccountId internally
Loading
sequenceDiagram
    participant API
    participant upsertDigest (in route)
    participant Database

    API->>upsertDigest: Call with messageId, threadId, emailAccountId, etc.
    upsertDigest->>Database: Find pending digest for emailAccountId
    alt Digest exists
        upsertDigest->>Database: Find digest item by messageId/threadId
        alt Digest item exists
            upsertDigest->>Database: Update digest item
        else Digest item does not exist
            upsertDigest->>Database: Create new digest item
        end
    else Digest does not exist
        upsertDigest->>Database: Create new pending digest
        upsertDigest->>Database: Create new digest item
    end
    upsertDigest-->>API: Return result or throw error
Loading

Poem

🐇
Version hops from four to five,
Categories now self-derive.
Digests upsert with local might,
Old database code hops out of sight.
Types renamed, mappings checked,
Loading screens now more direct.
With every change, we leap ahead—
A happy rabbit, well code-fed!

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/app/api/ai/digest/route.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.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 806e87a and df9d514.

📒 Files selected for processing (1)
  • apps/web/app/api/ai/digest/route.ts (3 hunks)
✨ 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.

@elie222 elie222 merged commit b55770a into main Jun 23, 2025
9 checks passed
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: 0

🧹 Nitpick comments (1)
apps/web/app/api/ai/digest/route.ts (1)

58-148: Clean implementation of digest upsertion with proper scoping.

The function correctly scopes all database operations to emailAccountId and handles optional fields elegantly using the spread operator pattern. The find-or-create pattern provides reasonable protection against duplicates.

Consider using a database transaction for true atomicity if you experience race conditions with simultaneous requests for the same digest.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e64f3fb and 806e87a.

📒 Files selected for processing (7)
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (1 hunks)
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx (1 hunks)
  • apps/web/app/api/ai/digest/route.ts (2 hunks)
  • apps/web/app/api/user/categorization-preferences/route.ts (1 hunks)
  • apps/web/app/api/user/digest-settings/route.ts (3 hunks)
  • apps/web/utils/digest/index.ts (0 hunks)
  • version.txt (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/utils/digest/index.ts
🧰 Additional context used
📓 Path-based instructions (8)
`apps/web/**/app/**`: Follow NextJS app router structure by organizing code within the app directory.

apps/web/**/app/**: Follow NextJS app router structure by organizing code within the app directory.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`apps/web/**/*.{ts,tsx}`: Use TypeScript with strict null checks enabled. Use path aliases with @/ for imports from the project root. Use proper error handling with try/catch block...

apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks enabled.
Use path aliases with @/ for imports from the project root.
Use proper error handling with try/catch blocks.
Use the LoadingContent component for async data loading states.
Prefix client-side environment variables with NEXT_PUBLIC_.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`apps/web/**/*.{ts,tsx,js,jsx}`: Format code with Prettier and follow tailwindcss patterns using prettier-plugin-tailwindcss.

apps/web/**/*.{ts,tsx,js,jsx}: Format code with Prettier and follow tailwindcss patterns using prettier-plugin-tailwindcss.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`apps/web/**`: Install packages only within the 'apps/web' directory, not at the repository root.

apps/web/**: Install packages only within the 'apps/web' directory, not at the repository root.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`apps/web/app/(app)/**/*.{js,jsx,ts,tsx}`: If you need to use onClick in a component, that component is a client component and file must start with 'use client'.

apps/web/app/(app)/**/*.{js,jsx,ts,tsx}: If you need to use onClick in a component, that component is a client component and file must start with 'use client'.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
`**/*.{js,jsx,ts,tsx}`: Use Shadcn UI and Tailwind for components and styling. Implement responsive design with Tailwind CSS using a mobile-first approach. Use the `next/image` pac...

**/*.{js,jsx,ts,tsx}: Use Shadcn UI and Tailwind for components and styling.
Implement responsive design with Tailwind CSS using a mobile-first approach.
Use the next/image package for images.

  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx
  • apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx
  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`apps/web/app/api/**/*`: All API route handlers must use authentication middleware such as withAuth, withEmailAccount, or withError with custom authentication logic. All database q...

apps/web/app/api/**/*: All API route handlers must use authentication middleware such as withAuth, withEmailAccount, or withError with custom authentication logic.
All database queries must include user/account filtering, using emailAccountId or userId in WHERE clauses.
Parameters must be validated before use; do not use direct parameter values in queries without validation.
Request bodies should use Zod schemas for validation.
Only necessary fields should be returned in API responses; use Prisma's select to limit fields.
Do not include sensitive data in error messages; use generic errors and SafeError for user-facing errors.
Cron endpoints must use hasCronSecret or hasPostCronSecret for authentication.
Do not hardcode weak secrets in cron endpoints; secrets should not be plain strings in code except for environment variables like CRON_SECRET.

  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
`**/api/**/*.ts`: ALL API routes that handle user data MUST use appropriate authentication and authorization middleware such as withAuth or withEmailAccount. ALL database queries i...

**/api/**/*.ts: ALL API routes that handle user data MUST use appropriate authentication and authorization middleware such as withAuth or withEmailAccount.
ALL database queries in API routes MUST be scoped to the authenticated user/account (e.g., include userId or emailAccountId in query filters).
Always validate that resources being accessed or modified belong to the authenticated user before performing operations.
All parameters (route, query, body) in API routes MUST be validated for type, format, and length before use.
Request bodies in API routes MUST be validated using Zod schemas or equivalent.
Error responses in API routes MUST NOT leak sensitive information; use generic error messages and consistent error formats.
All findUnique/findFirst database calls in API routes MUST include ownership filters (e.g., userId or emailAccountId).
All findMany database calls in API routes MUST be scoped to the authenticated user's data.
API routes MUST NOT return sensitive fields or data from other users.
API routes MUST NOT use direct object references (IDs) without ownership checks to prevent IDOR vulnerabilities.
API routes MUST use explicit whitelisting of allowed fields for updates to prevent mass assignment and privilege escalation.
API routes MUST NOT use user input directly in queries; always validate and sanitize inputs.
API routes MUST use SafeError or equivalent for error handling to prevent information disclosure.
API routes MUST use withError middleware (not withAuth or withEmailAccount) for public endpoints, webhooks, or cron endpoints, and MUST implement custom authentication/validation as appropriate.

  • apps/web/app/api/user/categorization-preferences/route.ts
  • apps/web/app/api/user/digest-settings/route.ts
  • apps/web/app/api/ai/digest/route.ts
🔇 Additional comments (11)
version.txt (1)

1-1: Version bump looks good.

The version increment from v1.7.4 to v1.7.5 aligns with the coordinated changes across the codebase.

apps/web/app/api/user/categorization-preferences/route.ts (1)

20-22: ```shell
#!/bin/bash

Re-check for any remaining references to GetOnboardingPreferencesResponse in TS/TSX files

rg "GetOnboardingPreferencesResponse" -g ".ts" -g ".tsx"


</details>
<details>
<summary>apps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsx (2)</summary>

`36-36`: **Good refactoring to use context provider.**

Using the `useAccount` hook to internally obtain `emailAccountId` centralizes the account handling logic.

---

`46-46`: ```shell
#!/bin/bash
# Inspect GlobalProviders to see EmailAccountProvider usage
echo "===== GlobalProviders.tsx ====="
sed -n '1,200p' apps/web/providers/GlobalProviders.tsx

# Inspect the root app layout
echo -e "\n===== apps/web/app/layout.tsx ====="
sed -n '1,200p' apps/web/app/layout.tsx

# Inspect the (app) group layout
echo -e "\n===== apps/web/app/(app)/layout.tsx ====="
sed -n '1,200p' apps/web/app/\(app\)/layout.tsx
apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx (3)

6-6: Import updated to use renamed type.

The import correctly uses the renamed GetCategorizationPreferencesResponse type.


10-16: Good use of useSWR for data fetching.

The data fetching pattern using useSWR with the new API endpoint is implemented correctly.


20-22: LoadingContent improves loading state handling.

Using LoadingContent wrapper simplifies the loading and error state management compared to multiple skeleton components.

apps/web/app/api/user/digest-settings/route.ts (3)

6-14: Good refactoring to explicit constant.

Defining SUPPORTED_SYSTEM_TYPES as an explicit constant improves maintainability and makes the supported types clear.


39-39: Proper use of spread operator with constant.

Using the spread operator with the constant array correctly maintains the same functionality while improving readability.


87-94: Runtime validation adds robustness.

The runtime check ensures that all supported system types have corresponding mappings, which helps catch configuration errors early.

apps/web/app/api/ai/digest/route.ts (1)

14-56: Well-implemented API endpoint following security best practices.

The POST handler correctly uses hasCronSecret for cron authentication, validates the request body with Zod schema, scopes database operations to emailAccountId, and returns generic error messages without leaking sensitive information.

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