zupost 0.2.0 → 0.6.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.js CHANGED
@@ -73,12 +73,13 @@ var __async = (__this, __arguments, generator) => {
73
73
  var index_exports = {};
74
74
  __export(index_exports, {
75
75
  Zupost: () => Zupost,
76
- ZupostError: () => ZupostError
76
+ ZupostError: () => ZupostError,
77
+ defineSequence: () => defineSequence
77
78
  });
78
79
  module.exports = __toCommonJS(index_exports);
79
80
 
80
81
  // package.json
81
- var version = "0.2.0";
82
+ var version = "0.6.0";
82
83
 
83
84
  // src/errors.ts
84
85
  var ZupostError = class _ZupostError extends Error {
@@ -139,7 +140,7 @@ var HttpClient = class {
139
140
  __privateAdd(this, _baseUrl);
140
141
  __privateSet(this, _baseUrl, baseUrl.replace(/\/$/, ""));
141
142
  __privateSet(this, _defaultHeaders, {
142
- Authorization: `Bearer ${apiKey}`,
143
+ "Authorization": `Bearer ${apiKey}`,
143
144
  "Content-Type": "application/json",
144
145
  "User-Agent": userAgent
145
146
  });
@@ -187,6 +188,16 @@ var HttpClient = class {
187
188
  return this.request(path, "POST", body);
188
189
  });
189
190
  }
191
+ patch(path, body) {
192
+ return __async(this, null, function* () {
193
+ return this.request(path, "PATCH", body);
194
+ });
195
+ }
196
+ delete(path, body) {
197
+ return __async(this, null, function* () {
198
+ return this.request(path, "DELETE", body);
199
+ });
200
+ }
190
201
  };
191
202
  _defaultHeaders = new WeakMap();
192
203
  _baseUrl = new WeakMap();
@@ -302,6 +313,324 @@ var Campaigns = class {
302
313
  }
303
314
  };
304
315
 
