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