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.
package/dist/index.js ADDED
@@ -0,0 +1,812 @@
1
+ 'use strict';
2
+
3
+ // src/errors.ts
4
+ var MigmaErrorCode = /* @__PURE__ */ ((MigmaErrorCode2) => {
5
+ MigmaErrorCode2["VALIDATION_ERROR"] = "validation_error";
6
+ MigmaErrorCode2["NOT_FOUND"] = "not_found";
7
+ MigmaErrorCode2["UNAUTHORIZED"] = "unauthorized";
8
+ MigmaErrorCode2["FORBIDDEN"] = "forbidden";
9
+ MigmaErrorCode2["RATE_LIMIT_EXCEEDED"] = "rate_limit_exceeded";
10
+ MigmaErrorCode2["CONFLICT"] = "conflict";
11
+ MigmaErrorCode2["TIMEOUT"] = "timeout";
12
+ MigmaErrorCode2["NETWORK_ERROR"] = "network_error";
13
+ MigmaErrorCode2["INTERNAL_ERROR"] = "internal_error";
14
+ MigmaErrorCode2["UNKNOWN"] = "unknown";
15
+ return MigmaErrorCode2;
16
+ })(MigmaErrorCode || {});
17
+ var MigmaError = class _MigmaError extends Error {
18
+ statusCode;
19
+ code;
20
+ constructor(message, statusCode, code) {
21
+ super(message);
22
+ this.name = "MigmaError";
23
+ this.statusCode = statusCode;
24
+ this.code = code ?? _MigmaError.codeFromStatus(statusCode);
25
+ }
26
+ static codeFromStatus(status) {
27
+ switch (status) {
28
+ case 400:
29
+ return "validation_error" /* VALIDATION_ERROR */;
30
+ case 401:
31
+ return "unauthorized" /* UNAUTHORIZED */;
32
+ case 403:
33
+ return "forbidden" /* FORBIDDEN */;
34
+ case 404:
35
+ return "not_found" /* NOT_FOUND */;
36
+ case 409:
37
+ return "conflict" /* CONFLICT */;
38
+ case 429:
39
+ return "rate_limit_exceeded" /* RATE_LIMIT_EXCEEDED */;
40
+ default:
41
+ if (status >= 500) return "internal_error" /* INTERNAL_ERROR */;
42
+ return "unknown" /* UNKNOWN */;
43
+ }
44
+ }
45
+ toJSON() {
46
+ return {
47
+ name: this.name,
48
+ message: this.message,
49
+ statusCode: this.statusCode,
50
+ code: this.code
51
+ };
52
+ }
53
+ };
54
+
55
+ // src/client.ts
56
+ var MigmaClient = class {
57
+ apiKey;
58
+ config;
59
+ constructor(apiKey, config) {
60
+ this.apiKey = apiKey;
61
+ this.config = config;
62
+ }
63
+ async request(options) {
64
+ const url = this.buildUrl(options.path, options.query);
65
+ const timeout = options.timeout ?? this.config.timeout;
66
+ const attempts = this.config.maxRetries + 1;
67
+ let lastError = null;
68
+ for (let attempt = 0; attempt < attempts; attempt++) {
69
+ const controller = new AbortController();
70
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
71
+ try {
72
+ const response = await fetch(url, {
73
+ method: options.method,
74
+ headers: {
75
+ Authorization: `Bearer ${this.apiKey}`,
76
+ "Content-Type": "application/json",
77
+ "User-Agent": "migma-node/1.0.0"
78
+ },
79
+ body: options.body ? JSON.stringify(options.body) : void 0,
80
+ signal: controller.signal
81
+ });
82
+ clearTimeout(timeoutId);
83
+ const json = await response.json();
84
+ if (!response.ok || !json.success) {
85
+ const error = new MigmaError(
86
+ json.error || `Request failed with status ${response.status}`,
87
+ response.status
88
+ );
89
+ if (response.status >= 500 || response.status === 429) {
90
+ lastError = error;
91
+ if (attempt < attempts - 1) {
92
+ const delay = response.status === 429 ? this.parseRetryAfter(response) ?? this.config.retryDelay * (attempt + 1) : this.config.retryDelay * Math.pow(2, attempt);
93
+ await this.sleep(delay);
94
+ continue;
95
+ }
96
+ }
97
+ return { data: null, error };
98
+ }
99
+ return { data: json.data, error: null };
100
+ } catch (err) {
101
+ clearTimeout(timeoutId);
102
+ if (err instanceof Error && err.name === "AbortError") {
103
+ return {
104
+ data: null,
105
+ error: new MigmaError(
106
+ "Request timed out",
107
+ 0,
108
+ "timeout" /* TIMEOUT */
109
+ )
110
+ };
111
+ }
112
+ lastError = new MigmaError(
113
+ err instanceof Error ? err.message : "Network error",
114
+ 0,
115
+ "network_error" /* NETWORK_ERROR */
116
+ );
117
+ if (attempt < attempts - 1) {
118
+ await this.sleep(this.config.retryDelay * Math.pow(2, attempt));
119
+ continue;
120
+ }
121
+ }
122
+ }
123
+ return { data: null, error: lastError };
124
+ }
125
+ /**
126
+ * For endpoints where the API returns `{ success, data, count }` and we want
127
+ * both the data array and the count together.
128
+ */
129
+ async requestWithCount(options) {
130
+ const url = this.buildUrl(options.path, options.query);
131
+ const timeout = options.timeout ?? this.config.timeout;
132
+ const controller = new AbortController();
133
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
134
+ try {
135
+ const response = await fetch(url, {
136
+ method: options.method,
137
+ headers: {
138
+ Authorization: `Bearer ${this.apiKey}`,
139
+ "Content-Type": "application/json",
140
+ "User-Agent": "migma-node/1.0.0"
141
+ },
142
+ body: options.body ? JSON.stringify(options.body) : void 0,
143
+ signal: controller.signal
144
+ });
145
+ clearTimeout(timeoutId);
146
+ const json = await response.json();
147
+ if (!response.ok || !json.success) {
148
+ return {
149
+ data: null,
150
+ error: new MigmaError(
151
+ json.error || `Request failed with status ${response.status}`,
152
+ response.status
153
+ )
154
+ };
155
+ }
156
+ return {
157
+ data: { data: json.data, count: json.count ?? 0 },
158
+ error: null
159
+ };
160
+ } catch (err) {
161
+ clearTimeout(timeoutId);
162
+ if (err instanceof Error && err.name === "AbortError") {
163
+ return {
164
+ data: null,
165
+ error: new MigmaError(
166
+ "Request timed out",
167
+ 0,
168
+ "timeout" /* TIMEOUT */
169
+ )
170
+ };
171
+ }
172
+ return {
173
+ data: null,
174
+ error: new MigmaError(
175
+ err instanceof Error ? err.message : "Network error",
176
+ 0,
177
+ "network_error" /* NETWORK_ERROR */
178
+ )
179
+ };
180
+ }
181
+ }
182
+ async get(path, query) {
183
+ return this.request({ method: "GET", path, query });
184
+ }
185
+ async getWithCount(path, query) {
186
+ return this.requestWithCount({ method: "GET", path, query });
187
+ }
188
+ async post(path, body) {
189
+ return this.request({ method: "POST", path, body });
190
+ }
191
+ async patch(path, body) {
192
+ return this.request({ method: "PATCH", path, body });
193
+ }
194
+ async put(path, body) {
195
+ return this.request({ method: "PUT", path, body });
196
+ }
197
+ async delete(path, query) {
198
+ return this.request({ method: "DELETE", path, query });
199
+ }
200
+ buildUrl(path, query) {
201
+ const url = new URL(`${this.config.baseUrl}${path}`);
202
+ if (query) {
203
+ for (const [key, value] of Object.entries(query)) {
204
+ if (value !== void 0 && value !== null) {
205
+ url.searchParams.set(key, String(value));
206
+ }
207
+ }
208
+ }
209
+ return url.toString();
210
+ }
211
+ parseRetryAfter(response) {
212
+ const retryAfter = response.headers.get("Retry-After");
213
+ if (retryAfter) {
214
+ const seconds = parseInt(retryAfter, 10);
215
+ if (!isNaN(seconds)) return seconds * 1e3;
216
+ }
217
+ return null;
218
+ }
219
+ sleep(ms) {
220
+ return new Promise((resolve) => setTimeout(resolve, ms));
221
+ }
222
+ };
223
+
224
+ // src/resources/contacts.ts
225
+ var Contacts = class {
226
+ constructor(client) {
227
+ this.client = client;
228
+ }
229
+ async create(params) {
230
+ return this.client.post("/contacts", params);
231
+ }
232
+ async list(params) {
233
+ const { projectId, page, limit, tags, status, search } = params;
234
+ return this.client.getWithCount("/contacts", {
235
+ projectId,
236
+ page,
237
+ limit,
238
+ tags,
239
+ status,
240
+ search
241
+ });
242
+ }
243
+ async get(id, projectId) {
244
+ return this.client.get(`/contacts/${id}`, { projectId });
245
+ }
246
+ async update(id, params) {
247
+ return this.client.patch(`/contacts/${id}`, params);
248
+ }
249
+ async remove(id, projectId) {
250
+ return this.client.delete(`/contacts/${id}`, { projectId });
251
+ }
252
+ async bulkImport(params) {
253
+ return this.client.post("/contacts/bulk", params);
254
+ }
255
+ async getBulkImportStatus(jobId) {
256
+ return this.client.get(`/contacts/bulk/${jobId}`);
257
+ }
258
+ async changeStatus(params) {
259
+ return this.client.post("/contacts/status", params);
260
+ }
261
+ };
262
+
263
+ // src/resources/tags.ts
264
+ var Tags = class {
265
+ constructor(client) {
266
+ this.client = client;
267
+ }
268
+ async list(params) {
269
+ const { projectId, page, limit, search, sortBy, sortOrder } = params;
270
+ return this.client.getWithCount("/tags", {
271
+ projectId,
272
+ page,
273
+ limit,
274
+ search,
275
+ sortBy,
276
+ sortOrder
277
+ });
278
+ }
279
+ async create(params) {
280
+ return this.client.post("/tags", params);
281
+ }
282
+ async get(id, projectId) {
283
+ return this.client.get(`/tags/${id}`, { projectId });
284
+ }
285
+ async update(id, params) {
286
+ return this.client.patch(`/tags/${id}`, params);
287
+ }
288
+ async remove(id, projectId) {
289
+ return this.client.delete(`/tags/${id}`, { projectId });
290
+ }
291
+ };
292
+
293
+ // src/resources/segments.ts
294
+ var Segments = class {
295
+ constructor(client) {
296
+ this.client = client;
297
+ }
298
+ async list(projectId) {
299
+ return this.client.getWithCount("/segments", {
300
+ projectId
301
+ });
302
+ }
303
+ async create(params) {
304
+ return this.client.post("/segments", params);
305
+ }
306
+ async get(id, projectId) {
307
+ return this.client.get(`/segments/${id}`, { projectId });
308
+ }
309
+ async update(id, params) {
310
+ return this.client.patch(`/segments/${id}`, params);
311
+ }
312
+ async remove(id, projectId) {
313
+ return this.client.delete(`/segments/${id}`, { projectId });
314
+ }
315
+ };
316
+
317
+ // src/resources/topics.ts
318
+ var Topics = class {
319
+ constructor(client) {
320
+ this.client = client;
321
+ }
322
+ async list(params) {
323
+ const { projectId, includeInactive } = params;
324
+ return this.client.getWithCount("/topics", {
325
+ projectId,
326
+ includeInactive
327
+ });
328
+ }
329
+ async create(params) {
330
+ return this.client.post("/topics", params);
331
+ }
332
+ async get(id, projectId) {
333
+ return this.client.get(`/topics/${id}`, { projectId });
334
+ }
335
+ async update(id, params) {
336
+ return this.client.patch(`/topics/${id}`, params);
337
+ }
338
+ async remove(id, projectId) {
339
+ return this.client.delete(`/topics/${id}`, { projectId });
340
+ }
341
+ async subscribe(topicId, params) {
342
+ return this.client.post(
343
+ `/topics/${topicId}/subscribe`,
344
+ params
345
+ );
346
+ }
347
+ async unsubscribe(topicId, params) {
348
+ return this.client.post(
349
+ `/topics/${topicId}/unsubscribe`,
350
+ params
351
+ );
352
+ }
353
+ };
354
+
355
+ // src/resources/sending.ts
356
+ var Sending = class {
357
+ constructor(client) {
358
+ this.client = client;
359
+ }
360
+ async send(params) {
361
+ return this.client.post("/sending", params);
362
+ }
363
+ async getBatchStatus(batchId) {
364
+ return this.client.get(`/sending/batches/${batchId}`);
365
+ }
366
+ };
367
+
368
+ // src/polling.ts
369
+ async function poll(fetcher, isComplete, options) {
370
+ const interval = options?.interval ?? 2e3;
371
+ const maxAttempts = options?.maxAttempts ?? 150;
372
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
373
+ if (options?.signal?.aborted) {
374
+ return {
375
+ data: null,
376
+ error: new MigmaError("Polling aborted", 0, "timeout" /* TIMEOUT */)
377
+ };
378
+ }
379
+ const result = await fetcher();
380
+ if (result.error) {
381
+ return result;
382
+ }
383
+ options?.onPoll?.(result.data, attempt);
384
+ if (isComplete(result.data)) {
385
+ return result;
386
+ }
387
+ await new Promise((resolve) => {
388
+ const timer = setTimeout(resolve, interval);
389
+ if (options?.signal) {
390
+ const onAbort = () => {
391
+ clearTimeout(timer);
392
+ resolve();
393
+ };
394
+ options.signal.addEventListener("abort", onAbort, { once: true });
395
+ }
396
+ });
397
+ }
398
+ return {
399
+ data: null,
400
+ error: new MigmaError(
401
+ "Polling timed out after maximum attempts",
402
+ 0,
403
+ "timeout" /* TIMEOUT */
404
+ )
405
+ };
406
+ }
407
+
408
+ // src/resources/projects.ts
409
+ var Projects = class {
410
+ constructor(client) {
411
+ this.client = client;
412
+ }
413
+ async list(params) {
414
+ return this.client.get("/projects", {
415
+ limit: params?.limit,
416
+ offset: params?.offset,
417
+ status: params?.status
418
+ });
419
+ }
420
+ async get(projectId) {
421
+ return this.client.get(`/projects/${projectId}`);
422
+ }
423
+ async import(params) {
424
+ return this.client.post(
425
+ "/projects/import",
426
+ params
427
+ );
428
+ }
429
+ async getImportStatus(projectId) {
430
+ return this.client.get(
431
+ `/projects/import/${projectId}/status`
432
+ );
433
+ }
434
+ async retryImport(projectId) {
435
+ return this.client.post(
436
+ `/projects/import/${projectId}/retry`
437
+ );
438
+ }
439
+ /**
440
+ * Import a project and wait for completion.
441
+ * Polls getImportStatus until status is 'active' or 'error'.
442
+ */
443
+ async importAndWait(params, options) {
444
+ const startResult = await this.import(params);
445
+ if (startResult.error) {
446
+ return { data: null, error: startResult.error };
447
+ }
448
+ const projectId = startResult.data.projectId;
449
+ return poll(
450
+ () => this.getImportStatus(projectId),
451
+ (status) => status.status === "active" || status.status === "error",
452
+ options
453
+ );
454
+ }
455
+ };
456
+
457
+ // src/resources/emails.ts
458
+ var Emails = class {
459
+ constructor(client) {
460
+ this.client = client;
461
+ }
462
+ /** Start async email generation */
463
+ async generate(params) {
464
+ return this.client.post(
465
+ "/projects/emails/generate",
466
+ params
467
+ );
468
+ }
469
+ /** Check email generation status */
470
+ async getGenerationStatus(conversationId) {
471
+ return this.client.get(
472
+ `/projects/emails/${conversationId}/status`
473
+ );
474
+ }
475
+ /**
476
+ * Generate an email and wait for completion.
477
+ * Polls getGenerationStatus until status is 'completed' or 'failed'.
478
+ */
479
+ async generateAndWait(params, options) {
480
+ const startResult = await this.generate(params);
481
+ if (startResult.error) {
482
+ return { data: null, error: startResult.error };
483
+ }
484
+ const conversationId = startResult.data.conversationId;
485
+ return poll(
486
+ () => this.getGenerationStatus(conversationId),
487
+ (status) => status.status === "completed" || status.status === "failed",
488
+ options
489
+ );
490
+ }
491
+ /** Send a test email from a completed conversation */
492
+ async sendTest(params) {
493
+ return this.client.post(
494
+ "/emails/test/send",
495
+ params
496
+ );
497
+ }
498
+ };
499
+
500
+ // src/resources/validation.ts
501
+ var Validation = class {
502
+ constructor(client) {
503
+ this.client = client;
504
+ }
505
+ async all(params) {
506
+ return this.client.post(
507
+ "/emails/validate/all",
508
+ params
509
+ );
510
+ }
511
+ async compatibility(params) {
512
+ return this.client.post(
513
+ "/emails/validate/compatibility",
514
+ params
515
+ );
516
+ }
517
+ async links(params) {
518
+ return this.client.post(
519
+ "/emails/validate/links",
520
+ params
521
+ );
522
+ }
523
+ async spelling(params) {
524
+ return this.client.post(
525
+ "/emails/validate/spelling",
526
+ params
527
+ );
528
+ }
529
+ async deliverability(params) {
530
+ return this.client.post(
531
+ "/emails/validate/deliverability",
532
+ params
533
+ );
534
+ }
535
+ };
536
+
537
+ // src/resources/previews.ts
538
+ var Previews = class {
539
+ constructor(client) {
540
+ this.client = client;
541
+ }
542
+ async create(params) {
543
+ return this.client.post(
544
+ "/emails/previews",
545
+ params
546
+ );
547
+ }
548
+ async get(previewId) {
549
+ return this.client.get(`/emails/previews/${previewId}`);
550
+ }
551
+ async getStatus(previewId) {
552
+ return this.client.get(
553
+ `/emails/previews/${previewId}/status`
554
+ );
555
+ }
556
+ async getDevice(previewId, deviceKey) {
557
+ return this.client.get(
558
+ `/emails/previews/${previewId}/devices/${deviceKey}`
559
+ );
560
+ }
561
+ async getSupportedDevices() {
562
+ return this.client.get(
563
+ "/emails/devices/supported"
564
+ );
565
+ }
566
+ /**
567
+ * Create a preview and wait for completion.
568
+ * Polls getStatus until status is 'COMPLETED', 'PARTIAL_SUCCESS', or 'FAILED'.
569
+ */
570
+ async createAndWait(params, options) {
571
+ const startResult = await this.create(params);
572
+ if (startResult.error) {
573
+ return { data: null, error: startResult.error };
574
+ }
575
+ const previewId = startResult.data.previewId;
576
+ return poll(
577
+ () => this.get(previewId),
578
+ (preview) => preview.status === "COMPLETED" || preview.status === "PARTIAL_SUCCESS" || preview.status === "FAILED",
579
+ options
580
+ );
581
+ }
582
+ };
583
+
584
+ // src/resources/export.ts
585
+ var Export = class {
586
+ constructor(client) {
587
+ this.client = client;
588
+ }
589
+ async getFormats() {
590
+ return this.client.get("/export/formats");
591
+ }
592
+ async getStatus(conversationId) {
593
+ return this.client.get(
594
+ `/export/status/${conversationId}`
595
+ );
596
+ }
597
+ async html(conversationId) {
598
+ return this.client.get(`/export/html/${conversationId}`);
599
+ }
600
+ async mjml(conversationId) {
601
+ return this.client.get(`/export/mjml/${conversationId}`);
602
+ }
603
+ async pdf(conversationId) {
604
+ return this.client.get(`/export/pdf/${conversationId}`);
605
+ }
606
+ async klaviyo(conversationId, klaviyoType) {
607
+ return this.client.get(
608
+ `/export/klaviyo/${conversationId}`,
609
+ { klaviyoType }
610
+ );
611
+ }
612
+ async mailchimp(conversationId) {
613
+ return this.client.get(`/export/mailchimp/${conversationId}`);
614
+ }
615
+ async hubspot(params) {
616
+ return this.client.post(
617
+ "/export/hubspot",
618
+ params
619
+ );
620
+ }
621
+ };
622
+
623
+ // src/resources/domains.ts
624
+ var Domains = class {
625
+ constructor(client) {
626
+ this.client = client;
627
+ }
628
+ async list() {
629
+ return this.client.get("/domains");
630
+ }
631
+ async create(params) {
632
+ return this.client.post("/domains", params);
633
+ }
634
+ async get(domain) {
635
+ return this.client.get(`/domains/${domain}`);
636
+ }
637
+ async verify(domain) {
638
+ return this.client.post(`/domains/${domain}/verify`);
639
+ }
640
+ async update(domain, params) {
641
+ return this.client.patch(`/domains/${domain}`, params);
642
+ }
643
+ async remove(domain) {
644
+ return this.client.delete(`/domains/${domain}`);
645
+ }
646
+ async checkAvailability(prefix) {
647
+ return this.client.get(`/domains/managed/check/${prefix}`);
648
+ }
649
+ async listManaged() {
650
+ return this.client.get("/domains/managed");
651
+ }
652
+ async createManaged(params) {
653
+ return this.client.post("/domains/managed", params);
654
+ }
655
+ async removeManaged(domain) {
656
+ return this.client.delete(`/domains/managed/${domain}`);
657
+ }
658
+ };
659
+
660
+ // src/resources/webhooks.ts
661
+ var Webhooks = class {
662
+ constructor(client) {
663
+ this.client = client;
664
+ }
665
+ async list() {
666
+ return this.client.get("/webhooks");
667
+ }
668
+ async create(params) {
669
+ return this.client.post("/webhooks", params);
670
+ }
671
+ async get(webhookId) {
672
+ return this.client.get(`/webhooks/${webhookId}`);
673
+ }
674
+ async update(webhookId, params) {
675
+ return this.client.patch(
676
+ `/webhooks/${webhookId}`,
677
+ params
678
+ );
679
+ }
680
+ async remove(webhookId) {
681
+ return this.client.delete(`/webhooks/${webhookId}`);
682
+ }
683
+ async test(webhookId) {
684
+ return this.client.post(`/webhooks/${webhookId}/test`);
685
+ }
686
+ async getDeliveries(webhookId, limit) {
687
+ return this.client.get(
688
+ `/webhooks/${webhookId}/deliveries`,
689
+ { limit }
690
+ );
691
+ }
692
+ async getEvents() {
693
+ return this.client.get("/webhooks/events");
694
+ }
695
+ async getStats() {
696
+ return this.client.get("/webhooks/stats");
697
+ }
698
+ };
699
+
700
+ // src/resources/knowledge-base.ts
701
+ var KnowledgeBase = class {
702
+ constructor(client) {
703
+ this.client = client;
704
+ }
705
+ async list(projectId) {
706
+ return this.client.get(
707
+ `/projects/${projectId}/knowledge-base`
708
+ );
709
+ }
710
+ async add(projectId, params) {
711
+ return this.client.post(
712
+ `/projects/${projectId}/knowledge-base`,
713
+ params
714
+ );
715
+ }
716
+ async update(projectId, entryId, params) {
717
+ return this.client.put(
718
+ `/projects/${projectId}/knowledge-base/${entryId}`,
719
+ params
720
+ );
721
+ }
722
+ async remove(projectId, entryId) {
723
+ return this.client.delete(
724
+ `/projects/${projectId}/knowledge-base/${entryId}`
725
+ );
726
+ }
727
+ };
728
+
729
+ // src/resources/images.ts
730
+ var Images = class {
731
+ constructor(client) {
732
+ this.client = client;
733
+ }
734
+ async add(projectId, params) {
735
+ return this.client.post(
736
+ `/projects/${projectId}/images`,
737
+ params
738
+ );
739
+ }
740
+ async update(projectId, params) {
741
+ return this.client.put(
742
+ `/projects/${projectId}/images`,
743
+ params
744
+ );
745
+ }
746
+ async remove(projectId, imageUrl) {
747
+ return this.client.delete(
748
+ `/projects/${projectId}/images`,
749
+ { imageUrl }
750
+ );
751
+ }
752
+ async updateLogos(projectId, params) {
753
+ return this.client.put(
754
+ `/projects/${projectId}/logos`,
755
+ params
756
+ );
757
+ }
758
+ };
759
+
760
+ // src/migma.ts
761
+ var Migma = class {
762
+ client;
763
+ contacts;
764
+ tags;
765
+ segments;
766
+ topics;
767
+ sending;
768
+ projects;
769
+ emails;
770
+ validation;
771
+ previews;
772
+ export;
773
+ domains;
774
+ webhooks;
775
+ knowledgeBase;
776
+ images;
777
+ constructor(apiKey, config) {
778
+ if (!apiKey) {
779
+ throw new Error(
780
+ 'Missing API key. Pass it to the constructor: `new Migma("your-api-key")`'
781
+ );
782
+ }
783
+ this.client = new MigmaClient(apiKey, {
784
+ baseUrl: config?.baseUrl ?? "https://api.migma.ai/api/v1",
785
+ timeout: config?.timeout ?? 3e4,
786
+ maxRetries: config?.maxRetries ?? 2,
787
+ retryDelay: config?.retryDelay ?? 1e3
788
+ });
789
+ this.contacts = new Contacts(this.client);
790
+ this.tags = new Tags(this.client);
791
+ this.segments = new Segments(this.client);
792
+ this.topics = new Topics(this.client);
793
+ this.sending = new Sending(this.client);
794
+ this.projects = new Projects(this.client);
795
+ this.emails = new Emails(this.client);
796
+ this.validation = new Validation(this.client);
797
+ this.previews = new Previews(this.client);
798
+ this.export = new Export(this.client);
799
+ this.domains = new Domains(this.client);
800
+ this.webhooks = new Webhooks(this.client);
801
+ this.knowledgeBase = new KnowledgeBase(this.client);
802
+ this.images = new Images(this.client);
803
+ }
804
+ };
805
+
806
+ exports.Migma = Migma;
807
+ exports.MigmaClient = MigmaClient;
808
+ exports.MigmaError = MigmaError;
809
+ exports.MigmaErrorCode = MigmaErrorCode;
810
+ exports.poll = poll;
811
+ //# sourceMappingURL=index.js.map
812
+ //# sourceMappingURL=index.js.map