migma 1.3.4 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,7 +97,7 @@ await migma.sending.send({
97
97
 
98
98
  ## Features
99
99
 
100
- - Full coverage of all Migma API v1 endpoints (80+ methods across 15 resources)
100
+ - Full coverage of all Migma API v1 endpoints (80+ methods across 16 resources)
101
101
  - TypeScript-first with complete type definitions
102
102
  - `{ data, error }` return pattern — methods never throw
103
103
  - Automatic retries with exponential backoff on 5xx/429
@@ -227,6 +227,27 @@ const { data: deletion } = await migma.contacts.bulkDeleteByEmail({
227
227
  projectId: 'proj_abc123',
228
228
  });
229
229
 
230
+ // Import contacts from a CSV file (multipart upload, processed in the background).
231
+ // `file` accepts a Blob/File, a Buffer, or a ReadableStream.
232
+ import { readFileSync } from 'node:fs';
233
+
234
+ const { data: job } = await migma.contacts.imports.create({
235
+ file: readFileSync('./contacts.csv'),
236
+ projectId: 'proj_abc123',
237
+ columnMap: {
238
+ email: 'Email',
239
+ firstName: 'First Name',
240
+ customFields: { plan: 'Plan' },
241
+ },
242
+ onConflict: 'upsert',
243
+ tags: ['newsletter'],
244
+ });
245
+
246
+ // Poll for status + counts until the import finishes.
247
+ const { data: status } = await migma.contacts.imports.get(job!.id);
248
+ // status.status → 'pending' | 'processing' | 'completed' | 'failed'
249
+ // status.counts → { total, created, updated, skipped, failed }
250
+
230
251
  // Safe retries: pass an Idempotency-Key so a retried write never duplicates.
231
252
  // Same key + same body within 24h replays the original response.
232
253
  await migma.contacts.create(
@@ -287,6 +308,23 @@ await migma.sending.send({
287
308
 
288
309
  [Sending API Reference](https://docs.migma.ai/api-reference/sending/send-email)
289
310
 
311
+ ### Sending Metrics
312
+
313
+ Read account sending totals, delivery outcomes, and remaining daily and monthly capacity.
314
+
315
+ ```typescript
316
+ const { data: metrics } = await migma.metrics.sending({ months: 6 });
317
+
318
+ console.log(metrics?.period, metrics?.monthly.sent, metrics?.remainingMonth);
319
+ console.log(metrics?.today.sent, metrics?.today.remainingToday);
320
+
321
+ for (const month of metrics?.history ?? []) {
322
+ console.log(month.period, month.sent, month.delivered, month.bounced, month.complained);
323
+ }
324
+ ```
325
+
326
+ Omit `months` when you only need the current month and today's capacity.
327
+
290
328
  ### Generated Series and Editing
291
329
 
292
330
  Generate a series with `count`, then use each email's `emailId` to fetch, prompt-edit, or send one email.
@@ -479,11 +517,11 @@ const { data: devices } = await migma.previews.getSupportedDevices();
479
517
 
480
518
  ### Export
481
519
 
482
- Export generated emails to HTML, MJML, PDF, or directly to ESP platforms.
520
+ Export generated emails to HTML, PNG, PDF, or directly to ESP platforms.
483
521
 
484
522
  ```typescript
485
523
  const { data: html } = await migma.export.html('conversation_id');
486
- const { data: mjml } = await migma.export.mjml('conversation_id');
524
+ const { data: png } = await migma.export.png('conversation_id');
487
525
  const { data: pdf } = await migma.export.pdf('conversation_id');
488
526
  const { data: klaviyo } = await migma.export.klaviyo('conversation_id', 'hybrid');
489
527
  const { data: mailchimp } = await migma.export.mailchimp('conversation_id');
@@ -601,16 +639,18 @@ await migma.images.updateLogos('proj_abc123', {
601
639
  | Resource | Methods | Docs |
602
640
  |----------|---------|------|
603
641
  | `migma.contacts` | `create` `list` `get` `update` `remove` `bulkImport` `getBulkImportStatus` `changeStatus` | [Contacts](https://docs.migma.ai/api-reference/contacts/get-contact) |
642
+ | `migma.contacts.imports` | `create` `get` | [Contact imports](https://docs.migma.ai/api-reference/contacts/get-contact) |
604
643
  | `migma.tags` | `create` `list` `get` `update` `remove` | [Tags](https://docs.migma.ai/api-reference/tags/list-tags) |
605
644
  | `migma.segments` | `create` `list` `get` `update` `remove` | [Segments](https://docs.migma.ai/api-reference/audiences/list-audiences) |
606
645
  | `migma.topics` | `create` `list` `get` `update` `remove` `subscribe` `unsubscribe` | [Topics](https://docs.migma.ai/api-reference/topics/list-topics) |
607
646
  | `migma.sending` | `send` `getBatchStatus` | [Sending](https://docs.migma.ai/api-reference/sending/send-email) |
647
+ | `migma.metrics` | `sending` | [API Reference](https://docs.migma.ai/api-reference/introduction) |
608
648
  | `migma.projects` | `list` `get` `import` `getImportStatus` `retryImport` `fieldCatalog` `importAndWait` | [Projects](https://docs.migma.ai/api-reference/projects/list-projects) |
609
649
  | `migma.emails` | `generate` `getGenerationStatus` `generateAndWait` `sendTest` `get` `edit` | [Email Generation](https://docs.migma.ai/api-reference/email/generate-email-async) |
610
650
  | `migma.campaigns` | `list` `create` `get` `send` `schedule` `cancel` `stats` `logs` `archive` `unarchive` | [Campaigns](https://docs.migma.ai/campaigns/overview) |
611
651
  | `migma.validation` | `all` `compatibility` `links` `spelling` `deliverability` | [Validation](https://docs.migma.ai/api-reference/email-validation/run-all-validation-checks) |
612
652
  | `migma.previews` | `create` `get` `getStatus` `getDevice` `getSupportedDevices` `createAndWait` | [Previews](https://docs.migma.ai/api-reference/email-previews/create-email-preview) |
613
- | `migma.export` | `getFormats` `getStatus` `html` `mjml` `pdf` `klaviyo` `mailchimp` `hubspot` | [Export](https://docs.migma.ai/api-reference/export/list-export-formats) |
653
+ | `migma.export` | `getFormats` `getStatus` `html` `pdf` `png` `klaviyo` `mailchimp` `hubspot` | [Export](https://docs.migma.ai/api-reference/export/list-export-formats) |
614
654
  | `migma.domains` | `create` `list` `get` `verify` `update` `remove` `checkAvailability` `listManaged` `createManaged` `removeManaged` `provisionStream` `setup` | [Domains](https://docs.migma.ai/api-reference/domains/list-domains) |
615
655
  | `migma.webhooks` | `create` `list` `get` `update` `remove` `test` `getDeliveries` `getEvents` `getStats` | [Webhooks](https://docs.migma.ai/webhooks) |
616
656
  | `migma.knowledgeBase` | `list` `add` `update` `remove` | [API Ref](https://docs.migma.ai/api-reference/introduction) |
package/dist/index.d.mts CHANGED
@@ -429,6 +429,14 @@ interface SendEmailResponse {
429
429
  status: string;
430
430
  sentCount?: number;
431
431
  message?: string;
432
+ /** Real tracking id for a single send — use with emails.metrics()/logs() and the activity view. Absent for batch sends. */
433
+ sendId?: string;
434
+ /** Batch id for an audience/tag send. Absent for single sends. */
435
+ batchId?: string;
436
+ /** Echoes the generated email id this send was tagged with, when provided. */
437
+ emailId?: string;
438
+ /** Conversation this send belongs to, when known. */
439
+ conversationId?: string;
432
440
  }
433
441
  interface BatchStatus {
434
442
  batchId: string;
@@ -707,6 +715,88 @@ interface EditEmailParams {
707
715
  prompt: string;
708
716
  label?: string;
709
717
  }
718
+ interface EmailMetricsSummary {
719
+ totalEmails: number;
720
+ delivered: number;
721
+ opened: number;
722
+ clicked: number;
723
+ bounced: number;
724
+ complained: number;
725
+ unsubscribed: number;
726
+ /** 0-100 */
727
+ deliveryRate: number;
728
+ /** 0-100 */
729
+ openRate: number;
730
+ /** 0-100 */
731
+ clickRate: number;
732
+ /** 0-100 */
733
+ bounceRate: number;
734
+ /** 0-100 */
735
+ complaintRate: number;
736
+ /** 0-100 */
737
+ unsubscribeRate: number;
738
+ }
739
+ interface EmailMetricsTimePoint {
740
+ date: string;
741
+ sent: number;
742
+ delivered: number;
743
+ opened: number;
744
+ clicked: number;
745
+ bounced: number;
746
+ complained: number;
747
+ }
748
+ interface EmailMetricsCountry {
749
+ country: string;
750
+ count: number;
751
+ }
752
+ /**
753
+ * Aggregate performance for one generated email across every API send of it,
754
+ * plus a daily time series and country breakdown.
755
+ *
756
+ * Sourced from the email tracking worker, so values may be slightly stale and
757
+ * cover roughly the last 30 days of raw send history (aggregates persist
758
+ * longer). Opens are directional — Apple Mail Privacy Protection and bots
759
+ * inflate them; clicks and delivery events are stronger signals.
760
+ */
761
+ interface EmailMetrics {
762
+ summary: EmailMetricsSummary;
763
+ timeSeries: EmailMetricsTimePoint[];
764
+ countryBreakdown: EmailMetricsCountry[];
765
+ /** ISO 8601 timestamp of when these stats were last refreshed. */
766
+ lastUpdated: string;
767
+ cached: boolean;
768
+ }
769
+ /**
770
+ * A single per-recipient send row for one generated email. Returned directly
771
+ * from the tracking worker's D1 table, so field names are snake_case.
772
+ */
773
+ interface EmailSendLog {
774
+ id: number;
775
+ tracking_id: string;
776
+ domain: string;
777
+ from_email: string;
778
+ to_email: string;
779
+ subject: string | null;
780
+ /** Delivery status, e.g. 'sent', 'delivered', 'bounced', 'suppressed'. */
781
+ status: string;
782
+ opened_at: string | null;
783
+ clicked_at: string | null;
784
+ open_count: number;
785
+ click_count: number;
786
+ bounce_type: string | null;
787
+ complaint_type: string | null;
788
+ created_at: string;
789
+ }
790
+ interface EmailLogsParams {
791
+ limit?: number;
792
+ cursor?: string;
793
+ status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'suppressed' | 'sent';
794
+ }
795
+ interface EmailLogsResponse {
796
+ emails: EmailSendLog[];
797
+ nextCursor: string | null;
798
+ hasMore: boolean;
799
+ }
710
800
 
711
801
  declare class Emails {
712
802
  private readonly client;
@@ -728,6 +818,15 @@ declare class Emails {
728
818
  generateAndWait(params: GenerateEmailParams, options?: PollingOptions, callOptions?: CallOptions): Promise<MigmaResult<EmailGenerationStatus>>;
729
819
  /** Send a test email from a completed conversation */
730
820
  sendTest(params: SendTestEmailParams): Promise<MigmaResult<SendTestEmailResponse>>;
821
+ /**
822
+ * Aggregate performance for one generated email across every API send of it:
823
+ * delivery, opens, clicks, bounces, complaints, unsubscribes + a daily time
824
+ * series. Events arrive asynchronously; opens are directional while clicks
825
+ * and delivery events are stronger signals.
826
+ */
827
+ metrics(emailId: string): Promise<MigmaResult<EmailMetrics>>;
828
+ /** Per-recipient send log for one generated email (cursor-paginated). */
829
+ logs(emailId: string, params?: EmailLogsParams): Promise<MigmaResult<EmailLogsResponse>>;
731
830
  }
732
831
 
733
832
  interface CheckCompatibilityParams {
@@ -989,8 +1088,8 @@ declare class Export {
989
1088
  getFormats(): Promise<MigmaResult<ExportFormatsResponse>>;
990
1089
  getStatus(conversationId: string): Promise<MigmaResult<ExportStatusResponse>>;
991
1090
  html(conversationId: string): Promise<MigmaResult<ExportResult>>;
992
- mjml(conversationId: string): Promise<MigmaResult<ExportResult>>;
993
1091
  pdf(conversationId: string): Promise<MigmaResult<ExportResult>>;
1092
+ png(conversationId: string): Promise<MigmaResult<ExportResult>>;
994
1093
  klaviyo(conversationId: string, klaviyoType?: 'html' | 'hybrid' | 'code'): Promise<MigmaResult<ExportResult>>;
995
1094
  mailchimp(conversationId: string): Promise<MigmaResult<ExportResult>>;
996
1095
  hubspot(params: HubspotExportParams): Promise<MigmaResult<ExportResult>>;
@@ -1005,6 +1104,7 @@ interface DnsRecord {
1005
1104
  }
1006
1105
  interface Domain {
1007
1106
  domain: string;
1107
+ /** AWS region the domain sends from. Automatically assigned at creation. */
1008
1108
  region: string;
1009
1109
  status: string;
1010
1110
  isVerified?: boolean;
@@ -1020,7 +1120,6 @@ interface Domain {
1020
1120
  }
1021
1121
  interface CreateDomainParams {
1022
1122
  domain: string;
1023
- region?: 'us-east-1' | 'eu-west-1';
1024
1123
  }
1025
1124
  interface UpdateDomainParams {
1026
1125
  openTracking?: boolean;
@@ -1039,7 +1138,6 @@ interface DomainAvailability {
1039
1138
  }
1040
1139
  interface CreateManagedDomainParams {
1041
1140
  prefix: string;
1042
- region?: string;
1043
1141
  }
1044
1142
  type DomainStream = 'transactional' | 'marketing';
1045
1143
  interface ProvisionStreamParams {
@@ -1047,14 +1145,12 @@ interface ProvisionStreamParams {
1047
1145
  rootDomain: string;
1048
1146
  /** 'transactional' provisions notify.<rootDomain>; 'marketing' provisions send.<rootDomain>. */
1049
1147
  stream: DomainStream;
1050
- region?: 'us-east-1' | 'eu-west-1';
1051
1148
  /** Show the apex domain in the From header when its DMARC passes. */
1052
1149
  vanityRootFrom?: boolean;
1053
1150
  }
1054
1151
  interface SetupDomainParams {
1055
1152
  /** Apex domain you own, e.g. 'acme.com'. */
1056
1153
  rootDomain: string;
1057
- region?: 'us-east-1' | 'eu-west-1';
1058
1154
  /** Default From display name applied to both provisioned streams. */
1059
1155
  fromName?: string;
1060
1156
  /** Associate the provisioned streams with a project. */
@@ -1257,7 +1353,7 @@ declare class Images {
1257
1353
  updateLogos(projectId: string, params: UpdateLogosParams): Promise<MigmaResult<LogosResponse>>;
1258
1354
  }
1259
1355
 
1260
- type CampaignStatus = 'draft' | 'scheduled' | 'sending' | 'throttled' | 'ab_testing' | 'sent' | 'failed' | 'cancelled';
1356
+ type CampaignStatus = 'draft' | 'pending_review' | 'scheduled' | 'sending' | 'throttled' | 'ab_testing' | 'sent' | 'failed' | 'cancelled';
1261
1357
  interface Campaign {
1262
1358
  id: string;
1263
1359
  projectId: string;
@@ -1377,7 +1473,7 @@ interface CampaignLog {
1377
1473
  interface CampaignLogsParams {
1378
1474
  limit?: number;
1379
1475
  cursor?: string;
1380
- status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'spam_report';
1476
+ status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained';
1381
1477
  }
1382
1478
  interface CampaignLogsResponse {
1383
1479
  emails: CampaignLog[];
@@ -1402,6 +1498,39 @@ declare class Campaigns {
1402
1498
  unarchive(id: string): Promise<MigmaResult<Campaign>>;
1403
1499
  }
1404
1500
 
1501
+ interface SendingMetricsParams {
1502
+ months?: number;
1503
+ }
1504
+ interface SendingMetricsCounts {
1505
+ sent: number;
1506
+ delivered: number;
1507
+ bounced: number;
1508
+ complained: number;
1509
+ }
1510
+ interface SendingMetricsToday {
1511
+ sent: number;
1512
+ reserved: number;
1513
+ dailyLimit: number;
1514
+ remainingToday: number;
1515
+ }
1516
+ interface SendingMetricsHistoryEntry extends SendingMetricsCounts {
1517
+ period: string;
1518
+ }
1519
+ interface SendingMetrics {
1520
+ period: string;
1521
+ monthly: SendingMetricsCounts;
1522
+ today: SendingMetricsToday;
1523
+ monthlyLimit: number;
1524
+ remainingMonth: number;
1525
+ history?: SendingMetricsHistoryEntry[];
1526
+ }
1527
+
1528
+ declare class Metrics {
1529
+ private readonly client;
1530
+ constructor(client: MigmaClient);
1531
+ sending(params?: SendingMetricsParams): Promise<MigmaResult<SendingMetrics>>;
1532
+ }
1533
+
1405
1534
  interface MigmaConfig {
1406
1535
  /** API base URL. Default: 'https://api.migma.ai/v1' */
1407
1536
  baseUrl?: string;
@@ -1427,7 +1556,8 @@ declare class Migma {
1427
1556
  readonly knowledgeBase: KnowledgeBase;
1428
1557
  readonly images: Images;
1429
1558
  readonly campaigns: Campaigns;
1559
+ readonly metrics: Metrics;
1430
1560
  constructor(apiKey: string, config?: MigmaConfig);
1431
1561
  }
1432
1562
 
1433
- export { type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BulkImportAsyncResponse, type BulkImportContactItem, type BulkImportJobStatus, type BulkImportParams, type BulkImportResponse, type BulkImportSyncResponse, type Campaign, type CampaignLog, type CampaignLogsParams, type CampaignLogsResponse, type CampaignStats, type CampaignStatus, type ChangeStatusParams, type CheckCompatibilityParams, type CheckSpellingParams, type CheckedLink, type ClientConfig, type CompatibilityResponse, type Contact, type ContactStatus, type CreateCampaignParams, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type CreateWebhookResponse, type DeleteResponse, type DeliverabilityResponse, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailGenerationResult, type EmailGenerationStatus, type EmailImage, type ExportFile, type ExportFormat, type ExportFormatsResponse, type ExportResult, type ExportStatusResponse, type FieldCatalogEntry, type FieldCatalogEntryType, type FieldCatalogParams, type FieldCatalogResponse, type GenerateEmailParams, type GenerateEmailResponse, type GeneratedEmail, type GetDevicePreviewResponse, type GetPreviewResponse, type GetPreviewStatusResponse, type GetSupportedDevicesResponse, type HubspotExportParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListCampaignsParams, type ListCampaignsResponse, type ListContactsParams, type ListContactsResponse, type ListEmailsEmail, type ListEmailsParams, type ListEmailsResponse, type ListProjectsParams, type ListProjectsResponse, type ListSegmentsResponse, type ListTagsParams, type ListTagsResponse, type ListTopicsParams, type ListTopicsResponse, type ListWebhooksResponse, type LogosResponse, type MessageResponse, Migma, MigmaClient, type MigmaConfig, MigmaError, MigmaErrorCode, type MigmaResult, type PollingOptions, type PreviewDevice, type PreviewDeviceCategory, type PreviewDeviceStatus, type PreviewMetadata, type PreviewStatus, type Project, type ProjectImage, type ProviderType, type ProvisionStreamParams, type RecipientType, type RetryImportResponse, type ScheduleCampaignParams, type Segment, type SegmentActivityFilter, type SegmentFieldFilter, type SegmentFilters, type SendEmailParams, type SendEmailResponse, type SendTestEmailParams, type SendTestEmailResponse, type SetupDomainParams, type SetupDomainResponse, type SpellingResponse, type SupportedDevice, type Tag, type Topic, type TopicSubscriptionParams, type TopicSubscriptionResponse, type UpdateContactParams, type UpdateDomainParams, type UpdateImageParams, type UpdateKnowledgeBaseParams, type UpdateLogosParams, type UpdateSegmentParams, type UpdateTagParams, type UpdateTopicParams, type UpdateWebhookParams, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, poll };
1563
+ export { type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BulkImportAsyncResponse, type BulkImportContactItem, type BulkImportJobStatus, type BulkImportParams, type BulkImportResponse, type BulkImportSyncResponse, type Campaign, type CampaignLog, type CampaignLogsParams, type CampaignLogsResponse, type CampaignStats, type CampaignStatus, type ChangeStatusParams, type CheckCompatibilityParams, type CheckSpellingParams, type CheckedLink, type ClientConfig, type CompatibilityResponse, type Contact, type ContactStatus, type CreateCampaignParams, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type CreateWebhookResponse, type DeleteResponse, type DeliverabilityResponse, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailGenerationResult, type EmailGenerationStatus, type EmailImage, type EmailLogsParams, type EmailLogsResponse, type EmailMetrics, type EmailMetricsCountry, type EmailMetricsSummary, type EmailMetricsTimePoint, type EmailSendLog, type ExportFile, type ExportFormat, type ExportFormatsResponse, type ExportResult, type ExportStatusResponse, type FieldCatalogEntry, type FieldCatalogEntryType, type FieldCatalogParams, type FieldCatalogResponse, type GenerateEmailParams, type GenerateEmailResponse, type GeneratedEmail, type GetDevicePreviewResponse, type GetPreviewResponse, type GetPreviewStatusResponse, type GetSupportedDevicesResponse, type HubspotExportParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListCampaignsParams, type ListCampaignsResponse, type ListContactsParams, type ListContactsResponse, type ListEmailsEmail, type ListEmailsParams, type ListEmailsResponse, type ListProjectsParams, type ListProjectsResponse, type ListSegmentsResponse, type ListTagsParams, type ListTagsResponse, type ListTopicsParams, type ListTopicsResponse, type ListWebhooksResponse, type LogosResponse, type MessageResponse, Migma, MigmaClient, type MigmaConfig, MigmaError, MigmaErrorCode, type MigmaResult, type PollingOptions, type PreviewDevice, type PreviewDeviceCategory, type PreviewDeviceStatus, type PreviewMetadata, type PreviewStatus, type Project, type ProjectImage, type ProviderType, type ProvisionStreamParams, type RecipientType, type RetryImportResponse, type ScheduleCampaignParams, type Segment, type SegmentActivityFilter, type SegmentFieldFilter, type SegmentFilters, type SendEmailParams, type SendEmailResponse, type SendTestEmailParams, type SendTestEmailResponse, type SendingMetrics, type SendingMetricsCounts, type SendingMetricsHistoryEntry, type SendingMetricsParams, type SendingMetricsToday, type SetupDomainParams, type SetupDomainResponse, type SpellingResponse, type SupportedDevice, type Tag, type Topic, type TopicSubscriptionParams, type TopicSubscriptionResponse, type UpdateContactParams, type UpdateDomainParams, type UpdateImageParams, type UpdateKnowledgeBaseParams, type UpdateLogosParams, type UpdateSegmentParams, type UpdateTagParams, type UpdateTopicParams, type UpdateWebhookParams, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, poll };
package/dist/index.d.ts CHANGED
@@ -429,6 +429,14 @@ interface SendEmailResponse {
429
429
  status: string;
430
430
  sentCount?: number;
431
431
  message?: string;
432
+ /** Real tracking id for a single send — use with emails.metrics()/logs() and the activity view. Absent for batch sends. */
433
+ sendId?: string;
434
+ /** Batch id for an audience/tag send. Absent for single sends. */
435
+ batchId?: string;
436
+ /** Echoes the generated email id this send was tagged with, when provided. */
437
+ emailId?: string;
438
+ /** Conversation this send belongs to, when known. */
439
+ conversationId?: string;
432
440
  }
433
441
  interface BatchStatus {
434
442
  batchId: string;
@@ -707,6 +715,88 @@ interface EditEmailParams {
707
715
  prompt: string;
708
716
  label?: string;
709
717
  }
718
+ interface EmailMetricsSummary {
719
+ totalEmails: number;
720
+ delivered: number;
721
+ opened: number;
722
+ clicked: number;
723
+ bounced: number;
724
+ complained: number;
725
+ unsubscribed: number;
726
+ /** 0-100 */
727
+ deliveryRate: number;
728
+ /** 0-100 */
729
+ openRate: number;
730
+ /** 0-100 */
731
+ clickRate: number;
732
+ /** 0-100 */
733
+ bounceRate: number;
734
+ /** 0-100 */
735
+ complaintRate: number;
736
+ /** 0-100 */
737
+ unsubscribeRate: number;
738
+ }
739
+ interface EmailMetricsTimePoint {
740
+ date: string;
741
+ sent: number;
742
+ delivered: number;
743
+ opened: number;
744
+ clicked: number;
745
+ bounced: number;
746
+ complained: number;
747
+ }
748
+ interface EmailMetricsCountry {
749
+ country: string;
750
+ count: number;
751
+ }
752
+ /**
753
+ * Aggregate performance for one generated email across every API send of it,
754
+ * plus a daily time series and country breakdown.
755
+ *
756
+ * Sourced from the email tracking worker, so values may be slightly stale and
757
+ * cover roughly the last 30 days of raw send history (aggregates persist
758
+ * longer). Opens are directional — Apple Mail Privacy Protection and bots
759
+ * inflate them; clicks and delivery events are stronger signals.
760
+ */
761
+ interface EmailMetrics {
762
+ summary: EmailMetricsSummary;
763
+ timeSeries: EmailMetricsTimePoint[];
764
+ countryBreakdown: EmailMetricsCountry[];
765
+ /** ISO 8601 timestamp of when these stats were last refreshed. */
766
+ lastUpdated: string;
767
+ cached: boolean;
768
+ }
769
+ /**
770
+ * A single per-recipient send row for one generated email. Returned directly
771
+ * from the tracking worker's D1 table, so field names are snake_case.
772
+ */
773
+ interface EmailSendLog {
774
+ id: number;
775
+ tracking_id: string;
776
+ domain: string;
777
+ from_email: string;
778
+ to_email: string;
779
+ subject: string | null;
780
+ /** Delivery status, e.g. 'sent', 'delivered', 'bounced', 'suppressed'. */
781
+ status: string;
782
+ opened_at: string | null;
783
+ clicked_at: string | null;
784
+ open_count: number;
785
+ click_count: number;
786
+ bounce_type: string | null;
787
+ complaint_type: string | null;
788
+ created_at: string;
789
+ }
790
+ interface EmailLogsParams {
791
+ limit?: number;
792
+ cursor?: string;
793
+ status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'suppressed' | 'sent';
794
+ }
795
+ interface EmailLogsResponse {
796
+ emails: EmailSendLog[];
797
+ nextCursor: string | null;
798
+ hasMore: boolean;
799
+ }
710
800
 
711
801
  declare class Emails {
712
802
  private readonly client;
@@ -728,6 +818,15 @@ declare class Emails {
728
818
  generateAndWait(params: GenerateEmailParams, options?: PollingOptions, callOptions?: CallOptions): Promise<MigmaResult<EmailGenerationStatus>>;
729
819
  /** Send a test email from a completed conversation */
730
820
  sendTest(params: SendTestEmailParams): Promise<MigmaResult<SendTestEmailResponse>>;
821
+ /**
822
+ * Aggregate performance for one generated email across every API send of it:
823
+ * delivery, opens, clicks, bounces, complaints, unsubscribes + a daily time
824
+ * series. Events arrive asynchronously; opens are directional while clicks
825
+ * and delivery events are stronger signals.
826
+ */
827
+ metrics(emailId: string): Promise<MigmaResult<EmailMetrics>>;
828
+ /** Per-recipient send log for one generated email (cursor-paginated). */
829
+ logs(emailId: string, params?: EmailLogsParams): Promise<MigmaResult<EmailLogsResponse>>;
731
830
  }
732
831
 
733
832
  interface CheckCompatibilityParams {
@@ -989,8 +1088,8 @@ declare class Export {
989
1088
  getFormats(): Promise<MigmaResult<ExportFormatsResponse>>;
990
1089
  getStatus(conversationId: string): Promise<MigmaResult<ExportStatusResponse>>;
991
1090
  html(conversationId: string): Promise<MigmaResult<ExportResult>>;
992
- mjml(conversationId: string): Promise<MigmaResult<ExportResult>>;
993
1091
  pdf(conversationId: string): Promise<MigmaResult<ExportResult>>;
1092
+ png(conversationId: string): Promise<MigmaResult<ExportResult>>;
994
1093
  klaviyo(conversationId: string, klaviyoType?: 'html' | 'hybrid' | 'code'): Promise<MigmaResult<ExportResult>>;
995
1094
  mailchimp(conversationId: string): Promise<MigmaResult<ExportResult>>;
996
1095
  hubspot(params: HubspotExportParams): Promise<MigmaResult<ExportResult>>;
@@ -1005,6 +1104,7 @@ interface DnsRecord {
1005
1104
  }
1006
1105
  interface Domain {
1007
1106
  domain: string;
1107
+ /** AWS region the domain sends from. Automatically assigned at creation. */
1008
1108
  region: string;
1009
1109
  status: string;
1010
1110
  isVerified?: boolean;
@@ -1020,7 +1120,6 @@ interface Domain {
1020
1120
  }
1021
1121
  interface CreateDomainParams {
1022
1122
  domain: string;
1023
- region?: 'us-east-1' | 'eu-west-1';
1024
1123
  }
1025
1124
  interface UpdateDomainParams {
1026
1125
  openTracking?: boolean;
@@ -1039,7 +1138,6 @@ interface DomainAvailability {
1039
1138
  }
1040
1139
  interface CreateManagedDomainParams {
1041
1140
  prefix: string;
1042
- region?: string;
1043
1141
  }
1044
1142
  type DomainStream = 'transactional' | 'marketing';
1045
1143
  interface ProvisionStreamParams {
@@ -1047,14 +1145,12 @@ interface ProvisionStreamParams {
1047
1145
  rootDomain: string;
1048
1146
  /** 'transactional' provisions notify.<rootDomain>; 'marketing' provisions send.<rootDomain>. */
1049
1147
  stream: DomainStream;
1050
- region?: 'us-east-1' | 'eu-west-1';
1051
1148
  /** Show the apex domain in the From header when its DMARC passes. */
1052
1149
  vanityRootFrom?: boolean;
1053
1150
  }
1054
1151
  interface SetupDomainParams {
1055
1152
  /** Apex domain you own, e.g. 'acme.com'. */
1056
1153
  rootDomain: string;
1057
- region?: 'us-east-1' | 'eu-west-1';
1058
1154
  /** Default From display name applied to both provisioned streams. */
1059
1155
  fromName?: string;
1060
1156
  /** Associate the provisioned streams with a project. */
@@ -1257,7 +1353,7 @@ declare class Images {
1257
1353
  updateLogos(projectId: string, params: UpdateLogosParams): Promise<MigmaResult<LogosResponse>>;
1258
1354
  }
1259
1355
 
1260
- type CampaignStatus = 'draft' | 'scheduled' | 'sending' | 'throttled' | 'ab_testing' | 'sent' | 'failed' | 'cancelled';
1356
+ type CampaignStatus = 'draft' | 'pending_review' | 'scheduled' | 'sending' | 'throttled' | 'ab_testing' | 'sent' | 'failed' | 'cancelled';
1261
1357
  interface Campaign {
1262
1358
  id: string;
1263
1359
  projectId: string;
@@ -1377,7 +1473,7 @@ interface CampaignLog {
1377
1473
  interface CampaignLogsParams {
1378
1474
  limit?: number;
1379
1475
  cursor?: string;
1380
- status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'spam_report';
1476
+ status?: 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained';
1381
1477
  }
1382
1478
  interface CampaignLogsResponse {
1383
1479
  emails: CampaignLog[];
@@ -1402,6 +1498,39 @@ declare class Campaigns {
1402
1498
  unarchive(id: string): Promise<MigmaResult<Campaign>>;
1403
1499
  }
1404
1500
 
1501
+ interface SendingMetricsParams {
1502
+ months?: number;
1503
+ }
1504
+ interface SendingMetricsCounts {
1505
+ sent: number;
1506
+ delivered: number;
1507
+ bounced: number;
1508
+ complained: number;
1509
+ }
1510
+ interface SendingMetricsToday {
1511
+ sent: number;
1512
+ reserved: number;
1513
+ dailyLimit: number;
1514
+ remainingToday: number;
1515
+ }
1516
+ interface SendingMetricsHistoryEntry extends SendingMetricsCounts {
1517
+ period: string;
1518
+ }
1519
+ interface SendingMetrics {
1520
+ period: string;
1521
+ monthly: SendingMetricsCounts;
1522
+ today: SendingMetricsToday;
1523
+ monthlyLimit: number;
1524
+ remainingMonth: number;
1525
+ history?: SendingMetricsHistoryEntry[];
1526
+ }
1527
+
1528
+ declare class Metrics {
1529
+ private readonly client;
1530
+ constructor(client: MigmaClient);
1531
+ sending(params?: SendingMetricsParams): Promise<MigmaResult<SendingMetrics>>;
1532
+ }
1533
+
1405
1534
  interface MigmaConfig {
1406
1535
  /** API base URL. Default: 'https://api.migma.ai/v1' */
1407
1536
  baseUrl?: string;
@@ -1427,7 +1556,8 @@ declare class Migma {
1427
1556
  readonly knowledgeBase: KnowledgeBase;
1428
1557
  readonly images: Images;
1429
1558
  readonly campaigns: Campaigns;
1559
+ readonly metrics: Metrics;
1430
1560
  constructor(apiKey: string, config?: MigmaConfig);
1431
1561
  }
1432
1562
 
1433
- export { type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BulkImportAsyncResponse, type BulkImportContactItem, type BulkImportJobStatus, type BulkImportParams, type BulkImportResponse, type BulkImportSyncResponse, type Campaign, type CampaignLog, type CampaignLogsParams, type CampaignLogsResponse, type CampaignStats, type CampaignStatus, type ChangeStatusParams, type CheckCompatibilityParams, type CheckSpellingParams, type CheckedLink, type ClientConfig, type CompatibilityResponse, type Contact, type ContactStatus, type CreateCampaignParams, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type CreateWebhookResponse, type DeleteResponse, type DeliverabilityResponse, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailGenerationResult, type EmailGenerationStatus, type EmailImage, type ExportFile, type ExportFormat, type ExportFormatsResponse, type ExportResult, type ExportStatusResponse, type FieldCatalogEntry, type FieldCatalogEntryType, type FieldCatalogParams, type FieldCatalogResponse, type GenerateEmailParams, type GenerateEmailResponse, type GeneratedEmail, type GetDevicePreviewResponse, type GetPreviewResponse, type GetPreviewStatusResponse, type GetSupportedDevicesResponse, type HubspotExportParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListCampaignsParams, type ListCampaignsResponse, type ListContactsParams, type ListContactsResponse, type ListEmailsEmail, type ListEmailsParams, type ListEmailsResponse, type ListProjectsParams, type ListProjectsResponse, type ListSegmentsResponse, type ListTagsParams, type ListTagsResponse, type ListTopicsParams, type ListTopicsResponse, type ListWebhooksResponse, type LogosResponse, type MessageResponse, Migma, MigmaClient, type MigmaConfig, MigmaError, MigmaErrorCode, type MigmaResult, type PollingOptions, type PreviewDevice, type PreviewDeviceCategory, type PreviewDeviceStatus, type PreviewMetadata, type PreviewStatus, type Project, type ProjectImage, type ProviderType, type ProvisionStreamParams, type RecipientType, type RetryImportResponse, type ScheduleCampaignParams, type Segment, type SegmentActivityFilter, type SegmentFieldFilter, type SegmentFilters, type SendEmailParams, type SendEmailResponse, type SendTestEmailParams, type SendTestEmailResponse, type SetupDomainParams, type SetupDomainResponse, type SpellingResponse, type SupportedDevice, type Tag, type Topic, type TopicSubscriptionParams, type TopicSubscriptionResponse, type UpdateContactParams, type UpdateDomainParams, type UpdateImageParams, type UpdateKnowledgeBaseParams, type UpdateLogosParams, type UpdateSegmentParams, type UpdateTagParams, type UpdateTopicParams, type UpdateWebhookParams, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, poll };
1563
+ export { type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BulkImportAsyncResponse, type BulkImportContactItem, type BulkImportJobStatus, type BulkImportParams, type BulkImportResponse, type BulkImportSyncResponse, type Campaign, type CampaignLog, type CampaignLogsParams, type CampaignLogsResponse, type CampaignStats, type CampaignStatus, type ChangeStatusParams, type CheckCompatibilityParams, type CheckSpellingParams, type CheckedLink, type ClientConfig, type CompatibilityResponse, type Contact, type ContactStatus, type CreateCampaignParams, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type CreateWebhookResponse, type DeleteResponse, type DeliverabilityResponse, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailGenerationResult, type EmailGenerationStatus, type EmailImage, type EmailLogsParams, type EmailLogsResponse, type EmailMetrics, type EmailMetricsCountry, type EmailMetricsSummary, type EmailMetricsTimePoint, type EmailSendLog, type ExportFile, type ExportFormat, type ExportFormatsResponse, type ExportResult, type ExportStatusResponse, type FieldCatalogEntry, type FieldCatalogEntryType, type FieldCatalogParams, type FieldCatalogResponse, type GenerateEmailParams, type GenerateEmailResponse, type GeneratedEmail, type GetDevicePreviewResponse, type GetPreviewResponse, type GetPreviewStatusResponse, type GetSupportedDevicesResponse, type HubspotExportParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListCampaignsParams, type ListCampaignsResponse, type ListContactsParams, type ListContactsResponse, type ListEmailsEmail, type ListEmailsParams, type ListEmailsResponse, type ListProjectsParams, type ListProjectsResponse, type ListSegmentsResponse, type ListTagsParams, type ListTagsResponse, type ListTopicsParams, type ListTopicsResponse, type ListWebhooksResponse, type LogosResponse, type MessageResponse, Migma, MigmaClient, type MigmaConfig, MigmaError, MigmaErrorCode, type MigmaResult, type PollingOptions, type PreviewDevice, type PreviewDeviceCategory, type PreviewDeviceStatus, type PreviewMetadata, type PreviewStatus, type Project, type ProjectImage, type ProviderType, type ProvisionStreamParams, type RecipientType, type RetryImportResponse, type ScheduleCampaignParams, type Segment, type SegmentActivityFilter, type SegmentFieldFilter, type SegmentFilters, type SendEmailParams, type SendEmailResponse, type SendTestEmailParams, type SendTestEmailResponse, type SendingMetrics, type SendingMetricsCounts, type SendingMetricsHistoryEntry, type SendingMetricsParams, type SendingMetricsToday, type SetupDomainParams, type SetupDomainResponse, type SpellingResponse, type SupportedDevice, type Tag, type Topic, type TopicSubscriptionParams, type TopicSubscriptionResponse, type UpdateContactParams, type UpdateDomainParams, type UpdateImageParams, type UpdateKnowledgeBaseParams, type UpdateLogosParams, type UpdateSegmentParams, type UpdateTagParams, type UpdateTopicParams, type UpdateWebhookParams, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, poll };
package/dist/index.js CHANGED
@@ -524,6 +524,23 @@ var Emails = class {
524
524
  params
525
525
  );
526
526
  }
527
+ /**
528
+ * Aggregate performance for one generated email across every API send of it:
529
+ * delivery, opens, clicks, bounces, complaints, unsubscribes + a daily time
530
+ * series. Events arrive asynchronously; opens are directional while clicks
531
+ * and delivery events are stronger signals.
532
+ */
533
+ async metrics(emailId) {
534
+ return this.client.get(`/emails/${emailId}/metrics`);
535
+ }
536
+ /** Per-recipient send log for one generated email (cursor-paginated). */
537
+ async logs(emailId, params) {
538
+ return this.client.get(`/emails/${emailId}/logs`, {
539
+ limit: params?.limit,
540
+ cursor: params?.cursor,
541
+ status: params?.status
542
+ });
543
+ }
527
544
  };
528
545
 
529
546
  // src/resources/validation.ts
@@ -626,12 +643,12 @@ var Export = class {
626
643
  async html(conversationId) {
627
644
  return this.client.get(`/export/html/${conversationId}`);
628
645
  }
629
- async mjml(conversationId) {
630
- return this.client.get(`/export/mjml/${conversationId}`);
631
- }
632
646
  async pdf(conversationId) {
633
647
  return this.client.get(`/export/pdf/${conversationId}`);
634
648
  }
649
+ async png(conversationId) {
650
+ return this.client.get(`/export/png/${conversationId}`);
651
+ }
635
652
  async klaviyo(conversationId, klaviyoType) {
636
653
  return this.client.get(
637
654
  `/export/klaviyo/${conversationId}`,
@@ -852,6 +869,18 @@ var Campaigns = class {
852
869
  }
853
870
  };
854
871
 
872
+ // src/resources/metrics.ts
873
+ var Metrics = class {
874
+ constructor(client) {
875
+ this.client = client;
876
+ }
877
+ async sending(params) {
878
+ return this.client.get("/metrics/sending", {
879
+ months: params?.months
880
+ });
881
+ }
882
+ };
883
+
855
884
  // src/migma.ts
856
885
  var Migma = class {
857
886
  client;
@@ -870,6 +899,7 @@ var Migma = class {
870
899
  knowledgeBase;
871
900
  images;
872
901
  campaigns;
902
+ metrics;
873
903
  constructor(apiKey, config) {
874
904
  if (!apiKey) {
875
905
  throw new Error(
@@ -896,6 +926,7 @@ var Migma = class {
896
926
  this.knowledgeBase = new KnowledgeBase(this.client);
897
927
  this.images = new Images(this.client);
898
928
  this.campaigns = new Campaigns(this.client);
929
+ this.metrics = new Metrics(this.client);
899
930
  }
900
931
  };
901
932