@dereekb/nestjs 13.31.0 → 13.32.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.
@@ -7,15 +7,15 @@ var Mailgun = require('mailgun.js');
7
7
  var FormData = require('form-data');
8
8
  var config = require('@nestjs/config');
9
9
 
10
- function _array_like_to_array$1(arr, len) {
10
+ function _array_like_to_array$2(arr, len) {
11
11
  if (len == null || len > arr.length) len = arr.length;
12
12
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
13
13
  return arr2;
14
14
  }
15
- function _array_with_holes(arr) {
15
+ function _array_with_holes$1(arr) {
16
16
  if (Array.isArray(arr)) return arr;
17
17
  }
18
- function _define_property$4(obj, key, value) {
18
+ function _define_property$5(obj, key, value) {
19
19
  if (key in obj) {
20
20
  Object.defineProperty(obj, key, {
21
21
  value: value,
@@ -36,7 +36,7 @@ function _instanceof(left, right) {
36
36
  return left instanceof right;
37
37
  }
38
38
  }
39
- function _iterable_to_array_limit(arr, i) {
39
+ function _iterable_to_array_limit$1(arr, i) {
40
40
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
41
41
  if (_i == null) return;
42
42
  var _arr = [];
@@ -60,10 +60,10 @@ function _iterable_to_array_limit(arr, i) {
60
60
  }
61
61
  return _arr;
62
62
  }
63
- function _non_iterable_rest() {
63
+ function _non_iterable_rest$1() {
64
64
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
65
  }
66
- function _object_spread$2(target) {
66
+ function _object_spread$3(target) {
67
67
  for(var i = 1; i < arguments.length; i++){
68
68
  var source = arguments[i] != null ? arguments[i] : {};
69
69
  var ownKeys = Object.keys(source);
@@ -73,7 +73,7 @@ function _object_spread$2(target) {
73
73
  }));
74
74
  }
75
75
  ownKeys.forEach(function(key) {
76
- _define_property$4(target, key, source[key]);
76
+ _define_property$5(target, key, source[key]);
77
77
  });
78
78
  }
79
79
  return target;
@@ -97,20 +97,20 @@ function _object_spread_props$1(target, source) {
97
97
  }
98
98
  return target;
99
99
  }
100
- function _sliced_to_array(arr, i) {
101
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest();
100
+ function _sliced_to_array$1(arr, i) {
101
+ return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$1();
102
102
  }
103
103
  function _type_of$1(obj) {
104
104
  "@swc/helpers - typeof";
105
105
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
106
106
  }
107
- function _unsupported_iterable_to_array$1(o, minLen) {
107
+ function _unsupported_iterable_to_array$2(o, minLen) {
108
108
  if (!o) return;
109
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
109
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
110
110
  var n = Object.prototype.toString.call(o).slice(8, -1);
111
111
  if (n === "Object" && o.constructor) n = o.constructor.name;
112
112
  if (n === "Map" || n === "Set") return Array.from(n);
113
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
113
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
114
114
  }
115
115
  var DEFAULT_RECIPIENT_VARIABLE_PREFIX = 'recipient-';
116
116
  var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
@@ -136,7 +136,7 @@ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
136
136
  var allowBatchSending = (_request_batchSend = request.batchSend) !== null && _request_batchSend !== void 0 ? _request_batchSend : true;
137
137
  var mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
138
138
  function mapEmailToLowercase(x) {
139
- return _object_spread_props$1(_object_spread$2({}, x), {
139
+ return _object_spread_props$1(_object_spread$3({}, x), {
140
140
  email: x.email.toLowerCase()
141
141
  });
142
142
  }
@@ -154,7 +154,7 @@ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
154
154
  if (allowBatchSending && to.length > MAX_BATCH_SEND_RECIPIENTS) {
155
155
  throw new Error("convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ".concat(MAX_BATCH_SEND_RECIPIENTS, " recipients."));
156
156
  }
157
- var data = _object_spread$2({
157
+ var data = _object_spread$3({
158
158
  from: from,
159
159
  to: to,
160
160
  cc: cc,
@@ -171,7 +171,7 @@ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
171
171
  if (request.templateVariables) {
172
172
  util.forEachKeyValue(request.templateVariables, {
173
173
  forEach: function forEach(x) {
174
- var _x = _sliced_to_array(x, 2), key = _x[0], value = _x[1];
174
+ var _x = _sliced_to_array$1(x, 2), key = _x[0], value = _x[1];
175
175
  var encodedValue = encodeMailgunTemplateVariableValue(value);
176
176
  if (encodedValue != null) {
177
177
  data["v:".concat(key)] = encodedValue;
@@ -200,7 +200,7 @@ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
200
200
  var decoded = JSON.parse(data['recipient-variables']);
201
201
  util.forEachKeyValue(decoded, {
202
202
  forEach: function forEach(x) {
203
- var _x = _sliced_to_array(x, 2), recipientEmail = _x[0], userVariables = _x[1];
203
+ var _x = _sliced_to_array$1(x, 2), recipientEmail = _x[0], userVariables = _x[1];
204
204
  var email = recipientEmail.toLowerCase();
205
205
  if (email in recipientVariables) {
206
206
  util.overrideInObject(recipientVariables[email], {
@@ -228,10 +228,10 @@ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
228
228
  // iterate all recipient variables and merge them into the global variables
229
229
  util.forEachKeyValue(recipientVariables, {
230
230
  forEach: function forEach(x) {
231
- var _x = _sliced_to_array(x, 2); _x[0]; var userVariables = _x[1];
231
+ var _x = _sliced_to_array$1(x, 2); _x[0]; var userVariables = _x[1];
232
232
  util.forEachKeyValue(userVariables, {
233
233
  forEach: function forEach(y) {
234
- var _y = _sliced_to_array(y, 2), key = _y[0], value = _y[1];
234
+ var _y = _sliced_to_array$1(y, 2), key = _y[0], value = _y[1];
235
235
  var encodedValue = encodeMailgunTemplateVariableValue(value);
236
236
  if (encodedValue != null) {
237
237
  if (addRecipientPrefixVariable) {
@@ -375,7 +375,7 @@ function _create_class$2(Constructor, protoProps, staticProps) {
375
375
  if (staticProps) _defineProperties$2(Constructor, staticProps);
376
376
  return Constructor;
377
377
  }
378
- function _define_property$3(obj, key, value) {
378
+ function _define_property$4(obj, key, value) {
379
379
  if (key in obj) {
380
380
  Object.defineProperty(obj, key, {
381
381
  value: value,
@@ -392,19 +392,19 @@ var MailgunServiceConfig = /*#__PURE__*/ function() {
392
392
  function MailgunServiceConfig() {
393
393
  _class_call_check$3(this, MailgunServiceConfig);
394
394
  // Mailgun Config
395
- _define_property$3(this, "mailgun", void 0);
395
+ _define_property$4(this, "mailgun", void 0);
396
396
  /**
397
397
  * Base URL to the client.
398
- */ _define_property$3(this, "clientUrl", void 0);
398
+ */ _define_property$4(this, "clientUrl", void 0);
399
399
  /**
400
400
  * Main domain to send emails from.
401
- */ _define_property$3(this, "domain", void 0);
401
+ */ _define_property$4(this, "domain", void 0);
402
402
  /**
403
403
  * Mailgun sender string.
404
- */ _define_property$3(this, "sender", void 0);
404
+ */ _define_property$4(this, "sender", void 0);
405
405
  /**
406
406
  * Additional messages config
407
- */ _define_property$3(this, "messages", void 0);
407
+ */ _define_property$4(this, "messages", void 0);
408
408
  }
409
409
  _create_class$2(MailgunServiceConfig, null, [
410
410
  {
@@ -446,7 +446,7 @@ function _create_class$1(Constructor, protoProps, staticProps) {
446
446
  if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
447
447
  return Constructor;
448
448
  }
449
- function _define_property$2(obj, key, value) {
449
+ function _define_property$3(obj, key, value) {
450
450
  if (key in obj) {
451
451
  Object.defineProperty(obj, key, {
452
452
  value: value,
@@ -459,7 +459,7 @@ function _define_property$2(obj, key, value) {
459
459
  }
460
460
  return obj;
461
461
  }
462
- function _object_spread$1(target) {
462
+ function _object_spread$2(target) {
463
463
  for(var i = 1; i < arguments.length; i++){
464
464
  var source = arguments[i] != null ? arguments[i] : {};
465
465
  var ownKeys = Object.keys(source);
@@ -469,7 +469,7 @@ function _object_spread$1(target) {
469
469
  }));
470
470
  }
471
471
  ownKeys.forEach(function(key) {
472
- _define_property$2(target, key, source[key]);
472
+ _define_property$3(target, key, source[key]);
473
473
  });
474
474
  }
475
475
  return target;
@@ -477,10 +477,10 @@ function _object_spread$1(target) {
477
477
  exports.MailgunApi = /*#__PURE__*/ function() {
478
478
  function MailgunApi(config) {
479
479
  _class_call_check$2(this, MailgunApi);
480
- _define_property$2(this, "config", void 0);
481
- _define_property$2(this, "client", void 0);
480
+ _define_property$3(this, "config", void 0);
481
+ _define_property$3(this, "client", void 0);
482
482
  this.config = config;
483
- this.client = new Mailgun(FormData).client(_object_spread$1({}, config.mailgun));
483
+ this.client = new Mailgun(FormData).client(_object_spread$2({}, config.mailgun));
484
484
  }
485
485
  _create_class$1(MailgunApi, [
486
486
  {
@@ -489,6 +489,50 @@ exports.MailgunApi = /*#__PURE__*/ function() {
489
489
  return this.client.messages;
490
490
  }
491
491
  },
492
+ {
493
+ key: "suppressions",
494
+ get: /**
495
+ * The domain's suppression lists (bounces, spam complaints, unsubscribes, whitelists).
496
+ *
497
+ * An address on the bounce or complaint list is silently dropped by Mailgun on every subsequent send,
498
+ * which makes this the first thing to check when diagnosing "this recipient stopped receiving email".
499
+ *
500
+ * @returns The suppressions client.
501
+ */ function get() {
502
+ return this.client.suppressions;
503
+ }
504
+ },
505
+ {
506
+ key: "events",
507
+ get: /**
508
+ * The domain's event log, used to inspect what actually happened to sent messages
509
+ * (accepted/delivered/failed/rejected/complained/unsubscribed).
510
+ *
511
+ * @returns The events client.
512
+ */ function get() {
513
+ return this.client.events;
514
+ }
515
+ },
516
+ {
517
+ key: "validate",
518
+ get: /**
519
+ * Single-address validation.
520
+ *
521
+ * @returns The validation client.
522
+ */ function get() {
523
+ return this.client.validate;
524
+ }
525
+ },
526
+ {
527
+ key: "domains",
528
+ get: /**
529
+ * Domain administration, used to read the sending domain's verification state.
530
+ *
531
+ * @returns The domains client.
532
+ */ function get() {
533
+ return this.client.domains;
534
+ }
535
+ },
492
536
  {
493
537
  key: "clientUrl",
494
538
  get: function get() {
@@ -515,6 +559,604 @@ exports.MailgunApi = __decorate([
515
559
  __param(0, common.Inject(MailgunServiceConfig))
516
560
  ], exports.MailgunApi);
517
561
 
562
+ function _array_like_to_array$1(arr, len) {
563
+ if (len == null || len > arr.length) len = arr.length;
564
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
565
+ return arr2;
566
+ }
567
+ function _array_with_holes(arr) {
568
+ if (Array.isArray(arr)) return arr;
569
+ }
570
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
571
+ try {
572
+ var info = gen[key](arg);
573
+ var value = info.value;
574
+ } catch (error) {
575
+ reject(error);
576
+ return;
577
+ }
578
+ if (info.done) {
579
+ resolve(value);
580
+ } else {
581
+ Promise.resolve(value).then(_next, _throw);
582
+ }
583
+ }
584
+ function _async_to_generator$1(fn) {
585
+ return function() {
586
+ var self = this, args = arguments;
587
+ return new Promise(function(resolve, reject) {
588
+ var gen = fn.apply(self, args);
589
+ function _next(value) {
590
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
591
+ }
592
+ function _throw(err) {
593
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
594
+ }
595
+ _next(undefined);
596
+ });
597
+ };
598
+ }
599
+ function _define_property$2(obj, key, value) {
600
+ if (key in obj) {
601
+ Object.defineProperty(obj, key, {
602
+ value: value,
603
+ enumerable: true,
604
+ configurable: true,
605
+ writable: true
606
+ });
607
+ } else {
608
+ obj[key] = value;
609
+ }
610
+ return obj;
611
+ }
612
+ function _iterable_to_array_limit(arr, i) {
613
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
614
+ if (_i == null) return;
615
+ var _arr = [];
616
+ var _n = true;
617
+ var _d = false;
618
+ var _s, _e;
619
+ try {
620
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
621
+ _arr.push(_s.value);
622
+ if (i && _arr.length === i) break;
623
+ }
624
+ } catch (err) {
625
+ _d = true;
626
+ _e = err;
627
+ } finally{
628
+ try {
629
+ if (!_n && _i["return"] != null) _i["return"]();
630
+ } finally{
631
+ if (_d) throw _e;
632
+ }
633
+ }
634
+ return _arr;
635
+ }
636
+ function _non_iterable_rest() {
637
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
638
+ }
639
+ function _object_spread$1(target) {
640
+ for(var i = 1; i < arguments.length; i++){
641
+ var source = arguments[i] != null ? arguments[i] : {};
642
+ var ownKeys = Object.keys(source);
643
+ if (typeof Object.getOwnPropertySymbols === "function") {
644
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
645
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
646
+ }));
647
+ }
648
+ ownKeys.forEach(function(key) {
649
+ _define_property$2(target, key, source[key]);
650
+ });
651
+ }
652
+ return target;
653
+ }
654
+ function _sliced_to_array(arr, i) {
655
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest();
656
+ }
657
+ function _unsupported_iterable_to_array$1(o, minLen) {
658
+ if (!o) return;
659
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
660
+ var n = Object.prototype.toString.call(o).slice(8, -1);
661
+ if (n === "Object" && o.constructor) n = o.constructor.name;
662
+ if (n === "Map" || n === "Set") return Array.from(n);
663
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
664
+ }
665
+ function _ts_generator$1(thisArg, body) {
666
+ var f, y, t, _ = {
667
+ label: 0,
668
+ sent: function() {
669
+ if (t[0] & 1) throw t[1];
670
+ return t[1];
671
+ },
672
+ trys: [],
673
+ ops: []
674
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
675
+ return d(g, "next", {
676
+ value: verb(0)
677
+ }), d(g, "throw", {
678
+ value: verb(1)
679
+ }), d(g, "return", {
680
+ value: verb(2)
681
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
682
+ value: function() {
683
+ return this;
684
+ }
685
+ }), g;
686
+ function verb(n) {
687
+ return function(v) {
688
+ return step([
689
+ n,
690
+ v
691
+ ]);
692
+ };
693
+ }
694
+ function step(op) {
695
+ if (f) throw new TypeError("Generator is already executing.");
696
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
697
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
698
+ if (y = 0, t) op = [
699
+ op[0] & 2,
700
+ t.value
701
+ ];
702
+ switch(op[0]){
703
+ case 0:
704
+ case 1:
705
+ t = op;
706
+ break;
707
+ case 4:
708
+ _.label++;
709
+ return {
710
+ value: op[1],
711
+ done: false
712
+ };
713
+ case 5:
714
+ _.label++;
715
+ y = op[1];
716
+ op = [
717
+ 0
718
+ ];
719
+ continue;
720
+ case 7:
721
+ op = _.ops.pop();
722
+ _.trys.pop();
723
+ continue;
724
+ default:
725
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
726
+ _ = 0;
727
+ continue;
728
+ }
729
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
730
+ _.label = op[1];
731
+ break;
732
+ }
733
+ if (op[0] === 6 && _.label < t[1]) {
734
+ _.label = t[1];
735
+ t = op;
736
+ break;
737
+ }
738
+ if (t && _.label < t[2]) {
739
+ _.label = t[2];
740
+ _.ops.push(op);
741
+ break;
742
+ }
743
+ if (t[2]) _.ops.pop();
744
+ _.trys.pop();
745
+ continue;
746
+ }
747
+ op = body.call(thisArg, _);
748
+ } catch (e) {
749
+ op = [
750
+ 6,
751
+ e
752
+ ];
753
+ y = 0;
754
+ } finally{
755
+ f = t = 0;
756
+ }
757
+ if (op[0] & 5) throw op[1];
758
+ return {
759
+ value: op[0] ? op[1] : void 0,
760
+ done: true
761
+ };
762
+ }
763
+ }
764
+ /**
765
+ * The default number of events to read back when inspecting a recipient's recent activity.
766
+ */ var DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT = 25;
767
+ /**
768
+ * The default window of history to inspect when reading a recipient's recent events.
769
+ */ var DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS = 30;
770
+ /**
771
+ * Mailgun event names relevant to delivery diagnosis.
772
+ *
773
+ * Mailgun returns these as free-form strings; this enum names the ones that carry
774
+ * delivery meaning. Unknown values are passed through untouched.
775
+ */ exports.MailgunEventName = void 0;
776
+ (function(MailgunEventName) {
777
+ MailgunEventName["ACCEPTED"] = "accepted";
778
+ MailgunEventName["DELIVERED"] = "delivered";
779
+ MailgunEventName["FAILED"] = "failed";
780
+ MailgunEventName["REJECTED"] = "rejected";
781
+ MailgunEventName["COMPLAINED"] = "complained";
782
+ MailgunEventName["UNSUBSCRIBED"] = "unsubscribed";
783
+ MailgunEventName["OPENED"] = "opened";
784
+ MailgunEventName["CLICKED"] = "clicked";
785
+ MailgunEventName["STORED"] = "stored";
786
+ })(exports.MailgunEventName || (exports.MailgunEventName = {}));
787
+ /**
788
+ * Mailgun failure severities. A `permanent` failure will never succeed on retry;
789
+ * a `temporary` one may.
790
+ */ exports.MailgunEventSeverity = void 0;
791
+ (function(MailgunEventSeverity) {
792
+ MailgunEventSeverity["PERMANENT"] = "permanent";
793
+ MailgunEventSeverity["TEMPORARY"] = "temporary";
794
+ })(exports.MailgunEventSeverity || (exports.MailgunEventSeverity = {}));
795
+ /**
796
+ * True if any suppression record was found for the address.
797
+ *
798
+ * @param suppressions - The suppression records to check.
799
+ * @returns True if the address appears on any of the domain's suppression lists.
800
+ */ function hasAnyMailgunRecipientSuppression(suppressions) {
801
+ return suppressions.bounce != null || suppressions.complaint != null || suppressions.unsubscribe != null;
802
+ }
803
+ /**
804
+ * Reads a single suppression entry, treating "not found" as an absent value.
805
+ *
806
+ * The Mailgun API responds 404 when the address is not on the requested list, which is the common case
807
+ * and not an error condition here.
808
+ *
809
+ * @param read - Performs the suppression lookup.
810
+ * @returns The suppression record, or undefined if the address is not on the list or the lookup failed.
811
+ */ function readSuppression(read) {
812
+ return _async_to_generator$1(function() {
813
+ var result;
814
+ return _ts_generator$1(this, function(_state) {
815
+ switch(_state.label){
816
+ case 0:
817
+ _state.trys.push([
818
+ 0,
819
+ 2,
820
+ ,
821
+ 3
822
+ ]);
823
+ return [
824
+ 4,
825
+ read()
826
+ ];
827
+ case 1:
828
+ result = _state.sent();
829
+ return [
830
+ 3,
831
+ 3
832
+ ];
833
+ case 2:
834
+ _state.sent();
835
+ result = undefined;
836
+ return [
837
+ 3,
838
+ 3
839
+ ];
840
+ case 3:
841
+ return [
842
+ 2,
843
+ result
844
+ ];
845
+ }
846
+ });
847
+ })();
848
+ }
849
+ /**
850
+ * Looks up an address across the domain's bounce, complaint, and unsubscribe lists.
851
+ *
852
+ * @param api - The Mailgun API.
853
+ * @param email - The address to look up.
854
+ * @returns The suppression records found for the address. Absent fields mean the address is not on that list.
855
+ *
856
+ * @example
857
+ * ```ts
858
+ * const suppressions = await mailgunSuppressionsForRecipient(api, 'user@example.com');
859
+ *
860
+ * if (suppressions.bounce) {
861
+ * console.log(`suppressed by bounce: ${suppressions.bounce.error}`);
862
+ * }
863
+ * ```
864
+ */ function mailgunSuppressionsForRecipient(api, email) {
865
+ return _async_to_generator$1(function() {
866
+ var domain, suppressions, _ref, bounce, complaint, unsubscribe;
867
+ return _ts_generator$1(this, function(_state) {
868
+ switch(_state.label){
869
+ case 0:
870
+ domain = api.domain, suppressions = api.suppressions;
871
+ return [
872
+ 4,
873
+ Promise.all([
874
+ //
875
+ readSuppression(function() {
876
+ return suppressions.get(domain, 'bounces', email);
877
+ }),
878
+ readSuppression(function() {
879
+ return suppressions.get(domain, 'complaints', email);
880
+ }),
881
+ readSuppression(function() {
882
+ return suppressions.get(domain, 'unsubscribes', email);
883
+ })
884
+ ])
885
+ ];
886
+ case 1:
887
+ _ref = _sliced_to_array.apply(void 0, [
888
+ _state.sent(),
889
+ 3
890
+ ]), bounce = _ref[0], complaint = _ref[1], unsubscribe = _ref[2];
891
+ return [
892
+ 2,
893
+ {
894
+ bounce: bounce,
895
+ complaint: complaint,
896
+ unsubscribe: unsubscribe
897
+ }
898
+ ];
899
+ }
900
+ });
901
+ })();
902
+ }
903
+ /**
904
+ * Reads the most recent Mailgun events for a recipient address, newest first.
905
+ *
906
+ * @param api - The Mailgun API.
907
+ * @param email - The recipient address to filter on.
908
+ * @param config - Optional limit/window/event filters.
909
+ * @returns The matching events, newest first. Empty if there is no recent activity or the lookup failed.
910
+ *
911
+ * @example
912
+ * ```ts
913
+ * const events = await mailgunRecentEventsForRecipient(api, 'user@example.com', { limit: 10 });
914
+ * const lastDelivered = events.find((x) => x.event === MailgunEventName.DELIVERED);
915
+ * ```
916
+ */ function mailgunRecentEventsForRecipient(api, email, config) {
917
+ return _async_to_generator$1(function() {
918
+ var _ref, _ref1, limit, begin, query;
919
+ return _ts_generator$1(this, function(_state) {
920
+ limit = (_ref = config === null || config === void 0 ? void 0 : config.limit) !== null && _ref !== void 0 ? _ref : DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT;
921
+ begin = (_ref1 = config === null || config === void 0 ? void 0 : config.begin) !== null && _ref1 !== void 0 ? _ref1 : new Date(Date.now() - DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS * 24 * 60 * 60 * 1000);
922
+ query = {
923
+ recipient: email,
924
+ begin: begin.toUTCString(),
925
+ ascending: 'no',
926
+ limit: limit
927
+ };
928
+ if (config === null || config === void 0 ? void 0 : config.event) {
929
+ query.event = config.event;
930
+ }
931
+ return [
932
+ 2,
933
+ mailgunEventsForQuery(api, query)
934
+ ];
935
+ });
936
+ })();
937
+ }
938
+ /**
939
+ * Strips the angle brackets Mailgun's send response wraps a message id in.
940
+ *
941
+ * `messages.create()` returns an id shaped like `<20240101120000.1.abc@domain>`, while the
942
+ * Events API `message-id` filter expects the bare `20240101120000.1.abc@domain`. Passing the
943
+ * bracketed form matches nothing.
944
+ *
945
+ * @param messageId - A message id in either form.
946
+ * @returns The message id without surrounding angle brackets.
947
+ */ function bareMailgunMessageId(messageId) {
948
+ return messageId.replaceAll(/^<|>$/g, '');
949
+ }
950
+ /**
951
+ * Reads all Mailgun events recorded for a specific message id.
952
+ *
953
+ * Used to resolve the outcome of a message that was already sent — the Events API lags the
954
+ * send by seconds to minutes, so an empty result means "not known yet", not "not delivered".
955
+ *
956
+ * @param api - The Mailgun API.
957
+ * @param messageId - The message id, with or without angle brackets.
958
+ * @param config - Optional additional filters (e.g. `recipient` to scope the lookup).
959
+ * @returns The events recorded for the message. Empty if none are recorded yet or the lookup failed.
960
+ */ function mailgunEventsForMessageId(api, messageId, config) {
961
+ return _async_to_generator$1(function() {
962
+ var query;
963
+ return _ts_generator$1(this, function(_state) {
964
+ query = _object_spread$1({
965
+ 'message-id': bareMailgunMessageId(messageId),
966
+ ascending: 'no'
967
+ }, config);
968
+ return [
969
+ 2,
970
+ mailgunEventsForQuery(api, query)
971
+ ];
972
+ });
973
+ })();
974
+ }
975
+ /**
976
+ * Runs an arbitrary Events API query, returning an empty list if the lookup fails.
977
+ *
978
+ * @param api - The Mailgun API.
979
+ * @param query - The events query.
980
+ * @returns The matching events, or an empty array on failure.
981
+ */ function mailgunEventsForQuery(api, query) {
982
+ return _async_to_generator$1(function() {
983
+ var events, _result_items, result;
984
+ return _ts_generator$1(this, function(_state) {
985
+ switch(_state.label){
986
+ case 0:
987
+ _state.trys.push([
988
+ 0,
989
+ 2,
990
+ ,
991
+ 3
992
+ ]);
993
+ return [
994
+ 4,
995
+ api.events.get(api.domain, query)
996
+ ];
997
+ case 1:
998
+ result = _state.sent();
999
+ events = (_result_items = result.items) !== null && _result_items !== void 0 ? _result_items : [];
1000
+ return [
1001
+ 3,
1002
+ 3
1003
+ ];
1004
+ case 2:
1005
+ _state.sent();
1006
+ events = [];
1007
+ return [
1008
+ 3,
1009
+ 3
1010
+ ];
1011
+ case 3:
1012
+ return [
1013
+ 2,
1014
+ events
1015
+ ];
1016
+ }
1017
+ });
1018
+ })();
1019
+ }
1020
+ /**
1021
+ * Reads the sending domain's state.
1022
+ *
1023
+ * A domain that is not `active` will fail to deliver regardless of recipient configuration,
1024
+ * so this distinguishes a system-wide outage from a per-recipient problem.
1025
+ *
1026
+ * @param api - The Mailgun API.
1027
+ * @returns The domain's state, with `unknown` set if it could not be read.
1028
+ */ function mailgunDomainState(api) {
1029
+ return _async_to_generator$1(function() {
1030
+ var domain, state, result;
1031
+ return _ts_generator$1(this, function(_state) {
1032
+ switch(_state.label){
1033
+ case 0:
1034
+ domain = api.domain;
1035
+ _state.label = 1;
1036
+ case 1:
1037
+ _state.trys.push([
1038
+ 1,
1039
+ 3,
1040
+ ,
1041
+ 4
1042
+ ]);
1043
+ return [
1044
+ 4,
1045
+ api.domains.get(domain)
1046
+ ];
1047
+ case 2:
1048
+ result = _state.sent();
1049
+ state = {
1050
+ domain: domain,
1051
+ state: result === null || result === void 0 ? void 0 : result.state,
1052
+ disabled: result === null || result === void 0 ? void 0 : result.is_disabled
1053
+ };
1054
+ return [
1055
+ 3,
1056
+ 4
1057
+ ];
1058
+ case 3:
1059
+ _state.sent();
1060
+ state = {
1061
+ domain: domain,
1062
+ unknown: true
1063
+ };
1064
+ return [
1065
+ 3,
1066
+ 4
1067
+ ];
1068
+ case 4:
1069
+ return [
1070
+ 2,
1071
+ state
1072
+ ];
1073
+ }
1074
+ });
1075
+ })();
1076
+ }
1077
+ /**
1078
+ * Validates a single email address via the Mailgun Validation API.
1079
+ *
1080
+ * Note that validation consumes Mailgun validation quota, so callers should treat this as
1081
+ * an opt-in check rather than something to run on every request.
1082
+ *
1083
+ * @param api - The Mailgun API.
1084
+ * @param email - The address to validate.
1085
+ * @returns The validation result, or undefined if validation is unavailable or failed.
1086
+ */ function mailgunValidateEmail(api, email) {
1087
+ return _async_to_generator$1(function() {
1088
+ var result;
1089
+ return _ts_generator$1(this, function(_state) {
1090
+ switch(_state.label){
1091
+ case 0:
1092
+ _state.trys.push([
1093
+ 0,
1094
+ 2,
1095
+ ,
1096
+ 3
1097
+ ]);
1098
+ return [
1099
+ 4,
1100
+ api.validate.get(email)
1101
+ ];
1102
+ case 1:
1103
+ result = _state.sent();
1104
+ return [
1105
+ 3,
1106
+ 3
1107
+ ];
1108
+ case 2:
1109
+ _state.sent();
1110
+ result = undefined;
1111
+ return [
1112
+ 3,
1113
+ 3
1114
+ ];
1115
+ case 3:
1116
+ return [
1117
+ 2,
1118
+ result
1119
+ ];
1120
+ }
1121
+ });
1122
+ })();
1123
+ }
1124
+ /**
1125
+ * Converts a Mailgun event's unix-seconds timestamp to a Date.
1126
+ *
1127
+ * @param event - The event.
1128
+ * @returns The event's timestamp as a Date.
1129
+ */ function mailgunDomainEventDate(event) {
1130
+ return new Date(event.timestamp * 1000);
1131
+ }
1132
+ /**
1133
+ * The age of a Mailgun event in milliseconds relative to `now`.
1134
+ *
1135
+ * @param event - The event.
1136
+ * @param now - The reference time. Defaults to the current time.
1137
+ * @returns The event's age in milliseconds.
1138
+ */ function mailgunDomainEventAge(event) {
1139
+ var now = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : new Date();
1140
+ return now.getTime() - mailgunDomainEventDate(event).getTime();
1141
+ }
1142
+ /**
1143
+ * Extracts the most useful human-readable reason from a failed/rejected Mailgun event.
1144
+ *
1145
+ * Mailgun spreads the explanation across `reason`, `delivery-status.description`, and
1146
+ * `delivery-status.message` depending on how the failure occurred, and any of them may be
1147
+ * empty.
1148
+ *
1149
+ * @param event - The event.
1150
+ * @returns The best available description, or undefined if the event carries none.
1151
+ */ function mailgunDomainEventFailureReason(event) {
1152
+ var _ref;
1153
+ var deliveryStatus = event['delivery-status'];
1154
+ var description = (deliveryStatus === null || deliveryStatus === void 0 ? void 0 : deliveryStatus.description) || undefined;
1155
+ var message = (deliveryStatus === null || deliveryStatus === void 0 ? void 0 : deliveryStatus.message) || undefined;
1156
+ var reason = event.reason || undefined;
1157
+ return (_ref = description !== null && description !== void 0 ? description : message) !== null && _ref !== void 0 ? _ref : reason;
1158
+ }
1159
+
518
1160
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
519
1161
  try {
520
1162
  var info = gen[key](arg);
@@ -1133,15 +1775,28 @@ function _unsupported_iterable_to_array(o, minLen) {
1133
1775
  };
1134
1776
  }
1135
1777
 
1778
+ exports.DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT = DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT;
1779
+ exports.DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS = DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS;
1136
1780
  exports.DEFAULT_RECIPIENT_VARIABLE_PREFIX = DEFAULT_RECIPIENT_VARIABLE_PREFIX;
1137
1781
  exports.MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE;
1138
1782
  exports.MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY;
1139
1783
  exports.MAX_BATCH_SEND_RECIPIENTS = MAX_BATCH_SEND_RECIPIENTS;
1784
+ exports.bareMailgunMessageId = bareMailgunMessageId;
1140
1785
  exports.convertMailgunRecipientToString = convertMailgunRecipientToString;
1141
1786
  exports.convertMailgunRecipientsToStrings = convertMailgunRecipientsToStrings;
1142
1787
  exports.convertMailgunTemplateEmailRequestToMailgunMessageData = convertMailgunTemplateEmailRequestToMailgunMessageData;
1143
1788
  exports.encodeMailgunTemplateVariableValue = encodeMailgunTemplateVariableValue;
1144
1789
  exports.expandMailgunRecipientBatchSendTargetRequestFactory = expandMailgunRecipientBatchSendTargetRequestFactory;
1790
+ exports.hasAnyMailgunRecipientSuppression = hasAnyMailgunRecipientSuppression;
1791
+ exports.mailgunDomainEventAge = mailgunDomainEventAge;
1792
+ exports.mailgunDomainEventDate = mailgunDomainEventDate;
1793
+ exports.mailgunDomainEventFailureReason = mailgunDomainEventFailureReason;
1794
+ exports.mailgunDomainState = mailgunDomainState;
1795
+ exports.mailgunEventsForMessageId = mailgunEventsForMessageId;
1796
+ exports.mailgunEventsForQuery = mailgunEventsForQuery;
1797
+ exports.mailgunRecentEventsForRecipient = mailgunRecentEventsForRecipient;
1145
1798
  exports.mailgunRecipientBatchSendTargetEntityKeyRecipientLookup = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup;
1146
1799
  exports.mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey = mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey;
1147
1800
  exports.mailgunServiceConfigFactory = mailgunServiceConfigFactory;
1801
+ exports.mailgunSuppressionsForRecipient = mailgunSuppressionsForRecipient;
1802
+ exports.mailgunValidateEmail = mailgunValidateEmail;