@dereekb/nestjs 13.0.0 → 13.0.2

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.
@@ -18,173 +18,155 @@ const MAX_BATCH_SEND_RECIPIENTS = 1000;
18
18
  * @returns
19
19
  */
20
20
  function convertMailgunTemplateEmailRequestToMailgunMessageData(config) {
21
- const {
22
- request,
23
- defaultSender,
24
- isTestingEnvironment: testEnvironment,
25
- recipientVariablePrefix: inputRecipientVariablePrefix = DEFAULT_RECIPIENT_VARIABLE_PREFIX,
26
- addRecipientVariablePrefixToAllMergedGlobalVariables: inputAddRecipientVariablePrefixToAllMergedGlobalVariables = true,
27
- addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables: inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = false,
28
- addCopyOfTemplateVariablesWithRecipientVariablePrefix: inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix = false
29
- } = config;
30
- const {
31
- recipientVariablesConfig
32
- } = request;
33
- const recipientVariablePrefix = recipientVariablesConfig?.recipientVariablePrefix ?? inputRecipientVariablePrefix;
34
- const addRecipientVariablePrefixToAllMergedGlobalVariables = recipientVariablesConfig?.addRecipientVariablePrefixToAllMergedGlobalVariables ?? inputAddRecipientVariablePrefixToAllMergedGlobalVariables;
35
- const addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = recipientVariablesConfig?.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables ?? inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables;
36
- const addCopyOfTemplateVariablesWithRecipientVariablePrefix = recipientVariablesConfig?.addCopyOfTemplateVariablesWithRecipientVariablePrefix ?? inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix;
37
- const finalizeRecipientVariables = request.finalizeRecipientVariables ?? MAP_IDENTITY;
38
- const allowBatchSending = request.batchSend ?? true;
39
- const mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
40
- function mapEmailToLowercase(x) {
41
- return {
42
- ...x,
43
- email: x.email.toLowerCase()
21
+ const { request, defaultSender, isTestingEnvironment: testEnvironment, recipientVariablePrefix: inputRecipientVariablePrefix = DEFAULT_RECIPIENT_VARIABLE_PREFIX, addRecipientVariablePrefixToAllMergedGlobalVariables: inputAddRecipientVariablePrefixToAllMergedGlobalVariables = true, addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables: inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = false, addCopyOfTemplateVariablesWithRecipientVariablePrefix: inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix = false } = config;
22
+ const { recipientVariablesConfig } = request;
23
+ const recipientVariablePrefix = recipientVariablesConfig?.recipientVariablePrefix ?? inputRecipientVariablePrefix;
24
+ const addRecipientVariablePrefixToAllMergedGlobalVariables = recipientVariablesConfig?.addRecipientVariablePrefixToAllMergedGlobalVariables ?? inputAddRecipientVariablePrefixToAllMergedGlobalVariables;
25
+ const addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables = recipientVariablesConfig?.addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables ?? inputAddCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables;
26
+ const addCopyOfTemplateVariablesWithRecipientVariablePrefix = recipientVariablesConfig?.addCopyOfTemplateVariablesWithRecipientVariablePrefix ?? inputAddCopyOfTemplateVariablesWithRecipientVariablePrefix;
27
+ const finalizeRecipientVariables = request.finalizeRecipientVariables ?? MAP_IDENTITY;
28
+ const allowBatchSending = request.batchSend ?? true;
29
+ const mergeRecipientVariablesIntoGlobalVariable = !allowBatchSending;
30
+ function mapEmailToLowercase(x) {
31
+ return { ...x, email: x.email.toLowerCase() };
32
+ }
33
+ const toInput = asArray(request.to).map(mapEmailToLowercase);
34
+ const ccInput = request.cc ? asArray(request.cc).map(mapEmailToLowercase) : undefined;
35
+ const bccInput = request.bcc ? asArray(request.bcc).map(mapEmailToLowercase) : undefined;
36
+ const from = request.from ? convertMailgunRecipientToString(request.from) : defaultSender;
37
+ const to = convertMailgunRecipientsToStrings(toInput);
38
+ const cc = ccInput?.length ? convertMailgunRecipientsToStrings(ccInput) : undefined;
39
+ const bcc = bccInput?.length ? convertMailgunRecipientsToStrings(bccInput) : undefined;
40
+ // throw an error if batchSend is not defined and cc or bcc is defined
41
+ if (request.batchSend == null && (ccInput || bccInput)) {
42
+ throw new Error('convertMailgunTemplateEmailRequestToMailgunMessageData(): batchSend must be false when either "cc" or "bcc" is defined.');
43
+ }
44
+ if (allowBatchSending && to.length > MAX_BATCH_SEND_RECIPIENTS) {
45
+ throw new Error(`convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ${MAX_BATCH_SEND_RECIPIENTS} recipients.`);
46
+ }
47
+ const data = {
48
+ from,
49
+ to,
50
+ cc,
51
+ bcc,
52
+ subject: request.subject,
53
+ template: request.template,
54
+ ...request.messageData
44
55
  };
45
- }
46
- const toInput = asArray(request.to).map(mapEmailToLowercase);
47
- const ccInput = request.cc ? asArray(request.cc).map(mapEmailToLowercase) : undefined;
48
- const bccInput = request.bcc ? asArray(request.bcc).map(mapEmailToLowercase) : undefined;
49
- const from = request.from ? convertMailgunRecipientToString(request.from) : defaultSender;
50
- const to = convertMailgunRecipientsToStrings(toInput);
51
- const cc = ccInput?.length ? convertMailgunRecipientsToStrings(ccInput) : undefined;
52
- const bcc = bccInput?.length ? convertMailgunRecipientsToStrings(bccInput) : undefined;
53
- // throw an error if batchSend is not defined and cc or bcc is defined
54
- if (request.batchSend == null && (ccInput || bccInput)) {
55
- throw new Error('convertMailgunTemplateEmailRequestToMailgunMessageData(): batchSend must be false when either "cc" or "bcc" is defined.');
56
- }
57
- if (allowBatchSending && to.length > MAX_BATCH_SEND_RECIPIENTS) {
58
- throw new Error(`convertMailgunTemplateEmailRequestToMailgunMessageData(): Can only batch send to a maximum of ${MAX_BATCH_SEND_RECIPIENTS} recipients.`);
59
- }
60
- const data = {
61
- from,
62
- to,
63
- cc,
64
- bcc,
65
- subject: request.subject,
66
- template: request.template,
67
- ...request.messageData
68
- };
69
- if (request.replyTo != null) {
70
- data[MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY] = convertMailgunRecipientToString(request.replyTo);
71
- }
72
- if (request.testEmail === true || (testEnvironment ?? isTestNodeEnv()) && request.testEmail !== false) {
73
- data['o:testmode'] = true;
74
- }
75
- if (request.templateVariables) {
76
- forEachKeyValue(request.templateVariables, {
77
- forEach: x => {
78
- const [key, value] = x;
79
- const encodedValue = encodeMailgunTemplateVariableValue(value);
80
- if (encodedValue != null) {
81
- data[`v:${key}`] = encodedValue;
82
- if (recipientVariablePrefix && addCopyOfTemplateVariablesWithRecipientVariablePrefix) {
83
- data[`v:${recipientVariablePrefix}${key}`] = encodedValue;
84
- }
85
- }
86
- }
87
- });
88
- }
89
- const hasUserVariables = Boolean(data['recipient-variables']) || toInput.findIndex(x => x.userVariables != null) !== -1;
90
- if (hasUserVariables) {
91
- let recipientVariables = {};
92
- const allRecipientVariableKeys = new Set();
93
- toInput.forEach(({
94
- email,
95
- userVariables
96
- }) => {
97
- if (userVariables != null && !objectIsEmpty(userVariables)) {
98
- recipientVariables[email] = userVariables;
99
- addToSet(allRecipientVariableKeys, Object.keys(userVariables));
100
- }
101
- });
102
- if (data['recipient-variables']) {
103
- const decoded = JSON.parse(data['recipient-variables']);
104
- forEachKeyValue(decoded, {
105
- forEach: x => {
106
- const [recipientEmail, userVariables] = x;
107
- const email = recipientEmail.toLowerCase();
108
- if (recipientVariables[email] != null) {
109
- overrideInObject(recipientVariables[email], {
110
- from: [userVariables],
111
- filter: {
112
- valueFilter: KeyValueTypleValueFilter.UNDEFINED
113
- }
114
- });
115
- } else {
116
- recipientVariables[email] = userVariables;
117
- }
118
- addToSet(allRecipientVariableKeys, Object.keys(userVariables));
119
- }
120
- });
56
+ if (request.replyTo != null) {
57
+ data[MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY] = convertMailgunRecipientToString(request.replyTo);
121
58
  }
122
- // Finalize the recipient variables before they are re-encoded back to JSON
123
- recipientVariables = finalizeRecipientVariables(recipientVariables, {
124
- messageData: data,
125
- config
126
- }) ?? recipientVariables;
127
- if (mergeRecipientVariablesIntoGlobalVariable) {
128
- const addRecipientPrefixVariable = recipientVariablePrefix && addRecipientVariablePrefixToAllMergedGlobalVariables;
129
- // iterate all recipient variables and merge them into the global variables
130
- forEachKeyValue(recipientVariables, {
131
- forEach: x => {
132
- const [email, userVariables] = x;
133
- forEachKeyValue(userVariables, {
134
- forEach: y => {
135
- const [key, value] = y;
136
- const encodedValue = encodeMailgunTemplateVariableValue(value);
137
- if (encodedValue != null) {
138
- if (addRecipientPrefixVariable) {
139
- // also add the variable using the recipient variable prefix
140
- const recipientVariableKey = `${recipientVariablePrefix}${key}`;
141
- data[`v:${recipientVariableKey}`] = encodedValue;
59
+ if (request.testEmail === true || ((testEnvironment ?? isTestNodeEnv()) && request.testEmail !== false)) {
60
+ data['o:testmode'] = true;
61
+ }
62
+ if (request.templateVariables) {
63
+ forEachKeyValue(request.templateVariables, {
64
+ forEach: (x) => {
65
+ const [key, value] = x;
66
+ const encodedValue = encodeMailgunTemplateVariableValue(value);
67
+ if (encodedValue != null) {
68
+ data[`v:${key}`] = encodedValue;
69
+ if (recipientVariablePrefix && addCopyOfTemplateVariablesWithRecipientVariablePrefix) {
70
+ data[`v:${recipientVariablePrefix}${key}`] = encodedValue;
71
+ }
72
+ }
73
+ }
74
+ });
75
+ }
76
+ const hasUserVariables = Boolean(data['recipient-variables']) || toInput.findIndex((x) => x.userVariables != null) !== -1;
77
+ if (hasUserVariables) {
78
+ let recipientVariables = {};
79
+ const allRecipientVariableKeys = new Set();
80
+ toInput.forEach(({ email, userVariables }) => {
81
+ if (userVariables != null && !objectIsEmpty(userVariables)) {
82
+ recipientVariables[email] = userVariables;
83
+ addToSet(allRecipientVariableKeys, Object.keys(userVariables));
84
+ }
85
+ });
86
+ if (data['recipient-variables']) {
87
+ const decoded = JSON.parse(data['recipient-variables']);
88
+ forEachKeyValue(decoded, {
89
+ forEach: (x) => {
90
+ const [recipientEmail, userVariables] = x;
91
+ const email = recipientEmail.toLowerCase();
92
+ if (recipientVariables[email] != null) {
93
+ overrideInObject(recipientVariables[email], { from: [userVariables], filter: { valueFilter: KeyValueTypleValueFilter.UNDEFINED } });
94
+ }
95
+ else {
96
+ recipientVariables[email] = userVariables;
97
+ }
98
+ addToSet(allRecipientVariableKeys, Object.keys(userVariables));
142
99
  }
143
- // add if not adding the prefix variable, or if it was requested
144
- if (!addRecipientPrefixVariable || addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) {
145
- data[`v:${key}`] = encodedValue;
100
+ });
101
+ }
102
+ // Finalize the recipient variables before they are re-encoded back to JSON
103
+ recipientVariables =
104
+ finalizeRecipientVariables(recipientVariables, {
105
+ messageData: data,
106
+ config
107
+ }) ?? recipientVariables;
108
+ if (mergeRecipientVariablesIntoGlobalVariable) {
109
+ const addRecipientPrefixVariable = recipientVariablePrefix && addRecipientVariablePrefixToAllMergedGlobalVariables;
110
+ // iterate all recipient variables and merge them into the global variables
111
+ forEachKeyValue(recipientVariables, {
112
+ forEach: (x) => {
113
+ const [email, userVariables] = x;
114
+ forEachKeyValue(userVariables, {
115
+ forEach: (y) => {
116
+ const [key, value] = y;
117
+ const encodedValue = encodeMailgunTemplateVariableValue(value);
118
+ if (encodedValue != null) {
119
+ if (addRecipientPrefixVariable) {
120
+ // also add the variable using the recipient variable prefix
121
+ const recipientVariableKey = `${recipientVariablePrefix}${key}`;
122
+ data[`v:${recipientVariableKey}`] = encodedValue;
123
+ }
124
+ // add if not adding the prefix variable, or if it was requested
125
+ if (!addRecipientPrefixVariable || addCopyOfMergedRecipientVariablesWithoutPrefixToGlobalVariables) {
126
+ data[`v:${key}`] = encodedValue;
127
+ }
128
+ }
129
+ }
130
+ });
146
131
  }
147
- }
132
+ });
133
+ }
134
+ else {
135
+ // set back on the data object
136
+ data['recipient-variables'] = JSON.stringify(recipientVariables);
137
+ // add all recipient variable to the other variables so they can be used easily/directly in templates as variables too.
138
+ // https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages
139
+ if (recipientVariablePrefix) {
140
+ forEachInIterable(allRecipientVariableKeys, (key) => {
141
+ const recipientVariableKey = `${recipientVariablePrefix}${key}`;
142
+ // v:recipient-id=%recipient.id%
143
+ data[`v:${recipientVariableKey}`] = `%recipient.${key}%`;
144
+ });
148
145
  }
149
- });
150
146
  }
151
- });
152
- } else {
153
- // set back on the data object
154
- data['recipient-variables'] = JSON.stringify(recipientVariables);
155
- // add all recipient variable to the other variables so they can be used easily/directly in templates as variables too.
156
- // https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages
157
- if (recipientVariablePrefix) {
158
- forEachInIterable(allRecipientVariableKeys, key => {
159
- const recipientVariableKey = `${recipientVariablePrefix}${key}`;
160
- // v:recipient-id=%recipient.id%
161
- data[`v:${recipientVariableKey}`] = `%recipient.${key}%`;
162
- });
163
- }
164
147
  }
165
- }
166
- // double check and remove the recipient variables if we merged them into the global variables
167
- if (mergeRecipientVariablesIntoGlobalVariable) {
168
- delete data['recipient-variables'];
169
- }
170
- const inputAttachments = request.attachments;
171
- if (inputAttachments) {
172
- if (data.attachment) {
173
- throw new Error(`Cannot specify attachments in both messageData and in the request's attachments field.`);
148
+ // double check and remove the recipient variables if we merged them into the global variables
149
+ if (mergeRecipientVariablesIntoGlobalVariable) {
150
+ delete data['recipient-variables'];
151
+ }
152
+ const inputAttachments = request.attachments;
153
+ if (inputAttachments) {
154
+ if (data.attachment) {
155
+ throw new Error(`Cannot specify attachments in both messageData and in the request's attachments field.`);
156
+ }
157
+ data.attachment = inputAttachments;
174
158
  }
175
- data.attachment = inputAttachments;
176
- }
177
- return data;
159
+ return data;
178
160
  }
179
161
  function convertMailgunRecipientsToStrings(recipients) {
180
- return recipients.map(x => convertMailgunRecipientToString(x));
162
+ return recipients.map((x) => convertMailgunRecipientToString(x));
181
163
  }
182
164
  function convertMailgunRecipientToString(recipient) {
183
- let address = recipient.email;
184
- if (recipient.name) {
185
- address = `${recipient.name} <${address}>`;
186
- }
187
- return address;
165
+ let address = recipient.email;
166
+ if (recipient.name) {
167
+ address = `${recipient.name} <${address}>`;
168
+ }
169
+ return address;
188
170
  }
189
171
  /**
190
172
  * Encodes a value to a string for use as a Mailgun template variable. Throws an error if the value is not supported.
@@ -193,29 +175,30 @@ function convertMailgunRecipientToString(recipient) {
193
175
  * @returns The encoded value, or undefined if the value is null or undefined.
194
176
  */
195
177
  function encodeMailgunTemplateVariableValue(value) {
196
- let encodedValue;
197
- switch (typeof value) {
198
- case 'object':
199
- if (value) {
200
- if (value instanceof Date) {
201
- encodedValue = value.toISOString();
202
- } else {
203
- encodedValue = JSON.stringify(value);
204
- }
205
- }
206
- break;
207
- case 'bigint':
208
- case 'boolean':
209
- case 'number':
210
- case 'string':
211
- encodedValue = String(value); // encoded as a string value
212
- break;
213
- default:
214
- if (value) {
215
- throw new Error(`Invalid value "${value}" passed to encodeMailgunTemplateVariableValue().`);
216
- }
217
- }
218
- return encodedValue;
178
+ let encodedValue;
179
+ switch (typeof value) {
180
+ case 'object':
181
+ if (value) {
182
+ if (value instanceof Date) {
183
+ encodedValue = value.toISOString();
184
+ }
185
+ else {
186
+ encodedValue = JSON.stringify(value);
187
+ }
188
+ }
189
+ break;
190
+ case 'bigint':
191
+ case 'boolean':
192
+ case 'number':
193
+ case 'string':
194
+ encodedValue = String(value); // encoded as a string value
195
+ break;
196
+ default:
197
+ if (value) {
198
+ throw new Error(`Invalid value "${value}" passed to encodeMailgunTemplateVariableValue().`);
199
+ }
200
+ }
201
+ return encodedValue;
219
202
  }
220
203
 
221
204
  /******************************************************************************
@@ -256,170 +239,190 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
256
239
  };
257
240
 
258
241
  class MailgunServiceConfig {
259
- // Mailgun Config
260
- mailgun;
261
- /**
262
- * Base URL to the client.
263
- */
264
- clientUrl;
265
- /**
266
- * Main domain to send emails from.
267
- */
268
- domain;
269
- /**
270
- * Mailgun sender string.
271
- */
272
- sender;
273
- /**
274
- * Additional messages config
275
- */
276
- messages;
277
- static assertValidConfig(config) {
278
- if (!config.mailgun.username) {
279
- throw new Error('No mailgun username specified.');
280
- } else if (!config.mailgun.key) {
281
- throw new Error('No mailgun key specified.');
282
- } else if (!config.domain) {
283
- throw new Error('No mailgun domain specified.');
284
- } else if (!config.clientUrl) {
285
- throw new Error('No client url specified.');
286
- } else if (!config.sender) {
287
- throw new Error('No mailgun sender specified.');
288
- } else if (!config.messages) {
289
- throw new Error('No mailgun messages config specified.');
242
+ // Mailgun Config
243
+ mailgun;
244
+ /**
245
+ * Base URL to the client.
246
+ */
247
+ clientUrl;
248
+ /**
249
+ * Main domain to send emails from.
250
+ */
251
+ domain;
252
+ /**
253
+ * Mailgun sender string.
254
+ */
255
+ sender;
256
+ /**
257
+ * Additional messages config
258
+ */
259
+ messages;
260
+ static assertValidConfig(config) {
261
+ if (!config.mailgun.username) {
262
+ throw new Error('No mailgun username specified.');
263
+ }
264
+ else if (!config.mailgun.key) {
265
+ throw new Error('No mailgun key specified.');
266
+ }
267
+ else if (!config.domain) {
268
+ throw new Error('No mailgun domain specified.');
269
+ }
270
+ else if (!config.clientUrl) {
271
+ throw new Error('No client url specified.');
272
+ }
273
+ else if (!config.sender) {
274
+ throw new Error('No mailgun sender specified.');
275
+ }
276
+ else if (!config.messages) {
277
+ throw new Error('No mailgun messages config specified.');
278
+ }
290
279
  }
291
- }
292
280
  }
293
281
 
294
282
  let MailgunApi = class MailgunApi {
295
- config;
296
- client;
297
- constructor(config) {
298
- this.config = config;
299
- this.client = new Mailgun(FormData).client({
300
- ...config.mailgun
301
- });
302
- }
303
- get messages() {
304
- return this.client.messages;
305
- }
306
- get clientUrl() {
307
- return this.config.clientUrl;
308
- }
309
- get domain() {
310
- return this.config.domain;
311
- }
312
- get sender() {
313
- return this.config.sender;
314
- }
283
+ config;
284
+ client;
285
+ constructor(config) {
286
+ this.config = config;
287
+ this.client = new Mailgun(FormData).client({
288
+ ...config.mailgun
289
+ });
290
+ }
291
+ get messages() {
292
+ return this.client.messages;
293
+ }
294
+ get clientUrl() {
295
+ return this.config.clientUrl;
296
+ }
297
+ get domain() {
298
+ return this.config.domain;
299
+ }
300
+ get sender() {
301
+ return this.config.sender;
302
+ }
315
303
  };
316
- MailgunApi = __decorate([Injectable(), __param(0, Inject(MailgunServiceConfig)), __metadata("design:paramtypes", [MailgunServiceConfig])], MailgunApi);
304
+ MailgunApi = __decorate([
305
+ Injectable(),
306
+ __param(0, Inject(MailgunServiceConfig)),
307
+ __metadata("design:paramtypes", [MailgunServiceConfig])
308
+ ], MailgunApi);
317
309
 
318
310
  let MailgunService = class MailgunService {
319
- _mailgunApi;
320
- _serverEnvironmentService;
321
- constructor(mailgunApi, serverEnvironmentService) {
322
- this._mailgunApi = mailgunApi;
323
- this._serverEnvironmentService = serverEnvironmentService;
324
- }
325
- get mailgunApi() {
326
- return this._mailgunApi;
327
- }
328
- get serverEnvironmentService() {
329
- return this._serverEnvironmentService;
330
- }
331
- async sendTemplateEmail(request) {
332
- const domain = this.mailgunApi.domain;
333
- const sender = this.mailgunApi.sender;
334
- const isTestingEnvironment = this.serverEnvironmentService.isTestingEnv;
335
- const {
336
- recipientVariablePrefix
337
- } = this.mailgunApi.config.messages;
338
- const data = convertMailgunTemplateEmailRequestToMailgunMessageData({
339
- request,
340
- defaultSender: sender,
341
- recipientVariablePrefix,
342
- isTestingEnvironment
343
- });
344
- let result;
345
- const shouldSend = !isTestingEnvironment || request.sendTestEmails || this.mailgunApi.config.messages.sendTestEmails;
346
- if (shouldSend) {
347
- try {
348
- result = await this.mailgunApi.messages.create(domain, data);
349
- } catch (e) {
350
- console.error('Failed sending email: ', e);
351
- throw e;
352
- }
353
- } else {
354
- result = {
355
- status: 200,
356
- message: 'Success. Env prevented sending email.'
357
- };
311
+ _mailgunApi;
312
+ _serverEnvironmentService;
313
+ constructor(mailgunApi, serverEnvironmentService) {
314
+ this._mailgunApi = mailgunApi;
315
+ this._serverEnvironmentService = serverEnvironmentService;
316
+ }
317
+ get mailgunApi() {
318
+ return this._mailgunApi;
319
+ }
320
+ get serverEnvironmentService() {
321
+ return this._serverEnvironmentService;
322
+ }
323
+ async sendTemplateEmail(request) {
324
+ const domain = this.mailgunApi.domain;
325
+ const sender = this.mailgunApi.sender;
326
+ const isTestingEnvironment = this.serverEnvironmentService.isTestingEnv;
327
+ const { recipientVariablePrefix } = this.mailgunApi.config.messages;
328
+ const data = convertMailgunTemplateEmailRequestToMailgunMessageData({ request, defaultSender: sender, recipientVariablePrefix, isTestingEnvironment });
329
+ let result;
330
+ const shouldSend = !isTestingEnvironment || request.sendTestEmails || this.mailgunApi.config.messages.sendTestEmails;
331
+ if (shouldSend) {
332
+ try {
333
+ result = await this.mailgunApi.messages.create(domain, data);
334
+ }
335
+ catch (e) {
336
+ console.error('Failed sending email: ', e);
337
+ throw e;
338
+ }
339
+ }
340
+ else {
341
+ result = {
342
+ status: 200,
343
+ message: 'Success. Env prevented sending email.'
344
+ };
345
+ }
346
+ return result;
358
347
  }
359
- return result;
360
- }
361
348
  };
362
- MailgunService = __decorate([Injectable(), __param(0, Inject(MailgunApi)), __param(1, Inject(ServerEnvironmentService)), __metadata("design:paramtypes", [MailgunApi, ServerEnvironmentService])], MailgunService);
349
+ MailgunService = __decorate([
350
+ Injectable(),
351
+ __param(0, Inject(MailgunApi)),
352
+ __param(1, Inject(ServerEnvironmentService)),
353
+ __metadata("design:paramtypes", [MailgunApi, ServerEnvironmentService])
354
+ ], MailgunService);
363
355
 
364
356
  function mailgunServiceConfigFactory(configService, serverEnvironmentService) {
365
- const isTestingEnv = serverEnvironmentService.isTestingEnv;
366
- const useSandbox = configService.get('USE_MAILGUN_SANDBOX') === 'true' || isTestingEnv;
367
- const sendTestEmails = configService.get('MAILGUN_SEND_TEST_EMAILS') === 'true';
368
- let key = configService.get('MAILGUN_API_KEY');
369
- let domain = configService.get('MAILGUN_DOMAIN');
370
- if (useSandbox) {
371
- key = configService.get('MAILGUN_SANDBOX_API_KEY');
372
- domain = configService.get('MAILGUN_SANDBOX_DOMAIN');
373
- if (!key || !domain) {
374
- 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.');
375
- } else if (!serverEnvironmentService.isTestingEnv) {
376
- console.log('Using Mailgun Sandbox Domain: ', domain);
357
+ const isTestingEnv = serverEnvironmentService.isTestingEnv;
358
+ const useSandbox = configService.get('USE_MAILGUN_SANDBOX') === 'true' || isTestingEnv;
359
+ const sendTestEmails = configService.get('MAILGUN_SEND_TEST_EMAILS') === 'true';
360
+ let key = configService.get('MAILGUN_API_KEY');
361
+ let domain = configService.get('MAILGUN_DOMAIN');
362
+ if (useSandbox) {
363
+ key = configService.get('MAILGUN_SANDBOX_API_KEY');
364
+ domain = configService.get('MAILGUN_SANDBOX_DOMAIN');
365
+ if (!key || !domain) {
366
+ 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.');
367
+ }
368
+ else if (!serverEnvironmentService.isTestingEnv) {
369
+ console.log('Using Mailgun Sandbox Domain: ', domain);
370
+ }
371
+ }
372
+ else if (!serverEnvironmentService.isTestingEnv) {
373
+ console.log('Using Mailgun Production Domain: ', domain);
374
+ }
375
+ const name = configService.get('MAILGUN_SENDER_NAME');
376
+ const email = configService.get('MAILGUN_SENDER_EMAIL');
377
+ const url = configService.get('MAILGUN_API_URL');
378
+ const recipientVariablePrefix = configService.get('MAILGUN_MESSAGES_RECIPIENT_VARIABLE_PREFIX') ?? undefined;
379
+ if (!email) {
380
+ throw new Error('MAILGUN_SENDER_EMAIL is required but was not configured.');
377
381
  }
378
- } else if (!serverEnvironmentService.isTestingEnv) {
379
- console.log('Using Mailgun Production Domain: ', domain);
380
- }
381
- const name = configService.get('MAILGUN_SENDER_NAME');
382
- const email = configService.get('MAILGUN_SENDER_EMAIL');
383
- const url = configService.get('MAILGUN_API_URL');
384
- const recipientVariablePrefix = configService.get('MAILGUN_MESSAGES_RECIPIENT_VARIABLE_PREFIX') ?? undefined;
385
- if (!email) {
386
- throw new Error('MAILGUN_SENDER_EMAIL is required but was not configured.');
387
- } else if (!key) {
388
- throw new Error('MAILGUN_API_KEY (or MAILGUN_SANDBOX_API_KEY for tests) is required but was not configured.');
389
- } else if (!domain) {
390
- throw new Error('MAILGUN_DOMAIN (or MAILGUN_SANDBOX_DOMAIN for tests) is required but was not configured.');
391
- }
392
- const clientUrl = configService.get('CLIENT_APP_URL') ?? domain;
393
- const config = {
394
- mailgun: {
395
- username: configService.get('MAILGUN_USERNAME') ?? 'api',
396
- key,
397
- url
398
- },
399
- domain,
400
- clientUrl,
401
- sender: convertMailgunRecipientToString({
402
- name,
403
- email
404
- }),
405
- messages: {
406
- sendTestEmails,
407
- recipientVariablePrefix
382
+ else if (!key) {
383
+ throw new Error('MAILGUN_API_KEY (or MAILGUN_SANDBOX_API_KEY for tests) is required but was not configured.');
408
384
  }
409
- };
410
- MailgunServiceConfig.assertValidConfig(config);
411
- return config;
385
+ else if (!domain) {
386
+ throw new Error('MAILGUN_DOMAIN (or MAILGUN_SANDBOX_DOMAIN for tests) is required but was not configured.');
387
+ }
388
+ const clientUrl = configService.get('CLIENT_APP_URL') ?? domain;
389
+ const config = {
390
+ mailgun: {
391
+ username: configService.get('MAILGUN_USERNAME') ?? 'api',
392
+ key,
393
+ url
394
+ },
395
+ domain,
396
+ clientUrl,
397
+ sender: convertMailgunRecipientToString({
398
+ name,
399
+ email
400
+ }),
401
+ messages: {
402
+ sendTestEmails,
403
+ recipientVariablePrefix
404
+ }
405
+ };
406
+ MailgunServiceConfig.assertValidConfig(config);
407
+ return config;
412
408
  }
413
- let MailgunServiceModule = class MailgunServiceModule {};
414
- MailgunServiceModule = __decorate([Module({
415
- imports: [ConfigModule],
416
- providers: [{
417
- provide: MailgunServiceConfig,
418
- inject: [ConfigService, ServerEnvironmentService],
419
- useFactory: mailgunServiceConfigFactory
420
- }, MailgunApi, MailgunService],
421
- exports: [MailgunApi, MailgunService]
422
- })], MailgunServiceModule);
409
+ let MailgunServiceModule = class MailgunServiceModule {
410
+ };
411
+ MailgunServiceModule = __decorate([
412
+ Module({
413
+ imports: [ConfigModule],
414
+ providers: [
415
+ {
416
+ provide: MailgunServiceConfig,
417
+ inject: [ConfigService, ServerEnvironmentService],
418
+ useFactory: mailgunServiceConfigFactory
419
+ },
420
+ MailgunApi,
421
+ MailgunService
422
+ ],
423
+ exports: [MailgunApi, MailgunService]
424
+ })
425
+ ], MailgunServiceModule);
423
426
 
424
427
  /**
425
428
  * The default template subject to use when batch sending emails.
@@ -431,9 +434,9 @@ const MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE = `%recipient.subject%`;
431
434
  * Creates a composite key from the from/replyTo email addresses used to group MailgunRecipientBatchSendTarget values.
432
435
  */
433
436
  function mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey(recipient) {
434
- const fromEmail = (recipient.from?.email ?? '').toLowerCase();
435
- const replyToEmail = (recipient.replyTo?.email ?? '').toLowerCase();
436
- return `f:${fromEmail}|r:${replyToEmail}`;
437
+ const fromEmail = (recipient.from?.email ?? '').toLowerCase();
438
+ const replyToEmail = (recipient.replyTo?.email ?? '').toLowerCase();
439
+ return `f:${fromEmail}|r:${replyToEmail}`;
437
440
  }
438
441
  /**
439
442
  * Creates a ExpandMailgunRecipientBatchSendTargetRequestFactory from the input config.
@@ -442,158 +445,150 @@ function mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey(recipient) {
442
445
  * @returns
443
446
  */
444
447
  function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
445
- const {
446
- request: inputBaseRequest,
447
- useSubjectFromRecipientUserVariables,
448
- allowSingleRecipientBatchSendRequests,
449
- recipientVariablesConfig,
450
- mailgunRecipientBatchSendTargetEntityKeyRecipientLookup,
451
- overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients
452
- } = config;
453
- const defaultSubject = inputBaseRequest.subject;
454
- if (!defaultSubject && !useSubjectFromRecipientUserVariables) {
455
- throw new Error('defaultSubject must be set when "useSubjectFromRecipientUserVariables" is false');
456
- }
457
- /**
458
- * Returns the carbon copy recipients, based on the input.
459
- *
460
- * Will return undefined if the array would be empty.
461
- *
462
- * @param input
463
- * @returns
464
- */
465
- function determineCarbonCopyRecipients(input) {
466
- const {
467
- baseRequestCarbonCopyRecipients,
468
- carbonCopyRecipients,
469
- carbonCopyRecipientsKeys
470
- } = input;
471
- let cc = carbonCopyRecipients ? asArray(carbonCopyRecipients) : baseRequestCarbonCopyRecipients;
472
- const resolvedCc = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientsForKeys(carbonCopyRecipientsKeys);
473
- if (resolvedCc?.length) {
474
- if (overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients) {
475
- cc = resolvedCc;
476
- } else {
477
- cc = [...(cc ?? []), ...resolvedCc];
478
- }
448
+ const { request: inputBaseRequest, useSubjectFromRecipientUserVariables, allowSingleRecipientBatchSendRequests, recipientVariablesConfig, mailgunRecipientBatchSendTargetEntityKeyRecipientLookup, overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients } = config;
449
+ const defaultSubject = inputBaseRequest.subject;
450
+ if (!defaultSubject && !useSubjectFromRecipientUserVariables) {
451
+ throw new Error('defaultSubject must be set when "useSubjectFromRecipientUserVariables" is false');
479
452
  }
480
- return cc?.length ? cc : undefined;
481
- }
482
- const baseRequestCc = determineCarbonCopyRecipients({
483
- carbonCopyRecipients: inputBaseRequest.cc,
484
- carbonCopyRecipientsKeys: inputBaseRequest.ccKeys
485
- });
486
- const baseRequestBcc = determineCarbonCopyRecipients({
487
- carbonCopyRecipients: inputBaseRequest.bcc,
488
- carbonCopyRecipientsKeys: inputBaseRequest.bccKeys
489
- });
490
- const baseRequestFrom = inputBaseRequest.from ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.fromKey);
491
- const baseRequestReplyTo = inputBaseRequest.replyTo ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.replyToKey);
492
- const baseRequest = {
493
- ...inputBaseRequest,
494
- from: baseRequestFrom,
495
- replyTo: baseRequestReplyTo,
496
- cc: baseRequestCc,
497
- bcc: baseRequestBcc
498
- };
499
- delete baseRequest.fromKey;
500
- delete baseRequest.replyToKey;
501
- delete baseRequest.ccKeys;
502
- delete baseRequest.bccKeys;
503
- const configAllowBatchSend = baseRequest.batchSend !== false;
504
- return inputRecipients => {
505
- // Process recipients to resolve keys
506
- const recipients = inputRecipients.map(recipient => {
507
- let from = recipient.from;
508
- let replyTo = recipient.replyTo;
509
- if (mailgunRecipientBatchSendTargetEntityKeyRecipientLookup) {
510
- // try the fromKey, otherwise use the baseRequest.from
511
- if (!from) {
512
- from = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.fromKey, baseRequest.from);
513
- }
514
- // try the replyToKey, otherwise use the baseRequest.replyTo
515
- if (!replyTo) {
516
- replyTo = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.replyToKey, baseRequest.replyTo);
517
- }
518
- } else {
519
- // use defaults from base request
520
- if (!from) {
521
- from = baseRequest.from;
522
- }
523
- if (!replyTo) {
524
- replyTo = baseRequest.replyTo;
453
+ /**
454
+ * Returns the carbon copy recipients, based on the input.
455
+ *
456
+ * Will return undefined if the array would be empty.
457
+ *
458
+ * @param input
459
+ * @returns
460
+ */
461
+ function determineCarbonCopyRecipients(input) {
462
+ const { baseRequestCarbonCopyRecipients, carbonCopyRecipients, carbonCopyRecipientsKeys } = input;
463
+ let cc = carbonCopyRecipients ? asArray(carbonCopyRecipients) : baseRequestCarbonCopyRecipients;
464
+ const resolvedCc = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientsForKeys(carbonCopyRecipientsKeys);
465
+ if (resolvedCc?.length) {
466
+ if (overrideCarbonCopyVariablesWithCarbonCopyKeyRecipients) {
467
+ cc = resolvedCc;
468
+ }
469
+ else {
470
+ cc = [...(cc ?? []), ...resolvedCc];
471
+ }
525
472
  }
526
- }
527
- const cc = determineCarbonCopyRecipients({
528
- baseRequestCarbonCopyRecipients: baseRequestCc,
529
- carbonCopyRecipients: recipient.cc,
530
- carbonCopyRecipientsKeys: recipient.ccKeys
531
- });
532
- const bcc = determineCarbonCopyRecipients({
533
- baseRequestCarbonCopyRecipients: baseRequestBcc,
534
- carbonCopyRecipients: recipient.bcc,
535
- carbonCopyRecipientsKeys: recipient.bccKeys
536
- });
537
- const result = {
538
- ...recipient,
539
- from,
540
- replyTo,
541
- cc,
542
- bcc
543
- };
544
- return result;
473
+ return cc?.length ? cc : undefined;
474
+ }
475
+ const baseRequestCc = determineCarbonCopyRecipients({
476
+ carbonCopyRecipients: inputBaseRequest.cc,
477
+ carbonCopyRecipientsKeys: inputBaseRequest.ccKeys
545
478
  });
546
- const allowBatchSend = configAllowBatchSend && (allowSingleRecipientBatchSendRequests || recipients.length > 1);
547
- const nonBatchSendRequests = [];
548
- const batchSendRequestRecipients = [];
549
- recipients.forEach(recipient => {
550
- const recipientHasCarbonCopy = Boolean(recipient.cc?.length || recipient.bcc?.length);
551
- if (allowBatchSend && !recipientHasCarbonCopy) {
552
- // add to batch send recipients
553
- batchSendRequestRecipients.push(recipient);
554
- } else {
555
- // add to non-batch send requests
556
- // use the subject from the recipient's user variables if available as a default
557
- const cc = recipient.cc;
558
- const bcc = recipient.bcc;
559
- const subject = (useSubjectFromRecipientUserVariables ? recipient.userVariables?.['subject'] : undefined) ?? defaultSubject ?? recipient.userVariables?.['subject'];
560
- const request = {
561
- ...baseRequest,
562
- from: recipient.from ?? baseRequest.from,
563
- replyTo: recipient.replyTo ?? baseRequest.replyTo,
564
- recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
565
- to: recipient,
566
- cc,
567
- bcc,
568
- subject,
569
- batchSend: false // explicitly disable batch send for non-batch requests
570
- };
571
- nonBatchSendRequests.push(request);
572
- }
479
+ const baseRequestBcc = determineCarbonCopyRecipients({
480
+ carbonCopyRecipients: inputBaseRequest.bcc,
481
+ carbonCopyRecipientsKeys: inputBaseRequest.bccKeys
573
482
  });
574
- // create batch send request(s)
575
- const batchSendRequests = [];
576
- if (batchSendRequestRecipients.length > 0) {
577
- const subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
578
- // Group recipients by their from/replyTo values
579
- const batchSendRecipientGroups = makeValuesGroupMap(batchSendRequestRecipients, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey);
580
- batchSendRecipientGroups.forEach(groupRecipients => {
581
- // All recipients in this group should share the same from/replyTo values
582
- const firstRecipient = groupRecipients[0];
583
- const batchRequest = {
584
- ...baseRequest,
585
- from: firstRecipient.from,
586
- replyTo: firstRecipient.replyTo,
587
- recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
588
- to: groupRecipients,
589
- subject,
590
- batchSend: true
591
- };
592
- batchSendRequests.push(batchRequest);
593
- });
594
- }
595
- return filterMaybeArrayValues([...batchSendRequests, ...nonBatchSendRequests]);
596
- };
483
+ const baseRequestFrom = inputBaseRequest.from ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.fromKey);
484
+ const baseRequestReplyTo = inputBaseRequest.replyTo ?? mailgunRecipientBatchSendTargetEntityKeyRecipientLookup?.getRecipientOrDefaultForKey(inputBaseRequest.replyToKey);
485
+ const baseRequest = {
486
+ ...inputBaseRequest,
487
+ from: baseRequestFrom,
488
+ replyTo: baseRequestReplyTo,
489
+ cc: baseRequestCc,
490
+ bcc: baseRequestBcc
491
+ };
492
+ delete baseRequest.fromKey;
493
+ delete baseRequest.replyToKey;
494
+ delete baseRequest.ccKeys;
495
+ delete baseRequest.bccKeys;
496
+ const configAllowBatchSend = baseRequest.batchSend !== false;
497
+ return (inputRecipients) => {
498
+ // Process recipients to resolve keys
499
+ const recipients = inputRecipients.map((recipient) => {
500
+ let from = recipient.from;
501
+ let replyTo = recipient.replyTo;
502
+ if (mailgunRecipientBatchSendTargetEntityKeyRecipientLookup) {
503
+ // try the fromKey, otherwise use the baseRequest.from
504
+ if (!from) {
505
+ from = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.fromKey, baseRequest.from);
506
+ }
507
+ // try the replyToKey, otherwise use the baseRequest.replyTo
508
+ if (!replyTo) {
509
+ replyTo = mailgunRecipientBatchSendTargetEntityKeyRecipientLookup.getRecipientOrDefaultForKey(recipient.replyToKey, baseRequest.replyTo);
510
+ }
511
+ }
512
+ else {
513
+ // use defaults from base request
514
+ if (!from) {
515
+ from = baseRequest.from;
516
+ }
517
+ if (!replyTo) {
518
+ replyTo = baseRequest.replyTo;
519
+ }
520
+ }
521
+ const cc = determineCarbonCopyRecipients({
522
+ baseRequestCarbonCopyRecipients: baseRequestCc,
523
+ carbonCopyRecipients: recipient.cc,
524
+ carbonCopyRecipientsKeys: recipient.ccKeys
525
+ });
526
+ const bcc = determineCarbonCopyRecipients({
527
+ baseRequestCarbonCopyRecipients: baseRequestBcc,
528
+ carbonCopyRecipients: recipient.bcc,
529
+ carbonCopyRecipientsKeys: recipient.bccKeys
530
+ });
531
+ const result = {
532
+ ...recipient,
533
+ from,
534
+ replyTo,
535
+ cc,
536
+ bcc
537
+ };
538
+ return result;
539
+ });
540
+ const allowBatchSend = configAllowBatchSend && (allowSingleRecipientBatchSendRequests || recipients.length > 1);
541
+ const nonBatchSendRequests = [];
542
+ const batchSendRequestRecipients = [];
543
+ recipients.forEach((recipient) => {
544
+ const recipientHasCarbonCopy = Boolean(recipient.cc?.length || recipient.bcc?.length);
545
+ if (allowBatchSend && !recipientHasCarbonCopy) {
546
+ // add to batch send recipients
547
+ batchSendRequestRecipients.push(recipient);
548
+ }
549
+ else {
550
+ // add to non-batch send requests
551
+ // use the subject from the recipient's user variables if available as a default
552
+ const cc = recipient.cc;
553
+ const bcc = recipient.bcc;
554
+ const subject = (useSubjectFromRecipientUserVariables ? recipient.userVariables?.['subject'] : undefined) ?? defaultSubject ?? recipient.userVariables?.['subject'];
555
+ const request = {
556
+ ...baseRequest,
557
+ from: recipient.from ?? baseRequest.from,
558
+ replyTo: recipient.replyTo ?? baseRequest.replyTo,
559
+ recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
560
+ to: recipient,
561
+ cc,
562
+ bcc,
563
+ subject,
564
+ batchSend: false // explicitly disable batch send for non-batch requests
565
+ };
566
+ nonBatchSendRequests.push(request);
567
+ }
568
+ });
569
+ // create batch send request(s)
570
+ const batchSendRequests = [];
571
+ if (batchSendRequestRecipients.length > 0) {
572
+ const subject = useSubjectFromRecipientUserVariables ? MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE : defaultSubject;
573
+ // Group recipients by their from/replyTo values
574
+ const batchSendRecipientGroups = makeValuesGroupMap(batchSendRequestRecipients, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey);
575
+ batchSendRecipientGroups.forEach((groupRecipients) => {
576
+ // All recipients in this group should share the same from/replyTo values
577
+ const firstRecipient = groupRecipients[0];
578
+ const batchRequest = {
579
+ ...baseRequest,
580
+ from: firstRecipient.from,
581
+ replyTo: firstRecipient.replyTo,
582
+ recipientVariablesConfig: baseRequest.recipientVariablesConfig ?? recipientVariablesConfig,
583
+ to: groupRecipients,
584
+ subject,
585
+ batchSend: true
586
+ };
587
+ batchSendRequests.push(batchRequest);
588
+ });
589
+ }
590
+ return filterMaybeArrayValues([...batchSendRequests, ...nonBatchSendRequests]);
591
+ };
597
592
  }
598
593
  /**
599
594
  * Creates a MailgunRecipientBatchSendTargetEntityKeyRecipientLookup given the input configuration.
@@ -602,32 +597,30 @@ function expandMailgunRecipientBatchSendTargetRequestFactory(config) {
602
597
  * @returns The lookup.
603
598
  */
604
599
  function mailgunRecipientBatchSendTargetEntityKeyRecipientLookup(config) {
605
- const {
606
- recipientsMap
607
- } = config;
608
- function getRecipientOrDefaultForKey(input, defaultRecipient) {
609
- let result = defaultRecipient;
610
- if (input) {
611
- result = recipientsMap.get(input) ?? defaultRecipient;
600
+ const { recipientsMap } = config;
601
+ function getRecipientOrDefaultForKey(input, defaultRecipient) {
602
+ let result = defaultRecipient;
603
+ if (input) {
604
+ result = recipientsMap.get(input) ?? defaultRecipient;
605
+ }
606
+ return result;
612
607
  }
613
- return result;
614
- }
615
- function getRecipientsForKeys(input) {
616
- let result = undefined;
617
- if (input) {
618
- const keysArray = asArray(input);
619
- const recipients = filterMaybeArrayValues(keysArray.map(key => recipientsMap.get(key)));
620
- if (recipients.length > 0) {
621
- result = recipients;
622
- }
608
+ function getRecipientsForKeys(input) {
609
+ let result = undefined;
610
+ if (input) {
611
+ const keysArray = asArray(input);
612
+ const recipients = filterMaybeArrayValues(keysArray.map((key) => recipientsMap.get(key)));
613
+ if (recipients.length > 0) {
614
+ result = recipients;
615
+ }
616
+ }
617
+ return result;
623
618
  }
624
- return result;
625
- }
626
- return {
627
- recipientsMap,
628
- getRecipientOrDefaultForKey,
629
- getRecipientsForKeys
630
- };
619
+ return {
620
+ recipientsMap,
621
+ getRecipientOrDefaultForKey,
622
+ getRecipientsForKeys
623
+ };
631
624
  }
632
625
 
633
626
  export { DEFAULT_RECIPIENT_VARIABLE_PREFIX, MAILGUN_BATCH_SEND_RECIPIENT_SUBJECT_TEMPLATE, MAILGUN_REPLY_TO_EMAIL_HEADER_DATA_VARIABLE_KEY, MAX_BATCH_SEND_RECIPIENTS, MailgunApi, MailgunService, MailgunServiceModule, convertMailgunRecipientToString, convertMailgunRecipientsToStrings, convertMailgunTemplateEmailRequestToMailgunMessageData, encodeMailgunTemplateVariableValue, expandMailgunRecipientBatchSendTargetRequestFactory, mailgunRecipientBatchSendTargetEntityKeyRecipientLookup, mailgunRecipientBatchSendTargetFromReplyToBatchGroupKey, mailgunServiceConfigFactory };