316
+ // src/contact/contacts.ts
317
+ function buildQuery(params) {
318
+ const search = new URLSearchParams();
319
+ for (const [key, value] of Object.entries(params)) {
320
+ if (value === void 0) continue;
321
+ if (Array.isArray(value)) {
322
+ for (const v of value) search.append(key, String(v));
323
+ } else {
324
+ search.set(key, String(value));
325
+ }
326
+ }
327
+ const query = search.toString();
328
+ return query ? `?${query}` : "";
329
+ }
330
+ var Contacts = class {
331
+ constructor(http) {
332
+ this.http = http;
333
+ }
334
+ /**
335
+ * Create or upsert a contact by email. Idempotent on (project, email).
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * const contact = await zupost.contacts.create({
340
+ * email: 'user@example.com',
341
+ * name: 'Jane Doe',
342
+ * marketingConsent: true,
343
+ * marketingConsentSource: 'signup-form',
344
+ * tags: ['vip', 'beta'],
345
+ * });
346
+ * ```
347
+ */
348
+ create(options) {
349
+ return __async(this, null, function* () {
350
+ return this.http.post("/contact", options);
351
+ });
352
+ }
353
+ /**
354
+ * Get a contact by ID.
355
+ */
356
+ get(id) {
357
+ return __async(this, null, function* () {
358
+ return this.http.get(`/contact/${encodeURIComponent(id)}`);
359
+ });
360
+ }
361
+ /**
362
+ * List contacts with optional search, consent and tag filters.
363
+ */
364
+ list() {
365
+ return __async(this, arguments, function* (options = {}) {
366
+ const query = buildQuery({
367
+ skip: options.skip,
368
+ take: options.take,
369
+ search: options.search,
370
+ marketingConsent: options.marketingConsent === void 0 ? void 0 : String(options.marketingConsent),
371
+ tag: options.tag
372
+ });
373
+ return this.http.get(`/contact${query}`);
374
+ });
375
+ }
376
+ /**
377
+ * Update a contact. Pass only the fields that should change.
378
+ *
379
+ * Toggling `marketingConsent` or `trackingConsent` automatically records
380
+ * a corresponding ContactEvent for the audit trail.
381
+ */
382
+ update(id, patch) {
383
+ return __async(this, null, function* () {
384
+ return this.http.patch(`/contact/${encodeURIComponent(id)}`, patch);
385
+ });
386
+ }
387
+ /**
388
+ * GDPR right-to-be-forgotten. Anonymises the contact, sets `forgottenAt`
389
+ * and disables consent. Existing email events are anonymised in a
390
+ * follow-up cascade.
391
+ */
392
+ forget(id) {
393
+ return __async(this, null, function* () {
394
+ return this.http.delete(`/contact/${encodeURIComponent(id)}`);
395
+ });
396
+ }
397
+ /**
398
+ * Get the chronological event timeline for a contact.
399
+ */
400
+ events(_0) {
401
+ return __async(this, arguments, function* (id, options = {}) {
402
+ const query = buildQuery({
403
+ skip: options.skip,
404
+ take: options.take,
405
+ type: options.type
406
+ });
407
+ return this.http.get(`/contact/${encodeURIComponent(id)}/events${query}`);
408
+ });
409
+ }
410
+ /**
411
+ * GDPR data access export. Returns the complete record for a contact
412
+ * including all emails, events, subscriptions and tags.
413
+ */
414
+ export(id) {
415
+ return __async(this, null, function* () {
416
+ return this.http.get(`/contact/${encodeURIComponent(id)}/export`);
417
+ });
418
+ }
419
+ /**
420
+ * Add a tag to a contact (idempotent).
421
+ */
422
+ addTag(id, name) {
423
+ return __async(this, null, function* () {
424
+ return this.http.post(`/contact/${encodeURIComponent(id)}/tags`, { name });
425
+ });
426
+ }
427
+ /**
428
+ * Remove a tag from a contact.
429
+ */
430
+ removeTag(id, name) {
431
+ return __async(this, null, function* () {
432
+ return this.http.delete(
433
+ `/contact/${encodeURIComponent(id)}/tags/${encodeURIComponent(name)}`
434
+ );
435
+ });
436
+ }
437
+ };
438
+
439
+ // src/sequence/sequences.ts
440
+ function buildQuery2(params) {
441
+ const search = new URLSearchParams();
442
+ for (const [key, value] of Object.entries(params)) {
443
+ if (value === void 0) continue;
444
+ search.set(key, String(value));
445
+ }
446
+ const q = search.toString();
447
+ return q ? `?${q}` : "";
448
+ }
449
+ var Sequences = class {
450
+ constructor(http) {
451
+ this.http = http;
452
+ this.runs = {
453
+ list: (_0, ..._1) => __async(this, [_0, ..._1], function* (sequenceId, options = {}) {
454
+ const query = buildQuery2({
455
+ skip: options.skip,
456
+ take: options.take,
457
+ status: options.status,
458
+ contactId: options.contactId
459
+ });
460
+ return this.http.get(
461
+ `/sequence/${encodeURIComponent(sequenceId)}/runs${query}`
462
+ );
463
+ })
464
+ };
465
+ }
466
+ /**
467
+ * Create a new sequence (always starts in DRAFT). Pass `definition` to
468
+ * seed the first version, or omit it to create an empty placeholder you
469
+ * can later push versions into.
470
+ */
471
+ create(options) {
472
+ return __async(this, null, function* () {
473
+ return this.http.post("/sequence", options);
474
+ });
475
+ }
476
+ /**
477
+ * Get a sequence by ID.
478
+ */
479
+ get(id) {
480
+ return __async(this, null, function* () {
481
+ return this.http.get(`/sequence/${encodeURIComponent(id)}`);
482
+ });
483
+ }
484
+ /**
485
+ * List sequences with filters.
486
+ */
487
+ list() {
488
+ return __async(this, arguments, function* (options = {}) {
489
+ const query = buildQuery2({
490
+ skip: options.skip,
491
+ take: options.take,
492
+ type: options.type,
493
+ status: options.status,
494
+ search: options.search
495
+ });
496
+ return this.http.get(`/sequence${query}`);
497
+ });
498
+ }
499
+ /**
500
+ * Delete a sequence and all its versions and runs.
501
+ */
502
+ delete(id) {
503
+ return __async(this, null, function* () {
504
+ return this.http.delete(`/sequence/${encodeURIComponent(id)}`);
505
+ });
506
+ }
507
+ /**
508
+ * Change the lifecycle status: DRAFT, ACTIVE, PAUSED, ARCHIVED.
509
+ */
510
+ setStatus(id, status) {
511
+ return __async(this, null, function* () {
512
+ return this.http.post(`/sequence/${encodeURIComponent(id)}/status`, { status });
513
+ });
514
+ }
515
+ /**
516
+ * Save a new immutable version of the sequence definition. If `activate`
517
+ * is true (default), the new version becomes the active one for future
518
+ * triggered runs. Existing in-flight runs keep their pinned version.
519
+ */
520
+ saveVersion(id, options) {
521
+ return __async(this, null, function* () {
522
+ return this.http.post(`/sequence/${encodeURIComponent(id)}/versions`, options);
523
+ });
524
+ }
525
+ /**
526
+ * Trigger a sequence run for a contact or ad-hoc email. The sequence
527
+ * must be ACTIVE.
528
+ */
529
+ trigger(id, options) {
530
+ return __async(this, null, function* () {
531
+ if (!options.contactId && !options.email) {
532
+ throw new Error("trigger requires contactId or email");
533
+ }
534
+ return this.http.post(`/sequence/${encodeURIComponent(id)}/runs`, options);
535
+ });
536
+ }
537
+ };
538
+
539
+ // src/domain/domains.ts
540
+ var DEFAULT_REGION = "eu-central-1";
541
+ var Domains = class {
542
+ constructor(http) {
543
+ this.http = http;
544
+ }
545
+ /**
546
+ * Register a new sending domain. The response contains the `dnsRecords` you
547
+ * need to add at your DNS provider before calling {@link verify}.
548
+ *
549
+ * @example
550
+ * ```typescript
551
+ * const domain = await zupost.domains.create({ name: 'example.com' });
552
+ * for (const record of domain.dnsRecords) {
553
+ * console.log(record.type, record.name, record.value);
554
+ * }
555
+ * ```
556
+ */
557
+ create(options) {
558
+ return __async(this, null, function* () {
559
+ var _a;
560
+ return this.http.post("/domain", {
561
+ name: options.name,
562
+ region: (_a = options.region) != null ? _a : DEFAULT_REGION
563
+ });
564
+ });
565
+ }
566
+ /**
567
+ * Get a domain by ID, including its current verification status and DNS
568
+ * records.
569
+ */
570
+ get(id) {
571
+ return __async(this, null, function* () {
572
+ return this.http.get(`/domain/${encodeURIComponent(id)}`);
573
+ });
574
+ }
575
+ /**
576
+ * List all domains in the project.
577
+ */
578
+ list() {
579
+ return __async(this, null, function* () {
580
+ return this.http.get("/domain");
581
+ });
582
+ }
583
+ /**
584
+ * Start the verification process for a domain. Add the DNS records returned
585
+ * by {@link create} or {@link get} first; Zupost then checks them and
586
+ * updates the domain's `status`.
587
+ */
588
+ verify(id) {
589
+ return __async(this, null, function* () {
590
+ return this.http.post(
591
+ `/domain/${encodeURIComponent(id)}/verify`,
592
+ void 0
593
+ );
594
+ });
595
+ }
596
+ /**
597
+ * Schedule a domain for deletion.
598
+ */
599
+ delete(id) {
600
+ return __async(this, null, function* () {
601
+ return this.http.delete(`/domain/${encodeURIComponent(id)}`);
602
+ });
603
+ }
604
+ };
605
+
606
+ // src/inbound/inbound.ts
607
+ var Inbound = class {
608
+ constructor(http) {
609
+ this.http = http;
610
+ /**
611
+ * Inbound channels route mail received on a domain to a webhook.
612
+ */
613
+ this.channels = {
614
+ /**
615
+ * Create an inbound channel for a verified domain.
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * const channel = await zupost.inbound.channels.create({
620
+ * name: 'Support inbox',
621
+ * domainId: 'dom_123',
622
+ * webhookUrl: 'https://example.com/zupost/inbound',
623
+ * webhookSecret: process.env.ZUPOST_INBOUND_SECRET!,
624
+ * });
625
+ * ```
626
+ */
627
+ create: (options) => __async(this, null, function* () {
628
+ return this.http.post("/inbound-channel", options);
629
+ })
630
+ };
631
+ }
632
+ };
633
+
305
634
  // src/zupost.ts
