@dereekb/nestjs 13.2.1 → 13.3.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,94 +7,208 @@ var Mailgun = require('mailgun.js');
7
7
  var FormData = require('form-data');
8
8
  var config = require('@nestjs/config');
9
9
 
10
- const DEFAULT_RECIPIENT_VARIABLE_PREFIX = 'recipient-';
11
- const MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = `h:Reply-To`;
10
+ function _array_like_to_array$1(arr, len) {
11
+ if (len == null || len > arr.length) len = arr.length;
12
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
13
+ return arr2;
14
+ }
15
+ function _array_with_holes(arr) {
16
+ if (Array.isArray(arr)) return arr;
17
+ }
18
+ function _define_property$4(obj, key, value) {
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+ return obj;
30
+ }
31
+ function _instanceof(left, right) {
32
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
33
+ return !!right[Symbol.hasInstance](left);
34
+ } else {
35
+ return left instanceof right;
36
+ }
37
+ }
38
+ function _iterable_to_array_limit(arr, i) {
39
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
+ if (_i == null) return;
41
+ var _arr = [];
42
+ var _n = true;
43
+ var _d = false;
44
+ var _s, _e;
45
+ try {
46
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
+ _arr.push(_s.value);
48
+ if (i && _arr.length === i) break;
49
+ }
50
+ } catch (err) {
51
+ _d = true;
52
+ _e = err;
53
+ } finally{
54
+ try {
55
+ if (!_n && _i["return"] != null) _i["return"]();
56
+ } finally{
57
+ if (_d) throw _e;
58
+ }
59
+ }
60
+ return _arr;
61
+ }
62
+ function _non_iterable_rest() {
63
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
+ }
65
+ function _object_spread$2(target) {
66
+ for(var i = 1; i < arguments.length; i++){
67
+ var source = arguments[i] != null ? arguments[i] : {};
68
+ var ownKeys = Object.keys(source);
69
+ if (typeof Object.getOwnPropertySymbols === "function") {
70
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
71
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
72
+ }));
73
+ }
74
+ ownKeys.forEach(function(key) {
75
+ _define_property$4(target, key, source[key]);
76
+ });
77
+ }
78
+ return target;
79
+ }
80
+ function ownKeys$1(object, enumerableOnly) {
81
+ var keys = Object.keys(object);
82
+ if (Object.getOwnPropertySymbols) {
83
+ var symbols = Object.getOwnPropertySymbols(object);
84
+ keys.push.apply(keys, symbols);
85
+ }
86
+ return keys;
87
+ }
88
+ function _object_spread_props$1(target, source) {
89
+ source = source != null ? source : {};
90
+ if (Object.getOwnPropertyDescriptors) {
91
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
92
+ } else {
93
+ ownKeys$1(Object(source)).forEach(function(key) {
94
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
95
+ });
96
+ }
97
+ return target;
98
+ }
99
+ function _sliced_to_array(arr, i) {
100
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest();
101
+ }
102
+ function _type_of$1(obj) {
103
+ "@swc/helpers - typeof";
104
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
105
+ }
106
+ function _unsupported_iterable_to_array$1(o, minLen) {
107
+ if (!o) return;
108
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
109
+ var n = Object.prototype.toString.call(o).slice(8, -1);
110
+ if (n === "Object" && o.constructor) n = o.constructor.name;
111
+ if (n === "Map" || n === "Set") return Array.from(n);
112
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
113
+ }
114
+ var DEFAULT_RECIPIENT_VARIABLE_PREFIX = 'recipient-';
115
+ var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
12
116
  /**
13
117
  * The maximum number of recipients allowed in a single batch send request.
14
- */
15
- const MAX_BATCH_SEND_RECIPIENTS = 1000;
118
+ */ var MAX_BATCH_SEND_RECIPIENTS = 1000;
16
119
  /**
17
120
  * Converts a MailgunTemplateEmailRequest to a MailgunMessageData.
18
121
  *
19
122
  * @param config
20
123
  * @returns
21
- */
22
- function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
23
- const { request, defaultSender, isTestingEnvironment: testEnvironment, recipientVariablePrefix: inputRecipientVariablePrefix = DEFAULT_RECIPIENT_VARIABLE_PREFIX, addRecipientVariablePrefixToAllMergedGlobalVariables: inputAddRecipientVariablePrefixToAllMergedGlobalVariables = true, addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables: inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = false, addCopyOfTemplateVariablesWithRecipientVariablePrefix: inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix = false } = config;
24
- const { recipientVariablesConfig } = request;
25
- const recipientVariablePrefix = recipientVariablesConfig?.recipientVariablePrefix ?? inputRecipientVariablePrefix;
26
- const addRecipientVariablePrefixToAllMergedGlobalVariables = recipientVariablesConfig?.addRecipientVariablePrefixToAllMergedGlobalVariables ?? inputAddRecipientVariablePrefixToAllMergedGlobalVariables;
27
- const addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = recipientVariablesConfig?.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables ?? inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables;
28
- const addCopyOfTemplateVariablesWithRecipientVariablePrefix = recipientVariablesConfig?.addCopyOfTemplateVariablesWithRecipientVariablePrefix ?? inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix;
29
- const finalizeRecipientVariables = request.finalizeRecipientVariables ?? util.MAP_IDENTITY;
30
- const allowBatchSending = request.batchSend ?? true;
31
- const mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
124
+ */ function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
125
+ var _ref, _ref1, _ref2, _ref3, _request_finalizeRecipientVariables, _request_batchSend;
126
+ var request = config.request, defaultSender = config.defaultSender, testEnvironment = config.isTestingEnvironment, tmp = config.recipientVariablePrefix, inputRecipientVariablePrefix = tmp === void 0 ? DEFAULT_RECIPIENT_VARIABLE_PREFIX : tmp, tmp1 = config.addRecipientVariablePrefixToAllMergedGlobalVariables, inputAddRecipientVariablePrefixToAllMergedGlobalVariables = tmp1 === void 0 ? true : tmp1, tmp2 = config.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables, inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = tmp2 === void 0 ? false : tmp2, tmp3 = config.addCopyOfTemplateVariablesWithRecipientVariablePrefix, inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix = tmp3 === void 0 ? false : tmp3;
127
+ var recipientVariablesConfig = request.recipientVariablesConfig;
128
+ var recipientVariablePrefix = (_ref = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.recipientVariablePrefix) !== null && _ref !== void 0 ? _ref : inputRecipientVariablePrefix;
129
+ var addRecipientVariablePrefixToAllMergedGlobalVariables = (_ref1 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addRecipientVariablePrefixToAllMergedGlobalVariables) !== null && _ref1 !== void 0 ? _ref1 : inputAddRecipientVariablePrefixToAllMergedGlobalVariables;
130
+ var addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = (_ref2 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) !== null && _ref2 !== void 0 ? _ref2 : inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables;
131
+ var addCopyOfTemplateVariablesWithRecipientVariablePrefix = (_ref3 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addCopyOfTemplateVariablesWithRecipientVariablePrefix) !== null && _ref3 !== void 0 ? _ref3 : inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix;
132
+ var finalizeRecipientVariables = (_request_finalizeRecipientVariables = request.finalizeRecipientVariables) !== null && _request_finalizeRecipientVariables !== void 0 ? _request_finalizeRecipientVariables : util.MAP_IDENTITY;
133
+ var allowBatchSending = (_request_batchSend = request.batchSend) !== null && _request_batchSend !== void 0 ? _request_batchSend : true;
134
+ var mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
32
135
  function mapEmailToLowercase(x) {
33
- return { ...x, email: x.email.toLowerCase() };
34
- }
35
- const toInput = util.asArray(request.to).map(mapEmailToLowercase);
36
- const ccInput = request.cc ? util.asArray(request.cc).map(mapEmailToLowercase) : undefined;
37
- const bccInput = request.bcc ? util.asArray(request.bcc).map(mapEmailToLowercase) : undefined;
38
- const from = request.from ? convertMailgunRecipientToString(request.from) : defaultSender;
39
- const to = convertMailgunRecipientsToStrings(toInput);
40
- const cc = ccInput?.length ? convertMailgunRecipientsToStrings(ccInput) : undefined;
41
- const bcc = bccInput?.length ? convertMailgunRecipientsToStrings(bccInput) : undefined;
136
+ return _object_spread_props$1(_object_spread$2({}, x), {
137
+ email: x.email.toLowerCase()
138
+ });
139
+ }
140
+ var toInput = util.asArray(request.to).map(mapEmailToLowercase);
141
+ var ccInput = request.cc ? util.asArray(request.cc).map(mapEmailToLowercase) : undefined;
142
+ var bccInput = request.bcc ? util.asArray(request.bcc).map(mapEmailToLowercase) : undefined;
143
+ var from = request.from ? convertMailgunRecipientToString(request.from) : defaultSender;
144
+ var to = convertMailgunRecipientsToStrings(toInput);
145
+ var cc = (ccInput === null || ccInput === void 0 ? void 0 : ccInput.length) ? convertMailgunRecipientsToStrings(ccInput) : undefined;
146
+ var bcc = (bccInput === null || bccInput === void 0 ? void 0 : bccInput.length) ? convertMailgunRecipientsToStrings(bccInput) : undefined;
42
147
  // throw an error if batchSend is not defined and cc or bcc is defined
