feat: emails.metrics() for account-level email metrics - #1042
Conversation
commit: |
a6c8948 to
bde573f
Compare
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.
Re-trigger cubic
Also cover timezone/granularity serialization in the metrics options test, per cubic review on #1042.
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: This adds a new public SDK method and exported request/response types for a new API endpoint, expanding the package's public contract surface. A human should approve the added method, parameter mapping, and types before release.
Re-trigger cubic
klotty
left a comment
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Adds a new API wrapper method that delegates to the backend endpoint; no existing behavior changed, no operational or security tradeoff visible in the diff.
Re-trigger cubic
Also cover timezone/granularity serialization in the metrics options test, per cubic review on #1042.
4b0a606 to
4011a30
Compare
10e0dc9 to
e50c36b
Compare
Also cover timezone/granularity serialization in the metrics options test, per cubic review on #1042.
4011a30 to
8683e39
Compare
e50c36b to
afc19ce
Compare
Based on resend-docs#1686.
Seven near-identical if-blocks reduced to one key/value map filtered in a single loop.
Also cover timezone/granularity serialization in the metrics options test, per cubic review on #1042.
…cs() Mirrors the domain dimension/filter. Keeps the SDK in sync with the emails/metrics endpoint's new per-email breakdown.
- sortBy: 'date' for a period breakdown, or a count/derived metric (received, delivered, ..., sent) for a domain-only or email-only breakdown. - sortOrder: 'asc' | 'desc', defaults to 'asc' for a period breakdown and 'desc' otherwise. - Response now echoes the resolved sort_by/sort_order. - Also omit empty metrics/dimensions arrays from the query string, same fix as segments.metrics(). Based on resend-monorepo#7814.
Corrects the doc comment and adds a test: sortBy='date' requires dimensions to include 'period', not be exactly ['period'] — it also works for a period+domain or period+email breakdown. Based on the latest resend-monorepo#7814 commit that fixed this same gap server-side.
…rived The API now supports sorting a domain/email breakdown by engagement metrics (unique_opened, unique_clicked) and rate metrics (open_rate, bounce_rate, etc.), not just the count/derived ones. Widens EmailMetricsSortBy from the narrower SortableEmailMetric subset to EmailMetric directly, since every metric is sortable now - some via the Tinybird pipe, some client-side, but that's an API implementation detail the SDK type doesn't need to encode.
8683e39 to
5873b0e
Compare
Summary
emails.metrics()to retrieve account-level email metrics: counts and rates forsent,delivered,opened,clicked,bounced, etc., optionally broken down byperiodand/ordomain.startDate/endDaterange,timezone,granularity(hourly/daily/weekly), ametricsallowlist,dimensionsbreakdown, andfilter.domainId.totalsand eachdatarow 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.tscoversmetrics()with no options, with date range/metrics/dimensions/filter, and an error responseemails.spec.tssuite 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 resolvedsort_by/sort_order.New Features
resend.emails.metrics(options?)for/emails/metrics.startDate/endDate,timezone,granularity(hourly|daily|weekly),metrics,dimensions(period|domain|email),filter.domainId,filter.emailId,sortBy(dateor any metric, including engagement and rate),sortOrder(asc|desc).Bug Fixes
sortBy: 'date'works whendimensionsincludesperiod(alone or withdomain/email).metrics/dimensions, serializestimezone/granularity, and is simplified;get-metricstypes exported fromemails/interfaces.Written for commit 5873b0e. Summary will update on new commits.