migma 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +489 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,489 @@
1
+ # migma
2
+
3
+ The official Node.js SDK for the [Migma](https://migma.ai) email platform API.
4
+
5
+ Generate pixel-perfect, on-brand emails with AI in 30 seconds. Manage contacts, domains, webhooks, and more — all from code.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/migma.svg)](https://www.npmjs.com/package/migma)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install migma
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ```typescript
19
+ import { Migma } from 'migma';
20
+
21
+ const migma = new Migma('mgma_sk_live_...');
22
+
23
+ // Generate an email with AI
24
+ const { data, error } = await migma.emails.generateAndWait({
25
+ projectId: 'proj_abc123',
26
+ prompt: 'Create a welcome email for new subscribers',
27
+ });
28
+
29
+ if (data?.status === 'completed') {
30
+ console.log(data.result.subject);
31
+ console.log(data.result.html);
32
+ }
33
+ ```
34
+
35
+ Get your API key from the [Migma Dashboard](https://migma.ai) under **Settings > API Integration > API Keys**.
36
+
37
+ ## Documentation
38
+
39
+ | Resource | Link |
40
+ |----------|------|
41
+ | API Reference | [docs.migma.ai/api-reference](https://docs.migma.ai/api-reference/introduction) |
42
+ | Quickstart Guide | [docs.migma.ai/quickstart](https://docs.migma.ai/quickstart) |
43
+ | Authentication | [docs.migma.ai/authentication](https://docs.migma.ai/authentication) |
44
+ | Webhooks Guide | [docs.migma.ai/webhooks](https://docs.migma.ai/webhooks) |
45
+ | Platform | [migma.ai](https://migma.ai) |
46
+ | Community | [Discord](https://discord.gg/ZB6c2meCUA) |
47
+
48
+ ## Features
49
+
50
+ - Full coverage of all Migma API v1 endpoints (80+ methods across 14 resources)
51
+ - TypeScript-first with complete type definitions
52
+ - `{ data, error }` return pattern — methods never throw
53
+ - Automatic retries with exponential backoff on 5xx/429
54
+ - Polling helpers for async operations (email generation, project import, previews)
55
+ - Zero runtime dependencies (uses native `fetch`)
56
+ - Dual ESM + CommonJS support
57
+
58
+ ## Usage
59
+
60
+ ### Configuration
61
+
62
+ ```typescript
63
+ import { Migma } from 'migma';
64
+
65
+ const migma = new Migma('mgma_sk_live_...', {
66
+ baseUrl: 'https://api.migma.ai/api/v1', // default
67
+ timeout: 30000, // 30s default
68
+ maxRetries: 2, // retries on 5xx/429
69
+ retryDelay: 1000, // base delay between retries
70
+ });
71
+ ```
72
+
73
+ ### Error Handling
74
+
75
+ Every method returns `{ data, error }` instead of throwing. TypeScript narrows the types automatically:
76
+
77
+ ```typescript
78
+ const { data, error } = await migma.contacts.create({
79
+ email: 'john@example.com',
80
+ projectId: 'proj_abc123',
81
+ });
82
+
83
+ if (error) {
84
+ console.error(error.statusCode, error.code, error.message);
85
+ // 400 validation_error "Invalid email address"
86
+ return;
87
+ }
88
+
89
+ // TypeScript knows data is non-null here
90
+ console.log(data.id, data.email);
91
+ ```
92
+
93
+ Error codes: `validation_error` | `not_found` | `unauthorized` | `forbidden` | `rate_limit_exceeded` | `conflict` | `timeout` | `network_error` | `internal_error`
94
+
95
+ ---
96
+
97
+ ### Projects
98
+
99
+ Import your brand and manage projects.
100
+
101
+ ```typescript
102
+ // List all projects
103
+ const { data } = await migma.projects.list({ limit: 20 });
104
+
105
+ // Import a brand from a URL and wait for it to finish
106
+ const { data: project } = await migma.projects.importAndWait(
107
+ { urls: ['https://example.com'] },
108
+ {
109
+ interval: 3000,
110
+ onPoll: (status) => console.log(`${status.progress.percentage}%`),
111
+ }
112
+ );
113
+ ```
114
+
115
+ [Projects API Reference](https://docs.migma.ai/api-reference/projects/list-projects)
116
+
117
+ ### AI Email Generation
118
+
119
+ Generate emails with AI — fire-and-forget or wait for the result.
120
+
121
+ ```typescript
122
+ // Generate and wait for the result
123
+ const { data } = await migma.emails.generateAndWait({
124
+ projectId: 'proj_abc123',
125
+ prompt: 'Black Friday promotional email with 30% discount',
126
+ images: [{ source: { type: 'url', url: 'https://example.com/hero.jpg' } }],
127
+ languages: ['en'],
128
+ });
129
+
130
+ if (data?.status === 'completed') {
131
+ console.log('Subject:', data.result.subject);
132
+ console.log('HTML:', data.result.html);
133
+ }
134
+
135
+ // Or fire-and-forget, check status later
136
+ const { data: gen } = await migma.emails.generate({
137
+ projectId: 'proj_abc123',
138
+ prompt: 'Weekly newsletter',
139
+ });
140
+ const { data: status } = await migma.emails.getGenerationStatus(gen.conversationId);
141
+ ```
142
+
143
+ [Email Generation API Reference](https://docs.migma.ai/api-reference/email/generate-email-async)
144
+
145
+ ### Contacts
146
+
147
+ ```typescript
148
+ // Create
149
+ const { data: contact } = await migma.contacts.create({
150
+ email: 'john@example.com',
151
+ firstName: 'John',
152
+ lastName: 'Doe',
153
+ tags: ['newsletter', 'vip'],
154
+ projectId: 'proj_abc123',
155
+ });
156
+
157
+ // List with filters
158
+ const { data: contacts } = await migma.contacts.list({
159
+ projectId: 'proj_abc123',
160
+ status: 'active',
161
+ tags: 'newsletter',
162
+ limit: 50,
163
+ });
164
+
165
+ // Bulk import (sync for <=5000 contacts, async for more)
166
+ const { data: result } = await migma.contacts.bulkImport({
167
+ subscribers: [
168
+ { email: 'a@example.com', firstName: 'Alice' },
169
+ { email: 'b@example.com', firstName: 'Bob' },
170
+ ],
171
+ projectId: 'proj_abc123',
172
+ });
173
+ ```
174
+
175
+ [Contacts API Reference](https://docs.migma.ai/api-reference/contacts/get-contact)
176
+
177
+ ### Sending Emails
178
+
179
+ Send to a single recipient, segment, tag, or full audience.
180
+
181
+ ```typescript
182
+ // Send to a single recipient
183
+ await migma.sending.send({
184
+ recipientType: 'email',
185
+ recipientEmail: 'user@example.com',
186
+ from: 'hello@yourdomain.com',
187
+ fromName: 'Your Company',
188
+ subject: 'Welcome!',
189
+ template: '<html>...</html>',
190
+ projectId: 'proj_abc123',
191
+ });
192
+
193
+ // Send to a segment
194
+ await migma.sending.send({
195
+ recipientType: 'segment',
196
+ recipientId: 'seg_abc123',
197
+ from: 'hello@yourdomain.com',
198
+ fromName: 'Your Company',
199
+ subject: 'Big Announcement',
200
+ template: '<html>...</html>',
201
+ projectId: 'proj_abc123',
202
+ });
203
+ ```
204
+
205
+ [Sending API Reference](https://docs.migma.ai/api-reference/sending/send-email)
206
+
207
+ ### Email Validation
208
+
209
+ Run preflight checks — compatibility, links, spelling, and deliverability.
210
+
211
+ ```typescript
212
+ // Run all checks at once
213
+ const { data } = await migma.validation.all({
214
+ html: '<html>...</html>',
215
+ subject: 'My Email',
216
+ options: {
217
+ checkCompatibility: true,
218
+ checkLinks: true,
219
+ checkSpelling: true,
220
+ checkDeliverability: true,
221
+ },
222
+ });
223
+
224
+ console.log('Score:', data.overallScore);
225
+ console.log('Spam score:', data.deliverability?.spamScore.score);
226
+
227
+ // Or run individual checks
228
+ const { data: compat } = await migma.validation.compatibility({ html: '...' });
229
+ const { data: links } = await migma.validation.links({ html: '...' });
230
+ const { data: spam } = await migma.validation.deliverability({ html: '...' });
231
+ ```
232
+
233
+ [Validation API Reference](https://docs.migma.ai/api-reference/email-validation/run-all-validation-checks)
234
+
235
+ ### Email Previews
236
+
237
+ Preview emails across 20+ email clients and devices.
238
+
239
+ ```typescript
240
+ const { data } = await migma.previews.createAndWait({
241
+ html: '<html>...</html>',
242
+ subject: 'Test Email',
243
+ devices: ['apple-mail.ios', 'gmail.desktop-webmail'],
244
+ });
245
+
246
+ data.devices.forEach((d) => {
247
+ console.log(`${d.deviceName}: ${d.screenshotUrl}`);
248
+ });
249
+
250
+ // List all supported devices
251
+ const { data: devices } = await migma.previews.getSupportedDevices();
252
+ ```
253
+
254
+ [Previews API Reference](https://docs.migma.ai/api-reference/email-previews/create-email-preview)
255
+
256
+ ### Export
257
+
258
+ Export generated emails to HTML, MJML, PDF, or directly to ESP platforms.
259
+
260
+ ```typescript
261
+ const { data: html } = await migma.export.html('conversation_id');
262
+ const { data: mjml } = await migma.export.mjml('conversation_id');
263
+ const { data: pdf } = await migma.export.pdf('conversation_id');
264
+ const { data: klaviyo } = await migma.export.klaviyo('conversation_id', 'hybrid');
265
+ const { data: mailchimp } = await migma.export.mailchimp('conversation_id');
266
+ ```
267
+
268
+ [Export API Reference](https://docs.migma.ai/api-reference/export/list-export-formats)
269
+
270
+ ### Domains
271
+
272
+ Add custom sending domains or use managed quick-start domains.
273
+
274
+ ```typescript
275
+ // Add and verify a custom domain
276
+ await migma.domains.create({ domain: 'mail.example.com', region: 'us-east-1' });
277
+ await migma.domains.verify('mail.example.com');
278
+
279
+ // Or use a managed domain (quick start)
280
+ const { data: avail } = await migma.domains.checkAvailability('mycompany');
281
+ if (avail.available) {
282
+ await migma.domains.createManaged({ prefix: 'mycompany' });
283
+ }
284
+ ```
285
+
286
+ [Domains API Reference](https://docs.migma.ai/api-reference/domains/list-domains)
287
+
288
+ ### Tags, Segments & Topics
289
+
290
+ ```typescript
291
+ // Tags
292
+ const { data: tag } = await migma.tags.create({
293
+ name: 'VIP Customers',
294
+ color: '#FF5733',
295
+ projectId: 'proj_abc123',
296
+ });
297
+
298
+ // Segments
299
+ const { data: segment } = await migma.segments.create({
300
+ name: 'Active US Customers',
301
+ filters: { status: 'subscribed', customFields: { country: ['US'] } },
302
+ projectId: 'proj_abc123',
303
+ });
304
+
305
+ // Topics with subscribe/unsubscribe
306
+ const { data: topic } = await migma.topics.create({
307
+ name: 'Weekly Newsletter',
308
+ defaultSubscription: 'opt_out',
309
+ projectId: 'proj_abc123',
310
+ });
311
+ await migma.topics.subscribe('topic_id', {
312
+ subscriberId: 'sub_id',
313
+ projectId: 'proj_abc123',
314
+ });
315
+ ```
316
+
317
+ [Tags](https://docs.migma.ai/api-reference/tags/list-tags) | [Segments](https://docs.migma.ai/api-reference/audiences/list-audiences) | [Topics](https://docs.migma.ai/api-reference/topics/list-topics)
318
+
319
+ ### Webhooks
320
+
321
+ ```typescript
322
+ const { data: webhook } = await migma.webhooks.create({
323
+ url: 'https://example.com/webhooks',
324
+ events: ['email.generation.completed', 'subscriber.added'],
325
+ });
326
+
327
+ const { data: test } = await migma.webhooks.test(webhook.id);
328
+ console.log('Success:', test.success);
329
+ ```
330
+
331
+ [Webhooks Guide](https://docs.migma.ai/webhooks)
332
+
333
+ ### Knowledge Base & Images
334
+
335
+ ```typescript
336
+ // Add context for AI email generation
337
+ await migma.knowledgeBase.add('proj_abc123', {
338
+ title: 'Company FAQ',
339
+ content: 'We are a SaaS company that...',
340
+ });
341
+
342
+ // Manage project images
343
+ await migma.images.add('proj_abc123', {
344
+ url: 'https://example.com/hero.jpg',
345
+ description: 'Hero banner',
346
+ });
347
+
348
+ await migma.images.updateLogos('proj_abc123', {
349
+ primary: 'https://example.com/logo.png',
350
+ });
351
+ ```
352
+
353
+ ---
354
+
355
+ ## All Resources
356
+
357
+ | Resource | Methods | Docs |
358
+ |----------|---------|------|
359
+ | `migma.contacts` | `create` `list` `get` `update` `remove` `bulkImport` `getBulkImportStatus` `changeStatus` | [Contacts](https://docs.migma.ai/api-reference/contacts/get-contact) |
360
+ | `migma.tags` | `create` `list` `get` `update` `remove` | [Tags](https://docs.migma.ai/api-reference/tags/list-tags) |
361
+ | `migma.segments` | `create` `list` `get` `update` `remove` | [Segments](https://docs.migma.ai/api-reference/audiences/list-audiences) |
362
+ | `migma.topics` | `create` `list` `get` `update` `remove` `subscribe` `unsubscribe` | [Topics](https://docs.migma.ai/api-reference/topics/list-topics) |
363
+ | `migma.sending` | `send` `getBatchStatus` | [Sending](https://docs.migma.ai/api-reference/sending/send-email) |
364
+ | `migma.projects` | `list` `get` `import` `getImportStatus` `retryImport` `importAndWait` | [Projects](https://docs.migma.ai/api-reference/projects/list-projects) |
365
+ | `migma.emails` | `generate` `getGenerationStatus` `generateAndWait` `sendTest` | [Email Generation](https://docs.migma.ai/api-reference/email/generate-email-async) |
366
+ | `migma.validation` | `all` `compatibility` `links` `spelling` `deliverability` | [Validation](https://docs.migma.ai/api-reference/email-validation/run-all-validation-checks) |
367
+ | `migma.previews` | `create` `get` `getStatus` `getDevice` `getSupportedDevices` `createAndWait` | [Previews](https://docs.migma.ai/api-reference/email-previews/create-email-preview) |
368
+ | `migma.export` | `getFormats` `getStatus` `html` `mjml` `pdf` `klaviyo` `mailchimp` `hubspot` | [Export](https://docs.migma.ai/api-reference/export/list-export-formats) |
369
+ | `migma.domains` | `create` `list` `get` `verify` `update` `remove` `checkAvailability` `listManaged` `createManaged` `removeManaged` | [Domains](https://docs.migma.ai/api-reference/domains/list-domains) |
370
+ | `migma.webhooks` | `create` `list` `get` `update` `remove` `test` `getDeliveries` `getEvents` `getStats` | [Webhooks](https://docs.migma.ai/webhooks) |
371
+ | `migma.knowledgeBase` | `list` `add` `update` `remove` | [API Ref](https://docs.migma.ai/api-reference/introduction) |
372
+ | `migma.images` | `add` `update` `remove` `updateLogos` | [API Ref](https://docs.migma.ai/api-reference/introduction) |
373
+
374
+ ## Async Polling Helpers
375
+
376
+ Three resources support async operations with built-in polling:
377
+
378
+ ```typescript
379
+ // All polling methods accept optional config
380
+ const options = {
381
+ interval: 2000, // poll every 2s (default)
382
+ maxAttempts: 150, // max polls before timeout (default)
383
+ onPoll: (status, attempt) => console.log(`Attempt ${attempt}:`, status),
384
+ signal: abortController.signal, // cancel polling
385
+ };
386
+
387
+ await migma.emails.generateAndWait(params, options);
388
+ await migma.projects.importAndWait(params, options);
389
+ await migma.previews.createAndWait(params, options);
390
+ ```
391
+
392
+ ## Use Cases
393
+
394
+ ### Send emails from WhatsApp/Telegram via OpenClaw
395
+
396
+ [OpenClaw](https://openclaw.ai/) is an open-source AI agent for messaging apps. Pair it with Migma to send professional emails from a single chat command — no ESP dashboard needed.
397
+
398
+ ```typescript
399
+ // Set up a managed domain (instant, no DNS)
400
+ await migma.domains.createManaged({ prefix: 'yourcompany' });
401
+
402
+ // Send from your OpenClaw bot
403
+ await migma.sending.send({
404
+ recipientType: 'email',
405
+ recipientEmail: 'sarah@example.com',
406
+ from: 'hello@yourcompany.migma.email',
407
+ fromName: 'Your Company',
408
+ subject: 'Hello from OpenClaw',
409
+ template: '<h1>Hi!</h1><p>Sent via OpenClaw + Migma.</p>',
410
+ providerType: 'migma',
411
+ projectId: 'proj_abc123',
412
+ });
413
+ ```
414
+
415
+ [OpenClaw Guide](https://docs.migma.ai/integrations/openclaw)
416
+
417
+ ### Generate + validate + send in one pipeline
418
+
419
+ ```typescript
420
+ const { data: email } = await migma.emails.generateAndWait({
421
+ projectId: 'proj_abc123',
422
+ prompt: 'Summer sale — 30% off everything this weekend',
423
+ });
424
+
425
+ const { data: checks } = await migma.validation.all({
426
+ html: email.result.html,
427
+ subject: email.result.subject,
428
+ });
429
+
430
+ if (checks.overallScore > 80) {
431
+ await migma.sending.send({
432
+ recipientType: 'tag',
433
+ recipientId: 'newsletter-subscribers',
434
+ from: 'hello@yourdomain.com',
435
+ fromName: 'Your Brand',
436
+ subject: email.result.subject,
437
+ template: email.result.html,
438
+ projectId: 'proj_abc123',
439
+ });
440
+ }
441
+ ```
442
+
443
+ ### Pull live data from Shopify, Notion, Stripe via MCP
444
+
445
+ Migma connects to [26+ tools via MCP](https://docs.migma.ai/integrations/mcp-servers). Generate emails with live product data, content calendars, or revenue metrics.
446
+
447
+ ```typescript
448
+ await migma.emails.generateAndWait({
449
+ projectId: 'proj_abc123',
450
+ prompt: 'Product launch email for items tagged "New Arrival" from Shopify',
451
+ });
452
+ ```
453
+
454
+ ### Email preview testing in CI/CD
455
+
456
+ ```typescript
457
+ const { data: preview } = await migma.previews.createAndWait({
458
+ html: emailHtml,
459
+ devices: ['apple-mail.ios', 'gmail.desktop-webmail', 'outlook.desktop-windows'],
460
+ });
461
+
462
+ const failed = preview.devices.filter((d) => d.status === 'FAILED');
463
+ if (failed.length) throw new Error(`Broken on: ${failed.map((d) => d.deviceName)}`);
464
+ ```
465
+
466
+ ### One-click export to Klaviyo, Mailchimp, HubSpot
467
+
468
+ ```typescript
469
+ const { data } = await migma.export.klaviyo(conversationId, 'hybrid');
470
+ console.log('Download:', data.files[0].url);
471
+ ```
472
+
473
+ ---
474
+
475
+ ## Requirements
476
+
477
+ - Node.js 18 or later (uses native `fetch`)
478
+ - [Migma API key](https://migma.ai) (Settings > API Integration)
479
+
480
+ ## Support
481
+
482
+ - [Documentation](https://docs.migma.ai)
483
+ - [Discord Community](https://discord.gg/ZB6c2meCUA)
484
+ - [Support](https://migma.ai/support)
485
+ - [Email](mailto:support@migma.ai)
486
+
487
+ ## License
488
+
489
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "migma",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official Node.js SDK for the Migma email platform API",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -44,7 +44,7 @@
44
44
  "license": "MIT",
45
45
  "repository": {
46
46
  "type": "git",
47
- "url": "https://github.com/migma-ai/migma-node"
47
+ "url": "https://github.com/MigmaAI/migma-node"
48
48
  },
49
49
  "homepage": "https://docs.migma.ai",
50
50
  "engines": {