@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.
- package/discord/index.cjs.js +1171 -207
- package/discord/index.esm.js +1173 -209
- package/discord/package.json +5 -5
- package/index.cjs.js +918 -144
- package/index.esm.js +914 -146
- package/mailgun/index.cjs.js +797 -315
- package/mailgun/index.esm.js +797 -315
- package/mailgun/package.json +8 -8
- package/openai/index.cjs.js +867 -154
- package/openai/index.esm.js +867 -154
- package/openai/package.json +8 -8
- package/package.json +4 -4
- package/src/lib/decorators/local.decorator.d.ts +1 -1
- package/src/lib/decorators/rawbody.d.ts +73 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/middlewares/json.middleware.d.ts +10 -0
- package/src/lib/middlewares/webhook.d.ts +1 -1
- package/src/lib/module/client/client.config.d.ts +16 -0
- package/src/lib/module/env/env.config.d.ts +6 -0
- package/src/lib/module/env/env.service.d.ts +1 -0
- package/src/lib/util/encryption/index.d.ts +1 -0
- package/src/lib/util/encryption/json.encrypt.d.ts +130 -0
- package/src/lib/util/index.d.ts +1 -0
- package/stripe/index.cjs.js +625 -114
- package/stripe/index.esm.js +625 -114
- package/stripe/package.json +8 -8
- package/typeform/index.cjs.js +930 -173
- package/typeform/index.esm.js +930 -173
- package/typeform/package.json +8 -8
- package/vapiai/index.cjs.js +876 -151
- package/vapiai/index.esm.js +876 -151
- package/vapiai/package.json +8 -8
package/mailgun/index.esm.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
150
|
+
throw new Error("convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ".concat(MAX_BATCH_SEND_RECIPIENTS, " recipients."));
|
|
46
151
|
}
|
|
47
|
-
|
|
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
|
-
|
|
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 || (
|
|
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
|
-
|
|
66
|
-
|
|
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[
|
|
172
|
+
data["v:".concat(key)] = encodedValue;
|
|
69
173
|
if (recipientVariablePrefix && addCopyOfTemplateVariablesWithRecipientVariablePrefix) {
|
|
70
|
-
data[
|
|
174
|
+
data["v:".concat(recipientVariablePrefix).concat(key)] = encodedValue;
|
|
71
175
|
}
|
|
72
176
|
}
|
|
73
177
|
}
|
|
74
178
|
});
|
|
75
179
|
}
|
|
76
|
-
|
|
180
|
+
var hasUserVariables = Boolean(data['recipient-variables']) || toInput.findIndex(function(x) {
|
|
181
|
+
return x.userVariables != null;
|
|
182
|
+
}) !== -1;
|
|
77
183
|
if (hasUserVariables) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
195
|
+
var decoded = JSON.parse(data['recipient-variables']);
|
|
88
196
|
forEachKeyValue(decoded, {
|
|
89
|
-
forEach: (x)
|
|
90
|
-
|
|
91
|
-
|
|
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], {
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
122
|
-
data[
|
|
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[
|
|
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
|
-
|
|
252
|
+
forEachInIterable(allRecipientVariableKeys, function(key) {
|
|
253
|
+
var recipientVariableKey = "".concat(recipientVariablePrefix).concat(key);
|
|
142
254
|
// v:recipient-id=%recipient.id%
|
|
143
|
-
data[
|
|
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
|
-
|
|
264
|
+
var inputAttachments = request.attachments;
|
|
153
265
|
if (inputAttachments) {
|
|
154
266
|
if (data.attachment) {
|
|
155
|
-
throw new Error(
|
|
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)
|
|
274
|
+
return recipients.map(function(x) {
|
|
275
|
+
return convertMailgunRecipientToString(x);
|
|
276
|
+
});
|
|
163
277
|
}
|
|
164
278
|
function convertMailgunRecipientToString(recipient) {
|
|
165
|
-
|
|
279
|
+
var address = recipient.email;
|
|
166
280
|
if (recipient.name) {
|
|
167
|
-
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
|
-
|
|
178
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
244
|
-
/**
|
|
374
|
+
*/ _define_property$3(this, "clientUrl", void 0);
|
|
375
|
+
/**
|
|
245
376
|
* Main domain to send emails from.
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
/**
|
|
377
|
+
*/ _define_property$3(this, "domain", void 0);
|
|
378
|
+
/**
|
|
249
379
|
* Mailgun sender string.
|
|
250
|
-
*/
|
|
251
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
288
|
-
|
|
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
|
-
|
|
291
|
-
|
|
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
|
-
|
|
294
|
-
|
|
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
|
-
|
|
297
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
331
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
383
|
-
|
|
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')
|
|
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
|
-
|
|
806
|
+
var MailgunServiceModule = function MailgunServiceModule() {
|
|
807
|
+
_class_call_check(this, MailgunServiceModule);
|
|
404
808
|
};
|
|
405
809
|
MailgunServiceModule = __decorate([
|
|
406
810
|
Module({
|
|
407
|
-
imports: [
|
|
811
|
+
imports: [
|
|
812
|
+
ConfigModule
|
|
813
|
+
],
|
|
408
814
|
providers: [
|
|
409
815
|
{
|
|
410
816
|
provide: MailgunServiceConfig,
|
|
411
|
-
inject: [
|
|
817
|
+
inject: [
|
|
818
|
+
ConfigService,
|
|
819
|
+
ServerEnvironmentService
|
|
820
|
+
],
|
|
412
821
|
useFactory: mailgunServiceConfigFactory
|
|
413
822
|
},
|
|
414
823
|
MailgunApi,
|
|
415
824
|
MailgunService
|
|
416
825
|
],
|
|
417
|
-
exports: [
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
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
|
|
949
|
+
return (cc === null || cc === void 0 ? void 0 : cc.length) ? cc : undefined;
|
|
468
950
|
}
|
|
469
|
-
|
|
951
|
+
var baseRequestCc = determineCarbonCopyRecipients({
|
|
470
952
|
carbonCopyRecipients: inputBaseRequest.cc,
|
|
471
953
|
carbonCopyRecipientsKeys: inputBaseRequest.ccKeys
|
|
472
954
|
});
|
|
473
|
-
|
|
955
|
+
var baseRequestBcc = determineCarbonCopyRecipients({
|
|
474
956
|
carbonCopyRecipients: inputBaseRequest.bcc,
|
|
475
957
|
carbonCopyRecipientsKeys: inputBaseRequest.bccKeys
|
|
476
958
|
});
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
|
|
491
|
-
return (inputRecipients)
|
|
971
|
+
var configAllowBatchSend = baseRequest.batchSend !== false;
|
|
972
|
+
return function(inputRecipients) {
|
|
492
973
|
// Process recipients to resolve keys
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
-
|
|
995
|
+
var cc = determineCarbonCopyRecipients({
|
|
516
996
|
baseRequestCarbonCopyRecipients: baseRequestCc,
|
|
517
997
|
carbonCopyRecipients: recipient.cc,
|
|
518
998
|
carbonCopyRecipientsKeys: recipient.ccKeys
|
|
519
999
|
});
|
|
520
|
-
|
|
1000
|
+
var bcc = determineCarbonCopyRecipients({
|
|
521
1001
|
baseRequestCarbonCopyRecipients: baseRequestBcc,
|
|
522
1002
|
carbonCopyRecipients: recipient.bcc,
|
|
523
1003
|
carbonCopyRecipientsKeys: recipient.bccKeys
|
|
524
1004
|
});
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
recipients.forEach((recipient)
|
|
538
|
-
|
|
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
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
-
|
|
1044
|
+
var batchSendRequests = [];
|
|
565
1045
|
if (batchSendRequestRecipients.length > 0) {
|
|
566
|
-
|
|
1046
|
+
var subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
|
|
567
1047
|
// Group recipients by their from/replyTo values
|
|
568
|
-
|
|
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
|
-
|
|
572
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
594
|
-
const { recipientsMap } = config;
|
|
1072
|
+
*/ function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
|
|
1073
|
+
var recipientsMap = config.recipientsMap;
|
|
595
1074
|
function getRecipientOrDefaultForKey(input, defaultRecipient) {
|
|
596
|
-
|
|
1075
|
+
var result = defaultRecipient;
|
|
597
1076
|
if (input) {
|
|
598
|
-
|
|
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
|
-
|
|
1083
|
+
var result = undefined;
|
|
604
1084
|
if (input) {
|
|
605
|
-
|
|
606
|
-
|
|
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
|
|