feat: emails.metrics() for account-level email metrics

Merged
DI
3mo ago
+553-0

Summary

  • Adds emails.metrics() to retrieve account-level email metrics: counts and rates for sent, delivered, opened, clicked, bounced, etc., optionally broken down by period and/or domain.
  • Supports startDate/endDate range, timezone, granularity (hourly/daily/weekly), a metrics allowlist, dimensions breakdown, and filter.domainId.
  • totals and each data row are typed as a partial record over the possible metric keys, since the set of metrics present depends on what was requested.

Based on resend-docs#1686.

Test plan

  • emails.spec.ts covers metrics() with no options, with date range/metrics/dimensions/filter, and an error response
  • Full emails.spec.ts suite passes (27 tests)

Summary by cubic

Adds resend.emails.metrics() to fetch account-level email metrics with date range, timezone, granularity, breakdowns, filters, and flexible sorting (by date or any metric). Returns typed totals and optional rows; response echoes resolved sort_by/sort_order.

  • New Features

    • New resend.emails.metrics(options?) for /emails/metrics.
    • Options: startDate/endDate, timezone, granularity (hourly|daily|weekly), metrics, dimensions (period|domain|email), filter.domainId, filter.emailId, sortBy (date or any metric, including engagement and rate), sortOrder (asc|desc).
  • Bug Fixes

    • sortBy: 'date' works when dimensions includes period (alone or with domain/email).
    • Query builder omits empty metrics/dimensions, serializes timezone/granularity, and is simplified; get-metrics types exported from emails/interfaces.