migma 1.0.0

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.
@@ -0,0 +1,1066 @@
1
+ declare enum MigmaErrorCode {
2
+ VALIDATION_ERROR = "validation_error",
3
+ NOT_FOUND = "not_found",
4
+ UNAUTHORIZED = "unauthorized",
5
+ FORBIDDEN = "forbidden",
6
+ RATE_LIMIT_EXCEEDED = "rate_limit_exceeded",
7
+ CONFLICT = "conflict",
8
+ TIMEOUT = "timeout",
9
+ NETWORK_ERROR = "network_error",
10
+ INTERNAL_ERROR = "internal_error",
11
+ UNKNOWN = "unknown"
12
+ }
13
+ declare class MigmaError extends Error {
14
+ readonly statusCode: number;
15
+ readonly code: MigmaErrorCode;
16
+ constructor(message: string, statusCode: number, code?: MigmaErrorCode);
17
+ private static codeFromStatus;
18
+ toJSON(): {
19
+ name: string;
20
+ message: string;
21
+ statusCode: number;
22
+ code: MigmaErrorCode;
23
+ };
24
+ }
25
+
26
+ /** Result type returned by all SDK methods — never throws */
27
+ type MigmaResult<T> = {
28
+ data: T;
29
+ error: null;
30
+ } | {
31
+ data: null;
32
+ error: MigmaError;
33
+ };
34
+ /** Raw API response envelope from the Migma backend */
35
+ interface ApiResponse<T> {
36
+ success: boolean;
37
+ data?: T;
38
+ error?: string;
39
+ count?: number;
40
+ message?: string;
41
+ }
42
+ /** Delete response */
43
+ interface DeleteResponse {
44
+ id: string;
45
+ deleted: boolean;
46
+ }
47
+ /** Generic message response */
48
+ interface MessageResponse {
49
+ message: string;
50
+ }
51
+
52
+ interface ClientConfig {
53
+ baseUrl: string;
54
+ timeout: number;
55
+ maxRetries: number;
56
+ retryDelay: number;
57
+ }
58
+ type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
59
+ interface RequestOptions {
60
+ method: HttpMethod;
61
+ path: string;
62
+ body?: Record<string, unknown>;
63
+ query?: Record<string, string | number | boolean | undefined>;
64
+ timeout?: number;
65
+ }
66
+ declare class MigmaClient {
67
+ private readonly apiKey;
68
+ private readonly config;
69
+ constructor(apiKey: string, config: ClientConfig);
70
+ request<T>(options: RequestOptions): Promise<MigmaResult<T>>;
71
+ /**
72
+ * For endpoints where the API returns `{ success, data, count }` and we want
73
+ * both the data array and the count together.
74
+ */
75
+ requestWithCount<T>(options: RequestOptions): Promise<MigmaResult<{
76
+ data: T;
77
+ count: number;
78
+ }>>;
79
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<MigmaResult<T>>;
80
+ getWithCount<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<MigmaResult<{
81
+ data: T;
82
+ count: number;
83
+ }>>;
84
+ post<T>(path: string, body?: Record<string, unknown>): Promise<MigmaResult<T>>;
85
+ patch<T>(path: string, body?: Record<string, unknown>): Promise<MigmaResult<T>>;
86
+ put<T>(path: string, body?: Record<string, unknown>): Promise<MigmaResult<T>>;
87
+ delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<MigmaResult<T>>;
88
+ private buildUrl;
89
+ private parseRetryAfter;
90
+ private sleep;
91
+ }
92
+
93
+ type ContactStatus = 'active' | 'unsubscribed' | 'bounced' | 'complained';
94
+ interface Contact {
95
+ id: string;
96
+ email: string;
97
+ firstName?: string;
98
+ lastName?: string;
99
+ country?: string;
100
+ language?: string;
101
+ tags: string[];
102
+ customFields?: Record<string, unknown>;
103
+ status: ContactStatus;
104
+ unsubscribedAt?: string;
105
+ createdAt: string;
106
+ updatedAt: string;
107
+ }
108
+ interface CreateContactParams {
109
+ email: string;
110
+ firstName?: string;
111
+ lastName?: string;
112
+ /** ISO 3166-1 alpha-2 country code (e.g., US, CA, GB) */
113
+ country?: string;
114
+ /** Language code in ISO 639-1 or BCP 47 format (e.g., en, en-US) */
115
+ language?: string;
116
+ tags?: string[];
117
+ customFields?: Record<string, unknown>;
118
+ projectId: string;
119
+ }
120
+ interface UpdateContactParams {
121
+ firstName?: string;
122
+ lastName?: string;
123
+ country?: string;
124
+ language?: string;
125
+ tags?: string[];
126
+ customFields?: Record<string, unknown>;
127
+ status?: 'subscribed' | 'unsubscribed' | 'bounced' | 'non-subscribed';
128
+ projectId: string;
129
+ }
130
+ interface ListContactsParams {
131
+ projectId: string;
132
+ page?: number;
133
+ limit?: number;
134
+ tags?: string;
135
+ status?: ContactStatus;
136
+ search?: string;
137
+ }
138
+ interface ListContactsResponse {
139
+ data: Contact[];
140
+ count: number;
141
+ }
142
+ interface BulkImportContactItem {
143
+ email: string;
144
+ firstName?: string;
145
+ lastName?: string;
146
+ country?: string;
147
+ language?: string;
148
+ tags?: string[];
149
+ customFields?: Record<string, unknown>;
150
+ }
151
+ interface BulkImportParams {
152
+ subscribers: BulkImportContactItem[];
153
+ projectId: string;
154
+ }
155
+ interface BulkImportSyncResponse {
156
+ success: number;
157
+ failed: number;
158
+ updated: number;
159
+ errors?: string[];
160
+ }
161
+ interface BulkImportAsyncResponse {
162
+ jobId: string;
163
+ status: 'processing';
164
+ totalContacts: number;
165
+ message: string;
166
+ }
167
+ type BulkImportResponse = BulkImportSyncResponse | BulkImportAsyncResponse;
168
+ interface BulkImportJobStatus {
169
+ jobId: string;
170
+ status: 'pending' | 'processing' | 'completed' | 'failed';
171
+ totalContacts: number;
172
+ processed: number;
173
+ result: BulkImportSyncResponse | null;
174
+ error: string | null;
175
+ createdAt: string;
176
+ completedAt: string | null;
177
+ }
178
+ interface ChangeStatusParams {
179
+ email: string;
180
+ status: 'subscribed' | 'unsubscribed' | 'bounced' | 'non-subscribed';
181
+ allLists?: boolean;
182
+ tags?: string[];
183
+ projectId: string;
184
+ }
185
+
186
+ declare class Contacts {
187
+ private readonly client;
188
+ constructor(client: MigmaClient);
189
+ create(params: CreateContactParams): Promise<MigmaResult<Contact>>;
190
+ list(params: ListContactsParams): Promise<MigmaResult<ListContactsResponse>>;
191
+ get(id: string, projectId: string): Promise<MigmaResult<Contact>>;
192
+ update(id: string, params: UpdateContactParams): Promise<MigmaResult<Contact>>;
193
+ remove(id: string, projectId: string): Promise<MigmaResult<DeleteResponse>>;
194
+ bulkImport(params: BulkImportParams): Promise<MigmaResult<BulkImportResponse>>;
195
+ getBulkImportStatus(jobId: string): Promise<MigmaResult<BulkImportJobStatus>>;
196
+ changeStatus(params: ChangeStatusParams): Promise<MigmaResult<{
197
+ success: boolean;
198
+ }>>;
199
+ }
200
+
201
+ interface Tag {
202
+ id: string;
203
+ name: string;
204
+ color: string;
205
+ description: string;
206
+ subscriberCount: number;
207
+ createdAt: string;
208
+ updatedAt: string;
209
+ }
210
+ interface CreateTagParams {
211
+ name: string;
212
+ /** Hex color e.g. #FF5733 */
213
+ color?: string;
214
+ description?: string;
215
+ projectId: string;
216
+ }
217
+ interface UpdateTagParams {
218
+ name?: string;
219
+ color?: string;
220
+ description?: string;
221
+ projectId: string;
222
+ }
223
+ interface ListTagsParams {
224
+ projectId: string;
225
+ page?: number;
226
+ limit?: number;
227
+ search?: string;
228
+ sortBy?: 'createdAt' | 'name';
229
+ sortOrder?: 'asc' | 'desc';
230
+ }
231
+ interface ListTagsResponse {
232
+ data: Tag[];
233
+ count: number;
234
+ }
235
+
236
+ declare class Tags {
237
+ private readonly client;
238
+ constructor(client: MigmaClient);
239
+ list(params: ListTagsParams): Promise<MigmaResult<ListTagsResponse>>;
240
+ create(params: CreateTagParams): Promise<MigmaResult<Tag>>;
241
+ get(id: string, projectId: string): Promise<MigmaResult<Tag>>;
242
+ update(id: string, params: UpdateTagParams): Promise<MigmaResult<Tag>>;
243
+ remove(id: string, projectId: string): Promise<MigmaResult<DeleteResponse>>;
244
+ }
245
+
246
+ interface SegmentFilters {
247
+ tags?: string[];
248
+ status?: 'subscribed' | 'unsubscribed' | 'non-subscribed' | 'bounced';
249
+ customFields?: Record<string, string[]>;
250
+ }
251
+ interface Segment {
252
+ id: string;
253
+ name: string;
254
+ description: string;
255
+ filters: SegmentFilters;
256
+ count: number;
257
+ createdAt: string;
258
+ updatedAt: string;
259
+ }
260
+ interface CreateSegmentParams {
261
+ name: string;
262
+ description?: string;
263
+ filters?: SegmentFilters;
264
+ projectId: string;
265
+ }
266
+ interface UpdateSegmentParams {
267
+ name?: string;
268
+ description?: string;
269
+ filters?: SegmentFilters;
270
+ projectId: string;
271
+ }
272
+ interface ListSegmentsResponse {
273
+ data: Segment[];
274
+ count: number;
275
+ }
276
+
277
+ declare class Segments {
278
+ private readonly client;
279
+ constructor(client: MigmaClient);
280
+ list(projectId: string): Promise<MigmaResult<ListSegmentsResponse>>;
281
+ create(params: CreateSegmentParams): Promise<MigmaResult<Segment>>;
282
+ get(id: string, projectId: string): Promise<MigmaResult<Segment>>;
283
+ update(id: string, params: UpdateSegmentParams): Promise<MigmaResult<Segment>>;
284
+ remove(id: string, projectId: string): Promise<MigmaResult<DeleteResponse>>;
285
+ }
286
+
287
+ interface Topic {
288
+ id: string;
289
+ name: string;
290
+ description: string;
291
+ defaultSubscription: 'opt_in' | 'opt_out';
292
+ visibility: 'public' | 'private';
293
+ displayOrder: number;
294
+ isActive: boolean;
295
+ createdAt: string;
296
+ updatedAt: string;
297
+ }
298
+ interface CreateTopicParams {
299
+ name: string;
300
+ description?: string;
301
+ defaultSubscription?: 'opt_in' | 'opt_out';
302
+ visibility?: 'public' | 'private';
303
+ displayOrder?: number;
304
+ projectId: string;
305
+ }
306
+ interface UpdateTopicParams {
307
+ name?: string;
308
+ description?: string;
309
+ visibility?: 'public' | 'private';
310
+ displayOrder?: number;
311
+ isActive?: boolean;
312
+ projectId: string;
313
+ }
314
+ interface ListTopicsParams {
315
+ projectId: string;
316
+ includeInactive?: boolean;
317
+ }
318
+ interface ListTopicsResponse {
319
+ data: Topic[];
320
+ count: number;
321
+ }
322
+ interface TopicSubscriptionParams {
323
+ subscriberId: string;
324
+ projectId: string;
325
+ }
326
+ interface TopicSubscriptionResponse {
327
+ topicId: string;
328
+ subscriberId: string;
329
+ subscribed: boolean;
330
+ }
331
+
332
+ declare class Topics {
333
+ private readonly client;
334
+ constructor(client: MigmaClient);
335
+ list(params: ListTopicsParams): Promise<MigmaResult<ListTopicsResponse>>;
336
+ create(params: CreateTopicParams): Promise<MigmaResult<Topic>>;
337
+ get(id: string, projectId: string): Promise<MigmaResult<Topic>>;
338
+ update(id: string, params: UpdateTopicParams): Promise<MigmaResult<Topic>>;
339
+ remove(id: string, projectId: string): Promise<MigmaResult<DeleteResponse>>;
340
+ subscribe(topicId: string, params: TopicSubscriptionParams): Promise<MigmaResult<TopicSubscriptionResponse>>;
341
+ unsubscribe(topicId: string, params: TopicSubscriptionParams): Promise<MigmaResult<TopicSubscriptionResponse>>;
342
+ }
343
+
344
+ type RecipientType = 'email' | 'audience' | 'segment' | 'tag';
345
+ type ProviderType = 'ses' | 'resend' | 'sendgrid' | 'mailgun' | 'migma';
346
+ interface SendEmailParams {
347
+ recipientType: RecipientType;
348
+ /** Required when recipientType is audience, segment, or tag */
349
+ recipientId?: string;
350
+ /** Required when recipientType is email */
351
+ recipientEmail?: string;
352
+ from: string;
353
+ fromName: string;
354
+ replyTo?: string;
355
+ subject: string;
356
+ /** HTML template string */
357
+ template: string;
358
+ variables?: Record<string, unknown>;
359
+ providerType?: ProviderType;
360
+ projectId: string;
361
+ conversationId?: string;
362
+ }
363
+ interface SendEmailResponse {
364
+ [key: string]: unknown;
365
+ }
366
+ interface BatchStatus {
367
+ batchId: string;
368
+ status: 'pending' | 'processing' | 'completed' | 'failed';
369
+ recipientType: string;
370
+ recipientId?: string;
371
+ provider: string;
372
+ totalCount: number;
373
+ queuedCount: number;
374
+ sentCount: number;
375
+ failedCount: number;
376
+ from: string;
377
+ fromName: string;
378
+ subject: string;
379
+ createdAt: string;
380
+ updatedAt?: string;
381
+ error?: string;
382
+ }
383
+
384
+ declare class Sending {
385
+ private readonly client;
386
+ constructor(client: MigmaClient);
387
+ send(params: SendEmailParams): Promise<MigmaResult<SendEmailResponse>>;
388
+ getBatchStatus(batchId: string): Promise<MigmaResult<BatchStatus>>;
389
+ }
390
+
391
+ interface Project {
392
+ _id: string;
393
+ name: string;
394
+ description: string;
395
+ status: 'pending' | 'processing' | 'active' | 'error';
396
+ domain: string;
397
+ logoUrls?: {
398
+ primary?: string;
399
+ secondary?: string;
400
+ favicon?: string;
401
+ };
402
+ screenshotUrl?: string;
403
+ createdAt: string;
404
+ updatedAt: string;
405
+ [key: string]: unknown;
406
+ }
407
+ interface ListProjectsParams {
408
+ limit?: number;
409
+ offset?: number;
410
+ status?: string;
411
+ }
412
+ interface ListProjectsResponse {
413
+ projects: Project[];
414
+ pagination: {
415
+ total: number;
416
+ limit: number;
417
+ offset: number;
418
+ hasMore: boolean;
419
+ };
420
+ }
421
+ interface ImportProjectParams {
422
+ urls: string[];
423
+ logoUrls?: {
424
+ primary?: string;
425
+ secondary?: string;
426
+ favicon?: string;
427
+ };
428
+ }
429
+ interface ImportProjectResponse {
430
+ projectId: string;
431
+ status: 'pending';
432
+ domain: string;
433
+ urls: string[];
434
+ message: string;
435
+ }
436
+ interface ImportStatusResponse {
437
+ projectId: string;
438
+ status: 'pending' | 'processing' | 'active' | 'error';
439
+ name?: string;
440
+ description?: string;
441
+ domain?: string;
442
+ error?: string;
443
+ progress: {
444
+ stage: string;
445
+ percentage: number;
446
+ };
447
+ importMetrics?: Record<string, unknown>;
448
+ }
449
+ interface RetryImportResponse {
450
+ projectId: string;
451
+ status: string;
452
+ message: string;
453
+ }
454
+
455
+ interface PollingOptions {
456
+ /** Polling interval in ms. Default: 2000 */
457
+ interval?: number;
458
+ /** Maximum number of polls before giving up. Default: 150 (5 minutes at 2s) */
459
+ maxAttempts?: number;
460
+ /** Callback on each poll with current status */
461
+ onPoll?: (status: unknown, attempt: number) => void;
462
+ /** AbortSignal to cancel polling */
463
+ signal?: AbortSignal;
464
+ }
465
+ /**
466
+ * Generic polling function.
467
+ * Calls `fetcher()` repeatedly until `isComplete(result)` returns true
468
+ * or max attempts are reached.
469
+ */
470
+ declare function poll<T>(fetcher: () => Promise<MigmaResult<T>>, isComplete: (data: T) => boolean, options?: PollingOptions): Promise<MigmaResult<T>>;
471
+
472
+ declare class Projects {
473
+ private readonly client;
474
+ constructor(client: MigmaClient);
475
+ list(params?: ListProjectsParams): Promise<MigmaResult<ListProjectsResponse>>;
476
+ get(projectId: string): Promise<MigmaResult<Project>>;
477
+ import(params: ImportProjectParams): Promise<MigmaResult<ImportProjectResponse>>;
478
+ getImportStatus(projectId: string): Promise<MigmaResult<ImportStatusResponse>>;
479
+ retryImport(projectId: string): Promise<MigmaResult<RetryImportResponse>>;
480
+ /**
481
+ * Import a project and wait for completion.
482
+ * Polls getImportStatus until status is 'active' or 'error'.
483
+ */
484
+ importAndWait(params: ImportProjectParams, options?: PollingOptions): Promise<MigmaResult<ImportStatusResponse>>;
485
+ }
486
+
487
+ interface EmailImage {
488
+ source: {
489
+ type: 'url';
490
+ url: string;
491
+ };
492
+ }
493
+ interface GenerateEmailParams {
494
+ projectId: string;
495
+ prompt: string;
496
+ images?: EmailImage[];
497
+ model?: string;
498
+ webMode?: boolean;
499
+ languages?: string[];
500
+ visibility?: 'private' | 'unlisted' | 'public';
501
+ referenceId?: string;
502
+ }
503
+ interface GenerateEmailResponse {
504
+ conversationId: string;
505
+ status: 'pending';
506
+ message: string;
507
+ link: string;
508
+ }
509
+ interface EmailGenerationResult {
510
+ subject: string;
511
+ previewText: string;
512
+ html: string;
513
+ screenshotUrl: string | null;
514
+ screenshotFullUrl: string | null;
515
+ stats: {
516
+ imageCount: number;
517
+ buttonCount: number;
518
+ estimatedLength: string;
519
+ colors: string[];
520
+ };
521
+ languages: string[];
522
+ }
523
+ interface EmailGenerationStatus {
524
+ conversationId: string;
525
+ status: 'pending' | 'processing' | 'completed' | 'failed';
526
+ createdAt: string;
527
+ updatedAt: string;
528
+ error?: string;
529
+ result?: EmailGenerationResult;
530
+ }
531
+ interface SendTestEmailParams {
532
+ conversationId: string;
533
+ to: string;
534
+ }
535
+ interface SendTestEmailResponse {
536
+ messageId: string;
537
+ conversationId: string;
538
+ sentTo: string;
539
+ sentAt: string;
540
+ subject: string;
541
+ }
542
+
543
+ declare class Emails {
544
+ private readonly client;
545
+ constructor(client: MigmaClient);
546
+ /** Start async email generation */
547
+ generate(params: GenerateEmailParams): Promise<MigmaResult<GenerateEmailResponse>>;
548
+ /** Check email generation status */
549
+ getGenerationStatus(conversationId: string): Promise<MigmaResult<EmailGenerationStatus>>;
550
+ /**
551
+ * Generate an email and wait for completion.
552
+ * Polls getGenerationStatus until status is 'completed' or 'failed'.
553
+ */
554
+ generateAndWait(params: GenerateEmailParams, options?: PollingOptions): Promise<MigmaResult<EmailGenerationStatus>>;
555
+ /** Send a test email from a completed conversation */
556
+ sendTest(params: SendTestEmailParams): Promise<MigmaResult<SendTestEmailResponse>>;
557
+ }
558
+
559
+ interface CheckCompatibilityParams {
560
+ html: string;
561
+ clients?: string[];
562
+ }
563
+ interface CompatibilityResponse {
564
+ clientIssues: Record<string, unknown>;
565
+ summary: {
566
+ totalErrors: number;
567
+ totalWarnings: number;
568
+ compatibilityScore: number;
569
+ };
570
+ supportedClients: unknown[];
571
+ metadata: {
572
+ processingTime: number;
573
+ clientsTested: number;
574
+ };
575
+ }
576
+ interface AnalyzeLinksParams {
577
+ html: string;
578
+ timeout?: number;
579
+ followRedirects?: boolean;
580
+ }
581
+ interface CheckedLink {
582
+ url: string;
583
+ status: string;
584
+ responseTime?: number;
585
+ error?: string;
586
+ }
587
+ interface LinkAnalysisResponse {
588
+ totalLinks: number;
589
+ checkedLinks: CheckedLink[];
590
+ summary: {
591
+ brokenLinks: number;
592
+ unreachableLinks: number;
593
+ averageResponseTime: number;
594
+ };
595
+ recommendations: string[];
596
+ metadata: {
597
+ processingTime: number;
598
+ linksChecked: number;
599
+ linksSkipped: number;
600
+ };
601
+ }
602
+ interface CheckSpellingParams {
603
+ html: string;
604
+ languages?: string[];
605
+ checkGrammar?: boolean;
606
+ }
607
+ interface SpellingResponse {
608
+ summary: {
609
+ totalErrors: number;
610
+ };
611
+ metadata: {
612
+ processingTime: number;
613
+ aiModel: string;
614
+ tokensUsed: number;
615
+ };
616
+ [key: string]: unknown;
617
+ }
618
+ interface AnalyzeDeliverabilityParams {
619
+ html: string;
620
+ subject?: string;
621
+ fromName?: string;
622
+ fromEmail?: string;
623
+ }
624
+ interface DeliverabilityResponse {
625
+ prediction: {
626
+ category: 'inbox' | 'promotions' | 'spam';
627
+ confidence: number;
628
+ score: number;
629
+ reasoning: string;
630
+ };
631
+ contentSignals: {
632
+ promotional: string[];
633
+ transactional: string[];
634
+ spam: string[];
635
+ engagement: string[];
636
+ };
637
+ spamScore: {
638
+ score: number;
639
+ triggers: string[];
640
+ recommendations: string[];
641
+ };
642
+ recommendations: {
643
+ critical: string[];
644
+ important: string[];
645
+ suggested: string[];
646
+ };
647
+ metadata: {
648
+ processingTime: number;
649
+ analysisType: string;
650
+ };
651
+ }
652
+ interface ValidateAllParams {
653
+ html: string;
654
+ subject?: string;
655
+ options?: {
656
+ checkCompatibility?: boolean;
657
+ checkLinks?: boolean;
658
+ checkSpelling?: boolean;
659
+ checkDeliverability?: boolean;
660
+ clients?: string[];
661
+ languages?: string[];
662
+ };
663
+ }
664
+ interface ValidateAllResponse {
665
+ overallScore: number;
666
+ compatibility?: CompatibilityResponse;
667
+ linkAnalysis?: LinkAnalysisResponse;
668
+ spelling?: SpellingResponse;
669
+ deliverability?: DeliverabilityResponse;
670
+ summary: {
671
+ criticalIssues: number;
672
+ warnings: number;
673
+ passed: string[];
674
+ failed: string[];
675
+ };
676
+ recommendations: {
677
+ critical: string[];
678
+ important: string[];
679
+ suggested: string[];
680
+ };
681
+ metadata: {
682
+ totalProcessingTime: number;
683
+ checksPerformed: string[];
684
+ };
685
+ }
686
+
687
+ declare class Validation {
688
+ private readonly client;
689
+ constructor(client: MigmaClient);
690
+ all(params: ValidateAllParams): Promise<MigmaResult<ValidateAllResponse>>;
691
+ compatibility(params: CheckCompatibilityParams): Promise<MigmaResult<CompatibilityResponse>>;
692
+ links(params: AnalyzeLinksParams): Promise<MigmaResult<LinkAnalysisResponse>>;
693
+ spelling(params: CheckSpellingParams): Promise<MigmaResult<SpellingResponse>>;
694
+ deliverability(params: AnalyzeDeliverabilityParams): Promise<MigmaResult<DeliverabilityResponse>>;
695
+ }
696
+
697
+ type PreviewDeviceStatus = 'PROCESSING' | 'SUCCESSFUL' | 'FAILED';
698
+ type PreviewDeviceCategory = 'DESKTOP' | 'MOBILE' | 'WEB' | 'MISC';
699
+ type PreviewStatus = 'PROCESSING' | 'COMPLETED' | 'PARTIAL_SUCCESS' | 'FAILED';
700
+ interface PreviewDevice {
701
+ deviceKey: string;
702
+ deviceName: string;
703
+ client: string;
704
+ os: string;
705
+ category: string;
706
+ status: PreviewDeviceStatus;
707
+ screenshotUrl: string | null;
708
+ thumbnailUrl: string | null;
709
+ fullThumbnailUrl: string | null;
710
+ processingTime?: number | null;
711
+ }
712
+ interface PreviewMetadata {
713
+ requestedDevices: number;
714
+ completedDevices: number;
715
+ failedDevices: number;
716
+ processingDevices: number;
717
+ processingTime?: number;
718
+ }
719
+ interface CreatePreviewParams {
720
+ html: string;
721
+ subject?: string;
722
+ devices?: string[];
723
+ name?: string;
724
+ }
725
+ interface CreatePreviewResponse {
726
+ previewId: string;
727
+ status: PreviewStatus;
728
+ devices?: PreviewDevice[];
729
+ metadata: PreviewMetadata;
730
+ cached?: boolean;
731
+ }
732
+ interface GetPreviewResponse {
733
+ previewId: string;
734
+ status: PreviewStatus;
735
+ devices: PreviewDevice[];
736
+ metadata: PreviewMetadata;
737
+ }
738
+ interface GetPreviewStatusResponse {
739
+ previewId: string;
740
+ status: PreviewStatus;
741
+ metadata: PreviewMetadata;
742
+ }
743
+ interface GetDevicePreviewResponse {
744
+ device: PreviewDevice;
745
+ }
746
+ interface SupportedDevice {
747
+ key: string;
748
+ name: string;
749
+ category: PreviewDeviceCategory;
750
+ }
751
+ interface DeviceCategoriesResponse {
752
+ desktop: SupportedDevice[];
753
+ mobile: SupportedDevice[];
754
+ web: SupportedDevice[];
755
+ misc: SupportedDevice[];
756
+ }
757
+ interface GetSupportedDevicesResponse {
758
+ total: number;
759
+ categories: DeviceCategoriesResponse;
760
+ devices: SupportedDevice[];
761
+ }
762
+
763
+ declare class Previews {
764
+ private readonly client;
765
+ constructor(client: MigmaClient);
766
+ create(params: CreatePreviewParams): Promise<MigmaResult<CreatePreviewResponse>>;
767
+ get(previewId: string): Promise<MigmaResult<GetPreviewResponse>>;
768
+ getStatus(previewId: string): Promise<MigmaResult<GetPreviewStatusResponse>>;
769
+ getDevice(previewId: string, deviceKey: string): Promise<MigmaResult<GetDevicePreviewResponse>>;
770
+ getSupportedDevices(): Promise<MigmaResult<GetSupportedDevicesResponse>>;
771
+ /**
772
+ * Create a preview and wait for completion.
773
+ * Polls getStatus until status is 'COMPLETED', 'PARTIAL_SUCCESS', or 'FAILED'.
774
+ */
775
+ createAndWait(params: CreatePreviewParams, options?: PollingOptions): Promise<MigmaResult<GetPreviewResponse>>;
776
+ }
777
+
778
+ interface ExportFile {
779
+ filename: string;
780
+ url: string;
781
+ format: string;
782
+ }
783
+ interface ExportResult {
784
+ files: ExportFile[];
785
+ executionTime: number;
786
+ exportType: string;
787
+ }
788
+ interface ExportFormat {
789
+ name: string;
790
+ description: string;
791
+ supportedFormats: string[];
792
+ type: 'simple' | 'complex';
793
+ }
794
+ interface ExportFormatsResponse {
795
+ formats: ExportFormat[];
796
+ total: number;
797
+ }
798
+ interface ExportStatusResponse {
799
+ conversationId: string;
800
+ canExport: boolean;
801
+ availableFormats: string[];
802
+ reason?: string;
803
+ }
804
+ interface HubspotExportParams {
805
+ conversationId: string;
806
+ customOptions?: {
807
+ customInstructions?: string;
808
+ [key: string]: unknown;
809
+ };
810
+ }
811
+
812
+ declare class Export {
813
+ private readonly client;
814
+ constructor(client: MigmaClient);
815
+ getFormats(): Promise<MigmaResult<ExportFormatsResponse>>;
816
+ getStatus(conversationId: string): Promise<MigmaResult<ExportStatusResponse>>;
817
+ html(conversationId: string): Promise<MigmaResult<ExportResult>>;
818
+ mjml(conversationId: string): Promise<MigmaResult<ExportResult>>;
819
+ pdf(conversationId: string): Promise<MigmaResult<ExportResult>>;
820
+ klaviyo(conversationId: string, klaviyoType?: 'html' | 'hybrid' | 'code'): Promise<MigmaResult<ExportResult>>;
821
+ mailchimp(conversationId: string): Promise<MigmaResult<ExportResult>>;
822
+ hubspot(params: HubspotExportParams): Promise<MigmaResult<ExportResult>>;
823
+ }
824
+
825
+ interface DnsRecord {
826
+ type: string;
827
+ name: string;
828
+ value: string;
829
+ priority?: number;
830
+ status?: string;
831
+ }
832
+ interface Domain {
833
+ domain: string;
834
+ region: string;
835
+ status: string;
836
+ isVerified?: boolean;
837
+ dnsRecords?: DnsRecord[];
838
+ trackingSettings?: {
839
+ openTracking?: boolean;
840
+ clickTracking?: boolean;
841
+ brandedTracking?: boolean;
842
+ };
843
+ createdAt?: string;
844
+ updatedAt?: string;
845
+ [key: string]: unknown;
846
+ }
847
+ interface CreateDomainParams {
848
+ domain: string;
849
+ region?: 'us-east-1' | 'eu-west-1';
850
+ }
851
+ interface UpdateDomainParams {
852
+ openTracking?: boolean;
853
+ clickTracking?: boolean;
854
+ brandedTracking?: boolean;
855
+ }
856
+ interface DomainVerificationResult {
857
+ domain: string;
858
+ status: string;
859
+ dnsRecords?: DnsRecord[];
860
+ [key: string]: unknown;
861
+ }
862
+ interface DomainAvailability {
863
+ available: boolean;
864
+ [key: string]: unknown;
865
+ }
866
+ interface CreateManagedDomainParams {
867
+ prefix: string;
868
+ region?: string;
869
+ }
870
+ interface DomainDeleteResponse {
871
+ domain: string;
872
+ deleted: boolean;
873
+ }
874
+
875
+ declare class Domains {
876
+ private readonly client;
877
+ constructor(client: MigmaClient);
878
+ list(): Promise<MigmaResult<Domain[]>>;
879
+ create(params: CreateDomainParams): Promise<MigmaResult<Domain>>;
880
+ get(domain: string): Promise<MigmaResult<Domain>>;
881
+ verify(domain: string): Promise<MigmaResult<DomainVerificationResult>>;
882
+ update(domain: string, params: UpdateDomainParams): Promise<MigmaResult<Domain>>;
883
+ remove(domain: string): Promise<MigmaResult<DomainDeleteResponse>>;
884
+ checkAvailability(prefix: string): Promise<MigmaResult<DomainAvailability>>;
885
+ listManaged(): Promise<MigmaResult<Domain[]>>;
886
+ createManaged(params: CreateManagedDomainParams): Promise<MigmaResult<Domain>>;
887
+ removeManaged(domain: string): Promise<MigmaResult<DomainDeleteResponse>>;
888
+ }
889
+
890
+ type WebhookEventType = 'email.generation.started' | 'email.generation.completed' | 'email.generation.failed' | 'email.test.sent' | 'project.import.started' | 'project.import.processing' | 'project.import.completed' | 'project.import.failed' | 'export.completed' | 'export.failed' | 'subscriber.added' | 'subscriber.updated' | 'subscriber.unsubscribed' | 'subscriber.bulk_imported' | 'api_key.created' | 'api_key.revoked';
891
+ interface CreateWebhookParams {
892
+ url: string;
893
+ events: WebhookEventType[];
894
+ description?: string;
895
+ customHeaders?: Record<string, string>;
896
+ }
897
+ interface UpdateWebhookParams {
898
+ url?: string;
899
+ events?: WebhookEventType[];
900
+ active?: boolean;
901
+ description?: string;
902
+ customHeaders?: Record<string, string>;
903
+ }
904
+ interface Webhook {
905
+ id: string;
906
+ url: string;
907
+ events: WebhookEventType[];
908
+ active: boolean;
909
+ secret: string;
910
+ description?: string;
911
+ createdAt: string;
912
+ }
913
+ interface WebhookDetail extends Webhook {
914
+ customHeaders?: Record<string, string>;
915
+ successCount: number;
916
+ failureCount: number;
917
+ lastTriggeredAt?: string;
918
+ updatedAt: string;
919
+ }
920
+ interface ListWebhooksResponse {
921
+ webhooks: WebhookDetail[];
922
+ total: number;
923
+ }
924
+ interface WebhookTestResult {
925
+ success: boolean;
926
+ statusCode?: number;
927
+ responseTime?: number;
928
+ error?: string;
929
+ }
930
+ interface WebhookDelivery {
931
+ id: string;
932
+ eventId: string;
933
+ eventType: WebhookEventType;
934
+ status: string;
935
+ attempts: number;
936
+ lastAttemptAt: string;
937
+ response: Record<string, unknown>;
938
+ createdAt: string;
939
+ }
940
+ interface WebhookDeliveriesResponse {
941
+ deliveries: WebhookDelivery[];
942
+ total: number;
943
+ }
944
+ interface WebhookEvent {
945
+ type: WebhookEventType;
946
+ description: string;
947
+ }
948
+ interface WebhookEventsResponse {
949
+ events: WebhookEvent[];
950
+ total: number;
951
+ }
952
+
953
+ declare class Webhooks {
954
+ private readonly client;
955
+ constructor(client: MigmaClient);
956
+ list(): Promise<MigmaResult<ListWebhooksResponse>>;
957
+ create(params: CreateWebhookParams): Promise<MigmaResult<Webhook>>;
958
+ get(webhookId: string): Promise<MigmaResult<WebhookDetail>>;
959
+ update(webhookId: string, params: UpdateWebhookParams): Promise<MigmaResult<{
960
+ updated: boolean;
961
+ }>>;
962
+ remove(webhookId: string): Promise<MigmaResult<{
963
+ deleted: boolean;
964
+ }>>;
965
+ test(webhookId: string): Promise<MigmaResult<WebhookTestResult>>;
966
+ getDeliveries(webhookId: string, limit?: number): Promise<MigmaResult<WebhookDeliveriesResponse>>;
967
+ getEvents(): Promise<MigmaResult<WebhookEventsResponse>>;
968
+ getStats(): Promise<MigmaResult<Record<string, unknown>>>;
969
+ }
970
+
971
+ interface KnowledgeBaseEntry {
972
+ id: string;
973
+ title: string;
974
+ content: string;
975
+ date: string;
976
+ }
977
+ interface KnowledgeBaseListResponse {
978
+ entries: KnowledgeBaseEntry[];
979
+ total: number;
980
+ }
981
+ interface AddKnowledgeBaseParams {
982
+ title: string;
983
+ content: string;
984
+ }
985
+ interface UpdateKnowledgeBaseParams {
986
+ title?: string;
987
+ content?: string;
988
+ }
989
+
990
+ declare class KnowledgeBase {
991
+ private readonly client;
992
+ constructor(client: MigmaClient);
993
+ list(projectId: string): Promise<MigmaResult<KnowledgeBaseListResponse>>;
994
+ add(projectId: string, params: AddKnowledgeBaseParams): Promise<MigmaResult<KnowledgeBaseEntry>>;
995
+ update(projectId: string, entryId: string, params: UpdateKnowledgeBaseParams): Promise<MigmaResult<KnowledgeBaseEntry>>;
996
+ remove(projectId: string, entryId: string): Promise<MigmaResult<MessageResponse>>;
997
+ }
998
+
999
+ interface ProjectImage {
1000
+ url: string;
1001
+ description?: string;
1002
+ tags?: string[];
1003
+ [key: string]: unknown;
1004
+ }
1005
+ interface AddImageParams {
1006
+ url: string;
1007
+ description?: string;
1008
+ tags?: string[];
1009
+ }
1010
+ interface UpdateImageParams {
1011
+ imageUrl: string;
1012
+ description?: string;
1013
+ tags?: string[];
1014
+ }
1015
+ interface UpdateLogosParams {
1016
+ primary?: string | null;
1017
+ secondary?: string | null;
1018
+ favicon?: string | null;
1019
+ }
1020
+ interface LogosResponse {
1021
+ logoUrls: {
1022
+ primary?: string;
1023
+ secondary?: string;
1024
+ favicon?: string;
1025
+ };
1026
+ }
1027
+
1028
+ declare class Images {
1029
+ private readonly client;
1030
+ constructor(client: MigmaClient);
1031
+ add(projectId: string, params: AddImageParams): Promise<MigmaResult<ProjectImage>>;
1032
+ update(projectId: string, params: UpdateImageParams): Promise<MigmaResult<ProjectImage>>;
1033
+ remove(projectId: string, imageUrl: string): Promise<MigmaResult<MessageResponse>>;
1034
+ updateLogos(projectId: string, params: UpdateLogosParams): Promise<MigmaResult<LogosResponse>>;
1035
+ }
1036
+
1037
+ interface MigmaConfig {
1038
+ /** API base URL. Default: 'https://api.migma.ai/api/v1' */
1039
+ baseUrl?: string;
1040
+ /** Request timeout in ms. Default: 30000 */
1041
+ timeout?: number;
1042
+ /** Max retries on 5xx/429 errors. Default: 2 */
1043
+ maxRetries?: number;
1044
+ /** Base delay between retries in ms. Default: 1000 */
1045
+ retryDelay?: number;
1046
+ }
1047
+ declare class Migma {
1048
+ private readonly client;
1049
+ readonly contacts: Contacts;
1050
+ readonly tags: Tags;
1051
+ readonly segments: Segments;
1052
+ readonly topics: Topics;
1053
+ readonly sending: Sending;
1054
+ readonly projects: Projects;
1055
+ readonly emails: Emails;
1056
+ readonly validation: Validation;
1057
+ readonly previews: Previews;
1058
+ readonly export: Export;
1059
+ readonly domains: Domains;
1060
+ readonly webhooks: Webhooks;
1061
+ readonly knowledgeBase: KnowledgeBase;
1062
+ readonly images: Images;
1063
+ constructor(apiKey: string, config?: MigmaConfig);
1064
+ }
1065
+
1066
+ export { type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchStatus, type BulkImportAsyncResponse, type BulkImportContactItem, type BulkImportJobStatus, type BulkImportParams, type BulkImportResponse, type BulkImportSyncResponse, type ChangeStatusParams, type CheckCompatibilityParams, type CheckSpellingParams, type CheckedLink, type ClientConfig, type CompatibilityResponse, type Contact, type ContactStatus, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type DeleteResponse, type DeliverabilityResponse, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainVerificationResult, type EmailGenerationResult, type EmailGenerationStatus, type EmailImage, type ExportFile, type ExportFormat, type ExportFormatsResponse, type ExportResult, type ExportStatusResponse, type GenerateEmailParams, type GenerateEmailResponse, type GetDevicePreviewResponse, type GetPreviewResponse, type GetPreviewStatusResponse, type GetSupportedDevicesResponse, type HubspotExportParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListContactsParams, type ListContactsResponse, 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 RecipientType, type RetryImportResponse, type Segment, type SegmentFilters, type SendEmailParams, type SendEmailResponse, type SendTestEmailParams, type SendTestEmailResponse, 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 };