Skip to content

feat(billing): extract email listeners + ship generic templates#3747

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
feat/promote-billing-emails
May 31, 2026
Merged

feat(billing): extract email listeners + ship generic templates#3747
PierreBrisorgueil merged 1 commit into
masterfrom
feat/promote-billing-emails

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

Summary

Trawl had meter.threshold_crossed + payment.failed listeners + email helpers (resolveOrgAdminEmails, sendBillingEmail) inline in billing.init.js. These are universal — every downstream running the billing module wants billing quota warnings and payment failure notifications.

  • New modules/billing/billing.email.js exports setupBillingEmails() which wires the two listeners + both helpers. Called from billing.init.js.
  • Generic templates ship in config/templates/billing-quota-warning-80.html, billing-quota-reached-100.html, billing-payment-failed.html with {{appName}} placeholder — zero hardcoded branding, fully config-driven via config.app.title.
  • Downstream override: place same-named files in downstream's config/templates/ — they shadow devkit defaults via template-resolution glob-merge. Trawl's own branded templates already exist and still win.
  • Subjects are config-driven: ${config.app.title} weekly quota reached — each downstream gets its own app name.
  • 18 de-trawlified unit tests ported covering both listener paths (threshold 80/100 + payment.failed), mailer not-configured, empty email list, DB failure, sendMail rejection, multi-recipient, missing-email filter.
  • Existing billing.init tests updated to mock billing.email.js so boot-validator tests remain isolated.

Test plan

  • billing.init.email-alerts.unit.tests.js — 18 tests, all passing
  • Full unit suite — 1641 tests, all passing
  • ESLint — no issues on all changed/new files
  • Zero trawl / Trawl references in any new file
  • Templates use {{appName}} throughout, no hardcoded branding

References

- New `modules/billing/billing.email.js` exports `setupBillingEmails()` which wires
  `meter.threshold_crossed` (80%/100%) and `payment.failed` event listeners,
  plus `resolveOrgAdminEmails` and `sendBillingEmail` helpers
- `billing.init.js` imports and calls `setupBillingEmails()` from the new file
- Ship 3 generic HTML templates in `config/templates/billing-*.html` using
  `{{appName}}` placeholder (resolved from `config.app.title` at send-time);
  zero hardcoded branding — every downstream gets working billing emails out of the box
- Downstream override: place same-named files in downstream's `config/templates/`;
  they shadow devkit defaults via template-resolution glob-merge
- Port + de-trawlify 18 unit tests covering both listener paths (threshold + payment.failed)
- Subjects are now config-driven (`${config.app.title} weekly quota reached`)
  so each downstream gets its own app name in email subjects

Closes #3746
Copilot AI review requested due to automatic review settings May 31, 2026 18:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5e7fb46-9916-4fd6-a595-0cf30f8b3cad

📥 Commits

Reviewing files that changed from the base of the PR and between 2ff4161 and 2c3f1ed.

📒 Files selected for processing (8)
  • config/templates/billing-payment-failed.html
  • config/templates/billing-quota-reached-100.html
  • config/templates/billing-quota-warning-80.html
  • modules/billing/billing.email.js
  • modules/billing/billing.init.js
  • modules/billing/tests/billing.init.email-alerts.unit.tests.js
  • modules/billing/tests/billing.init.ops-listeners.unit.tests.js
  • modules/billing/tests/billing.init.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/promote-billing-emails

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
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.11%. Comparing base (2ff4161) to head (2c3f1ed).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3747      +/-   ##
==========================================
+ Coverage   90.03%   90.11%   +0.07%     
==========================================
  Files         148      149       +1     
  Lines        4898     4936      +38     
  Branches     1546     1564      +18     
==========================================
+ Hits         4410     4448      +38     
  Misses        383      383              
  Partials      105      105              
Flag Coverage Δ
integration 59.66% <15.78%> (-0.35%) ⬇️
unit 68.73% <100.00%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ff4161...2c3f1ed. Read the comment docs.

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

@PierreBrisorgueil PierreBrisorgueil merged commit 8393489 into master May 31, 2026
8 of 9 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

feat(billing): extract email listeners + ship generic templates so every downstream gets quota / payment-failed mails

2 participants