Skip to content

Comments

fix: Fixes digest validation issues#576

Merged
elie222 merged 4 commits intoelie222:mainfrom
edulelis:digest-emails-v3
Jul 17, 2025
Merged

fix: Fixes digest validation issues#576
elie222 merged 4 commits intoelie222:mainfrom
edulelis:digest-emails-v3

Conversation

@edulelis
Copy link
Collaborator

@edulelis edulelis commented Jul 17, 2025

Updated to display categories in 2 * n + 1 rows as can be seen in images below:

  • Custom categories
Screenshot 2025-07-17 at 00 50 30
  • Single category
Screenshot 2025-07-17 at 00 52 02

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing recipient information in email digests to prevent errors when the "to" field is undefined or absent.
  • Refactor

    • Updated validation rules to make the recipient field optional in email digest processing.
    • Enhanced email digest categories to support dynamic, arbitrary category names instead of fixed lists.
    • Simplified digest email layout with uniform category grid and improved handling of unknown or empty categories.
    • FIXES digest mails not being sent: Embedded cron secret directly in request payload for digest resend operations instead of in headers.

@vercel
Copy link

vercel bot commented Jul 17, 2025

@edulelis is attempting to deploy a commit to the Inbox Zero Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Walkthrough

The updates adjust how the to field is handled in email message objects across validation, processing, and summarization logic. The to field is now optional in validation, and downstream code ensures it is always a string by defaulting to an empty string when undefined or null. Additionally, digest category handling was generalized to accept arbitrary category strings instead of a fixed set, with corresponding updates in validation, processing, and UI rendering. The resend digest API was also updated to embed the cron secret in the request body instead of headers.

Changes

File(s) Change Summary
.../digest/validation.ts Made the to property in the message schema optional; replaced fixed digest category enum with a flexible string schema.
.../digest/route.ts Ensured the to property in the message object is always a string (`to
.../digest/index.ts Updated message construction to set to as `email.headers.to
.../resend/digest/validation.ts Replaced fixed digest category enum with a flexible string schema; updated digest schema to use a record of string keys.
.../resend/digest/route.ts Removed validation against fixed digest categories; used rule names directly as categories; adjusted object spreading order.
.../resend/digest/all/route.ts Moved CRON_SECRET from request headers into the request body payload for Qstash queue requests.
packages/resend/emails/digest.tsx Generalized DigestEmailProps to accept arbitrary categories; updated rendering logic to dynamically handle any category; simplified layout and added fallback category info.

Possibly related PRs

  • Digest clean up #521: Refactors digest upsert logic and database handling, related to digest processing but does not overlap on the same code or variables.

Poem

A hop and a skip, the “to” is now free,
Optional in schema, as clear as can be.
Categories once fixed, now wild and wide,
New keys and layouts, with joy we glide.
Secrets tucked safely inside the payload,
Rabbits leap forward on this new code road!
🐇✨📧


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f09ee42 and d5da6f3.

📒 Files selected for processing (3)
  • apps/web/app/api/resend/digest/route.ts (2 hunks)
  • apps/web/app/api/resend/digest/validation.ts (1 hunks)
  • packages/resend/emails/digest.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/app/api/resend/digest/route.ts
  • apps/web/app/api/resend/digest/validation.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.tsx

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/data-fetching.mdc
  • .cursor/rules/form-handling.mdc
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/form-handling.mdc
🧠 Learnings (2)
📓 Common learnings
Learnt from: edulelis
PR: elie222/inbox-zero#576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.046Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses `[key: string]: DigestItem[] | undefined | string | Date | undefined` instead of intersection types like `& Record<string, DigestItem[] | undefined>` due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.
packages/resend/emails/digest.tsx (1)
Learnt from: edulelis
PR: elie222/inbox-zero#576
File: packages/resend/emails/digest.tsx:78-83
Timestamp: 2025-07-17T04:19:57.046Z
Learning: In packages/resend/emails/digest.tsx, the DigestEmailProps type uses `[key: string]: DigestItem[] | undefined | string | Date | undefined` instead of intersection types like `& Record<string, DigestItem[] | undefined>` due to implementation constraints. This was the initial implementation approach and cannot be changed to more restrictive typing.
⏰ 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). (2)
  • GitHub Check: Static Code Analysis Js
  • GitHub Check: Jit Security
🔇 Additional comments (6)
packages/resend/emails/digest.tsx (6)

86-149: Excellent implementation of flexible category handling.

The destructuring approach with digestData and the getCategoryInfo function with fallback for unknown categories is well-designed. The fallback properly provides consistent styling (gray color, folder icon) for custom categories as intended.


151-238: Good refactor of category grid rendering.

