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