Skip to content

Commit ecfed1b

Browse files
authored
Merge pull request #1097 from opencrvs/ocrvs-10658
Ocrvs 10658
2 parents e0fab41 + 0eefbe0 commit ecfed1b

File tree

12 files changed

+188
-12
lines changed

12 files changed

+188
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"@hapi/boom": "^9.1.1",
7070
"@hapi/hapi": "^20.0.1",
7171
"@hapi/inert": "^6.0.3",
72-
"@opencrvs/toolkit": "1.8.1-rc.591e5a8",
72+
"@opencrvs/toolkit": "1.8.1-rc.c8c6227",
7373
"@types/chalk": "^2.2.0",
7474
"@types/csv2json": "^1.4.0",
7575
"@types/fhir": "^0.0.30",

src/api/notification/__snapshots__/notification.user.email.test.ts.snap

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,132 @@ exports[`User notification - Email > 2fa 1`] = `
6363
}
6464
`;
6565

66+
exports[`User notification - Email > change-email-address 1`] = `
67+
{
68+
"from": "",
69+
"html": "<!DOCTYPE html>
70+
<html>
71+
72+
<head>
73+
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap" rel="stylesheet" />
74+
<style type="text/css">
75+
body {
76+
font-family: 'Noto Sans', sans-serif;
77+
color: #222;
78+
padding: 16px 24px;
79+
}
80+
81+
h1 {
82+
font-size: 21px;
83+
margin-top: 32px;
84+
margin-bottom: 36px;
85+
font-weight: 700;
86+
}
87+
88+
p {
89+
font-weight: 400;
90+
font-size: 16px;
91+
line-height: 1.8;
92+
margin-bottom: 24px;
93+
}
94+
95+
i {
96+
color: #666;
97+
font-weight: 400;
98+
font-size: 16px;
99+
}
100+
</style>
101+
</head>
102+
103+
<body>
104+
<img src="http://localhost:3040/content/country-logo" alt="country_logo" style="max-height: 88px;
105+
max-width: 100%;">
106+
<h1>Change email address</h1>
107+
<p>
108+
Hello John,
109+
</p>
110+
<p>
111+
You recently requested to change your email address for your Farajaland CRS account.
112+
</p>
113+
<p>
114+
To confirm this change, use the code: <strong>654321</strong>
115+
</p>
116+
</br>
117+
<p>
118+
Best regards, <br />
119+
Farajaland CRS Team
120+
</p>
121+
</body>
122+
123+
</html>",
124+
"subject": "Email address change request",
125+
126+
}
127+
`;
128+
129+
exports[`User notification - Email > change-phone-number 1`] = `
130+
{
131+
"from": "",
132+
"html": "<!DOCTYPE html>
133+
<html>
134+
135+
<head>
136+
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap" rel="stylesheet" />
137+
<style type="text/css">
138+
body {
139+
font-family: 'Noto Sans', sans-serif;
140+
color: #222;
141+
padding: 16px 24px;
142+
}
143+
144+
h1 {
145+
font-size: 21px;
146+
margin-top: 32px;
147+
margin-bottom: 36px;
148+
font-weight: 700;
149+
}
150+
151+
p {
152+
font-weight: 400;
153+
font-size: 16px;
154+
line-height: 1.8;
155+
margin-bottom: 24px;
156+
}
157+
158+
i {
159+
color: #666;
160+
font-weight: 400;
161+
font-size: 16px;
162+
}
163+
</style>
164+
</head>
165+
166+
<body>
167+
<img src="http://localhost:3040/content/country-logo" alt="country_logo" style="max-height: 88px;
168+
max-width: 100%;">
169+
<h1>Change phone number</h1>
170+
<p>
171+
Hello John,
172+
</p>
173+
<p>
174+
You recently requested to change your phone number for your Farajaland CRS account.
175+
</p>
176+
<p>
177+
To confirm this change, use the code: <strong>123456</strong>
178+
</p>
179+
</br>
180+
<p>
181+
Best regards, <br />
182+
Farajaland CRS Team
183+
</p>
184+
</body>
185+
186+
</html>",
187+
"subject": "Phone number change request",
188+
189+
}
190+
`;
191+
66192
exports[`User notification - Email > reset-password 1`] = `
67193
{
68194
"from": "",

src/api/notification/__snapshots__/notification.user.sms.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
exports[`User notification - sms > 2fa 1`] = `"{"messages":[{"destinations":[{"recipient":"+15551234567"}],"from":"mock_sender","text":"Your OpenCRVS authentication code is: 102030"}]}"`;
44

5+
exports[`User notification - sms > change-email-address 1`] = `"{"messages":[{"destinations":[{"recipient":"+15551234567"}],"from":"mock_sender","text":"Your OpenCRVS authentication code is: 654321"}]}"`;
6+
7+
exports[`User notification - sms > change-phone-number 1`] = `"{"messages":[{"destinations":[{"recipient":"+15551234567"}],"from":"mock_sender","text":"Your OpenCRVS authentication code is: 123456"}]}"`;
8+
59
exports[`User notification - sms > reset-password 1`] = `"{"messages":[{"destinations":[{"recipient":"+15551234567"}],"from":"mock_sender","text":"Use the code 112233 to reset your Farajaland CRS password. This code expires in 10 minutes."}]}"`;
610

711
exports[`User notification - sms > reset-password-by-admin 1`] = `"{"messages":[{"destinations":[{"recipient":"+15551234567"}],"from":"mock_sender","text":"Your password has been reset. Please login to Farajaland CRS with the temporary password: tempPass123."}]}"`;

src/api/notification/email-templates/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ export const TriggerVariable = {
7676
[TriggerEvent.ALL_USER_NOTIFICATION]: z.object({
7777
subject: z.string(),
7878
body: z.string()
79+
}),
80+
[TriggerEvent.CHANGE_EMAIL_ADDRESS]: z.object({
81+
firstname: z.string(),
82+
code: z.string()
83+
}),
84+
[TriggerEvent.CHANGE_PHONE_NUMBER]: z.object({
85+
firstname: z.string(),
86+
code: z.string()
7987
})
8088
} as const
8189

src/api/notification/email-templates/other/change-email-address.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
max-width: 100%;">
3838
<h1>Change email address</h1>
3939
<p>
40-
Hello {{firstNames}},
40+
Hello {{firstname}},
4141
</p>
4242
<p>
4343
You recently requested to change your email address for your {{applicationName}} account.
4444
</p>
4545
<p>
46-
To confirm this change, use the code: <strong>{{authCode}}</strong>
46+
To confirm this change, use the code: <strong>{{code}}</strong>
4747
</p>
4848
</br>
4949
<p>

src/api/notification/email-templates/other/change-phone-number.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
max-width: 100%;">
3838
<h1>Change phone number</h1>
3939
<p>
40-
Hello {{firstNames}},
40+
Hello {{firstname}},
4141
</p>
4242
<p>
4343
You recently requested to change your phone number for your {{applicationName}} account.
4444
</p>
4545
<p>
46-
To confirm this change, use the code: <strong>{{authCode}}</strong>
46+
To confirm this change, use the code: <strong>{{code}}</strong>
4747
</p>
4848
</br>
4949
<p>

src/api/notification/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ function convertPayloadToVariable({
284284
}
285285

286286
case TriggerEvent.TWO_FA:
287+
case TriggerEvent.CHANGE_EMAIL_ADDRESS:
288+
case TriggerEvent.CHANGE_PHONE_NUMBER:
287289
return {
288290
firstname,
289291
code: payload.code

src/api/notification/sms-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export const TriggerToSMSTemplate = {
131131
['reset-password']: 'resetUserPasswordNotification',
132132
['reset-password-by-admin']: 'resetUserPasswordByAdminNotification',
133133
['2fa']: 'authenticationCodeNotification',
134-
['all-user-notification']: 'allUserNotification'
134+
['all-user-notification']: 'allUserNotification',
135+
['change-email-address']: 'authenticationCodeNotification',
136+
['change-phone-number']: 'authenticationCodeNotification'
135137
} satisfies Record<TriggerEvent, SMSTemplateType>
136138

137139
function isTriggerEvent(event: any): event is TriggerEvent {

src/api/notification/testData.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Recipient } from '@opencrvs/toolkit/notification'
1+
import { Recipient, TriggerEvent } from '@opencrvs/toolkit/notification'
22
import { UUID } from '@opencrvs/toolkit/events'
33
import { TriggerEventPayloadPair } from './handler'
44
import {
@@ -71,6 +71,20 @@ export const userNotificationTestData: TriggerEventPayloadPair[] = [
7171
role: 'NATIONAL_SYSTEM_ADMIN'
7272
}
7373
}
74+
},
75+
{
76+
event: TriggerEvent.CHANGE_EMAIL_ADDRESS,
77+
payload: {
78+
recipient,
79+
code: '654321'
80+
}
81+
},
82+
{
83+
event: TriggerEvent.CHANGE_PHONE_NUMBER,
84+
payload: {
85+
recipient,
86+
code: '123456'
87+
}
7488
}
7589
]
7690

src/config/routes/userNotificationRoutes.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ export default function getUserNotificationRoutes(): ServerRoute<ReqRefDefaults>
8383
tags: ['api'],
8484
description: 'Handles broadcast for all user '
8585
}
86+
},
87+
{
88+
method: 'POST',
89+
path: '/triggers/user/change-phone-number',
90+
handler: makeNotificationHandler('change-phone-number'),
91+
options: {
92+
auth: false,
93+
tags: ['api'],
94+
description: 'Handles verification for phone number change'
95+
}
96+
},
97+
{
98+
method: 'POST',
99+
path: '/triggers/user/change-email-address',
100+
handler: makeNotificationHandler('change-email-address'),
101+
options: {
102+
auth: false,
103+
tags: ['api'],
104+
description: 'Handles verification for email address change'
105+
}
86106
}
87107
]
88108
}

0 commit comments

Comments
 (0)