@opencrvs/toolkit 2.1.0-rc.5135dc7 → 2.1.0-rc.517ffcd
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/build.sh +3 -0
- package/create-countryconfig/index.js +114 -66
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +242 -207
- package/dist/cli.js +556 -81
- package/dist/commons/api/router.d.ts +407 -50
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +6 -2
- package/dist/commons/events/ActionDocument.d.ts +4 -4
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
- package/dist/commons/events/EventDocument.d.ts +470 -2
- package/dist/commons/events/EventMetadata.d.ts +1 -11
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +18 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +15 -15
- package/dist/commons/events/locations.d.ts +59 -10
- package/dist/commons/events/test.utils.d.ts +8 -4
- package/dist/commons/events/utils.d.ts +2 -2
- package/dist/commons/notification/UserNotifications.d.ts +28 -13
- package/dist/commons/notification/dispatch.d.ts +15 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +77 -55
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.js +1 -1
- package/dist/events/index.js +839 -775
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +530 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +469 -0
- package/dist/notification/index.js +911 -1359
- package/dist/scopes/index.d.ts +71 -1
- package/dist/scopes/index.js +77 -55
- package/dist/telemetry/index.d.ts +48 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +42 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +1 -1
- package/dist/templates/charts-values/opentelemetry/values.yaml +22 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/opencrvs-toolkit-2.1.0-rc.517ffcd.tgz +0 -0
- package/package.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.5135dc7.tgz +0 -0
|
@@ -212,7 +212,476 @@ Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.l
|
|
|
212
212
|
);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
216
|
+
var import_ts_morph2 = require("ts-morph");
|
|
217
|
+
var import_fs = require("fs");
|
|
218
|
+
var import_path2 = __toESM(require("path"));
|
|
219
|
+
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
220
|
+
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
221
|
+
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
222
|
+
var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
|
|
223
|
+
var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
|
|
224
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
225
|
+
var LOGIN_CSV = "src/translations/login.csv";
|
|
226
|
+
var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
|
|
227
|
+
var TEMPLATES_OBJECT = "templates";
|
|
228
|
+
var OTHER_TEMPLATES_OBJECT = "otherTemplates";
|
|
229
|
+
var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
|
|
230
|
+
var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
|
|
231
|
+
var ROUTES_FUNCTION = "getUserNotificationRoutes";
|
|
232
|
+
var RECOVERY_EVENTS = [
|
|
233
|
+
{
|
|
234
|
+
id: "password-reset-link",
|
|
235
|
+
constant: "PASSWORD_RESET_LINK",
|
|
236
|
+
smsTemplate: "resetPasswordLinkNotification",
|
|
237
|
+
emailSubject: "Reset your password",
|
|
238
|
+
routeDescription: "Handles notification for password reset recovery link",
|
|
239
|
+
heading: "Reset your password",
|
|
240
|
+
reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
|
|
241
|
+
linkLabel: "Reset your password"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "username-reminder-link",
|
|
245
|
+
constant: "USERNAME_REMINDER_LINK",
|
|
246
|
+
smsTemplate: "retrieveUsernameLinkNotification",
|
|
247
|
+
emailSubject: "Retrieve your username",
|
|
248
|
+
routeDescription: "Handles notification for username reminder recovery link",
|
|
249
|
+
heading: "Retrieve your username",
|
|
250
|
+
reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
|
|
251
|
+
linkLabel: "Retrieve your username"
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
var NOTIFICATION_CSV_ROWS = [
|
|
255
|
+
`resetPasswordLinkNotification,The SMS message that is sent to a user containing a self-service password reset link,{{applicationName}}: reset your password using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9initialisez votre mot de passe \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`,
|
|
256
|
+
`retrieveUsernameLinkNotification,The SMS message that is sent to a user containing a self-service username retrieval link,{{applicationName}}: retrieve your username using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9cup\xE9rez votre nom d'utilisateur \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`
|
|
257
|
+
];
|
|
258
|
+
var LOGIN_CSV_ROWS = [
|
|
259
|
+
`buttons.backToLogin,"Label used to leave a screen that is waiting on an emailed link, where logging in is not yet possible",Back to login,Retour \xE0 la connexion`,
|
|
260
|
+
`resetCredentials.recoveryInstructionsSent.body,"Body message for the recovery instructions sent page. Must not assert delivery, since the account may not exist.","If we found an account, you'll receive instructions for {forgottenItem, select, username {retrieving your username} other {resetting your password}}. The link expires in 1 hour.","Si nous trouvons un compte correspondant, vous recevrez les instructions pour {forgottenItem, select, username {r\xE9cup\xE9rer votre nom d'utilisateur} other {r\xE9initialiser votre mot de passe}}. Le lien expire dans 1 heure."`,
|
|
261
|
+
`resetCredentials.recoveryInstructionsSent.title.email,Title for the recovery instructions sent page when notifications are delivered by email,Check your email,V\xE9rifiez votre e-mail`,
|
|
262
|
+
`resetCredentials.recoveryInstructionsSent.title.phone,Title for the recovery instructions sent page when notifications are delivered by SMS,Check your phone,V\xE9rifiez votre t\xE9l\xE9phone`,
|
|
263
|
+
`resetCredentials.recoveryLinkLanding.expired.body,"Body shown when a recovery link is invalid, expired, or already used. Must not reveal whether the underlying account exists.",This link is no longer valid. Request a new one to continue.,Ce lien n'est plus valide. Veuillez en demander un nouveau pour continuer.`,
|
|
264
|
+
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
265
|
+
`resetCredentials.recoveryLinkLanding.expired.title,"Title shown when a recovery link is invalid, expired, or already used",This link has expired,Ce lien a expir\xE9`
|
|
266
|
+
];
|
|
267
|
+
var skipped = [];
|
|
268
|
+
function warnSkipped(message) {
|
|
269
|
+
skipped.push(message);
|
|
270
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
271
|
+
}
|
|
272
|
+
function findObjectLiteral(declaration) {
|
|
273
|
+
let expression = declaration?.getInitializer();
|
|
274
|
+
while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
|
|
275
|
+
expression = expression.getExpression();
|
|
276
|
+
}
|
|
277
|
+
return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
278
|
+
}
|
|
279
|
+
function hasKeyFor(obj, key, constant) {
|
|
280
|
+
const accepted = /* @__PURE__ */ new Set([
|
|
281
|
+
`[TriggerEvent.${constant}]`,
|
|
282
|
+
`['${key}']`,
|
|
283
|
+
`["${key}"]`,
|
|
284
|
+
`'${key}'`,
|
|
285
|
+
`"${key}"`,
|
|
286
|
+
key
|
|
287
|
+
]);
|
|
288
|
+
return obj.getProperties().some(
|
|
289
|
+
(property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function renderKey(obj, key, constant) {
|
|
293
|
+
const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
|
|
294
|
+
if (names.some((name) => name.startsWith("[TriggerEvent."))) {
|
|
295
|
+
return `[TriggerEvent.${constant}]`;
|
|
296
|
+
}
|
|
297
|
+
if (names.some((name) => name.startsWith("["))) {
|
|
298
|
+
return `['${key}']`;
|
|
299
|
+
}
|
|
300
|
+
return `'${key}'`;
|
|
301
|
+
}
|
|
302
|
+
function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
303
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
304
|
+
const properties = obj?.getProperties() ?? [];
|
|
305
|
+
const lastProperty = properties[properties.length - 1];
|
|
306
|
+
if (!lastProperty) return false;
|
|
307
|
+
const indent = lastProperty.getIndentationText();
|
|
308
|
+
const entry = valueLines.map((line, index) => `${indent}${index === 0 ? `${key}: ${line}` : line}`).join("\n");
|
|
309
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
310
|
+
${entry}`);
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
function objectHasKeyFor(sourceFile, objectName, key, constant) {
|
|
314
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
315
|
+
return obj ? hasKeyFor(obj, key, constant) : false;
|
|
316
|
+
}
|
|
317
|
+
function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
318
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
319
|
+
return obj ? renderKey(obj, key, constant) : `'${key}'`;
|
|
320
|
+
}
|
|
321
|
+
function updateEmailTemplates(project, cwd) {
|
|
322
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
323
|
+
if (!sourceFile) {
|
|
324
|
+
warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
328
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
329
|
+
);
|
|
330
|
+
if (missingObject) {
|
|
331
|
+
warnSkipped(
|
|
332
|
+
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
333
|
+
);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
for (const event of RECOVERY_EVENTS) {
|
|
337
|
+
if (!objectHasKeyFor(
|
|
338
|
+
sourceFile,
|
|
339
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
340
|
+
event.id,
|
|
341
|
+
event.constant
|
|
342
|
+
) && appendEntry(
|
|
343
|
+
sourceFile,
|
|
344
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
345
|
+
renderKeyFor(
|
|
346
|
+
sourceFile,
|
|
347
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
348
|
+
event.id,
|
|
349
|
+
event.constant
|
|
350
|
+
),
|
|
351
|
+
[
|
|
352
|
+
"z.object({",
|
|
353
|
+
" firstname: z.string(),",
|
|
354
|
+
" applicationName: z.string(),",
|
|
355
|
+
" countryLogo: z.string(),",
|
|
356
|
+
" recoveryURL: z.string()",
|
|
357
|
+
"})"
|
|
358
|
+
]
|
|
359
|
+
)) {
|
|
360
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
|
|
361
|
+
}
|
|
362
|
+
if (!objectHasKeyFor(
|
|
363
|
+
sourceFile,
|
|
364
|
+
TEMPLATES_OBJECT,
|
|
365
|
+
event.id,
|
|
366
|
+
event.constant
|
|
367
|
+
) && appendEntry(
|
|
368
|
+
sourceFile,
|
|
369
|
+
TEMPLATES_OBJECT,
|
|
370
|
+
renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
|
|
371
|
+
[
|
|
372
|
+
"{",
|
|
373
|
+
` type: '${event.id}',`,
|
|
374
|
+
` subject: '${event.emailSubject}',`,
|
|
375
|
+
` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
|
|
376
|
+
` '${event.id}'`,
|
|
377
|
+
" )",
|
|
378
|
+
"}"
|
|
379
|
+
]
|
|
380
|
+
)) {
|
|
381
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function updateSmsService(project, cwd) {
|
|
386
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
387
|
+
if (!sourceFile) {
|
|
388
|
+
warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const missingObject = [
|
|
392
|
+
OTHER_TEMPLATES_OBJECT,
|
|
393
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT
|
|
394
|
+
].find(
|
|
395
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
396
|
+
);
|
|
397
|
+
if (missingObject) {
|
|
398
|
+
warnSkipped(
|
|
399
|
+
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
400
|
+
);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
for (const event of RECOVERY_EVENTS) {
|
|
404
|
+
if (!objectHasKeyFor(
|
|
405
|
+
sourceFile,
|
|
406
|
+
OTHER_TEMPLATES_OBJECT,
|
|
407
|
+
event.smsTemplate,
|
|
408
|
+
event.smsTemplate
|
|
409
|
+
) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
|
|
410
|
+
`'${event.smsTemplate}'`
|
|
411
|
+
])) {
|
|
412
|
+
console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
|
|
413
|
+
}
|
|
414
|
+
if (!objectHasKeyFor(
|
|
415
|
+
sourceFile,
|
|
416
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
417
|
+
event.id,
|
|
418
|
+
event.constant
|
|
419
|
+
) && appendEntry(
|
|
420
|
+
sourceFile,
|
|
421
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
422
|
+
renderKeyFor(
|
|
423
|
+
sourceFile,
|
|
424
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
425
|
+
event.id,
|
|
426
|
+
event.constant
|
|
427
|
+
),
|
|
428
|
+
[`'${event.smsTemplate}'`]
|
|
429
|
+
)) {
|
|
430
|
+
console.log(
|
|
431
|
+
` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function updateHandler(project, cwd) {
|
|
437
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
438
|
+
if (!sourceFile) {
|
|
439
|
+
warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
443
|
+
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
444
|
+
if (!caseBlock) {
|
|
445
|
+
warnSkipped(
|
|
446
|
+
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
447
|
+
);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const missing = RECOVERY_EVENTS.filter(
|
|
451
|
+
(event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
|
|
452
|
+
);
|
|
453
|
+
if (missing.length === 0) return;
|
|
454
|
+
const existingClauses = caseBlock.getClauses();
|
|
455
|
+
if (existingClauses.length === 0) {
|
|
456
|
+
warnSkipped(
|
|
457
|
+
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
458
|
+
);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
|
|
462
|
+
const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
|
|
463
|
+
const indent = anchor.getIndentationText();
|
|
464
|
+
const lines = [
|
|
465
|
+
...missing.map((event) => `case TriggerEvent.${event.constant}:`),
|
|
466
|
+
` return {`,
|
|
467
|
+
` firstname,`,
|
|
468
|
+
` applicationName: applicationConfig.APPLICATION_NAME,`,
|
|
469
|
+
` countryLogo: COUNTRY_LOGO_URL,`,
|
|
470
|
+
` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
|
|
471
|
+
` }`
|
|
472
|
+
];
|
|
473
|
+
if (defaultClause) {
|
|
474
|
+
caseBlock.insertText(
|
|
475
|
+
anchor.getStart(),
|
|
476
|
+
`${lines.map((line, index) => index === 0 ? line : `${indent}${line}`).join("\n")}
|
|
477
|
+
${indent}`
|
|
478
|
+
);
|
|
479
|
+
} else {
|
|
480
|
+
caseBlock.insertText(
|
|
481
|
+
anchor.getEnd(),
|
|
482
|
+
`
|
|
483
|
+
${lines.map((line) => `${indent}${line}`).join("\n")}`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
for (const event of missing) {
|
|
487
|
+
console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function updateRoutes(project, cwd) {
|
|
491
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
492
|
+
if (!sourceFile) {
|
|
493
|
+
warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
497
|
+
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
498
|
+
if (!routesArray) {
|
|
499
|
+
warnSkipped(
|
|
500
|
+
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
501
|
+
);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
for (const event of RECOVERY_EVENTS) {
|
|
505
|
+
if (routesArray.getText().includes(`/triggers/user/${event.id}`)) continue;
|
|
506
|
+
routesArray.addElement(`{
|
|
507
|
+
method: 'POST',
|
|
508
|
+
path: '/triggers/user/${event.id}',
|
|
509
|
+
handler: makeNotificationHandler('${event.id}'),
|
|
510
|
+
options: {
|
|
511
|
+
auth: false,
|
|
512
|
+
tags: ['api'],
|
|
513
|
+
description: '${event.routeDescription}'
|
|
514
|
+
}
|
|
515
|
+
}`);
|
|
516
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function renderEmailTemplate(event) {
|
|
520
|
+
return `<!--
|
|
521
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
522
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
523
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
524
|
+
|
|
525
|
+
OpenCRVS is also distributed under the terms of the Civil Registration
|
|
526
|
+
& Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
527
|
+
|
|
528
|
+
Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
529
|
+
-->
|
|
530
|
+
<!doctype html>
|
|
531
|
+
<html>
|
|
532
|
+
<head>
|
|
533
|
+
<link
|
|
534
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
535
|
+
rel="stylesheet"
|
|
536
|
+
/>
|
|
537
|
+
<style type="text/css">
|
|
538
|
+
body {
|
|
539
|
+
font-family: 'Noto Sans', sans-serif;
|
|
540
|
+
color: #222;
|
|
541
|
+
padding: 16px 24px;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
h1 {
|
|
545
|
+
font-size: 21px;
|
|
546
|
+
margin-top: 32px;
|
|
547
|
+
margin-bottom: 36px;
|
|
548
|
+
font-weight: 700;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
p {
|
|
552
|
+
font-weight: 400;
|
|
553
|
+
font-size: 16px;
|
|
554
|
+
line-height: 1.8;
|
|
555
|
+
margin-bottom: 24px;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
i {
|
|
559
|
+
color: #666;
|
|
560
|
+
font-weight: 400;
|
|
561
|
+
font-size: 16px;
|
|
562
|
+
}
|
|
563
|
+
</style>
|
|
564
|
+
</head>
|
|
565
|
+
|
|
566
|
+
<body>
|
|
567
|
+
<img
|
|
568
|
+
src="{{countryLogo}}"
|
|
569
|
+
alt="country_logo"
|
|
570
|
+
style="max-height: 88px; max-width: 100%"
|
|
571
|
+
/>
|
|
572
|
+
<h1>${event.heading}</h1>
|
|
573
|
+
<p>Hello {{firstname}},</p>
|
|
574
|
+
<p>
|
|
575
|
+
${event.reason}
|
|
576
|
+
</p>
|
|
577
|
+
|
|
578
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
579
|
+
<a href="{{{recoveryURL}}}">${event.linkLabel}</a>
|
|
580
|
+
</div>
|
|
581
|
+
<br />
|
|
582
|
+
<p>
|
|
583
|
+
This link expires in 1 hour and can only be used once. If you did not
|
|
584
|
+
request this, you can ignore this email.
|
|
585
|
+
</p>
|
|
586
|
+
<br />
|
|
587
|
+
<p>
|
|
588
|
+
Best regards, <br />
|
|
589
|
+
{{applicationName}} Team
|
|
590
|
+
</p>
|
|
591
|
+
</body>
|
|
592
|
+
</html>
|
|
593
|
+
`;
|
|
594
|
+
}
|
|
595
|
+
function writeEmailTemplates(cwd) {
|
|
596
|
+
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
597
|
+
if (!(0, import_fs.existsSync)(templateDir)) {
|
|
598
|
+
warnSkipped(
|
|
599
|
+
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
600
|
+
);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
for (const event of RECOVERY_EVENTS) {
|
|
604
|
+
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
605
|
+
if ((0, import_fs.existsSync)(templatePath)) continue;
|
|
606
|
+
(0, import_fs.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
607
|
+
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function addCsvRows(cwd, relativePath, rows) {
|
|
611
|
+
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
612
|
+
if (!(0, import_fs.existsSync)(csvPath)) {
|
|
613
|
+
warnSkipped(`${relativePath} not found; translations not added`);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const original = (0, import_fs.readFileSync)(csvPath, "utf8");
|
|
617
|
+
const newline = original.includes("\r\n") ? "\r\n" : "\n";
|
|
618
|
+
const hadTrailingNewline = /\r?\n$/.test(original);
|
|
619
|
+
const lines = original.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
620
|
+
const idOf = (line) => line.slice(0, line.indexOf(","));
|
|
621
|
+
const header = lines[0];
|
|
622
|
+
const body = lines.slice(1);
|
|
623
|
+
const isSorted = body.every(
|
|
624
|
+
(line, index) => index === 0 || idOf(body[index - 1]) <= idOf(line)
|
|
625
|
+
);
|
|
626
|
+
let added = 0;
|
|
627
|
+
for (const row of rows) {
|
|
628
|
+
const id = idOf(row);
|
|
629
|
+
if (body.some((line) => idOf(line) === id)) continue;
|
|
630
|
+
const insertAt = isSorted ? body.findIndex((line) => idOf(line) > id) : -1;
|
|
631
|
+
if (insertAt === -1) {
|
|
632
|
+
body.push(row);
|
|
633
|
+
} else {
|
|
634
|
+
body.splice(insertAt, 0, row);
|
|
635
|
+
}
|
|
636
|
+
added++;
|
|
637
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
638
|
+
}
|
|
639
|
+
if (added === 0) return;
|
|
640
|
+
(0, import_fs.writeFileSync)(
|
|
641
|
+
csvPath,
|
|
642
|
+
[header, ...body].join(newline) + (hadTrailingNewline ? newline : "")
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
async function main2() {
|
|
646
|
+
const cwd = process.cwd();
|
|
647
|
+
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
648
|
+
console.log(
|
|
649
|
+
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
650
|
+
);
|
|
651
|
+
if (!(0, import_fs.existsSync)(tsConfigFilePath)) {
|
|
652
|
+
warnSkipped(
|
|
653
|
+
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
654
|
+
);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const project = new import_ts_morph2.Project({
|
|
658
|
+
tsConfigFilePath,
|
|
659
|
+
skipAddingFilesFromTsConfig: false,
|
|
660
|
+
// ts-morph indents inserted code with four spaces by default, which every
|
|
661
|
+
// country config's prettier run would immediately undo.
|
|
662
|
+
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
663
|
+
});
|
|
664
|
+
updateEmailTemplates(project, cwd);
|
|
665
|
+
updateSmsService(project, cwd);
|
|
666
|
+
updateHandler(project, cwd);
|
|
667
|
+
updateRoutes(project, cwd);
|
|
668
|
+
await project.save();
|
|
669
|
+
writeEmailTemplates(cwd);
|
|
670
|
+
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
671
|
+
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
672
|
+
if (skipped.length > 0) {
|
|
673
|
+
console.warn(
|
|
674
|
+
`
|
|
675
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
|
|
676
|
+
);
|
|
677
|
+
for (const message of skipped) {
|
|
678
|
+
console.warn(` - ${message}`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
215
683
|
// src/migrations/v2.1/index.ts
|
|
216
684
|
async function runUpgrade(dockerSwarm) {
|
|
217
685
|
await main();
|
|
686
|
+
await main2();
|
|
218
687
|
}
|