306
635
  var _client;
307
636
  var Zupost = class {
@@ -315,11 +644,55 @@ var Zupost = class {
315
644
  __privateSet(this, _client, new HttpClient(apiKey, baseUrl, `node-sdk@${version}`));
316
645
  this.emails = new Emails(__privateGet(this, _client));
317
646
  this.campaigns = new Campaigns(__privateGet(this, _client));
647
+ this.contacts = new Contacts(__privateGet(this, _client));
648
+ this.sequences = new Sequences(__privateGet(this, _client));
649
+ this.domains = new Domains(__privateGet(this, _client));
650
+ this.inbound = new Inbound(__privateGet(this, _client));
318
651
  }
319
652
  };
320
653
  _client = new WeakMap();
654
+
655
+ // src/sequence/define.ts
656
+ function defineSequence(definition) {
657
+ const issues = [];
658
+ const stepKeys = Object.keys(definition.steps);
659
+ if (!definition.steps[definition.entry]) {
660
+ issues.push(`entry "${String(definition.entry)}" is not a defined step`);
661
+ }
662
+ if (stepKeys.length === 0) issues.push("steps must contain at least one step");
663
+ for (const key of stepKeys) {
664
+ const step = definition.steps[key];
665
+ if (step.key !== key) issues.push(`step.key "${step.key}" does not match object key "${key}"`);
666
+ const checkRef = (ref, where) => {
667
+ if (ref && !definition.steps[ref]) {
668
+ issues.push(`step "${key}" ${where} points at unknown step "${ref}"`);
669
+ }
670
+ };
671
+ switch (step.type) {
672
+ case "send_email":
673
+ case "wait":
674
+ case "tag_add":
675
+ case "tag_remove":
676
+ case "update_contact":
677
+ case "webhook":
678
+ checkRef(step.next, "next");
679
+ break;
680
+ case "branch":
681
+ checkRef(step.thenNext, "thenNext");
682
+ checkRef(step.elseNext, "elseNext");
683
+ break;
684
+ case "end":
685
+ break;
686
+ }
687
+ }
688
+ if (issues.length > 0) {
689
+ throw new Error(`Invalid sequence definition: ${issues.join("; ")}`);
690
+ }
691
+ return definition;
692
+ }
321
693
  // Annotate the CommonJS export names for ESM import in node:
322
694
  0 && (module.exports = {
323
695
  Zupost,
324
- ZupostError
696
+ ZupostError,
697
+ defineSequence
325
698
  });