migma 1.12.0 → 1.13.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 CHANGED
@@ -229,10 +229,10 @@ const { data: deletion } = await migma.contacts.bulkDeleteByEmail({
229
229
  });
230
230
 
231
231
  // Import contacts from a CSV file (multipart upload, processed in the background).
232
- // `file` accepts a Blob/File, a Buffer, or a ReadableStream.
232
+ // `file` accepts a Buffer, Uint8Array, Blob or File. Requires 1.13.0 or later.
233
233
  import { readFileSync } from 'node:fs';
234
234
 
235
- const { data: job } = await migma.contacts.imports.create({
235
+ const { data: job } = await migma.contacts.createImport({
236
236
  file: readFileSync('./contacts.csv'),
237
237
  projectId: 'proj_abc123',
238
238
  columnMap: {
@@ -244,10 +244,10 @@ const { data: job } = await migma.contacts.imports.create({
244
244
  tags: ['newsletter'],
245
245
  });
246
246
 
247
- // Poll for status + counts until the import finishes.
248
- const { data: status } = await migma.contacts.imports.get(job!.id);
247
+ // Check status and counts. Repeat until the status is completed or failed.
248
+ const { data: status } = await migma.contacts.getImport(job!.id);
249
249
  // status.status → 'pending' | 'processing' | 'completed' | 'failed'
250
- // status.counts → { total, created, updated, skipped, failed }
250
+ // status.counts → { total, created, updated, skipped, failed, non_sendable }
251
251
 
252
252
  // Safe retries: pass an Idempotency-Key so a retried write never duplicates.
253
253
  // Same key + same body within 24h replays the original response.
@@ -699,8 +699,7 @@ await migma.images.updateLogos('proj_abc123', {
699
699
 
700
700
  | Resource | Methods | Docs |
701
701
  |----------|---------|------|
702
- | `migma.contacts` | `create` `list` `get` `update` `remove` `bulkImport` `getBulkImportStatus` `changeStatus` | [Contacts](https://docs.migma.ai/api-reference/contacts/get-contact) |
703
- | `migma.contacts.imports` | `create` `get` | [Contact imports](https://docs.migma.ai/api-reference/contacts/get-contact) |
702
+ | `migma.contacts` | `create` `list` `get` `update` `remove` `bulkImport` `getBulkImportStatus` `createImport` `getImport` `changeStatus` | [Contacts](https://docs.migma.ai/api-reference/contacts/get-contact) |
704
703
  | `migma.tags` | `create` `list` `get` `update` `remove` | [Tags](https://docs.migma.ai/api-reference/tags/list-tags) |
705
704
  | `migma.segments` | `create` `list` `get` `update` `remove` | [Segments](https://docs.migma.ai/api-reference/audiences/list-audiences) |
706
705
  | `migma.topics` | `create` `list` `get` `update` `remove` `subscribe` `unsubscribe` | [Topics](https://docs.migma.ai/api-reference/topics/list-topics) |
package/dist/index.d.mts CHANGED
@@ -59,7 +59,7 @@ type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
59
59
  interface RequestOptions {
60
60
  method: HttpMethod;
61
61
  path: string;
62
- body?: Record<string, unknown>;
62
+ body?: Record<string, unknown> | FormData;
63
63
  query?: Record<string, string | number | boolean | undefined>;
64
64
  headers?: Record<string, string>;
65
65
  maxRetries?: number;
@@ -95,9 +95,12 @@ declare class MigmaClient {
95
95
  count: number;
96
96
  }>>;
97
97
  post<T>(path: string, body?: Record<string, unknown>, options?: CallOptions): Promise<MigmaResult<T>>;
98
+ postForm<T>(path: string, body: FormData, options?: CallOptions): Promise<MigmaResult<T>>;
98
99
  patch<T>(path: string, body?: Record<string, unknown>, options?: CallOptions): Promise<MigmaResult<T>>;
99
100
  put<T>(path: string, body?: Record<string, unknown>): Promise<MigmaResult<T>>;
100
101
  delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>, options?: CallOptions): Promise<MigmaResult<T>>;
102
+ /** JSON by default. A form body drops the JSON header so fetch sets the multipart one with its boundary. */
103
+ private encode;
101
104
  private callHeaders;
102
105
  private buildUrl;
103
106
  private parseRetryAfter;
@@ -297,7 +300,59 @@ interface ContactExportStatus {
297
300
  downloadExpiresAt?: string;
298
301
  error?: string;
299
302
  }
303
+ /** Maps contact fields to CSV header names. Only email is required. */
304
+ interface ContactImportColumnMap {
305
+ email: string;
306
+ firstName?: string;
307
+ lastName?: string;
308
+ name?: string;
309
+ phone?: string;
310
+ country?: string;
311
+ language?: string;
312
+ /** Custom field key to CSV header name. */
313
+ customFields?: Record<string, string>;
314
+ }
315
+ interface CreateContactImportParams {
316
+ /** CSV contents, up to 200MB: a Buffer, Uint8Array, Blob or File. */
317
+ file: Blob | Uint8Array;
318
+ /** Name shown for the import. Defaults to the File's name, then contacts.csv. */
319
+ fileName?: string;
320
+ projectId: string;
321
+ columnMap: ContactImportColumnMap;
322
+ /** Rows whose email already exists: upsert updates them (default), skip leaves them untouched. */
323
+ onConflict?: 'upsert' | 'skip';
324
+ /** CSV field delimiter. Default comma. */
325
+ delimiter?: string;
326
+ /** Tag names or existing tag IDs for every imported contact. Unknown names create tags. */
327
+ tags?: string[];
328
+ }
329
+ interface ContactImportStarted {
330
+ object: 'contact_import';
331
+ id: string;
332
+ status: 'processing';
333
+ }
300
334
  type ContactImportProvider = 'klaviyo' | 'mailchimp' | 'hubspot';
335
+ /** A CSV or provider import. Provider, tag and segment fields are null for CSV imports. */
336
+ interface ContactImportStatus {
337
+ object: 'contact_import';
338
+ id: string;
339
+ status: 'pending' | 'processing' | 'completed' | 'failed';
340
+ provider: ContactImportProvider | null;
341
+ tag_id: string | null;
342
+ segment_id: string | null;
343
+ counts: {
344
+ total: number;
345
+ created: number;
346
+ updated: number;
347
+ skipped: number;
348
+ failed: number;
349
+ /** Imported contacts who are not subscribed and cannot receive campaigns. */
350
+ non_sendable: number;
351
+ };
352
+ error: string | null;
353
+ created_at: string;
354
+ completed_at: string | null;
355
+ }
301
356
  /** A list or segment in the connected provider account that can be imported. */
302
357
  interface ProviderImportSource {
303
358
  id: string;
@@ -320,7 +375,7 @@ interface ImportFromProviderParams {
320
375
  consentMode?: 'subscribed-only' | 'include-all';
321
376
  connectionId?: string;
322
377
  }
323
- /** Each import becomes a tag and a segment named after its sources. Poll the import with its id. */
378
+ /** Each import becomes a tag and a segment named after its sources. Poll getImport with its id. */
324
379
  interface ProviderImportStarted {
325
380
  object: 'contact_import';
326
381
  id: string;
@@ -350,11 +405,18 @@ declare class Contacts {
350
405
  /** Queue a filtered CSV export. Poll getExport; do not list every contact to build a CSV. */
351
406
  createExport(params: CreateContactExportParams, options?: CallOptions): Promise<MigmaResult<ContactExportStatus>>;
352
407
  getExport(jobId: string, projectId: string): Promise<MigmaResult<ContactExportStatus>>;
408
+ /**
409
+ * Upload a CSV to import in the background. Poll getImport for status and counts.
410
+ * Never retried automatically: the endpoint has no idempotency key, so a repeat creates a second import.
411
+ */
412
+ createImport(params: CreateContactImportParams): Promise<MigmaResult<ContactImportStarted>>;
413
+ /** Status and counts of a CSV or provider import. */
414
+ getImport(id: string): Promise<MigmaResult<ContactImportStatus>>;
353
415
  /** Lists and segments in the brand's connected Klaviyo, Mailchimp or HubSpot account. A 409 error message includes the link to connect it. */
354
416
  listProviderImportSources(params: ListProviderImportSourcesParams): Promise<MigmaResult<{
355
417
  sources: ProviderImportSource[];
356
418
  }>>;
357
- /** Import provider sources as contacts (subscribed only by default). Poll GET /contacts/imports/{id} for counts. */
419
+ /** Import provider sources as contacts (subscribed only by default). Poll getImport for counts. */
358
420
  importFromProvider(params: ImportFromProviderParams, options?: CallOptions): Promise<MigmaResult<ProviderImportStarted>>;
359
421
  changeStatus(params: ChangeStatusParams, options?: CallOptions): Promise<MigmaResult<{
360
422
  success: boolean;
@@ -2001,4 +2063,4 @@ declare class Migma {
2001
2063
  constructor(apiKey: string, config?: MigmaConfig);
2002
2064
  }
2003
2065
 
2004
- 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 LocalTimePassed, 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 };
2066
+ 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 ContactImportColumnMap, type ContactImportProvider, type ContactImportStarted, type ContactImportStatus, type ContactStatus, type CreateCampaignParams, type CreateContactExportParams, type CreateContactImportParams, 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 LocalTimePassed, 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.d.ts CHANGED
@@ -59,7 +59,7 @@ type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
59
59
  interface RequestOptions {
60
60
  method: HttpMethod;
61
61
  path: string;
62
- body?: Record<string, unknown>;
62
+ body?: Record<string, unknown> | FormData;
63
63
  query?: Record<string, string | number | boolean | undefined>;
64
64
  headers?: Record<string, string>;
65
65
  maxRetries?: number;
@@ -95,9 +95,12 @@ declare class MigmaClient {
95
95
  count: number;
96
96
  }>>;
97
97
  post<T>(path: string, body?: Record<string, unknown>, options?: CallOptions): Promise<MigmaResult<T>>;
98
+ postForm<T>(path: string, body: FormData, options?: CallOptions): Promise<MigmaResult<T>>;
98
99
  patch<T>(path: string, body?: Record<string, unknown>, options?: CallOptions): Promise<MigmaResult<T>>;
99
100
  put<T>(path: string, body?: Record<string, unknown>): Promise<MigmaResult<T>>;
100
101
  delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>, options?: CallOptions): Promise<MigmaResult<T>>;
102
+ /** JSON by default. A form body drops the JSON header so fetch sets the multipart one with its boundary. */
103
+ private encode;
101
104
  private callHeaders;
102
105
  private buildUrl;
103
106
  private parseRetryAfter;
@@ -297,7 +300,59 @@ interface ContactExportStatus {
297
300
  downloadExpiresAt?: string;
298
301
  error?: string;
299
302
  }
303
+ /** Maps contact fields to CSV header names. Only email is required. */
304
+ interface ContactImportColumnMap {
305
+ email: string;
306
+ firstName?: string;
307
+ lastName?: string;
308
+ name?: string;
309
+ phone?: string;
310
+ country?: string;
311
+ language?: string;
312
+ /** Custom field key to CSV header name. */
313
+ customFields?: Record<string, string>;
314
+ }
315
+ interface CreateContactImportParams {
316
+ /** CSV contents, up to 200MB: a Buffer, Uint8Array, Blob or File. */
317
+ file: Blob | Uint8Array;
318
+ /** Name shown for the import. Defaults to the File's name, then contacts.csv. */
319
+ fileName?: string;
320
+ projectId: string;
321
+ columnMap: ContactImportColumnMap;
322
+ /** Rows whose email already exists: upsert updates them (default), skip leaves them untouched. */
323
+ onConflict?: 'upsert' | 'skip';
324
+ /** CSV field delimiter. Default comma. */
325
+ delimiter?: string;
326
+ /** Tag names or existing tag IDs for every imported contact. Unknown names create tags. */
327
+ tags?: string[];
328
+ }
329
+ interface ContactImportStarted {
330
+ object: 'contact_import';
331
+ id: string;
332
+ status: 'processing';
333
+ }
300
334
  type ContactImportProvider = 'klaviyo' | 'mailchimp' | 'hubspot';
335
+ /** A CSV or provider import. Provider, tag and segment fields are null for CSV imports. */
336
+ interface ContactImportStatus {
337
+ object: 'contact_import';
338
+ id: string;
339
+ status: 'pending' | 'processing' | 'completed' | 'failed';
340
+ provider: ContactImportProvider | null;
341
+ tag_id: string | null;
342
+ segment_id: string | null;
343
+ counts: {
344
+ total: number;
345
+ created: number;
346
+ updated: number;
347
+ skipped: number;
348
+ failed: number;
349
+ /** Imported contacts who are not subscribed and cannot receive campaigns. */
350
+ non_sendable: number;
351
+ };
352
+ error: string | null;
353
+ created_at: string;
354
+ completed_at: string | null;
355
+ }
301
356
  /** A list or segment in the connected provider account that can be imported. */
302
357
  interface ProviderImportSource {
303
358
  id: string;
@@ -320,7 +375,7 @@ interface ImportFromProviderParams {
320
375
  consentMode?: 'subscribed-only' | 'include-all';
321
376
  connectionId?: string;
322
377
  }
323
- /** Each import becomes a tag and a segment named after its sources. Poll the import with its id. */
378
+ /** Each import becomes a tag and a segment named after its sources. Poll getImport with its id. */
324
379
  interface ProviderImportStarted {
325
380
  object: 'contact_import';
326
381
  id: string;
@@ -350,11 +405,18 @@ declare class Contacts {
350
405
  /** Queue a filtered CSV export. Poll getExport; do not list every contact to build a CSV. */
351
406
  createExport(params: CreateContactExportParams, options?: CallOptions): Promise<MigmaResult<ContactExportStatus>>;
352
407
  getExport(jobId: string, projectId: string): Promise<MigmaResult<ContactExportStatus>>;
408
+ /**
409
+ * Upload a CSV to import in the background. Poll getImport for status and counts.
410
+ * Never retried automatically: the endpoint has no idempotency key, so a repeat creates a second import.
411
+ */
412
+ createImport(params: CreateContactImportParams): Promise<MigmaResult<ContactImportStarted>>;
413
+ /** Status and counts of a CSV or provider import. */
414
+ getImport(id: string): Promise<MigmaResult<ContactImportStatus>>;
353
415
  /** Lists and segments in the brand's connected Klaviyo, Mailchimp or HubSpot account. A 409 error message includes the link to connect it. */
354
416
  listProviderImportSources(params: ListProviderImportSourcesParams): Promise<MigmaResult<{
355
417
  sources: ProviderImportSource[];
356
418
  }>>;
357
- /** Import provider sources as contacts (subscribed only by default). Poll GET /contacts/imports/{id} for counts. */
419
+ /** Import provider sources as contacts (subscribed only by default). Poll getImport for counts. */
358
420
  importFromProvider(params: ImportFromProviderParams, options?: CallOptions): Promise<MigmaResult<ProviderImportStarted>>;
359
421
  changeStatus(params: ChangeStatusParams, options?: CallOptions): Promise<MigmaResult<{
360
422
  success: boolean;
@@ -2001,4 +2063,4 @@ declare class Migma {
2001
2063
  constructor(apiKey: string, config?: MigmaConfig);
2002
2064
  }
2003
2065
 
2004
- 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 LocalTimePassed, 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 };
2066
+ 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 ContactImportColumnMap, type ContactImportProvider, type ContactImportStarted, type ContactImportStatus, type ContactStatus, type CreateCampaignParams, type CreateContactExportParams, type CreateContactImportParams, 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 LocalTimePassed, 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
@@ -103,8 +103,7 @@ var MigmaClient = class {
103
103
  try {
104
104
  const response = await fetch(url, {
105
105
  method: options.method,
106
- headers: { ...this.headers, ...options.headers },
107
- body: options.body ? JSON.stringify(options.body) : void 0
106
+ ...this.encode(options)
108
107
  });
109
108
  const json = await readJson(response);
110
109
  if (!response.ok || !json?.success) {
@@ -177,6 +176,9 @@ var MigmaClient = class {
177
176
  async post(path, body, options) {
178
177
  return this.request({ method: "POST", path, body, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
179
178
  }
179
+ async postForm(path, body, options) {
180
+ return this.request({ method: "POST", path, body, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
181
+ }
180
182
  async patch(path, body, options) {
181
183
  return this.request({ method: "PATCH", path, body, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
182
184
  }
@@ -186,6 +188,15 @@ var MigmaClient = class {
186
188
  async delete(path, query, options) {
187
189
  return this.request({ method: "DELETE", path, query, headers: this.callHeaders(options), maxRetries: options?.maxRetries });
188
190
  }
191
+ /** JSON by default. A form body drops the JSON header so fetch sets the multipart one with its boundary. */
192
+ encode(options) {
193
+ const headers = { ...this.headers, ...options.headers };
194
+ if (options.body instanceof FormData) {
195
+ delete headers["Content-Type"];
196
+ return { headers, body: options.body };
197
+ }
198
+ return { headers, body: options.body ? JSON.stringify(options.body) : void 0 };
199
+ }
189
200
  callHeaders(options) {
190
201
  if (options?.idempotencyKey) {
191
202
  return { "Idempotency-Key": options.idempotencyKey };
@@ -273,12 +284,35 @@ var Contacts = class {
273
284
  async getExport(jobId, projectId) {
274
285
  return this.client.get(`/contacts/exports/${encodeURIComponent(jobId)}`, { projectId });
275
286
  }
287
+ /**
288
+ * Upload a CSV to import in the background. Poll getImport for status and counts.
289
+ * Never retried automatically: the endpoint has no idempotency key, so a repeat creates a second import.
290
+ */
291
+ async createImport(params) {
292
+ const { file, fileName, projectId, columnMap, onConflict, delimiter, tags } = params;
293
+ const form = new FormData();
294
+ form.append(
295
+ "file",
296
+ file instanceof Blob ? file : new Blob([file], { type: "text/csv" }),
297
+ fileName ?? file.name ?? "contacts.csv"
298
+ );
299
+ form.append("projectId", projectId);
300
+ form.append("columnMap", JSON.stringify(columnMap));
301
+ if (onConflict) form.append("onConflict", onConflict);
302
+ if (delimiter) form.append("delimiter", delimiter);
303
+ if (tags?.length) form.append("tags", JSON.stringify(tags));
304
+ return this.client.postForm("/contacts/imports", form, { maxRetries: 0 });
305
+ }
306
+ /** Status and counts of a CSV or provider import. */
307
+ async getImport(id) {
308
+ return this.client.get(`/contacts/imports/${encodeURIComponent(id)}`);
309
+ }
276
310
  /** Lists and segments in the brand's connected Klaviyo, Mailchimp or HubSpot account. A 409 error message includes the link to connect it. */
277
311
  async listProviderImportSources(params) {
278
312
  const { provider, projectId, connectionId } = params;
279
313
  return this.client.get(`/contacts/imports/providers/${encodeURIComponent(provider)}/sources`, { projectId, connectionId });
280
314
  }
281
- /** Import provider sources as contacts (subscribed only by default). Poll GET /contacts/imports/{id} for counts. */
315
+ /** Import provider sources as contacts (subscribed only by default). Poll getImport for counts. */
282
316
  async importFromProvider(params, options) {
283
317
  return this.client.post("/contacts/imports/provider", params, { ...options, maxRetries: options?.idempotencyKey ? options.maxRetries : 0 });
284
318
  }