@dereekb/nestjs 13.2.2 → 13.3.1

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