@dereekb/nestjs 13.38.0 → 13.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint/package.json +7 -7
- package/mailgun/package.json +11 -11
- package/openai/package.json +11 -11
- package/openrouter/package.json +8 -8
- package/package.json +27 -35
- package/stripe/package.json +11 -11
- package/twilio/index.esm.js +18 -1
- package/twilio/package.json +11 -11
- package/twilio/src/lib/twilio.api.d.ts +1 -1
- package/twilio/src/lib/twilio.interop.d.ts +7 -0
- package/typeform/package.json +11 -11
- package/vapiai/package.json +11 -11
- package/eslint/index.cjs.default.js +0 -1
- package/eslint/index.cjs.js +0 -418
- package/eslint/index.cjs.mjs +0 -2
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -2789
- package/index.cjs.mjs +0 -2
- package/mailgun/index.cjs.default.js +0 -1
- package/mailgun/index.cjs.js +0 -1802
- package/mailgun/index.cjs.mjs +0 -2
- package/openai/index.cjs.default.js +0 -1
- package/openai/index.cjs.js +0 -1068
- package/openai/index.cjs.mjs +0 -2
- package/openrouter/index.cjs.default.js +0 -1
- package/openrouter/index.cjs.js +0 -1200
- package/openrouter/index.cjs.mjs +0 -2
- package/stripe/index.cjs.default.js +0 -1
- package/stripe/index.cjs.js +0 -780
- package/stripe/index.cjs.mjs +0 -2
- package/twilio/index.cjs.default.js +0 -1
- package/twilio/index.cjs.js +0 -2184
- package/twilio/index.cjs.mjs +0 -2
- package/typeform/index.cjs.default.js +0 -1
- package/typeform/index.cjs.js +0 -1182
- package/typeform/index.cjs.mjs +0 -2
- package/vapiai/index.cjs.default.js +0 -1
- package/vapiai/index.cjs.js +0 -1055
- package/vapiai/index.cjs.mjs +0 -2
package/mailgun/index.cjs.js
DELETED
|
@@ -1,1802 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var nestjs = require('@dereekb/nestjs');
|
|
4
|
-
var util = require('@dereekb/util');
|
|
5
|
-
var common = require('@nestjs/common');
|
|
6
|
-
var Mailgun = require('mailgun.js');
|
|
7
|
-
var FormData = require('form-data');
|
|
8
|
-
var config = require('@nestjs/config');
|
|
9
|
-
|
|
10
|
-
function _array_like_to_array$2(arr, len) {
|
|
11
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
12
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
13
|
-
return arr2;
|
|
14
|
-
}
|
|
15
|
-
function _array_with_holes$1(arr) {
|
|
16
|
-
if (Array.isArray(arr)) return arr;
|
|
17
|
-
}
|
|
18
|
-
function _define_property$5(obj, key, value) {
|
|
19
|
-
if (key in obj) {
|
|
20
|
-
Object.defineProperty(obj, key, {
|
|
21
|
-
value: value,
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
obj[key] = value;
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
function _instanceof(left, right) {
|
|
32
|
-
"@swc/helpers - instanceof";
|
|
33
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
34
|
-
return !!right[Symbol.hasInstance](left);
|
|
35
|
-
} else {
|
|
36
|
-
return left instanceof right;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function _iterable_to_array_limit$1(arr, i) {
|
|
40
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
41
|
-
if (_i == null) return;
|
|
42
|
-
var _arr = [];
|
|
43
|
-
var _n = true;
|
|
44
|
-
var _d = false;
|
|
45
|
-
var _s, _e;
|
|
46
|
-
try {
|
|
47
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
48
|
-
_arr.push(_s.value);
|
|
49
|
-
if (i && _arr.length === i) break;
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
_d = true;
|
|
53
|
-
_e = err;
|
|
54
|
-
} finally{
|
|
55
|
-
try {
|
|
56
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
57
|
-
} finally{
|
|
58
|
-
if (_d) throw _e;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return _arr;
|
|
62
|
-
}
|
|
63
|
-
function _non_iterable_rest$1() {
|
|
64
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
65
|
-
}
|
|
66
|
-
function _object_spread$3(target) {
|
|
67
|
-
for(var i = 1; i < arguments.length; i++){
|
|
68
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
69
|
-
var ownKeys = Object.keys(source);
|
|
70
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
71
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
72
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
ownKeys.forEach(function(key) {
|
|
76
|
-
_define_property$5(target, key, source[key]);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return target;
|
|
80
|
-
}
|
|
81
|
-
function ownKeys$1(object, enumerableOnly) {
|
|
82
|
-
var keys = Object.keys(object);
|
|
83
|
-
if (Object.getOwnPropertySymbols) {
|
|
84
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
85
|
-
keys.push.apply(keys, symbols);
|
|
86
|
-
}
|
|
87
|
-
return keys;
|
|
88
|
-
}
|
|
89
|
-
function _object_spread_props$1(target, source) {
|
|
90
|
-
source = source != null ? source : {};
|
|
91
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
92
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
93
|
-
} else {
|
|
94
|
-
ownKeys$1(Object(source)).forEach(function(key) {
|
|
95
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return target;
|
|
99
|
-
}
|
|
100
|
-
function _sliced_to_array$1(arr, i) {
|
|
101
|
-
return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$1();
|
|
102
|
-
}
|
|
103
|
-
function _type_of$1(obj) {
|
|
104
|
-
"@swc/helpers - typeof";
|
|
105
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
106
|
-
}
|
|
107
|
-
function _unsupported_iterable_to_array$2(o, minLen) {
|
|
108
|
-
if (!o) return;
|
|
109
|
-
if (typeof o === "string") return _array_like_to_array$2(o, minLen);
|
|
110
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
111
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
112
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
113
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
|
|
114
|
-
}
|
|
115
|
-
var DEFAULT_RECIPIENT_VARIABLE_PREFIX = 'recipient-';
|
|
116
|
-
var MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = "h:Reply-To";
|
|
117
|
-
/**
|
|
118
|
-
* The maximum number of recipients allowed in a single batch send request.
|
|
119
|
-
*/ var MAX_BATCH_SEND_RECIPIENTS = 1000;
|
|
120
|
-
/**
|
|
121
|
-
* Converts a {@link MailgunTemplateEmailRequest} into Mailgun-compatible {@link MailgunMessageData},
|
|
122
|
-
* applying sender defaults, recipient variable prefixing, and test environment overrides.
|
|
123
|
-
*
|
|
124
|
-
* @param config - The conversion configuration containing the email request, default sender, and recipient variable settings.
|
|
125
|
-
* @returns The constructed {@link MailgunMessageData} ready to be sent via the Mailgun API.
|
|
126
|
-
* @throws {Error} When `batchSend` is enabled with `cc`/`bcc` set, when the recipient list exceeds {@link MAX_BATCH_SEND_RECIPIENTS}, or when attachments are supplied via both `messageData` and `request.attachments`.
|
|
127
|
-
*/ function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
|
|
128
|
-
var _ref, _ref1, _ref2, _ref3, _request_finalizeRecipientVariables, _request_batchSend;
|
|
129
|
-
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;
|
|
130
|
-
var recipientVariablesConfig = request.recipientVariablesConfig;
|
|
131
|
-
var recipientVariablePrefix = (_ref = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.recipientVariablePrefix) !== null && _ref !== void 0 ? _ref : inputRecipientVariablePrefix;
|
|
132
|
-
var addRecipientVariablePrefixToAllMergedGlobalVariables = (_ref1 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addRecipientVariablePrefixToAllMergedGlobalVariables) !== null && _ref1 !== void 0 ? _ref1 : inputAddRecipientVariablePrefixToAllMergedGlobalVariables;
|
|
133
|
-
var addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = (_ref2 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) !== null && _ref2 !== void 0 ? _ref2 : inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables;
|
|
134
|
-
var addCopyOfTemplateVariablesWithRecipientVariablePrefix = (_ref3 = recipientVariablesConfig === null || recipientVariablesConfig === void 0 ? void 0 : recipientVariablesConfig.addCopyOfTemplateVariablesWithRecipientVariablePrefix) !== null && _ref3 !== void 0 ? _ref3 : inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix;
|
|
135
|
-
var finalizeRecipientVariables = (_request_finalizeRecipientVariables = request.finalizeRecipientVariables) !== null && _request_finalizeRecipientVariables !== void 0 ? _request_finalizeRecipientVariables : util.MAP_IDENTITY;
|
|
136
|
-
var allowBatchSending = (_request_batchSend = request.batchSend) !== null && _request_batchSend !== void 0 ? _request_batchSend : true;
|
|
137
|
-
var mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
|
|
138
|
-
function mapEmailToLowercase(x) {
|
|
139
|
-
return _object_spread_props$1(_object_spread$3({}, x), {
|
|
140
|
-
email: x.email.toLowerCase()
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
var toInput = util.asArray(request.to).map(mapEmailToLowercase);
|
|
144
|
-
var ccInput = request.cc ? util.asArray(request.cc).map(mapEmailToLowercase) : undefined;
|
|
145
|
-
var bccInput = request.bcc ? util.asArray(request.bcc).map(mapEmailToLowercase) : undefined;
|
|
146
|
-
var from = request.from ? convertMailgunRecipientToString(request.from) : defaultSender;
|
|
147
|
-
var to = convertMailgunRecipientsToStrings(toInput);
|
|
148
|
-
var cc = (ccInput === null || ccInput === void 0 ? void 0 : ccInput.length) ? convertMailgunRecipientsToStrings(ccInput) : undefined;
|
|
149
|
-
var bcc = (bccInput === null || bccInput === void 0 ? void 0 : bccInput.length) ? convertMailgunRecipientsToStrings(bccInput) : undefined;
|
|
150
|
-
// throw an error if batchSend is not defined and cc or bcc is defined
|
|
151
|
-
if (request.batchSend == null && (ccInput || bccInput)) {
|
|
152
|
-
throw new Error('convertMailgunTemplateEmailRequestToMailgunMessageData(): batchSend must be false when either "cc" or "bcc" is defined.');
|
|
153
|
-
}
|
|
154
|
-
if (allowBatchSending && to.length > MAX_BATCH_SEND_RECIPIENTS) {
|
|
155
|
-
throw new Error("convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ".concat(MAX_BATCH_SEND_RECIPIENTS, " recipients."));
|
|
156
|
-
}
|
|
157
|
-
var data = _object_spread$3({
|
|
158
|
-
from: from,
|
|
159
|
-
to: to,
|
|
160
|
-
cc: cc,
|
|
161
|
-
bcc: bcc,
|
|
162
|
-
subject: request.subject,
|
|
163
|
-
template: request.template
|
|
164
|
-
}, request.messageData);
|
|
165
|
-
if (request.replyTo != null) {
|
|
166
|
-
data[MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY] = convertMailgunRecipientToString(request.replyTo);
|
|
167
|
-
}
|
|
168
|
-
if (request.testEmail === true || (testEnvironment !== null && testEnvironment !== void 0 ? testEnvironment : nestjs.isTestNodeEnv()) && request.testEmail !== false) {
|
|
169
|
-
data['o:testmode'] = true;
|
|
170
|
-
}
|
|
171
|
-
if (request.templateVariables) {
|
|
172
|
-
util.forEachKeyValue(request.templateVariables, {
|
|
173
|
-
forEach: function forEach(x) {
|
|
174
|
-
var _x = _sliced_to_array$1(x, 2), key = _x[0], value = _x[1];
|
|
175
|
-
var encodedValue = encodeMailgunTemplateVariableValue(value);
|
|
176
|
-
if (encodedValue != null) {
|
|
177
|
-
data["v:".concat(key)] = encodedValue;
|
|
178
|
-
if (recipientVariablePrefix && addCopyOfTemplateVariablesWithRecipientVariablePrefix) {
|
|
179
|
-
data["v:".concat(recipientVariablePrefix).concat(key)] = encodedValue;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
var hasUserVariables = Boolean(data['recipient-variables']) || toInput.some(function(x) {
|
|
186
|
-
return x.userVariables != null;
|
|
187
|
-
});
|
|
188
|
-
if (hasUserVariables) {
|
|
189
|
-
var _finalizeRecipientVariables;
|
|
190
|
-
var recipientVariables = {};
|
|
191
|
-
var allRecipientVariableKeys = new Set();
|
|
192
|
-
toInput.forEach(function(param) {
|
|
193
|
-
var email = param.email, userVariables = param.userVariables;
|
|
194
|
-
if (userVariables != null && !util.objectIsEmpty(userVariables)) {
|
|
195
|
-
recipientVariables[email] = userVariables;
|
|
196
|
-
util.addToSet(allRecipientVariableKeys, Object.keys(userVariables));
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
if (data['recipient-variables']) {
|
|
200
|
-
var decoded = JSON.parse(data['recipient-variables']);
|
|
201
|
-
util.forEachKeyValue(decoded, {
|
|
202
|
-
forEach: function forEach(x) {
|
|
203
|
-
var _x = _sliced_to_array$1(x, 2), recipientEmail = _x[0], userVariables = _x[1];
|
|
204
|
-
var email = recipientEmail.toLowerCase();
|
|
205
|
-
if (email in recipientVariables) {
|
|
206
|
-
util.overrideInObject(recipientVariables[email], {
|
|
207
|
-
from: [
|
|
208
|
-
userVariables
|
|
209
|
-
],
|
|
210
|
-
filter: {
|
|
211
|
-
valueFilter: util.KeyValueTypleValueFilter.UNDEFINED
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
} else {
|
|
215
|
-
recipientVariables[email] = userVariables;
|
|
216
|
-
}
|
|
217
|
-
util.addToSet(allRecipientVariableKeys, Object.keys(userVariables));
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
// Finalize the recipient variables before they are re-encoded back to JSON
|
|
222
|
-
recipientVariables = (_finalizeRecipientVariables = finalizeRecipientVariables(recipientVariables, {
|
|
223
|
-
messageData: data,
|
|
224
|
-
config: config
|
|
225
|
-
})) !== null && _finalizeRecipientVariables !== void 0 ? _finalizeRecipientVariables : recipientVariables;
|
|
226
|
-
if (mergeRecipientVariablesIntoGlobalVariable) {
|
|
227
|
-
var addRecipientPrefixVariable = recipientVariablePrefix && addRecipientVariablePrefixToAllMergedGlobalVariables;
|
|
228
|
-
// iterate all recipient variables and merge them into the global variables
|
|
229
|
-
util.forEachKeyValue(recipientVariables, {
|
|
230
|
-
forEach: function forEach(x) {
|
|
231
|
-
var _x = _sliced_to_array$1(x, 2); _x[0]; var userVariables = _x[1];
|
|
232
|
-
util.forEachKeyValue(userVariables, {
|
|
233
|
-
forEach: function forEach(y) {
|
|
234
|
-
var _y = _sliced_to_array$1(y, 2), key = _y[0], value = _y[1];
|
|
235
|
-
var encodedValue = encodeMailgunTemplateVariableValue(value);
|
|
236
|
-
if (encodedValue != null) {
|
|
237
|
-
if (addRecipientPrefixVariable) {
|
|
238
|
-
// also add the variable using the recipient variable prefix
|
|
239
|
-
var recipientVariableKey = "".concat(recipientVariablePrefix).concat(key);
|
|
240
|
-
data["v:".concat(recipientVariableKey)] = encodedValue;
|
|
241
|
-
}
|
|
242
|
-
// add if not adding the prefix variable, or if it was requested
|
|
243
|
-
if (!addRecipientPrefixVariable || addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) {
|
|
244
|
-
data["v:".concat(key)] = encodedValue;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
} else {
|
|
252
|
-
// set back on the data object
|
|
253
|
-
data['recipient-variables'] = JSON.stringify(recipientVariables);
|
|
254
|
-
// add all recipient variable to the other variables so they can be used easily/directly in templates as variables too.
|
|
255
|
-
// https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages
|
|
256
|
-
if (recipientVariablePrefix) {
|
|
257
|
-
util.forEachInIterable(allRecipientVariableKeys, function(key) {
|
|
258
|
-
var recipientVariableKey = "".concat(recipientVariablePrefix).concat(key);
|
|
259
|
-
// v:recipient-id=%recipient.id%
|
|
260
|
-
data["v:".concat(recipientVariableKey)] = "%recipient.".concat(key, "%");
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// double check and remove the recipient variables if we merged them into the global variables
|
|
266
|
-
if (mergeRecipientVariablesIntoGlobalVariable) {
|
|
267
|
-
delete data['recipient-variables'];
|
|
268
|
-
}
|
|
269
|
-
var inputAttachments = request.attachments;
|
|
270
|
-
if (inputAttachments) {
|
|
271
|
-
if (data.attachment) {
|
|
272
|
-
throw new Error("Cannot specify attachments in both messageData and in the request's attachments field.");
|
|
273
|
-
}
|
|
274
|
-
data.attachment = inputAttachments;
|
|
275
|
-
}
|
|
276
|
-
return data;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Converts an array of MailgunRecipient objects to formatted email address strings.
|
|
280
|
-
*
|
|
281
|
-
* Each recipient is formatted as "Name <email>" when a name is present, or just the email address.
|
|
282
|
-
*
|
|
283
|
-
* @param recipients - Recipients to convert.
|
|
284
|
-
* @returns Formatted email address strings.
|
|
285
|
-
*/ function convertMailgunRecipientsToStrings(recipients) {
|
|
286
|
-
return recipients.map(function(x) {
|
|
287
|
-
return convertMailgunRecipientToString(x);
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Converts a MailgunRecipient to a formatted email address string.
|
|
292
|
-
*
|
|
293
|
-
* Returns "Name <email>" when a name is present, or just the email address otherwise.
|
|
294
|
-
*
|
|
295
|
-
* @param recipient - The recipient to convert.
|
|
296
|
-
* @returns A formatted email participant string.
|
|
297
|
-
*/ function convertMailgunRecipientToString(recipient) {
|
|
298
|
-
var address = recipient.email;
|
|
299
|
-
if (recipient.name) {
|
|
300
|
-
address = "".concat(recipient.name, " <").concat(address, ">");
|
|
301
|
-
}
|
|
302
|
-
return address;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Encodes a value to a string for use as a Mailgun template variable. Throws an error if the value is not supported.
|
|
306
|
-
*
|
|
307
|
-
* @param value - The value to encode.
|
|
308
|
-
* @returns The encoded value, or undefined if the value is null or undefined.
|
|
309
|
-
* @throws {Error} When `value` has an unsupported runtime type.
|
|
310
|
-
*/ function encodeMailgunTemplateVariableValue(value) {
|
|
311
|
-
var encodedValue;
|
|
312
|
-
switch(typeof value === "undefined" ? "undefined" : _type_of$1(value)){
|
|
313
|
-
case 'object':
|
|
314
|
-
if (value) {
|
|
315
|
-
if (_instanceof(value, Date)) {
|
|
316
|
-
encodedValue = value.toISOString();
|
|
317
|
-
} else {
|
|
318
|
-
encodedValue = JSON.stringify(value);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
break;
|
|
322
|
-
case 'symbol':
|
|
323
|
-
case 'function':
|
|
324
|
-
case 'undefined':
|
|
325
|
-
break;
|
|
326
|
-
case 'bigint':
|
|
327
|
-
case 'boolean':
|
|
328
|
-
case 'number':
|
|
329
|
-
case 'string':
|
|
330
|
-
encodedValue = String(value); // encoded as a string value
|
|
331
|
-
break;
|
|
332
|
-
default:
|
|
333
|
-
if (value) {
|
|
334
|
-
throw new Error('Invalid value "'.concat(String(value), '" passed to encodeMailgunTemplateVariableValue().'));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return encodedValue;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function _type_of(obj) {
|
|
341
|
-
"@swc/helpers - typeof";
|
|
342
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
343
|
-
}
|
|
344
|
-
function __decorate(decorators, target, key, desc) {
|
|
345
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
346
|
-
if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
347
|
-
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;
|
|
348
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
349
|
-
}
|
|
350
|
-
function __param(paramIndex, decorator) {
|
|
351
|
-
return function(target, key) {
|
|
352
|
-
decorator(target, key, paramIndex);
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
356
|
-
var e = new Error(message);
|
|
357
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
function _class_call_check$3(instance, Constructor) {
|
|
361
|
-
if (!(instance instanceof Constructor)) {
|
|
362
|
-
throw new TypeError("Cannot call a class as a function");
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
function _defineProperties$2(target, props) {
|
|
366
|
-
for(var i = 0; i < props.length; i++){
|
|
367
|
-
var descriptor = props[i];
|
|
368
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
369
|
-
descriptor.configurable = true;
|
|
370
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
371
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
375
|
-
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
376
|
-
return Constructor;
|
|
377
|
-
}
|
|
378
|
-
function _define_property$4(obj, key, value) {
|
|
379
|
-
if (key in obj) {
|
|
380
|
-
Object.defineProperty(obj, key, {
|
|
381
|
-
value: value,
|
|
382
|
-
enumerable: true,
|
|
383
|
-
configurable: true,
|
|
384
|
-
writable: true
|
|
385
|
-
});
|
|
386
|
-
} else {
|
|
387
|
-
obj[key] = value;
|
|
388
|
-
}
|
|
389
|
-
return obj;
|
|
390
|
-
}
|
|
391
|
-
var MailgunServiceConfig = /*#__PURE__*/ function() {
|
|
392
|
-
function MailgunServiceConfig() {
|
|
393
|
-
_class_call_check$3(this, MailgunServiceConfig);
|
|
394
|
-
// Mailgun Config
|
|
395
|
-
_define_property$4(this, "mailgun", void 0);
|
|
396
|
-
/**
|
|
397
|
-
* Base URL to the client.
|
|
398
|
-
*/ _define_property$4(this, "clientUrl", void 0);
|
|
399
|
-
/**
|
|
400
|
-
* Main domain to send emails from.
|
|
401
|
-
*/ _define_property$4(this, "domain", void 0);
|
|
402
|
-
/**
|
|
403
|
-
* Mailgun sender string.
|
|
404
|
-
*/ _define_property$4(this, "sender", void 0);
|
|
405
|
-
/**
|
|
406
|
-
* Additional messages config
|
|
407
|
-
*/ _define_property$4(this, "messages", void 0);
|
|
408
|
-
}
|
|
409
|
-
_create_class$2(MailgunServiceConfig, null, [
|
|
410
|
-
{
|
|
411
|
-
key: "assertValidConfig",
|
|
412
|
-
value: function assertValidConfig(config) {
|
|
413
|
-
if (!config.mailgun.username) {
|
|
414
|
-
throw new Error('No mailgun username specified.');
|
|
415
|
-
} else if (!config.mailgun.key) {
|
|
416
|
-
throw new Error('No mailgun key specified.');
|
|
417
|
-
} else if (!config.domain) {
|
|
418
|
-
throw new Error('No mailgun domain specified.');
|
|
419
|
-
} else if (!config.clientUrl) {
|
|
420
|
-
throw new Error('No client url specified.');
|
|
421
|
-
} else if (!config.sender) {
|
|
422
|
-
throw new Error('No mailgun sender specified.');
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
]);
|
|
427
|
-
return MailgunServiceConfig;
|
|
428
|
-
}
|
|
429
|
-
();
|
|
430
|
-
|
|
431
|
-
function _class_call_check$2(instance, Constructor) {
|
|
432
|
-
if (!(instance instanceof Constructor)) {
|
|
433
|
-
throw new TypeError("Cannot call a class as a function");
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
function _defineProperties$1(target, props) {
|
|
437
|
-
for(var i = 0; i < props.length; i++){
|
|
438
|
-
var descriptor = props[i];
|
|
439
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
440
|
-
descriptor.configurable = true;
|
|
441
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
442
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
446
|
-
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
447
|
-
return Constructor;
|
|
448
|
-
}
|
|
449
|
-
function _define_property$3(obj, key, value) {
|
|
450
|
-
if (key in obj) {
|
|
451
|
-
Object.defineProperty(obj, key, {
|
|
452
|
-
value: value,
|
|
453
|
-
enumerable: true,
|
|
454
|
-
configurable: true,
|
|
455
|
-
writable: true
|
|
456
|
-
});
|
|
457
|
-
} else {
|
|
458
|
-
obj[key] = value;
|
|
459
|
-
}
|
|
460
|
-
return obj;
|
|
461
|
-
}
|
|
462
|
-
function _object_spread$2(target) {
|
|
463
|
-
for(var i = 1; i < arguments.length; i++){
|
|
464
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
465
|
-
var ownKeys = Object.keys(source);
|
|
466
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
467
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
468
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
469
|
-
}));
|
|
470
|
-
}
|
|
471
|
-
ownKeys.forEach(function(key) {
|
|
472
|
-
_define_property$3(target, key, source[key]);
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
return target;
|
|
476
|
-
}
|
|
477
|
-
exports.MailgunApi = /*#__PURE__*/ function() {
|
|
478
|
-
function MailgunApi(config) {
|
|
479
|
-
_class_call_check$2(this, MailgunApi);
|
|
480
|
-
_define_property$3(this, "config", void 0);
|
|
481
|
-
_define_property$3(this, "client", void 0);
|
|
482
|
-
this.config = config;
|
|
483
|
-
this.client = new Mailgun(FormData).client(_object_spread$2({}, config.mailgun));
|
|
484
|
-
}
|
|
485
|
-
_create_class$1(MailgunApi, [
|
|
486
|
-
{
|
|
487
|
-
key: "messages",
|
|
488
|
-
get: function get() {
|
|
489
|
-
return this.client.messages;
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
key: "suppressions",
|
|
494
|
-
get: /**
|
|
495
|
-
* The domain's suppression lists (bounces, spam complaints, unsubscribes, whitelists).
|
|
496
|
-
*
|
|
497
|
-
* An address on the bounce or complaint list is silently dropped by Mailgun on every subsequent send,
|
|
498
|
-
* which makes this the first thing to check when diagnosing "this recipient stopped receiving email".
|
|
499
|
-
*
|
|
500
|
-
* @returns The suppressions client.
|
|
501
|
-
*/ function get() {
|
|
502
|
-
return this.client.suppressions;
|
|
503
|
-
}
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
key: "events",
|
|
507
|
-
get: /**
|
|
508
|
-
* The domain's event log, used to inspect what actually happened to sent messages
|
|
509
|
-
* (accepted/delivered/failed/rejected/complained/unsubscribed).
|
|
510
|
-
*
|
|
511
|
-
* @returns The events client.
|
|
512
|
-
*/ function get() {
|
|
513
|
-
return this.client.events;
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
key: "validate",
|
|
518
|
-
get: /**
|
|
519
|
-
* Single-address validation.
|
|
520
|
-
*
|
|
521
|
-
* @returns The validation client.
|
|
522
|
-
*/ function get() {
|
|
523
|
-
return this.client.validate;
|
|
524
|
-
}
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
key: "domains",
|
|
528
|
-
get: /**
|
|
529
|
-
* Domain administration, used to read the sending domain's verification state.
|
|
530
|
-
*
|
|
531
|
-
* @returns The domains client.
|
|
532
|
-
*/ function get() {
|
|
533
|
-
return this.client.domains;
|
|
534
|
-
}
|
|
535
|
-
},
|
|
536
|
-
{
|
|
537
|
-
key: "clientUrl",
|
|
538
|
-
get: function get() {
|
|
539
|
-
return this.config.clientUrl;
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
key: "domain",
|
|
544
|
-
get: function get() {
|
|
545
|
-
return this.config.domain;
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
key: "sender",
|
|
550
|
-
get: function get() {
|
|
551
|
-
return this.config.sender;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
]);
|
|
555
|
-
return MailgunApi;
|
|
556
|
-
}();
|
|
557
|
-
exports.MailgunApi = __decorate([
|
|
558
|
-
common.Injectable(),
|
|
559
|
-
__param(0, common.Inject(MailgunServiceConfig))
|
|
560
|
-
], exports.MailgunApi);
|
|
561
|
-
|
|
562
|
-
function _array_like_to_array$1(arr, len) {
|
|
563
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
564
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
565
|
-
return arr2;
|
|
566
|
-
}
|
|
567
|
-
function _array_with_holes(arr) {
|
|
568
|
-
if (Array.isArray(arr)) return arr;
|
|
569
|
-
}
|
|
570
|
-
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
571
|
-
try {
|
|
572
|
-
var info = gen[key](arg);
|
|
573
|
-
var value = info.value;
|
|
574
|
-
} catch (error) {
|
|
575
|
-
reject(error);
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
if (info.done) {
|
|
579
|
-
resolve(value);
|
|
580
|
-
} else {
|
|
581
|
-
Promise.resolve(value).then(_next, _throw);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function _async_to_generator$1(fn) {
|
|
585
|
-
return function() {
|
|
586
|
-
var self = this, args = arguments;
|
|
587
|
-
return new Promise(function(resolve, reject) {
|
|
588
|
-
var gen = fn.apply(self, args);
|
|
589
|
-
function _next(value) {
|
|
590
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
591
|
-
}
|
|
592
|
-
function _throw(err) {
|
|
593
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
594
|
-
}
|
|
595
|
-
_next(undefined);
|
|
596
|
-
});
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
function _define_property$2(obj, key, value) {
|
|
600
|
-
if (key in obj) {
|
|
601
|
-
Object.defineProperty(obj, key, {
|
|
602
|
-
value: value,
|
|
603
|
-
enumerable: true,
|
|
604
|
-
configurable: true,
|
|
605
|
-
writable: true
|
|
606
|
-
});
|
|
607
|
-
} else {
|
|
608
|
-
obj[key] = value;
|
|
609
|
-
}
|
|
610
|
-
return obj;
|
|
611
|
-
}
|
|
612
|
-
function _iterable_to_array_limit(arr, i) {
|
|
613
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
614
|
-
if (_i == null) return;
|
|
615
|
-
var _arr = [];
|
|
616
|
-
var _n = true;
|
|
617
|
-
var _d = false;
|
|
618
|
-
var _s, _e;
|
|
619
|
-
try {
|
|
620
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
621
|
-
_arr.push(_s.value);
|
|
622
|
-
if (i && _arr.length === i) break;
|
|
623
|
-
}
|
|
624
|
-
} catch (err) {
|
|
625
|
-
_d = true;
|
|
626
|
-
_e = err;
|
|
627
|
-
} finally{
|
|
628
|
-
try {
|
|
629
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
630
|
-
} finally{
|
|
631
|
-
if (_d) throw _e;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return _arr;
|
|
635
|
-
}
|
|
636
|
-
function _non_iterable_rest() {
|
|
637
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
638
|
-
}
|
|
639
|
-
function _object_spread$1(target) {
|
|
640
|
-
for(var i = 1; i < arguments.length; i++){
|
|
641
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
642
|
-
var ownKeys = Object.keys(source);
|
|
643
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
644
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
645
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
646
|
-
}));
|
|
647
|
-
}
|
|
648
|
-
ownKeys.forEach(function(key) {
|
|
649
|
-
_define_property$2(target, key, source[key]);
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
return target;
|
|
653
|
-
}
|
|
654
|
-
function _sliced_to_array(arr, i) {
|
|
655
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest();
|
|
656
|
-
}
|
|
657
|
-
function _unsupported_iterable_to_array$1(o, minLen) {
|
|
658
|
-
if (!o) return;
|
|
659
|
-
if (typeof o === "string") return _array_like_to_array$1(o, minLen);
|
|
660
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
661
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
662
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
663
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
664
|
-
}
|
|
665
|
-
function _ts_generator$1(thisArg, body) {
|
|
666
|
-
var f, y, t, _ = {
|
|
667
|
-
label: 0,
|
|
668
|
-
sent: function() {
|
|
669
|
-
if (t[0] & 1) throw t[1];
|
|
670
|
-
return t[1];
|
|
671
|
-
},
|
|
672
|
-
trys: [],
|
|
673
|
-
ops: []
|
|
674
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
675
|
-
return d(g, "next", {
|
|
676
|
-
value: verb(0)
|
|
677
|
-
}), d(g, "throw", {
|
|
678
|
-
value: verb(1)
|
|
679
|
-
}), d(g, "return", {
|
|
680
|
-
value: verb(2)
|
|
681
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
682
|
-
value: function() {
|
|
683
|
-
return this;
|
|
684
|
-
}
|
|
685
|
-
}), g;
|
|
686
|
-
function verb(n) {
|
|
687
|
-
return function(v) {
|
|
688
|
-
return step([
|
|
689
|
-
n,
|
|
690
|
-
v
|
|
691
|
-
]);
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
function step(op) {
|
|
695
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
696
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
697
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
698
|
-
if (y = 0, t) op = [
|
|
699
|
-
op[0] & 2,
|
|
700
|
-
t.value
|
|
701
|
-
];
|
|
702
|
-
switch(op[0]){
|
|
703
|
-
case 0:
|
|
704
|
-
case 1:
|
|
705
|
-
t = op;
|
|
706
|
-
break;
|
|
707
|
-
case 4:
|
|
708
|
-
_.label++;
|
|
709
|
-
return {
|
|
710
|
-
value: op[1],
|
|
711
|
-
done: false
|
|
712
|
-
};
|
|
713
|
-
case 5:
|
|
714
|
-
_.label++;
|
|
715
|
-
y = op[1];
|
|
716
|
-
op = [
|
|
717
|
-
0
|
|
718
|
-
];
|
|
719
|
-
continue;
|
|
720
|
-
case 7:
|
|
721
|
-
op = _.ops.pop();
|
|
722
|
-
_.trys.pop();
|
|
723
|
-
continue;
|
|
724
|
-
default:
|
|
725
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
726
|
-
_ = 0;
|
|
727
|
-
continue;
|
|
728
|
-
}
|
|
729
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
730
|
-
_.label = op[1];
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
734
|
-
_.label = t[1];
|
|
735
|
-
t = op;
|
|
736
|
-
break;
|
|
737
|
-
}
|
|
738
|
-
if (t && _.label < t[2]) {
|
|
739
|
-
_.label = t[2];
|
|
740
|
-
_.ops.push(op);
|
|
741
|
-
break;
|
|
742
|
-
}
|
|
743
|
-
if (t[2]) _.ops.pop();
|
|
744
|
-
_.trys.pop();
|
|
745
|
-
continue;
|
|
746
|
-
}
|
|
747
|
-
op = body.call(thisArg, _);
|
|
748
|
-
} catch (e) {
|
|
749
|
-
op = [
|
|
750
|
-
6,
|
|
751
|
-
e
|
|
752
|
-
];
|
|
753
|
-
y = 0;
|
|
754
|
-
} finally{
|
|
755
|
-
f = t = 0;
|
|
756
|
-
}
|
|
757
|
-
if (op[0] & 5) throw op[1];
|
|
758
|
-
return {
|
|
759
|
-
value: op[0] ? op[1] : void 0,
|
|
760
|
-
done: true
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* The default number of events to read back when inspecting a recipient's recent activity.
|
|
766
|
-
*/ var DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT = 25;
|
|
767
|
-
/**
|
|
768
|
-
* The default window of history to inspect when reading a recipient's recent events.
|
|
769
|
-
*/ var DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS = 30;
|
|
770
|
-
/**
|
|
771
|
-
* Mailgun event names relevant to delivery diagnosis.
|
|
772
|
-
*
|
|
773
|
-
* Mailgun returns these as free-form strings; this enum names the ones that carry
|
|
774
|
-
* delivery meaning. Unknown values are passed through untouched.
|
|
775
|
-
*/ exports.MailgunEventName = void 0;
|
|
776
|
-
(function(MailgunEventName) {
|
|
777
|
-
MailgunEventName["ACCEPTED"] = "accepted";
|
|
778
|
-
MailgunEventName["DELIVERED"] = "delivered";
|
|
779
|
-
MailgunEventName["FAILED"] = "failed";
|
|
780
|
-
MailgunEventName["REJECTED"] = "rejected";
|
|
781
|
-
MailgunEventName["COMPLAINED"] = "complained";
|
|
782
|
-
MailgunEventName["UNSUBSCRIBED"] = "unsubscribed";
|
|
783
|
-
MailgunEventName["OPENED"] = "opened";
|
|
784
|
-
MailgunEventName["CLICKED"] = "clicked";
|
|
785
|
-
MailgunEventName["STORED"] = "stored";
|
|
786
|
-
})(exports.MailgunEventName || (exports.MailgunEventName = {}));
|
|
787
|
-
/**
|
|
788
|
-
* Mailgun failure severities. A `permanent` failure will never succeed on retry;
|
|
789
|
-
* a `temporary` one may.
|
|
790
|
-
*/ exports.MailgunEventSeverity = void 0;
|
|
791
|
-
(function(MailgunEventSeverity) {
|
|
792
|
-
MailgunEventSeverity["PERMANENT"] = "permanent";
|
|
793
|
-
MailgunEventSeverity["TEMPORARY"] = "temporary";
|
|
794
|
-
})(exports.MailgunEventSeverity || (exports.MailgunEventSeverity = {}));
|
|
795
|
-
/**
|
|
796
|
-
* True if any suppression record was found for the address.
|
|
797
|
-
*
|
|
798
|
-
* @param suppressions - The suppression records to check.
|
|
799
|
-
* @returns True if the address appears on any of the domain's suppression lists.
|
|
800
|
-
*/ function hasAnyMailgunRecipientSuppression(suppressions) {
|
|
801
|
-
return suppressions.bounce != null || suppressions.complaint != null || suppressions.unsubscribe != null;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Reads a single suppression entry, treating "not found" as an absent value.
|
|
805
|
-
*
|
|
806
|
-
* The Mailgun API responds 404 when the address is not on the requested list, which is the common case
|
|
807
|
-
* and not an error condition here.
|
|
808
|
-
*
|
|
809
|
-
* @param read - Performs the suppression lookup.
|
|
810
|
-
* @returns The suppression record, or undefined if the address is not on the list or the lookup failed.
|
|
811
|
-
*/ function readSuppression(read) {
|
|
812
|
-
return _async_to_generator$1(function() {
|
|
813
|
-
var result;
|
|
814
|
-
return _ts_generator$1(this, function(_state) {
|
|
815
|
-
switch(_state.label){
|
|
816
|
-
case 0:
|
|
817
|
-
_state.trys.push([
|
|
818
|
-
0,
|
|
819
|
-
2,
|
|
820
|
-
,
|
|
821
|
-
3
|
|
822
|
-
]);
|
|
823
|
-
return [
|
|
824
|
-
4,
|
|
825
|
-
read()
|
|
826
|
-
];
|
|
827
|
-
case 1:
|
|
828
|
-
result = _state.sent();
|
|
829
|
-
return [
|
|
830
|
-
3,
|
|
831
|
-
3
|
|
832
|
-
];
|
|
833
|
-
case 2:
|
|
834
|
-
_state.sent();
|
|
835
|
-
result = undefined;
|
|
836
|
-
return [
|
|
837
|
-
3,
|
|
838
|
-
3
|
|
839
|
-
];
|
|
840
|
-
case 3:
|
|
841
|
-
return [
|
|
842
|
-
2,
|
|
843
|
-
result
|
|
844
|
-
];
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
})();
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Looks up an address across the domain's bounce, complaint, and unsubscribe lists.
|
|
851
|
-
*
|
|
852
|
-
* @param api - The Mailgun API.
|
|
853
|
-
* @param email - The address to look up.
|
|
854
|
-
* @returns The suppression records found for the address. Absent fields mean the address is not on that list.
|
|
855
|
-
*
|
|
856
|
-
* @example
|
|
857
|
-
* ```ts
|
|
858
|
-
* const suppressions = await mailgunSuppressionsForRecipient(api, 'user@example.com');
|
|
859
|
-
*
|
|
860
|
-
* if (suppressions.bounce) {
|
|
861
|
-
* console.log(`suppressed by bounce: ${suppressions.bounce.error}`);
|
|
862
|
-
* }
|
|
863
|
-
* ```
|
|
864
|
-
*/ function mailgunSuppressionsForRecipient(api, email) {
|
|
865
|
-
return _async_to_generator$1(function() {
|
|
866
|
-
var domain, suppressions, _ref, bounce, complaint, unsubscribe;
|
|
867
|
-
return _ts_generator$1(this, function(_state) {
|
|
868
|
-
switch(_state.label){
|
|
869
|
-
case 0:
|
|
870
|
-
domain = api.domain, suppressions = api.suppressions;
|
|
871
|
-
return [
|
|
872
|
-
4,
|
|
873
|
-
Promise.all([
|
|
874
|
-
//
|
|
875
|
-
readSuppression(function() {
|
|
876
|
-
return suppressions.get(domain, 'bounces', email);
|
|
877
|
-
}),
|
|
878
|
-
readSuppression(function() {
|
|
879
|
-
return suppressions.get(domain, 'complaints', email);
|
|
880
|
-
}),
|
|
881
|
-
readSuppression(function() {
|
|
882
|
-
return suppressions.get(domain, 'unsubscribes', email);
|
|
883
|
-
})
|
|
884
|
-
])
|
|
885
|
-
];
|
|
886
|
-
case 1:
|
|
887
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
888
|
-
_state.sent(),
|
|
889
|
-
3
|
|
890
|
-
]), bounce = _ref[0], complaint = _ref[1], unsubscribe = _ref[2];
|
|
891
|
-
return [
|
|
892
|
-
2,
|
|
893
|
-
{
|
|
894
|
-
bounce: bounce,
|
|
895
|
-
complaint: complaint,
|
|
896
|
-
unsubscribe: unsubscribe
|
|
897
|
-
}
|
|
898
|
-
];
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
})();
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Reads the most recent Mailgun events for a recipient address, newest first.
|
|
905
|
-
*
|
|
906
|
-
* @param api - The Mailgun API.
|
|
907
|
-
* @param email - The recipient address to filter on.
|
|
908
|
-
* @param config - Optional limit/window/event filters.
|
|
909
|
-
* @returns The matching events, newest first. Empty if there is no recent activity or the lookup failed.
|
|
910
|
-
*
|
|
911
|
-
* @example
|
|
912
|
-
* ```ts
|
|
913
|
-
* const events = await mailgunRecentEventsForRecipient(api, 'user@example.com', { limit: 10 });
|
|
914
|
-
* const lastDelivered = events.find((x) => x.event === MailgunEventName.DELIVERED);
|
|
915
|
-
* ```
|
|
916
|
-
*/ function mailgunRecentEventsForRecipient(api, email, config) {
|
|
917
|
-
return _async_to_generator$1(function() {
|
|
918
|
-
var _ref, _ref1, limit, begin, query;
|
|
919
|
-
return _ts_generator$1(this, function(_state) {
|
|
920
|
-
limit = (_ref = config === null || config === void 0 ? void 0 : config.limit) !== null && _ref !== void 0 ? _ref : DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT;
|
|
921
|
-
begin = (_ref1 = config === null || config === void 0 ? void 0 : config.begin) !== null && _ref1 !== void 0 ? _ref1 : new Date(Date.now() - DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS * 24 * 60 * 60 * 1000);
|
|
922
|
-
query = {
|
|
923
|
-
recipient: email,
|
|
924
|
-
begin: begin.toUTCString(),
|
|
925
|
-
ascending: 'no',
|
|
926
|
-
limit: limit
|
|
927
|
-
};
|
|
928
|
-
if (config === null || config === void 0 ? void 0 : config.event) {
|
|
929
|
-
query.event = config.event;
|
|
930
|
-
}
|
|
931
|
-
return [
|
|
932
|
-
2,
|
|
933
|
-
mailgunEventsForQuery(api, query)
|
|
934
|
-
];
|
|
935
|
-
});
|
|
936
|
-
})();
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Strips the angle brackets Mailgun's send response wraps a message id in.
|
|
940
|
-
*
|
|
941
|
-
* `messages.create()` returns an id shaped like `<20240101120000.1.abc@domain>`, while the
|
|
942
|
-
* Events API `message-id` filter expects the bare `20240101120000.1.abc@domain`. Passing the
|
|
943
|
-
* bracketed form matches nothing.
|
|
944
|
-
*
|
|
945
|
-
* @param messageId - A message id in either form.
|
|
946
|
-
* @returns The message id without surrounding angle brackets.
|
|
947
|
-
*/ function bareMailgunMessageId(messageId) {
|
|
948
|
-
return messageId.replaceAll(/^<|>$/g, '');
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Reads all Mailgun events recorded for a specific message id.
|
|
952
|
-
*
|
|
953
|
-
* Used to resolve the outcome of a message that was already sent — the Events API lags the
|
|
954
|
-
* send by seconds to minutes, so an empty result means "not known yet", not "not delivered".
|
|
955
|
-
*
|
|
956
|
-
* @param api - The Mailgun API.
|
|
957
|
-
* @param messageId - The message id, with or without angle brackets.
|
|
958
|
-
* @param config - Optional additional filters (e.g. `recipient` to scope the lookup).
|
|
959
|
-
* @returns The events recorded for the message. Empty if none are recorded yet or the lookup failed.
|
|
960
|
-
*/ function mailgunEventsForMessageId(api, messageId, config) {
|
|
961
|
-
return _async_to_generator$1(function() {
|
|
962
|
-
var query;
|
|
963
|
-
return _ts_generator$1(this, function(_state) {
|
|
964
|
-
query = _object_spread$1({
|
|
965
|
-
'message-id': bareMailgunMessageId(messageId),
|
|
966
|
-
ascending: 'no'
|
|
967
|
-
}, config);
|
|
968
|
-
return [
|
|
969
|
-
2,
|
|
970
|
-
mailgunEventsForQuery(api, query)
|
|
971
|
-
];
|
|
972
|
-
});
|
|
973
|
-
})();
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Runs an arbitrary Events API query, returning an empty list if the lookup fails.
|
|
977
|
-
*
|
|
978
|
-
* @param api - The Mailgun API.
|
|
979
|
-
* @param query - The events query.
|
|
980
|
-
* @returns The matching events, or an empty array on failure.
|
|
981
|
-
*/ function mailgunEventsForQuery(api, query) {
|
|
982
|
-
return _async_to_generator$1(function() {
|
|
983
|
-
var events, _result_items, result;
|
|
984
|
-
return _ts_generator$1(this, function(_state) {
|
|
985
|
-
switch(_state.label){
|
|
986
|
-
case 0:
|
|
987
|
-
_state.trys.push([
|
|
988
|
-
0,
|
|
989
|
-
2,
|
|
990
|
-
,
|
|
991
|
-
3
|
|
992
|
-
]);
|
|
993
|
-
return [
|
|
994
|
-
4,
|
|
995
|
-
api.events.get(api.domain, query)
|
|
996
|
-
];
|
|
997
|
-
case 1:
|
|
998
|
-
result = _state.sent();
|
|
999
|
-
events = (_result_items = result.items) !== null && _result_items !== void 0 ? _result_items : [];
|
|
1000
|
-
return [
|
|
1001
|
-
3,
|
|
1002
|
-
3
|
|
1003
|
-
];
|
|
1004
|
-
case 2:
|
|
1005
|
-
_state.sent();
|
|
1006
|
-
events = [];
|
|
1007
|
-
return [
|
|
1008
|
-
3,
|
|
1009
|
-
3
|
|
1010
|
-
];
|
|
1011
|
-
case 3:
|
|
1012
|
-
return [
|
|
1013
|
-
2,
|
|
1014
|
-
events
|
|
1015
|
-
];
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
})();
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Reads the sending domain's state.
|
|
1022
|
-
*
|
|
1023
|
-
* A domain that is not `active` will fail to deliver regardless of recipient configuration,
|
|
1024
|
-
* so this distinguishes a system-wide outage from a per-recipient problem.
|
|
1025
|
-
*
|
|
1026
|
-
* @param api - The Mailgun API.
|
|
1027
|
-
* @returns The domain's state, with `unknown` set if it could not be read.
|
|
1028
|
-
*/ function mailgunDomainState(api) {
|
|
1029
|
-
return _async_to_generator$1(function() {
|
|
1030
|
-
var domain, state, result;
|
|
1031
|
-
return _ts_generator$1(this, function(_state) {
|
|
1032
|
-
switch(_state.label){
|
|
1033
|
-
case 0:
|
|
1034
|
-
domain = api.domain;
|
|
1035
|
-
_state.label = 1;
|
|
1036
|
-
case 1:
|
|
1037
|
-
_state.trys.push([
|
|
1038
|
-
1,
|
|
1039
|
-
3,
|
|
1040
|
-
,
|
|
1041
|
-
4
|
|
1042
|
-
]);
|
|
1043
|
-
return [
|
|
1044
|
-
4,
|
|
1045
|
-
api.domains.get(domain)
|
|
1046
|
-
];
|
|
1047
|
-
case 2:
|
|
1048
|
-
result = _state.sent();
|
|
1049
|
-
state = {
|
|
1050
|
-
domain: domain,
|
|
1051
|
-
state: result === null || result === void 0 ? void 0 : result.state,
|
|
1052
|
-
disabled: result === null || result === void 0 ? void 0 : result.is_disabled
|
|
1053
|
-
};
|
|
1054
|
-
return [
|
|
1055
|
-
3,
|
|
1056
|
-
4
|
|
1057
|
-
];
|
|
1058
|
-
case 3:
|
|
1059
|
-
_state.sent();
|
|
1060
|
-
state = {
|
|
1061
|
-
domain: domain,
|
|
1062
|
-
unknown: true
|
|
1063
|
-
};
|
|
1064
|
-
return [
|
|
1065
|
-
3,
|
|
1066
|
-
4
|
|
1067
|
-
];
|
|
1068
|
-
case 4:
|
|
1069
|
-
return [
|
|
1070
|
-
2,
|
|
1071
|
-
state
|
|
1072
|
-
];
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1075
|
-
})();
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Validates a single email address via the Mailgun Validation API.
|
|
1079
|
-
*
|
|
1080
|
-
* Note that validation consumes Mailgun validation quota, so callers should treat this as
|
|
1081
|
-
* an opt-in check rather than something to run on every request.
|
|
1082
|
-
*
|
|
1083
|
-
* @param api - The Mailgun API.
|
|
1084
|
-
* @param email - The address to validate.
|
|
1085
|
-
* @returns The validation result, or undefined if validation is unavailable or failed.
|
|
1086
|
-
*/ function mailgunValidateEmail(api, email) {
|
|
1087
|
-
return _async_to_generator$1(function() {
|
|
1088
|
-
var result;
|
|
1089
|
-
return _ts_generator$1(this, function(_state) {
|
|
1090
|
-
switch(_state.label){
|
|
1091
|
-
case 0:
|
|
1092
|
-
_state.trys.push([
|
|
1093
|
-
0,
|
|
1094
|
-
2,
|
|
1095
|
-
,
|
|
1096
|
-
3
|
|
1097
|
-
]);
|
|
1098
|
-
return [
|
|
1099
|
-
4,
|
|
1100
|
-
api.validate.get(email)
|
|
1101
|
-
];
|
|
1102
|
-
case 1:
|
|
1103
|
-
result = _state.sent();
|
|
1104
|
-
return [
|
|
1105
|
-
3,
|
|
1106
|
-
3
|
|
1107
|
-
];
|
|
1108
|
-
case 2:
|
|
1109
|
-
_state.sent();
|
|
1110
|
-
result = undefined;
|
|
1111
|
-
return [
|
|
1112
|
-
3,
|
|
1113
|
-
3
|
|
1114
|
-
];
|
|
1115
|
-
case 3:
|
|
1116
|
-
return [
|
|
1117
|
-
2,
|
|
1118
|
-
result
|
|
1119
|
-
];
|
|
1120
|
-
}
|
|
1121
|
-
});
|
|
1122
|
-
})();
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Converts a Mailgun event's unix-seconds timestamp to a Date.
|
|
1126
|
-
*
|
|
1127
|
-
* @param event - The event.
|
|
1128
|
-
* @returns The event's timestamp as a Date.
|
|
1129
|
-
*/ function mailgunDomainEventDate(event) {
|
|
1130
|
-
return new Date(event.timestamp * 1000);
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* The age of a Mailgun event in milliseconds relative to `now`.
|
|
1134
|
-
*
|
|
1135
|
-
* @param event - The event.
|
|
1136
|
-
* @param now - The reference time. Defaults to the current time.
|
|
1137
|
-
* @returns The event's age in milliseconds.
|
|
1138
|
-
*/ function mailgunDomainEventAge(event) {
|
|
1139
|
-
var now = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : new Date();
|
|
1140
|
-
return now.getTime() - mailgunDomainEventDate(event).getTime();
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Extracts the most useful human-readable reason from a failed/rejected Mailgun event.
|
|
1144
|
-
*
|
|
1145
|
-
* Mailgun spreads the explanation across `reason`, `delivery-status.description`, and
|
|
1146
|
-
* `delivery-status.message` depending on how the failure occurred, and any of them may be
|
|
1147
|
-
* empty.
|
|
1148
|
-
*
|
|
1149
|
-
* @param event - The event.
|
|
1150
|
-
* @returns The best available description, or undefined if the event carries none.
|
|
1151
|
-
*/ function mailgunDomainEventFailureReason(event) {
|
|
1152
|
-
var _ref;
|
|
1153
|
-
var deliveryStatus = event['delivery-status'];
|
|
1154
|
-
var description = (deliveryStatus === null || deliveryStatus === void 0 ? void 0 : deliveryStatus.description) || undefined;
|
|
1155
|
-
var message = (deliveryStatus === null || deliveryStatus === void 0 ? void 0 : deliveryStatus.message) || undefined;
|
|
1156
|
-
var reason = event.reason || undefined;
|
|
1157
|
-
return (_ref = description !== null && description !== void 0 ? description : message) !== null && _ref !== void 0 ? _ref : reason;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1161
|
-
try {
|
|
1162
|
-
var info = gen[key](arg);
|
|
1163
|
-
var value = info.value;
|
|
1164
|
-
} catch (error) {
|
|
1165
|
-
reject(error);
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
if (info.done) {
|
|
1169
|
-
resolve(value);
|
|
1170
|
-
} else {
|
|
1171
|
-
Promise.resolve(value).then(_next, _throw);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
function _async_to_generator(fn) {
|
|
1175
|
-
return function() {
|
|
1176
|
-
var self = this, args = arguments;
|
|
1177
|
-
return new Promise(function(resolve, reject) {
|
|
1178
|
-
var gen = fn.apply(self, args);
|
|
1179
|
-
function _next(value) {
|
|
1180
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1181
|
-
}
|
|
1182
|
-
function _throw(err) {
|
|
1183
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1184
|
-
}
|
|
1185
|
-
_next(undefined);
|
|
1186
|
-
});
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
function _class_call_check$1(instance, Constructor) {
|
|
1190
|
-
if (!(instance instanceof Constructor)) {
|
|
1191
|
-
throw new TypeError("Cannot call a class as a function");
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
function _defineProperties(target, props) {
|
|
1195
|
-
for(var i = 0; i < props.length; i++){
|
|
1196
|
-
var descriptor = props[i];
|
|
1197
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
1198
|
-
descriptor.configurable = true;
|
|
1199
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
1200
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
1204
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
1205
|
-
return Constructor;
|
|
1206
|
-
}
|
|
1207
|
-
function _define_property$1(obj, key, value) {
|
|
1208
|
-
if (key in obj) {
|
|
1209
|
-
Object.defineProperty(obj, key, {
|
|
1210
|
-
value: value,
|
|
1211
|
-
enumerable: true,
|
|
1212
|
-
configurable: true,
|
|
1213
|
-
writable: true
|
|
1214
|
-
});
|
|
1215
|
-
} else {
|
|
1216
|
-
obj[key] = value;
|
|
1217
|
-
}
|
|
1218
|
-
return obj;
|
|
1219
|
-
}
|
|
1220
|
-
function _ts_generator(thisArg, body) {
|
|
1221
|
-
var f, y, t, _ = {
|
|
1222
|
-
label: 0,
|
|
1223
|
-
sent: function() {
|
|
1224
|
-
if (t[0] & 1) throw t[1];
|
|
1225
|
-
return t[1];
|
|
1226
|
-
},
|
|
1227
|
-
trys: [],
|
|
1228
|
-
ops: []
|
|
1229
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1230
|
-
return d(g, "next", {
|
|
1231
|
-
value: verb(0)
|
|
1232
|
-
}), d(g, "throw", {
|
|
1233
|
-
value: verb(1)
|
|
1234
|
-
}), d(g, "return", {
|
|
1235
|
-
value: verb(2)
|
|
1236
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1237
|
-
value: function() {
|
|
1238
|
-
return this;
|
|
1239
|
-
}
|
|
1240
|
-
}), g;
|
|
1241
|
-
function verb(n) {
|
|
1242
|
-
return function(v) {
|
|
1243
|
-
return step([
|
|
1244
|
-
n,
|
|
1245
|
-
v
|
|
1246
|
-
]);
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1249
|
-
function step(op) {
|
|
1250
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
1251
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1252
|
-
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;
|
|
1253
|
-
if (y = 0, t) op = [
|
|
1254
|
-
op[0] & 2,
|
|
1255
|
-
t.value
|
|
1256
|
-
];
|
|
1257
|
-
switch(op[0]){
|
|
1258
|
-
case 0:
|
|
1259
|
-
case 1:
|
|
1260
|
-
t = op;
|
|
1261
|
-
break;
|
|
1262
|
-
case 4:
|
|
1263
|
-
_.label++;
|
|
1264
|
-
return {
|
|
1265
|
-
value: op[1],
|
|
1266
|
-
done: false
|
|
1267
|
-
};
|
|
1268
|
-
case 5:
|
|
1269
|
-
_.label++;
|
|
1270
|
-
y = op[1];
|
|
1271
|
-
op = [
|
|
1272
|
-
0
|
|
1273
|
-
];
|
|
1274
|
-
continue;
|
|
1275
|
-
case 7:
|
|
1276
|
-
op = _.ops.pop();
|
|
1277
|
-
_.trys.pop();
|
|
1278
|
-
continue;
|
|
1279
|
-
default:
|
|
1280
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1281
|
-
_ = 0;
|
|
1282
|
-
continue;
|
|
1283
|
-
}
|
|
1284
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1285
|
-
_.label = op[1];
|
|
1286
|
-
break;
|
|
1287
|
-
}
|
|
1288
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
1289
|
-
_.label = t[1];
|
|
1290
|
-
t = op;
|
|
1291
|
-
break;
|
|
1292
|
-
}
|
|
1293
|
-
if (t && _.label < t[2]) {
|
|
1294
|
-
_.label = t[2];
|
|
1295
|
-
_.ops.push(op);
|
|
1296
|
-
break;
|
|
1297
|
-
}
|
|
1298
|
-
if (t[2]) _.ops.pop();
|
|
1299
|
-
_.trys.pop();
|
|
1300
|
-
continue;
|
|
1301
|
-
}
|
|
1302
|
-
op = body.call(thisArg, _);
|
|
1303
|
-
} catch (e) {
|
|
1304
|
-
op = [
|
|
1305
|
-
6,
|
|
1306
|
-
e
|
|
1307
|
-
];
|
|
1308
|
-
y = 0;
|
|
1309
|
-
} finally{
|
|
1310
|
-
f = t = 0;
|
|
1311
|
-
}
|
|
1312
|
-
if (op[0] & 5) throw op[1];
|
|
1313
|
-
return {
|
|
1314
|
-
value: op[0] ? op[1] : void 0,
|
|
1315
|
-
done: true
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
exports.MailgunService = /*#__PURE__*/ function() {
|
|
1320
|
-
function MailgunService(mailgunApi, serverEnvironmentService) {
|
|
1321
|
-
_class_call_check$1(this, MailgunService);
|
|
1322
|
-
_define_property$1(this, "logger", new common.Logger('MailgunService'));
|
|
1323
|
-
_define_property$1(this, "_mailgunApi", void 0);
|
|
1324
|
-
_define_property$1(this, "_serverEnvironmentService", void 0);
|
|
1325
|
-
this._mailgunApi = mailgunApi;
|
|
1326
|
-
this._serverEnvironmentService = serverEnvironmentService;
|
|
1327
|
-
}
|
|
1328
|
-
_create_class(MailgunService, [
|
|
1329
|
-
{
|
|
1330
|
-
key: "mailgunApi",
|
|
1331
|
-
get: function get() {
|
|
1332
|
-
return this._mailgunApi;
|
|
1333
|
-
}
|
|
1334
|
-
},
|
|
1335
|
-
{
|
|
1336
|
-
key: "serverEnvironmentService",
|
|
1337
|
-
get: function get() {
|
|
1338
|
-
return this._serverEnvironmentService;
|
|
1339
|
-
}
|
|
1340
|
-
},
|
|
1341
|
-
{
|
|
1342
|
-
key: "sendTemplateEmail",
|
|
1343
|
-
value: function sendTemplateEmail(request) {
|
|
1344
|
-
return _async_to_generator(function() {
|
|
1345
|
-
var _request_sendTestEmails, domain, sender, isTestingEnvironment, recipientVariablePrefix, data, result, shouldSend, e;
|
|
1346
|
-
return _ts_generator(this, function(_state) {
|
|
1347
|
-
switch(_state.label){
|
|
1348
|
-
case 0:
|
|
1349
|
-
domain = this.mailgunApi.domain;
|
|
1350
|
-
sender = this.mailgunApi.sender;
|
|
1351
|
-
isTestingEnvironment = this.serverEnvironmentService.isTestingEnv;
|
|
1352
|
-
recipientVariablePrefix = this.mailgunApi.config.messages.recipientVariablePrefix;
|
|
1353
|
-
data = convertMailgunTemplateEmailRequestToMailgunMessageData({
|
|
1354
|
-
request: request,
|
|
1355
|
-
defaultSender: sender,
|
|
1356
|
-
recipientVariablePrefix: recipientVariablePrefix,
|
|
1357
|
-
isTestingEnvironment: isTestingEnvironment
|
|
1358
|
-
});
|
|
1359
|
-
shouldSend = !isTestingEnvironment || ((_request_sendTestEmails = request.sendTestEmails) !== null && _request_sendTestEmails !== void 0 ? _request_sendTestEmails : this.mailgunApi.config.messages.sendTestEmails);
|
|
1360
|
-
if (!shouldSend) return [
|
|
1361
|
-
3,
|
|
1362
|
-
5
|
|
1363
|
-
];
|
|
1364
|
-
_state.label = 1;
|
|
1365
|
-
case 1:
|
|
1366
|
-
_state.trys.push([
|
|
1367
|
-
1,
|
|
1368
|
-
3,
|
|
1369
|
-
,
|
|
1370
|
-
4
|
|
1371
|
-
]);
|
|
1372
|
-
return [
|
|
1373
|
-
4,
|
|
1374
|
-
this.mailgunApi.messages.create(domain, data)
|
|
1375
|
-
];
|
|
1376
|
-
case 2:
|
|
1377
|
-
result = _state.sent();
|
|
1378
|
-
return [
|
|
1379
|
-
3,
|
|
1380
|
-
4
|
|
1381
|
-
];
|
|
1382
|
-
case 3:
|
|
1383
|
-
e = _state.sent();
|
|
1384
|
-
this.logger.error('Failed sending email: ', e);
|
|
1385
|
-
throw e;
|
|
1386
|
-
case 4:
|
|
1387
|
-
return [
|
|
1388
|
-
3,
|
|
1389
|
-
6
|
|
1390
|
-
];
|
|
1391
|
-
case 5:
|
|
1392
|
-
result = {
|
|
1393
|
-
status: 200,
|
|
1394
|
-
message: 'Success. Env prevented sending email.'
|
|
1395
|
-
};
|
|
1396
|
-
_state.label = 6;
|
|
1397
|
-
case 6:
|
|
1398
|
-
return [
|
|
1399
|
-
2,
|
|
1400
|
-
result
|
|
1401
|
-
];
|
|
1402
|
-
}
|
|
1403
|
-
});
|
|
1404
|
-
}).call(this);
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
]);
|
|
1408
|
-
return MailgunService;
|
|
1409
|
-
}();
|
|
1410
|
-
exports.MailgunService = __decorate([
|
|
1411
|
-
common.Injectable(),
|
|
1412
|
-
__param(0, common.Inject(exports.MailgunApi)),
|
|
1413
|
-
__param(1, common.Inject(nestjs.ServerEnvironmentService))
|
|
1414
|
-
], exports.MailgunService);
|
|
1415
|
-
|
|
1416
|
-
function _class_call_check(instance, Constructor) {
|
|
1417
|
-
if (!(instance instanceof Constructor)) {
|
|
1418
|
-
throw new TypeError("Cannot call a class as a function");
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
var mailgunLogger = new common.Logger('MailgunServiceModule');
|
|
1422
|
-
/**
|
|
1423
|
-
* Factory that creates a MailgunServiceConfig from environment variables.
|
|
1424
|
-
*
|
|
1425
|
-
* Automatically switches to sandbox credentials when USE_MAILGUN_SANDBOX is true or the environment is a test environment.
|
|
1426
|
-
*
|
|
1427
|
-
* @param configService - NestJS config service for reading environment variables.
|
|
1428
|
-
* @param serverEnvironmentService - Service indicating the current server environment.
|
|
1429
|
-
* @returns A validated MailgunServiceConfig.
|
|
1430
|
-
* @throws {Error} When sandbox mode is requested without sandbox credentials, or when `MAILGUN_SENDER_EMAIL` / `MAILGUN_API_KEY` / `MAILGUN_DOMAIN` are missing.
|
|
1431
|
-
*/ function mailgunServiceConfigFactory(configService, serverEnvironmentService) {
|
|
1432
|
-
var _configService_get, _configService_get1, _configService_get2;
|
|
1433
|
-
var isTestingEnv = serverEnvironmentService.isTestingEnv;
|
|
1434
|
-
var useSandbox = configService.get('USE_MAILGUN_SANDBOX') === 'true' || isTestingEnv;
|
|
1435
|
-
var sendTestEmails = configService.get('MAILGUN_SEND_TEST_EMAILS') === 'true';
|
|
1436
|
-
var key = configService.get('MAILGUN_API_KEY');
|
|
1437
|
-
var domain = configService.get('MAILGUN_DOMAIN');
|
|
1438
|
-
if (useSandbox) {
|
|
1439
|
-
key = configService.get('MAILGUN_SANDBOX_API_KEY');
|
|
1440
|
-
domain = configService.get('MAILGUN_SANDBOX_DOMAIN');
|
|
1441
|
-
if (!key || !domain) {
|
|
1442
|
-
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.');
|
|
1443
|
-
} else if (!serverEnvironmentService.isTestingEnv) {
|
|
1444
|
-
mailgunLogger.log("Using Mailgun Sandbox Domain: ".concat(domain));
|
|
1445
|
-
}
|
|
1446
|
-
} else {
|
|
1447
|
-
mailgunLogger.log("Using Mailgun Production Domain: ".concat(domain));
|
|
1448
|
-
}
|
|
1449
|
-
var name = configService.get('MAILGUN_SENDER_NAME');
|
|
1450
|
-
var email = configService.get('MAILGUN_SENDER_EMAIL');
|
|
1451
|
-
var url = configService.get('MAILGUN_API_URL');
|
|
1452
|
-
var recipientVariablePrefix = (_configService_get = configService.get('MAILGUN_MESSAGES_RECIPIENT_VARIABLE_PREFIX')) !== null && _configService_get !== void 0 ? _configService_get : undefined;
|
|
1453
|
-
if (!email) {
|
|
1454
|
-
throw new Error('MAILGUN_SENDER_EMAIL is required but was not configured.');
|
|
1455
|
-
} else if (!key) {
|
|
1456
|
-
throw new Error('MAILGUN_API_KEY (or MAILGUN_SANDBOX_API_KEY for tests) is required but was not configured.');
|
|
1457
|
-
} else if (!domain) {
|
|
1458
|
-
throw new Error('MAILGUN_DOMAIN (or MAILGUN_SANDBOX_DOMAIN for tests) is required but was not configured.');
|
|
1459
|
-
}
|
|
1460
|
-
var clientUrl = (_configService_get1 = configService.get('CLIENT_APP_URL')) !== null && _configService_get1 !== void 0 ? _configService_get1 : domain;
|
|
1461
|
-
var config = {
|
|
1462
|
-
mailgun: {
|
|
1463
|
-
username: (_configService_get2 = configService.get('MAILGUN_USERNAME')) !== null && _configService_get2 !== void 0 ? _configService_get2 : 'api',
|
|
1464
|
-
key: key,
|
|
1465
|
-
url: url
|
|
1466
|
-
},
|
|
1467
|
-
domain: domain,
|
|
1468
|
-
clientUrl: clientUrl,
|
|
1469
|
-
sender: convertMailgunRecipientToString({
|
|
1470
|
-
name: name,
|
|
1471
|
-
email: email
|
|
1472
|
-
}),
|
|
1473
|
-
messages: {
|
|
1474
|
-
sendTestEmails: sendTestEmails,
|
|
1475
|
-
recipientVariablePrefix: recipientVariablePrefix
|
|
1476
|
-
}
|
|
1477
|
-
};
|
|
1478
|
-
MailgunServiceConfig.assertValidConfig(config);
|
|
1479
|
-
return config;
|
|
1480
|
-
}
|
|
1481
|
-
/**
|
|
1482
|
-
* NestJS module that provides the MailgunApi and MailgunService for sending emails.
|
|
1483
|
-
*
|
|
1484
|
-
* Reads Mailgun credentials and sender configuration from environment variables,
|
|
1485
|
-
* with automatic fallback to sandbox settings in test environments.
|
|
1486
|
-
*/ exports.MailgunServiceModule = function MailgunServiceModule() {
|
|
1487
|
-
_class_call_check(this, MailgunServiceModule);
|
|
1488
|
-
};
|
|
1489
|
-
exports.MailgunServiceModule = __decorate([
|
|
1490
|
-
common.Module({
|
|
1491
|
-
imports: [
|
|
1492
|
-
config.ConfigModule
|
|
1493
|
-
],
|
|
1494
|
-
providers: [
|
|
1495
|
-
{
|
|
1496
|
-
provide: MailgunServiceConfig,
|
|
1497
|
-
inject: [
|
|
1498
|
-
config.ConfigService,
|
|
1499
|
-
nestjs.ServerEnvironmentService
|
|
1500
|
-
],
|
|
1501
|
-
useFactory: mailgunServiceConfigFactory
|
|
1502
|
-
},
|
|
1503
|
-
exports.MailgunApi,
|
|
1504
|
-
exports.MailgunService
|
|
1505
|
-
],
|
|
1506
|
-
exports: [
|
|
1507
|
-
exports.MailgunApi,
|
|
1508
|
-
exports.MailgunService
|
|
1509
|
-
]
|
|
1510
|
-
})
|
|
1511
|
-
], exports.MailgunServiceModule);
|
|
1512
|
-
|
|
1513
|
-
function _array_like_to_array(arr, len) {
|
|
1514
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1515
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1516
|
-
return arr2;
|
|
1517
|
-
}
|
|
1518
|
-
function _array_without_holes(arr) {
|
|
1519
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1520
|
-
}
|
|
1521
|
-
function _define_property(obj, key, value) {
|
|
1522
|
-
if (key in obj) {
|
|
1523
|
-
Object.defineProperty(obj, key, {
|
|
1524
|
-
value: value,
|
|
1525
|
-
enumerable: true,
|
|
1526
|
-
configurable: true,
|
|
1527
|
-
writable: true
|
|
1528
|
-
});
|
|
1529
|
-
} else {
|
|
1530
|
-
obj[key] = value;
|
|
1531
|
-
}
|
|
1532
|
-
return obj;
|
|
1533
|
-
}
|
|
1534
|
-
function _iterable_to_array(iter) {
|
|
1535
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1536
|
-
}
|
|
1537
|
-
function _non_iterable_spread() {
|
|
1538
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1539
|
-
}
|
|
1540
|
-
function _object_spread(target) {
|
|
1541
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1542
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
1543
|
-
var ownKeys = Object.keys(source);
|
|
1544
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1545
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1546
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1547
|
-
}));
|
|
1548
|
-
}
|
|
1549
|
-
ownKeys.forEach(function(key) {
|
|
1550
|
-
_define_property(target, key, source[key]);
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
return target;
|
|
1554
|
-
}
|
|
1555
|
-
function ownKeys(object, enumerableOnly) {
|
|
1556
|
-
var keys = Object.keys(object);
|
|
1557
|
-
if (Object.getOwnPropertySymbols) {
|
|
1558
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
1559
|
-
keys.push.apply(keys, symbols);
|
|
1560
|
-
}
|
|
1561
|
-
return keys;
|
|
1562
|
-
}
|
|
1563
|
-
function _object_spread_props(target, source) {
|
|
1564
|
-
source = source != null ? source : {};
|
|
1565
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
1566
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1567
|
-
} else {
|
|
1568
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
1569
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1570
|
-
});
|
|
1571
|
-
}
|
|
1572
|
-
return target;
|
|
1573
|
-
}
|
|
1574
|
-
function _to_consumable_array(arr) {
|
|
1575
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
1576
|
-
}
|
|
1577
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
1578
|
-
if (!o) return;
|
|
1579
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1580
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1581
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1582
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1583
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* The default template subject to use when batch sending emails.
|
|
1587
|
-
*
|
|
1588
|
-
* This pulls the subject from each recipient's user variables.
|
|
1589
|
-
*/ var MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = "%recipient.subject%";
|
|
1590
|
-
/**
|
|
1591
|
-
* Creates a composite key from the from/replyTo email addresses used to group MailgunRecipientBatchSendTarget values.
|
|
1592
|
-
*
|
|
1593
|
-
* @param recipient - Batch send target whose from/replyTo addresses are used as the grouping key.
|
|
1594
|
-
* @returns Composite key in the form "f:{fromEmail}|r:{replyToEmail}" used to group recipients into batches.
|
|
1595
|
-
*/ function mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey(recipient) {
|
|
1596
|
-
var _ref, _ref1;
|
|
1597
|
-
var _recipient_from, _recipient_replyTo;
|
|
1598
|
-
var fromEmail = ((_ref = (_recipient_from = recipient.from) === null || _recipient_from === void 0 ? void 0 : _recipient_from.email) !== null && _ref !== void 0 ? _ref : '').toLowerCase();
|
|
1599
|
-
var replyToEmail = ((_ref1 = (_recipient_replyTo = recipient.replyTo) === null || _recipient_replyTo === void 0 ? void 0 : _recipient_replyTo.email) !== null && _ref1 !== void 0 ? _ref1 : '').toLowerCase();
|
|
1600
|
-
return "f:".concat(fromEmail, "|r:").concat(replyToEmail);
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* Creates a ExpandMailgunRecipientBatchSendTargetRequestFactory from the input config.
|
|
1604
|
-
*
|
|
1605
|
-
* @param config - Factory configuration providing the base request, recipient lookup, and per-recipient variable handling.
|
|
1606
|
-
* @returns A factory that expands `MailgunRecipientBatchSendTarget` lists into individual `MailgunTemplateEmailRequest` objects.
|
|
1607
|
-
* @throws {Error} When no subject is configured and `useSubjectFromRecipientUserVariables` is false.
|
|
1608
|
-
*/ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
|
|
1609
|
-
var _inputBaseRequest_from, _inputBaseRequest_replyTo;
|
|
1610
|
-
var inputBaseRequest = config.request, useSubjectFromRecipientUserVariables = config.useSubjectFromRecipientUserVariables, allowSingleRecipientBatchSendRequests = config.allowSingleRecipientBatchSendRequests, recipientVariablesConfig = config.recipientVariablesConfig, mailgunRecipientBatchSendTargetEntityKeyRecipientLookup = config.mailgunRecipientBatchSendTargetEntityKeyRecipientLookup, overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients = config.overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients;
|
|
1611
|
-
var defaultSubject = inputBaseRequest.subject;
|
|
1612
|
-
if (!defaultSubject && !useSubjectFromRecipientUserVariables) {
|
|
1613
|
-
throw new Error('defaultSubject must be set when "useSubjectFromRecipientUserVariables" is false');
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Returns the carbon copy recipients, based on the input.
|
|
1617
|
-
*
|
|
1618
|
-
* Will return undefined if the array would be empty.
|
|
1619
|
-
*
|
|
1620
|
-
* @param input
|
|
1621
|
-
* @returns
|
|
1622
|
-
*/ function determineCarbonCopyRecipients(input) {
|
|
1623
|
-
var baseRequestCarbonCopyRecipients = input.baseRequestCarbonCopyRecipients, carbonCopyRecipients = input.carbonCopyRecipients, carbonCopyRecipientsKeys = input.carbonCopyRecipientsKeys;
|
|
1624
|
-
var cc = carbonCopyRecipients ? util.asArray(carbonCopyRecipients) : baseRequestCarbonCopyRecipients;
|
|
1625
|
-
var resolvedCc = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientsForKeys(carbonCopyRecipientsKeys);
|
|
1626
|
-
if (resolvedCc === null || resolvedCc === void 0 ? void 0 : resolvedCc.length) {
|
|
1627
|
-
if (overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients) {
|
|
1628
|
-
cc = resolvedCc;
|
|
1629
|
-
} else {
|
|
1630
|
-
cc = _to_consumable_array(cc !== null && cc !== void 0 ? cc : []).concat(_to_consumable_array(resolvedCc));
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
return (cc === null || cc === void 0 ? void 0 : cc.length) ? cc : undefined;
|
|
1634
|
-
}
|
|
1635
|
-
var baseRequestCc = determineCarbonCopyRecipients({
|
|
1636
|
-
carbonCopyRecipients: inputBaseRequest.cc,
|
|
1637
|
-
carbonCopyRecipientsKeys: inputBaseRequest.ccKeys
|
|
1638
|
-
});
|
|
1639
|
-
var baseRequestBcc = determineCarbonCopyRecipients({
|
|
1640
|
-
carbonCopyRecipients: inputBaseRequest.bcc,
|
|
1641
|
-
carbonCopyRecipientsKeys: inputBaseRequest.bccKeys
|
|
1642
|
-
});
|
|
1643
|
-
var baseRequestFrom = (_inputBaseRequest_from = inputBaseRequest.from) !== null && _inputBaseRequest_from !== void 0 ? _inputBaseRequest_from : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(inputBaseRequest.fromKey);
|
|
1644
|
-
var baseRequestReplyTo = (_inputBaseRequest_replyTo = inputBaseRequest.replyTo) !== null && _inputBaseRequest_replyTo !== void 0 ? _inputBaseRequest_replyTo : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === null || mailgunRecipientBatchSendTargetEntityKeyRecipientLookup === void 0 ? void 0 : mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(inputBaseRequest.replyToKey);
|
|
1645
|
-
var baseRequest = _object_spread_props(_object_spread({}, inputBaseRequest), {
|
|
1646
|
-
from: baseRequestFrom,
|
|
1647
|
-
replyTo: baseRequestReplyTo,
|
|
1648
|
-
cc: baseRequestCc,
|
|
1649
|
-
bcc: baseRequestBcc
|
|
1650
|
-
});
|
|
1651
|
-
delete baseRequest.fromKey;
|
|
1652
|
-
delete baseRequest.replyToKey;
|
|
1653
|
-
delete baseRequest.ccKeys;
|
|
1654
|
-
delete baseRequest.bccKeys;
|
|
1655
|
-
var configAllowBatchSend = baseRequest.batchSend !== false;
|
|
1656
|
-
return function(inputRecipients) {
|
|
1657
|
-
// Process recipients to resolve keys
|
|
1658
|
-
var recipients = inputRecipients.map(function(recipient) {
|
|
1659
|
-
var from = recipient.from;
|
|
1660
|
-
var replyTo = recipient.replyTo;
|
|
1661
|
-
if (mailgunRecipientBatchSendTargetEntityKeyRecipientLookup) {
|
|
1662
|
-
// try the fromKey, otherwise use the baseRequest.from
|
|
1663
|
-
from !== null && from !== void 0 ? from : from = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.fromKey, baseRequest.from);
|
|
1664
|
-
// try the replyToKey, otherwise use the baseRequest.replyTo
|
|
1665
|
-
replyTo !== null && replyTo !== void 0 ? replyTo : replyTo = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.replyToKey, baseRequest.replyTo);
|
|
1666
|
-
} else {
|
|
1667
|
-
// use defaults from base request
|
|
1668
|
-
from !== null && from !== void 0 ? from : from = baseRequest.from;
|
|
1669
|
-
replyTo !== null && replyTo !== void 0 ? replyTo : replyTo = baseRequest.replyTo;
|
|
1670
|
-
}
|
|
1671
|
-
var cc = determineCarbonCopyRecipients({
|
|
1672
|
-
baseRequestCarbonCopyRecipients: baseRequestCc,
|
|
1673
|
-
carbonCopyRecipients: recipient.cc,
|
|
1674
|
-
carbonCopyRecipientsKeys: recipient.ccKeys
|
|
1675
|
-
});
|
|
1676
|
-
var bcc = determineCarbonCopyRecipients({
|
|
1677
|
-
baseRequestCarbonCopyRecipients: baseRequestBcc,
|
|
1678
|
-
carbonCopyRecipients: recipient.bcc,
|
|
1679
|
-
carbonCopyRecipientsKeys: recipient.bccKeys
|
|
1680
|
-
});
|
|
1681
|
-
var result = _object_spread_props(_object_spread({}, recipient), {
|
|
1682
|
-
from: from,
|
|
1683
|
-
replyTo: replyTo,
|
|
1684
|
-
cc: cc,
|
|
1685
|
-
bcc: bcc
|
|
1686
|
-
});
|
|
1687
|
-
return result;
|
|
1688
|
-
});
|
|
1689
|
-
var allowBatchSend = configAllowBatchSend && (allowSingleRecipientBatchSendRequests !== null && allowSingleRecipientBatchSendRequests !== void 0 ? allowSingleRecipientBatchSendRequests : recipients.length > 1);
|
|
1690
|
-
var nonBatchSendRequests = [];
|
|
1691
|
-
var batchSendRequestRecipients = [];
|
|
1692
|
-
recipients.forEach(function(recipient) {
|
|
1693
|
-
var _recipient_cc, _recipient_bcc;
|
|
1694
|
-
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));
|
|
1695
|
-
if (allowBatchSend && !recipientHasCarbonCopy) {
|
|
1696
|
-
// add to batch send recipients
|
|
1697
|
-
batchSendRequestRecipients.push(recipient);
|
|
1698
|
-
} else {
|
|
1699
|
-
var _ref, _ref1, _recipient_from, _recipient_replyTo, _baseRequest_recipientVariablesConfig;
|
|
1700
|
-
var _recipient_userVariables, _recipient_userVariables1;
|
|
1701
|
-
// add to non-batch send requests
|
|
1702
|
-
// use the subject from the recipient's user variables if available as a default
|
|
1703
|
-
var cc = recipient.cc;
|
|
1704
|
-
var bcc = recipient.bcc;
|
|
1705
|
-
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'];
|
|
1706
|
-
var request = _object_spread_props(_object_spread({}, baseRequest), {
|
|
1707
|
-
from: (_recipient_from = recipient.from) !== null && _recipient_from !== void 0 ? _recipient_from : baseRequest.from,
|
|
1708
|
-
replyTo: (_recipient_replyTo = recipient.replyTo) !== null && _recipient_replyTo !== void 0 ? _recipient_replyTo : baseRequest.replyTo,
|
|
1709
|
-
recipientVariablesConfig: (_baseRequest_recipientVariablesConfig = baseRequest.recipientVariablesConfig) !== null && _baseRequest_recipientVariablesConfig !== void 0 ? _baseRequest_recipientVariablesConfig : recipientVariablesConfig,
|
|
1710
|
-
to: recipient,
|
|
1711
|
-
cc: cc,
|
|
1712
|
-
bcc: bcc,
|
|
1713
|
-
subject: subject,
|
|
1714
|
-
batchSend: false // explicitly disable batch send for non-batch requests
|
|
1715
|
-
});
|
|
1716
|
-
nonBatchSendRequests.push(request);
|
|
1717
|
-
}
|
|
1718
|
-
});
|
|
1719
|
-
// create batch send request(s)
|
|
1720
|
-
var batchSendRequests = [];
|
|
1721
|
-
if (batchSendRequestRecipients.length > 0) {
|
|
1722
|
-
var subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
|
|
1723
|
-
// Group recipients by their from/replyTo values
|
|
1724
|
-
var batchSendRecipientGroups = util.makeValuesGroupMap(batchSendRequestRecipients, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey);
|
|
1725
|
-
batchSendRecipientGroups.forEach(function(groupRecipients) {
|
|
1726
|
-
var _baseRequest_recipientVariablesConfig;
|
|
1727
|
-
// All recipients in this group should share the same from/replyTo values
|
|
1728
|
-
var firstRecipient = groupRecipients[0];
|
|
1729
|
-
var batchRequest = _object_spread_props(_object_spread({}, baseRequest), {
|
|
1730
|
-
from: firstRecipient.from,
|
|
1731
|
-
replyTo: firstRecipient.replyTo,
|
|
1732
|
-
recipientVariablesConfig: (_baseRequest_recipientVariablesConfig = baseRequest.recipientVariablesConfig) !== null && _baseRequest_recipientVariablesConfig !== void 0 ? _baseRequest_recipientVariablesConfig : recipientVariablesConfig,
|
|
1733
|
-
to: groupRecipients,
|
|
1734
|
-
subject: subject,
|
|
1735
|
-
batchSend: true
|
|
1736
|
-
});
|
|
1737
|
-
batchSendRequests.push(batchRequest);
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
|
-
return util.filterMaybeArrayValues(_to_consumable_array(batchSendRequests).concat(_to_consumable_array(nonBatchSendRequests)));
|
|
1741
|
-
};
|
|
1742
|
-
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Creates a MailgunRecipientBatchSendTargetEntityKeyRecipientLookup given the input configuration.
|
|
1745
|
-
*
|
|
1746
|
-
* @param config - The configuration for the lookup.
|
|
1747
|
-
* @returns The lookup.
|
|
1748
|
-
*/ function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
|
|
1749
|
-
var recipientsMap = config.recipientsMap;
|
|
1750
|
-
function getRecipientOrDefaultForKey(input, defaultRecipient) {
|
|
1751
|
-
var result = defaultRecipient;
|
|
1752
|
-
if (input) {
|
|
1753
|
-
var _recipientsMap_get;
|
|
1754
|
-
result = (_recipientsMap_get = recipientsMap.get(input)) !== null && _recipientsMap_get !== void 0 ? _recipientsMap_get : defaultRecipient;
|
|
1755
|
-
}
|
|
1756
|
-
return result;
|
|
1757
|
-
}
|
|
1758
|
-
function getRecipientsForKeys(input) {
|
|
1759
|
-
var result = undefined;
|
|
1760
|
-
if (input) {
|
|
1761
|
-
var keysArray = util.asArray(input);
|
|
1762
|
-
var recipients = util.filterMaybeArrayValues(keysArray.map(function(key) {
|
|
1763
|
-
return recipientsMap.get(key);
|
|
1764
|
-
}));
|
|
1765
|
-
if (recipients.length > 0) {
|
|
1766
|
-
result = recipients;
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
return result;
|
|
1770
|
-
}
|
|
1771
|
-
return {
|
|
1772
|
-
recipientsMap: recipientsMap,
|
|
1773
|
-
getRecipientOrDefaultForKey: getRecipientOrDefaultForKey,
|
|
1774
|
-
getRecipientsForKeys: getRecipientsForKeys
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
exports.DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT = DEFAULT_MAILGUN_RECENT_EVENTS_LIMIT;
|
|
1779
|
-
exports.DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS = DEFAULT_MAILGUN_RECENT_EVENTS_WINDOW_DAYS;
|
|
1780
|
-
exports.DEFAULT_RECIPIENT_VARIABLE_PREFIX = DEFAULT_RECIPIENT_VARIABLE_PREFIX;
|
|
1781
|
-
exports.MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE;
|
|
1782
|
-
exports.MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY = MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY;
|
|
1783
|
-
exports.MAX_BATCH_SEND_RECIPIENTS = MAX_BATCH_SEND_RECIPIENTS;
|
|
1784
|
-
exports.bareMailgunMessageId = bareMailgunMessageId;
|
|
1785
|
-
exports.convertMailgunRecipientToString = convertMailgunRecipientToString;
|
|
1786
|
-
exports.convertMailgunRecipientsToStrings = convertMailgunRecipientsToStrings;
|
|
1787
|
-
exports.convertMailgunTemplateEmailRequestToMailgunMessageData = convertMailgunTemplateEmailRequestToMailgunMessageData;
|
|
1788
|
-
exports.encodeMailgunTemplateVariableValue = encodeMailgunTemplateVariableValue;
|
|
1789
|
-
exports.expandMailgunRecipientBatchSendTargetRequestFactory = expandMailgunRecipientBatchSendTargetRequestFactory;
|
|
1790
|
-
exports.hasAnyMailgunRecipientSuppression = hasAnyMailgunRecipientSuppression;
|
|
1791
|
-
exports.mailgunDomainEventAge = mailgunDomainEventAge;
|
|
1792
|
-
exports.mailgunDomainEventDate = mailgunDomainEventDate;
|
|
1793
|
-
exports.mailgunDomainEventFailureReason = mailgunDomainEventFailureReason;
|
|
1794
|
-
exports.mailgunDomainState = mailgunDomainState;
|
|
1795
|
-
exports.mailgunEventsForMessageId = mailgunEventsForMessageId;
|
|
1796
|
-
exports.mailgunEventsForQuery = mailgunEventsForQuery;
|
|
1797
|
-
exports.mailgunRecentEventsForRecipient = mailgunRecentEventsForRecipient;
|
|
1798
|
-
exports.mailgunRecipientBatchSendTargetEntityKeyRecipientLookup = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup;
|
|
1799
|
-
exports.mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey = mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey;
|
|
1800
|
-
exports.mailgunServiceConfigFactory = mailgunServiceConfigFactory;
|
|
1801
|
-
exports.mailgunSuppressionsForRecipient = mailgunSuppressionsForRecipient;
|
|
1802
|
-
exports.mailgunValidateEmail = mailgunValidateEmail;
|