-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathcreate-warning-connection.email.js
64 lines (60 loc) · 2.77 KB
/
create-warning-connection.email.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { LOCALE } from '../../../shared/domain/constants.js';
import { urlBuilder } from '../../../shared/infrastructure/utils/url-builder.js';
import { EmailFactory } from '../../../shared/mail/domain/models/EmailFactory.js';
import { mailer } from '../../../shared/mail/infrastructure/services/mailer.js';
/**
* Creates an email to warn users for suspicious connection.
*
* @param {Object} params - The parameters for creating the email.
* @param {string} params.locale - The locale for the email.
* @param {string} params.email - The recipient's email address.
* @param {string} params.firstName - The recipient's first name.
* @param {string} params.validationToken - The token for email validation.
* @returns {Email} The email object.
*/
export function createWarningConnectionEmail({ locale, email, firstName, validationToken }) {
locale = locale || LOCALE.FRENCH_FRANCE;
const lang = new Intl.Locale(locale).language;
let localeSupport;
if (locale.toLowerCase() === LOCALE.FRENCH_FRANCE) {
localeSupport = LOCALE.FRENCH_FRANCE;
} else {
localeSupport = lang;
}
const factory = new EmailFactory({ app: 'pix-app', locale: localeSupport });
const { i18n, defaultVariables } = factory;
const pixAppUrl = urlBuilder.getPixAppBaseUrl(locale);
const resetUrl = `${pixAppUrl}/mot-de-passe-oublie?lang=${lang}`;
return factory.buildEmail({
template: mailer.warningConnectionTemplateId,
subject: i18n.__('warning-connection-email.subject'),
to: email,
variables: {
homeName: defaultVariables.homeName,
homeUrl: defaultVariables.homeUrl,
helpDeskUrl: urlBuilder.getEmailValidationUrl({
locale: localeSupport,
redirectUrl: defaultVariables.helpdeskUrl,
token: validationToken,
}),
displayNationalLogo: defaultVariables.displayNationalLogo,
contactUs: i18n.__('common.email.contactUs'),
doNotAnswer: i18n.__('common.email.doNotAnswer'),
moreOn: i18n.__('common.email.moreOn'),
pixPresentation: i18n.__('common.email.pixPresentation'),
hello: i18n.__('warning-connection-email.params.hello', { firstName }),
context: i18n.__('warning-connection-email.params.context'),
disclaimer: i18n.__('warning-connection-email.params.disclaimer'),
warningMessage: i18n.__('warning-connection-email.params.warningMessage'),
resetMyPassword: i18n.__('warning-connection-email.params.resetMyPassword'),
resetUrl: urlBuilder.getEmailValidationUrl({
locale: localeSupport,
redirectUrl: resetUrl,
token: validationToken,
}),
supportContact: i18n.__('warning-connection-email.params.supportContact'),
thanks: i18n.__('warning-connection-email.params.thanks'),
signing: i18n.__('warning-connection-email.params.signing'),
},
});
}