43
148
  if (request.batchSend == null && (ccInput || bccInput)) {
44
149
  throw new Error('convertMailgunTemplateEmailRequestToMailgunMessageData(): batchSend must be false when either "cc" or "bcc" is defined.');
45
150
  }
46
151
  if (allowBatchSending && to.length > MAX_BATCH_SEND_RECIPIENTS) {
47
- throw new Error(`convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ${MAX_BATCH_SEND_RECIPIENTS} recipients.`);
152
+ throw new Error("convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ".concat(MAX_BATCH_SEND_RECIPIENTS, " recipients."));
48
153
  }
49
- const data = {
50
- from,
51
- to,
52
- cc,
53
- bcc,
154
+ var data = _object_spread$2({
155
+ from: from,
156
+ to: to,
157
+ cc: cc,
158
+ bcc: bcc,
54
159
  subject: request.subject,
55
- template: request.template,
56
- ...request.messageData
57
- };
160
+ template: request.template
161
+ }, request.messageData);
58
162
  if (request.replyTo != null) {
59
163
  data[MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY] = convertMailgunRecipientToString(request.replyTo);
60
164
  }
61
- if (request.testEmail === true || ((testEnvironment ?? nestjs.isTestNodeEnv()) && request.testEmail !== false)) {
165
+ if (request.testEmail === true || (testEnvironment !== null && testEnvironment !== void 0 ? testEnvironment : nestjs.isTestNodeEnv()) && request.testEmail !== false) {
62
166
  data['o:testmode'] = true;
63
167
  }
64
168
  if (request.templateVariables) {
65
169
  util.forEachKeyValue(request.templateVariables, {
66
- forEach: (x) => {
67
- const [key, value] = x;
68
- const encodedValue = encodeMailgunTemplateVariableValue(value);
170
+ forEach: function forEach(x) {
171
+ var _x = _sliced_to_array(x, 2), key = _x[0], value = _x[1];
172
+ var encodedValue = encodeMailgunTemplateVariableValue(value);
69
173
  if (encodedValue != null) {
70
- data[`v:${key}`] = encodedValue;
174
+ data["v:".concat(key)] = encodedValue;
71
175
  if (recipientVariablePrefix && addCopyOfTemplateVariablesWithRecipientVariablePrefix) {
72
- data[`v:${recipientVariablePrefix}${key}`] = encodedValue;
176
+ data["v:".concat(recipientVariablePrefix).concat(key)] = encodedValue;
73
177
  }
74
178
  }
75
179
  }
76
180
  });
77
181
  }
78
- const hasUserVariables = Boolean(data['recipient-variables']) || toInput.findIndex((x) => x.userVariables != null) !== -1;
182
+ var hasUserVariables = Boolean(data['recipient-variables']) || toInput.findIndex(function(x) {
183
+ return x.userVariables != null;
184
+ }) !== -1;
79
185
  if (hasUserVariables) {
80
- let recipientVariables = {};
81
- const allRecipientVariableKeys = new Set();
82
- toInput.forEach(({ email, userVariables }) => {
186
+ var _finalizeRecipientVariables;
187
+ var recipientVariables = {};
188
+ var allRecipientVariableKeys = new Set();
189
+ toInput.forEach(function(param) {
190
+ var email = param.email, userVariables = param.userVariables;
83
191
  if (userVariables != null && !util.objectIsEmpty(userVariables)) {
84
192
  recipientVariables[email] = userVariables;
85
193
  util.addToSet(allRecipientVariableKeys, Object.keys(userVariables));
86
194
  }
87
195
  });
88
196
  if (data['recipient-variables']) {
89
- const decoded = JSON.parse(data['recipient-variables']);
197
+ var decoded = JSON.parse(data['recipient-variables']);
90
198
  util.forEachKeyValue(decoded, {
91
- forEach: (x) => {
92
- const [recipientEmail, userVariables] = x;
93
- const email = recipientEmail.toLowerCase();
199
+ forEach: function forEach(x) {
200
+ var _x = _sliced_to_array(x, 2), recipientEmail = _x[0], userVariables = _x[1];
201
+ var email = recipientEmail.toLowerCase();
94
202
  if (recipientVariables[email] != null) {
95
- util.overrideInObject(recipientVariables[email], { from: [userVariables], filter: { valueFilter: util.KeyValueTypleValueFilter.UNDEFINED } });
96
- }
97
- else {
203
+ util.overrideInObject(recipientVariables[email], {
204
+ from: [
205
+ userVariables
206
+ ],
207
+ filter: {
208
+ valueFilter: util.KeyValueTypleValueFilter.UNDEFINED
209
+ }
210
+ });
211
+ } else {
98
212
  recipientVariables[email] = userVariables;
99
213
  }
100
214
  util.addToSet(allRecipientVariableKeys, Object.keys(userVariables));
@@ -102,47 +216,45 @@ function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
102
216
  });
103
217
  }
104
218
  // Finalize the recipient variables before they are re-encoded back to JSON
105
- recipientVariables =
106
- finalizeRecipientVariables(recipientVariables, {
107
- messageData: data,
108
- config
109
- }) ?? recipientVariables;
219
+ recipientVariables = (_finalizeRecipientVariables = finalizeRecipientVariables(recipientVariables, {
220
+ messageData: data,
221
+ config: config
222
+ })) !== null && _finalizeRecipientVariables !== void 0 ? _finalizeRecipientVariables : recipientVariables;
110
223
  if (mergeRecipientVariablesIntoGlobalVariable) {
111
- const addRecipientPrefixVariable = recipientVariablePrefix && addRecipientVariablePrefixToAllMergedGlobalVariables;
224
+ var addRecipientPrefixVariable = recipientVariablePrefix && addRecipientVariablePrefixToAllMergedGlobalVariables;
112
225
  // iterate all recipient variables and merge them into the global variables
113
226
  util.forEachKeyValue(recipientVariables, {
114
- forEach: (x) => {
115
- const [email, userVariables] = x;
227
+ forEach: function forEach(x) {
228
+ var _x = _sliced_to_array(x, 2); _x[0]; var userVariables = _x[1];
116
229
  util.forEachKeyValue(userVariables, {
117
- forEach: (y) => {
118
- const [key, value] = y;
119
- const encodedValue = encodeMailgunTemplateVariableValue(value);
230
+ forEach: function forEach(y) {
231
+ var _y = _sliced_to_array(y, 2), key = _y[0], value = _y[1];
232
+ var encodedValue = encodeMailgunTemplateVariableValue(value);
120
233
  if (encodedValue != null) {
121
234
  if (addRecipientPrefixVariable) {
122
235
  // also add the variable using the recipient variable prefix
123
- const recipientVariableKey = `${recipientVariablePrefix}${key}`;
124
- data[`v:${recipientVariableKey}`] = encodedValue;
236
+ var recipientVariableKey = "".concat(recipientVariablePrefix).concat(key);
237
+ data["v:".concat(recipientVariableKey)] = encodedValue;
125
238
  }
126
239
  // add if not adding the prefix variable, or if it was requested
127
240
  if (!addRecipientPrefixVariable || addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) {
128
- data[`v:${key}`] = encodedValue;
241
+ data["v:".concat(key)] = encodedValue;
129
242
  }
130
243
  }
131
244
  }
132
245
  });
133
246
  }
134
247
  });
135
- }
136
- else {
248
+ } else {
137
249
  // set back on the data object
138
250
  data['recipient-variables'] = JSON.stringify(recipientVariables);
139
251
  // add all recipient variable to the other variables so they can be used easily/directly in templates as variables too.
140
252
  // https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages
141
253
  if (recipientVariablePrefix) {
142
- util.forEachInIterable(allRecipientVariableKeys, (key) => {
143
- const recipientVariableKey = `${recipientVariablePrefix}${key}`;
254
+ util.forEachInIterable(allRecipientVariableKeys, function(key) {
255
+ var recipientVariableKey = "".concat(recipientVariablePrefix).concat(key);
144
256
  // v:recipient-id=%recipient.id%
145
- data[`v:${recipientVariableKey}`] = `%recipient.${key}%`;
257
+ data["v:".concat(recipientVariableKey)] = "%recipient.".concat(key, "%");
146
258
  });
147
259
  }
148
260
  }
@@ -151,22 +263,24 @@ function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
151
263
  if (mergeRecipientVariablesIntoGlobalVariable) {
152
264
  delete data['recipient-variables'];
153
265
  }
154
- const inputAttachments = request.attachments;
266
+ var inputAttachments = request.attachments;
155
267
  if (inputAttachments) {
156
268
  if (data.attachment) {
157
- throw new Error(`Cannot specify attachments in both messageData and in the request's attachments field.`);
269
+ throw new Error("Cannot specify attachments in both messageData and in the request's attachments field.");
158
270
  }
159
271
  data.attachment = inputAttachments;
160
272
  }
161
273
  return data;
162
274
  }
163
275
  function convertMailgunRecipientsToStrings(recipients) {
164
- return recipients.map((x) => convertMailgunRecipientToString(x));
276
+ return recipients.map(function(x) {
277
+ return convertMailgunRecipientToString(x);
278
+ });
165
279
  }
166
280
  function convertMailgunRecipientToString(recipient) {
167
- let address = recipient.email;
281
+ var address = recipient.email;
168
282
  if (recipient.name) {
169
- address = `${recipient.name} <${address}>`;
283
+ address = "".concat(recipient.name, " <").concat(address, ">");
170
284
  }
171
285
  return address;
172
286
  }
@@ -175,16 +289,14 @@ function convertMailgunRecipientToString(recipient) {
175
289
  *
176
290
  * @param value The value to encode.
177
291
  * @returns The encoded value, or undefined if the value is null or undefined.
178
- */
179
- function encodeMailgunTemplateVariableValue(value) {
180
- let encodedValue;
181
- switch (typeof value) {
292
+ */ function encodeMailgunTemplateVariableValue(value) {
293
+ var encodedValue;
294
+ switch(typeof value === "undefined" ? "undefined" : _type_of$1(value)){
182
295
  case 'object':
183
296
  if (value) {
184
- if (value instanceof Date) {
297
+ if (_instanceof(value, Date)) {
185
298
  encodedValue = value.toISOString();
186
- }
187
- else {
299
+ } else {
188
300
  encodedValue = JSON.stringify(value);
189
301
  }
190
302
  }
@@ -197,252 +309,624 @@ function encodeMailgunTemplateVariableValue(value) {
197
309
  break;
198
310
  default:
199
311
  if (value) {
200
- throw new Error(`Invalid value "${value}" passed to encodeMailgunTemplateVariableValue().`);
312
+ throw new Error('Invalid value "'.concat(value, '" passed to encodeMailgunTemplateVariableValue().'));
201
313
  }
202
314
  }
203
315
  return encodedValue;
204
316
  }
205
317
 
206
- /******************************************************************************
207
- Copyright (c) Microsoft Corporation.
208
-
209
- Permission to use, copy, modify, and/or distribute this software for any
210
- purpose with or without fee is hereby granted.
211
-
212
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
213
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
214
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
215
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
216
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
217
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
218
- PERFORMANCE OF THIS SOFTWARE.
219
- ***************************************************************************** */
220
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
221
-
222
-
223
- function __decorate(decorators, target, key, desc) {
224
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
225
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
226
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
227
- return c > 3 && r && Object.defineProperty(target, key, r), r;
228
- }
229
-
230
- function __param(paramIndex, decorator) {
231
- return function (target, key) { decorator(target, key, paramIndex); }
232
- }
233
-
234
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
235
- var e = new Error(message);
236
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
318
+ function _type_of(obj) {
319
+ "@swc/helpers - typeof";
320
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
321
+ }
322
+ function __decorate(decorators, target, key, desc) {
323
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
324
+ if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
325
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
326
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
327
+ }
328
+ function __param(paramIndex, decorator) {
329
+ return function(target, key) {
330
+ decorator(target, key, paramIndex);
331
+ };
332
+ }
333
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
334
+ var e = new Error(message);
335
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
237
336
  };
238
337
 
239
- class MailgunServiceConfig {
240
- // Mailgun Config
241
- mailgun;
242
- /**
338
+ function _class_call_check$3(instance, Constructor) {
339
+ if (!(instance instanceof Constructor)) {
340
+ throw new TypeError("Cannot call a class as a function");
341
+ }
342
+ }
343
+ function _defineProperties$2(target, props) {
344
+ for(var i = 0; i < props.length; i++){
345
+ var descriptor = props[i];
346
+ descriptor.enumerable = descriptor.enumerable || false;
347
+ descriptor.configurable = true;
348
+ if ("value" in descriptor) descriptor.writable = true;
349
+ Object.defineProperty(target, descriptor.key, descriptor);
350
+ }
351
+ }
352
+ function _create_class$2(Constructor, protoProps, staticProps) {
353
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
354
+ return Constructor;
355
+ }
356
+ function _define_property$3(obj, key, value) {
357
+ if (key in obj) {
358
+ Object.defineProperty(obj, key, {
359
+ value: value,
360
+ enumerable: true,
361
+ configurable: true,
362
+ writable: true
363
+ });
364
+ } else {
365
+ obj[key] = value;
366
+ }
367
+ return obj;
368
+ }
369
+ var MailgunServiceConfig = /*#__PURE__*/ function() {
370
+ function MailgunServiceConfig() {
371
+ _class_call_check$3(this, MailgunServiceConfig);
372
+ // Mailgun Config
373
+ _define_property$3(this, "mailgun", void 0);
374
+ /**
243
375
  * Base URL to the client.
244
- */
245
- clientUrl;
246
- /**
376
+ */ _define_property$3(this, "clientUrl", void 0);
377
+ /**
247
378
  * Main domain to send emails from.
248
- */
249
- domain;
250
- /**
379
+ */ _define_property$3(this, "domain", void 0);
380
+ /**
251
381
  * Mailgun sender string.
252
- */
253
- sender;
254
- /**
382
+ */ _define_property$3(this, "sender", void 0);
383
+ /**
255
384
  * Additional messages config
256
- */
257
- messages;
258
- static assertValidConfig(config) {
259
- if (!config.mailgun.username) {
260
- throw new Error('No mailgun username specified.');
261
- }
262
- else if (!config.mailgun.key) {
263
- throw new Error('No mailgun key specified.');
264
- }
265
- else if (!config.domain) {
266
- throw new Error('No mailgun domain specified.');
267
- }
268
- else if (!config.clientUrl) {
269
- throw new Error('No client url specified.');
270
- }
271
- else if (!config.sender) {
272
- throw new Error('No mailgun sender specified.');
273
- }
274
- else if (!config.messages) {
275
- throw new Error('No mailgun messages config specified.');
276
- }
385
+ */ _define_property$3(this, "messages", void 0);
277
386
  }
278
- }
387
+ _create_class$2(MailgunServiceConfig, null, [
388
+ {
389
+ key: "assertValidConfig",
390
+ value: function assertValidConfig(config) {
391
+ if (!config.mailgun.username) {
392
+ throw new Error('No mailgun username specified.');
393
+ } else if (!config.mailgun.key) {
394
+ throw new Error('No mailgun key specified.');
395
+ } else if (!config.domain) {
396
+ throw new Error('No mailgun domain specified.');
397
+ } else if (!config.clientUrl) {
398
+ throw new Error('No client url specified.');
399
+ } else if (!config.sender) {
400
+ throw new Error('No mailgun sender specified.');
401
+ } else if (!config.messages) {
402
+ throw new Error('No mailgun messages config specified.');
403
+ }
404
+ }
405
+ }
406
+ ]);
407
+ return MailgunServiceConfig;
408
+ }
409
+ ();
279
410
 
280
- exports.MailgunApi = class MailgunApi {
281
- config;
282
- client;
283
- constructor(config) {
284
- this.config = config;
285
- this.client = new Mailgun(FormData).client({
286
- ...config.mailgun
287
- });
411
+ function _class_call_check$2(instance, Constructor) {
412
+ if (!(instance instanceof Constructor)) {
413
+ throw new TypeError("Cannot call a class as a function");
288
414
  }
289
- get messages() {
290
- return this.client.messages;
415
+ }
416
+ function _defineProperties$1(target, props) {
417
+ for(var i = 0; i < props.length; i++){
418
+ var descriptor = props[i];
419
+ descriptor.enumerable = descriptor.enumerable || false;
420
+ descriptor.configurable = true;
421
+ if ("value" in descriptor) descriptor.writable = true;
422
+ Object.defineProperty(target, descriptor.key, descriptor);
291
423
  }
292
- get clientUrl() {
293
- return this.config.clientUrl;
424
+ }
425
+ function _create_class$1(Constructor, protoProps, staticProps) {
426
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
427
+ return Constructor;
428
+ }
429
+ function _define_property$2(obj, key, value) {
430
+ if (key in obj) {
431
+ Object.defineProperty(obj, key, {
432
+ value: value,
433
+ enumerable: true,
434
+ configurable: true,
435
+ writable: true
436
+ });
437
+ } else {
438
+ obj[key] = value;
294
439
  }
295
- get domain() {
296
- return this.config.domain;
440
+ return obj;
441
+ }
442
+ function _object_spread$1(target) {
443
+ for(var i = 1; i < arguments.length; i++){
444
+ var source = arguments[i] != null ? arguments[i] : {};
445
+ var ownKeys = Object.keys(source);
446
+ if (typeof Object.getOwnPropertySymbols === "function") {
447
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
448
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
449
+ }));
450
+ }
451
+ ownKeys.forEach(function(key) {
452
+ _define_property$2(target, key, source[key]);
453
+ });
297
454
  }
298
- get sender() {
299
- return this.config.sender;
455
+ return target;
456
+ }
457
+ exports.MailgunApi = /*#__PURE__*/ function() {
458
+ function MailgunApi(config) {
459
+ _class_call_check$2(this, MailgunApi);
460
+ _define_property$2(this, "config", void 0);
461
+ _define_property$2(this, "client", void 0);
462
+ this.config = config;
463
+ this.client = new Mailgun(FormData).client(_object_spread$1({}, config.mailgun));
300
464
  }
301
- };
465
+ _create_class$1(MailgunApi, [
466
+ {
467
+ key: "messages",
468
+ get: function get() {
469
+ return this.client.messages;
470
+ }
471
+ },
472
+ {
473
+ key: "clientUrl",
474
+ get: function get() {
475
+ return this.config.clientUrl;
476
+ }
477
+ },
478
+ {
479
+ key: "domain",
480
+ get: function get() {
481
+ return this.config.domain;
482
+ }
483
+ },
484
+ {
485
+ key: "sender",
486
+ get: function get() {
487
+ return this.config.sender;
488
+ }
489
+ }
490
+ ]);
491
+ return MailgunApi;
492
+ }();
302
493
  exports.MailgunApi = __decorate([
303
494
  common.Injectable(),
304
495
  __param(0, common.Inject(MailgunServiceConfig))
305
496
  ], exports.MailgunApi);
306
497
 
307
- exports.MailgunService = class MailgunService {
308
- _mailgunApi;
309
- _serverEnvironmentService;
310
- constructor(mailgunApi, serverEnvironmentService) {
311
- this._mailgunApi = mailgunApi;
312
- this._serverEnvironmentService = serverEnvironmentService;
498
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
499
+ try {
500
+ var info = gen[key](arg);
501
+ var value = info.value;
502
+ } catch (error) {
503
+ reject(error);
504
+ return;
313
505
  }
314
- get mailgunApi() {
315
- return this._mailgunApi;
316
- }
317
- get serverEnvironmentService() {
318
- return this._serverEnvironmentService;
319
- }
320
- async sendTemplateEmail(request) {
321
- const domain = this.mailgunApi.domain;
322
- const sender = this.mailgunApi.sender;
323
- const isTestingEnvironment = this.serverEnvironmentService.isTestingEnv;
324
- const { recipientVariablePrefix } = this.mailgunApi.config.messages;
325
- const data = convertMailgunTemplateEmailRequestToMailgunMessageData({ request, defaultSender: sender, recipientVariablePrefix, isTestingEnvironment });
326
- let result;
327
- const shouldSend = !isTestingEnvironment || request.sendTestEmails || this.mailgunApi.config.messages.sendTestEmails;
328
- if (shouldSend) {
329
- try {
330
- result = await this.mailgunApi.messages.create(domain, data);
506
+ if (info.done) {
507
+ resolve(value);
508
+ } else {
509
+ Promise.resolve(value).then(_next, _throw);
510
+ }
511
+ }
512
+ function _async_to_generator(fn) {
513
+ return function() {
514
+ var self = this, args = arguments;
515
+ return new Promise(function(resolve, reject) {
516
+ var gen = fn.apply(self, args);
517
+ function _next(value) {
518
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
331
519
  }
332
- catch (e) {
333
- console.error('Failed sending email: ', e);
334
- throw e;
520
+ function _throw(err) {
521
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
335
522
  }
523
+ _next(undefined);
524
+ });
525
+ };
526
+ }
527
+ function _class_call_check$1(instance, Constructor) {
528
+ if (!(instance instanceof Constructor)) {
529
+ throw new TypeError("Cannot call a class as a function");
530
+ }
531
+ }
532
+ function _defineProperties(target, props) {
533
+ for(var i = 0; i < props.length; i++){
534
+ var descriptor = props[i];
535
+ descriptor.enumerable = descriptor.enumerable || false;
536
+ descriptor.configurable = true;
537
+ if ("value" in descriptor) descriptor.writable = true;
538
+ Object.defineProperty(target, descriptor.key, descriptor);
539
+ }
540
+ }
541
+ function _create_class(Constructor, protoProps, staticProps) {
542
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
543
+ return Constructor;
544
+ }
545
+ function _define_property$1(obj, key, value) {
546
+ if (key in obj) {
547
+ Object.defineProperty(obj, key, {
548
+ value: value,
549
+ enumerable: true,
550
+ configurable: true,
551
+ writable: true
552
+ });
553
+ } else {
554
+ obj[key] = value;
555
+ }
556
+ return obj;
557
+ }
558
+ function _ts_generator(thisArg, body) {
559
+ var f, y, t, _ = {
560
+ label: 0,
561
+ sent: function() {
562
+ if (t[0] & 1) throw t[1];
563
+ return t[1];
564
+ },
565
+ trys: [],
566
+ ops: []
567
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
568
+ return d(g, "next", {
569
+ value: verb(0)
570
+ }), d(g, "throw", {
571
+ value: verb(1)
572
+ }), d(g, "return", {
573
+ value: verb(2)
574
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
575
+ value: function() {
576
+ return this;
336
577
  }
337
- else {
338
- result = {
339
- status: 200,
340
- message: 'Success. Env prevented sending email.'
341
- };
578
+ }), g;
579
+ function verb(n) {
580
+ return function(v) {
581
+ return step([
582
+ n,
583
+ v
584
+ ]);
585
+ };
586
+ }
587
+ function step(op) {
588
+ if (f) throw new TypeError("Generator is already executing.");
589
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
590
+ 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;
591
+ if (y = 0, t) op = [
592
+ op[0] & 2,
593
+ t.value
594
+ ];
595
+ switch(op[0]){
596
+ case 0:
597
+ case 1:
598
+ t = op;
599
+ break;
600
+ case 4:
601
+ _.label++;
602
+ return {
603
+ value: op[1],
604
+ done: false
605
+ };
606
+ case 5:
607
+ _.label++;
608
+ y = op[1];
609
+ op = [
610
+ 0
611
+ ];
612
+ continue;
613
+ case 7:
614
+ op = _.ops.pop();
615
+ _.trys.pop();
616
+ continue;
617
+ default:
618
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
619
+ _ = 0;
620
+ continue;
621
+ }
622
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
623
+ _.label = op[1];
624
+ break;
625
+ }
626
+ if (op[0] === 6 && _.label < t[1]) {
627
+ _.label = t[1];
628
+ t = op;
629
+ break;
630
+ }
631
+ if (t && _.label < t[2]) {
632
+ _.label = t[2];
633
+ _.ops.push(op);
634
+ break;
635
+ }
636
+ if (t[2]) _.ops.pop();
637
+ _.trys.pop();
638
+ continue;
639
+ }
640
+ op = body.call(thisArg, _);
641
+ } catch (e) {
642
+ op = [
643
+ 6,
644
+ e
645
+ ];
646
+ y = 0;
647
+ } finally{
648
+ f = t = 0;
342
649
  }
343
- return result;
650
+ if (op[0] & 5) throw op[1];
651
+ return {
652
+ value: op[0] ? op[1] : void 0,
653
+ done: true
654
+ };
344
655
  }
345
- };
656
+ }
657
+ exports.MailgunService = /*#__PURE__*/ function() {
658
+ function MailgunService(mailgunApi, serverEnvironmentService) {
659
+ _class_call_check$1(this, MailgunService);
660
+ _define_property$1(this, "_mailgunApi", void 0);
661
+ _define_property$1(this, "_serverEnvironmentService", void 0);
662
+ this._mailgunApi = mailgunApi;
663
+ this._serverEnvironmentService = serverEnvironmentService;
664
+ }
665
+ _create_class(MailgunService, [
666
+ {
667
+ key: "mailgunApi",
668
+ get: function get() {
669
+ return this._mailgunApi;
670
+ }
671
+ },
672
+ {
673
+ key: "serverEnvironmentService",
674
+ get: function get() {
675
+ return this._serverEnvironmentService;
676
+ }
677
+ },
678
+ {
679
+ key: "sendTemplateEmail",
680
+ value: function sendTemplateEmail(request) {
681
+ return _async_to_generator(function() {
682
+ var domain, sender, isTestingEnvironment, recipientVariablePrefix, data, result, shouldSend, e;
683
+ return _ts_generator(this, function(_state) {
684
+ switch(_state.label){
685
+ case 0:
686
+ domain = this.mailgunApi.domain;
687
+ sender = this.mailgunApi.sender;
688
+ isTestingEnvironment = this.serverEnvironmentService.isTestingEnv;
689
+ recipientVariablePrefix = this.mailgunApi.config.messages.recipientVariablePrefix;
690
+ data = convertMailgunTemplateEmailRequestToMailgunMessageData({
691
+ request: request,
692
+ defaultSender: sender,
693
+ recipientVariablePrefix: recipientVariablePrefix,
694
+ isTestingEnvironment: isTestingEnvironment
695
+ });
696
+ shouldSend = !isTestingEnvironment || request.sendTestEmails || this.mailgunApi.config.messages.sendTestEmails;
697
+ if (!shouldSend) return [
698
+ 3,
699
+ 5
700
+ ];
701
+ _state.label = 1;
702
+ case 1:
703
+ _state.trys.push([
704
+ 1,
705
+ 3,
706
+ ,
707
+ 4
708
+ ]);
709
+ return [
710
+ 4,
711
+ this.mailgunApi.messages.create(domain, data)
712
+ ];
713
+ case 2:
714
+ result = _state.sent();
715
+ return [
716
+ 3,
717
+ 4
718
+ ];
719
+ case 3:
720
+ e = _state.sent();
721
+ console.error('Failed sending email: ', e);
722
+ throw e;
723
+ case 4:
724
+ return [
725
+ 3,
726
+ 6
727
+ ];
728
+ case 5:
729
+ result = {
730
+ status: 200,
731
+ message: 'Success. Env prevented sending email.'
732
+ };
733
+ _state.label = 6;
734
+ case 6:
735
+ return [
736
+ 2,
737
+ result
738
+ ];
739
+ }
740
+ });
741
+ }).call(this);
742
+ }
743
+ }
744
+ ]);
745
+ return MailgunService;
746
+ }();
346
747
  exports.MailgunService = __decorate([
347
748
  common.Injectable(),
348
749
  __param(0, common.Inject(exports.MailgunApi)),
349
750
  __param(1, common.Inject(nestjs.ServerEnvironmentService))
350
751
  ], exports.MailgunService);
351
752
 
753
+ function _class_call_check(instance, Constructor) {
754
+ if (!(instance instanceof Constructor)) {
755
+ throw new TypeError("Cannot call a class as a function");
756
+ }
757
+ }
352
758
  function mailgunServiceConfigFactory(configService, serverEnvironmentService) {
353
- const isTestingEnv = serverEnvironmentService.isTestingEnv;
354
- const useSandbox = configService.get('USE_MAILGUN_SANDBOX') === 'true' || isTestingEnv;
355
- const sendTestEmails = configService.get('MAILGUN_SEND_TEST_EMAILS') === 'true';
356
- let key = configService.get('MAILGUN_API_KEY');
357
- let domain = configService.get('MAILGUN_DOMAIN');
759
+ var _configService_get, _configService_get1, _configService_get2;
760
+ var isTestingEnv = serverEnvironmentService.isTestingEnv;
761
+ var useSandbox = configService.get('USE_MAILGUN_SANDBOX') === 'true' || isTestingEnv;
762
+ var sendTestEmails = configService.get('MAILGUN_SEND_TEST_EMAILS') === 'true';
763
+ var key = configService.get('MAILGUN_API_KEY');
764
+ var domain = configService.get('MAILGUN_DOMAIN');
358
765
  if (useSandbox) {
359
766
  key = configService.get('MAILGUN_SANDBOX_API_KEY');
360
767
  domain = configService.get('MAILGUN_SANDBOX_DOMAIN');
361
768
  if (!key || !domain) {
362
769
  throw new Error('USE_MAILGUN_SANDBOX is set to "true" (or current environment is a testing environment), but no environment variables for the sandbox (MAILGUN_SANDBOX_API_KEY, MAILGUN_SANDBOX_DOMAIN) are provided.');
363
- }
364
- else if (!serverEnvironmentService.isTestingEnv) {
770
+ } else if (!serverEnvironmentService.isTestingEnv) {
365
771
  console.log('Using Mailgun Sandbox Domain: ', domain);
366
772
  }
367
- }
368
- else if (!serverEnvironmentService.isTestingEnv) {
773
+ } else if (!serverEnvironmentService.isTestingEnv) {
369
774
  console.log('Using Mailgun Production Domain: ', domain);
370
775
  }
371
- const name = configService.get('MAILGUN_SENDER_NAME');
372
- const email = configService.get('MAILGUN_SENDER_EMAIL');
373
- const url = configService.get('MAILGUN_API_URL');
374
- const recipientVariablePrefix = configService.get('MAILGUN_MESSAGES_RECIPIENT_VARIABLE_PREFIX') ?? undefined;
776
+ var name = configService.get('MAILGUN_SENDER_NAME');
777
+ var email = configService.get('MAILGUN_SENDER_EMAIL');
778
+ var url = configService.get('MAILGUN_API_URL');
779
+ var recipientVariablePrefix = (_configService_get = configService.get('MAILGUN_MESSAGES_RECIPIENT_VARIABLE_PREFIX')) !== null && _configService_get !== void 0 ? _configService_get : undefined;
375
780
  if (!email) {
376
781
  throw new Error('MAILGUN_SENDER_EMAIL is required but was not configured.');
377
- }
378
- else if (!key) {
782
+ } else if (!key) {
379
783
  throw new Error('MAILGUN_API_KEY (or MAILGUN_SANDBOX_API_KEY for tests) is required but was not configured.');
380
- }
381
- else if (!domain) {
784
+ } else if (!domain) {
382
785
  throw new Error('MAILGUN_DOMAIN (or MAILGUN_SANDBOX_DOMAIN for tests) is required but was not configured.');
383
786
  }
384
- const clientUrl = configService.get('CLIENT_APP_URL') ?? domain;
385
- const config = {
787
+ var clientUrl = (_configService_get1 = configService.get('CLIENT_APP_URL')) !== null && _configService_get1 !== void 0 ? _configService_get1 : domain;
788
+ var config = {
386
789
  mailgun: {
387
- username: configService.get('MAILGUN_USERNAME') ?? 'api',
388
- key,
389
- url
790
+ username: (_configService_get2 = configService.get('MAILGUN_USERNAME')) !== null && _configService_get2 !== void 0 ? _configService_get2 : 'api',
791
+ key: key,
792
+ url: url
390
793
  },
391
- domain,
392
- clientUrl,
794
+ domain: domain,
795
+ clientUrl: clientUrl,
393
796
  sender: convertMailgunRecipientToString({
394
- name,
395
- email
797
+ name: name,
798
+ email: email
396
799
  }),
397
800
  messages: {
398
- sendTestEmails,
399
- recipientVariablePrefix
801
+ sendTestEmails: sendTestEmails,
802
+ recipientVariablePrefix: recipientVariablePrefix
400
803
  }
401
804
  };
402
805
  MailgunServiceConfig.assertValidConfig(config);
403
806
  return config;
404
807
  }
405
- exports.MailgunServiceModule = class MailgunServiceModule {
808
+ exports.MailgunServiceModule = function MailgunServiceModule() {
809
+ _class_call_check(this, MailgunServiceModule);
406
810
  };
407
811
  exports.MailgunServiceModule = __decorate([
408
812
  common.Module({
409
- imports: [config.ConfigModule],
813
+ imports: [
814
+ config.ConfigModule
815
+ ],
410
816
  providers: [
411
817
  {
412
818
  provide: MailgunServiceConfig,
413
- inject: [config.ConfigService, nestjs.ServerEnvironmentService],
819
+ inject: [
820
+ config.ConfigService,
821
+ nestjs.ServerEnvironmentService
822
+ ],
414
823
  useFactory: mailgunServiceConfigFactory
415
824
  },
416
825
  exports.MailgunApi,
417
826
  exports.MailgunService
418
827
  ],
419
- exports: [exports.MailgunApi, exports.MailgunService]
828
+ exports: [
829
+ exports.MailgunApi,
830
+ exports.MailgunService
831
+ ]
420
832
  })
421
833
  ], exports.MailgunServiceModule);
422
834
 
835
+ function _array_like_to_array(arr, len) {
836
+ if (len == null || len > arr.length) len = arr.length;
837
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
838
+ return arr2;
839
+ }
840
+ function _array_without_holes(arr) {
841
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
842
+ }
843
+ function _define_property(obj, key, value) {
844
+ if (key in obj) {
845
+ Object.defineProperty(obj, key, {
846
+ value: value,
847
+ enumerable: true,
848
+ configurable: true,
849
+ writable: true
850
+ });
851
+ } else {
852
+ obj[key] = value;
853
+ }
854
+ return obj;
855
+ }
856
+ function _iterable_to_array(iter) {
857
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
858
+ }
859
+ function _non_iterable_spread() {
860
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
861
+ }
862
+ function _object_spread(target) {
863
+ for(var i = 1; i < arguments.length; i++){
864
+ var source = arguments[i] != null ? arguments[i] : {};
865
+ var ownKeys = Object.keys(source);
866
+ if (typeof Object.getOwnPropertySymbols === "function") {
867
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
868
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
869
+ }));
870
+ }
871
+ ownKeys.forEach(function(key) {
872
+ _define_property(target, key, source[key]);
873
+ });
874
+ }
875
+ return target;
876
+ }
877
+ function ownKeys(object, enumerableOnly) {
878
+ var keys = Object.keys(object);
879
+ if (Object.getOwnPropertySymbols) {
880
+ var symbols = Object.getOwnPropertySymbols(object);
881
+ keys.push.apply(keys, symbols);
882
+ }
883
+ return keys;
884
+ }
885
+ function _object_spread_props(target, source) {
886
+ source = source != null ? source : {};
887
+ if (Object.getOwnPropertyDescriptors) {
888
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
889
+ } else {
890
+ ownKeys(Object(source)).forEach(function(key) {
891
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
892
+ });
893
+ }
894
+ return target;
895
+ }
896
+ function _to_consumable_array(arr) {
897
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
898
+ }
899
+ function _unsupported_iterable_to_array(o, minLen) {
900
+ if (!o) return;
901
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
902
+ var n = Object.prototype.toString.call(o).slice(8, -1);
903
+ if (n === "Object" && o.constructor) n = o.constructor.name;
904
+ if (n === "Map" || n === "Set") return Array.from(n);
905
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
906
+ }
423
907
  /**
424
908
  * The default template subject to use when batch sending emails.
425
909
  *
426
910
  * This pulls the subject from each recipient's user variables.
427
- */
428
- const MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = `%recipient.subject%`;
911
+ */ var MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = "%recipient.subject%";
429
912
  /**
430
913
  * Creates a composite key from the from/replyTo email addresses used to group MailgunRecipientBatchSendTarget values.
431
- */
432
- function mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey(recipient) {
433
- const fromEmail = (recipient.from?.email ?? '').toLowerCase();
434
- const replyToEmail = (recipient.replyTo?.email ?? '').toLowerCase();
435
- return `f:${fromEmail}|r:${replyToEmail}`;
914
+ */ function mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey(recipient) {
915
+ var _ref, _ref1;
916
+ var _recipient_from, _recipient_replyTo;
917
+ var fromEmail = ((_ref = (_recipient_from = recipient.from) === null || _recipient_from === void 0 ? void 0 : _recipient_from.email) !== null && _ref !== void 0 ? _ref : '').toLowerCase();
918
+ var replyToEmail = ((_ref1 = (_recipient_replyTo = recipient.replyTo) === null || _recipient_replyTo === void 0 ? void 0 : _recipient_replyTo.email) !== null && _ref1 !== void 0 ? _ref1 : '').toLowerCase();
919
+ return "f:".concat(fromEmail, "|r:").concat(replyToEmail);
436
920
  }
437
921
  /**
438
922
  * Creates a ExpandMailgunRecipientBatchSendTargetRequestFactory from the input config.
439
923
  *
440
924
  * @param config
441
925
  * @returns
442
- */
443
- function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
444
- const { request: inputBaseRequest, useSubjectFromRecipientUserVariables, allowSingleRecipientBatchSendRequests, recipientVariablesConfig, mailgunRecipientBatchSendTargetEntityKeyRecipientLookup, overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients } = config;
445
- const defaultSubject = inputBaseRequest.subject;
926
+ */ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
927
+ var _inputBaseRequest_from, _inputBaseRequest_replyTo;
928
+ var inputBaseRequest = config.request, useSubjectFromRecipientUserVariables = config.useSubjectFromRecipientUserVariables, allowSingleRecipientBatchSendRequests = config.allowSingleRecipientBatchSendRequests, recipientVariablesConfig = config.recipientVariablesConfig, mailgunRecipientBatchSendTargetEntityKeyRecipientLookup = config.mailgunRecipientBatchSendTargetEntityKeyRecipientLookup, overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients = config.overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients;
929
+ var defaultSubject = inputBaseRequest.subject;
446
930
  if (!defaultSubject && !useSubjectFromRecipientUserVariables) {
447
931
  throw new Error('defaultSubject must be set when "useSubjectFromRecipientUserVariables" is false');
448
932
  }
@@ -453,48 +937,45 @@ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
453
937
  *
454
938
  * @param input
455
939
  * @returns
456
- */
457
- function determineCarbonCopyRecipients(input) {
458
- const { baseRequestCarbonCopyRecipients, carbonCopyRecipients, carbonCopyRecipientsKeys } = input;
459
- let cc = carbonCopyRecipients ? util.asArray(carbonCopyRecipients) : baseRequestCarbonCopyRecipients;
460
- const resolvedCc = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientsForKeys(carbonCopyRecipientsKeys);
461
- if (resolvedCc?.length) {
940
+ */ function determineCarbonCopyRecipients(input) {
941
+ var baseRequestCarbonCopyRecipients = input.baseRequestCarbonCopyRecipients, carbonCopyRecipients = input.carbonCopyRecipients, carbonCopyRecipientsKeys = input.carbonCopyRecipientsKeys;
942
+ var cc = carbonCopyRecipients ? util.asArray(carbonCopyRecipients) : baseRequestCarbonCopyRecipients;
943
+ var resolvedCc = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientsForKeys(carbonCopyRecipientsKeys);
944
+ if (resolvedCc === null || resolvedCc === void 0 ? void 0 : resolvedCc.length) {
462
945
  if (overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients) {
463
946
  cc = resolvedCc;
464
- }
465
- else {
466
- cc = [...(cc ?? []), ...resolvedCc];
947
+ } else {
948
+ cc = _to_consumable_array(cc !== null && cc !== void 0 ? cc : []).concat(_to_consumable_array(resolvedCc));
467
949
  }
468
950
  }
469
- return cc?.length ? cc : undefined;
951
+ return (cc === null || cc === void 0 ? void 0 : cc.length) ? cc : undefined;
470
952
  }
471
- const baseRequestCc = determineCarbonCopyRecipients({
953
+ var baseRequestCc = determineCarbonCopyRecipients({
472
954
  carbonCopyRecipients: inputBaseRequest.cc,
473
955
  carbonCopyRecipientsKeys: inputBaseRequest.ccKeys
474
956
  });
475
- const baseRequestBcc = determineCarbonCopyRecipients({
957
+ var baseRequestBcc = determineCarbonCopyRecipients({
476
958
  carbonCopyRecipients: inputBaseRequest.bcc,
477
959
  carbonCopyRecipientsKeys: inputBaseRequest.bccKeys
478
960
  });
479
- const baseRequestFrom = inputBaseRequest.from ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.fromKey);
480
- const baseRequestReplyTo = inputBaseRequest.replyTo ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.replyToKey);
481
- const baseRequest = {
482
- ...inputBaseRequest,
961
+ var baseRequestFrom = (_inputBaseRequest_from = inputBaseRequest.from) !== null && _inputBaseRequest_from !== void 0 ? _inputBaseRequest_from : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(inputBaseRequest.fromKey);
962
+ var baseRequestReplyTo = (_inputBaseRequest_replyTo = inputBaseRequest.replyTo) !== null && _inputBaseRequest_replyTo !== void 0 ? _inputBaseRequest_replyTo : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(inputBaseRequest.replyToKey);
963
+ var baseRequest = _object_spread_props(_object_spread({}, inputBaseRequest), {
483
964
  from: baseRequestFrom,
484
965
  replyTo: baseRequestReplyTo,
485
966
  cc: baseRequestCc,
486
967
  bcc: baseRequestBcc
487
- };
968
+ });
488
969
  delete baseRequest.fromKey;
489
970
  delete baseRequest.replyToKey;
490
971
  delete baseRequest.ccKeys;
491
972
  delete baseRequest.bccKeys;
492
- const configAllowBatchSend = baseRequest.batchSend !== false;
493
- return (inputRecipients) => {
973
+ var configAllowBatchSend = baseRequest.batchSend !== false;
974
+ return function(inputRecipients) {
494
975
  // Process recipients to resolve keys
495
- const recipients = inputRecipients.map((recipient) => {
496
- let from = recipient.from;
497
- let replyTo = recipient.replyTo;
976
+ var recipients = inputRecipients.map(function(recipient) {
977
+ var from = recipient.from;
978
+ var replyTo = recipient.replyTo;
498
979
  if (mailgunRecipientBatchSendTargetEntityKeyRecipientLookup) {
499
980
  // try the fromKey, otherwise use the baseRequest.from
500
981
  if (!from) {
@@ -504,8 +985,7 @@ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
504
985
  if (!replyTo) {
505
986
  replyTo = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.replyToKey, baseRequest.replyTo);
506
987
  }
507
- }
508
- else {
988
+ } else {
509
989
  // use defaults from base request
510
990
  if (!from) {
511
991
  from = baseRequest.from;
@@ -514,76 +994,76 @@ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
514
994
  replyTo = baseRequest.replyTo;
515
995
  }
516
996
  }
517
- const cc = determineCarbonCopyRecipients({
997
+ var cc = determineCarbonCopyRecipients({
518
998
  baseRequestCarbonCopyRecipients: baseRequestCc,
519
999
  carbonCopyRecipients: recipient.cc,
520
1000
  carbonCopyRecipientsKeys: recipient.ccKeys
521
1001
  });
522
- const bcc = determineCarbonCopyRecipients({
1002
+ var bcc = determineCarbonCopyRecipients({
523
1003
  baseRequestCarbonCopyRecipients: baseRequestBcc,
524
1004
  carbonCopyRecipients: recipient.bcc,
525
1005
  carbonCopyRecipientsKeys: recipient.bccKeys
526
1006
  });
527
- const result = {
528
- ...recipient,
529
- from,
530
- replyTo,
531
- cc,
532
- bcc
533
- };
1007
+ var result = _object_spread_props(_object_spread({}, recipient), {
1008
+ from: from,
1009
+ replyTo: replyTo,
1010
+ cc: cc,
1011
+ bcc: bcc
1012
+ });
534
1013
  return result;
535
1014
  });
536
- const allowBatchSend = configAllowBatchSend && (allowSingleRecipientBatchSendRequests || recipients.length > 1);
537
- const nonBatchSendRequests = [];
538
- const batchSendRequestRecipients = [];
539
- recipients.forEach((recipient) => {
540
- const recipientHasCarbonCopy = Boolean(recipient.cc?.length || recipient.bcc?.length);
1015
+ var allowBatchSend = configAllowBatchSend && (allowSingleRecipientBatchSendRequests || recipients.length > 1);
1016
+ var nonBatchSendRequests = [];
1017
+ var batchSendRequestRecipients = [];
1018
+ recipients.forEach(function(recipient) {
1019
+ var _recipient_cc, _recipient_bcc;
1020
+ var recipientHasCarbonCopy = Boolean(((_recipient_cc = recipient.cc) === null || _recipient_cc === void 0 ? void 0 : _recipient_cc.length) || ((_recipient_bcc = recipient.bcc) === null || _recipient_bcc === void 0 ? void 0 : _recipient_bcc.length));
541
1021
  if (allowBatchSend && !recipientHasCarbonCopy) {
542
1022
  // add to batch send recipients
543
1023
  batchSendRequestRecipients.push(recipient);
544
- }
545
- else {
1024
+ } else {
1025
+ var _ref, _ref1, _recipient_from, _recipient_replyTo, _baseRequest_recipientVariablesConfig;
1026
+ var _recipient_userVariables, _recipient_userVariables1;
546
1027
  // add to non-batch send requests
547
1028
  // use the subject from the recipient's user variables if available as a default
548
- const cc = recipient.cc;
549
- const bcc = recipient.bcc;
550
- const subject = (useSubjectFromRecipientUserVariables ? recipient.userVariables?.['subject'] : undefined) ?? defaultSubject ?? recipient.userVariables?.['subject'];
551
- const request = {
552
- ...baseRequest,
553
- from: recipient.from ?? baseRequest.from,
554
- replyTo: recipient.replyTo ?? baseRequest.replyTo,
555
- recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
1029
+ var cc = recipient.cc;
1030
+ var bcc = recipient.bcc;
1031
+ var subject = (_ref = (_ref1 = useSubjectFromRecipientUserVariables ? (_recipient_userVariables = recipient.userVariables) === null || _recipient_userVariables === void 0 ? void 0 : _recipient_userVariables['subject'] : undefined) !== null && _ref1 !== void 0 ? _ref1 : defaultSubject) !== null && _ref !== void 0 ? _ref : (_recipient_userVariables1 = recipient.userVariables) === null || _recipient_userVariables1 === void 0 ? void 0 : _recipient_userVariables1['subject'];
1032
+ var request = _object_spread_props(_object_spread({}, baseRequest), {
1033
+ from: (_recipient_from = recipient.from) !== null && _recipient_from !== void 0 ? _recipient_from : baseRequest.from,
1034
+ replyTo: (_recipient_replyTo = recipient.replyTo) !== null && _recipient_replyTo !== void 0 ? _recipient_replyTo : baseRequest.replyTo,
1035
+ recipientVariablesConfig: (_baseRequest_recipientVariablesConfig = baseRequest.recipientVariablesConfig) !== null && _baseRequest_recipientVariablesConfig !== void 0 ? _baseRequest_recipientVariablesConfig : recipientVariablesConfig,
556
1036
  to: recipient,
557
- cc,
558
- bcc,
559
- subject,
1037
+ cc: cc,
1038
+ bcc: bcc,
1039
+ subject: subject,
560
1040
  batchSend: false // explicitly disable batch send for non-batch requests
561
- };
1041
+ });
562
1042
  nonBatchSendRequests.push(request);
563
1043
  }
564
1044
  });
565
1045
  // create batch send request(s)
566
- const batchSendRequests = [];
1046
+ var batchSendRequests = [];
567
1047
  if (batchSendRequestRecipients.length > 0) {
568
- const subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
1048
+ var subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
569
1049
  // Group recipients by their from/replyTo values
570
- const batchSendRecipientGroups = util.makeValuesGroupMap(batchSendRequestRecipients, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey);
571
- batchSendRecipientGroups.forEach((groupRecipients) => {
1050
+ var batchSendRecipientGroups = util.makeValuesGroupMap(batchSendRequestRecipients, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey);
1051
+ batchSendRecipientGroups.forEach(function(groupRecipients) {
1052
+ var _baseRequest_recipientVariablesConfig;
572
1053
  // All recipients in this group should share the same from/replyTo values
573
- const firstRecipient = groupRecipients[0];
574
- const batchRequest = {
575
- ...baseRequest,
1054
+ var firstRecipient = groupRecipients[0];
1055
+ var batchRequest = _object_spread_props(_object_spread({}, baseRequest), {
576
1056
  from: firstRecipient.from,
577
1057
  replyTo: firstRecipient.replyTo,
578
- recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
1058
+ recipientVariablesConfig: (_baseRequest_recipientVariablesConfig = baseRequest.recipientVariablesConfig) !== null && _baseRequest_recipientVariablesConfig !== void 0 ? _baseRequest_recipientVariablesConfig : recipientVariablesConfig,
579
1059
  to: groupRecipients,
580
- subject,
1060
+ subject: subject,
581
1061
  batchSend: true
582
- };
1062
+ });
583
1063
  batchSendRequests.push(batchRequest);
584
1064
  });
585
1065
  }
586
- return util.filterMaybeArrayValues([...batchSendRequests, ...nonBatchSendRequests]);
1066
+ return util.filterMaybeArrayValues(_to_consumable_array(batchSendRequests).concat(_to_consumable_array(nonBatchSendRequests)));
587
1067
  };
588
1068
  }
589
1069
  /**
@@ -591,21 +1071,23 @@ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
591
1071
  *
592
1072
  * @param config The configuration for the lookup.
593
1073
  * @returns The lookup.
594
- */
595
- function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
596
- const { recipientsMap } = config;
1074
+ */ function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
1075
+ var recipientsMap = config.recipientsMap;
597
1076
  function getRecipientOrDefaultForKey(input, defaultRecipient) {
598
- let result = defaultRecipient;
1077
+ var result = defaultRecipient;
599
1078
  if (input) {
600
- result = recipientsMap.get(input) ?? defaultRecipient;
1079
+ var _recipientsMap_get;
1080
+ result = (_recipientsMap_get = recipientsMap.get(input)) !== null && _recipientsMap_get !== void 0 ? _recipientsMap_get : defaultRecipient;
601
1081
  }
602
1082
  return result;
603
1083
  }
604
1084
  function getRecipientsForKeys(input) {
605
- let result = undefined;
1085
+ var result = undefined;
606
1086
  if (input) {
607
- const keysArray = util.asArray(input);
608
- const recipients = util.filterMaybeArrayValues(keysArray.map((key) => recipientsMap.get(key)));
1087
+ var keysArray = util.asArray(input);
1088
+ var recipients = util.filterMaybeArrayValues(keysArray.map(function(key) {
1089
+ return recipientsMap.get(key);
1090
+ }));
609
1091
  if (recipients.length > 0) {
610
1092
  result = recipients;
611
1093
  }
@@ -613,9 +1095,9 @@ function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
613
1095
  return result;
614
1096
  }
615
1097
  return {
616
- recipientsMap,
617
- getRecipientOrDefaultForKey,
618
- getRecipientsForKeys
1098
+ recipientsMap: recipientsMap,
1099
+ getRecipientOrDefaultForKey: getRecipientOrDefaultForKey,
1100
+ getRecipientsForKeys: getRecipientsForKeys
619
1101
  };
620
1102
  }
621
1103