migma 1.8.1 → 1.10.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/README.md +61 -3
- package/dist/index.d.mts +224 -60
- package/dist/index.d.ts +224 -60
- package/dist/index.js +71 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -61,9 +61,12 @@ interface RequestOptions {
|
|
|
61
61
|
body?: Record<string, unknown>;
|
|
62
62
|
query?: Record<string, string | number | boolean | undefined>;
|
|
63
63
|
headers?: Record<string, string>;
|
|
64
|
+
maxRetries?: number;
|
|
64
65
|
}
|
|
65
66
|
/** Per-call options for write methods (POST/PATCH/DELETE). */
|
|
66
67
|
interface CallOptions {
|
|
68
|
+
/** Override automatic retries for this call. Use 0 for unsafe writes. */
|
|
69
|
+
maxRetries?: number;
|
|
67
70
|
/**
|
|
68
71
|
* Optional Idempotency-Key (max 100 chars). Same key + same body within 24h
|
|
69
72
|
* replays the original response; a different body returns 409 IDEMPOTENCY_CONFLICT.
|
|
@@ -100,6 +103,64 @@ declare class MigmaClient {
|
|
|
100
103
|
private sleep;
|
|
101
104
|
}
|
|
102
105
|
|
|
106
|
+
interface SegmentFieldFilter {
|
|
107
|
+
key: string;
|
|
108
|
+
/** Exact/pattern, date, or numeric comparison. Date/number comparisons use one
|
|
109
|
+
* value; date_between/number_between use two ordered bounds. */
|
|
110
|
+
mode?: 'is' | 'is_not' | 'starts_with' | 'ends_with' | 'contains' | 'not_contains' | 'date_after' | 'date_before' | 'date_on' | 'date_between' | 'number_gt' | 'number_gte' | 'number_lt' | 'number_lte' | 'number_between';
|
|
111
|
+
values: string[];
|
|
112
|
+
}
|
|
113
|
+
interface SegmentActivityFilter {
|
|
114
|
+
action: 'sent' | 'opened' | 'clicked';
|
|
115
|
+
channel?: 'email';
|
|
116
|
+
mode: 'within' | 'before' | 'never' | 'between';
|
|
117
|
+
unit?: 'hours' | 'days';
|
|
118
|
+
amount?: number;
|
|
119
|
+
from?: string | Date;
|
|
120
|
+
to?: string | Date;
|
|
121
|
+
campaignId?: string;
|
|
122
|
+
}
|
|
123
|
+
interface SegmentFilters {
|
|
124
|
+
/** Combines this group's conditions and child groups. Defaults to all (AND).
|
|
125
|
+
* Campaign-scoped activity requires all in its group and every ancestor. */
|
|
126
|
+
match?: 'all' | 'any';
|
|
127
|
+
/** Nonempty child groups: at most 10 per group, 3 levels below the root,
|
|
128
|
+
* and 50 conditions across the entire filter tree. The root may be empty. */
|
|
129
|
+
groups?: SegmentFilters[];
|
|
130
|
+
tags?: string[];
|
|
131
|
+
excludeTags?: string[];
|
|
132
|
+
status?: 'subscribed' | 'unsubscribed' | 'non-subscribed' | 'bounced';
|
|
133
|
+
validationStatus?: 'valid' | 'invalid' | 'risky' | 'unknown';
|
|
134
|
+
customFields?: Record<string, string[]>;
|
|
135
|
+
fields?: SegmentFieldFilter[];
|
|
136
|
+
activity?: SegmentActivityFilter[];
|
|
137
|
+
}
|
|
138
|
+
interface Segment {
|
|
139
|
+
id: string;
|
|
140
|
+
name: string;
|
|
141
|
+
description: string;
|
|
142
|
+
filters: SegmentFilters;
|
|
143
|
+
count: number;
|
|
144
|
+
createdAt: string;
|
|
145
|
+
updatedAt: string;
|
|
146
|
+
}
|
|
147
|
+
interface CreateSegmentParams {
|
|
148
|
+
name: string;
|
|
149
|
+
description?: string;
|
|
150
|
+
filters?: SegmentFilters;
|
|
151
|
+
projectId: string;
|
|
152
|
+
}
|
|
153
|
+
interface UpdateSegmentParams {
|
|
154
|
+
name?: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
filters?: SegmentFilters;
|
|
157
|
+
projectId: string;
|
|
158
|
+
}
|
|
159
|
+
interface ListSegmentsResponse {
|
|
160
|
+
data: Segment[];
|
|
161
|
+
count: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
103
164
|
type ContactStatus = 'subscribed' | 'unsubscribed' | 'bounced' | 'non-subscribed';
|
|
104
165
|
interface Contact {
|
|
105
166
|
id: string;
|
|
@@ -209,6 +270,64 @@ interface ChangeStatusParams {
|
|
|
209
270
|
tags?: string[];
|
|
210
271
|
projectId: string;
|
|
211
272
|
}
|
|
273
|
+
interface CreateContactExportParams {
|
|
274
|
+
projectId: string;
|
|
275
|
+
segmentId?: string;
|
|
276
|
+
/** Same filters used by saved segments; tags are IDs, not names. */
|
|
277
|
+
filters?: SegmentFilters & {
|
|
278
|
+
search?: string;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
interface ContactExportStatus {
|
|
282
|
+
jobId: string;
|
|
283
|
+
projectId: string;
|
|
284
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
285
|
+
contactCount: number;
|
|
286
|
+
fileName: string;
|
|
287
|
+
createdAt: string;
|
|
288
|
+
completedAt: string | null;
|
|
289
|
+
/** Present only after the private CSV has been uploaded. Expires after one hour. */
|
|
290
|
+
downloadUrl?: string;
|
|
291
|
+
downloadExpiresAt?: string;
|
|
292
|
+
error?: string;
|
|
293
|
+
}
|
|
294
|
+
type ContactImportProvider = 'klaviyo' | 'mailchimp' | 'hubspot';
|
|
295
|
+
/** A list or segment in the connected provider account that can be imported. */
|
|
296
|
+
interface ProviderImportSource {
|
|
297
|
+
id: string;
|
|
298
|
+
type: 'audience' | 'segment' | 'tag' | 'list';
|
|
299
|
+
name: string;
|
|
300
|
+
[key: string]: unknown;
|
|
301
|
+
}
|
|
302
|
+
interface ListProviderImportSourcesParams {
|
|
303
|
+
provider: ContactImportProvider;
|
|
304
|
+
projectId: string;
|
|
305
|
+
/** Only when the brand has several accounts connected for this provider. */
|
|
306
|
+
connectionId?: string;
|
|
307
|
+
}
|
|
308
|
+
interface ImportFromProviderParams {
|
|
309
|
+
provider: ContactImportProvider;
|
|
310
|
+
projectId: string;
|
|
311
|
+
/** 1 to 25 sources from listProviderImportSources. */
|
|
312
|
+
sources: Pick<ProviderImportSource, 'id' | 'type' | 'name'>[];
|
|
313
|
+
/** Default subscribed-only. */
|
|
314
|
+
consentMode?: 'subscribed-only' | 'include-all';
|
|
315
|
+
connectionId?: string;
|
|
316
|
+
}
|
|
317
|
+
/** Each import becomes a tag and a segment named after its sources. Poll the import with its id. */
|
|
318
|
+
interface ProviderImportStarted {
|
|
319
|
+
object: 'contact_import';
|
|
320
|
+
id: string;
|
|
321
|
+
status: 'pending';
|
|
322
|
+
tag: {
|
|
323
|
+
id: string;
|
|
324
|
+
name: string;
|
|
325
|
+
};
|
|
326
|
+
segment: {
|
|
327
|
+
id: string;
|
|
328
|
+
name: string;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
212
331
|
|
|
213
332
|
declare class Contacts {
|
|
214
333
|
private readonly client;
|
|
@@ -222,6 +341,15 @@ declare class Contacts {
|
|
|
222
341
|
getBulkImportStatus(jobId: string): Promise<MigmaResult<BulkImportJobStatus>>;
|
|
223
342
|
/** Batch delete contacts by email (up to 1000). Emails with no match come back in `notFound`. */
|
|
224
343
|
bulkDeleteByEmail(params: BatchDeleteContactsParams, options?: CallOptions): Promise<MigmaResult<BatchDeleteResponse>>;
|
|
344
|
+
/** Queue a filtered CSV export. Poll getExport; do not list every contact to build a CSV. */
|
|
345
|
+
createExport(params: CreateContactExportParams, options?: CallOptions): Promise<MigmaResult<ContactExportStatus>>;
|
|
346
|
+
getExport(jobId: string, projectId: string): Promise<MigmaResult<ContactExportStatus>>;
|
|
347
|
+
/** Lists and segments in the brand's connected Klaviyo, Mailchimp or HubSpot account. A 409 error message includes the link to connect it. */
|
|
348
|
+
listProviderImportSources(params: ListProviderImportSourcesParams): Promise<MigmaResult<{
|
|
349
|
+
sources: ProviderImportSource[];
|
|
350
|
+
}>>;
|
|
351
|
+
/** Import provider sources as contacts (subscribed only by default). Poll GET /contacts/imports/{id} for counts. */
|
|
352
|
+
importFromProvider(params: ImportFromProviderParams, options?: CallOptions): Promise<MigmaResult<ProviderImportStarted>>;
|
|
225
353
|
changeStatus(params: ChangeStatusParams, options?: CallOptions): Promise<MigmaResult<{
|
|
226
354
|
success: boolean;
|
|
227
355
|
}>>;
|
|
@@ -272,59 +400,6 @@ declare class Tags {
|
|
|
272
400
|
remove(id: string, projectId: string): Promise<MigmaResult<DeleteResponse>>;
|
|
273
401
|
}
|
|
274
402
|
|
|
275
|
-
interface SegmentFieldFilter {
|
|
276
|
-
key: string;
|
|
277
|
-
/** Exact match (is/is_not) or pattern match (starts_with/ends_with/contains/not_contains,
|
|
278
|
-
* compiled to anchored case-insensitive regex). Pattern modes keep a value group
|
|
279
|
-
* like "email ends_with .vc" accurate as new contacts arrive. */
|
|
280
|
-
mode?: 'is' | 'is_not' | 'starts_with' | 'ends_with' | 'contains' | 'not_contains';
|
|
281
|
-
values: string[];
|
|
282
|
-
}
|
|
283
|
-
interface SegmentActivityFilter {
|
|
284
|
-
action: 'sent' | 'opened' | 'clicked';
|
|
285
|
-
channel?: 'email';
|
|
286
|
-
mode: 'within' | 'before' | 'never' | 'between';
|
|
287
|
-
unit?: 'hours' | 'days';
|
|
288
|
-
amount?: number;
|
|
289
|
-
from?: string | Date;
|
|
290
|
-
to?: string | Date;
|
|
291
|
-
campaignId?: string;
|
|
292
|
-
}
|
|
293
|
-
interface SegmentFilters {
|
|
294
|
-
tags?: string[];
|
|
295
|
-
excludeTags?: string[];
|
|
296
|
-
status?: 'subscribed' | 'unsubscribed' | 'non-subscribed' | 'bounced';
|
|
297
|
-
validationStatus?: 'valid' | 'invalid' | 'risky' | 'unknown';
|
|
298
|
-
customFields?: Record<string, string[]>;
|
|
299
|
-
fields?: SegmentFieldFilter[];
|
|
300
|
-
activity?: SegmentActivityFilter[];
|
|
301
|
-
}
|
|
302
|
-
interface Segment {
|
|
303
|
-
id: string;
|
|
304
|
-
name: string;
|
|
305
|
-
description: string;
|
|
306
|
-
filters: SegmentFilters;
|
|
307
|
-
count: number;
|
|
308
|
-
createdAt: string;
|
|
309
|
-
updatedAt: string;
|
|
310
|
-
}
|
|
311
|
-
interface CreateSegmentParams {
|
|
312
|
-
name: string;
|
|
313
|
-
description?: string;
|
|
314
|
-
filters?: SegmentFilters;
|
|
315
|
-
projectId: string;
|
|
316
|
-
}
|
|
317
|
-
interface UpdateSegmentParams {
|
|
318
|
-
name?: string;
|
|
319
|
-
description?: string;
|
|
320
|
-
filters?: SegmentFilters;
|
|
321
|
-
projectId: string;
|
|
322
|
-
}
|
|
323
|
-
interface ListSegmentsResponse {
|
|
324
|
-
data: Segment[];
|
|
325
|
-
count: number;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
403
|
declare class Segments {
|
|
329
404
|
private readonly client;
|
|
330
405
|
constructor(client: MigmaClient);
|
|
@@ -472,6 +547,38 @@ declare class Sending {
|
|
|
472
547
|
getBatchStatus(batchId: string): Promise<MigmaResult<BatchStatus>>;
|
|
473
548
|
}
|
|
474
549
|
|
|
550
|
+
interface ConnectedToolScope {
|
|
551
|
+
projectId: string;
|
|
552
|
+
serverId: string;
|
|
553
|
+
toolName: string;
|
|
554
|
+
}
|
|
555
|
+
interface ListConnectedToolsParams {
|
|
556
|
+
projectId: string;
|
|
557
|
+
search?: string;
|
|
558
|
+
offset?: number;
|
|
559
|
+
limit?: number;
|
|
560
|
+
}
|
|
561
|
+
interface ConnectedToolSummary {
|
|
562
|
+
name: string;
|
|
563
|
+
serverId: string;
|
|
564
|
+
description: string;
|
|
565
|
+
requiresApproval: boolean;
|
|
566
|
+
annotations?: Record<string, unknown>;
|
|
567
|
+
}
|
|
568
|
+
interface ConnectedToolSchema extends ConnectedToolSummary {
|
|
569
|
+
inputSchema: Record<string, unknown>;
|
|
570
|
+
}
|
|
571
|
+
interface ListConnectedToolsResponse {
|
|
572
|
+
tools: ConnectedToolSummary[];
|
|
573
|
+
total: number;
|
|
574
|
+
nextOffset: number | null;
|
|
575
|
+
unreachableServers: string[];
|
|
576
|
+
authRequired: Array<{
|
|
577
|
+
serverId: string;
|
|
578
|
+
authUrl: string;
|
|
579
|
+
}>;
|
|
580
|
+
}
|
|
581
|
+
|
|
475
582
|
interface Project {
|
|
476
583
|
_id: string;
|
|
477
584
|
name: string;
|
|
@@ -620,6 +727,12 @@ declare class Projects {
|
|
|
620
727
|
references(projectId: string): Promise<MigmaResult<ProjectReferencesResponse>>;
|
|
621
728
|
retryImport(projectId: string): Promise<MigmaResult<RetryImportResponse>>;
|
|
622
729
|
fieldCatalog(projectId: string, params?: FieldCatalogParams): Promise<MigmaResult<FieldCatalogResponse>>;
|
|
730
|
+
listConnectedTools(params: ListConnectedToolsParams): Promise<MigmaResult<ListConnectedToolsResponse>>;
|
|
731
|
+
getConnectedTool(params: ConnectedToolScope): Promise<MigmaResult<ConnectedToolSchema>>;
|
|
732
|
+
/** Never automatically replay external writes; provider outcome can be unknown. */
|
|
733
|
+
callConnectedTool(params: ConnectedToolScope & {
|
|
734
|
+
parameters: Record<string, unknown>;
|
|
735
|
+
}): Promise<MigmaResult<unknown>>;
|
|
623
736
|
/**
|
|
624
737
|
* Import a project and wait for completion.
|
|
625
738
|
* Polls getImportStatus until status is 'active' or 'error'.
|
|
@@ -773,6 +886,21 @@ interface EditEmailParams {
|
|
|
773
886
|
prompt: string;
|
|
774
887
|
label?: string;
|
|
775
888
|
}
|
|
889
|
+
interface EmailEditOperation {
|
|
890
|
+
editId: string;
|
|
891
|
+
emailId: string;
|
|
892
|
+
conversationId: string;
|
|
893
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
894
|
+
stage: string;
|
|
895
|
+
createdAt: string;
|
|
896
|
+
updatedAt: string;
|
|
897
|
+
pollAfterMs: number;
|
|
898
|
+
error?: string;
|
|
899
|
+
/** Inspect the saved email before starting another edit after a failure. */
|
|
900
|
+
changesMayHaveBeenSaved?: boolean;
|
|
901
|
+
/** Current saved email, included by getEditStatus after completion. */
|
|
902
|
+
result?: Email;
|
|
903
|
+
}
|
|
776
904
|
interface EmailMetricsSummary {
|
|
777
905
|
totalEmails: number;
|
|
778
906
|
delivered: number;
|
|
@@ -875,8 +1003,12 @@ declare class Emails {
|
|
|
875
1003
|
getGenerationStatus(conversationId: string): Promise<MigmaResult<EmailGenerationStatus>>;
|
|
876
1004
|
/** Fetch one generated email by email id */
|
|
877
1005
|
get(emailId: string): Promise<MigmaResult<Email>>;
|
|
878
|
-
/**
|
|
1006
|
+
/** Synchronous edit. No automatic retries; use startEdit for long edits. */
|
|
879
1007
|
edit(emailId: string, params: EditEmailParams): Promise<MigmaResult<Email>>;
|
|
1008
|
+
/** Queue an edit immediately. Retain an explicit key to recover uncertain submissions. */
|
|
1009
|
+
startEdit(emailId: string, params: EditEmailParams, options?: CallOptions): Promise<MigmaResult<EmailEditOperation>>;
|
|
1010
|
+
/** Poll the exact edit; a completed conversation may belong to an earlier turn. */
|
|
1011
|
+
getEditStatus(emailId: string, editId: string): Promise<MigmaResult<EmailEditOperation>>;
|
|
880
1012
|
/**
|
|
881
1013
|
* Generate an email and wait for completion.
|
|
882
1014
|
* Polls getGenerationStatus until status is 'completed' or 'failed'.
|
|
@@ -1182,6 +1314,8 @@ interface Domain {
|
|
|
1182
1314
|
status: string;
|
|
1183
1315
|
isVerified?: boolean;
|
|
1184
1316
|
dnsRecords?: DnsRecord[];
|
|
1317
|
+
/** Set while a custom domain cannot send yet: a Migma page that starts one-click DNS setup. */
|
|
1318
|
+
connectUrl?: string;
|
|
1185
1319
|
trackingSettings?: {
|
|
1186
1320
|
openTracking?: boolean;
|
|
1187
1321
|
clickTracking?: boolean;
|
|
@@ -1386,16 +1520,20 @@ interface CreditStatus {
|
|
|
1386
1520
|
type UpgradePlan = 'basic' | 'premium' | 'business' | 'basic_annual' | 'premium_annual' | 'business_annual';
|
|
1387
1521
|
interface UpgradeLinkParams {
|
|
1388
1522
|
/**
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1523
|
+
* User-chosen plan for new subscription checkout. Omit for an existing
|
|
1524
|
+
* Stripe customer's billing portal. Passing plan for an active subscription
|
|
1525
|
+
* can change it and charge immediately; requires explicit charge approval.
|
|
1391
1526
|
*/
|
|
1392
1527
|
plan?: UpgradePlan;
|
|
1393
1528
|
}
|
|
1394
1529
|
interface UpgradeLink {
|
|
1395
|
-
/**
|
|
1530
|
+
/** Checkout, invoice, confirmation, or portal URL; not proof of payment. */
|
|
1396
1531
|
url: string;
|
|
1532
|
+
/** checkout includes an existing plan-change result; portal is the billing portal. */
|
|
1397
1533
|
kind: 'checkout' | 'portal';
|
|
1534
|
+
/** Present when a new Stripe Checkout session was created. */
|
|
1398
1535
|
sessionId?: string;
|
|
1536
|
+
/** Migma checkout order id or Stripe invoice id for an existing plan change. */
|
|
1399
1537
|
orderId?: string;
|
|
1400
1538
|
}
|
|
1401
1539
|
|
|
@@ -1405,8 +1543,10 @@ declare class Billing {
|
|
|
1405
1543
|
/** Plan and remaining credits for the API key owner. */
|
|
1406
1544
|
credits(): Promise<MigmaResult<CreditStatus>>;
|
|
1407
1545
|
/**
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1546
|
+
* Create checkout for a user-chosen new plan, or omit plan for the existing
|
|
1547
|
+
* customer's billing portal. Passing plan for an active subscription can
|
|
1548
|
+
* change it and charge prorated payment immediately; obtain charge approval.
|
|
1549
|
+
* The returned URL alone does not confirm payment. Do not retry unknown writes.
|
|
1410
1550
|
*/
|
|
1411
1551
|
upgradeLink(params?: UpgradeLinkParams): Promise<MigmaResult<UpgradeLink>>;
|
|
1412
1552
|
}
|
|
@@ -1512,6 +1652,13 @@ interface KnowledgeBaseEntry {
|
|
|
1512
1652
|
thumbnailUrl?: string;
|
|
1513
1653
|
screenshotUrl?: string;
|
|
1514
1654
|
referenceOrigin?: ReferenceOrigin;
|
|
1655
|
+
sourceFileName?: string;
|
|
1656
|
+
/** Preparation runs after save; poll list() for completion. Retry failures by updating the original content. */
|
|
1657
|
+
conversion?: {
|
|
1658
|
+
status: 'pending' | 'complete' | 'failed';
|
|
1659
|
+
revision: string;
|
|
1660
|
+
error?: string;
|
|
1661
|
+
};
|
|
1515
1662
|
}
|
|
1516
1663
|
interface KnowledgeBaseListResponse {
|
|
1517
1664
|
entries: KnowledgeBaseEntry[];
|
|
@@ -1520,6 +1667,8 @@ interface KnowledgeBaseListResponse {
|
|
|
1520
1667
|
interface AddKnowledgeBaseParams {
|
|
1521
1668
|
title: string;
|
|
1522
1669
|
content: string;
|
|
1670
|
+
/** Original upload name, including .html, .eml, or .mjml; at most 255 characters. */
|
|
1671
|
+
sourceFileName?: string;
|
|
1523
1672
|
/** Set to mark the entry as a design reference generation should match. */
|
|
1524
1673
|
referenceOrigin?: ReferenceOrigin;
|
|
1525
1674
|
previewHtml?: string;
|
|
@@ -1529,6 +1678,8 @@ interface AddKnowledgeBaseParams {
|
|
|
1529
1678
|
interface UpdateKnowledgeBaseParams {
|
|
1530
1679
|
title?: string;
|
|
1531
1680
|
content?: string;
|
|
1681
|
+
/** Empty string clears the previous upload name. */
|
|
1682
|
+
sourceFileName?: string;
|
|
1532
1683
|
}
|
|
1533
1684
|
|
|
1534
1685
|
declare class KnowledgeBase {
|
|
@@ -1592,6 +1743,8 @@ interface Campaign {
|
|
|
1592
1743
|
replyTo?: string | null;
|
|
1593
1744
|
recipientType: 'audience' | 'tag';
|
|
1594
1745
|
recipientId: string;
|
|
1746
|
+
/** Present when the campaign targets more than one segment or list. */
|
|
1747
|
+
recipientIds?: string[];
|
|
1595
1748
|
topicId?: string | null;
|
|
1596
1749
|
estimatedRecipients?: number | null;
|
|
1597
1750
|
providerType: string;
|
|
@@ -1599,6 +1752,8 @@ interface Campaign {
|
|
|
1599
1752
|
status: CampaignStatus;
|
|
1600
1753
|
scheduledAt?: string | null;
|
|
1601
1754
|
scheduledTimezone?: string | null;
|
|
1755
|
+
/** True when the scheduled clock time is used in each contact's own time zone. */
|
|
1756
|
+
localTimeDelivery?: boolean;
|
|
1602
1757
|
batchId?: string | null;
|
|
1603
1758
|
sentAt?: string | null;
|
|
1604
1759
|
completedAt?: string | null;
|
|
@@ -1622,6 +1777,8 @@ interface CreateCampaignParams {
|
|
|
1622
1777
|
replyTo?: string;
|
|
1623
1778
|
recipientType: 'audience' | 'tag';
|
|
1624
1779
|
recipientId: string;
|
|
1780
|
+
/** Full list of segment or list IDs of the same type. When set, this is the selection; recipientId is stored as the first id. Unique people receive one email. Max 20. */
|
|
1781
|
+
recipientIds?: string[];
|
|
1625
1782
|
topicId?: string;
|
|
1626
1783
|
providerType?: 'ses' | 'resend' | 'sendgrid' | 'mailgun' | 'migma';
|
|
1627
1784
|
variables?: Record<string, unknown>;
|
|
@@ -1640,6 +1797,13 @@ interface ListCampaignsResponse {
|
|
|
1640
1797
|
interface ScheduleCampaignParams {
|
|
1641
1798
|
scheduledAt: string;
|
|
1642
1799
|
scheduledTimezone?: string;
|
|
1800
|
+
/**
|
|
1801
|
+
* Send at the clock time of `scheduledAt` in `scheduledTimezone`, in each contact's own time zone (by country).
|
|
1802
|
+
* Requires `scheduledTimezone`. Contacts without a country get it at `scheduledAt`; where that time has passed,
|
|
1803
|
+
* the same time the next day. Not available with A/B tests or batch sending. Omit to keep the campaign's current
|
|
1804
|
+
* setting; `false` turns it off.
|
|
1805
|
+
*/
|
|
1806
|
+
localTimeDelivery?: boolean;
|
|
1643
1807
|
}
|
|
1644
1808
|
/**
|
|
1645
1809
|
* Aggregated engagement metrics for a campaign.
|
|
@@ -1816,4 +1980,4 @@ declare class Migma {
|
|
|
1816
1980
|
constructor(apiKey: string, config?: MigmaConfig);
|
|
1817
1981
|
}
|
|
1818
1982
|
|
|
1819
|
-
export { type AddCustomDnsRecordParams, type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BrandGuidelinesParams, type BrandGuidelinesResponse, type BrandImageStyle, 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 CreditStatus, type CustomDnsRecord, type CustomDnsRecordList, type CustomDnsRecordType, type DeleteResponse, type DeliverabilityResponse, type DesignReferenceItem, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainPurchaseCheckout, type DomainPurchaseParams, type DomainPurchaseQuote, type DomainPurchaseSearchParams, type DomainRegistration, type DomainRegistrationStatus, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailFavorite, 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 ImportHtmlEmailFile, type ImportHtmlEmailParams, 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 ListWorkspacesResponse, 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 ProjectReferencesResponse, type ProviderType, type ProvisionStreamParams, type RecipientType, type ReferenceOrigin, 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 UpgradeLink, type UpgradeLinkParams, type UpgradePlan, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, type Workspace, poll };
|
|
1983
|
+
export { type AddCustomDnsRecordParams, type AddImageParams, type AddKnowledgeBaseParams, type AnalyzeDeliverabilityParams, type AnalyzeLinksParams, type ApiResponse, type BatchDeleteContactsParams, type BatchDeleteResponse, type BatchStatus, type BrandGuidelinesParams, type BrandGuidelinesResponse, type BrandImageStyle, 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 ConnectedToolSchema, type ConnectedToolScope, type ConnectedToolSummary, type Contact, type ContactExportStatus, type ContactImportProvider, type ContactStatus, type CreateCampaignParams, type CreateContactExportParams, type CreateContactParams, type CreateDomainParams, type CreateManagedDomainParams, type CreatePreviewParams, type CreatePreviewResponse, type CreateSegmentParams, type CreateTagParams, type CreateTopicParams, type CreateWebhookParams, type CreateWebhookResponse, type CreditStatus, type CustomDnsRecord, type CustomDnsRecordList, type CustomDnsRecordType, type DeleteResponse, type DeliverabilityResponse, type DesignReferenceItem, type DeviceCategoriesResponse, type DnsRecord, type Domain, type DomainAvailability, type DomainDeleteResponse, type DomainPurchaseCheckout, type DomainPurchaseParams, type DomainPurchaseQuote, type DomainPurchaseSearchParams, type DomainRegistration, type DomainRegistrationStatus, type DomainStream, type DomainVerificationResult, type EditEmailParams, type Email, type EmailEditOperation, type EmailFavorite, 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 ImportFromProviderParams, type ImportHtmlEmailFile, type ImportHtmlEmailParams, type ImportProjectParams, type ImportProjectResponse, type ImportStatusResponse, type KnowledgeBaseEntry, type KnowledgeBaseListResponse, type LinkAnalysisResponse, type ListCampaignsParams, type ListCampaignsResponse, type ListConnectedToolsParams, type ListConnectedToolsResponse, type ListContactsParams, type ListContactsResponse, type ListEmailsEmail, type ListEmailsParams, type ListEmailsResponse, type ListProjectsParams, type ListProjectsResponse, type ListProviderImportSourcesParams, type ListSegmentsResponse, type ListTagsParams, type ListTagsResponse, type ListTopicsParams, type ListTopicsResponse, type ListWebhooksResponse, type ListWorkspacesResponse, 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 ProjectReferencesResponse, type ProviderImportSource, type ProviderImportStarted, type ProviderType, type ProvisionStreamParams, type RecipientType, type ReferenceOrigin, 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 UpgradeLink, type UpgradeLinkParams, type UpgradePlan, type ValidateAllParams, type ValidateAllResponse, type Webhook, type WebhookDeliveriesResponse, type WebhookDelivery, type WebhookDetail, type WebhookEvent, type WebhookEventType, type WebhookEventsResponse, type WebhookTestResult, type Workspace, poll };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
3
5
|
// src/agent-identity.ts
|
|
4
6
|
var AGENT_ID_PATTERN = /^ai:[a-z0-9][a-z0-9._-]{0,62}$/;
|
|
5
7
|
var HOST_AGENT_ENV = [
|
|
@@ -89,7 +91,7 @@ var MigmaClient = class {
|
|
|
89
91
|
}
|
|
90
92
|
async request(options) {
|
|
91
93
|
const url = this.buildUrl(options.path, options.query);
|
|
92
|
-
const attempts = this.config.maxRetries + 1;
|
|
94
|
+
const attempts = (options.maxRetries ?? this.config.maxRetries) + 1;
|
|
93
95
|
let lastError = null;
|
|
94
96
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
95
97
|
try {
|
|
@@ -98,12 +100,9 @@ var MigmaClient = class {
|
|
|
98
100
|
headers: { ...this.headers, ...options.headers },
|
|
99
101
|
body: options.body ? JSON.stringify(options.body) : void 0
|
|
100
102
|
});
|
|
101
|
-
const json = await response
|
|
102
|
-
if (!response.ok || !json
|
|
103
|
-
const error = new MigmaError(
|
|
104
|
-
json.error || `Request failed with status ${response.status}`,
|
|
105
|
-
response.status
|
|
106
|
-
);
|
|
103
|
+
const json = await readJson(response);
|
|
104
|
+
if (!response.ok || !json?.success) {
|
|
105
|
+
const error = new MigmaError(failureMessage(response, json), response.status);
|
|
107
106
|
if (response.status >= 500 || response.status === 429) {
|
|
108
107
|
lastError = error;
|
|
109
108
|
if (attempt < attempts - 1) {
|
|
@@ -141,14 +140,11 @@ var MigmaClient = class {
|
|
|
141
140
|
headers: { ...this.headers, ...options.headers },
|
|
142
141
|
body: options.body ? JSON.stringify(options.body) : void 0
|
|
143
142
|
});
|
|
144
|
-
const json = await response
|
|
145
|
-
if (!response.ok || !json
|
|
143
|
+
const json = await readJson(response);
|
|
144
|
+
if (!response.ok || !json?.success) {
|
|
146
145
|
return {
|
|
147
146
|
data: null,
|
|
148
|
-
error: new MigmaError(
|
|
149
|
-
json.error || `Request failed with status ${response.status}`,
|
|
150
|
-
response.status
|
|
151
|
-
)
|
|
147
|
+
error: new MigmaError(failureMessage(response, json), response.status)
|
|
152
148
|
};
|
|
153
149
|
}
|
|
154
150
|
return {
|
|
@@ -173,16 +169,16 @@ var MigmaClient = class {
|
|
|
173
169
|
return this.requestWithCount({ method: "GET", path, query });
|
|
174
170
|
}
|
|
175
171
|
async post(path, body, options) {
|
|
176
|
-
return this.request({ method: "POST", path, body, headers: this.callHeaders(options) });
|
|
172
|
+
return this.request({ method: "POST", path, body, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
|
|
177
173
|
}
|
|
178
174
|
async patch(path, body, options) {
|
|
179
|
-
return this.request({ method: "PATCH", path, body, headers: this.callHeaders(options) });
|
|
175
|
+
return this.request({ method: "PATCH", path, body, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
|
|
180
176
|
}
|
|
181
177
|
async put(path, body) {
|
|
182
178
|
return this.request({ method: "PUT", path, body });
|
|
183
179
|
}
|
|
184
180
|
async delete(path, query, options) {
|
|
185
|
-
return this.request({ method: "DELETE", path, query, headers: this.callHeaders(options) });
|
|
181
|
+
return this.request({ method: "DELETE", path, query, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
|
|
186
182
|
}
|
|
187
183
|
callHeaders(options) {
|
|
188
184
|
if (options?.idempotencyKey) {
|
|
@@ -213,6 +209,18 @@ var MigmaClient = class {
|
|
|
213
209
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
214
210
|
}
|
|
215
211
|
};
|
|
212
|
+
async function readJson(response) {
|
|
213
|
+
const text = await response.text();
|
|
214
|
+
try {
|
|
215
|
+
return JSON.parse(text);
|
|
216
|
+
} catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function failureMessage(response, json) {
|
|
221
|
+
if (json?.error) return json.error;
|
|
222
|
+
return json ? `Request failed with status ${response.status}` : `Request failed with status ${response.status}: the server did not return JSON`;
|
|
223
|
+
}
|
|
216
224
|
|
|
217
225
|
// src/resources/contacts.ts
|
|
218
226
|
var Contacts = class {
|
|
@@ -252,6 +260,22 @@ var Contacts = class {
|
|
|
252
260
|
async bulkDeleteByEmail(params, options) {
|
|
253
261
|
return this.client.post("/contacts/bulk-delete", params, options);
|
|
254
262
|
}
|
|
263
|
+
/** Queue a filtered CSV export. Poll getExport; do not list every contact to build a CSV. */
|
|
264
|
+
async createExport(params, options) {
|
|
265
|
+
return this.client.post("/contacts/exports", params, { ...options, maxRetries: options?.idempotencyKey ? options.maxRetries : 0 });
|
|
266
|
+
}
|
|
267
|
+
async getExport(jobId, projectId) {
|
|
268
|
+
return this.client.get(`/contacts/exports/${encodeURIComponent(jobId)}`, { projectId });
|
|
269
|
+
}
|
|
270
|
+
/** Lists and segments in the brand's connected Klaviyo, Mailchimp or HubSpot account. A 409 error message includes the link to connect it. */
|
|
271
|
+
async listProviderImportSources(params) {
|
|
272
|
+
const { provider, projectId, connectionId } = params;
|
|
273
|
+
return this.client.get(`/contacts/imports/providers/${encodeURIComponent(provider)}/sources`, { projectId, connectionId });
|
|
274
|
+
}
|
|
275
|
+
/** Import provider sources as contacts (subscribed only by default). Poll GET /contacts/imports/{id} for counts. */
|
|
276
|
+
async importFromProvider(params, options) {
|
|
277
|
+
return this.client.post("/contacts/imports/provider", params, { ...options, maxRetries: options?.idempotencyKey ? options.maxRetries : 0 });
|
|
278
|
+
}
|
|
255
279
|
async changeStatus(params, options) {
|
|
256
280
|
return this.client.post("/contacts/status", params, options);
|
|
257
281
|
}
|
|
@@ -454,6 +478,16 @@ var Projects = class {
|
|
|
454
478
|
}
|
|
455
479
|
);
|
|
456
480
|
}
|
|
481
|
+
async listConnectedTools(params) {
|
|
482
|
+
return this.client.get("/connected-tools", { ...params });
|
|
483
|
+
}
|
|
484
|
+
async getConnectedTool(params) {
|
|
485
|
+
return this.client.get("/connected-tools/schema", { ...params });
|
|
486
|
+
}
|
|
487
|
+
/** Never automatically replay external writes; provider outcome can be unknown. */
|
|
488
|
+
async callConnectedTool(params) {
|
|
489
|
+
return this.client.post("/connected-tools/call", { ...params }, { maxRetries: 0 });
|
|
490
|
+
}
|
|
457
491
|
/**
|
|
458
492
|
* Import a project and wait for completion.
|
|
459
493
|
* Polls getImportStatus until status is 'active' or 'error'.
|
|
@@ -471,8 +505,6 @@ var Projects = class {
|
|
|
471
505
|
);
|
|
472
506
|
}
|
|
473
507
|
};
|
|
474
|
-
|
|
475
|
-
// src/resources/emails.ts
|
|
476
508
|
var Emails = class {
|
|
477
509
|
constructor(client) {
|
|
478
510
|
this.client = client;
|
|
@@ -514,11 +546,26 @@ var Emails = class {
|
|
|
514
546
|
async get(emailId) {
|
|
515
547
|
return this.client.get(`/emails/${emailId}`);
|
|
516
548
|
}
|
|
517
|
-
/**
|
|
549
|
+
/** Synchronous edit. No automatic retries; use startEdit for long edits. */
|
|
518
550
|
async edit(emailId, params) {
|
|
519
551
|
return this.client.post(
|
|
520
552
|
`/emails/${emailId}/edit`,
|
|
521
|
-
params
|
|
553
|
+
params,
|
|
554
|
+
{ maxRetries: 0 }
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
/** Queue an edit immediately. Retain an explicit key to recover uncertain submissions. */
|
|
558
|
+
async startEdit(emailId, params, options) {
|
|
559
|
+
return this.client.post(
|
|
560
|
+
`/emails/${encodeURIComponent(emailId)}/edit`,
|
|
561
|
+
{ ...params, async: true },
|
|
562
|
+
{ ...options, idempotencyKey: options?.idempotencyKey || crypto.randomUUID() }
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
/** Poll the exact edit; a completed conversation may belong to an earlier turn. */
|
|
566
|
+
async getEditStatus(emailId, editId) {
|
|
567
|
+
return this.client.get(
|
|
568
|
+
`/emails/${encodeURIComponent(emailId)}/edits/${encodeURIComponent(editId)}`
|
|
522
569
|
);
|
|
523
570
|
}
|
|
524
571
|
/**
|
|
@@ -821,8 +868,10 @@ var Billing = class {
|
|
|
821
868
|
return this.client.get("/billing/credits");
|
|
822
869
|
}
|
|
823
870
|
/**
|
|
824
|
-
*
|
|
825
|
-
*
|
|
871
|
+
* Create checkout for a user-chosen new plan, or omit plan for the existing
|
|
872
|
+
* customer's billing portal. Passing plan for an active subscription can
|
|
873
|
+
* change it and charge prorated payment immediately; obtain charge approval.
|
|
874
|
+
* The returned URL alone does not confirm payment. Do not retry unknown writes.
|
|
826
875
|
*/
|
|
827
876
|
async upgradeLink(params = {}) {
|
|
828
877
|
return this.client.post("/billing/upgrade-link", params);
|