@unboundcx/sdk 2.7.3 → 2.7.4

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/package.json +1 -1
  2. package/services/messaging.js +230 -67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -214,37 +214,61 @@ export class EmailService {
214
214
  this.addresses = new EmailAddressesService(sdk);
215
215
  }
216
216
 
217
+ /**
218
+ * Send an email message
219
+ * @param {Object} params - Email parameters
220
+ * @param {string} params.from - Sender email address (required)
221
+ * @param {string|Array<string>} params.to - Recipient email address(es) (required)
222
+ * @param {string} params.subject - Email subject (required)
223
+ * @param {string|Array<string>} [params.cc] - CC recipients
224
+ * @param {string|Array<string>} [params.bcc] - BCC recipients
225
+ * @param {string} [params.html] - HTML email body
226
+ * @param {string} [params.text] - Plain text email body
227
+ * @param {string} [params.templateId] - Email template ID to use
228
+ * @param {Object} [params.variables] - Template variables for substitution
229
+ * @param {Array} [params.storageId] - Array of storage IDs for attachments
230
+ * @param {string} [params.replyTo] - Reply-to email address
231
+ * @param {string} [params.replyToEmailId] - ID of email this is replying to
232
+ * @param {string} [params.relatedId] - Related record ID
233
+ * @param {string} [params.emailType='marketing'] - Email type: 'marketing' or 'transactional'
234
+ * @param {boolean} [params.tracking=true] - Enable email tracking (opens, clicks)
235
+ * @returns {Promise<Object>} Email send result with ID
236
+ */
217
237
  async send({
218
238
  from,
219
239
  to,
220
240
  cc,
221
241
  bcc,
222
242
  subject,
223
- htmlBody,
224
- textBody,
243
+ html,
244
+ text,
225
245
  templateId,
226
246
  variables,
227
- attachments,
247
+ storageId,
228
248
  replyTo,
229
- priority,
230
- tags,
249
+ replyToEmailId,
250
+ relatedId,
251
+ emailType,
252
+ tracking,
231
253
  }) {
232
254
  this.sdk.validateParams(
233
255
  { from, to, subject },
234
256
  {
235
257
  from: { type: 'string', required: true },
236
- to: { type: 'string', required: true },
258
+ to: { type: ['string', 'array'], required: true },
237
259
  subject: { type: 'string', required: true },
238
- cc: { type: 'string', required: false },
239
- bcc: { type: 'string', required: false },
240
- htmlBody: { type: 'string', required: false },
241
- textBody: { type: 'string', required: false },
260
+ cc: { type: ['string', 'array'], required: false },
261
+ bcc: { type: ['string', 'array'], required: false },
262
+ html: { type: 'string', required: false },
263
+ text: { type: 'string', required: false },
242
264
  templateId: { type: 'string', required: false },
243
265
  variables: { type: 'object', required: false },
244
- attachments: { type: 'array', required: false },
266
+ storageId: { type: 'array', required: false },
245
267
  replyTo: { type: 'string', required: false },
246
- priority: { type: 'string', required: false },
247
- tags: { type: 'array', required: false },
268
+ replyToEmailId: { type: 'string', required: false },
269
+ relatedId: { type: 'string', required: false },
270
+ emailType: { type: 'string', required: false },
271
+ tracking: { type: 'boolean', required: false },
248
272
  },
249
273
  );
250
274
 
@@ -256,14 +280,16 @@ export class EmailService {
256
280
 
257
281
  if (cc) emailData.cc = cc;
258
282
  if (bcc) emailData.bcc = bcc;
259
- if (htmlBody) emailData.htmlBody = htmlBody;
260
- if (textBody) emailData.textBody = textBody;
283
+ if (html) emailData.html = html;
284
+ if (text) emailData.text = text;
261
285
  if (templateId) emailData.templateId = templateId;
262
286
  if (variables) emailData.variables = variables;
263
- if (attachments) emailData.attachments = attachments;
287
+ if (storageId) emailData.storageId = storageId;
264
288
  if (replyTo) emailData.replyTo = replyTo;
265
- if (priority) emailData.priority = priority;
266
- if (tags) emailData.tags = tags;
289
+ if (replyToEmailId) emailData.replyToEmailId = replyToEmailId;
290
+ if (relatedId) emailData.relatedId = relatedId;
291
+ if (emailType) emailData.emailType = emailType;
292
+ if (tracking !== undefined) emailData.tracking = tracking;
267
293
 
268
294
  const options = {
269
295
  body: emailData,
@@ -273,6 +299,11 @@ export class EmailService {
273
299
  return result;
274
300
  }
275
301
 
302
+ /**
303
+ * Get email message by ID
304
+ * @param {string} id - Email message ID (required)
305
+ * @returns {Promise<Object>} Email message details
306
+ */
276
307
  async get(id) {
277
308
  this.sdk.validateParams(
278
309
  { id },
@@ -285,11 +316,19 @@ export class EmailService {
285
316
  return result;
286
317
  }
287
318
 
288
- async updateDomain(domain, { dkimEnabled, customDkim }) {
319
+ /**
320
+ * Update domain email settings
321
+ * @param {string} id - Domain ID (required)
322
+ * @param {Object} params - Update parameters
323
+ * @param {boolean} [params.dkimEnabled] - Enable DKIM signing
324
+ * @param {Object} [params.customDkim] - Custom DKIM configuration
325
+ * @returns {Promise<Object>} Updated domain details
326
+ */
327
+ async updateDomain(id, { dkimEnabled, customDkim }) {
289
328
  this.sdk.validateParams(
290
- { domain },
329
+ { id },
291
330
  {
292
- domain: { type: 'string', required: true },
331
+ id: { type: 'string', required: true },
293
332
  dkimEnabled: { type: 'boolean', required: false },
294
333
  customDkim: { type: 'object', required: false },
295
334
  },
@@ -304,7 +343,7 @@ export class EmailService {
304
343
  };
305
344
 
306
345
  const result = await this.sdk._fetch(
307
- `/messaging/email/domain/${domain}`,
346
+ `/messaging/email/${id}`,
308
347
  'PUT',
309
348
  options,
310
349
  );
@@ -317,21 +356,31 @@ export class EmailTemplatesService {
317
356
  this.sdk = sdk;
318
357
  }
319
358
 
320
- async create({ name, subject, htmlBody, textBody, variables }) {
359
+ /**
360
+ * Create email template
361
+ * @param {Object} params - Template parameters
362
+ * @param {string} params.name - Template name (required)
363
+ * @param {string} params.subject - Template subject (required)
364
+ * @param {string} [params.html] - HTML template body
365
+ * @param {string} [params.text] - Plain text template body
366
+ * @param {Object} [params.variables] - Template variable definitions
367
+ * @returns {Promise<Object>} Created template details
368
+ */
369
+ async create({ name, subject, html, text, variables }) {
321
370
  this.sdk.validateParams(
322
371
  { name, subject },
323
372
  {
324
373
  name: { type: 'string', required: true },
325
374
  subject: { type: 'string', required: true },
326
- htmlBody: { type: 'string', required: false },
327
- textBody: { type: 'string', required: false },
375
+ html: { type: 'string', required: false },
376
+ text: { type: 'string', required: false },
328
377
  variables: { type: 'object', required: false },
329
378
  },
330
379
  );
331
380
 
332
381
  const templateData = { name, subject };
333
- if (htmlBody) templateData.htmlBody = htmlBody;
334
- if (textBody) templateData.textBody = textBody;
382
+ if (html) templateData.html = html;
383
+ if (text) templateData.text = text;
335
384
  if (variables) templateData.variables = variables;
336
385
 
337
386
  const options = {
@@ -339,22 +388,33 @@ export class EmailTemplatesService {
339
388
  };
340
389
 
341
390
  const result = await this.sdk._fetch(
342
- '/messaging/email/templates',
391
+ '/messaging/email/template',
343
392
  'POST',
344
393
  options,
345
394
  );
346
395
  return result;
347
396
  }
348
397
 
349
- async update(id, { name, subject, htmlBody, textBody, variables }) {
398
+ /**
399
+ * Update email template
400
+ * @param {string} id - Template ID (required)
401
+ * @param {Object} params - Update parameters
402
+ * @param {string} [params.name] - Template name
403
+ * @param {string} [params.subject] - Template subject
404
+ * @param {string} [params.html] - HTML template body
405
+ * @param {string} [params.text] - Plain text template body
406
+ * @param {Object} [params.variables] - Template variable definitions
407
+ * @returns {Promise<Object>} Updated template details
408
+ */
409
+ async update(id, { name, subject, html, text, variables }) {
350
410
  this.sdk.validateParams(
351
411
  { id },
352
412
  {
353
413
  id: { type: 'string', required: true },
354
414
  name: { type: 'string', required: false },
355
415
  subject: { type: 'string', required: false },
356
- htmlBody: { type: 'string', required: false },
357
- textBody: { type: 'string', required: false },
416
+ html: { type: 'string', required: false },
417
+ text: { type: 'string', required: false },
358
418
  variables: { type: 'object', required: false },
359
419
  },
360
420
  );
@@ -362,8 +422,8 @@ export class EmailTemplatesService {
362
422
  const updateData = {};
363
423
  if (name) updateData.name = name;
364
424
  if (subject) updateData.subject = subject;
365
- if (htmlBody) updateData.htmlBody = htmlBody;
366
- if (textBody) updateData.textBody = textBody;
425
+ if (html) updateData.html = html;
426
+ if (text) updateData.text = text;
367
427
  if (variables) updateData.variables = variables;
368
428
 
369
429
  const options = {
@@ -371,13 +431,18 @@ export class EmailTemplatesService {
371
431
  };
372
432
 
373
433
  const result = await this.sdk._fetch(
374
- `/messaging/email/templates/${id}`,
434
+ `/messaging/email/template/${id}`,
375
435
  'PUT',
376
436
  options,
377
437
  );
378
438
  return result;
379
439
  }
380
440
 
441
+ /**
442
+ * Delete email template
443
+ * @param {string} id - Template ID (required)
444
+ * @returns {Promise<Object>} Deletion confirmation
445
+ */
381
446
  async delete(id) {
382
447
  this.sdk.validateParams(
383
448
  { id },
@@ -387,12 +452,17 @@ export class EmailTemplatesService {
387
452
  );
388
453
 
389
454
  const result = await this.sdk._fetch(
390
- `/messaging/email/templates/${id}`,
455
+ `/messaging/email/template/${id}`,
391
456
  'DELETE',
392
457
  );
393
458
  return result;
394
459
  }
395
460
 
461
+ /**
462
+ * Get email template by ID
463
+ * @param {string} id - Template ID (required)
464
+ * @returns {Promise<Object>} Template details
465
+ */
396
466
  async get(id) {
397
467
  this.sdk.validateParams(
398
468
  { id },
@@ -402,14 +472,18 @@ export class EmailTemplatesService {
402
472
  );
403
473
 
404
474
  const result = await this.sdk._fetch(
405
- `/messaging/email/templates/${id}`,
475
+ `/messaging/email/template/${id}`,
406
476
  'GET',
407
477
  );
408
478
  return result;
409
479
  }
410
480
 
481
+ /**
482
+ * List all email templates
483
+ * @returns {Promise<Array>} List of email templates
484
+ */
411
485
  async list() {
412
- const result = await this.sdk._fetch('/messaging/email/templates', 'GET');
486
+ const result = await this.sdk._fetch('/messaging/email/template', 'GET');
413
487
  return result;
414
488
  }
415
489
  }
@@ -419,46 +493,82 @@ export class EmailDomainsService {
419
493
  this.sdk = sdk;
420
494
  }
421
495
 
422
- async create(domain) {
496
+ /**
497
+ * Create domain verification
498
+ * @param {Object} params - Domain parameters
499
+ * @param {string} params.domain - Domain name (required)
500
+ * @param {string} [params.primaryRegion] - Primary AWS region
501
+ * @param {string} [params.secondaryRegion] - Secondary AWS region
502
+ * @param {string} [params.mailFromSubdomain='mail'] - Mail-from subdomain
503
+ * @returns {Promise<Object>} Created domain with DNS records to configure
504
+ */
505
+ async create({ domain, primaryRegion, secondaryRegion, mailFromSubdomain }) {
423
506
  this.sdk.validateParams(
424
507
  { domain },
425
508
  {
426
509
  domain: { type: 'string', required: true },
510
+ primaryRegion: { type: 'string', required: false },
511
+ secondaryRegion: { type: 'string', required: false },
512
+ mailFromSubdomain: { type: 'string', required: false },
427
513
  },
428
514
  );
429
515
 
516
+ const domainData = { domain };
517
+ if (primaryRegion) domainData.primaryRegion = primaryRegion;
518
+ if (secondaryRegion) domainData.secondaryRegion = secondaryRegion;
519
+ if (mailFromSubdomain) domainData.mailFromSubdomain = mailFromSubdomain;
520
+
430
521
  const options = {
431
- body: { domain },
522
+ body: domainData,
432
523
  };
433
524
 
434
525
  const result = await this.sdk._fetch(
435
- '/messaging/email/domains',
526
+ '/messaging/email/validate/domain',
436
527
  'POST',
437
528
  options,
438
529
  );
439
530
  return result;
440
531
  }
441
532
 
442
- async delete(domain) {
533
+ /**
534
+ * Delete domain verification
535
+ * @param {string} domainId - Domain ID (required)
536
+ * @returns {Promise<Object>} Deletion confirmation
537
+ */
538
+ async delete(domainId) {
443
539
  this.sdk.validateParams(
444
- { domain },
540
+ { domainId },
445
541
  {
446
- domain: { type: 'string', required: true },
542
+ domainId: { type: 'string', required: true },
447
543
  },
448
544
  );
449
545
 
546
+ const options = {
547
+ body: { domainId },
548
+ };
549
+
450
550
  const result = await this.sdk._fetch(
451
- `/messaging/email/domains/${domain}`,
551
+ '/messaging/email/validate/domain',
452
552
  'DELETE',
553
+ options,
453
554
  );
454
555
  return result;
455
556
  }
456
557
 
558
+ /**
559
+ * List all verified domains
560
+ * @returns {Promise<Array>} List of verified domains with status
561
+ */
457
562
  async list() {
458
- const result = await this.sdk._fetch('/messaging/email/domains', 'GET');
563
+ const result = await this.sdk._fetch('/messaging/email/validate/domain', 'GET');
459
564
  return result;
460
565
  }
461
566
 
567
+ /**
568
+ * Validate DNS records for domain
569
+ * @param {string} domain - Domain name (required)
570
+ * @returns {Promise<Object>} DNS validation results
571
+ */
462
572
  async validateDns(domain) {
463
573
  this.sdk.validateParams(
464
574
  { domain },
@@ -467,13 +577,23 @@ export class EmailDomainsService {
467
577
  },
468
578
  );
469
579
 
580
+ const options = {
581
+ query: { domain },
582
+ };
583
+
470
584
  const result = await this.sdk._fetch(
471
- `/messaging/email/domains/${domain}/validate`,
472
- 'POST',
585
+ '/messaging/email/validate/domain/dns',
586
+ 'GET',
587
+ options,
473
588
  );
474
589
  return result;
475
590
  }
476
591
 
592
+ /**
593
+ * Check domain verification status
594
+ * @param {string} domain - Domain name (required)
595
+ * @returns {Promise<Object>} Domain verification status
596
+ */
477
597
  async checkStatus(domain) {
478
598
  this.sdk.validateParams(
479
599
  { domain },
@@ -482,24 +602,43 @@ export class EmailDomainsService {
482
602
  },
483
603
  );
484
604
 
605
+ const options = {
606
+ query: { domain },
607
+ };
608
+
485
609
  const result = await this.sdk._fetch(
486
- `/messaging/email/domains/${domain}/status`,
610
+ '/messaging/email/validate/domain/status',
487
611
  'GET',
612
+ options,
488
613
  );
489
614
  return result;
490
615
  }
491
616
 
492
- async update(domain, { dkimEnabled, customDkim }) {
617
+ /**
618
+ * Update domain settings
619
+ * @param {Object} params - Update parameters
620
+ * @param {string} params.domainId - Domain ID (required)
621
+ * @param {string} [params.primaryRegion] - Primary AWS region
622
+ * @param {string} [params.secondaryRegion] - Secondary AWS region
623
+ * @param {boolean} [params.dkimEnabled] - Enable DKIM signing
624
+ * @param {Object} [params.customDkim] - Custom DKIM configuration
625
+ * @returns {Promise<Object>} Updated domain details
626
+ */
627
+ async update({ domainId, primaryRegion, secondaryRegion, dkimEnabled, customDkim }) {
493
628
  this.sdk.validateParams(
494
- { domain },
629
+ { domainId },
495
630
  {
496
- domain: { type: 'string', required: true },
631
+ domainId: { type: 'string', required: true },
632
+ primaryRegion: { type: 'string', required: false },
633
+ secondaryRegion: { type: 'string', required: false },
497
634
  dkimEnabled: { type: 'boolean', required: false },
498
635
  customDkim: { type: 'object', required: false },
499
636
  },
500
637
  );
501
638
 
502
- const updateData = {};
639
+ const updateData = { domainId };
640
+ if (primaryRegion) updateData.primaryRegion = primaryRegion;
641
+ if (secondaryRegion) updateData.secondaryRegion = secondaryRegion;
503
642
  if (dkimEnabled !== undefined) updateData.dkimEnabled = dkimEnabled;
504
643
  if (customDkim) updateData.customDkim = customDkim;
505
644
 
@@ -508,7 +647,7 @@ export class EmailDomainsService {
508
647
  };
509
648
 
510
649
  const result = await this.sdk._fetch(
511
- `/messaging/email/domains/${domain}`,
650
+ '/messaging/email/validate/domain',
512
651
  'PUT',
513
652
  options,
514
653
  );
@@ -521,57 +660,81 @@ export class EmailAddressesService {
521
660
  this.sdk = sdk;
522
661
  }
523
662
 
524
- async create(email) {
663
+ /**
664
+ * Create email address verification
665
+ * @param {string} emailAddress - Email address to verify (required)
666
+ * @returns {Promise<Object>} Email verification details
667
+ */
668
+ async create(emailAddress) {
525
669
  this.sdk.validateParams(
526
- { email },
670
+ { emailAddress },
527
671
  {
528
- email: { type: 'string', required: true },
672
+ emailAddress: { type: 'string', required: true },
529
673
  },
530
674
  );
531
675
 
532
676
  const options = {
533
- body: { email },
677
+ body: { emailAddress },
534
678
  };
535
679
 
536
680
  const result = await this.sdk._fetch(
537
- '/messaging/email/addresses',
681
+ '/messaging/email/validate/emailAddress',
538
682
  'POST',
539
683
  options,
540
684
  );
541
685
  return result;
542
686
  }
543
687
 
544
- async delete(email) {
688
+ /**
689
+ * Delete email address verification
690
+ * @param {string} emailAddress - Email address to remove (required)
691
+ * @returns {Promise<Object>} Deletion confirmation
692
+ */
693
+ async delete(emailAddress) {
545
694
  this.sdk.validateParams(
546
- { email },
695
+ { emailAddress },
547
696
  {
548
- email: { type: 'string', required: true },
697
+ emailAddress: { type: 'string', required: true },
549
698
  },
550
699
  );
551
700
 
552
701
  const result = await this.sdk._fetch(
553
- `/messaging/email/addresses/${encodeURIComponent(email)}`,
702
+ `/messaging/email/validate/emailAddress/${encodeURIComponent(emailAddress)}`,
554
703
  'DELETE',
555
704
  );
556
705
  return result;
557
706
  }
558
707
 
708
+ /**
709
+ * List all verified email addresses
710
+ * @returns {Promise<Array>} List of verified email addresses
711
+ */
559
712
  async list() {
560
- const result = await this.sdk._fetch('/messaging/email/addresses', 'GET');
713
+ const result = await this.sdk._fetch('/messaging/email/validate/emailAddress', 'GET');
561
714
  return result;
562
715
  }
563
716
 
564
- async checkStatus(email) {
717
+ /**
718
+ * Check email address verification status
719
+ * @param {string} emailAddress - Email address to check (required)
720
+ * @returns {Promise<Object>} Email verification status
721
+ */
722
+ async checkStatus(emailAddress) {
565
723
  this.sdk.validateParams(
566
- { email },
724
+ { emailAddress },
567
725
  {
568
- email: { type: 'string', required: true },
726
+ emailAddress: { type: 'string', required: true },
569
727
  },
570
728
  );
571
729
 
730
+ const options = {
731
+ query: { emailAddress },
732
+ };
733
+
572
734
  const result = await this.sdk._fetch(
573
- `/messaging/email/addresses/${encodeURIComponent(email)}/status`,
735
+ '/messaging/email/validate/emailAddress/status',
574
736
  'GET',
737
+ options,
575
738
  );
576
739
  return result;
577
740
  }