Skip to content

fix(mailer): normalize provider response to nodemailer format#3375

Merged
PierreBrisorgueil merged 9 commits into
masterfrom
fix/mailer-normalize-resend-response
Apr 2, 2026
Merged

fix(mailer): normalize provider response to nodemailer format#3375
PierreBrisorgueil merged 9 commits into
masterfrom
fix/mailer-normalize-resend-response

Conversation

@PierreBrisorgueil

Copy link
Copy Markdown
Contributor

Summary

  • Resend returns { id } while Nodemailer returns { accepted, rejected } — controllers checking mail?.accepted.length always got 0 with Resend, returning 400 "Failure sending email"
  • In sendMail(), normalize response: if result.accepted is not an array, spread result and inject accepted: [mail.to], rejected: []
  • Also adds attachment support to both NodemailerProvider and ResendProvider (base64 encoding for Resend)

Test plan

  • mailer.unit.tests.js — covers normalization for non-array response and pass-through when already normalized
  • provider.resend.unit.tests.js — covers attachment encoding
  • All 9 mailer tests pass, pre-existing failure in migrations.integration.tests.js is unrelated

Closes #3373

- GET /api/admin/readiness (admin-only) returns startup checklist as JSON
- validateSaaSReadiness() prints status table at boot (skipped in test)
- 7 categories: Config, Security, Auth, Mail, Billing, Analytics, Monitoring
- Smart dependencies: Resend configured → skip Nodemailer warning
- Non-blocking: warnings only, never prevents startup
…tion

- Add proper JSDoc with @returns on logConfiguration
- Fix isSet JSDoc to match implementation (non-empty string check)
- JWT check now catches missing/empty secret, not just default value
- Remove mail provider name from response to avoid leaking placeholders
… cache isSet

- Add @returns {void} to readiness controller JSDoc
- Use can('manage', 'Readiness') matching standard CASL pattern
- Log readiness check failures at boot instead of swallowing
- Cache isSet(config.domain) to avoid duplicate calls
Cover all getReadinessStatus branches (ok/warning paths for each check
category) and the readiness controller error handler to improve patch
and project coverage.
- Wrap config mutation tests with try/finally to prevent state leakage
- Strengthen 401 assertion with status check
- Clarify isSet JSDoc wording
Pre-clean regular-readiness@test.com before creating it to prevent unique
index failures on re-runs, hoist to suite scope, and delete in afterAll.
Resend returns { id } while Nodemailer returns { accepted, rejected }.
Normalize in sendMail() so controllers checking mail?.accepted.length
work correctly with any provider. Also add attachment support to both
providers and mailer index.

Closes #3373
Copilot AI review requested due to automatic review settings April 2, 2026 07:16
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 20 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 20 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 15edaadf-3d0d-4a75-8a90-991d2308eacc

📥 Commits

Reviewing files that changed from the base of the PR and between ad23017 and 82228c8.

📒 Files selected for processing (12)
  • lib/app.js
  • lib/helpers/mailer/index.js
  • lib/helpers/mailer/provider.nodemailer.js
  • lib/helpers/mailer/provider.resend.js
  • lib/helpers/mailer/tests/mailer.unit.tests.js
  • lib/helpers/mailer/tests/provider.resend.unit.tests.js
  • lib/middlewares/policy.js
  • modules/home/controllers/home.controller.js
  • modules/home/policies/home.policy.js
  • modules/home/routes/home.route.js
  • modules/home/services/home.service.js
  • modules/home/tests/home.integration.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mailer-normalize-resend-response

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.84%. Comparing base (ac00abd) to head (82228c8).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3375      +/-   ##
==========================================
+ Coverage   84.60%   84.84%   +0.24%     
==========================================
  Files         110      110              
  Lines        2767     2811      +44     
  Branches      769      789      +20     
==========================================
+ Hits         2341     2385      +44     
  Misses        337      337              
  Partials       89       89              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves mail delivery consistency by normalizing provider responses to Nodemailer’s { accepted, rejected } shape and adds attachment support across mail providers. It also introduces a new admin-only “readiness” endpoint plus startup logging to surface configuration readiness signals.

Changes:

  • Normalize sendMail() results so non-Nodemailer providers (e.g., Resend) still return { accepted, rejected } for downstream controllers.
  • Add attachment support for both Resend (base64 encoding) and Nodemailer providers.
  • Add admin-only readiness checks endpoint (/api/admin/readiness) and log a readiness summary during server startup.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
modules/home/tests/home.integration.tests.js Adds integration coverage for readiness auth + response shape and scenarios.
modules/home/services/home.service.js Implements readiness checks derived from config + mailer configuration.
modules/home/routes/home.route.js Registers new admin readiness route with JWT auth + CASL policy.
modules/home/policies/home.policy.js Grants admins CASL ability to manage/read the readiness subject.
modules/home/controllers/home.controller.js Adds readiness controller action returning the readiness checks.
lib/middlewares/policy.js Maps /api/admin/readiness to the Readiness CASL subject type.
lib/helpers/mailer/tests/provider.resend.unit.tests.js Adds unit test coverage for attachment encoding in Resend provider.
lib/helpers/mailer/tests/mailer.unit.tests.js Adds unit tests for response normalization + attachment forwarding.
lib/helpers/mailer/provider.resend.js Implements attachment base64 encoding for Resend payloads.
lib/helpers/mailer/provider.nodemailer.js Adds attachment forwarding into Nodemailer sendMail() payload.
lib/helpers/mailer/index.js Forwards attachments and normalizes provider send results to {accepted,rejected}.
lib/app.js Logs readiness summary at startup via dynamic import of HomeService.

Comment thread modules/home/services/home.service.js
Comment thread lib/helpers/mailer/provider.nodemailer.js
Comment thread lib/app.js
Comment thread lib/app.js
Comment thread modules/home/tests/home.integration.tests.js
@PierreBrisorgueil
PierreBrisorgueil merged commit c8bd3a0 into master Apr 2, 2026
9 checks passed
@PierreBrisorgueil
PierreBrisorgueil deleted the fix/mailer-normalize-resend-response branch April 2, 2026 07:55
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.

fix(mailer): normalize provider response to nodemailer format (accepted/rejected)

2 participants