The simplified approach with consistent 2-per-row layout is more maintainable than the previous complex conditional logic. The dynamic category filtering and proper spacing logic work well with the new flexible category system.


240-248: Good defensive programming practice.

The early return prevents rendering empty digest emails, which improves the user experience. The filtering logic is consistent with other functions in the component.


250-311: Well-implemented flexible CategorySection component.

The updates properly handle both known and unknown categories with appropriate fallbacks. The double fallback approach (category.color fallback + colorClasses.gray fallback) ensures robust error handling.


344-357: Correct implementation of dynamic category rendering.

The switch from hardcoded categories to dynamic mapping over digestData keys properly supports the flexible category system. The type checking and conditional rendering logic is sound.


601-634: Good test cases for flexible category system.

The custom categories provide excellent test coverage for the new flexible category functionality, demonstrating how unknown categories are handled with fallback styling.

✨ 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.

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.

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: 4

🧹 Nitpick comments (1)
apps/web/app/api/resend/digest/validation.ts (1)

33-35: Consider adding constraints to the flexible schema

While the flexible category approach is good for extensibility, consider adding reasonable constraints to prevent potential issues:

Add validation constraints for category names and limits:

-export const digestCategorySchema = z.string();
+export const digestCategorySchema = z.string().min(1).max(50).regex(/^[a-zA-Z0-9]+$/);

-export const digestSchema = z.record(z.string(), z.array(digestItemSchema).optional());
+export const digestSchema = z.record(
+  digestCategorySchema,
+  z.array(digestItemSchema).max(100).optional()
+).refine(
+  (data) => Object.keys(data).length <= 20,
+  { message: "Maximum 20 categories allowed" }
+);

This ensures category names are alphanumeric, reasonably sized, and limits the total number of categories and items per category.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb237bb and f09ee42.

📒 Files selected for processing (4)
  • apps/web/app/api/resend/digest/all/route.ts (1 hunks)
  • apps/web/app/api/resend/digest/route.ts (2 hunks)
  • apps/web/app/api/resend/digest/validation.ts (1 hunks)
  • packages/resend/emails/digest.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/web/**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • apps/web/CLAUDE.md
apps/web/app/**/*

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • apps/web/CLAUDE.md
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/form-handling.mdc
**/*.tsx

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/data-fetching.mdc
  • .cursor/rules/form-handling.mdc
🧠 Learnings (2)
apps/web/app/api/resend/digest/all/route.ts (3)
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-06-23T12:27:05.686Z
Learning: Do not hardcode secrets directly in code for cron endpoints; secrets should be managed via environment variables (e.g., CRON_SECRET) and not as plain strings in the source code.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security.mdc:0-0
Timestamp: 2025-06-23T12:27:17.978Z
Learning: Cron endpoints must use withError middleware and validate requests with strong secrets (hasCronSecret/hasPostCronSecret); never use weak or predictable secrets.
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-06-23T12:27:05.686Z
Learning: Cron endpoints in API routes must be protected with secret validation middleware such as hasCronSecret or hasPostCronSecret to prevent unauthorized access.
apps/web/app/api/resend/digest/validation.ts (2)
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/form-handling.mdc:0-0
Timestamp: 2025-07-03T12:02:53.001Z
Learning: Applies to **/*.{ts,tsx} : Define validation schemas using Zod
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/server-actions.mdc:0-0
Timestamp: 2025-06-23T12:27:23.938Z
Learning: Input validation schemas for server actions should be defined using Zod in dedicated .validation.ts files, which can be reused on the client for form validation.
⏰ 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). (2)
  • GitHub Check: Static Code Analysis Js
  • GitHub Check: Jit Security
🔇 Additional comments (2)
packages/resend/emails/digest.tsx (2)

138-149: Well-implemented fallback handling for dynamic categories

The fallback mechanism for unknown categories is robust - it provides sensible defaults for name, emoji, color, and href. The use of the nullish coalescing operator for colors ensures the UI remains consistent even with unexpected category values.

Also applies to: 255-255


237-243: Good defensive programming with early return

The early return when no digest items are present prevents sending empty emails and improves performance by avoiding unnecessary rendering.

return availableCategories[key as keyof typeof availableCategories];
}
// Fallback for unknown categories
return {
Copy link
Collaborator Author

@edulelis edulelis Jul 17, 2025

Choose a reason for hiding this comment

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

All custom categories will have a gray color with a folder icon, as can be seen in the image attached.

@elie222
Copy link
Owner

elie222 commented Jul 17, 2025

@claude review this

@claude
Copy link

claude bot commented Jul 17, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@coderabbitai coderabbitai bot mentioned this pull request Sep 21, 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.

2 participants