unitpost 0.1.0 → 0.2.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.
- package/README.md +3 -3
- package/dist/index.cjs +57 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +57 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ import { Unitpost } from "unitpost";
|
|
|
18
18
|
|
|
19
19
|
const unitpost = new Unitpost(process.env.UNITPOST_API_KEY);
|
|
20
20
|
|
|
21
|
-
const { data, error } = await unitpost.
|
|
21
|
+
const { data, error } = await unitpost.email.send({
|
|
22
22
|
from: "Acme <you@yourdomain.com>", // bare address works too
|
|
23
23
|
to: "customer@example.com",
|
|
24
24
|
subject: "Hello",
|
|
@@ -126,8 +126,8 @@ send twice. Pass your own to dedupe across separate calls (e.g. a user
|
|
|
126
126
|
double-clicks "send"):
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
|
-
await unitpost.
|
|
130
|
-
await unitpost.
|
|
129
|
+
await unitpost.email.send({ ... }, { idempotencyKey: crypto.randomUUID() });
|
|
130
|
+
await unitpost.email.batch([ ... ], { idempotencyKey: crypto.randomUUID() });
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
> The server dedupes on `(workspace, idempotency key)` for 24h and replays the
|
package/dist/index.cjs
CHANGED
|
@@ -261,7 +261,18 @@ var Resource = class {
|
|
|
261
261
|
}
|
|
262
262
|
http;
|
|
263
263
|
};
|
|
264
|
-
var
|
|
264
|
+
var Email = class extends Resource {
|
|
265
|
+
topics;
|
|
266
|
+
campaigns;
|
|
267
|
+
templates;
|
|
268
|
+
domains;
|
|
269
|
+
constructor(http) {
|
|
270
|
+
super(http);
|
|
271
|
+
this.topics = new Topics(http);
|
|
272
|
+
this.campaigns = new Campaigns(http);
|
|
273
|
+
this.templates = new Templates(http);
|
|
274
|
+
this.domains = new Domains(http);
|
|
275
|
+
}
|
|
265
276
|
/**
|
|
266
277
|
* Send or schedule a transactional email.
|
|
267
278
|
*
|
|
@@ -272,7 +283,7 @@ var Emails = class extends Resource {
|
|
|
272
283
|
send(body, opts = {}) {
|
|
273
284
|
return this.http.request({
|
|
274
285
|
method: "POST",
|
|
275
|
-
path: "/
|
|
286
|
+
path: "/email",
|
|
276
287
|
body,
|
|
277
288
|
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
278
289
|
});
|
|
@@ -288,34 +299,34 @@ var Emails = class extends Resource {
|
|
|
288
299
|
batch(body, opts = {}) {
|
|
289
300
|
return this.http.request({
|
|
290
301
|
method: "POST",
|
|
291
|
-
path: "/
|
|
302
|
+
path: "/email/batch",
|
|
292
303
|
body,
|
|
293
304
|
idempotencyKey: opts.idempotencyKey ?? crypto.randomUUID()
|
|
294
305
|
});
|
|
295
306
|
}
|
|
296
307
|
/** Retrieve a batch by id. */
|
|
297
308
|
getBatch(id) {
|
|
298
|
-
return this.http.request({ method: "GET", path: `/
|
|
309
|
+
return this.http.request({ method: "GET", path: `/email/batches/${enc(id)}` });
|
|
299
310
|
}
|
|
300
311
|
/** Cancel every still-cancelable message in a batch. */
|
|
301
312
|
cancelBatch(id) {
|
|
302
|
-
return this.http.request({ method: "POST", path: `/
|
|
313
|
+
return this.http.request({ method: "POST", path: `/email/batches/${enc(id)}/cancel` });
|
|
303
314
|
}
|
|
304
315
|
/** List sent/scheduled emails (cursor-paginated). */
|
|
305
316
|
list(params = {}) {
|
|
306
|
-
return this.http.request({ method: "GET", path: "/
|
|
317
|
+
return this.http.request({ method: "GET", path: "/email", query: params });
|
|
307
318
|
}
|
|
308
319
|
/** Async-iterate every sent/scheduled email. */
|
|
309
320
|
listAll(params = {}) {
|
|
310
|
-
return paginate(this.http, "/
|
|
321
|
+
return paginate(this.http, "/email", params);
|
|
311
322
|
}
|
|
312
323
|
/** Retrieve a sent or scheduled email. */
|
|
313
324
|
get(id) {
|
|
314
|
-
return this.http.request({ method: "GET", path: `/
|
|
325
|
+
return this.http.request({ method: "GET", path: `/email/${enc(id)}` });
|
|
315
326
|
}
|
|
316
327
|
/** Cancel or reschedule a scheduled/queued email. */
|
|
317
328
|
update(id, body) {
|
|
318
|
-
return this.http.request({ method: "PATCH", path: `/
|
|
329
|
+
return this.http.request({ method: "PATCH", path: `/email/${enc(id)}`, body });
|
|
319
330
|
}
|
|
320
331
|
/**
|
|
321
332
|
* Deliverability / engagement stats over a rolling window.
|
|
@@ -323,17 +334,17 @@ var Emails = class extends Resource {
|
|
|
323
334
|
* `days` is the window size (1–365); defaults to 30 server-side.
|
|
324
335
|
*/
|
|
325
336
|
stats(params = {}) {
|
|
326
|
-
return this.http.request({ method: "GET", path: "/
|
|
337
|
+
return this.http.request({ method: "GET", path: "/email/stats", query: params });
|
|
327
338
|
}
|
|
328
339
|
// --- Inbound (received) emails ---
|
|
329
340
|
receivedList(params = {}) {
|
|
330
|
-
return this.http.request({ method: "GET", path: "/
|
|
341
|
+
return this.http.request({ method: "GET", path: "/email/received", query: params });
|
|
331
342
|
}
|
|
332
343
|
receivedGet(id) {
|
|
333
|
-
return this.http.request({ method: "GET", path: `/
|
|
344
|
+
return this.http.request({ method: "GET", path: `/email/received/${enc(id)}` });
|
|
334
345
|
}
|
|
335
346
|
receivedAttachmentUrl(id, attachmentId) {
|
|
336
|
-
return this.http.request({ method: "GET", path: `/
|
|
347
|
+
return this.http.request({ method: "GET", path: `/email/received/${enc(id)}/attachments/${enc(attachmentId)}` });
|
|
337
348
|
}
|
|
338
349
|
};
|
|
339
350
|
var Contacts = class extends Resource {
|
|
@@ -423,22 +434,22 @@ var Segments = class extends Resource {
|
|
|
423
434
|
};
|
|
424
435
|
var Topics = class extends Resource {
|
|
425
436
|
list(params = {}) {
|
|
426
|
-
return this.http.request({ method: "GET", path: "/topics", query: params });
|
|
437
|
+
return this.http.request({ method: "GET", path: "/email/topics", query: params });
|
|
427
438
|
}
|
|
428
439
|
listAll(params = {}) {
|
|
429
|
-
return paginate(this.http, "/topics", params);
|
|
440
|
+
return paginate(this.http, "/email/topics", params);
|
|
430
441
|
}
|
|
431
442
|
create(body) {
|
|
432
|
-
return this.http.request({ method: "POST", path: "/topics", body });
|
|
443
|
+
return this.http.request({ method: "POST", path: "/email/topics", body });
|
|
433
444
|
}
|
|
434
445
|
get(id) {
|
|
435
|
-
return this.http.request({ method: "GET", path: `/topics/${enc(id)}` });
|
|
446
|
+
return this.http.request({ method: "GET", path: `/email/topics/${enc(id)}` });
|
|
436
447
|
}
|
|
437
448
|
update(id, body) {
|
|
438
|
-
return this.http.request({ method: "PATCH", path: `/topics/${enc(id)}`, body });
|
|
449
|
+
return this.http.request({ method: "PATCH", path: `/email/topics/${enc(id)}`, body });
|
|
439
450
|
}
|
|
440
451
|
delete(id) {
|
|
441
|
-
return this.http.request({ method: "DELETE", path: `/topics/${enc(id)}` });
|
|
452
|
+
return this.http.request({ method: "DELETE", path: `/email/topics/${enc(id)}` });
|
|
442
453
|
}
|
|
443
454
|
/** List a contact's effective topic subscriptions. */
|
|
444
455
|
listTopics(contactId, params = {}) {
|
|
@@ -451,63 +462,63 @@ var Topics = class extends Resource {
|
|
|
451
462
|
};
|
|
452
463
|
var Campaigns = class extends Resource {
|
|
453
464
|
list(params = {}) {
|
|
454
|
-
return this.http.request({ method: "GET", path: "/campaigns", query: params });
|
|
465
|
+
return this.http.request({ method: "GET", path: "/email/campaigns", query: params });
|
|
455
466
|
}
|
|
456
467
|
listAll(params = {}) {
|
|
457
|
-
return paginate(this.http, "/campaigns", params);
|
|
468
|
+
return paginate(this.http, "/email/campaigns", params);
|
|
458
469
|
}
|
|
459
470
|
create(body) {
|
|
460
|
-
return this.http.request({ method: "POST", path: "/campaigns", body });
|
|
471
|
+
return this.http.request({ method: "POST", path: "/email/campaigns", body });
|
|
461
472
|
}
|
|
462
473
|
get(id) {
|
|
463
|
-
return this.http.request({ method: "GET", path: `/campaigns/${enc(id)}` });
|
|
474
|
+
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}` });
|
|
464
475
|
}
|
|
465
476
|
update(id, body) {
|
|
466
|
-
return this.http.request({ method: "PATCH", path: `/campaigns/${enc(id)}`, body });
|
|
477
|
+
return this.http.request({ method: "PATCH", path: `/email/campaigns/${enc(id)}`, body });
|
|
467
478
|
}
|
|
468
479
|
delete(id) {
|
|
469
|
-
return this.http.request({ method: "DELETE", path: `/campaigns/${enc(id)}` });
|
|
480
|
+
return this.http.request({ method: "DELETE", path: `/email/campaigns/${enc(id)}` });
|
|
470
481
|
}
|
|
471
482
|
send(id) {
|
|
472
|
-
return this.http.request({ method: "POST", path: `/campaigns/${enc(id)}/send` });
|
|
483
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/send` });
|
|
473
484
|
}
|
|
474
485
|
cancel(id) {
|
|
475
|
-
return this.http.request({ method: "POST", path: `/campaigns/${enc(id)}/cancel` });
|
|
486
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/cancel` });
|
|
476
487
|
}
|
|
477
488
|
/** Pause a scheduled/sending campaign; already-sent messages are untouched. */
|
|
478
489
|
pause(id) {
|
|
479
|
-
return this.http.request({ method: "POST", path: `/campaigns/${enc(id)}/pause` });
|
|
490
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/pause` });
|
|
480
491
|
}
|
|
481
492
|
/** Resume a paused campaign; sending continues with the remaining recipients. */
|
|
482
493
|
resume(id) {
|
|
483
|
-
return this.http.request({ method: "POST", path: `/campaigns/${enc(id)}/resume` });
|
|
494
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/resume` });
|
|
484
495
|
}
|
|
485
496
|
reschedule(id, body) {
|
|
486
|
-
return this.http.request({ method: "POST", path: `/campaigns/${enc(id)}/reschedule`, body });
|
|
497
|
+
return this.http.request({ method: "POST", path: `/email/campaigns/${enc(id)}/reschedule`, body });
|
|
487
498
|
}
|
|
488
499
|
/** Non-mutating pre-send validation report. */
|
|
489
500
|
validate(id) {
|
|
490
|
-
return this.http.request({ method: "GET", path: `/campaigns/${enc(id)}/validate` });
|
|
501
|
+
return this.http.request({ method: "GET", path: `/email/campaigns/${enc(id)}/validate` });
|
|
491
502
|
}
|
|
492
503
|
};
|
|
493
504
|
var Templates = class extends Resource {
|
|
494
505
|
list(params = {}) {
|
|
495
|
-
return this.http.request({ method: "GET", path: "/templates", query: params });
|
|
506
|
+
return this.http.request({ method: "GET", path: "/email/templates", query: params });
|
|
496
507
|
}
|
|
497
508
|
listAll(params = {}) {
|
|
498
|
-
return paginate(this.http, "/templates", params);
|
|
509
|
+
return paginate(this.http, "/email/templates", params);
|
|
499
510
|
}
|
|
500
511
|
create(body) {
|
|
501
|
-
return this.http.request({ method: "POST", path: "/templates", body });
|
|
512
|
+
return this.http.request({ method: "POST", path: "/email/templates", body });
|
|
502
513
|
}
|
|
503
514
|
get(id) {
|
|
504
|
-
return this.http.request({ method: "GET", path: `/templates/${enc(id)}` });
|
|
515
|
+
return this.http.request({ method: "GET", path: `/email/templates/${enc(id)}` });
|
|
505
516
|
}
|
|
506
517
|
update(id, body) {
|
|
507
|
-
return this.http.request({ method: "PATCH", path: `/templates/${enc(id)}`, body });
|
|
518
|
+
return this.http.request({ method: "PATCH", path: `/email/templates/${enc(id)}`, body });
|
|
508
519
|
}
|
|
509
520
|
delete(id) {
|
|
510
|
-
return this.http.request({ method: "DELETE", path: `/templates/${enc(id)}` });
|
|
521
|
+
return this.http.request({ method: "DELETE", path: `/email/templates/${enc(id)}` });
|
|
511
522
|
}
|
|
512
523
|
};
|
|
513
524
|
var BrandKits = class extends Resource {
|
|
@@ -522,26 +533,26 @@ var BrandKits = class extends Resource {
|
|
|
522
533
|
};
|
|
523
534
|
var Domains = class extends Resource {
|
|
524
535
|
list(params = {}) {
|
|
525
|
-
return this.http.request({ method: "GET", path: "/domains", query: params });
|
|
536
|
+
return this.http.request({ method: "GET", path: "/email/domains", query: params });
|
|
526
537
|
}
|
|
527
538
|
listAll(params = {}) {
|
|
528
|
-
return paginate(this.http, "/domains", params);
|
|
539
|
+
return paginate(this.http, "/email/domains", params);
|
|
529
540
|
}
|
|
530
541
|
create(body) {
|
|
531
|
-
return this.http.request({ method: "POST", path: "/domains", body });
|
|
542
|
+
return this.http.request({ method: "POST", path: "/email/domains", body });
|
|
532
543
|
}
|
|
533
544
|
get(id) {
|
|
534
|
-
return this.http.request({ method: "GET", path: `/domains/${enc(id)}` });
|
|
545
|
+
return this.http.request({ method: "GET", path: `/email/domains/${enc(id)}` });
|
|
535
546
|
}
|
|
536
547
|
delete(id) {
|
|
537
|
-
return this.http.request({ method: "DELETE", path: `/domains/${enc(id)}` });
|
|
548
|
+
return this.http.request({ method: "DELETE", path: `/email/domains/${enc(id)}` });
|
|
538
549
|
}
|
|
539
550
|
update(id, body) {
|
|
540
|
-
return this.http.request({ method: "PATCH", path: `/domains/${enc(id)}`, body });
|
|
551
|
+
return this.http.request({ method: "PATCH", path: `/email/domains/${enc(id)}`, body });
|
|
541
552
|
}
|
|
542
553
|
/** Run an on-demand DNS/SES verification check. */
|
|
543
554
|
verify(id) {
|
|
544
|
-
return this.http.request({ method: "POST", path: `/domains/${enc(id)}/verify` });
|
|
555
|
+
return this.http.request({ method: "POST", path: `/email/domains/${enc(id)}/verify` });
|
|
545
556
|
}
|
|
546
557
|
};
|
|
547
558
|
var Webhooks = class extends Resource {
|
|
@@ -634,15 +645,11 @@ function enc(segment) {
|
|
|
634
645
|
|
|
635
646
|
// src/client.ts
|
|
636
647
|
var Unitpost = class {
|
|
637
|
-
|
|
648
|
+
email;
|
|
638
649
|
contacts;
|
|
639
650
|
contactFields;
|
|
640
651
|
segments;
|
|
641
|
-
topics;
|
|
642
|
-
campaigns;
|
|
643
|
-
templates;
|
|
644
652
|
brandKits;
|
|
645
|
-
domains;
|
|
646
653
|
webhooks;
|
|
647
654
|
apiKeys;
|
|
648
655
|
suppressions;
|
|
@@ -652,15 +659,11 @@ var Unitpost = class {
|
|
|
652
659
|
constructor(apiKeyOrOptions) {
|
|
653
660
|
const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions ?? {};
|
|
654
661
|
const http = new HttpClient(options);
|
|
655
|
-
this.
|
|
662
|
+
this.email = new Email(http);
|
|
656
663
|
this.contacts = new Contacts(http);
|
|
657
664
|
this.contactFields = new ContactFields(http);
|
|
658
665
|
this.segments = new Segments(http);
|
|
659
|
-
this.topics = new Topics(http);
|
|
660
|
-
this.campaigns = new Campaigns(http);
|
|
661
|
-
this.templates = new Templates(http);
|
|
662
666
|
this.brandKits = new BrandKits(http);
|
|
663
|
-
this.domains = new Domains(http);
|
|
664
667
|
this.webhooks = new Webhooks(http);
|
|
665
668
|
this.apiKeys = new ApiKeys(http);
|
|
666
669
|
this.suppressions = new Suppressions(http);
|