Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Caution Review failedThe pull request is closed. WalkthroughThe 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
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
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
Poem
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
apps/web/app/api/ai/digest/route.tsOops! 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. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
emailAccountIdand 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
📒 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.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsxapps/web/app/api/user/categorization-preferences/route.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsxapps/web/app/api/user/categorization-preferences/route.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsxapps/web/app/api/user/categorization-preferences/route.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsxapps/web/app/api/user/categorization-preferences/route.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsxapps/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 thenext/imagepackage for images.
apps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/CategoriesSetup.tsxapps/web/app/api/user/categorization-preferences/route.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsapps/web/app/api/user/digest-settings/route.tsapps/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.tsapps/web/app/api/user/digest-settings/route.tsapps/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/bashRe-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.tsxapps/web/app/(app)/[emailAccountId]/assistant/onboarding/page.tsx (3)
6-6: Import updated to use renamed type.The import correctly uses the renamed
GetCategorizationPreferencesResponsetype.
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
LoadingContentwrapper 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_TYPESas 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
hasCronSecretfor cron authentication, validates the request body with Zod schema, scopes database operations toemailAccountId, and returns generic error messages without leaking sensitive information.
Summary by CodeRabbit
Refactor
Chores